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.
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
;
67 struct DownloadResult
;
75 class MainWindow final
: public QMainWindow
, public GUIApplicationComponent
78 Q_DISABLE_COPY_MOVE(MainWindow
)
81 explicit MainWindow(IGUIApplication
*app
, WindowState initialState
= WindowState::Normal
);
82 ~MainWindow() override
;
84 QWidget
*currentTabWidget() const;
85 TransferListWidget
*transferListWidget() const;
86 PropertiesWidget
*propertiesWidget() const;
88 // ExecutionLog properties
89 bool isExecutionLogEnabled() const;
90 void setExecutionLogEnabled(bool value
);
91 Log::MsgTypes
executionLogMsgTypes() const;
92 void setExecutionLogMsgTypes(Log::MsgTypes value
);
94 // Notifications properties
97 bool isDownloadTrackerFavicon() const;
98 void setDownloadTrackerFavicon(bool value
);
104 void showFilterContextMenu();
105 void desktopNotificationClicked();
106 void saveSettings() const;
108 void saveSplitterSettings() const;
109 void tabChanged(int newTab
);
110 bool defineUILockPassword();
111 void clearUILockPassword();
113 void notifyOfUpdate(const QString
&);
114 void showConnectionSettings();
115 void minimizeWindow();
116 // Keyboard shortcuts
117 void createKeyboardShortcuts();
118 void displayTransferTab() const;
119 void displaySearchTab();
120 void displayRSSTab();
121 void displayExecutionLogTab();
122 void focusSearchFilter();
123 void reloadSessionStats();
124 void reloadTorrentStats(const QVector
<BitTorrent::Torrent
*> &torrents
);
125 void loadPreferences();
126 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent
*torrent
);
128 void toggleAlternativeSpeeds();
131 void pythonDownloadFinished(const Net::DownloadResult
&result
);
133 void addToolbarContextMenu();
134 void manageCookies();
136 void downloadFromURLList(const QStringList
&urlList
);
137 void updateAltSpeedsBtn(bool alternative
);
138 void updateNbTorrents();
139 void handleRSSUnreadCountUpdated(int count
);
141 void on_actionSearchWidget_triggered();
142 void on_actionRSSReader_triggered();
143 void on_actionSpeedInTitleBar_triggered();
144 void on_actionTopToolBar_triggered();
145 void on_actionShowStatusbar_triggered();
146 void on_actionShowFiltersSidebar_triggered(bool checked
);
147 void on_actionDonateMoney_triggered();
148 void on_actionExecutionLogs_triggered(bool checked
);
149 void on_actionNormalMessages_triggered(bool checked
);
150 void on_actionInformationMessages_triggered(bool checked
);
151 void on_actionWarningMessages_triggered(bool checked
);
152 void on_actionCriticalMessages_triggered(bool checked
);
153 void on_actionAutoExit_toggled(bool);
154 void on_actionAutoSuspend_toggled(bool);
155 void on_actionAutoHibernate_toggled(bool);
156 void on_actionAutoShutdown_toggled(bool);
157 void on_actionAbout_triggered();
158 void on_actionStatistics_triggered();
159 void on_actionCreateTorrent_triggered();
160 void on_actionOptions_triggered();
161 void on_actionSetGlobalSpeedLimits_triggered();
162 void on_actionDocumentation_triggered() const;
163 void on_actionOpen_triggered();
164 void on_actionDownloadFromURL_triggered();
165 void on_actionExit_triggered();
166 void on_actionLock_triggered();
167 // Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
168 void updatePowerManagementState();
170 void toolbarMenuRequested();
171 void toolbarIconsOnly();
172 void toolbarTextOnly();
173 void toolbarTextBeside();
174 void toolbarTextUnder();
175 void toolbarFollowSystem();
177 void on_actionCloseWindow_triggered();
179 void toggleVisibility();
183 QMenu
*createDesktopIntegrationMenu();
185 void installPython();
188 void dropEvent(QDropEvent
*event
) override
;
189 void dragEnterEvent(QDragEnterEvent
*event
) override
;
190 void closeEvent(QCloseEvent
*) override
;
191 void showEvent(QShowEvent
*) override
;
192 void keyPressEvent(QKeyEvent
*event
) override
;
193 bool event(QEvent
*e
) override
;
194 void displayRSSTab(bool enable
);
195 void displaySearchTab(bool enable
);
196 void createTorrentTriggered(const Path
&path
);
197 void showStatusBar(bool show
);
198 void showFiltersSidebar(bool show
);
199 void applyTransferListFilter();
201 Ui::MainWindow
*m_ui
= nullptr;
203 QFileSystemWatcher
*m_executableWatcher
= nullptr;
205 bool m_posInitialized
= false;
206 bool m_neverShown
= true;
207 QPointer
<QTabWidget
> m_tabs
;
208 QPointer
<StatusBar
> m_statusBar
;
209 QPointer
<OptionsDialog
> m_options
;
210 QPointer
<AboutDialog
> m_aboutDlg
;
211 QPointer
<StatsDialog
> m_statsDlg
;
212 QPointer
<TorrentCreatorDialog
> m_createTorrentDlg
;
213 QPointer
<DownloadFromURLDialog
> m_downloadFromURLDialog
;
215 QPointer
<QMenu
> m_trayIconMenu
;
217 TransferListWidget
*m_transferListWidget
= nullptr;
218 TransferListFiltersWidget
*m_transferListFiltersWidget
= nullptr;
219 PropertiesWidget
*m_propertiesWidget
= nullptr;
220 bool m_displaySpeedInTitle
= false;
221 bool m_forceExit
= false;
222 bool m_uiLocked
= false;
223 bool m_unlockDlgShowing
= false;
224 QWidget
*m_columnFilterWidget
= nullptr;
225 LineEdit
*m_columnFilterEdit
= nullptr;
226 QAction
*m_columnFilterAction
= nullptr;
227 QComboBox
*m_columnFilterComboBox
= nullptr;
229 QAction
*m_queueSeparator
= nullptr;
230 QAction
*m_queueSeparatorMenu
= nullptr;
231 QSplitter
*m_splitter
= nullptr;
232 QPointer
<SearchWidget
> m_searchWidget
;
233 QPointer
<RSSWidget
> m_rssWidget
;
234 QPointer
<ExecutionLogWidget
> m_executionLog
;
236 PowerManagement
*m_pwr
= nullptr;
237 QTimer
*m_preventTimer
= nullptr;
238 bool m_hasPython
= false;
239 QMenu
*m_toolbarMenu
= nullptr;
241 SettingValue
<bool> m_storeExecutionLogEnabled
;
242 SettingValue
<bool> m_storeDownloadTrackerFavicon
;
243 CachedSettingValue
<Log::MsgTypes
> m_storeExecutionLogTypes
;
245 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
246 void checkProgramUpdate(bool invokedByUser
);
247 void handleUpdateCheckFinished(ProgramUpdater
*updater
, bool invokedByUser
);
249 QTimer
*m_programUpdateTimer
= nullptr;