Adding the C++ application and the Settings class
authorMohammed Sameer <msameer@foolab.org>
Tue, 4 Sep 2012 09:54:17 +0000 (12:54 +0300)
committerMohammed Sameer <msameer@foolab.org>
Thu, 6 Sep 2012 16:10:10 +0000 (19:10 +0300)
src/main.cpp [new file with mode: 0644]
src/settings.cpp [new file with mode: 0644]
src/settings.h [new file with mode: 0644]
src/src.pro [new file with mode: 0644]

diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644 (file)
index 0000000..c582233
--- /dev/null
@@ -0,0 +1,30 @@
+#include <QApplication>
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+#include <QDeclarativeEngine>
+#include <QtDeclarative>
+#include <QGLWidget>
+
+#include "imports/plugin.h"
+
+#include "settings.h"
+
+Q_DECL_EXPORT int main(int argc, char *argv[]) {
+  QApplication app(argc, argv);
+
+  QDeclarativeView view;
+  view.setViewport(new QGLWidget);
+  view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
+  view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+
+  Plugin::registerTypes(view.engine());
+  qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
+
+  QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
+  view.setSource(sourceUrl);
+
+  view.showFullScreen();
+
+  int ret = app.exec();
+  return ret;
+};
diff --git a/src/settings.cpp b/src/settings.cpp
new file mode 100644 (file)
index 0000000..a5da1a9
--- /dev/null
@@ -0,0 +1,29 @@
+#include "settings.h"
+#include <QSettings>
+#include <QDir>
+
+#define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
+
+#define DEFAULT_MODE 0
+
+Settings::Settings(QObject *parent) :
+  QObject(parent),
+  m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
+
+}
+
+Settings::~Settings() {
+  delete m_settings; m_settings = 0;
+}
+
+int Settings::mode() const {
+  return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
+}
+
+void Settings::setMode(int mode) {
+  if (mode != Settings::mode()) {
+    m_settings->setValue("camera/mode", mode);
+    emit modeChanged();
+  }
+}
+
diff --git a/src/settings.h b/src/settings.h
new file mode 100644 (file)
index 0000000..33e152e
--- /dev/null
@@ -0,0 +1,29 @@
+// -*- c++ -*-
+
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <QObject>
+
+class QSettings;
+
+class Settings : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(int mode READ mode WRITE setMode NOTIFY modeChanged);
+
+public:
+  Settings(QObject *parent = 0);
+  ~Settings();
+
+  int mode() const;
+  void setMode(int mode);
+
+signals:
+  void modeChanged();
+
+private:
+  QSettings *m_settings;
+};
+
+#endif /* SETTINGS_H */
diff --git a/src/src.pro b/src/src.pro
new file mode 100644 (file)
index 0000000..82245e4
--- /dev/null
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = cameraplus
+DEPENDPATH += . ../
+INCLUDEPATH += . ../
+
+QT += declarative opengl
+
+CONFIG += link_pkgconfig debug static
+
+PKGCONFIG = gstreamer-0.10 gstreamer-interfaces-0.10 gstreamer-video-0.10 gstreamer-tag-0.10 \
+            gstreamer-pbutils-0.10 meego-gstreamer-interfaces-0.10
+
+LIBS +=  -L../imports/ -limports -L../lib/ -lqtcamera
+
+SOURCES += main.cpp settings.cpp
+HEADERS += settings.h