407095bc521e2da2c1ee541e6678578376d58754
[harmattan/cameraplus] / src / main.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #if defined(QT4)
22 #include <QApplication>
23 #include <QDeclarativeView>
24 #include <QDeclarativeContext>
25 #include <QDeclarativeEngine>
26 #include <QtDeclarative>
27 #include <QGLWidget>
28 #elif defined(QT5)
29 #include <QGuiApplication>
30 #include <QQuickView>
31 #include <QQmlError>
32 #endif
33
34 #include "settings.h"
35 #include "filenaming.h"
36 #ifdef HARMATTAN
37 #include "quillitem.h"
38 #endif
39 #include "geocode.h"
40 #include "deviceinfo.h"
41 #include "soundvolumecontrol.h"
42 #include "displaystate.h"
43 #include "fsmonitor.h"
44 #include "cameraresources.h"
45 #include "compass.h"
46 #include "orientation.h"
47 #include "mountprotector.h"
48 #include "trackerstore.h"
49 #include "focusrectangle.h"
50 #include "sharehelper.h"
51 #include "deletehelper.h"
52 #include "galleryhelper.h"
53 #include "postcapturemodel.h"
54 #include "batteryinfo.h"
55 #include "gridlines.h"
56 #include "devicekeys.h"
57 #include "platformsettings.h"
58 #include "dbusservice.h"
59 #include <MDeclarativeCache>
60
61 #ifdef QMLJSDEBUGGER
62 #include "qt_private/qdeclarativedebughelper_p.h"
63 #endif /* QMLJSDEBUGGER */
64
65 #if defined(QT4)
66 #include <QAbstractFileEngineHandler>
67 #include "qmlfileengine.h"
68
69 class QmlFileEngineHandler : public QAbstractFileEngineHandler {
70   QAbstractFileEngine *create(const QString& fileName) const {
71     QString fn = fileName.toLower();
72     if (fn.startsWith(':') && fn.endsWith(".qml")) {
73       return new QmlFileEngine(fileName);
74     }
75
76     return 0;
77   }
78 };
79 #endif
80
81 Q_DECL_EXPORT int main(int argc, char *argv[]) {
82 #if defined(QT4)
83   QApplication::setAttribute(Qt::AA_X11InitThreads, true);
84   QApplication *app = new QApplication(argc, argv);
85   app->setApplicationName("cameraplus");
86
87   QmlFileEngineHandler handler;
88   Q_UNUSED(handler);
89
90   QDeclarativeView *view = MDeclarativeCache::qDeclarativeView();
91 #elif defined(QT5)
92   QGuiApplication *app = MDeclarativeCache::qApplication(argc, argv);
93   app->setApplicationName("cameraplus");
94
95   QQuickView *view = MDeclarativeCache::qQuickView();
96 #endif
97
98 #ifdef QMLJSDEBUGGER
99   QDeclarativeDebugHelper::enableDebugging();
100 #endif /* QMLJSDEBUGGER */
101
102 #if defined(QT4)
103   view->setAttribute(Qt::WA_NoSystemBackground);
104   view->setViewport(new QGLWidget);
105   view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
106   view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
107   view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
108 #endif
109
110 #if defined(QT5)
111   view->setResizeMode(QQuickView::SizeRootObjectToView);
112   // TODO:
113 #endif
114
115   qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
116   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
117 #ifdef HARMATTAN
118   qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
119 #endif
120   qmlRegisterType<Geocode>("CameraPlus", 1, 0, "ReverseGeocode");
121   qmlRegisterType<DeviceInfo>("CameraPlus", 1, 0, "DeviceInfo");
122   qmlRegisterType<SoundVolumeControl>("CameraPlus", 1, 0, "SoundVolumeControl");
123   qmlRegisterType<DisplayState>("CameraPlus", 1, 0, "DisplayState");
124   qmlRegisterType<FSMonitor>("CameraPlus", 1, 0, "FSMonitor");
125   qmlRegisterType<CameraResources>("CameraPlus", 1, 0, "CameraResources");
126   qmlRegisterType<Compass>("CameraPlus", 1, 0, "CameraCompass");
127   qmlRegisterType<Orientation>("CameraPlus", 1, 0, "CameraOrientation");
128   qmlRegisterType<MountProtector>("CameraPlus", 1, 0, "MountProtector");
129   qmlRegisterType<TrackerStore>("CameraPlus", 1, 0, "TrackerStore");
130   qmlRegisterType<FocusRectangle>("CameraPlus", 1, 0, "FocusRectangle");
131   qmlRegisterType<ShareHelper>("CameraPlus", 1, 0, "ShareHelper");
132   qmlRegisterType<DeleteHelper>("CameraPlus", 1, 0, "DeleteHelper");
133   qmlRegisterType<GalleryHelper>("CameraPlus", 1, 0, "GalleryHelper");
134   qmlRegisterType<PostCaptureModel>("CameraPlus", 1, 0, "PostCaptureModel");
135   qmlRegisterType<BatteryInfo>("CameraPlus", 1, 0, "BatteryInfo");
136   qmlRegisterType<GridLines>("CameraPlus", 1, 0, "GridLines");
137   qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
138   qmlRegisterType<PlatformSettings>("CameraPlus", 1, 0, "PlatformSettings");
139
140   view->setSource(QUrl("qrc:/qml/main.qml"));
141
142 #if defined(QT5)
143   if (view->status() == QQuickView::Error) {
144     qCritical() << "Errors loading QML:";
145     QList<QQmlError> errors = view->errors();
146
147     foreach (const QQmlError& error, errors) {
148       qCritical() << error.toString();
149     }
150
151     delete view;
152     delete app;
153
154     return 1;
155   }
156 #endif
157
158   view->showFullScreen();
159
160   int ret = app->exec();
161
162   delete view;
163   delete app;
164
165   return ret;
166 }