Provide torrent creation feature via WebAPI
[qBittorrent.git] / src / gui / mainwindow.h
blobc4e7178998fc2889d0b0a024dd8c9715c8ea717b
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #pragma once
32 #include <QMainWindow>
33 #include <QPointer>
35 #include "base/bittorrent/torrent.h"
36 #include "base/logger.h"
37 #include "base/settingvalue.h"
38 #include "guiapplicationcomponent.h"
39 #include "windowstate.h"
41 class QCloseEvent;
42 class QComboBox;
43 class QFileSystemWatcher;
44 class QSplitter;
45 class QString;
46 class QTabWidget;
47 class QTimer;
49 class AboutDialog;
50 class DownloadFromURLDialog;
51 class ExecutionLogWidget;
52 class LineEdit;
53 class OptionsDialog;
54 class PowerManagement;
55 class ProgramUpdater;
56 class PropertiesWidget;
57 class RSSWidget;
58 class SearchWidget;
59 class StatsDialog;
60 class StatusBar;
61 class TorrentCreatorDialog;
62 class TransferListFiltersWidget;
63 class TransferListWidget;
65 #ifdef Q_OS_MACOS
66 namespace MacUtils
68 class Badger;
70 #endif
72 namespace Net
74 struct DownloadResult;
77 namespace Ui
79 class MainWindow;
82 class MainWindow final : public GUIApplicationComponent<QMainWindow>
84 Q_OBJECT
85 Q_DISABLE_COPY_MOVE(MainWindow)
87 public:
88 explicit MainWindow(IGUIApplication *app, WindowState initialState = WindowState::Normal, const QString &titleSuffix = {});
89 ~MainWindow() override;
91 QWidget *currentTabWidget() const;
92 TransferListWidget *transferListWidget() const;
93 PropertiesWidget *propertiesWidget() const;
95 // ExecutionLog properties
96 bool isExecutionLogEnabled() const;
97 void setExecutionLogEnabled(bool value);
98 Log::MsgTypes executionLogMsgTypes() const;
99 void setExecutionLogMsgTypes(Log::MsgTypes value);
101 // Misc properties
102 bool isDownloadTrackerFavicon() const;
103 void setDownloadTrackerFavicon(bool value);
105 void setTitleSuffix(const QString &suffix);
107 void activate();
108 void cleanup();
110 private slots:
111 void showFilterContextMenu();
112 void desktopNotificationClicked();
113 void saveSettings() const;
114 void loadSettings();
115 void saveSplitterSettings() const;
116 void tabChanged(int newTab);
117 bool defineUILockPassword();
118 void clearUILockPassword();
119 bool unlockUI();
120 void notifyOfUpdate(const QString &);
121 void showConnectionSettings();
122 void minimizeWindow();
123 // Keyboard shortcuts
124 void createKeyboardShortcuts();
125 void displayTransferTab() const;
126 void displaySearchTab();
127 void displayRSSTab();
128 void displayExecutionLogTab();
129 void toggleFocusBetweenLineEdits();
130 void reloadSessionStats();
131 void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
132 void loadPreferences();
133 void optionsSaved();
134 void toggleAlternativeSpeeds();
136 #ifdef Q_OS_WIN
137 void pythonDownloadFinished(const Net::DownloadResult &result);
138 #endif
139 void addToolbarContextMenu();
140 void manageCookies();
142 void downloadFromURLList(const QStringList &urlList);
143 void updateAltSpeedsBtn(bool alternative);
144 void updateNbTorrents();
145 void handleRSSUnreadCountUpdated(int count);
147 void on_actionSearchWidget_triggered();
148 void on_actionRSSReader_triggered();
149 void on_actionSpeedInTitleBar_triggered();
150 void on_actionTopToolBar_triggered();
151 void on_actionShowStatusbar_triggered();
152 void on_actionShowFiltersSidebar_triggered(bool checked);
153 void on_actionDonateMoney_triggered();
154 void on_actionExecutionLogs_triggered(bool checked);
155 void on_actionNormalMessages_triggered(bool checked);
156 void on_actionInformationMessages_triggered(bool checked);
157 void on_actionWarningMessages_triggered(bool checked);
158 void on_actionCriticalMessages_triggered(bool checked);
159 void on_actionAutoExit_toggled(bool);
160 void on_actionAutoSuspend_toggled(bool);
161 void on_actionAutoHibernate_toggled(bool);
162 void on_actionAutoShutdown_toggled(bool);
163 void on_actionAbout_triggered();
164 void on_actionStatistics_triggered();
165 void on_actionCreateTorrent_triggered();
166 void on_actionOptions_triggered();
167 void on_actionSetGlobalSpeedLimits_triggered();
168 void on_actionDocumentation_triggered() const;
169 void on_actionOpen_triggered();
170 void on_actionDownloadFromURL_triggered();
171 void on_actionExit_triggered();
172 void on_actionLock_triggered();
173 // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
174 void updatePowerManagementState() const;
176 void toolbarMenuRequested();
177 void toolbarIconsOnly();
178 void toolbarTextOnly();
179 void toolbarTextBeside();
180 void toolbarTextUnder();
181 void toolbarFollowSystem();
182 #ifdef Q_OS_MACOS
183 void on_actionCloseWindow_triggered();
184 #else
185 void toggleVisibility();
186 #endif
188 private:
189 QMenu *createDesktopIntegrationMenu();
190 #ifdef Q_OS_WIN
191 void installPython();
192 #endif
194 void dropEvent(QDropEvent *event) override;
195 void dragEnterEvent(QDragEnterEvent *event) override;
196 void closeEvent(QCloseEvent *) override;
197 void showEvent(QShowEvent *) override;
198 void keyPressEvent(QKeyEvent *event) override;
199 bool event(QEvent *e) override;
200 void displayRSSTab(bool enable);
201 void displaySearchTab(bool enable);
202 void createTorrentTriggered(const Path &path);
203 void showStatusBar(bool show);
204 void showFiltersSidebar(bool show);
205 void applyTransferListFilter();
207 Ui::MainWindow *m_ui = nullptr;
209 QFileSystemWatcher *m_executableWatcher = nullptr;
210 // GUI related
211 QString m_windowTitle;
212 bool m_posInitialized = false;
213 bool m_neverShown = true;
214 QPointer<QTabWidget> m_tabs;
215 QPointer<StatusBar> m_statusBar;
216 QPointer<OptionsDialog> m_options;
217 QPointer<AboutDialog> m_aboutDlg;
218 QPointer<StatsDialog> m_statsDlg;
219 QPointer<TorrentCreatorDialog> m_createTorrentDlg;
220 QPointer<DownloadFromURLDialog> m_downloadFromURLDialog;
222 QPointer<QMenu> m_trayIconMenu;
224 TransferListWidget *m_transferListWidget = nullptr;
225 TransferListFiltersWidget *m_transferListFiltersWidget = nullptr;
226 PropertiesWidget *m_propertiesWidget = nullptr;
227 bool m_displaySpeedInTitle = false;
228 bool m_forceExit = false;
229 bool m_uiLocked = false;
230 bool m_unlockDlgShowing = false;
231 QWidget *m_columnFilterWidget = nullptr;
232 LineEdit *m_columnFilterEdit = nullptr;
233 QAction *m_columnFilterAction = nullptr;
234 QComboBox *m_columnFilterComboBox = nullptr;
235 // Widgets
236 QAction *m_queueSeparator = nullptr;
237 QAction *m_queueSeparatorMenu = nullptr;
238 QSplitter *m_splitter = nullptr;
239 QPointer<SearchWidget> m_searchWidget;
240 QPointer<RSSWidget> m_rssWidget;
241 QPointer<ExecutionLogWidget> m_executionLog;
242 // Power Management
243 PowerManagement *m_pwr = nullptr;
244 QTimer *m_preventTimer = nullptr;
245 QMenu *m_toolbarMenu = nullptr;
247 SettingValue<bool> m_storeExecutionLogEnabled;
248 SettingValue<bool> m_storeDownloadTrackerFavicon;
249 CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
251 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
252 void checkProgramUpdate(bool invokedByUser);
253 void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
255 QTimer *m_programUpdateTimer = nullptr;
256 #endif
257 #ifdef Q_OS_MACOS
258 std::unique_ptr<MacUtils::Badger> m_badger;
259 #endif