bool DeclarativeTabModel::activateTab(const int &index)
{
    if (index >= 0 && index < m_tabs.count()) {
        Tab newActiveTab = m_tabs.at(index);
#ifdef DEBUG_LOGS
        qDebug() << "active tab: " << index << newActiveTab.currentLink().url();
#endif
        beginRemoveRows(QModelIndex(), index, index);
        m_tabs.removeAt(index);
        endRemoveRows();

        // Current active tab back to model data.
        if (m_activeTab.isValid()) {
#ifdef DEBUG_LOGS
            qDebug() << "insert to first index: " << m_activeTab.currentLink().url() << m_activeTab.currentLink().title() << m_activeTab.currentLink().thumbPath();
#endif
            beginInsertRows(QModelIndex(), 0, 0);
            m_tabs.insert(0, m_activeTab);
            endInsertRows();
        }

        updateActiveTab(newActiveTab);
        return true;
    }
    return false;
}
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);
    }
}
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);
        }
    }
}
Ejemplo n.º 4
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()));
    }
}
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);
    }
}