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>
|
|
|
|
|
2010-07-31 23:11:05 +00:00
|
|
|
#include <QtGui>
|
2013-09-14 22:50:25 +00:00
|
|
|
#include <QCheckBox>
|
2014-12-12 21:47:22 +00:00
|
|
|
#include <QIcon>
|
2017-02-18 18:22:34 +00:00
|
|
|
#include <QPainter>
|
2013-07-27 21:58:14 +00:00
|
|
|
#include <QProxyStyle>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QLatin1String const TotalRatioStatsModeName("total-ratio");
|
|
|
|
QLatin1String const TotalTransferStatsModeName("total-transfer");
|
|
|
|
QLatin1String const SessionRatioStatsModeName("session-ratio");
|
|
|
|
QLatin1String const SessionTransferStatsModeName("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-20 16:02:19 +00:00
|
|
|
int styleHint(StyleHint hint, QStyleOption const* option = 0, QWidget const* widget = 0,
|
2017-04-19 12:04:45 +00:00
|
|
|
QStyleHintReturn* returnData = 0) const
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
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-19 12:04:45 +00:00
|
|
|
if (icon.isNull() && (fallback >= 0))
|
|
|
|
{
|
|
|
|
icon = style()->standardIcon(QStyle::StandardPixmap(fallback), 0, this);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QIcon MainWindow::getStockIcon(QString const& name, int fallback, QStringList const& emblemNames)
|
2017-02-18 18:22:34 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QIcon baseIcon = getStockIcon(name, fallback);
|
2017-02-18 18:22:34 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (baseIcon.isNull())
|
2017-02-18 18:22:34 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return baseIcon;
|
2017-02-18 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QIcon emblemIcon;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& emblemName : emblemNames)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
emblemIcon = QIcon::fromTheme(emblemName);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!emblemIcon.isNull())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (emblemIcon.isNull())
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return baseIcon;
|
2015-08-06 20:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QIcon icon;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QSize const& size : baseIcon.availableSizes())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QSize const emblemSize = size / 2;
|
|
|
|
QRect const emblemRect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom | Qt::AlignRight, emblemSize,
|
2017-04-19 12:04:45 +00:00
|
|
|
QRect(QPoint(0, 0), size));
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QPixmap pixmap = baseIcon.pixmap(size);
|
|
|
|
QPixmap emblemPixmap = emblemIcon.pixmap(emblemSize);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QPainter painter(&pixmap);
|
|
|
|
painter.drawPixmap(emblemRect, emblemPixmap, emblemPixmap.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool minimized) :
|
|
|
|
mySession(session),
|
|
|
|
myPrefs(prefs),
|
|
|
|
myModel(model),
|
|
|
|
myLastFullUpdateTime(0),
|
|
|
|
mySessionDialog(),
|
|
|
|
myPrefsDialog(),
|
|
|
|
myAboutDialog(),
|
|
|
|
myStatsDialog(),
|
|
|
|
myDetailsDialog(),
|
|
|
|
myFilterModel(prefs),
|
|
|
|
myTorrentDelegate(new TorrentDelegate(this)),
|
|
|
|
myTorrentDelegateMin(new TorrentDelegateMin(this)),
|
|
|
|
myLastSendTime(0),
|
|
|
|
myLastReadTime(0),
|
|
|
|
myNetworkTimer(this),
|
|
|
|
myNetworkError(false),
|
|
|
|
myRefreshTrayIconTimer(this),
|
|
|
|
myRefreshActionSensitivityTimer(this)
|
|
|
|
{
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
|
|
|
QAction* sep = new QAction(this);
|
|
|
|
sep->setSeparator(true);
|
|
|
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
ui.listView->setStyle(new ListViewProxyStyle);
|
|
|
|
ui.listView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
|
|
|
// icons
|
|
|
|
ui.action_OpenFile->setIcon(getStockIcon(QLatin1String("document-open"), QStyle::SP_DialogOpenButton));
|
|
|
|
ui.action_AddURL->setIcon(getStockIcon(QLatin1String("document-open"), QStyle::SP_DialogOpenButton,
|
|
|
|
QStringList() << QLatin1String("emblem-web") << QLatin1String("applications-internet")));
|
|
|
|
ui.action_New->setIcon(getStockIcon(QLatin1String("document-new"), QStyle::SP_DesktopIcon));
|
|
|
|
ui.action_Properties->setIcon(getStockIcon(QLatin1String("document-properties"), QStyle::SP_DesktopIcon));
|
|
|
|
ui.action_OpenFolder->setIcon(getStockIcon(QLatin1String("folder-open"), QStyle::SP_DirOpenIcon));
|
|
|
|
ui.action_Start->setIcon(getStockIcon(QLatin1String("media-playback-start"), QStyle::SP_MediaPlay));
|
|
|
|
ui.action_StartNow->setIcon(getStockIcon(QLatin1String("media-playback-start"), QStyle::SP_MediaPlay));
|
|
|
|
ui.action_Announce->setIcon(getStockIcon(QLatin1String("network-transmit-receive")));
|
|
|
|
ui.action_Pause->setIcon(getStockIcon(QLatin1String("media-playback-pause"), QStyle::SP_MediaPause));
|
|
|
|
ui.action_Remove->setIcon(getStockIcon(QLatin1String("list-remove"), QStyle::SP_TrashIcon));
|
|
|
|
ui.action_Delete->setIcon(getStockIcon(QLatin1String("edit-delete"), QStyle::SP_TrashIcon));
|
|
|
|
ui.action_StartAll->setIcon(getStockIcon(QLatin1String("media-playback-start"), QStyle::SP_MediaPlay));
|
|
|
|
ui.action_PauseAll->setIcon(getStockIcon(QLatin1String("media-playback-pause"), QStyle::SP_MediaPause));
|
|
|
|
ui.action_Quit->setIcon(getStockIcon(QLatin1String("application-exit")));
|
|
|
|
ui.action_SelectAll->setIcon(getStockIcon(QLatin1String("edit-select-all")));
|
|
|
|
ui.action_ReverseSortOrder->setIcon(getStockIcon(QLatin1String("view-sort-ascending"), QStyle::SP_ArrowDown));
|
|
|
|
ui.action_Preferences->setIcon(getStockIcon(QLatin1String("preferences-system")));
|
|
|
|
ui.action_Contents->setIcon(getStockIcon(QLatin1String("help-contents"), QStyle::SP_DialogHelpButton));
|
|
|
|
ui.action_About->setIcon(getStockIcon(QLatin1String("help-about")));
|
|
|
|
ui.action_QueueMoveTop->setIcon(getStockIcon(QLatin1String("go-top")));
|
|
|
|
ui.action_QueueMoveUp->setIcon(getStockIcon(QLatin1String("go-up"), QStyle::SP_ArrowUp));
|
|
|
|
ui.action_QueueMoveDown->setIcon(getStockIcon(QLatin1String("go-down"), QStyle::SP_ArrowDown));
|
|
|
|
ui.action_QueueMoveBottom->setIcon(getStockIcon(QLatin1String("go-bottom")));
|
|
|
|
|
|
|
|
// ui signals
|
|
|
|
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()));
|
|
|
|
|
|
|
|
// signals
|
|
|
|
connect(ui.action_SelectAll, SIGNAL(triggered()), ui.listView, SLOT(selectAll()));
|
|
|
|
connect(ui.action_DeselectAll, SIGNAL(triggered()), ui.listView, SLOT(clearSelection()));
|
|
|
|
|
|
|
|
connect(&myFilterModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(refreshActionSensitivitySoon()));
|
|
|
|
connect(&myFilterModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(refreshActionSensitivitySoon()));
|
|
|
|
|
|
|
|
connect(ui.action_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
|
|
|
|
|
|
|
// torrent view
|
|
|
|
myFilterModel.setSourceModel(&myModel);
|
|
|
|
connect(&myModel, SIGNAL(modelReset()), this, SLOT(onModelReset()));
|
|
|
|
connect(&myModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(onModelReset()));
|
|
|
|
connect(&myModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(onModelReset()));
|
|
|
|
connect(&myModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(refreshTrayIconSoon()));
|
|
|
|
|
|
|
|
ui.listView->setModel(&myFilterModel);
|
|
|
|
connect(ui.listView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
|
|
|
|
SLOT(refreshActionSensitivitySoon()));
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QPair<QAction*, int> const sortModes[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
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))
|
|
|
|
};
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QActionGroup* actionGroup = new QActionGroup(this);
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (auto const& mode : sortModes)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
mode.first->setProperty(SORT_MODE_KEY, mode.second);
|
|
|
|
actionGroup->addAction(mode.first);
|
|
|
|
}
|
2015-10-19 20:30:26 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSortModeChanged(QAction*)));
|
|
|
|
|
|
|
|
myAltSpeedAction = new QAction(tr("Speed Limits"), this);
|
|
|
|
myAltSpeedAction->setIcon(ui.altSpeedButton->icon());
|
|
|
|
myAltSpeedAction->setCheckable(true);
|
|
|
|
connect(myAltSpeedAction, SIGNAL(triggered()), this, SLOT(toggleSpeedMode()));
|
|
|
|
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
|
|
menu->addAction(ui.action_OpenFile);
|
|
|
|
menu->addAction(ui.action_AddURL);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui.action_ShowMainWindow);
|
|
|
|
menu->addAction(ui.action_ShowMessageLog);
|
|
|
|
menu->addAction(ui.action_About);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui.action_StartAll);
|
|
|
|
menu->addAction(ui.action_PauseAll);
|
|
|
|
menu->addAction(myAltSpeedAction);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui.action_Quit);
|
|
|
|
myTrayIcon.setContextMenu(menu);
|
|
|
|
myTrayIcon.setIcon(QIcon::fromTheme(QLatin1String("transmission-tray-icon"), qApp->windowIcon()));
|
|
|
|
|
|
|
|
connect(&myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
|
|
|
|
connect(ui.action_ShowMainWindow, SIGNAL(triggered(bool)), this, SLOT(toggleWindows(bool)));
|
|
|
|
connect(&myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
|
|
|
|
SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
|
|
|
toggleWindows(!minimized);
|
|
|
|
ui.action_TrayIcon->setChecked(minimized || prefs.getBool(Prefs::SHOW_TRAY_ICON));
|
|
|
|
|
|
|
|
initStatusBar();
|
|
|
|
ui.verticalLayout->insertWidget(0, myFilterBar = new FilterBar(myPrefs, myModel, myFilterModel));
|
|
|
|
|
|
|
|
connect(&myModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(refreshTorrentViewHeader()));
|
|
|
|
connect(&myModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(refreshTorrentViewHeader()));
|
|
|
|
connect(&myFilterModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(refreshTorrentViewHeader()));
|
|
|
|
connect(&myFilterModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(refreshTorrentViewHeader()));
|
|
|
|
connect(ui.listView, SIGNAL(headerDoubleClicked()), myFilterBar, SLOT(clear()));
|
|
|
|
|
|
|
|
QList<int> initKeys;
|
|
|
|
initKeys << Prefs::MAIN_WINDOW_X << Prefs::SHOW_TRAY_ICON << Prefs::SORT_REVERSED << Prefs::SORT_MODE << Prefs::FILTERBAR <<
|
|
|
|
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;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const key : initKeys)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
refreshPref(key);
|
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(&mySession, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()));
|
|
|
|
connect(&mySession, SIGNAL(statsUpdated()), this, SLOT(refreshStatusBar()));
|
|
|
|
connect(&mySession, SIGNAL(dataReadProgress()), this, SLOT(dataReadProgress()));
|
|
|
|
connect(&mySession, SIGNAL(dataSendProgress()), this, SLOT(dataSendProgress()));
|
|
|
|
connect(&mySession, SIGNAL(httpAuthenticationRequired()), this, SLOT(wrongAuthentication()));
|
|
|
|
connect(&mySession, SIGNAL(networkResponse(QNetworkReply::NetworkError, QString)), this,
|
|
|
|
SLOT(onNetworkResponse(QNetworkReply::NetworkError, QString)));
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mySession.isServer())
|
2009-05-06 13:39:48 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(&myNetworkTimer, SIGNAL(timeout()), this, SLOT(onNetworkTimer()));
|
|
|
|
myNetworkTimer.start(1000);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(&myRefreshTrayIconTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIcon()));
|
|
|
|
connect(&myRefreshActionSensitivityTimer, SIGNAL(timeout()), this, SLOT(refreshActionSensitivity()));
|
2011-07-13 17:22:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshActionSensitivitySoon();
|
|
|
|
refreshTrayIconSoon();
|
|
|
|
refreshStatusBar();
|
|
|
|
refreshTitle();
|
|
|
|
refreshTorrentViewHeader();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
MainWindow::~MainWindow()
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myModel.clear();
|
2009-05-03 18:35:33 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onModelReset()
|
2009-05-03 18:35:33 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshTitle();
|
|
|
|
refreshActionSensitivitySoon();
|
|
|
|
refreshStatusBar();
|
|
|
|
refreshTrayIconSoon();
|
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-19 12:04:45 +00:00
|
|
|
assert((p.size() % 2) == 0);
|
|
|
|
|
|
|
|
for (int i = 0, n = p.size(); i < n; i += 2)
|
|
|
|
{
|
|
|
|
myPrefs.set(p[i].toInt(), p[i + 1]);
|
|
|
|
}
|
2009-04-14 22:05:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::onSetPrefs(bool isChecked)
|
2009-04-14 22:05:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (isChecked)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.optionsButton->setMenu(createOptionsMenu());
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int const minimumSpeedWidth = ui.downloadSpeedLabel->fontMetrics().width(Formatter::uploadSpeedToString(Speed::fromKBps(
|
2017-04-19 12:04:45 +00:00
|
|
|
999.99)));
|
|
|
|
ui.downloadSpeedLabel->setMinimumWidth(minimumSpeedWidth);
|
|
|
|
ui.uploadSpeedLabel->setMinimumWidth(minimumSpeedWidth);
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.statsModeButton->setMenu(createStatsModeMenu());
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
auto const initSpeedSubMenu = [this](QMenu* menu, QAction*& offAction, QAction*& onAction, int pref, int enabledPref)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const stockSpeeds[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
|
|
|
|
int const currentValue = myPrefs.get<int>(pref);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
QActionGroup* actionGroup = new QActionGroup(this);
|
|
|
|
|
|
|
|
offAction = menu->addAction(tr("Unlimited"));
|
|
|
|
offAction->setCheckable(true);
|
|
|
|
offAction->setProperty(PREF_VARIANTS_KEY, QVariantList() << enabledPref << false);
|
|
|
|
actionGroup->addAction(offAction);
|
|
|
|
connect(offAction, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
|
|
|
|
|
|
|
onAction = menu->addAction(tr("Limited at %1").arg(Formatter::speedToString(Speed::fromKBps(currentValue))));
|
|
|
|
onAction->setCheckable(true);
|
|
|
|
onAction->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << currentValue << enabledPref << true);
|
|
|
|
actionGroup->addAction(onAction);
|
|
|
|
connect(onAction, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const i : stockSpeeds)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(Formatter::speedToString(Speed::fromKBps(i)));
|
|
|
|
action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << i << enabledPref << true);
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
auto const initSeedRatioSubMenu = [this](QMenu* menu, QAction*& offAction, QAction*& onAction, int pref, int enabledPref)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
double const stockRatios[] = { 0.25, 0.50, 0.75, 1, 1.5, 2, 3 };
|
|
|
|
double const currentValue = myPrefs.get<double>(pref);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QActionGroup* actionGroup = new QActionGroup(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
offAction = menu->addAction(tr("Seed Forever"));
|
|
|
|
offAction->setCheckable(true);
|
|
|
|
offAction->setProperty(PREF_VARIANTS_KEY, QVariantList() << enabledPref << false);
|
|
|
|
actionGroup->addAction(offAction);
|
|
|
|
connect(offAction, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)));
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
onAction = menu->addAction(tr("Stop at Ratio (%1)").arg(Formatter::ratioToString(currentValue)));
|
|
|
|
onAction->setCheckable(true);
|
|
|
|
onAction->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << currentValue << enabledPref << true);
|
|
|
|
actionGroup->addAction(onAction);
|
|
|
|
connect(onAction, 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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (double const i : stockRatios)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
QAction* action = menu->addAction(Formatter::ratioToString(i));
|
|
|
|
action->setProperty(PREF_VARIANTS_KEY, QVariantList() << pref << i << enabledPref << true);
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
};
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QMenu* menu = new QMenu(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
initSpeedSubMenu(menu->addMenu(tr("Limit Download Speed")), myDlimitOffAction, myDlimitOnAction, Prefs::DSPEED,
|
|
|
|
Prefs::DSPEED_ENABLED);
|
|
|
|
initSpeedSubMenu(menu->addMenu(tr("Limit Upload Speed")), myUlimitOffAction, myUlimitOnAction, Prefs::USPEED,
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
initSeedRatioSubMenu(menu->addMenu(tr("Stop Seeding at Ratio")), myRatioOffAction, myRatioOnAction, Prefs::RATIO,
|
|
|
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QPair<QAction*, QLatin1String> const statsModes[] =
|
2015-08-06 20:28:44 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
qMakePair(ui.action_TotalRatio, TotalRatioStatsModeName),
|
|
|
|
qMakePair(ui.action_TotalTransfer, TotalTransferStatsModeName),
|
|
|
|
qMakePair(ui.action_SessionRatio, SessionRatioStatsModeName),
|
|
|
|
qMakePair(ui.action_SessionTransfer, SessionTransferStatsModeName)
|
2015-08-06 20:28:44 +00:00
|
|
|
};
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QActionGroup* actionGroup = new QActionGroup(this);
|
|
|
|
QMenu* menu = new QMenu(this);
|
2015-08-06 20:28:44 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (auto const& mode : statsModes)
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Q_UNUSED(event);
|
2013-01-01 20:02:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Q_UNUSED(event);
|
2013-01-01 20:02:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!isVisible())
|
|
|
|
{
|
|
|
|
ui.action_ShowMainWindow->setChecked(false);
|
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Utils::openDialog(mySessionDialog, mySession, myPrefs, 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Utils::openDialog(myPrefsDialog, mySession, myPrefs, 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Utils::openDialog(myDetailsDialog, mySession, myPrefs, myModel, this);
|
|
|
|
myDetailsDialog->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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
RelocateDialog* d = new RelocateDialog(mySession, myModel, getSelectedTorrents(), this);
|
|
|
|
d->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
d->show();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const explorer = QLatin1String("explorer");
|
2017-04-19 12:04:45 +00:00
|
|
|
QString param;
|
|
|
|
|
|
|
|
if (!QFileInfo(path).isDir())
|
|
|
|
{
|
|
|
|
param = QLatin1String("/select,");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
QStringList scriptArgs;
|
|
|
|
scriptArgs << QLatin1String("-e") <<
|
|
|
|
QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(path);
|
|
|
|
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
|
|
|
|
|
|
|
|
scriptArgs.clear();
|
|
|
|
scriptArgs << QLatin1String("-e") << QLatin1String("tell application \"Finder\" to activate");
|
|
|
|
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
|
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-19 12:04:45 +00:00
|
|
|
void MainWindow::openFolder()
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QSet<int> const selectedTorrents = getSelectedTorrents();
|
2015-10-04 06:16:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (selectedTorrents.size() != 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrentId(*selectedTorrents.begin());
|
|
|
|
Torrent const* tor(myModel.getTorrentFromId(torrentId));
|
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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const firstfile = files.at(0).filename;
|
2017-04-19 12:04:45 +00:00
|
|
|
int slashIndex = firstfile.indexOf(QLatin1Char('/'));
|
|
|
|
|
|
|
|
if (slashIndex > -1)
|
|
|
|
{
|
|
|
|
path = path + QLatin1Char('/') + firstfile.left(slashIndex);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
openSelect(path + QLatin1Char('/') + firstfile);
|
|
|
|
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());
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Utils::openDialog(myStatsDialog, mySession, 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QLatin1String("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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Utils::openDialog(myAboutDialog, 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromLatin1("https://transmissionbt.com/help/gtk/%1.%2x").arg(MAJOR_VERSION).
|
|
|
|
arg(MINOR_VERSION / 10)));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshTitle()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QString title(QLatin1String("Transmission"));
|
2017-04-20 16:02:19 +00:00
|
|
|
QUrl const url(mySession.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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshTrayIconSoon()
|
2011-07-13 17:22:01 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myRefreshTrayIconTimer.isActive())
|
2011-07-13 17:22:01 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myRefreshTrayIconTimer.setSingleShot(true);
|
|
|
|
myRefreshTrayIconTimer.start(100);
|
2011-07-13 17:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
void MainWindow::refreshTrayIcon()
|
2010-08-05 15:01:40 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Speed upSpeed, downSpeed;
|
|
|
|
size_t upCount, downCount;
|
|
|
|
QString tip;
|
2010-08-05 15:01:40 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
myModel.getTransferSpeed(upSpeed, upCount, downSpeed, downCount);
|
2013-02-07 21:07:16 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (myNetworkError)
|
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
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (!upCount && !downCount)
|
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
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (downCount)
|
2013-02-07 21:07:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tip = Formatter::downloadSpeedToString(downSpeed) + QLatin1String(" ") + Formatter::uploadSpeedToString(upSpeed);
|
2013-02-07 21:07:16 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (upCount)
|
2013-02-07 21:07:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tip = Formatter::uploadSpeedToString(upSpeed);
|
2013-02-07 21:07:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
myTrayIcon.setToolTip(tip);
|
2010-08-05 15:01:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::refreshStatusBar()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Speed upSpeed, downSpeed;
|
|
|
|
size_t upCount, downCount;
|
|
|
|
myModel.getTransferSpeed(upSpeed, upCount, downSpeed, downCount);
|
2013-02-07 21:07:16 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.uploadSpeedLabel->setText(Formatter::uploadSpeedToString(upSpeed));
|
|
|
|
ui.uploadSpeedLabel->setVisible(downCount || upCount);
|
|
|
|
ui.downloadSpeedLabel->setText(Formatter::downloadSpeedToString(downSpeed));
|
|
|
|
ui.downloadSpeedLabel->setVisible(downCount);
|
2009-05-02 14:25:18 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.networkLabel->setVisible(!mySession.isServer());
|
2009-05-06 13:46:10 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const mode(myPrefs.getString(Prefs::STATUSBAR_STATS));
|
2017-04-19 12:04:45 +00:00
|
|
|
QString str;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mode == SessionRatioStatsModeName)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = tr("Ratio: %1").arg(Formatter::ratioToString(mySession.getStats().ratio));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (mode == SessionTransferStatsModeName)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session_stats const& stats(mySession.getStats());
|
2017-04-19 12:04:45 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
|
|
|
|
arg(Formatter::sizeToString(stats.uploadedBytes));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (mode == TotalTransferStatsModeName)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session_stats const& stats(mySession.getCumulativeStats());
|
2017-04-19 12:04:45 +00:00
|
|
|
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
assert(mode == TotalRatioStatsModeName);
|
|
|
|
str = tr("Ratio: %1").arg(Formatter::ratioToString(mySession.getCumulativeStats().ratio));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const totalCount = myModel.rowCount();
|
|
|
|
int const visibleCount = myFilterModel.rowCount();
|
2011-07-19 21:19:18 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (visibleCount == totalCount)
|
|
|
|
{
|
|
|
|
ui.listView->setHeaderText(QString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.listView->setHeaderText(tr("Showing %L1 of %Ln torrent(s)", 0, totalCount).arg(visibleCount));
|
|
|
|
}
|
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::refreshActionSensitivitySoon()
|
2011-07-19 21:19:18 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myRefreshActionSensitivityTimer.isActive())
|
2011-07-19 21:19:18 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myRefreshActionSensitivityTimer.setSingleShot(true);
|
|
|
|
myRefreshActionSensitivityTimer.start(100);
|
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 selected(0);
|
|
|
|
int paused(0);
|
|
|
|
int queued(0);
|
|
|
|
int selectedAndPaused(0);
|
|
|
|
int selectedAndQueued(0);
|
|
|
|
int selectedWithMetadata(0);
|
|
|
|
int canAnnounce(0);
|
2017-04-20 16:02:19 +00:00
|
|
|
QAbstractItemModel const* model(ui.listView->model());
|
|
|
|
QItemSelectionModel const* selectionModel(ui.listView->selectionModel());
|
|
|
|
int const rowCount(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
|
|
|
|
for (int row = 0; row < rowCount; ++row)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex const modelIndex(model->index(row, 0));
|
2017-04-19 12:04:45 +00:00
|
|
|
assert(model == modelIndex.model());
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent const* tor(model->data(modelIndex, TorrentModel::TorrentRole).value<Torrent const*>());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (tor)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const isSelected(selectionModel->isSelected(modelIndex));
|
|
|
|
bool const isPaused(tor->isPaused());
|
|
|
|
bool const isQueued(tor->isQueued());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (isSelected)
|
|
|
|
{
|
|
|
|
++selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isQueued)
|
|
|
|
{
|
|
|
|
++queued;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPaused)
|
|
|
|
{
|
|
|
|
++paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSelected && isPaused)
|
|
|
|
{
|
|
|
|
++selectedAndPaused;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSelected && isQueued)
|
|
|
|
{
|
|
|
|
++selectedAndQueued;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSelected && tor->hasMetadata())
|
|
|
|
{
|
|
|
|
++selectedWithMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tor->canManualAnnounce())
|
|
|
|
{
|
|
|
|
++canAnnounce;
|
|
|
|
}
|
2009-10-10 00:39:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const haveSelection(selected > 0);
|
|
|
|
bool const haveSelectionWithMetadata = selectedWithMetadata > 0;
|
|
|
|
bool const oneSelection(selected == 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
ui.action_Verify->setEnabled(haveSelectionWithMetadata);
|
|
|
|
ui.action_Remove->setEnabled(haveSelection);
|
|
|
|
ui.action_Delete->setEnabled(haveSelection);
|
|
|
|
ui.action_Properties->setEnabled(haveSelection);
|
|
|
|
ui.action_DeselectAll->setEnabled(haveSelection);
|
|
|
|
ui.action_SetLocation->setEnabled(haveSelection);
|
|
|
|
|
|
|
|
ui.action_OpenFolder->setEnabled(oneSelection && haveSelectionWithMetadata && mySession.isLocal());
|
|
|
|
ui.action_CopyMagnetToClipboard->setEnabled(oneSelection);
|
|
|
|
|
|
|
|
ui.action_SelectAll->setEnabled(selected < rowCount);
|
|
|
|
ui.action_StartAll->setEnabled(paused > 0);
|
|
|
|
ui.action_PauseAll->setEnabled(paused < rowCount);
|
|
|
|
ui.action_Start->setEnabled(selectedAndPaused > 0);
|
|
|
|
ui.action_StartNow->setEnabled(selectedAndPaused + selectedAndQueued > 0);
|
|
|
|
ui.action_Pause->setEnabled(selectedAndPaused < selected);
|
|
|
|
ui.action_Announce->setEnabled(selected > 0 && (canAnnounce == selected));
|
|
|
|
|
|
|
|
ui.action_QueueMoveTop->setEnabled(haveSelection);
|
|
|
|
ui.action_QueueMoveUp->setEnabled(haveSelection);
|
|
|
|
ui.action_QueueMoveDown->setEnabled(haveSelection);
|
|
|
|
ui.action_QueueMoveBottom->setEnabled(haveSelection);
|
|
|
|
|
|
|
|
if (!myDetailsDialog.isNull())
|
|
|
|
{
|
|
|
|
myDetailsDialog->setIds(getSelectedTorrents());
|
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.action_DeselectAll->trigger();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QSet<int> MainWindow::getSelectedTorrents(bool withMetadataOnly) const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QSet<int> ids;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QModelIndex const& index : ui.listView->selectionModel()->selectedRows())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent const* tor(index.data(TorrentModel::TorrentRole).value<Torrent const*>());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (tor != nullptr && (!withMetadataOnly || tor->hasMetadata()))
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.toggleBool(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const mode = myPrefs.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
2017-04-19 12:04:45 +00:00
|
|
|
myAltSpeedAction->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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.set(Prefs::STATUSBAR, visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MainWindow::toggleWindows(bool doShow)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!doShow)
|
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-19 12:04:45 +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;
|
|
|
|
QActionGroup* actionGroup;
|
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:
|
|
|
|
str = myPrefs.getString(key);
|
|
|
|
actionGroup = ui.action_TotalRatio->actionGroup();
|
|
|
|
assert(actionGroup != nullptr);
|
|
|
|
|
|
|
|
for (QAction* action : actionGroup->actions())
|
|
|
|
{
|
|
|
|
action->setChecked(str == action->property(STATS_MODE_KEY).toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshStatusBar();
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::SORT_REVERSED:
|
|
|
|
ui.action_ReverseSortOrder->setChecked(myPrefs.getBool(key));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::SORT_MODE:
|
|
|
|
i = myPrefs.get<SortMode>(key).mode();
|
|
|
|
actionGroup = ui.action_SortByActivity->actionGroup();
|
|
|
|
assert(actionGroup != nullptr);
|
|
|
|
|
|
|
|
for (QAction* action : actionGroup->actions())
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
(myPrefs.get<bool>(key) ? myDlimitOnAction : myDlimitOffAction)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::DSPEED:
|
|
|
|
myDlimitOnAction->setText(tr("Limited at %1").arg(Formatter::speedToString(Speed::fromKBps(myPrefs.get<int>(key)))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::USPEED_ENABLED:
|
|
|
|
(myPrefs.get<bool>(key) ? myUlimitOnAction : myUlimitOffAction)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::USPEED:
|
|
|
|
myUlimitOnAction->setText(tr("Limited at %1").arg(Formatter::speedToString(Speed::fromKBps(myPrefs.get<int>(key)))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RATIO_ENABLED:
|
|
|
|
(myPrefs.get<bool>(key) ? myRatioOnAction : myRatioOffAction)->setChecked(true);
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RATIO:
|
|
|
|
myRatioOnAction->setText(tr("Stop at Ratio (%1)").arg(Formatter::ratioToString(myPrefs.get<double>(key))));
|
2013-01-27 18:09:49 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::FILTERBAR:
|
|
|
|
b = myPrefs.getBool(key);
|
|
|
|
myFilterBar->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:
|
|
|
|
b = myPrefs.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:
|
|
|
|
b = myPrefs.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:
|
|
|
|
b = myPrefs.getBool(key);
|
|
|
|
ui.action_TrayIcon->setChecked(b);
|
|
|
|
myTrayIcon.setVisible(b);
|
|
|
|
qApp->setQuitOnLastWindowClosed(!b);
|
|
|
|
refreshTrayIconSoon();
|
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
|
|
|
|
|
|
|
QItemSelectionModel* selectionModel(ui.listView->selectionModel());
|
2017-04-20 16:02:19 +00:00
|
|
|
QItemSelection const selection(selectionModel->selection());
|
|
|
|
QModelIndex const currentIndex(selectionModel->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
|
|
|
|
|
|
|
b = myPrefs.getBool(key);
|
|
|
|
ui.action_CompactView->setChecked(b);
|
|
|
|
ui.listView->setItemDelegate(b ? myTorrentDelegateMin : myTorrentDelegate);
|
|
|
|
|
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();
|
|
|
|
ui.listView->reset(); // force the rows to resize
|
|
|
|
selectionModel->select(selection, QItemSelectionModel::Select);
|
|
|
|
selectionModel->setCurrentIndex(currentIndex, QItemSelectionModel::NoUpdate);
|
|
|
|
|
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:
|
|
|
|
setGeometry(myPrefs.getInt(Prefs::MAIN_WINDOW_X), myPrefs.getInt(Prefs::MAIN_WINDOW_Y),
|
|
|
|
myPrefs.getInt(Prefs::MAIN_WINDOW_WIDTH), myPrefs.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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
b = myPrefs.getBool(Prefs::ALT_SPEED_LIMIT_ENABLED);
|
|
|
|
myAltSpeedAction->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)");
|
2017-04-20 16:02:19 +00:00
|
|
|
Speed const d = Speed::fromKBps(myPrefs.getInt(Prefs::ALT_SPEED_LIMIT_DOWN));
|
|
|
|
Speed const u = Speed::fromKBps(myPrefs.getInt(Prefs::ALT_SPEED_LIMIT_UP));
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.altSpeedButton->setToolTip(fmt.arg(Formatter::speedToString(d)).arg(Formatter::speedToString(u)));
|
|
|
|
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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QLatin1String const SHOW_OPTIONS_CHECKBOX_NAME("show-options-checkbox");
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void MainWindow::newTorrent()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
MakeDialog* dialog = new MakeDialog(mySession, this);
|
|
|
|
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;
|
|
|
|
d = new QFileDialog(this, tr("Open Torrent"), myPrefs.getString(Prefs::OPEN_DIALOG_FOLDER),
|
|
|
|
tr("Torrent Files (*.torrent);;All Files (*.*)"));
|
|
|
|
d->setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
d->setAttribute(Qt::WA_DeleteOnClose);
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2017-04-20 16:02:19 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QCheckBox* b = new QCheckBox(tr("Show &options dialog"));
|
|
|
|
b->setChecked(myPrefs.getBool(Prefs::OPTIONS_PROMPT));
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool showOptions = myPrefs.getBool(Prefs::OPTIONS_PROMPT);
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QFileDialog const* const fileDialog = qobject_cast<QFileDialog const*>(sender());
|
2013-09-14 22:50:25 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (fileDialog != NULL)
|
2013-09-14 22:50:25 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QCheckBox const* const b = fileDialog->findChild<QCheckBox const*>(SHOW_OPTIONS_CHECKBOX_NAME);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (b != NULL)
|
|
|
|
{
|
|
|
|
showOptions = b->isChecked();
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
addTorrent(filename, showOptions);
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void MainWindow::addTorrent(AddData const& addMe, bool showOptions)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (showOptions)
|
2013-01-27 18:09:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
OptionsDialog* o = new OptionsDialog(mySession, myPrefs, addMe, this);
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.addTorrent(addMe);
|
|
|
|
qApp->alert(this);
|
2013-02-09 23:11:17 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void MainWindow::removeTorrents(bool const deleteFiles)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QSet<int> ids;
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
QString primary_text, secondary_text;
|
|
|
|
int incomplete = 0;
|
|
|
|
int connected = 0;
|
|
|
|
int count;
|
2010-04-23 03:58:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QModelIndex const& index : ui.listView->selectionModel()->selectedRows())
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent 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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (ids.isEmpty())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!deleteFiles)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
primary_text = (count == 1) ? tr("Remove torrent?") : tr("Remove %Ln torrent(s)?", 0, 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-19 12:04:45 +00:00
|
|
|
primary_text = (count == 1) ? tr("Delete this torrent's downloaded files?") :
|
|
|
|
tr("Delete these %Ln torrent(s)' downloaded files?", 0, count);
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!incomplete && !connected)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
secondary_text = (count == 1) ?
|
|
|
|
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-19 12:04:45 +00:00
|
|
|
secondary_text = (count == 1) ? tr("This torrent has not finished downloading.") :
|
|
|
|
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-19 12:04:45 +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-19 12:04:45 +00:00
|
|
|
if (connected)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
secondary_text = (connected == 1) ? tr("One of these torrents is connected to peers.") :
|
|
|
|
tr("Some of these torrents are connected to peers.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (connected && incomplete)
|
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-19 12:04:45 +00:00
|
|
|
if (incomplete)
|
2010-04-23 03:58:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
secondary_text += (incomplete == 1) ? tr("One of these torrents has not finished downloading.") :
|
|
|
|
tr("Some of these torrents have not finished downloading.");
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
msgBox.setWindowTitle(QLatin1String(" "));
|
|
|
|
msgBox.setText(QString::fromLatin1("<big><b>%1</big></b>").arg(primary_text));
|
|
|
|
msgBox.setInformativeText(secondary_text);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
msgBox.setIcon(QMessageBox::Question);
|
|
|
|
// hack needed to keep the dialog from being too narrow
|
|
|
|
auto layout = qobject_cast<QGridLayout*>(msgBox.layout());
|
|
|
|
|
|
|
|
if (layout == nullptr)
|
2014-03-16 22:50:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
layout = new QGridLayout;
|
|
|
|
msgBox.setLayout(layout);
|
2014-03-16 22:50:39 +00:00
|
|
|
}
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QSpacerItem* spacer = new QSpacerItem(450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
|
layout->addItem(spacer, layout->rowCount(), 0, 1, layout->columnCount());
|
|
|
|
|
|
|
|
if (msgBox.exec() == QMessageBox::Ok)
|
2010-06-16 03:01:09 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.listView->selectionModel()->clear();
|
|
|
|
mySession.removeTorrents(ids, deleteFiles);
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t const now = time(NULL);
|
|
|
|
int const period = 3;
|
|
|
|
time_t const secondsSinceLastSend = now - myLastSendTime;
|
|
|
|
time_t const secondsSinceLastRead = now - myLastReadTime;
|
|
|
|
bool const isSending = secondsSinceLastSend <= period;
|
|
|
|
bool const isReading = secondsSinceLastRead <= period;
|
|
|
|
char const* key;
|
2013-01-03 04:21:45 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (myNetworkError)
|
|
|
|
{
|
|
|
|
key = "network-error";
|
|
|
|
}
|
|
|
|
else if (isSending && isReading)
|
|
|
|
{
|
|
|
|
key = "network-transmit-receive";
|
|
|
|
}
|
|
|
|
else if (isSending)
|
|
|
|
{
|
|
|
|
key = "network-transmit";
|
|
|
|
}
|
|
|
|
else if (isReading)
|
|
|
|
{
|
|
|
|
key = "network-receive";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key = "network-idle";
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QIcon const icon = getStockIcon(QLatin1String(key), QStyle::SP_DriveNetIcon);
|
|
|
|
QPixmap const pixmap = icon.pixmap(16, 16);
|
2013-01-03 04:21:45 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString tip;
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const url = mySession.getRemoteUrl().host();
|
2013-01-03 04:21:45 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myLastReadTime)
|
|
|
|
{
|
|
|
|
tip = tr("%1 has not responded yet").arg(url);
|
|
|
|
}
|
|
|
|
else if (myNetworkError)
|
|
|
|
{
|
|
|
|
tip = tr(myErrorMessage.toLatin1().constData());
|
|
|
|
}
|
|
|
|
else if (secondsSinceLastRead < 30)
|
|
|
|
{
|
|
|
|
tip = tr("%1 is responding").arg(url);
|
|
|
|
}
|
|
|
|
else if (secondsSinceLastRead < (60 * 2))
|
|
|
|
{
|
|
|
|
tip = tr("%1 last responded %2 ago").arg(url).arg(Formatter::timeToString(secondsSinceLastRead));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tip = tr("%1 is not responding").arg(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myNetworkError)
|
|
|
|
{
|
|
|
|
myLastReadTime = time(NULL);
|
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myLastSendTime = time(NULL);
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const hadError = myNetworkError;
|
|
|
|
bool const haveError = (code != QNetworkReply::NoError) && (code != QNetworkReply::UnknownContentError);
|
2014-04-27 00:33:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
myNetworkError = haveError;
|
|
|
|
myErrorMessage = message;
|
|
|
|
refreshTrayIconSoon();
|
|
|
|
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
|
|
|
|
if (hadError && !haveError)
|
|
|
|
{
|
|
|
|
myModel.clear();
|
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.stop();
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mime->hasFormat(QLatin1String("application/x-bittorrent")) || mime->hasUrls() ||
|
|
|
|
mime->text().trimmed().endsWith(QLatin1String(".torrent"), Qt::CaseInsensitive) ||
|
|
|
|
mime->text().startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.menuTorrent->popup(event->globalPos());
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|