]> granicus.if.org Git - transmission/commitdiff
#5993: Improve magnets handling in main window
authorMike Gelfand <mikedld@mikedld.com>
Sun, 4 Oct 2015 06:16:59 +0000 (06:16 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sun, 4 Oct 2015 06:16:59 +0000 (06:16 +0000)
Disable "Open Folder" and "Verify Local Data" actions for magnets in
Torrent menu. If more than one torrent is selected, "Verify Local Data"
is enabled but only non-magnets are verified if activated.
Add a few sanity checks when opening folder, just in case.

qt/MainWindow.cc
qt/MainWindow.h

index 86e22669c33894e18f0276374181e183a06a0f22..6d0be0ffbc026eb5dffc9b2c14eb5b239193f49f 100644 (file)
@@ -569,10 +569,20 @@ void openSelect (const QString& path)
 void
 MainWindow::openFolder ()
 {
-  const int torrentId (*getSelectedTorrents ().begin ());
+  const QSet<int> selectedTorrents = getSelectedTorrents ();
+  if (selectedTorrents.size () != 1)
+    return;
+
+  const int torrentId (*selectedTorrents.begin ());
   const Torrent * tor (myModel.getTorrentFromId (torrentId));
+  if (tor == nullptr)
+    return;
+
   QString path (tor->getPath ());
-  const FileList files = tor->files ();
+  const FileList& files = tor->files ();
+  if (files.isEmpty ())
+    return;
+
   const QString firstfile = files.at (0).filename;
   int slashIndex = firstfile.indexOf (QLatin1Char ('/'));
   if (slashIndex > -1)
@@ -586,6 +596,7 @@ MainWindow::openFolder ()
       return;
     }
 #endif
+
   QDesktopServices::openUrl (QUrl::fromLocalFile (path));
 }
 
@@ -734,6 +745,7 @@ MainWindow::refreshActionSensitivity ()
   int queued (0);
   int selectedAndPaused (0);
   int selectedAndQueued (0);
+  int selectedWithMetadata (0);
   int canAnnounce (0);
   const QAbstractItemModel * model (ui.listView->model ());
   const QItemSelectionModel * selectionModel (ui.listView->selectionModel ());
@@ -755,20 +767,23 @@ MainWindow::refreshActionSensitivity ()
           if (isPaused) ++ paused;
           if (isSelected && isPaused) ++selectedAndPaused;
           if (isSelected && isQueued) ++selectedAndQueued;
+          if (isSelected && tor->hasMetadata ()) ++selectedWithMetadata;
           if (tor->canManualAnnounce ()) ++canAnnounce;
         }
     }
 
   const bool haveSelection (selected > 0);
-  ui.action_Verify->setEnabled (haveSelection);
+  const bool haveSelectionWithMetadata = selectedWithMetadata > 0;
+  const bool oneSelection (selected == 1);
+
+  ui.action_Verify->setEnabled (haveSelectionWithMetadata);
   ui.action_Remove->setEnabled (haveSelection);
   ui.action_Delete->setEnabled (haveSelection);
   ui.action_Properties->setEnabled (haveSelection);
   ui.action_DeselectAll->setEnabled (haveSelection);
   ui.action_SetLocation->setEnabled (haveSelection);
 
-  const bool oneSelection (selected == 1);
-  ui.action_OpenFolder->setEnabled (oneSelection && mySession.isLocal ());
+  ui.action_OpenFolder->setEnabled (oneSelection && haveSelectionWithMetadata && mySession.isLocal ());
   ui.action_CopyMagnetToClipboard->setEnabled (oneSelection);
 
   ui.action_SelectAll->setEnabled (selected < rowCount);
@@ -799,14 +814,15 @@ MainWindow::clearSelection ()
 }
 
 QSet<int>
-MainWindow::getSelectedTorrents () const
+MainWindow::getSelectedTorrents (bool withMetadataOnly) const
 {
   QSet<int> ids;
 
   for (const QModelIndex& index: ui.listView->selectionModel ()->selectedRows ())
     {
       const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ());
-      ids.insert (tor->id ());
+      if (tor != nullptr && (!withMetadataOnly || tor->hasMetadata ()))
+        ids.insert (tor->id ());
     }
 
   return ids;
@@ -870,7 +886,7 @@ MainWindow::deleteSelected ()
 void
 MainWindow::verifySelected ()
 {
-  mySession.verifyTorrents (getSelectedTorrents ());
+  mySession.verifyTorrents (getSelectedTorrents (true));
 }
 void
 MainWindow::reannounceSelected ()
index c378e60a62b2798b40f97dbc259497423299ff7b..b9e6217ba785e1876286102dc88ad2f05a010737 100644 (file)
@@ -88,7 +88,7 @@ class MainWindow: public QMainWindow
   private:
     QIcon getStockIcon (const QString&, int fallback = -1);
 
-    QSet<int> getSelectedTorrents () const;
+    QSet<int> getSelectedTorrents (bool withMetadataOnly = false) const;
     void updateNetworkIcon ();
 
     QMenu * createOptionsMenu ();