Added cameraplus.ini to store application specific settings
authorMohammed Sameer <msameer@foolab.org>
Sat, 23 Feb 2013 20:54:16 +0000 (22:54 +0200)
committerMohammed Sameer <msameer@foolab.org>
Sat, 23 Feb 2013 20:54:16 +0000 (22:54 +0200)
data/n9/cameraplus.ini [new file with mode: 0644]
src/main.cpp
src/platformsettings.cpp [new file with mode: 0644]
src/platformsettings.h [new file with mode: 0644]
src/src.pro

diff --git a/data/n9/cameraplus.ini b/data/n9/cameraplus.ini
new file mode 100644 (file)
index 0000000..c5d0389
--- /dev/null
@@ -0,0 +1,13 @@
+[quill]
+previewSize = @Size(854 480)
+thumbnailFlavorName = screen
+thumbnailExtension = jpeg
+
+# QColor(Qt::black)
+backgroundRenderingColor = @Variant(\0\0\0\x43\x1\xff\xff\0\0\0\0\0\0\0\0)
+
+# Empty to use the default
+
+temporaryFilePath =
+dbusThumbnailingEnabled = true
+thumbnailCreationEnabled = true
index 3e33b8c..d7e6306 100644 (file)
 #include "gridlines.h"
 #include "deviceinfo.h"
 #include "devicekeys.h"
+#include "platformsettings.h"
 
 #ifdef QMLJSDEBUGGER
 #include "qt_private/qdeclarativedebughelper_p.h"
 #endif /* QMLJSDEBUGGER */
 
-static void initQuill() {
-  // TODO: All these are hardcoded.
-  Quill::setPreviewLevelCount(1);
-  Quill::setPreviewSize(0, QSize(854, 480));
-  Quill::setMinimumPreviewSize(0, QSize(854, 480));
-  Quill::setThumbnailExtension("jpeg");
-  Quill::setThumbnailFlavorName(0, "screen");
-  Quill::setBackgroundRenderingColor(Qt::black);
-  QString tempPath(QDir::homePath() +  QDir::separator() + ".config" +
-                  QDir::separator() + "quill" + QDir::separator() + "tmp");
+static void initQuill(PlatformSettings *settings) {
+  QList<QPair<QString, QSize> > previewLevels = settings->previewLevels();
+  Quill::setPreviewLevelCount(previewLevels.size());
+
+  for (int x = 0; x < previewLevels.size(); x++) {
+    Quill::setThumbnailFlavorName(x, previewLevels[x].first);
+    Quill::setPreviewSize(x, previewLevels[x].second);
+    Quill::setMinimumPreviewSize(x, previewLevels[x].second);
+  }
+
+  Quill::setThumbnailExtension(settings->thumbnailExtension());
+  Quill::setBackgroundRenderingColor(settings->backgroundRenderingColor());
+  Quill::setDBusThumbnailingEnabled(settings->isDBusThumbnailingEnabled());
+  Quill::setThumbnailCreationEnabled(settings->isThumbnailCreationEnabled());
+
+  QString tempPath = settings->temporaryFilePath();
   QDir().mkpath(tempPath);
   Quill::setTemporaryFilePath(tempPath);
-  Quill::setDBusThumbnailingEnabled(true);
-  Quill::setThumbnailCreationEnabled(true);
 }
 
 Q_DECL_EXPORT int main(int argc, char *argv[]) {
@@ -75,9 +80,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   QDeclarativeDebugHelper::enableDebugging();
 #endif /* QMLJSDEBUGGER */
 
-  // Let's initialize Quill:
-  initQuill();
-
   QDeclarativeView view;
   view.setAttribute(Qt::WA_NoSystemBackground);
   view.setViewport(new QGLWidget);
@@ -85,6 +87,11 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
   view.viewport()->setAttribute(Qt::WA_NoSystemBackground);
 
+  PlatformSettings platformSettings;
+
+  // Let's initialize Quill:
+  initQuill(&platformSettings);
+
   qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
   qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
diff --git a/src/platformsettings.cpp b/src/platformsettings.cpp
new file mode 100644 (file)
index 0000000..9122bed
--- /dev/null
@@ -0,0 +1,69 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "platformsettings.h"
+#include <QDir>
+#include <QSize>
+
+#define PATH "/usr/share/cameraplus/config/cameraplus.ini"
+
+#define PREVIEW_SIZE                             QSize(854, 480)
+#define THUMBNAIL_FLAVOR_NAME                    QString("screen")
+#define TEMPORARY_FILE_PATH                      "%1%2.config%2quill%2tmp"
+#define THUMBNAIL_EXTENSION                      QString("jpeg")
+#define THUMBNAIL_CREATION_ENABLED               true
+#define DBUS_THUMBNAILING_ENABLED                true
+#define BACKGROUND_RENDERING_COLOR               QColor(Qt::black)
+
+PlatformSettings::PlatformSettings() :
+  QSettings(PATH, QSettings::IniFormat) {
+
+}
+
+PlatformSettings::~PlatformSettings() {
+
+}
+
+QList<QPair<QString, QSize> > PlatformSettings::previewLevels() {
+  return QList<QPair<QString, QSize> >() <<
+    qMakePair<QString, QSize>(value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString(),
+                             value("quill/previewSize", PREVIEW_SIZE).toSize());
+}
+
+QString PlatformSettings::thumbnailExtension() {
+  return value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
+}
+
+QColor PlatformSettings::backgroundRenderingColor() {
+  return value("quill/backgroundRenderingColor", BACKGROUND_RENDERING_COLOR).value<QColor>();
+}
+
+bool PlatformSettings::isDBusThumbnailingEnabled() {
+  return value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
+}
+
+bool PlatformSettings::isThumbnailCreationEnabled() {
+  return value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
+}
+
+QString PlatformSettings::temporaryFilePath() {
+  QString defaultPath = QString(TEMPORARY_FILE_PATH).arg(QDir::homePath()).arg(QDir::separator());
+  return value("quill/temporaryFilePath", defaultPath).toString();
+}
diff --git a/src/platformsettings.h b/src/platformsettings.h
new file mode 100644 (file)
index 0000000..2c3ad9f
--- /dev/null
@@ -0,0 +1,43 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef PLATFORM_SETTINGS_H
+#define PLATFORM_SETTINGS_H
+
+#include <QSettings>
+#include <QColor>
+
+class PlatformSettings : private QSettings {
+public:
+  PlatformSettings();
+  ~PlatformSettings();
+
+  QList<QPair<QString, QSize> > previewLevels();
+
+  QString thumbnailExtension();
+  QColor backgroundRenderingColor();
+  bool isDBusThumbnailingEnabled();
+  bool isThumbnailCreationEnabled();
+  QString temporaryFilePath();
+};
+
+#endif /* PLATFORM_SETTINGS_H */
index f73043f..fbddb4d 100644 (file)
@@ -15,12 +15,14 @@ PKGCONFIG = quill qmsystem2 libresourceqt1
 SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
            cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \
            trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp galleryhelper.cpp \
-           postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp devicekeys.cpp
+           postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp devicekeys.cpp \
+           platformsettings.cpp
 
 HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
            cameraresources.h compass.h orientation.h geocode.h mountprotector.h \
            trackerstore.h focusrectangle.h sharehelper.h deletehelper.h galleryhelper.h \
-           postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h devicekeys.h
+           postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h devicekeys.h \
+           platformsettings.h
 
 RESOURCES += ../qml/qml.qrc