cc-sharing-panel.c 46.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Copyright (C) 2013 Intel, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Author: Thomas Wood <thomas.wood@intel.com>
 *
 */

#include "cc-sharing-panel.h"
23
#include "cc-hostname-entry.h"
24

25
#include "list-box-helper.h"
26
27
28
29
30
#include "cc-sharing-resources.h"
#include "vino-preferences.h"
#include "cc-remote-login.h"
#include "file-share-properties.h"
#include "cc-media-sharing.h"
31
32
#include "cc-sharing-networks.h"
#include "cc-sharing-switch.h"
33
#include "cc-gnome-remote-desktop.h"
34
#include "org.gnome.SettingsDaemon.Sharing.h"
35

36
37
38
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
39
#include <glib/gi18n.h>
40
41
#include <config.h>

42
static void cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, GtkWidget *label);
43
44
static GtkWidget *cc_sharing_panel_new_media_sharing_row (const char     *uri_or_path,
                                                          CcSharingPanel *self);
45

46
47
#define VINO_SCHEMA_ID "org.gnome.Vino"
#define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing"
48
#define GNOME_REMOTE_DESKTOP_SCHEMA_ID "org.gnome.desktop.remote-desktop"
49
50
51
52
53
54
55
#define GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID "org.gnome.desktop.remote-desktop.vnc"

typedef enum
{
  GRD_VNC_AUTH_METHOD_PROMPT,
  GRD_VNC_AUTH_METHOD_PASSWORD
} GrdVncAuthMethod;
56

57
struct _CcSharingPanel
58
{
59
60
  CcPanel parent_instance;

Robert Ancell's avatar
Robert Ancell committed
61
  GtkWidget *approve_connections_radiobutton;
62
  GtkWidget *hostname_entry;
Robert Ancell's avatar
Robert Ancell committed
63
64
65
66
67
68
  GtkWidget *main_list_box;
  GtkWidget *master_switch;
  GtkWidget *media_sharing_button;
  GtkWidget *media_sharing_dialog;
  GtkWidget *media_sharing_headerbar;
  GtkWidget *media_sharing_status_label;
69
  GtkWidget *media_sharing_switch;
Robert Ancell's avatar
Robert Ancell committed
70
71
72
73
74
75
76
77
78
  GtkWidget *personal_file_sharing_button;
  GtkWidget *personal_file_sharing_dialog;
  GtkWidget *personal_file_sharing_grid;
  GtkWidget *personal_file_sharing_headerbar;
  GtkWidget *personal_file_sharing_label;
  GtkWidget *personal_file_sharing_password_entry;
  GtkWidget *personal_file_sharing_password_label;
  GtkWidget *personal_file_sharing_require_password_switch;
  GtkWidget *personal_file_sharing_status_label;
79
  GtkWidget *personal_file_sharing_switch;
Robert Ancell's avatar
Robert Ancell committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  GtkWidget *password_grid;
  GtkWidget *remote_control_box;
  GtkWidget *remote_control_checkbutton;
  GtkWidget *remote_control_password_entry;
  GtkWidget *remote_login_button;
  GtkWidget *remote_login_dialog;
  GtkWidget *remote_login_label;
  GtkWidget *remote_login_status_label;
  GtkWidget *remote_login_switch;
  GtkWidget *require_password_radiobutton;
  GtkWidget *screen_sharing_button;
  GtkWidget *screen_sharing_dialog;
  GtkWidget *screen_sharing_grid;
  GtkWidget *screen_sharing_headerbar;
  GtkWidget *screen_sharing_label;
  GtkWidget *screen_sharing_status_label;
96
  GtkWidget *screen_sharing_switch;
Robert Ancell's avatar
Robert Ancell committed
97
98
99
100
101
  GtkWidget *shared_folders_grid;
  GtkWidget *shared_folders_listbox;
  GtkWidget *show_password_checkbutton;

  GDBusProxy *sharing_proxy;
102

103
  guint remote_desktop_name_watch;
104
105
};

106
107
CC_PANEL_REGISTER (CcSharingPanel, cc_sharing_panel)

108
#define OFF_IF_VISIBLE(x, y) { if (gtk_widget_is_visible(x) && (y) != NULL && gtk_widget_is_sensitive(y)) gtk_switch_set_active (GTK_SWITCH(y), FALSE); }
109

110
111
112
113
114
115
116
117
118
119
120
121
static void
cc_sharing_panel_master_switch_notify (GtkSwitch      *gtkswitch,
                                       GParamSpec     *pspec,
                                       CcSharingPanel *self)
{
  gboolean active;

  active = gtk_switch_get_active (gtkswitch);

  if (!active)
    {
      /* disable all services if the master switch is not active */
Stefano Facchini's avatar
Stefano Facchini committed
122
123
124
      OFF_IF_VISIBLE(self->media_sharing_button, self->media_sharing_switch);
      OFF_IF_VISIBLE(self->personal_file_sharing_button, self->personal_file_sharing_switch);
      OFF_IF_VISIBLE(self->screen_sharing_button, self->screen_sharing_switch);
125

Robert Ancell's avatar
Robert Ancell committed
126
      gtk_switch_set_active (GTK_SWITCH (self->remote_login_switch), FALSE);
127
128
    }

Robert Ancell's avatar
Robert Ancell committed
129
  gtk_widget_set_sensitive (self->main_list_box, active);
130
131
132
133
134
}

static void
cc_sharing_panel_constructed (GObject *object)
{
135
  CcSharingPanel *self = CC_SHARING_PANEL (object);
136
137
138
139
140

  G_OBJECT_CLASS (cc_sharing_panel_parent_class)->constructed (object);

  /* add the master switch */
  cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (object)),
141
142
                                   gtk_widget_get_parent (self->master_switch),
                                   GTK_POS_RIGHT);
143
144
}

145
146
147
static void
cc_sharing_panel_dispose (GObject *object)
{
148
  CcSharingPanel *self = CC_SHARING_PANEL (object);
149

150
151
152
  if (self->remote_desktop_name_watch)
    g_bus_unwatch_name (self->remote_desktop_name_watch);
  self->remote_desktop_name_watch = 0;
153

154
  if (self->media_sharing_dialog)
155
    {
156
157
      gtk_widget_destroy (self->media_sharing_dialog);
      self->media_sharing_dialog = NULL;
158
159
    }

160
  if (self->personal_file_sharing_dialog)
161
    {
162
163
      gtk_widget_destroy (self->personal_file_sharing_dialog);
      self->personal_file_sharing_dialog = NULL;
164
165
    }

166
  if (self->remote_login_dialog)
167
    {
168
169
      gtk_widget_destroy (self->remote_login_dialog);
      self->remote_login_dialog = NULL;
170
171
    }

172
  if (self->screen_sharing_dialog)
173
    {
174
175
      gtk_widget_destroy (self->screen_sharing_dialog);
      self->screen_sharing_dialog = NULL;
176
177
    }

178
  g_clear_object (&self->sharing_proxy);
179

180
181
182
  G_OBJECT_CLASS (cc_sharing_panel_parent_class)->dispose (object);
}

183
184
185
static const char *
cc_sharing_panel_get_help_uri (CcPanel *panel)
{
David King's avatar
David King committed
186
  return "help:gnome-help/prefs-sharing";
187
188
}

189
190
191
static void
cc_sharing_panel_class_init (CcSharingPanelClass *klass)
{
Robert Ancell's avatar
Robert Ancell committed
192
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
193
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
194
  CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
195

196
  object_class->constructed = cc_sharing_panel_constructed;
197
  object_class->dispose = cc_sharing_panel_dispose;
198
199

  panel_class->get_help_uri = cc_sharing_panel_get_help_uri;
200

201
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sharing/cc-sharing-panel.ui");
Robert Ancell's avatar
Robert Ancell committed
202
203

  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, approve_connections_radiobutton);
204
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, hostname_entry);
Robert Ancell's avatar
Robert Ancell committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_grid);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, shared_folders_grid);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, main_list_box);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_button);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_dialog);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_headerbar);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_status_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_button);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_dialog);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_grid);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_headerbar);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_password_entry);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_password_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_require_password_switch);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_status_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, password_grid);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_box);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_checkbutton);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_password_entry);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_button);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_dialog);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_status_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_switch);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, require_password_radiobutton);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_button);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_dialog);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_headerbar);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_status_label);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, shared_folders_listbox);
  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, show_password_checkbutton);

239
  g_type_ensure (CC_TYPE_HOSTNAME_ENTRY);
240
241
242
243
}

static void
cc_sharing_panel_run_dialog (CcSharingPanel *self,
Robert Ancell's avatar
Robert Ancell committed
244
                             GtkWidget      *dialog)
245
{
Robert Ancell's avatar
Robert Ancell committed
246
  GtkWidget *parent;
247

248
249
  /* ensure labels with the hostname are updated if the hostname has changed */
  cc_sharing_panel_setup_label_with_hostname (self,
Robert Ancell's avatar
Robert Ancell committed
250
251
                                              self->screen_sharing_label);
  cc_sharing_panel_setup_label_with_hostname (self, self->remote_login_label);
252
  cc_sharing_panel_setup_label_with_hostname (self,
Robert Ancell's avatar
Robert Ancell committed
253
                                              self->personal_file_sharing_label);
254
255


256
257
258
259
260
261
262
  parent = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self)));

  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
  gtk_dialog_run (GTK_DIALOG (dialog));
}

static void
263
264
265
cc_sharing_panel_main_list_box_row_activated (GtkListBox     *listbox,
                                              GtkListBoxRow  *row,
                                              CcSharingPanel *self)
266
{
Robert Ancell's avatar
Robert Ancell committed
267
  GtkWidget *dialog;
268

Robert Ancell's avatar
Robert Ancell committed
269
270
271
272
273
274
275
276
277
  if (row == GTK_LIST_BOX_ROW (self->media_sharing_button))
    dialog = self->media_sharing_dialog;
  else if (row == GTK_LIST_BOX_ROW (self->personal_file_sharing_button))
    dialog = self->personal_file_sharing_dialog;
  else if (row == GTK_LIST_BOX_ROW (self->remote_login_button))
    dialog = self->remote_login_dialog;
  else if (row == GTK_LIST_BOX_ROW (self->screen_sharing_button))
    dialog = self->screen_sharing_dialog;
  else
278
279
    return;

280
  gtk_list_box_select_row (listbox, NULL);
281

Robert Ancell's avatar
Robert Ancell committed
282
  cc_sharing_panel_run_dialog (self, dialog);
283
284
285
}

static gboolean
286
287
288
289
cc_sharing_panel_switch_to_label_transform_func (GBinding       *binding,
                                                 const GValue   *source_value,
                                                 GValue         *target_value,
                                                 CcSharingPanel *self)
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
{
  gboolean active;

  if (!G_VALUE_HOLDS_BOOLEAN (source_value))
    return FALSE;

  if (!G_VALUE_HOLDS_STRING (target_value))
    return FALSE;

  active = g_value_get_boolean (source_value);

  if (active)
    g_value_set_string (target_value, C_("service is enabled", "On"));
  else
    g_value_set_string (target_value, C_("service is disabled", "Off"));

306
307
  /* ensure the master switch is active if one of the services is active */
  if (active)
308
    gtk_switch_set_active (GTK_SWITCH (self->master_switch), TRUE);
309

310
311
312
  return TRUE;
}

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
static gboolean
cc_sharing_panel_networks_to_label_transform_func (GBinding       *binding,
                                                   const GValue   *source_value,
                                                   GValue         *target_value,
                                                   CcSharingPanel *self)
{
  CcSharingStatus status;

  if (!G_VALUE_HOLDS_UINT (source_value))
    return FALSE;

  if (!G_VALUE_HOLDS_STRING (target_value))
    return FALSE;

  status = g_value_get_uint (source_value);

  switch (status) {
  case CC_SHARING_STATUS_OFF:
    g_value_set_string (target_value, C_("service is disabled", "Off"));
    break;
  case CC_SHARING_STATUS_ENABLED:
    g_value_set_string (target_value, C_("service is enabled", "Enabled"));
    break;
  case CC_SHARING_STATUS_ACTIVE:
    g_value_set_string (target_value, C_("service is active", "Active"));
    break;
  default:
    return FALSE;
  }

  /* ensure the master switch is active if one of the services is active */
  if (status != CC_SHARING_STATUS_OFF)
345
    gtk_switch_set_active (GTK_SWITCH (self->master_switch), TRUE);
346
347
348
349

  return TRUE;
}

350
static void
351
352
353
cc_sharing_panel_bind_switch_to_label (CcSharingPanel *self,
                                       GtkWidget      *gtkswitch,
                                       GtkWidget      *label)
354
355
356
{
  g_object_bind_property_full (gtkswitch, "active", label, "label",
                               G_BINDING_SYNC_CREATE,
357
358
                               (GBindingTransformFunc) cc_sharing_panel_switch_to_label_transform_func,
                               NULL, self, NULL);
359
360
}

361
362
363
364
365
366
367
368
369
370
371
static void
cc_sharing_panel_bind_networks_to_label (CcSharingPanel *self,
					 GtkWidget      *networks,
					 GtkWidget      *label)
{
  g_object_bind_property_full (networks, "status", label, "label",
                               G_BINDING_SYNC_CREATE,
                               (GBindingTransformFunc) cc_sharing_panel_networks_to_label_transform_func,
                               NULL, self, NULL);
}

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
static void
cc_sharing_panel_bind_switch_to_widgets (GtkWidget *gtkswitch,
                                         GtkWidget *first_widget,
                                         ...)
{
  va_list w;
  GtkWidget *widget;

  va_start (w, first_widget);

  g_object_bind_property (gtkswitch, "active", first_widget,
                          "sensitive", G_BINDING_SYNC_CREATE);

  while ((widget = va_arg (w, GtkWidget*)))
    {
      g_object_bind_property (gtkswitch, "active", widget,
                              "sensitive", G_BINDING_SYNC_CREATE);
    }

  va_end (w);
}

static void
395
396
cc_sharing_panel_add_folder (GtkListBox     *box,
                             GtkListBoxRow  *row,
397
398
399
                             CcSharingPanel *self)
{
  GtkWidget *dialog;
400
  g_autofree gchar *folder = NULL;
401
  gboolean matching = FALSE;
402
403
404
405
  GList *rows, *l;

  if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-add")))
    return;
406
407

  dialog = gtk_file_chooser_dialog_new (_("Choose a Folder"),
408
                                        GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (box))),
409
                                        GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
Yosef Or Boczko's avatar
Yosef Or Boczko committed
410
411
                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
                                        _("_Open"), GTK_RESPONSE_ACCEPT,
412
                                        NULL);
413
  gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
414
415
  if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
    goto bail;
416
417
418

  gtk_widget_hide (dialog);

Robert Ancell's avatar
Robert Ancell committed
419
  rows = gtk_container_get_children (GTK_CONTAINER (self->shared_folders_listbox));
420

421
  folder = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
422
423
424
425
  if (!folder || g_str_equal (folder, ""))
    goto bail;

  g_debug ("Trying to add %s", folder);
426

427
  for (l = rows; l != NULL; l = l->next)
428
    {
429
      const char *string;
430

431
      string = g_object_get_data (G_OBJECT (l->data), "path");
432
      matching = (g_strcmp0 (string, folder) == 0);
433
434

      if (matching)
435
436
437
438
        {
          g_debug ("Found a duplicate for %s", folder);
          break;
        }
439
440
    }

441
  if (!matching)
442
443
444
445
446
447
    {
      GtkWidget *row;
      int i;

      row = cc_sharing_panel_new_media_sharing_row (folder, self);
      i = g_list_length (rows);
Robert Ancell's avatar
Robert Ancell committed
448
      gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, i - 1);
449
      gtk_widget_set_visible (row, TRUE);
450
    }
Robert Ancell's avatar
Robert Ancell committed
451
  cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox));
452

453
bail:
454
455
456
457
458
459
460
  gtk_widget_destroy (dialog);
}

static void
cc_sharing_panel_remove_folder (GtkButton      *button,
                                CcSharingPanel *self)
{
461
  GtkWidget *row;
462

463
464
  row = g_object_get_data (G_OBJECT (button), "row");
  gtk_widget_destroy (row);
Robert Ancell's avatar
Robert Ancell committed
465
  cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox));
466
467
468
469
470
471
472
}

static void
cc_sharing_panel_media_sharing_dialog_response (GtkDialog      *dialog,
                                                gint            reponse_id,
                                                CcSharingPanel *self)
{
473
  g_autoptr(GPtrArray) folders = NULL;
474
475
  GtkWidget *box;
  GList *rows, *l;
476

Robert Ancell's avatar
Robert Ancell committed
477
  box = self->shared_folders_listbox;
478
  rows = gtk_container_get_children (GTK_CONTAINER (box));
479
480
  folders = g_ptr_array_new_with_free_func (g_free);

481
  for (l = rows; l != NULL; l = l->next)
482
    {
483
      const char *folder;
484

485
486
487
488
      folder = g_object_get_data (G_OBJECT (l->data), "path");
      if (folder == NULL)
        continue;
      g_ptr_array_add (folders, g_strdup (folder));
489
490
491
492
    }

  g_ptr_array_add (folders, NULL);

493
  cc_media_sharing_set_preferences ((gchar **) folders->pdata);
494
495
}

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
#define ICON_NAME_FOLDER                "folder-symbolic"
#define ICON_NAME_FOLDER_DESKTOP        "user-desktop-symbolic"
#define ICON_NAME_FOLDER_DOCUMENTS      "folder-documents-symbolic"
#define ICON_NAME_FOLDER_DOWNLOAD       "folder-download-symbolic"
#define ICON_NAME_FOLDER_MUSIC          "folder-music-symbolic"
#define ICON_NAME_FOLDER_PICTURES       "folder-pictures-symbolic"
#define ICON_NAME_FOLDER_PUBLIC_SHARE   "folder-publicshare-symbolic"
#define ICON_NAME_FOLDER_TEMPLATES      "folder-templates-symbolic"
#define ICON_NAME_FOLDER_VIDEOS         "folder-videos-symbolic"
#define ICON_NAME_FOLDER_SAVED_SEARCH   "folder-saved-search-symbolic"

static GIcon *
special_directory_get_gicon (GUserDirectory directory)
{
#define ICON_CASE(x)                      \
  case G_USER_DIRECTORY_ ## x:            \
          return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER_ ## x);

  switch (directory)
    {
      ICON_CASE (DESKTOP);
      ICON_CASE (DOCUMENTS);
      ICON_CASE (DOWNLOAD);
      ICON_CASE (MUSIC);
      ICON_CASE (PICTURES);
      ICON_CASE (PUBLIC_SHARE);
      ICON_CASE (TEMPLATES);
      ICON_CASE (VIDEOS);

    default:
      return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER);
    }

#undef ICON_CASE
}

static GtkWidget *
cc_sharing_panel_new_media_sharing_row (const char     *uri_or_path,
                                        CcSharingPanel *self)
{
  GtkWidget *row, *box, *w;
  GUserDirectory dir = G_USER_N_DIRECTORIES;
538
  g_autoptr(GIcon) icon = NULL;
539
  guint i;
540
541
542
  g_autofree gchar *basename = NULL;
  g_autofree gchar *path = NULL;
  g_autoptr(GFile) file = NULL;
543
544
545
546
547
548

  file = g_file_new_for_commandline_arg (uri_or_path);
  path = g_file_get_path (file);

  row = gtk_list_box_row_new ();
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
549
  gtk_widget_show (box);
550
551
  gtk_container_set_border_width (GTK_CONTAINER (box), 3);
  gtk_widget_set_margin_start (box, 6);
552
553
554
555
556
557
558
559
560
561
562
563
564
565
  gtk_container_add (GTK_CONTAINER (row), box);

  /* Find the icon and create it */
  for (i = 0; i < G_USER_N_DIRECTORIES; i++)
    {
      if (g_strcmp0 (path, g_get_user_special_dir (i)) == 0)
        {
          dir = i;
          break;
        }
    }

  icon = special_directory_get_gicon (dir);
  w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
566
  gtk_widget_show (w);
567
568
569
570
571
572
  gtk_widget_set_margin_end (w, 12);
  gtk_container_add (GTK_CONTAINER (box), w);

  /* Label */
  basename = g_filename_display_basename (path);
  w = gtk_label_new (basename);
573
  gtk_widget_show (w);
574
575
576
577
  gtk_container_add (GTK_CONTAINER (box), w);

  /* Remove button */
  w = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
578
  gtk_widget_show (w);
579
580
581
582
583
584
585
586
587
588
  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
  gtk_widget_set_margin_top (w, 3);
  gtk_widget_set_margin_bottom (w, 3);
  gtk_widget_set_margin_end (w, 12);
  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (w), "clicked",
                    G_CALLBACK (cc_sharing_panel_remove_folder), self);
  g_object_set_data (G_OBJECT (w), "row", row);

589
  g_object_set_data_full (G_OBJECT (row), "path", g_steal_pointer (&path), g_free);
590
591
592
593
594
595
596
597
598
599
600

  return row;
}

static GtkWidget *
cc_sharing_panel_new_add_media_sharing_row (CcSharingPanel *self)
{
  GtkWidget *row, *box, *w;

  row = gtk_list_box_row_new ();
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
601
  gtk_widget_show (box);
602
  gtk_container_set_border_width (GTK_CONTAINER (box), 3);
603
604
605
  gtk_container_add (GTK_CONTAINER (row), box);

  w = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
606
  gtk_widget_show (w);
607
608
609
610
611
612
613
614
615
616
617
618
  gtk_container_add (GTK_CONTAINER (box), w);
  gtk_widget_set_hexpand (w, TRUE);
  gtk_widget_set_margin_top (w, 6);
  gtk_widget_set_margin_bottom (w, 6);

  g_object_set_data (G_OBJECT (w), "row", row);

  g_object_set_data (G_OBJECT (row), "is-add", GINT_TO_POINTER (1));

  return row;
}

619
620
621
static void
cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
{
622
623
  g_auto(GStrv) folders = NULL;
  GStrv list;
624
  GtkWidget *row, *networks, *w;
625
  g_autofree gchar *path = NULL;
626
627
628
629

  path = g_find_program_in_path ("rygel");
  if (path == NULL)
    {
Robert Ancell's avatar
Robert Ancell committed
630
      gtk_widget_hide (self->media_sharing_button);
631
632
      return;
    }
633

Robert Ancell's avatar
Robert Ancell committed
634
  g_signal_connect (self->media_sharing_dialog, "response",
635
636
637
                    G_CALLBACK (cc_sharing_panel_media_sharing_dialog_response),
                    self);

638
  cc_media_sharing_get_preferences (&folders);
639

Robert Ancell's avatar
Robert Ancell committed
640
  gtk_list_box_set_header_func (GTK_LIST_BOX (self->shared_folders_listbox),
641
                                cc_list_box_update_header_func, NULL,
642
                                NULL);
Robert Ancell's avatar
Robert Ancell committed
643
  cc_list_box_setup_scrolling (GTK_LIST_BOX (self->shared_folders_listbox), 3);
644

645
646
647
  list = folders;
  while (list && *list)
    {
648
      row = cc_sharing_panel_new_media_sharing_row (*list, self);
649
      gtk_widget_show (row);
Robert Ancell's avatar
Robert Ancell committed
650
      gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, -1);
651
652
653
      list++;
    }

654
655
656
  row = cc_sharing_panel_new_add_media_sharing_row (self);
  gtk_widget_show (row);
  gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, -1);
657

Robert Ancell's avatar
Robert Ancell committed
658
  cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox));
659

Robert Ancell's avatar
Robert Ancell committed
660
  g_signal_connect (G_OBJECT (self->shared_folders_listbox), "row-activated",
661
662
                    G_CALLBACK (cc_sharing_panel_add_folder), self);

663
  networks = cc_sharing_networks_new (self->sharing_proxy, "rygel");
Robert Ancell's avatar
Robert Ancell committed
664
  gtk_grid_attach (GTK_GRID (self->shared_folders_grid), networks, 0, 4, 2, 1);
665
666
667
  gtk_widget_show (networks);

  w = cc_sharing_switch_new (networks);
Robert Ancell's avatar
Robert Ancell committed
668
  gtk_header_bar_pack_start (GTK_HEADER_BAR (self->media_sharing_headerbar), w);
669
  self->media_sharing_switch = w;
670
671

  cc_sharing_panel_bind_networks_to_label (self, networks,
Robert Ancell's avatar
Robert Ancell committed
672
                                           self->media_sharing_status_label);
673
674
675
676
677
678
679
}

static gboolean
cc_sharing_panel_label_activate_link (GtkLabel *label,
                                      gchar    *uri,
                                      GtkMenu  *menu)
{
680
  gtk_menu_popup_at_pointer (menu, NULL);
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699

  g_object_set_data_full (G_OBJECT (menu), "uri-text", g_strdup (uri), g_free);

  return TRUE;
}

static void
copy_uri_to_clipboard (GtkMenuItem *item,
                       GtkMenu     *menu)
{
  GtkClipboard *clipboard;
  const gchar *text;

  text = g_object_get_data (G_OBJECT (menu), "uri-text");

  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
  gtk_clipboard_set_text (clipboard, text, -1);
}

700
static void
701
702
703
cc_sharing_panel_setup_label (CcSharingPanel *self,
                              GtkWidget      *label,
                              const gchar    *hostname)
704
{
705
  g_autofree gchar *text = NULL;
706

Robert Ancell's avatar
Robert Ancell committed
707
  if (label == self->personal_file_sharing_label)
708
709
710
711
712
    {
      g_autofree gchar *url = g_strdup_printf ("<a href=\"dav://%s\">dav://%s</a>", hostname, hostname);
      /* TRANSLATORS: %s is replaced with a link to a dav://<hostname> URL */
      text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: %s"), url);
    }
Robert Ancell's avatar
Robert Ancell committed
713
  else if (label == self->remote_login_label)
714
715
716
717
718
    {
      g_autofree gchar *command = g_strdup_printf ("<a href=\"ssh %s\">ssh %s</a>", hostname, hostname);
      /* TRANSLATORS: %s is replaced with a link to a "ssh <hostname>" command to run */
      text = g_strdup_printf (_("When remote login is enabled, remote users can connect using the Secure Shell command:\n%s"), command);
    }
Robert Ancell's avatar
Robert Ancell committed
719
  else if (label == self->screen_sharing_label)
720
721
722
723
724
    {
      g_autofree gchar *url = g_strdup_printf ("<a href=\"vnc://%s\">vnc://%s</a>", hostname, hostname);
      /* TRANSLATORS: %s is replaced with a link to a vnc://<hostname> URL */
      text = g_strdup_printf (_("Screen sharing allows remote users to view or control your screen by connecting to %s"), url);
    }
725
726
  else
    g_assert_not_reached ();
727

728
  gtk_label_set_label (GTK_LABEL (label), text);
729
730
731
732
733
734
735
736
}

typedef struct
{
  CcSharingPanel *panel;
  GtkWidget *label;
} GetHostNameData;

737
738
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetHostNameData, g_free);

739
static void
740
cc_sharing_panel_get_host_name_fqdn_done (GObject         *object,
741
                                          GAsyncResult    *res,
742
                                          gpointer         user_data)
743
{
744
745
746
747
  GDBusConnection *connection = G_DBUS_CONNECTION (object);
  g_autoptr(GetHostNameData) data = user_data;
  g_autoptr(GError) error = NULL;
  g_autoptr(GVariant) variant = NULL;
748
749
750
751
752
753
754
755
756
757
758
  const gchar *fqdn;

  variant = g_dbus_connection_call_finish (connection, res, &error);

  if (variant == NULL)
    {
      /* Avahi service may not be available */
      g_debug ("Error calling GetHostNameFqdn: %s", error->message);

      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
759
          g_autofree gchar *hostname = NULL;
760

761
          hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
762

763
          cc_sharing_panel_setup_label (data->panel, data->label, hostname);
764
765
766
767
768
769
770
        }

      return;
    }

  g_variant_get (variant, "(&s)", &fqdn);

771
  cc_sharing_panel_setup_label (data->panel, data->label, fqdn);
772
773
774
775
776
}

static void
cc_sharing_panel_bus_ready (GObject         *object,
                            GAsyncResult    *res,
777
                            gpointer         user_data)
778
{
779
780
781
  g_autoptr(GDBusConnection) connection = NULL;
  g_autoptr(GetHostNameData) data = user_data;
  g_autoptr(GError) error = NULL;
782
783
784
785
786
787
788
789
790

  connection = g_bus_get_finish (res, &error);

  if (connection == NULL)
    {
      g_warning ("Could not connect to system bus: %s", error->message);

      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
791
          g_autofree gchar *hostname = NULL;
792

793
          hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
794

795
          cc_sharing_panel_setup_label (data->panel, data->label, hostname);
796
797
798
799
800
801
802
803
804
805
806
807
808
809
        }

      return;
    }

  g_dbus_connection_call (connection,
                          "org.freedesktop.Avahi",
                          "/",
                          "org.freedesktop.Avahi.Server",
                          "GetHostNameFqdn",
                          NULL,
                          (GVariantType*)"(s)",
                          G_DBUS_CALL_FLAGS_NONE,
                          -1,
810
                          cc_panel_get_cancellable (CC_PANEL (data->panel)),
811
                          cc_sharing_panel_get_host_name_fqdn_done,
812
                          data);
813
  g_steal_pointer (&data);
814
815
816
}


817
818
819
820
821
822
static void
cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self,
                                            GtkWidget      *label)
{
  GtkWidget *menu;
  GtkWidget *menu_item;
823
  GetHostNameData *get_hostname_data;
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843

  /* create the menu */
  menu = gtk_menu_new ();

  menu_item = gtk_menu_item_new_with_label (_("Copy"));
  gtk_widget_show (menu_item);

  g_signal_connect (menu_item, "activate", G_CALLBACK (copy_uri_to_clipboard),
                    menu);

  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

  /* show the menu when the link is activated */
  g_signal_connect (label, "activate-link",
                    G_CALLBACK (cc_sharing_panel_label_activate_link), menu);

  /* destroy the menu when the label is destroyed */
  g_signal_connect_swapped (label, "destroy", G_CALLBACK (gtk_widget_destroy),
                            menu);

844
845
846
847
848

  /* set the hostname */
  get_hostname_data = g_new (GetHostNameData, 1);
  get_hostname_data->panel = self;
  get_hostname_data->label = label;
849
  g_bus_get (G_BUS_TYPE_SYSTEM,
850
             cc_panel_get_cancellable (CC_PANEL (self)),
851
             cc_sharing_panel_bus_ready,
852
             get_hostname_data);
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
}

static gboolean
file_sharing_get_require_password (GValue   *value,
                                   GVariant *variant,
                                   gpointer  user_data)
{
  if (g_str_equal (g_variant_get_string (variant, NULL), "always"))
    g_value_set_boolean (value, TRUE);
  else
    g_value_set_boolean (value, FALSE);

  return TRUE;
}

static GVariant *
file_sharing_set_require_password (const GValue       *value,
                                   const GVariantType *type,
                                   gpointer            user_data)
{
  if (g_value_get_boolean (value))
    return g_variant_new_string ("always");
  else
    return g_variant_new_string ("never");
}

static void
file_sharing_password_changed (GtkEntry *entry)
{
  file_share_write_out_password (gtk_entry_get_text (entry));
}

static void
cc_sharing_panel_setup_personal_file_sharing_dialog (CcSharingPanel *self)
{
  GSettings *settings;
Robert Ancell's avatar
Robert Ancell committed
889
  GtkWidget *networks, *w;
890

Robert Ancell's avatar
Robert Ancell committed
891
892
893
  cc_sharing_panel_bind_switch_to_widgets (self->personal_file_sharing_require_password_switch,
                                           self->personal_file_sharing_password_entry,
                                           self->personal_file_sharing_password_label,
894
895
896
                                           NULL);

  cc_sharing_panel_setup_label_with_hostname (self,
Robert Ancell's avatar
Robert Ancell committed
897
                                              self->personal_file_sharing_label);
898
899

  /* the password cannot be read, so just make sure the entry is not empty */
Robert Ancell's avatar
Robert Ancell committed
900
  gtk_entry_set_text (GTK_ENTRY (self->personal_file_sharing_password_entry),
901
902
903
904
                      "password");

  settings = g_settings_new (FILE_SHARING_SCHEMA_ID);
  g_settings_bind_with_mapping (settings, "require-password",
Robert Ancell's avatar
Robert Ancell committed
905
                                self->personal_file_sharing_require_password_switch,
906
907
908
909
910
                                "active",
                                G_SETTINGS_BIND_DEFAULT,
                                file_sharing_get_require_password,
                                file_sharing_set_require_password, NULL, NULL);

Robert Ancell's avatar
Robert Ancell committed
911
  g_signal_connect (self->personal_file_sharing_password_entry,
912
913
                    "notify::text", G_CALLBACK (file_sharing_password_changed),
                    NULL);
914

915
  networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-user-share-webdav");
Robert Ancell's avatar
Robert Ancell committed
916
  gtk_grid_attach (GTK_GRID (self->personal_file_sharing_grid), networks, 0, 3, 2, 1);
917
918
919
  gtk_widget_show (networks);

  w = cc_sharing_switch_new (networks);
Robert Ancell's avatar
Robert Ancell committed
920
  gtk_header_bar_pack_start (GTK_HEADER_BAR (self->personal_file_sharing_headerbar), w);
921
  self->personal_file_sharing_switch = w;
922
923
924

  cc_sharing_panel_bind_networks_to_label (self,
                                           networks,
Robert Ancell's avatar
Robert Ancell committed
925
                                           self->personal_file_sharing_status_label);
926
927
928
929
}

static void
remote_login_switch_activate (GtkSwitch      *remote_login_switch,
930
                              GParamSpec     *pspec,
931
932
                              CcSharingPanel *self)
{
933
  cc_remote_login_set_enabled (cc_panel_get_cancellable (CC_PANEL (self)), remote_login_switch);
934
935
936
937
938
}

static void
cc_sharing_panel_setup_remote_login_dialog (CcSharingPanel *self)
{
Robert Ancell's avatar
Robert Ancell committed
939
940
  cc_sharing_panel_bind_switch_to_label (self, self->remote_login_switch,
                                         self->remote_login_status_label);
941

Robert Ancell's avatar
Robert Ancell committed
942
  cc_sharing_panel_setup_label_with_hostname (self, self->remote_login_label);
943

Robert Ancell's avatar
Robert Ancell committed
944
  g_signal_connect (self->remote_login_switch, "notify::active",
945
                    G_CALLBACK (remote_login_switch_activate), self);
Robert Ancell's avatar
Robert Ancell committed
946
  gtk_widget_set_sensitive (self->remote_login_switch, FALSE);
947

948
  cc_remote_login_get_enabled (cc_panel_get_cancellable (CC_PANEL (self)),
Robert Ancell's avatar
Robert Ancell committed
949
950
                               GTK_SWITCH (self->remote_login_switch),
                               self->remote_login_button);
951
952
953
954
955
956
}

static gboolean
cc_sharing_panel_check_schema_available (CcSharingPanel *self,
                                         const gchar *schema_id)
{
Rui Matos's avatar
Rui Matos committed
957
  GSettingsSchemaSource *source;
958
  g_autoptr(GSettingsSchema) schema = NULL;
959

Rui Matos's avatar
Rui Matos committed
960
961
  source = g_settings_schema_source_get_default ();
  if (!source)
962
963
    return FALSE;

Rui Matos's avatar
Rui Matos committed
964
965
966
  schema = g_settings_schema_source_lookup (source, schema_id, TRUE);
  if (!schema)
    return FALSE;
967

Rui Matos's avatar
Rui Matos committed
968
  return TRUE;
969
970
}

971
972
973
static void
screen_sharing_show_cb (GtkWidget *widget, CcSharingPanel *self)
{
Robert Ancell's avatar
Robert Ancell committed
974
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->show_password_checkbutton),
975
976
977
                                FALSE);
}

978
979
980
static void
screen_sharing_hide_cb (GtkWidget *widget, CcSharingPanel *self)
{
981
  GtkToggleButton *ac_radio;
982
983
984
  GtkEntry    *pw_entry;
  const gchar *password;

Robert Ancell's avatar
Robert Ancell committed
985
986
  ac_radio = GTK_TOGGLE_BUTTON (self->approve_connections_radiobutton);
  pw_entry = GTK_ENTRY (self->remote_control_password_entry);
987
988
989
  password = gtk_entry_get_text (pw_entry);

  if (password == NULL || *password == '\0')
990
    gtk_toggle_button_set_active (ac_radio, TRUE);
991
992
}

993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
#define MAX_PASSWORD_SIZE 8
static void
screen_sharing_password_insert_text_cb (GtkEditable *editable,
                                        gchar       *new_text,
                                        gint         new_text_length,
                                        gpointer     position,
                                        gpointer     user_data)
{
  int l, available_size;

  l = gtk_entry_buffer_get_bytes (gtk_entry_get_buffer (GTK_ENTRY (editable)));

  if (l + new_text_length <= MAX_PASSWORD_SIZE)
    return;

  g_signal_stop_emission_by_name (editable, "insert-text");
  gtk_widget_error_bell (GTK_WIDGET (editable));

  available_size = g_utf8_strlen (new_text, MAX_PASSWORD_SIZE - l);
  if (available_size == 0)
    return;

  g_signal_handlers_block_by_func (editable,
                                   (gpointer) screen_sharing_password_insert_text_cb,
                                   user_data);
  gtk_editable_insert_text (editable, new_text, available_size, position);
  g_signal_handlers_unblock_by_func (editable,
                                     (gpointer) screen_sharing_password_insert_text_cb,
                                     user_data);
}
#undef MAX_PASSWORD_SIZE

1025
static void
1026
cc_sharing_panel_setup_screen_sharing_dialog_vino (CcSharingPanel *self)
1027
1028
{
  GSettings *settings;
1029
  GtkWidget *networks, *box, *w;
1030

Robert Ancell's avatar
Robert Ancell committed
1031
1032
  cc_sharing_panel_bind_switch_to_widgets (self->require_password_radiobutton,
                                           self->password_grid,
1033
1034
1035
                                           NULL);

  cc_sharing_panel_setup_label_with_hostname (self,
Robert Ancell's avatar
Robert Ancell committed
1036
                                              self->screen_sharing_label);
1037
1038
1039

  /* settings bindings */
  settings = g_settings_new (VINO_SCHEMA_ID);
Robert Ancell's avatar
Robert Ancell committed
1040
  g_settings_bind (settings, "view-only", self->remote_control_checkbutton,
1041
1042
1043
                   "active",
                   G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
  g_settings_bind (settings, "prompt-enabled",
Robert Ancell's avatar
Robert Ancell committed
1044
                   self->approve_connections_radiobutton, "active",
1045
1046
                   G_SETTINGS_BIND_DEFAULT);
  g_settings_bind_with_mapping (settings, "authentication-methods",
Robert Ancell's avatar
Robert Ancell committed
1047
                                self->require_password_radiobutton,
1048
1049
1050
1051
1052
                                "active",
                                G_SETTINGS_BIND_DEFAULT,
                                vino_get_authtype, vino_set_authtype, NULL, NULL);

  g_settings_bind_with_mapping (settings, "vnc-password",
Robert Ancell's avatar
Robert Ancell committed
1053
                                self->remote_control_password_entry,
1054
1055
1056
                                "text",
                                G_SETTINGS_BIND_DEFAULT,
                                vino_get_password, vino_set_password, NULL, NULL);
1057

Robert Ancell's avatar
Robert Ancell committed
1058
1059
  g_object_bind_property (self->show_password_checkbutton, "active",
                          self->remote_control_password_entry, "visibility",
1060
                          G_BINDING_SYNC_CREATE);
1061
1062

  /* make sure the password entry is hidden by default */
1063
  g_signal_connect (self->screen_sharing_dialog, "show",
1064
                    G_CALLBACK (screen_sharing_show_cb), self);
1065

1066
  g_signal_connect (self->screen_sharing_dialog, "hide",
1067
1068
                    G_CALLBACK (screen_sharing_hide_cb), self);

1069
  /* accept at most 8 bytes in password entry */
Robert Ancell's avatar
Robert Ancell committed
1070
  g_signal_connect (self->remote_control_password_entry, "insert-text",
1071
                    G_CALLBACK (screen_sharing_password_insert_text_cb), self);
1072

1073
  networks = cc_sharing_networks_new (self->sharing_proxy, "vino-server");
Robert Ancell's avatar
Robert Ancell committed
1074
  box = self->remote_control_box;
1075
1076
1077
1078
  gtk_box_pack_end (GTK_BOX (box), networks, TRUE, TRUE, 0);
  gtk_widget_show (networks);

  w = cc_sharing_switch_new (networks);
Robert Ancell's avatar
Robert Ancell committed
1079
  gtk_header_bar_pack_start (GTK_HEADER_BAR (self->screen_sharing_headerbar), w);
1080
  self->screen_sharing_switch = w;
1081
1082

  cc_sharing_panel_bind_networks_to_label (self, networks,
Robert Ancell's avatar
Robert Ancell committed
1083
                                           self->screen_sharing_status_label);
1084
1085
}

1086
1087
1088
static void
cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPanel *self)
{
1089
  g_autoptr(GSettings) vnc_settings = NULL;
1090
1091
  GtkWidget *networks, *w;

1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
  cc_sharing_panel_bind_switch_to_widgets (self->require_password_radiobutton, self->password_grid, NULL);

  cc_sharing_panel_setup_label_with_hostname (self, self->screen_sharing_label);

  g_object_bind_property (self->show_password_checkbutton,
                          "active",
                          self->remote_control_password_entry,
                          "visibility",
                          G_BINDING_SYNC_CREATE);

  /* make sure the password entry is hidden by default */
  g_signal_connect (self->screen_sharing_dialog,
                    "show",
                    G_CALLBACK (screen_sharing_show_cb),
                    self);

  g_signal_connect (self->screen_sharing_dialog,
                    "hide",
                    G_CALLBACK (screen_sharing_hide_cb),
                    self);

1113
1114
  cc_grd_update_password_entry (self->remote_control_password_entry);

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
  /* accept at most 8 bytes in password entry */
  g_signal_connect (self->remote_control_password_entry,
                    "insert-text",
                    G_CALLBACK (screen_sharing_password_insert_text_cb),
                    self);

  /* Bind settings to widgets */
  vnc_settings = g_settings_new (GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID);

  g_settings_bind (vnc_settings,
                   "view-only",
                   self->remote_control_checkbutton,
                   "active",
                   G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);

  g_settings_bind_with_mapping (vnc_settings,
                                "auth-method",
                                self->approve_connections_radiobutton,
                                "active",
                                G_SETTINGS_BIND_DEFAULT,
                                cc_grd_get_is_auth_method_prompt,
                                cc_grd_set_is_auth_method_prompt,
                                NULL,
                                NULL);

  g_settings_bind_with_mapping (vnc_settings,
                                "auth-method",
                                self->require_password_radiobutton,
                                "active",
                                G_SETTINGS_BIND_DEFAULT,
                                cc_grd_get_is_auth_method_password,
                                cc_grd_set_is_auth_method_password,
                                NULL,
                                NULL);

  g_signal_connect (self->remote_control_password_entry,
                    "notify::text",
                    G_CALLBACK (cc_grd_on_vnc_password_entry_notify_text),
                    self);

1155
  networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-remote-desktop");
1156
  gtk_box_pack_end (GTK_BOX (self->remote_control_box), networks, TRUE, TRUE, 0);
1157
  gtk_widget_show (networks);
1158
1159

  w = cc_sharing_switch_new (networks);
Robert Ancell's avatar
Robert Ancell committed
1160
  gtk_header_bar_pack_start (GTK_HEADER_BAR (self->screen_sharing_headerbar), w);
1161
  self->screen_sharing_switch = w;
1162
1163

  cc_sharing_panel_bind_networks_to_label (self, networks,
Robert Ancell's avatar
Robert Ancell committed
1164
                                           self->screen_sharing_sta