2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2022-04-25 01:49:52 +00:00
|
|
|
#include <cstddef>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <ctime>
|
2020-07-29 23:21:11 +00:00
|
|
|
#include <memory>
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QMainWindow>
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QNetworkReply>
|
2015-01-25 15:47:03 +00:00
|
|
|
#include <QPointer>
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
#include <QStringList>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWidgetList>
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
#include <libtransmission/tr-macros.h>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Filters.h"
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Speed.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "TorrentFilter.h"
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Typedefs.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ui_MainWindow.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class QAction;
|
|
|
|
class QIcon;
|
|
|
|
class QMenu;
|
|
|
|
|
2015-07-30 06:18:02 +00:00
|
|
|
class AboutDialog;
|
2013-02-09 23:11:17 +00:00
|
|
|
class AddData;
|
2015-06-10 21:27:11 +00:00
|
|
|
class DetailsDialog;
|
2020-07-29 23:21:11 +00:00
|
|
|
class ListViewProxyStyle;
|
2015-07-30 06:18:02 +00:00
|
|
|
class Prefs;
|
|
|
|
class PrefsDialog;
|
2009-04-09 18:55:47 +00:00
|
|
|
class Session;
|
2015-07-30 06:18:02 +00:00
|
|
|
class SessionDialog;
|
|
|
|
class StatsDialog;
|
2009-04-09 18:55:47 +00:00
|
|
|
class TorrentDelegate;
|
|
|
|
class TorrentDelegateMin;
|
|
|
|
class TorrentModel;
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
struct tr_variant;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class MainWindow : public QMainWindow
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-01-27 18:09:49 +00:00
|
|
|
Q_OBJECT
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(MainWindow)
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2022-04-21 14:28:38 +00:00
|
|
|
MainWindow(Session&, Prefs&, TorrentModel&, bool minimized);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
QSystemTrayIcon& trayIcon()
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return tray_icon_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void startAll();
|
|
|
|
void startSelected();
|
|
|
|
void startSelectedNow();
|
|
|
|
void pauseAll();
|
|
|
|
void pauseSelected();
|
|
|
|
void removeSelected();
|
|
|
|
void deleteSelected();
|
|
|
|
void verifySelected();
|
|
|
|
void queueMoveTop();
|
|
|
|
void queueMoveUp();
|
|
|
|
void queueMoveDown();
|
|
|
|
void queueMoveBottom();
|
|
|
|
void reannounceSelected();
|
|
|
|
void onNetworkTimer();
|
|
|
|
|
|
|
|
void setToolbarVisible(bool);
|
|
|
|
void setFilterbarVisible(bool);
|
|
|
|
void setStatusbarVisible(bool);
|
|
|
|
void setCompactView(bool);
|
|
|
|
void wrongAuthentication();
|
|
|
|
|
|
|
|
void openSession();
|
|
|
|
|
|
|
|
protected:
|
2015-06-12 22:12:12 +00:00
|
|
|
// QWidget
|
2019-11-12 01:37:05 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent*) override;
|
|
|
|
void dragEnterEvent(QDragEnterEvent*) override;
|
|
|
|
void dropEvent(QDropEvent*) override;
|
2022-01-23 15:57:21 +00:00
|
|
|
bool event(QEvent*) override;
|
2013-01-27 18:09:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private slots:
|
2017-04-20 16:02:19 +00:00
|
|
|
void addTorrents(QStringList const& filenames);
|
2017-04-19 12:04:45 +00:00
|
|
|
void copyMagnetLinkToClipboard();
|
|
|
|
void dataReadProgress();
|
|
|
|
void dataSendProgress();
|
2019-11-09 14:44:40 +00:00
|
|
|
void newTorrent();
|
2017-04-20 16:02:19 +00:00
|
|
|
void onNetworkResponse(QNetworkReply::NetworkError code, QString const& message);
|
2019-11-09 14:44:40 +00:00
|
|
|
void onRefreshTimer();
|
|
|
|
void onSessionSourceChanged();
|
2017-04-19 12:04:45 +00:00
|
|
|
void onSetPrefs();
|
|
|
|
void onSetPrefs(bool);
|
2020-11-09 03:31:02 +00:00
|
|
|
void onSortModeChanged(QAction const* action);
|
|
|
|
void onStatsModeChanged(QAction const* action);
|
2019-11-09 14:44:40 +00:00
|
|
|
void openAbout();
|
2020-11-09 03:31:02 +00:00
|
|
|
void openDonate() const;
|
2019-11-09 14:44:40 +00:00
|
|
|
void openFolder();
|
2020-11-09 03:31:02 +00:00
|
|
|
void openHelp() const;
|
2019-11-09 14:44:40 +00:00
|
|
|
void openPreferences();
|
|
|
|
void openProperties();
|
|
|
|
void openStats();
|
|
|
|
void openTorrent();
|
|
|
|
void openURL();
|
|
|
|
void refreshPref(int key);
|
|
|
|
void refreshSoon(int fields = ~0);
|
2020-05-27 21:53:12 +00:00
|
|
|
void removeTorrents(bool const delete_files);
|
2019-11-09 14:44:40 +00:00
|
|
|
void setLocation();
|
|
|
|
void setSortAscendingPref(bool);
|
|
|
|
void toggleSpeedMode();
|
2020-05-27 21:53:12 +00:00
|
|
|
void toggleWindows(bool do_show);
|
2019-11-09 14:44:40 +00:00
|
|
|
void trayActivated(QSystemTrayIcon::ActivationReason);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-09 03:31:02 +00:00
|
|
|
QIcon addEmblem(QIcon icon, QStringList const& emblem_names) const;
|
2020-11-05 22:46:21 +00:00
|
|
|
|
|
|
|
torrent_ids_t getSelectedTorrents(bool withMetadataOnly = false) const;
|
|
|
|
void updateNetworkIcon();
|
|
|
|
|
|
|
|
QMenu* createOptionsMenu();
|
|
|
|
QMenu* createStatsModeMenu();
|
|
|
|
void initStatusBar();
|
|
|
|
|
|
|
|
void clearSelection();
|
|
|
|
void addTorrent(AddData const& add_me, bool show_options);
|
|
|
|
|
|
|
|
// QWidget
|
|
|
|
void hideEvent(QHideEvent* event) override;
|
|
|
|
void showEvent(QShowEvent* event) override;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
Session& session_;
|
|
|
|
Prefs& prefs_;
|
|
|
|
TorrentModel& model_;
|
|
|
|
|
2020-07-29 23:21:11 +00:00
|
|
|
std::shared_ptr<ListViewProxyStyle> lvp_style_;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QPixmap pixmap_network_error_;
|
|
|
|
QPixmap pixmap_network_idle_;
|
|
|
|
QPixmap pixmap_network_receive_;
|
|
|
|
QPixmap pixmap_network_transmit_;
|
|
|
|
QPixmap pixmap_network_transmit_receive_;
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
Ui_MainWindow ui_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
|
|
|
|
time_t last_full_update_time_ = {};
|
|
|
|
QPointer<SessionDialog> session_dialog_;
|
|
|
|
QPointer<PrefsDialog> prefs_dialog_;
|
|
|
|
QPointer<AboutDialog> about_dialog_;
|
|
|
|
QPointer<StatsDialog> stats_dialog_;
|
|
|
|
QPointer<DetailsDialog> details_dialog_;
|
|
|
|
QSystemTrayIcon tray_icon_;
|
|
|
|
TorrentFilter filter_model_;
|
|
|
|
TorrentDelegate* torrent_delegate_ = {};
|
|
|
|
TorrentDelegateMin* torrent_delegate_min_ = {};
|
|
|
|
time_t last_send_time_ = {};
|
|
|
|
time_t last_read_time_ = {};
|
|
|
|
QTimer network_timer_;
|
|
|
|
bool network_error_ = {};
|
|
|
|
QAction* dlimit_off_action_ = {};
|
|
|
|
QAction* dlimit_on_action_ = {};
|
|
|
|
QAction* ulimit_off_action_ = {};
|
|
|
|
QAction* ulimit_on_action_ = {};
|
|
|
|
QAction* ratio_off_action_ = {};
|
|
|
|
QAction* ratio_on_action_ = {};
|
|
|
|
QWidgetList hidden_;
|
|
|
|
QWidget* filter_bar_ = {};
|
|
|
|
QAction* alt_speed_action_ = {};
|
|
|
|
QString error_message_;
|
2022-01-23 15:57:21 +00:00
|
|
|
bool auto_add_clipboard_links = {};
|
|
|
|
QStringList clipboard_processed_keys_ = {};
|
2019-11-09 14:44:40 +00:00
|
|
|
|
2020-11-02 01:13:32 +00:00
|
|
|
QString const total_ratio_stats_mode_name_ = QStringLiteral("total-ratio");
|
|
|
|
QString const total_transfer_stats_mode_name_ = QStringLiteral("total-transfer");
|
|
|
|
QString const session_ratio_stats_mode_name_ = QStringLiteral("session-ratio");
|
|
|
|
QString const session_transfer_stats_mode_name_ = QStringLiteral("session-transfer");
|
|
|
|
QString const show_options_checkbox_name_ = QStringLiteral("show-options-checkbox");
|
2020-08-15 15:42:51 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
struct TransferStats
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
Speed speed_up;
|
|
|
|
Speed speed_down;
|
|
|
|
size_t peers_sending = 0;
|
|
|
|
size_t peers_receiving = 0;
|
2019-11-12 01:37:05 +00:00
|
|
|
};
|
|
|
|
TransferStats getTransferStats() const;
|
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
REFRESH_TITLE = (1 << 0),
|
|
|
|
REFRESH_STATUS_BAR = (1 << 1),
|
|
|
|
REFRESH_TRAY_ICON = (1 << 2),
|
|
|
|
REFRESH_TORRENT_VIEW_HEADER = (1 << 3),
|
|
|
|
REFRESH_ACTION_SENSITIVITY = (1 << 4)
|
|
|
|
};
|
2020-05-27 21:53:12 +00:00
|
|
|
int refresh_fields_ = {};
|
|
|
|
QTimer refresh_timer_;
|
|
|
|
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshActionSensitivity();
|
2019-11-12 01:37:05 +00:00
|
|
|
void refreshStatusBar(TransferStats const&);
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshTitle();
|
2019-11-09 14:44:40 +00:00
|
|
|
void refreshTorrentViewHeader();
|
2020-05-02 04:23:47 +00:00
|
|
|
void refreshTrayIcon(TransferStats const&);
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|