diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index 391d85fbf..e28d39f03 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -91,6 +91,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&))); connect(filesList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openDoubleClickedFile(QModelIndex))); connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); + connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&))); connect(addWS_button, SIGNAL(clicked()), this, SLOT(askWebSeed())); connect(deleteWS_button, SIGNAL(clicked()), this, SLOT(deleteSelectedUrlSeeds())); connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle)), this, SLOT(loadTorrentInfos(QTorrentHandle))); @@ -503,6 +504,34 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) { } } +void PropertiesWidget::displayWebSeedListMenu(const QPoint&) { + QMenu seedMenu; + QModelIndexList rows = listWebSeeds->selectionModel()->selectedRows(); + QAction *actAdd = seedMenu.addAction(IconProvider::instance()->getIcon("list-add"), tr("New Web seed")); + QAction *actDel = 0; + QAction *actCpy = 0; + QAction *actEdit = 0; + + if (rows.size()) { + actDel = seedMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove Web seed")); + seedMenu.addSeparator(); + actCpy = seedMenu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy Web seed URL")); + actEdit = seedMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Edit Web seed URL")); + } + + const QAction *act = seedMenu.exec(QCursor::pos()); + if (act) { + if (act == actAdd) + askWebSeed(); + else if (act == actDel) + deleteSelectedUrlSeeds(); + else if (act == actCpy) + copySelectedWebSeedsToClipboard(); + else if (act == actEdit) + editWebSeed(); + } +} + void PropertiesWidget::renameSelectedFile() { const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); Q_ASSERT(selectedIndexes.size() == 1); @@ -633,7 +662,8 @@ void PropertiesWidget::askWebSeed() { QMessageBox::Ok); return; } - h.add_url_seed(url_seed); + if (h.is_valid()) + h.add_url_seed(url_seed); // Refresh the seeds list loadUrlSeeds(); } @@ -643,8 +673,10 @@ void PropertiesWidget::deleteSelectedUrlSeeds() { bool change = false; foreach (const QListWidgetItem *item, selectedItems) { QString url_seed = item->text(); - h.remove_url_seed(url_seed); - change = true; + try { + h.remove_url_seed(url_seed); + change = true; + } catch (invalid_handle&) {} } if (change) { // Refresh list @@ -652,6 +684,46 @@ void PropertiesWidget::deleteSelectedUrlSeeds() { } } +void PropertiesWidget::copySelectedWebSeedsToClipboard() const { + const QList selected_items = listWebSeeds->selectedItems(); + if (selected_items.isEmpty()) + return; + + QStringList urls_to_copy; + foreach (QListWidgetItem *item, selected_items) + urls_to_copy << item->text(); + + QApplication::clipboard()->setText(urls_to_copy.join("\n")); +} + +void PropertiesWidget::editWebSeed() { + const QList selected_items = listWebSeeds->selectedItems(); + if (selected_items.isEmpty()) + return; + + const QListWidgetItem *selected_item = selected_items.last(); + const QString old_seed = selected_item->text(); + bool result; + const QString new_seed = QInputDialog::getText(this, tr("Web seed editing"), + tr("Web seed URL:"), QLineEdit::Normal, + old_seed, &result); + if (!result) + return; + + if (!listWebSeeds->findItems(new_seed, Qt::MatchFixedString).empty()) { + QMessageBox::warning(this, tr("qBittorrent"), + tr("This url seed is already in the list."), + QMessageBox::Ok); + return; + } + + try { + h.remove_url_seed(old_seed); + h.add_url_seed(new_seed); + loadUrlSeeds(); + } catch (invalid_handle&) {} +} + bool PropertiesWidget::applyPriorities() { qDebug("Saving files priorities"); const std::vector priorities = PropListModel->model()->getFilesPriorities(); diff --git a/src/properties/propertieswidget.h b/src/properties/propertieswidget.h index c3942b307..5ba610b6e 100644 --- a/src/properties/propertieswidget.h +++ b/src/properties/propertieswidget.h @@ -78,7 +78,10 @@ protected slots: void loadUrlSeeds(); void askWebSeed(); void deleteSelectedUrlSeeds(); + void copySelectedWebSeedsToClipboard() const; + void editWebSeed(); void displayFilesListMenu(const QPoint& pos); + void displayWebSeedListMenu(const QPoint& pos); void filteredFilesChanged(); void showPiecesDownloaded(bool show); void showPiecesAvailability(bool show); diff --git a/src/properties/propertieswidget.ui b/src/properties/propertieswidget.ui index edee14d0a..223bacd5b 100644 --- a/src/properties/propertieswidget.ui +++ b/src/properties/propertieswidget.ui @@ -641,7 +641,14 @@ - + + + Qt::CustomContextMenu + + + QAbstractItemView::ExtendedSelection + +