1 /*
2  * App.hpp
3  * Copyright (C) 2017  Belledonne Communications, Grenoble, France
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *  Created on: February 2, 2017
20  *      Author: Ronan Abhamon
21  */
22 
23 #ifndef APP_H_
24 #define APP_H_
25 
26 #include <QQmlApplicationEngine>
27 #include <QQuickWindow>
28 
29 #include "../components/notifier/Notifier.hpp"
30 #include "../components/other/colors/Colors.hpp"
31 #include "single-application/SingleApplication.hpp"
32 
33 #define APP_CODE_RESTART 1000
34 
35 // =============================================================================
36 
37 class QCommandLineParser;
38 
39 class Cli;
40 class DefaultTranslator;
41 
42 class App : public SingleApplication {
43   Q_OBJECT;
44 
45   Q_PROPERTY(QString configLocale READ getConfigLocale WRITE setConfigLocale NOTIFY configLocaleChanged);
46   Q_PROPERTY(QString locale READ getLocale CONSTANT);
47   Q_PROPERTY(QVariantList availableLocales READ getAvailableLocales CONSTANT);
48   Q_PROPERTY(QString qtVersion READ getQtVersion CONSTANT);
49 
50 public:
51   App (int &argc, char *argv[]);
52   ~App ();
53 
54   void initContentApp ();
55 
56   QString getCommandArgument ();
57 
getEngine()58   QQmlEngine *getEngine () {
59     return mEngine;
60   }
61 
getNotifier() const62   Notifier *getNotifier () const {
63     return mNotifier;
64   }
65 
getColors() const66   const Colors *getColors () const {
67     return mColors;
68   }
69 
70   QQuickWindow *getMainWindow () const;
71 
72   bool hasFocus () const;
73 
getInstance()74   static App *getInstance () {
75     return static_cast<App *>(QApplication::instance());
76   }
77 
restart()78   Q_INVOKABLE void restart () {
79     exit(APP_CODE_RESTART);
80   }
81 
82   Q_INVOKABLE QQuickWindow *getCallsWindow () const;
83   Q_INVOKABLE QQuickWindow *getSettingsWindow () const;
84 
85   Q_INVOKABLE static void smartShowWindow (QQuickWindow *window);
86 
87 signals:
88   void configLocaleChanged (const QString &locale);
89 
90 private:
91   void createParser ();
92 
93   void registerTypes ();
94   void registerSharedTypes ();
95   void registerToolTypes ();
96   void registerSharedToolTypes ();
97 
98   void setTrayIcon ();
99   void createNotifier ();
100 
101   void initLocale (const std::shared_ptr<linphone::Config> &config);
102 
103   QString getConfigLocale () const;
104   void setConfigLocale (const QString &locale);
105 
106   QString getLocale () const;
107 
getAvailableLocales() const108   QVariantList getAvailableLocales () const {
109     return mAvailableLocales;
110   }
111 
112   void openAppAfterInit ();
113 
114   static void checkForUpdate ();
115 
getQtVersion()116   static QString getQtVersion () {
117     return qVersion();
118   }
119 
120   QCommandLineParser *mParser = nullptr;
121 
122   QVariantList mAvailableLocales;
123   QString mLocale;
124 
125   QQmlApplicationEngine *mEngine = nullptr;
126 
127   DefaultTranslator *mTranslator = nullptr;
128   Notifier *mNotifier = nullptr;
129 
130   QQuickWindow *mCallsWindow = nullptr;
131   QQuickWindow *mSettingsWindow = nullptr;
132 
133   Colors *mColors = nullptr;
134 
135   Cli *mCli = nullptr;
136 };
137 
138 #endif // APP_H_
139