Merge lp:~chipaca/ubuntu-push/gsettings into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Rejected
Rejected by: John Lenton
Proposed branch: lp:~chipaca/ubuntu-push/gsettings
Merge into: lp:ubuntu-push/automatic
Diff against target: 174 lines (+141/-1)
4 files modified
click/cblacklist/cblacklist.go (+1/-1)
debian/control (+1/-0)
gsettings/gsettings.go (+86/-0)
gsettings/gsettings_test.go (+53/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/gsettings
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+234874@code.launchpad.net

Commit message

Minimal wrapper for some gsettings bits.

Description of the change

Minimal wrapper for some gsettings bits.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

nice

review: Approve

Unmerged revisions

335. By John Lenton

gsettings

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/cblacklist/cblacklist.go'
2--- click/cblacklist/cblacklist.go 2014-08-01 23:25:43 +0000
3+++ click/cblacklist/cblacklist.go 2014-09-16 19:41:21 +0000
4@@ -37,7 +37,7 @@
5
6 if (!pushSettings) {
7 GSettingsSchemaSource * source = g_settings_schema_source_get_default ();
8- if (!g_settings_schema_source_lookup (g_settings_schema_source_get_default (), BLACKLIST_CONFIG_SCHEMA_ID, TRUE)) {
9+ if (!g_settings_schema_source_lookup (source, BLACKLIST_CONFIG_SCHEMA_ID, TRUE)) {
10 return -1;
11 }
12 pushSettings = g_settings_new(BLACKLIST_CONFIG_SCHEMA_ID);
13
14=== modified file 'debian/control'
15--- debian/control 2014-09-05 10:48:36 +0000
16+++ debian/control 2014-09-16 19:41:21 +0000
17@@ -24,6 +24,7 @@
18 libaccounts-glib-dev,
19 cmake,
20 python3,
21+ gsettings-ubuntu-schemas,
22 Standards-Version: 3.9.5
23 Homepage: http://launchpad.net/ubuntu-push
24 Vcs-Bzr: lp:ubuntu-push
25
26=== added directory 'gsettings'
27=== added file 'gsettings/gsettings.go'
28--- gsettings/gsettings.go 1970-01-01 00:00:00 +0000
29+++ gsettings/gsettings.go 2014-09-16 19:41:21 +0000
30@@ -0,0 +1,86 @@
31+/*
32+ Copyright 2014 Canonical Ltd.
33+
34+ This program is free software: you can redistribute it and/or modify it
35+ under the terms of the GNU General Public License version 3, as published
36+ by the Free Software Foundation.
37+
38+ This program is distributed in the hope that it will be useful, but
39+ WITHOUT ANY WARRANTY; without even the implied warranties of
40+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
41+ PURPOSE. See the GNU General Public License for more details.
42+
43+ You should have received a copy of the GNU General Public License along
44+ with this program. If not, see <http://www.gnu.org/licenses/>.
45+*/
46+
47+// package gsettings is a very incomplete wrapper to gio's gsettings,
48+// only exposing the bits used in the project.
49+package gsettings
50+
51+/*
52+#cgo pkg-config: gio-2.0
53+
54+#include <gio/gio.h>
55+
56+*/
57+import "C"
58+
59+import (
60+ "errors"
61+ "runtime"
62+)
63+
64+type GSettings struct {
65+ inner *C.GSettings
66+ schema *C.GSettingsSchema
67+}
68+
69+var (
70+ ErrSchemaNotFound = errors.New("Schema not found")
71+ ErrKeyNotFound = errors.New("Key not found")
72+)
73+
74+func gstring(s string) *C.gchar {
75+ return (*C.gchar)(C.CString(s))
76+}
77+
78+func gostring(s *C.gchar) string {
79+ return C.GoString((*C.char)(s))
80+}
81+
82+func gfree(s *C.gchar) {
83+ C.g_free(C.gpointer(s))
84+}
85+
86+func New(schema string) (*GSettings, error) {
87+ src := C.g_settings_schema_source_get_default()
88+ cs := gstring(schema)
89+ defer gfree(cs)
90+ cschema := C.g_settings_schema_source_lookup(src, cs, C.TRUE)
91+ if cschema == nil {
92+ return nil, ErrSchemaNotFound
93+ }
94+ settings := &GSettings{inner: C.g_settings_new(cs), schema: cschema}
95+
96+ runtime.SetFinalizer(settings, func(s *GSettings) {
97+ C.g_settings_schema_unref(s.schema)
98+ C.g_object_unref(C.gpointer(s.inner))
99+ })
100+
101+ return settings, nil
102+}
103+
104+func (settings *GSettings) GetString(key string) (string, error) {
105+ ckey := gstring(key)
106+ defer gfree(ckey)
107+
108+ if C.g_settings_schema_has_key(settings.schema, ckey) != C.TRUE {
109+ return "", ErrKeyNotFound
110+ }
111+
112+ cstr := C.g_settings_get_string(settings.inner, ckey)
113+ defer gfree(cstr)
114+ str := gostring(cstr)
115+ return str, nil
116+}
117
118=== added file 'gsettings/gsettings_test.go'
119--- gsettings/gsettings_test.go 1970-01-01 00:00:00 +0000
120+++ gsettings/gsettings_test.go 2014-09-16 19:41:21 +0000
121@@ -0,0 +1,53 @@
122+/*
123+ Copyright 2014 Canonical Ltd.
124+
125+ This program is free software: you can redistribute it and/or modify it
126+ under the terms of the GNU General Public License version 3, as published
127+ by the Free Software Foundation.
128+
129+ This program is distributed in the hope that it will be useful, but
130+ WITHOUT ANY WARRANTY; without even the implied warranties of
131+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
132+ PURPOSE. See the GNU General Public License for more details.
133+
134+ You should have received a copy of the GNU General Public License along
135+ with this program. If not, see <http://www.gnu.org/licenses/>.
136+*/
137+
138+package gsettings
139+
140+import (
141+ "testing"
142+
143+ . "launchpad.net/gocheck"
144+)
145+
146+func TestGSettings(t *testing.T) { TestingT(t) }
147+
148+type gssuite struct{}
149+
150+var _ = Suite(&gssuite{})
151+
152+func (gs *gssuite) TestBadSchema(c *C) {
153+ s, e := New("potato")
154+ c.Check(e, Equals, ErrSchemaNotFound)
155+ c.Check(s, IsNil)
156+}
157+
158+func (gs *gssuite) TestBadKey(c *C) {
159+ s, e := New("com.ubuntu.touch.sound")
160+ c.Assert(e, IsNil)
161+ c.Assert(s, NotNil)
162+ k, e := s.GetString("potato")
163+ c.Check(e, Equals, ErrKeyNotFound)
164+ c.Check(k, Equals, "")
165+}
166+
167+func (gs *gssuite) TestGoodKey(c *C) {
168+ s, e := New("com.ubuntu.touch.sound")
169+ c.Assert(e, IsNil)
170+ c.Assert(s, NotNil)
171+ k, e := s.GetString("incoming-message-sound")
172+ c.Check(e, IsNil)
173+ c.Check(k, Matches, ".*/sounds/.*")
174+}

Subscribers

People subscribed via source and target branches