BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
application.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef APPLICATION_H
32 #define APPLICATION_H
33 
34 #include <QApplication>
35 
36 #include "definitions/definitions.h"
37 #include "miscellaneous/settings.h"
38 #include "miscellaneous/systemfactory.h"
39 #include "gui/systemtrayicon.h"
40 
41 #include <QNetworkReply>
42 #include <QSessionManager>
43 #include <QHash>
44 
45 #if defined(qApp)
46 #undef qApp
47 #endif
48 
49 // Define new qApp macro. Yeaaaaah.
50 #define qApp (Application::instance())
51 
52 typedef QPair<UpdateInfo, QNetworkReply::NetworkError> UpdateCheck;
53 
54 class TemplateFactory;
55 class FormMain;
56 class SkinFactory;
57 class QAction;
58 class QMutex;
59 
60 /// \brief Key application class containing all critical
61 /// elements of the application.
62 /// \see Settings, FormMain, UpdateInfo, SystemTrayIcon
63 class Application : public QApplication {
64  Q_OBJECT
65 
66  public:
67  /// \brief Constructor.
68  /// \param argc Count of arguments passed to the executable file.
69  /// \param argv Array of strings of arguments.
70  explicit Application(int &argc, char **argv);
71  virtual ~Application();
72 
73  /// \brief Tries to download list with new updates.
74  /// \return Returns pair of information: metadata of update and
75  /// network status of update.
76  UpdateCheck checkForUpdates();
77 
78  /// \brief Access to application-wide settings.
79  /// \return
80  inline Settings *settings() {
81  if (m_settings == NULL) {
82  m_settings = Settings::setupSettings(this);
83  }
84 
85  return m_settings;
86  }
87 
88  /// \brief Access to application-wide close lock.
89  /// \return Returns pointer to application-wide close lock.
90  /// \remarks Application-wide close lock is used to determine if
91  /// application can be closed securely.
92  inline QMutex *closeLock() const {
93  return m_closeLock;
94  }
95 
96  /// \brief Access to application-wide skin facilities.
97  /// \return Returns pointer to skin facilities.
99 
100  /// \brief Access to "zip" utility path.
101  /// \return Returns path to "zip" utlity.
102  inline QString zipUtilityPath() {
103  return settings()->value(APP_CFG_GEN,
104  "zip_path",
105  QString(APP_ZIP_PATH)).toString();
106  }
107 
108  /// \brief Sets new path to "zip".
109  /// \param zip_path Path to "zip".
110  void setZipUtilityPath(const QString &zip_path);
111 
112  /// \brief Access to path to "signapk" utility.
113  /// \return Return path to "signapk".
114  inline QString signApkUtlityPath() {
115  return settings()->value(APP_CFG_GEN,
116  "signapk_path",
117  QString(APP_SIGNAPK_PATH)).toString();
118  }
119 
120  /// \brief Sets new path to "signapk".
121  /// \param signapk_path New path to "signapk".
122  void setSignApkUtilityPath(const QString &signapk_path);
123 
124  /// \brief Access to path to "java" interpreter.
125  /// \return Returns path to "java" interpreter.
126  inline QString javaInterpreterPath() {
127  return settings()->value(APP_CFG_GEN, "java_path", QString(APP_JAVA_PATH)).toString();
128  }
129 
130  /// \brief Sets new "java" interpreter path.
131  /// \param java_path New path to "java".
132  void setJavaInterpreterPath(const QString &java_path) {
133  settings()->setValue(APP_CFG_GEN, "java_path", java_path);
134  }
135 
136  /// \brief Tests if binary in new_path is correct JAVA executable.
137  /// \param new_path Path to JAVA executable.
138  /// \return Returns specific return code of JAVA executable.
139  int checkJava(const QString &new_path = QString());
140 
141  /// \brief Tests if binary in new_path is correct SIGNAPK executable.
142  /// \param new_path Path to SIGNAPK executable.
143  /// \param java_path Path to JAVA executable.
144  /// \return Returns specific return code of SIGNAPK executable.
145  int checkSignApk(const QString &new_path = QString(), const QString &java_path = QString());
146 
147  /// \brief Tests if binary in new_path is correct ZIP executable.
148  /// \param new_path Path to ZIP executable.
149  /// \return Returns specific return code of ZIP executable.
150  int checkZip(const QString &new_path = QString());
151 
152  void recheckExternalApplications(bool emit_signals);
153 
154  QString interpretJava(int return_code);
155  QString interpretZip(int return_code);
156  QString interpretSignApk(int return_code);
157 
158  /// \brief Access to main application form.
159  /// \return Returns pointer to main application form.
160  inline FormMain *mainForm() {
161  return m_mainForm;
162  }
163 
164  /// \brief Setter for main application form.
165  /// \param main_form Pointer to main application form.
166  void setMainForm(FormMain *main_form) {
167  m_mainForm = main_form;
168  }
169 
170  /// \brief Access to all application-wide useable actions.
171  /// \return Return list of user actions.
172  QList<QAction*> availableActions();
173 
174  /// \brief Access to application tray icon.
175  /// \return Returns pointer to application tray icon.
176  /// \warning Always use this in cooperation with
177  /// SystemTrayIcon::isSystemTrayActivated().
179 
180  /// \brief Access to template high level manager.
181  /// \see TemplateFactory
183 
184  /// \brief Main static getter of global Application instance.
185  /// \return Returns singleton for Application.
186  inline static Application *instance() {
187  return static_cast<Application*>(QCoreApplication::instance());
188  }
189 
190  bool externalApplicationsReady() const;
191  QString externalApplicationsStatus() const;
192  bool externalApplicationChecked() const;
193 
194  /// \brief Application closing indication.
195  /// \return Returns true, if application is closing, otherwise returns false.
196  bool isClosing() const;
197 
198  public slots:
199  /// \brief Schedules check for updates.
200  ///
201  /// Check for updates is executed in separate thread. Result is announced
202  /// via tray icon balloon tip. If tray icon is not available, then
203  /// result is not announced and is suppressed.
205 
206  private slots:
207  void onAboutToQuit();
208  void onCommitData(QSessionManager &manager);
209  void onSaveState(QSessionManager &manager);
210  void handleBackgroundUpdatesCheck();
211 
212  signals:
213  /// \brief Emitted if external applications are rechecked which happens
214  /// usually if path to some of external application changes.
216 
217  private:
218  bool m_externalApplicationChecked;
219  bool m_externalApplicationsReady;
220  QString m_externalApplicationsStatus;
221  QMutex *m_closeLock;
222  QList<QAction*> m_availableActions;
223  Settings *m_settings;
224  SkinFactory *m_skinFactory;
225  SystemTrayIcon *m_trayIcon;
226  FormMain *m_mainForm;
227  TemplateFactory *m_templateManager;
228  bool m_closing;
229 };
230 
231 #endif // APPLICATION_H
int checkZip(const QString &new_path=QString())
Tests if binary in new_path is correct ZIP executable.
bool isClosing() const
Application closing indication.
Main features for skinning.
Definition: skinfactory.h:59
Settings * settings()
Access to application-wide settings.
Definition: application.h:80
Main application window.
Definition: formmain.h:53
FormMain * mainForm()
Access to main application form.
Definition: application.h:160
QString javaInterpreterPath()
Access to path to "java" interpreter.
Definition: application.h:126
void setMainForm(FormMain *main_form)
Setter for main application form.
Definition: application.h:166
void checkForUpdatesOnBackground()
Schedules check for updates.
void setJavaInterpreterPath(const QString &java_path)
Sets new "java" interpreter path.
Definition: application.h:132
void setSignApkUtilityPath(const QString &signapk_path)
Sets new path to "signapk".
Definition: application.cpp:86
void setValue(const QString &section, const QString &key, const QVariant &value)
Sets new value into settings.
Definition: settings.h:74
static Application * instance()
Main static getter of global Application instance.
Definition: application.h:186
int checkJava(const QString &new_path=QString())
Tests if binary in new_path is correct JAVA executable.
Definition: application.cpp:90
UpdateCheck checkForUpdates()
Tries to download list with new updates.
Definition: application.cpp:70
The top-level manager of templates.
QMutex * closeLock() const
Access to application-wide close lock.
Definition: application.h:92
TemplateFactory * templateManager()
Access to template high level manager.
Application-wide settings mechanism.
Definition: settings.h:40
Key application class containing all critical elements of the application.
Definition: application.h:63
QList< QAction * > availableActions()
Access to all application-wide useable actions.
SkinFactory * skinFactory()
Access to application-wide skin facilities.
Definition: application.cpp:74
void externalApplicationsRechecked()
Emitted if external applications are rechecked which happens usually if path to some of external appl...
SystemTrayIcon * trayIcon()
Access to application tray icon.
Application-wide tray icon.
QVariant value(const QString &section, const QString &key, const QVariant &default_value=QVariant())
Getter/setter for settings values.
Definition: settings.h:64
QString zipUtilityPath()
Access to "zip" utility path.
Definition: application.h:102
Application(int &argc, char **argv)
Constructor.
Definition: application.cpp:51
static Settings * setupSettings(QObject *parent)
Creates settings file in correct location.
Definition: settings.cpp:57
void setZipUtilityPath(const QString &zip_path)
Sets new path to "zip".
Definition: application.cpp:82
int checkSignApk(const QString &new_path=QString(), const QString &java_path=QString())
Tests if binary in new_path is correct SIGNAPK executable.
QString signApkUtlityPath()
Access to path to "signapk" utility.
Definition: application.h:114