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