2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* 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-03-02 16:57:41 +01:00
|
|
|
#include "historymodel.h"
|
|
|
|
#include "webview.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
HistoryModel::HistoryModel(QupZilla* mainClass, QObject* parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
: QObject(parent)
|
|
|
|
,m_isSaving(true)
|
|
|
|
,p_QupZilla(mainClass)
|
|
|
|
{
|
|
|
|
loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryModel::loadSettings()
|
|
|
|
{
|
2011-03-04 13:59:07 +01:00
|
|
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
|
|
|
m_isSaving = settings.value("allowHistory",true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryModel::addHistoryEntry(const QString &url, QString &title)
|
|
|
|
{
|
|
|
|
if (!m_isSaving)
|
|
|
|
return -2;
|
|
|
|
if (url.contains("file://") || title.contains(tr("Failed loading page")) || url.isEmpty() || url.contains("about:blank") )
|
|
|
|
return -1;
|
2011-03-17 20:47:06 +01:00
|
|
|
if (title == "")
|
|
|
|
title=tr("No Named Page");
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("SELECT id FROM history WHERE url=?");
|
|
|
|
query.bindValue(0, url);
|
|
|
|
query.exec();
|
|
|
|
if (!query.next()) {
|
|
|
|
query.prepare("INSERT INTO history (count, date, url, title) VALUES (1,?,?,?)");
|
2011-03-18 18:35:09 +01:00
|
|
|
query.bindValue(0, QDateTime::currentMSecsSinceEpoch());
|
2011-03-02 16:57:41 +01:00
|
|
|
query.bindValue(1, url);
|
|
|
|
query.bindValue(2, title);
|
|
|
|
query.exec();
|
|
|
|
}else{
|
2011-03-17 20:47:06 +01:00
|
|
|
query.prepare("UPDATE history SET count = count + 1, date=?, title=? WHERE url=?");
|
2011-03-18 18:35:09 +01:00
|
|
|
query.bindValue(0, QDateTime::currentMSecsSinceEpoch());
|
2011-03-17 20:47:06 +01:00
|
|
|
query.bindValue(1, title);
|
|
|
|
query.bindValue(2, url);
|
2011-03-02 16:57:41 +01:00
|
|
|
query.exec();
|
|
|
|
}
|
|
|
|
return query.lastInsertId().toInt();
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
int HistoryModel::addHistoryEntry(WebView* view)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (!m_isSaving)
|
|
|
|
return -2;
|
|
|
|
QString url = view->url().toString();
|
|
|
|
QString title = view->title();
|
|
|
|
return addHistoryEntry(url, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryModel::deleteHistoryEntry(int index)
|
|
|
|
{
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("DELETE FROM history WHERE id=?");
|
|
|
|
query.bindValue(0, index);
|
|
|
|
if (query.exec())
|
|
|
|
return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
|
|
|
|
{
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("DELETE FROM history WHERE url=? AND title=?");
|
|
|
|
query.bindValue(0, url);
|
|
|
|
query.bindValue(1, title);
|
|
|
|
if (query.exec())
|
|
|
|
return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryModel::optimizeHistory()
|
|
|
|
{
|
|
|
|
QSqlQuery query;
|
|
|
|
return query.exec("VACUUM");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryModel::clearHistory()
|
|
|
|
{
|
|
|
|
QSqlQuery query;
|
|
|
|
return query.exec("DELETE FROM history");
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryModel::setSaving(bool state)
|
|
|
|
{
|
|
|
|
m_isSaving = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryModel::isSaving()
|
|
|
|
{
|
|
|
|
return m_isSaving;
|
|
|
|
}
|