2011-07-30 17:57:14 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-07-30 17:57:14 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-07-29 15:39:43 +02:00
|
|
|
#include "browsinglibrary.h"
|
|
|
|
#include "ui_browsinglibrary.h"
|
2014-02-15 01:49:12 +01:00
|
|
|
#include "bookmarksimport/bookmarksimportdialog.h"
|
2014-02-17 12:13:26 +01:00
|
|
|
#include "bookmarksexport/bookmarksexportdialog.h"
|
2011-07-29 15:39:43 +02:00
|
|
|
#include "historymanager.h"
|
|
|
|
#include "bookmarksmanager.h"
|
|
|
|
#include "mainapplication.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
#include <QMenu>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QCloseEvent>
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
BrowsingLibrary::BrowsingLibrary(BrowserWindow* window, QWidget* parent)
|
2011-07-29 15:39:43 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::BrowsingLibrary)
|
2014-02-19 22:07:21 +01:00
|
|
|
, m_historyManager(new HistoryManager(window))
|
|
|
|
, m_bookmarksManager(new BookmarksManager(window))
|
2011-07-29 15:39:43 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-07-30 17:57:14 +02:00
|
|
|
settings.beginGroup("BrowsingLibrary");
|
|
|
|
resize(settings.value("size", QSize(760, 470)).toSize());
|
2012-04-30 16:33:14 +02:00
|
|
|
m_historyManager->restoreState(settings.value("historyState", QByteArray()).toByteArray());
|
2011-07-30 17:57:14 +02:00
|
|
|
settings.endGroup();
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QzTools::centerWidgetOnScreen(this);
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2016-12-30 22:23:04 +01:00
|
|
|
QIcon historyIcon;
|
|
|
|
historyIcon.addFile(QSL(":/icons/other/bighistory.svg"), QSize(), QIcon::Normal);
|
|
|
|
historyIcon.addFile(QSL(":/icons/other/bighistory-selected.svg"), QSize(), QIcon::Selected);
|
|
|
|
|
|
|
|
QIcon bookmarksIcon;
|
|
|
|
bookmarksIcon.addFile(QSL(":/icons/other/bigstar.svg"), QSize(), QIcon::Normal);
|
|
|
|
bookmarksIcon.addFile(QSL(":/icons/other/bigstar-selected.svg"), QSize(), QIcon::Selected);
|
|
|
|
|
|
|
|
ui->tabs->AddTab(m_historyManager, historyIcon, tr("History"));
|
|
|
|
ui->tabs->AddTab(m_bookmarksManager, bookmarksIcon, tr("Bookmarks"));
|
2011-07-29 15:39:43 +02:00
|
|
|
ui->tabs->SetMode(FancyTabWidget::Mode_LargeSidebar);
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->tabs->setFocus();
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
QMenu* m = new QMenu(this);
|
|
|
|
m->addAction(tr("Import Bookmarks..."), this, SLOT(importBookmarks()));
|
2014-02-17 12:13:26 +01:00
|
|
|
m->addAction(tr("Export Bookmarks..."), this, SLOT(exportBookmarks()));
|
2014-02-10 14:57:48 +01:00
|
|
|
ui->importExport->setMenu(m);
|
|
|
|
|
2016-12-31 10:11:52 +01:00
|
|
|
connect(ui->tabs, &FancyTabWidget::CurrentChanged, ui->searchLine, &QLineEdit::clear);
|
2013-03-04 21:34:43 +01:00
|
|
|
connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(search()));
|
2013-07-07 12:32:55 +02:00
|
|
|
|
|
|
|
QzTools::setWmClass("Browsing Library", this);
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::search()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (ui->tabs->current_index() == 0) {
|
2011-07-30 17:57:14 +02:00
|
|
|
m_historyManager->search(ui->searchLine->text());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-07-30 17:57:14 +02:00
|
|
|
m_bookmarksManager->search(ui->searchLine->text());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
void BrowsingLibrary::importBookmarks()
|
|
|
|
{
|
|
|
|
BookmarksImportDialog* d = new BookmarksImportDialog(this);
|
2014-11-07 18:08:12 +01:00
|
|
|
d->open();
|
2014-02-10 14:57:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::exportBookmarks()
|
|
|
|
{
|
2014-02-17 12:13:26 +01:00
|
|
|
BookmarksExportDialog* d = new BookmarksExportDialog(this);
|
2014-11-07 18:08:12 +01:00
|
|
|
d->open();
|
2014-02-10 14:57:48 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowsingLibrary::showHistory(BrowserWindow* window)
|
2011-07-29 15:39:43 +02:00
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(0);
|
|
|
|
show();
|
2014-02-19 22:07:21 +01:00
|
|
|
m_historyManager->setMainWindow(window);
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
raise();
|
2011-10-21 23:26:34 +02:00
|
|
|
activateWindow();
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowsingLibrary::showBookmarks(BrowserWindow* window)
|
2011-07-29 15:39:43 +02:00
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(1);
|
|
|
|
show();
|
2014-02-19 22:07:21 +01:00
|
|
|
m_bookmarksManager->setMainWindow(window);
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
raise();
|
2011-10-21 23:26:34 +02:00
|
|
|
activateWindow();
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void BrowsingLibrary::closeEvent(QCloseEvent* e)
|
2011-07-30 17:57:14 +02:00
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-07-30 17:57:14 +02:00
|
|
|
settings.beginGroup("BrowsingLibrary");
|
|
|
|
settings.setValue("size", size());
|
2012-04-30 16:33:14 +02:00
|
|
|
settings.setValue("historyState", m_historyManager->saveState());
|
2011-07-30 17:57:14 +02:00
|
|
|
settings.endGroup();
|
|
|
|
e->accept();
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 14:49:16 +02:00
|
|
|
void BrowsingLibrary::keyPressEvent(QKeyEvent* e)
|
|
|
|
{
|
2014-12-20 15:58:25 +01:00
|
|
|
if (e->key() == Qt::Key_Escape
|
|
|
|
|| (e->key() == Qt::Key_W && e->modifiers() == Qt::ControlModifier)) {
|
2012-04-20 14:49:16 +02:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
BrowsingLibrary::~BrowsingLibrary()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|