Esempio n. 1
0
void
MainWindow::showEditMonitoredComponents()
{
    MonitorDialog d;
    QMap<QString, QString> componentMap;
    // First get the list of monitored components for each tracker, so
    // we can compare later.
    QMapIterator<QString, Backend *> i(mBackendMap);
    while (i.hasNext())
    {
        i.next();
        componentMap[i.key()] = SqlUtilities::getMonitoredComponents(i.key());
    }

    // When the user modifies the monitored components,
    // we want to update the affected trackers, and then
    // we need to set the last sync time to 1970 in order
    // to fetch the appropriate components.
    if (d.exec() == QDialog::Accepted)
    {
        i.toFront();
        while (i.hasNext())
        {
            i.next();
            QString components =  SqlUtilities::getMonitoredComponents(i.key());
            qDebug() << "Components for " << i.key() << " are now " << components;

            if (componentMap[i.key()] != components)
            {
                Backend *b = i.value();
                // Remove all of the bugs for this tracker, and resync
                SqlUtilities::clearBugs(b->type(), i.key());
                if (components.isEmpty())
                    b->setMonitorComponents(QStringList());
                else
                    b->setMonitorComponents(components.split(","));
                b->setLastSync("1970-01-01T12:13:14");
                mSyncPosition = mBackendList.size();
                syncTracker(b);
            }
        }
    }
}
Esempio n. 2
0
// Called from the tracker tab to display the context menu
void
MainWindow::showMenu(int tabIndex)
{
    QMenu contextMenu(tr("Context menu"), this);
    QAction *a;
    // Show a different context menu for the search tab
    int searchIndex = ui->trackerTab->indexOf(pSearchTab);
    if (tabIndex == searchIndex)
    {
        QAction *searchAction = contextMenu.addAction(tr("Clear Results"));
        a = contextMenu.exec(QCursor::pos());
        if (a == searchAction)
        {
            SqlUtilities::clearSearch();
            QSettings settings("Entomologist");
            settings.setValue("last-search-query", "");
            pSearchTab->refreshResults();
        }
        return;
    }

    QString trackerName = ui->trackerTab->tabText(tabIndex);
    Backend *b = NULL;
    for (int i = 0; i < mBackendList.size(); ++i)
    {
        b = mBackendList.at(i);
        if (trackerName == b->name())
            break;
    }

    if (b == NULL)
        return;

    QString id = b->id();
    QAction *editAction = contextMenu.addAction(tr("Edit"));
    QAction *deleteAction = contextMenu.addAction(tr("Delete"));
    QAction *resyncAction = contextMenu.addAction(tr("Resync"));
    a = contextMenu.exec(QCursor::pos());
    if (a == editAction)
    {
        NewTracker t(this, true);
        QString tmpName = b->name();
        t.setName(b->name());
        t.setHost(b->url());
        t.setUsername(b->username());
        t.setPassword(b->password());
        t.setTrackerType(b->type());
        if (t.exec() == QDialog::Accepted)
        {
            bool updateName = false;
            if (t.data().value("name") != tmpName)
                updateName = true;
            updateTracker(id, t.data(), updateName);
        }
    }
    else if (a == deleteAction)
    {
        QMessageBox box;
        box.setText(QString("Are you sure you want to delete %1?").arg(b->name()));
        box.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
        if (box.exec() == QMessageBox::Yes)
        {
            deleteTracker(id);
        }
    }
    else if (a == resyncAction)
    {
        mSyncPosition = mBackendList.size();
        syncTracker(b);
    }
}