HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent) : QWidget(parent) , ui(new Ui::HistoryManager) , p_QupZilla(mainClass) , m_historyModel(mApp->history()) { ui->setupUi(this); ui->historyTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed); ui->historyTree->setSelectionMode(QAbstractItemView::ExtendedSelection); ui->deleteB->setShortcut(QKeySequence("Del")); connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(ui->historyTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem())); connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory())); connect(ui->historyTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); connect(m_historyModel, SIGNAL(historyEntryAdded(HistoryEntry)), this, SLOT(historyEntryAdded(HistoryEntry))); connect(m_historyModel, SIGNAL(historyEntryDeleted(HistoryEntry)), this, SLOT(historyEntryDeleted(HistoryEntry))); connect(m_historyModel, SIGNAL(historyEntryEdited(HistoryEntry, HistoryEntry)), this, SLOT(historyEntryEdited(HistoryEntry, HistoryEntry))); connect(m_historyModel, SIGNAL(historyClear()), ui->historyTree, SLOT(clear())); connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb())); //QTimer::singleShot(0, this, SLOT(refreshTable())); ui->historyTree->setFocus(); }
HistoryModel::HistoryModel(History* history) : QAbstractItemModel(history) , m_rootItem(new HistoryItem(0)) , m_todayItem(0) , m_history(history) { init(); connect(m_history, SIGNAL(resetHistory()), this, SLOT(resetHistory())); connect(m_history, SIGNAL(historyEntryAdded(HistoryEntry)), this, SLOT(historyEntryAdded(HistoryEntry))); connect(m_history, SIGNAL(historyEntryDeleted(HistoryEntry)), this, SLOT(historyEntryDeleted(HistoryEntry))); connect(m_history, SIGNAL(historyEntryEdited(HistoryEntry,HistoryEntry)), this, SLOT(historyEntryEdited(HistoryEntry,HistoryEntry))); }
void HistoryModel::slotAddHistoryEntry(const QUrl &url, QString title) { if (!m_isSaving) { return; } if (url.scheme() == "file:" || url.scheme() == "qupzilla" || url.scheme() == "about" || title.contains(tr("Failed loading page")) || url.isEmpty()) { return; } if (title == "") { title = tr("No Named Page"); } 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,?,?,?)"); query.bindValue(0, QDateTime::currentMSecsSinceEpoch()); query.bindValue(1, url); query.bindValue(2, title); query.exec(); int id = query.lastInsertId().toInt(); HistoryEntry entry; entry.id = id; entry.count = 1; entry.date = QDateTime::currentDateTime(); entry.url = url; entry.title = title; emit historyEntryAdded(entry); } else { int id = query.value(0).toInt(); query.prepare("UPDATE history SET count = count + 1, date=?, title=? WHERE url=?"); query.bindValue(0, QDateTime::currentMSecsSinceEpoch()); query.bindValue(1, title); query.bindValue(2, url); query.exec(); HistoryEntry before; before.id = id; HistoryEntry after; after.id = id; after.date = QDateTime::currentDateTime(); after.url = url; after.title = title; emit historyEntryEdited(before, after); } }
void History::addHistoryEntry(const QUrl &url, QString title) { if (!m_isSaving) { return; } if (url.isEmpty() || url.scheme() == QLatin1String("qupzilla") || url.scheme() == QLatin1String("about") || url.scheme() == QLatin1String("data") ) { return; } if (title.isEmpty()) { title = tr("Empty Page"); } QSqlQuery query; query.prepare("SELECT id, count, date, title FROM history WHERE url=?"); query.bindValue(0, url); query.exec(); if (!query.next()) { query.prepare("INSERT INTO history (count, date, url, title) VALUES (1,?,?,?)"); query.bindValue(0, QDateTime::currentMSecsSinceEpoch()); query.bindValue(1, url); query.bindValue(2, title); query.exec(); int id = query.lastInsertId().toInt(); HistoryEntry entry; entry.id = id; entry.count = 1; entry.date = QDateTime::currentDateTime(); entry.url = url; entry.urlString = url.toEncoded(); entry.title = title; emit historyEntryAdded(entry); } else { int id = query.value(0).toInt(); int count = query.value(1).toInt(); QDateTime date = QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong()); QString oldTitle = query.value(3).toString(); query.prepare("UPDATE history SET count = count + 1, date=?, title=? WHERE url=?"); query.bindValue(0, QDateTime::currentMSecsSinceEpoch()); query.bindValue(1, title); query.bindValue(2, url); query.exec(); HistoryEntry before; before.id = id; before.count = count; before.date = date; before.url = url; before.urlString = url.toEncoded(); before.title = oldTitle; HistoryEntry after = before; after.count = count + 1; after.date = QDateTime::currentDateTime(); after.title = title; emit historyEntryEdited(before, after); } }