2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2016-04-19 20:41:59 +00:00
|
|
|
* This file Copyright (C) 2009-2016 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
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"
|
|
|
|
#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
|
|
|
|
2015-08-06 20:28:44 +00:00
|
|
|
#define PREF_VARIANTS_KEY "pref-variants-list"
|
|
|
|
#define STATS_MODE_KEY "stats-mode"
|
|
|
|
#define SORT_MODE_KEY "sort-mode"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-29 17:40:07 +00:00
|
|
|
auto const TOTAL_RATIO_STATS_MODE_NAME = QStringLiteral("total-ratio");
|
|
|
|
auto const TOTAL_TRANSFER_STATS_MODE_NAME = QStringLiteral("total-transfer");
|
|
|
|
auto const SESSION_RATIO_STATS_MODE_NAME = QStringLiteral("session-ratio");
|
|
|
|
auto const SESSION_TRANSFER_STATS_MODE_NAME = QStringLiteral("session-transfer");
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
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:
|
2017-04-30 09:29:58 +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
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QIcon MainWindow::getStockIcon(QString const& name, int fallback)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QIcon icon = QIcon::fromTheme(name);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (icon.isNull() && fallback >= 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
icon = style()->standardIcon(QStyle::StandardPixmap(fallback), nullptr, this);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return icon;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QIcon MainWindow::addEmblem(QIcon base_icon, QStringList const& emblem_names)
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emblem_icon = QIcon::fromTheme(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;
|
|
|
|
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);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QPainter painter(&pixmap);
|
2020-05-27 21:53:12 +00:00
|
|
|
painter.drawPixmap(emblem_rect, emblem_pixmap, emblem_pixmap.rect());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool minimized) :
|
2020-05-27 21:53:12 +00:00
|
|
|
session_(session),
|
|
|
|
prefs_(prefs),
|
|
|
|
model_(model),
|
|
|
|
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-05-27 21:53:12 +00:00
|
|
|
ui_.listView->setStyle(new ListViewProxyStyle);
|
|
|
|
ui_.listView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// icons
|
2020-05-29 17:40:07 +00:00
|
|
|
QIcon const icon_play = getStockIcon(QStringLiteral("media-playback-start"), QStyle::SP_MediaPlay);
|
|
|
|
QIcon const icon_pause = getStockIcon(QStringLiteral("media-playback-pause"), QStyle::SP_MediaPause);
|
|
|
|
QIcon const icon_open = getStockIcon(QStringLiteral("document-open"), QStyle::SP_DialogOpenButton);
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_OpenFile->setIcon(icon_open);
|
|
|
|
ui_.action_AddURL->setIcon(addEmblem(icon_open,
|
2020-05-29 17:40:07 +00:00
|
|
|
QStringList() << QStringLiteral("emblem-web") << QStringLiteral("applications-internet")));
|
|
|
|
ui_.action_New->setIcon(getStockIcon(QStringLiteral("document-new"), QStyle::SP_DesktopIcon));
|
|
|
|
ui_.action_Properties->setIcon(getStockIcon(QStringLiteral("document-properties"), QStyle::SP_DesktopIcon));
|
|
|
|
ui_.action_OpenFolder->setIcon(getStockIcon(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);
|
2020-05-29 17:40:07 +00:00
|
|
|
ui_.action_Announce->setIcon(getStockIcon(QStringLiteral("network-transmit-receive")));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.action_Pause->setIcon(icon_pause);
|
2020-05-29 17:40:07 +00:00
|
|
|
ui_.action_Remove->setIcon(getStockIcon(QStringLiteral("list-remove"), QStyle::SP_TrashIcon));
|
|
|
|
ui_.action_Delete->setIcon(getStockIcon(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);
|
2020-05-29 17:40:07 +00:00
|
|
|
ui_.action_Quit->setIcon(getStockIcon(QStringLiteral("application-exit")));
|
|
|
|
ui_.action_SelectAll->setIcon(getStockIcon(QStringLiteral("edit-select-all")));
|
|
|
|
ui_.action_ReverseSortOrder->setIcon(getStockIcon(QStringLiteral("view-sort-ascending"), QStyle::SP_ArrowDown));
|
|
|
|
ui_.action_Preferences->setIcon(getStockIcon(QStringLiteral("preferences-system")));
|
|
|
|
ui_.action_Contents->setIcon(getStockIcon(QStringLiteral("help-contents"), QStyle::SP_DialogHelpButton));
|
|
|
|
ui_.action_About->setIcon(getStockIcon(QStringLiteral("help-about")));
|
|
|
|
ui_.action_QueueMoveTop->setIcon(getStockIcon(QStringLiteral("go-top")));
|
|
|
|
ui_.action_QueueMoveUp->setIcon(getStockIcon(QStringLiteral("go-up"), QStyle::SP_ArrowUp));
|
|
|
|
ui_.action_QueueMoveDown->setIcon(getStockIcon(QStringLiteral("go-down"), QStyle::SP_ArrowDown));
|
|
|
|
ui_.action_QueueMoveBottom->setIcon(getStockIcon(QStringLiteral("go-bottom")));
|
2020-05-27 21:53:12 +00:00
|
|
|
|
|
|
|
auto makeNetworkPixmap = [this](char const* name_in, QSize size = QSize(16, 16))
|
2019-11-06 21:09:04 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
auto const name = QString::fromUtf8(name_in);
|
2019-11-06 21:09:04 +00:00
|
|
|
QIcon const icon = getStockIcon(name, QStyle::SP_DriveNetIcon);
|
|
|
|
return icon.pixmap(size);
|
|
|
|
};
|
2020-05-27 21:53:12 +00:00
|
|
|
pixmap_network_error_ = makeNetworkPixmap("network-error");
|
|
|
|
pixmap_network_idle_ = makeNetworkPixmap("network-idle");
|
|
|
|
pixmap_network_receive_ = makeNetworkPixmap("network-receive");
|
|
|
|
pixmap_network_transmit_ = makeNetworkPixmap("network-transmit");
|
|
|
|
pixmap_network_transmit_receive_ = makeNetworkPixmap("network-transmit-receive");
|
2019-11-06 21:09:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// ui signals
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(ui_.action_Toolbar, SIGNAL(toggled(bool)), this, SLOT(setToolbarVisible(bool)));
|
|
|
|
connect(ui_.action_Filterbar, SIGNAL(toggled(bool)), this, SLOT(setFilterbarVisible(bool)));
|
|
|
|
connect(ui_.action_Statusbar, SIGNAL(toggled(bool)), this, SLOT(setStatusbarVisible(bool)));
|
|
|
|
connect(ui_.action_CompactView, SIGNAL(toggled(bool)), this, SLOT(setCompactView(bool)));
|
|
|
|
connect(ui_.action_ReverseSortOrder, SIGNAL(toggled(bool)), this, SLOT(setSortAscendingPref(bool)));
|
|
|
|
connect(ui_.action_Start, SIGNAL(triggered()), this, SLOT(startSelected()));
|
|
|
|
connect(ui_.action_QueueMoveTop, SIGNAL(triggered()), this, SLOT(queueMoveTop()));
|
|
|
|
connect(ui_.action_QueueMoveUp, SIGNAL(triggered()), this, SLOT(queueMoveUp()));
|
|
|
|
connect(ui_.action_QueueMoveDown, SIGNAL(triggered()), this, SLOT(queueMoveDown()));
|
|
|
|
connect(ui_.action_QueueMoveBottom, SIGNAL(triggered()), this, SLOT(queueMoveBottom()));
|
|
|
|
connect(ui_.action_StartNow, SIGNAL(triggered()), this, SLOT(startSelectedNow()));
|
|
|
|
connect(ui_.action_Pause, SIGNAL(triggered()), this, SLOT(pauseSelected()));
|
|
|
|
connect(ui_.action_Remove, SIGNAL(triggered()), this, SLOT(removeSelected()));
|
|
|
|
connect(ui_.action_Delete, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
|
|
|
connect(ui_.action_Verify, SIGNAL(triggered()), this, SLOT(verifySelected()));
|
|
|
|
connect(ui_.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()));
|
|
|
|
connect(ui_.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll()));
|
|
|
|
connect(ui_.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll()));
|
|
|
|
connect(ui_.action_OpenFile, SIGNAL(triggered()), this, SLOT(openTorrent()));
|
|
|
|
connect(ui_.action_AddURL, SIGNAL(triggered()), this, SLOT(openURL()));
|
|
|
|
connect(ui_.action_New, SIGNAL(triggered()), this, SLOT(newTorrent()));
|
|
|
|
connect(ui_.action_Preferences, SIGNAL(triggered()), this, SLOT(openPreferences()));
|
|
|
|
connect(ui_.action_Statistics, SIGNAL(triggered()), this, SLOT(openStats()));
|
|
|
|
connect(ui_.action_Donate, SIGNAL(triggered()), this, SLOT(openDonate()));
|
|
|
|
connect(ui_.action_About, SIGNAL(triggered()), this, SLOT(openAbout()));
|
|
|
|
connect(ui_.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
|
|
|
|
connect(ui_.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
|
|
|
|
connect(ui_.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard()));
|
|
|
|
connect(ui_.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
|
|
|
|
connect(ui_.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
|
|
|
|
connect(ui_.action_SessionDialog, SIGNAL(triggered()), this, SLOT(openSession()));
|
|
|
|
connect(ui_.listView, SIGNAL(activated(QModelIndex)), ui_.action_Properties, SLOT(trigger()));
|
|
|
|
connect(ui_.action_SelectAll, SIGNAL(triggered()), ui_.listView, SLOT(selectAll()));
|
|
|
|
connect(ui_.action_DeselectAll, SIGNAL(triggered()), ui_.listView, SLOT(clearSelection()));
|
|
|
|
connect(ui_.action_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
auto refreshActionSensitivitySoon = [this]() { refreshSoon(REFRESH_ACTION_SENSITIVITY); };
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&filter_model_, &TorrentFilter::rowsInserted, this, refreshActionSensitivitySoon);
|
|
|
|
connect(&filter_model_, &TorrentFilter::rowsRemoved, this, refreshActionSensitivitySoon);
|
|
|
|
connect(&model_, &TorrentModel::torrentsChanged, this, refreshActionSensitivitySoon);
|
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_);
|
2019-11-09 14:44:40 +00:00
|
|
|
auto refreshSoonAdapter = [this]() { refreshSoon(); };
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&model_, &TorrentModel::modelReset, this, refreshSoonAdapter);
|
|
|
|
connect(&model_, &TorrentModel::rowsRemoved, this, refreshSoonAdapter);
|
|
|
|
connect(&model_, &TorrentModel::rowsInserted, this, refreshSoonAdapter);
|
|
|
|
connect(&model_, &TorrentModel::dataChanged, this, refreshSoonAdapter);
|
|
|
|
|
|
|
|
ui_.listView->setModel(&filter_model_);
|
|
|
|
connect(ui_.listView->selectionModel(), &QItemSelectionModel::selectionChanged, refreshActionSensitivitySoon);
|
|
|
|
|
|
|
|
QPair<QAction*, int> const sort_modes[] =
|
|
|
|
{
|
|
|
|
qMakePair(ui_.action_SortByActivity, static_cast<int>(SortMode::SORT_BY_ACTIVITY)),
|
|
|
|
qMakePair(ui_.action_SortByAge, static_cast<int>(SortMode::SORT_BY_AGE)),
|
|
|
|
qMakePair(ui_.action_SortByETA, static_cast<int>(SortMode::SORT_BY_ETA)),
|
|
|
|
qMakePair(ui_.action_SortByName, static_cast<int>(SortMode::SORT_BY_NAME)),
|
|
|
|
qMakePair(ui_.action_SortByProgress, static_cast<int>(SortMode::SORT_BY_PROGRESS)),
|
|
|
|
qMakePair(ui_.action_SortByQueue, static_cast<int>(SortMode::SORT_BY_QUEUE)),
|
|
|
|
qMakePair(ui_.action_SortByRatio, static_cast<int>(SortMode::SORT_BY_RATIO)),
|
|
|
|
qMakePair(ui_.action_SortBySize, static_cast<int>(SortMode::SORT_BY_SIZE)),
|
|
|
|
qMakePair(ui_.action_SortByState, static_cast<int>(SortMode::SORT_BY_STATE))
|
2017-04-19 12:04:45 +00:00
|
|
|
};
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (auto const& mode : sort_modes)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
mode.first->setProperty(SORT_MODE_KEY, mode.second);
|
2020-05-27 21:53:12 +00:00
|
|
|
action_group->addAction(mode.first);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-10-19 20:30:26 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(action_group, SIGNAL(triggered(QAction*)), this, SLOT(onSortModeChanged(QAction*)));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
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);
|
|
|
|
connect(alt_speed_action_, SIGNAL(triggered()), this, SLOT(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-05-29 17:40:07 +00:00
|
|
|
tray_icon_.setIcon(QIcon::fromTheme(QStringLiteral("transmission-tray-icon"), qApp->windowIcon()));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&prefs_, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
|
|
|
|
connect(ui_.action_ShowMainWindow, SIGNAL(triggered(bool)), this, SLOT(toggleWindows(bool)));
|
|
|
|
connect(&tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
|
2017-04-19 12:04:45 +00:00
|
|
|
SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
|
|
|
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-05-27 21:53:12 +00:00
|
|
|
ui_.verticalLayout->insertWidget(0, filter_bar_ = new FilterBar(prefs_, model_, filter_model_));
|
|
|
|
|
|
|
|
auto refresh_header_soon = [this]() { refreshSoon(REFRESH_TORRENT_VIEW_HEADER); };
|
|
|
|
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);
|
|
|
|
connect(ui_.listView, SIGNAL(headerDoubleClicked()), filter_bar_, SLOT(clear()));
|
|
|
|
|
|
|
|
QList<int> init_keys;
|
|
|
|
init_keys << Prefs::MAIN_WINDOW_X << Prefs::SHOW_TRAY_ICON << Prefs::SORT_REVERSED << Prefs::SORT_MODE <<
|
|
|
|
Prefs::FILTERBAR <<
|
2017-04-19 12:04:45 +00:00
|
|
|
Prefs::STATUSBAR << Prefs::STATUSBAR_STATS << Prefs::TOOLBAR << Prefs::ALT_SPEED_LIMIT_ENABLED <<
|
|
|
|
Prefs::COMPACT_VIEW << Prefs::DSPEED << Prefs::DSPEED_ENABLED << Prefs::USPEED << Prefs::USPEED_ENABLED <<
|
|
|
|
Prefs::RATIO << Prefs::RATIO_ENABLED;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int const key : init_keys)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
refreshPref(key);
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto refresh_status_soon = [this]() { refreshSoon(REFRESH_STATUS_BAR); };
|
|
|
|
connect(&session_, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()));
|
|
|
|
connect(&session_, &Session::statsUpdated, this, refresh_status_soon);
|
|
|
|
connect(&session_, SIGNAL(dataReadProgress()), this, SLOT(dataReadProgress()));
|
|
|
|
connect(&session_, SIGNAL(dataSendProgress()), this, SLOT(dataSendProgress()));
|
|
|
|
connect(&session_, SIGNAL(httpAuthenticationRequired()), this, SLOT(wrongAuthentication()));
|
|
|
|
connect(&session_, SIGNAL(networkResponse(QNetworkReply::NetworkError, QString)), this,
|
2017-04-19 12:04:45 +00:00
|
|
|
SLOT(onNetworkResponse(QNetworkReply::NetworkError, QString)));
|
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
|
|
|
}
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
MainWindow::~MainWindow() = default;
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QVariantList const p = sender()->property(PREF_VARIANTS_KEY).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
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
int const minimum_speed_width =
|
|
|
|
ui_.downloadSpeedLabel->fontMetrics().boundingRect(Formatter::uploadSpeedToString(Speed::fromKBps(999.99))).width();
|
|
|
|
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-05-27 21:53:12 +00:00
|
|
|
connect(ui_.altSpeedButton, SIGNAL(clicked()), this, SLOT(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)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int const stock_speeds[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
|
|
|
|
int const current_value = prefs_.get<int>(pref);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
off_action = menu->addAction(tr("Unlimited"));
|
|
|
|
off_action->setCheckable(true);
|
|
|
|
off_action->setProperty(PREF_VARIANTS_KEY, QVariantList() << enabled_pref << false);
|
|
|
|
action_group->addAction(off_action);
|
|
|
|
connect(off_action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
on_action = menu->addAction(tr("Limited at %1").arg(Formatter::speedToString(Speed::fromKBps(current_value))));
|
|
|
|
on_action->setCheckable(true);
|
|
|
|
on_action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << current_value << enabled_pref << true);
|
|
|
|
action_group->addAction(on_action);
|
|
|
|
connect(on_action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int const i : stock_speeds)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(Formatter::speedToString(Speed::fromKBps(i)));
|
2020-05-27 21:53:12 +00:00
|
|
|
action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << i << enabled_pref << true);
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const initSeedRatioSubMenu = [this](QMenu* menu, QAction*& off_action, QAction*& on_action, int pref, int enabled_pref)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
double const 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
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* action_group = new QActionGroup(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
off_action = menu->addAction(tr("Seed Forever"));
|
|
|
|
off_action->setCheckable(true);
|
|
|
|
off_action->setProperty(PREF_VARIANTS_KEY, QVariantList() << enabled_pref << false);
|
|
|
|
action_group->addAction(off_action);
|
|
|
|
connect(off_action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
on_action = menu->addAction(tr("Stop at Ratio (%1)").arg(Formatter::ratioToString(current_value)));
|
|
|
|
on_action->setCheckable(true);
|
|
|
|
on_action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << current_value << enabled_pref << true);
|
|
|
|
action_group->addAction(on_action);
|
|
|
|
connect(on_action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
menu->addSeparator();
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (double const i : stock_ratios)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(Formatter::ratioToString(i));
|
2020-05-27 21:53:12 +00:00
|
|
|
action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << i << enabled_pref << true);
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(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
|
|
|
|
2020-05-27 21:53:12 +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);
|
2020-05-27 21:53:12 +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
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
initSeedRatioSubMenu(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
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
QPair<QAction*, QString> const stats_modes[] =
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +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-05-20 01:32:51 +00:00
|
|
|
auto* actionGroup = new QActionGroup(this);
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mode.first->setProperty(STATS_MODE_KEY, QString(mode.second));
|
|
|
|
actionGroup->addAction(mode.first);
|
|
|
|
menu->addAction(mode.first);
|
2015-08-06 20:28:44 +00:00
|
|
|
}
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onStatsModeChanged(QAction*)));
|
2014-12-18 01:30:50 +00:00
|
|
|
|
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
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onSortModeChanged(QAction* action)
|
2009-04-11 18:25:12 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::SORT_MODE, SortMode(action->property(SORT_MODE_KEY).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
|
2012-12-27 18:22:48 +00:00
|
|
|
#undef HAVE_OPEN_SELECT
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
|
|
|
#define HAVE_OPEN_SELECT
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static 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
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void openSelect(QString const& path)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QStringList script_args;
|
2020-05-29 17:40:07 +00:00
|
|
|
script_args << QStringLiteral("-e") <<
|
|
|
|
QStringLiteral("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(path);
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (files.isEmpty())
|
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;
|
|
|
|
int slash_index = first_file.indexOf(QLatin1Char('/'));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openDonate()
|
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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Utils::openDialog(about_dialog_, this);
|
2015-07-30 06:18:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::openHelp()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QStringLiteral("https://transmissionbt.com/help/gtk/%1.%2x").arg(MAJOR_VERSION).
|
2019-02-10 11:05:16 +00:00
|
|
|
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"));
|
2020-05-27 21:53:12 +00:00
|
|
|
QUrl const url(session_.getRemoteUrl());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!url.isEmpty())
|
|
|
|
{
|
|
|
|
//: Second (optional) part of main window title "Transmission - host:port" (added when connected to remote session);
|
|
|
|
//: 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-05-29 17:40:07 +00:00
|
|
|
tip = Formatter::downloadSpeedToString(stats.speed_down) + QStringLiteral(" ") + Formatter::uploadSpeedToString(
|
2020-05-27 21:53:12 +00:00
|
|
|
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-05-27 21:53:12 +00:00
|
|
|
tip = Formatter::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-05-27 21:53:12 +00:00
|
|
|
ui_.uploadSpeedLabel->setText(Formatter::uploadSpeedToString(stats.speed_up));
|
|
|
|
ui_.uploadSpeedLabel->setVisible(stats.peers_sending || stats.peers_receiving);
|
|
|
|
ui_.downloadSpeedLabel->setText(Formatter::downloadSpeedToString(stats.speed_down));
|
|
|
|
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-05-27 21:53:12 +00:00
|
|
|
QString const mode(prefs_.getString(Prefs::STATUSBAR_STATS));
|
2017-04-19 12:04:45 +00:00
|
|
|
QString str;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-29 17:40:07 +00:00
|
|
|
if (mode == SESSION_RATIO_STATS_MODE_NAME)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
str = tr("Ratio: %1").arg(Formatter::ratioToString(session_.getStats().ratio));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2020-05-29 17:40:07 +00:00
|
|
|
else if (mode == SESSION_TRANSFER_STATS_MODE_NAME)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_session_stats const& stats(session_.getStats());
|
2017-04-19 12:04:45 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
|
2019-02-10 11:05:16 +00:00
|
|
|
arg(Formatter::sizeToString(stats.uploadedBytes));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2020-05-29 17:40:07 +00:00
|
|
|
else if (mode == TOTAL_TRANSFER_STATS_MODE_NAME)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_session_stats const& stats(session_.getCumulativeStats());
|
2017-04-19 12:04:45 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
|
2019-02-10 11:05:16 +00:00
|
|
|
arg(Formatter::sizeToString(stats.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-05-29 17:40:07 +00:00
|
|
|
assert(mode == TOTAL_RATIO_STATS_MODE_NAME);
|
2020-05-27 21:53:12 +00:00
|
|
|
str = tr("Ratio: %1").arg(Formatter::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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int paused(0);
|
2019-11-06 23:31:41 +00:00
|
|
|
int selected(0);
|
2020-05-27 21:53:12 +00:00
|
|
|
int selected_and_can_announce(0);
|
|
|
|
int selected_and_paused(0);
|
|
|
|
int selected_and_queued(0);
|
|
|
|
int selected_with_metadata(0);
|
|
|
|
QAbstractItemModel const* model(ui_.listView->model());
|
|
|
|
QItemSelectionModel const* selection_model(ui_.listView->selectionModel());
|
|
|
|
bool const has_selection = selection_model->hasSelection();
|
|
|
|
int 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
|
2019-11-06 23:31:41 +00:00
|
|
|
auto const now = time(nullptr);
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int row = 0; row < row_count; ++row)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex const modelIndex(model->index(row, 0));
|
2019-11-12 01:37:05 +00:00
|
|
|
auto const& tor = model->data(modelIndex, TorrentModel::TorrentRole).value<Torrent const*>();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (tor != nullptr)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const is_selected = has_selection && selection_model->isSelected(modelIndex);
|
|
|
|
bool const is_paused = tor->isPaused();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_paused)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
++paused;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_selected)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2019-11-06 23:31:41 +00:00
|
|
|
++selected;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_paused)
|
2019-11-06 23:31:41 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
++selected_and_paused;
|
2019-11-06 23:31:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
if (tor->isQueued())
|
2019-11-06 23:31:41 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
++selected_and_queued;
|
2019-11-06 23:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tor->hasMetadata())
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
++selected_with_metadata;
|
2019-11-06 23:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tor->canManualAnnounceAt(now))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
++selected_and_can_announce;
|
2019-11-06 23:31:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-10-10 00:39:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const have_selection(selected > 0);
|
|
|
|
bool const have_selection_with_metadata = selected_with_metadata > 0;
|
|
|
|
bool 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);
|
|
|
|
ui_.action_StartAll->setEnabled(paused > 0);
|
|
|
|
ui_.action_PauseAll->setEnabled(paused < row_count);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onStatsModeChanged(QAction* action)
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::STATUSBAR_STATS, action->property(STATS_MODE_KEY).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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// activateWindow ();
|
|
|
|
raise();
|
|
|
|
qApp->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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool b;
|
|
|
|
int i;
|
|
|
|
QString str;
|
2020-05-27 21:53:12 +00:00
|
|
|
QActionGroup* action_group;
|
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);
|
|
|
|
action_group = ui_.action_TotalRatio->actionGroup();
|
|
|
|
assert(action_group != nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QAction* action : action_group->actions())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
action->setChecked(str == action->property(STATS_MODE_KEY).toString());
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
action_group = ui_.action_SortByActivity->actionGroup();
|
|
|
|
assert(action_group != nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QAction* action : action_group->actions())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
action->setChecked(i == action->property(SORT_MODE_KEY).toInt());
|
|
|
|
}
|
|
|
|
|
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:
|
2020-05-27 21:53:12 +00:00
|
|
|
dlimit_on_action_->setText(tr("Limited at %1").arg(Formatter::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:
|
2020-05-27 21:53:12 +00:00
|
|
|
ulimit_on_action_->setText(tr("Limited at %1").arg(Formatter::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-05-27 21:53:12 +00:00
|
|
|
ratio_on_action_->setText(tr("Stop at Ratio (%1)").arg(Formatter::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);
|
2017-04-19 12:04:45 +00:00
|
|
|
qApp->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:
|
|
|
|
{
|
2015-04-20 09:28:26 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) // QTBUG-33537
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QItemSelectionModel* selection_model(ui_.listView->selectionModel());
|
|
|
|
QItemSelection const selection(selection_model->selection());
|
|
|
|
QModelIndex const current_index(selection_model->currentIndex());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2015-04-20 09:28:26 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
b = prefs_.getBool(key);
|
|
|
|
ui_.action_CompactView->setChecked(b);
|
|
|
|
ui_.listView->setItemDelegate(b ? torrent_delegate_min_ : torrent_delegate_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2015-04-20 09:28:26 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) // QTBUG-33537
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
selectionModel->clear();
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.listView->reset(); // force the rows to resize
|
2017-04-19 12:04:45 +00:00
|
|
|
selectionModel->select(selection, QItemSelectionModel::Select);
|
2020-05-27 21:53:12 +00:00
|
|
|
selectionModel->setCurrentIndex(current_index, QItemSelectionModel::NoUpdate);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2015-04-20 09:28:26 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
2010-09-18 15:51:38 +00:00
|
|
|
}
|
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:
|
2020-05-27 21:53:12 +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)") :
|
2017-04-19 12:04:45 +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));
|
|
|
|
ui_.altSpeedButton->setToolTip(fmt.arg(Formatter::speedToString(d)).arg(Formatter::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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2015-01-29 21:53:05 +00:00
|
|
|
namespace
|
|
|
|
{
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2020-05-29 17:40:07 +00:00
|
|
|
auto const SHOW_OPTIONS_CHECKBOX_NAME = QStringLiteral("show-options-checkbox");
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QFileDialog* d;
|
2020-05-27 21:53:12 +00:00
|
|
|
d = new QFileDialog(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
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* const l = qobject_cast<QGridLayout*>(d->layout());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (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));
|
2017-04-19 12:04:45 +00:00
|
|
|
b->setObjectName(SHOW_OPTIONS_CHECKBOX_NAME);
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(d, SIGNAL(filesSelected(QStringList)), this, SLOT(addTorrents(QStringList)));
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QString str = qApp->clipboard()->text(QClipboard::Selection);
|
2011-01-21 21:51:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!AddData::isSupported(str))
|
|
|
|
{
|
|
|
|
str = qApp->clipboard()->text(QClipboard::Clipboard);
|
|
|
|
}
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
addTorrent(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
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const* const file_dialog = qobject_cast<QFileDialog const*>(sender());
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_dialog != nullptr)
|
2013-09-14 22:50:25 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +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-05-27 21:53:12 +00:00
|
|
|
addTorrent(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();
|
|
|
|
qApp->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);
|
2017-04-19 12:04:45 +00:00
|
|
|
qApp->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;
|
|
|
|
int count;
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
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?") :
|
2017-04-30 09:29:58 +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.") :
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
secondary_text = count == 1 ? tr("This torrent is connected to peers.") :
|
2017-04-19 12:04:45 +00:00
|
|
|
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.") :
|
2017-04-19 12:04:45 +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.") :
|
2017-04-19 12:04:45 +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-05-27 21:53:12 +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_;
|
|
|
|
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);
|
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (seconds_since_last_read < 60 * 2)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tip = tr("%1 last responded %2 ago").arg(url).arg(Formatter::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) ||
|
|
|
|
mime->text().startsWith(QStringLiteral("magnet:"), Qt::CaseInsensitive))
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QUrl const url(key);
|
2013-06-09 20:18:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (url.isLocalFile())
|
|
|
|
{
|
|
|
|
key = url.toLocalFile();
|
|
|
|
}
|
2013-06-09 20:18:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
qApp->addTorrent(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
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
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
|
|
|
}
|