void TransfersContentsWidget::showContextMenu(const QPoint &point) { TransferInformation *transfer = getTransfer(m_ui->transfersView->indexAt(point)); QMenu menu(this); if (transfer) { menu.addAction(tr("Open"), this, SLOT(openTransfer())); menu.addAction(tr("Open Folder"), this, SLOT(openTransferFolder())); menu.addSeparator(); menu.addAction(((transfer->state == ErrorTransfer) ? tr("Resume") : tr("Stop")), this, SLOT(stopResumeTransfer()))->setEnabled(transfer->state == RunningTransfer || transfer->state == ErrorTransfer); menu.addAction("Redownload", this, SLOT(redownloadTransfer())); menu.addSeparator(); menu.addAction(tr("Copy Transfer Information"), this, SLOT(copyTransferInformation())); menu.addSeparator(); menu.addAction(tr("Remove"), this, SLOT(removeTransfer())); } const QList<TransferInformation*> transfers = TransfersManager::getTransfers(); int finishedTransfers = 0; for (int i = 0; i < transfers.count(); ++i) { if (transfers.at(i)->state == FinishedTransfer) { ++finishedTransfers; } } menu.addAction(tr("Clear Finished Transfers"), this, SLOT(clearFinishedTransfers()))->setEnabled(finishedTransfers > 0); menu.exec(m_ui->transfersView->mapToGlobal(point)); }
void TransfersContentsWidget::showContextMenu(const QPoint &point) { Transfer *transfer = getTransfer(m_ui->transfersViewWidget->indexAt(point)); QMenu menu(this); if (transfer) { menu.addAction(tr("Open"), this, SLOT(openTransfer())); const QList<ApplicationInformation> applications = Utils::getApplicationsForMimeType(transfer->getMimeType()); if (applications.count() > 1) { QMenu *applicationsMenu = menu.addMenu(tr("Open With")); for (int i = 0; i < applications.count(); ++i) { applicationsMenu->addAction(applications.at(i).icon, ((applications.at(i).name.isEmpty()) ? tr("Unknown") : applications.at(i).name))->setData(applications.at(i).command); if (i == 0) { applicationsMenu->addSeparator(); } } connect(applicationsMenu, SIGNAL(triggered(QAction*)), this, SLOT(openTransfer(QAction*))); } menu.addAction(tr("Open Folder"), this, SLOT(openTransferFolder())); menu.addSeparator(); menu.addAction(((transfer->getState() == Transfer::ErrorState) ? tr("Resume") : tr("Stop")), this, SLOT(stopResumeTransfer()))->setEnabled(transfer->getState() == Transfer::RunningState || transfer->getState() == Transfer::ErrorState); menu.addAction(tr("Redownload"), this, SLOT(redownloadTransfer())); menu.addSeparator(); menu.addAction(tr("Copy Transfer Information"), this, SLOT(copyTransferInformation())); menu.addSeparator(); menu.addAction(tr("Remove"), this, SLOT(removeTransfer())); }
TransfersView::TransfersView(QWidget *parent) : QWidget(parent), m_model(new TransferModel(this)), m_transferMenu(new QMenu(tr("&Transfer"), this)), m_categoryMenu(new QMenu(tr("&Category"), this)), m_priorityMenu(new QMenu(tr("&Priority"), this)), m_propertiesMenu(new QMenu(tr("&Properties"), this)), m_concurrentMenu(new QMenu(tr("Maximum &concurrent transfers"), this)), m_categoryGroup(new QActionGroup(this)), m_priorityGroup(new QActionGroup(this)), m_concurrentGroup(new QActionGroup(this)), m_startAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Start all downloads"), this)), m_pauseAction(new QAction(QIcon::fromTheme("media-playback-pause"), tr("&Pause all downloads"), this)), m_propertiesAction(new QAction(QIcon::fromTheme("document-properties"), tr("&Properties"), this)), m_transferCommandAction(new QAction(QIcon::fromTheme("system-run"), tr("Set &custom command"), this)), m_transferStartAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Start"), this)), m_transferPauseAction(new QAction(QIcon::fromTheme("media-playback-pause"), tr("&Pause"), this)), m_transferRemoveAction(new QAction(QIcon::fromTheme("edit-delete"), tr("&Remove"), this)), m_toolBar(new QToolBar(this)), m_view(new QTreeView(this)), m_layout(new QVBoxLayout(this)) { m_transferMenu->addAction(m_transferCommandAction); m_transferMenu->addAction(m_transferStartAction); m_transferMenu->addAction(m_transferPauseAction); m_transferMenu->addMenu(m_categoryMenu); m_transferMenu->addMenu(m_priorityMenu); m_transferMenu->addAction(m_transferRemoveAction); m_transferMenu->setEnabled(false); setCategoryMenuActions(); const QStringList priorities = QStringList() << tr("High") << tr("Normal") << tr("Low"); for (int i = 0; i < priorities.size(); i++) { QAction *action = m_priorityMenu->addAction(priorities.at(i), this, SLOT(setTransferPriority())); action->setCheckable(true); action->setData(i); m_priorityGroup->addAction(action); } const int max = Settings::maximumConcurrentTransfers(); for (int i = 1; i <= MAX_CONCURRENT_TRANSFERS; i++) { QAction *action = m_concurrentMenu->addAction(QString::number(i), this, SLOT(setMaximumConcurrentTransfers())); action->setCheckable(true); action->setChecked(i == max); action->setData(i); m_concurrentGroup->addAction(action); } m_propertiesMenu->addMenu(m_concurrentMenu); m_toolBar->setMovable(false); m_toolBar->addAction(m_startAction); m_toolBar->addAction(m_pauseAction); m_toolBar->addAction(m_propertiesAction); m_view->setModel(m_model); m_view->setItemDelegate(new TransferDelegate(m_view)); m_view->setAlternatingRowColors(true); m_view->setSelectionBehavior(QTreeView::SelectRows); m_view->setContextMenuPolicy(Qt::CustomContextMenu); m_view->setEditTriggers(QTreeView::NoEditTriggers); m_view->setItemsExpandable(false); m_view->setUniformRowHeights(true); m_view->setAllColumnsShowFocus(true); m_view->setRootIsDecorated(false); m_view->header()->restoreState(Settings::transfersHeaderViewState()); m_layout->addWidget(m_toolBar); m_layout->addWidget(m_view); m_layout->setContentsMargins(0, 0, 0, 0); connect(m_categoryMenu, SIGNAL(aboutToShow()), this, SLOT(setActiveCategoryMenuAction())); connect(m_priorityMenu, SIGNAL(aboutToShow()), this, SLOT(setActivePriorityMenuAction())); connect(m_startAction, SIGNAL(triggered()), Transfers::instance(), SLOT(start())); connect(m_pauseAction, SIGNAL(triggered()), Transfers::instance(), SLOT(pause())); connect(m_propertiesAction, SIGNAL(triggered()), this, SLOT(showPropertiesMenu())); connect(m_transferCommandAction, SIGNAL(triggered()), this, SLOT(setTransferCustomCommand())); connect(m_transferStartAction, SIGNAL(triggered()), this, SLOT(queueTransfer())); connect(m_transferPauseAction, SIGNAL(triggered()), this, SLOT(pauseTransfer())); connect(m_transferRemoveAction, SIGNAL(triggered()), this, SLOT(removeTransfer())); connect(m_view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); connect(m_view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(onCurrentTransferChanged(QModelIndex))); connect(Settings::instance(), SIGNAL(categoriesChanged()), this, SLOT(setCategoryMenuActions())); connect(Settings::instance(), SIGNAL(maximumConcurrentTransfersChanged(int)), this, SLOT(onMaximumConcurrentTransfersChanged(int))); }
void TransfersView::removeTransfer() { if (m_view->currentIndex().isValid()) { removeTransfer(m_view->currentIndex()); } }