Commit 1d2f3661 authored by Robin Burchell's avatar Robin Burchell

[systemsettings] initial commit

parents
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QDebug>
#include <QStringList>
#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();
}
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QSystemStorageInfo>
#include <QSystemNetworkInfo>
#include <QSystemDeviceInfo>
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
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QDir>
#include <QDebug>
const char * const AlarmToneDir = "/usr/share/sounds/jolla-ringtones/stereo/";
AlarmToneModel::AlarmToneModel(QObject *parent)
: QAbstractListModel(parent)
{
QHash<int, QByteArray> 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();
}
}
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QAbstractListModel>
#include <QFileInfo>
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
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QDebug>
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();
}
}
}
}
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QObject>
#include <QTime>
#include <qmtime.h>
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
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <mce/dbus-names.h>
#include <mce/mode-names.h>
#include "mceiface.h"
#include "displaysettings.h"
#include <QDebug>
DisplaySettings::DisplaySettings(QObject *parent)
: QObject(parent)
{
m_mceIface = new ComNokiaMceRequestInterface(MCE_SERVICE, MCE_REQUEST_PATH, QDBusConnection::systemBus(), this);
QDBusPendingReply<QDBusVariant> 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<QDBusVariant> result = m_mceIface->get_config(QDBusObjectPath("/system/osso/dsm/display/max_display_brightness_levels"));
result.waitForFinished();
return result.value().variant().toInt();
}
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QObject>
#include <qdeclarative.h>
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
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* 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 <QDir>
#include <QDebug>
#include <QSettings>
#include <QHash>
#include <QDBusInterface>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
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<int, QByteArray> 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