Esempio n. 1
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);
    }
}