5e99551a1b6518b107fba772a0ece21783a79a5c
[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             QStringList result;
40             result = app.arguments().filter(".qml");
41             if (result.size() == 1 && QFile(result.last()).exists()) {
42               app.sendMessage(QFileInfo(result.last()).absoluteFilePath());
43             } else {
44               app.sendMessage(APP_MESSAGE_SETWIDGET);         
45             }
46             return 0;
47         }
48     }
49
50     app.setQuitOnLastWindowClosed(false);
51     AppEventListener::instance();
52
53     if (app.arguments().contains("forget-widgets"))
54     {
55         qDebug() << "We were asked to forget all widgets!";
56         QeMaemo5DynamicWidgetHelper::globalInstance()->forgetAllWidgets();
57     }
58     else
59     {
60         qDebug() << "Restoring all widgets";
61         QeMaemo5DynamicWidgetHelper::globalInstance()->restoreWidgets<QuickWidget>();
62     }
63     QStringList result;
64     result = app.arguments().filter(".qml");
65     if (result.size() == 1 && QFile(result.last()).exists()) {
66       app.sendMessage(QFileInfo(result.last()).absoluteFilePath());
67     } else if (!app.arguments().contains("in-background"))
68     {
69         // setting for new widget
70         QuickWidgetSettings settingsDialog;
71         settingsDialog.exec();
72         //app.sendMessage(APP_MESSAGE_SETWIDGET);
73     }
74     return app.exec();
75 }