]> Pileus Git - ~andy/gtk/blob - gtk/gtkmountoperation.c
Updated Arabic translation
[~andy/gtk] / gtk / gtkmountoperation.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3  * Copyright (C) Christian Kellner <gicmo@gnome.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /*
20  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
21  * file for a list of people on the GTK+ Team.  See the ChangeLog
22  * files for a list of changes.  These files are distributed with
23  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
24  */
25
26 #include "config.h"
27
28 #include <string.h>
29
30 #include "gtkmountoperationprivate.h"
31 #include "gtkbox.h"
32 #include "gtkentry.h"
33 #include "gtkbox.h"
34 #include "gtkintl.h"
35 #include "gtklabel.h"
36 #include "gtkmessagedialog.h"
37 #include "gtkmountoperation.h"
38 #include "gtkprivate.h"
39 #include "gtkradiobutton.h"
40 #include "gtkstock.h"
41 #include "gtkgrid.h"
42 #include "gtkwindow.h"
43 #include "gtktreeview.h"
44 #include "gtktreeselection.h"
45 #include "gtkcellrenderertext.h"
46 #include "gtkcellrendererpixbuf.h"
47 #include "gtkscrolledwindow.h"
48 #include "gtkicontheme.h"
49 #include "gtkimagemenuitem.h"
50 #include "gtkmain.h"
51
52 /**
53  * SECTION:filesystem
54  * @short_description: Functions for working with GIO
55  * @Title: Filesystem utilities
56  *
57  * The functions and objects described here make working with GTK+ and
58  * GIO more convenient.
59  *
60  * #GtkMountOperation is needed when mounting volumes:
61  * It is an implementation of #GMountOperation that can be used with
62  * GIO functions for mounting volumes such as
63  * g_file_mount_enclosing_volume(), g_file_mount_mountable(),
64  * g_volume_mount(), g_mount_unmount_with_operation() and others.
65  *
66  * When necessary, #GtkMountOperation shows dialogs to ask for
67  * passwords, questions or show processes blocking unmount.
68  *
69  * gtk_show_uri() is a convenient way to launch applications for URIs.
70  *
71  * Another object that is worth mentioning in this context is
72  * #GdkAppLaunchContext, which provides visual feedback when lauching
73  * applications.
74  */
75
76 static void   gtk_mount_operation_finalize     (GObject          *object);
77 static void   gtk_mount_operation_set_property (GObject          *object,
78                                                 guint             prop_id,
79                                                 const GValue     *value,
80                                                 GParamSpec       *pspec);
81 static void   gtk_mount_operation_get_property (GObject          *object,
82                                                 guint             prop_id,
83                                                 GValue           *value,
84                                                 GParamSpec       *pspec);
85
86 static void   gtk_mount_operation_ask_password (GMountOperation *op,
87                                                 const char      *message,
88                                                 const char      *default_user,
89                                                 const char      *default_domain,
90                                                 GAskPasswordFlags flags);
91
92 static void   gtk_mount_operation_ask_question (GMountOperation *op,
93                                                 const char      *message,
94                                                 const char      *choices[]);
95
96 static void   gtk_mount_operation_show_processes (GMountOperation *op,
97                                                   const char      *message,
98                                                   GArray          *processes,
99                                                   const char      *choices[]);
100
101 static void   gtk_mount_operation_aborted      (GMountOperation *op);
102
103 G_DEFINE_TYPE (GtkMountOperation, gtk_mount_operation, G_TYPE_MOUNT_OPERATION);
104
105 enum {
106   PROP_0,
107   PROP_PARENT,
108   PROP_IS_SHOWING,
109   PROP_SCREEN
110
111 };
112
113 struct _GtkMountOperationPrivate {
114   GtkWindow *parent_window;
115   GtkDialog *dialog;
116   GdkScreen *screen;
117
118   /* for the ask-password dialog */
119   GtkWidget *entry_container;
120   GtkWidget *username_entry;
121   GtkWidget *domain_entry;
122   GtkWidget *password_entry;
123   GtkWidget *anonymous_toggle;
124
125   GAskPasswordFlags ask_flags;
126   GPasswordSave     password_save;
127   gboolean          anonymous;
128
129   /* for the show-processes dialog */
130   GtkWidget *process_tree_view;
131   GtkListStore *process_list_store;
132 };
133
134 static void
135 gtk_mount_operation_class_init (GtkMountOperationClass *klass)
136 {
137   GObjectClass         *object_class = G_OBJECT_CLASS (klass);
138   GMountOperationClass *mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
139
140   g_type_class_add_private (klass, sizeof (GtkMountOperationPrivate));
141
142   object_class->finalize     = gtk_mount_operation_finalize;
143   object_class->get_property = gtk_mount_operation_get_property;
144   object_class->set_property = gtk_mount_operation_set_property;
145
146   mount_op_class->ask_password = gtk_mount_operation_ask_password;
147   mount_op_class->ask_question = gtk_mount_operation_ask_question;
148   mount_op_class->show_processes = gtk_mount_operation_show_processes;
149   mount_op_class->aborted = gtk_mount_operation_aborted;
150
151   g_object_class_install_property (object_class,
152                                    PROP_PARENT,
153                                    g_param_spec_object ("parent",
154                                                         P_("Parent"),
155                                                         P_("The parent window"),
156                                                         GTK_TYPE_WINDOW,
157                                                         GTK_PARAM_READWRITE));
158
159   g_object_class_install_property (object_class,
160                                    PROP_IS_SHOWING,
161                                    g_param_spec_boolean ("is-showing",
162                                                          P_("Is Showing"),
163                                                          P_("Are we showing a dialog"),
164                                                          FALSE,
165                                                          GTK_PARAM_READABLE));
166
167   g_object_class_install_property (object_class,
168                                    PROP_SCREEN,
169                                    g_param_spec_object ("screen",
170                                                         P_("Screen"),
171                                                         P_("The screen where this window will be displayed."),
172                                                         GDK_TYPE_SCREEN,
173                                                         GTK_PARAM_READWRITE));
174 }
175
176 static void
177 gtk_mount_operation_init (GtkMountOperation *operation)
178 {
179   operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation,
180                                                  GTK_TYPE_MOUNT_OPERATION,
181                                                  GtkMountOperationPrivate);
182 }
183
184 static void
185 gtk_mount_operation_finalize (GObject *object)
186 {
187   GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
188   GtkMountOperationPrivate *priv = operation->priv;
189
190   if (priv->parent_window)
191     g_object_unref (priv->parent_window);
192
193   if (priv->screen)
194     g_object_unref (priv->screen);
195
196   G_OBJECT_CLASS (gtk_mount_operation_parent_class)->finalize (object);
197 }
198
199 static void
200 gtk_mount_operation_set_property (GObject      *object,
201                                   guint         prop_id,
202                                   const GValue *value,
203                                   GParamSpec   *pspec)
204 {
205   GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
206
207   switch (prop_id)
208     {
209     case PROP_PARENT:
210       gtk_mount_operation_set_parent (operation, g_value_get_object (value));
211       break;
212
213     case PROP_SCREEN:
214       gtk_mount_operation_set_screen (operation, g_value_get_object (value));
215       break;
216
217     case PROP_IS_SHOWING:
218     default:
219       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220       break;
221     }
222 }
223
224 static void
225 gtk_mount_operation_get_property (GObject    *object,
226                                   guint       prop_id,
227                                   GValue     *value,
228                                   GParamSpec *pspec)
229 {
230   GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
231   GtkMountOperationPrivate *priv = operation->priv;
232
233   switch (prop_id)
234     {
235     case PROP_PARENT:
236       g_value_set_object (value, priv->parent_window);
237       break;
238
239     case PROP_IS_SHOWING:
240       g_value_set_boolean (value, priv->dialog != NULL);
241       break;
242
243     case PROP_SCREEN:
244       g_value_set_object (value, priv->screen);
245       break;
246
247     default:
248       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249       break;
250     }
251 }
252
253 static void
254 remember_button_toggled (GtkToggleButton   *button,
255                          GtkMountOperation *operation)
256 {
257   GtkMountOperationPrivate *priv = operation->priv;
258
259   if (gtk_toggle_button_get_active (button))
260     {
261       gpointer data;
262
263       data = g_object_get_data (G_OBJECT (button), "password-save");
264       priv->password_save = GPOINTER_TO_INT (data);
265     }
266 }
267
268 static void
269 pw_dialog_got_response (GtkDialog         *dialog,
270                         gint               response_id,
271                         GtkMountOperation *mount_op)
272 {
273   GtkMountOperationPrivate *priv = mount_op->priv;
274   GMountOperation *op = G_MOUNT_OPERATION (mount_op);
275
276   if (response_id == GTK_RESPONSE_OK)
277     {
278       const char *text;
279
280       if (priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED)
281         g_mount_operation_set_anonymous (op, priv->anonymous);
282
283       if (priv->username_entry)
284         {
285           text = gtk_entry_get_text (GTK_ENTRY (priv->username_entry));
286           g_mount_operation_set_username (op, text);
287         }
288
289       if (priv->domain_entry)
290         {
291           text = gtk_entry_get_text (GTK_ENTRY (priv->domain_entry));
292           g_mount_operation_set_domain (op, text);
293         }
294
295       if (priv->password_entry)
296         {
297           text = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
298           g_mount_operation_set_password (op, text);
299         }
300
301       if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
302         g_mount_operation_set_password_save (op, priv->password_save);
303
304       g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
305     }
306   else
307     g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
308
309   priv->dialog = NULL;
310   g_object_notify (G_OBJECT (op), "is-showing");
311   gtk_widget_destroy (GTK_WIDGET (dialog));
312   g_object_unref (op);
313 }
314
315 static gboolean
316 entry_has_input (GtkWidget *entry_widget)
317 {
318   const char *text;
319
320   if (entry_widget == NULL)
321     return TRUE;
322
323   text = gtk_entry_get_text (GTK_ENTRY (entry_widget));
324
325   return text != NULL && text[0] != '\0';
326 }
327
328 static gboolean
329 pw_dialog_input_is_valid (GtkMountOperation *operation)
330 {
331   GtkMountOperationPrivate *priv = operation->priv;
332   gboolean is_valid = TRUE;
333
334   /* We don't require password to be non-empty here
335    * since there are situations where it is not needed,
336    * see bug 578365.
337    * We may add a way for the backend to specify that it
338    * definitively needs a password.
339    */
340   is_valid = entry_has_input (priv->username_entry) &&
341              entry_has_input (priv->domain_entry);
342
343   return is_valid;
344 }
345
346 static void
347 pw_dialog_verify_input (GtkEditable       *editable,
348                         GtkMountOperation *operation)
349 {
350   GtkMountOperationPrivate *priv = operation->priv;
351   gboolean is_valid;
352
353   is_valid = pw_dialog_input_is_valid (operation);
354   gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
355                                      GTK_RESPONSE_OK,
356                                      is_valid);
357 }
358
359 static void
360 pw_dialog_anonymous_toggled (GtkWidget         *widget,
361                              GtkMountOperation *operation)
362 {
363   GtkMountOperationPrivate *priv = operation->priv;
364   gboolean is_valid;
365
366   priv->anonymous = widget == priv->anonymous_toggle;
367
368   if (priv->anonymous)
369     is_valid = TRUE;
370   else
371     is_valid = pw_dialog_input_is_valid (operation);
372
373   gtk_widget_set_sensitive (priv->entry_container, priv->anonymous == FALSE);
374   gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
375                                      GTK_RESPONSE_OK,
376                                      is_valid);
377 }
378
379
380 static void
381 pw_dialog_cycle_focus (GtkWidget         *widget,
382                        GtkMountOperation *operation)
383 {
384   GtkMountOperationPrivate *priv;
385   GtkWidget *next_widget = NULL;
386
387   priv = operation->priv;
388
389   if (widget == priv->username_entry)
390     {
391       if (priv->domain_entry != NULL)
392         next_widget = priv->domain_entry;
393       else if (priv->password_entry != NULL)
394         next_widget = priv->password_entry;
395     }
396   else if (widget == priv->domain_entry && priv->password_entry)
397     next_widget = priv->password_entry;
398
399   if (next_widget)
400     gtk_widget_grab_focus (next_widget);
401   else if (pw_dialog_input_is_valid (operation))
402     gtk_window_activate_default (GTK_WINDOW (priv->dialog));
403 }
404
405 static GtkWidget *
406 table_add_entry (GtkWidget  *table,
407                  int         row,
408                  const char *label_text,
409                  const char *value,
410                  gpointer    user_data)
411 {
412   GtkWidget *entry;
413   GtkWidget *label;
414
415   label = gtk_label_new_with_mnemonic (label_text);
416   gtk_widget_set_halign (label, GTK_ALIGN_START);
417   gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
418   gtk_widget_set_hexpand (label, TRUE);
419
420   entry = gtk_entry_new ();
421
422   if (value)
423     gtk_entry_set_text (GTK_ENTRY (entry), value);
424
425   gtk_grid_attach (GTK_GRID (table), label, 0, row, 1, 1);
426   gtk_grid_attach (GTK_GRID (table), entry, 1, row, 1, 1);
427   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
428
429   g_signal_connect (entry, "changed",
430                     G_CALLBACK (pw_dialog_verify_input), user_data);
431
432   g_signal_connect (entry, "activate",
433                     G_CALLBACK (pw_dialog_cycle_focus), user_data);
434
435   return entry;
436 }
437
438 static void
439 gtk_mount_operation_ask_password (GMountOperation   *mount_op,
440                                   const char        *message,
441                                   const char        *default_user,
442                                   const char        *default_domain,
443                                   GAskPasswordFlags  flags)
444 {
445   GtkMountOperation *operation;
446   GtkMountOperationPrivate *priv;
447   GtkWidget *widget;
448   GtkDialog *dialog;
449   GtkWindow *window;
450   GtkWidget *hbox, *main_vbox, *vbox, *icon;
451   GtkWidget *table;
452   GtkWidget *message_label;
453   GtkWidget *content_area, *action_area;
454   gboolean   can_anonymous;
455   guint      rows;
456   const gchar *secondary;
457
458   operation = GTK_MOUNT_OPERATION (mount_op);
459   priv = operation->priv;
460
461   priv->ask_flags = flags;
462
463   widget = gtk_dialog_new ();
464   dialog = GTK_DIALOG (widget);
465   window = GTK_WINDOW (widget);
466
467   priv->dialog = dialog;
468
469   content_area = gtk_dialog_get_content_area (dialog);
470   action_area = gtk_dialog_get_action_area (dialog);
471
472   /* Set the dialog up with HIG properties */
473   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
474   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
475   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
476   gtk_box_set_spacing (GTK_BOX (action_area), 6);
477
478   gtk_window_set_resizable (window, FALSE);
479   gtk_window_set_title (window, "");
480   gtk_window_set_icon_name (window, GTK_STOCK_DIALOG_AUTHENTICATION);
481
482   gtk_dialog_add_buttons (dialog,
483                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
484                           _("Co_nnect"), GTK_RESPONSE_OK,
485                           NULL);
486   gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
487
488   gtk_dialog_set_alternative_button_order (dialog,
489                                            GTK_RESPONSE_OK,
490                                            GTK_RESPONSE_CANCEL,
491                                            -1);
492
493   /* Build contents */
494   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
495   gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
496   gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
497
498   icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
499                                    GTK_ICON_SIZE_DIALOG);
500
501   gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
502   gtk_widget_set_valign (icon, GTK_ALIGN_START);
503   gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
504
505   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
506   gtk_box_pack_start (GTK_BOX (hbox), main_vbox, TRUE, TRUE, 0);
507
508   secondary = strstr (message, "\n");
509   if (secondary != NULL)
510     {
511       gchar *s;
512       gchar *primary;
513
514       primary = g_strndup (message, secondary - message + 1);
515       s = g_strdup_printf ("<big><b>%s</b></big>%s", primary, secondary);
516
517       message_label = gtk_label_new (NULL);
518       gtk_label_set_markup (GTK_LABEL (message_label), s);
519       gtk_widget_set_halign (message_label, GTK_ALIGN_START);
520       gtk_widget_set_valign (message_label, GTK_ALIGN_CENTER);
521       gtk_label_set_line_wrap (GTK_LABEL (message_label), TRUE);
522       gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (message_label),
523                           FALSE, TRUE, 0);
524
525       g_free (s);
526       g_free (primary);
527     }
528   else
529     {
530       message_label = gtk_label_new (message);
531       gtk_widget_set_halign (message_label, GTK_ALIGN_START);
532       gtk_widget_set_valign (message_label, GTK_ALIGN_CENTER);
533       gtk_label_set_line_wrap (GTK_LABEL (message_label), TRUE);
534       gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (message_label),
535                           FALSE, FALSE, 0);
536     }
537
538   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
539   gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
540
541   can_anonymous = flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
542
543   priv->anonymous_toggle = NULL;
544   if (can_anonymous)
545     {
546       GtkWidget *anon_box;
547       GtkWidget *choice;
548       GSList    *group;
549
550       anon_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
551       gtk_box_pack_start (GTK_BOX (vbox), anon_box,
552                           FALSE, FALSE, 0);
553
554       choice = gtk_radio_button_new_with_mnemonic (NULL, _("Connect _anonymously"));
555       gtk_box_pack_start (GTK_BOX (anon_box),
556                           choice,
557                           FALSE, FALSE, 0);
558       g_signal_connect (choice, "toggled",
559                         G_CALLBACK (pw_dialog_anonymous_toggled), operation);
560       priv->anonymous_toggle = choice;
561
562       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
563       choice = gtk_radio_button_new_with_mnemonic (group, _("Connect as u_ser:"));
564       gtk_box_pack_start (GTK_BOX (anon_box),
565                           choice,
566                           FALSE, FALSE, 0);
567       g_signal_connect (choice, "toggled",
568                         G_CALLBACK (pw_dialog_anonymous_toggled), operation);
569     }
570
571   rows = 0;
572
573   if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
574     rows++;
575
576   if (flags & G_ASK_PASSWORD_NEED_USERNAME)
577     rows++;
578
579   if (flags &G_ASK_PASSWORD_NEED_DOMAIN)
580     rows++;
581
582   /* The table that holds the entries */
583   table = gtk_grid_new ();
584   gtk_grid_set_row_spacing (GTK_GRID (table), 6);
585   gtk_grid_set_column_spacing (GTK_GRID (table), 6);
586
587   if (can_anonymous)
588     gtk_widget_set_margin_left (table, 12);
589
590   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
591   priv->entry_container = table;
592
593   rows = 0;
594
595   priv->username_entry = NULL;
596   if (flags & G_ASK_PASSWORD_NEED_USERNAME)
597     priv->username_entry = table_add_entry (table, rows++, _("_Username:"),
598                                             default_user, operation);
599
600   priv->domain_entry = NULL;
601   if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
602     priv->domain_entry = table_add_entry (table, rows++, _("_Domain:"),
603                                           default_domain, operation);
604
605   priv->password_entry = NULL;
606   if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
607     {
608       priv->password_entry = table_add_entry (table, rows++, _("_Password:"),
609                                               NULL, operation);
610       gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE);
611     }
612
613    if (flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
614     {
615       GtkWidget    *choice;
616       GtkWidget    *remember_box;
617       GSList       *group;
618       GPasswordSave password_save;
619
620       remember_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
621       gtk_box_pack_start (GTK_BOX (vbox), remember_box,
622                           FALSE, FALSE, 0);
623
624       password_save = g_mount_operation_get_password_save (mount_op);
625       
626       choice = gtk_radio_button_new_with_mnemonic (NULL, _("Forget password _immediately"));
627       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
628                                     password_save == G_PASSWORD_SAVE_NEVER);
629       g_object_set_data (G_OBJECT (choice), "password-save",
630                          GINT_TO_POINTER (G_PASSWORD_SAVE_NEVER));
631       g_signal_connect (choice, "toggled",
632                         G_CALLBACK (remember_button_toggled), operation);
633       gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
634
635       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
636       choice = gtk_radio_button_new_with_mnemonic (group, _("Remember password until you _logout"));
637       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
638                                     password_save == G_PASSWORD_SAVE_FOR_SESSION);
639       g_object_set_data (G_OBJECT (choice), "password-save",
640                          GINT_TO_POINTER (G_PASSWORD_SAVE_FOR_SESSION));
641       g_signal_connect (choice, "toggled",
642                         G_CALLBACK (remember_button_toggled), operation);
643       gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
644
645       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
646       choice = gtk_radio_button_new_with_mnemonic (group, _("Remember _forever"));
647       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
648                                     password_save == G_PASSWORD_SAVE_PERMANENTLY);
649       g_object_set_data (G_OBJECT (choice), "password-save",
650                          GINT_TO_POINTER (G_PASSWORD_SAVE_PERMANENTLY));
651       g_signal_connect (choice, "toggled",
652                         G_CALLBACK (remember_button_toggled), operation);
653       gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
654     }
655
656   g_signal_connect (G_OBJECT (dialog), "response",
657                     G_CALLBACK (pw_dialog_got_response), operation);
658
659   if (can_anonymous)
660     {
661       /* The anonymous option will be active by default,
662        * ensure the toggled signal is emitted for it.
663        */
664       gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (priv->anonymous_toggle));
665     }
666   else if (! pw_dialog_input_is_valid (operation))
667     gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, FALSE);
668
669   g_object_notify (G_OBJECT (operation), "is-showing");
670
671   if (priv->parent_window)
672     {
673       gtk_window_set_transient_for (window, priv->parent_window);
674       gtk_window_set_modal (window, TRUE);
675     }
676   else if (priv->screen)
677     gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
678
679   gtk_widget_show_all (GTK_WIDGET (dialog));
680
681   g_object_ref (operation);
682 }
683
684 static void
685 question_dialog_button_clicked (GtkDialog       *dialog,
686                                 gint             button_number,
687                                 GMountOperation *op)
688 {
689   GtkMountOperationPrivate *priv;
690   GtkMountOperation *operation;
691
692   operation = GTK_MOUNT_OPERATION (op);
693   priv = operation->priv;
694
695   if (button_number >= 0)
696     {
697       g_mount_operation_set_choice (op, button_number);
698       g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
699     }
700   else
701     g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
702
703   priv->dialog = NULL;
704   g_object_notify (G_OBJECT (operation), "is-showing");
705   gtk_widget_destroy (GTK_WIDGET (dialog));
706   g_object_unref (op);
707 }
708
709 static void
710 gtk_mount_operation_ask_question (GMountOperation *op,
711                                   const char      *message,
712                                   const char      *choices[])
713 {
714   GtkMountOperationPrivate *priv;
715   GtkWidget  *dialog;
716   const char *secondary = NULL;
717   char       *primary;
718   int        count, len = 0;
719
720   g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
721   g_return_if_fail (message != NULL);
722   g_return_if_fail (choices != NULL);
723
724   priv = GTK_MOUNT_OPERATION (op)->priv;
725
726   primary = strstr (message, "\n");
727   if (primary)
728     {
729       secondary = primary + 1;
730       primary = g_strndup (message, primary - message);
731     }
732
733   dialog = gtk_message_dialog_new (priv->parent_window, 0,
734                                    GTK_MESSAGE_QUESTION,
735                                    GTK_BUTTONS_NONE, "%s",
736                                    primary != NULL ? primary : message);
737   g_free (primary);
738
739   if (secondary)
740     gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
741                                               "%s", secondary);
742
743   /* First count the items in the list then
744    * add the buttons in reverse order */
745
746   while (choices[len] != NULL)
747     len++;
748
749   for (count = len - 1; count >= 0; count--)
750     gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
751
752   g_signal_connect (G_OBJECT (dialog), "response",
753                     G_CALLBACK (question_dialog_button_clicked), op);
754
755   priv->dialog = GTK_DIALOG (dialog);
756   g_object_notify (G_OBJECT (op), "is-showing");
757
758   if (priv->parent_window == NULL && priv->screen)
759     gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
760
761   gtk_widget_show (dialog);
762   g_object_ref (op);
763 }
764
765 static void
766 show_processes_button_clicked (GtkDialog       *dialog,
767                                gint             button_number,
768                                GMountOperation *op)
769 {
770   GtkMountOperationPrivate *priv;
771   GtkMountOperation *operation;
772
773   operation = GTK_MOUNT_OPERATION (op);
774   priv = operation->priv;
775
776   if (button_number >= 0)
777     {
778       g_mount_operation_set_choice (op, button_number);
779       g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
780     }
781   else
782     g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
783
784   priv->dialog = NULL;
785   g_object_notify (G_OBJECT (operation), "is-showing");
786   gtk_widget_destroy (GTK_WIDGET (dialog));
787   g_object_unref (op);
788 }
789
790 static gint
791 pid_equal (gconstpointer a,
792            gconstpointer b)
793 {
794   GPid pa, pb;
795
796   pa = *((GPid *) a);
797   pb = *((GPid *) b);
798
799   return GPOINTER_TO_INT(pb) - GPOINTER_TO_INT(pa);
800 }
801
802 static void
803 diff_sorted_arrays (GArray         *array1,
804                     GArray         *array2,
805                     GCompareFunc   compare,
806                     GArray         *added_indices,
807                     GArray         *removed_indices)
808 {
809   gint order;
810   guint n1, n2;
811   guint elem_size;
812
813   n1 = n2 = 0;
814
815   elem_size = g_array_get_element_size (array1);
816   g_assert (elem_size == g_array_get_element_size (array2));
817
818   while (n1 < array1->len && n2 < array2->len)
819     {
820       order = (*compare) (((const char*) array1->data) + n1 * elem_size,
821                           ((const char*) array2->data) + n2 * elem_size);
822       if (order < 0)
823         {
824           g_array_append_val (removed_indices, n1);
825           n1++;
826         }
827       else if (order > 0)
828         {
829           g_array_append_val (added_indices, n2);
830           n2++;
831         }
832       else
833         { /* same item */
834           n1++;
835           n2++;
836         }
837     }
838
839   while (n1 < array1->len)
840     {
841       g_array_append_val (removed_indices, n1);
842       n1++;
843     }
844   while (n2 < array2->len)
845     {
846       g_array_append_val (added_indices, n2);
847       n2++;
848     }
849 }
850
851
852 static void
853 add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
854                                GtkMountOperationLookupContext *lookup_context,
855                                GtkListStore                   *list_store,
856                                GPid                            pid)
857 {
858   gchar *command_line;
859   gchar *name;
860   GdkPixbuf *pixbuf;
861   gchar *markup;
862   GtkTreeIter iter;
863
864   name = NULL;
865   pixbuf = NULL;
866   command_line = NULL;
867   _gtk_mount_operation_lookup_info (lookup_context,
868                                     pid,
869                                     24,
870                                     &name,
871                                     &command_line,
872                                     &pixbuf);
873
874   if (name == NULL)
875     name = g_strdup_printf (_("Unknown Application (PID %d)"), pid);
876
877   if (command_line == NULL)
878     command_line = g_strdup ("");
879
880   if (pixbuf == NULL)
881     {
882       GtkIconTheme *theme;
883       theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (mount_operation->priv->dialog)));
884       pixbuf = gtk_icon_theme_load_icon (theme,
885                                          "application-x-executable",
886                                          24,
887                                          0,
888                                          NULL);
889     }
890
891   markup = g_strdup_printf ("<b>%s</b>\n"
892                             "<small>%s</small>",
893                             name,
894                             command_line);
895
896   gtk_list_store_append (list_store, &iter);
897   gtk_list_store_set (list_store, &iter,
898                       0, pixbuf,
899                       1, markup,
900                       2, pid,
901                       -1);
902
903   if (pixbuf != NULL)
904     g_object_unref (pixbuf);
905   g_free (markup);
906   g_free (name);
907   g_free (command_line);
908 }
909
910 static void
911 remove_pid_from_process_list_store (GtkMountOperation *mount_operation,
912                                     GtkListStore      *list_store,
913                                     GPid               pid)
914 {
915   GtkTreeIter iter;
916   GPid pid_of_item;
917
918   if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
919     {
920       do
921         {
922           gtk_tree_model_get (GTK_TREE_MODEL (list_store),
923                               &iter,
924                               2, &pid_of_item,
925                               -1);
926
927           if (pid_of_item == pid)
928             {
929               gtk_list_store_remove (list_store, &iter);
930               break;
931             }
932         }
933       while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
934     }
935 }
936
937
938 static void
939 update_process_list_store (GtkMountOperation *mount_operation,
940                            GtkListStore      *list_store,
941                            GArray            *processes)
942 {
943   guint n;
944   GtkMountOperationLookupContext *lookup_context;
945   GArray *current_pids;
946   GArray *pid_indices_to_add;
947   GArray *pid_indices_to_remove;
948   GtkTreeIter iter;
949   GPid pid;
950
951   /* Just removing all items and adding new ones will screw up the
952    * focus handling in the treeview - so compute the delta, and add/remove
953    * items as appropriate
954    */
955   current_pids = g_array_new (FALSE, FALSE, sizeof (GPid));
956   pid_indices_to_add = g_array_new (FALSE, FALSE, sizeof (gint));
957   pid_indices_to_remove = g_array_new (FALSE, FALSE, sizeof (gint));
958
959   if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
960     {
961       do
962         {
963           gtk_tree_model_get (GTK_TREE_MODEL (list_store),
964                               &iter,
965                               2, &pid,
966                               -1);
967
968           g_array_append_val (current_pids, pid);
969         }
970       while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
971     }
972
973   g_array_sort (current_pids, pid_equal);
974   g_array_sort (processes, pid_equal);
975
976   diff_sorted_arrays (current_pids, processes, pid_equal, pid_indices_to_add, pid_indices_to_remove);
977
978   for (n = 0; n < pid_indices_to_remove->len; n++)
979     {
980       pid = g_array_index (current_pids, GPid, n);
981       remove_pid_from_process_list_store (mount_operation, list_store, pid);
982     }
983
984   if (pid_indices_to_add->len > 0)
985     {
986       lookup_context = _gtk_mount_operation_lookup_context_get (gtk_widget_get_display (mount_operation->priv->process_tree_view));
987       for (n = 0; n < pid_indices_to_add->len; n++)
988         {
989           pid = g_array_index (processes, GPid, n);
990           add_pid_to_process_list_store (mount_operation, lookup_context, list_store, pid);
991         }
992       _gtk_mount_operation_lookup_context_free (lookup_context);
993     }
994
995   /* select the first item, if we went from a zero to a non-zero amount of processes */
996   if (current_pids->len == 0 && pid_indices_to_add->len > 0)
997     {
998       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
999         {
1000           GtkTreeSelection *tree_selection;
1001           tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (mount_operation->priv->process_tree_view));
1002           gtk_tree_selection_select_iter (tree_selection, &iter);
1003         }
1004     }
1005
1006   g_array_unref (current_pids);
1007   g_array_unref (pid_indices_to_add);
1008   g_array_unref (pid_indices_to_remove);
1009 }
1010
1011 static void
1012 on_end_process_activated (GtkMenuItem *item,
1013                           gpointer user_data)
1014 {
1015   GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1016   GtkTreeSelection *selection;
1017   GtkTreeIter iter;
1018   GPid pid_to_kill;
1019   GError *error;
1020
1021   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
1022
1023   if (!gtk_tree_selection_get_selected (selection,
1024                                         NULL,
1025                                         &iter))
1026     goto out;
1027
1028   gtk_tree_model_get (GTK_TREE_MODEL (op->priv->process_list_store),
1029                       &iter,
1030                       2, &pid_to_kill,
1031                       -1);
1032
1033   /* TODO: We might want to either
1034    *
1035    *       - Be smart about things and send SIGKILL rather than SIGTERM if
1036    *         this is the second time the user requests killing a process
1037    *
1038    *       - Or, easier (but worse user experience), offer both "End Process"
1039    *         and "Terminate Process" options
1040    *
1041    *      But that's not how things work right now....
1042    */
1043   error = NULL;
1044   if (!_gtk_mount_operation_kill_process (pid_to_kill, &error))
1045     {
1046       GtkWidget *dialog;
1047       gint response;
1048
1049       /* Use GTK_DIALOG_DESTROY_WITH_PARENT here since the parent dialog can be
1050        * indeed be destroyed via the GMountOperation::abort signal... for example,
1051        * this is triggered if the user yanks the device while we are showing
1052        * the dialog...
1053        */
1054       dialog = gtk_message_dialog_new (GTK_WINDOW (op->priv->dialog),
1055                                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1056                                        GTK_MESSAGE_ERROR,
1057                                        GTK_BUTTONS_CLOSE,
1058                                        _("Unable to end process"));
1059       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1060                                                 "%s",
1061                                                 error->message);
1062
1063       gtk_widget_show_all (dialog);
1064       response = gtk_dialog_run (GTK_DIALOG (dialog));
1065
1066       /* GTK_RESPONSE_NONE means the dialog were programmatically destroy, e.g. that
1067        * GTK_DIALOG_DESTROY_WITH_PARENT kicked in - so it would trigger a warning to
1068        * destroy the dialog in that case
1069        */
1070       if (response != GTK_RESPONSE_NONE)
1071         gtk_widget_destroy (dialog);
1072
1073       g_error_free (error);
1074     }
1075
1076  out:
1077   ;
1078 }
1079
1080 static gboolean
1081 do_popup_menu_for_process_tree_view (GtkWidget         *widget,
1082                                      GdkEventButton    *event,
1083                                      GtkMountOperation *op)
1084 {
1085   GtkWidget *menu;
1086   GtkWidget *item;
1087   gint button;
1088   gint event_time;
1089   gboolean popped_up_menu;
1090
1091   popped_up_menu = FALSE;
1092
1093   menu = gtk_menu_new ();
1094
1095   item = gtk_image_menu_item_new_with_mnemonic (_("_End Process"));
1096   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1097                                  gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
1098   g_signal_connect (item, "activate",
1099                     G_CALLBACK (on_end_process_activated),
1100                     op);
1101   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1102   gtk_widget_show_all (menu);
1103
1104   if (event != NULL)
1105     {
1106       GtkTreePath *path;
1107       GtkTreeSelection *selection;
1108
1109       if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (op->priv->process_tree_view),
1110                                          (gint) event->x,
1111                                          (gint) event->y,
1112                                          &path,
1113                                          NULL,
1114                                          NULL,
1115                                          NULL))
1116         {
1117           selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
1118           gtk_tree_selection_select_path (selection, path);
1119           gtk_tree_path_free (path);
1120         }
1121       else
1122         {
1123           /* don't popup a menu if the user right-clicked in an area with no rows */
1124           goto out;
1125         }
1126
1127       button = event->button;
1128       event_time = event->time;
1129     }
1130   else
1131     {
1132       button = 0;
1133       event_time = gtk_get_current_event_time ();
1134     }
1135
1136   gtk_menu_popup (GTK_MENU (menu),
1137                   NULL,
1138                   widget,
1139                   NULL,
1140                   NULL,
1141                   button,
1142                   event_time);
1143
1144   popped_up_menu = TRUE;
1145
1146  out:
1147   return popped_up_menu;
1148 }
1149
1150 static gboolean
1151 on_popup_menu_for_process_tree_view (GtkWidget *widget,
1152                                      gpointer   user_data)
1153 {
1154   GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1155   return do_popup_menu_for_process_tree_view (widget, NULL, op);
1156 }
1157
1158 static gboolean
1159 on_button_press_event_for_process_tree_view (GtkWidget      *widget,
1160                                              GdkEventButton *event,
1161                                              gpointer        user_data)
1162 {
1163   GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1164   gboolean ret;
1165
1166   ret = FALSE;
1167
1168   if (gdk_event_triggers_context_menu ((GdkEvent *) event))
1169     {
1170       ret = do_popup_menu_for_process_tree_view (widget, event, op);
1171     }
1172
1173   return ret;
1174 }
1175
1176 static GtkWidget *
1177 create_show_processes_dialog (GMountOperation *op,
1178                               const char      *message,
1179                               const char      *choices[])
1180 {
1181   GtkMountOperationPrivate *priv;
1182   GtkWidget  *dialog;
1183   const char *secondary = NULL;
1184   char       *primary;
1185   int        count, len = 0;
1186   GtkWidget *label;
1187   GtkWidget *tree_view;
1188   GtkWidget *scrolled_window;
1189   GtkWidget *vbox;
1190   GtkWidget *content_area;
1191   GtkTreeViewColumn *column;
1192   GtkCellRenderer *renderer;
1193   GtkListStore *list_store;
1194   gchar *s;
1195
1196   priv = GTK_MOUNT_OPERATION (op)->priv;
1197
1198   primary = strstr (message, "\n");
1199   if (primary)
1200     {
1201       secondary = primary + 1;
1202       primary = g_strndup (message, primary - message);
1203     }
1204
1205   dialog = gtk_dialog_new ();
1206
1207   if (priv->parent_window != NULL)
1208     gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->parent_window);
1209   gtk_window_set_title (GTK_WINDOW (dialog), "");
1210
1211   content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1212   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
1213   gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
1214   gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
1215
1216   if (secondary != NULL)
1217     {
1218       s = g_strdup_printf ("<big><b>%s</b></big>\n\n%s", primary, secondary);
1219     }
1220   else
1221     {
1222       s = g_strdup_printf ("%s", primary);
1223     }
1224   g_free (primary);
1225   label = gtk_label_new (NULL);
1226   gtk_label_set_markup (GTK_LABEL (label), s);
1227   g_free (s);
1228   gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1229
1230   /* First count the items in the list then
1231    * add the buttons in reverse order */
1232
1233   while (choices[len] != NULL)
1234     len++;
1235
1236   for (count = len - 1; count >= 0; count--)
1237     gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
1238
1239   g_signal_connect (G_OBJECT (dialog), "response",
1240                     G_CALLBACK (show_processes_button_clicked), op);
1241
1242   priv->dialog = GTK_DIALOG (dialog);
1243   g_object_notify (G_OBJECT (op), "is-showing");
1244
1245   if (priv->parent_window == NULL && priv->screen)
1246     gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
1247
1248   tree_view = gtk_tree_view_new ();
1249   /* TODO: should use EM's when gtk+ RI patches land */
1250   gtk_widget_set_size_request (tree_view,
1251                                300,
1252                                120);
1253
1254   column = gtk_tree_view_column_new ();
1255   renderer = gtk_cell_renderer_pixbuf_new ();
1256   gtk_tree_view_column_pack_start (column, renderer, FALSE);
1257   gtk_tree_view_column_set_attributes (column, renderer,
1258                                        "pixbuf", 0,
1259                                        NULL);
1260   renderer = gtk_cell_renderer_text_new ();
1261   g_object_set (renderer,
1262                 "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
1263                 "ellipsize-set", TRUE,
1264                 NULL);
1265   gtk_tree_view_column_pack_start (column, renderer, TRUE);
1266   gtk_tree_view_column_set_attributes (column, renderer,
1267                                        "markup", 1,
1268                                        NULL);
1269   gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
1270   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
1271
1272
1273   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1274   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1275                                   GTK_POLICY_NEVER,
1276                                   GTK_POLICY_AUTOMATIC);
1277   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
1278
1279   gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
1280   gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
1281
1282   g_signal_connect (tree_view, "popup-menu",
1283                     G_CALLBACK (on_popup_menu_for_process_tree_view),
1284                     op);
1285   g_signal_connect (tree_view, "button-press-event",
1286                     G_CALLBACK (on_button_press_event_for_process_tree_view),
1287                     op);
1288
1289   list_store = gtk_list_store_new (3,
1290                                    GDK_TYPE_PIXBUF,
1291                                    G_TYPE_STRING,
1292                                    G_TYPE_INT);
1293
1294   gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store));
1295
1296   priv->process_list_store = list_store;
1297   priv->process_tree_view = tree_view;
1298   /* set pointers to NULL when dialog goes away */
1299   g_object_add_weak_pointer (G_OBJECT (list_store), (gpointer *) &priv->process_list_store);
1300   g_object_add_weak_pointer (G_OBJECT (tree_view), (gpointer *) &priv->process_tree_view);
1301
1302   g_object_unref (list_store);
1303   g_object_ref (op);
1304
1305   return dialog;
1306 }
1307
1308 static void
1309 gtk_mount_operation_show_processes (GMountOperation *op,
1310                                     const char      *message,
1311                                     GArray          *processes,
1312                                     const char      *choices[])
1313 {
1314   GtkMountOperationPrivate *priv;
1315   GtkWidget *dialog = NULL;
1316
1317   g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1318   g_return_if_fail (message != NULL);
1319   g_return_if_fail (processes != NULL);
1320   g_return_if_fail (choices != NULL);
1321
1322   priv = GTK_MOUNT_OPERATION (op)->priv;
1323
1324   if (priv->process_list_store == NULL)
1325     {
1326       /* need to create the dialog */
1327       dialog = create_show_processes_dialog (op, message, choices);
1328     }
1329
1330   /* otherwise, we're showing the dialog, assume messages+choices hasn't changed */
1331
1332   update_process_list_store (GTK_MOUNT_OPERATION (op),
1333                              priv->process_list_store,
1334                              processes);
1335
1336   if (dialog != NULL)
1337     {
1338       gtk_widget_show_all (dialog);
1339     }
1340 }
1341
1342 static void
1343 gtk_mount_operation_aborted (GMountOperation *op)
1344 {
1345   GtkMountOperationPrivate *priv;
1346
1347   priv = GTK_MOUNT_OPERATION (op)->priv;
1348
1349   if (priv->dialog != NULL)
1350     {
1351       gtk_widget_destroy (GTK_WIDGET (priv->dialog));
1352       priv->dialog = NULL;
1353       g_object_notify (G_OBJECT (op), "is-showing");
1354       g_object_unref (op);
1355     }
1356 }
1357
1358 /**
1359  * gtk_mount_operation_new:
1360  * @parent: (allow-none): transient parent of the window, or %NULL
1361  *
1362  * Creates a new #GtkMountOperation
1363  *
1364  * Returns: a new #GtkMountOperation
1365  *
1366  * Since: 2.14
1367  */
1368 GMountOperation *
1369 gtk_mount_operation_new (GtkWindow *parent)
1370 {
1371   GMountOperation *mount_operation;
1372
1373   mount_operation = g_object_new (GTK_TYPE_MOUNT_OPERATION,
1374                                   "parent", parent, NULL);
1375
1376   return mount_operation;
1377 }
1378
1379 /**
1380  * gtk_mount_operation_is_showing:
1381  * @op: a #GtkMountOperation
1382  *
1383  * Returns whether the #GtkMountOperation is currently displaying
1384  * a window.
1385  *
1386  * Returns: %TRUE if @op is currently displaying a window
1387  *
1388  * Since: 2.14
1389  */
1390 gboolean
1391 gtk_mount_operation_is_showing (GtkMountOperation *op)
1392 {
1393   g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), FALSE);
1394
1395   return op->priv->dialog != NULL;
1396 }
1397
1398 /**
1399  * gtk_mount_operation_set_parent:
1400  * @op: a #GtkMountOperation
1401  * @parent: (allow-none): transient parent of the window, or %NULL
1402  *
1403  * Sets the transient parent for windows shown by the
1404  * #GtkMountOperation.
1405  *
1406  * Since: 2.14
1407  */
1408 void
1409 gtk_mount_operation_set_parent (GtkMountOperation *op,
1410                                 GtkWindow         *parent)
1411 {
1412   GtkMountOperationPrivate *priv;
1413
1414   g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1415   g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
1416
1417   priv = op->priv;
1418
1419   if (priv->parent_window == parent)
1420     return;
1421
1422   if (priv->parent_window)
1423     {
1424       g_signal_handlers_disconnect_by_func (priv->parent_window,
1425                                             gtk_widget_destroyed,
1426                                             &priv->parent_window);
1427       priv->parent_window = NULL;
1428     }
1429
1430   if (parent)
1431     {
1432       priv->parent_window = g_object_ref (parent);
1433
1434       g_signal_connect (parent, "destroy",
1435                         G_CALLBACK (gtk_widget_destroyed),
1436                         &priv->parent_window);
1437
1438       if (priv->dialog)
1439         gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), parent);
1440     }
1441
1442   g_object_notify (G_OBJECT (op), "parent");
1443 }
1444
1445 /**
1446  * gtk_mount_operation_get_parent:
1447  * @op: a #GtkMountOperation
1448  *
1449  * Gets the transient parent used by the #GtkMountOperation
1450  *
1451  * Returns: (transfer none): the transient parent for windows shown by @op
1452  *
1453  * Since: 2.14
1454  */
1455 GtkWindow *
1456 gtk_mount_operation_get_parent (GtkMountOperation *op)
1457 {
1458   g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
1459
1460   return op->priv->parent_window;
1461 }
1462
1463 /**
1464  * gtk_mount_operation_set_screen:
1465  * @op: a #GtkMountOperation
1466  * @screen: a #GdkScreen
1467  *
1468  * Sets the screen to show windows of the #GtkMountOperation on.
1469  *
1470  * Since: 2.14
1471  */
1472 void
1473 gtk_mount_operation_set_screen (GtkMountOperation *op,
1474                                 GdkScreen         *screen)
1475 {
1476   GtkMountOperationPrivate *priv;
1477
1478   g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1479   g_return_if_fail (GDK_IS_SCREEN (screen));
1480
1481   priv = op->priv;
1482
1483   if (priv->screen == screen)
1484     return;
1485
1486   if (priv->screen)
1487     g_object_unref (priv->screen);
1488
1489   priv->screen = g_object_ref (screen);
1490
1491   if (priv->dialog)
1492     gtk_window_set_screen (GTK_WINDOW (priv->dialog), screen);
1493
1494   g_object_notify (G_OBJECT (op), "screen");
1495 }
1496
1497 /**
1498  * gtk_mount_operation_get_screen:
1499  * @op: a #GtkMountOperation
1500  *
1501  * Gets the screen on which windows of the #GtkMountOperation
1502  * will be shown.
1503  *
1504  * Returns: (transfer none): the screen on which windows of @op are shown
1505  *
1506  * Since: 2.14
1507  */
1508 GdkScreen *
1509 gtk_mount_operation_get_screen (GtkMountOperation *op)
1510 {
1511   GtkMountOperationPrivate *priv;
1512
1513   g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
1514
1515   priv = op->priv;
1516
1517   if (priv->dialog)
1518     return gtk_window_get_screen (GTK_WINDOW (priv->dialog));
1519   else if (priv->parent_window)
1520     return gtk_window_get_screen (GTK_WINDOW (priv->parent_window));
1521   else if (priv->screen)
1522     return priv->screen;
1523   else
1524     return gdk_screen_get_default ();
1525 }