c566fde8372cb685acdbc5d0d3fd2842d1827348
[harmattan/cameraplus] / src / platformsettings.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 #include "platformsettings.h"
22 #include <QDir>
23 #include <QSettings>
24 #ifdef HARMATTAN
25 #include <Quill>
26 #include "quillitem.h"
27 #endif
28
29 #define PATH "/usr/share/cameraplus/config/cameraplus.ini"
30
31 #define PREVIEW_SIZE                             QSize(854, 480)
32 #define THUMBNAIL_FLAVOR_NAME                    QString("screen")
33 #define TEMPORARY_FILE_PATH                      "%1%2.config%2quill%2tmp"
34 #define THUMBNAIL_EXTENSION                      QString("jpeg")
35 #define THUMBNAIL_CREATION_ENABLED               true
36 #define DBUS_THUMBNAILING_ENABLED                true
37 #define BACKGROUND_RENDERING_COLOR               QColor(Qt::black)
38
39 PlatformSettings::PlatformSettings(QObject *parent) :
40   QObject(parent), m_settings(new QSettings(PATH, QSettings::IniFormat)) {
41
42 }
43
44 PlatformSettings::~PlatformSettings() {
45   delete m_settings;
46 }
47
48 QSize PlatformSettings::previewSize() {
49   return m_settings->value("quill/previewSize", PREVIEW_SIZE).toSize();
50 }
51
52 QString PlatformSettings::thumbnailFlavorName() {
53   return m_settings->value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString();
54 }
55
56 QString PlatformSettings::thumbnailExtension() {
57   return m_settings->value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
58 }
59
60 QColor PlatformSettings::backgroundRenderingColor() {
61   return m_settings->value("quill/backgroundRenderingColor",
62                            BACKGROUND_RENDERING_COLOR).value<QColor>();
63 }
64
65 bool PlatformSettings::isDBusThumbnailingEnabled() {
66   return m_settings->value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
67 }
68
69 bool PlatformSettings::isThumbnailCreationEnabled() {
70   return m_settings->value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
71 }
72
73 QString PlatformSettings::temporaryFilePath() {
74   QString defaultPath = QString(TEMPORARY_FILE_PATH).arg(QDir::homePath()).arg(QDir::separator());
75   return m_settings->value("quill/temporaryFilePath", defaultPath).toString();
76 }
77
78 QSize PlatformSettings::portraitSize(const QSize& size) {
79   return size.width() > size.height() ? QSize(size.height(), size.width()) : size;
80 }
81
82 QSize PlatformSettings::landscapeSize(const QSize& size) {
83   return size.width() > size.height() ? size : QSize(size.height(), size.width());
84 }
85
86 void PlatformSettings::init() {
87 #ifdef HARMATTAN
88   // How we create thumbnails for portrait is really messy.
89   // I am sure there is a better way to tell Quill to generate proper
90   // portrait thumbnails without having 2 display levels but I don't know how.
91   // The issue is we generate screen sized thumbnails for landscape
92   // but we generate half screen sized thumbnails for portrait
93   Quill::setPreviewLevelCount(2);
94   QSize size = previewSize();
95
96   // Landscape:
97   Quill::setThumbnailFlavorName(LANDSCAPE_PREVIEW_LEVEL, thumbnailFlavorName());
98   Quill::setPreviewSize(LANDSCAPE_PREVIEW_LEVEL, landscapeSize(size));
99
100   // Portrait:
101   Quill::setThumbnailFlavorName(PORTRAIT_PREVIEW_LEVEL, thumbnailFlavorName());
102   Quill::setPreviewSize(PORTRAIT_PREVIEW_LEVEL, portraitSize(size));
103
104   Quill::setThumbnailExtension(thumbnailExtension());
105   Quill::setBackgroundRenderingColor(backgroundRenderingColor());
106   Quill::setDBusThumbnailingEnabled(isDBusThumbnailingEnabled());
107   Quill::setThumbnailCreationEnabled(isThumbnailCreationEnabled());
108
109   QString tempPath = temporaryFilePath();
110   QDir().mkpath(tempPath);
111   Quill::setTemporaryFilePath(tempPath);
112 #endif
113 }
114
115 PlatformSettings::Service PlatformSettings::service(const QString& id) {
116   PlatformSettings::Service service;
117   m_settings->beginGroup(id);
118
119   service.m_enabled = m_settings->value("enabled", false).toBool();
120   service.m_type = m_settings->value("type").toString();
121   service.m_path = m_settings->value("path").toString();
122   service.m_interface = m_settings->value("interface").toString();
123   service.m_dest = m_settings->value("dest").toString();
124   service.m_method = m_settings->value("method").toString();
125
126   m_settings->endGroup();
127
128   return service;
129 }
130
131 QString PlatformSettings::imageCaptureStartedSound() const {
132   return m_settings->value("sounds/imageCaptureStarted").toString();
133 }
134
135 QString PlatformSettings::imageCaptureEndedSound() const {
136   return m_settings->value("sounds/imageCaptureEnded").toString();
137 }
138
139 QString PlatformSettings::videoRecordingStartedSound() const {
140   return m_settings->value("sounds/videoRecordingStarted").toString();
141 }
142
143 QString PlatformSettings::videoRecordingEndedSound() const {
144   return m_settings->value("sounds/videoRecordingEnded").toString();
145 }
146
147 QString PlatformSettings::autoFocusAcquiredSound() const {
148   return m_settings->value("sounds/autoFocusAcquired").toString();
149 }