31 #include "miscellaneous/application.h"
33 #include "miscellaneous/systemfactory.h"
34 #include "miscellaneous/skinfactory.h"
35 #include "network-web/networkfactory.h"
36 #include "gui/systemtrayicon.h"
37 #include "gui/formmain.h"
38 #include "core/templatefactory.h"
42 #include <QFutureWatcher>
44 #if QT_VERSION >= 0x050000
45 #include <QtConcurrent/QtConcurrentRun>
47 #include <QtConcurrentRun>
52 : QApplication(argc, argv),
53 m_externalApplicationChecked(false),
54 m_closeLock(new QMutex()),
55 m_availableActions(QList<QAction*>()),
59 m_templateManager(NULL),
61 connect(
this, SIGNAL(aboutToQuit()),
this, SLOT(onAboutToQuit()));
62 connect(
this, SIGNAL(commitDataRequest(QSessionManager&)),
this, SLOT(onCommitData(QSessionManager&)));
63 connect(
this, SIGNAL(saveStateRequest(QSessionManager&)),
this, SLOT(onSaveState(QSessionManager&)));
66 Application::~Application() {
75 if (m_skinFactory == NULL) {
93 if (java_path.isEmpty()) {
94 return EXIT_STATUS_NOT_STARTED;
99 process.setReadChannelMode(QProcess::MergedChannels);
100 process.start(QDir::toNativeSeparators(java_path), QStringList() <<
"-version");
101 process.waitForFinished(-1);
103 return process.exitCode();
111 if (signapk_path.isEmpty()) {
112 return EXIT_STATUS_NOT_STARTED;
117 process.setReadChannelMode(QProcess::MergedChannels);
118 process.start(QDir::toNativeSeparators(real_java_path),
119 QStringList() <<
"-jar" << QDir::toNativeSeparators(signapk_path));
120 process.waitForFinished(-1);
122 return process.exitCode();
127 QString zip_path = new_path.isEmpty() ?
zipUtilityPath() : new_path;
129 if (zip_path.isEmpty()) {
130 return EXIT_STATUS_NOT_STARTED;
135 process.setReadChannelMode(QProcess::MergedChannels);
136 process.start(QDir::toNativeSeparators(zip_path), QStringList() <<
"--version");
137 process.waitForFinished(-1);
139 return process.exitCode();
143 void Application::recheckExternalApplications(
bool emit_signals) {
148 if (signapk_ready != EXIT_STATUS_SIGNAPK_NORMAL ||
149 java_ready != EXIT_STATUS_JAVA_NORMAL ||
150 zip_ready != EXIT_STATUS_ZIP_NORMAL) {
151 m_externalApplicationsStatus = QString();
153 if (signapk_ready != EXIT_STATUS_SIGNAPK_NORMAL) {
154 m_externalApplicationsStatus += qApp->interpretSignApk(signapk_ready) +
'\n';
157 if (java_ready != EXIT_STATUS_JAVA_NORMAL) {
158 m_externalApplicationsStatus += qApp->interpretJava(java_ready) +
'\n';
161 if (zip_ready != EXIT_STATUS_ZIP_NORMAL) {
162 m_externalApplicationsStatus += qApp->interpretZip(zip_ready) +
'\n';
165 m_externalApplicationsStatus.chop(1);
166 m_externalApplicationsReady =
false;
169 m_externalApplicationsReady =
true;
172 m_externalApplicationChecked =
true;
179 QString Application::interpretJava(
int return_code) {
180 switch (return_code) {
181 case EXIT_STATUS_NOT_STARTED:
182 return tr(
"JAVA was not found at given location.");
184 case EXIT_STATUS_CRASH:
185 return tr(
"JAVA found but is crashy.");
187 case EXIT_STATUS_JAVA_NORMAL:
188 return tr(
"JAVA found and probably working.");
191 return tr(
"JAVA returned uknown code.");
195 QString Application::interpretZip(
int return_code) {
196 switch (return_code) {
197 case EXIT_STATUS_NOT_STARTED:
198 return tr(
"ZIP was not found at given location.");
200 case EXIT_STATUS_CRASH:
201 return tr(
"ZIP found but is crashy.");
203 case EXIT_STATUS_ZIP_NORMAL:
204 return tr(
"ZIP found and probably working.");
207 return tr(
"ZIP returned uknown code.");
211 QString Application::interpretSignApk(
int return_code) {
212 switch (return_code) {
213 case EXIT_STATUS_NOT_STARTED:
214 return tr(
"SIGNAPK was not found because JAVA was not found.");
216 case EXIT_STATUS_CRASH:
217 return tr(
"SIGNAPK found but is crashy.");
219 case EXIT_STATUS_SIGNAPK_NOT_FOUND:
220 return tr(
"SIGNAPK not found.");
222 case EXIT_STATUS_SIGNAPK_NORMAL:
223 return tr(
"SIGNAPK found and probably working.");
225 case EXIT_STATUS_SIGNAPK_WORKING:
226 return tr(
"SIGNAPK found and but there is high risk it is invalid.");
229 return tr(
"SIGNAPK returned uknown code.");
234 if (m_mainForm == NULL) {
235 return QList<QAction*>();
238 if (m_availableActions.isEmpty()) {
239 m_availableActions = m_mainForm->
allActions();
242 return m_availableActions;
247 if (m_trayIcon == NULL) {
249 m_trayIcon->setToolTip(APP_LONG_NAME);
256 if (m_templateManager == NULL) {
260 return m_templateManager;
263 void Application::handleBackgroundUpdatesCheck() {
264 QFutureWatcher<UpdateCheck> *future_watcher =
static_cast<QFutureWatcher<UpdateCheck>*
>(sender());
265 UpdateCheck updates = future_watcher->result();
267 switch (updates.second) {
268 case QNetworkReply::NoError:
269 if (updates.first.m_availableVersion > APP_VERSION) {
272 tr(
"New application update is available."),
273 QSystemTrayIcon::Information,
274 TRAY_ICON_BUBBLE_TIMEOUT,
276 SLOT(showUpdatesAfterBubbleClick()));
282 tr(
"No new updates are available."),
283 QSystemTrayIcon::Information);
293 QSystemTrayIcon::Warning);
304 bool Application::externalApplicationChecked()
const {
305 return m_externalApplicationChecked;
308 QString Application::externalApplicationsStatus()
const {
309 return m_externalApplicationsStatus;
312 bool Application::externalApplicationsReady()
const {
313 return m_externalApplicationsReady;
318 "check_for_updates_startup",
320 qDebug(
"Checking for updates after application startup is not allowed.");
323 qDebug(
"Checking for updates after application has started.");
325 QFutureWatcher<UpdateCheck> *watcher_for_future =
new QFutureWatcher<UpdateCheck>(
this);
327 connect(watcher_for_future, SIGNAL(finished()),
this, SLOT(handleBackgroundUpdatesCheck()));
332 void Application::onAboutToQuit() {
333 qDebug(
"Quitting the application.");
334 qDebug(
"Cleaning up resources and saving application state.");
336 if (
closeLock()->tryLock(CLOSE_LOCK_TIMEOUT)) {
339 qDebug(
"Close lock was obtained safely.");
349 qDebug(
"Close lock timed-out.");
353 void Application::onCommitData(QSessionManager &manager) {
354 qDebug(
"OS asked application to commit its data.");
358 manager.setRestartHint(QSessionManager::RestartNever);
362 void Application::onSaveState(QSessionManager &manager) {
363 qDebug(
"OS asked application to save its state.");
365 manager.setRestartHint(QSessionManager::RestartNever);
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.
Settings * settings()
Access to application-wide settings.
QString javaInterpreterPath()
Access to path to "java" interpreter.
void showMessage(const QString &title, const QString &message, MessageIcon icon=Information, int milliseconds_timeout_hint=TRAY_ICON_BUBBLE_TIMEOUT, QObject *click_target=NULL, const char *click_slot=NULL)
Displays new balloon tip with message.
void checkForUpdatesOnBackground()
Schedules check for updates.
void setSignApkUtilityPath(const QString &signapk_path)
Sets new path to "signapk".
void setValue(const QString §ion, const QString &key, const QVariant &value)
Sets new value into settings.
static QPair< UpdateInfo, QNetworkReply::NetworkError > checkForUpdates()
Tries to synchronously download list with new updates.
int checkJava(const QString &new_path=QString())
Tests if binary in new_path is correct JAVA executable.
static QString networkErrorText(QNetworkReply::NetworkError error_code)
Gets human readable text for given network error.
UpdateCheck checkForUpdates()
Tries to download list with new updates.
The top-level manager of templates.
QMutex * closeLock() const
Access to application-wide close lock.
TemplateFactory * templateManager()
Access to template high level manager.
static bool isSystemTrayAvailable()
Indicates whether tray icon is supported.
QList< QAction * > availableActions()
Access to all application-wide useable actions.
void quit()
Quits running actions of template manager.
SkinFactory * skinFactory()
Access to application-wide skin facilities.
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 §ion, const QString &key, const QVariant &default_value=QVariant())
Getter/setter for settings values.
QList< QAction * > allActions()
Access to all actions provided by this window.
QString zipUtilityPath()
Access to "zip" utility path.
Application(int &argc, char **argv)
Constructor.
void setZipUtilityPath(const QString &zip_path)
Sets new path to "zip".
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.