2011-07-30 17:57:14 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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"
|
|
|
|
#include "historymanager.h"
|
|
|
|
#include "bookmarksmanager.h"
|
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "mainapplication.h"
|
2011-07-30 17:57:14 +02:00
|
|
|
#include "downloaditem.h"
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "globalfunctions.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2011-07-29 15:39:43 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
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_bookmarksLoaded(false)
|
|
|
|
, 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
|
|
|
|
2011-09-21 14:20:49 +02:00
|
|
|
qz_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"));
|
|
|
|
ui->tabs->AddTab(m_rssManager, QIcon(":/icons/other/bigrss.png"), tr("RSS"));
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
connect(ui->tabs, SIGNAL(CurrentChanged(int)), this, SLOT(currentIndexChanged(int)));
|
|
|
|
connect(ui->searchLine, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(search()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
if (!m_bookmarksLoaded) {
|
|
|
|
m_bookmarksManager->refreshTable();
|
|
|
|
m_bookmarksLoaded = true;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!m_bookmarksLoaded) {
|
|
|
|
m_bookmarksManager->refreshTable();
|
|
|
|
m_bookmarksLoaded = 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-29 15:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::showRSS(QupZilla* mainClass)
|
|
|
|
{
|
|
|
|
ui->tabs->SetCurrentIndex(2);
|
|
|
|
show();
|
|
|
|
m_rssManager->setMainWindow(mainClass);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingLibrary::optimizeDatabase()
|
|
|
|
{
|
|
|
|
mApp->setOverrideCursor(Qt::WaitCursor);
|
2012-04-04 18:48:54 +02:00
|
|
|
QString profilePath = mApp->currentProfilePath();
|
2012-08-23 15:40:10 +02:00
|
|
|
QString sizeBefore = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
|
2011-07-30 17:57:14 +02:00
|
|
|
mApp->history()->optimizeHistory();
|
2012-08-23 15:40:10 +02:00
|
|
|
QString sizeAfter = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
|
2011-07-30 17:57:14 +02:00
|
|
|
mApp->restoreOverrideCursor();
|
2011-11-04 12:19:31 +01:00
|
|
|
QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.<br/><br/><b>Database Size Before: </b>%1<br/><b>Database Size After: </b>%2").arg(sizeBefore, sizeAfter));
|
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();
|
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;
|
|
|
|
}
|