Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2013 Intel, Inc |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or modify |
5 |
|
|
* it under the terms of the GNU General Public License as published by |
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
7 |
|
|
* (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* This program is distributed in the hope that it will be useful, |
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
|
* GNU General Public License for more details. |
13 |
|
|
* |
14 |
|
|
* You should have received a copy of the GNU General Public License |
15 |
|
|
* along with this program; if not, write to the Free Software |
16 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
|
* |
18 |
|
|
* Author: Thomas Wood <thomas.wood@intel.com> |
19 |
|
|
* |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "cc-sharing-panel.h" |
23 |
|
|
#include "cc-hostname-entry.h" |
24 |
|
|
#include "cc-list-row.h" |
25 |
|
|
#include "shell/cc-application.h" |
26 |
|
|
#include "shell/cc-log.h" |
27 |
|
|
|
28 |
|
|
#include "cc-sharing-resources.h" |
29 |
|
|
#include "file-share-properties.h" |
30 |
|
|
#include "cc-media-sharing.h" |
31 |
|
|
#include "cc-sharing-networks.h" |
32 |
|
|
#include "org.gnome.SettingsDaemon.Sharing.h" |
33 |
|
|
|
34 |
|
|
#ifdef GDK_WINDOWING_WAYLAND |
35 |
|
|
#include <gdk/wayland/gdkwayland.h> |
36 |
|
|
#endif |
37 |
|
|
#include <glib/gi18n.h> |
38 |
|
|
|
39 |
|
|
#include <config.h> |
40 |
|
|
|
41 |
|
|
#include <unistd.h> |
42 |
|
|
|
43 |
|
|
static GtkWidget *cc_sharing_panel_new_media_sharing_row (const char *uri_or_path, |
44 |
|
|
CcSharingPanel *self); |
45 |
|
|
|
46 |
|
|
#define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing" |
47 |
|
|
|
48 |
|
|
struct _CcSharingPanel |
49 |
|
|
{ |
50 |
|
|
CcPanel parent_instance; |
51 |
|
|
|
52 |
|
|
GtkWidget *hostname_entry; |
53 |
|
|
GtkWidget *main_list_box; |
54 |
|
|
AdwDialog *media_sharing_dialog; |
55 |
|
|
AdwActionRow *media_sharing_enable_row; |
56 |
|
|
GtkWidget *media_sharing_row; |
57 |
|
|
GtkWidget *media_sharing_switch; |
58 |
|
|
AdwDialog *personal_file_sharing_dialog; |
59 |
|
|
GtkWidget *personal_file_sharing_vbox; |
60 |
|
|
AdwActionRow *personal_file_sharing_enable_row; |
61 |
|
|
AdwPreferencesPage *personal_file_sharing_page; |
62 |
|
|
GtkWidget *personal_file_sharing_password_entry_row; |
63 |
|
|
GtkWidget *personal_file_sharing_require_password_switch; |
64 |
|
|
GtkWidget *personal_file_sharing_row; |
65 |
|
|
GtkWidget *personal_file_sharing_switch; |
66 |
|
|
|
67 |
|
|
GtkWidget *media_sharing_vbox; |
68 |
|
|
GtkWidget *shared_folders_listbox; |
69 |
|
|
|
70 |
|
|
GDBusProxy *sharing_proxy; |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
✗ |
CC_PANEL_REGISTER (CcSharingPanel, cc_sharing_panel) |
74 |
|
|
|
75 |
|
|
static void |
76 |
|
✗ |
cc_sharing_panel_dispose (GObject *object) |
77 |
|
|
{ |
78 |
|
✗ |
CcSharingPanel *self = CC_SHARING_PANEL (object); |
79 |
|
|
|
80 |
|
✗ |
if (self->media_sharing_dialog) |
81 |
|
|
{ |
82 |
|
✗ |
adw_dialog_force_close (self->media_sharing_dialog); |
83 |
|
✗ |
self->media_sharing_dialog = NULL; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
✗ |
if (self->personal_file_sharing_dialog) |
87 |
|
|
{ |
88 |
|
✗ |
adw_dialog_force_close (self->personal_file_sharing_dialog); |
89 |
|
✗ |
self->personal_file_sharing_dialog = NULL; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
✗ |
G_OBJECT_CLASS (cc_sharing_panel_parent_class)->dispose (object); |
93 |
|
✗ |
} |
94 |
|
|
|
95 |
|
|
static const char * |
96 |
|
✗ |
cc_sharing_panel_get_help_uri (CcPanel *panel) |
97 |
|
|
{ |
98 |
|
✗ |
return "help:gnome-help/prefs-sharing"; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
static void |
102 |
|
✗ |
cc_sharing_panel_class_init (CcSharingPanelClass *klass) |
103 |
|
|
{ |
104 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
105 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
106 |
|
✗ |
CcPanelClass *panel_class = CC_PANEL_CLASS (klass); |
107 |
|
|
|
108 |
|
✗ |
object_class->dispose = cc_sharing_panel_dispose; |
109 |
|
|
|
110 |
|
✗ |
panel_class->get_help_uri = cc_sharing_panel_get_help_uri; |
111 |
|
|
|
112 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sharing/cc-sharing-panel.ui"); |
113 |
|
|
|
114 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, hostname_entry); |
115 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_vbox); |
116 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, main_list_box); |
117 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_dialog); |
118 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_enable_row); |
119 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_row); |
120 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_dialog); |
121 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_enable_row); |
122 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_page); |
123 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_password_entry_row); |
124 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_require_password_switch); |
125 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_vbox); |
126 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_row); |
127 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, shared_folders_listbox); |
128 |
|
|
|
129 |
|
✗ |
g_type_ensure (CC_TYPE_LIST_ROW); |
130 |
|
✗ |
g_type_ensure (CC_TYPE_HOSTNAME_ENTRY); |
131 |
|
✗ |
} |
132 |
|
|
|
133 |
|
|
static gboolean |
134 |
|
✗ |
cc_sharing_panel_networks_to_label_transform_func (GBinding *binding, |
135 |
|
|
const GValue *source_value, |
136 |
|
|
GValue *target_value, |
137 |
|
|
CcSharingPanel *self) |
138 |
|
|
{ |
139 |
|
|
CcSharingStatus status; |
140 |
|
|
|
141 |
|
✗ |
if (!G_VALUE_HOLDS_UINT (source_value)) |
142 |
|
✗ |
return FALSE; |
143 |
|
|
|
144 |
|
✗ |
if (!G_VALUE_HOLDS_STRING (target_value)) |
145 |
|
✗ |
return FALSE; |
146 |
|
|
|
147 |
|
✗ |
status = g_value_get_uint (source_value); |
148 |
|
|
|
149 |
|
✗ |
switch (status) { |
150 |
|
✗ |
case CC_SHARING_STATUS_OFF: |
151 |
|
✗ |
g_value_set_string (target_value, C_("service is disabled", "Off")); |
152 |
|
✗ |
break; |
153 |
|
✗ |
case CC_SHARING_STATUS_ENABLED: |
154 |
|
✗ |
g_value_set_string (target_value, C_("service is enabled", "Enabled")); |
155 |
|
✗ |
break; |
156 |
|
✗ |
case CC_SHARING_STATUS_ACTIVE: |
157 |
|
✗ |
g_value_set_string (target_value, C_("service is active", "Active")); |
158 |
|
✗ |
break; |
159 |
|
✗ |
default: |
160 |
|
✗ |
return FALSE; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
✗ |
return TRUE; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
static void |
167 |
|
✗ |
cc_sharing_panel_bind_networks_to_label (CcSharingPanel *self, |
168 |
|
|
GtkWidget *networks, |
169 |
|
|
GtkWidget *list_row) |
170 |
|
|
{ |
171 |
|
✗ |
g_object_bind_property_full (networks, "status", list_row, "secondary-label", |
172 |
|
|
G_BINDING_SYNC_CREATE, |
173 |
|
|
(GBindingTransformFunc) cc_sharing_panel_networks_to_label_transform_func, |
174 |
|
|
NULL, self, NULL); |
175 |
|
✗ |
} |
176 |
|
|
|
177 |
|
|
static void |
178 |
|
✗ |
on_add_folder_dialog_response_cb (CcSharingPanel *self, |
179 |
|
|
gint response, |
180 |
|
|
GtkDialog *dialog) |
181 |
|
|
{ |
182 |
|
✗ |
g_autofree gchar *folder = NULL; |
183 |
|
✗ |
g_autoptr(GFile) file = NULL; |
184 |
|
|
GtkWidget *child; |
185 |
|
✗ |
gboolean matching = FALSE; |
186 |
|
✗ |
gint n_rows = 0; |
187 |
|
|
|
188 |
|
✗ |
if (response != GTK_RESPONSE_ACCEPT) |
189 |
|
✗ |
goto bail; |
190 |
|
|
|
191 |
|
✗ |
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); |
192 |
|
✗ |
folder = g_file_get_uri (file); |
193 |
|
✗ |
if (!folder || g_str_equal (folder, "")) |
194 |
|
✗ |
goto bail; |
195 |
|
|
|
196 |
|
✗ |
g_debug ("Trying to add %s", folder); |
197 |
|
|
|
198 |
|
✗ |
for (child = gtk_widget_get_first_child (self->shared_folders_listbox); |
199 |
|
✗ |
child; |
200 |
|
✗ |
child = gtk_widget_get_next_sibling (child)) |
201 |
|
|
{ |
202 |
|
|
const char *string; |
203 |
|
|
|
204 |
|
✗ |
string = g_object_get_data (G_OBJECT (child), "path"); |
205 |
|
✗ |
matching = (g_strcmp0 (string, folder) == 0); |
206 |
|
|
|
207 |
|
✗ |
if (matching) |
208 |
|
|
{ |
209 |
|
✗ |
g_debug ("Found a duplicate for %s", folder); |
210 |
|
✗ |
break; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
✗ |
n_rows++; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
✗ |
if (!matching) |
217 |
|
|
{ |
218 |
|
✗ |
GtkWidget *row = cc_sharing_panel_new_media_sharing_row (folder, self); |
219 |
|
|
|
220 |
|
✗ |
gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), |
221 |
|
|
row, |
222 |
|
|
n_rows - 1); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
✗ |
bail: |
226 |
|
✗ |
gtk_window_destroy (GTK_WINDOW (dialog)); |
227 |
|
✗ |
} |
228 |
|
|
|
229 |
|
|
static void |
230 |
|
✗ |
cc_sharing_panel_add_folder (CcSharingPanel *self, |
231 |
|
|
GtkListBoxRow *row) |
232 |
|
|
{ |
233 |
|
|
GtkWidget *dialog; |
234 |
|
✗ |
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self))); |
235 |
|
|
|
236 |
|
✗ |
if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-add"))) |
237 |
|
✗ |
return; |
238 |
|
|
|
239 |
|
✗ |
dialog = gtk_file_chooser_dialog_new (_("Choose a Folder"), |
240 |
|
✗ |
GTK_WINDOW (toplevel), |
241 |
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
242 |
|
✗ |
_("_Cancel"), GTK_RESPONSE_CANCEL, |
243 |
|
|
_("_Open"), GTK_RESPONSE_ACCEPT, |
244 |
|
|
NULL); |
245 |
|
|
|
246 |
|
✗ |
g_signal_connect_object (dialog, |
247 |
|
|
"response", |
248 |
|
|
G_CALLBACK (on_add_folder_dialog_response_cb), |
249 |
|
|
self, |
250 |
|
|
G_CONNECT_SWAPPED); |
251 |
|
✗ |
gtk_window_present (GTK_WINDOW (dialog)); |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
static void |
255 |
|
✗ |
cc_sharing_panel_remove_folder (CcSharingPanel *self, |
256 |
|
|
GtkButton *button) |
257 |
|
|
{ |
258 |
|
|
GtkWidget *row; |
259 |
|
|
|
260 |
|
✗ |
row = g_object_get_data (G_OBJECT (button), "row"); |
261 |
|
✗ |
gtk_list_box_remove (GTK_LIST_BOX (self->shared_folders_listbox), row); |
262 |
|
✗ |
} |
263 |
|
|
|
264 |
|
|
static gboolean |
265 |
|
✗ |
cc_sharing_panel_media_sharing_dialog_close_request (CcSharingPanel *self) |
266 |
|
|
{ |
267 |
|
✗ |
g_autoptr(GPtrArray) folders = NULL; |
268 |
|
|
GtkWidget *child; |
269 |
|
|
|
270 |
|
✗ |
folders = g_ptr_array_new_with_free_func (g_free); |
271 |
|
|
|
272 |
|
✗ |
for (child = gtk_widget_get_first_child (self->shared_folders_listbox); |
273 |
|
✗ |
child; |
274 |
|
✗ |
child = gtk_widget_get_next_sibling (child)) |
275 |
|
|
{ |
276 |
|
|
const char *folder; |
277 |
|
|
|
278 |
|
✗ |
folder = g_object_get_data (G_OBJECT (child), "path"); |
279 |
|
✗ |
if (folder == NULL) |
280 |
|
✗ |
continue; |
281 |
|
✗ |
g_ptr_array_add (folders, g_strdup (folder)); |
282 |
|
|
} |
283 |
|
|
|
284 |
|
✗ |
g_ptr_array_add (folders, NULL); |
285 |
|
|
|
286 |
|
✗ |
cc_media_sharing_set_preferences ((gchar **) folders->pdata); |
287 |
|
|
|
288 |
|
✗ |
return GDK_EVENT_PROPAGATE; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
#define ICON_NAME_FOLDER "folder-symbolic" |
292 |
|
|
#define ICON_NAME_FOLDER_DESKTOP "user-desktop-symbolic" |
293 |
|
|
#define ICON_NAME_FOLDER_DOCUMENTS "folder-documents-symbolic" |
294 |
|
|
#define ICON_NAME_FOLDER_DOWNLOAD "folder-download-symbolic" |
295 |
|
|
#define ICON_NAME_FOLDER_MUSIC "folder-music-symbolic" |
296 |
|
|
#define ICON_NAME_FOLDER_PICTURES "folder-pictures-symbolic" |
297 |
|
|
#define ICON_NAME_FOLDER_PUBLIC_SHARE "folder-publicshare-symbolic" |
298 |
|
|
#define ICON_NAME_FOLDER_TEMPLATES "folder-templates-symbolic" |
299 |
|
|
#define ICON_NAME_FOLDER_VIDEOS "folder-videos-symbolic" |
300 |
|
|
#define ICON_NAME_FOLDER_SAVED_SEARCH "folder-saved-search-symbolic" |
301 |
|
|
|
302 |
|
|
static GIcon * |
303 |
|
✗ |
special_directory_get_gicon (GUserDirectory directory) |
304 |
|
|
{ |
305 |
|
|
#define ICON_CASE(x) \ |
306 |
|
|
case G_USER_DIRECTORY_ ## x: \ |
307 |
|
|
return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER_ ## x); |
308 |
|
|
|
309 |
|
✗ |
switch (directory) |
310 |
|
|
{ |
311 |
|
✗ |
ICON_CASE (DESKTOP); |
312 |
|
✗ |
ICON_CASE (DOCUMENTS); |
313 |
|
✗ |
ICON_CASE (DOWNLOAD); |
314 |
|
✗ |
ICON_CASE (MUSIC); |
315 |
|
✗ |
ICON_CASE (PICTURES); |
316 |
|
✗ |
ICON_CASE (PUBLIC_SHARE); |
317 |
|
✗ |
ICON_CASE (TEMPLATES); |
318 |
|
✗ |
ICON_CASE (VIDEOS); |
319 |
|
|
|
320 |
|
✗ |
default: |
321 |
|
✗ |
return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER); |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
#undef ICON_CASE |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
static GtkWidget * |
328 |
|
✗ |
cc_sharing_panel_new_media_sharing_row (const char *uri_or_path, |
329 |
|
|
CcSharingPanel *self) |
330 |
|
|
{ |
331 |
|
|
GtkWidget *row, *w; |
332 |
|
✗ |
GUserDirectory dir = G_USER_N_DIRECTORIES; |
333 |
|
✗ |
g_autoptr(GIcon) icon = NULL; |
334 |
|
|
guint i; |
335 |
|
✗ |
g_autofree gchar *basename = NULL; |
336 |
|
✗ |
g_autofree gchar *path = NULL; |
337 |
|
✗ |
g_autoptr(GFile) file = NULL; |
338 |
|
|
|
339 |
|
✗ |
file = g_file_new_for_commandline_arg (uri_or_path); |
340 |
|
✗ |
path = g_file_get_path (file); |
341 |
|
|
|
342 |
|
✗ |
row = adw_action_row_new (); |
343 |
|
|
|
344 |
|
|
/* Find the icon and create it */ |
345 |
|
✗ |
for (i = 0; i < G_USER_N_DIRECTORIES; i++) |
346 |
|
|
{ |
347 |
|
✗ |
if (g_strcmp0 (path, g_get_user_special_dir (i)) == 0) |
348 |
|
|
{ |
349 |
|
✗ |
dir = i; |
350 |
|
✗ |
break; |
351 |
|
|
} |
352 |
|
|
} |
353 |
|
|
|
354 |
|
✗ |
icon = special_directory_get_gicon (dir); |
355 |
|
✗ |
adw_action_row_add_prefix (ADW_ACTION_ROW (row), |
356 |
|
|
gtk_image_new_from_gicon (icon)); |
357 |
|
|
|
358 |
|
|
/* Label */ |
359 |
|
✗ |
basename = g_filename_display_basename (path); |
360 |
|
✗ |
adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), basename); |
361 |
|
|
|
362 |
|
|
/* Remove button */ |
363 |
|
✗ |
w = gtk_button_new_from_icon_name ("edit-delete-symbolic"); |
364 |
|
✗ |
gtk_widget_set_tooltip_text (GTK_WIDGET (w), _("Remove Folder")); |
365 |
|
✗ |
gtk_widget_add_css_class (w, "flat"); |
366 |
|
✗ |
gtk_widget_set_valign (w, GTK_ALIGN_CENTER); |
367 |
|
✗ |
adw_action_row_add_suffix (ADW_ACTION_ROW (row), w); |
368 |
|
✗ |
g_signal_connect_object (G_OBJECT (w), "clicked", |
369 |
|
|
G_CALLBACK (cc_sharing_panel_remove_folder), self, G_CONNECT_SWAPPED); |
370 |
|
✗ |
g_object_set_data (G_OBJECT (w), "row", row); |
371 |
|
|
|
372 |
|
✗ |
g_object_set_data_full (G_OBJECT (row), "path", g_steal_pointer (&path), g_free); |
373 |
|
|
|
374 |
|
✗ |
return row; |
375 |
|
|
} |
376 |
|
|
|
377 |
|
|
static GtkWidget * |
378 |
|
✗ |
cc_sharing_panel_new_add_media_sharing_row (CcSharingPanel *self) |
379 |
|
|
{ |
380 |
|
|
GtkWidget *row, *box, *w; |
381 |
|
|
|
382 |
|
✗ |
row = gtk_list_box_row_new (); |
383 |
|
✗ |
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); |
384 |
|
✗ |
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box); |
385 |
|
|
|
386 |
|
✗ |
w = gtk_image_new_from_icon_name ("list-add-symbolic"); |
387 |
|
✗ |
gtk_widget_set_tooltip_text (GTK_WIDGET (w), _("Add Folder")); |
388 |
|
✗ |
gtk_widget_set_hexpand (w, TRUE); |
389 |
|
✗ |
gtk_widget_set_margin_top (w, 12); |
390 |
|
✗ |
gtk_widget_set_margin_bottom (w, 12); |
391 |
|
✗ |
gtk_box_append (GTK_BOX (box), w); |
392 |
|
|
|
393 |
|
✗ |
g_object_set_data (G_OBJECT (w), "row", row); |
394 |
|
|
|
395 |
|
✗ |
g_object_set_data (G_OBJECT (row), "is-add", GINT_TO_POINTER (1)); |
396 |
|
|
|
397 |
|
✗ |
return row; |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
static GtkWidget * |
401 |
|
✗ |
create_switch_with_bindings (GtkSwitch *from) |
402 |
|
|
{ |
403 |
|
✗ |
GtkWidget *new_switch = gtk_switch_new (); |
404 |
|
|
|
405 |
|
✗ |
g_object_bind_property (from, "visible", new_switch, "visible", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
406 |
|
✗ |
g_object_bind_property (from, "state", new_switch, "state", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
407 |
|
✗ |
g_object_bind_property (from, "active", new_switch, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
408 |
|
✗ |
g_object_bind_property (from, "sensitive", new_switch, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
409 |
|
|
|
410 |
|
✗ |
return new_switch; |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
static gboolean |
414 |
|
✗ |
cc_sharing_panel_check_media_sharing_available (void) |
415 |
|
|
{ |
416 |
|
✗ |
g_autofree gchar *path = NULL; |
417 |
|
|
|
418 |
|
✗ |
path = g_find_program_in_path ("rygel"); |
419 |
|
✗ |
return (path != NULL); |
420 |
|
|
} |
421 |
|
|
|
422 |
|
|
static void |
423 |
|
✗ |
cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self) |
424 |
|
|
{ |
425 |
|
✗ |
g_auto(GStrv) folders = NULL; |
426 |
|
|
GStrv list; |
427 |
|
|
GtkWidget *row, *networks, *w; |
428 |
|
|
|
429 |
|
✗ |
g_signal_connect_object (self->media_sharing_dialog, "close-attempt", |
430 |
|
|
G_CALLBACK (cc_sharing_panel_media_sharing_dialog_close_request), |
431 |
|
|
self, G_CONNECT_SWAPPED); |
432 |
|
|
|
433 |
|
✗ |
cc_media_sharing_get_preferences (&folders); |
434 |
|
|
|
435 |
|
✗ |
list = folders; |
436 |
|
✗ |
while (list && *list) |
437 |
|
|
{ |
438 |
|
✗ |
row = cc_sharing_panel_new_media_sharing_row (*list, self); |
439 |
|
✗ |
gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, -1); |
440 |
|
✗ |
list++; |
441 |
|
|
} |
442 |
|
|
|
443 |
|
✗ |
row = cc_sharing_panel_new_add_media_sharing_row (self); |
444 |
|
✗ |
gtk_list_box_append (GTK_LIST_BOX (self->shared_folders_listbox), row); |
445 |
|
|
|
446 |
|
✗ |
g_signal_connect_object (self->shared_folders_listbox, "row-activated", |
447 |
|
|
G_CALLBACK (cc_sharing_panel_add_folder), self, G_CONNECT_SWAPPED); |
448 |
|
|
|
449 |
|
✗ |
networks = cc_sharing_networks_new (self->sharing_proxy, "rygel"); |
450 |
|
✗ |
gtk_box_append (GTK_BOX (self->media_sharing_vbox), networks); |
451 |
|
|
|
452 |
|
✗ |
w = create_switch_with_bindings (GTK_SWITCH (g_object_get_data (G_OBJECT (networks), "switch"))); |
453 |
|
✗ |
gtk_widget_set_valign (w, GTK_ALIGN_CENTER); |
454 |
|
✗ |
adw_action_row_add_suffix (self->media_sharing_enable_row, w); |
455 |
|
✗ |
adw_action_row_set_activatable_widget (self->media_sharing_enable_row, w); |
456 |
|
✗ |
self->media_sharing_switch = w; |
457 |
|
|
|
458 |
|
✗ |
cc_sharing_panel_bind_networks_to_label (self, networks, |
459 |
|
|
self->media_sharing_row); |
460 |
|
✗ |
} |
461 |
|
|
|
462 |
|
|
static void |
463 |
|
✗ |
cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, |
464 |
|
|
AdwPreferencesPage *page) |
465 |
|
|
{ |
466 |
|
✗ |
g_autofree gchar *text = NULL; |
467 |
|
|
const gchar *hostname; |
468 |
|
|
|
469 |
|
✗ |
hostname = gtk_editable_get_text (GTK_EDITABLE (self->hostname_entry)); |
470 |
|
|
|
471 |
|
✗ |
if (page == self->personal_file_sharing_page) |
472 |
|
|
{ |
473 |
|
✗ |
g_autofree gchar *url = g_strdup_printf ("<a href=\"dav://%s\">dav://%s</a>", hostname, hostname); |
474 |
|
|
/* TRANSLATORS: %s is replaced with a link to a dav://<hostname> URL */ |
475 |
|
✗ |
text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: %s"), url); |
476 |
|
|
} |
477 |
|
|
else |
478 |
|
✗ |
g_assert_not_reached (); |
479 |
|
|
|
480 |
|
✗ |
adw_preferences_page_set_description (ADW_PREFERENCES_PAGE (page), text); |
481 |
|
✗ |
} |
482 |
|
|
|
483 |
|
|
static gboolean |
484 |
|
✗ |
file_sharing_get_require_password (GValue *value, |
485 |
|
|
GVariant *variant, |
486 |
|
|
gpointer user_data) |
487 |
|
|
{ |
488 |
|
✗ |
if (g_str_equal (g_variant_get_string (variant, NULL), "always")) |
489 |
|
✗ |
g_value_set_boolean (value, TRUE); |
490 |
|
|
else |
491 |
|
✗ |
g_value_set_boolean (value, FALSE); |
492 |
|
|
|
493 |
|
✗ |
return TRUE; |
494 |
|
|
} |
495 |
|
|
|
496 |
|
|
static GVariant * |
497 |
|
✗ |
file_sharing_set_require_password (const GValue *value, |
498 |
|
|
const GVariantType *type, |
499 |
|
|
gpointer user_data) |
500 |
|
|
{ |
501 |
|
✗ |
if (g_value_get_boolean (value)) |
502 |
|
✗ |
return g_variant_new_string ("always"); |
503 |
|
|
else |
504 |
|
✗ |
return g_variant_new_string ("never"); |
505 |
|
|
} |
506 |
|
|
|
507 |
|
|
static void |
508 |
|
✗ |
file_sharing_password_changed (CcSharingPanel *self) |
509 |
|
|
{ |
510 |
|
✗ |
file_share_write_out_password (gtk_editable_get_text (GTK_EDITABLE (self->personal_file_sharing_password_entry_row))); |
511 |
|
✗ |
} |
512 |
|
|
|
513 |
|
|
static void |
514 |
|
✗ |
cc_sharing_panel_setup_personal_file_sharing_dialog (CcSharingPanel *self) |
515 |
|
|
{ |
516 |
|
|
GSettings *settings; |
517 |
|
|
GtkWidget *networks, *w; |
518 |
|
|
|
519 |
|
✗ |
g_object_bind_property (self->personal_file_sharing_require_password_switch, "active", |
520 |
|
✗ |
self->personal_file_sharing_password_entry_row, "sensitive", |
521 |
|
|
G_BINDING_SYNC_CREATE); |
522 |
|
|
|
523 |
|
|
/* the password cannot be read, so just make sure the entry is not empty */ |
524 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->personal_file_sharing_password_entry_row), |
525 |
|
|
"password"); |
526 |
|
|
|
527 |
|
✗ |
settings = g_settings_new (FILE_SHARING_SCHEMA_ID); |
528 |
|
✗ |
g_settings_bind_with_mapping (settings, "require-password", |
529 |
|
✗ |
self->personal_file_sharing_require_password_switch, |
530 |
|
|
"active", |
531 |
|
|
G_SETTINGS_BIND_DEFAULT, |
532 |
|
|
file_sharing_get_require_password, |
533 |
|
|
file_sharing_set_require_password, NULL, NULL); |
534 |
|
|
|
535 |
|
✗ |
g_signal_connect_swapped (self->personal_file_sharing_password_entry_row, |
536 |
|
|
"notify::text", G_CALLBACK (file_sharing_password_changed), |
537 |
|
|
self); |
538 |
|
|
|
539 |
|
✗ |
networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-user-share-webdav"); |
540 |
|
✗ |
gtk_box_append (GTK_BOX (self->personal_file_sharing_vbox), networks); |
541 |
|
|
|
542 |
|
✗ |
w = create_switch_with_bindings (GTK_SWITCH (g_object_get_data (G_OBJECT (networks), "switch"))); |
543 |
|
✗ |
gtk_widget_set_valign (w, GTK_ALIGN_CENTER); |
544 |
|
✗ |
adw_action_row_add_suffix (self->personal_file_sharing_enable_row, w); |
545 |
|
✗ |
adw_action_row_set_activatable_widget (self->personal_file_sharing_enable_row, w); |
546 |
|
✗ |
self->personal_file_sharing_switch = w; |
547 |
|
|
|
548 |
|
✗ |
cc_sharing_panel_bind_networks_to_label (self, |
549 |
|
|
networks, |
550 |
|
|
self->personal_file_sharing_row); |
551 |
|
✗ |
} |
552 |
|
|
|
553 |
|
|
static gboolean |
554 |
|
✗ |
cc_sharing_panel_check_schema_available (const gchar *schema_id) |
555 |
|
|
{ |
556 |
|
|
GSettingsSchemaSource *source; |
557 |
|
✗ |
g_autoptr(GSettingsSchema) schema = NULL; |
558 |
|
|
|
559 |
|
✗ |
source = g_settings_schema_source_get_default (); |
560 |
|
✗ |
if (!source) |
561 |
|
✗ |
return FALSE; |
562 |
|
|
|
563 |
|
✗ |
schema = g_settings_schema_source_lookup (source, schema_id, TRUE); |
564 |
|
✗ |
if (!schema) |
565 |
|
✗ |
return FALSE; |
566 |
|
|
|
567 |
|
✗ |
return TRUE; |
568 |
|
|
} |
569 |
|
|
|
570 |
|
|
static void |
571 |
|
✗ |
sharing_proxy_ready (GObject *source, |
572 |
|
|
GAsyncResult *res, |
573 |
|
|
gpointer user_data) |
574 |
|
|
{ |
575 |
|
|
CcSharingPanel *self; |
576 |
|
|
GDBusProxy *proxy; |
577 |
|
✗ |
g_autoptr(GError) error = NULL; |
578 |
|
|
|
579 |
|
✗ |
proxy = G_DBUS_PROXY (gsd_sharing_proxy_new_for_bus_finish (res, &error)); |
580 |
|
✗ |
if (!proxy) { |
581 |
|
✗ |
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
582 |
|
✗ |
g_warning ("Failed to get sharing proxy: %s", error->message); |
583 |
|
✗ |
return; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
✗ |
self = CC_SHARING_PANEL (user_data); |
587 |
|
✗ |
self->sharing_proxy = proxy; |
588 |
|
|
|
589 |
|
|
/* media sharing */ |
590 |
|
✗ |
if (cc_sharing_panel_check_media_sharing_available ()) |
591 |
|
✗ |
cc_sharing_panel_setup_media_sharing_dialog (self); |
592 |
|
|
else |
593 |
|
✗ |
gtk_widget_set_visible (self->media_sharing_row, FALSE); |
594 |
|
|
|
595 |
|
|
/* personal file sharing */ |
596 |
|
✗ |
if (cc_sharing_panel_check_schema_available (FILE_SHARING_SCHEMA_ID)) |
597 |
|
✗ |
cc_sharing_panel_setup_personal_file_sharing_dialog (self); |
598 |
|
|
else |
599 |
|
✗ |
gtk_widget_set_visible (self->personal_file_sharing_row, FALSE); |
600 |
|
|
|
601 |
|
✗ |
cc_sharing_panel_setup_label_with_hostname (self, self->personal_file_sharing_page); |
602 |
|
|
} |
603 |
|
|
|
604 |
|
|
static void |
605 |
|
✗ |
cc_sharing_panel_init (CcSharingPanel *self) |
606 |
|
|
{ |
607 |
|
✗ |
g_resources_register (cc_sharing_get_resource ()); |
608 |
|
|
|
609 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
610 |
|
|
|
611 |
|
✗ |
gsd_sharing_proxy_new_for_bus (G_BUS_TYPE_SESSION, |
612 |
|
|
G_DBUS_PROXY_FLAGS_NONE, |
613 |
|
|
"org.gnome.SettingsDaemon.Sharing", |
614 |
|
|
"/org/gnome/SettingsDaemon/Sharing", |
615 |
|
|
cc_panel_get_cancellable (CC_PANEL (self)), |
616 |
|
|
sharing_proxy_ready, |
617 |
|
|
self); |
618 |
|
✗ |
} |
619 |
|
|
|
620 |
|
|
CcSharingPanel * |
621 |
|
✗ |
cc_sharing_panel_new (void) |
622 |
|
|
{ |
623 |
|
✗ |
return g_object_new (CC_TYPE_SHARING_PANEL, NULL); |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
void |
627 |
|
✗ |
cc_sharing_panel_static_init_func (void) |
628 |
|
|
{ |
629 |
|
|
CcApplication *application; |
630 |
|
|
gboolean visible; |
631 |
|
|
|
632 |
|
✗ |
CC_TRACE_MSG ("Updating Sharing panel visibility"); |
633 |
|
|
|
634 |
|
✗ |
visible = cc_sharing_panel_check_schema_available (FILE_SHARING_SCHEMA_ID) || |
635 |
|
✗ |
cc_sharing_panel_check_media_sharing_available (); |
636 |
|
|
|
637 |
|
✗ |
application = CC_APPLICATION (g_application_get_default ()); |
638 |
|
✗ |
cc_shell_model_set_panel_visibility (cc_application_get_model (application), |
639 |
|
|
"sharing", |
640 |
|
|
visible ? CC_PANEL_VISIBLE : CC_PANEL_HIDDEN); |
641 |
|
✗ |
g_debug ("Sharing panel visible: %s", visible ? "yes" : "no"); |
642 |
|
✗ |
} |
643 |
|
|
|