void DeclarativeTabModel::tabChanged(const Tab &tab)
{
#ifdef DEBUG_LOGS
    qDebug() << &m_activeTab;
    qDebug() << "new tab data:" << &tab;
#endif
    if (m_activeTab.tabId() == tab.tabId()) {
        updateActiveTab(tab);
    } else {
        int i = m_tabs.indexOf(tab); // match based on tab_id
        if (i > -1) {
            QVector<int> roles;
            Tab oldTab = m_tabs[i];
            if (oldTab.url() != tab.url()) {
                roles << UrlRole;
            }
            if (oldTab.title() != tab.title()) {
                roles << TitleRole;
            }
            if (oldTab.thumbnailPath() != tab.thumbnailPath()) {
                roles << ThumbPathRole;
            }
            m_tabs[i] = tab;
            QModelIndex start = index(i, 0);
            QModelIndex end = index(i, 0);
            emit dataChanged(start, end, roles);
        }
    }
}
Esempio n. 2
0
void DBWorker::createTab(const Tab &tab)
{
#if DEBUG_LOGS
    qDebug() << "new tab id: " << tab.tabId();
#endif
    QSqlQuery query = prepare("INSERT INTO tab (tab_id, tab_history_id) VALUES (?,?);");
    query.bindValue(0, tab.tabId());
    query.bindValue(1, 0);
    execute(query);

    if (tab.url().isEmpty()) {
        return;
    }

    int linkId = createLink(tab.url(), tab.title(), tab.thumbnailPath());

    if (addToBrowserHistory(tab.url(), tab.title()) == Error) {
        qWarning() << Q_FUNC_INFO << "failed to add url to history" << tab.url();
    }

    int historyId = addToTabHistory(tab.tabId(), linkId);
    if (historyId > 0) {
        updateTab(tab.tabId(), historyId);
    } else {
        qWarning() << Q_FUNC_INFO << "failed to add url to tab history" << tab.url();
    }

#if DEBUG_LOGS
    qDebug() << "created link:" << linkId << "with history id:" << historyId << "for tab:" << tab.tabId() << tab.url();
#endif
}
Esempio n. 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()) {
#if DEBUG_LOGS
        Tab tab = getTabData(query.value(0).toInt(), query.value(1).toInt());
        qDebug() << query.value(0).toInt() << query.value(1).toInt() << tab.title() << tab.url();
#endif
        emit tabAvailable(getTabData(query.value(0).toInt(), query.value(1).toInt()));
    }
}