Make sure we don't play camera sounds in silent profile
[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 "phoneprofile.h"
60 #include <MDeclarativeCache>
61
62 #ifdef QMLJSDEBUGGER
63 #include "qt_private/qdeclarativedebughelper_p.h"
64 #endif /* QMLJSDEBUGGER */
65
66 #if defined(QT4)
67 #include <QAbstractFileEngineHandler>
68 #include "qmlfileengine.h"
69
70 class QmlFileEngineHandler : public QAbstractFileEngineHandler {
71   QAbstractFileEngine *create(const QString& fileName) const {
72     QString fn = fileName.toLower();
73     if (fn.startsWith(':') && fn.endsWith(".qml")) {
74       return new QmlFileEngine(fileName);
75     }
76
77     return 0;
78   }
79 };
80 #endif
81
82 Q_DECL_EXPORT int main(int argc, char *argv[]) {
83 #ifdef QMLJSDEBUGGER
84   QDeclarativeDebugHelper::enableDebugging();
85 #endif /* QMLJSDEBUGGER */
86
87 #if defined(QT4)
88   QApplication::setAttribute(Qt::AA_X11InitThreads, true);
89   QApplication *app = new QApplication(argc, argv);
90   app->setApplicationName("cameraplus");
91
92   QmlFileEngineHandler handler;
93   Q_UNUSED(handler);
94
95   QDeclarativeView *view = MDeclarativeCache::qDeclarativeView();
96 #elif defined(QT5)
97   QGuiApplication *app = MDeclarativeCache::qApplication(argc, argv);
98   app->setApplicationName("cameraplus");
99
100   QQuickView *view = MDeclarativeCache::qQuickView();
101 #endif
102
103 #if defined(QT4)
104   view->setAttribute(Qt::WA_NoSystemBackground);
105   view->setViewport(new QGLWidget);
106   view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
107   view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
108   view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
109 #endif
110
111 #if defined(QT5)
112   view->setResizeMode(QQuickView::SizeRootObjectToView);
113   // TODO:
114 #endif
115
116   qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
117   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
118 #ifdef HARMATTAN
119   qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
120 #endif
121   qmlRegisterType<Geocode>("CameraPlus", 1, 0, "ReverseGeocode");
122   qmlRegisterType<DeviceInfo>("CameraPlus", 1, 0, "DeviceInfo");
123   qmlRegisterType<SoundVolumeControl>("CameraPlus", 1, 0, "SoundVolumeControl");
124   qmlRegisterType<DisplayState>("CameraPlus", 1, 0, "DisplayState");
125   qmlRegisterType<FSMonitor>("CameraPlus", 1, 0, "FSMonitor");
126   qmlRegisterType<CameraResources>("CameraPlus", 1, 0, "CameraResources");
127   qmlRegisterType<Compass>("CameraPlus", 1, 0, "CameraCompass");
128   qmlRegisterType<Orientation>("CameraPlus", 1, 0, "CameraOrientation");
129   qmlRegisterType<MountProtector>("CameraPlus", 1, 0, "MountProtector");
130   qmlRegisterType<TrackerStore>("CameraPlus", 1, 0, "TrackerStore");
131   qmlRegisterType<FocusRectangle>("CameraPlus", 1, 0, "FocusRectangle");
132   qmlRegisterType<ShareHelper>("CameraPlus", 1, 0, "ShareHelper");
133   qmlRegisterType<DeleteHelper>("CameraPlus", 1, 0, "DeleteHelper");
134   qmlRegisterType<GalleryHelper>("CameraPlus", 1, 0, "GalleryHelper");
135   qmlRegisterType<PostCaptureModel>("CameraPlus", 1, 0, "PostCaptureModel");
136   qmlRegisterType<BatteryInfo>("CameraPlus", 1, 0, "BatteryInfo");
137   qmlRegisterType<GridLines>("CameraPlus", 1, 0, "GridLines");
138   qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
139   qmlRegisterType<PlatformSettings>("CameraPlus", 1, 0, "PlatformSettings");
140   qmlRegisterType<PhoneProfile>("CameraPlus", 1, 0, "PhoneProfile");
141
142   view->setSource(QUrl("qrc:/qml/main.qml"));
143
144 #if defined(QT5)
145   if (view->status() == QQuickView::Error) {
146     qCritical() << "Errors loading QML:";
147     QList<QQmlError> errors = view->errors();
148
149     foreach (const QQmlError& error, errors) {
150       qCritical() << error.toString();
151     }
152
153     delete view;
154     delete app;
155
156     return 1;
157   }
158 #endif
159
160   view->showFullScreen();
161
162   int ret = app->exec();
163
164   delete view;
165   delete app;
166
167   return ret;
168 }