Merge lp:~indicator-applet-developers/libindicator/ubuntu into lp:~ubuntu-desktop/libindicator/ubuntu
- ubuntu
- Merge into ubuntu
Proposed by
Ted Gould
Status: | Merged | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merge reported by: | Ken VanDine | ||||||||||||||||||||||||||||
Merged at revision: | not available | ||||||||||||||||||||||||||||
Proposed branch: | lp:~indicator-applet-developers/libindicator/ubuntu | ||||||||||||||||||||||||||||
Merge into: | lp:~ubuntu-desktop/libindicator/ubuntu | ||||||||||||||||||||||||||||
Diff against target: |
3570 lines (+3246/-29) 41 files modified
.bzrignore (+40/-0) Makefile.am (+3/-1) autogen.sh (+1/-1) configure.ac (+17/-2) debian/changelog (+21/-0) debian/control (+26/-2) debian/libindicator-dev.install (+4/-0) debian/libindicator-tools.install (+1/-0) debian/libindicator0.install (+1/-0) libindicator/Makefile.am (+53/-2) libindicator/dbus-shared.h (+28/-0) libindicator/indicator-object.c (+344/-0) libindicator/indicator-object.h (+123/-0) libindicator/indicator-service-manager.c (+493/-0) libindicator/indicator-service-manager.h (+88/-0) libindicator/indicator-service.c (+479/-0) libindicator/indicator-service.h (+85/-0) libindicator/indicator-service.xml (+21/-0) libindicator/indicator.h (+4/-18) libindicator/indicator.pc.in (+3/-3) tests/Makefile.am (+308/-0) tests/dummy-indicator-blank.c (+5/-0) tests/dummy-indicator-null.c (+95/-0) tests/dummy-indicator-signaler.c (+109/-0) tests/dummy-indicator-simple.c (+98/-0) tests/service-manager-connect-service.c (+48/-0) tests/service-manager-connect.c (+63/-0) tests/service-manager-connect.service.in (+3/-0) tests/service-manager-no-connect.c (+47/-0) tests/service-manager-nostart-connect.c (+65/-0) tests/service-shutdown-timeout.c (+46/-0) tests/service-version-bad-service.c (+47/-0) tests/service-version-bad.service.in (+3/-0) tests/service-version-good-service.c (+47/-0) tests/service-version-good.service.in (+3/-0) tests/service-version-manager.c (+64/-0) tests/service-version-values.h (+4/-0) tests/session.conf.in (+40/-0) tests/test-loader.c (+146/-0) tools/Makefile.am (+21/-0) tools/indicator-loader.c (+149/-0) |
||||||||||||||||||||||||||||
To merge this branch: | bzr merge lp:~indicator-applet-developers/libindicator/ubuntu | ||||||||||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ken VanDine | Pending | ||
Review via email: mp+15966@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2009-08-07 15:06:32 +0000 | |||
3 | +++ .bzrignore 2009-12-10 17:02:12 +0000 | |||
4 | @@ -103,3 +103,43 @@ | |||
5 | 103 | data/GNOME_IndicatorAppletSUS.server | 103 | data/GNOME_IndicatorAppletSUS.server |
6 | 104 | data/GNOME_IndicatorAppletSUS.server.in | 104 | data/GNOME_IndicatorAppletSUS.server.in |
7 | 105 | src-sus/indicator-applet-no-sus | 105 | src-sus/indicator-applet-no-sus |
8 | 106 | libindicator/libindicator.la | ||
9 | 107 | libindicator/libindicator_la-indicator-object. | ||
10 | 108 | libindicator/libindicator_la-indicator-object.lo | ||
11 | 109 | tests/loader-check-results.xml | ||
12 | 110 | tests/loader-check-results.html | ||
13 | 111 | tests/test-loader | ||
14 | 112 | tests/libdummy-indicator-null.la | ||
15 | 113 | tests/libdummy_indicator_null_la-dummy-indicator-null.lo | ||
16 | 114 | tests/libdummy-indicator-simple.la | ||
17 | 115 | tests/libdummy_indicator_simple_la-dummy-indicator-simple.lo | ||
18 | 116 | tests/libdummy-indicator-blank.la | ||
19 | 117 | tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo | ||
20 | 118 | libindicator-[0-9].[0-9].[0-9].tar.gz | ||
21 | 119 | libindicator-[0-9].[0-9].[0-9].tar.gz.asc | ||
22 | 120 | libindicator/libindicator_la-indicator-instance.lo | ||
23 | 121 | tests/libdummy-indicator-signaler.la | ||
24 | 122 | tests/libdummy_indicator_signaler_la-dummy-indicator-signaler.lo | ||
25 | 123 | libindicator/indicator-service-client.h | ||
26 | 124 | libindicator/indicator-service-server.h | ||
27 | 125 | libindicator/libindicator_la-indicator-service.lo | ||
28 | 126 | libindicator/libindicator_la-indicator-service-manager.lo | ||
29 | 127 | tests/service-shutdown-timeout | ||
30 | 128 | tests/loader-tester | ||
31 | 129 | tests/service-shutdown-timeout-tester | ||
32 | 130 | tests/service-manager-no-connect | ||
33 | 131 | tests/service-manager-no-connect-tester | ||
34 | 132 | tests/service-manager-connect | ||
35 | 133 | tests/service-manager-connect-service | ||
36 | 134 | tests/service-manager-connect-tester | ||
37 | 135 | tests/session.conf | ||
38 | 136 | tests/service-manager-connect.service | ||
39 | 137 | tools/indicator-loader | ||
40 | 138 | tests/service-version-bad-service | ||
41 | 139 | tests/service-version-bad.service | ||
42 | 140 | tests/service-version-good-service | ||
43 | 141 | tests/service-version-good.service | ||
44 | 142 | tests/service-version-manager | ||
45 | 143 | tests/service-version-tester | ||
46 | 144 | tests/service-manager-connect-nostart-tester | ||
47 | 145 | tests/service-manager-nostart-connect | ||
48 | 106 | 146 | ||
49 | === modified file 'Makefile.am' | |||
50 | --- Makefile.am 2009-08-18 16:52:09 +0000 | |||
51 | +++ Makefile.am 2009-12-10 17:02:12 +0000 | |||
52 | @@ -1,6 +1,8 @@ | |||
53 | 1 | 1 | ||
54 | 2 | SUBDIRS = \ | 2 | SUBDIRS = \ |
56 | 3 | libindicator | 3 | libindicator \ |
57 | 4 | tests \ | ||
58 | 5 | tools | ||
59 | 4 | 6 | ||
60 | 5 | DISTCLEANFILES = \ | 7 | DISTCLEANFILES = \ |
61 | 6 | libindicator-*.tar.gz | 8 | libindicator-*.tar.gz |
62 | 7 | 9 | ||
63 | === modified file 'autogen.sh' | |||
64 | --- autogen.sh 2009-08-18 16:52:09 +0000 | |||
65 | +++ autogen.sh 2009-12-10 17:02:12 +0000 | |||
66 | @@ -8,4 +8,4 @@ | |||
67 | 8 | } | 8 | } |
68 | 9 | 9 | ||
69 | 10 | USE_GNOME2_MACROS=1 \ | 10 | USE_GNOME2_MACROS=1 \ |
71 | 11 | gnome-autogen.sh | 11 | . gnome-autogen.sh |
72 | 12 | 12 | ||
73 | === modified file 'configure.ac' | |||
74 | --- configure.ac 2009-10-08 14:16:40 +0000 | |||
75 | +++ configure.ac 2009-12-10 17:02:12 +0000 | |||
76 | @@ -1,10 +1,10 @@ | |||
77 | 1 | 1 | ||
79 | 2 | AC_INIT(libindicator, 0.2.1, ted@canonical.com) | 2 | AC_INIT(libindicator, 0.3.0, ted@canonical.com) |
80 | 3 | 3 | ||
81 | 4 | AC_PREREQ(2.53) | 4 | AC_PREREQ(2.53) |
82 | 5 | 5 | ||
83 | 6 | AM_CONFIG_HEADER(config.h) | 6 | AM_CONFIG_HEADER(config.h) |
85 | 7 | AM_INIT_AUTOMAKE(libindicator, 0.2.1) | 7 | AM_INIT_AUTOMAKE(libindicator, 0.3.0) |
86 | 8 | 8 | ||
87 | 9 | AM_MAINTAINER_MODE | 9 | AM_MAINTAINER_MODE |
88 | 10 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES]) | 10 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES]) |
89 | @@ -21,6 +21,19 @@ | |||
90 | 21 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) | 21 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) |
91 | 22 | 22 | ||
92 | 23 | ############################## | 23 | ############################## |
93 | 24 | # Dependencies | ||
94 | 25 | ############################## | ||
95 | 26 | |||
96 | 27 | GTK_REQUIRED_VERSION=2.18 | ||
97 | 28 | DBUS_REQUIRED_VERSION=0.76 | ||
98 | 29 | |||
99 | 30 | PKG_CHECK_MODULES(LIBINDICATOR, gtk+-2.0 >= $GTK_REQUIRED_VERSION | ||
100 | 31 | dbus-glib-1 >= $DBUS_REQUIRED_VERSION) | ||
101 | 32 | |||
102 | 33 | AC_SUBST(LIBINDICATOR_CFLAGS) | ||
103 | 34 | AC_SUBST(LIBINDICATOR_LIBS) | ||
104 | 35 | |||
105 | 36 | ############################## | ||
106 | 24 | # Custom Junk | 37 | # Custom Junk |
107 | 25 | ############################## | 38 | ############################## |
108 | 26 | 39 | ||
109 | @@ -73,6 +86,8 @@ | |||
110 | 73 | Makefile | 86 | Makefile |
111 | 74 | libindicator/Makefile | 87 | libindicator/Makefile |
112 | 75 | libindicator/indicator.pc | 88 | libindicator/indicator.pc |
113 | 89 | tests/Makefile | ||
114 | 90 | tools/Makefile | ||
115 | 76 | ]) | 91 | ]) |
116 | 77 | 92 | ||
117 | 78 | ########################### | 93 | ########################### |
118 | 79 | 94 | ||
119 | === modified file 'debian/changelog' | |||
120 | --- debian/changelog 2009-10-09 06:12:31 +0000 | |||
121 | +++ debian/changelog 2009-12-10 17:02:12 +0000 | |||
122 | @@ -1,3 +1,24 @@ | |||
123 | 1 | libindicator (0.3.0-0ubuntu1~ppa1) karmic; urgency=low | ||
124 | 2 | |||
125 | 3 | * Upstream 0.3.0 Release | ||
126 | 4 | * Adds a new tool to load indicators from the command line. | ||
127 | 5 | * Adds an object for loading indicators. | ||
128 | 6 | * Changes the indicator interface to be object based. | ||
129 | 7 | * debian/control, debian/libindicator0: Adding in a new packages | ||
130 | 8 | for the binary library. | ||
131 | 9 | * debian/control, debian/libindicator-tools: Adding in a new | ||
132 | 10 | package for the tools of libindicator. | ||
133 | 11 | |||
134 | 12 | -- Ted Gould <ted@ubuntu.com> Thu, 10 Dec 2009 10:59:37 -0600 | ||
135 | 13 | |||
136 | 14 | libindicator (0.2.1-0ubuntu2~ppa1) karmic; urgency=low | ||
137 | 15 | |||
138 | 16 | * Adding in service management code. | ||
139 | 17 | * debian/control: Adding a target for libindicator0 | ||
140 | 18 | * Adding libindicator0.install and libindicator-dev.install | ||
141 | 19 | |||
142 | 20 | -- Ted Gould <ted@ubuntu.com> Wed, 04 Nov 2009 08:19:01 -0600 | ||
143 | 21 | |||
144 | 1 | libindicator (0.2.1-0ubuntu1) karmic; urgency=low | 22 | libindicator (0.2.1-0ubuntu1) karmic; urgency=low |
145 | 2 | 23 | ||
146 | 3 | * Upstream release 0.2.1 (LP: #446619) | 24 | * Upstream release 0.2.1 (LP: #446619) |
147 | 4 | 25 | ||
148 | === modified file 'debian/control' | |||
149 | --- debian/control 2009-08-25 06:33:06 +0000 | |||
150 | +++ debian/control 2009-12-10 17:02:12 +0000 | |||
151 | @@ -4,21 +4,45 @@ | |||
152 | 4 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 4 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
153 | 5 | Build-Depends: debhelper (>= 5.0), | 5 | Build-Depends: debhelper (>= 5.0), |
154 | 6 | cdbs (>= 0.4.41), | 6 | cdbs (>= 0.4.41), |
156 | 7 | libtool | 7 | libgtk2.0-dev (>= 2.12.0), |
157 | 8 | libdbus-glib-1-dev, | ||
158 | 9 | libtool, | ||
159 | 10 | intltool, | ||
160 | 11 | gtk-doc-tools | ||
161 | 8 | Standards-Version: 3.8.0 | 12 | Standards-Version: 3.8.0 |
162 | 9 | Homepage: https://launchpad.net/libindicator | 13 | Homepage: https://launchpad.net/libindicator |
163 | 10 | Vcs-Bzr: https://code.launchpad.net/~ubuntu-desktop/libindicator/ubuntu | 14 | Vcs-Bzr: https://code.launchpad.net/~ubuntu-desktop/libindicator/ubuntu |
164 | 11 | Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-desktop/libindicator/ubuntu | 15 | Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-desktop/libindicator/ubuntu |
165 | 12 | 16 | ||
166 | 17 | Package: libindicator0 | ||
167 | 18 | Section: libs | ||
168 | 19 | Architecture: any | ||
169 | 20 | Depends: ${shlibs:Depends}, | ||
170 | 21 | ${misc:Depends} | ||
171 | 22 | Description: GNOME panel indicator applet - shared library | ||
172 | 23 | This library contains information to build indicators to go into | ||
173 | 24 | the indicator applet. | ||
174 | 25 | . | ||
175 | 26 | This package contains files that are needed to build applications. | ||
176 | 27 | |||
177 | 13 | Package: libindicator-dev | 28 | Package: libindicator-dev |
178 | 14 | Section: libdevel | 29 | Section: libdevel |
179 | 15 | Architecture: any | 30 | Architecture: any |
180 | 16 | Depends: ${shlibs:Depends}, | 31 | Depends: ${shlibs:Depends}, |
181 | 17 | ${misc:Depends}, | 32 | ${misc:Depends}, |
183 | 18 | libgtk2.0-dev (>= 2.12.0) | 33 | libgtk2.0-dev (>= 2.12.0), |
184 | 34 | libindicator0 (= ${binary:Version}) | ||
185 | 19 | Description: GNOME panel indicator applet - shared library | 35 | Description: GNOME panel indicator applet - shared library |
186 | 20 | This library contains information to build indicators to go into | 36 | This library contains information to build indicators to go into |
187 | 21 | the indicator applet. | 37 | the indicator applet. |
188 | 22 | . | 38 | . |
189 | 23 | This package contains files that are needed to build applications. | 39 | This package contains files that are needed to build applications. |
190 | 24 | 40 | ||
191 | 41 | Package: libindicator-tools | ||
192 | 42 | Section: devel | ||
193 | 43 | Architecture: any | ||
194 | 44 | Depends: ${shlibs:Depends}, | ||
195 | 45 | ${misc:Depends}, | ||
196 | 46 | libindicator0 (= ${binary:Version}) | ||
197 | 47 | Description: Need a better description | ||
198 | 48 | |||
199 | 25 | 49 | ||
200 | === added file 'debian/libindicator-dev.install' | |||
201 | --- debian/libindicator-dev.install 1970-01-01 00:00:00 +0000 | |||
202 | +++ debian/libindicator-dev.install 2009-12-10 17:02:12 +0000 | |||
203 | @@ -0,0 +1,4 @@ | |||
204 | 1 | debian/tmp/usr/include/libindicator-0.3/libindicator/* | ||
205 | 2 | debian/tmp/usr/lib/pkgconfig/indicator.pc | ||
206 | 3 | debian/tmp/usr/lib/libindicator.a | ||
207 | 4 | debian/tmp/usr/lib/libindicator.so | ||
208 | 0 | 5 | ||
209 | === added file 'debian/libindicator-tools.install' | |||
210 | --- debian/libindicator-tools.install 1970-01-01 00:00:00 +0000 | |||
211 | +++ debian/libindicator-tools.install 2009-12-10 17:02:12 +0000 | |||
212 | @@ -0,0 +1,1 @@ | |||
213 | 1 | debian/tmp/usr/lib/libindicator/* | ||
214 | 0 | 2 | ||
215 | === added file 'debian/libindicator0.install' | |||
216 | --- debian/libindicator0.install 1970-01-01 00:00:00 +0000 | |||
217 | +++ debian/libindicator0.install 2009-12-10 17:02:12 +0000 | |||
218 | @@ -0,0 +1,1 @@ | |||
219 | 1 | debian/tmp/usr/lib/libindicator.so.* | ||
220 | 0 | 2 | ||
221 | === modified file 'libindicator/Makefile.am' | |||
222 | --- libindicator/Makefile.am 2009-04-21 19:15:22 +0000 | |||
223 | +++ libindicator/Makefile.am 2009-12-10 17:02:12 +0000 | |||
224 | @@ -1,14 +1,65 @@ | |||
225 | 1 | BUILT_SOURCES = | ||
226 | 2 | CLEANFILES = | ||
227 | 1 | EXTRA_DIST = \ | 3 | EXTRA_DIST = \ |
228 | 2 | indicator.pc.in | 4 | indicator.pc.in |
229 | 3 | 5 | ||
231 | 4 | libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator | 6 | libindicatorincludedir=$(includedir)/libindicator-0.3/libindicator |
232 | 5 | 7 | ||
233 | 6 | indicator_headers = \ | 8 | indicator_headers = \ |
235 | 7 | indicator.h | 9 | indicator.h \ |
236 | 10 | indicator-object.h \ | ||
237 | 11 | indicator-service.h \ | ||
238 | 12 | indicator-service-manager.h | ||
239 | 8 | 13 | ||
240 | 9 | libindicatorinclude_HEADERS = \ | 14 | libindicatorinclude_HEADERS = \ |
241 | 10 | $(indicator_headers) | 15 | $(indicator_headers) |
242 | 11 | 16 | ||
243 | 17 | lib_LTLIBRARIES = \ | ||
244 | 18 | libindicator.la | ||
245 | 19 | |||
246 | 20 | libindicator_la_SOURCES = \ | ||
247 | 21 | $(indicator_headers) \ | ||
248 | 22 | dbus-shared.h \ | ||
249 | 23 | indicator-object.c \ | ||
250 | 24 | indicator-service.c \ | ||
251 | 25 | indicator-service-manager.c | ||
252 | 26 | |||
253 | 27 | libindicator_la_CFLAGS = \ | ||
254 | 28 | $(LIBINDICATOR_CFLAGS) \ | ||
255 | 29 | -DG_LOG_DOMAIN=\"libindicator\" \ | ||
256 | 30 | -Wall -Werror | ||
257 | 31 | |||
258 | 32 | libindicator_la_LIBADD = \ | ||
259 | 33 | $(LIBINDICATOR_LIBS) | ||
260 | 34 | |||
261 | 12 | pkgconfig_DATA = indicator.pc | 35 | pkgconfig_DATA = indicator.pc |
262 | 13 | pkgconfigdir = $(libdir)/pkgconfig | 36 | pkgconfigdir = $(libdir)/pkgconfig |
263 | 14 | 37 | ||
264 | 38 | ################################## | ||
265 | 39 | # DBus Specs | ||
266 | 40 | ################################## | ||
267 | 41 | |||
268 | 42 | DBUS_SPECS = \ | ||
269 | 43 | indicator-service.xml | ||
270 | 44 | |||
271 | 45 | %-client.h: %.xml | ||
272 | 46 | dbus-binding-tool \ | ||
273 | 47 | --prefix=_$(subst -,_,$(basename $(notdir $<)))_client \ | ||
274 | 48 | --mode=glib-client \ | ||
275 | 49 | --output=$@ \ | ||
276 | 50 | $< | ||
277 | 51 | |||
278 | 52 | %-server.h: %.xml | ||
279 | 53 | dbus-binding-tool \ | ||
280 | 54 | --prefix=_$(subst -,_,$(basename $(notdir $<)))_server \ | ||
281 | 55 | --mode=glib-server \ | ||
282 | 56 | --output=$@ \ | ||
283 | 57 | $< | ||
284 | 58 | |||
285 | 59 | BUILT_SOURCES += \ | ||
286 | 60 | $(DBUS_SPECS:.xml=-client.h) \ | ||
287 | 61 | $(DBUS_SPECS:.xml=-server.h) | ||
288 | 62 | |||
289 | 63 | CLEANFILES += $(BUILT_SOURCES) | ||
290 | 64 | |||
291 | 65 | EXTRA_DIST += $(DBUS_SPECS) | ||
292 | 15 | 66 | ||
293 | === added file 'libindicator/dbus-shared.h' | |||
294 | --- libindicator/dbus-shared.h 1970-01-01 00:00:00 +0000 | |||
295 | +++ libindicator/dbus-shared.h 2009-12-10 17:02:12 +0000 | |||
296 | @@ -0,0 +1,28 @@ | |||
297 | 1 | /* | ||
298 | 2 | Shared defines for DBus interfaces and API versions to | ||
299 | 3 | make sure the server and client agree. | ||
300 | 4 | |||
301 | 5 | Copyright 2009 Canonical Ltd. | ||
302 | 6 | |||
303 | 7 | Authors: | ||
304 | 8 | Ted Gould <ted@canonical.com> | ||
305 | 9 | |||
306 | 10 | This library is free software; you can redistribute it and/or | ||
307 | 11 | modify it under the terms of the GNU General Public License | ||
308 | 12 | version 3.0 as published by the Free Software Foundation. | ||
309 | 13 | |||
310 | 14 | This library is distributed in the hope that it will be useful, | ||
311 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
312 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
313 | 17 | GNU General Public License version 3.0 for more details. | ||
314 | 18 | |||
315 | 19 | You should have received a copy of the GNU General Public | ||
316 | 20 | License along with this library. If not, see | ||
317 | 21 | <http://www.gnu.org/licenses/>. | ||
318 | 22 | */ | ||
319 | 23 | |||
320 | 24 | #define INDICATOR_SERVICE_INTERFACE "org.ayatana.indicator.service" | ||
321 | 25 | #define INDICATOR_SERVICE_OBJECT "/org/ayatana/indicator/service" | ||
322 | 26 | |||
323 | 27 | #define INDICATOR_SERVICE_VERSION 1 | ||
324 | 28 | |||
325 | 0 | 29 | ||
326 | === added file 'libindicator/indicator-object.c' | |||
327 | --- libindicator/indicator-object.c 1970-01-01 00:00:00 +0000 | |||
328 | +++ libindicator/indicator-object.c 2009-12-10 17:02:12 +0000 | |||
329 | @@ -0,0 +1,344 @@ | |||
330 | 1 | /* | ||
331 | 2 | An object to represent loadable indicator modules to make loading | ||
332 | 3 | them easy and objectified. | ||
333 | 4 | |||
334 | 5 | Copyright 2009 Canonical Ltd. | ||
335 | 6 | |||
336 | 7 | Authors: | ||
337 | 8 | Ted Gould <ted@canonical.com> | ||
338 | 9 | |||
339 | 10 | This library is free software; you can redistribute it and/or | ||
340 | 11 | modify it under the terms of the GNU General Public License | ||
341 | 12 | version 3.0 as published by the Free Software Foundation. | ||
342 | 13 | |||
343 | 14 | This library is distributed in the hope that it will be useful, | ||
344 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
345 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
346 | 17 | GNU General Public License version 3.0 for more details. | ||
347 | 18 | |||
348 | 19 | You should have received a copy of the GNU General Public | ||
349 | 20 | License along with this library. If not, see | ||
350 | 21 | <http://www.gnu.org/licenses/>. | ||
351 | 22 | */ | ||
352 | 23 | |||
353 | 24 | #ifdef HAVE_CONFIG_H | ||
354 | 25 | #include "config.h" | ||
355 | 26 | #endif | ||
356 | 27 | |||
357 | 28 | #include "indicator.h" | ||
358 | 29 | #include "indicator-object.h" | ||
359 | 30 | |||
360 | 31 | /** | ||
361 | 32 | IndicatorObjectPrivate: | ||
362 | 33 | @module: The loaded module representing the object. Note to | ||
363 | 34 | subclasses: This will not be set when you're initalized. | ||
364 | 35 | @entry: A default entry for objects that don't need all the | ||
365 | 36 | fancy stuff. This works with #get_entries_default. | ||
366 | 37 | @gotten_entries: A check to see if the @entry has been | ||
367 | 38 | populated intelligently yet. | ||
368 | 39 | |||
369 | 40 | Structure to define the memory for the private area | ||
370 | 41 | of the object instance. | ||
371 | 42 | */ | ||
372 | 43 | struct _IndicatorObjectPrivate { | ||
373 | 44 | GModule * module; | ||
374 | 45 | |||
375 | 46 | /* For get_entries_default */ | ||
376 | 47 | IndicatorObjectEntry entry; | ||
377 | 48 | gboolean gotten_entries; | ||
378 | 49 | }; | ||
379 | 50 | |||
380 | 51 | #define INDICATOR_OBJECT_GET_PRIVATE(o) (INDICATOR_OBJECT(o)->priv) | ||
381 | 52 | |||
382 | 53 | /* Signals Stuff */ | ||
383 | 54 | enum { | ||
384 | 55 | ENTRY_ADDED, | ||
385 | 56 | ENTRY_REMOVED, | ||
386 | 57 | LAST_SIGNAL | ||
387 | 58 | }; | ||
388 | 59 | |||
389 | 60 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
390 | 61 | |||
391 | 62 | /* GObject stuff */ | ||
392 | 63 | static void indicator_object_class_init (IndicatorObjectClass *klass); | ||
393 | 64 | static void indicator_object_init (IndicatorObject *self); | ||
394 | 65 | static void indicator_object_dispose (GObject *object); | ||
395 | 66 | static void indicator_object_finalize (GObject *object); | ||
396 | 67 | |||
397 | 68 | static GList * get_entries_default (IndicatorObject * io); | ||
398 | 69 | |||
399 | 70 | G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); | ||
400 | 71 | |||
401 | 72 | /* Setup the class and put the functions into the | ||
402 | 73 | class structure */ | ||
403 | 74 | static void | ||
404 | 75 | indicator_object_class_init (IndicatorObjectClass *klass) | ||
405 | 76 | { | ||
406 | 77 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
407 | 78 | |||
408 | 79 | g_type_class_add_private (klass, sizeof (IndicatorObjectPrivate)); | ||
409 | 80 | |||
410 | 81 | object_class->dispose = indicator_object_dispose; | ||
411 | 82 | object_class->finalize = indicator_object_finalize; | ||
412 | 83 | |||
413 | 84 | klass->get_label = NULL; | ||
414 | 85 | klass->get_menu = NULL; | ||
415 | 86 | klass->get_image = NULL; | ||
416 | 87 | |||
417 | 88 | klass->get_entries = get_entries_default; | ||
418 | 89 | |||
419 | 90 | /** | ||
420 | 91 | IndicatorObject::entry-added: | ||
421 | 92 | @arg0: The #IndicatorObject object | ||
422 | 93 | |||
423 | 94 | Signaled when a new entry is added and should | ||
424 | 95 | be shown by the person using this object. | ||
425 | 96 | */ | ||
426 | 97 | signals[ENTRY_ADDED] = g_signal_new (INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, | ||
427 | 98 | G_TYPE_FROM_CLASS(klass), | ||
428 | 99 | G_SIGNAL_RUN_LAST, | ||
429 | 100 | G_STRUCT_OFFSET (IndicatorObjectClass, entry_added), | ||
430 | 101 | NULL, NULL, | ||
431 | 102 | g_cclosure_marshal_VOID__POINTER, | ||
432 | 103 | G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE); | ||
433 | 104 | |||
434 | 105 | /** | ||
435 | 106 | IndicatorObject::entry-removed: | ||
436 | 107 | @arg0: The #IndicatorObject object | ||
437 | 108 | |||
438 | 109 | Signaled when an entry is removed and should | ||
439 | 110 | be removed by the person using this object. | ||
440 | 111 | */ | ||
441 | 112 | signals[ENTRY_REMOVED] = g_signal_new (INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, | ||
442 | 113 | G_TYPE_FROM_CLASS(klass), | ||
443 | 114 | G_SIGNAL_RUN_LAST, | ||
444 | 115 | G_STRUCT_OFFSET (IndicatorObjectClass, entry_removed), | ||
445 | 116 | NULL, NULL, | ||
446 | 117 | g_cclosure_marshal_VOID__POINTER, | ||
447 | 118 | G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE); | ||
448 | 119 | |||
449 | 120 | return; | ||
450 | 121 | } | ||
451 | 122 | |||
452 | 123 | /* Initialize an instance */ | ||
453 | 124 | static void | ||
454 | 125 | indicator_object_init (IndicatorObject *self) | ||
455 | 126 | { | ||
456 | 127 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_OBJECT_TYPE, IndicatorObjectPrivate); | ||
457 | 128 | |||
458 | 129 | self->priv->module = NULL; | ||
459 | 130 | |||
460 | 131 | self->priv->entry.menu = NULL; | ||
461 | 132 | self->priv->entry.label = NULL; | ||
462 | 133 | self->priv->entry.image = NULL; | ||
463 | 134 | |||
464 | 135 | self->priv->gotten_entries = FALSE; | ||
465 | 136 | |||
466 | 137 | return; | ||
467 | 138 | } | ||
468 | 139 | |||
469 | 140 | /* Unref the objects that we're holding on to. */ | ||
470 | 141 | static void | ||
471 | 142 | indicator_object_dispose (GObject *object) | ||
472 | 143 | { | ||
473 | 144 | |||
474 | 145 | G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); | ||
475 | 146 | return; | ||
476 | 147 | } | ||
477 | 148 | |||
478 | 149 | /* A small helper function that closes a module but | ||
479 | 150 | in the function prototype of a GSourceFunc. */ | ||
480 | 151 | static gboolean | ||
481 | 152 | module_unref (gpointer data) | ||
482 | 153 | { | ||
483 | 154 | if (!g_module_close((GModule *)data)) { | ||
484 | 155 | /* All we can do is warn. */ | ||
485 | 156 | g_warning("Unable to close module!"); | ||
486 | 157 | } | ||
487 | 158 | return FALSE; | ||
488 | 159 | } | ||
489 | 160 | |||
490 | 161 | /* Free memory */ | ||
491 | 162 | static void | ||
492 | 163 | indicator_object_finalize (GObject *object) | ||
493 | 164 | { | ||
494 | 165 | IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); | ||
495 | 166 | |||
496 | 167 | if (priv->module != NULL) { | ||
497 | 168 | /* Wow, this is convoluted. So basically we want to unref | ||
498 | 169 | the module which will cause the code it included to be | ||
499 | 170 | removed. But, since it's finalize function is the function | ||
500 | 171 | that called this one, we can't really remove it before | ||
501 | 172 | it finishes being executed. So we're putting the job into | ||
502 | 173 | the main loop to remove it the next time it gets a chance. | ||
503 | 174 | Slightly non-deterministic, but should work. */ | ||
504 | 175 | g_idle_add(module_unref, priv->module); | ||
505 | 176 | priv->module = NULL; | ||
506 | 177 | } | ||
507 | 178 | |||
508 | 179 | G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); | ||
509 | 180 | return; | ||
510 | 181 | } | ||
511 | 182 | |||
512 | 183 | /** | ||
513 | 184 | indicator_object_new_from_file: | ||
514 | 185 | @file: Filename containing a loadable module | ||
515 | 186 | |||
516 | 187 | This function builds an #IndicatorObject using the symbols | ||
517 | 188 | that are found in @file. The module is loaded and the | ||
518 | 189 | references are all kept by the object. To unload the | ||
519 | 190 | module the object must be destroyed. | ||
520 | 191 | |||
521 | 192 | Return value: A valid #IndicatorObject or #NULL if error. | ||
522 | 193 | */ | ||
523 | 194 | IndicatorObject * | ||
524 | 195 | indicator_object_new_from_file (const gchar * file) | ||
525 | 196 | { | ||
526 | 197 | GObject * object = NULL; | ||
527 | 198 | GModule * module = NULL; | ||
528 | 199 | |||
529 | 200 | /* Check to make sure the name exists and that the | ||
530 | 201 | file itself exists */ | ||
531 | 202 | if (file == NULL) { | ||
532 | 203 | g_warning("Invalid filename."); | ||
533 | 204 | return NULL; | ||
534 | 205 | } | ||
535 | 206 | |||
536 | 207 | if (!g_file_test(file, G_FILE_TEST_EXISTS)) { | ||
537 | 208 | g_warning("File '%s' does not exist.", file); | ||
538 | 209 | return NULL; | ||
539 | 210 | } | ||
540 | 211 | |||
541 | 212 | /* Grab the g_module reference, pull it in but let's | ||
542 | 213 | keep the symbols local to avoid conflicts. */ | ||
543 | 214 | module = g_module_open(file, | ||
544 | 215 | G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); | ||
545 | 216 | if (module == NULL) { | ||
546 | 217 | g_warning("Unable to load module: %s", file); | ||
547 | 218 | return NULL; | ||
548 | 219 | } | ||
549 | 220 | |||
550 | 221 | /* Look for the version function, error if not found. */ | ||
551 | 222 | get_version_t lget_version = NULL; | ||
552 | 223 | if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) { | ||
553 | 224 | g_warning("Unable to get the symbol for getting the version."); | ||
554 | 225 | return NULL; | ||
555 | 226 | } | ||
556 | 227 | |||
557 | 228 | /* Check the version with the macro and make sure we're | ||
558 | 229 | all talking the same language. */ | ||
559 | 230 | if (!INDICATOR_VERSION_CHECK(lget_version())) { | ||
560 | 231 | g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); | ||
561 | 232 | return NULL; | ||
562 | 233 | } | ||
563 | 234 | |||
564 | 235 | /* The function for grabbing a label from the module | ||
565 | 236 | execute it, and make sure everything is a-okay */ | ||
566 | 237 | get_type_t lget_type = NULL; | ||
567 | 238 | if (!g_module_symbol(module, INDICATOR_GET_TYPE_S, (gpointer *)(&lget_type))) { | ||
568 | 239 | g_warning("Unable to get '" INDICATOR_GET_TYPE_S "' symbol from module: %s", file); | ||
569 | 240 | goto unrefandout; | ||
570 | 241 | } | ||
571 | 242 | if (lget_type == NULL) { | ||
572 | 243 | g_warning("Symbol '" INDICATOR_GET_TYPE_S "' is (null) in module: %s", file); | ||
573 | 244 | goto unrefandout; | ||
574 | 245 | } | ||
575 | 246 | |||
576 | 247 | /* A this point we allocate the object, any code beyond | ||
577 | 248 | here needs to deallocate it if we're returning in an | ||
578 | 249 | error'd state. */ | ||
579 | 250 | object = g_object_new(lget_type(), NULL); | ||
580 | 251 | if (object == NULL) { | ||
581 | 252 | g_warning("Unable to build an object if type '%d' in module: %s", (gint)lget_type(), file); | ||
582 | 253 | goto unrefandout; | ||
583 | 254 | } | ||
584 | 255 | if (!INDICATOR_IS_OBJECT(object)) { | ||
585 | 256 | g_warning("Type '%d' in file %s is not a subclass of IndicatorObject.", (gint)lget_type(), file); | ||
586 | 257 | goto unrefandout; | ||
587 | 258 | } | ||
588 | 259 | |||
589 | 260 | IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); | ||
590 | 261 | /* Now we can track the module */ | ||
591 | 262 | priv->module = module; | ||
592 | 263 | |||
593 | 264 | return INDICATOR_OBJECT(object); | ||
594 | 265 | |||
595 | 266 | /* Error, let's drop the object and return NULL. Sad when | ||
596 | 267 | this happens. */ | ||
597 | 268 | unrefandout: | ||
598 | 269 | if (object != NULL) { | ||
599 | 270 | g_object_unref(object); | ||
600 | 271 | } | ||
601 | 272 | if (module != NULL) { | ||
602 | 273 | g_object_unref(module); | ||
603 | 274 | } | ||
604 | 275 | g_warning("Error building IndicatorObject from file: %s", file); | ||
605 | 276 | return NULL; | ||
606 | 277 | } | ||
607 | 278 | |||
608 | 279 | /* The default get entries function uses the other single | ||
609 | 280 | entries in the class to create an entry structure and | ||
610 | 281 | put it into a list. This makes it simple for simple objects | ||
611 | 282 | to create the list. Small changes from the way they | ||
612 | 283 | previously were. */ | ||
613 | 284 | static GList * | ||
614 | 285 | get_entries_default (IndicatorObject * io) | ||
615 | 286 | { | ||
616 | 287 | IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); | ||
617 | 288 | |||
618 | 289 | if (!priv->gotten_entries) { | ||
619 | 290 | IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); | ||
620 | 291 | |||
621 | 292 | if (class->get_label) { | ||
622 | 293 | priv->entry.label = class->get_label(io); | ||
623 | 294 | } | ||
624 | 295 | |||
625 | 296 | if (class->get_image) { | ||
626 | 297 | priv->entry.image = class->get_image(io); | ||
627 | 298 | } | ||
628 | 299 | |||
629 | 300 | if (priv->entry.image == NULL && priv->entry.label == NULL) { | ||
630 | 301 | g_warning("IndicatorObject class does not create an image or a label. We need one of those."); | ||
631 | 302 | return NULL; | ||
632 | 303 | } | ||
633 | 304 | |||
634 | 305 | if (class->get_menu) { | ||
635 | 306 | priv->entry.menu = class->get_menu(io); | ||
636 | 307 | } | ||
637 | 308 | |||
638 | 309 | if (priv->entry.menu == NULL) { | ||
639 | 310 | g_warning("IndicatorObject class does not create a menu. We need one of those."); | ||
640 | 311 | return NULL; | ||
641 | 312 | } | ||
642 | 313 | |||
643 | 314 | priv->gotten_entries = TRUE; | ||
644 | 315 | } | ||
645 | 316 | |||
646 | 317 | return g_list_append(NULL, &(priv->entry)); | ||
647 | 318 | } | ||
648 | 319 | |||
649 | 320 | /** | ||
650 | 321 | indicator_object_get_entires: | ||
651 | 322 | @io: #IndicatorObject to query | ||
652 | 323 | |||
653 | 324 | This function looks on the class for the object and calls | ||
654 | 325 | it's #IndicatorObjectClass::get_entries function. The | ||
655 | 326 | list should be owned by the caller, but the individual | ||
656 | 327 | enteries should not be. | ||
657 | 328 | |||
658 | 329 | Return value: A list if #IndicatorObjectEntry structures or | ||
659 | 330 | NULL if there is an error. | ||
660 | 331 | */ | ||
661 | 332 | GList * | ||
662 | 333 | indicator_object_get_entries (IndicatorObject * io) | ||
663 | 334 | { | ||
664 | 335 | g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); | ||
665 | 336 | IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); | ||
666 | 337 | |||
667 | 338 | if (class->get_entries) { | ||
668 | 339 | return class->get_entries(io); | ||
669 | 340 | } | ||
670 | 341 | |||
671 | 342 | g_error("No get_entries function on object. It must have been deleted?!?!"); | ||
672 | 343 | return NULL; | ||
673 | 344 | } | ||
674 | 0 | 345 | ||
675 | === added file 'libindicator/indicator-object.h' | |||
676 | --- libindicator/indicator-object.h 1970-01-01 00:00:00 +0000 | |||
677 | +++ libindicator/indicator-object.h 2009-12-10 17:02:12 +0000 | |||
678 | @@ -0,0 +1,123 @@ | |||
679 | 1 | /* | ||
680 | 2 | An object to represent loadable indicator modules to make loading | ||
681 | 3 | them easy and objectified. | ||
682 | 4 | |||
683 | 5 | Copyright 2009 Canonical Ltd. | ||
684 | 6 | |||
685 | 7 | Authors: | ||
686 | 8 | Ted Gould <ted@canonical.com> | ||
687 | 9 | |||
688 | 10 | This library is free software; you can redistribute it and/or | ||
689 | 11 | modify it under the terms of the GNU General Public License | ||
690 | 12 | version 3.0 as published by the Free Software Foundation. | ||
691 | 13 | |||
692 | 14 | This library is distributed in the hope that it will be useful, | ||
693 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
694 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
695 | 17 | GNU General Public License version 3.0 for more details. | ||
696 | 18 | |||
697 | 19 | You should have received a copy of the GNU General Public | ||
698 | 20 | License along with this library. If not, see | ||
699 | 21 | <http://www.gnu.org/licenses/>. | ||
700 | 22 | */ | ||
701 | 23 | |||
702 | 24 | #ifndef __INDICATOR_OBJECT_H__ | ||
703 | 25 | #define __INDICATOR_OBJECT_H__ | ||
704 | 26 | |||
705 | 27 | #include <glib.h> | ||
706 | 28 | #include <glib-object.h> | ||
707 | 29 | |||
708 | 30 | G_BEGIN_DECLS | ||
709 | 31 | |||
710 | 32 | #define INDICATOR_OBJECT_TYPE (indicator_object_get_type ()) | ||
711 | 33 | #define INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_OBJECT_TYPE, IndicatorObject)) | ||
712 | 34 | #define INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) | ||
713 | 35 | #define INDICATOR_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) | ||
714 | 36 | #define INDICATOR_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) | ||
715 | 37 | #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) | ||
716 | 38 | |||
717 | 39 | #define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED "entry-added" | ||
718 | 40 | #define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, INDICATOR_OBJECT_TYPE)) | ||
719 | 41 | #define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED "entry-removed" | ||
720 | 42 | #define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, INDICATOR_OBJECT_TYPE)) | ||
721 | 43 | |||
722 | 44 | typedef struct _IndicatorObject IndicatorObject; | ||
723 | 45 | typedef struct _IndicatorObjectClass IndicatorObjectClass; | ||
724 | 46 | typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; | ||
725 | 47 | typedef struct _IndicatorObjectEntry IndicatorObjectEntry; | ||
726 | 48 | |||
727 | 49 | /** | ||
728 | 50 | IndicatorObjectClass: | ||
729 | 51 | @parent_class: #GObjectClass | ||
730 | 52 | @get_label: Gets the label for this object. Should be set | ||
731 | 53 | to #NULL if @get_entries is set. Should NOT ref the | ||
732 | 54 | object. | ||
733 | 55 | @get_image: Gets the image for this object. Should be set | ||
734 | 56 | to #NULL if @get_entries is set. Should NOT ref the | ||
735 | 57 | object. | ||
736 | 58 | @get_menu: Gets the image for this object. Should be set | ||
737 | 59 | to #NULL if @get_entries is set. Should NOT ref the | ||
738 | 60 | object. | ||
739 | 61 | @get_entries: Gets all of the entires for this object returning | ||
740 | 62 | a #GList of #IndicatorObjectEntries. The list should be | ||
741 | 63 | under the ownership of the caller but the entires will | ||
742 | 64 | not be. | ||
743 | 65 | @entry_added: Slot for #IndicatorObject::entry-added | ||
744 | 66 | @entry_removed: Slot for #IndicatorObject::entry-removed | ||
745 | 67 | @indicator_object_reserved_1: Reserved for future use | ||
746 | 68 | @indicator_object_reserved_2: Reserved for future use | ||
747 | 69 | @indicator_object_reserved_3: Reserved for future use | ||
748 | 70 | @indicator_object_reserved_4: Reserved for future use | ||
749 | 71 | */ | ||
750 | 72 | struct _IndicatorObjectClass { | ||
751 | 73 | GObjectClass parent_class; | ||
752 | 74 | |||
753 | 75 | /* Virtual Functions */ | ||
754 | 76 | GtkLabel * (*get_label) (IndicatorObject * io); | ||
755 | 77 | GtkImage * (*get_image) (IndicatorObject * io); | ||
756 | 78 | GtkMenu * (*get_menu) (IndicatorObject * io); | ||
757 | 79 | |||
758 | 80 | GList * (*get_entries) (IndicatorObject * io); | ||
759 | 81 | |||
760 | 82 | /* Signals */ | ||
761 | 83 | void (*entry_added) (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); | ||
762 | 84 | void (*entry_removed) (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); | ||
763 | 85 | |||
764 | 86 | /* Reserved */ | ||
765 | 87 | void (* indicator_object_reserved_1) (void); | ||
766 | 88 | void (* indicator_object_reserved_2) (void); | ||
767 | 89 | void (* indicator_object_reserved_3) (void); | ||
768 | 90 | void (* indicator_object_reserved_4) (void); | ||
769 | 91 | }; | ||
770 | 92 | |||
771 | 93 | /** | ||
772 | 94 | IndicatorObject: | ||
773 | 95 | @parent: #GObject | ||
774 | 96 | @priv: A cached reference to the private data for the | ||
775 | 97 | instance. | ||
776 | 98 | */ | ||
777 | 99 | struct _IndicatorObject { | ||
778 | 100 | GObject parent; | ||
779 | 101 | IndicatorObjectPrivate * priv; | ||
780 | 102 | }; | ||
781 | 103 | |||
782 | 104 | /** | ||
783 | 105 | IndicatorObjectEntry: | ||
784 | 106 | @label: The label to be shown on the panel | ||
785 | 107 | @image: The image to be shown on the panel | ||
786 | 108 | @menu: The menu to be added to the menubar | ||
787 | 109 | */ | ||
788 | 110 | struct _IndicatorObjectEntry { | ||
789 | 111 | GtkLabel * label; | ||
790 | 112 | GtkImage * image; | ||
791 | 113 | GtkMenu * menu; | ||
792 | 114 | }; | ||
793 | 115 | |||
794 | 116 | GType indicator_object_get_type (void); | ||
795 | 117 | IndicatorObject * indicator_object_new_from_file (const gchar * file); | ||
796 | 118 | |||
797 | 119 | GList * indicator_object_get_entries (IndicatorObject * io); | ||
798 | 120 | |||
799 | 121 | G_END_DECLS | ||
800 | 122 | |||
801 | 123 | #endif | ||
802 | 0 | 124 | ||
803 | === added file 'libindicator/indicator-service-manager.c' | |||
804 | --- libindicator/indicator-service-manager.c 1970-01-01 00:00:00 +0000 | |||
805 | +++ libindicator/indicator-service-manager.c 2009-12-10 17:02:12 +0000 | |||
806 | @@ -0,0 +1,493 @@ | |||
807 | 1 | /* | ||
808 | 2 | An object used to manage services. Either start them or | ||
809 | 3 | just connect to them. | ||
810 | 4 | |||
811 | 5 | Copyright 2009 Canonical Ltd. | ||
812 | 6 | |||
813 | 7 | Authors: | ||
814 | 8 | Ted Gould <ted@canonical.com> | ||
815 | 9 | |||
816 | 10 | This library is free software; you can redistribute it and/or | ||
817 | 11 | modify it under the terms of the GNU General Public License | ||
818 | 12 | version 3.0 as published by the Free Software Foundation. | ||
819 | 13 | |||
820 | 14 | This library is distributed in the hope that it will be useful, | ||
821 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
822 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
823 | 17 | GNU General Public License version 3.0 for more details. | ||
824 | 18 | |||
825 | 19 | You should have received a copy of the GNU General Public | ||
826 | 20 | License along with this library. If not, see | ||
827 | 21 | <http://www.gnu.org/licenses/>. | ||
828 | 22 | */ | ||
829 | 23 | |||
830 | 24 | #ifdef HAVE_CONFIG_H | ||
831 | 25 | #include "config.h" | ||
832 | 26 | #endif | ||
833 | 27 | |||
834 | 28 | #include <dbus/dbus-glib-bindings.h> | ||
835 | 29 | #include <dbus/dbus-glib-lowlevel.h> | ||
836 | 30 | |||
837 | 31 | #include "indicator-service-manager.h" | ||
838 | 32 | #include "indicator-service-client.h" | ||
839 | 33 | #include "dbus-shared.h" | ||
840 | 34 | |||
841 | 35 | /* Private Stuff */ | ||
842 | 36 | /** | ||
843 | 37 | IndicatorServiceManagerPrivate: | ||
844 | 38 | @name: The well known dbus name the service should be on. | ||
845 | 39 | @dbus_proxy: A proxy to talk to the dbus daemon. | ||
846 | 40 | @service_proxy: The proxy to the service itself. | ||
847 | 41 | @connected: Whether we're connected to the service or not. | ||
848 | 42 | @this_service_version: The version of the service that we're looking for. | ||
849 | 43 | @bus: A reference to the bus so we don't have to keep getting it. | ||
850 | 44 | */ | ||
851 | 45 | typedef struct _IndicatorServiceManagerPrivate IndicatorServiceManagerPrivate; | ||
852 | 46 | struct _IndicatorServiceManagerPrivate { | ||
853 | 47 | gchar * name; | ||
854 | 48 | DBusGProxy * dbus_proxy; | ||
855 | 49 | DBusGProxy * service_proxy; | ||
856 | 50 | gboolean connected; | ||
857 | 51 | guint this_service_version; | ||
858 | 52 | DBusGConnection * bus; | ||
859 | 53 | }; | ||
860 | 54 | |||
861 | 55 | /* Signals Stuff */ | ||
862 | 56 | enum { | ||
863 | 57 | CONNECTION_CHANGE, | ||
864 | 58 | LAST_SIGNAL | ||
865 | 59 | }; | ||
866 | 60 | |||
867 | 61 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
868 | 62 | |||
869 | 63 | |||
870 | 64 | /* Properties */ | ||
871 | 65 | /* Enum for the properties so that they can be quickly | ||
872 | 66 | found and looked up. */ | ||
873 | 67 | enum { | ||
874 | 68 | PROP_0, | ||
875 | 69 | PROP_NAME, | ||
876 | 70 | PROP_VERSION | ||
877 | 71 | }; | ||
878 | 72 | |||
879 | 73 | /* The strings so that they can be slowly looked up. */ | ||
880 | 74 | #define PROP_NAME_S "name" | ||
881 | 75 | #define PROP_VERSION_S "version" | ||
882 | 76 | |||
883 | 77 | /* GObject Stuff */ | ||
884 | 78 | #define INDICATOR_SERVICE_MANAGER_GET_PRIVATE(o) \ | ||
885 | 79 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerPrivate)) | ||
886 | 80 | |||
887 | 81 | static void indicator_service_manager_class_init (IndicatorServiceManagerClass *klass); | ||
888 | 82 | static void indicator_service_manager_init (IndicatorServiceManager *self); | ||
889 | 83 | static void indicator_service_manager_dispose (GObject *object); | ||
890 | 84 | static void indicator_service_manager_finalize (GObject *object); | ||
891 | 85 | |||
892 | 86 | /* Prototypes */ | ||
893 | 87 | static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); | ||
894 | 88 | static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); | ||
895 | 89 | static void start_service (IndicatorServiceManager * service); | ||
896 | 90 | |||
897 | 91 | G_DEFINE_TYPE (IndicatorServiceManager, indicator_service_manager, G_TYPE_OBJECT); | ||
898 | 92 | |||
899 | 93 | /* Build all of our signals and proxies and tie everything | ||
900 | 94 | all together. Lovely. */ | ||
901 | 95 | static void | ||
902 | 96 | indicator_service_manager_class_init (IndicatorServiceManagerClass *klass) | ||
903 | 97 | { | ||
904 | 98 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
905 | 99 | |||
906 | 100 | g_type_class_add_private (klass, sizeof (IndicatorServiceManagerPrivate)); | ||
907 | 101 | |||
908 | 102 | object_class->dispose = indicator_service_manager_dispose; | ||
909 | 103 | object_class->finalize = indicator_service_manager_finalize; | ||
910 | 104 | |||
911 | 105 | /* Property funcs */ | ||
912 | 106 | object_class->set_property = set_property; | ||
913 | 107 | object_class->get_property = get_property; | ||
914 | 108 | |||
915 | 109 | /** | ||
916 | 110 | IndicatorServiceManager::connecton-change: | ||
917 | 111 | @arg0: The #IndicatorServiceManager object | ||
918 | 112 | @arg1: The state of the connection, TRUE is connected. | ||
919 | 113 | |||
920 | 114 | Signaled when the service is connected or disconnected | ||
921 | 115 | depending on it's previous state. | ||
922 | 116 | */ | ||
923 | 117 | signals[CONNECTION_CHANGE] = g_signal_new (INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, | ||
924 | 118 | G_TYPE_FROM_CLASS(klass), | ||
925 | 119 | G_SIGNAL_RUN_LAST, | ||
926 | 120 | G_STRUCT_OFFSET (IndicatorServiceManagerClass, connection_change), | ||
927 | 121 | NULL, NULL, | ||
928 | 122 | g_cclosure_marshal_VOID__BOOLEAN, | ||
929 | 123 | G_TYPE_NONE, 1, G_TYPE_BOOLEAN, G_TYPE_NONE); | ||
930 | 124 | |||
931 | 125 | /* Properties */ | ||
932 | 126 | g_object_class_install_property(object_class, PROP_NAME, | ||
933 | 127 | g_param_spec_string(PROP_NAME_S, | ||
934 | 128 | "The DBus name for the service to monitor", | ||
935 | 129 | "This is the name that should be used to start a service.", | ||
936 | 130 | NULL, | ||
937 | 131 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
938 | 132 | g_object_class_install_property(object_class, PROP_VERSION, | ||
939 | 133 | g_param_spec_uint(PROP_VERSION_S, | ||
940 | 134 | "The version of the service that we're expecting.", | ||
941 | 135 | "A number to check and reject a service if it gives us the wrong number. This should match across the manager and the service", | ||
942 | 136 | 0, G_MAXUINT, 0, | ||
943 | 137 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
944 | 138 | |||
945 | 139 | return; | ||
946 | 140 | } | ||
947 | 141 | |||
948 | 142 | /* This inits all the variable and sets up the proxy | ||
949 | 143 | to dbus. It doesn't look for the service as at this | ||
950 | 144 | point we don't know it's name. */ | ||
951 | 145 | static void | ||
952 | 146 | indicator_service_manager_init (IndicatorServiceManager *self) | ||
953 | 147 | { | ||
954 | 148 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self); | ||
955 | 149 | |||
956 | 150 | /* Get the private variables in a decent state */ | ||
957 | 151 | priv->name = NULL; | ||
958 | 152 | priv->dbus_proxy = NULL; | ||
959 | 153 | priv->service_proxy = NULL; | ||
960 | 154 | priv->connected = FALSE; | ||
961 | 155 | priv->this_service_version = 0; | ||
962 | 156 | priv->bus = NULL; | ||
963 | 157 | |||
964 | 158 | /* Start talkin' dbus */ | ||
965 | 159 | GError * error = NULL; | ||
966 | 160 | priv->bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); | ||
967 | 161 | if (error != NULL) { | ||
968 | 162 | g_error("Unable to get session bus for manager: %s", error->message); | ||
969 | 163 | g_error_free(error); | ||
970 | 164 | return; | ||
971 | 165 | } | ||
972 | 166 | |||
973 | 167 | priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, | ||
974 | 168 | DBUS_SERVICE_DBUS, | ||
975 | 169 | DBUS_PATH_DBUS, | ||
976 | 170 | DBUS_INTERFACE_DBUS, | ||
977 | 171 | &error); | ||
978 | 172 | if (error != NULL) { | ||
979 | 173 | g_error("Unable to get the proxy to DBus: %s", error->message); | ||
980 | 174 | g_error_free(error); | ||
981 | 175 | return; | ||
982 | 176 | } | ||
983 | 177 | |||
984 | 178 | return; | ||
985 | 179 | } | ||
986 | 180 | |||
987 | 181 | /* If we're connected this provides all the signals to say | ||
988 | 182 | that we're about to not be. Then it takes down the proxies | ||
989 | 183 | and tells the service that we're not interested in being | ||
990 | 184 | its friend anymore either. */ | ||
991 | 185 | static void | ||
992 | 186 | indicator_service_manager_dispose (GObject *object) | ||
993 | 187 | { | ||
994 | 188 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object); | ||
995 | 189 | |||
996 | 190 | /* If we were connected we need to make sure to | ||
997 | 191 | tell people that it's no longer the case. */ | ||
998 | 192 | if (priv->connected) { | ||
999 | 193 | priv->connected = FALSE; | ||
1000 | 194 | g_signal_emit(object, signals[CONNECTION_CHANGE], 0, FALSE, TRUE); | ||
1001 | 195 | } | ||
1002 | 196 | |||
1003 | 197 | /* Destory our DBus proxy, we won't need it. */ | ||
1004 | 198 | if (priv->dbus_proxy != NULL) { | ||
1005 | 199 | g_object_unref(G_OBJECT(priv->dbus_proxy)); | ||
1006 | 200 | priv->dbus_proxy = NULL; | ||
1007 | 201 | } | ||
1008 | 202 | |||
1009 | 203 | /* If we have a proxy, tell it we're shutting down. Just | ||
1010 | 204 | to be polite about it. */ | ||
1011 | 205 | if (priv->service_proxy != NULL) { | ||
1012 | 206 | dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID); | ||
1013 | 207 | } | ||
1014 | 208 | |||
1015 | 209 | /* Destory our service proxy, we won't need it. */ | ||
1016 | 210 | if (priv->service_proxy != NULL) { | ||
1017 | 211 | g_object_unref(G_OBJECT(priv->service_proxy)); | ||
1018 | 212 | priv->service_proxy = NULL; | ||
1019 | 213 | } | ||
1020 | 214 | |||
1021 | 215 | /* Let's see if our parents want to do anything. */ | ||
1022 | 216 | G_OBJECT_CLASS (indicator_service_manager_parent_class)->dispose (object); | ||
1023 | 217 | return; | ||
1024 | 218 | } | ||
1025 | 219 | |||
1026 | 220 | /* Ironically, we don't allocate a lot of memory ourselves. */ | ||
1027 | 221 | static void | ||
1028 | 222 | indicator_service_manager_finalize (GObject *object) | ||
1029 | 223 | { | ||
1030 | 224 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object); | ||
1031 | 225 | |||
1032 | 226 | if (priv->name != NULL) { | ||
1033 | 227 | g_free(priv->name); | ||
1034 | 228 | priv->name = NULL; | ||
1035 | 229 | } | ||
1036 | 230 | |||
1037 | 231 | G_OBJECT_CLASS (indicator_service_manager_parent_class)->finalize (object); | ||
1038 | 232 | return; | ||
1039 | 233 | } | ||
1040 | 234 | |||
1041 | 235 | /* Either copies the name into the private variable or | ||
1042 | 236 | sets the version. Do it wrong and it'll get upset. */ | ||
1043 | 237 | static void | ||
1044 | 238 | set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) | ||
1045 | 239 | { | ||
1046 | 240 | IndicatorServiceManager * self = INDICATOR_SERVICE_MANAGER(object); | ||
1047 | 241 | g_return_if_fail(self != NULL); | ||
1048 | 242 | |||
1049 | 243 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self); | ||
1050 | 244 | g_return_if_fail(priv != NULL); | ||
1051 | 245 | |||
1052 | 246 | switch (prop_id) { | ||
1053 | 247 | /* *********************** */ | ||
1054 | 248 | case PROP_NAME: | ||
1055 | 249 | if (priv->name != NULL) { | ||
1056 | 250 | g_error("Name can not be set twice!"); | ||
1057 | 251 | return; | ||
1058 | 252 | } | ||
1059 | 253 | priv->name = g_value_dup_string(value); | ||
1060 | 254 | start_service(self); | ||
1061 | 255 | break; | ||
1062 | 256 | /* *********************** */ | ||
1063 | 257 | case PROP_VERSION: | ||
1064 | 258 | priv->this_service_version = g_value_get_uint(value); | ||
1065 | 259 | break; | ||
1066 | 260 | /* *********************** */ | ||
1067 | 261 | default: | ||
1068 | 262 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1069 | 263 | break; | ||
1070 | 264 | } | ||
1071 | 265 | |||
1072 | 266 | return; | ||
1073 | 267 | } | ||
1074 | 268 | |||
1075 | 269 | /* Grabs the values from the private variables and | ||
1076 | 270 | puts them into the value. */ | ||
1077 | 271 | static void | ||
1078 | 272 | get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) | ||
1079 | 273 | { | ||
1080 | 274 | IndicatorServiceManager * self = INDICATOR_SERVICE_MANAGER(object); | ||
1081 | 275 | g_return_if_fail(self != NULL); | ||
1082 | 276 | |||
1083 | 277 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self); | ||
1084 | 278 | g_return_if_fail(priv != NULL); | ||
1085 | 279 | |||
1086 | 280 | switch (prop_id) { | ||
1087 | 281 | /* *********************** */ | ||
1088 | 282 | case PROP_NAME: | ||
1089 | 283 | g_value_set_string(value, priv->name); | ||
1090 | 284 | break; | ||
1091 | 285 | /* *********************** */ | ||
1092 | 286 | case PROP_VERSION: | ||
1093 | 287 | g_value_set_uint(value, priv->this_service_version); | ||
1094 | 288 | break; | ||
1095 | 289 | /* *********************** */ | ||
1096 | 290 | default: | ||
1097 | 291 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1098 | 292 | break; | ||
1099 | 293 | } | ||
1100 | 294 | |||
1101 | 295 | return; | ||
1102 | 296 | } | ||
1103 | 297 | |||
1104 | 298 | /* A callback from telling a service that we want to watch | ||
1105 | 299 | it. It gives us the service API version and the version | ||
1106 | 300 | of the other APIs it supports. We check both of those. | ||
1107 | 301 | If they don't match then we unwatch it. Otherwise, we | ||
1108 | 302 | signal a connection change to tell the rest of the world | ||
1109 | 303 | that we have a service now. */ | ||
1110 | 304 | static void | ||
1111 | 305 | watch_cb (DBusGProxy * proxy, guint service_api_version, guint this_service_version, GError * error, gpointer user_data) | ||
1112 | 306 | { | ||
1113 | 307 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); | ||
1114 | 308 | |||
1115 | 309 | if (error != NULL) { | ||
1116 | 310 | g_warning("Unable to set watch on '%s': '%s'", priv->name, error->message); | ||
1117 | 311 | g_error_free(error); | ||
1118 | 312 | return; | ||
1119 | 313 | } | ||
1120 | 314 | |||
1121 | 315 | if (service_api_version != INDICATOR_SERVICE_VERSION) { | ||
1122 | 316 | g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, service_api_version); | ||
1123 | 317 | dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID); | ||
1124 | 318 | return; | ||
1125 | 319 | } | ||
1126 | 320 | |||
1127 | 321 | if (this_service_version != priv->this_service_version) { | ||
1128 | 322 | g_warning("Service is using a different API version than the manager. Expecting %d and got %d.", priv->this_service_version, this_service_version); | ||
1129 | 323 | dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID); | ||
1130 | 324 | return; | ||
1131 | 325 | } | ||
1132 | 326 | |||
1133 | 327 | if (!priv->connected) { | ||
1134 | 328 | priv->connected = TRUE; | ||
1135 | 329 | g_signal_emit(G_OBJECT(user_data), signals[CONNECTION_CHANGE], 0, TRUE, TRUE); | ||
1136 | 330 | } | ||
1137 | 331 | |||
1138 | 332 | return; | ||
1139 | 333 | } | ||
1140 | 334 | |||
1141 | 335 | /* The callback after asking the dbus-daemon to start a | ||
1142 | 336 | service for us. It can return success or failure, on | ||
1143 | 337 | failure we can't do much. But, with sucess, we start | ||
1144 | 338 | to build a proxy and tell the service that we're watching. */ | ||
1145 | 339 | static void | ||
1146 | 340 | start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer user_data) | ||
1147 | 341 | { | ||
1148 | 342 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); | ||
1149 | 343 | |||
1150 | 344 | if (error != NULL) { | ||
1151 | 345 | g_warning("Unable to start service '%s': %s", priv->name, error->message); | ||
1152 | 346 | return; | ||
1153 | 347 | } | ||
1154 | 348 | |||
1155 | 349 | if (status != DBUS_START_REPLY_SUCCESS && status != DBUS_START_REPLY_ALREADY_RUNNING) { | ||
1156 | 350 | g_warning("Status of starting the process '%s' was an error: %d", priv->name, status); | ||
1157 | 351 | return; | ||
1158 | 352 | } | ||
1159 | 353 | |||
1160 | 354 | /* Woot! it's running. Let's do it some more. */ | ||
1161 | 355 | priv->service_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, | ||
1162 | 356 | priv->name, | ||
1163 | 357 | INDICATOR_SERVICE_OBJECT, | ||
1164 | 358 | INDICATOR_SERVICE_INTERFACE, | ||
1165 | 359 | &error); | ||
1166 | 360 | g_object_add_weak_pointer(G_OBJECT(priv->service_proxy), (gpointer *)&(priv->service_proxy)); | ||
1167 | 361 | |||
1168 | 362 | org_ayatana_indicator_service_watch_async(priv->service_proxy, | ||
1169 | 363 | watch_cb, | ||
1170 | 364 | user_data); | ||
1171 | 365 | |||
1172 | 366 | return; | ||
1173 | 367 | } | ||
1174 | 368 | |||
1175 | 369 | /* The function that handles getting us connected to the service. | ||
1176 | 370 | In many cases it will start the service, but if the service | ||
1177 | 371 | is already there it just allocates the service proxy and acts | ||
1178 | 372 | like it was no big deal. */ | ||
1179 | 373 | static void | ||
1180 | 374 | start_service (IndicatorServiceManager * service) | ||
1181 | 375 | { | ||
1182 | 376 | GError * error = NULL; | ||
1183 | 377 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(service); | ||
1184 | 378 | |||
1185 | 379 | g_return_if_fail(priv->dbus_proxy != NULL); | ||
1186 | 380 | g_return_if_fail(priv->name != NULL); | ||
1187 | 381 | |||
1188 | 382 | /* Check to see if we can get a proxy to it first. */ | ||
1189 | 383 | priv->service_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, | ||
1190 | 384 | priv->name, | ||
1191 | 385 | INDICATOR_SERVICE_OBJECT, | ||
1192 | 386 | INDICATOR_SERVICE_INTERFACE, | ||
1193 | 387 | &error); | ||
1194 | 388 | |||
1195 | 389 | if (error != NULL) { | ||
1196 | 390 | /* We don't care about the error, just start the service anyway. */ | ||
1197 | 391 | g_error_free(error); | ||
1198 | 392 | org_freedesktop_DBus_start_service_by_name_async (priv->dbus_proxy, | ||
1199 | 393 | priv->name, | ||
1200 | 394 | 0, | ||
1201 | 395 | start_service_cb, | ||
1202 | 396 | service); | ||
1203 | 397 | } else { | ||
1204 | 398 | g_object_add_weak_pointer(G_OBJECT(priv->service_proxy), (gpointer *)&(priv->service_proxy)); | ||
1205 | 399 | |||
1206 | 400 | /* If we got a proxy just because we're good people then | ||
1207 | 401 | we need to call watch on it just like 'start_service_cb' | ||
1208 | 402 | does. */ | ||
1209 | 403 | org_ayatana_indicator_service_watch_async(priv->service_proxy, | ||
1210 | 404 | watch_cb, | ||
1211 | 405 | service); | ||
1212 | 406 | } | ||
1213 | 407 | |||
1214 | 408 | return; | ||
1215 | 409 | } | ||
1216 | 410 | |||
1217 | 411 | /* API */ | ||
1218 | 412 | |||
1219 | 413 | /** | ||
1220 | 414 | indicator_service_manager_new: | ||
1221 | 415 | @dbus_name: The well known name of the service on DBus | ||
1222 | 416 | |||
1223 | 417 | This creates a new service manager object. If the service | ||
1224 | 418 | is not running it will start it. No matter what, it will | ||
1225 | 419 | give a IndicatorServiceManager::connection-changed event | ||
1226 | 420 | signal when it gets connected. | ||
1227 | 421 | |||
1228 | 422 | Return value: A brand new lovely #IndicatorServiceManager | ||
1229 | 423 | object. | ||
1230 | 424 | */ | ||
1231 | 425 | IndicatorServiceManager * | ||
1232 | 426 | indicator_service_manager_new (gchar * dbus_name) | ||
1233 | 427 | { | ||
1234 | 428 | GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE, | ||
1235 | 429 | PROP_NAME_S, dbus_name, | ||
1236 | 430 | NULL); | ||
1237 | 431 | |||
1238 | 432 | return INDICATOR_SERVICE_MANAGER(obj); | ||
1239 | 433 | } | ||
1240 | 434 | |||
1241 | 435 | /** | ||
1242 | 436 | inicator_service_manager_new_version: | ||
1243 | 437 | @dbus_name: The well known name of the service on DBus | ||
1244 | 438 | @version: Version of the service we expect | ||
1245 | 439 | |||
1246 | 440 | This creates a new service manager object. It also sets | ||
1247 | 441 | the version of the service that we're expecting to see. | ||
1248 | 442 | In general, it behaves similarly to #indicator_service_manager_new() | ||
1249 | 443 | except that it checks @version against the version returned | ||
1250 | 444 | by the service. | ||
1251 | 445 | |||
1252 | 446 | Return value: A brand new lovely #IndicatorServiceManager | ||
1253 | 447 | object. | ||
1254 | 448 | */ | ||
1255 | 449 | IndicatorServiceManager * | ||
1256 | 450 | indicator_service_manager_new_version (gchar * dbus_name, guint version) | ||
1257 | 451 | { | ||
1258 | 452 | GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE, | ||
1259 | 453 | PROP_NAME_S, dbus_name, | ||
1260 | 454 | PROP_VERSION_S, version, | ||
1261 | 455 | NULL); | ||
1262 | 456 | |||
1263 | 457 | return INDICATOR_SERVICE_MANAGER(obj); | ||
1264 | 458 | } | ||
1265 | 459 | |||
1266 | 460 | /** | ||
1267 | 461 | indicator_service_manager_connected: | ||
1268 | 462 | @sm: #IndicatorServiceManager object to check | ||
1269 | 463 | |||
1270 | 464 | Checks to see if the service manager is connected to a | ||
1271 | 465 | service. | ||
1272 | 466 | |||
1273 | 467 | Return value: #TRUE if there is a service connceted. | ||
1274 | 468 | */ | ||
1275 | 469 | gboolean | ||
1276 | 470 | indicator_service_manager_connected (IndicatorServiceManager * sm) | ||
1277 | 471 | { | ||
1278 | 472 | g_return_val_if_fail(INDICATOR_IS_SERVICE_MANAGER(sm), FALSE); | ||
1279 | 473 | IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(sm); | ||
1280 | 474 | return priv->connected; | ||
1281 | 475 | } | ||
1282 | 476 | |||
1283 | 477 | /** | ||
1284 | 478 | indicator_service_manager_set_refresh: | ||
1285 | 479 | @sm: #IndicatorServiceManager object to configure | ||
1286 | 480 | @time_in_ms: The refresh time in milliseconds | ||
1287 | 481 | |||
1288 | 482 | Use this function to set the amount of time between restarting | ||
1289 | 483 | services that may crash or shutdown. This is mostly useful | ||
1290 | 484 | for testing and development. | ||
1291 | 485 | |||
1292 | 486 | NOTE: Not yet implemented. | ||
1293 | 487 | */ | ||
1294 | 488 | void | ||
1295 | 489 | indicator_service_manager_set_refresh (IndicatorServiceManager * sm, guint time_in_ms) | ||
1296 | 490 | { | ||
1297 | 491 | |||
1298 | 492 | return; | ||
1299 | 493 | } | ||
1300 | 0 | 494 | ||
1301 | === added file 'libindicator/indicator-service-manager.h' | |||
1302 | --- libindicator/indicator-service-manager.h 1970-01-01 00:00:00 +0000 | |||
1303 | +++ libindicator/indicator-service-manager.h 2009-12-10 17:02:12 +0000 | |||
1304 | @@ -0,0 +1,88 @@ | |||
1305 | 1 | /* | ||
1306 | 2 | An object used to manage services. Either start them or | ||
1307 | 3 | just connect to them. | ||
1308 | 4 | |||
1309 | 5 | Copyright 2009 Canonical Ltd. | ||
1310 | 6 | |||
1311 | 7 | Authors: | ||
1312 | 8 | Ted Gould <ted@canonical.com> | ||
1313 | 9 | |||
1314 | 10 | This library is free software; you can redistribute it and/or | ||
1315 | 11 | modify it under the terms of the GNU General Public License | ||
1316 | 12 | version 3.0 as published by the Free Software Foundation. | ||
1317 | 13 | |||
1318 | 14 | This library is distributed in the hope that it will be useful, | ||
1319 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1320 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1321 | 17 | GNU General Public License version 3.0 for more details. | ||
1322 | 18 | |||
1323 | 19 | You should have received a copy of the GNU General Public | ||
1324 | 20 | License along with this library. If not, see | ||
1325 | 21 | <http://www.gnu.org/licenses/>. | ||
1326 | 22 | */ | ||
1327 | 23 | |||
1328 | 24 | #ifndef __INDICATOR_SERVICE_MANAGER_H__ | ||
1329 | 25 | #define __INDICATOR_SERVICE_MANAGER_H__ | ||
1330 | 26 | |||
1331 | 27 | #include <glib.h> | ||
1332 | 28 | #include <glib-object.h> | ||
1333 | 29 | |||
1334 | 30 | G_BEGIN_DECLS | ||
1335 | 31 | |||
1336 | 32 | #define INDICATOR_SERVICE_MANAGER_TYPE (indicator_service_manager_get_type ()) | ||
1337 | 33 | #define INDICATOR_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManager)) | ||
1338 | 34 | #define INDICATOR_SERVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerClass)) | ||
1339 | 35 | #define INDICATOR_IS_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_MANAGER_TYPE)) | ||
1340 | 36 | #define INDICATOR_IS_SERVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_MANAGER_TYPE)) | ||
1341 | 37 | #define INDICATOR_SERVICE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerClass)) | ||
1342 | 38 | |||
1343 | 39 | #define INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE "connection-change" | ||
1344 | 40 | |||
1345 | 41 | typedef struct _IndicatorServiceManager IndicatorServiceManager; | ||
1346 | 42 | typedef struct _IndicatorServiceManagerClass IndicatorServiceManagerClass; | ||
1347 | 43 | |||
1348 | 44 | /** | ||
1349 | 45 | IndicatorServiceManagerClass: | ||
1350 | 46 | @parent: #GObjectClass | ||
1351 | 47 | @connection_changed: Slot for #IndicatorServiceManager::connection-changed. | ||
1352 | 48 | @indicator_service_manager_reserved1: Reserved for future use. | ||
1353 | 49 | @indicator_service_manager_reserved2: Reserved for future use. | ||
1354 | 50 | @indicator_service_manager_reserved3: Reserved for future use. | ||
1355 | 51 | @indicator_service_manager_reserved4: Reserved for future use. | ||
1356 | 52 | |||
1357 | 53 | */ | ||
1358 | 54 | struct _IndicatorServiceManagerClass { | ||
1359 | 55 | GObjectClass parent_class; | ||
1360 | 56 | |||
1361 | 57 | /* Signals */ | ||
1362 | 58 | void (*connection_change) (IndicatorServiceManager * sm, gboolean connected, gpointer user_data); | ||
1363 | 59 | |||
1364 | 60 | /* Buffer */ | ||
1365 | 61 | void (*indicator_service_manager_reserved1) (void); | ||
1366 | 62 | void (*indicator_service_manager_reserved2) (void); | ||
1367 | 63 | void (*indicator_service_manager_reserved3) (void); | ||
1368 | 64 | void (*indicator_service_manager_reserved4) (void); | ||
1369 | 65 | }; | ||
1370 | 66 | |||
1371 | 67 | /** | ||
1372 | 68 | IndicatorServiceManager: | ||
1373 | 69 | @parent: #GObject | ||
1374 | 70 | |||
1375 | 71 | */ | ||
1376 | 72 | struct _IndicatorServiceManager { | ||
1377 | 73 | GObject parent; | ||
1378 | 74 | |||
1379 | 75 | }; | ||
1380 | 76 | |||
1381 | 77 | GType indicator_service_manager_get_type (void); | ||
1382 | 78 | |||
1383 | 79 | IndicatorServiceManager * indicator_service_manager_new (gchar * dbus_name); | ||
1384 | 80 | IndicatorServiceManager * indicator_service_manager_new_version (gchar * dbus_name, | ||
1385 | 81 | guint version); | ||
1386 | 82 | gboolean indicator_service_manager_connected (IndicatorServiceManager * sm); | ||
1387 | 83 | void indicator_service_manager_set_refresh (IndicatorServiceManager * sm, | ||
1388 | 84 | guint time_in_ms); | ||
1389 | 85 | |||
1390 | 86 | G_END_DECLS | ||
1391 | 87 | |||
1392 | 88 | #endif | ||
1393 | 0 | 89 | ||
1394 | === added file 'libindicator/indicator-service.c' | |||
1395 | --- libindicator/indicator-service.c 1970-01-01 00:00:00 +0000 | |||
1396 | +++ libindicator/indicator-service.c 2009-12-10 17:02:12 +0000 | |||
1397 | @@ -0,0 +1,479 @@ | |||
1398 | 1 | /* | ||
1399 | 2 | An object used to provide a simple interface for a service | ||
1400 | 3 | to query version and manage whether it's running. | ||
1401 | 4 | |||
1402 | 5 | Copyright 2009 Canonical Ltd. | ||
1403 | 6 | |||
1404 | 7 | Authors: | ||
1405 | 8 | Ted Gould <ted@canonical.com> | ||
1406 | 9 | |||
1407 | 10 | This library is free software; you can redistribute it and/or | ||
1408 | 11 | modify it under the terms of the GNU General Public License | ||
1409 | 12 | version 3.0 as published by the Free Software Foundation. | ||
1410 | 13 | |||
1411 | 14 | This library is distributed in the hope that it will be useful, | ||
1412 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1413 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1414 | 17 | GNU General Public License version 3.0 for more details. | ||
1415 | 18 | |||
1416 | 19 | You should have received a copy of the GNU General Public | ||
1417 | 20 | License along with this library. If not, see | ||
1418 | 21 | <http://www.gnu.org/licenses/>. | ||
1419 | 22 | */ | ||
1420 | 23 | |||
1421 | 24 | #ifdef HAVE_CONFIG_H | ||
1422 | 25 | #include "config.h" | ||
1423 | 26 | #endif | ||
1424 | 27 | #include <dbus/dbus-glib-bindings.h> | ||
1425 | 28 | #include <dbus/dbus-glib-lowlevel.h> | ||
1426 | 29 | |||
1427 | 30 | #include "indicator-service.h" | ||
1428 | 31 | |||
1429 | 32 | /* DBus Prototypes */ | ||
1430 | 33 | static gboolean _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method); | ||
1431 | 34 | static gboolean _indicator_service_server_un_watch (IndicatorService * service, DBusGMethodInvocation * method); | ||
1432 | 35 | |||
1433 | 36 | #include "indicator-service-server.h" | ||
1434 | 37 | #include "dbus-shared.h" | ||
1435 | 38 | |||
1436 | 39 | /* Private Stuff */ | ||
1437 | 40 | /** | ||
1438 | 41 | IndicatorSevicePrivate: | ||
1439 | 42 | @name: The DBus well known name for the service. | ||
1440 | 43 | @dbus_proxy: A proxy for talking to the dbus bus manager. | ||
1441 | 44 | @timeout: The source ID for the timeout event. | ||
1442 | 45 | @watcher: A list of processes on dbus that are watching us. | ||
1443 | 46 | @this_service_version: The version to hand out that we're | ||
1444 | 47 | implementing. May not be set, so we'll send zero (default). | ||
1445 | 48 | */ | ||
1446 | 49 | typedef struct _IndicatorServicePrivate IndicatorServicePrivate; | ||
1447 | 50 | struct _IndicatorServicePrivate { | ||
1448 | 51 | gchar * name; | ||
1449 | 52 | DBusGProxy * dbus_proxy; | ||
1450 | 53 | guint timeout; | ||
1451 | 54 | GList * watchers; | ||
1452 | 55 | guint this_service_version; | ||
1453 | 56 | }; | ||
1454 | 57 | |||
1455 | 58 | /* Signals Stuff */ | ||
1456 | 59 | enum { | ||
1457 | 60 | SHUTDOWN, | ||
1458 | 61 | LAST_SIGNAL | ||
1459 | 62 | }; | ||
1460 | 63 | |||
1461 | 64 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
1462 | 65 | |||
1463 | 66 | /* Properties */ | ||
1464 | 67 | /* Enum for the properties so that they can be quickly | ||
1465 | 68 | found and looked up. */ | ||
1466 | 69 | enum { | ||
1467 | 70 | PROP_0, | ||
1468 | 71 | PROP_NAME, | ||
1469 | 72 | PROP_VERSION | ||
1470 | 73 | }; | ||
1471 | 74 | |||
1472 | 75 | /* The strings so that they can be slowly looked up. */ | ||
1473 | 76 | #define PROP_NAME_S "name" | ||
1474 | 77 | #define PROP_VERSION_S "version" | ||
1475 | 78 | |||
1476 | 79 | /* GObject Stuff */ | ||
1477 | 80 | #define INDICATOR_SERVICE_GET_PRIVATE(o) \ | ||
1478 | 81 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SERVICE_TYPE, IndicatorServicePrivate)) | ||
1479 | 82 | |||
1480 | 83 | static void indicator_service_class_init (IndicatorServiceClass *klass); | ||
1481 | 84 | static void indicator_service_init (IndicatorService *self); | ||
1482 | 85 | static void indicator_service_dispose (GObject *object); | ||
1483 | 86 | static void indicator_service_finalize (GObject *object); | ||
1484 | 87 | |||
1485 | 88 | /* Other prototypes */ | ||
1486 | 89 | static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); | ||
1487 | 90 | static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); | ||
1488 | 91 | static void try_and_get_name (IndicatorService * service); | ||
1489 | 92 | |||
1490 | 93 | G_DEFINE_TYPE (IndicatorService, indicator_service, G_TYPE_OBJECT); | ||
1491 | 94 | |||
1492 | 95 | static void | ||
1493 | 96 | indicator_service_class_init (IndicatorServiceClass *klass) | ||
1494 | 97 | { | ||
1495 | 98 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
1496 | 99 | |||
1497 | 100 | g_type_class_add_private (klass, sizeof (IndicatorServicePrivate)); | ||
1498 | 101 | |||
1499 | 102 | object_class->dispose = indicator_service_dispose; | ||
1500 | 103 | object_class->finalize = indicator_service_finalize; | ||
1501 | 104 | |||
1502 | 105 | /* Property funcs */ | ||
1503 | 106 | object_class->set_property = set_property; | ||
1504 | 107 | object_class->get_property = get_property; | ||
1505 | 108 | |||
1506 | 109 | /* Properties */ | ||
1507 | 110 | g_object_class_install_property(object_class, PROP_NAME, | ||
1508 | 111 | g_param_spec_string(PROP_NAME_S, | ||
1509 | 112 | "The DBus name for this service", | ||
1510 | 113 | "This is the name that should be used on DBus for this service.", | ||
1511 | 114 | NULL, | ||
1512 | 115 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
1513 | 116 | g_object_class_install_property(object_class, PROP_VERSION, | ||
1514 | 117 | g_param_spec_uint(PROP_VERSION_S, | ||
1515 | 118 | "The version of the service that we're implementing.", | ||
1516 | 119 | "A number to represent the version of the other APIs the service provides. This should match across the manager and the service", | ||
1517 | 120 | 0, G_MAXUINT, 0, | ||
1518 | 121 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
1519 | 122 | |||
1520 | 123 | /* Signals */ | ||
1521 | 124 | |||
1522 | 125 | /** | ||
1523 | 126 | IndicatorService::shutdown: | ||
1524 | 127 | @arg0: The #IndicatorService object | ||
1525 | 128 | |||
1526 | 129 | Signaled when the service should shutdown as no one | ||
1527 | 130 | is listening anymore. | ||
1528 | 131 | */ | ||
1529 | 132 | signals[SHUTDOWN] = g_signal_new (INDICATOR_SERVICE_SIGNAL_SHUTDOWN, | ||
1530 | 133 | G_TYPE_FROM_CLASS(klass), | ||
1531 | 134 | G_SIGNAL_RUN_LAST, | ||
1532 | 135 | G_STRUCT_OFFSET (IndicatorServiceClass, shutdown), | ||
1533 | 136 | NULL, NULL, | ||
1534 | 137 | g_cclosure_marshal_VOID__VOID, | ||
1535 | 138 | G_TYPE_NONE, 0, G_TYPE_NONE); | ||
1536 | 139 | |||
1537 | 140 | /* Initialize the object as a DBus type */ | ||
1538 | 141 | dbus_g_object_type_install_info(INDICATOR_SERVICE_TYPE, | ||
1539 | 142 | &dbus_glib__indicator_service_server_object_info); | ||
1540 | 143 | |||
1541 | 144 | return; | ||
1542 | 145 | } | ||
1543 | 146 | |||
1544 | 147 | /* This function builds the variables, sets up the dbus | ||
1545 | 148 | proxy and registers the object on dbus. Importantly, | ||
1546 | 149 | it does not request a name as we don't know what name | ||
1547 | 150 | we have yet. */ | ||
1548 | 151 | static void | ||
1549 | 152 | indicator_service_init (IndicatorService *self) | ||
1550 | 153 | { | ||
1551 | 154 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self); | ||
1552 | 155 | |||
1553 | 156 | /* Get the private variables in a decent state */ | ||
1554 | 157 | priv->name = NULL; | ||
1555 | 158 | priv->dbus_proxy = NULL; | ||
1556 | 159 | priv->timeout = 0; | ||
1557 | 160 | priv->watchers = NULL; | ||
1558 | 161 | priv->this_service_version = 0; | ||
1559 | 162 | |||
1560 | 163 | /* Start talkin' dbus */ | ||
1561 | 164 | GError * error = NULL; | ||
1562 | 165 | DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error); | ||
1563 | 166 | if (error != NULL) { | ||
1564 | 167 | g_error("Unable to get starter bus: %s", error->message); | ||
1565 | 168 | g_error_free(error); | ||
1566 | 169 | |||
1567 | 170 | /* Okay, fine let's try the session bus then. */ | ||
1568 | 171 | /* I think this should automatically, but I can't find confirmation | ||
1569 | 172 | of that, so we're putting the extra little code in here. */ | ||
1570 | 173 | error = NULL; | ||
1571 | 174 | bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); | ||
1572 | 175 | if (error != NULL) { | ||
1573 | 176 | g_error("Unable to get session bus: %s", error->message); | ||
1574 | 177 | g_error_free(error); | ||
1575 | 178 | return; | ||
1576 | 179 | } | ||
1577 | 180 | } | ||
1578 | 181 | |||
1579 | 182 | priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(bus, | ||
1580 | 183 | DBUS_SERVICE_DBUS, | ||
1581 | 184 | DBUS_PATH_DBUS, | ||
1582 | 185 | DBUS_INTERFACE_DBUS, | ||
1583 | 186 | &error); | ||
1584 | 187 | if (error != NULL) { | ||
1585 | 188 | g_error("Unable to get the proxy to DBus: %s", error->message); | ||
1586 | 189 | g_error_free(error); | ||
1587 | 190 | return; | ||
1588 | 191 | } | ||
1589 | 192 | |||
1590 | 193 | dbus_g_connection_register_g_object(bus, | ||
1591 | 194 | INDICATOR_SERVICE_OBJECT, | ||
1592 | 195 | G_OBJECT(self)); | ||
1593 | 196 | |||
1594 | 197 | return; | ||
1595 | 198 | } | ||
1596 | 199 | |||
1597 | 200 | /* Unrefcounting the proxies and making sure that our | ||
1598 | 201 | timeout doesn't come to haunt us. */ | ||
1599 | 202 | static void | ||
1600 | 203 | indicator_service_dispose (GObject *object) | ||
1601 | 204 | { | ||
1602 | 205 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object); | ||
1603 | 206 | |||
1604 | 207 | if (priv->dbus_proxy != NULL) { | ||
1605 | 208 | g_object_unref(G_OBJECT(priv->dbus_proxy)); | ||
1606 | 209 | priv->dbus_proxy = NULL; | ||
1607 | 210 | } | ||
1608 | 211 | |||
1609 | 212 | if (priv->timeout != 0) { | ||
1610 | 213 | g_source_remove(priv->timeout); | ||
1611 | 214 | priv->timeout = 0; | ||
1612 | 215 | } | ||
1613 | 216 | |||
1614 | 217 | G_OBJECT_CLASS (indicator_service_parent_class)->dispose (object); | ||
1615 | 218 | return; | ||
1616 | 219 | } | ||
1617 | 220 | |||
1618 | 221 | /* Freeing the name we're looking for and all of the | ||
1619 | 222 | information on the watchers we're tracking. */ | ||
1620 | 223 | static void | ||
1621 | 224 | indicator_service_finalize (GObject *object) | ||
1622 | 225 | { | ||
1623 | 226 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object); | ||
1624 | 227 | |||
1625 | 228 | if (priv->name != NULL) { | ||
1626 | 229 | g_free(priv->name); | ||
1627 | 230 | } | ||
1628 | 231 | |||
1629 | 232 | if (priv->watchers != NULL) { | ||
1630 | 233 | g_list_foreach(priv->watchers, (GFunc)g_free, NULL); | ||
1631 | 234 | g_list_free(priv->watchers); | ||
1632 | 235 | priv->watchers = NULL; | ||
1633 | 236 | } | ||
1634 | 237 | |||
1635 | 238 | G_OBJECT_CLASS (indicator_service_parent_class)->finalize (object); | ||
1636 | 239 | return; | ||
1637 | 240 | } | ||
1638 | 241 | |||
1639 | 242 | /* Either copies a string for the name or it just grabs | ||
1640 | 243 | the value of the version. */ | ||
1641 | 244 | static void | ||
1642 | 245 | set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) | ||
1643 | 246 | { | ||
1644 | 247 | IndicatorService * self = INDICATOR_SERVICE(object); | ||
1645 | 248 | g_return_if_fail(self != NULL); | ||
1646 | 249 | |||
1647 | 250 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self); | ||
1648 | 251 | g_return_if_fail(priv != NULL); | ||
1649 | 252 | |||
1650 | 253 | switch (prop_id) { | ||
1651 | 254 | /* *********************** */ | ||
1652 | 255 | case PROP_NAME: | ||
1653 | 256 | if (G_VALUE_HOLDS_STRING(value)) { | ||
1654 | 257 | if (priv->name != NULL) { | ||
1655 | 258 | g_error("Name can not be set twice!"); | ||
1656 | 259 | return; | ||
1657 | 260 | } | ||
1658 | 261 | priv->name = g_value_dup_string(value); | ||
1659 | 262 | try_and_get_name(self); | ||
1660 | 263 | } else { | ||
1661 | 264 | g_warning("Name property requires a string value."); | ||
1662 | 265 | } | ||
1663 | 266 | break; | ||
1664 | 267 | /* *********************** */ | ||
1665 | 268 | case PROP_VERSION: | ||
1666 | 269 | priv->this_service_version = g_value_get_uint(value); | ||
1667 | 270 | break; | ||
1668 | 271 | /* *********************** */ | ||
1669 | 272 | default: | ||
1670 | 273 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1671 | 274 | break; | ||
1672 | 275 | } | ||
1673 | 276 | |||
1674 | 277 | return; | ||
1675 | 278 | } | ||
1676 | 279 | |||
1677 | 280 | /* Copies out the name into a value or the version number. | ||
1678 | 281 | Probably this is the least useful code in this file. */ | ||
1679 | 282 | static void | ||
1680 | 283 | get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) | ||
1681 | 284 | { | ||
1682 | 285 | IndicatorService * self = INDICATOR_SERVICE(object); | ||
1683 | 286 | g_return_if_fail(self != NULL); | ||
1684 | 287 | |||
1685 | 288 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self); | ||
1686 | 289 | g_return_if_fail(priv != NULL); | ||
1687 | 290 | |||
1688 | 291 | switch (prop_id) { | ||
1689 | 292 | /* *********************** */ | ||
1690 | 293 | case PROP_NAME: | ||
1691 | 294 | if (G_VALUE_HOLDS_STRING(value)) { | ||
1692 | 295 | g_value_set_string(value, priv->name); | ||
1693 | 296 | } else { | ||
1694 | 297 | g_warning("Name property requires a string value."); | ||
1695 | 298 | } | ||
1696 | 299 | break; | ||
1697 | 300 | /* *********************** */ | ||
1698 | 301 | case PROP_VERSION: | ||
1699 | 302 | g_value_set_uint(value, priv->this_service_version); | ||
1700 | 303 | break; | ||
1701 | 304 | /* *********************** */ | ||
1702 | 305 | default: | ||
1703 | 306 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1704 | 307 | break; | ||
1705 | 308 | } | ||
1706 | 309 | |||
1707 | 310 | return; | ||
1708 | 311 | } | ||
1709 | 312 | |||
1710 | 313 | /* This is the function that gets executed if we timeout | ||
1711 | 314 | because there are no watchers. We sent the shutdown | ||
1712 | 315 | signal and hope someone does something sane with it. */ | ||
1713 | 316 | static gboolean | ||
1714 | 317 | timeout_no_watchers (gpointer data) | ||
1715 | 318 | { | ||
1716 | 319 | g_signal_emit(G_OBJECT(data), signals[SHUTDOWN], 0, TRUE); | ||
1717 | 320 | return FALSE; | ||
1718 | 321 | } | ||
1719 | 322 | |||
1720 | 323 | /* The callback from our request to get a well known name | ||
1721 | 324 | on dbus. If we can't get it we send the shutdown signal. | ||
1722 | 325 | Else we start the timer to see if anyone cares about us. */ | ||
1723 | 326 | static void | ||
1724 | 327 | try_and_get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data) | ||
1725 | 328 | { | ||
1726 | 329 | IndicatorService * service = INDICATOR_SERVICE(data); | ||
1727 | 330 | g_return_if_fail(service != NULL); | ||
1728 | 331 | |||
1729 | 332 | if (status != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && status != DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) { | ||
1730 | 333 | /* The already owner seems like it shouldn't ever | ||
1731 | 334 | happen, but I have a hard time throwing an error | ||
1732 | 335 | on it as we did achieve our goals. */ | ||
1733 | 336 | g_signal_emit(G_OBJECT(data), signals[SHUTDOWN], 0, TRUE); | ||
1734 | 337 | return; | ||
1735 | 338 | } | ||
1736 | 339 | |||
1737 | 340 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service); | ||
1738 | 341 | priv->timeout = g_timeout_add(500, timeout_no_watchers, service); | ||
1739 | 342 | |||
1740 | 343 | return; | ||
1741 | 344 | } | ||
1742 | 345 | |||
1743 | 346 | /* This function sets up the request for the name on dbus. */ | ||
1744 | 347 | static void | ||
1745 | 348 | try_and_get_name (IndicatorService * service) | ||
1746 | 349 | { | ||
1747 | 350 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service); | ||
1748 | 351 | g_return_if_fail(priv->dbus_proxy != NULL); | ||
1749 | 352 | g_return_if_fail(priv->name != NULL); | ||
1750 | 353 | |||
1751 | 354 | org_freedesktop_DBus_request_name_async(priv->dbus_proxy, | ||
1752 | 355 | priv->name, | ||
1753 | 356 | DBUS_NAME_FLAG_DO_NOT_QUEUE, | ||
1754 | 357 | try_and_get_name_cb, | ||
1755 | 358 | service); | ||
1756 | 359 | |||
1757 | 360 | return; | ||
1758 | 361 | } | ||
1759 | 362 | |||
1760 | 363 | /* Here is the function that gets called by the dbus | ||
1761 | 364 | interface "Watch" function. It is an async function so | ||
1762 | 365 | that we can get the sender and store that information. We | ||
1763 | 366 | put them in a list and reset the timeout. */ | ||
1764 | 367 | static gboolean | ||
1765 | 368 | _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method) | ||
1766 | 369 | { | ||
1767 | 370 | g_return_val_if_fail(INDICATOR_IS_SERVICE(service), FALSE); | ||
1768 | 371 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service); | ||
1769 | 372 | |||
1770 | 373 | priv->watchers = g_list_append(priv->watchers, | ||
1771 | 374 | g_strdup(dbus_g_method_get_sender(method))); | ||
1772 | 375 | |||
1773 | 376 | if (priv->timeout != 0) { | ||
1774 | 377 | g_source_remove(priv->timeout); | ||
1775 | 378 | priv->timeout = 0; | ||
1776 | 379 | } | ||
1777 | 380 | |||
1778 | 381 | dbus_g_method_return(method, INDICATOR_SERVICE_VERSION, priv->this_service_version); | ||
1779 | 382 | return TRUE; | ||
1780 | 383 | } | ||
1781 | 384 | |||
1782 | 385 | /* Mung g_strcmp0 into GCompareFunc */ | ||
1783 | 386 | static gint | ||
1784 | 387 | find_watcher (gconstpointer a, gconstpointer b) | ||
1785 | 388 | { | ||
1786 | 389 | return g_strcmp0((const gchar *)a, (const gchar *)b); | ||
1787 | 390 | } | ||
1788 | 391 | |||
1789 | 392 | /* A function connecting into the dbus interface for the | ||
1790 | 393 | "UnWatch" function. It is also an async function to get | ||
1791 | 394 | the sender. It then looks the sender up and removes them | ||
1792 | 395 | from the list of watchers. If there are none left, it then | ||
1793 | 396 | starts the timer for the shutdown signal. */ | ||
1794 | 397 | static gboolean | ||
1795 | 398 | _indicator_service_server_un_watch (IndicatorService * service, DBusGMethodInvocation * method) | ||
1796 | 399 | { | ||
1797 | 400 | g_return_val_if_fail(INDICATOR_IS_SERVICE(service), FALSE); | ||
1798 | 401 | IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service); | ||
1799 | 402 | |||
1800 | 403 | /* Remove us from the watcher list here */ | ||
1801 | 404 | GList * watcher_item = g_list_find_custom(priv->watchers, dbus_g_method_get_sender(method), find_watcher); | ||
1802 | 405 | if (watcher_item != NULL) { | ||
1803 | 406 | /* Free the watcher */ | ||
1804 | 407 | gchar * name = watcher_item->data; | ||
1805 | 408 | priv->watchers = g_list_remove(priv->watchers, name); | ||
1806 | 409 | g_free(name); | ||
1807 | 410 | } else { | ||
1808 | 411 | /* Odd that we couldn't find the person, but, eh */ | ||
1809 | 412 | g_warning("Unable to find watcher who is unwatching: %s", dbus_g_method_get_sender(method)); | ||
1810 | 413 | } | ||
1811 | 414 | |||
1812 | 415 | /* If we're out of watchers set the timeout for shutdown */ | ||
1813 | 416 | if (priv->watchers == NULL) { | ||
1814 | 417 | if (priv->timeout != 0) { | ||
1815 | 418 | /* This should never really happen, but let's ensure that | ||
1816 | 419 | bad things don't happen if it does. */ | ||
1817 | 420 | g_warning("No watchers timeout set twice. Resolving, but odd."); | ||
1818 | 421 | g_source_remove(priv->timeout); | ||
1819 | 422 | priv->timeout = 0; | ||
1820 | 423 | } | ||
1821 | 424 | /* If we don't get a new watcher quickly, we'll shutdown. */ | ||
1822 | 425 | priv->timeout = g_timeout_add(500, timeout_no_watchers, service); | ||
1823 | 426 | } | ||
1824 | 427 | |||
1825 | 428 | dbus_g_method_return(method); | ||
1826 | 429 | return TRUE; | ||
1827 | 430 | } | ||
1828 | 431 | |||
1829 | 432 | /* API */ | ||
1830 | 433 | |||
1831 | 434 | /** | ||
1832 | 435 | indicator_service_new: | ||
1833 | 436 | @name: The name for the service on dbus | ||
1834 | 437 | |||
1835 | 438 | This function creates the service on DBus and tries to | ||
1836 | 439 | get a well-known name specified in @name. If the name | ||
1837 | 440 | can't be estabilished then the #IndicatorService::shutdown | ||
1838 | 441 | signal will be sent. | ||
1839 | 442 | |||
1840 | 443 | Return value: A brand new #IndicatorService object or #NULL | ||
1841 | 444 | if there is an error. | ||
1842 | 445 | */ | ||
1843 | 446 | IndicatorService * | ||
1844 | 447 | indicator_service_new (gchar * name) | ||
1845 | 448 | { | ||
1846 | 449 | GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE, | ||
1847 | 450 | PROP_NAME_S, name, | ||
1848 | 451 | NULL); | ||
1849 | 452 | |||
1850 | 453 | return INDICATOR_SERVICE(obj); | ||
1851 | 454 | } | ||
1852 | 455 | |||
1853 | 456 | /** | ||
1854 | 457 | indicator_service_new_version: | ||
1855 | 458 | @name: The name for the service on dbus | ||
1856 | 459 | @version: The version of the other interfaces provide | ||
1857 | 460 | by the service. | ||
1858 | 461 | |||
1859 | 462 | This function creates the service on DBus and tries to | ||
1860 | 463 | get a well-known name specified in @name. If the name | ||
1861 | 464 | can't be estabilished then the #IndicatorService::shutdown | ||
1862 | 465 | signal will be sent. | ||
1863 | 466 | |||
1864 | 467 | Return value: A brand new #IndicatorService object or #NULL | ||
1865 | 468 | if there is an error. | ||
1866 | 469 | */ | ||
1867 | 470 | IndicatorService * | ||
1868 | 471 | indicator_service_new_version (gchar * name, guint version) | ||
1869 | 472 | { | ||
1870 | 473 | GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE, | ||
1871 | 474 | PROP_NAME_S, name, | ||
1872 | 475 | PROP_VERSION_S, version, | ||
1873 | 476 | NULL); | ||
1874 | 477 | |||
1875 | 478 | return INDICATOR_SERVICE(obj); | ||
1876 | 479 | } | ||
1877 | 0 | 480 | ||
1878 | === added file 'libindicator/indicator-service.h' | |||
1879 | --- libindicator/indicator-service.h 1970-01-01 00:00:00 +0000 | |||
1880 | +++ libindicator/indicator-service.h 2009-12-10 17:02:12 +0000 | |||
1881 | @@ -0,0 +1,85 @@ | |||
1882 | 1 | /* | ||
1883 | 2 | An object used to provide a simple interface for a service | ||
1884 | 3 | to query version and manage whether it's running. | ||
1885 | 4 | |||
1886 | 5 | Copyright 2009 Canonical Ltd. | ||
1887 | 6 | |||
1888 | 7 | Authors: | ||
1889 | 8 | Ted Gould <ted@canonical.com> | ||
1890 | 9 | |||
1891 | 10 | This library is free software; you can redistribute it and/or | ||
1892 | 11 | modify it under the terms of the GNU General Public License | ||
1893 | 12 | version 3.0 as published by the Free Software Foundation. | ||
1894 | 13 | |||
1895 | 14 | This library is distributed in the hope that it will be useful, | ||
1896 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1897 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1898 | 17 | GNU General Public License version 3.0 for more details. | ||
1899 | 18 | |||
1900 | 19 | You should have received a copy of the GNU General Public | ||
1901 | 20 | License along with this library. If not, see | ||
1902 | 21 | <http://www.gnu.org/licenses/>. | ||
1903 | 22 | */ | ||
1904 | 23 | |||
1905 | 24 | #ifndef __INDICATOR_SERVICE_H__ | ||
1906 | 25 | #define __INDICATOR_SERVICE_H__ | ||
1907 | 26 | |||
1908 | 27 | #include <glib.h> | ||
1909 | 28 | #include <glib-object.h> | ||
1910 | 29 | |||
1911 | 30 | G_BEGIN_DECLS | ||
1912 | 31 | |||
1913 | 32 | #define INDICATOR_SERVICE_TYPE (indicator_service_get_type ()) | ||
1914 | 33 | #define INDICATOR_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SERVICE_TYPE, IndicatorService)) | ||
1915 | 34 | #define INDICATOR_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SERVICE_TYPE, IndicatorServiceClass)) | ||
1916 | 35 | #define INDICATOR_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_TYPE)) | ||
1917 | 36 | #define INDICATOR_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_TYPE)) | ||
1918 | 37 | #define INDICATOR_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SERVICE_TYPE, IndicatorServiceClass)) | ||
1919 | 38 | |||
1920 | 39 | #define INDICATOR_SERVICE_SIGNAL_SHUTDOWN "shutdown" | ||
1921 | 40 | |||
1922 | 41 | typedef struct _IndicatorService IndicatorService; | ||
1923 | 42 | typedef struct _IndicatorServiceClass IndicatorServiceClass; | ||
1924 | 43 | |||
1925 | 44 | /** | ||
1926 | 45 | IndicatorServiceClass: | ||
1927 | 46 | @parent_class: #GObjectClass | ||
1928 | 47 | @shutdown: Slot for IndicatorServiceClass::shutdown | ||
1929 | 48 | @indicator_service_reserved1: Reserved for future use | ||
1930 | 49 | @indicator_service_reserved2: Reserved for future use | ||
1931 | 50 | @indicator_service_reserved3: Reserved for future use | ||
1932 | 51 | @indicator_service_reserved4: Reserved for future use | ||
1933 | 52 | |||
1934 | 53 | */ | ||
1935 | 54 | struct _IndicatorServiceClass { | ||
1936 | 55 | GObjectClass parent_class; | ||
1937 | 56 | |||
1938 | 57 | /* Signals */ | ||
1939 | 58 | void (*shutdown) (IndicatorService * service, gpointer user_data); | ||
1940 | 59 | |||
1941 | 60 | /* Reserved */ | ||
1942 | 61 | void (*indicator_service_reserved1) (void); | ||
1943 | 62 | void (*indicator_service_reserved2) (void); | ||
1944 | 63 | void (*indicator_service_reserved3) (void); | ||
1945 | 64 | void (*indicator_service_reserved4) (void); | ||
1946 | 65 | }; | ||
1947 | 66 | |||
1948 | 67 | /** | ||
1949 | 68 | IndicatorService: | ||
1950 | 69 | @parent: #GObject | ||
1951 | 70 | |||
1952 | 71 | */ | ||
1953 | 72 | struct _IndicatorService { | ||
1954 | 73 | GObject parent; | ||
1955 | 74 | |||
1956 | 75 | }; | ||
1957 | 76 | |||
1958 | 77 | GType indicator_service_get_type (void); | ||
1959 | 78 | |||
1960 | 79 | IndicatorService * indicator_service_new (gchar * name); | ||
1961 | 80 | IndicatorService * indicator_service_new_version (gchar * name, | ||
1962 | 81 | guint version); | ||
1963 | 82 | |||
1964 | 83 | G_END_DECLS | ||
1965 | 84 | |||
1966 | 85 | #endif | ||
1967 | 0 | 86 | ||
1968 | === added file 'libindicator/indicator-service.xml' | |||
1969 | --- libindicator/indicator-service.xml 1970-01-01 00:00:00 +0000 | |||
1970 | +++ libindicator/indicator-service.xml 2009-12-10 17:02:12 +0000 | |||
1971 | @@ -0,0 +1,21 @@ | |||
1972 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1973 | 2 | <node name="/"> | ||
1974 | 3 | <interface name="org.ayatana.indicator.service"> | ||
1975 | 4 | <!-- Properties --> | ||
1976 | 5 | <!-- None currently --> | ||
1977 | 6 | |||
1978 | 7 | <!-- Methods --> | ||
1979 | 8 | <method name="Watch"> | ||
1980 | 9 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> | ||
1981 | 10 | <arg type="u" name="version" direction="out" /> | ||
1982 | 11 | <arg type="u" name="service_version" direction="out" /> | ||
1983 | 12 | </method> | ||
1984 | 13 | <method name="UnWatch"> | ||
1985 | 14 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> | ||
1986 | 15 | </method> | ||
1987 | 16 | |||
1988 | 17 | <!-- Signals --> | ||
1989 | 18 | <!-- None currently --> | ||
1990 | 19 | |||
1991 | 20 | </interface> | ||
1992 | 21 | </node> | ||
1993 | 0 | 22 | ||
1994 | === modified file 'libindicator/indicator.h' | |||
1995 | --- libindicator/indicator.h 2009-10-06 15:00:34 +0000 | |||
1996 | +++ libindicator/indicator.h 2009-12-10 17:02:12 +0000 | |||
1997 | @@ -25,31 +25,17 @@ | |||
1998 | 25 | 25 | ||
1999 | 26 | #include <gtk/gtk.h> | 26 | #include <gtk/gtk.h> |
2000 | 27 | 27 | ||
2001 | 28 | #define INDICATOR_GET_LABEL_S "get_label" | ||
2002 | 29 | typedef GtkLabel * (*get_label_t)(void); | ||
2003 | 30 | GtkLabel * get_label (void); | ||
2004 | 31 | |||
2005 | 32 | #define INDICATOR_GET_ICON_S "get_icon" | ||
2006 | 33 | typedef GtkImage * (*get_icon_t) (void); | ||
2007 | 34 | GtkImage * get_icon (void); | ||
2008 | 35 | |||
2009 | 36 | #define INDICATOR_GET_MENU_S "get_menu" | ||
2010 | 37 | typedef GtkMenu * (*get_menu_t) (void); | ||
2011 | 38 | GtkMenu * get_menu (void); | ||
2012 | 39 | |||
2013 | 40 | #define INDICATOR_GET_VERSION_S "get_version" | 28 | #define INDICATOR_GET_VERSION_S "get_version" |
2014 | 41 | typedef gchar * (*get_version_t) (void); | 29 | typedef gchar * (*get_version_t) (void); |
2015 | 42 | gchar * get_version (void); | 30 | gchar * get_version (void); |
2016 | 43 | 31 | ||
2018 | 44 | #define INDICATOR_VERSION "0.2.0" | 32 | #define INDICATOR_VERSION "0.3.0" |
2019 | 45 | #define INDICATOR_SET_VERSION gchar * get_version(void) { return INDICATOR_VERSION; } | 33 | #define INDICATOR_SET_VERSION gchar * get_version(void) { return INDICATOR_VERSION; } |
2020 | 46 | #define INDICATOR_VERSION_CHECK(x) (!g_strcmp0(x, INDICATOR_VERSION)) | 34 | #define INDICATOR_VERSION_CHECK(x) (!g_strcmp0(x, INDICATOR_VERSION)) |
2021 | 47 | 35 | ||
2027 | 48 | #define INDICATOR_GET_NAME_S "get_name" | 36 | #define INDICATOR_GET_TYPE_S "get_type" |
2028 | 49 | typedef gchar * (*get_name_t) (void); | 37 | typedef GType (*get_type_t) (void); |
2029 | 50 | gchar * get_name (void); | 38 | #define INDICATOR_SET_TYPE(x) GType get_type (void) { return x; } |
2025 | 51 | #define INDICATOR_SET_NAME(x) gchar * get_name(void) {return (x); } | ||
2026 | 52 | |||
2030 | 53 | 39 | ||
2031 | 54 | #endif /* __LIBINDICATOR_INDICATOR_H_SEEN__ */ | 40 | #endif /* __LIBINDICATOR_INDICATOR_H_SEEN__ */ |
2032 | 55 | 41 | ||
2033 | 56 | 42 | ||
2034 | === modified file 'libindicator/indicator.pc.in' | |||
2035 | --- libindicator/indicator.pc.in 2009-08-08 15:55:54 +0000 | |||
2036 | +++ libindicator/indicator.pc.in 2009-12-10 17:02:12 +0000 | |||
2037 | @@ -4,12 +4,12 @@ | |||
2038 | 4 | bindir=@bindir@ | 4 | bindir=@bindir@ |
2039 | 5 | includedir=@includedir@ | 5 | includedir=@includedir@ |
2040 | 6 | 6 | ||
2042 | 7 | indicatordir=${libdir}/indicators/2/ | 7 | indicatordir=${libdir}/indicators/3/ |
2043 | 8 | iconsdir=@datarootdir@/@PACKAGE@/icons/ | 8 | iconsdir=@datarootdir@/@PACKAGE@/icons/ |
2044 | 9 | 9 | ||
2046 | 10 | Cflags: -I${includedir}/libindicator-0.1 | 10 | Cflags: -I${includedir}/libindicator-0.3 |
2047 | 11 | Requires: gtk+-2.0 | 11 | Requires: gtk+-2.0 |
2049 | 12 | Libs: | 12 | Libs: -lindicator |
2050 | 13 | 13 | ||
2051 | 14 | Name: libindicator | 14 | Name: libindicator |
2052 | 15 | Description: libindicator. | 15 | Description: libindicator. |
2053 | 16 | 16 | ||
2054 | === added directory 'tests' | |||
2055 | === added file 'tests/Makefile.am' | |||
2056 | --- tests/Makefile.am 1970-01-01 00:00:00 +0000 | |||
2057 | +++ tests/Makefile.am 2009-12-10 17:02:12 +0000 | |||
2058 | @@ -0,0 +1,308 @@ | |||
2059 | 1 | TESTS = | ||
2060 | 2 | DISTCLEANFILES = | ||
2061 | 3 | |||
2062 | 4 | check_PROGRAMS = | ||
2063 | 5 | |||
2064 | 6 | lib_LTLIBRARIES = \ | ||
2065 | 7 | libdummy-indicator-blank.la \ | ||
2066 | 8 | libdummy-indicator-null.la \ | ||
2067 | 9 | libdummy-indicator-signaler.la \ | ||
2068 | 10 | libdummy-indicator-simple.la | ||
2069 | 11 | |||
2070 | 12 | DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf | ||
2071 | 13 | |||
2072 | 14 | ############################# | ||
2073 | 15 | # Test Loader | ||
2074 | 16 | ############################# | ||
2075 | 17 | |||
2076 | 18 | check_PROGRAMS += test-loader | ||
2077 | 19 | |||
2078 | 20 | test_loader_SOURCES = \ | ||
2079 | 21 | test-loader.c | ||
2080 | 22 | |||
2081 | 23 | test_loader_CFLAGS = \ | ||
2082 | 24 | -Wall -Werror \ | ||
2083 | 25 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ | ||
2084 | 26 | -DBUILD_DIR="\"$(builddir)\"" | ||
2085 | 27 | |||
2086 | 28 | test_loader_LDADD = \ | ||
2087 | 29 | $(LIBINDICATOR_LIBS) \ | ||
2088 | 30 | -L$(top_builddir)/libindicator/.libs \ | ||
2089 | 31 | -lindicator | ||
2090 | 32 | |||
2091 | 33 | ############################# | ||
2092 | 34 | # Dummy Indicator Blank | ||
2093 | 35 | ############################# | ||
2094 | 36 | |||
2095 | 37 | libdummy_indicator_blank_la_SOURCES = \ | ||
2096 | 38 | dummy-indicator-blank.c | ||
2097 | 39 | |||
2098 | 40 | libdummy_indicator_blank_la_CFLAGS = \ | ||
2099 | 41 | -Wall -Werror \ | ||
2100 | 42 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2101 | 43 | |||
2102 | 44 | libdummy_indicator_blank_la_LIBADD = \ | ||
2103 | 45 | $(LIBINDICATOR_LIBS) \ | ||
2104 | 46 | -L$(top_builddir)/libindicator/.libs \ | ||
2105 | 47 | -lindicator | ||
2106 | 48 | |||
2107 | 49 | libdummy_indicator_blank_la_LDFLAGS = \ | ||
2108 | 50 | -module \ | ||
2109 | 51 | -avoid-version | ||
2110 | 52 | |||
2111 | 53 | ############################# | ||
2112 | 54 | # Dummy Indicator NULL | ||
2113 | 55 | ############################# | ||
2114 | 56 | |||
2115 | 57 | libdummy_indicator_null_la_SOURCES = \ | ||
2116 | 58 | dummy-indicator-null.c | ||
2117 | 59 | |||
2118 | 60 | libdummy_indicator_null_la_CFLAGS = \ | ||
2119 | 61 | -Wall -Werror \ | ||
2120 | 62 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2121 | 63 | |||
2122 | 64 | libdummy_indicator_null_la_LIBADD = \ | ||
2123 | 65 | $(LIBINDICATOR_LIBS) \ | ||
2124 | 66 | -L$(top_builddir)/libindicator/.libs \ | ||
2125 | 67 | -lindicator | ||
2126 | 68 | |||
2127 | 69 | libdummy_indicator_null_la_LDFLAGS = \ | ||
2128 | 70 | -module \ | ||
2129 | 71 | -avoid-version | ||
2130 | 72 | |||
2131 | 73 | ############################# | ||
2132 | 74 | # Dummy Indicator Signaler | ||
2133 | 75 | ############################# | ||
2134 | 76 | |||
2135 | 77 | libdummy_indicator_signaler_la_SOURCES = \ | ||
2136 | 78 | dummy-indicator-signaler.c | ||
2137 | 79 | |||
2138 | 80 | libdummy_indicator_signaler_la_CFLAGS = \ | ||
2139 | 81 | -Wall -Werror \ | ||
2140 | 82 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2141 | 83 | |||
2142 | 84 | libdummy_indicator_signaler_la_LIBADD = \ | ||
2143 | 85 | $(LIBINDICATOR_LIBS) \ | ||
2144 | 86 | -L$(top_builddir)/libindicator/.libs \ | ||
2145 | 87 | -lindicator | ||
2146 | 88 | |||
2147 | 89 | libdummy_indicator_signaler_la_LDFLAGS = \ | ||
2148 | 90 | -module \ | ||
2149 | 91 | -avoid-version | ||
2150 | 92 | |||
2151 | 93 | ############################# | ||
2152 | 94 | # Dummy Indicator Simple | ||
2153 | 95 | ############################# | ||
2154 | 96 | |||
2155 | 97 | libdummy_indicator_simple_la_SOURCES = \ | ||
2156 | 98 | dummy-indicator-simple.c | ||
2157 | 99 | |||
2158 | 100 | libdummy_indicator_simple_la_CFLAGS = \ | ||
2159 | 101 | -Wall -Werror \ | ||
2160 | 102 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2161 | 103 | |||
2162 | 104 | libdummy_indicator_simple_la_LIBADD = \ | ||
2163 | 105 | $(LIBINDICATOR_LIBS) \ | ||
2164 | 106 | -L$(top_builddir)/libindicator/.libs \ | ||
2165 | 107 | -lindicator | ||
2166 | 108 | |||
2167 | 109 | libdummy_indicator_simple_la_LDFLAGS = \ | ||
2168 | 110 | -module \ | ||
2169 | 111 | -avoid-version | ||
2170 | 112 | |||
2171 | 113 | ############################# | ||
2172 | 114 | # Service Shutdown Timeout | ||
2173 | 115 | ############################# | ||
2174 | 116 | |||
2175 | 117 | check_PROGRAMS += service-shutdown-timeout | ||
2176 | 118 | |||
2177 | 119 | service_shutdown_timeout_SOURCES = \ | ||
2178 | 120 | service-shutdown-timeout.c | ||
2179 | 121 | |||
2180 | 122 | service_shutdown_timeout_CFLAGS = \ | ||
2181 | 123 | -Wall -Werror \ | ||
2182 | 124 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2183 | 125 | |||
2184 | 126 | service_shutdown_timeout_LDADD = \ | ||
2185 | 127 | $(LIBINDICATOR_LIBS) \ | ||
2186 | 128 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2187 | 129 | |||
2188 | 130 | service-shutdown-timeout-tester: service-shutdown-timeout Makefile | ||
2189 | 131 | @echo "#!/bin/sh" > service-shutdown-timeout-tester | ||
2190 | 132 | @echo $(DBUS_RUNNER) --task ./service-shutdown-timeout >> service-shutdown-timeout-tester | ||
2191 | 133 | @chmod +x service-shutdown-timeout-tester | ||
2192 | 134 | |||
2193 | 135 | TESTS += service-shutdown-timeout-tester | ||
2194 | 136 | DISTCLEANFILES += service-shutdown-timeout-tester | ||
2195 | 137 | |||
2196 | 138 | ############################# | ||
2197 | 139 | # Service Manager No Connect | ||
2198 | 140 | ############################# | ||
2199 | 141 | |||
2200 | 142 | check_PROGRAMS += service-manager-no-connect | ||
2201 | 143 | |||
2202 | 144 | service_manager_no_connect_SOURCES = \ | ||
2203 | 145 | service-manager-no-connect.c | ||
2204 | 146 | |||
2205 | 147 | service_manager_no_connect_CFLAGS = \ | ||
2206 | 148 | -Wall -Werror \ | ||
2207 | 149 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2208 | 150 | |||
2209 | 151 | service_manager_no_connect_LDADD = \ | ||
2210 | 152 | $(LIBINDICATOR_LIBS) \ | ||
2211 | 153 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2212 | 154 | |||
2213 | 155 | service-manager-no-connect-tester: service-manager-no-connect Makefile.am | ||
2214 | 156 | @echo "#!/bin/sh" > service-manager-no-connect-tester | ||
2215 | 157 | @echo $(DBUS_RUNNER) --task ./service-manager-no-connect >> service-manager-no-connect-tester | ||
2216 | 158 | @chmod +x service-manager-no-connect-tester | ||
2217 | 159 | |||
2218 | 160 | TESTS += service-manager-no-connect-tester | ||
2219 | 161 | DISTCLEANFILES += service-manager-no-connect-tester | ||
2220 | 162 | |||
2221 | 163 | ############################# | ||
2222 | 164 | # Service Manager Connect | ||
2223 | 165 | ############################# | ||
2224 | 166 | |||
2225 | 167 | session.conf: $(srcdir)/session.conf.in Makefile.am | ||
2226 | 168 | sed -e "s|\@servicedir\@|$(abspath $(builddir))|" $< > $@ | ||
2227 | 169 | |||
2228 | 170 | service-manager-connect.service: $(srcdir)/service-manager-connect.service.in Makefile.am | ||
2229 | 171 | sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ | ||
2230 | 172 | |||
2231 | 173 | check_PROGRAMS += service-manager-connect | ||
2232 | 174 | |||
2233 | 175 | service_manager_connect_SOURCES = \ | ||
2234 | 176 | service-manager-connect.c | ||
2235 | 177 | |||
2236 | 178 | service_manager_connect_CFLAGS = \ | ||
2237 | 179 | -Wall -Werror \ | ||
2238 | 180 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2239 | 181 | |||
2240 | 182 | service_manager_connect_LDADD = \ | ||
2241 | 183 | $(LIBINDICATOR_LIBS) \ | ||
2242 | 184 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2243 | 185 | |||
2244 | 186 | check_PROGRAMS += service-manager-connect-service | ||
2245 | 187 | |||
2246 | 188 | service_manager_connect_service_SOURCES = \ | ||
2247 | 189 | service-manager-connect-service.c | ||
2248 | 190 | |||
2249 | 191 | service_manager_connect_service_CFLAGS = \ | ||
2250 | 192 | -Wall -Werror \ | ||
2251 | 193 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2252 | 194 | |||
2253 | 195 | service_manager_connect_service_LDADD = \ | ||
2254 | 196 | $(LIBINDICATOR_LIBS) \ | ||
2255 | 197 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2256 | 198 | |||
2257 | 199 | service-manager-connect-tester: service-manager-connect service-manager-connect-service session.conf service-manager-connect.service Makefile.am | ||
2258 | 200 | @echo "#!/bin/sh" > service-manager-connect-tester | ||
2259 | 201 | @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-manager-connect >> service-manager-connect-tester | ||
2260 | 202 | @chmod +x service-manager-connect-tester | ||
2261 | 203 | |||
2262 | 204 | TESTS += service-manager-connect-tester | ||
2263 | 205 | DISTCLEANFILES += service-manager-connect-tester session.conf service-manager-connect.service | ||
2264 | 206 | |||
2265 | 207 | ############################# | ||
2266 | 208 | # Service Versions | ||
2267 | 209 | ############################# | ||
2268 | 210 | |||
2269 | 211 | service-version-good.service: $(srcdir)/service-version-good.service.in Makefile.am | ||
2270 | 212 | sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ | ||
2271 | 213 | |||
2272 | 214 | service-version-bad.service: $(srcdir)/service-version-bad.service.in Makefile.am | ||
2273 | 215 | sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ | ||
2274 | 216 | |||
2275 | 217 | check_PROGRAMS += service-version-manager | ||
2276 | 218 | |||
2277 | 219 | service_version_manager_SOURCES = \ | ||
2278 | 220 | service-version-values.h \ | ||
2279 | 221 | service-version-manager.c | ||
2280 | 222 | |||
2281 | 223 | service_version_manager_CFLAGS = \ | ||
2282 | 224 | -Wall -Werror \ | ||
2283 | 225 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2284 | 226 | |||
2285 | 227 | service_version_manager_LDADD = \ | ||
2286 | 228 | $(LIBINDICATOR_LIBS) \ | ||
2287 | 229 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2288 | 230 | |||
2289 | 231 | check_PROGRAMS += service-version-bad-service | ||
2290 | 232 | |||
2291 | 233 | service_version_bad_service_SOURCES = \ | ||
2292 | 234 | service-version-values.h \ | ||
2293 | 235 | service-version-bad-service.c | ||
2294 | 236 | |||
2295 | 237 | service_version_bad_service_CFLAGS = \ | ||
2296 | 238 | -Wall -Werror \ | ||
2297 | 239 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2298 | 240 | |||
2299 | 241 | service_version_bad_service_LDADD = \ | ||
2300 | 242 | $(LIBINDICATOR_LIBS) \ | ||
2301 | 243 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2302 | 244 | |||
2303 | 245 | check_PROGRAMS += service-version-good-service | ||
2304 | 246 | |||
2305 | 247 | service_version_good_service_SOURCES = \ | ||
2306 | 248 | service-version-values.h \ | ||
2307 | 249 | service-version-good-service.c | ||
2308 | 250 | |||
2309 | 251 | service_version_good_service_CFLAGS = \ | ||
2310 | 252 | -Wall -Werror \ | ||
2311 | 253 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2312 | 254 | |||
2313 | 255 | service_version_good_service_LDADD = \ | ||
2314 | 256 | $(LIBINDICATOR_LIBS) \ | ||
2315 | 257 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2316 | 258 | |||
2317 | 259 | service-version-tester: service-version-manager service-version-bad-service service-version-good-service session.conf service-version-bad.service service-version-good.service Makefile.am | ||
2318 | 260 | @echo "#!/bin/sh" > $@ | ||
2319 | 261 | @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-version-manager >> $@ | ||
2320 | 262 | @chmod +x $@ | ||
2321 | 263 | |||
2322 | 264 | TESTS += service-version-tester | ||
2323 | 265 | DISTCLEANFILES += service-version-tester service-version-bad.service service-version-good.service | ||
2324 | 266 | |||
2325 | 267 | ############################# | ||
2326 | 268 | # Service Manager Shutdown | ||
2327 | 269 | ############################# | ||
2328 | 270 | |||
2329 | 271 | check_PROGRAMS += service-manager-nostart-connect | ||
2330 | 272 | |||
2331 | 273 | service_manager_nostart_connect_SOURCES = \ | ||
2332 | 274 | service-manager-nostart-connect.c | ||
2333 | 275 | |||
2334 | 276 | service_manager_nostart_connect_CFLAGS = \ | ||
2335 | 277 | -Wall -Werror \ | ||
2336 | 278 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) | ||
2337 | 279 | |||
2338 | 280 | service_manager_nostart_connect_LDADD = \ | ||
2339 | 281 | $(LIBINDICATOR_LIBS) \ | ||
2340 | 282 | $(top_builddir)/libindicator/.libs/libindicator.a | ||
2341 | 283 | |||
2342 | 284 | service-manager-connect-nostart-tester: service-manager-nostart-connect service-manager-connect-service Makefile.am | ||
2343 | 285 | @echo "#!/bin/sh" > $@ | ||
2344 | 286 | @echo dbus-test-runner --task ./service-manager-nostart-connect --task ./service-manager-connect-service >> $@ | ||
2345 | 287 | @chmod +x $@ | ||
2346 | 288 | |||
2347 | 289 | TESTS += service-manager-connect-nostart-tester | ||
2348 | 290 | DISTCLEANFILES += service-manager-connect-nostart-tester | ||
2349 | 291 | |||
2350 | 292 | ############################# | ||
2351 | 293 | # Test stuff | ||
2352 | 294 | ############################# | ||
2353 | 295 | |||
2354 | 296 | XML_REPORT = loader-check-results.xml | ||
2355 | 297 | HTML_REPORT = loader-check-results.html | ||
2356 | 298 | |||
2357 | 299 | loader-tester: test-loader libdummy-indicator-null.la libdummy-indicator-simple.la Makefile | ||
2358 | 300 | @echo "#!/bin/sh" > loader-tester | ||
2359 | 301 | @echo gtester -k --verbose -o=$(XML_REPORT) ./test-loader >> loader-tester | ||
2360 | 302 | @chmod +x loader-tester | ||
2361 | 303 | |||
2362 | 304 | TESTS += loader-tester | ||
2363 | 305 | DISTCLEANFILES += loader-tester | ||
2364 | 306 | |||
2365 | 307 | DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) | ||
2366 | 308 | |||
2367 | 0 | 309 | ||
2368 | === added file 'tests/dummy-indicator-blank.c' | |||
2369 | --- tests/dummy-indicator-blank.c 1970-01-01 00:00:00 +0000 | |||
2370 | +++ tests/dummy-indicator-blank.c 2009-12-10 17:02:12 +0000 | |||
2371 | @@ -0,0 +1,5 @@ | |||
2372 | 1 | |||
2373 | 2 | #include "libindicator/indicator.h" | ||
2374 | 3 | |||
2375 | 4 | INDICATOR_SET_VERSION | ||
2376 | 5 | |||
2377 | 0 | 6 | ||
2378 | === added file 'tests/dummy-indicator-null.c' | |||
2379 | --- tests/dummy-indicator-null.c 1970-01-01 00:00:00 +0000 | |||
2380 | +++ tests/dummy-indicator-null.c 2009-12-10 17:02:12 +0000 | |||
2381 | @@ -0,0 +1,95 @@ | |||
2382 | 1 | |||
2383 | 2 | #include <glib.h> | ||
2384 | 3 | #include <glib-object.h> | ||
2385 | 4 | |||
2386 | 5 | #include "libindicator/indicator.h" | ||
2387 | 6 | #include "libindicator/indicator-object.h" | ||
2388 | 7 | |||
2389 | 8 | #define DUMMY_INDICATOR_NULL_TYPE (dummy_indicator_null_get_type ()) | ||
2390 | 9 | #define DUMMY_INDICATOR_NULL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNull)) | ||
2391 | 10 | #define DUMMY_INDICATOR_NULL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNullClass)) | ||
2392 | 11 | #define IS_DUMMY_INDICATOR_NULL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_NULL_TYPE)) | ||
2393 | 12 | #define IS_DUMMY_INDICATOR_NULL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_NULL_TYPE)) | ||
2394 | 13 | #define DUMMY_INDICATOR_NULL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNullClass)) | ||
2395 | 14 | |||
2396 | 15 | typedef struct _DummyIndicatorNull DummyIndicatorNull; | ||
2397 | 16 | typedef struct _DummyIndicatorNullClass DummyIndicatorNullClass; | ||
2398 | 17 | |||
2399 | 18 | struct _DummyIndicatorNullClass { | ||
2400 | 19 | IndicatorObjectClass parent_class; | ||
2401 | 20 | }; | ||
2402 | 21 | |||
2403 | 22 | struct _DummyIndicatorNull { | ||
2404 | 23 | IndicatorObject parent; | ||
2405 | 24 | }; | ||
2406 | 25 | |||
2407 | 26 | GType dummy_indicator_null_get_type (void); | ||
2408 | 27 | |||
2409 | 28 | INDICATOR_SET_VERSION | ||
2410 | 29 | INDICATOR_SET_TYPE(DUMMY_INDICATOR_NULL_TYPE) | ||
2411 | 30 | |||
2412 | 31 | |||
2413 | 32 | GtkLabel * | ||
2414 | 33 | get_label (IndicatorObject * io) | ||
2415 | 34 | { | ||
2416 | 35 | return NULL; | ||
2417 | 36 | } | ||
2418 | 37 | |||
2419 | 38 | GtkImage * | ||
2420 | 39 | get_icon (IndicatorObject * io) | ||
2421 | 40 | { | ||
2422 | 41 | return NULL; | ||
2423 | 42 | } | ||
2424 | 43 | |||
2425 | 44 | GtkMenu * | ||
2426 | 45 | get_menu (IndicatorObject * io) | ||
2427 | 46 | { | ||
2428 | 47 | return NULL; | ||
2429 | 48 | } | ||
2430 | 49 | |||
2431 | 50 | static void dummy_indicator_null_class_init (DummyIndicatorNullClass *klass); | ||
2432 | 51 | static void dummy_indicator_null_init (DummyIndicatorNull *self); | ||
2433 | 52 | static void dummy_indicator_null_dispose (GObject *object); | ||
2434 | 53 | static void dummy_indicator_null_finalize (GObject *object); | ||
2435 | 54 | |||
2436 | 55 | G_DEFINE_TYPE (DummyIndicatorNull, dummy_indicator_null, INDICATOR_OBJECT_TYPE); | ||
2437 | 56 | |||
2438 | 57 | static void | ||
2439 | 58 | dummy_indicator_null_class_init (DummyIndicatorNullClass *klass) | ||
2440 | 59 | { | ||
2441 | 60 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
2442 | 61 | |||
2443 | 62 | object_class->dispose = dummy_indicator_null_dispose; | ||
2444 | 63 | object_class->finalize = dummy_indicator_null_finalize; | ||
2445 | 64 | |||
2446 | 65 | IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); | ||
2447 | 66 | |||
2448 | 67 | io_class->get_label = get_label; | ||
2449 | 68 | io_class->get_image = get_icon; | ||
2450 | 69 | io_class->get_menu = get_menu; | ||
2451 | 70 | |||
2452 | 71 | return; | ||
2453 | 72 | } | ||
2454 | 73 | |||
2455 | 74 | static void | ||
2456 | 75 | dummy_indicator_null_init (DummyIndicatorNull *self) | ||
2457 | 76 | { | ||
2458 | 77 | |||
2459 | 78 | return; | ||
2460 | 79 | } | ||
2461 | 80 | |||
2462 | 81 | static void | ||
2463 | 82 | dummy_indicator_null_dispose (GObject *object) | ||
2464 | 83 | { | ||
2465 | 84 | |||
2466 | 85 | G_OBJECT_CLASS (dummy_indicator_null_parent_class)->dispose (object); | ||
2467 | 86 | return; | ||
2468 | 87 | } | ||
2469 | 88 | |||
2470 | 89 | static void | ||
2471 | 90 | dummy_indicator_null_finalize (GObject *object) | ||
2472 | 91 | { | ||
2473 | 92 | |||
2474 | 93 | G_OBJECT_CLASS (dummy_indicator_null_parent_class)->finalize (object); | ||
2475 | 94 | return; | ||
2476 | 95 | } | ||
2477 | 0 | 96 | ||
2478 | === added file 'tests/dummy-indicator-signaler.c' | |||
2479 | --- tests/dummy-indicator-signaler.c 1970-01-01 00:00:00 +0000 | |||
2480 | +++ tests/dummy-indicator-signaler.c 2009-12-10 17:02:12 +0000 | |||
2481 | @@ -0,0 +1,109 @@ | |||
2482 | 1 | #include <glib.h> | ||
2483 | 2 | #include <glib-object.h> | ||
2484 | 3 | |||
2485 | 4 | #include "libindicator/indicator.h" | ||
2486 | 5 | #include "libindicator/indicator-object.h" | ||
2487 | 6 | |||
2488 | 7 | #define DUMMY_INDICATOR_SIGNALER_TYPE (dummy_indicator_signaler_get_type ()) | ||
2489 | 8 | #define DUMMY_INDICATOR_SIGNALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignaler)) | ||
2490 | 9 | #define DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass)) | ||
2491 | 10 | #define IS_DUMMY_INDICATOR_SIGNALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIGNALER_TYPE)) | ||
2492 | 11 | #define IS_DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIGNALER_TYPE)) | ||
2493 | 12 | #define DUMMY_INDICATOR_SIGNALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass)) | ||
2494 | 13 | |||
2495 | 14 | typedef struct _DummyIndicatorSignaler DummyIndicatorSignaler; | ||
2496 | 15 | typedef struct _DummyIndicatorSignalerClass DummyIndicatorSignalerClass; | ||
2497 | 16 | |||
2498 | 17 | struct _DummyIndicatorSignalerClass { | ||
2499 | 18 | IndicatorObjectClass parent_class; | ||
2500 | 19 | }; | ||
2501 | 20 | |||
2502 | 21 | struct _DummyIndicatorSignaler { | ||
2503 | 22 | IndicatorObject parent; | ||
2504 | 23 | }; | ||
2505 | 24 | |||
2506 | 25 | GType dummy_indicator_signaler_get_type (void); | ||
2507 | 26 | |||
2508 | 27 | INDICATOR_SET_VERSION | ||
2509 | 28 | INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIGNALER_TYPE) | ||
2510 | 29 | |||
2511 | 30 | GtkLabel * | ||
2512 | 31 | get_label (IndicatorObject * io) | ||
2513 | 32 | { | ||
2514 | 33 | return GTK_LABEL(gtk_label_new("Signaler Item")); | ||
2515 | 34 | } | ||
2516 | 35 | |||
2517 | 36 | GtkImage * | ||
2518 | 37 | get_icon (IndicatorObject * io) | ||
2519 | 38 | { | ||
2520 | 39 | return GTK_IMAGE(gtk_image_new()); | ||
2521 | 40 | } | ||
2522 | 41 | |||
2523 | 42 | GtkMenu * | ||
2524 | 43 | get_menu (IndicatorObject * io) | ||
2525 | 44 | { | ||
2526 | 45 | GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); | ||
2527 | 46 | GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); | ||
2528 | 47 | gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item); | ||
2529 | 48 | gtk_widget_show(GTK_WIDGET(loading_item)); | ||
2530 | 49 | |||
2531 | 50 | return main_menu; | ||
2532 | 51 | } | ||
2533 | 52 | |||
2534 | 53 | static void dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass); | ||
2535 | 54 | static void dummy_indicator_signaler_init (DummyIndicatorSignaler *self); | ||
2536 | 55 | static void dummy_indicator_signaler_dispose (GObject *object); | ||
2537 | 56 | static void dummy_indicator_signaler_finalize (GObject *object); | ||
2538 | 57 | |||
2539 | 58 | G_DEFINE_TYPE (DummyIndicatorSignaler, dummy_indicator_signaler, INDICATOR_OBJECT_TYPE); | ||
2540 | 59 | |||
2541 | 60 | static void | ||
2542 | 61 | dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass) | ||
2543 | 62 | { | ||
2544 | 63 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
2545 | 64 | |||
2546 | 65 | object_class->dispose = dummy_indicator_signaler_dispose; | ||
2547 | 66 | object_class->finalize = dummy_indicator_signaler_finalize; | ||
2548 | 67 | |||
2549 | 68 | IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); | ||
2550 | 69 | |||
2551 | 70 | io_class->get_label = get_label; | ||
2552 | 71 | io_class->get_image = get_icon; | ||
2553 | 72 | io_class->get_menu = get_menu; | ||
2554 | 73 | |||
2555 | 74 | return; | ||
2556 | 75 | } | ||
2557 | 76 | |||
2558 | 77 | static gboolean | ||
2559 | 78 | idle_signal (gpointer data) | ||
2560 | 79 | { | ||
2561 | 80 | DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data); | ||
2562 | 81 | |||
2563 | 82 | g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, GUINT_TO_POINTER(5), TRUE); | ||
2564 | 83 | g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, GUINT_TO_POINTER(5), TRUE); | ||
2565 | 84 | |||
2566 | 85 | return FALSE; /* Don't queue again */ | ||
2567 | 86 | } | ||
2568 | 87 | |||
2569 | 88 | static void | ||
2570 | 89 | dummy_indicator_signaler_init (DummyIndicatorSignaler *self) | ||
2571 | 90 | { | ||
2572 | 91 | g_idle_add(idle_signal, self); | ||
2573 | 92 | return; | ||
2574 | 93 | } | ||
2575 | 94 | |||
2576 | 95 | static void | ||
2577 | 96 | dummy_indicator_signaler_dispose (GObject *object) | ||
2578 | 97 | { | ||
2579 | 98 | |||
2580 | 99 | G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->dispose (object); | ||
2581 | 100 | return; | ||
2582 | 101 | } | ||
2583 | 102 | |||
2584 | 103 | static void | ||
2585 | 104 | dummy_indicator_signaler_finalize (GObject *object) | ||
2586 | 105 | { | ||
2587 | 106 | |||
2588 | 107 | G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->finalize (object); | ||
2589 | 108 | return; | ||
2590 | 109 | } | ||
2591 | 0 | 110 | ||
2592 | === added file 'tests/dummy-indicator-simple.c' | |||
2593 | --- tests/dummy-indicator-simple.c 1970-01-01 00:00:00 +0000 | |||
2594 | +++ tests/dummy-indicator-simple.c 2009-12-10 17:02:12 +0000 | |||
2595 | @@ -0,0 +1,98 @@ | |||
2596 | 1 | #include <glib.h> | ||
2597 | 2 | #include <glib-object.h> | ||
2598 | 3 | |||
2599 | 4 | #include "libindicator/indicator.h" | ||
2600 | 5 | #include "libindicator/indicator-object.h" | ||
2601 | 6 | |||
2602 | 7 | #define DUMMY_INDICATOR_SIMPLE_TYPE (dummy_indicator_simple_get_type ()) | ||
2603 | 8 | #define DUMMY_INDICATOR_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimple)) | ||
2604 | 9 | #define DUMMY_INDICATOR_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimpleClass)) | ||
2605 | 10 | #define IS_DUMMY_INDICATOR_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIMPLE_TYPE)) | ||
2606 | 11 | #define IS_DUMMY_INDICATOR_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIMPLE_TYPE)) | ||
2607 | 12 | #define DUMMY_INDICATOR_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimpleClass)) | ||
2608 | 13 | |||
2609 | 14 | typedef struct _DummyIndicatorSimple DummyIndicatorSimple; | ||
2610 | 15 | typedef struct _DummyIndicatorSimpleClass DummyIndicatorSimpleClass; | ||
2611 | 16 | |||
2612 | 17 | struct _DummyIndicatorSimpleClass { | ||
2613 | 18 | IndicatorObjectClass parent_class; | ||
2614 | 19 | }; | ||
2615 | 20 | |||
2616 | 21 | struct _DummyIndicatorSimple { | ||
2617 | 22 | IndicatorObject parent; | ||
2618 | 23 | }; | ||
2619 | 24 | |||
2620 | 25 | GType dummy_indicator_simple_get_type (void); | ||
2621 | 26 | |||
2622 | 27 | INDICATOR_SET_VERSION | ||
2623 | 28 | INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIMPLE_TYPE) | ||
2624 | 29 | |||
2625 | 30 | GtkLabel * | ||
2626 | 31 | get_label (IndicatorObject * io) | ||
2627 | 32 | { | ||
2628 | 33 | return GTK_LABEL(gtk_label_new("Simple Item")); | ||
2629 | 34 | } | ||
2630 | 35 | |||
2631 | 36 | GtkImage * | ||
2632 | 37 | get_icon (IndicatorObject * io) | ||
2633 | 38 | { | ||
2634 | 39 | return GTK_IMAGE(gtk_image_new()); | ||
2635 | 40 | } | ||
2636 | 41 | |||
2637 | 42 | GtkMenu * | ||
2638 | 43 | get_menu (IndicatorObject * io) | ||
2639 | 44 | { | ||
2640 | 45 | GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); | ||
2641 | 46 | GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); | ||
2642 | 47 | gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item); | ||
2643 | 48 | gtk_widget_show(GTK_WIDGET(loading_item)); | ||
2644 | 49 | |||
2645 | 50 | return main_menu; | ||
2646 | 51 | } | ||
2647 | 52 | |||
2648 | 53 | static void dummy_indicator_simple_class_init (DummyIndicatorSimpleClass *klass); | ||
2649 | 54 | static void dummy_indicator_simple_init (DummyIndicatorSimple *self); | ||
2650 | 55 | static void dummy_indicator_simple_dispose (GObject *object); | ||
2651 | 56 | static void dummy_indicator_simple_finalize (GObject *object); | ||
2652 | 57 | |||
2653 | 58 | G_DEFINE_TYPE (DummyIndicatorSimple, dummy_indicator_simple, INDICATOR_OBJECT_TYPE); | ||
2654 | 59 | |||
2655 | 60 | static void | ||
2656 | 61 | dummy_indicator_simple_class_init (DummyIndicatorSimpleClass *klass) | ||
2657 | 62 | { | ||
2658 | 63 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
2659 | 64 | |||
2660 | 65 | object_class->dispose = dummy_indicator_simple_dispose; | ||
2661 | 66 | object_class->finalize = dummy_indicator_simple_finalize; | ||
2662 | 67 | |||
2663 | 68 | IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); | ||
2664 | 69 | |||
2665 | 70 | io_class->get_label = get_label; | ||
2666 | 71 | io_class->get_image = get_icon; | ||
2667 | 72 | io_class->get_menu = get_menu; | ||
2668 | 73 | |||
2669 | 74 | return; | ||
2670 | 75 | } | ||
2671 | 76 | |||
2672 | 77 | static void | ||
2673 | 78 | dummy_indicator_simple_init (DummyIndicatorSimple *self) | ||
2674 | 79 | { | ||
2675 | 80 | |||
2676 | 81 | return; | ||
2677 | 82 | } | ||
2678 | 83 | |||
2679 | 84 | static void | ||
2680 | 85 | dummy_indicator_simple_dispose (GObject *object) | ||
2681 | 86 | { | ||
2682 | 87 | |||
2683 | 88 | G_OBJECT_CLASS (dummy_indicator_simple_parent_class)->dispose (object); | ||
2684 | 89 | return; | ||
2685 | 90 | } | ||
2686 | 91 | |||
2687 | 92 | static void | ||
2688 | 93 | dummy_indicator_simple_finalize (GObject *object) | ||
2689 | 94 | { | ||
2690 | 95 | |||
2691 | 96 | G_OBJECT_CLASS (dummy_indicator_simple_parent_class)->finalize (object); | ||
2692 | 97 | return; | ||
2693 | 98 | } | ||
2694 | 0 | 99 | ||
2695 | === added file 'tests/service-manager-connect-service.c' | |||
2696 | --- tests/service-manager-connect-service.c 1970-01-01 00:00:00 +0000 | |||
2697 | +++ tests/service-manager-connect-service.c 2009-12-10 17:02:12 +0000 | |||
2698 | @@ -0,0 +1,48 @@ | |||
2699 | 1 | |||
2700 | 2 | #include <glib.h> | ||
2701 | 3 | #include "libindicator/indicator-service.h" | ||
2702 | 4 | |||
2703 | 5 | static GMainLoop * mainloop = NULL; | ||
2704 | 6 | static gboolean passed = FALSE; | ||
2705 | 7 | |||
2706 | 8 | gboolean | ||
2707 | 9 | timeout (gpointer data) | ||
2708 | 10 | { | ||
2709 | 11 | passed = FALSE; | ||
2710 | 12 | g_debug("Timeout with no shutdown."); | ||
2711 | 13 | g_main_loop_quit(mainloop); | ||
2712 | 14 | return FALSE; | ||
2713 | 15 | } | ||
2714 | 16 | |||
2715 | 17 | void | ||
2716 | 18 | shutdown (void) | ||
2717 | 19 | { | ||
2718 | 20 | g_debug("Shutdown"); | ||
2719 | 21 | passed = TRUE; | ||
2720 | 22 | g_main_loop_quit(mainloop); | ||
2721 | 23 | return; | ||
2722 | 24 | } | ||
2723 | 25 | |||
2724 | 26 | int | ||
2725 | 27 | main (int argc, char ** argv) | ||
2726 | 28 | { | ||
2727 | 29 | g_type_init(); | ||
2728 | 30 | |||
2729 | 31 | g_debug("Starting service"); | ||
2730 | 32 | |||
2731 | 33 | IndicatorService * is = indicator_service_new("org.ayatana.test"); | ||
2732 | 34 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); | ||
2733 | 35 | |||
2734 | 36 | g_timeout_add_seconds(1, timeout, NULL); | ||
2735 | 37 | |||
2736 | 38 | mainloop = g_main_loop_new(NULL, FALSE); | ||
2737 | 39 | g_main_loop_run(mainloop); | ||
2738 | 40 | |||
2739 | 41 | g_debug("Quiting"); | ||
2740 | 42 | if (passed) { | ||
2741 | 43 | g_debug("Passed"); | ||
2742 | 44 | return 0; | ||
2743 | 45 | } | ||
2744 | 46 | g_debug("Failed"); | ||
2745 | 47 | return 1; | ||
2746 | 48 | } | ||
2747 | 0 | 49 | ||
2748 | === added file 'tests/service-manager-connect.c' | |||
2749 | --- tests/service-manager-connect.c 1970-01-01 00:00:00 +0000 | |||
2750 | +++ tests/service-manager-connect.c 2009-12-10 17:02:12 +0000 | |||
2751 | @@ -0,0 +1,63 @@ | |||
2752 | 1 | |||
2753 | 2 | #include <glib.h> | ||
2754 | 3 | #include "libindicator/indicator-service-manager.h" | ||
2755 | 4 | |||
2756 | 5 | static GMainLoop * mainloop = NULL; | ||
2757 | 6 | static gboolean passed = FALSE; | ||
2758 | 7 | |||
2759 | 8 | gboolean | ||
2760 | 9 | timeout (gpointer data) | ||
2761 | 10 | { | ||
2762 | 11 | passed = FALSE; | ||
2763 | 12 | g_error("Timeout with no connection."); | ||
2764 | 13 | g_main_loop_quit(mainloop); | ||
2765 | 14 | return FALSE; | ||
2766 | 15 | } | ||
2767 | 16 | |||
2768 | 17 | void | ||
2769 | 18 | connection (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) | ||
2770 | 19 | { | ||
2771 | 20 | static gboolean has_connected = FALSE; | ||
2772 | 21 | |||
2773 | 22 | if (has_connected && connected) { | ||
2774 | 23 | g_warning("We got two connected signals. FAIL."); | ||
2775 | 24 | passed = FALSE; | ||
2776 | 25 | return; | ||
2777 | 26 | } | ||
2778 | 27 | |||
2779 | 28 | if (!connected) { | ||
2780 | 29 | g_debug("Not connected"); | ||
2781 | 30 | return; | ||
2782 | 31 | } | ||
2783 | 32 | |||
2784 | 33 | has_connected = TRUE; | ||
2785 | 34 | g_debug("Connection"); | ||
2786 | 35 | passed = TRUE; | ||
2787 | 36 | g_main_loop_quit(mainloop); | ||
2788 | 37 | return; | ||
2789 | 38 | } | ||
2790 | 39 | |||
2791 | 40 | int | ||
2792 | 41 | main (int argc, char ** argv) | ||
2793 | 42 | { | ||
2794 | 43 | g_type_init(); | ||
2795 | 44 | g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | ||
2796 | 45 | |||
2797 | 46 | IndicatorServiceManager * is = indicator_service_manager_new("org.ayatana.test"); | ||
2798 | 47 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection), NULL); | ||
2799 | 48 | |||
2800 | 49 | g_timeout_add_seconds(1, timeout, NULL); | ||
2801 | 50 | |||
2802 | 51 | mainloop = g_main_loop_new(NULL, FALSE); | ||
2803 | 52 | g_main_loop_run(mainloop); | ||
2804 | 53 | |||
2805 | 54 | g_object_unref(is); | ||
2806 | 55 | |||
2807 | 56 | g_debug("Quiting"); | ||
2808 | 57 | if (passed) { | ||
2809 | 58 | g_debug("Passed"); | ||
2810 | 59 | return 0; | ||
2811 | 60 | } | ||
2812 | 61 | g_debug("Failed"); | ||
2813 | 62 | return 1; | ||
2814 | 63 | } | ||
2815 | 0 | 64 | ||
2816 | === added file 'tests/service-manager-connect.service.in' | |||
2817 | --- tests/service-manager-connect.service.in 1970-01-01 00:00:00 +0000 | |||
2818 | +++ tests/service-manager-connect.service.in 2009-12-10 17:02:12 +0000 | |||
2819 | @@ -0,0 +1,3 @@ | |||
2820 | 1 | [D-BUS Service] | ||
2821 | 2 | Name=org.ayatana.test | ||
2822 | 3 | Exec=@builddir@/service-manager-connect-service | ||
2823 | 0 | 4 | ||
2824 | === added file 'tests/service-manager-no-connect.c' | |||
2825 | --- tests/service-manager-no-connect.c 1970-01-01 00:00:00 +0000 | |||
2826 | +++ tests/service-manager-no-connect.c 2009-12-10 17:02:12 +0000 | |||
2827 | @@ -0,0 +1,47 @@ | |||
2828 | 1 | |||
2829 | 2 | #include <glib.h> | ||
2830 | 3 | #include "libindicator/indicator-service-manager.h" | ||
2831 | 4 | |||
2832 | 5 | static GMainLoop * mainloop = NULL; | ||
2833 | 6 | static gboolean passed = FALSE; | ||
2834 | 7 | |||
2835 | 8 | gboolean | ||
2836 | 9 | timeout (gpointer data) | ||
2837 | 10 | { | ||
2838 | 11 | passed = TRUE; | ||
2839 | 12 | g_debug("Timeout with no connection."); | ||
2840 | 13 | g_main_loop_quit(mainloop); | ||
2841 | 14 | return FALSE; | ||
2842 | 15 | } | ||
2843 | 16 | |||
2844 | 17 | void | ||
2845 | 18 | connection (void) | ||
2846 | 19 | { | ||
2847 | 20 | g_debug("Connection"); | ||
2848 | 21 | passed = FALSE; | ||
2849 | 22 | g_main_loop_quit(mainloop); | ||
2850 | 23 | return; | ||
2851 | 24 | } | ||
2852 | 25 | |||
2853 | 26 | int | ||
2854 | 27 | main (int argc, char ** argv) | ||
2855 | 28 | { | ||
2856 | 29 | g_type_init(); | ||
2857 | 30 | g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | ||
2858 | 31 | |||
2859 | 32 | IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); | ||
2860 | 33 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); | ||
2861 | 34 | |||
2862 | 35 | g_timeout_add_seconds(1, timeout, NULL); | ||
2863 | 36 | |||
2864 | 37 | mainloop = g_main_loop_new(NULL, FALSE); | ||
2865 | 38 | g_main_loop_run(mainloop); | ||
2866 | 39 | |||
2867 | 40 | g_debug("Quiting"); | ||
2868 | 41 | if (passed) { | ||
2869 | 42 | g_debug("Passed"); | ||
2870 | 43 | return 0; | ||
2871 | 44 | } | ||
2872 | 45 | g_debug("Failed"); | ||
2873 | 46 | return 1; | ||
2874 | 47 | } | ||
2875 | 0 | 48 | ||
2876 | === added file 'tests/service-manager-nostart-connect.c' | |||
2877 | --- tests/service-manager-nostart-connect.c 1970-01-01 00:00:00 +0000 | |||
2878 | +++ tests/service-manager-nostart-connect.c 2009-12-10 17:02:12 +0000 | |||
2879 | @@ -0,0 +1,65 @@ | |||
2880 | 1 | |||
2881 | 2 | #include <glib.h> | ||
2882 | 3 | #include "libindicator/indicator-service-manager.h" | ||
2883 | 4 | |||
2884 | 5 | static GMainLoop * mainloop = NULL; | ||
2885 | 6 | static gboolean passed = FALSE; | ||
2886 | 7 | |||
2887 | 8 | gboolean | ||
2888 | 9 | timeout (gpointer data) | ||
2889 | 10 | { | ||
2890 | 11 | passed = FALSE; | ||
2891 | 12 | g_error("Timeout with no connection."); | ||
2892 | 13 | g_main_loop_quit(mainloop); | ||
2893 | 14 | return FALSE; | ||
2894 | 15 | } | ||
2895 | 16 | |||
2896 | 17 | void | ||
2897 | 18 | connection (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) | ||
2898 | 19 | { | ||
2899 | 20 | static gboolean has_connected = FALSE; | ||
2900 | 21 | |||
2901 | 22 | if (has_connected && connected) { | ||
2902 | 23 | g_warning("We got two connected signals. FAIL."); | ||
2903 | 24 | passed = FALSE; | ||
2904 | 25 | return; | ||
2905 | 26 | } | ||
2906 | 27 | |||
2907 | 28 | if (!connected) { | ||
2908 | 29 | g_debug("Not connected"); | ||
2909 | 30 | return; | ||
2910 | 31 | } | ||
2911 | 32 | |||
2912 | 33 | has_connected = TRUE; | ||
2913 | 34 | g_debug("Connection"); | ||
2914 | 35 | passed = TRUE; | ||
2915 | 36 | g_main_loop_quit(mainloop); | ||
2916 | 37 | return; | ||
2917 | 38 | } | ||
2918 | 39 | |||
2919 | 40 | int | ||
2920 | 41 | main (int argc, char ** argv) | ||
2921 | 42 | { | ||
2922 | 43 | g_type_init(); | ||
2923 | 44 | g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | ||
2924 | 45 | |||
2925 | 46 | g_usleep(150000); | ||
2926 | 47 | |||
2927 | 48 | IndicatorServiceManager * is = indicator_service_manager_new("org.ayatana.test"); | ||
2928 | 49 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection), NULL); | ||
2929 | 50 | |||
2930 | 51 | g_timeout_add_seconds(1, timeout, NULL); | ||
2931 | 52 | |||
2932 | 53 | mainloop = g_main_loop_new(NULL, FALSE); | ||
2933 | 54 | g_main_loop_run(mainloop); | ||
2934 | 55 | |||
2935 | 56 | g_object_unref(is); | ||
2936 | 57 | |||
2937 | 58 | g_debug("Quiting"); | ||
2938 | 59 | if (passed) { | ||
2939 | 60 | g_debug("Passed"); | ||
2940 | 61 | return 0; | ||
2941 | 62 | } | ||
2942 | 63 | g_debug("Failed"); | ||
2943 | 64 | return 1; | ||
2944 | 65 | } | ||
2945 | 0 | 66 | ||
2946 | === added file 'tests/service-shutdown-timeout.c' | |||
2947 | --- tests/service-shutdown-timeout.c 1970-01-01 00:00:00 +0000 | |||
2948 | +++ tests/service-shutdown-timeout.c 2009-12-10 17:02:12 +0000 | |||
2949 | @@ -0,0 +1,46 @@ | |||
2950 | 1 | |||
2951 | 2 | #include <glib.h> | ||
2952 | 3 | #include "libindicator/indicator-service.h" | ||
2953 | 4 | |||
2954 | 5 | static GMainLoop * mainloop = NULL; | ||
2955 | 6 | static gboolean passed = FALSE; | ||
2956 | 7 | |||
2957 | 8 | gboolean | ||
2958 | 9 | timeout (gpointer data) | ||
2959 | 10 | { | ||
2960 | 11 | passed = FALSE; | ||
2961 | 12 | g_error("Timeout with no shutdown."); | ||
2962 | 13 | g_main_loop_quit(mainloop); | ||
2963 | 14 | return FALSE; | ||
2964 | 15 | } | ||
2965 | 16 | |||
2966 | 17 | void | ||
2967 | 18 | shutdown (void) | ||
2968 | 19 | { | ||
2969 | 20 | g_debug("Shutdown"); | ||
2970 | 21 | passed = TRUE; | ||
2971 | 22 | g_main_loop_quit(mainloop); | ||
2972 | 23 | return; | ||
2973 | 24 | } | ||
2974 | 25 | |||
2975 | 26 | int | ||
2976 | 27 | main (int argc, char ** argv) | ||
2977 | 28 | { | ||
2978 | 29 | g_type_init(); | ||
2979 | 30 | |||
2980 | 31 | IndicatorService * is = indicator_service_new("my.test.name"); | ||
2981 | 32 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); | ||
2982 | 33 | |||
2983 | 34 | g_timeout_add_seconds(1, timeout, NULL); | ||
2984 | 35 | |||
2985 | 36 | mainloop = g_main_loop_new(NULL, FALSE); | ||
2986 | 37 | g_main_loop_run(mainloop); | ||
2987 | 38 | |||
2988 | 39 | g_debug("Quiting"); | ||
2989 | 40 | if (passed) { | ||
2990 | 41 | g_debug("Passed"); | ||
2991 | 42 | return 0; | ||
2992 | 43 | } | ||
2993 | 44 | g_debug("Failed"); | ||
2994 | 45 | return 1; | ||
2995 | 46 | } | ||
2996 | 0 | 47 | ||
2997 | === added file 'tests/service-version-bad-service.c' | |||
2998 | --- tests/service-version-bad-service.c 1970-01-01 00:00:00 +0000 | |||
2999 | +++ tests/service-version-bad-service.c 2009-12-10 17:02:12 +0000 | |||
3000 | @@ -0,0 +1,47 @@ | |||
3001 | 1 | |||
3002 | 2 | #include <glib.h> | ||
3003 | 3 | #include "libindicator/indicator-service.h" | ||
3004 | 4 | #include "service-version-values.h" | ||
3005 | 5 | |||
3006 | 6 | static GMainLoop * mainloop = NULL; | ||
3007 | 7 | static gboolean passed = FALSE; | ||
3008 | 8 | |||
3009 | 9 | gboolean | ||
3010 | 10 | timeout (gpointer data) | ||
3011 | 11 | { | ||
3012 | 12 | passed = FALSE; | ||
3013 | 13 | g_debug("Timeout with no shutdown."); | ||
3014 | 14 | g_main_loop_quit(mainloop); | ||
3015 | 15 | return FALSE; | ||
3016 | 16 | } | ||
3017 | 17 | |||
3018 | 18 | void | ||
3019 | 19 | shutdown (void) | ||
3020 | 20 | { | ||
3021 | 21 | g_debug("Shutdown"); | ||
3022 | 22 | passed = TRUE; | ||
3023 | 23 | g_main_loop_quit(mainloop); | ||
3024 | 24 | return; | ||
3025 | 25 | } | ||
3026 | 26 | |||
3027 | 27 | int | ||
3028 | 28 | main (int argc, char ** argv) | ||
3029 | 29 | { | ||
3030 | 30 | g_type_init(); | ||
3031 | 31 | |||
3032 | 32 | IndicatorService * is = indicator_service_new_version("org.ayatana.version.bad", SERVICE_VERSION_BAD); | ||
3033 | 33 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); | ||
3034 | 34 | |||
3035 | 35 | g_timeout_add_seconds(1, timeout, NULL); | ||
3036 | 36 | |||
3037 | 37 | mainloop = g_main_loop_new(NULL, FALSE); | ||
3038 | 38 | g_main_loop_run(mainloop); | ||
3039 | 39 | |||
3040 | 40 | g_debug("Quiting"); | ||
3041 | 41 | if (passed) { | ||
3042 | 42 | g_debug("Passed"); | ||
3043 | 43 | return 0; | ||
3044 | 44 | } | ||
3045 | 45 | g_debug("Failed"); | ||
3046 | 46 | return 1; | ||
3047 | 47 | } | ||
3048 | 0 | 48 | ||
3049 | === added file 'tests/service-version-bad.service.in' | |||
3050 | --- tests/service-version-bad.service.in 1970-01-01 00:00:00 +0000 | |||
3051 | +++ tests/service-version-bad.service.in 2009-12-10 17:02:12 +0000 | |||
3052 | @@ -0,0 +1,3 @@ | |||
3053 | 1 | [D-BUS Service] | ||
3054 | 2 | Name=org.ayatana.version.bad | ||
3055 | 3 | Exec=@builddir@/service-version-bad-service | ||
3056 | 0 | 4 | ||
3057 | === added file 'tests/service-version-good-service.c' | |||
3058 | --- tests/service-version-good-service.c 1970-01-01 00:00:00 +0000 | |||
3059 | +++ tests/service-version-good-service.c 2009-12-10 17:02:12 +0000 | |||
3060 | @@ -0,0 +1,47 @@ | |||
3061 | 1 | |||
3062 | 2 | #include <glib.h> | ||
3063 | 3 | #include "libindicator/indicator-service.h" | ||
3064 | 4 | #include "service-version-values.h" | ||
3065 | 5 | |||
3066 | 6 | static GMainLoop * mainloop = NULL; | ||
3067 | 7 | static gboolean passed = FALSE; | ||
3068 | 8 | |||
3069 | 9 | gboolean | ||
3070 | 10 | timeout (gpointer data) | ||
3071 | 11 | { | ||
3072 | 12 | passed = FALSE; | ||
3073 | 13 | g_debug("Timeout with no shutdown."); | ||
3074 | 14 | g_main_loop_quit(mainloop); | ||
3075 | 15 | return FALSE; | ||
3076 | 16 | } | ||
3077 | 17 | |||
3078 | 18 | void | ||
3079 | 19 | shutdown (void) | ||
3080 | 20 | { | ||
3081 | 21 | g_debug("Shutdown"); | ||
3082 | 22 | passed = TRUE; | ||
3083 | 23 | g_main_loop_quit(mainloop); | ||
3084 | 24 | return; | ||
3085 | 25 | } | ||
3086 | 26 | |||
3087 | 27 | int | ||
3088 | 28 | main (int argc, char ** argv) | ||
3089 | 29 | { | ||
3090 | 30 | g_type_init(); | ||
3091 | 31 | |||
3092 | 32 | IndicatorService * is = indicator_service_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD); | ||
3093 | 33 | g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); | ||
3094 | 34 | |||
3095 | 35 | g_timeout_add_seconds(1, timeout, NULL); | ||
3096 | 36 | |||
3097 | 37 | mainloop = g_main_loop_new(NULL, FALSE); | ||
3098 | 38 | g_main_loop_run(mainloop); | ||
3099 | 39 | |||
3100 | 40 | g_debug("Quiting"); | ||
3101 | 41 | if (passed) { | ||
3102 | 42 | g_debug("Passed"); | ||
3103 | 43 | return 0; | ||
3104 | 44 | } | ||
3105 | 45 | g_debug("Failed"); | ||
3106 | 46 | return 1; | ||
3107 | 47 | } | ||
3108 | 0 | 48 | ||
3109 | === added file 'tests/service-version-good.service.in' | |||
3110 | --- tests/service-version-good.service.in 1970-01-01 00:00:00 +0000 | |||
3111 | +++ tests/service-version-good.service.in 2009-12-10 17:02:12 +0000 | |||
3112 | @@ -0,0 +1,3 @@ | |||
3113 | 1 | [D-BUS Service] | ||
3114 | 2 | Name=org.ayatana.version.good | ||
3115 | 3 | Exec=@builddir@/service-version-good-service | ||
3116 | 0 | 4 | ||
3117 | === added file 'tests/service-version-manager.c' | |||
3118 | --- tests/service-version-manager.c 1970-01-01 00:00:00 +0000 | |||
3119 | +++ tests/service-version-manager.c 2009-12-10 17:02:12 +0000 | |||
3120 | @@ -0,0 +1,64 @@ | |||
3121 | 1 | |||
3122 | 2 | #include <glib.h> | ||
3123 | 3 | #include "libindicator/indicator-service-manager.h" | ||
3124 | 4 | #include "service-version-values.h" | ||
3125 | 5 | |||
3126 | 6 | static GMainLoop * mainloop = NULL; | ||
3127 | 7 | static gboolean con_good = FALSE; | ||
3128 | 8 | static gboolean con_bad = FALSE; | ||
3129 | 9 | |||
3130 | 10 | gboolean | ||
3131 | 11 | timeout (gpointer data) | ||
3132 | 12 | { | ||
3133 | 13 | g_debug("Timeout."); | ||
3134 | 14 | g_main_loop_quit(mainloop); | ||
3135 | 15 | return FALSE; | ||
3136 | 16 | } | ||
3137 | 17 | |||
3138 | 18 | void | ||
3139 | 19 | connection_bad (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) | ||
3140 | 20 | { | ||
3141 | 21 | if (!connected) return; | ||
3142 | 22 | g_debug("Connection From Bad!"); | ||
3143 | 23 | con_bad = TRUE; | ||
3144 | 24 | return; | ||
3145 | 25 | } | ||
3146 | 26 | |||
3147 | 27 | void | ||
3148 | 28 | connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) | ||
3149 | 29 | { | ||
3150 | 30 | if (!connected) return; | ||
3151 | 31 | g_debug("Connection From Good."); | ||
3152 | 32 | con_good = TRUE; | ||
3153 | 33 | return; | ||
3154 | 34 | } | ||
3155 | 35 | |||
3156 | 36 | int | ||
3157 | 37 | main (int argc, char ** argv) | ||
3158 | 38 | { | ||
3159 | 39 | g_type_init(); | ||
3160 | 40 | g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | ||
3161 | 41 | g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS")); | ||
3162 | 42 | |||
3163 | 43 | IndicatorServiceManager * goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD); | ||
3164 | 44 | g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL); | ||
3165 | 45 | |||
3166 | 46 | IndicatorServiceManager * badis = indicator_service_manager_new_version("org.ayatana.version.bad", SERVICE_VERSION_GOOD); | ||
3167 | 47 | g_signal_connect(G_OBJECT(badis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_bad), NULL); | ||
3168 | 48 | |||
3169 | 49 | g_timeout_add_seconds(1, timeout, NULL); | ||
3170 | 50 | |||
3171 | 51 | mainloop = g_main_loop_new(NULL, FALSE); | ||
3172 | 52 | g_main_loop_run(mainloop); | ||
3173 | 53 | |||
3174 | 54 | g_object_unref(goodis); | ||
3175 | 55 | g_object_unref(badis); | ||
3176 | 56 | |||
3177 | 57 | g_debug("Quiting"); | ||
3178 | 58 | if (con_good && !con_bad) { | ||
3179 | 59 | g_debug("Passed"); | ||
3180 | 60 | return 0; | ||
3181 | 61 | } | ||
3182 | 62 | g_debug("Failed"); | ||
3183 | 63 | return 1; | ||
3184 | 64 | } | ||
3185 | 0 | 65 | ||
3186 | === added file 'tests/service-version-values.h' | |||
3187 | --- tests/service-version-values.h 1970-01-01 00:00:00 +0000 | |||
3188 | +++ tests/service-version-values.h 2009-12-10 17:02:12 +0000 | |||
3189 | @@ -0,0 +1,4 @@ | |||
3190 | 1 | |||
3191 | 2 | #define SERVICE_VERSION_GOOD 1342 | ||
3192 | 3 | #define SERVICE_VERSION_BAD 543 | ||
3193 | 4 | |||
3194 | 0 | 5 | ||
3195 | === added file 'tests/session.conf.in' | |||
3196 | --- tests/session.conf.in 1970-01-01 00:00:00 +0000 | |||
3197 | +++ tests/session.conf.in 2009-12-10 17:02:12 +0000 | |||
3198 | @@ -0,0 +1,40 @@ | |||
3199 | 1 | <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" | ||
3200 | 2 | "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
3201 | 3 | <busconfig> | ||
3202 | 4 | <!-- If we fork, keep the user's original umask to avoid affecting | ||
3203 | 5 | the behavior of child processes. --> | ||
3204 | 6 | <keep_umask/> | ||
3205 | 7 | |||
3206 | 8 | <listen>unix:tmpdir=/tmp</listen> | ||
3207 | 9 | |||
3208 | 10 | <servicedir>@servicedir@</servicedir> | ||
3209 | 11 | |||
3210 | 12 | <policy context="default"> | ||
3211 | 13 | <!-- Allow everything to be sent --> | ||
3212 | 14 | <allow send_destination="*" eavesdrop="true"/> | ||
3213 | 15 | <!-- Allow everything to be received --> | ||
3214 | 16 | <allow eavesdrop="true"/> | ||
3215 | 17 | <!-- Allow anyone to own anything --> | ||
3216 | 18 | <allow own="*"/> | ||
3217 | 19 | </policy> | ||
3218 | 20 | |||
3219 | 21 | <!-- raise the service start timeout to 40 seconds as it can timeout | ||
3220 | 22 | on the live cd on slow machines --> | ||
3221 | 23 | <limit name="service_start_timeout">60000</limit> | ||
3222 | 24 | |||
3223 | 25 | <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max --> | ||
3224 | 26 | <limit name="max_incoming_bytes">1000000000</limit> | ||
3225 | 27 | <limit name="max_outgoing_bytes">1000000000</limit> | ||
3226 | 28 | <limit name="max_message_size">1000000000</limit> | ||
3227 | 29 | <limit name="service_start_timeout">120000</limit> | ||
3228 | 30 | <limit name="auth_timeout">240000</limit> | ||
3229 | 31 | <limit name="max_completed_connections">100000</limit> | ||
3230 | 32 | <limit name="max_incomplete_connections">10000</limit> | ||
3231 | 33 | <limit name="max_connections_per_user">100000</limit> | ||
3232 | 34 | <limit name="max_pending_service_starts">10000</limit> | ||
3233 | 35 | <limit name="max_names_per_connection">50000</limit> | ||
3234 | 36 | <limit name="max_match_rules_per_connection">50000</limit> | ||
3235 | 37 | <limit name="max_replies_per_connection">50000</limit> | ||
3236 | 38 | <limit name="reply_timeout">300000</limit> | ||
3237 | 39 | |||
3238 | 40 | </busconfig> | ||
3239 | 0 | 41 | ||
3240 | === added file 'tests/test-loader.c' | |||
3241 | --- tests/test-loader.c 1970-01-01 00:00:00 +0000 | |||
3242 | +++ tests/test-loader.c 2009-12-10 17:02:12 +0000 | |||
3243 | @@ -0,0 +1,146 @@ | |||
3244 | 1 | #include <gtk/gtk.h> | ||
3245 | 2 | #include "libindicator/indicator-object.h" | ||
3246 | 3 | |||
3247 | 4 | void destroy_cb (gpointer data, GObject * object); | ||
3248 | 5 | |||
3249 | 6 | void | ||
3250 | 7 | entry_change_cb (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer data) | ||
3251 | 8 | { | ||
3252 | 9 | gpointer * valuestore = (gpointer *)data; | ||
3253 | 10 | *valuestore = entry; | ||
3254 | 11 | return; | ||
3255 | 12 | } | ||
3256 | 13 | |||
3257 | 14 | void | ||
3258 | 15 | test_loader_filename_dummy_signaler (void) | ||
3259 | 16 | { | ||
3260 | 17 | IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-signaler.so"); | ||
3261 | 18 | g_assert(object != NULL); | ||
3262 | 19 | |||
3263 | 20 | gpointer added_value = NULL, removed_value = NULL; | ||
3264 | 21 | |||
3265 | 22 | g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_change_cb), &added_value); | ||
3266 | 23 | g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_change_cb), &removed_value); | ||
3267 | 24 | |||
3268 | 25 | GList * list = indicator_object_get_entries(object); | ||
3269 | 26 | g_assert(list != NULL); | ||
3270 | 27 | g_list_free(list); | ||
3271 | 28 | |||
3272 | 29 | while (g_main_context_pending(NULL)) { | ||
3273 | 30 | g_main_context_iteration(NULL, TRUE); | ||
3274 | 31 | } | ||
3275 | 32 | |||
3276 | 33 | g_assert(GPOINTER_TO_UINT(added_value) == 5); | ||
3277 | 34 | g_assert(GPOINTER_TO_UINT(removed_value) == 5); | ||
3278 | 35 | |||
3279 | 36 | g_object_unref(object); | ||
3280 | 37 | |||
3281 | 38 | return; | ||
3282 | 39 | } | ||
3283 | 40 | |||
3284 | 41 | |||
3285 | 42 | void | ||
3286 | 43 | test_loader_filename_dummy_simple_accessors (void) | ||
3287 | 44 | { | ||
3288 | 45 | IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); | ||
3289 | 46 | g_assert(object != NULL); | ||
3290 | 47 | |||
3291 | 48 | g_assert(indicator_object_get_entries(object) != NULL); | ||
3292 | 49 | |||
3293 | 50 | g_object_unref(object); | ||
3294 | 51 | |||
3295 | 52 | return; | ||
3296 | 53 | } | ||
3297 | 54 | |||
3298 | 55 | void | ||
3299 | 56 | test_loader_filename_dummy_simple (void) | ||
3300 | 57 | { | ||
3301 | 58 | IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); | ||
3302 | 59 | g_assert(object != NULL); | ||
3303 | 60 | |||
3304 | 61 | gboolean unreffed = FALSE; | ||
3305 | 62 | g_object_weak_ref(G_OBJECT(object), destroy_cb, &unreffed); | ||
3306 | 63 | |||
3307 | 64 | g_object_unref(object); | ||
3308 | 65 | g_assert(unreffed == TRUE); | ||
3309 | 66 | |||
3310 | 67 | return; | ||
3311 | 68 | } | ||
3312 | 69 | |||
3313 | 70 | void | ||
3314 | 71 | test_loader_filename_dummy_blank (void) | ||
3315 | 72 | { | ||
3316 | 73 | IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-blank.so"); | ||
3317 | 74 | g_assert(object == NULL); | ||
3318 | 75 | return; | ||
3319 | 76 | } | ||
3320 | 77 | |||
3321 | 78 | void | ||
3322 | 79 | test_loader_filename_dummy_null (void) | ||
3323 | 80 | { | ||
3324 | 81 | IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); | ||
3325 | 82 | g_assert(object != NULL); | ||
3326 | 83 | g_assert(indicator_object_get_entries(object) == NULL); | ||
3327 | 84 | g_object_unref(G_OBJECT(object)); | ||
3328 | 85 | return; | ||
3329 | 86 | } | ||
3330 | 87 | |||
3331 | 88 | void | ||
3332 | 89 | test_loader_filename_bad (void) | ||
3333 | 90 | { | ||
3334 | 91 | IndicatorObject * object = indicator_object_new_from_file("/this/file/should/not/exist.so"); | ||
3335 | 92 | g_assert(object == NULL); | ||
3336 | 93 | return; | ||
3337 | 94 | } | ||
3338 | 95 | |||
3339 | 96 | void | ||
3340 | 97 | destroy_cb (gpointer data, GObject * object) | ||
3341 | 98 | { | ||
3342 | 99 | gboolean * bob = (gboolean *)data; | ||
3343 | 100 | *bob = TRUE; | ||
3344 | 101 | return; | ||
3345 | 102 | } | ||
3346 | 103 | |||
3347 | 104 | void | ||
3348 | 105 | test_loader_refunref (void) | ||
3349 | 106 | { | ||
3350 | 107 | GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); | ||
3351 | 108 | |||
3352 | 109 | gboolean unreffed = FALSE; | ||
3353 | 110 | g_object_weak_ref(object, destroy_cb, &unreffed); | ||
3354 | 111 | |||
3355 | 112 | g_object_unref(object); | ||
3356 | 113 | |||
3357 | 114 | g_assert(unreffed == TRUE); | ||
3358 | 115 | |||
3359 | 116 | return; | ||
3360 | 117 | } | ||
3361 | 118 | |||
3362 | 119 | void | ||
3363 | 120 | test_loader_creation_deletion_suite (void) | ||
3364 | 121 | { | ||
3365 | 122 | g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); | ||
3366 | 123 | g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); | ||
3367 | 124 | g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); | ||
3368 | 125 | g_test_add_func ("/libindicator/loader/dummy/blank_load", test_loader_filename_dummy_null); | ||
3369 | 126 | g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); | ||
3370 | 127 | g_test_add_func ("/libindicator/loader/dummy/simple_accessors", test_loader_filename_dummy_simple_accessors); | ||
3371 | 128 | g_test_add_func ("/libindicator/loader/dummy/signaler", test_loader_filename_dummy_signaler); | ||
3372 | 129 | |||
3373 | 130 | return; | ||
3374 | 131 | } | ||
3375 | 132 | |||
3376 | 133 | |||
3377 | 134 | int | ||
3378 | 135 | main (int argc, char ** argv) | ||
3379 | 136 | { | ||
3380 | 137 | g_type_init (); | ||
3381 | 138 | g_test_init (&argc, &argv, NULL); | ||
3382 | 139 | gtk_init(&argc, &argv); | ||
3383 | 140 | |||
3384 | 141 | test_loader_creation_deletion_suite(); | ||
3385 | 142 | |||
3386 | 143 | g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | ||
3387 | 144 | |||
3388 | 145 | return g_test_run(); | ||
3389 | 146 | } | ||
3390 | 0 | 147 | ||
3391 | === added directory 'tools' | |||
3392 | === added file 'tools/Makefile.am' | |||
3393 | --- tools/Makefile.am 1970-01-01 00:00:00 +0000 | |||
3394 | +++ tools/Makefile.am 2009-12-10 17:02:12 +0000 | |||
3395 | @@ -0,0 +1,21 @@ | |||
3396 | 1 | |||
3397 | 2 | libexec_PROGRAMS = \ | ||
3398 | 3 | indicator-loader | ||
3399 | 4 | |||
3400 | 5 | ############################# | ||
3401 | 6 | # Indicator Loader | ||
3402 | 7 | ############################# | ||
3403 | 8 | |||
3404 | 9 | indicator_loader_SOURCES = \ | ||
3405 | 10 | indicator-loader.c | ||
3406 | 11 | |||
3407 | 12 | indicator_loader_CFLAGS = \ | ||
3408 | 13 | -Wall -Werror \ | ||
3409 | 14 | $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ | ||
3410 | 15 | -DBUILD_DIR="\"$(builddir)\"" | ||
3411 | 16 | |||
3412 | 17 | indicator_loader_LDADD = \ | ||
3413 | 18 | $(LIBINDICATOR_LIBS) \ | ||
3414 | 19 | -L$(top_builddir)/libindicator/.libs \ | ||
3415 | 20 | -lindicator | ||
3416 | 21 | |||
3417 | 0 | 22 | ||
3418 | === added file 'tools/indicator-loader.c' | |||
3419 | --- tools/indicator-loader.c 1970-01-01 00:00:00 +0000 | |||
3420 | +++ tools/indicator-loader.c 2009-12-10 17:02:12 +0000 | |||
3421 | @@ -0,0 +1,149 @@ | |||
3422 | 1 | /* | ||
3423 | 2 | A small test loader for loading indicators in test suites | ||
3424 | 3 | and during development of them. | ||
3425 | 4 | |||
3426 | 5 | Copyright 2009 Canonical Ltd. | ||
3427 | 6 | |||
3428 | 7 | Authors: | ||
3429 | 8 | Ted Gould <ted@canonical.com> | ||
3430 | 9 | |||
3431 | 10 | This library is free software; you can redistribute it and/or | ||
3432 | 11 | modify it under the terms of the GNU General Public License | ||
3433 | 12 | version 3.0 as published by the Free Software Foundation. | ||
3434 | 13 | |||
3435 | 14 | This library is distributed in the hope that it will be useful, | ||
3436 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3437 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3438 | 17 | GNU General Public License version 3.0 for more details. | ||
3439 | 18 | |||
3440 | 19 | You should have received a copy of the GNU General Public | ||
3441 | 20 | License along with this library. If not, see | ||
3442 | 21 | <http://www.gnu.org/licenses/>. | ||
3443 | 22 | */ | ||
3444 | 23 | |||
3445 | 24 | |||
3446 | 25 | #include <gtk/gtk.h> | ||
3447 | 26 | #include <libindicator/indicator-object.h> | ||
3448 | 27 | |||
3449 | 28 | #define ENTRY_DATA_NAME "indicator-custom-entry-data" | ||
3450 | 29 | |||
3451 | 30 | static void | ||
3452 | 31 | entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) | ||
3453 | 32 | { | ||
3454 | 33 | g_debug("Signal: Entry Added"); | ||
3455 | 34 | |||
3456 | 35 | GtkWidget * menuitem = gtk_menu_item_new(); | ||
3457 | 36 | GtkWidget * hbox = gtk_hbox_new(FALSE, 3); | ||
3458 | 37 | |||
3459 | 38 | if (entry->image != NULL) { | ||
3460 | 39 | gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0); | ||
3461 | 40 | } | ||
3462 | 41 | if (entry->label != NULL) { | ||
3463 | 42 | gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0); | ||
3464 | 43 | } | ||
3465 | 44 | gtk_container_add(GTK_CONTAINER(menuitem), hbox); | ||
3466 | 45 | gtk_widget_show(hbox); | ||
3467 | 46 | |||
3468 | 47 | if (entry->menu != NULL) { | ||
3469 | 48 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu)); | ||
3470 | 49 | } | ||
3471 | 50 | |||
3472 | 51 | gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem); | ||
3473 | 52 | gtk_widget_show(menuitem); | ||
3474 | 53 | |||
3475 | 54 | g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); | ||
3476 | 55 | |||
3477 | 56 | return; | ||
3478 | 57 | } | ||
3479 | 58 | |||
3480 | 59 | static void | ||
3481 | 60 | entry_removed_cb (GtkWidget * widget, gpointer userdata) | ||
3482 | 61 | { | ||
3483 | 62 | gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME); | ||
3484 | 63 | |||
3485 | 64 | if (data != userdata) { | ||
3486 | 65 | return; | ||
3487 | 66 | } | ||
3488 | 67 | |||
3489 | 68 | gtk_widget_destroy(widget); | ||
3490 | 69 | return; | ||
3491 | 70 | } | ||
3492 | 71 | |||
3493 | 72 | static void | ||
3494 | 73 | entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) | ||
3495 | 74 | { | ||
3496 | 75 | g_debug("Signal: Entry Removed"); | ||
3497 | 76 | |||
3498 | 77 | gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry); | ||
3499 | 78 | |||
3500 | 79 | return; | ||
3501 | 80 | } | ||
3502 | 81 | |||
3503 | 82 | static gboolean | ||
3504 | 83 | load_module (const gchar * name, GtkWidget * menu) | ||
3505 | 84 | { | ||
3506 | 85 | g_debug("Looking at Module: %s", name); | ||
3507 | 86 | g_return_val_if_fail(name != NULL, FALSE); | ||
3508 | 87 | |||
3509 | 88 | if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) { | ||
3510 | 89 | return FALSE; | ||
3511 | 90 | } | ||
3512 | 91 | |||
3513 | 92 | g_debug("Loading Module: %s", name); | ||
3514 | 93 | |||
3515 | 94 | /* Build the object for the module */ | ||
3516 | 95 | IndicatorObject * io = indicator_object_new_from_file(name); | ||
3517 | 96 | |||
3518 | 97 | /* Connect to it's signals */ | ||
3519 | 98 | g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu); | ||
3520 | 99 | g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu); | ||
3521 | 100 | |||
3522 | 101 | /* Work on the entries */ | ||
3523 | 102 | GList * entries = indicator_object_get_entries(io); | ||
3524 | 103 | GList * entry = NULL; | ||
3525 | 104 | |||
3526 | 105 | for (entry = entries; entry != NULL; entry = g_list_next(entry)) { | ||
3527 | 106 | IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data; | ||
3528 | 107 | entry_added(io, entrydata, menu); | ||
3529 | 108 | } | ||
3530 | 109 | |||
3531 | 110 | g_list_free(entries); | ||
3532 | 111 | |||
3533 | 112 | return TRUE; | ||
3534 | 113 | } | ||
3535 | 114 | |||
3536 | 115 | static void | ||
3537 | 116 | destroy (gpointer data) | ||
3538 | 117 | { | ||
3539 | 118 | gtk_main_quit(); | ||
3540 | 119 | return; | ||
3541 | 120 | } | ||
3542 | 121 | |||
3543 | 122 | int | ||
3544 | 123 | main (int argc, char ** argv) | ||
3545 | 124 | { | ||
3546 | 125 | gtk_init(&argc, &argv); | ||
3547 | 126 | |||
3548 | 127 | if (argc != 2) { | ||
3549 | 128 | g_error("Need filename"); | ||
3550 | 129 | return 1; | ||
3551 | 130 | } | ||
3552 | 131 | |||
3553 | 132 | GtkWidget * menubar = gtk_menu_bar_new(); | ||
3554 | 133 | if (!load_module(argv[1], menubar)) { | ||
3555 | 134 | g_error("Unable to load module"); | ||
3556 | 135 | return 1; | ||
3557 | 136 | } | ||
3558 | 137 | |||
3559 | 138 | GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
3560 | 139 | g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); | ||
3561 | 140 | |||
3562 | 141 | gtk_container_add(GTK_CONTAINER(window), menubar); | ||
3563 | 142 | |||
3564 | 143 | gtk_widget_show(menubar); | ||
3565 | 144 | gtk_widget_show(window); | ||
3566 | 145 | |||
3567 | 146 | gtk_main(); | ||
3568 | 147 | |||
3569 | 148 | return 0; | ||
3570 | 149 | } |