qBittorrent
application.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
4  * Copyright (C) 2006 Christophe Dumez
5  *
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.
10  *
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.
15  *
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.
19  *
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.
28  */
29 
30 #pragma once
31 
32 #include <QPointer>
33 #include <QStringList>
34 #include <QTranslator>
35 
36 #ifndef DISABLE_GUI
37 #include <QApplication>
38 using BaseApplication = QApplication;
39 class MainWindow;
40 
41 #ifdef Q_OS_WIN
42 class QSessionManager;
43 #endif // Q_OS_WIN
44 
45 #else
46 #include <QCoreApplication>
47 using BaseApplication = QCoreApplication;
48 #endif // DISABLE_GUI
49 
50 #include "base/settingvalue.h"
51 #include "base/types.h"
52 #include "cmdoptions.h"
53 
54 #ifndef DISABLE_WEBUI
55 class WebUI;
56 #endif
57 
59 class FileLogger;
60 
61 namespace BitTorrent
62 {
63  class Torrent;
64 }
65 
66 namespace RSS
67 {
68  class Session;
69  class AutoDownloader;
70 }
71 
72 class Application final : public BaseApplication
73 {
74  Q_OBJECT
75  Q_DISABLE_COPY_MOVE(Application)
76 
77 public:
78  Application(int &argc, char **argv);
79  ~Application() override;
80 
81  bool isRunning();
82  int exec(const QStringList &params);
83  bool sendParams(const QStringList &params);
84 
85 #ifndef DISABLE_GUI
86  QPointer<MainWindow> mainWindow();
87 #endif
88 
90 
91  // FileLogger properties
92  bool isFileLoggerEnabled() const;
93  void setFileLoggerEnabled(bool value);
94  QString fileLoggerPath() const;
95  void setFileLoggerPath(const QString &path);
96  bool isFileLoggerBackup() const;
97  void setFileLoggerBackup(bool value);
98  bool isFileLoggerDeleteOld() const;
99  void setFileLoggerDeleteOld(bool value);
100  int fileLoggerMaxSize() const;
101  void setFileLoggerMaxSize(int bytes);
102  int fileLoggerAge() const;
103  void setFileLoggerAge(int value);
104  int fileLoggerAgeType() const;
105  void setFileLoggerAgeType(int value);
106 
107 protected:
108 #ifndef DISABLE_GUI
109 #ifdef Q_OS_MACOS
110  bool event(QEvent *) override;
111 #endif
112 #endif
113 
114 private slots:
115  void processMessage(const QString &message);
116  void torrentFinished(BitTorrent::Torrent *const torrent);
117  void allTorrentsFinished();
118  void cleanup();
119 #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
120  void shutdownCleanup(QSessionManager &manager);
121 #endif
122 
123 private:
124  void initializeTranslation();
125  void processParams(const QStringList &params);
126  void runExternalProgram(const BitTorrent::Torrent *torrent) const;
127  void sendNotificationEmail(const BitTorrent::Torrent *torrent);
128 
130  bool m_running;
133 
134 #ifndef DISABLE_GUI
135  QPointer<MainWindow> m_window;
136 #endif
137 
138 #ifndef DISABLE_WEBUI
139  WebUI *m_webui = nullptr;
140 #endif
141 
142  // FileLog
143  QPointer<FileLogger> m_fileLogger;
144 
145  QTranslator m_qtTranslator;
146  QTranslator m_translator;
147  QStringList m_paramsQueue;
148 
156 };
QApplication BaseApplication
Definition: application.h:38
void setFileLoggerDeleteOld(bool value)
QStringList m_paramsQueue
Definition: application.h:147
int fileLoggerAge() const
QPointer< FileLogger > m_fileLogger
Definition: application.h:143
void setFileLoggerBackup(bool value)
SettingValue< bool > m_storeFileLoggerDeleteOld
Definition: application.h:151
int fileLoggerAgeType() const
bool isFileLoggerEnabled() const
QBtCommandLineParameters m_commandLineArgs
Definition: application.h:132
bool isFileLoggerDeleteOld() const
QPointer< MainWindow > m_window
Definition: application.h:135
SettingValue< QString > m_storeFileLoggerPath
Definition: application.h:155
void sendNotificationEmail(const BitTorrent::Torrent *torrent)
WebUI * m_webui
Definition: application.h:139
~Application() override
SettingValue< bool > m_storeFileLoggerEnabled
Definition: application.h:149
QTranslator m_translator
Definition: application.h:146
bool isFileLoggerBackup() const
SettingValue< bool > m_storeFileLoggerBackup
Definition: application.h:150
QPointer< MainWindow > mainWindow()
SettingValue< int > m_storeFileLoggerAge
Definition: application.h:153
void setFileLoggerAgeType(int value)
SettingValue< int > m_storeFileLoggerMaxSize
Definition: application.h:152
void setFileLoggerAge(int value)
Application(int &argc, char **argv)
void torrentFinished(BitTorrent::Torrent *const torrent)
bool m_running
Definition: application.h:130
int exec(const QStringList &params)
void allTorrentsFinished()
QString fileLoggerPath() const
void processParams(const QStringList &params)
void processMessage(const QString &message)
SettingValue< int > m_storeFileLoggerAgeType
Definition: application.h:154
ApplicationInstanceManager * m_instanceManager
Definition: application.h:129
QTranslator m_qtTranslator
Definition: application.h:145
void cleanup()
const QBtCommandLineParameters & commandLineArgs() const
void setFileLoggerEnabled(bool value)
void initializeTranslation()
void setFileLoggerMaxSize(int bytes)
int fileLoggerMaxSize() const
bool isRunning()
void setFileLoggerPath(const QString &path)
void runExternalProgram(const BitTorrent::Torrent *torrent) const
ShutdownDialogAction m_shutdownAct
Definition: application.h:131
bool sendParams(const QStringList &params)
Definition: webui.h:47
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64
ShutdownDialogAction
Definition: types.h:36