2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Mike Tzou (Chocobo1)
4 * Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
5 * Copyright (C) 2006 Christophe Dumez
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
35 #include <QtSystemDetection>
36 #include <QCoreApplication>
38 #include <QStringList>
39 #include <QTranslator>
42 #include <QApplication>
45 #include "base/bittorrent/addtorrentparams.h"
46 #include "base/interfaces/iapplication.h"
47 #include "base/path.h"
48 #include "base/settingvalue.h"
49 #include "base/types.h"
50 #include "cmdoptions.h"
53 #include "gui/interfaces/iguiapplication.h"
56 class ApplicationInstanceManager
;
71 class QProgressDialog
;
73 class DesktopIntegration
;
76 using AddTorrentManagerImpl
= GUIAddTorrentManager
;
77 using BaseApplication
= QApplication
;
78 using BaseIApplication
= IGUIApplication
;
81 class QSessionManager
;
84 using AddTorrentManagerImpl
= AddTorrentManager
;
85 using BaseApplication
= QCoreApplication
;
86 using BaseIApplication
= IApplication
;
93 class Application final
: public BaseApplication
, public BaseIApplication
96 Q_DISABLE_COPY_MOVE(Application
)
99 Application(int &argc
, char **argv
);
100 ~Application() override
;
105 bool callMainInstance();
106 const QBtCommandLineParameters
&commandLineArgs() const;
108 // FileLogger properties
109 bool isFileLoggerEnabled() const override
;
110 void setFileLoggerEnabled(bool value
) override
;
111 Path
fileLoggerPath() const override
;
112 void setFileLoggerPath(const Path
&path
) override
;
113 bool isFileLoggerBackup() const override
;
114 void setFileLoggerBackup(bool value
) override
;
115 bool isFileLoggerDeleteOld() const override
;
116 void setFileLoggerDeleteOld(bool value
) override
;
117 int fileLoggerMaxSize() const override
;
118 void setFileLoggerMaxSize(int bytes
) override
;
119 int fileLoggerAge() const override
;
120 void setFileLoggerAge(int value
) override
;
121 int fileLoggerAgeType() const override
;
122 void setFileLoggerAgeType(int value
) override
;
124 int memoryWorkingSetLimit() const override
;
125 void setMemoryWorkingSetLimit(int size
) override
;
128 MemoryPriority
processMemoryPriority() const override
;
129 void setProcessMemoryPriority(MemoryPriority priority
) override
;
133 DesktopIntegration
*desktopIntegration() override
;
134 MainWindow
*mainWindow() override
;
136 WindowState
startUpWindowState() const override
;
137 void setStartUpWindowState(WindowState windowState
) override
;
139 bool isTorrentAddedNotificationsEnabled() const override
;
140 void setTorrentAddedNotificationsEnabled(bool value
) override
;
144 void processMessage(const QString
&message
);
145 void torrentAdded(const BitTorrent::Torrent
*torrent
) const;
146 void torrentFinished(const BitTorrent::Torrent
*torrent
);
147 void allTorrentsFinished();
150 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
151 void shutdownCleanup(QSessionManager
&manager
);
155 AddTorrentManagerImpl
*addTorrentManager() const override
;
157 void initializeTranslation();
158 void processParams(const QBtCommandLineParameters
¶ms
);
159 void runExternalProgram(const QString
&programTemplate
, const BitTorrent::Torrent
*torrent
) const;
160 void sendNotificationEmail(const BitTorrent::Torrent
*torrent
);
162 #ifdef QBT_USES_LIBTORRENT2
163 void applyMemoryWorkingSetLimit() const;
167 void applyMemoryPriority() const;
168 void adjustThreadPriority() const;
172 void createStartupProgressDialog();
174 bool event(QEvent
*) override
;
176 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent
*torrent
);
177 void recursiveTorrentDownload(const BitTorrent::TorrentID
&torrentID
);
180 ApplicationInstanceManager
*m_instanceManager
= nullptr;
181 std::atomic_bool m_isCleanupRun
;
182 bool m_isProcessingParamsAllowed
= false;
183 ShutdownDialogAction m_shutdownAct
= ShutdownDialogAction::Exit
;
184 QBtCommandLineParameters m_commandLineArgs
;
187 QPointer
<FileLogger
> m_fileLogger
;
189 QTranslator m_qtTranslator
;
190 QTranslator m_translator
;
192 QList
<QBtCommandLineParameters
> m_paramsQueue
;
194 SettingValue
<bool> m_storeFileLoggerEnabled
;
195 SettingValue
<bool> m_storeFileLoggerBackup
;
196 SettingValue
<bool> m_storeFileLoggerDeleteOld
;
197 SettingValue
<int> m_storeFileLoggerMaxSize
;
198 SettingValue
<int> m_storeFileLoggerAge
;
199 SettingValue
<int> m_storeFileLoggerAgeType
;
200 SettingValue
<Path
> m_storeFileLoggerPath
;
201 SettingValue
<int> m_storeMemoryWorkingSetLimit
;
204 SettingValue
<MemoryPriority
> m_processMemoryPriority
;
207 AddTorrentManagerImpl
*m_addTorrentManager
= nullptr;
210 SettingValue
<WindowState
> m_startUpWindowState
;
211 SettingValue
<bool> m_storeNotificationTorrentAdded
;
213 DesktopIntegration
*m_desktopIntegration
= nullptr;
214 MainWindow
*m_window
= nullptr;
215 QProgressDialog
*m_startupProgressDialog
= nullptr;
218 #ifndef DISABLE_WEBUI
219 WebUI
*m_webui
= nullptr;