50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <QList>
|
|
#include <QSqlDatabase>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QUrl>
|
|
|
|
// Browsing history in history.sqlite under AppDataLocation. Two tables:
|
|
// "visits" is an append-only log of every page load; "urls" holds one row per
|
|
// URL with its latest title and visit time, and is what completion searches.
|
|
//
|
|
// Queries run synchronously on the GUI thread. That is fine for SQLite at
|
|
// browser-history sizes, with WAL so a write never waits on a full fsync.
|
|
class History
|
|
{
|
|
public:
|
|
struct Entry {
|
|
QString url;
|
|
QString title;
|
|
};
|
|
|
|
History();
|
|
~History();
|
|
|
|
History(const History &) = delete;
|
|
History &operator=(const History &) = delete;
|
|
|
|
bool isOpen() const { return m_open; }
|
|
|
|
void addVisit(const QUrl &url, const QString &title);
|
|
// Pages often set their title after the load finished.
|
|
void updateTitle(const QUrl &url, const QString &title);
|
|
|
|
// Most recently visited first. Every word must appear in the URL or the
|
|
// title, case-insensitively.
|
|
QList<Entry> search(const QStringList &words, int limit) const;
|
|
|
|
bool clear();
|
|
|
|
// Whether a URL belongs in history at all: no internal or data pages.
|
|
static bool isRecordable(const QUrl &url);
|
|
|
|
private:
|
|
bool exec(const QString &sql);
|
|
|
|
QSqlDatabase m_db;
|
|
bool m_open = false;
|
|
};
|