Ejemplo n.º 1
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
}
void DeclarativeTabModel::tabChanged(Tab tab)
{
    // When a tab was closed do not update anything from database as
    // loading might be on going.
    if (m_activeTabClosed && this->sender() == DBManager::instance()) {
        m_activeTabClosed = false;
        return;
    }
#ifdef DEBUG_LOGS
    qDebug() << "tab: " << tab.tabId() << m_activeTab.tabId() << tab.currentLink().thumbPath() << tab.currentLink().url() << tab.currentLink().title() << m_tabs.indexOf(tab);
#endif
    if (tab.tabId() == m_activeTab.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.currentLink().url() != tab.currentLink().url()) {
                roles << UrlRole;
            }
            if (oldTab.currentLink().title() != tab.currentLink().title()) {
                roles << TitleRole;
            }
            if (oldTab.currentLink().thumbPath() != tab.currentLink().thumbPath()) {
                roles << ThumbPathRole;
            }
            m_tabs[i] = tab;
            QModelIndex start = index(i, 0);
            QModelIndex end = index(i, 0);
            emit dataChanged(start, end, roles);
        }
    }
}
bool DeclarativeTabModel::tabSort(const Tab &t1, const Tab &t2)
{
    int i1 = s_tabOrder.indexOf(t1.tabId());
    int i2 = s_tabOrder.indexOf(t2.tabId());
    if (i2 == -1) {
        return true;
    } else {
        return i1 < i2;
    }
}
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);
        }
    }
}
void DeclarativeTabModel::updateActiveTab(const Tab &activeTab, bool loadActiveTab)
{
#if DEBUG_LOGS
    qDebug() << "new active tab:" << &activeTab << "old active tab:" << &m_activeTab << "count:" << m_tabs.count();
#endif
    if (m_tabs.isEmpty()) {
        return;
    }

    if (m_activeTab != activeTab) {
        int oldTabId = m_activeTab.tabId();
        m_activeTab = activeTab;

        // If tab has changed, update active tab role.
        int tabIndex = activeTabIndex();
        if (oldTabId != m_activeTab.tabId() && tabIndex >= 0) {
            emit activeTabIndexChanged();
        }
        // To avoid blinking we don't expose "activeTabIndex" as a model role because
        // it should be updated over here and this is too early.
        // Instead, we pass current contentItem and activeTabIndex
        // when pushing the TabPage to the PageStack. This is the signal changes the
        // contentItem of WebView.
        emit activeTabChanged(oldTabId, activeTab.tabId(), loadActiveTab);
    }
}
Ejemplo n.º 6
0
bool Tab::operator==(const Tab &other) const
{
    return (m_tabId == other.tabId() &&
            m_previousLinkId == other.m_previousLinkId &&
            m_nextLinkId == other.m_nextLinkId &&
            m_currentLink == other.m_currentLink);
}
void DeclarativeTabModel::updateActiveTab(const Tab &activeTab)
{
#ifdef DEBUG_LOGS
    qDebug() << "old active tab: " << &m_activeTab << m_tabs.count();
    qDebug() << "new active tab: " << &activeTab;
#endif
    if (m_activeTab != activeTab) {
        int oldTabId = m_activeTab.tabId();
        m_activeTab = activeTab;
        emit activeTabChanged(oldTabId, activeTab.tabId());
        saveTabOrder();
    }
}
void DeclarativeTabModel::updateActiveTab(const Tab &newActiveTab, bool updateCurrentTab)
{
#ifdef DEBUG_LOGS
    qDebug() << "change tab: " << updateCurrentTab << m_currentTab;
    qDebug() << "old active tab: " << m_activeTab.tabId() << m_activeTab.isValid() << m_activeTab.currentLink().url() << m_tabs.count();
    qDebug() << "new active tab: " << newActiveTab.tabId() << newActiveTab.isValid() << newActiveTab.currentLink().url();
#endif
    m_activeTab = newActiveTab;
    emit currentTabIdChanged();

    saveTabOrder();
    if (updateCurrentTab && m_currentTab) {
        m_currentTab->tabChanged(m_activeTab);
    }
}
void DeclarativeTabModel::removeTab(const Tab &tab, int index)
{
#ifdef DEBUG_LOGS
    qDebug() << "index:" << index << tab.currentLink().url();
#endif
    int tabId = tab.tabId();
    DBManager::instance()->removeTab(tabId);

    QFile f(tab.currentLink().thumbPath());
    if (f.exists()) {
        f.remove();
    }

    if (index >= 0) {
        m_tabs.removeAt(index);
    }
}