Initial Qt5 port
[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 #endif
32
33 #include "settings.h"
34 #include "filenaming.h"
35 #ifdef HARMATTAN
36 #include "quillitem.h"
37 #endif
38 #include "soundvolumecontrol.h"
39 #include "displaystate.h"
40 #include "fsmonitor.h"
41 #include "cameraresources.h"
42 #include "compass.h"
43 #include "orientation.h"
44 #if defined(QT4) // TODO:
45 #include "geocode.h"
46 #endif
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 "deviceinfo.h"
57 #include "devicekeys.h"
58 #include "platformsettings.h"
59 #include "dbusservice.h"
60
61 #ifdef HAVE_BOOSTER
62 #include <MDeclarativeCache>
63 #endif
64
65 #ifdef QMLJSDEBUGGER
66 #include "qt_private/qdeclarativedebughelper_p.h"
67 #endif /* QMLJSDEBUGGER */
68
69 #if defined(QT4)
70 #include <QAbstractFileEngineHandler>
71 #include "qmlfileengine.h"
72
73 class QmlFileEngineHandler : public QAbstractFileEngineHandler {
74   QAbstractFileEngine *create(const QString& fileName) const {
75     QString fn = fileName.toLower();
76     if (fn.startsWith(':') && fn.endsWith(".qml")) {
77       return new QmlFileEngine(fileName);
78     }
79
80     return 0;
81   }
82 };
83 #endif
84
85 Q_DECL_EXPORT int main(int argc, char *argv[]) {
86 #if defined(QT4)
87   QApplication::setAttribute(Qt::AA_X11InitThreads, true);
88   QApplication *app = new QApplication(argc, argv);
89
90   QmlFileEngineHandler handler;
91   Q_UNUSED(handler);
92
93   QDeclarativeView *view = new QDeclarativeView;
94 #elif defined(HAVE_BOOSTER)
95   QGuiApplication *app = MDeclarativeCache::qApplication(argc, argv);
96   QQuickView *view = MDeclarativeCache::qQuickView();
97 #elif defined(QT5)
98   QGuiApplication::setAttribute(Qt::AA_X11InitThreads, true);
99   QGuiApplication *app = new QGuiApplication(argc, argv);
100   QQuickView *view = new QQuickView;
101 #endif
102
103 #ifdef QMLJSDEBUGGER
104   QDeclarativeDebugHelper::enableDebugging();
105 #endif /* QMLJSDEBUGGER */
106
107 #if defined(QT4)
108   view->setAttribute(Qt::WA_NoSystemBackground);
109   view->setViewport(new QGLWidget);
110   view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
111   view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
112   view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
113 #endif
114
115 #if defined(QT5)
116   view->setResizeMode(QQuickView::SizeRootObjectToView);
117   // TODO:
118 #endif
119
120   qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
121   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
122 #ifdef HARMATTAN
123   qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
124 #endif
125   qmlRegisterType<SoundVolumeControl>("CameraPlus", 1, 0, "SoundVolumeControl");
126   qmlRegisterType<DisplayState>("CameraPlus", 1, 0, "DisplayState");
127   qmlRegisterType<FSMonitor>("CameraPlus", 1, 0, "FSMonitor");
128   qmlRegisterType<CameraResources>("CameraPlus", 1, 0, "CameraResources");
129   qmlRegisterType<Compass>("CameraPlus", 1, 0, "Compass");
130   qmlRegisterType<Orientation>("CameraPlus", 1, 0, "Orientation");
131 #if defined(QT4) // TODO:
132   qmlRegisterType<Geocode>("CameraPlus", 1, 0, "ReverseGeocode");
133 #endif
134   qmlRegisterType<MountProtector>("CameraPlus", 1, 0, "MountProtector");
135   qmlRegisterType<TrackerStore>("CameraPlus", 1, 0, "TrackerStore");
136   qmlRegisterType<FocusRectangle>("CameraPlus", 1, 0, "FocusRectangle");
137   qmlRegisterType<ShareHelper>("CameraPlus", 1, 0, "ShareHelper");
138   qmlRegisterType<DeleteHelper>("CameraPlus", 1, 0, "DeleteHelper");
139   qmlRegisterType<GalleryHelper>("CameraPlus", 1, 0, "GalleryHelper");
140   qmlRegisterType<PostCaptureModel>("CameraPlus", 1, 0, "PostCaptureModel");
141   qmlRegisterType<BatteryInfo>("CameraPlus", 1, 0, "BatteryInfo");
142   qmlRegisterType<GridLines>("CameraPlus", 1, 0, "GridLines");
143 #if defined(QT4) // TODO:
144   qmlRegisterType<DeviceInfo>("CameraPlus", 1, 0, "DeviceInfo");
145 #endif
146   qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
147   qmlRegisterType<PlatformSettings>("CameraPlus", 1, 0, "PlatformSettings");
148
149   view->setSource(QUrl("qrc:/qml/main.qml"));
150
151   view->showFullScreen();
152
153   int ret = app->exec();
154
155   delete view;
156   delete app;
157
158   return ret;
159 }