Merge lp:~khurshid-alam/unity-settings-daemon/sharing-plugin into lp:unity-settings-daemon
- sharing-plugin
- Merge into trunk
Proposed by
Khurshid Alam
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | 4183 |
Merged at revision: | 4185 |
Proposed branch: | lp:~khurshid-alam/unity-settings-daemon/sharing-plugin |
Merge into: | lp:unity-settings-daemon |
Diff against target: |
1130 lines (+1029/-1) 11 files modified
configure.ac (+21/-0) debian/control (+1/-0) debian/rules (+1/-1) plugins/Makefile.am (+1/-0) plugins/sharing/Makefile.am (+49/-0) plugins/sharing/gsd-sharing-enums.h (+34/-0) plugins/sharing/gsd-sharing-manager.c (+822/-0) plugins/sharing/gsd-sharing-manager.h (+56/-0) plugins/sharing/gsd-sharing-plugin.c (+28/-0) plugins/sharing/sharing.gnome-settings-plugin.in (+9/-0) plugins/sharing/test-sharing.c (+7/-0) |
To merge this branch: | bzr merge lp:~khurshid-alam/unity-settings-daemon/sharing-plugin |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
Review via email:
|
Commit message
Add sharing plugin
we are importing sharing panel from gnome-control-
Description of the change
PPA: unity7maintaine
Testing: https:/
The related control center branch is https:/
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Marco Trevisan (Treviño) (3v1n0) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2017-03-24 03:49:07 +0000 | |||
3 | +++ configure.ac 2018-09-30 12:23:49 +0000 | |||
4 | @@ -58,6 +58,7 @@ | |||
5 | 58 | GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=3.7.2.1 | 58 | GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=3.7.2.1 |
6 | 59 | XRANDR_REQUIRED_VERSION=1.3 | 59 | XRANDR_REQUIRED_VERSION=1.3 |
7 | 60 | XEXT_REQUIRED_VERSION=1.1 | 60 | XEXT_REQUIRED_VERSION=1.1 |
8 | 61 | NM_REQUIRED_VERSION=1.0 | ||
9 | 61 | 62 | ||
10 | 62 | EXTRA_COMPILE_WARNINGS(yes) | 63 | EXTRA_COMPILE_WARNINGS(yes) |
11 | 63 | 64 | ||
12 | @@ -376,6 +377,24 @@ | |||
13 | 376 | 377 | ||
14 | 377 | AC_SUBST(NSS_DATABASE) | 378 | AC_SUBST(NSS_DATABASE) |
15 | 378 | 379 | ||
16 | 380 | dnl --------------------------------------------------------------------------- | ||
17 | 381 | dnl Sharing plugin | ||
18 | 382 | dnl --------------------------------------------------------------------------- | ||
19 | 383 | |||
20 | 384 | AC_ARG_ENABLE(network-manager, | ||
21 | 385 | AS_HELP_STRING([--disable-network-manager], | ||
22 | 386 | [Disable NetworkManager support]), | ||
23 | 387 | enable_network_manager=$enableval, | ||
24 | 388 | enable_network_manager=yes) | ||
25 | 389 | |||
26 | 390 | if test "x$enable_network_manager" = "xyes" ; then | ||
27 | 391 | NM_MODULE="libnm >= $NM_REQUIRED_VERSION" | ||
28 | 392 | AC_DEFINE(HAVE_NETWORK_MANAGER, 1, [Defined if NetworkManager support is enabled]) | ||
29 | 393 | else | ||
30 | 394 | NM_MODULE= | ||
31 | 395 | fi | ||
32 | 396 | |||
33 | 397 | PKG_CHECK_MODULES(SHARING, gio-2.0 $NM_MODULE) | ||
34 | 379 | 398 | ||
35 | 380 | # --------------------------------------------------------------------------- | 399 | # --------------------------------------------------------------------------- |
36 | 381 | # Enable Profiling | 400 | # Enable Profiling |
37 | @@ -497,6 +516,7 @@ | |||
38 | 497 | plugins/orientation/Makefile | 516 | plugins/orientation/Makefile |
39 | 498 | plugins/remote-display/Makefile | 517 | plugins/remote-display/Makefile |
40 | 499 | plugins/screensaver-proxy/Makefile | 518 | plugins/screensaver-proxy/Makefile |
41 | 519 | plugins/sharing/Makefile | ||
42 | 500 | plugins/smartcard/Makefile | 520 | plugins/smartcard/Makefile |
43 | 501 | plugins/sound/Makefile | 521 | plugins/sound/Makefile |
44 | 502 | plugins/updates/Makefile | 522 | plugins/updates/Makefile |
45 | @@ -537,6 +557,7 @@ | |||
46 | 537 | 557 | ||
47 | 538 | Session tracking: ${SESSION_TRACKING} | 558 | Session tracking: ${SESSION_TRACKING} |
48 | 539 | LCMS DICT support: ${have_new_lcms} | 559 | LCMS DICT support: ${have_new_lcms} |
49 | 560 | NetworkManager support: ${enable_network_manager} | ||
50 | 540 | IBus support: ${enable_ibus} | 561 | IBus support: ${enable_ibus} |
51 | 541 | Fcitx support: ${enable_fcitx} | 562 | Fcitx support: ${enable_fcitx} |
52 | 542 | Libnotify support: ${have_libnotify} | 563 | Libnotify support: ${have_libnotify} |
53 | 543 | 564 | ||
54 | === modified file 'debian/control' | |||
55 | --- debian/control 2018-04-13 18:45:04 +0000 | |||
56 | +++ debian/control 2018-09-30 12:23:49 +0000 | |||
57 | @@ -13,6 +13,7 @@ | |||
58 | 13 | libdbus-glib-1-dev (>= 0.74), | 13 | libdbus-glib-1-dev (>= 0.74), |
59 | 14 | libglib2.0-dev (>= 2.35.3), | 14 | libglib2.0-dev (>= 2.35.3), |
60 | 15 | libgtk-3-dev (>= 3.7.8), | 15 | libgtk-3-dev (>= 3.7.8), |
61 | 16 | libnm-dev (>= 1.0) [linux-any], | ||
62 | 16 | libnotify-dev (>= 0.7.0), | 17 | libnotify-dev (>= 0.7.0), |
63 | 17 | libxt-dev, | 18 | libxt-dev, |
64 | 18 | libxi-dev, | 19 | libxi-dev, |
65 | 19 | 20 | ||
66 | === modified file 'debian/rules' | |||
67 | --- debian/rules 2018-04-13 18:45:04 +0000 | |||
68 | +++ debian/rules 2018-09-30 12:23:49 +0000 | |||
69 | @@ -8,7 +8,7 @@ | |||
70 | 8 | 8 | ||
71 | 9 | DEB_DH_MAKESHLIBS_ARGS_ALL += -X/usr/lib/unity-settings-daemon-1.0 | 9 | DEB_DH_MAKESHLIBS_ARGS_ALL += -X/usr/lib/unity-settings-daemon-1.0 |
72 | 10 | DEB_CONFIGURE_SCRIPT := ./autogen.sh | 10 | DEB_CONFIGURE_SCRIPT := ./autogen.sh |
74 | 11 | DEB_CONFIGURE_EXTRA_FLAGS = --disable-packagekit --enable-ibus --enable-fcitx | 11 | DEB_CONFIGURE_EXTRA_FLAGS = --disable-packagekit --enable-ibus --enable-fcitx --enable-network-manager |
75 | 12 | 12 | ||
76 | 13 | build/unity-settings-daemon:: | 13 | build/unity-settings-daemon:: |
77 | 14 | gcc -o gnome-settings-daemon/gnome-update-wallpaper-cache debian/gnome-update-wallpaper-cache.c `pkg-config --cflags --libs glib-2.0 gdk-3.0 gdk-x11-3.0 gio-2.0 gnome-desktop-3.0` | 14 | gcc -o gnome-settings-daemon/gnome-update-wallpaper-cache debian/gnome-update-wallpaper-cache.c `pkg-config --cflags --libs glib-2.0 gdk-3.0 gdk-x11-3.0 gio-2.0 gnome-desktop-3.0` |
78 | 15 | 15 | ||
79 | === modified file 'plugins/Makefile.am' | |||
80 | --- plugins/Makefile.am 2017-03-24 03:49:07 +0000 | |||
81 | +++ plugins/Makefile.am 2018-09-30 12:23:49 +0000 | |||
82 | @@ -16,6 +16,7 @@ | |||
83 | 16 | mouse \ | 16 | mouse \ |
84 | 17 | remote-display \ | 17 | remote-display \ |
85 | 18 | screensaver-proxy \ | 18 | screensaver-proxy \ |
86 | 19 | sharing \ | ||
87 | 19 | sound \ | 20 | sound \ |
88 | 20 | xrandr \ | 21 | xrandr \ |
89 | 21 | xsettings \ | 22 | xsettings \ |
90 | 22 | 23 | ||
91 | === added directory 'plugins/sharing' | |||
92 | === added file 'plugins/sharing/Makefile.am' | |||
93 | --- plugins/sharing/Makefile.am 1970-01-01 00:00:00 +0000 | |||
94 | +++ plugins/sharing/Makefile.am 2018-09-30 12:23:49 +0000 | |||
95 | @@ -0,0 +1,49 @@ | |||
96 | 1 | plugin_name = sharing | ||
97 | 2 | |||
98 | 3 | plugin_LTLIBRARIES = libsharing.la | ||
99 | 4 | |||
100 | 5 | libsharing_la_SOURCES = \ | ||
101 | 6 | gsd-sharing-manager.c \ | ||
102 | 7 | gsd-sharing-manager.h \ | ||
103 | 8 | gsd-sharing-enums.h \ | ||
104 | 9 | gsd-sharing-plugin.c | ||
105 | 10 | |||
106 | 11 | libsharing_la_CPPFLAGS = \ | ||
107 | 12 | -I$(top_srcdir)/gnome-settings-daemon \ | ||
108 | 13 | -I$(top_builddir)/gnome-settings-daemon \ | ||
109 | 14 | -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ | ||
110 | 15 | $(AM_CPPFLAGS) | ||
111 | 16 | |||
112 | 17 | libsharing_la_CFLAGS = \ | ||
113 | 18 | -I$(top_srcdir)/plugins/common \ | ||
114 | 19 | $(SHARING_CFLAGS) \ | ||
115 | 20 | $(PLUGIN_CFLAGS) \ | ||
116 | 21 | $(SETTINGS_PLUGIN_CFLAGS) \ | ||
117 | 22 | $(AM_CFLAGS) | ||
118 | 23 | |||
119 | 24 | libsharing_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) | ||
120 | 25 | |||
121 | 26 | libsharing_la_LIBADD = $(SETTINGS_PLUGIN_LIBS) $(SHARING_LIBS) | ||
122 | 27 | |||
123 | 28 | noinst_PROGRAMS = gsd-test-sharing | ||
124 | 29 | gsd_test_sharing_SOURCES = \ | ||
125 | 30 | gsd-sharing-manager.c \ | ||
126 | 31 | gsd-sharing-manager.h \ | ||
127 | 32 | test-sharing.c | ||
128 | 33 | |||
129 | 34 | gsd_test_sharing_CFLAGS = $(libsharing_la_CFLAGS) | ||
130 | 35 | gsd_test_sharing_CPPFLAGS = $(libsharing_la_CPPFLAGS) | ||
131 | 36 | gsd_test_sharing_LDADD = \ | ||
132 | 37 | $(top_builddir)/gnome-settings-daemon/libgsd.la \ | ||
133 | 38 | $(SHARING_LIBS) \ | ||
134 | 39 | $(SETTINGS_PLUGIN_LIBS) | ||
135 | 40 | |||
136 | 41 | plugin_in_files = sharing.gnome-settings-plugin.in | ||
137 | 42 | |||
138 | 43 | plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) | ||
139 | 44 | |||
140 | 45 | EXTRA_DIST = $(plugin_in_files) | ||
141 | 46 | CLEANFILES = $(plugin_DATA) | ||
142 | 47 | DISTCLEANFILES = $(plugin_DATA) | ||
143 | 48 | |||
144 | 49 | @GSD_INTLTOOL_PLUGIN_RULE@ | ||
145 | 0 | 50 | ||
146 | === added file 'plugins/sharing/gsd-sharing-enums.h' | |||
147 | --- plugins/sharing/gsd-sharing-enums.h 1970-01-01 00:00:00 +0000 | |||
148 | +++ plugins/sharing/gsd-sharing-enums.h 2018-09-30 12:23:49 +0000 | |||
149 | @@ -0,0 +1,34 @@ | |||
150 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
151 | 2 | * | ||
152 | 3 | * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> | ||
153 | 4 | * | ||
154 | 5 | * This program is free software; you can redistribute it and/or modify | ||
155 | 6 | * it under the terms of the GNU General Public License as published by | ||
156 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
157 | 8 | * (at your option) any later version. | ||
158 | 9 | * | ||
159 | 10 | * This program is distributed in the hope that it will be useful, | ||
160 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
161 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
162 | 13 | * GNU General Public License for more details. | ||
163 | 14 | * | ||
164 | 15 | * You should have received a copy of the GNU General Public License | ||
165 | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
166 | 17 | * | ||
167 | 18 | */ | ||
168 | 19 | |||
169 | 20 | #ifndef __GSD_SHARING_ENUMS_H | ||
170 | 21 | #define __GSD_SHARING_ENUMS_H | ||
171 | 22 | |||
172 | 23 | G_BEGIN_DECLS | ||
173 | 24 | |||
174 | 25 | typedef enum { | ||
175 | 26 | GSD_SHARING_STATUS_OFFLINE, | ||
176 | 27 | GSD_SHARING_STATUS_DISABLED_MOBILE_BROADBAND, | ||
177 | 28 | GSD_SHARING_STATUS_DISABLED_LOW_SECURITY, | ||
178 | 29 | GSD_SHARING_STATUS_AVAILABLE | ||
179 | 30 | } GsdSharingStatus; | ||
180 | 31 | |||
181 | 32 | G_END_DECLS | ||
182 | 33 | |||
183 | 34 | #endif /* __GSD_SHARING_ENUMS_H */ | ||
184 | 0 | 35 | ||
185 | === added file 'plugins/sharing/gsd-sharing-manager.c' | |||
186 | --- plugins/sharing/gsd-sharing-manager.c 1970-01-01 00:00:00 +0000 | |||
187 | +++ plugins/sharing/gsd-sharing-manager.c 2018-09-30 12:23:49 +0000 | |||
188 | @@ -0,0 +1,822 @@ | |||
189 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
190 | 2 | * | ||
191 | 3 | * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> | ||
192 | 4 | * | ||
193 | 5 | * This program is free software; you can redistribute it and/or modify | ||
194 | 6 | * it under the terms of the GNU General Public License as published by | ||
195 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
196 | 8 | * (at your option) any later version. | ||
197 | 9 | * | ||
198 | 10 | * This program is distributed in the hope that it will be useful, | ||
199 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
200 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
201 | 13 | * GNU General Public License for more details. | ||
202 | 14 | * | ||
203 | 15 | * You should have received a copy of the GNU General Public License | ||
204 | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
205 | 17 | * | ||
206 | 18 | */ | ||
207 | 19 | |||
208 | 20 | #include "config.h" | ||
209 | 21 | |||
210 | 22 | #include <locale.h> | ||
211 | 23 | #include <glib.h> | ||
212 | 24 | #include <gio/gio.h> | ||
213 | 25 | #include <gio/gdesktopappinfo.h> | ||
214 | 26 | #include <glib/gstdio.h> | ||
215 | 27 | |||
216 | 28 | #ifdef HAVE_NETWORK_MANAGER | ||
217 | 29 | #include <NetworkManager.h> | ||
218 | 30 | #endif /* HAVE_NETWORK_MANAGER */ | ||
219 | 31 | |||
220 | 32 | #include "gnome-settings-plugin.h" | ||
221 | 33 | #include "gnome-settings-profile.h" | ||
222 | 34 | #include "gsd-sharing-manager.h" | ||
223 | 35 | #include "gsd-sharing-enums.h" | ||
224 | 36 | |||
225 | 37 | #define GSD_SHARING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerPrivate)) | ||
226 | 38 | |||
227 | 39 | typedef struct { | ||
228 | 40 | const char *name; | ||
229 | 41 | GSettings *settings; | ||
230 | 42 | gboolean started; | ||
231 | 43 | GSubprocess *process; | ||
232 | 44 | } ServiceInfo; | ||
233 | 45 | |||
234 | 46 | struct GsdSharingManagerPrivate | ||
235 | 47 | { | ||
236 | 48 | GDBusNodeInfo *introspection_data; | ||
237 | 49 | guint name_id; | ||
238 | 50 | GDBusConnection *connection; | ||
239 | 51 | |||
240 | 52 | GCancellable *cancellable; | ||
241 | 53 | #ifdef HAVE_NETWORK_MANAGER | ||
242 | 54 | NMClient *client; | ||
243 | 55 | #endif /* HAVE_NETWORK_MANAGER */ | ||
244 | 56 | |||
245 | 57 | GHashTable *services; | ||
246 | 58 | |||
247 | 59 | char *current_network; | ||
248 | 60 | char *current_network_name; | ||
249 | 61 | char *carrier_type; | ||
250 | 62 | GsdSharingStatus sharing_status; | ||
251 | 63 | }; | ||
252 | 64 | |||
253 | 65 | #define GSD_SHARING_DBUS_NAME GSD_DBUS_NAME ".Sharing" | ||
254 | 66 | #define GSD_SHARING_DBUS_PATH GSD_DBUS_PATH "/Sharing" | ||
255 | 67 | |||
256 | 68 | static const gchar introspection_xml[] = | ||
257 | 69 | "<node>" | ||
258 | 70 | " <interface name='org.gnome.SettingsDaemon.Sharing'>" | ||
259 | 71 | " <annotation name='org.freedesktop.DBus.GLib.CSymbol' value='gsd_sharing_manager'/>" | ||
260 | 72 | " <property name='CurrentNetwork' type='s' access='read'/>" | ||
261 | 73 | " <property name='CurrentNetworkName' type='s' access='read'/>" | ||
262 | 74 | " <property name='CarrierType' type='s' access='read'/>" | ||
263 | 75 | " <property name='SharingStatus' type='u' access='read'/>" | ||
264 | 76 | " <method name='EnableService'>" | ||
265 | 77 | " <arg name='service-name' direction='in' type='s'/>" | ||
266 | 78 | " </method>" | ||
267 | 79 | " <method name='DisableService'>" | ||
268 | 80 | " <arg name='service-name' direction='in' type='s'/>" | ||
269 | 81 | " <arg name='network' direction='in' type='s'/>" | ||
270 | 82 | " </method>" | ||
271 | 83 | " <method name='ListNetworks'>" | ||
272 | 84 | " <arg name='service-name' direction='in' type='s'/>" | ||
273 | 85 | " <arg name='networks' direction='out' type='a(sss)'/>" | ||
274 | 86 | " </method>" | ||
275 | 87 | " </interface>" | ||
276 | 88 | "</node>"; | ||
277 | 89 | |||
278 | 90 | static void gsd_sharing_manager_class_init (GsdSharingManagerClass *klass); | ||
279 | 91 | static void gsd_sharing_manager_init (GsdSharingManager *manager); | ||
280 | 92 | static void gsd_sharing_manager_finalize (GObject *object); | ||
281 | 93 | |||
282 | 94 | G_DEFINE_TYPE (GsdSharingManager, gsd_sharing_manager, G_TYPE_OBJECT) | ||
283 | 95 | |||
284 | 96 | static gpointer manager_object = NULL; | ||
285 | 97 | |||
286 | 98 | static const char * const services[] = { | ||
287 | 99 | "rygel", | ||
288 | 100 | "vino-server", | ||
289 | 101 | "gnome-user-share-webdav" | ||
290 | 102 | }; | ||
291 | 103 | |||
292 | 104 | static void | ||
293 | 105 | gsd_sharing_manager_start_service (GsdSharingManager *manager, | ||
294 | 106 | ServiceInfo *service) | ||
295 | 107 | { | ||
296 | 108 | GDesktopAppInfo *app; | ||
297 | 109 | const char *exec; | ||
298 | 110 | char *desktop, **argvp; | ||
299 | 111 | GError *error = NULL; | ||
300 | 112 | |||
301 | 113 | if (service->started) | ||
302 | 114 | return; | ||
303 | 115 | g_debug ("About to start %s", service->name); | ||
304 | 116 | |||
305 | 117 | desktop = g_strdup_printf ("%s.desktop", service->name); | ||
306 | 118 | app = g_desktop_app_info_new (desktop); | ||
307 | 119 | g_free (desktop); | ||
308 | 120 | |||
309 | 121 | if (!app) { | ||
310 | 122 | g_warning ("Could not find desktop file for service '%s'", service->name); | ||
311 | 123 | return; | ||
312 | 124 | } | ||
313 | 125 | |||
314 | 126 | exec = g_app_info_get_commandline (G_APP_INFO (app)); | ||
315 | 127 | |||
316 | 128 | if (!g_shell_parse_argv (exec, NULL, &argvp, &error)) { | ||
317 | 129 | g_warning ("Could not parse command-line '%s': %s", exec, error->message); | ||
318 | 130 | g_error_free (error); | ||
319 | 131 | g_object_unref (app); | ||
320 | 132 | return; | ||
321 | 133 | } | ||
322 | 134 | |||
323 | 135 | service->process = g_subprocess_newv ((const gchar * const*) argvp, G_SUBPROCESS_FLAGS_NONE, &error); | ||
324 | 136 | |||
325 | 137 | if (!service->process) { | ||
326 | 138 | g_warning ("Could not start command-line '%s': %s", exec, error->message); | ||
327 | 139 | g_error_free (error); | ||
328 | 140 | service->started = FALSE; | ||
329 | 141 | } else { | ||
330 | 142 | service->started = TRUE; | ||
331 | 143 | } | ||
332 | 144 | |||
333 | 145 | g_strfreev (argvp); | ||
334 | 146 | g_object_unref (app); | ||
335 | 147 | } | ||
336 | 148 | |||
337 | 149 | #ifdef HAVE_NETWORK_MANAGER | ||
338 | 150 | static gboolean | ||
339 | 151 | service_is_enabled_on_current_connection (GsdSharingManager *manager, | ||
340 | 152 | ServiceInfo *service) | ||
341 | 153 | { | ||
342 | 154 | char **connections; | ||
343 | 155 | int j; | ||
344 | 156 | gboolean ret; | ||
345 | 157 | connections = g_settings_get_strv (service->settings, "enabled-connections"); | ||
346 | 158 | ret = FALSE; | ||
347 | 159 | for (j = 0; connections[j] != NULL; j++) { | ||
348 | 160 | if (g_strcmp0 (connections[j], manager->priv->current_network) == 0) { | ||
349 | 161 | ret = TRUE; | ||
350 | 162 | break; | ||
351 | 163 | } | ||
352 | 164 | } | ||
353 | 165 | |||
354 | 166 | g_strfreev (connections); | ||
355 | 167 | return ret; | ||
356 | 168 | } | ||
357 | 169 | #else | ||
358 | 170 | static gboolean | ||
359 | 171 | service_is_enabled_on_current_connection (GsdSharingManager *manager, | ||
360 | 172 | ServiceInfo *service) | ||
361 | 173 | { | ||
362 | 174 | return FALSE; | ||
363 | 175 | } | ||
364 | 176 | #endif /* HAVE_NETWORK_MANAGER */ | ||
365 | 177 | |||
366 | 178 | static void | ||
367 | 179 | gsd_sharing_manager_stop_service (GsdSharingManager *manager, | ||
368 | 180 | ServiceInfo *service) | ||
369 | 181 | { | ||
370 | 182 | if (!service->started || | ||
371 | 183 | service->process == NULL) { | ||
372 | 184 | return; | ||
373 | 185 | } | ||
374 | 186 | |||
375 | 187 | g_debug ("About to stop %s", service->name); | ||
376 | 188 | |||
377 | 189 | g_subprocess_send_signal (service->process, SIGTERM); | ||
378 | 190 | g_clear_object (&service->process); | ||
379 | 191 | service->started = FALSE; | ||
380 | 192 | } | ||
381 | 193 | |||
382 | 194 | static void | ||
383 | 195 | gsd_sharing_manager_sync_services (GsdSharingManager *manager) | ||
384 | 196 | { | ||
385 | 197 | GList *services, *l; | ||
386 | 198 | |||
387 | 199 | services = g_hash_table_get_values (manager->priv->services); | ||
388 | 200 | |||
389 | 201 | for (l = services; l != NULL; l = l->next) { | ||
390 | 202 | ServiceInfo *service = l->data; | ||
391 | 203 | gboolean should_be_started = FALSE; | ||
392 | 204 | |||
393 | 205 | if (manager->priv->sharing_status == GSD_SHARING_STATUS_AVAILABLE && | ||
394 | 206 | service_is_enabled_on_current_connection (manager, service)) | ||
395 | 207 | should_be_started = TRUE; | ||
396 | 208 | |||
397 | 209 | if (service->started != should_be_started) { | ||
398 | 210 | if (service->started) | ||
399 | 211 | gsd_sharing_manager_stop_service (manager, service); | ||
400 | 212 | else | ||
401 | 213 | gsd_sharing_manager_start_service (manager, service); | ||
402 | 214 | } | ||
403 | 215 | } | ||
404 | 216 | g_list_free (services); | ||
405 | 217 | } | ||
406 | 218 | |||
407 | 219 | #ifdef HAVE_NETWORK_MANAGER | ||
408 | 220 | static void | ||
409 | 221 | properties_changed (GsdSharingManager *manager) | ||
410 | 222 | { | ||
411 | 223 | GVariantBuilder props_builder; | ||
412 | 224 | GVariant *props_changed = NULL; | ||
413 | 225 | |||
414 | 226 | /* not yet connected to the session bus */ | ||
415 | 227 | if (manager->priv->connection == NULL) | ||
416 | 228 | return; | ||
417 | 229 | |||
418 | 230 | g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); | ||
419 | 231 | |||
420 | 232 | g_variant_builder_add (&props_builder, "{sv}", "CurrentNetwork", | ||
421 | 233 | g_variant_new_string (manager->priv->current_network)); | ||
422 | 234 | g_variant_builder_add (&props_builder, "{sv}", "CurrentNetworkName", | ||
423 | 235 | g_variant_new_string (manager->priv->current_network_name)); | ||
424 | 236 | g_variant_builder_add (&props_builder, "{sv}", "CarrierType", | ||
425 | 237 | g_variant_new_string (manager->priv->carrier_type)); | ||
426 | 238 | g_variant_builder_add (&props_builder, "{sv}", "SharingStatus", | ||
427 | 239 | g_variant_new_uint32 (manager->priv->sharing_status)); | ||
428 | 240 | |||
429 | 241 | props_changed = g_variant_new ("(s@a{sv}@as)", GSD_SHARING_DBUS_NAME, | ||
430 | 242 | g_variant_builder_end (&props_builder), | ||
431 | 243 | g_variant_new_strv (NULL, 0)); | ||
432 | 244 | |||
433 | 245 | g_dbus_connection_emit_signal (manager->priv->connection, | ||
434 | 246 | NULL, | ||
435 | 247 | GSD_SHARING_DBUS_PATH, | ||
436 | 248 | "org.freedesktop.DBus.Properties", | ||
437 | 249 | "PropertiesChanged", | ||
438 | 250 | props_changed, NULL); | ||
439 | 251 | } | ||
440 | 252 | |||
441 | 253 | static char ** | ||
442 | 254 | get_connections_for_service (GsdSharingManager *manager, | ||
443 | 255 | const char *service_name) | ||
444 | 256 | { | ||
445 | 257 | ServiceInfo *service; | ||
446 | 258 | |||
447 | 259 | service = g_hash_table_lookup (manager->priv->services, service_name); | ||
448 | 260 | return g_settings_get_strv (service->settings, "enabled-connections"); | ||
449 | 261 | } | ||
450 | 262 | #else | ||
451 | 263 | static char ** | ||
452 | 264 | get_connections_for_service (GsdSharingManager *manager, | ||
453 | 265 | const char *service_name) | ||
454 | 266 | { | ||
455 | 267 | const char * const * connections [] = { NULL }; | ||
456 | 268 | return g_strdupv ((char **) connections); | ||
457 | 269 | } | ||
458 | 270 | #endif /* HAVE_NETWORK_MANAGER */ | ||
459 | 271 | |||
460 | 272 | static gboolean | ||
461 | 273 | check_service (GsdSharingManager *manager, | ||
462 | 274 | const char *service_name, | ||
463 | 275 | GError **error) | ||
464 | 276 | { | ||
465 | 277 | if (g_hash_table_lookup (manager->priv->services, service_name)) | ||
466 | 278 | return TRUE; | ||
467 | 279 | |||
468 | 280 | g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, | ||
469 | 281 | "Invalid service name '%s'", service_name); | ||
470 | 282 | return FALSE; | ||
471 | 283 | } | ||
472 | 284 | |||
473 | 285 | static gboolean | ||
474 | 286 | gsd_sharing_manager_enable_service (GsdSharingManager *manager, | ||
475 | 287 | const char *service_name, | ||
476 | 288 | GError **error) | ||
477 | 289 | { | ||
478 | 290 | ServiceInfo *service; | ||
479 | 291 | char **connections; | ||
480 | 292 | GPtrArray *array; | ||
481 | 293 | guint i; | ||
482 | 294 | |||
483 | 295 | if (!check_service (manager, service_name, error)) | ||
484 | 296 | return FALSE; | ||
485 | 297 | |||
486 | 298 | if (manager->priv->sharing_status != GSD_SHARING_STATUS_AVAILABLE) { | ||
487 | 299 | g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, | ||
488 | 300 | "Sharing cannot be enabled on this network, status is '%d'", manager->priv->sharing_status); | ||
489 | 301 | return FALSE; | ||
490 | 302 | } | ||
491 | 303 | |||
492 | 304 | service = g_hash_table_lookup (manager->priv->services, service_name); | ||
493 | 305 | connections = g_settings_get_strv (service->settings, "enabled-connections"); | ||
494 | 306 | array = g_ptr_array_new (); | ||
495 | 307 | for (i = 0; connections[i] != NULL; i++) { | ||
496 | 308 | if (g_strcmp0 (connections[i], manager->priv->current_network) == 0) | ||
497 | 309 | goto bail; | ||
498 | 310 | g_ptr_array_add (array, connections[i]); | ||
499 | 311 | } | ||
500 | 312 | g_ptr_array_add (array, manager->priv->current_network); | ||
501 | 313 | g_ptr_array_add (array, NULL); | ||
502 | 314 | |||
503 | 315 | g_settings_set_strv (service->settings, "enabled-connections", (const gchar *const *) array->pdata); | ||
504 | 316 | |||
505 | 317 | bail: | ||
506 | 318 | |||
507 | 319 | gsd_sharing_manager_start_service (manager, service); | ||
508 | 320 | |||
509 | 321 | g_ptr_array_unref (array); | ||
510 | 322 | g_strfreev (connections); | ||
511 | 323 | |||
512 | 324 | return TRUE; | ||
513 | 325 | } | ||
514 | 326 | |||
515 | 327 | static gboolean | ||
516 | 328 | gsd_sharing_manager_disable_service (GsdSharingManager *manager, | ||
517 | 329 | const char *service_name, | ||
518 | 330 | const char *network_name, | ||
519 | 331 | GError **error) | ||
520 | 332 | { | ||
521 | 333 | ServiceInfo *service; | ||
522 | 334 | char **connections; | ||
523 | 335 | GPtrArray *array; | ||
524 | 336 | guint i; | ||
525 | 337 | |||
526 | 338 | if (!check_service (manager, service_name, error)) | ||
527 | 339 | return FALSE; | ||
528 | 340 | |||
529 | 341 | service = g_hash_table_lookup (manager->priv->services, service_name); | ||
530 | 342 | connections = g_settings_get_strv (service->settings, "enabled-connections"); | ||
531 | 343 | array = g_ptr_array_new (); | ||
532 | 344 | for (i = 0; connections[i] != NULL; i++) { | ||
533 | 345 | if (g_strcmp0 (connections[i], network_name) != 0) | ||
534 | 346 | g_ptr_array_add (array, connections[i]); | ||
535 | 347 | } | ||
536 | 348 | g_ptr_array_add (array, NULL); | ||
537 | 349 | |||
538 | 350 | g_settings_set_strv (service->settings, "enabled-connections", (const gchar *const *) array->pdata); | ||
539 | 351 | g_ptr_array_unref (array); | ||
540 | 352 | g_strfreev (connections); | ||
541 | 353 | |||
542 | 354 | if (g_str_equal (network_name, manager->priv->current_network)) | ||
543 | 355 | gsd_sharing_manager_stop_service (manager, service); | ||
544 | 356 | |||
545 | 357 | return TRUE; | ||
546 | 358 | } | ||
547 | 359 | |||
548 | 360 | #ifdef HAVE_NETWORK_MANAGER | ||
549 | 361 | static const char * | ||
550 | 362 | get_type_and_name_for_connection_uuid (GsdSharingManager *manager, | ||
551 | 363 | const char *uuid, | ||
552 | 364 | const char **name) | ||
553 | 365 | { | ||
554 | 366 | NMRemoteConnection *conn; | ||
555 | 367 | const char *type; | ||
556 | 368 | |||
557 | 369 | if (!manager->priv->client) | ||
558 | 370 | return NULL; | ||
559 | 371 | |||
560 | 372 | conn = nm_client_get_connection_by_uuid (manager->priv->client, uuid); | ||
561 | 373 | if (!conn) | ||
562 | 374 | return NULL; | ||
563 | 375 | type = nm_connection_get_connection_type (NM_CONNECTION (conn)); | ||
564 | 376 | *name = nm_connection_get_id (NM_CONNECTION (conn)); | ||
565 | 377 | |||
566 | 378 | return type; | ||
567 | 379 | } | ||
568 | 380 | #else | ||
569 | 381 | static const char * | ||
570 | 382 | get_type_and_name_for_connection_uuid (GsdSharingManager *manager, | ||
571 | 383 | const char *id, | ||
572 | 384 | const char **name) | ||
573 | 385 | { | ||
574 | 386 | return NULL; | ||
575 | 387 | } | ||
576 | 388 | #endif /* HAVE_NETWORK_MANAGER */ | ||
577 | 389 | |||
578 | 390 | #ifdef HAVE_NETWORK_MANAGER | ||
579 | 391 | static gboolean | ||
580 | 392 | connection_is_low_security (GsdSharingManager *manager, | ||
581 | 393 | const char *uuid) | ||
582 | 394 | { | ||
583 | 395 | NMRemoteConnection *conn; | ||
584 | 396 | |||
585 | 397 | if (!manager->priv->client) | ||
586 | 398 | return TRUE; | ||
587 | 399 | |||
588 | 400 | conn = nm_client_get_connection_by_uuid (manager->priv->client, uuid); | ||
589 | 401 | if (!conn) | ||
590 | 402 | return TRUE; | ||
591 | 403 | |||
592 | 404 | /* Disable sharing on open Wi-Fi | ||
593 | 405 | * XXX: Also do this for WEP networks? */ | ||
594 | 406 | return (nm_connection_get_setting_wireless_security (NM_CONNECTION (conn)) == NULL); | ||
595 | 407 | } | ||
596 | 408 | #endif /* HAVE_NETWORK_MANAGER */ | ||
597 | 409 | |||
598 | 410 | static GVariant * | ||
599 | 411 | gsd_sharing_manager_list_networks (GsdSharingManager *manager, | ||
600 | 412 | const char *service_name, | ||
601 | 413 | GError **error) | ||
602 | 414 | { | ||
603 | 415 | char **connections; | ||
604 | 416 | GVariantBuilder builder; | ||
605 | 417 | guint i; | ||
606 | 418 | |||
607 | 419 | if (!check_service (manager, service_name, error)) | ||
608 | 420 | return NULL; | ||
609 | 421 | |||
610 | 422 | #ifdef HAVE_NETWORK_MANAGER | ||
611 | 423 | if (!manager->priv->client) { | ||
612 | 424 | g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Not ready yet"); | ||
613 | 425 | return NULL; | ||
614 | 426 | } | ||
615 | 427 | #endif /* HAVE_NETWORK_MANAGER */ | ||
616 | 428 | |||
617 | 429 | connections = get_connections_for_service (manager, service_name); | ||
618 | 430 | |||
619 | 431 | g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a(sss))")); | ||
620 | 432 | g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(sss)")); | ||
621 | 433 | |||
622 | 434 | for (i = 0; connections[i] != NULL; i++) { | ||
623 | 435 | const char *type, *name; | ||
624 | 436 | |||
625 | 437 | type = get_type_and_name_for_connection_uuid (manager, connections[i], &name); | ||
626 | 438 | if (!type) | ||
627 | 439 | continue; | ||
628 | 440 | |||
629 | 441 | g_variant_builder_add (&builder, "(sss)", connections[i], name, type); | ||
630 | 442 | } | ||
631 | 443 | g_strfreev (connections); | ||
632 | 444 | |||
633 | 445 | g_variant_builder_close (&builder); | ||
634 | 446 | |||
635 | 447 | return g_variant_builder_end (&builder); | ||
636 | 448 | } | ||
637 | 449 | |||
638 | 450 | static GVariant * | ||
639 | 451 | handle_get_property (GDBusConnection *connection, | ||
640 | 452 | const gchar *sender, | ||
641 | 453 | const gchar *object_path, | ||
642 | 454 | const gchar *interface_name, | ||
643 | 455 | const gchar *property_name, | ||
644 | 456 | GError **error, | ||
645 | 457 | gpointer user_data) | ||
646 | 458 | { | ||
647 | 459 | GsdSharingManager *manager = GSD_SHARING_MANAGER (user_data); | ||
648 | 460 | |||
649 | 461 | /* Check session pointer as a proxy for whether the manager is in the | ||
650 | 462 | start or stop state */ | ||
651 | 463 | if (manager->priv->connection == NULL) | ||
652 | 464 | return NULL; | ||
653 | 465 | |||
654 | 466 | if (g_strcmp0 (property_name, "CurrentNetwork") == 0) { | ||
655 | 467 | return g_variant_new_string (manager->priv->current_network); | ||
656 | 468 | } | ||
657 | 469 | |||
658 | 470 | if (g_strcmp0 (property_name, "CurrentNetworkName") == 0) { | ||
659 | 471 | return g_variant_new_string (manager->priv->current_network_name); | ||
660 | 472 | } | ||
661 | 473 | |||
662 | 474 | if (g_strcmp0 (property_name, "CarrierType") == 0) { | ||
663 | 475 | return g_variant_new_string (manager->priv->carrier_type); | ||
664 | 476 | } | ||
665 | 477 | |||
666 | 478 | if (g_strcmp0 (property_name, "SharingStatus") == 0) { | ||
667 | 479 | return g_variant_new_uint32 (manager->priv->sharing_status); | ||
668 | 480 | } | ||
669 | 481 | |||
670 | 482 | return NULL; | ||
671 | 483 | } | ||
672 | 484 | |||
673 | 485 | static void | ||
674 | 486 | handle_method_call (GDBusConnection *connection, | ||
675 | 487 | const gchar *sender, | ||
676 | 488 | const gchar *object_path, | ||
677 | 489 | const gchar *interface_name, | ||
678 | 490 | const gchar *method_name, | ||
679 | 491 | GVariant *parameters, | ||
680 | 492 | GDBusMethodInvocation *invocation, | ||
681 | 493 | gpointer user_data) | ||
682 | 494 | { | ||
683 | 495 | GsdSharingManager *manager = (GsdSharingManager *) user_data; | ||
684 | 496 | |||
685 | 497 | g_debug ("Calling method '%s' for sharing", method_name); | ||
686 | 498 | |||
687 | 499 | /* Check session pointer as a proxy for whether the manager is in the | ||
688 | 500 | start or stop state */ | ||
689 | 501 | if (manager->priv->connection == NULL) | ||
690 | 502 | return; | ||
691 | 503 | |||
692 | 504 | if (g_strcmp0 (method_name, "EnableService") == 0) { | ||
693 | 505 | const char *service; | ||
694 | 506 | GError *error = NULL; | ||
695 | 507 | |||
696 | 508 | g_variant_get (parameters, "(&s)", &service); | ||
697 | 509 | if (!gsd_sharing_manager_enable_service (manager, service, &error)) | ||
698 | 510 | g_dbus_method_invocation_take_error (invocation, error); | ||
699 | 511 | else | ||
700 | 512 | g_dbus_method_invocation_return_value (invocation, NULL); | ||
701 | 513 | } else if (g_strcmp0 (method_name, "DisableService") == 0) { | ||
702 | 514 | const char *service; | ||
703 | 515 | const char *network_name; | ||
704 | 516 | GError *error = NULL; | ||
705 | 517 | |||
706 | 518 | g_variant_get (parameters, "(&s&s)", &service, &network_name); | ||
707 | 519 | if (!gsd_sharing_manager_disable_service (manager, service, network_name, &error)) | ||
708 | 520 | g_dbus_method_invocation_take_error (invocation, error); | ||
709 | 521 | else | ||
710 | 522 | g_dbus_method_invocation_return_value (invocation, NULL); | ||
711 | 523 | } else if (g_strcmp0 (method_name, "ListNetworks") == 0) { | ||
712 | 524 | const char *service; | ||
713 | 525 | GError *error = NULL; | ||
714 | 526 | GVariant *variant; | ||
715 | 527 | |||
716 | 528 | g_variant_get (parameters, "(&s)", &service); | ||
717 | 529 | variant = gsd_sharing_manager_list_networks (manager, service, &error); | ||
718 | 530 | if (!variant) | ||
719 | 531 | g_dbus_method_invocation_take_error (invocation, error); | ||
720 | 532 | else | ||
721 | 533 | g_dbus_method_invocation_return_value (invocation, variant); | ||
722 | 534 | } | ||
723 | 535 | } | ||
724 | 536 | |||
725 | 537 | static const GDBusInterfaceVTable interface_vtable = | ||
726 | 538 | { | ||
727 | 539 | handle_method_call, | ||
728 | 540 | handle_get_property, | ||
729 | 541 | NULL | ||
730 | 542 | }; | ||
731 | 543 | |||
732 | 544 | static void | ||
733 | 545 | on_bus_gotten (GObject *source_object, | ||
734 | 546 | GAsyncResult *res, | ||
735 | 547 | GsdSharingManager *manager) | ||
736 | 548 | { | ||
737 | 549 | GDBusConnection *connection; | ||
738 | 550 | GError *error = NULL; | ||
739 | 551 | |||
740 | 552 | connection = g_bus_get_finish (res, &error); | ||
741 | 553 | if (connection == NULL) { | ||
742 | 554 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
743 | 555 | g_warning ("Could not get session bus: %s", error->message); | ||
744 | 556 | g_error_free (error); | ||
745 | 557 | return; | ||
746 | 558 | } | ||
747 | 559 | manager->priv->connection = connection; | ||
748 | 560 | |||
749 | 561 | g_dbus_connection_register_object (connection, | ||
750 | 562 | GSD_SHARING_DBUS_PATH, | ||
751 | 563 | manager->priv->introspection_data->interfaces[0], | ||
752 | 564 | &interface_vtable, | ||
753 | 565 | manager, | ||
754 | 566 | NULL, | ||
755 | 567 | NULL); | ||
756 | 568 | |||
757 | 569 | manager->priv->name_id = g_bus_own_name_on_connection (connection, | ||
758 | 570 | GSD_SHARING_DBUS_NAME, | ||
759 | 571 | G_BUS_NAME_OWNER_FLAGS_NONE, | ||
760 | 572 | NULL, | ||
761 | 573 | NULL, | ||
762 | 574 | NULL, | ||
763 | 575 | NULL); | ||
764 | 576 | } | ||
765 | 577 | |||
766 | 578 | #ifdef HAVE_NETWORK_MANAGER | ||
767 | 579 | static void | ||
768 | 580 | primary_connection_changed (GObject *gobject, | ||
769 | 581 | GParamSpec *pspec, | ||
770 | 582 | gpointer user_data) | ||
771 | 583 | { | ||
772 | 584 | GsdSharingManager *manager = user_data; | ||
773 | 585 | NMActiveConnection *a_con; | ||
774 | 586 | |||
775 | 587 | a_con = nm_client_get_primary_connection (manager->priv->client); | ||
776 | 588 | |||
777 | 589 | g_clear_pointer (&manager->priv->current_network, g_free); | ||
778 | 590 | g_clear_pointer (&manager->priv->current_network_name, g_free); | ||
779 | 591 | g_clear_pointer (&manager->priv->carrier_type, g_free); | ||
780 | 592 | |||
781 | 593 | if (a_con) { | ||
782 | 594 | manager->priv->current_network = g_strdup (nm_active_connection_get_uuid (a_con)); | ||
783 | 595 | manager->priv->current_network_name = g_strdup (nm_active_connection_get_id (a_con)); | ||
784 | 596 | manager->priv->carrier_type = g_strdup (nm_active_connection_get_connection_type (a_con)); | ||
785 | 597 | if (manager->priv->carrier_type == NULL) | ||
786 | 598 | manager->priv->carrier_type = g_strdup (""); | ||
787 | 599 | } else { | ||
788 | 600 | manager->priv->current_network = g_strdup (""); | ||
789 | 601 | manager->priv->current_network_name = g_strdup (""); | ||
790 | 602 | manager->priv->carrier_type = g_strdup (""); | ||
791 | 603 | } | ||
792 | 604 | |||
793 | 605 | if (!a_con) { | ||
794 | 606 | manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; | ||
795 | 607 | } else if (*(manager->priv->carrier_type) == '\0') { | ||
796 | 608 | /* Missing carrier type information? */ | ||
797 | 609 | manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; | ||
798 | 610 | } else if (g_str_equal (manager->priv->carrier_type, "bluetooth") || | ||
799 | 611 | g_str_equal (manager->priv->carrier_type, "gsm") || | ||
800 | 612 | g_str_equal (manager->priv->carrier_type, "cdma")) { | ||
801 | 613 | manager->priv->sharing_status = GSD_SHARING_STATUS_DISABLED_MOBILE_BROADBAND; | ||
802 | 614 | } else if (g_str_equal (manager->priv->carrier_type, "802-11-wireless")) { | ||
803 | 615 | if (connection_is_low_security (manager, manager->priv->current_network)) | ||
804 | 616 | manager->priv->sharing_status = GSD_SHARING_STATUS_DISABLED_LOW_SECURITY; | ||
805 | 617 | else | ||
806 | 618 | manager->priv->sharing_status = GSD_SHARING_STATUS_AVAILABLE; | ||
807 | 619 | } else { | ||
808 | 620 | manager->priv->sharing_status = GSD_SHARING_STATUS_AVAILABLE; | ||
809 | 621 | } | ||
810 | 622 | |||
811 | 623 | g_debug ("current network: %s", manager->priv->current_network); | ||
812 | 624 | g_debug ("current network name: %s", manager->priv->current_network_name); | ||
813 | 625 | g_debug ("conn type: %s", manager->priv->carrier_type); | ||
814 | 626 | g_debug ("status: %d", manager->priv->sharing_status); | ||
815 | 627 | |||
816 | 628 | properties_changed (manager); | ||
817 | 629 | gsd_sharing_manager_sync_services (manager); | ||
818 | 630 | } | ||
819 | 631 | |||
820 | 632 | static void | ||
821 | 633 | nm_client_ready (GObject *source_object, | ||
822 | 634 | GAsyncResult *res, | ||
823 | 635 | gpointer user_data) | ||
824 | 636 | { | ||
825 | 637 | GsdSharingManager *manager = user_data; | ||
826 | 638 | GError *error = NULL; | ||
827 | 639 | NMClient *client; | ||
828 | 640 | |||
829 | 641 | client = nm_client_new_finish (res, &error); | ||
830 | 642 | if (!client) { | ||
831 | 643 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
832 | 644 | g_warning ("Couldn't get NMClient: %s", error->message); | ||
833 | 645 | g_error_free (error); | ||
834 | 646 | return; | ||
835 | 647 | } | ||
836 | 648 | manager->priv->client = client; | ||
837 | 649 | |||
838 | 650 | g_signal_connect (G_OBJECT (client), "notify::primary-connection", | ||
839 | 651 | G_CALLBACK (primary_connection_changed), manager); | ||
840 | 652 | |||
841 | 653 | primary_connection_changed (NULL, NULL, manager); | ||
842 | 654 | } | ||
843 | 655 | |||
844 | 656 | #endif /* HAVE_NETWORK_MANAGER */ | ||
845 | 657 | |||
846 | 658 | #define RYGEL_BUS_NAME "org.gnome.Rygel1" | ||
847 | 659 | #define RYGEL_OBJECT_PATH "/org/gnome/Rygel1" | ||
848 | 660 | #define RYGEL_INTERFACE_NAME "org.gnome.Rygel1" | ||
849 | 661 | |||
850 | 662 | static void | ||
851 | 663 | gsd_sharing_manager_disable_rygel (void) | ||
852 | 664 | { | ||
853 | 665 | GDBusConnection *connection; | ||
854 | 666 | gchar *path; | ||
855 | 667 | |||
856 | 668 | path = g_build_filename (g_get_user_config_dir (), "autostart", | ||
857 | 669 | "rygel.desktop", NULL); | ||
858 | 670 | if (!g_file_test (path, G_FILE_TEST_IS_SYMLINK | G_FILE_TEST_IS_REGULAR)) | ||
859 | 671 | goto out; | ||
860 | 672 | |||
861 | 673 | g_unlink (path); | ||
862 | 674 | |||
863 | 675 | connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); | ||
864 | 676 | if (connection) { | ||
865 | 677 | g_dbus_connection_call (connection, RYGEL_BUS_NAME, RYGEL_OBJECT_PATH, RYGEL_INTERFACE_NAME, | ||
866 | 678 | "Shutdown", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, | ||
867 | 679 | NULL, NULL, NULL); | ||
868 | 680 | } | ||
869 | 681 | g_object_unref (connection); | ||
870 | 682 | |||
871 | 683 | out: | ||
872 | 684 | g_free (path); | ||
873 | 685 | } | ||
874 | 686 | |||
875 | 687 | gboolean | ||
876 | 688 | gsd_sharing_manager_start (GsdSharingManager *manager, | ||
877 | 689 | GError **error) | ||
878 | 690 | { | ||
879 | 691 | g_debug ("Starting sharing manager"); | ||
880 | 692 | gnome_settings_profile_start (NULL); | ||
881 | 693 | |||
882 | 694 | manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); | ||
883 | 695 | g_assert (manager->priv->introspection_data != NULL); | ||
884 | 696 | |||
885 | 697 | gsd_sharing_manager_disable_rygel (); | ||
886 | 698 | |||
887 | 699 | manager->priv->cancellable = g_cancellable_new (); | ||
888 | 700 | #ifdef HAVE_NETWORK_MANAGER | ||
889 | 701 | nm_client_new_async (manager->priv->cancellable, nm_client_ready, manager); | ||
890 | 702 | #endif /* HAVE_NETWORK_MANAGER */ | ||
891 | 703 | |||
892 | 704 | /* Start process of owning a D-Bus name */ | ||
893 | 705 | g_bus_get (G_BUS_TYPE_SESSION, | ||
894 | 706 | manager->priv->cancellable, | ||
895 | 707 | (GAsyncReadyCallback) on_bus_gotten, | ||
896 | 708 | manager); | ||
897 | 709 | |||
898 | 710 | gnome_settings_profile_end (NULL); | ||
899 | 711 | return TRUE; | ||
900 | 712 | } | ||
901 | 713 | |||
902 | 714 | void | ||
903 | 715 | gsd_sharing_manager_stop (GsdSharingManager *manager) | ||
904 | 716 | { | ||
905 | 717 | g_debug ("Stopping sharing manager"); | ||
906 | 718 | |||
907 | 719 | manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; | ||
908 | 720 | gsd_sharing_manager_sync_services (manager); | ||
909 | 721 | |||
910 | 722 | if (manager->priv->cancellable) { | ||
911 | 723 | g_cancellable_cancel (manager->priv->cancellable); | ||
912 | 724 | g_clear_object (&manager->priv->cancellable); | ||
913 | 725 | } | ||
914 | 726 | |||
915 | 727 | #ifdef HAVE_NETWORK_MANAGER | ||
916 | 728 | g_clear_object (&manager->priv->client); | ||
917 | 729 | #endif /* HAVE_NETWORK_MANAGER */ | ||
918 | 730 | |||
919 | 731 | if (manager->priv->name_id != 0) { | ||
920 | 732 | g_bus_unown_name (manager->priv->name_id); | ||
921 | 733 | manager->priv->name_id = 0; | ||
922 | 734 | } | ||
923 | 735 | |||
924 | 736 | g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref); | ||
925 | 737 | g_clear_object (&manager->priv->connection); | ||
926 | 738 | |||
927 | 739 | g_clear_pointer (&manager->priv->current_network, g_free); | ||
928 | 740 | g_clear_pointer (&manager->priv->current_network_name, g_free); | ||
929 | 741 | g_clear_pointer (&manager->priv->carrier_type, g_free); | ||
930 | 742 | } | ||
931 | 743 | |||
932 | 744 | static void | ||
933 | 745 | gsd_sharing_manager_class_init (GsdSharingManagerClass *klass) | ||
934 | 746 | { | ||
935 | 747 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
936 | 748 | |||
937 | 749 | object_class->finalize = gsd_sharing_manager_finalize; | ||
938 | 750 | |||
939 | 751 | g_type_class_add_private (klass, sizeof (GsdSharingManagerPrivate)); | ||
940 | 752 | } | ||
941 | 753 | |||
942 | 754 | static void | ||
943 | 755 | service_free (gpointer pointer) | ||
944 | 756 | { | ||
945 | 757 | ServiceInfo *service = pointer; | ||
946 | 758 | |||
947 | 759 | g_clear_object (&service->settings); | ||
948 | 760 | g_free (service); | ||
949 | 761 | } | ||
950 | 762 | |||
951 | 763 | static void | ||
952 | 764 | gsd_sharing_manager_init (GsdSharingManager *manager) | ||
953 | 765 | { | ||
954 | 766 | guint i; | ||
955 | 767 | |||
956 | 768 | manager->priv = GSD_SHARING_MANAGER_GET_PRIVATE (manager); | ||
957 | 769 | manager->priv->services = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, service_free); | ||
958 | 770 | |||
959 | 771 | /* Default state */ | ||
960 | 772 | manager->priv->current_network = g_strdup (""); | ||
961 | 773 | manager->priv->current_network_name = g_strdup (""); | ||
962 | 774 | manager->priv->carrier_type = g_strdup (""); | ||
963 | 775 | manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; | ||
964 | 776 | |||
965 | 777 | for (i = 0; i < G_N_ELEMENTS (services); i++) { | ||
966 | 778 | ServiceInfo *service; | ||
967 | 779 | char *path; | ||
968 | 780 | |||
969 | 781 | service = g_new0 (ServiceInfo, 1); | ||
970 | 782 | service->name = services[i]; | ||
971 | 783 | path = g_strdup_printf ("/org/gnome/settings-daemon/plugins/sharing/%s/", services[i]); | ||
972 | 784 | service->settings = g_settings_new_with_path ("org.gnome.settings-daemon.plugins.sharing.service", path); | ||
973 | 785 | g_free (path); | ||
974 | 786 | |||
975 | 787 | g_hash_table_insert (manager->priv->services, (gpointer) services[i], service); | ||
976 | 788 | } | ||
977 | 789 | } | ||
978 | 790 | |||
979 | 791 | static void | ||
980 | 792 | gsd_sharing_manager_finalize (GObject *object) | ||
981 | 793 | { | ||
982 | 794 | GsdSharingManager *manager; | ||
983 | 795 | |||
984 | 796 | g_return_if_fail (object != NULL); | ||
985 | 797 | g_return_if_fail (GSD_IS_SHARING_MANAGER (object)); | ||
986 | 798 | |||
987 | 799 | manager = GSD_SHARING_MANAGER (object); | ||
988 | 800 | |||
989 | 801 | g_return_if_fail (manager->priv != NULL); | ||
990 | 802 | |||
991 | 803 | gsd_sharing_manager_stop (manager); | ||
992 | 804 | |||
993 | 805 | g_hash_table_unref (manager->priv->services); | ||
994 | 806 | |||
995 | 807 | G_OBJECT_CLASS (gsd_sharing_manager_parent_class)->finalize (object); | ||
996 | 808 | } | ||
997 | 809 | |||
998 | 810 | GsdSharingManager * | ||
999 | 811 | gsd_sharing_manager_new (void) | ||
1000 | 812 | { | ||
1001 | 813 | if (manager_object != NULL) { | ||
1002 | 814 | g_object_ref (manager_object); | ||
1003 | 815 | } else { | ||
1004 | 816 | manager_object = g_object_new (GSD_TYPE_SHARING_MANAGER, NULL); | ||
1005 | 817 | g_object_add_weak_pointer (manager_object, | ||
1006 | 818 | (gpointer *) &manager_object); | ||
1007 | 819 | } | ||
1008 | 820 | |||
1009 | 821 | return GSD_SHARING_MANAGER (manager_object); | ||
1010 | 822 | } | ||
1011 | 0 | 823 | ||
1012 | === added file 'plugins/sharing/gsd-sharing-manager.h' | |||
1013 | --- plugins/sharing/gsd-sharing-manager.h 1970-01-01 00:00:00 +0000 | |||
1014 | +++ plugins/sharing/gsd-sharing-manager.h 2018-09-30 12:23:49 +0000 | |||
1015 | @@ -0,0 +1,56 @@ | |||
1016 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
1017 | 2 | * | ||
1018 | 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> | ||
1019 | 4 | * | ||
1020 | 5 | * This program is free software; you can redistribute it and/or modify | ||
1021 | 6 | * it under the terms of the GNU General Public License as published by | ||
1022 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
1023 | 8 | * (at your option) any later version. | ||
1024 | 9 | * | ||
1025 | 10 | * This program is distributed in the hope that it will be useful, | ||
1026 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1027 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1028 | 13 | * GNU General Public License for more details. | ||
1029 | 14 | * | ||
1030 | 15 | * You should have received a copy of the GNU General Public License | ||
1031 | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
1032 | 17 | * | ||
1033 | 18 | */ | ||
1034 | 19 | |||
1035 | 20 | #ifndef __GSD_SHARING_MANAGER_H | ||
1036 | 21 | #define __GSD_SHARING_MANAGER_H | ||
1037 | 22 | |||
1038 | 23 | #include <glib-object.h> | ||
1039 | 24 | |||
1040 | 25 | G_BEGIN_DECLS | ||
1041 | 26 | |||
1042 | 27 | #define GSD_TYPE_SHARING_MANAGER (gsd_sharing_manager_get_type ()) | ||
1043 | 28 | #define GSD_SHARING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManager)) | ||
1044 | 29 | #define GSD_SHARING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerClass)) | ||
1045 | 30 | #define GSD_IS_SHARING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SHARING_MANAGER)) | ||
1046 | 31 | #define GSD_IS_SHARING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SHARING_MANAGER)) | ||
1047 | 32 | #define GSD_SHARING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerClass)) | ||
1048 | 33 | |||
1049 | 34 | typedef struct GsdSharingManagerPrivate GsdSharingManagerPrivate; | ||
1050 | 35 | |||
1051 | 36 | typedef struct | ||
1052 | 37 | { | ||
1053 | 38 | GObject parent; | ||
1054 | 39 | GsdSharingManagerPrivate *priv; | ||
1055 | 40 | } GsdSharingManager; | ||
1056 | 41 | |||
1057 | 42 | typedef struct | ||
1058 | 43 | { | ||
1059 | 44 | GObjectClass parent_class; | ||
1060 | 45 | } GsdSharingManagerClass; | ||
1061 | 46 | |||
1062 | 47 | GType gsd_sharing_manager_get_type (void); | ||
1063 | 48 | |||
1064 | 49 | GsdSharingManager * gsd_sharing_manager_new (void); | ||
1065 | 50 | gboolean gsd_sharing_manager_start (GsdSharingManager *manager, | ||
1066 | 51 | GError **error); | ||
1067 | 52 | void gsd_sharing_manager_stop (GsdSharingManager *manager); | ||
1068 | 53 | |||
1069 | 54 | G_END_DECLS | ||
1070 | 55 | |||
1071 | 56 | #endif /* __GSD_SHARING_MANAGER_H */ | ||
1072 | 0 | 57 | ||
1073 | === added file 'plugins/sharing/gsd-sharing-plugin.c' | |||
1074 | --- plugins/sharing/gsd-sharing-plugin.c 1970-01-01 00:00:00 +0000 | |||
1075 | +++ plugins/sharing/gsd-sharing-plugin.c 2018-09-30 12:23:49 +0000 | |||
1076 | @@ -0,0 +1,28 @@ | |||
1077 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
1078 | 2 | * | ||
1079 | 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> | ||
1080 | 4 | * | ||
1081 | 5 | * This program is free software; you can redistribute it and/or modify | ||
1082 | 6 | * it under the terms of the GNU General Public License as published by | ||
1083 | 7 | * the Free Software Foundation; either version 2, or (at your option) | ||
1084 | 8 | * any later version. | ||
1085 | 9 | * | ||
1086 | 10 | * This program is distributed in the hope that it will be useful, | ||
1087 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1088 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1089 | 13 | * GNU General Public License for more details. | ||
1090 | 14 | * | ||
1091 | 15 | * You should have received a copy of the GNU General Public License | ||
1092 | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
1093 | 17 | * | ||
1094 | 18 | */ | ||
1095 | 19 | |||
1096 | 20 | #include "config.h" | ||
1097 | 21 | |||
1098 | 22 | #include <glib/gi18n-lib.h> | ||
1099 | 23 | #include <gmodule.h> | ||
1100 | 24 | |||
1101 | 25 | #include "gnome-settings-plugin.h" | ||
1102 | 26 | #include "gsd-sharing-manager.h" | ||
1103 | 27 | |||
1104 | 28 | GNOME_SETTINGS_PLUGIN_REGISTER (GsdSharing, gsd_sharing) | ||
1105 | 0 | 29 | ||
1106 | === added file 'plugins/sharing/sharing.gnome-settings-plugin.in' | |||
1107 | --- plugins/sharing/sharing.gnome-settings-plugin.in 1970-01-01 00:00:00 +0000 | |||
1108 | +++ plugins/sharing/sharing.gnome-settings-plugin.in 2018-09-30 12:23:49 +0000 | |||
1109 | @@ -0,0 +1,9 @@ | |||
1110 | 1 | [GNOME Settings Plugin] | ||
1111 | 2 | Module=sharing | ||
1112 | 3 | IAge=0 | ||
1113 | 4 | # 100 is the default load Priority | ||
1114 | 5 | Priority=100 | ||
1115 | 6 | Name=Sharing | ||
1116 | 7 | Description=Sharing plugin | ||
1117 | 8 | Authors=Bastien Nocera <hadess@hadess.net> | ||
1118 | 9 | Copyright=Copyright © 2014 AUTHOR | ||
1119 | 0 | 10 | ||
1120 | === added file 'plugins/sharing/test-sharing.c' | |||
1121 | --- plugins/sharing/test-sharing.c 1970-01-01 00:00:00 +0000 | |||
1122 | +++ plugins/sharing/test-sharing.c 2018-09-30 12:23:49 +0000 | |||
1123 | @@ -0,0 +1,7 @@ | |||
1124 | 1 | #define NEW gsd_sharing_manager_new | ||
1125 | 2 | #define START gsd_sharing_manager_start | ||
1126 | 3 | #define STOP gsd_sharing_manager_stop | ||
1127 | 4 | #define MANAGER GsdSharingManager | ||
1128 | 5 | #include "gsd-sharing-manager.h" | ||
1129 | 6 | |||
1130 | 7 | #include "test-plugin.h" |