2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
21 #include "platformsettings.h"
26 #include "quillitem.h"
29 #define PATH "/usr/share/cameraplus/config/cameraplus.ini"
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)
39 PlatformSettings::PlatformSettings(QObject *parent) :
40 QObject(parent), m_settings(new QSettings(PATH, QSettings::IniFormat)) {
44 PlatformSettings::~PlatformSettings() {
48 QSize PlatformSettings::previewSize() {
49 return m_settings->value("quill/previewSize", PREVIEW_SIZE).toSize();
52 QString PlatformSettings::thumbnailFlavorName() {
53 return m_settings->value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString();
56 QString PlatformSettings::thumbnailExtension() {
57 return m_settings->value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
60 QColor PlatformSettings::backgroundRenderingColor() {
61 return m_settings->value("quill/backgroundRenderingColor",
62 BACKGROUND_RENDERING_COLOR).value<QColor>();
65 bool PlatformSettings::isDBusThumbnailingEnabled() {
66 return m_settings->value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
69 bool PlatformSettings::isThumbnailCreationEnabled() {
70 return m_settings->value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
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();
78 QSize PlatformSettings::portraitSize(const QSize& size) {
79 return size.width() > size.height() ? QSize(size.height(), size.width()) : size;
82 QSize PlatformSettings::landscapeSize(const QSize& size) {
83 return size.width() > size.height() ? size : QSize(size.height(), size.width());
86 void PlatformSettings::init() {
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();
97 Quill::setThumbnailFlavorName(LANDSCAPE_PREVIEW_LEVEL, thumbnailFlavorName());
98 Quill::setPreviewSize(LANDSCAPE_PREVIEW_LEVEL, landscapeSize(size));
101 Quill::setThumbnailFlavorName(PORTRAIT_PREVIEW_LEVEL, thumbnailFlavorName());
102 Quill::setPreviewSize(PORTRAIT_PREVIEW_LEVEL, portraitSize(size));
104 Quill::setThumbnailExtension(thumbnailExtension());
105 Quill::setBackgroundRenderingColor(backgroundRenderingColor());
106 Quill::setDBusThumbnailingEnabled(isDBusThumbnailingEnabled());
107 Quill::setThumbnailCreationEnabled(isThumbnailCreationEnabled());
109 QString tempPath = temporaryFilePath();
110 QDir().mkpath(tempPath);
111 Quill::setTemporaryFilePath(tempPath);
115 PlatformSettings::Service PlatformSettings::service(const QString& id) {
116 PlatformSettings::Service service;
117 m_settings->beginGroup(id);
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();
126 m_settings->endGroup();
131 QString PlatformSettings::imageCaptureStartedSound() const {
132 return m_settings->value("sounds/imageCaptureStarted").toString();
135 QString PlatformSettings::imageCaptureEndedSound() const {
136 return m_settings->value("sounds/imageCaptureEnded").toString();
139 QString PlatformSettings::videoRecordingStartedSound() const {
140 return m_settings->value("sounds/videoRecordingStarted").toString();
143 QString PlatformSettings::videoRecordingEndedSound() const {
144 return m_settings->value("sounds/videoRecordingEnded").toString();
147 QString PlatformSettings::autoFocusAcquiredSound() const {
148 return m_settings->value("sounds/autoFocusAcquired").toString();