transmission/qt/MainWindow.h

215 lines
5.8 KiB
C
Raw Normal View History

// This file Copyright © 2009-2023 Mnemosyne LLC.
2022-08-08 18:05:39 +00:00
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// 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
#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>
#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>
#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>
#include <libtransmission/tr-macros.h>
#include "Filters.h"
#include "Speed.h"
#include "TorrentFilter.h"
#include "Typedefs.h"
#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;
class AboutDialog;
class AddData;
class DetailsDialog;
class ListViewProxyStyle;
class Prefs;
class PrefsDialog;
2009-04-09 18:55:47 +00:00
class Session;
class SessionDialog;
class StatsDialog;
2009-04-09 18:55:47 +00:00
class TorrentDelegate;
class TorrentDelegateMin;
class TorrentModel;
extern "C"
{
struct tr_variant;
}
class MainWindow : public QMainWindow
2009-04-09 18:55:47 +00:00
{
Q_OBJECT
TR_DISABLE_COPY_MOVE(MainWindow)
public:
MainWindow(Session&, Prefs&, TorrentModel&, bool minimized);
[[nodiscard]] constexpr QSystemTrayIcon& trayIcon() noexcept
{
return tray_icon_;
}
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
void contextMenuEvent(QContextMenuEvent*) override;
void dragEnterEvent(QDragEnterEvent*) override;
void dropEvent(QDropEvent*) override;
bool event(QEvent*) override;
private slots:
void addTorrents(QStringList const& filenames);
void copyMagnetLinkToClipboard();
void dataReadProgress();
void dataSendProgress();
void newTorrent();
void onNetworkResponse(QNetworkReply::NetworkError code, QString const& message);
void onRefreshTimer();
void onSessionSourceChanged();
void onSetPrefs();
void onSetPrefs(bool);
void onSortModeChanged(QAction const* action);
void onStatsModeChanged(QAction const* action);
void openAbout();
void openDonate() const;
void openFolder();
void openHelp() const;
void openPreferences();
void openProperties();
void openStats();
void openTorrent();
void openURL();
void refreshPref(int key);
void refreshSoon(int fields = ~0);
void removeTorrents(bool const delete_files);
void setLocation();
void setSortAscendingPref(bool);
void toggleSpeedMode();
void toggleWindows(bool do_show);
void trayActivated(QSystemTrayIcon::ActivationReason);
private:
QIcon addEmblem(QIcon icon, QStringList const& emblem_names) const;
torrent_ids_t getSelectedTorrents(bool with_metadata_only = false) const;
void updateNetworkIcon();
QMenu* createOptionsMenu();
QMenu* createStatsModeMenu();
void initStatusBar();
void clearSelection();
void addTorrent(AddData add_me, bool show_options);
// QWidget
void hideEvent(QHideEvent* event) override;
void showEvent(QShowEvent* event) override;
Session& session_;
Prefs& prefs_;
TorrentModel& model_;
std::shared_ptr<ListViewProxyStyle> lvp_style_;
QPixmap pixmap_network_error_;
QPixmap pixmap_network_idle_;
QPixmap pixmap_network_receive_;
QPixmap pixmap_network_transmit_;
QPixmap pixmap_network_transmit_receive_;
Ui_MainWindow ui_ = {};
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_;
bool auto_add_clipboard_links = {};
QStringList clipboard_processed_keys_ = {};
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");
struct TransferStats
{
Speed speed_up;
Speed speed_down;
size_t peers_sending = 0;
size_t peers_receiving = 0;
};
TransferStats getTransferStats() const;
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)
};
int refresh_fields_ = {};
QTimer refresh_timer_;
void refreshActionSensitivity();
void refreshStatusBar(TransferStats const&);
void refreshTitle();
void refreshTorrentViewHeader();
void refreshTrayIcon(TransferStats const&);
2009-04-09 18:55:47 +00:00
};