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)
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())
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
51 PlatformSettings::PlatformSettings(QObject *parent) :
52 QObject(parent), m_settings(new QSettings(PATH, QSettings::IniFormat)) {
56 PlatformSettings::~PlatformSettings() {
60 QSize PlatformSettings::previewSize() {
61 return m_settings->value("quill/previewSize", PREVIEW_SIZE).toSize();
64 QString PlatformSettings::thumbnailFlavorName() {
65 return m_settings->value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString();
68 QString PlatformSettings::thumbnailExtension() {
69 return m_settings->value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
72 QColor PlatformSettings::backgroundRenderingColor() {
73 return m_settings->value("quill/backgroundRenderingColor",
74 BACKGROUND_RENDERING_COLOR).value<QColor>();
77 bool PlatformSettings::isDBusThumbnailingEnabled() {
78 return m_settings->value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
81 bool PlatformSettings::isThumbnailCreationEnabled() {
82 return m_settings->value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
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();
90 QSize PlatformSettings::portraitSize(const QSize& size) {
91 return size.width() > size.height() ? QSize(size.height(), size.width()) : size;
94 QSize PlatformSettings::landscapeSize(const QSize& size) {
95 return size.width() > size.height() ? size : QSize(size.height(), size.width());
98 void PlatformSettings::init() {
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();
109 Quill::setThumbnailFlavorName(LANDSCAPE_PREVIEW_LEVEL, thumbnailFlavorName());
110 Quill::setPreviewSize(LANDSCAPE_PREVIEW_LEVEL, landscapeSize(size));
113 Quill::setThumbnailFlavorName(PORTRAIT_PREVIEW_LEVEL, thumbnailFlavorName());
114 Quill::setPreviewSize(PORTRAIT_PREVIEW_LEVEL, portraitSize(size));
116 Quill::setThumbnailExtension(thumbnailExtension());
117 Quill::setBackgroundRenderingColor(backgroundRenderingColor());
118 Quill::setDBusThumbnailingEnabled(isDBusThumbnailingEnabled());
119 Quill::setThumbnailCreationEnabled(isThumbnailCreationEnabled());
121 QString tempPath = temporaryFilePath();
122 QDir().mkpath(tempPath);
123 Quill::setTemporaryFilePath(tempPath);
127 PlatformSettings::Service PlatformSettings::service(const QString& id) {
128 PlatformSettings::Service service;
129 m_settings->beginGroup(id);
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();
138 m_settings->endGroup();
143 QString PlatformSettings::imageCaptureStartedSound() const {
144 return m_settings->value("sounds/imageCaptureStarted").toString();
147 QString PlatformSettings::imageCaptureEndedSound() const {
148 return m_settings->value("sounds/imageCaptureEnded").toString();
151 QString PlatformSettings::videoRecordingStartedSound() const {
152 return m_settings->value("sounds/videoRecordingStarted").toString();
155 QString PlatformSettings::videoRecordingEndedSound() const {
156 return m_settings->value("sounds/videoRecordingEnded").toString();
159 QString PlatformSettings::autoFocusAcquiredSound() const {
160 return m_settings->value("sounds/autoFocusAcquired").toString();
163 QString PlatformSettings::imagePath() const {
167 QString PlatformSettings::videoPath() const {
171 QString PlatformSettings::temporaryVideoPath() const {