2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022-2024 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.
32 #include <QMainWindow>
35 #include "base/bittorrent/torrent.h"
36 #include "base/logger.h"
37 #include "base/settingvalue.h"
38 #include "guiapplicationcomponent.h"
39 #include "windowstate.h"
43 class QFileSystemWatcher
;
50 class DownloadFromURLDialog
;
51 class ExecutionLogWidget
;
54 class PowerManagement
;
56 class PropertiesWidget
;
61 class TorrentCreatorDialog
;
62 class TransferListFiltersWidget
;
63 class TransferListWidget
;
74 struct DownloadResult
;
82 class MainWindow final
: public GUIApplicationComponent
<QMainWindow
>
85 Q_DISABLE_COPY_MOVE(MainWindow
)
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
);
102 bool isDownloadTrackerFavicon() const;
103 void setDownloadTrackerFavicon(bool value
);
105 void setTitleSuffix(const QString
&suffix
);
111 void showFilterContextMenu();
112 void desktopNotificationClicked();
113 void saveSettings() const;
115 void saveSplitterSettings() const;
116 void tabChanged(int newTab
);
117 bool defineUILockPassword();
118 void clearUILockPassword();
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 loadSessionStats();
131 void reloadTorrentStats(const QList
<BitTorrent::Torrent
*> &torrents
);
132 void loadPreferences();
134 void toggleAlternativeSpeeds();
137 void pythonDownloadFinished(const Net::DownloadResult
&result
);
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 non-stopped 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();
183 void on_actionCloseWindow_triggered();
185 void toggleVisibility();
189 void populateDesktopIntegrationMenu();
191 void installPython();
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();
206 void refreshWindowTitle();
207 void refreshTrayIconTooltip();
209 Ui::MainWindow
*m_ui
= nullptr;
211 QString m_windowTitle
;
212 QString m_downloadRate
;
213 QString m_uploadRate
;
214 bool m_posInitialized
= false;
215 bool m_neverShown
= true;
217 QFileSystemWatcher
*m_executableWatcher
= nullptr;
219 QPointer
<QTabWidget
> m_tabs
;
220 QPointer
<StatusBar
> m_statusBar
;
221 QPointer
<OptionsDialog
> m_options
;
222 QPointer
<AboutDialog
> m_aboutDlg
;
223 QPointer
<StatsDialog
> m_statsDlg
;
224 QPointer
<TorrentCreatorDialog
> m_createTorrentDlg
;
225 QPointer
<DownloadFromURLDialog
> m_downloadFromURLDialog
;
227 QPointer
<QMenu
> m_trayIconMenu
;
229 TransferListWidget
*m_transferListWidget
= nullptr;
230 TransferListFiltersWidget
*m_transferListFiltersWidget
= nullptr;
231 PropertiesWidget
*m_propertiesWidget
= nullptr;
232 bool m_displaySpeedInTitle
= false;
233 bool m_forceExit
= false;
234 bool m_uiLocked
= false;
235 bool m_unlockDlgShowing
= false;
236 QWidget
*m_columnFilterWidget
= nullptr;
237 LineEdit
*m_columnFilterEdit
= nullptr;
238 QAction
*m_columnFilterAction
= nullptr;
239 QComboBox
*m_columnFilterComboBox
= nullptr;
241 QAction
*m_queueSeparator
= nullptr;
242 QAction
*m_queueSeparatorMenu
= nullptr;
243 QSplitter
*m_splitter
= nullptr;
244 QPointer
<SearchWidget
> m_searchWidget
;
245 QPointer
<RSSWidget
> m_rssWidget
;
246 QPointer
<ExecutionLogWidget
> m_executionLog
;
248 PowerManagement
*m_pwr
= nullptr;
249 QTimer
*m_preventTimer
= nullptr;
250 QMenu
*m_toolbarMenu
= nullptr;
252 SettingValue
<bool> m_storeExecutionLogEnabled
;
253 SettingValue
<bool> m_storeDownloadTrackerFavicon
;
254 CachedSettingValue
<Log::MsgTypes
> m_storeExecutionLogTypes
;
256 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
257 void checkProgramUpdate(bool invokedByUser
);
258 void handleUpdateCheckFinished(ProgramUpdater
*updater
, bool invokedByUser
);
260 QTimer
*m_programUpdateTimer
= nullptr;
263 std::unique_ptr
<MacUtils::Badger
> m_badger
;