2006-09-30 20:02:39 +04:00
|
|
|
/*
|
2016-01-24 13:16:25 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2018-06-06 16:48:17 +03:00
|
|
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
2006-09-30 20:02:39 +04:00
|
|
|
*/
|
|
|
|
|
2020-12-10 20:56:37 +03:00
|
|
|
#pragma once
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
#include <QMainWindow>
|
2008-09-13 11:33:41 +04:00
|
|
|
#include <QPointer>
|
2016-01-24 13:16:25 +03:00
|
|
|
|
2019-09-05 15:11:33 +03:00
|
|
|
#ifndef Q_OS_MACOS
|
2017-06-12 22:47:28 +03:00
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
#endif
|
|
|
|
|
2021-07-24 15:37:11 +03:00
|
|
|
#include "base/bittorrent/torrent.h"
|
2021-11-08 08:23:33 +03:00
|
|
|
#include "base/logger.h"
|
|
|
|
#include "base/settingvalue.h"
|
2021-07-24 15:37:11 +03:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
class QCloseEvent;
|
|
|
|
class QFileSystemWatcher;
|
|
|
|
class QSplitter;
|
|
|
|
class QTabWidget;
|
|
|
|
class QTimer;
|
2007-02-19 19:34:23 +03:00
|
|
|
|
2018-06-06 16:48:17 +03:00
|
|
|
class AboutDialog;
|
2018-06-14 14:46:50 +03:00
|
|
|
class DownloadFromURLDialog;
|
|
|
|
class ExecutionLogWidget;
|
|
|
|
class LineEdit;
|
2016-04-25 10:54:38 +03:00
|
|
|
class OptionsDialog;
|
2018-06-14 14:46:50 +03:00
|
|
|
class PowerManagement;
|
2021-01-25 10:49:29 +03:00
|
|
|
class ProgramUpdater;
|
2009-11-08 17:20:58 +03:00
|
|
|
class PropertiesWidget;
|
2018-06-14 14:46:50 +03:00
|
|
|
class RSSWidget;
|
|
|
|
class SearchWidget;
|
|
|
|
class StatsDialog;
|
2009-11-18 16:18:55 +03:00
|
|
|
class StatusBar;
|
2018-06-14 12:54:23 +03:00
|
|
|
class TorrentCreatorDialog;
|
2018-06-14 14:46:50 +03:00
|
|
|
class TransferListFiltersWidget;
|
|
|
|
class TransferListWidget;
|
2011-02-27 18:41:05 +03:00
|
|
|
|
2019-03-01 10:38:16 +03:00
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
struct DownloadResult;
|
|
|
|
}
|
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
namespace Ui
|
|
|
|
{
|
|
|
|
class MainWindow;
|
|
|
|
}
|
|
|
|
|
2020-04-19 05:42:11 +03:00
|
|
|
class MainWindow final : public QMainWindow
|
2014-12-20 20:53:58 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2010-03-03 17:48:49 +03:00
|
|
|
public:
|
2018-04-15 13:06:31 +03:00
|
|
|
explicit MainWindow(QWidget *parent = nullptr);
|
2016-01-24 13:16:25 +03:00
|
|
|
~MainWindow() override;
|
|
|
|
|
2017-01-08 03:46:01 +03:00
|
|
|
QWidget *currentTabWidget() const;
|
|
|
|
TransferListWidget *transferListWidget() const;
|
2016-01-24 13:16:25 +03:00
|
|
|
PropertiesWidget *propertiesWidget() const;
|
2010-03-03 17:48:49 +03:00
|
|
|
|
2016-03-14 15:39:13 +03:00
|
|
|
// ExecutionLog properties
|
|
|
|
bool isExecutionLogEnabled() const;
|
|
|
|
void setExecutionLogEnabled(bool value);
|
2021-11-08 08:23:33 +03:00
|
|
|
Log::MsgTypes executionLogMsgTypes() const;
|
|
|
|
void setExecutionLogMsgTypes(Log::MsgTypes value);
|
2016-03-14 15:39:13 +03:00
|
|
|
|
2016-04-17 22:56:51 +03:00
|
|
|
// Notifications properties
|
|
|
|
bool isNotificationsEnabled() const;
|
|
|
|
void setNotificationsEnabled(bool value);
|
|
|
|
bool isTorrentAddedNotificationsEnabled() const;
|
|
|
|
void setTorrentAddedNotificationsEnabled(bool value);
|
2021-04-13 17:22:48 +03:00
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
|
|
|
|
int getNotificationTimeout() const;
|
|
|
|
void setNotificationTimeout(int value);
|
|
|
|
#endif
|
2016-04-17 22:56:51 +03:00
|
|
|
|
2016-11-13 23:46:17 +03:00
|
|
|
// Misc properties
|
|
|
|
bool isDownloadTrackerFavicon() const;
|
|
|
|
void setDownloadTrackerFavicon(bool value);
|
|
|
|
|
2015-01-22 15:56:16 +03:00
|
|
|
void activate();
|
2015-04-16 00:47:59 +03:00
|
|
|
void cleanup();
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2021-10-09 19:14:18 +03:00
|
|
|
void showNotificationBalloon(const QString &title, const QString &msg) const;
|
2016-01-24 13:16:25 +03:00
|
|
|
|
2021-12-14 09:38:31 +03:00
|
|
|
signals:
|
|
|
|
void systemTrayIconCreated();
|
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
private slots:
|
2022-01-21 12:31:31 +03:00
|
|
|
void showFilterContextMenu();
|
2014-12-20 20:53:58 +03:00
|
|
|
void balloonClicked();
|
|
|
|
void writeSettings();
|
|
|
|
void readSettings();
|
2021-01-06 15:12:40 +03:00
|
|
|
void fullDiskError(BitTorrent::Torrent *const torrent, const QString &msg) const;
|
2019-02-12 03:45:30 +03:00
|
|
|
void handleDownloadFromUrlFailure(const QString &, const QString &) const;
|
2016-01-24 13:16:25 +03:00
|
|
|
void tabChanged(int newTab);
|
2018-11-21 16:40:31 +03:00
|
|
|
bool defineUILockPassword();
|
2014-12-20 20:53:58 +03:00
|
|
|
void clearUILockPassword();
|
|
|
|
bool unlockUI();
|
2019-02-12 03:45:30 +03:00
|
|
|
void notifyOfUpdate(const QString &);
|
2014-12-20 20:53:58 +03:00
|
|
|
void showConnectionSettings();
|
|
|
|
void minimizeWindow();
|
|
|
|
// Keyboard shortcuts
|
|
|
|
void createKeyboardShortcuts();
|
|
|
|
void displayTransferTab() const;
|
2017-01-26 22:01:19 +03:00
|
|
|
void displaySearchTab();
|
|
|
|
void displayRSSTab();
|
|
|
|
void displayExecutionLogTab();
|
2016-11-11 17:32:58 +03:00
|
|
|
void focusSearchFilter();
|
2019-09-24 06:29:07 +03:00
|
|
|
void reloadSessionStats();
|
2021-01-06 15:12:40 +03:00
|
|
|
void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
|
2021-12-13 10:56:20 +03:00
|
|
|
void loadPreferences();
|
2015-04-19 18:17:47 +03:00
|
|
|
void addTorrentFailed(const QString &error) const;
|
2021-01-06 15:12:40 +03:00
|
|
|
void torrentNew(BitTorrent::Torrent *const torrent) const;
|
|
|
|
void finishedTorrent(BitTorrent::Torrent *const torrent) const;
|
|
|
|
void askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent);
|
2014-12-20 20:53:58 +03:00
|
|
|
void optionsSaved();
|
2017-05-25 17:50:05 +03:00
|
|
|
void toggleAlternativeSpeeds();
|
2009-03-28 01:25:34 +03:00
|
|
|
|
2016-01-24 10:46:57 +03:00
|
|
|
#ifdef Q_OS_WIN
|
2019-03-01 10:38:16 +03:00
|
|
|
void pythonDownloadFinished(const Net::DownloadResult &result);
|
2014-09-14 15:30:22 +04:00
|
|
|
#endif
|
2014-10-18 18:18:58 +04:00
|
|
|
void addToolbarContextMenu();
|
2016-01-23 15:12:13 +03:00
|
|
|
void manageCookies();
|
2011-03-12 23:59:44 +03:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
void downloadFromURLList(const QStringList &urlList);
|
|
|
|
void updateAltSpeedsBtn(bool alternative);
|
|
|
|
void updateNbTorrents();
|
2017-03-07 16:10:42 +03:00
|
|
|
void handleRSSUnreadCountUpdated(int count);
|
2010-06-21 22:32:01 +04:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
void on_actionSearchWidget_triggered();
|
|
|
|
void on_actionRSSReader_triggered();
|
|
|
|
void on_actionSpeedInTitleBar_triggered();
|
|
|
|
void on_actionTopToolBar_triggered();
|
2015-10-30 16:03:44 +03:00
|
|
|
void on_actionShowStatusbar_triggered();
|
2016-01-24 13:16:25 +03:00
|
|
|
void on_actionDonateMoney_triggered();
|
2016-01-24 22:38:45 +03:00
|
|
|
void on_actionExecutionLogs_triggered(bool checked);
|
|
|
|
void on_actionNormalMessages_triggered(bool checked);
|
|
|
|
void on_actionInformationMessages_triggered(bool checked);
|
|
|
|
void on_actionWarningMessages_triggered(bool checked);
|
|
|
|
void on_actionCriticalMessages_triggered(bool checked);
|
2016-01-24 13:16:25 +03:00
|
|
|
void on_actionAutoExit_toggled(bool);
|
|
|
|
void on_actionAutoSuspend_toggled(bool);
|
|
|
|
void on_actionAutoHibernate_toggled(bool);
|
|
|
|
void on_actionAutoShutdown_toggled(bool);
|
|
|
|
void on_actionAbout_triggered();
|
|
|
|
void on_actionStatistics_triggered();
|
|
|
|
void on_actionCreateTorrent_triggered();
|
|
|
|
void on_actionOptions_triggered();
|
2019-08-25 21:19:05 +03:00
|
|
|
void on_actionSetGlobalSpeedLimits_triggered();
|
2016-01-24 13:16:25 +03:00
|
|
|
void on_actionDocumentation_triggered() const;
|
|
|
|
void on_actionOpen_triggered();
|
|
|
|
void on_actionDownloadFromURL_triggered();
|
|
|
|
void on_actionExit_triggered();
|
|
|
|
void on_actionLock_triggered();
|
2018-08-02 22:45:21 +03:00
|
|
|
// Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
|
|
|
|
void updatePowerManagementState();
|
2021-01-25 10:49:29 +03:00
|
|
|
|
2022-01-21 12:31:31 +03:00
|
|
|
void toolbarMenuRequested();
|
2014-10-18 18:18:58 +04:00
|
|
|
void toolbarIconsOnly();
|
|
|
|
void toolbarTextOnly();
|
|
|
|
void toolbarTextBeside();
|
|
|
|
void toolbarTextUnder();
|
|
|
|
void toolbarFollowSystem();
|
2019-09-05 15:11:33 +03:00
|
|
|
#ifdef Q_OS_MACOS
|
2017-12-12 18:01:55 +03:00
|
|
|
void on_actionCloseWindow_triggered();
|
|
|
|
#else
|
2017-07-16 06:49:06 +03:00
|
|
|
void toggleVisibility(const QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Trigger);
|
|
|
|
#endif
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
private:
|
2021-12-13 10:56:20 +03:00
|
|
|
void createTrayIconMenu();
|
2019-09-05 15:11:33 +03:00
|
|
|
#ifdef Q_OS_MACOS
|
2017-06-12 22:47:28 +03:00
|
|
|
void setupDockClickHandler();
|
|
|
|
#else
|
2021-12-13 10:56:20 +03:00
|
|
|
void createTrayIcon(int retries);
|
2017-06-12 22:47:28 +03:00
|
|
|
#endif
|
2016-01-24 13:16:25 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
void installPython();
|
2006-09-30 20:02:39 +04:00
|
|
|
#endif
|
2016-01-24 13:16:25 +03:00
|
|
|
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void closeEvent(QCloseEvent *) override;
|
|
|
|
void showEvent(QShowEvent *) override;
|
2020-10-30 20:49:15 +03:00
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
2017-05-09 08:55:24 +03:00
|
|
|
bool event(QEvent *e) override;
|
2016-01-24 13:16:25 +03:00
|
|
|
void displayRSSTab(bool enable);
|
|
|
|
void displaySearchTab(bool enable);
|
2019-02-22 04:33:04 +03:00
|
|
|
void createTorrentTriggered(const QString &path = {});
|
2017-05-25 17:50:05 +03:00
|
|
|
void showStatusBar(bool show);
|
2016-01-24 13:16:25 +03:00
|
|
|
|
|
|
|
Ui::MainWindow *m_ui;
|
|
|
|
|
|
|
|
QFileSystemWatcher *m_executableWatcher;
|
|
|
|
// GUI related
|
2021-11-08 08:23:33 +03:00
|
|
|
bool m_posInitialized = false;
|
2017-03-07 16:10:42 +03:00
|
|
|
QPointer<QTabWidget> m_tabs;
|
2017-05-25 17:50:05 +03:00
|
|
|
QPointer<StatusBar> m_statusBar;
|
2016-04-25 10:54:38 +03:00
|
|
|
QPointer<OptionsDialog> m_options;
|
2018-06-06 16:48:17 +03:00
|
|
|
QPointer<AboutDialog> m_aboutDlg;
|
2016-01-24 13:16:25 +03:00
|
|
|
QPointer<StatsDialog> m_statsDlg;
|
2018-06-14 12:54:23 +03:00
|
|
|
QPointer<TorrentCreatorDialog> m_createTorrentDlg;
|
2018-05-23 11:43:03 +03:00
|
|
|
QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
|
2021-12-13 10:56:20 +03:00
|
|
|
|
2019-09-05 15:11:33 +03:00
|
|
|
#ifndef Q_OS_MACOS
|
2016-01-24 13:16:25 +03:00
|
|
|
QPointer<QSystemTrayIcon> m_systrayIcon;
|
2017-06-12 22:47:28 +03:00
|
|
|
#endif
|
2016-01-24 13:16:25 +03:00
|
|
|
QPointer<QMenu> m_trayIconMenu;
|
2021-12-13 10:56:20 +03:00
|
|
|
|
2016-01-24 13:16:25 +03:00
|
|
|
TransferListWidget *m_transferListWidget;
|
|
|
|
TransferListFiltersWidget *m_transferListFiltersWidget;
|
|
|
|
PropertiesWidget *m_propertiesWidget;
|
|
|
|
bool m_displaySpeedInTitle;
|
2021-11-08 08:23:33 +03:00
|
|
|
bool m_forceExit = false;
|
2016-01-24 13:16:25 +03:00
|
|
|
bool m_uiLocked;
|
2021-11-08 08:23:33 +03:00
|
|
|
bool m_unlockDlgShowing = false;
|
2016-01-24 13:16:25 +03:00
|
|
|
LineEdit *m_searchFilter;
|
|
|
|
QAction *m_searchFilterAction;
|
|
|
|
// Widgets
|
2018-12-08 02:01:09 +03:00
|
|
|
QAction *m_queueSeparator;
|
|
|
|
QAction *m_queueSeparatorMenu;
|
2016-01-24 13:16:25 +03:00
|
|
|
QSplitter *m_splitter;
|
|
|
|
QPointer<SearchWidget> m_searchWidget;
|
2017-03-07 16:10:42 +03:00
|
|
|
QPointer<RSSWidget> m_rssWidget;
|
2018-06-14 12:54:23 +03:00
|
|
|
QPointer<ExecutionLogWidget> m_executionLog;
|
2016-01-24 13:16:25 +03:00
|
|
|
// Power Management
|
|
|
|
PowerManagement *m_pwr;
|
|
|
|
QTimer *m_preventTimer;
|
2021-11-08 08:23:33 +03:00
|
|
|
bool m_hasPython = false;
|
2016-01-24 13:16:25 +03:00
|
|
|
QMenu *m_toolbarMenu;
|
2021-01-25 10:49:29 +03:00
|
|
|
|
2021-11-08 08:23:33 +03:00
|
|
|
SettingValue<bool> m_storeExecutionLogEnabled;
|
|
|
|
SettingValue<bool> m_storeDownloadTrackerFavicon;
|
|
|
|
SettingValue<bool> m_storeNotificationEnabled;
|
|
|
|
SettingValue<bool> m_storeNotificationTorrentAdded;
|
|
|
|
CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
|
|
|
|
|
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
|
|
|
|
SettingValue<int> m_storeNotificationTimeOut;
|
|
|
|
#endif
|
|
|
|
|
2021-01-25 10:49:29 +03:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
|
|
|
void checkProgramUpdate(bool invokedByUser);
|
|
|
|
void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
|
|
|
|
|
|
|
|
QTimer *m_programUpdateTimer = nullptr;
|
|
|
|
#endif
|
2016-01-24 13:16:25 +03:00
|
|
|
};
|