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
;
104 bool hasAnotherInstance() const;
105 bool callMainInstance();
106 const QBtCommandLineParameters
&commandLineArgs() const;
108 QString
instanceName() const override
;
109 void setInstanceName(const QString
&name
) override
;
111 // FileLogger properties
112 bool isFileLoggerEnabled() const override
;
113 void setFileLoggerEnabled(bool value
) override
;
114 Path
fileLoggerPath() const override
;
115 void setFileLoggerPath(const Path
&path
) override
;
116 bool isFileLoggerBackup() const override
;
117 void setFileLoggerBackup(bool value
) override
;
118 bool isFileLoggerDeleteOld() const override
;
119 void setFileLoggerDeleteOld(bool value
) override
;
120 int fileLoggerMaxSize() const override
;
121 void setFileLoggerMaxSize(int bytes
) override
;
122 int fileLoggerAge() const override
;
123 void setFileLoggerAge(int value
) override
;
124 int fileLoggerAgeType() const override
;
125 void setFileLoggerAgeType(int value
) override
;
127 int memoryWorkingSetLimit() const override
;
128 void setMemoryWorkingSetLimit(int size
) override
;
130 void sendTestEmail() const override
;
133 MemoryPriority
processMemoryPriority() const override
;
134 void setProcessMemoryPriority(MemoryPriority priority
) override
;
138 DesktopIntegration
*desktopIntegration() override
;
139 MainWindow
*mainWindow() override
;
141 WindowState
startUpWindowState() const override
;
142 void setStartUpWindowState(WindowState windowState
) override
;
144 bool isTorrentAddedNotificationsEnabled() const override
;
145 void setTorrentAddedNotificationsEnabled(bool value
) override
;
149 void processMessage(const QString
&message
);
150 void torrentAdded(const BitTorrent::Torrent
*torrent
) const;
151 void torrentFinished(const BitTorrent::Torrent
*torrent
);
152 void allTorrentsFinished();
155 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
156 void shutdownCleanup(QSessionManager
&manager
);
160 AddTorrentManagerImpl
*addTorrentManager() const override
;
161 #ifndef DISABLE_WEBUI
162 WebUI
*webUI() const override
;
165 void initializeTranslation();
166 void processParams(const QBtCommandLineParameters
¶ms
);
167 void runExternalProgram(const QString
&programTemplate
, const BitTorrent::Torrent
*torrent
) const;
168 void sendNotificationEmail(const BitTorrent::Torrent
*torrent
);
170 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
171 void applyMemoryWorkingSetLimit() const;
175 void applyMemoryPriority() const;
176 void adjustThreadPriority() const;
180 void createStartupProgressDialog();
182 bool event(QEvent
*) override
;
184 void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent
*torrent
);
185 void recursiveTorrentDownload(const BitTorrent::TorrentID
&torrentID
);
188 ApplicationInstanceManager
*m_instanceManager
= nullptr;
189 std::atomic_bool m_isCleanupRun
;
190 bool m_isProcessingParamsAllowed
= false;
191 ShutdownDialogAction m_shutdownAct
= ShutdownDialogAction::Exit
;
192 QBtCommandLineParameters m_commandLineArgs
;
195 QPointer
<FileLogger
> m_fileLogger
;
197 QTranslator m_qtTranslator
;
198 QTranslator m_translator
;
200 QList
<QBtCommandLineParameters
> m_paramsQueue
;
202 SettingValue
<QString
> m_storeInstanceName
;
203 SettingValue
<bool> m_storeFileLoggerEnabled
;
204 SettingValue
<bool> m_storeFileLoggerBackup
;
205 SettingValue
<bool> m_storeFileLoggerDeleteOld
;
206 SettingValue
<int> m_storeFileLoggerMaxSize
;
207 SettingValue
<int> m_storeFileLoggerAge
;
208 SettingValue
<int> m_storeFileLoggerAgeType
;
209 SettingValue
<Path
> m_storeFileLoggerPath
;
210 SettingValue
<int> m_storeMemoryWorkingSetLimit
;
213 SettingValue
<MemoryPriority
> m_processMemoryPriority
;
216 AddTorrentManagerImpl
*m_addTorrentManager
= nullptr;
219 SettingValue
<WindowState
> m_startUpWindowState
;
220 SettingValue
<bool> m_storeNotificationTorrentAdded
;
222 DesktopIntegration
*m_desktopIntegration
= nullptr;
223 MainWindow
*m_window
= nullptr;
224 QProgressDialog
*m_startupProgressDialog
= nullptr;
227 #ifndef DISABLE_WEBUI
228 WebUI
*m_webui
= nullptr;