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 "rssmanager.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>
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent)
|
2011-07-29 15:39:43 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::BrowsingLibrary)
|
|
|
|
, m_historyManager(new HistoryManager(mainClass))
|
|
|
|
, m_bookmarksManager(new BookmarksManager(mainClass))
|
|
|
|
, m_rssManager(mApp->rssManager())
|
|
|
|
, m_rssLoaded(false)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
ui->tabs->AddTab(m_historyManager, QIcon(":/icons/other/bighistory.png"), tr("History"));
|
|
|
|
ui->tabs->AddTab(m_bookmarksManager, QIcon(":/icons/other/bigstar.png"), tr("Bookmarks"));
|
2014-01-04 22:37:18 +01:00
|
|
|
ui->tabs->AddTab(m_rssManager, QIcon(":/icons/other/feed.png"), tr("RSS"));
|
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);
|
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
connect(ui->tabs, SIGNAL(CurrentChanged(int)), this, SLOT(currentIndexChanged(int)));
|
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::currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
ui->searchLine->show();
|
2011-07-30 17:57:14 +02:00
|
|
|
search();
|
2011-07-29 15:39:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->searchLine->show();
|
|
|
|
search();
|
2011-07-29 15:39:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (!m_rssLoaded) {
|
|
|
|
m_rssManager->refreshTable();
|
|
|
|
m_rssLoaded = true;
|
|
|
|
}
|
|
|
|
ui->searchLine->hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
qWarning("BrowsingLibrary::currentIndexChanged() received index out of range!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
d->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::exportBookmarks()
|
|
|
|
{
|
2014-02-17 12:13:26 +01:00
|
|
|
BookmarksExportDialog* d = new BookmarksExportDialog(this);
|
|
|
|
d->show();
|
2014-02-10 14:57:48 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
void BrowsingLibrary::showHistory(QupZilla* mainClass)
|
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(0);
|
|
|
|
show();
|
|
|
|
m_historyManager->setMainWindow(mainClass);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::showBookmarks(QupZilla* mainClass)
|
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(1);
|
|
|
|
show();
|
|
|
|
m_bookmarksManager->setMainWindow(mainClass);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::showRSS(QupZilla* mainClass)
|
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(2);
|
|
|
|
show();
|
|
|
|
m_rssManager->setMainWindow(mainClass);
|
2013-12-28 16:35:52 +01:00
|
|
|
|
|
|
|
if (!m_rssLoaded) {
|
|
|
|
m_rssManager->refreshTable();
|
|
|
|
m_rssLoaded = true;
|
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
raise();
|
2011-10-21 23:26:34 +02:00
|
|
|
activateWindow();
|
2011-07-30 17:57:14 +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();
|
2013-07-10 05:36:05 +02:00
|
|
|
|
2013-12-28 16:35:52 +01:00
|
|
|
// Saves a few megabytes
|
2013-07-10 05:36:05 +02:00
|
|
|
m_rssManager->deleteAllTabs();
|
2013-12-28 16:35:52 +01:00
|
|
|
m_rssLoaded = false;
|
2011-07-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 14:49:16 +02:00
|
|
|
void BrowsingLibrary::keyPressEvent(QKeyEvent* e)
|
|
|
|
{
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
BrowsingLibrary::~BrowsingLibrary()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|