Skip to content

Commit

Permalink
[systemsettings] Import changes from Jolla.
Browse files Browse the repository at this point in the history
TBD: Make this a library. This is required for properly unforking this from the
Jolla side, and will be done in the next commit.
  • Loading branch information
rburchell committed Aug 20, 2013
1 parent 1322126 commit 283e211
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 124 deletions.
20 changes: 12 additions & 8 deletions src/aboutsettings.cpp
Expand Up @@ -29,17 +29,21 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#include "aboutsettings.h"

#include <QDebug>
#include <QStringList>
#include "aboutsettings.h"
#include <QStorageInfo>
#include <QNetworkInfo>
#include <QDeviceInfo>

AboutSettings::AboutSettings(QObject *parent)
: QObject(parent),
m_sysinfo(new QSystemStorageInfo(this)),
m_netinfo(new QSystemNetworkInfo(this)),
m_devinfo(new QSystemDeviceInfo(this))
m_sysinfo(new QStorageInfo(this)),
m_netinfo(new QNetworkInfo(this)),
m_devinfo(new QDeviceInfo(this))
{
qDebug() << "Drives:" << m_sysinfo->logicalDrives();
qDebug() << "Drives:" << m_sysinfo->allLogicalDrives();
}

AboutSettings::~AboutSettings()
Expand All @@ -58,17 +62,17 @@ qlonglong AboutSettings::availableDiskSpace() const

const QString AboutSettings::bluetoothAddress() const
{
return m_netinfo->macAddress(QSystemNetworkInfo::BluetoothMode);
return m_netinfo->macAddress(QNetworkInfo::BluetoothMode, 0);
}

const QString AboutSettings::wlanMacAddress() const
{
return m_netinfo->macAddress(QSystemNetworkInfo::WlanMode);
return m_netinfo->macAddress(QNetworkInfo::WlanMode, 0);
}

const QString AboutSettings::imei() const
{
return m_devinfo->imei();
return m_devinfo->imei(0);
}

const QString AboutSettings::manufacturer() const
Expand Down
15 changes: 7 additions & 8 deletions src/aboutsettings.h
Expand Up @@ -32,12 +32,11 @@
#ifndef ABOUTSETTINGS_H
#define ABOUTSETTINGS_H

#include <QSystemStorageInfo>
#include <QSystemNetworkInfo>
#include <QSystemDeviceInfo>

QTM_USE_NAMESPACE
#include <QObject>

class QStorageInfo;
class QNetworkInfo;
class QDeviceInfo;
class AboutSettings: public QObject
{
Q_OBJECT
Expand All @@ -64,9 +63,9 @@ class AboutSettings: public QObject
const QString model() const;

private:
QSystemStorageInfo *m_sysinfo;
QSystemNetworkInfo *m_netinfo;
QSystemDeviceInfo *m_devinfo;
QStorageInfo *m_sysinfo;
QNetworkInfo *m_netinfo;
QDeviceInfo *m_devinfo;
};

#endif
32 changes: 27 additions & 5 deletions src/alarmtonemodel.cpp
Expand Up @@ -33,18 +33,15 @@

#include <QDir>
#include <QDebug>
#include <QQmlEngine>
#include <qqml.h>

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?
Expand All @@ -55,6 +52,15 @@ AlarmToneModel::~AlarmToneModel()
{
}

QHash<int, QByteArray> AlarmToneModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[FilenameRole] = "filename";
roles[TitleRole] = "title";

return roles;
}

int AlarmToneModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
Expand All @@ -78,3 +84,19 @@ QVariant AlarmToneModel::data(const QModelIndex &index, int role) const
return QVariant();
}
}

QJSValue AlarmToneModel::get(int index) const
{
if (index < 0 || m_fileInfoList.count() <= index) {
return QJSValue();
}

QFileInfo info = m_fileInfoList.at(index);
QJSEngine *const engine = qmlEngine(this);
QJSValue value = engine->newObject();

value.setProperty("filename", engine->toScriptValue(info.absoluteFilePath()));
value.setProperty("title", engine->toScriptValue(info.baseName()));

return value;
}
13 changes: 10 additions & 3 deletions src/alarmtonemodel.h
Expand Up @@ -34,11 +34,13 @@

#include <QAbstractListModel>
#include <QFileInfo>
#include <QJSValue>

class AlarmToneModel : public QAbstractListModel
class AlarmToneModel
: public QAbstractListModel
{
Q_OBJECT

Q_PROPERTY(int count READ rowCount CONSTANT)
public:
enum ApplicationRoles {
FilenameRole = Qt::UserRole + 1,
Expand All @@ -47,14 +49,19 @@ class AlarmToneModel : public QAbstractListModel

explicit AlarmToneModel(QObject *parent = 0);
virtual ~AlarmToneModel();

virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;

Q_INVOKABLE QJSValue get(int index) const;

signals:
void selectedFileChanged();
void currentIndexChanged();

protected:
QHash<int, QByteArray> roleNames() const;

private:
QFileInfoList m_fileInfoList;
};
Expand Down
6 changes: 4 additions & 2 deletions src/datetimesettings.cpp
Expand Up @@ -80,8 +80,9 @@ bool DateTimeSettings::automaticTimezoneUpdate()
void DateTimeSettings::setAutomaticTimezoneUpdate(bool enable)
{
bool enabled = m_autoTimezone == MeeGo::QmTime::AutoTimeZoneOn;
if (enabled == enable)
if (enabled == enable) {
return;
}

m_time.setAutoTimeZone(enable ? MeeGo::QmTime::AutoTimeZoneOn : MeeGo::QmTime::AutoTimeZoneOff);
}
Expand All @@ -93,8 +94,9 @@ QString DateTimeSettings::timezone() const

void DateTimeSettings::setTimezone(const QString &tz)
{
if (tz == m_timezone)
if (tz == m_timezone) {
return;
}

m_time.setTimezone(tz);
}
Expand Down
91 changes: 91 additions & 0 deletions src/devicelockiface.cpp
@@ -0,0 +1,91 @@
/*
* 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 <QObject>
#include <QSettings>
#include <QProcess>
#include <QDebug>
#include "devicelockiface.h"

static bool runPlugin(QStringList args)
{
QSettings s("/usr/share/lipstick/devicelock/devicelock.conf", QSettings::IniFormat);
QString pluginName = s.value("DeviceLock/pluginName").toString();

if (pluginName.isEmpty()) {
qWarning("DeviceLock: no plugin configuration set in /usr/share/lipstick/devicelock/devicelock.conf");
return false;
}

QProcess p;
p.start(pluginName, args);
if (!p.waitForFinished()) {
qWarning("DeviceLock: plugin did not finish in time");
return false;
}

qDebug() << p.readAllStandardOutput();
qWarning() << p.readAllStandardError();
return p.exitCode() == 0;
}

DeviceLockInterface::DeviceLockInterface(QObject *parent)
: QObject(parent),
m_cacheRefreshNeeded(true)
{
}

DeviceLockInterface::~DeviceLockInterface()
{
}

bool DeviceLockInterface::checkCode(const QString &code)
{
return runPlugin(QStringList() << "--check-code" << code);
}

bool DeviceLockInterface::setCode(const QString &oldCode, const QString &newCode)
{
bool return_value = runPlugin(QStringList() << "--set-code" << oldCode << newCode);
if (return_value) {
m_cacheRefreshNeeded = true;
emit isSetChanged();
}
return return_value;
}

bool DeviceLockInterface::isSet() {
if (m_cacheRefreshNeeded) {
m_codeSet = runPlugin(QStringList() << "--is-set" << "lockcode");
m_cacheRefreshNeeded = false;
}
return m_codeSet;
}
57 changes: 57 additions & 0 deletions src/devicelockiface.h
@@ -0,0 +1,57 @@
/*
* 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 DEVICELOCKINTERFACE_H
#define DEVICELOCKINTERFACE_H
#include <QObject>
#include <QSettings>
#include <QProcess>
#include <QDebug>

class DeviceLockInterface : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isSet READ isSet NOTIFY isSetChanged);
public:
explicit DeviceLockInterface(QObject *parent = 0);
virtual ~DeviceLockInterface();

Q_INVOKABLE bool checkCode(const QString &code);
Q_INVOKABLE bool setCode(const QString &oldCode, const QString &newCode);
Q_INVOKABLE bool isSet();
signals:
void isSetChanged();
private:
bool m_codeSet;
bool m_cacheRefreshNeeded;
};

#endif

0 comments on commit 283e211

Please sign in to comment.