28#include <QWebEngineProfile>
51 m_isSaving = settings.
value(
QSL(
"allowHistory"),
true).toBool();
62 const QUrl url = view->url();
63 const QString title = view->
title();
74 const QStringList schemes = {
78 if (!schemes.contains(url.scheme()) && !
qzSettings->allowedSchemes.contains(url.scheme())) {
82 if (title.isEmpty()) {
83 title = tr(
"Empty Page");
86 auto job =
new SqlQueryJob(
QSL(
"SELECT id, count, date, title FROM history WHERE url=?"),
this);
87 job->addBindValue(url);
89 if (job->records().isEmpty()) {
90 auto job = new SqlQueryJob(QSL(
"INSERT INTO history (count, date, url, title) VALUES (1,?,?,?)"), this);
91 job->addBindValue(QDateTime::currentMSecsSinceEpoch());
92 job->addBindValue(url);
93 job->addBindValue(title);
94 connect(job, &SqlQueryJob::finished, this, [=]() {
96 entry.id = job->lastInsertId().toInt();
98 entry.date = QDateTime::currentDateTime();
100 entry.urlString = QString::fromUtf8(url.toEncoded());
102 Q_EMIT historyEntryAdded(entry);
106 const auto record = job->records().at(0);
107 const int id = record.value(0).toInt();
108 const int count = record.value(1).toInt();
109 const QDateTime date = QDateTime::fromMSecsSinceEpoch(record.value(2).toLongLong());
110 const QString oldTitle = record.value(3).toString();
112 auto job =
new SqlQueryJob(
QSL(
"UPDATE history SET count = count + 1, date=?, title=? WHERE url=?"),
this);
113 job->addBindValue(QDateTime::currentMSecsSinceEpoch());
114 job->addBindValue(title);
115 job->addBindValue(url);
119 before.
count = count;
122 before.
urlString = QString::fromUtf8(url.toEncoded());
123 before.
title = oldTitle;
126 after.
count = count + 1;
127 after.
date = QDateTime::currentDateTime();
152 for (
int index : list) {
154 query.prepare(
QSL(
"SELECT count, date, url, title FROM history WHERE id=?"));
155 query.addBindValue(index);
158 if (!query.isActive() || !query.next()) {
164 entry.
count = query.value(0).toInt();
165 entry.
date = QDateTime::fromMSecsSinceEpoch(query.value(1).toLongLong());
166 entry.
url = query.value(2).toUrl();
167 entry.
urlString = QString::fromUtf8(entry.
url.toEncoded());
168 entry.
title = query.value(3).toString();
170 query.prepare(
QSL(
"DELETE FROM history WHERE id=?"));
171 query.addBindValue(index);
174 query.prepare(
QSL(
"DELETE FROM icons WHERE url=?"));
175 query.addBindValue(entry.
url.toEncoded(QUrl::RemoveFragment));
187 query.prepare(
QSL(
"SELECT id FROM history WHERE url=?"));
188 query.bindValue(0, url);
191 int id = query.value(0).toInt();
199 query.prepare(
QSL(
"SELECT id FROM history WHERE url=? AND title=?"));
200 query.bindValue(0, url);
201 query.bindValue(1, title);
204 int id = query.value(0).toInt();
213 if (start < 0 || end < 0) {
218 query.prepare(
QSL(
"SELECT id FROM history WHERE date BETWEEN ? AND ?"));
219 query.addBindValue(end);
220 query.addBindValue(start);
223 while (query.next()) {
224 list.append(query.value(0).toInt());
232 QVector<HistoryEntry> list;
234 query.prepare(
QSL(
"SELECT count, date, id, title, url FROM history ORDER BY count DESC LIMIT %1").arg(count));
236 while (query.next()) {
238 entry.
count = query.value(0).toInt();
239 entry.
date = query.value(1).toDateTime();
240 entry.
id = query.value(2).toInt();
241 entry.
title = query.value(3).toString();
242 entry.
url = query.value(4).toUrl();
251 query.exec(
QSL(
"DELETE FROM history"));
252 query.exec(
QSL(
"VACUUM"));
254 mApp->webProfile()->clearAllVisitedLinks();
273 return tr(
"January");
275 return tr(
"February");
289 return tr(
"September");
291 return tr(
"October");
293 return tr(
"November");
295 return tr(
"December");
297 qWarning(
"Month number out of range!");
304 QList<HistoryEntry> list;
306 query.prepare(
QSL(
"SELECT count, date, id, title, url FROM history WHERE title LIKE ? OR url LIKE ?"));
307 query.bindValue(0,
QSL(
"%%1%").arg(text));
308 query.bindValue(1,
QSL(
"%%1%").arg(text));
310 while (query.next()) {
312 entry.
count = query.value(0).toInt();
313 entry.
date = query.value(1).toDateTime();
314 entry.
id = query.value(2).toInt();
315 entry.
title = query.value(3).toString();
316 entry.
url = query.value(4).toUrl();
325 query.prepare(
QSL(
"SELECT count, date, id, title, url FROM history WHERE url = ?"));
326 query.bindValue(0, text);
331 entry.
count = query.value(0).toInt();
332 entry.
date = query.value(1).toDateTime();
333 entry.
id = query.value(2).toInt();
334 entry.
title = query.value(3).toString();
335 entry.
url = query.value(4).toUrl();
QList< int > indexesFromTimeRange(qint64 start, qint64 end)
HistoryEntry getHistoryEntry(const QString &text)
void historyEntryDeleted(const HistoryEntry &entry)
void setSaving(bool state)
void historyEntryEdited(const HistoryEntry &before, const HistoryEntry &after)
void addHistoryEntry(WebView *view)
void deleteHistoryEntry(int index)
QVector< HistoryEntry > mostVisited(int count)
QList< HistoryEntry > searchHistoryEntry(const QString &text)
static QString titleCaseLocalizedMonth(int month)
void beginGroup(const QString &prefix)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant())
static SqlDatabase * instance()
void finished(SqlQueryJob *job)
QString title(bool allowEmpty=false) const