Changeset 14566


Ignore:
Timestamp:
Oct 4, 2015, 6:16:59 AM (5 years ago)
Author:
mikedld
Message:

#5993: Improve magnets handling in main window

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.

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/MainWindow.cc

    r14563 r14566  
    570570MainWindow::openFolder ()
    571571{
    572   const int torrentId (*getSelectedTorrents ().begin ());
     572  const QSet<int> selectedTorrents = getSelectedTorrents ();
     573  if (selectedTorrents.size () != 1)
     574    return;
     575
     576  const int torrentId (*selectedTorrents.begin ());
    573577  const Torrent * tor (myModel.getTorrentFromId (torrentId));
     578  if (tor == nullptr)
     579    return;
     580
    574581  QString path (tor->getPath ());
    575   const FileList files = tor->files ();
     582  const FileList& files = tor->files ();
     583  if (files.isEmpty ())
     584    return;
     585
    576586  const QString firstfile = files.at (0).filename;
    577587  int slashIndex = firstfile.indexOf (QLatin1Char ('/'));
     
    587597    }
    588598#endif
     599
    589600  QDesktopServices::openUrl (QUrl::fromLocalFile (path));
    590601}
     
    735746  int selectedAndPaused (0);
    736747  int selectedAndQueued (0);
     748  int selectedWithMetadata (0);
    737749  int canAnnounce (0);
    738750  const QAbstractItemModel * model (ui.listView->model ());
     
    756768          if (isSelected && isPaused) ++selectedAndPaused;
    757769          if (isSelected && isQueued) ++selectedAndQueued;
     770          if (isSelected && tor->hasMetadata ()) ++selectedWithMetadata;
    758771          if (tor->canManualAnnounce ()) ++canAnnounce;
    759772        }
     
    761774
    762775  const bool haveSelection (selected > 0);
    763   ui.action_Verify->setEnabled (haveSelection);
     776  const bool haveSelectionWithMetadata = selectedWithMetadata > 0;
     777  const bool oneSelection (selected == 1);
     778
     779  ui.action_Verify->setEnabled (haveSelectionWithMetadata);
    764780  ui.action_Remove->setEnabled (haveSelection);
    765781  ui.action_Delete->setEnabled (haveSelection);
     
    768784  ui.action_SetLocation->setEnabled (haveSelection);
    769785
    770   const bool oneSelection (selected == 1);
    771   ui.action_OpenFolder->setEnabled (oneSelection && mySession.isLocal ());
     786  ui.action_OpenFolder->setEnabled (oneSelection && haveSelectionWithMetadata && mySession.isLocal ());
    772787  ui.action_CopyMagnetToClipboard->setEnabled (oneSelection);
    773788
     
    800815
    801816QSet<int>
    802 MainWindow::getSelectedTorrents () const
     817MainWindow::getSelectedTorrents (bool withMetadataOnly) const
    803818{
    804819  QSet<int> ids;
     
    807822    {
    808823      const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ());
    809       ids.insert (tor->id ());
     824      if (tor != nullptr && (!withMetadataOnly || tor->hasMetadata ()))
     825        ids.insert (tor->id ());
    810826    }
    811827
     
    871887MainWindow::verifySelected ()
    872888{
    873   mySession.verifyTorrents (getSelectedTorrents ());
     889  mySession.verifyTorrents (getSelectedTorrents (true));
    874890}
    875891void
  • trunk/qt/MainWindow.h

    r14556 r14566  
    8989    QIcon getStockIcon (const QString&, int fallback = -1);
    9090
    91     QSet<int> getSelectedTorrents () const;
     91    QSet<int> getSelectedTorrents (bool withMetadataOnly = false) const;
    9292    void updateNetworkIcon ();
    9393
Note: See TracChangeset for help on using the changeset viewer.