1 /*
2  * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12  * for more details.
13  */
14 
15 #ifndef APPLICATION_H
16 #define APPLICATION_H
17 
18 #include <QApplication>
19 #include <QPointer>
20 #include <QQueue>
21 #include <QTimer>
22 #include <QElapsedTimer>
23 #include <QNetworkConfigurationManager>
24 
25 #include "3rdparty/qtsingleapplication/qtsingleapplication.h"
26 
27 #include "syncresult.h"
28 #include "logbrowser.h"
29 #include "owncloudgui.h"
30 #include "connectionvalidator.h"
31 #include "progressdispatcher.h"
32 #include "clientproxy.h"
33 #include "folderman.h"
34 
35 class QMessageBox;
36 class QSystemTrayIcon;
37 class QSocket;
38 
39 namespace CrashReporter {
40 class Handler;
41 }
42 
43 namespace OCC {
44 
45 Q_DECLARE_LOGGING_CATEGORY(lcApplication)
46 
47 class Theme;
48 class Folder;
49 class SslErrorDialog;
50 
51 /**
52  * @brief The Application class
53  * @ingroup gui
54  */
55 class Application : public SharedTools::QtSingleApplication
56 {
57     Q_OBJECT
58 public:
59     explicit Application(int &argc, char **argv);
60     ~Application() override;
61 
62     bool giveHelp();
63     void showHelp();
64     void showHint(std::string errorHint);
65     bool debugMode();
66     bool versionOnly(); // only display the version?
67     void showVersion();
68 
69     void showSettingsDialog();
70 
71     ownCloudGui *gui() const;
72 
73 public slots:
74     // TODO: this should not be public
75     void slotownCloudWizardDone(int);
76     void slotCrash();
77     void slotCrashEnforce();
78     void slotCrashFatal();
79     /**
80      * Will download a virtual file, and open the result.
81      * The argument is the filename of the virtual file (including the extension)
82      */
83     void openVirtualFile(const QString &filename);
84 
85     /// Attempt to show() the tray icon again. Used if no systray was available initially.
86     void tryTrayAgain();
87 
88 protected:
89     void parseOptions(const QStringList &);
90     void setupTranslations();
91     void setupLogging();
92     bool event(QEvent *event) override;
93 
94 signals:
95     void folderRemoved();
96     void folderStateChanged(Folder *);
97 
98 protected slots:
99     void slotParseMessage(const QString &, QObject *);
100     void slotCheckConnection();
101     void slotUseMonoIconsChanged(bool);
102     void slotCleanup();
103     void slotAccountStateAdded(AccountState *accountState);
104     void slotAccountStateRemoved(AccountState *accountState);
105     void slotSystemOnlineConfigurationChanged(QNetworkConfiguration);
106 
107 private:
108     void setHelp();
109 
110     /**
111      * Maybe a newer version of the client was used with this config file:
112      * if so, backup, confirm with user and remove the config that can't be read.
113      */
114     bool configVersionMigration();
115 
116     QPointer<ownCloudGui> _gui;
117 
118     Theme *_theme;
119 
120     bool _helpOnly;
121     bool _versionOnly;
122 
123 
124 #ifdef Q_OS_LINUX
125     QElapsedTimer _startedAt;
126 #endif
127 
128     // options from command line:
129     bool _showLogWindow;
130     bool _showSettings = false;
131     bool _quitInstance = false;
132     QString _logFile;
133     QString _logDir;
134     std::chrono::hours _logExpire;
135     bool _logFlush;
136     bool _logDebug;
137     bool _userTriggeredConnect;
138     bool _debugMode;
139 
140     ClientProxy _proxy;
141 
142     QNetworkConfigurationManager _networkConfigurationManager;
143     QTimer _checkConnectionTimer;
144 
145 #if defined(WITH_CRASHREPORTER)
146     QScopedPointer<CrashReporter::Handler> _crashHandler;
147 #endif
148     QScopedPointer<FolderMan> _folderManager;
149 };
150 
ocApp()151 inline Application *ocApp()
152 {
153     auto instance = qobject_cast<Application *>(qApp);
154     OC_ENFORCE(instance);
155     return instance;
156 }
157 
158 } // namespace OCC
159 
160 #endif // APPLICATION_H
161