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"
25 #include "quillitem.h"
27 #define PATH "/usr/share/cameraplus/config/cameraplus.ini"
29 #define PREVIEW_SIZE QSize(854, 480)
30 #define THUMBNAIL_FLAVOR_NAME QString("screen")
31 #define TEMPORARY_FILE_PATH "%1%2.config%2quill%2tmp"
32 #define THUMBNAIL_EXTENSION QString("jpeg")
33 #define THUMBNAIL_CREATION_ENABLED true
34 #define DBUS_THUMBNAILING_ENABLED true
35 #define BACKGROUND_RENDERING_COLOR QColor(Qt::black)
37 PlatformSettings::PlatformSettings(QObject *parent) :
38 QObject(parent), m_settings(new QSettings(PATH, QSettings::IniFormat)) {
42 PlatformSettings::~PlatformSettings() {
46 QSize PlatformSettings::previewSize() {
47 return m_settings->value("quill/previewSize", PREVIEW_SIZE).toSize();
50 QString PlatformSettings::thumbnailFlavorName() {
51 return m_settings->value("quill/thumbnailFlavorName", THUMBNAIL_FLAVOR_NAME).toString();
54 QString PlatformSettings::thumbnailExtension() {
55 return m_settings->value("quill/thumbnailExtension", THUMBNAIL_EXTENSION).toString();
58 QColor PlatformSettings::backgroundRenderingColor() {
59 return m_settings->value("quill/backgroundRenderingColor",
60 BACKGROUND_RENDERING_COLOR).value<QColor>();
63 bool PlatformSettings::isDBusThumbnailingEnabled() {
64 return m_settings->value("quill/dbusThumbnailingEnabled", DBUS_THUMBNAILING_ENABLED).toBool();
67 bool PlatformSettings::isThumbnailCreationEnabled() {
68 return m_settings->value("quill/thumbnailCreationEnabled", THUMBNAIL_CREATION_ENABLED).toBool();
71 QString PlatformSettings::temporaryFilePath() {
72 QString defaultPath = QString(TEMPORARY_FILE_PATH).arg(QDir::homePath()).arg(QDir::separator());
73 return m_settings->value("quill/temporaryFilePath", defaultPath).toString();
76 QSize PlatformSettings::portraitSize(const QSize& size) {
77 return size.width() > size.height() ? QSize(size.height(), size.width()) : size;
80 QSize PlatformSettings::landscapeSize(const QSize& size) {
81 return size.width() > size.height() ? size : QSize(size.height(), size.width());
84 void PlatformSettings::init() {
85 // How we create thumbnails for portrait is really messy.
86 // I am sure there is a better way to tell Quill to generate proper
87 // portrait thumbnails without having 2 display levels but I don't know how.
88 // The issue is we generate screen sized thumbnails for landscape
89 // but we generate half screen sized thumbnails for portrait
90 Quill::setPreviewLevelCount(2);
91 QSize size = previewSize();
94 Quill::setThumbnailFlavorName(LANDSCAPE_PREVIEW_LEVEL, thumbnailFlavorName());
95 Quill::setPreviewSize(LANDSCAPE_PREVIEW_LEVEL, landscapeSize(size));
98 Quill::setThumbnailFlavorName(PORTRAIT_PREVIEW_LEVEL, thumbnailFlavorName());
99 Quill::setPreviewSize(PORTRAIT_PREVIEW_LEVEL, portraitSize(size));
101 Quill::setThumbnailExtension(thumbnailExtension());
102 Quill::setBackgroundRenderingColor(backgroundRenderingColor());
103 Quill::setDBusThumbnailingEnabled(isDBusThumbnailingEnabled());
104 Quill::setThumbnailCreationEnabled(isThumbnailCreationEnabled());
106 QString tempPath = temporaryFilePath();
107 QDir().mkpath(tempPath);
108 Quill::setTemporaryFilePath(tempPath);
111 PlatformSettings::Service PlatformSettings::service(const QString& id) {
112 PlatformSettings::Service service;
113 m_settings->beginGroup(id);
115 service.m_enabled = m_settings->value("enabled", false).toBool();
116 service.m_type = m_settings->value("type").toString();
117 service.m_path = m_settings->value("path").toString();
118 service.m_interface = m_settings->value("interface").toString();
119 service.m_dest = m_settings->value("dest").toString();
120 service.m_method = m_settings->value("method").toString();
122 m_settings->endGroup();