Example #1
0
DBManager::DBManager(QObject *parent)
    : QObject(parent)
    , m_maxTabId(0)
{
    qRegisterMetaType<QList<Tab> >("QList<Tab>");
    qRegisterMetaType<QList<Link> >("QList<Link>");
    qRegisterMetaType<Tab>("Tab");

    worker = new DBWorker();
    worker->moveToThread(&workerThread);

    connect(&workerThread, SIGNAL(finished()), worker, SLOT(deleteLater()));
    connect(worker, SIGNAL(tabsAvailable(QList<Tab>)), this, SLOT(tabListAvailable(QList<Tab>)));
    connect(worker, SIGNAL(historyAvailable(QList<Link>)), this, SIGNAL(historyAvailable(QList<Link>)));
    connect(worker, SIGNAL(tabHistoryAvailable(int,QList<Link>)), this, SIGNAL(tabHistoryAvailable(int,QList<Link>)));
    connect(worker, SIGNAL(tabChanged(Tab)), this, SIGNAL(tabChanged(Tab)));
    connect(worker, SIGNAL(tabAvailable(Tab)), this, SIGNAL(tabAvailable(Tab)));
    connect(worker, SIGNAL(titleChanged(QString,QString)), this, SIGNAL(titleChanged(QString,QString)));
    connect(worker, SIGNAL(thumbPathChanged(QString,QString,int)), this, SIGNAL(thumbPathChanged(QString,QString,int)));
    workerThread.start();

    QMetaObject::invokeMethod(worker, "init", Qt::BlockingQueuedConnection);
    QMetaObject::invokeMethod(worker, "getMaxTabId", Qt::BlockingQueuedConnection,
                              Q_RETURN_ARG(int, m_maxTabId));
    QMetaObject::invokeMethod(worker, "getSettings", Qt::BlockingQueuedConnection,
                              Q_RETURN_ARG(SettingsMap, m_settings));
}
Example #2
0
void DBWorker::removeTab(int tabId)
{
#ifdef DEBUG_LOGS
    qDebug() << "tab id:" << tabId;
#endif

    QSqlQuery query = prepare("DELETE FROM tab WHERE tab_id = ?;");
    query.bindValue(0, tabId);
    execute(query);

    // Remove links that are only related to this tab
    query = prepare("DELETE FROM link WHERE link_id IN "
                    "(SELECT DISTINCT link_id FROM tab_history WHERE tab_id = ? "
                    "AND link_id NOT IN (SELECT link_id FROM tab_history WHERE tab_id != ? "
                    "UNION SELECT link_id FROM history))");
    query.bindValue(0, tabId);
    query.bindValue(1, tabId);

    // Remove history
    query = prepare("DELETE FROM tab_history WHERE tab_id = ?;");
    query.bindValue(0, tabId);
    execute(query);

    // Check last tab closed
    if (!tabCount()) {
        emit tabAvailable(Tab(-1, Link(), -1, -1));
    }
}
Example #3
0
void DBWorker::getTab(int tabId)
{
    QSqlQuery query = prepare("SELECT tab_id, tab_history_id FROM tab WHERE tab_id = ?;");
    query.bindValue(0, tabId);
    if (!execute(query)) {
        return;
    }

    if (query.first()) {
#ifdef DEBUG_LOGS
        Tab tab = getTabData(query.value(0).toInt(), query.value(1).toInt());
        qDebug() << query.value(0).toInt() << query.value(1).toInt() << tab.currentLink().title() << tab.currentLink().url();
#endif
        emit tabAvailable(getTabData(query.value(0).toInt(), query.value(1).toInt()));
    }
}
Example #4
0
void DBWorker::removeAllTabs()
{
    QSqlQuery query = prepare("DELETE FROM tab;");
    execute(query);

    // Remove links that are not stored in history
    query = prepare("DELETE FROM link WHERE link_id IN "
                    "(SELECT DISTINCT link_id FROM tab_history "
                    "WHERE link_id NOT IN (SELECT link_id FROM history))");
    execute(query);

    // Remove history
    query = prepare("DELETE FROM tab_history;");
    execute(query);

    emit tabAvailable(Tab(-1, Link(), -1, -1));
}