Import Upstream version 0.2

This commit is contained in:
openKylinBot 2022-05-14 03:30:57 +08:00
commit a2940a81ed
34 changed files with 2050 additions and 0 deletions

165
COPYING Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

182
GSettings/gsettings-qml.cpp Normal file
View File

@ -0,0 +1,182 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#include "gsettings-qml.h"
#include <QGSettings>
struct GSettingsSchemaQmlPrivate
{
QByteArray id;
QByteArray path;
bool isValid;
GSettingsSchemaQmlPrivate() : isValid(false) {}
};
struct GSettingsQmlPrivate
{
GSettingsSchemaQml *schema;
QGSettings *settings;
};
GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent)
{
priv = new GSettingsSchemaQmlPrivate;
}
GSettingsSchemaQml::~GSettingsSchemaQml()
{
delete priv;
}
QByteArray GSettingsSchemaQml::id() const
{
return priv->id;
}
void GSettingsSchemaQml::setId(const QByteArray &id)
{
if (!priv->id.isEmpty()) {
qWarning("GSettings.schema.id may only be set on construction");
return;
}
priv->id = id;
}
QByteArray GSettingsSchemaQml::path() const
{
return priv->path;
}
void GSettingsSchemaQml::setPath(const QByteArray &path)
{
if (!priv->path.isEmpty()) {
qWarning("GSettings.schema.path may only be set on construction");
return;
}
priv->path = path;
}
bool GSettingsSchemaQml::isValid() const
{
return priv->isValid;
}
void GSettingsSchemaQml::setIsValid(bool valid)
{
if (valid != priv->isValid) {
priv->isValid = valid;
Q_EMIT isValidChanged();
}
}
QVariantList GSettingsSchemaQml::choices(const QByteArray &key) const
{
GSettingsQml *parent = (GSettingsQml *) this->parent();
if (parent->priv->settings == NULL)
return QVariantList();
if (!parent->contains(key))
return QVariantList();
return parent->priv->settings->choices(key);
}
void GSettingsSchemaQml::reset(const QByteArray &key)
{
GSettingsQml *parent = (GSettingsQml *) this->parent();
if (parent->priv->settings != NULL) {
parent->priv->settings->reset(key);
// make sure this object gets the new value immediately and not on the
// next main loop iteration (see updateValue)
parent->settingChanged(key);
}
}
GSettingsQml::GSettingsQml(QObject *parent): QQmlPropertyMap(this, parent)
{
priv = new GSettingsQmlPrivate;
priv->schema = new GSettingsSchemaQml(this);
priv->settings = NULL;
}
GSettingsQml::~GSettingsQml()
{
delete priv;
}
GSettingsSchemaQml * GSettingsQml::schema() const
{
return priv->schema;
}
void GSettingsQml::classBegin()
{
}
void GSettingsQml::componentComplete()
{
bool schemaValid = QGSettings::isSchemaInstalled(priv->schema->id());
if (schemaValid) {
priv->settings = new QGSettings(priv->schema->id(), priv->schema->path(), this);
connect(priv->settings, SIGNAL(changed(const QString &)), this, SLOT(settingChanged(const QString &)));
Q_FOREACH(const QString &key, priv->settings->keys())
this->insert(key, priv->settings->get(key));
Q_EMIT(schemaChanged());
}
// emit isValid notification only once everything is setup
priv->schema->setIsValid(schemaValid);
}
void GSettingsQml::settingChanged(const QString &key)
{
QVariant value = priv->settings->get(key);
if (this->value(key) != value) {
this->insert(key, value);
Q_EMIT(changed(key, value));
}
}
QVariant GSettingsQml::updateValue(const QString& key, const QVariant &value)
{
if (priv->settings == NULL)
return QVariant();
if (priv->settings->trySet(key, value)) {
// due to QTBUG-32859, QGSettings doesn't dispatch its changed signal
// directly, but on a new main loop iteration. At that point, this
// object already has the new value set and doesn't emit its own
// changed signal (see ::settingChanged). Emit it here so that it is
// sent even when the setting is changed from qml.
Q_EMIT(changed(key, value));
return value;
}
else {
qWarning("unable to set key '%s' to value '%s'", key.toUtf8().constData(), value.toString().toUtf8().constData());
return priv->settings->get(key);
}
}

80
GSettings/gsettings-qml.h Normal file
View File

@ -0,0 +1,80 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#include <QtQml>
#include <QQmlParserStatus>
class GSettingsSchemaQml: public QObject
{
Q_OBJECT
Q_PROPERTY(QByteArray id READ id WRITE setId)
Q_PROPERTY(QByteArray path READ path WRITE setPath)
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
public:
GSettingsSchemaQml(QObject *parent = NULL);
~GSettingsSchemaQml();
QByteArray id() const;
void setId(const QByteArray &id);
QByteArray path() const;
void setPath(const QByteArray &path);
bool isValid() const;
void setIsValid(bool valid);
Q_INVOKABLE QVariantList choices(const QByteArray &key) const;
Q_INVOKABLE void reset(const QByteArray &key);
Q_SIGNALS:
void isValidChanged();
private:
struct GSettingsSchemaQmlPrivate *priv;
};
class GSettingsQml: public QQmlPropertyMap, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
public:
GSettingsQml(QObject *parent = NULL);
~GSettingsQml();
GSettingsSchemaQml * schema() const;
void classBegin();
void componentComplete();
Q_SIGNALS:
void schemaChanged();
void changed (const QString &key, const QVariant &value);
private Q_SLOTS:
void settingChanged(const QString &key);
private:
struct GSettingsQmlPrivate *priv;
QVariant updateValue(const QString& key, const QVariant &value);
friend class GSettingsSchemaQml;
};

View File

@ -0,0 +1,30 @@
TEMPLATE = lib
QT += qml
QT -= gui
CONFIG += qt plugin no_keywords link_pkgconfig
PKGCONFIG += gio-2.0
INCLUDEPATH += ../src .
LIBS += -L../src -lgsettings-qt
TARGET = GSettingsQmlPlugin
HEADERS = plugin.h gsettings-qml.h
SOURCES = plugin.cpp gsettings-qml.cpp
uri = GSettings
API_VER = 1.0
# deployment rules for the plugin
installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /).$$API_VER
target.path = $$installPath
INSTALLS += target
extra.path = $$installPath
extra.files += qmldir
INSTALLS += extra
qmltypes.path = $$installPath
qmltypes.files = plugins.qmltypes
qmltypes.extra = export LD_PRELOAD=../src/libgsettings-qt.so.1; $$[QT_INSTALL_BINS]/qmlplugindump -notrelocatable GSettings 1.0 .. > $(INSTALL_ROOT)/$$installPath/plugins.qmltypes
INSTALLS += qmltypes

28
GSettings/plugin.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#include "plugin.h"
#include "gsettings-qml.h"
void GSettingsQmlPlugin::registerTypes(const char *uri)
{
qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
"GSettingsSchema can only be used inside of a GSettings component");
}

28
GSettings/plugin.h Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#include <QtQml>
class GSettingsQmlPlugin: public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.ubports.GSettings")
public:
void registerTypes(const char *uri);
};

3
GSettings/qmldir Normal file
View File

@ -0,0 +1,3 @@
module GSettings
plugin GSettingsQmlPlugin
typeinfo plugins.qmltypes

66
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,66 @@
pipeline {
agent any
stages {
stage('Build source') {
steps {
sh '/usr/bin/build-source.sh'
stash(name: 'source', includes: '*.gz,*.bz2,*.xz,*.deb,*.dsc,*.changes,*.buildinfo,lintian.txt')
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
}
stage('Build binary - armhf') {
steps {
parallel(
"Build binary - armhf": {
node(label: 'arm64') {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
unstash 'source'
sh '''export architecture="armhf"
build-binary.sh'''
stash(includes: '*.gz,*.bz2,*.xz,*.deb,*.dsc,*.changes,*.buildinfo,lintian.txt', name: 'build-armhf')
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
},
"Build binary - arm64": {
node(label: 'arm64') {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
unstash 'source'
sh '''export architecture="arm64"
build-binary.sh'''
stash(includes: '*.gz,*.bz2,*.xz,*.deb,*.dsc,*.changes,*.buildinfo,lintian.txt', name: 'build-arm64')
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
},
"Build binary - amd64": {
node(label: 'amd64') {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
unstash 'source'
sh '''export architecture="amd64"
build-binary.sh'''
stash(includes: '*.gz,*.bz2,*.xz,*.deb,*.dsc,*.changes,*.buildinfo,lintian.txt', name: 'build-amd64')
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
}
)
}
}
stage('Results') {
steps {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
unstash 'build-armhf'
unstash 'build-arm64'
unstash 'build-amd64'
archiveArtifacts(artifacts: '*.gz,*.bz2,*.xz,*.deb,*.dsc,*.changes,*.buildinfo', fingerprint: true, onlyIfSuccessful: true)
sh '''/usr/bin/build-repo.sh'''
}
}
stage('Cleanup') {
steps {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
}
}
}

373
debian/changelog vendored Normal file
View File

@ -0,0 +1,373 @@
gsettings-qt (0.2+ubports) bionic; urgency=medium
* Imported to UBports
-- UBports auto importer <infra@ubports.com> Thu, 26 Oct 2017 13:41:36 +0200
gsettings-qt (0.1+17.10.20170824-0ubuntu1) artful; urgency=medium
* Update debian/libgsettings-qt1.symbols with the latest symbols
changes.
-- Dmitry Shachnev <mitya57@ubuntu.com> Thu, 24 Aug 2017 17:09:31 +0000
gsettings-qt (0.1+16.04.20160329-0ubuntu3~1) zesty; urgency=medium
* No change rebuild
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Wed, 04 Jan 2017 08:53:28 +0200
gsettings-qt (0.1+16.04.20160329-0ubuntu2~4) yakkety; urgency=medium
* Build against Qt 5.6.
* Adjust test running to changes in Qt 5.6.
* debian/control: don't use transitional package names
* Update symbols.
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Fri, 01 Apr 2016 10:12:26 +0000
gsettings-qt (0.1+16.04.20160329-0ubuntu1) xenial; urgency=medium
[ Albert Astals Cid ]
* Use QChar toUpper/toLower instead of C version (LP: #1556461)
-- Michał Sawicz <michal.sawicz@canonical.com> Tue, 29 Mar 2016 12:56:42 +0000
gsettings-qt (0.1+16.04.20160111-0ubuntu1) xenial; urgency=medium
[ Albert Astals Cid ]
* Disconnect signal handler on destruction
-- Michał Sawicz <michal.sawicz@canonical.com> Mon, 11 Jan 2016 11:26:52 +0000
gsettings-qt (0.1+16.04.20151130-0ubuntu1) xenial; urgency=medium
* No-change rebuild.
-- CI Train Bot <ci-train-bot@canonical.com> Mon, 30 Nov 2015 14:50:27 +0000
gsettings-qt (0.1+16.04.20151104-0ubuntu1) xenial; urgency=medium
[ Lars Uebernickel ]
* qgsettings-qml: explicitly emit changed events (LP: #1503693)
-- Sebastien Bacher <seb128@ubuntu.com> Wed, 04 Nov 2015 17:59:13 +0000
gsettings-qt (0.1+15.04.20150810-0ubuntu1) vivid; urgency=medium
[ Lukáš Tinkl ]
* Force handling deferred delete events to avoid memory leaks (LP:
#1460970)
* Force handling deferred delete events to avoid memory leaks (LP:
#1460970)
-- CI Train Bot <ci-train-bot@canonical.com> Mon, 10 Aug 2015 15:49:54 +0000
gsettings-qt (0.1+14.10.20140807-0ubuntu6~gcc5.1) wily; urgency=medium
* No-change test rebuild for g++5 ABI transition
-- Steve Langasek <steve.langasek@ubuntu.com> Wed, 15 Jul 2015 07:53:08 +0000
gsettings-qt (0.1+14.10.20140807-0ubuntu5) wily; urgency=medium
* No-change rebuild against Qt 5.4.2.
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Fri, 12 Jun 2015 09:21:19 +0300
gsettings-qt (0.1+14.10.20140807-0ubuntu4) vivid; urgency=medium
* No-change rebuild against Qt 5.4.1.
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Wed, 11 Mar 2015 08:25:19 +0200
gsettings-qt (0.1+14.10.20140807-0ubuntu3) vivid; urgency=medium
* No-change rebuild against Qt 5.4.0.
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Fri, 13 Feb 2015 13:57:38 +0200
gsettings-qt (0.1+14.10.20140807-0ubuntu2) vivid; urgency=medium
* No-change rebuild against Qt 5.3.2.
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Tue, 28 Oct 2014 13:40:39 +0200
gsettings-qt (0.1+14.10.20140807-0ubuntu1) utopic; urgency=low
[ Ken VanDine ]
* qtdeclarative5-gsettings1.0 needs to depend on the same version of
libgsettings-qt1
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 07 Aug 2014 15:26:43 +0000
gsettings-qt (0.1+14.10.20140801.1-0ubuntu1) utopic; urgency=low
[ Ubuntu daily release ]
* debian/libgsettings-qt1.symbols: auto-update to released version
* New rebuild forced
[ Ken VanDine ]
* added tests for a{ss}
[ Lars Uebernickel ]
* qconftypes: support a{ss} We don't support a{sv} because gsettings
is typed more strictly than javascript and qvariant. (LP: #1349787)
[ Łukasz 'sil2100' Zemczak ]
* Work-around a symbols problem in ppc64el
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 01 Aug 2014 17:06:59 +0000
gsettings-qt (0.1+14.10.20140624-0ubuntu1) utopic; urgency=low
[ Lars Uebernickel ]
* Stop using deprecated g_settings_get_range()
* qml: only emit changed when the value has actually changed This
cannot be done for the c++ class, because that would involve a
round-trip to the dconf database. The QML component already caches
all values because of the way QQmlPropertyMap works. (LP: #1330365)
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 24 Jun 2014 10:01:54 +0000
gsettings-qt (0.1+14.10.20140607-0ubuntu1) utopic; urgency=low
* New rebuild forced
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Sat, 07 Jun 2014 10:54:33 +0000
gsettings-qt (0.1+14.10.20140606-0ubuntu1) utopic; urgency=low
[ Lars Uebernickel ]
* Sync settings in destructor To ensure that settings are saved to
disc when an app exits.
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 06 Jun 2014 14:31:00 +0000
gsettings-qt (0.1+14.10.20140520-0ubuntu1) utopic; urgency=low
[ Iain Lane ]
* Add a symbols file so that the qtdeclarative module (and other
rdeps) get correctly versioned dependencies (LP: #1304611)
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 20 May 2014 18:39:37 +0000
gsettings-qt (0.1+14.10.20140501-0ubuntu1) utopic; urgency=low
[ Michal Hruby ]
* Fix incorrect unref call.
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 01 May 2014 10:29:56 +0000
gsettings-qt (0.1+14.04.20140408-0ubuntu1) trusty; urgency=medium
[ Michal Hruby ]
* Added API to check if a schema is installed
[ CI bot ]
* Added API to check if a schema is installed. (LP: #1209235)
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 08 Apr 2014 13:44:50 +0000
gsettings-qt (0.0+13.10.20130902.1-0ubuntu2) trusty; urgency=medium
* Rebuild against Qt 5.2.1
-- Timo Jyrinki <timo-jyrinki@ubuntu.com> Mon, 03 Mar 2014 07:46:18 +0200
gsettings-qt (0.0+13.10.20130902.1-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Don't write values into the QQmlPropertyMap when the write failed
This makes sure that the property map doesn't get out of sync with
the gsettings database.
[ Ubuntu daily release ]
* Automatic snapshot from revision 41
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 02 Sep 2013 06:12:44 +0000
gsettings-qt (0.0+13.10.20130829-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Add API to reset a key to its default value. (LP: #1218005)
[ Ubuntu daily release ]
* Automatic snapshot from revision 39
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 29 Aug 2013 12:29:45 +0000
gsettings-qt (0.0+13.10.20130807-0ubuntu1) saucy; urgency=low
[ Ken VanDine ]
* Install QML module in a versioned dir so it is really parallel
installable .
[ Lars Uebernickel ]
* Fix crash in unqtify_name For one, stop using g_string_new_len(),
which creates a string with a given length, not allocation. Also,
make sure the QByteArray stays around for the duration of the loop.
[ Ubuntu daily release ]
* Automatic snapshot from revision 37
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 07 Aug 2013 07:02:05 +0000
gsettings-qt (0.0+13.10.20130802-0ubuntu1) saucy; urgency=low
[ Sebastien Bacher ]
* let the dev binary depends on the library.
[ Ubuntu daily release ]
* Automatic snapshot from revision 34
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 02 Aug 2013 20:16:44 +0000
gsettings-qt (0.0+13.10.20130730.1-0ubuntu1) saucy; urgency=low
[ Sebastien Bacher ]
* build a .qmltypes, so qtcreator knows about GSettings.
[ Ubuntu daily release ]
* Automatic snapshot from revision 32
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 30 Jul 2013 18:08:14 +0000
gsettings-qt (0.0+13.10.20130730-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Fix regression: GSettingsQml didn't update values on change. (LP:
#1206181)
[ Ubuntu daily release ]
* Automatic snapshot from revision 30
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 30 Jul 2013 07:01:52 +0000
gsettings-qt (0.0+13.10.20130725-0ubuntu1) saucy; urgency=low
[ Sebastien Bacher ]
* Add a library that can be used from qt/c++ and make gsettings-qml
use that.
[ Lars Uebernickel ]
* Add a library that can be used from qt/c++ and make gsettings-qml
use that.
[ Ubuntu daily release ]
* Automatic snapshot from revision 28
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 25 Jul 2013 07:01:48 +0000
gsettings-qt (0.0+13.10.20130720-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Don't abort when calling schema.choices() for an unknown key. Also
adds a test for accessing an unknown key from the settings object.
* Clean up tests and add some more testing.
[ Ubuntu daily release ]
* Automatic snapshot from revision 26
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Sat, 20 Jul 2013 07:01:48 +0000
gsettings-qt (0.0+13.10.20130717-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Add GSettings.schema.choices A function that takes the name of a key
and returns the possible values the key may assume. The values are
returned in a QVariantList, so they can be used as qml models (with
the modelData role). This breaks API: the settings schema must now
be set with "schema.id" and the path with "schema.path".
[ Ubuntu daily release ]
* Automatic snapshot from revision 23
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 17 Jul 2013 16:55:56 +0000
gsettings-qt (0.0+13.10.20130716-0ubuntu1) saucy; urgency=low
[ Iain Lane ]
* Add a testcase for the onChanged signal.
[ Ubuntu daily release ]
* Automatic snapshot from revision 21
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 16 Jul 2013 07:01:42 +0000
gsettings-qt (0.0+13.10.20130713-0ubuntu1) saucy; urgency=low
[ Lars Uebernickel ]
* Add 'changed' signal There's a 'valueChanged' on QQmlPropertyMap,
but that is not emitted when values are inserted via insert().
'changed' is always emitted, except when the values are first read.
[ Ubuntu daily release ]
* Automatic snapshot from revision 19
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Sat, 13 Jul 2013 07:01:43 +0000
gsettings-qt (0.0+13.10.20130701-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 17
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 01 Jul 2013 07:01:01 +0000
gsettings-qt (0.0+13.10.20130630-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 16
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Sun, 30 Jun 2013 07:00:59 +0000
gsettings-qt (0.0+13.10.20130629-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 15
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Sat, 29 Jun 2013 07:01:00 +0000
gsettings-qt (0.0+13.10.20130628.1-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 14
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 28 Jun 2013 19:40:37 +0000
gsettings-qt (0.0+13.10.20130628-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 13
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 28 Jun 2013 07:01:01 +0000
gsettings-qt (0.0+13.10.20130627-0ubuntu1) saucy; urgency=low
* Automatic snapshot from revision 12
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 27 Jun 2013 07:01:01 +0000
gsettings-qt (0.0+13.10.20130626.1-0ubuntu1) saucy; urgency=low
[ Ken VanDine ]
* build depend on qtdeclarative5-test-plugin .
[ Lars Uebernickel ]
* gsettings-qt: gsettings bindings for qml
* Merge initial packaging From lp:~ken-vandine/gsettings-qt/packaging
* Add basic testing
* Remove QtGui dependency qmake adds this by default. Note that this
does not remove the dependency from `make check`, qtquicktests
depends on it.
* debian: run `make check` under xvfb-run
* Merge trunk
* debian: run xvfb with -a
* Don't install tests Merged from lp:~ken-vandine/gsettings-
qt/no_install_tests
[ Ubuntu daily release ]
* Automatic snapshot from revision 11
-- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 26 Jun 2013 19:36:35 +0000
gsettings-qt (0.0-0ubuntu1) saucy; urgency=low
* Initial package
-- Ken VanDine <ken.vandine@canonical.com> Fri, 21 Jun 2013 14:35:13 -0400

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
9

49
debian/control vendored Normal file
View File

@ -0,0 +1,49 @@
Source: gsettings-qt
Priority: extra
Maintainer: UBports Developers <developers@ubports.com>
Build-Depends: debhelper (>= 9),
pkg-config,
libglib2.0-dev,
qtchooser,
qt5-qmake,
qtbase5-dev,
qtdeclarative5-dev,
qtdeclarative5-dev-tools,
qml-module-qttest,
qml-module-qtquick2,
xvfb,
Standards-Version: 3.9.4
Section: libs
Homepage: https://gitlab.com/ubports/core-os/gsettings-qt
Package: qtdeclarative5-gsettings1.0
Section: libs
Architecture: any
Pre-Depends: ${misc:Pre-Depends}
Depends: ${shlibs:Depends},
${misc:Depends},
libgsettings-qt1 (= ${binary:Version}),
Description: QML Bindings for GSettings
Expose QML bindings for GSettings
Package: libgsettings-qt1
Section: libs
Architecture: any
Multi-Arch: same
Pre-Depends: ${misc:Pre-Depends}
Depends: ${shlibs:Depends},
${misc:Depends},
Description: Library to access GSettings from Qt
Library to access GSettings from Qt
Package: libgsettings-qt-dev
Section: libdevel
Architecture: any
Pre-Depends: dpkg (>= 1.15.6~)
Depends: ${misc:Depends},
libgsettings-qt1 (= ${binary:Version}),
Description: Library to access GSettings from Qt - devel
Library to access GSettings from Qt
.
This package contains the development files needed to build applications using
the GSettings Qt library

21
debian/copyright vendored Normal file
View File

@ -0,0 +1,21 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: gsettings-qt
Source: https://launchpad.net/gsettings-qt
Files: *
Copyright: 2013 Canonical Ltd.
License: LGPL-3
This package is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 3.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
.
On Debian systems, the complete text of the GNU Lesser General
Public License can be found in "/usr/share/common-licenses/LGPL-3".

3
debian/libgsettings-qt-dev.install vendored Normal file
View File

@ -0,0 +1,3 @@
usr/lib/*/lib*.so
usr/include
usr/lib/*/pkgconfig/gsettings-qt.pc

1
debian/libgsettings-qt1.install vendored Normal file
View File

@ -0,0 +1 @@
usr/lib/*/lib*.so.*

42
debian/libgsettings-qt1.symbols vendored Normal file
View File

@ -0,0 +1,42 @@
# SymbolsHelper-Confirmed: 0.1+16.04.20160329-0ubuntu2 amd64 arm64 armhf i386 ppc64el
libgsettings-qt.so.1 libgsettings-qt1 #MINVER#
(c++)"QByteArray::~QByteArray()@Base" 0.1+14.04.20140408
(c++)"QGSettings::QGSettings(QByteArray const&, QByteArray const&, QObject*)@Base" 0.1+14.04.20140408
(c++)"QGSettings::changed(QString const&)@Base" 0.1+14.04.20140408
(c++)"QGSettings::choices(QString const&) const@Base" 0.1+14.04.20140408
(c++)"QGSettings::get(QString const&) const@Base" 0.1+14.04.20140408
(c++)"QGSettings::isSchemaInstalled(QByteArray const&)@Base" 0.1+14.04.20140408
(c++)"QGSettings::keys() const@Base" 0.1+14.04.20140408
(c++)"QGSettings::metaObject() const@Base" 0.1+14.04.20140408
(c++)"QGSettings::qt_metacall(QMetaObject::Call, int, void**)@Base" 0.1+14.04.20140408
(c++)"QGSettings::qt_metacast(char const*)@Base" 0.1+14.04.20140408
(c++)"QGSettings::reset(QString const&)@Base" 0.1+14.04.20140408
(c++)"QGSettings::set(QString const&, QVariant const&)@Base" 0.1+14.04.20140408
(c++)"QGSettings::staticMetaObject@Base" 0.1+14.04.20140408
(c++)"QGSettings::trySet(QString const&, QVariant const&)@Base" 0.1+14.04.20140408
(c++)"QGSettings::~QGSettings()@Base" 0.1+14.04.20140408
(c++)"QGSettingsPrivate::settingChanged(_GSettings*, char const*, void*)@Base" 0.1+14.04.20140408
(c++|optional=templinst)"QList<QString>::append(QString const&)@Base" 0.1+14.04.20140408
(c++|optional=templinst)"QList<QString>::detach_helper_grow(int, int)@Base" 0.1+14.10.20140801.1
(c++|optional=templinst)"QList<QString>::~QList()@Base" 0.1+14.04.20140408
(c++|optional=templinst|arch=!ppc64el)"QList<QVariant>::append(QVariant const&)@Base" 0.1+14.04.20140408
(c++|optional=templinst)"QList<QVariant>::detach_helper_grow(int, int)@Base" 0.1+14.04.20140408
(c++|optional=templinst)"QList<QVariant>::~QList()@Base" 0.1+14.04.20140408
(c++)"QMap<QString, QVariant>::~QMap()@Base" 0.1+14.10.20140801.1
(c++)"QMapNode<QString, QVariant>::copy(QMapData<QString, QVariant>*) const@Base" 0.1+14.10.20140801.1
(c++)"QMapNode<QString, QVariant>::destroySubTree()@Base" 0.1+14.10.20140801.1
(c++)"QString::~QString()@Base" 0.1+14.04.20140408
(optional=templinst)_ZN4QMapI7QString8QVariantEC1ERKS2_@Base 0.1+16.04.20160329-0ubuntu2
(optional=templinst)_ZN4QMapI7QString8QVariantEC2ERKS2_@Base 0.1+16.04.20160329-0ubuntu2
(optional=templinst)_ZN5QListI7QStringEC1ERKS1_@Base 0.1+16.04.20160329-0ubuntu2
(optional=templinst)_ZN5QListI7QStringEC2ERKS1_@Base 0.1+16.04.20160329-0ubuntu2
(optional=templinst|arch=ppc64el)_ZN5QListI8QVariantE6appendERKS0_@Base 0.1+16.04.20160329-0ubuntu2
(optional=templinst)_ZN8QMapDataI7QString8QVariantE7destroyEv@Base 0.1+16.04.20160329-0ubuntu2
(c++)"qconf_types_collect_from_variant(_GVariantType const*, QVariant const&)@Base" 0.1+14.04.20140408
(c++)"qconf_types_convert(_GVariantType const*)@Base" 0.1+14.04.20140408
(c++)"qconf_types_to_qvariant(_GVariant*)@Base" 0.1+14.04.20140408
(c++)"qtify_name(char const*)@Base" 0.1+14.04.20140408
(c++)"typeinfo for QGSettings@Base" 0.1+14.04.20140408
(c++)"typeinfo name for QGSettings@Base" 0.1+14.04.20140408
(c++)"unqtify_name(QString const&)@Base" 0.1+14.04.20140408
(c++)"vtable for QGSettings@Base" 0.1+14.04.20140408

View File

@ -0,0 +1 @@
usr/lib/*/qt5

24
debian/rules vendored Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export QT_SELECT=qt5
# Skip tests on the archs they are known to be flaky
testskip_architectures := powerpc
override_dh_install:
rm -rf debian/*/usr/tests
dh_install --fail-missing
override_dh_auto_test:
ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(testskip_architectures)))
QT_QPA_PLATFORM=minimal LD_LIBRARY_PATH=../src GSETTINGS_BACKEND=memory GSETTINGS_SCHEMA_DIR=. xvfb-run -a dh_auto_test
endif
override_dh_makeshlibs:
dh_makeshlibs -- -c4
%:
dh $@

33
examples/choices.qml Normal file
View File

@ -0,0 +1,33 @@
import GSettings 1.0
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItems
Item {
width: 400
height: 300
GSettings {
id: settings
schema.id: "com.ubports.Unity.Lenses"
}
Column {
anchors.fill: parent
ListItems.Standard {
text: 'Dash search'
control: Switch {
checked: settings.remoteContentSearch == 'all'
onClicked: settings.remoteContentSearch = checked ? 'all' : 'none'
}
}
ListItems.SingleValue {
text: 'Possible values'
value: settings.schema.choices('remoteContentSearch').join(', ')
}
}
}

2
gsettings-qt.pro Normal file
View File

@ -0,0 +1,2 @@
TEMPLATE = subdirs
SUBDIRS += src/gsettings-qt.pro GSettings/gsettings-qt.pro tests/tests.pro tests/cpptest.pro

1
src/QGSettings Normal file
View File

@ -0,0 +1 @@
#include "qgsettings.h"

25
src/gsettings-qt.pro Normal file
View File

@ -0,0 +1,25 @@
TEMPLATE = lib
INCLUDEPATH += .
QT -= gui
CONFIG += qt no_keywords link_pkgconfig create_pc create_prl no_install_prl
PKGCONFIG += gio-2.0
TARGET = gsettings-qt
HEADERS = qgsettings.h util.h qconftypes.h
SOURCES = qgsettings.cpp util.cpp qconftypes.cpp
target.path = $$[QT_INSTALL_LIBS]
INSTALLS += target
headers.path = $$[QT_INSTALL_HEADERS]/QGSettings
headers.files = qgsettings.h QGSettings
INSTALLS += headers
QMAKE_PKGCONFIG_NAME = GSettingsQt
QMAKE_PKGCONFIG_DESCRIPTION = Qt bindings to GSettings
QMAKE_PKGCONFIG_PREFIX = $$INSTALLBASE
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$headers.path
QMAKE_PKGCONFIG_VERSION = $$VERSION
QMAKE_PKGCONFIG_DESTDIR = pkgconfig

256
src/qconftypes.cpp Normal file
View File

@ -0,0 +1,256 @@
/*
* Copyright © 2011 Canonical Limited
*
* This library is free software: you can redistribute it and/or modify it under the terms of version 3 of the
* GNU Lesser General Public License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#include "qconftypes.h"
#include <QStringList>
/* This file is responsible for conversion between C++ values and GVariant *.
*
* We use the QVariant type system (but not QVariant) to express the types of native C++ values. This is
* necessary because we must expose these types to Qt via the QMetaObject system.
*
* GSettings uses the GVariant type system to specify the types of the keys in a schema.
*
* We therefore have a non-injective, non-surjective partial function from GVariant types to QVariant types.
*
* The non-injectivity is mandated by the fact that the QVariant type system is less expressive than the
* GVariant type system when it comes to specifying the sizes of integers. The non-surjectivity is mandated by
* the fact that the GVariant type system has less breadth than the QVariant type system (no date, time, font,
* etc. types).
*
* Due to the non-injectivity, we can only ever go in the direction from GVariant to QVariant; all native type
* to GVariant conversions must be done in the presence of GVariant type information. For example, we are
* unsure if 'Int' is supposed to be a 32 or 16 bit integer.
*
* The function is partial: not all GVariant types are handled. This can be improved in the future, but for now
* it is probably sufficient to handle the common types that are used in 99% of cases.
*
* GVariant Type Name/Code C++ Type Name QVariant Type Name
* --------------------------------------------------------------------------
* boolean b bool QVariant::Bool
* byte y char QVariant::Char
* int16 n int QVariant::Int
* uint16 q unsigned int QVariant::UInt
* int32 i int QVariant::Int
* uint32 u unsigned int QVariant::UInt
* int64 x long long QVariant::LongLong
* uint64 t unsigned long long QVariant::ULongLong
* double d double QVariant::Double
* string s QString QVariant::String
* string array* as QStringList QVariant::StringList
* byte array ay QByteArray QVariant::ByteArray
* dictionary a{ss} QVariantMap QVariant::Map
*
* [*] not strictly an array, but called as such for sake of
* consistency with the 'a' appearing in the DBus type system
*
* We provide three functions here: the (one-way) mapping from GVariantType to QVariant::Type, plus two helpers
* for converting GVariant to and from native C++ types. The signatures of these helpers are decided by the
* fact that they always need to know the GVariant type information (as discussed above).
*
* The three functions should all be kept completely in sync with each other in terms of what types they support
* and how they elect to map those types. Not-reached assertions are used in the two value conversion functions
* in the cases that the type conversion function would have failed (ie: that could should be unreachable).
*/
QVariant::Type qconf_types_convert(const GVariantType *gtype)
{
switch (g_variant_type_peek_string(gtype)[0]) {
case G_VARIANT_CLASS_BOOLEAN:
return QVariant::Bool;
case G_VARIANT_CLASS_BYTE:
return QVariant::Char;
case G_VARIANT_CLASS_INT16:
return QVariant::Int;
case G_VARIANT_CLASS_UINT16:
return QVariant::UInt;
case G_VARIANT_CLASS_INT32:
return QVariant::Int;
case G_VARIANT_CLASS_UINT32:
return QVariant::UInt;
case G_VARIANT_CLASS_INT64:
return QVariant::LongLong;
case G_VARIANT_CLASS_UINT64:
return QVariant::ULongLong;
case G_VARIANT_CLASS_DOUBLE:
return QVariant::Double;
case G_VARIANT_CLASS_STRING:
return QVariant::String;
case G_VARIANT_CLASS_ARRAY:
if (g_variant_type_equal(gtype, G_VARIANT_TYPE_STRING_ARRAY))
return QVariant::StringList;
else if (g_variant_type_equal(gtype, G_VARIANT_TYPE_BYTESTRING))
return QVariant::ByteArray;
else if (g_variant_type_equal(gtype, G_VARIANT_TYPE ("a{ss}")))
return QVariant::Map;
// fall through
default:
return QVariant::Invalid;
}
}
QVariant qconf_types_to_qvariant(GVariant *value)
{
switch (g_variant_classify(value)) {
case G_VARIANT_CLASS_BOOLEAN:
return QVariant((bool) g_variant_get_boolean(value));
case G_VARIANT_CLASS_BYTE:
return QVariant((char) g_variant_get_byte(value));
case G_VARIANT_CLASS_INT16:
return QVariant((int) g_variant_get_int16(value));
case G_VARIANT_CLASS_UINT16:
return QVariant((unsigned int) g_variant_get_uint16(value));
case G_VARIANT_CLASS_INT32:
return QVariant((int) g_variant_get_int32(value));
case G_VARIANT_CLASS_UINT32:
return QVariant((unsigned int) g_variant_get_uint32(value));
case G_VARIANT_CLASS_INT64:
return QVariant((long long) g_variant_get_int64(value));
case G_VARIANT_CLASS_UINT64:
return QVariant((unsigned long long) g_variant_get_uint64(value));
case G_VARIANT_CLASS_DOUBLE:
return QVariant(g_variant_get_double(value));
case G_VARIANT_CLASS_STRING:
return QVariant(g_variant_get_string(value, NULL));
case G_VARIANT_CLASS_ARRAY:
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING_ARRAY)) {
GVariantIter iter;
QStringList list;
const gchar *str;
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "&s", &str))
list.append (str);
return QVariant(list);
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) {
return QVariant(QByteArray(g_variant_get_bytestring(value)));
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE("a{ss}"))) {
GVariantIter iter;
QMap<QString, QVariant> map;
const gchar *key;
const gchar *val;
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "{&s&s}", &key, &val))
map.insert(key, QVariant(val));
return map;
}
// fall through
default:
g_assert_not_reached();
}
}
GVariant *qconf_types_collect_from_variant(const GVariantType *gtype, const QVariant &v)
{
switch (g_variant_type_peek_string(gtype)[0]) {
case G_VARIANT_CLASS_BOOLEAN:
return g_variant_new_boolean(v.toBool());
case G_VARIANT_CLASS_BYTE:
return g_variant_new_byte(v.toChar().cell());
case G_VARIANT_CLASS_INT16:
return g_variant_new_int16(v.toInt());
case G_VARIANT_CLASS_UINT16:
return g_variant_new_uint16(v.toUInt());
case G_VARIANT_CLASS_INT32:
return g_variant_new_int32(v.toInt());
case G_VARIANT_CLASS_UINT32:
return g_variant_new_uint32(v.toUInt());
case G_VARIANT_CLASS_INT64:
return g_variant_new_int64(v.toLongLong());
case G_VARIANT_CLASS_UINT64:
return g_variant_new_int64(v.toULongLong());
case G_VARIANT_CLASS_DOUBLE:
return g_variant_new_double(v.toDouble());
case G_VARIANT_CLASS_STRING:
return g_variant_new_string(v.toString().toUtf8());
case G_VARIANT_CLASS_ARRAY:
if (g_variant_type_equal(gtype, G_VARIANT_TYPE_STRING_ARRAY)) {
const QStringList list = v.toStringList();
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY);
Q_FOREACH (const QString& string, list)
g_variant_builder_add(&builder, "s", string.toUtf8().constData());
return g_variant_builder_end(&builder);
} else if (g_variant_type_equal(gtype, G_VARIANT_TYPE_BYTESTRING)) {
const QByteArray array = v.toByteArray();
gsize size = array.size();
gpointer data;
data = g_memdup(array.data(), size);
return g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
data, size, TRUE, g_free, data);
} else if (g_variant_type_equal(gtype, G_VARIANT_TYPE("a{ss}"))) {
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE ("a{ss}"));
QMapIterator<QString, QVariant> it(v.toMap());
while (it.hasNext()) {
it.next();
QByteArray key = it.key().toUtf8();
QByteArray val = it.value().toByteArray();
g_variant_builder_add (&builder, "{ss}", key.constData(), val.constData());
}
return g_variant_builder_end (&builder);
}
// fall through
default:
return NULL;
}
}
// vim:sw=4 tw=112

29
src/qconftypes.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright © 2011 Canonical Limited
*
* This library is free software: you can redistribute it and/or modify it under the terms of version 3 of the
* GNU Lesser General Public License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#ifndef _qconftypes_h_
#define _qconftypes_h_
#include <QVariant>
#include <glib.h>
QVariant::Type qconf_types_convert(const GVariantType *gtype);
GVariant * qconf_types_collect(const GVariantType *gtype, const void *argument);
GVariant *qconf_types_collect_from_variant(const GVariantType *gtype, const QVariant &v);
void qconf_types_unpack(GVariant *value, void *argument);
QVariant qconf_types_to_qvariant(GVariant *value);
#endif /* _qconftypes_h_ */

166
src/qgsettings.cpp Normal file
View File

@ -0,0 +1,166 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#include "qgsettings.h"
#include "qconftypes.h"
#include "util.h"
#include <gio/gio.h>
struct QGSettingsPrivate
{
QByteArray schema_id;
QByteArray path;
GSettings *settings;
GSettingsSchema *schema;
gulong signal_handler_id;
static void settingChanged(GSettings *settings, const gchar *key, gpointer user_data);
};
void QGSettingsPrivate::settingChanged(GSettings *, const gchar *key, gpointer user_data)
{
QGSettings *self = (QGSettings *)user_data;
// work around https://bugreports.qt.io/browse/QTBUG-32859 and http://pad.lv/1460970
QMetaObject::invokeMethod(self, "changed", Qt::QueuedConnection, Q_ARG(QString, qtify_name(key)));
}
QGSettings::QGSettings(const QByteArray &schema_id, const QByteArray &path, QObject *parent):
QObject(parent)
{
priv = new QGSettingsPrivate;
priv->schema_id = schema_id;
priv->path = path;
if (priv->path.isEmpty())
priv->settings = g_settings_new(priv->schema_id.constData());
else
priv->settings = g_settings_new_with_path(priv->schema_id.constData(), priv->path.constData());
g_object_get (priv->settings, "settings-schema", &priv->schema, NULL);
priv->signal_handler_id = g_signal_connect(priv->settings, "changed", G_CALLBACK(QGSettingsPrivate::settingChanged), this);
}
QGSettings::~QGSettings()
{
if (priv->schema) {
g_settings_sync ();
g_signal_handler_disconnect(priv->settings, priv->signal_handler_id);
g_object_unref (priv->settings);
g_settings_schema_unref (priv->schema);
}
delete priv;
}
QVariant QGSettings::get(const QString &key) const
{
gchar *gkey = unqtify_name(key);
GVariant *value = g_settings_get_value(priv->settings, gkey);
QVariant qvalue = qconf_types_to_qvariant(value);
g_variant_unref(value);
g_free(gkey);
return qvalue;
}
void QGSettings::set(const QString &key, const QVariant &value)
{
if (!this->trySet(key, value))
qWarning("unable to set key '%s' to value '%s'", key.toUtf8().constData(), value.toString().toUtf8().constData());
}
bool QGSettings::trySet(const QString &key, const QVariant &value)
{
gchar *gkey = unqtify_name(key);
bool success = false;
/* fetch current value to find out the exact type */
GVariant *cur = g_settings_get_value(priv->settings, gkey);
GVariant *new_value = qconf_types_collect_from_variant(g_variant_get_type (cur), value);
if (new_value)
success = g_settings_set_value(priv->settings, gkey, new_value);
g_free(gkey);
g_variant_unref (cur);
return success;
}
QStringList QGSettings::keys() const
{
QStringList list;
gchar **keys = g_settings_list_keys(priv->settings);
for (int i = 0; keys[i]; i++)
list.append(qtify_name(keys[i]));
g_strfreev(keys);
return list;
}
QVariantList QGSettings::choices(const QString &qkey) const
{
gchar *key = unqtify_name (qkey);
GSettingsSchemaKey *schema_key = g_settings_schema_get_key (priv->schema, key);
GVariant *range = g_settings_schema_key_get_range(schema_key);
g_settings_schema_key_unref (schema_key);
g_free(key);
if (range == NULL)
return QVariantList();
const gchar *type;
GVariant *value;
g_variant_get(range, "(&sv)", &type, &value);
QVariantList choices;
if (g_str_equal(type, "enum")) {
GVariantIter iter;
GVariant *child;
g_variant_iter_init (&iter, value);
while ((child = g_variant_iter_next_value(&iter))) {
choices.append(qconf_types_to_qvariant(child));
g_variant_unref(child);
}
}
g_variant_unref (value);
g_variant_unref (range);
return choices;
}
void QGSettings::reset(const QString &qkey)
{
gchar *key = unqtify_name(qkey);
g_settings_reset(priv->settings, key);
g_free(key);
}
bool QGSettings::isSchemaInstalled(const QByteArray &schema_id)
{
GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
GSettingsSchema *schema = g_settings_schema_source_lookup (source, schema_id.constData(), TRUE);
if (schema) {
g_settings_schema_unref (schema);
return true;
} else {
return false;
}
}

115
src/qgsettings.h Normal file
View File

@ -0,0 +1,115 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#ifndef __QGSETTINGS_H__
#define __QGSETTINGS_H__
#include <QObject>
#include <QStringList>
/**
* @brief QGSettings provides access to application settings stored with GSettings.
*
* GSettings does not allow keys to contain anything other than lower-case
* characters and dashes. This class converts all keys to camelCase, to make it easier
* for people used to Qt's naming convention.
*/
class QGSettings: public QObject
{
Q_OBJECT
public:
/**
* @brief Create a QGSettings object for a given schema_id and path.
* @param schema_id The id of the schema
* @param path If non-empty, specifies the path for a relocatable schema
*/
QGSettings(const QByteArray &schema_id, const QByteArray &path = QByteArray(), QObject *parent = NULL);
~QGSettings();
/**
* @brief Gets the value that is stored at key
* @param key The key for which to retrieve the value (in camelCase)
*
* It is an error if key does not exist in the schema associated with this
* QGSettings object.
*/
QVariant get(const QString &key) const;
/**
* @brief Sets the value at key to value
* @key The key for which to set the value (in camelCase)
* @value The value to set
*
* It is an error if key does not exist in the schema associated with this
* QGSettings object.
*
* Not all values that a QVariant can hold can be serialized into a
* setting. Basic types (integers, doubles, strings) and string lists are
* supported.
*/
void set(const QString &key, const QVariant &value);
/**
* @brief Sets the value at key to value
* @key The key for which to set the value
* @value The value to set
*
* Behaves just like ::set(key, value), but returns false instead of
* printing a warning if the key couldn't be set.
*
* @return whether the key was set
*/
bool trySet(const QString &key, const QVariant &value);
/**
* \brief Retrieves the list of avaliable keys
*/
QStringList keys() const;
/**
* \brief Returns the list of values that key can assume
*
* Returns an empty list if the schema doesn't contain that information for
* the key.
*/
QVariantList choices(const QString &key) const;
/**
* @brief Resets the setting for @key to its default value.
*/
void reset(const QString &key);
/**
* @brief Checks if a schema with the given id is installed.
*/
static bool isSchemaInstalled(const QByteArray &schema_id);
Q_SIGNALS:
/**
* \brief Emitted when the value associated with key has changed
*/
void changed(const QString &key);
private:
struct QGSettingsPrivate *priv;
friend struct QGSettingsPrivate;
};
#endif

75
src/util.cpp Normal file
View File

@ -0,0 +1,75 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
* Ryan Lortie <desrt@desrt.ca>
*/
#include <glib.h>
#include <QString>
/* convert 'some-key' to 'someKey' or 'SomeKey'.
* the second form is needed for appending to 'set' for 'setSomeKey'
*/
QString qtify_name(const char *name)
{
bool next_cap = false;
QString result;
while (*name) {
if (*name == '-') {
next_cap = true;
} else if (next_cap) {
result.append(QChar(*name).toUpper().toLatin1());
next_cap = false;
} else {
result.append(*name);
}
name++;
}
return result;
}
/* Convert 'someKey' to 'some-key'
*
* This is the inverse function of qtify_name, iff qtify_name was called with a
* valid gsettings key name (no capital letters, no consecutive dashes).
*
* Returns a newly-allocated string.
*/
gchar * unqtify_name(const QString &name)
{
const gchar *p;
QByteArray bytes;
GString *str;
bytes = name.toUtf8();
str = g_string_new (NULL);
for (p = bytes.constData(); *p; p++) {
const QChar c(*p);
if (c.isUpper()) {
g_string_append_c (str, '-');
g_string_append_c (str, c.toLower().toLatin1());
}
else {
g_string_append_c (str, *p);
}
}
return g_string_free(str, FALSE);
}

27
src/util.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Lars Uebernickel <lars.uebernickel@canonical.com>
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include <QString>
QString qtify_name(const char *name);
gchar * unqtify_name(const QString &name);
#endif

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="com.ubports.gsettings.Test" path="/com/ubports/gsettings/test/">
<key name="test-integer" type="i">
<default>42</default>
</key>
<key name="test-double" type="d">
<default>1.5</default>
</key>
<key name="test-boolean" type="b">
<default>false</default>
</key>
<key name="test-string" type="s">
<default>"hello"</default>
</key>
<key name="test-enum" type="s">
<choices>
<choice value='one'/>
<choice value='two'/>
<choice value='three'/>
</choices>
<default>'one'</default>
</key>
<key name="test-string-list" type="as">
<default>['one', 'two', 'three']</default>
</key>
<key name="test-map" type="a{ss}">
<default>{'foo': 'one', 'bar': 'two'}</default>
</key>
</schema>
</schemalist>

35
tests/cpptest.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <QtTest/QtTest>
#include <QGSettings>
class TestDeferredDelete: public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void test_deferredDelete();
private:
QGSettings * settings;
QPointer<QObject> dummy;
};
void TestDeferredDelete::initTestCase()
{
settings = new QGSettings("com.ubports.gsettings.Test", QByteArray(), this);
dummy = new QObject;
connect(settings, &QGSettings::changed, dummy.data(), &QObject::deleteLater); // delete the dummy object upon any gsettings change
}
void TestDeferredDelete::test_deferredDelete()
{
QSignalSpy spy(dummy.data(), &QObject::destroyed); // watch the dummy object get destroyed
settings->set("testString", "bar");
QVERIFY(spy.wait(1));
QVERIFY(dummy.isNull()); // verify dummy got destroyed for real
QCOMPARE(settings->get("testString").toString(), QStringLiteral("bar")); // also verify the setting got written by reading it back
}
QTEST_MAIN(TestDeferredDelete)
#include "cpptest.moc"

16
tests/cpptest.pro Normal file
View File

@ -0,0 +1,16 @@
TEMPLATE = app
QT += testlib
QT -= gui
CONFIG += testcase link_pkgconfig
TARGET = cpptest
IMPORTPATH = $$PWD/..
SOURCES = cpptest.cpp
INCLUDEPATH += $$(PWD)/../src
LIBS += -L$$(PWD)/../src -lgsettings-qt
schema.target = gschemas.compiled
schema.commands = glib-compile-schemas $$PWD
schema.depends = com.ubports.gsettings.test.gschema.xml
QMAKE_EXTRA_TARGETS += schema
PRE_TARGETDEPS = gschemas.compiled

15
tests/manual Normal file
View File

@ -0,0 +1,15 @@
Test-case gsettings-qt/unity8-check-setting
<dl>
<dt>Open system settings with the security panel </dt>
<dd>Ensure "Dash search" is set to "Phone and Internet"</dd>
<dt>Change "Dash search" to "Phone only"</dt>
<dd>Ensure that the music and video lenses don't show online content</dd>
</dl>
Test-case gsettings-qt/run-example
<dl>
<dt>Download the <a href="http://bazaar.launchpad.net/~system-settings-touch/gsettings-qt/trunk/view/head:/examples/choices.qml">choices example</a> and run it with qmlscene</dt>
<dd>Ensure that the switch is synchronized with the "Dash Search" setting in the security panel of system settings</dd>
<dd>Ensure that the "Possible values" list item has a value of "all, none"</dd>
</dl>

3
tests/test.cpp Normal file
View File

@ -0,0 +1,3 @@
#include <QtQuickTest/quicktest.h>
QUICK_TEST_MAIN(GSettings)

15
tests/tests.pro Normal file
View File

@ -0,0 +1,15 @@
TEMPLATE = app
QT += qml testlib
QT -= gui
CONFIG += qmltestcase
TARGET = test
IMPORTPATH = $$PWD/..
SOURCES = test.cpp
schema.target = gschemas.compiled
schema.commands = glib-compile-schemas $$PWD
schema.depends = com.ubports.gsettings.test.gschema.xml
QMAKE_EXTRA_TARGETS += schema
PRE_TARGETDEPS = gschemas.compiled
OTHER_FILES += tst_GSettings.qml

109
tests/tst_GSettings.qml Normal file
View File

@ -0,0 +1,109 @@
import QtTest 1.0
import "../GSettings" 1.0
import QtQuick 2.0
TestCase {
id: testCase
property var changes: []
GSettings {
id: settings
schema.id: "com.ubports.gsettings.Test"
// has to be "valueChanged" signal, not "changed"; the latter doesn't work reliably with the in-memory gsettings backend
onValueChanged: changes.push([key, value]);
}
SignalSpy {
id: changesSpy
target: settings
signalName: "changed"
}
GSettings {
id: invalid_settings
schema.id: "com.ubports.gsettings.NonExisting"
}
property string bindingTest: settings.testString
// this test must run first (others overwrite keys), hence the 'aaa'
function test_aaa_read_defaults() {
compare(settings.schema.isValid, true);
compare(settings.testInteger, 42);
compare(settings.testDouble, 1.5);
compare(settings.testBoolean, false);
compare(settings.testString, 'hello');
compare(settings.testStringList, ['one', 'two', 'three']);
compare(settings.testMap, {'foo': 'one', 'bar': 'two'});
compare(testCase.bindingTest, 'hello');
}
function test_write() {
settings.testInteger = 2;
compare(settings.testInteger, 2);
settings.testDouble = 2.5;
compare(settings.testDouble, 2.5);
settings.testBoolean = true;
compare(settings.testBoolean, true);
settings.testString = 'bye';
compare(settings.testString, 'bye');
compare(testCase.bindingTest, 'bye');
settings.testStringList = ['four', 'five']
compare(settings.testStringList, ['four', 'five']);
settings.testStringList = ['six']
compare(settings.testStringList, ['six']);
settings.testStringList = [];
compare(settings.testStringList, []);
settings.testMap = {'baz': 'three'}
compare(settings.testMap, {'baz': 'three'});
settings.testMap = {};
compare(settings.testMap, {});
settings.testEnum = 'two';
compare(settings.testEnum, 'two');
// test whether writing an out-of-range key doesn't work
settings.testEnum = 'notanumber';
compare(settings.testEnum, 'two');
}
function test_changed() {
changes = []
settings.testInteger = 4;
settings.testDouble = 3.14
settings.testString = 'goodbye';
compare(changes, [['testInteger', 4], ['testDouble', 3.14], ['testString', 'goodbye']]);
}
function test_choices() {
compare(settings.schema.choices('testEnum'), ['one', 'two', 'three']);
compare(settings.schema.choices('testInteger'), []);
}
function test_non_existing() {
compare(settings.schema.aKeyThatsNotInTheSchema, undefined);
compare(settings.schema.choices('aKeyThatsNotInTheSchema'), []);
}
function test_reset() {
settings.testInteger = 4;
changesSpy.clear();
settings.schema.reset('testInteger');
compare(settings.testInteger, 42);
tryCompare(changesSpy, "count", 1);
}
function test_invalid_schema() {
compare(invalid_settings.schema.isValid, false);
compare(invalid_settings.schema.testInteger, undefined);
}
}