From 1d2f3661d2191cedc53f670c57cd7caf6c4bf77c Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Sat, 11 May 2013 17:30:27 +0000 Subject: [PATCH] [systemsettings] initial commit --- src/aboutsettings.cpp | 87 ++++++ src/aboutsettings.h | 72 +++++ src/alarmtonemodel.cpp | 80 +++++ src/alarmtonemodel.h | 62 ++++ src/datetimesettings.cpp | 127 ++++++++ src/datetimesettings.h | 80 +++++ src/displaysettings.cpp | 69 ++++ src/displaysettings.h | 65 ++++ src/languagemodel.cpp | 212 +++++++++++++ src/languagemodel.h | 89 ++++++ src/mce.xml | 28 ++ src/plugin.cpp | 67 ++++ src/profilecontrol.cpp | 658 +++++++++++++++++++++++++++++++++++++++ src/profilecontrol.h | 228 ++++++++++++++ src/qmldir | 1 + src/src.pro | 36 +++ src/usbsettings.cpp | 135 ++++++++ src/usbsettings.h | 74 +++++ systemsettings.pro | 2 + 19 files changed, 2172 insertions(+) create mode 100644 src/aboutsettings.cpp create mode 100644 src/aboutsettings.h create mode 100644 src/alarmtonemodel.cpp create mode 100644 src/alarmtonemodel.h create mode 100644 src/datetimesettings.cpp create mode 100644 src/datetimesettings.h create mode 100644 src/displaysettings.cpp create mode 100644 src/displaysettings.h create mode 100644 src/languagemodel.cpp create mode 100644 src/languagemodel.h create mode 100644 src/mce.xml create mode 100644 src/plugin.cpp create mode 100644 src/profilecontrol.cpp create mode 100644 src/profilecontrol.h create mode 100644 src/qmldir create mode 100644 src/src.pro create mode 100644 src/usbsettings.cpp create mode 100644 src/usbsettings.h create mode 100644 systemsettings.pro diff --git a/src/aboutsettings.cpp b/src/aboutsettings.cpp new file mode 100644 index 0000000..c1233e4 --- /dev/null +++ b/src/aboutsettings.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include +#include +#include "aboutsettings.h" + +AboutSettings::AboutSettings(QObject *parent) + : QObject(parent), + m_sysinfo(new QSystemStorageInfo(this)), + m_netinfo(new QSystemNetworkInfo(this)), + m_devinfo(new QSystemDeviceInfo(this)) +{ + qDebug() << "Drives:" << m_sysinfo->logicalDrives(); +} + +AboutSettings::~AboutSettings() +{ +} + +qlonglong AboutSettings::totalDiskSpace() const +{ + return m_sysinfo->totalDiskSpace("/"); +} + +qlonglong AboutSettings::availableDiskSpace() const +{ + return m_sysinfo->availableDiskSpace("/"); +} + +const QString AboutSettings::bluetoothAddress() const +{ + return m_netinfo->macAddress(QSystemNetworkInfo::BluetoothMode); +} + +const QString AboutSettings::wlanMacAddress() const +{ + return m_netinfo->macAddress(QSystemNetworkInfo::WlanMode); +} + +const QString AboutSettings::imei() const +{ + return m_devinfo->imei(); +} + +const QString AboutSettings::manufacturer() const +{ + return m_devinfo->manufacturer(); +} + +const QString AboutSettings::productName() const +{ + return m_devinfo->productName(); +} + +const QString AboutSettings::model() const +{ + return m_devinfo->model(); +} diff --git a/src/aboutsettings.h b/src/aboutsettings.h new file mode 100644 index 0000000..6ce5e74 --- /dev/null +++ b/src/aboutsettings.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef ABOUTSETTINGS_H +#define ABOUTSETTINGS_H + +#include +#include +#include + +QTM_USE_NAMESPACE + +class AboutSettings: public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString bluetoothAddress READ bluetoothAddress CONSTANT) + Q_PROPERTY(QString wlanMacAddress READ wlanMacAddress CONSTANT) + Q_PROPERTY(QString imei READ imei CONSTANT) + Q_PROPERTY(QString manufacturer READ manufacturer CONSTANT) + Q_PROPERTY(QString productName READ productName CONSTANT) + Q_PROPERTY(QString model READ model CONSTANT) + +public: + explicit AboutSettings(QObject *parent = 0); + virtual ~AboutSettings(); + + Q_INVOKABLE qlonglong totalDiskSpace() const; + Q_INVOKABLE qlonglong availableDiskSpace() const; + + const QString bluetoothAddress() const; + const QString wlanMacAddress() const; + const QString imei() const; + const QString manufacturer() const; + const QString productName() const; + const QString model() const; + +private: + QSystemStorageInfo *m_sysinfo; + QSystemNetworkInfo *m_netinfo; + QSystemDeviceInfo *m_devinfo; +}; + +#endif diff --git a/src/alarmtonemodel.cpp b/src/alarmtonemodel.cpp new file mode 100644 index 0000000..71c4a05 --- /dev/null +++ b/src/alarmtonemodel.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include "alarmtonemodel.h" + +#include +#include + +const char * const AlarmToneDir = "/usr/share/sounds/jolla-ringtones/stereo/"; + + +AlarmToneModel::AlarmToneModel(QObject *parent) + : QAbstractListModel(parent) +{ + QHash roles; + roles[FilenameRole] = "filename"; + roles[TitleRole] = "title"; + setRoleNames(roles); + + QDir ringtoneDir(AlarmToneDir); + QStringList filters; + filters << "*.wav" << "*.mp3" << "*.ogg"; // TODO: need more? + m_fileInfoList = ringtoneDir.entryInfoList(filters, QDir::Files, QDir::Name); +} + +AlarmToneModel::~AlarmToneModel() +{ +} + +int AlarmToneModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return m_fileInfoList.count(); +} + +QVariant AlarmToneModel::data(const QModelIndex &index, int role) const +{ + int row = index.row(); + if (row < 0 || row > m_fileInfoList.count()) { + return QVariant(); + } + + switch (role) { + case FilenameRole: + return m_fileInfoList.at(row).absoluteFilePath(); + case TitleRole: + // for now just strip extension + return m_fileInfoList.at(row).baseName(); + default: + return QVariant(); + } +} diff --git a/src/alarmtonemodel.h b/src/alarmtonemodel.h new file mode 100644 index 0000000..9ee59d2 --- /dev/null +++ b/src/alarmtonemodel.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef ALARMTONEMODEL_H +#define ALARMTONEMODEL_H + +#include +#include + +class AlarmToneModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum ApplicationRoles { + FilenameRole = Qt::UserRole + 1, + TitleRole + }; + + explicit AlarmToneModel(QObject *parent = 0); + virtual ~AlarmToneModel(); + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex &index, int role) const; + +signals: + void selectedFileChanged(); + void currentIndexChanged(); + +private: + QFileInfoList m_fileInfoList; +}; + +#endif diff --git a/src/datetimesettings.cpp b/src/datetimesettings.cpp new file mode 100644 index 0000000..14d0c38 --- /dev/null +++ b/src/datetimesettings.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include "datetimesettings.h" +#include + +DateTimeSettings::DateTimeSettings(QObject *parent) + : QObject(parent), + m_autoSystemTime(m_time.autoSystemTime()), + m_autoTimezone(m_time.autoTimeZone()) +{ + m_time.getTimezone(m_timezone); + connect(&m_time, SIGNAL(timeOrSettingsChanged(MeeGo::QmTime::WhatChanged)), + this, SLOT(handleTimeChanged(MeeGo::QmTime::WhatChanged))); +} + +DateTimeSettings::~DateTimeSettings() +{ +} + +void DateTimeSettings::setTime(int hour, int minute) +{ + QDate currentDate = QDate::currentDate(); + QTime time(hour, minute); + QDateTime newTime(currentDate, time); + m_time.setTime(newTime.toTime_t()); +} + + +void DateTimeSettings::setDate(const QDate &date) +{ + QDateTime newTime = QDateTime::currentDateTime(); + newTime.setDate(date); + m_time.setTime(newTime.toTime_t()); +} + +bool DateTimeSettings::automaticTimeUpdate() +{ + return m_autoSystemTime == MeeGo::QmTime::AutoSystemTimeOn; +} + +void DateTimeSettings::setAutomaticTimeUpdate(bool enable) +{ + m_time.setAutoSystemTime(enable ? MeeGo::QmTime::AutoSystemTimeOn : MeeGo::QmTime::AutoSystemTimeOff); +} + +bool DateTimeSettings::automaticTimezoneUpdate() +{ + return m_autoTimezone == MeeGo::QmTime::AutoTimeZoneOn; +} + +void DateTimeSettings::setAutomaticTimezoneUpdate(bool enable) +{ + bool enabled = m_autoTimezone == MeeGo::QmTime::AutoTimeZoneOn; + if (enabled == enable) + return; + + m_time.setAutoTimeZone(enable ? MeeGo::QmTime::AutoTimeZoneOn : MeeGo::QmTime::AutoTimeZoneOff); +} + +QString DateTimeSettings::timezone() const +{ + return m_timezone; +} + +void DateTimeSettings::setTimezone(const QString &tz) +{ + if (tz == m_timezone) + return; + + m_time.setTimezone(tz); +} + +void DateTimeSettings::handleTimeChanged(MeeGo::QmTime::WhatChanged what) +{ + switch (what) { + case MeeGo::QmTime::TimeChanged: + emit timeChanged(); + // fall through + case MeeGo::QmTime::OnlySettingsChanged: + { + MeeGo::QmTime::AutoSystemTimeStatus newAutoSystemTime = m_time.autoSystemTime(); + if (newAutoSystemTime != m_autoSystemTime) { + m_autoSystemTime = newAutoSystemTime; + emit automaticTimeUpdateChanged(); + } + MeeGo::QmTime::AutoTimeZoneStatus newAutoTimezone = m_time.autoTimeZone(); + if (newAutoTimezone != m_autoTimezone) { + m_autoTimezone = newAutoTimezone; + emit automaticTimezoneUpdateChanged(); + } + QString newTimezone; + if (m_time.getTimezone(newTimezone) && newTimezone != m_timezone) { + m_timezone = newTimezone; + emit timezoneChanged(); + } + } + } +} diff --git a/src/datetimesettings.h b/src/datetimesettings.h new file mode 100644 index 0000000..952b11c --- /dev/null +++ b/src/datetimesettings.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef DATETIMESETTINGS_H +#define DATETIMESETTINGS_H + +#include +#include + +#include + +class DateTimeSettings: public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool automaticTimeUpdate READ automaticTimeUpdate WRITE setAutomaticTimeUpdate NOTIFY automaticTimeUpdateChanged) + Q_PROPERTY(bool automaticTimezoneUpdate READ automaticTimezoneUpdate WRITE setAutomaticTimezoneUpdate NOTIFY automaticTimezoneUpdateChanged) + Q_PROPERTY(QString timezone READ timezone WRITE setTimezone NOTIFY timezoneChanged) + +public: + explicit DateTimeSettings(QObject *parent = 0); + virtual ~DateTimeSettings(); + + Q_INVOKABLE void setTime(int hour, int minute); + Q_INVOKABLE void setDate(const QDate &date); + + bool automaticTimeUpdate(); + void setAutomaticTimeUpdate(bool enable); + + bool automaticTimezoneUpdate(); + void setAutomaticTimezoneUpdate(bool enable); + + QString timezone() const; + void setTimezone(const QString &); + +signals: + void timeChanged(); + void automaticTimeUpdateChanged(); + void automaticTimezoneUpdateChanged(); + void timezoneChanged(); + +private slots: + void handleTimeChanged(MeeGo::QmTime::WhatChanged what); + +private: + MeeGo::QmTime m_time; + MeeGo::QmTime::AutoSystemTimeStatus m_autoSystemTime; + MeeGo::QmTime::AutoTimeZoneStatus m_autoTimezone; + QString m_timezone; +}; + +#endif diff --git a/src/displaysettings.cpp b/src/displaysettings.cpp new file mode 100644 index 0000000..01546a6 --- /dev/null +++ b/src/displaysettings.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include +#include +#include "mceiface.h" +#include "displaysettings.h" +#include + +DisplaySettings::DisplaySettings(QObject *parent) + : QObject(parent) +{ + m_mceIface = new ComNokiaMceRequestInterface(MCE_SERVICE, MCE_REQUEST_PATH, QDBusConnection::systemBus(), this); + QDBusPendingReply result = m_mceIface->get_config(QDBusObjectPath("/system/osso/dsm/display/display_brightness")); + result.waitForFinished(); + + m_brightness = result.value().variant().toInt(); +} + +int DisplaySettings::brightness() +{ + return m_brightness; +} + +void DisplaySettings::setBrightness(int value) +{ + if (m_brightness != value) { + m_brightness = value; + m_mceIface->set_config(QDBusObjectPath("/system/osso/dsm/display/display_brightness"), QDBusVariant(value)); + emit brightnessChanged(); + } +} + +int DisplaySettings::maximumBrightness() +{ + QDBusPendingReply result = m_mceIface->get_config(QDBusObjectPath("/system/osso/dsm/display/max_display_brightness_levels")); + result.waitForFinished(); + + return result.value().variant().toInt(); +} + diff --git a/src/displaysettings.h b/src/displaysettings.h new file mode 100644 index 0000000..e280f10 --- /dev/null +++ b/src/displaysettings.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef DISPLAYSETTINGS_H +#define DISPLAYSETTINGS_H + +#include +#include + +class ComNokiaMceRequestInterface; + +class DisplaySettings: public QObject +{ + Q_OBJECT + + Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) + Q_PROPERTY(int maximumBrightness READ maximumBrightness CONSTANT) + +public: + explicit DisplaySettings(QObject *parent = 0); + + int brightness(); + void setBrightness(int); + + int maximumBrightness(); + +signals: + void brightnessChanged(); + +private: + ComNokiaMceRequestInterface *m_mceIface; + int m_brightness; +}; + +QML_DECLARE_TYPE(DisplaySettings) + +#endif diff --git a/src/languagemodel.cpp b/src/languagemodel.cpp new file mode 100644 index 0000000..513e1d6 --- /dev/null +++ b/src/languagemodel.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ +#include "languagemodel.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + + +namespace { +const char * const LanguageSupportDirectory = "/usr/share/jolla-supported-languages"; + +bool nameLessThan(const Language &lang1, const Language &lang2) +{ + return (lang1.name().localeAwareCompare(lang2.name()) <= 0); +} + +QString localeConfigPath() +{ + struct passwd *passwdInfo = getpwuid(getuid()); + QString userName; + if (passwdInfo) { + userName = passwdInfo->pw_name; + } + return QString("/var/lib/environment/%1/locale.conf").arg(userName); +} +} + + +Language::Language(QString name, QString localeCode, QString region) + : m_name(name), m_localeCode(localeCode), m_region(region) +{ +} + +QString Language::name() const +{ + return m_name; +} + +QString Language::localeCode() const +{ + return m_localeCode; +} + +QString Language::region() const +{ + return m_region; +} + + +LanguageModel::LanguageModel(QObject *parent) + : QAbstractListModel(parent), + m_currentIndex(-1) +{ + QHash roles; + roles[NameRole] = "name"; + roles[LocaleRole] = "locale"; + roles[RegionRole] = "region"; + setRoleNames(roles); + + // get supported languages + QDir languageDirectory(LanguageSupportDirectory); + QFileInfoList fileInfoList = languageDirectory.entryInfoList(QStringList("*.conf"), QDir::Files); + + foreach (const QFileInfo &fileInfo, fileInfoList) { + QSettings settings(fileInfo.filePath(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + QString name = settings.value("Name").toString(); + QString localeCode = settings.value("LocaleCode").toString(); + QString region = settings.value("Region").toString(); + if (name.isEmpty() || localeCode.isEmpty() || region.isEmpty()) { + continue; + } + Language newLanguage(name, localeCode, region); + m_languages.append(newLanguage); + } + + qSort(m_languages.begin(), m_languages.end(), nameLessThan); + + readCurrentLocale(); +} + +LanguageModel::~LanguageModel() +{ +} + + +void LanguageModel::readCurrentLocale() +{ + QFile localeConfig(localeConfigPath()); + + if (!localeConfig.exists() || !localeConfig.open(QIODevice::ReadOnly)) { + return; + } + + QString locale; + while (!localeConfig.atEnd()) { + QString line = localeConfig.readLine().trimmed(); + if (line.startsWith("LANG=")) { + locale = line.mid(5); + break; + } + } + + m_currentIndex = getLocaleIndex(locale); +} + + + +int LanguageModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent) + return m_languages.count(); +} + +QVariant LanguageModel::data(const QModelIndex &index, int role) const +{ + int row = index.row(); + if (row < 0 || row >= m_languages.count()) { + return QVariant(); + } + + const Language &language = m_languages.at(row); + switch (role) { + case NameRole: + return language.name(); + case LocaleRole: + return language.localeCode(); + case RegionRole: + return language.region(); + default: + return QVariant(); + } +} + +int LanguageModel::currentIndex() const +{ + return m_currentIndex; +} + +void LanguageModel::setSystemLocale(const QString &localeCode, LocaleUpdateMode updateMode) +{ + QFile localeConfig(localeConfigPath()); + if (!localeConfig.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { + qWarning() << "Language model unable to open locale configuration file for writing:" << localeConfigPath() + << " - " << localeConfig.errorString(); + return; + } + + localeConfig.write("# Autogenerated by settings\n"); + localeConfig.write(QString("LANG=%1\n").arg(localeCode).toAscii()); + localeConfig.close(); + + int oldLocale = m_currentIndex; + m_currentIndex = getLocaleIndex(localeCode); + if (m_currentIndex != oldLocale) { + emit currentIndexChanged(); + } + + if (updateMode == UpdateAndReboot) { + QDBusInterface dsmeInterface("com.nokia.dsme", "/com/nokia/dsme/request", "com.nokia.dsme.request", + QDBusConnection::systemBus()); + dsmeInterface.call("req_reboot"); + } +} + +int LanguageModel::getLocaleIndex(const QString &locale) const +{ + int i = 0; + foreach (Language language, m_languages) { + if (language.localeCode() == locale) { + return i; + } + i++; + } + + return -1; +} diff --git a/src/languagemodel.h b/src/languagemodel.h new file mode 100644 index 0000000..e314460 --- /dev/null +++ b/src/languagemodel.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef LANGUAGEMODEL_H +#define LANGUAGEMODEL_H + +#include +#include + +class Language { +public: + Language(QString name, QString localeCode, QString region); + QString name() const; + QString localeCode() const; + QString region() const; + +private: + QString m_name; + QString m_localeCode; + QString m_region; +}; + +class LanguageModel: public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged) + Q_ENUMS(LocaleUpdateMode) + +public: + enum LanguageRoles { + NameRole = Qt::UserRole + 1, + LocaleRole, + RegionRole + }; + + enum LocaleUpdateMode { + UpdateAndReboot, + UpdateWithoutReboot + }; + + explicit LanguageModel(QObject *parent = 0); + virtual ~LanguageModel(); + + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex &index, int role) const; + + int currentIndex() const; + Q_INVOKABLE void setSystemLocale(const QString &localeCode, LocaleUpdateMode updateMode); + +signals: + void currentIndexChanged(); + +private: + void readCurrentLocale(); + int getLocaleIndex(const QString &locale) const; + + QList m_languages; + int m_currentIndex; +}; + +#endif diff --git a/src/mce.xml b/src/mce.xml new file mode 100644 index 0000000..87bbb10 --- /dev/null +++ b/src/mce.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/plugin.cpp b/src/plugin.cpp new file mode 100644 index 0000000..50f12ab --- /dev/null +++ b/src/plugin.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include +#include +#include +#include + +#include "languagemodel.h" +#include "datetimesettings.h" +#include "profilecontrol.h" +#include "alarmtonemodel.h" +#include "displaysettings.h" +#include "usbsettings.h" +#include "aboutsettings.h" + +class SystemSettingsPlugin : public QDeclarativeExtensionPlugin +{ +public: + void initializeEngine(QDeclarativeEngine *engine, const char *uri) + { + Q_UNUSED(uri) + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.nemomobile.systemsettings")); + qmlRegisterType(uri, 1, 0, "LanguageModel"); + qmlRegisterType(uri, 1, 0, "DateTimeSettings"); + qmlRegisterType(uri, 1, 0, "ProfileControl"); + qmlRegisterType(uri, 1, 0, "AlarmToneModel"); + qmlRegisterType(uri, 1, 0, "DisplaySettings"); + qmlRegisterType(uri, 1, 0, "USBSettings"); + qmlRegisterType(uri, 1, 0, "AboutSettings"); + } +}; + +Q_EXPORT_PLUGIN2(systemsettingsplugin, SystemSettingsPlugin) + diff --git a/src/profilecontrol.cpp b/src/profilecontrol.cpp new file mode 100644 index 0000000..e2de075 --- /dev/null +++ b/src/profilecontrol.cpp @@ -0,0 +1,658 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include +#include "profilecontrol.h" +#include + +// NOTE: most of profiled interface blocks + + +const char * const VolumeKey = "ringing.alert.volume"; +const char * const VibraKey = "vibrating.alert.enabled"; +const char * const SystemSoundLevelKey = "system.sound.level"; +const char * const TouchscreenToneLevelKey = "touchscreen.sound.level"; +const char * const TouchscreenVibrationLevelKey = "touchscreen.vibration.level"; + +const char * const RingerToneKey = "ringing.alert.tone"; +const char * const MessageToneKey ="sms.alert.tone"; +const char * const ChatToneKey ="im.alert.tone"; +const char * const MailToneKey ="email.alert.tone"; +const char * const InternetCallToneKey ="voip.alert.tone"; +const char * const CalendarToneKey ="calendar.alert.tone"; +const char * const ClockAlarmToneKey ="clock.alert.tone"; + +const char * const RingerToneEnabledKey = "ringing.alert.enabled"; +const char * const MessageToneEnabledKey ="sms.alert.enabled"; +const char * const ChatToneEnabledKey ="im.alert.enabled"; +const char * const MailToneEnabledKey ="email.alert.enabled"; +const char * const InternetCallToneEnabledKey ="voip.alert.enabled"; +const char * const CalendarToneEnabledKey ="calendar.alert.enabled"; +const char * const ClockAlarmToneEnabledKey ="clock.alert.enabled"; + +const char * const GeneralProfile = "general"; +const char * const SilentProfile = "silent"; + +int ProfileControl::s_instanceCounter = 0; + + +ProfileControl::ProfileControl(QObject *parent) + : QObject(parent), + m_systemSoundLevel(-1), + m_touchscreenToneLevel(-1), + m_touchscreenVibrationLevel(-1), + m_ringerToneEnabled(-1), + m_messageToneEnabled(-1), + m_chatToneEnabled(-1), + m_mailToneEnabled(-1), + m_internetCallToneEnabled(-1), + m_calendarToneEnabled(-1), + m_clockAlarmToneEnabled(-1) +{ + profile_track_add_profile_cb((profile_track_profile_fn_data) currentProfileChangedCallback, this, NULL); + + // track changes in active and inactive profile(s) + profile_track_add_active_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this, NULL); + profile_track_add_change_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this, NULL); + + profile_connection_enable_autoconnect(); + + if (s_instanceCounter == 0) { + profile_tracker_init(); + } + s_instanceCounter++; + + m_ringerVolume = profile_get_value_as_int(GeneralProfile, VolumeKey); + m_vibraInGeneral = profile_get_value_as_bool(GeneralProfile, VibraKey); + m_vibraInSilent = profile_get_value_as_bool(SilentProfile, VibraKey); +} + +ProfileControl::~ProfileControl() +{ + s_instanceCounter--; + if (s_instanceCounter == 0) { + profile_tracker_quit(); + } + + profile_track_remove_profile_cb((profile_track_profile_fn_data) currentProfileChangedCallback, this); + profile_track_remove_active_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this); + profile_track_remove_change_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this); +} + +QString ProfileControl::profile() +{ + if (m_profile.isEmpty()) { + m_profile = QString::fromUtf8(profile_get_profile()); + } + + return m_profile; +} + +void ProfileControl::setProfile(const QString &profile) +{ + if (profile != m_profile) { + m_profile = profile; + profile_set_profile(profile.toUtf8().constData()); + } +} + +int ProfileControl::ringerVolume() const +{ + return m_ringerVolume; +} + +void ProfileControl::setRingerVolume(int volume) +{ + if (volume == m_ringerVolume) { + return; + } + + m_ringerVolume = volume; + profile_set_value_as_int(GeneralProfile, VolumeKey, volume); + emit ringerVolumeChanged(); +} + +int ProfileControl::vibraMode() const +{ + VibraMode result; + + if (m_vibraInGeneral) { + if (m_vibraInSilent) { + result = VibraAlways; + } else { + result = VibraNormal; + } + } else { + result = VibraSilent; + } + + return result; +} + +void ProfileControl::setVibraMode(int mode) +{ + bool generalValue = false; + bool silentValue = false; + + switch (mode) { + case VibraAlways: + generalValue = true; + silentValue = true; + break; + case VibraSilent: + silentValue = true; + break; + case VibraNormal: + generalValue = true; + break; + } + + bool changed = false; + if (generalValue != m_vibraInGeneral) { + m_vibraInGeneral = generalValue; + profile_set_value_as_bool(GeneralProfile, VibraKey, m_vibraInGeneral); + changed = true; + } + if (silentValue != m_vibraInSilent) { + m_vibraInSilent = silentValue; + profile_set_value_as_bool(SilentProfile, VibraKey, m_vibraInSilent); + changed = true; + } + + if (changed) { + emit vibraModeChanged(); + } +} + +int ProfileControl::systemSoundLevel() +{ + if (m_systemSoundLevel == -1) { + m_systemSoundLevel = profile_get_value_as_int(GeneralProfile, SystemSoundLevelKey); + } + return m_systemSoundLevel; +} + +void ProfileControl::setSystemSoundLevel(int level) +{ + if (level == m_systemSoundLevel) { + return; + } + m_systemSoundLevel = level; + profile_set_value_as_int(GeneralProfile, SystemSoundLevelKey, level); + emit systemSoundLevelChanged(); +} + +int ProfileControl::touchscreenToneLevel() +{ + if (m_touchscreenToneLevel == -1) { + m_touchscreenToneLevel = profile_get_value_as_int(GeneralProfile, TouchscreenToneLevelKey); + } + return m_touchscreenToneLevel; +} + +void ProfileControl::setTouchscreenToneLevel(int level) +{ + if (level == m_touchscreenToneLevel) { + return; + } + m_touchscreenToneLevel = level; + profile_set_value_as_int(GeneralProfile, TouchscreenToneLevelKey, level); + emit touchscreenToneLevelChanged(); +} + +int ProfileControl::touchscreenVibrationLevel() +{ + if (m_touchscreenVibrationLevel == -1) { + m_touchscreenVibrationLevel = profile_get_value_as_int(GeneralProfile, TouchscreenVibrationLevelKey); + } + return m_touchscreenVibrationLevel; +} + +void ProfileControl::setTouchscreenVibrationLevel(int level) +{ + if (level == m_touchscreenVibrationLevel) { + return; + } + m_touchscreenVibrationLevel = level; + profile_set_value_as_int(GeneralProfile, TouchscreenVibrationLevelKey, level); + emit touchscreenVibrationLevelChanged(); +} + +QString ProfileControl::ringerToneFile() +{ + if (m_ringerToneFile.isNull()) { + m_ringerToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, RingerToneKey)); + } + + return m_ringerToneFile; +} + +void ProfileControl::setRingerToneFile(const QString &filename) +{ + if (filename == m_ringerToneFile) { + return; + } + + m_ringerToneFile = filename; + profile_set_value(GeneralProfile, RingerToneKey, filename.toUtf8().constData()); + emit ringerToneFileChanged(); +} + +QString ProfileControl::messageToneFile() +{ + if (m_messageToneFile.isNull()) { + m_messageToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, MessageToneKey)); + } + + return m_messageToneFile; +} + +void ProfileControl::setMessageToneFile(const QString &filename) +{ + if (filename == m_messageToneFile) { + return; + } + + m_messageToneFile = filename; + profile_set_value(GeneralProfile, MessageToneKey, filename.toUtf8().constData()); + emit messageToneFileChanged(); +} + +QString ProfileControl::chatToneFile() +{ + if (m_chatToneFile.isNull()) { + m_chatToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, ChatToneKey)); + } + + return m_chatToneFile; +} + +void ProfileControl::setChatToneFile(const QString &filename) +{ + if (filename == m_chatToneFile) { + return; + } + + m_chatToneFile = filename; + profile_set_value(GeneralProfile, ChatToneKey, filename.toUtf8().constData()); + emit chatToneFileChanged(); +} + +QString ProfileControl::mailToneFile() +{ + if (m_mailToneFile.isNull()) { + m_mailToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, MailToneKey)); + } + + return m_mailToneFile; +} + +void ProfileControl::setMailToneFile(const QString &filename) +{ + if (filename == m_mailToneFile) { + return; + } + + m_mailToneFile = filename; + profile_set_value(GeneralProfile, MailToneKey, filename.toUtf8().constData()); + emit mailToneFileChanged(); +} + +QString ProfileControl::calendarToneFile() +{ + if (m_calendarToneFile.isNull()) { + m_calendarToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, CalendarToneKey)); + } + + return m_calendarToneFile; +} + +void ProfileControl::setCalendarToneFile(const QString &filename) +{ + if (filename == m_calendarToneFile) { + return; + } + + m_calendarToneFile = filename; + profile_set_value(GeneralProfile, CalendarToneKey, filename.toUtf8().constData()); + emit calendarToneFileChanged(); +} + +QString ProfileControl::internetCallToneFile() +{ + if (m_internetCallToneFile.isNull()) { + m_internetCallToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, InternetCallToneKey)); + } + + return m_internetCallToneFile; +} + +void ProfileControl::setInternetCallToneFile(const QString &filename) +{ + if (filename == m_internetCallToneFile) { + return; + } + + m_internetCallToneFile = filename; + profile_set_value(GeneralProfile, InternetCallToneKey, filename.toUtf8().constData()); + emit internetCallToneFileChanged(); +} + +QString ProfileControl::clockAlarmToneFile() +{ + if (m_clockAlarmToneFile.isNull()) { + m_clockAlarmToneFile = QString::fromUtf8(profile_get_value(GeneralProfile, ClockAlarmToneKey)); + } + + return m_clockAlarmToneFile; +} + +void ProfileControl::setClockAlarmToneFile(const QString &filename) +{ + if (filename == m_clockAlarmToneFile) { + return; + } + + m_clockAlarmToneFile = filename; + profile_set_value(GeneralProfile, ClockAlarmToneKey, filename.toUtf8().constData()); + emit clockAlarmToneFileChanged(); +} + + +bool ProfileControl::ringerToneEnabled() +{ + if (m_ringerToneEnabled == -1) { + m_ringerToneEnabled = profile_get_value_as_bool(GeneralProfile, RingerToneEnabledKey); + } + return m_ringerToneEnabled; +} + +void ProfileControl::setRingerToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_ringerToneEnabled) { + return; + } + m_ringerToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, RingerToneEnabledKey, enabled); + emit ringerToneEnabledChanged(); +} + +bool ProfileControl::messageToneEnabled() +{ + if (m_messageToneEnabled == -1) { + m_messageToneEnabled = profile_get_value_as_bool(GeneralProfile, MessageToneEnabledKey); + } + return m_messageToneEnabled; +} + +void ProfileControl::setMessageToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_messageToneEnabled) { + return; + } + m_messageToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, MessageToneEnabledKey, enabled); + emit messageToneEnabledChanged(); +} + +bool ProfileControl::chatToneEnabled() +{ + if (m_chatToneEnabled == -1) { + m_chatToneEnabled = profile_get_value_as_bool(GeneralProfile, ChatToneEnabledKey); + } + return m_chatToneEnabled; +} + +void ProfileControl::setChatToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_chatToneEnabled) { + return; + } + m_chatToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, ChatToneEnabledKey, enabled); + emit chatToneEnabledChanged(); +} + +bool ProfileControl::mailToneEnabled() +{ + if (m_mailToneEnabled == -1) { + m_mailToneEnabled = profile_get_value_as_bool(GeneralProfile, MailToneEnabledKey); + } + return m_mailToneEnabled; +} + +void ProfileControl::setMailToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_mailToneEnabled) { + return; + } + m_mailToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, MailToneEnabledKey, enabled); + emit mailToneEnabledChanged(); +} + +bool ProfileControl::internetCallToneEnabled() +{ + if (m_internetCallToneEnabled == -1) { + m_internetCallToneEnabled = profile_get_value_as_bool(GeneralProfile, InternetCallToneEnabledKey); + } + return m_internetCallToneEnabled; +} + +void ProfileControl::setInternetCallToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_internetCallToneEnabled) { + return; + } + m_internetCallToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, InternetCallToneEnabledKey, enabled); + emit internetCallToneEnabledChanged(); +} + +bool ProfileControl::calendarToneEnabled() +{ + if (m_calendarToneEnabled == -1) { + m_calendarToneEnabled = profile_get_value_as_bool(GeneralProfile, CalendarToneEnabledKey); + } + return m_calendarToneEnabled; +} + +void ProfileControl::setCalendarToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_calendarToneEnabled) { + return; + } + m_calendarToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, CalendarToneEnabledKey, enabled); + emit calendarToneEnabledChanged(); +} + +bool ProfileControl::clockAlarmToneEnabled() +{ + if (m_clockAlarmToneEnabled == -1) { + m_clockAlarmToneEnabled = profile_get_value_as_bool(GeneralProfile, ClockAlarmToneEnabledKey); + } + return m_clockAlarmToneEnabled; +} + +void ProfileControl::setClockAlarmToneEnabled(bool enabled) +{ + if (static_cast(enabled) == m_clockAlarmToneEnabled) { + return; + } + m_clockAlarmToneEnabled = enabled; + profile_set_value_as_bool(GeneralProfile, ClockAlarmToneEnabledKey, enabled); + emit clockAlarmToneEnabledChanged(); +} + + +void ProfileControl::currentProfileChangedCallback(const char *name, ProfileControl *profileControl) +{ + emit profileControl->profileChanged(QString::fromUtf8(name)); +} + +void ProfileControl::updateStateCallBack(const char *profile, const char *key, const char *val, const char *type) +{ + Q_UNUSED(type) + + if (qstrcmp(profile, GeneralProfile) == 0) { + if (qstrcmp(key, VolumeKey) == 0) { + int newVolume = QString(val).toInt(); + if (newVolume != m_ringerVolume) { + m_ringerVolume = newVolume; + emit ringerVolumeChanged(); + } + } else if (qstrcmp(key, VibraKey) == 0) { + bool newVibra = (qstrcmp(val, "On") == 0); + if (newVibra != m_vibraInGeneral) { + m_vibraInGeneral = newVibra; + + emit vibraModeChanged(); + } + } else if (qstrcmp(key, SystemSoundLevelKey) == 0) { + int newLevel = QString(val).toInt(); + if (newLevel != m_systemSoundLevel) { + m_systemSoundLevel = newLevel; + emit systemSoundLevelChanged(); + } + } else if (qstrcmp(key, TouchscreenToneLevelKey) == 0) { + int newLevel = QString(val).toInt(); + if (newLevel != m_touchscreenToneLevel) { + m_touchscreenToneLevel = newLevel; + emit touchscreenToneLevelChanged(); + } + } else if (qstrcmp(key, TouchscreenVibrationLevelKey) == 0) { + int newLevel = QString(val).toInt(); + if (newLevel != m_touchscreenVibrationLevel) { + m_touchscreenVibrationLevel = newLevel; + emit touchscreenVibrationLevelChanged(); + } + + // alarm files begin + } else if (qstrcmp(key, RingerToneKey) == 0) { + QString newFile = val; + if (newFile != m_ringerToneFile) { + m_ringerToneFile = newFile; + emit ringerToneFileChanged(); + } + } else if (qstrcmp(key, MessageToneKey) == 0) { + QString newFile = val; + if (newFile != m_messageToneFile) { + m_messageToneFile = newFile; + emit messageToneFileChanged(); + } + } else if (qstrcmp(key, MailToneKey) == 0) { + QString newFile = val; + if (newFile != m_mailToneFile) { + m_mailToneFile = newFile; + emit mailToneFileChanged(); + } + } else if (qstrcmp(key, InternetCallToneKey) == 0) { + QString newFile = val; + if (newFile != m_internetCallToneFile) { + m_internetCallToneFile = newFile; + emit internetCallToneFileChanged(); + } + } else if (qstrcmp(key, CalendarToneKey) == 0) { + QString newFile = val; + if (newFile != m_calendarToneFile) { + m_calendarToneFile = newFile; + emit calendarToneFileChanged(); + } + } else if (qstrcmp(key, ClockAlarmToneKey) == 0) { + QString newFile = val; + if (newFile != m_clockAlarmToneFile) { + m_clockAlarmToneFile = newFile; + emit clockAlarmToneFileChanged(); + } + + // alarms enabled begin + } else if (qstrcmp(key, RingerToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_ringerToneEnabled) { + m_ringerToneEnabled = newEnabled; + emit ringerToneEnabledChanged(); + } + } else if (qstrcmp(key, MessageToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_messageToneEnabled) { + m_messageToneEnabled = newEnabled; + emit messageToneEnabledChanged(); + } + } else if (qstrcmp(key, ChatToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_chatToneEnabled) { + m_chatToneEnabled = newEnabled; + emit chatToneEnabledChanged(); + } + } else if (qstrcmp(key, MailToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_mailToneEnabled) { + m_mailToneEnabled = newEnabled; + emit mailToneEnabledChanged(); + } + } else if (qstrcmp(key, InternetCallToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_internetCallToneEnabled) { + m_internetCallToneEnabled = newEnabled; + emit internetCallToneEnabledChanged(); + } + } else if (qstrcmp(key, CalendarToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_calendarToneEnabled) { + m_calendarToneEnabled = newEnabled; + emit calendarToneEnabledChanged(); + } + } else if (qstrcmp(key, ClockAlarmToneEnabledKey) == 0) { + int newEnabled = profile_parse_bool(val); + if (newEnabled != m_clockAlarmToneEnabled) { + m_clockAlarmToneEnabled = newEnabled; + emit clockAlarmToneEnabledChanged(); + } + } + + } else if (qstrcmp(profile, SilentProfile) == 0) { + if (qstrcmp(key, VibraKey) == 0) { + bool newVibra = (qstrcmp(val, "On") == 0); + if (newVibra != m_vibraInSilent) { + m_vibraInGeneral = newVibra; + + emit vibraModeChanged(); + } + } + } +} + +void ProfileControl::updateStateCallBackTrampoline(const char *profile, const char *key, const char *val, + const char *type, ProfileControl *profileControl) +{ + profileControl->updateStateCallBack(profile, key, val, type); +} diff --git a/src/profilecontrol.h b/src/profilecontrol.h new file mode 100644 index 0000000..9c9f022 --- /dev/null +++ b/src/profilecontrol.h @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef PROFILECONTROL_H +#define PROFILECONTROL_H + +#include +#include +#include + +class ProfileControl: public QObject +{ + Q_OBJECT + Q_ENUMS(VibraMode) + Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged) + Q_PROPERTY(int ringerVolume READ ringerVolume WRITE setRingerVolume NOTIFY ringerVolumeChanged()) + Q_PROPERTY(int vibraMode READ vibraMode WRITE setVibraMode NOTIFY vibraModeChanged()) + Q_PROPERTY(int systemSoundLevel READ systemSoundLevel WRITE setSystemSoundLevel NOTIFY systemSoundLevelChanged) + Q_PROPERTY(int touchscreenToneLevel READ touchscreenToneLevel WRITE setTouchscreenToneLevel NOTIFY touchscreenToneLevelChanged) + Q_PROPERTY(int touchscreenVibrationLevel READ touchscreenVibrationLevel WRITE setTouchscreenVibrationLevel NOTIFY touchscreenVibrationLevelChanged) + + Q_PROPERTY(QString ringerToneFile READ ringerToneFile WRITE setRingerToneFile NOTIFY ringerToneFileChanged) + Q_PROPERTY(QString messageToneFile READ messageToneFile WRITE setMessageToneFile NOTIFY messageToneFileChanged) + Q_PROPERTY(QString chatToneFile READ chatToneFile WRITE setChatToneFile NOTIFY chatToneFileChanged) + Q_PROPERTY(QString mailToneFile READ mailToneFile WRITE setMailToneFile NOTIFY mailToneFileChanged) + Q_PROPERTY(QString internetCallToneFile READ internetCallToneFile WRITE setInternetCallToneFile NOTIFY internetCallToneFileChanged) + Q_PROPERTY(QString calendarToneFile READ calendarToneFile WRITE setCalendarToneFile NOTIFY calendarToneFileChanged) + Q_PROPERTY(QString clockAlarmToneFile READ clockAlarmToneFile WRITE setClockAlarmToneFile NOTIFY clockAlarmToneFileChanged) + + Q_PROPERTY(bool ringerToneEnabled READ ringerToneEnabled WRITE setRingerToneEnabled NOTIFY ringerToneEnabledChanged) + Q_PROPERTY(bool messageToneEnabled READ messageToneEnabled WRITE setMessageToneEnabled NOTIFY messageToneEnabledChanged) + Q_PROPERTY(bool chatToneEnabled READ chatToneEnabled WRITE setChatToneEnabled NOTIFY chatToneEnabledChanged) + Q_PROPERTY(bool mailToneEnabled READ mailToneEnabled WRITE setMailToneEnabled NOTIFY mailToneEnabledChanged) + Q_PROPERTY(bool internetCallToneEnabled READ internetCallToneEnabled WRITE setInternetCallToneEnabled NOTIFY internetCallToneEnabledChanged) + Q_PROPERTY(bool calendarToneEnabled READ calendarToneEnabled WRITE setCalendarToneEnabled NOTIFY calendarToneEnabledChanged) + Q_PROPERTY(bool clockAlarmToneEnabled READ clockAlarmToneEnabled WRITE setClockAlarmToneEnabled NOTIFY clockAlarmToneEnabledChanged) + +public: + enum VibraMode { + VibraAlways, + VibraSilent, + VibraNormal + }; + + /*! + * Register the callback functions with libprofile and + * activate profile change tracking. + * + * \param parent the parent object + */ + ProfileControl(QObject *parent = 0); + + /*! + * Unregisters the callback functions from libprofile and + * deactivates profile change tracking. + */ + virtual ~ProfileControl(); + + /*! + * Returns the name of the current profile. + * + * \return the current profile + */ + QString profile(); + + /*! + * Sets the current profile. + * + * \param profile the name of the profile to set. + */ + void setProfile(const QString &profile); + + int ringerVolume() const; + void setRingerVolume(int volume); + + int vibraMode() const; + void setVibraMode(int mode); + + int systemSoundLevel(); + void setSystemSoundLevel(int level); + + int touchscreenToneLevel(); + void setTouchscreenToneLevel(int level); + + int touchscreenVibrationLevel(); + void setTouchscreenVibrationLevel(int level); + + QString ringerToneFile(); + void setRingerToneFile(const QString &filename); + + int ringerToneVolume(); + void setRingerToneVolume(int volume); + + QString messageToneFile(); + void setMessageToneFile(const QString &filename); + + QString chatToneFile(); + void setChatToneFile(const QString &filename); + + QString mailToneFile(); + void setMailToneFile(const QString &filename); + + QString internetCallToneFile(); + void setInternetCallToneFile(const QString &filename); + + QString calendarToneFile(); + void setCalendarToneFile(const QString &filename); + + QString clockAlarmToneFile(); + void setClockAlarmToneFile(const QString &filename); + + bool ringerToneEnabled(); + void setRingerToneEnabled(bool enabled); + + bool messageToneEnabled(); + void setMessageToneEnabled(bool enabled); + + bool chatToneEnabled(); + void setChatToneEnabled(bool enabled); + + bool mailToneEnabled(); + void setMailToneEnabled(bool enabled); + + bool internetCallToneEnabled(); + void setInternetCallToneEnabled(bool enabled); + + bool calendarToneEnabled(); + void setCalendarToneEnabled(bool enabled); + + bool clockAlarmToneEnabled(); + void setClockAlarmToneEnabled(bool enabled); + + +signals: + /*! + * Signal that the profile has changed. + * + * \param profile The profile that has been selected as the current profile + */ + void profileChanged(const QString &profile); + void ringerVolumeChanged(); + void vibraModeChanged(); + + void systemSoundLevelChanged(); + void touchscreenToneLevelChanged(); + void touchscreenVibrationLevelChanged(); + + void ringerToneFileChanged(); + void messageToneFileChanged(); + void messageToneVolumeChanged(); + void internetCallToneFileChanged(); + void chatToneFileChanged(); + void mailToneFileChanged(); + void calendarToneFileChanged(); + void clockAlarmToneFileChanged(); + + void ringerToneEnabledChanged(); + void messageToneEnabledChanged(); + void chatToneEnabledChanged(); + void mailToneEnabledChanged(); + void internetCallToneEnabledChanged(); + void calendarToneEnabledChanged(); + void clockAlarmToneEnabledChanged(); + +private: + static int s_instanceCounter; + + QString m_profile; + int m_ringerVolume; + bool m_vibraInGeneral; + bool m_vibraInSilent; + int m_systemSoundLevel; + int m_touchscreenToneLevel; + int m_touchscreenVibrationLevel; + QString m_ringerToneFile; + QString m_messageToneFile; + QString m_internetCallToneFile; + QString m_chatToneFile; + QString m_mailToneFile; + QString m_calendarToneFile; + QString m_clockAlarmToneFile; + + int m_ringerToneEnabled; + int m_messageToneEnabled; + int m_chatToneEnabled; + int m_mailToneEnabled; + int m_internetCallToneEnabled; + int m_calendarToneEnabled; + int m_clockAlarmToneEnabled; + + //! libprofile callback for profile changes + static void currentProfileChangedCallback(const char *profile, ProfileControl *profileControl); + + //! libprofile callback for property changes + static void updateStateCallBackTrampoline(const char *profile, const char *key, const char *val, const char *type, + ProfileControl *profileControl); + void updateStateCallBack(const char *profile, const char *key, const char *val, const char *type); +}; + +#endif diff --git a/src/qmldir b/src/qmldir new file mode 100644 index 0000000..a1743ff --- /dev/null +++ b/src/qmldir @@ -0,0 +1 @@ +plugin nemosystemsettings diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..5d8cccc --- /dev/null +++ b/src/src.pro @@ -0,0 +1,36 @@ +TARGET = nemosystemsettings +PLUGIN_IMPORT_PATH = org/nemomobile/systemsettings + +QT += dbus +CONFIG += qmsystem2 mobility link_pkgconfig +PKGCONFIG += profile +MOBILITY += systeminfo + +OTHER_FILES += \ + qmldir + +system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml) + +SOURCES += \ + plugin.cpp \ + languagemodel.cpp \ + datetimesettings.cpp \ + profilecontrol.cpp \ + alarmtonemodel.cpp \ + mceiface.cpp \ + displaysettings.cpp \ + usbsettings.cpp \ + aboutsettings.cpp + +HEADERS += \ + languagemodel.h \ + datetimesettings.h \ + profilecontrol.h \ + alarmtonemodel.h \ + mceiface.h \ + displaysettings.h \ + usbsettings.h \ + aboutsettings.h + +include(../../plugin.pri) + diff --git a/src/usbsettings.cpp b/src/usbsettings.cpp new file mode 100644 index 0000000..365d518 --- /dev/null +++ b/src/usbsettings.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include "usbsettings.h" + +using namespace MeeGo; + +// mapping from QmUSBMode default mode to USBSettings default mode +static USBSettings::Mode qm2settings(QmUSBMode::Mode mode) +{ + switch (mode) { + case QmUSBMode::Ask: + return USBSettings::AskMode; + case QmUSBMode::MassStorage: + return USBSettings::MassStorageMode; + case QmUSBMode::Developer: + return USBSettings::DeveloperMode; + case QmUSBMode::MTP: + return USBSettings::MTPMode; + case QmUSBMode::ChargingOnly: + return USBSettings::ChargingMode; + default: + return USBSettings::AskMode; + } +} + +// mapping from USBSettings default mode to QmUSBMode default mode +static QmUSBMode::Mode settings2qm(USBSettings::Mode mode) +{ + switch(mode) { + case USBSettings::AskMode: + return QmUSBMode::Ask; + case USBSettings::MassStorageMode: + return QmUSBMode::MassStorage; + case USBSettings::DeveloperMode: + return QmUSBMode::Developer; + case USBSettings::MTPMode: + return QmUSBMode::MTP; + case USBSettings::ChargingMode: + return QmUSBMode::ChargingOnly; + case USBSettings::UndefinedMode: + return QmUSBMode::Undefined; + default: + qWarning("Unknown USB mode"); + return QmUSBMode::Undefined; + } +} + +USBSettings::USBSettings(QObject *parent) + : QObject(parent), + m_qmmode(new QmUSBMode(this)) +{ + connect(m_qmmode, SIGNAL(modeChanged(MeeGo::QmUSBMode::Mode)), + this, SIGNAL(currentModeChanged())); +} + +USBSettings::~USBSettings() +{ +} + +USBSettings::Mode USBSettings::currentMode() const +{ + QmUSBMode::Mode active = m_qmmode->getMode(); + + switch (active) { + case QmUSBMode::MassStorage: + return USBSettings::MassStorageMode; + + case QmUSBMode::Developer: + return USBSettings::DeveloperMode; + + case QmUSBMode::MTP: + return USBSettings::MTPMode; + + case QmUSBMode::ModeRequest: + case QmUSBMode::Ask: + case QmUSBMode::ChargingOnly: + return USBSettings::ChargingMode; + + case QmUSBMode::Disconnected: + case QmUSBMode::Undefined: + return USBSettings::UndefinedMode; + + default: + qWarning("Unhandled USB mode: %d", active); + } + + return USBSettings::UndefinedMode; +} + +USBSettings::Mode USBSettings::defaultMode() const +{ + return qm2settings(m_qmmode->getDefaultMode()); +} + +void USBSettings::setDefaultMode(const USBSettings::Mode mode) +{ + if (mode == defaultMode()) { + return; + } + + if (m_qmmode->setDefaultMode(settings2qm(mode))) { + emit defaultModeChanged(); + } else { + qWarning("Couldn't set default mode"); + } +} diff --git a/src/usbsettings.h b/src/usbsettings.h new file mode 100644 index 0000000..c747536 --- /dev/null +++ b/src/usbsettings.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013 Jolla Ltd. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef USBSETTINGS_H +#define USBSETTINGS_H + +#include +#include + +class USBSettings: public QObject +{ + Q_OBJECT + + Q_ENUMS(Mode) + + Q_PROPERTY(Mode currentMode READ currentMode NOTIFY currentModeChanged) + Q_PROPERTY(Mode defaultMode READ defaultMode WRITE setDefaultMode NOTIFY defaultModeChanged) + +public: + enum Mode { + AskMode = 0, + MassStorageMode, + DeveloperMode, + MTPMode, + ChargingMode, + UndefinedMode + }; + + explicit USBSettings(QObject *parent = 0); + virtual ~USBSettings(); + + Mode currentMode() const; + Mode defaultMode() const; + +public slots: + void setDefaultMode(const Mode mode); + +signals: + void currentModeChanged(); + void defaultModeChanged(); + +private: + MeeGo::QmUSBMode *m_qmmode; +}; + +#endif diff --git a/systemsettings.pro b/systemsettings.pro new file mode 100644 index 0000000..65d9262 --- /dev/null +++ b/systemsettings.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = src