2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
#include <array>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <cassert>
|
2020-06-23 17:16:07 +00:00
|
|
|
#include <functional>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <memory>
|
2020-06-05 19:02:11 +00:00
|
|
|
#include <utility>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:50:25 +00:00
|
|
|
#include <QCheckBox>
|
2019-11-12 01:37:05 +00:00
|
|
|
#include <QFileDialog>
|
2014-12-12 21:47:22 +00:00
|
|
|
#include <QIcon>
|
2013-07-27 21:58:14 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMessageBox>
|
2019-11-12 01:37:05 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QProxyStyle>
|
|
|
|
#include <QtGui>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2009-12-12 15:38:14 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2009-04-13 19:04:21 +00:00
|
|
|
#include <libtransmission/version.h>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "AboutDialog.h"
|
|
|
|
#include "AddData.h"
|
|
|
|
#include "Application.h"
|
|
|
|
#include "DetailsDialog.h"
|
|
|
|
#include "FilterBar.h"
|
|
|
|
#include "Filters.h"
|
|
|
|
#include "Formatter.h"
|
2021-12-09 08:13:04 +00:00
|
|
|
#include "IconCache.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "MakeDialog.h"
|
|
|
|
#include "OptionsDialog.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "RelocateDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "SessionDialog.h"
|
|
|
|
#include "Speed.h"
|
|
|
|
#include "StatsDialog.h"
|
|
|
|
#include "TorrentDelegate.h"
|
|
|
|
#include "TorrentDelegateMin.h"
|
|
|
|
#include "TorrentFilter.h"
|
|
|
|
#include "TorrentModel.h"
|
2015-07-30 06:18:02 +00:00
|
|
|
#include "Utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-11-02 01:13:32 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
char const* const PrefVariantsKey = "submenu";
|
|
|
|
char const* const StatsModeKey = "stats-mode";
|
|
|
|
char const* const SortModeKey = "sort-mode";
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
} // namespace
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2012-08-18 15:39:11 +00:00
|
|
|
/**
|
|
|
|
* This is a proxy-style for that forces it to be always disabled.
|
|
|
|
* We use this to make our torrent list view behave consistently on
|
|
|
|
* both GTK and Qt implementations.
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
class ListViewProxyStyle : public QProxyStyle
|
2012-08-18 15:39:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2021-08-15 09:41:48 +00:00
|
|
|
int styleHint(
|
|
|
|
StyleHint hint,
|
|
|
|
QStyleOption const* option = nullptr,
|
|
|
|
QWidget const* widget = nullptr,
|
2020-05-27 21:53:12 +00:00
|
|
|
QStyleHintReturn* return_data = nullptr) const override
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
return QProxyStyle::styleHint(hint, option, widget, return_data);
|
2013-01-27 18:09:49 +00:00
|
|
|
}
|
2012-08-18 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
QIcon MainWindow::addEmblem(QIcon base_icon, QStringList const& emblem_names) const
|
2017-02-18 18:22:34 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (base_icon.isNull())
|
2017-02-18 18:22:34 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return base_icon;
|
2017-02-18 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
auto& icons = IconCache::get();
|
2020-05-27 21:53:12 +00:00
|
|
|
QIcon emblem_icon;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QString const& emblem_name : emblem_names)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-12-09 08:13:04 +00:00
|
|
|
emblem_icon = icons.getThemeIcon(emblem_name);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!emblem_icon.isNull())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (emblem_icon.isNull())
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return base_icon;
|
2015-08-06 20:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QIcon icon;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QSize const& size : base_icon.availableSizes())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QSize const emblem_size = size / 2;
|
2021-08-15 09:41:48 +00:00
|
|
|
QRect const emblem_rect = QStyle::alignedRect(
|
|
|
|
layoutDirection(),
|
|
|
|
Qt::AlignBottom | Qt::AlignRight,
|
|
|
|
emblem_size,
|
2017-04-19 12:04:45 +00:00
|
|
|
QRect(QPoint(0, 0), size));
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QPixmap pixmap = base_icon.pixmap(size);
|
|
|
|
QPixmap emblem_pixmap = emblem_icon.pixmap(emblem_size);
|
2020-11-09 03:31:02 +00:00
|
|
|
QPainter(&pixmap).drawPixmap(emblem_rect, emblem_pixmap, emblem_pixmap.rect());
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
icon.addPixmap(pixmap);
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool minimized)
|
|
|
|
: session_(session)
|
|
|
|
, prefs_(prefs)
|
|
|
|
, model_(model)
|
|
|
|
, lvp_style_(std::make_shared<ListViewProxyStyle>())
|
|
|
|
, filter_model_(prefs)
|
|
|
|
, torrent_delegate_(new TorrentDelegate(this))
|
|
|
|
, torrent_delegate_min_(new TorrentDelegateMin(this))
|
|
|
|
, network_timer_(this)
|
|
|
|
, refresh_timer_(this)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* sep = new QAction(this);
|
2017-04-19 12:04:45 +00:00
|
|
|
sep->setSeparator(true);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-07-29 23:21:11 +00:00
|
|
|
ui_.listView->setStyle(lvp_style_.get());
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.listView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
auto& icons = IconCache::get();
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// icons
|
2021-12-09 08:13:04 +00:00
|
|
|
QIcon const icon_play = icons.getThemeIcon(QStringLiteral("media-playback-start"), QStyle::SP_MediaPlay);
|
|
|
|
QIcon const icon_pause = icons.getThemeIcon(QStringLiteral("media-playback-pause"), QStyle::SP_MediaPause);
|
|
|
|
QIcon const icon_open = icons.getThemeIcon(QStringLiteral("document-open"), QStyle::SP_DialogOpenButton);
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_OpenFile->setIcon(icon_open);
|
2021-08-15 09:41:48 +00:00
|
|
|
ui_.action_AddURL->setIcon(
|
|
|
|
addEmblem(icon_open, QStringList() << QStringLiteral("emblem-web") << QStringLiteral("applications-internet")));
|
2021-12-09 08:13:04 +00:00
|
|
|
ui_.action_New->setIcon(icons.getThemeIcon(QStringLiteral("document-new"), QStyle::SP_DesktopIcon));
|
|
|
|
ui_.action_Properties->setIcon(icons.getThemeIcon(QStringLiteral("document-properties"), QStyle::SP_DesktopIcon));
|
|
|
|
ui_.action_OpenFolder->setIcon(icons.getThemeIcon(QStringLiteral("folder-open"), QStyle::SP_DirOpenIcon));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_Start->setIcon(icon_play);
|
|
|
|
ui_.action_StartNow->setIcon(icon_play);
|
2021-12-09 08:13:04 +00:00
|
|
|
ui_.action_Announce->setIcon(icons.getThemeIcon(QStringLiteral("network-transmit-receive")));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_Pause->setIcon(icon_pause);
|
2021-12-09 08:13:04 +00:00
|
|
|
ui_.action_Remove->setIcon(icons.getThemeIcon(QStringLiteral("list-remove"), QStyle::SP_TrashIcon));
|
|
|
|
ui_.action_Delete->setIcon(icons.getThemeIcon(QStringLiteral("edit-delete"), QStyle::SP_TrashIcon));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_StartAll->setIcon(icon_play);
|
|
|
|
ui_.action_PauseAll->setIcon(icon_pause);
|
2021-12-09 08:13:04 +00:00
|
|
|
ui_.action_Quit->setIcon(icons.getThemeIcon(QStringLiteral("application-exit")));
|
|
|
|
ui_.action_SelectAll->setIcon(icons.getThemeIcon(QStringLiteral("edit-select-all")));
|
|
|
|
ui_.action_ReverseSortOrder->setIcon(icons.getThemeIcon(QStringLiteral("view-sort-ascending"), QStyle::SP_ArrowDown));
|
|
|
|
ui_.action_Preferences->setIcon(icons.getThemeIcon(QStringLiteral("preferences-system")));
|
|
|
|
ui_.action_Contents->setIcon(icons.getThemeIcon(QStringLiteral("help-contents"), QStyle::SP_DialogHelpButton));
|
|
|
|
ui_.action_About->setIcon(icons.getThemeIcon(QStringLiteral("help-about")));
|
|
|
|
ui_.action_QueueMoveTop->setIcon(icons.getThemeIcon(QStringLiteral("go-top")));
|
|
|
|
ui_.action_QueueMoveUp->setIcon(icons.getThemeIcon(QStringLiteral("go-up"), QStyle::SP_ArrowUp));
|
|
|
|
ui_.action_QueueMoveDown->setIcon(icons.getThemeIcon(QStringLiteral("go-down"), QStyle::SP_ArrowDown));
|
|
|
|
ui_.action_QueueMoveBottom->setIcon(icons.getThemeIcon(QStringLiteral("go-bottom")));
|
|
|
|
|
2021-12-09 22:28:37 +00:00
|
|
|
auto make_network_pixmap = [&icons](QString name, QSize size = { 16, 16 })
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-09 08:13:04 +00:00
|
|
|
return icons.getThemeIcon(name, QStyle::SP_DriveNetIcon).pixmap(size);
|
2021-08-15 09:41:48 +00:00
|
|
|
};
|
2020-06-05 19:02:11 +00:00
|
|
|
pixmap_network_error_ = make_network_pixmap(QStringLiteral("network-error"));
|
|
|
|
pixmap_network_idle_ = make_network_pixmap(QStringLiteral("network-idle"));
|
|
|
|
pixmap_network_receive_ = make_network_pixmap(QStringLiteral("network-receive"));
|
|
|
|
pixmap_network_transmit_ = make_network_pixmap(QStringLiteral("network-transmit"));
|
|
|
|
pixmap_network_transmit_receive_ = make_network_pixmap(QStringLiteral("network-transmit-receive"));
|
2019-11-06 21:09:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// ui signals
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.action_Toolbar, &QAction::toggled, this, &MainWindow::setToolbarVisible);
|
|
|
|
connect(ui_.action_Filterbar, &QAction::toggled, this, &MainWindow::setFilterbarVisible);
|
|
|
|
connect(ui_.action_Statusbar, &QAction::toggled, this, &MainWindow::setStatusbarVisible);
|
|
|
|
connect(ui_.action_CompactView, &QAction::toggled, this, &MainWindow::setCompactView);
|
|
|
|
connect(ui_.action_ReverseSortOrder, &QAction::toggled, this, &MainWindow::setSortAscendingPref);
|
|
|
|
connect(ui_.action_Start, &QAction::triggered, this, &MainWindow::startSelected);
|
|
|
|
connect(ui_.action_QueueMoveTop, &QAction::triggered, this, &MainWindow::queueMoveTop);
|
|
|
|
connect(ui_.action_QueueMoveUp, &QAction::triggered, this, &MainWindow::queueMoveUp);
|
|
|
|
connect(ui_.action_QueueMoveDown, &QAction::triggered, this, &MainWindow::queueMoveDown);
|
|
|
|
connect(ui_.action_QueueMoveBottom, &QAction::triggered, this, &MainWindow::queueMoveBottom);
|
|
|
|
connect(ui_.action_StartNow, &QAction::triggered, this, &MainWindow::startSelectedNow);
|
|
|
|
connect(ui_.action_Pause, &QAction::triggered, this, &MainWindow::pauseSelected);
|
|
|
|
connect(ui_.action_Remove, &QAction::triggered, this, &MainWindow::removeSelected);
|
|
|
|
connect(ui_.action_Delete, &QAction::triggered, this, &MainWindow::deleteSelected);
|
|
|
|
connect(ui_.action_Verify, &QAction::triggered, this, &MainWindow::verifySelected);
|
|
|
|
connect(ui_.action_Announce, &QAction::triggered, this, &MainWindow::reannounceSelected);
|
|
|
|
connect(ui_.action_StartAll, &QAction::triggered, this, &MainWindow::startAll);
|
|
|
|
connect(ui_.action_PauseAll, &QAction::triggered, this, &MainWindow::pauseAll);
|
|
|
|
connect(ui_.action_OpenFile, &QAction::triggered, this, &MainWindow::openTorrent);
|
|
|
|
connect(ui_.action_AddURL, &QAction::triggered, this, &MainWindow::openURL);
|
|
|
|
connect(ui_.action_New, &QAction::triggered, this, &MainWindow::newTorrent);
|
|
|
|
connect(ui_.action_Preferences, &QAction::triggered, this, &MainWindow::openPreferences);
|
|
|
|
connect(ui_.action_Statistics, &QAction::triggered, this, &MainWindow::openStats);
|
|
|
|
connect(ui_.action_Donate, &QAction::triggered, this, &MainWindow::openDonate);
|
|
|
|
connect(ui_.action_About, &QAction::triggered, this, &MainWindow::openAbout);
|
|
|
|
connect(ui_.action_Contents, &QAction::triggered, this, &MainWindow::openHelp);
|
|
|
|
connect(ui_.action_OpenFolder, &QAction::triggered, this, &MainWindow::openFolder);
|
|
|
|
connect(ui_.action_CopyMagnetToClipboard, &QAction::triggered, this, &MainWindow::copyMagnetLinkToClipboard);
|
|
|
|
connect(ui_.action_SetLocation, &QAction::triggered, this, &MainWindow::setLocation);
|
|
|
|
connect(ui_.action_Properties, &QAction::triggered, this, &MainWindow::openProperties);
|
|
|
|
connect(ui_.action_SessionDialog, &QAction::triggered, this, &MainWindow::openSession);
|
|
|
|
connect(ui_.listView, &QAbstractItemView::activated, ui_.action_Properties, &QAction::trigger);
|
|
|
|
connect(ui_.action_SelectAll, &QAction::triggered, ui_.listView, &QAbstractItemView::selectAll);
|
|
|
|
connect(ui_.action_DeselectAll, &QAction::triggered, ui_.listView, &QAbstractItemView::clearSelection);
|
|
|
|
connect(ui_.action_Quit, &QAction::triggered, qApp, &QCoreApplication::quit);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
auto refresh_action_sensitivity_soon = [this]()
|
|
|
|
{
|
|
|
|
refreshSoon(REFRESH_ACTION_SENSITIVITY);
|
|
|
|
};
|
2020-06-05 19:02:11 +00:00
|
|
|
connect(&filter_model_, &TorrentFilter::rowsInserted, this, refresh_action_sensitivity_soon);
|
|
|
|
connect(&filter_model_, &TorrentFilter::rowsRemoved, this, refresh_action_sensitivity_soon);
|
|
|
|
connect(&model_, &TorrentModel::torrentsChanged, this, refresh_action_sensitivity_soon);
|
2019-11-09 14:44:40 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// torrent view
|
2020-05-27 21:53:12 +00:00
|
|
|
filter_model_.setSourceModel(&model_);
|
2021-08-15 09:41:48 +00:00
|
|
|
auto refresh_soon_adapter = [this]()
|
|
|
|
{
|
|
|
|
refreshSoon();
|
|
|
|
};
|
2020-06-05 19:02:11 +00:00
|
|
|
connect(&model_, &TorrentModel::modelReset, this, refresh_soon_adapter);
|
|
|
|
connect(&model_, &TorrentModel::rowsRemoved, this, refresh_soon_adapter);
|
|
|
|
connect(&model_, &TorrentModel::rowsInserted, this, refresh_soon_adapter);
|
2020-06-23 21:11:16 +00:00
|
|
|
connect(&model_, &TorrentModel::torrentsChanged, this, refresh_soon_adapter);
|
2020-05-27 21:53:12 +00:00
|
|
|
|
|
|
|
ui_.listView->setModel(&filter_model_);
|
2020-06-05 19:02:11 +00:00
|
|
|
connect(ui_.listView->selectionModel(), &QItemSelectionModel::selectionChanged, refresh_action_sensitivity_soon);
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
std::array<std::pair<QAction*, int>, 9> const sort_modes = { {
|
2020-06-05 19:02:11 +00:00
|
|
|
{ ui_.action_SortByActivity, SortMode::SORT_BY_ACTIVITY },
|
|
|
|
{ ui_.action_SortByAge, SortMode::SORT_BY_AGE },
|
|
|
|
{ ui_.action_SortByETA, SortMode::SORT_BY_ETA },
|
|
|
|
{ ui_.action_SortByName, SortMode::SORT_BY_NAME },
|
|
|
|
{ ui_.action_SortByProgress, SortMode::SORT_BY_PROGRESS },
|
|
|
|
{ ui_.action_SortByQueue, SortMode::SORT_BY_QUEUE },
|
|
|
|
{ ui_.action_SortByRatio, SortMode::SORT_BY_RATIO },
|
|
|
|
{ ui_.action_SortBySize, SortMode::SORT_BY_SIZE },
|
2021-08-15 09:41:48 +00:00
|
|
|
{ ui_.action_SortByState, SortMode::SORT_BY_STATE },
|
|
|
|
} };
|
2020-06-05 19:02:11 +00:00
|
|
|
|
|
|
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2022-01-24 00:53:35 +00:00
|
|
|
for (auto const& [action, mode] : sort_modes)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
action->setProperty(SortModeKey, mode);
|
|
|
|
action_group->addAction(action);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-10-19 20:30:26 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(action_group, &QActionGroup::triggered, this, &MainWindow::onSortModeChanged);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
2020-05-27 21:53:12 +00:00
|
|
|
alt_speed_action_ = new QAction(tr("Speed Limits"), this);
|
|
|
|
alt_speed_action_->setIcon(ui_.altSpeedButton->icon());
|
|
|
|
alt_speed_action_->setCheckable(true);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(alt_speed_action_, &QAction::triggered, this, &MainWindow::toggleSpeedMode);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* menu = new QMenu(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
menu->addAction(ui_.action_OpenFile);
|
|
|
|
menu->addAction(ui_.action_AddURL);
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addSeparator();
|
2020-05-27 21:53:12 +00:00
|
|
|
menu->addAction(ui_.action_ShowMainWindow);
|
|
|
|
menu->addAction(ui_.action_ShowMessageLog);
|
|
|
|
menu->addAction(ui_.action_About);
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addSeparator();
|
2020-05-27 21:53:12 +00:00
|
|
|
menu->addAction(ui_.action_StartAll);
|
|
|
|
menu->addAction(ui_.action_PauseAll);
|
|
|
|
menu->addAction(alt_speed_action_);
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addSeparator();
|
2020-05-27 21:53:12 +00:00
|
|
|
menu->addAction(ui_.action_Quit);
|
|
|
|
tray_icon_.setContextMenu(menu);
|
2020-11-02 01:13:32 +00:00
|
|
|
tray_icon_.setIcon(QIcon::fromTheme(QStringLiteral("transmission-tray-icon"), QApplication::windowIcon()));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&prefs_, &Prefs::changed, this, &MainWindow::refreshPref);
|
|
|
|
connect(ui_.action_ShowMainWindow, &QAction::triggered, this, &MainWindow::toggleWindows);
|
|
|
|
connect(&tray_icon_, &QSystemTrayIcon::activated, this, &MainWindow::trayActivated);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
toggleWindows(!minimized);
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_TrayIcon->setChecked(minimized || prefs.getBool(Prefs::SHOW_TRAY_ICON));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
initStatusBar();
|
2020-10-31 18:56:12 +00:00
|
|
|
auto* filter_bar = new FilterBar(prefs_, model_, filter_model_);
|
|
|
|
ui_.verticalLayout->insertWidget(0, filter_bar);
|
|
|
|
filter_bar_ = filter_bar;
|
2020-05-27 21:53:12 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
auto refresh_header_soon = [this]()
|
|
|
|
{
|
|
|
|
refreshSoon(REFRESH_TORRENT_VIEW_HEADER);
|
|
|
|
};
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&model_, &TorrentModel::rowsInserted, this, refresh_header_soon);
|
|
|
|
connect(&model_, &TorrentModel::rowsRemoved, this, refresh_header_soon);
|
|
|
|
connect(&filter_model_, &TorrentFilter::rowsInserted, this, refresh_header_soon);
|
|
|
|
connect(&filter_model_, &TorrentFilter::rowsRemoved, this, refresh_header_soon);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.listView, &TorrentView::headerDoubleClicked, filter_bar, &FilterBar::clear);
|
2020-05-27 21:53:12 +00:00
|
|
|
|
2022-01-23 15:57:21 +00:00
|
|
|
static std::array<int, 17> constexpr InitKeys = {
|
2021-08-15 09:41:48 +00:00
|
|
|
Prefs::ALT_SPEED_LIMIT_ENABLED, //
|
|
|
|
Prefs::COMPACT_VIEW, //
|
|
|
|
Prefs::DSPEED, //
|
|
|
|
Prefs::DSPEED_ENABLED, //
|
|
|
|
Prefs::FILTERBAR, //
|
|
|
|
Prefs::MAIN_WINDOW_X, //
|
|
|
|
Prefs::RATIO, //
|
|
|
|
Prefs::RATIO_ENABLED, //
|
2022-01-23 15:57:21 +00:00
|
|
|
Prefs::READ_CLIPBOARD, //
|
2021-08-15 09:41:48 +00:00
|
|
|
Prefs::SHOW_TRAY_ICON, //
|
|
|
|
Prefs::SORT_MODE, //
|
|
|
|
Prefs::SORT_REVERSED, //
|
|
|
|
Prefs::STATUSBAR, //
|
|
|
|
Prefs::STATUSBAR_STATS, //
|
|
|
|
Prefs::TOOLBAR, //
|
|
|
|
Prefs::USPEED, //
|
|
|
|
Prefs::USPEED_ENABLED, //
|
2020-06-05 19:02:11 +00:00
|
|
|
};
|
|
|
|
for (auto const key : InitKeys)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
refreshPref(key);
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
auto refresh_status_soon = [this]()
|
|
|
|
{
|
|
|
|
refreshSoon(REFRESH_STATUS_BAR);
|
|
|
|
};
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&session_, &Session::sourceChanged, this, &MainWindow::onSessionSourceChanged);
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&session_, &Session::statsUpdated, this, refresh_status_soon);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&session_, &Session::dataReadProgress, this, &MainWindow::dataReadProgress);
|
|
|
|
connect(&session_, &Session::dataSendProgress, this, &MainWindow::dataSendProgress);
|
|
|
|
connect(&session_, &Session::httpAuthenticationRequired, this, &MainWindow::wrongAuthentication);
|
|
|
|
connect(&session_, &Session::networkResponse, this, &MainWindow::onNetworkResponse);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_.isServer())
|
2009-05-06 13:39:48 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.networkLabel->hide();
|
2009-05-06 13:39:48 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&network_timer_, &QTimer::timeout, this, &MainWindow::onNetworkTimer);
|
|
|
|
network_timer_.start(1000);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&refresh_timer_, &QTimer::timeout, this, &MainWindow::onRefreshTimer);
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshSoon();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onSessionSourceChanged()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
model_.clear();
|
2009-05-03 18:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 17:37:39 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onSetPrefs()
|
2009-04-14 22:05:11 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
QVariantList const p = sender()->property(PrefVariantsKey).toList();
|
2017-04-30 16:25:26 +00:00
|
|
|
assert(p.size() % 2 == 0);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
for (int i = 0, n = p.size(); i < n; i += 2)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(p[i].toInt(), p[i + 1]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-14 22:05:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void MainWindow::onSetPrefs(bool is_checked)
|
2009-04-14 22:05:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_checked)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
onSetPrefs();
|
|
|
|
}
|
2009-04-14 22:05:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::initStatusBar()
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.optionsButton->setMenu(createOptionsMenu());
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const minimum_speed_width = ui_.downloadSpeedLabel->fontMetrics()
|
2021-12-05 23:32:19 +00:00
|
|
|
.size(0, Formatter::get().uploadSpeedToString(Speed::fromKBps(999.99)))
|
2021-08-15 09:41:48 +00:00
|
|
|
.width();
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.downloadSpeedLabel->setMinimumWidth(minimum_speed_width);
|
|
|
|
ui_.uploadSpeedLabel->setMinimumWidth(minimum_speed_width);
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.statsModeButton->setMenu(createStatsModeMenu());
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.altSpeedButton, &QAbstractButton::clicked, this, &MainWindow::toggleSpeedMode);
|
2009-04-15 01:59:54 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QMenu* MainWindow::createOptionsMenu()
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const init_speed_sub_menu = [this](QMenu* menu, QAction*& off_action, QAction*& on_action, int pref, int enabled_pref)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
std::array<int, 13> stock_speeds = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
|
|
|
|
int const current_value = prefs_.get<int>(pref);
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
|
|
|
auto* action_group = new QActionGroup(this);
|
|
|
|
|
|
|
|
off_action = menu->addAction(tr("Unlimited"));
|
|
|
|
off_action->setCheckable(true);
|
|
|
|
off_action->setProperty(PrefVariantsKey, QVariantList{ enabled_pref, false });
|
|
|
|
action_group->addAction(off_action);
|
|
|
|
connect(off_action, &QAction::triggered, this, qOverload<bool>(&MainWindow::onSetPrefs));
|
|
|
|
|
|
|
|
on_action = menu->addAction(tr("Limited at %1").arg(Formatter::get().speedToString(Speed::fromKBps(current_value))));
|
|
|
|
on_action->setCheckable(true);
|
|
|
|
on_action->setProperty(PrefVariantsKey, QVariantList{ pref, current_value, enabled_pref, true });
|
|
|
|
action_group->addAction(on_action);
|
|
|
|
connect(on_action, &QAction::triggered, this, qOverload<bool>(&MainWindow::onSetPrefs));
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
for (int const i : stock_speeds)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
QAction* action = menu->addAction(Formatter::get().speedToString(Speed::fromKBps(i)));
|
|
|
|
action->setProperty(PrefVariantsKey, QVariantList{ pref, i, enabled_pref, true });
|
|
|
|
connect(action, &QAction::triggered, this, qOverload<>(&MainWindow::onSetPrefs));
|
|
|
|
}
|
|
|
|
};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
auto const init_seed_ratio_sub_menu =
|
|
|
|
[this](QMenu* menu, QAction*& off_action, QAction*& on_action, int pref, int enabled_pref)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
std::array<double, 7> stock_ratios = { 0.25, 0.50, 0.75, 1, 1.5, 2, 3 };
|
|
|
|
auto const current_value = prefs_.get<double>(pref);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
off_action = menu->addAction(tr("Seed Forever"));
|
|
|
|
off_action->setCheckable(true);
|
|
|
|
off_action->setProperty(PrefVariantsKey, QVariantList{ enabled_pref, false });
|
|
|
|
action_group->addAction(off_action);
|
|
|
|
connect(off_action, &QAction::triggered, this, qOverload<bool>(&MainWindow::onSetPrefs));
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
on_action = menu->addAction(tr("Stop at Ratio (%1)").arg(Formatter::get().ratioToString(current_value)));
|
|
|
|
on_action->setCheckable(true);
|
|
|
|
on_action->setProperty(PrefVariantsKey, QVariantList{ pref, current_value, enabled_pref, true });
|
|
|
|
action_group->addAction(on_action);
|
|
|
|
connect(on_action, &QAction::triggered, this, qOverload<bool>(&MainWindow::onSetPrefs));
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
menu->addSeparator();
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (double const i : stock_ratios)
|
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(Formatter::get().ratioToString(i));
|
|
|
|
action->setProperty(PrefVariantsKey, QVariantList{ pref, i, enabled_pref, true });
|
|
|
|
connect(action, &QAction::triggered, this, qOverload<>(&MainWindow::onSetPrefs));
|
|
|
|
}
|
|
|
|
};
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* menu = new QMenu(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
init_speed_sub_menu(
|
|
|
|
menu->addMenu(tr("Limit Download Speed")),
|
|
|
|
dlimit_off_action_,
|
|
|
|
dlimit_on_action_,
|
|
|
|
Prefs::DSPEED,
|
2017-04-19 12:04:45 +00:00
|
|
|
Prefs::DSPEED_ENABLED);
|
2021-08-15 09:41:48 +00:00
|
|
|
init_speed_sub_menu(
|
|
|
|
menu->addMenu(tr("Limit Upload Speed")),
|
|
|
|
ulimit_off_action_,
|
|
|
|
ulimit_on_action_,
|
|
|
|
Prefs::USPEED,
|
2017-04-19 12:04:45 +00:00
|
|
|
Prefs::USPEED_ENABLED);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addSeparator();
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
init_seed_ratio_sub_menu(
|
|
|
|
menu->addMenu(tr("Stop Seeding at Ratio")),
|
|
|
|
ratio_off_action_,
|
|
|
|
ratio_on_action_,
|
|
|
|
Prefs::RATIO,
|
2017-04-19 12:04:45 +00:00
|
|
|
Prefs::RATIO_ENABLED);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return menu;
|
2009-04-14 22:05:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QMenu* MainWindow::createStatsModeMenu()
|
2014-12-18 01:30:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
std::array<QPair<QAction*, QString>, 4> stats_modes = {
|
2020-08-15 15:42:51 +00:00
|
|
|
qMakePair(ui_.action_TotalRatio, total_ratio_stats_mode_name_),
|
|
|
|
qMakePair(ui_.action_TotalTransfer, total_transfer_stats_mode_name_),
|
|
|
|
qMakePair(ui_.action_SessionRatio, session_ratio_stats_mode_name_),
|
|
|
|
qMakePair(ui_.action_SessionTransfer, session_transfer_stats_mode_name_)
|
2015-08-06 20:28:44 +00:00
|
|
|
};
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* menu = new QMenu(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (auto const& mode : stats_modes)
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
mode.first->setProperty(StatsModeKey, QString(mode.second));
|
2020-06-05 19:02:11 +00:00
|
|
|
action_group->addAction(mode.first);
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addAction(mode.first);
|
2015-08-06 20:28:44 +00:00
|
|
|
}
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(action_group, &QActionGroup::triggered, this, &MainWindow::onStatsModeChanged);
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
2017-04-19 12:04:45 +00:00
|
|
|
return menu;
|
2014-12-18 01:30:50 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
void MainWindow::onSortModeChanged(QAction const* action)
|
2009-04-11 18:25:12 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
prefs_.set(Prefs::SORT_MODE, SortMode(action->property(SortModeKey).toInt()));
|
2009-04-11 18:25:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::setSortAscendingPref(bool b)
|
2009-04-11 18:25:12 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::SORT_REVERSED, b);
|
2009-04-11 18:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::showEvent(QShowEvent* event)
|
2013-01-01 20:02:20 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
Q_UNUSED(event)
|
2013-01-01 20:02:20 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_ShowMainWindow->setChecked(true);
|
2013-01-01 20:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::hideEvent(QHideEvent* event)
|
2013-01-01 20:02:20 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
Q_UNUSED(event)
|
2013-01-01 20:02:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!isVisible())
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_ShowMainWindow->setChecked(false);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-01 20:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openSession()
|
2010-05-06 04:49:10 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Utils::openDialog(session_dialog_, session_, prefs_, this);
|
2010-05-06 04:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openPreferences()
|
2009-04-18 23:18:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Utils::openDialog(prefs_dialog_, session_, prefs_, this);
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openProperties()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Utils::openDialog(details_dialog_, session_, prefs_, model_, this);
|
|
|
|
details_dialog_->setIds(getSelectedTorrents());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::setLocation()
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* d = new RelocateDialog(session_, model_, getSelectedTorrents(), this);
|
2017-04-19 12:04:45 +00:00
|
|
|
d->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
d->show();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:30:03 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2012-04-07 00:16:14 +00:00
|
|
|
// Open Folder & select torrent's file or top folder
|
2020-11-05 22:46:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OPEN_SELECT
|
2012-12-27 18:22:48 +00:00
|
|
|
#undef HAVE_OPEN_SELECT
|
2020-11-05 22:46:21 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
|
|
|
#define HAVE_OPEN_SELECT
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
void openSelect(QString const& path)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
auto const explorer = QStringLiteral("explorer");
|
2017-04-19 12:04:45 +00:00
|
|
|
QString param;
|
|
|
|
|
|
|
|
if (!QFileInfo(path).isDir())
|
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
param = QStringLiteral("/select,");
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
param += QDir::toNativeSeparators(path);
|
|
|
|
QProcess::startDetached(explorer, QStringList(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
|
|
|
|
#define HAVE_OPEN_SELECT
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
void openSelect(QString const& path)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QStringList script_args;
|
2021-08-15 09:41:48 +00:00
|
|
|
script_args << QStringLiteral("-e") << QStringLiteral("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(path);
|
2020-05-29 17:40:07 +00:00
|
|
|
QProcess::execute(QStringLiteral("/usr/bin/osascript"), script_args);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
script_args.clear();
|
2020-05-29 17:40:07 +00:00
|
|
|
script_args << QStringLiteral("-e") << QStringLiteral("tell application \"Finder\" to activate");
|
|
|
|
QProcess::execute(QStringLiteral("/usr/bin/osascript"), script_args);
|
2012-04-07 00:16:14 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2012-12-27 18:22:48 +00:00
|
|
|
#endif
|
2012-04-07 00:16:14 +00:00
|
|
|
|
2017-04-30 16:30:03 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openFolder()
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const selected_torrents = getSelectedTorrents();
|
2015-10-04 06:16:59 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (selected_torrents.size() != 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
int const torrent_id(*selected_torrents.begin());
|
|
|
|
Torrent const* tor(model_.getTorrentFromId(torrent_id));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (tor == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-10-04 06:16:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString path(tor->getPath());
|
2017-04-20 16:02:19 +00:00
|
|
|
FileList const& files = tor->files();
|
2015-10-04 06:16:59 +00:00
|
|
|
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
if (files.empty())
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return;
|
2012-04-07 00:16:14 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const first_file = files.at(0).filename;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (int const slash_index = first_file.indexOf(QLatin1Char('/')); slash_index > -1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
path = path + QLatin1Char('/') + first_file.left(slash_index);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 18:22:48 +00:00
|
|
|
#ifdef HAVE_OPEN_SELECT
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
else
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
openSelect(path + QLatin1Char('/') + first_file);
|
2017-04-19 12:04:45 +00:00
|
|
|
return;
|
2012-12-27 18:22:48 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2012-12-27 18:22:48 +00:00
|
|
|
#endif
|
2015-10-04 06:16:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::copyMagnetLinkToClipboard()
|
2009-12-03 15:23:43 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const id(*getSelectedTorrents().begin());
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.copyMagnetLinkToClipboard(id);
|
2009-12-03 15:23:43 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openStats()
|
2015-07-30 06:18:02 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Utils::openDialog(stats_dialog_, session_, this);
|
2015-07-30 06:18:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
void MainWindow::openDonate() const
|
2010-08-02 03:07:42 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QStringLiteral("https://transmissionbt.com/donate/")));
|
2010-08-02 03:07:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openAbout()
|
2015-07-30 06:18:02 +00:00
|
|
|
{
|
2021-01-24 17:43:14 +00:00
|
|
|
Utils::openDialog(about_dialog_, session_, this);
|
2015-07-30 06:18:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
void MainWindow::openHelp() const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
QDesktopServices::openUrl(
|
|
|
|
QUrl(QStringLiteral("https://transmissionbt.com/help/gtk/%1.%2x").arg(MAJOR_VERSION).arg(MINOR_VERSION / 10)));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
void MainWindow::refreshSoon(int fields)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
refresh_fields_ |= fields;
|
2019-11-09 14:44:40 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!refresh_timer_.isActive())
|
2019-11-09 14:44:40 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
refresh_timer_.setSingleShot(true);
|
|
|
|
refresh_timer_.start(200);
|
2019-11-09 14:44:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
MainWindow::TransferStats MainWindow::getTransferStats() const
|
|
|
|
{
|
|
|
|
TransferStats stats;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (auto const& tor : model_.torrents())
|
2019-11-12 01:37:05 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
stats.speed_up += tor->uploadSpeed();
|
|
|
|
stats.speed_down += tor->downloadSpeed();
|
|
|
|
stats.peers_sending += tor->webseedsWeAreDownloadingFrom();
|
|
|
|
stats.peers_sending += tor->peersWeAreDownloadingFrom();
|
|
|
|
stats.peers_receiving += tor->peersWeAreUploadingTo();
|
2019-11-12 01:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
void MainWindow::onRefreshTimer()
|
|
|
|
{
|
|
|
|
int fields = 0;
|
2020-05-27 21:53:12 +00:00
|
|
|
std::swap(fields, refresh_fields_);
|
2019-11-09 14:44:40 +00:00
|
|
|
|
|
|
|
if (fields & REFRESH_TITLE)
|
|
|
|
{
|
|
|
|
refreshTitle();
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
if (fields & (REFRESH_TRAY_ICON | REFRESH_STATUS_BAR))
|
2019-11-09 14:44:40 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
auto const stats = getTransferStats();
|
2019-11-09 14:44:40 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
if (fields & REFRESH_TRAY_ICON)
|
|
|
|
{
|
|
|
|
refreshTrayIcon(stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields & REFRESH_STATUS_BAR)
|
|
|
|
{
|
|
|
|
refreshStatusBar(stats);
|
|
|
|
}
|
2019-11-09 14:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fields & REFRESH_TORRENT_VIEW_HEADER)
|
|
|
|
{
|
|
|
|
refreshTorrentViewHeader();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields & REFRESH_ACTION_SENSITIVITY)
|
|
|
|
{
|
|
|
|
refreshActionSensitivity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshTitle()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
QString title(QStringLiteral("Transmission"));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const url = QUrl(session_.getRemoteUrl()); !url.isEmpty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-09 03:31:02 +00:00
|
|
|
//: Second (optional) part of main window title "Transmission - host:port" (added when connected to remote session)
|
2017-04-19 12:04:45 +00:00
|
|
|
//: notice that leading space (before the dash) is included here
|
|
|
|
title += tr(" - %1:%2").arg(url.host()).arg(url.port());
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(title);
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void MainWindow::refreshTrayIcon(TransferStats const& stats)
|
2010-08-05 15:01:40 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QString tip;
|
2010-08-05 15:01:40 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (network_error_)
|
2014-04-27 00:33:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tip = tr("Network Error");
|
2014-04-27 00:33:19 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (stats.peers_sending == 0 && stats.peers_receiving == 0)
|
2013-02-07 21:07:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tip = tr("Idle");
|
2013-02-07 21:07:16 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (stats.peers_sending != 0)
|
2013-02-07 21:07:16 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
tip = Formatter::get().downloadSpeedToString(stats.speed_down) + QStringLiteral(" ") +
|
2021-08-15 09:41:48 +00:00
|
|
|
Formatter::get().uploadSpeedToString(stats.speed_up);
|
2013-02-07 21:07:16 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (stats.peers_receiving != 0)
|
2013-02-07 21:07:16 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
tip = Formatter::get().uploadSpeedToString(stats.speed_up);
|
2013-02-07 21:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
tray_icon_.setToolTip(tip);
|
2010-08-05 15:01:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void MainWindow::refreshStatusBar(TransferStats const& stats)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-11-09 03:31:02 +00:00
|
|
|
auto const& fmt = Formatter::get();
|
|
|
|
ui_.uploadSpeedLabel->setText(fmt.uploadSpeedToString(stats.speed_up));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.uploadSpeedLabel->setVisible(stats.peers_sending || stats.peers_receiving);
|
2020-11-09 03:31:02 +00:00
|
|
|
ui_.downloadSpeedLabel->setText(fmt.downloadSpeedToString(stats.speed_down));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.downloadSpeedLabel->setVisible(stats.peers_sending);
|
2009-05-02 14:25:18 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.networkLabel->setVisible(!session_.isServer());
|
2009-05-06 13:46:10 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
auto const mode = prefs_.getString(Prefs::STATUSBAR_STATS);
|
2021-08-15 09:41:48 +00:00
|
|
|
auto str = QString{};
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-08-15 15:42:51 +00:00
|
|
|
if (mode == session_ratio_stats_mode_name_)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Ratio: %1").arg(fmt.ratioToString(session_.getStats().ratio));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2020-08-15 15:42:51 +00:00
|
|
|
else if (mode == session_transfer_stats_mode_name_)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-08-11 18:11:55 +00:00
|
|
|
auto const& st = session_.getStats();
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(fmt.sizeToString(st.downloadedBytes)).arg(fmt.sizeToString(st.uploadedBytes));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2020-08-15 15:42:51 +00:00
|
|
|
else if (mode == total_transfer_stats_mode_name_)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-08-11 18:11:55 +00:00
|
|
|
auto const& st = session_.getCumulativeStats();
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(fmt.sizeToString(st.downloadedBytes)).arg(fmt.sizeToString(st.uploadedBytes));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else // default is "total-ratio"
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
assert(mode == total_ratio_stats_mode_name_);
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Ratio: %1").arg(fmt.ratioToString(session_.getCumulativeStats().ratio));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.statsLabel->setText(str);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshTorrentViewHeader()
|
2015-10-19 20:30:26 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int const total_count = model_.rowCount();
|
|
|
|
int const visible_count = filter_model_.rowCount();
|
2011-07-19 21:19:18 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (visible_count == total_count)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.listView->setHeaderText(QString());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.listView->setHeaderText(tr("Showing %L1 of %Ln torrent(s)", nullptr, total_count).arg(visible_count));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-10-19 20:30:26 +00:00
|
|
|
}
|
2011-07-19 21:19:18 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshActionSensitivity()
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-06-23 17:16:07 +00:00
|
|
|
auto const* model = ui_.listView->model();
|
|
|
|
auto const* selection_model = ui_.listView->selectionModel();
|
|
|
|
auto const row_count = model->rowCount();
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// count how many torrents are selected, paused, etc
|
2020-06-23 17:16:07 +00:00
|
|
|
auto selected = int{};
|
|
|
|
auto selected_and_can_announce = int{};
|
|
|
|
auto selected_and_paused = int{};
|
|
|
|
auto selected_and_queued = int{};
|
|
|
|
auto selected_with_metadata = int{};
|
2019-11-06 23:31:41 +00:00
|
|
|
auto const now = time(nullptr);
|
2020-06-23 17:16:07 +00:00
|
|
|
for (auto const& row : selection_model->selectedRows())
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-06-23 17:16:07 +00:00
|
|
|
auto const& tor = model->data(row, TorrentModel::TorrentRole).value<Torrent const*>();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-23 17:16:07 +00:00
|
|
|
++selected;
|
|
|
|
|
|
|
|
if (tor->isPaused())
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-06-23 17:16:07 +00:00
|
|
|
++selected_and_paused;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-23 17:16:07 +00:00
|
|
|
if (tor->isQueued())
|
|
|
|
{
|
|
|
|
++selected_and_queued;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-23 17:16:07 +00:00
|
|
|
if (tor->hasMetadata())
|
|
|
|
{
|
|
|
|
++selected_with_metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tor->canManualAnnounceAt(now))
|
|
|
|
{
|
|
|
|
++selected_and_can_announce;
|
2009-10-10 00:39:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 17:16:07 +00:00
|
|
|
auto const& torrents = model_.torrents();
|
2021-08-15 09:41:48 +00:00
|
|
|
auto const is_paused = [](auto const* tor)
|
|
|
|
{
|
|
|
|
return tor->isPaused();
|
|
|
|
};
|
2020-06-23 17:16:07 +00:00
|
|
|
auto const any_paused = std::any_of(std::begin(torrents), std::end(torrents), is_paused);
|
2020-09-08 15:09:16 +00:00
|
|
|
auto const any_not_paused = !std::all_of(std::begin(torrents), std::end(torrents), is_paused);
|
2020-06-23 17:16:07 +00:00
|
|
|
|
|
|
|
auto const have_selection = selected > 0;
|
|
|
|
auto const have_selection_with_metadata = selected_with_metadata > 0;
|
|
|
|
auto const one_selection = selected == 1;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_Verify->setEnabled(have_selection_with_metadata);
|
|
|
|
ui_.action_Remove->setEnabled(have_selection);
|
|
|
|
ui_.action_Delete->setEnabled(have_selection);
|
|
|
|
ui_.action_Properties->setEnabled(have_selection);
|
|
|
|
ui_.action_DeselectAll->setEnabled(have_selection);
|
|
|
|
ui_.action_SetLocation->setEnabled(have_selection);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_OpenFolder->setEnabled(one_selection && have_selection_with_metadata && session_.isLocal());
|
|
|
|
ui_.action_CopyMagnetToClipboard->setEnabled(one_selection);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_SelectAll->setEnabled(selected < row_count);
|
2020-06-23 17:16:07 +00:00
|
|
|
ui_.action_StartAll->setEnabled(any_paused);
|
|
|
|
ui_.action_PauseAll->setEnabled(any_not_paused);
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_Start->setEnabled(selected_and_paused > 0);
|
|
|
|
ui_.action_StartNow->setEnabled(selected_and_paused + selected_and_queued > 0);
|
|
|
|
ui_.action_Pause->setEnabled(selected_and_paused < selected);
|
|
|
|
ui_.action_Announce->setEnabled(selected > 0 && (selected_and_can_announce == selected));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_QueueMoveTop->setEnabled(have_selection);
|
|
|
|
ui_.action_QueueMoveUp->setEnabled(have_selection);
|
|
|
|
ui_.action_QueueMoveDown->setEnabled(have_selection);
|
|
|
|
ui_.action_QueueMoveBottom->setEnabled(have_selection);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!details_dialog_.isNull())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
details_dialog_->setIds(getSelectedTorrents());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
// NOLINTNEXTLINE(readability-make-member-function-const)
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::clearSelection()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_DeselectAll->trigger();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
torrent_ids_t MainWindow::getSelectedTorrents(bool with_metadata_only) const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
torrent_ids_t ids;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& index : ui_.listView->selectionModel()->selectedRows())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto const* tor(index.data(TorrentModel::TorrentRole).value<Torrent const*>());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (tor != nullptr && (!with_metadata_only || tor->hasMetadata()))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
ids.insert(tor->id());
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ids;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::startSelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.startTorrents(getSelectedTorrents());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::startSelectedNow()
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.startTorrentsNow(getSelectedTorrents());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::pauseSelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.pauseTorrents(getSelectedTorrents());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::queueMoveTop()
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.queueMoveTop(getSelectedTorrents());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::queueMoveUp()
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.queueMoveUp(getSelectedTorrents());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::queueMoveDown()
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.queueMoveDown(getSelectedTorrents());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::queueMoveBottom()
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.queueMoveBottom(getSelectedTorrents());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::startAll()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.startTorrents();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::pauseAll()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.pauseTorrents();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::removeSelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
removeTorrents(false);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::deleteSelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
removeTorrents(true);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::verifySelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.verifyTorrents(getSelectedTorrents(true));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::reannounceSelected()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.reannounceTorrents(getSelectedTorrents());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
void MainWindow::onStatsModeChanged(QAction const* action)
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
prefs_.set(Prefs::STATUSBAR_STATS, action->property(StatsModeKey).toString());
|
2015-08-06 20:28:44 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::setCompactView(bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::COMPACT_VIEW, visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::toggleSpeedMode()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.toggleBool(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
|
|
|
bool const mode = prefs_.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
|
|
|
alt_speed_action_->setChecked(mode);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::setToolbarVisible(bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::TOOLBAR, visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::setFilterbarVisible(bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::FILTERBAR, visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::setStatusbarVisible(bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::STATUSBAR, visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void MainWindow::toggleWindows(bool do_show)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!do_show)
|
2009-08-11 18:57:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
hide();
|
2009-08-11 18:57:49 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2009-08-11 18:57:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!isVisible())
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMinimized())
|
|
|
|
{
|
|
|
|
showNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
raise();
|
2020-11-02 01:13:32 +00:00
|
|
|
QApplication::setActiveWindow(this);
|
2009-08-11 18:57:49 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick)
|
2009-08-11 18:57:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (isMinimized())
|
|
|
|
{
|
|
|
|
toggleWindows(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
toggleWindows(!isVisible());
|
|
|
|
}
|
2009-08-11 18:57:49 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshPref(int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
auto b = bool{};
|
|
|
|
auto i = int{};
|
|
|
|
auto str = QString{};
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::STATUSBAR_STATS:
|
2020-05-27 21:53:12 +00:00
|
|
|
str = prefs_.getString(key);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
for (auto* action : ui_.action_TotalRatio->actionGroup()->actions())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
action->setChecked(str == action->property(StatsModeKey).toString());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
refreshSoon(REFRESH_STATUS_BAR);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::SORT_REVERSED:
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_ReverseSortOrder->setChecked(prefs_.getBool(key));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::SORT_MODE:
|
2020-05-27 21:53:12 +00:00
|
|
|
i = prefs_.get<SortMode>(key).mode();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
for (auto* action : ui_.action_SortByActivity->actionGroup()->actions())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
action->setChecked(i == action->property(SortModeKey).toInt());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::DSPEED_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
(prefs_.get<bool>(key) ? dlimit_on_action_ : dlimit_off_action_)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::DSPEED:
|
2021-08-15 09:41:48 +00:00
|
|
|
dlimit_on_action_->setText(
|
|
|
|
tr("Limited at %1").arg(Formatter::get().speedToString(Speed::fromKBps(prefs_.get<int>(key)))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::USPEED_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
(prefs_.get<bool>(key) ? ulimit_on_action_ : ulimit_off_action_)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::USPEED:
|
2021-08-15 09:41:48 +00:00
|
|
|
ulimit_on_action_->setText(
|
|
|
|
tr("Limited at %1").arg(Formatter::get().speedToString(Speed::fromKBps(prefs_.get<int>(key)))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RATIO_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
(prefs_.get<bool>(key) ? ratio_on_action_ : ratio_off_action_)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RATIO:
|
2020-08-15 15:42:51 +00:00
|
|
|
ratio_on_action_->setText(tr("Stop at Ratio (%1)").arg(Formatter::get().ratioToString(prefs_.get<double>(key))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::FILTERBAR:
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
filter_bar_->setVisible(b);
|
|
|
|
ui_.action_Filterbar->setChecked(b);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::STATUSBAR:
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
ui_.statusBar->setVisible(b);
|
|
|
|
ui_.action_Statusbar->setChecked(b);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::TOOLBAR:
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
ui_.toolBar->setVisible(b);
|
|
|
|
ui_.action_Toolbar->setChecked(b);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::SHOW_TRAY_ICON:
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
ui_.action_TrayIcon->setChecked(b);
|
|
|
|
tray_icon_.setVisible(b);
|
2020-11-02 01:13:32 +00:00
|
|
|
QApplication::setQuitOnLastWindowClosed(!b);
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshSoon(REFRESH_TRAY_ICON);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::COMPACT_VIEW:
|
2022-01-23 15:57:21 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
ui_.action_CompactView->setChecked(b);
|
|
|
|
ui_.listView->setItemDelegate(b ? torrent_delegate_min_ : torrent_delegate_);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::MAIN_WINDOW_X:
|
|
|
|
case Prefs::MAIN_WINDOW_Y:
|
|
|
|
case Prefs::MAIN_WINDOW_WIDTH:
|
|
|
|
case Prefs::MAIN_WINDOW_HEIGHT:
|
2021-08-15 09:41:48 +00:00
|
|
|
setGeometry(
|
|
|
|
prefs_.getInt(Prefs::MAIN_WINDOW_X),
|
|
|
|
prefs_.getInt(Prefs::MAIN_WINDOW_Y),
|
|
|
|
prefs_.getInt(Prefs::MAIN_WINDOW_WIDTH),
|
|
|
|
prefs_.getInt(Prefs::MAIN_WINDOW_HEIGHT));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::ALT_SPEED_LIMIT_ENABLED:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_UP:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_DOWN:
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
|
|
|
alt_speed_action_->setChecked(b);
|
|
|
|
ui_.altSpeedButton->setChecked(b);
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const fmt = b ? tr("Click to disable Temporary Speed Limits\n (%1 down, %2 up)") :
|
2021-08-15 09:41:48 +00:00
|
|
|
tr("Click to enable Temporary Speed Limits\n (%1 down, %2 up)");
|
2020-05-27 21:53:12 +00:00
|
|
|
Speed const d = Speed::fromKBps(prefs_.getInt(Prefs::ALT_SPEED_LIMIT_DOWN));
|
|
|
|
Speed const u = Speed::fromKBps(prefs_.getInt(Prefs::ALT_SPEED_LIMIT_UP));
|
2020-08-15 15:42:51 +00:00
|
|
|
ui_.altSpeedButton->setToolTip(fmt.arg(Formatter::get().speedToString(d)).arg(Formatter::get().speedToString(u)));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2009-06-27 05:23:13 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2022-01-23 15:57:21 +00:00
|
|
|
case Prefs::READ_CLIPBOARD:
|
|
|
|
auto_add_clipboard_links = prefs_.getBool(Prefs::READ_CLIPBOARD);
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::newTorrent()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* dialog = new MakeDialog(session_, this);
|
2017-04-19 12:04:45 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->show();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openTorrent()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
auto* const d = new QFileDialog(
|
2021-08-15 09:41:48 +00:00
|
|
|
this,
|
|
|
|
tr("Open Torrent"),
|
|
|
|
prefs_.getString(Prefs::OPEN_DIALOG_FOLDER),
|
2017-04-19 12:04:45 +00:00
|
|
|
tr("Torrent Files (*.torrent);;All Files (*.*)"));
|
|
|
|
d->setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
d->setAttribute(Qt::WA_DeleteOnClose);
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto* const l = qobject_cast<QGridLayout*>(d->layout()); l != nullptr)
|
2014-03-16 22:50:39 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* b = new QCheckBox(tr("Show &options dialog"));
|
2020-05-27 21:53:12 +00:00
|
|
|
b->setChecked(prefs_.getBool(Prefs::OPTIONS_PROMPT));
|
2020-08-15 15:42:51 +00:00
|
|
|
b->setObjectName(show_options_checkbox_name_);
|
2017-04-19 12:04:45 +00:00
|
|
|
l->addWidget(b, l->rowCount(), 0, 1, -1, Qt::AlignLeft);
|
2014-03-16 22:50:39 +00:00
|
|
|
}
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(d, &QFileDialog::filesSelected, this, &MainWindow::addTorrents);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
d->open();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openURL()
|
2010-04-27 03:10:32 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
QString str = QApplication::clipboard()->text(QClipboard::Selection);
|
2011-01-21 21:51:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!AddData::isSupported(str))
|
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
str = QApplication::clipboard()->text(QClipboard::Clipboard);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-01-21 21:51:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!AddData::isSupported(str))
|
|
|
|
{
|
|
|
|
str.clear();
|
|
|
|
}
|
2011-01-21 21:51:50 +00:00
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
addTorrent(AddData(str), true);
|
2009-12-03 17:23:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void MainWindow::addTorrents(QStringList const& filenames)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool show_options = prefs_.getBool(Prefs::OPTIONS_PROMPT);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* const file_dialog = qobject_cast<QFileDialog const*>(sender()); file_dialog != nullptr)
|
2013-09-14 22:50:25 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
auto const* const b = file_dialog->findChild<QCheckBox const*>(show_options_checkbox_name_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
if (b != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
show_options = b->isChecked();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-09-14 22:50:25 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& filename : filenames)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
addTorrent(AddData(filename), show_options);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void MainWindow::addTorrent(AddData const& addMe, bool show_options)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (show_options)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* o = new OptionsDialog(session_, prefs_, addMe, this);
|
2017-04-19 12:04:45 +00:00
|
|
|
o->show();
|
2020-11-02 01:13:32 +00:00
|
|
|
QApplication::alert(o);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-02-09 23:11:17 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.addTorrent(addMe);
|
2020-11-02 01:13:32 +00:00
|
|
|
QApplication::alert(this);
|
2013-02-09 23:11:17 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void MainWindow::removeTorrents(bool const delete_files)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
torrent_ids_t ids;
|
2020-05-27 21:53:12 +00:00
|
|
|
QMessageBox msg_box(this);
|
2017-05-01 15:46:41 +00:00
|
|
|
QString primary_text;
|
|
|
|
QString secondary_text;
|
2017-04-19 12:04:45 +00:00
|
|
|
int incomplete = 0;
|
|
|
|
int connected = 0;
|
2010-04-23 03:58:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& index : ui_.listView->selectionModel()->selectedRows())
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto const* tor(index.data(TorrentModel::TorrentRole).value<Torrent const*>());
|
2017-04-19 12:04:45 +00:00
|
|
|
ids.insert(tor->id());
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tor->connectedPeers())
|
|
|
|
{
|
|
|
|
++connected;
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!tor->isDone())
|
|
|
|
{
|
|
|
|
++incomplete;
|
|
|
|
}
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
if (ids.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
int const count = ids.size();
|
2010-04-23 03:58:42 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!delete_files)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
primary_text = count == 1 ? tr("Remove torrent?") : tr("Remove %Ln torrent(s)?", nullptr, count);
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
primary_text = count == 1 ? tr("Delete this torrent's downloaded files?") :
|
2021-08-15 09:41:48 +00:00
|
|
|
tr("Delete these %Ln torrent(s)' downloaded files?", nullptr, count);
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 12:40:41 +00:00
|
|
|
if (incomplete == 0 && connected == 0)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
secondary_text = count == 1 ?
|
2017-04-19 12:04:45 +00:00
|
|
|
tr("Once removed, continuing the transfer will require the torrent file or magnet link.") :
|
|
|
|
tr("Once removed, continuing the transfers will require the torrent files or magnet links.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (count == incomplete)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
secondary_text = count == 1 ? tr("This torrent has not finished downloading.") :
|
2021-08-15 09:41:48 +00:00
|
|
|
tr("These torrents have not finished downloading.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (count == connected)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
secondary_text = count == 1 ? tr("This torrent is connected to peers.") : tr("These torrents are connected to peers.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
if (connected != 0)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
secondary_text = connected == 1 ? tr("One of these torrents is connected to peers.") :
|
2021-08-15 09:41:48 +00:00
|
|
|
tr("Some of these torrents are connected to peers.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (connected != 0 && incomplete != 0)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
secondary_text += QLatin1Char('\n');
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (incomplete != 0)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
secondary_text += incomplete == 1 ? tr("One of these torrents has not finished downloading.") :
|
2021-08-15 09:41:48 +00:00
|
|
|
tr("Some of these torrents have not finished downloading.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 17:40:07 +00:00
|
|
|
msg_box.setWindowTitle(QStringLiteral(" "));
|
|
|
|
msg_box.setText(QStringLiteral("<big><b>%1</big></b>").arg(primary_text));
|
2020-05-27 21:53:12 +00:00
|
|
|
msg_box.setInformativeText(secondary_text);
|
|
|
|
msg_box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msg_box.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
msg_box.setIcon(QMessageBox::Question);
|
2017-04-19 12:04:45 +00:00
|
|
|
// hack needed to keep the dialog from being too narrow
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* layout = qobject_cast<QGridLayout*>(msg_box.layout());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (layout == nullptr)
|
2014-03-16 22:50:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
layout = new QGridLayout;
|
2020-05-27 21:53:12 +00:00
|
|
|
msg_box.setLayout(layout);
|
2014-03-16 22:50:39 +00:00
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* spacer = new QSpacerItem(450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
2017-04-19 12:04:45 +00:00
|
|
|
layout->addItem(spacer, layout->rowCount(), 0, 1, layout->columnCount());
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (msg_box.exec() == QMessageBox::Ok)
|
2010-06-16 03:01:09 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.listView->selectionModel()->clear();
|
|
|
|
session_.removeTorrents(ids, delete_files);
|
2010-06-16 03:01:09 +00:00
|
|
|
}
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::updateNetworkIcon()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
static constexpr int const Period = 3;
|
2017-04-30 09:29:58 +00:00
|
|
|
time_t const now = time(nullptr);
|
2020-05-27 21:53:12 +00:00
|
|
|
time_t const seconds_since_last_send = now - last_send_time_;
|
|
|
|
time_t const seconds_since_last_read = now - last_read_time_;
|
2020-06-05 19:02:11 +00:00
|
|
|
bool const is_sending = seconds_since_last_send <= Period;
|
|
|
|
bool const is_reading = seconds_since_last_read <= Period;
|
2019-11-06 21:09:04 +00:00
|
|
|
QPixmap pixmap;
|
2013-01-03 04:21:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (network_error_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap = pixmap_network_error_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (is_sending && is_reading)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap = pixmap_network_transmit_receive_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (is_sending)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap = pixmap_network_transmit_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (is_reading)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap = pixmap_network_receive_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap = pixmap_network_idle_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString tip;
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const url = session_.getRemoteUrl().host();
|
2013-01-03 04:21:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (last_read_time_ == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tip = tr("%1 has not responded yet").arg(url);
|
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (network_error_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tip = tr(error_message_.toLatin1().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (seconds_since_last_read < 30)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tip = tr("%1 is responding").arg(url);
|
|
|
|
}
|
2022-02-08 03:56:04 +00:00
|
|
|
else if (seconds_since_last_read < 120)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
tip = tr("%1 last responded %2 ago").arg(url).arg(Formatter::get().timeToString(seconds_since_last_read));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tip = tr("%1 is not responding").arg(url);
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.networkLabel->setPixmap(pixmap);
|
|
|
|
ui_.networkLabel->setToolTip(tip);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onNetworkTimer()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
updateNetworkIcon();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::dataReadProgress()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!network_error_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
last_read_time_ = time(nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::dataSendProgress()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
last_send_time_ = time(nullptr);
|
2013-10-20 19:57:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void MainWindow::onNetworkResponse(QNetworkReply::NetworkError code, QString const& message)
|
2013-10-20 19:57:48 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const had_error = network_error_;
|
|
|
|
bool const have_error = code != QNetworkReply::NoError && code != QNetworkReply::UnknownContentError;
|
2014-04-27 00:33:19 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
network_error_ = have_error;
|
|
|
|
error_message_ = message;
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshSoon(REFRESH_TRAY_ICON);
|
2017-04-19 12:04:45 +00:00
|
|
|
updateNetworkIcon();
|
2014-04-27 00:33:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// Refresh our model if we've just gotten a clean connection to the session.
|
|
|
|
// That way we can rebuild after a restart of transmission-daemon
|
2020-05-27 21:53:12 +00:00
|
|
|
if (had_error && !have_error)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
model_.clear();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-10-20 19:57:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::wrongAuthentication()
|
2009-05-03 22:00:56 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.stop();
|
2017-04-19 12:04:45 +00:00
|
|
|
openSession();
|
2009-05-03 22:00:56 +00:00
|
|
|
}
|
2010-07-31 23:11:05 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
2010-07-31 23:11:05 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QMimeData const* mime = event->mimeData();
|
2010-07-31 23:11:05 +00:00
|
|
|
|
2020-05-29 17:40:07 +00:00
|
|
|
if (mime->hasFormat(QStringLiteral("application/x-bittorrent")) || mime->hasUrls() ||
|
|
|
|
mime->text().trimmed().endsWith(QStringLiteral(".torrent"), Qt::CaseInsensitive) ||
|
2022-02-13 04:16:55 +00:00
|
|
|
tr_magnet_metainfo{}.parseMagnet(mime->text().toStdString()))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2010-07-31 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::dropEvent(QDropEvent* event)
|
2010-07-31 23:11:05 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QStringList list;
|
2013-06-26 01:48:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (event->mimeData()->hasText())
|
2013-06-26 01:48:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
list = event->mimeData()->text().trimmed().split(QLatin1Char('\n'));
|
2013-06-26 01:48:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (event->mimeData()->hasUrls())
|
2013-06-26 01:48:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QUrl const& url : event->mimeData()->urls())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
list.append(url.toLocalFile());
|
|
|
|
}
|
2013-06-26 01:48:47 +00:00
|
|
|
}
|
2010-07-31 23:11:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& entry : list)
|
2013-06-09 20:18:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QString key = entry.trimmed();
|
2013-06-09 20:18:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!key.isEmpty())
|
2013-06-09 20:18:47 +00:00
|
|
|
{
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const url = QUrl(key); url.isLocalFile())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
key = url.toLocalFile();
|
|
|
|
}
|
2013-06-09 20:18:47 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
trApp->addTorrent(AddData(key));
|
2013-06-09 20:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-31 23:11:05 +00:00
|
|
|
}
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2022-01-23 15:57:21 +00:00
|
|
|
bool MainWindow::event(QEvent* e)
|
|
|
|
{
|
|
|
|
if (e->type() != QEvent::WindowActivate || !auto_add_clipboard_links)
|
|
|
|
{
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
}
|
|
|
|
|
2022-01-24 00:53:35 +00:00
|
|
|
if (auto const text = QGuiApplication::clipboard()->text().trimmed();
|
2022-02-13 04:16:55 +00:00
|
|
|
text.endsWith(QStringLiteral(".torrent"), Qt::CaseInsensitive) || tr_magnet_metainfo{}.parseMagnet(text.toStdString()))
|
2022-01-23 15:57:21 +00:00
|
|
|
{
|
2022-02-13 04:16:55 +00:00
|
|
|
for (auto const& entry : text.split(QLatin1Char('\n')))
|
2022-01-23 15:57:21 +00:00
|
|
|
{
|
2022-02-13 04:16:55 +00:00
|
|
|
auto key = entry.trimmed();
|
2022-01-23 15:57:21 +00:00
|
|
|
if (key.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
if (auto const url = QUrl{ key }; url.isLocalFile())
|
2022-01-23 15:57:21 +00:00
|
|
|
{
|
|
|
|
key = url.toLocalFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clipboard_processed_keys_.contains(key))
|
|
|
|
{
|
|
|
|
clipboard_processed_keys_.append(key);
|
|
|
|
trApp->addTorrent(AddData(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
}
|
|
|
|
|
2011-08-01 22:24:24 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::contextMenuEvent(QContextMenuEvent* event)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.menuTorrent->popup(event->globalPos());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|