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