void DeclarativeTabModel::updateTabUrl(int tabId, bool activeTab, const QString &url, bool navigate)
{
    if (!LinkValidator::navigable(QUrl(url))) {
#if DEBUG_LOGS
        qDebug() << "invalid url: " << url;
#endif
        return;
    }

    int tabIndex = findTabIndex(tabId);
    bool updateDb = false;
    if (tabIndex >= 0 && (m_tabs.at(tabIndex).url() != url || activeTab)) {
        QVector<int> roles;
        roles << UrlRole << TitleRole << ThumbPathRole;
        m_tabs[tabIndex].setUrl(url);

        if (navigate) {
            m_tabs[tabIndex].setNextLink(0);
            int currentLinkId = m_tabs.at(tabIndex).currentLink();
            m_tabs[tabIndex].setPreviousLink(currentLinkId);
            m_tabs[tabIndex].setCurrentLink(nextLinkId());
        }
        m_tabs[tabIndex].setTitle("");
        m_tabs[tabIndex].setThumbnailPath("");

        if (tabId == m_activeTab.tabId()) {
            m_activeTab = m_tabs[tabIndex];
        }

        emit dataChanged(index(tabIndex, 0), index(tabIndex, 0), roles);
        updateDb = true;
    }

    if (updateDb) {
        if (!navigate) {
            updateTab(tabId, url, "", "");
        } else {
            navigateTo(tabId, url, "", "");
        }
    }

}
Exemple #2
0
int DBWorker::createLink(QString url, QString title, QString thumbPath)
{
    QSqlQuery query = prepare("INSERT INTO link (url, title, thumb_path) VALUES (?, ?, ?);");
    query.bindValue(0, url);
    query.bindValue(1, title);
    query.bindValue(2, thumbPath);
    execute(query);

    QVariant lastId = query.lastInsertId();
    if (!lastId.isValid()) {
        qWarning() << Q_FUNC_INFO << "unable to fetch last inserted id";
        return 0;
    }

#if DEBUG_LOGS
    qDebug() << title << url << thumbPath << lastId.toInt();
#endif
    int linkId = lastId.toInt();

    emit nextLinkId(linkId + 1);
    return linkId;
}