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);
        }
    }
}
Ejemplo 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
}