Commit latest bug fixes
[quick-widgets] / main.cpp
1 #include <QApplication>
2 //#include <QDeclarativeEngine>
3 #include <QDeclarativeComponent>
4 #include <q-extras/qemaemo5dynamicwidgethelper.h>
5 #include <q-extras/qtsingleapplication.h>
6 #include <q-extras/qesettingsmanager.h>
7 #include "ProcessObject.h"
8 #include "quickwidget.hpp"
9 #include "quickwidgetsettings.hpp"
10 #include "appeventlistener.hpp"
11
12 int main(int argc, char *argv[])
13 {
14     QApplication::setApplicationName("Quick Widgets");
15     QApplication::setOrganizationName("Marquarding");
16     // APP_VERSION and APP_BETA are defined in the .pro file
17     QApplication::setApplicationVersion(QString(APP_VERSION)
18 #if APP_BETA
19         + " beta"
20 #endif
21         );
22
23     QtSingleApplication app(argc, argv);
24     qmlRegisterType<ProcessObject>("quickwidgets", 1,0, "Process");
25
26     qDebug() << "Launched quick widgets app";
27
28     if (app.isRunning())
29     {
30         qDebug() << "Another instance of the app is running.";
31         if (app.arguments().contains("in-background"))
32         {
33             qDebug() << "Closing that other instance.";
34             app.sendMessage(APP_MESSAGE_CLOSE);
35         }
36         else
37         {
38             qDebug() << "Asking it to offer to create a new widget.";
39             app.sendMessage(APP_MESSAGE_ADDWIDGET);
40             return 0;
41         }
42     }
43
44     app.setQuitOnLastWindowClosed(false);
45     AppEventListener::instance();
46
47     if (app.arguments().contains("forget-widgets"))
48     {
49         qDebug() << "We were asked to forget all widgets!";
50         QeMaemo5DynamicWidgetHelper::globalInstance()->forgetAllWidgets();
51     }
52     else
53     {
54         qDebug() << "Restoring all widgets";
55         QeMaemo5DynamicWidgetHelper::globalInstance()->restoreWidgets<QuickWidget>();
56     }
57
58     if (!app.arguments().contains("in-background"))
59     {
60         // setting for new widget
61         QuickWidgetSettings settingsDialog;
62         settingsDialog.exec();
63         //app.sendMessage(APP_MESSAGE_ADDWIDGET);
64     }
65     return app.exec();
66 }