Source /tmp/session_bus_address.user before invoking dbus-send in postinst script
[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 #ifdef HARMATTAN
40 #define IMAGE_PATH QString("%1%2MyDocs%2DCIM%2").arg(QDir::homePath()).arg(QDir::separator())
41 #define VIDEO_PATH IMAGE_PATH
42 #define TEMP_VIDEO QString("%1%2MyDocs%2.cameraplus%2").arg(QDir::homePath()).arg(QDir::separator())
43 #endif
44
45 #ifdef SAILFISH
46 #define IMAGE_PATH QString("%1%2Pictures%2Camera%2").arg(QDir::homePath()).arg(QDir::separator())
47 #define VIDEO_PATH QString("%1%2Videos%2Camera%2").arg(QDir::homePath()).arg(QDir::separator())
48 #define TEMP_VIDEO VIDEO_PATH
49 #endif
50
51 PlatformSettings::PlatformSettings(QObject *parent) :
52   QObject(parent), m_settings(new QSettings(PATH, QSettings::IniFormat)) {
53
54 }
55
56 PlatformSettings::~PlatformSettings() {
57   delete m_settings;
58 }
59
60 QSize PlatformSettings::previewSize() {
61   return m_settings->value("quill/previewSize", PREVIEW_SIZE).toSize();
62 }
63
64 QString PlatformSettings::thumbnailFlavorName() {
65   return m_settings->value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString();
66 }
67
68 QString PlatformSettings::thumbnailExtension() {
69   return m_settings->value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
70 }
71
72 QColor PlatformSettings::backgroundRenderingColor() {
73   return m_settings->value("quill/backgroundRenderingColor",
74                            BACKGROUND_RENDERING_COLOR).value<QColor>();
75 }
76
77 bool PlatformSettings::isDBusThumbnailingEnabled() {
78   return m_settings->value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
79 }
80
81 bool PlatformSettings::isThumbnailCreationEnabled() {
82   return m_settings->value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
83 }
84
85 QString PlatformSettings::temporaryFilePath() {
86   QString defaultPath = QString(TEMPORARY_FILE_PATH).arg(QDir::homePath()).arg(QDir::separator());
87   return m_settings->value("quill/temporaryFilePath", defaultPath).toString();
88 }
89
90 QSize PlatformSettings::portraitSize(const QSize& size) {
91   return size.width() > size.height() ? QSize(size.height(), size.width()) : size;
92 }
93
94 QSize PlatformSettings::landscapeSize(const QSize& size) {
95   return size.width() > size.height() ? size : QSize(size.height(), size.width());
96 }
97
98 void PlatformSettings::init() {
99 #ifdef HARMATTAN
100   // How we create thumbnails for portrait is really messy.
101   // I am sure there is a better way to tell Quill to generate proper
102   // portrait thumbnails without having 2 display levels but I don't know how.
103   // The issue is we generate screen sized thumbnails for landscape
104   // but we generate half screen sized thumbnails for portrait
105   Quill::setPreviewLevelCount(2);
106   QSize size = previewSize();
107
108   // Landscape:
109   Quill::setThumbnailFlavorName(LANDSCAPE_PREVIEW_LEVEL, thumbnailFlavorName());
110   Quill::setPreviewSize(LANDSCAPE_PREVIEW_LEVEL, landscapeSize(size));
111
112   // Portrait:
113   Quill::setThumbnailFlavorName(PORTRAIT_PREVIEW_LEVEL, thumbnailFlavorName());
114   Quill::setPreviewSize(PORTRAIT_PREVIEW_LEVEL, portraitSize(size));
115
116   Quill::setThumbnailExtension(thumbnailExtension());
117   Quill::setBackgroundRenderingColor(backgroundRenderingColor());
118   Quill::setDBusThumbnailingEnabled(isDBusThumbnailingEnabled());
119   Quill::setThumbnailCreationEnabled(isThumbnailCreationEnabled());
120
121   QString tempPath = temporaryFilePath();
122   QDir().mkpath(tempPath);
123   Quill::setTemporaryFilePath(tempPath);
124 #endif
125 }
126
127 PlatformSettings::Service PlatformSettings::service(const QString& id) {
128   PlatformSettings::Service service;
129   m_settings->beginGroup(id);
130
131   service.m_enabled = m_settings->value("enabled", false).toBool();
132   service.m_type = m_settings->value("type").toString();
133   service.m_path = m_settings->value("path").toString();
134   service.m_interface = m_settings->value("interface").toString();
135   service.m_dest = m_settings->value("dest").toString();
136   service.m_method = m_settings->value("method").toString();
137
138   m_settings->endGroup();
139
140   return service;
141 }
142
143 QString PlatformSettings::imageCaptureStartedSound() const {
144   return m_settings->value("sounds/imageCaptureStarted").toString();
145 }
146
147 QString PlatformSettings::imageCaptureEndedSound() const {
148   return m_settings->value("sounds/imageCaptureEnded").toString();
149 }
150
151 QString PlatformSettings::videoRecordingStartedSound() const {
152   return m_settings->value("sounds/videoRecordingStarted").toString();
153 }
154
155 QString PlatformSettings::videoRecordingEndedSound() const {
156   return m_settings->value("sounds/videoRecordingEnded").toString();
157 }
158
159 QString PlatformSettings::autoFocusAcquiredSound() const {
160   return m_settings->value("sounds/autoFocusAcquired").toString();
161 }
162
163 QString PlatformSettings::imagePath() const {
164   return IMAGE_PATH;
165 }
166
167 QString PlatformSettings::videoPath() const {
168   return VIDEO_PATH;
169 }
170
171 QString PlatformSettings::temporaryVideoPath() const {
172   return TEMP_VIDEO;
173 }