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>
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.
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.
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/>.
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/.
30 #include "gtkmountoperationprivate.h"
32 #include "gtkdbusgenerated.h"
37 #include "gtkmessagedialog.h"
38 #include "gtkmountoperation.h"
39 #include "gtkprivate.h"
40 #include "gtkradiobutton.h"
43 #include "gtkwindow.h"
44 #include "gtktreeview.h"
45 #include "gtktreeselection.h"
46 #include "gtkcellrenderertext.h"
47 #include "gtkcellrendererpixbuf.h"
48 #include "gtkscrolledwindow.h"
49 #include "gtkicontheme.h"
50 #include "gtkimagemenuitem.h"
53 #include <glib/gprintf.h>
57 * @short_description: Functions for working with GIO
58 * @Title: Filesystem utilities
60 * The functions and objects described here make working with GTK+ and
61 * GIO more convenient.
63 * #GtkMountOperation is needed when mounting volumes:
64 * It is an implementation of #GMountOperation that can be used with
65 * GIO functions for mounting volumes such as
66 * g_file_mount_enclosing_volume(), g_file_mount_mountable(),
67 * g_volume_mount(), g_mount_unmount_with_operation() and others.
69 * When necessary, #GtkMountOperation shows dialogs to ask for
70 * passwords, questions or show processes blocking unmount.
72 * gtk_show_uri() is a convenient way to launch applications for URIs.
74 * Another object that is worth mentioning in this context is
75 * #GdkAppLaunchContext, which provides visual feedback when lauching
79 static void gtk_mount_operation_finalize (GObject *object);
80 static void gtk_mount_operation_set_property (GObject *object,
84 static void gtk_mount_operation_get_property (GObject *object,
89 static void gtk_mount_operation_ask_password (GMountOperation *op,
91 const char *default_user,
92 const char *default_domain,
93 GAskPasswordFlags flags);
95 static void gtk_mount_operation_ask_question (GMountOperation *op,
97 const char *choices[]);
99 static void gtk_mount_operation_show_processes (GMountOperation *op,
102 const char *choices[]);
104 static void gtk_mount_operation_aborted (GMountOperation *op);
106 G_DEFINE_TYPE (GtkMountOperation, gtk_mount_operation, G_TYPE_MOUNT_OPERATION);
116 struct _GtkMountOperationPrivate {
117 GtkWindow *parent_window;
122 _GtkMountOperationHandler *handler;
123 GCancellable *cancellable;
124 gboolean handler_showing;
126 /* for the ask-password dialog */
128 GtkWidget *username_entry;
129 GtkWidget *domain_entry;
130 GtkWidget *password_entry;
131 GtkWidget *anonymous_toggle;
134 GAskPasswordFlags ask_flags;
135 GPasswordSave password_save;
138 /* for the show-processes dialog */
139 GtkWidget *process_tree_view;
140 GtkListStore *process_list_store;
144 gtk_mount_operation_class_init (GtkMountOperationClass *klass)
146 GObjectClass *object_class = G_OBJECT_CLASS (klass);
147 GMountOperationClass *mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
149 g_type_class_add_private (klass, sizeof (GtkMountOperationPrivate));
151 object_class->finalize = gtk_mount_operation_finalize;
152 object_class->get_property = gtk_mount_operation_get_property;
153 object_class->set_property = gtk_mount_operation_set_property;
155 mount_op_class->ask_password = gtk_mount_operation_ask_password;
156 mount_op_class->ask_question = gtk_mount_operation_ask_question;
157 mount_op_class->show_processes = gtk_mount_operation_show_processes;
158 mount_op_class->aborted = gtk_mount_operation_aborted;
160 g_object_class_install_property (object_class,
162 g_param_spec_object ("parent",
164 P_("The parent window"),
166 GTK_PARAM_READWRITE));
168 g_object_class_install_property (object_class,
170 g_param_spec_boolean ("is-showing",
172 P_("Are we showing a dialog"),
174 GTK_PARAM_READABLE));
176 g_object_class_install_property (object_class,
178 g_param_spec_object ("screen",
180 P_("The screen where this window will be displayed."),
182 GTK_PARAM_READWRITE));
186 gtk_mount_operation_init (GtkMountOperation *operation)
190 operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation,
191 GTK_TYPE_MOUNT_OPERATION,
192 GtkMountOperationPrivate);
194 operation->priv->handler =
195 _gtk_mount_operation_handler_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
196 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
197 "org.gtk.MountOperationHandler",
198 "/org/gtk/MountOperationHandler",
200 name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (operation->priv->handler));
202 g_clear_object (&operation->priv->handler);
205 if (operation->priv->handler)
206 g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (operation->priv->handler), G_MAXINT);
210 gtk_mount_operation_finalize (GObject *object)
212 GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
213 GtkMountOperationPrivate *priv = operation->priv;
215 if (priv->user_widgets)
216 g_list_free (priv->user_widgets);
218 if (priv->parent_window)
219 g_object_unref (priv->parent_window);
222 g_object_unref (priv->screen);
225 g_object_unref (priv->handler);
227 G_OBJECT_CLASS (gtk_mount_operation_parent_class)->finalize (object);
231 gtk_mount_operation_set_property (GObject *object,
236 GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
241 gtk_mount_operation_set_parent (operation, g_value_get_object (value));
245 gtk_mount_operation_set_screen (operation, g_value_get_object (value));
248 case PROP_IS_SHOWING:
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
256 gtk_mount_operation_get_property (GObject *object,
261 GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
262 GtkMountOperationPrivate *priv = operation->priv;
267 g_value_set_object (value, priv->parent_window);
270 case PROP_IS_SHOWING:
271 g_value_set_boolean (value, priv->dialog != NULL || priv->handler_showing);
275 g_value_set_object (value, priv->screen);
279 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
285 gtk_mount_operation_proxy_finish (GtkMountOperation *op,
286 GMountOperationResult result)
288 _gtk_mount_operation_handler_call_close (op->priv->handler, NULL, NULL, NULL);
290 op->priv->handler_showing = FALSE;
291 g_object_notify (G_OBJECT (op), "is-showing");
293 g_mount_operation_reply (G_MOUNT_OPERATION (op), result);
295 /* drop the reference acquired when calling the proxy method */
300 remember_button_toggled (GtkToggleButton *button,
301 GtkMountOperation *operation)
303 GtkMountOperationPrivate *priv = operation->priv;
305 if (gtk_toggle_button_get_active (button))
309 data = g_object_get_data (G_OBJECT (button), "password-save");
310 priv->password_save = GPOINTER_TO_INT (data);
315 pw_dialog_got_response (GtkDialog *dialog,
317 GtkMountOperation *mount_op)
319 GtkMountOperationPrivate *priv = mount_op->priv;
320 GMountOperation *op = G_MOUNT_OPERATION (mount_op);
322 if (response_id == GTK_RESPONSE_OK)
326 if (priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED)
327 g_mount_operation_set_anonymous (op, priv->anonymous);
329 if (priv->username_entry)
331 text = gtk_entry_get_text (GTK_ENTRY (priv->username_entry));
332 g_mount_operation_set_username (op, text);
335 if (priv->domain_entry)
337 text = gtk_entry_get_text (GTK_ENTRY (priv->domain_entry));
338 g_mount_operation_set_domain (op, text);
341 if (priv->password_entry)
343 text = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
344 g_mount_operation_set_password (op, text);
347 if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
348 g_mount_operation_set_password_save (op, priv->password_save);
350 g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
353 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
356 g_object_notify (G_OBJECT (op), "is-showing");
357 gtk_widget_destroy (GTK_WIDGET (dialog));
362 entry_has_input (GtkWidget *entry_widget)
366 if (entry_widget == NULL)
369 text = gtk_entry_get_text (GTK_ENTRY (entry_widget));
371 return text != NULL && text[0] != '\0';
375 pw_dialog_input_is_valid (GtkMountOperation *operation)
377 GtkMountOperationPrivate *priv = operation->priv;
378 gboolean is_valid = TRUE;
380 /* We don't require password to be non-empty here
381 * since there are situations where it is not needed,
383 * We may add a way for the backend to specify that it
384 * definitively needs a password.
386 is_valid = entry_has_input (priv->username_entry) &&
387 entry_has_input (priv->domain_entry);
393 pw_dialog_verify_input (GtkEditable *editable,
394 GtkMountOperation *operation)
396 GtkMountOperationPrivate *priv = operation->priv;
399 is_valid = pw_dialog_input_is_valid (operation);
400 gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
406 pw_dialog_anonymous_toggled (GtkWidget *widget,
407 GtkMountOperation *operation)
409 GtkMountOperationPrivate *priv = operation->priv;
413 priv->anonymous = widget == priv->anonymous_toggle;
418 is_valid = pw_dialog_input_is_valid (operation);
420 for (l = priv->user_widgets; l != NULL; l = l->next)
422 gtk_widget_set_sensitive (GTK_WIDGET (l->data), !priv->anonymous);
425 gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
432 pw_dialog_cycle_focus (GtkWidget *widget,
433 GtkMountOperation *operation)
435 GtkMountOperationPrivate *priv;
436 GtkWidget *next_widget = NULL;
438 priv = operation->priv;
440 if (widget == priv->username_entry)
442 if (priv->domain_entry != NULL)
443 next_widget = priv->domain_entry;
444 else if (priv->password_entry != NULL)
445 next_widget = priv->password_entry;
447 else if (widget == priv->domain_entry && priv->password_entry)
448 next_widget = priv->password_entry;
451 gtk_widget_grab_focus (next_widget);
452 else if (pw_dialog_input_is_valid (operation))
453 gtk_window_activate_default (GTK_WINDOW (priv->dialog));
457 table_add_entry (GtkMountOperation *operation,
459 const char *label_text,
466 label = gtk_label_new_with_mnemonic (label_text);
467 gtk_widget_set_halign (label, GTK_ALIGN_END);
468 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
469 gtk_widget_set_hexpand (label, FALSE);
470 operation->priv->user_widgets = g_list_prepend (operation->priv->user_widgets, label);
472 entry = gtk_entry_new ();
473 gtk_widget_set_hexpand (entry, TRUE);
476 gtk_entry_set_text (GTK_ENTRY (entry), value);
478 gtk_grid_attach (GTK_GRID (operation->priv->grid), label, 0, row, 1, 1);
479 gtk_grid_attach (GTK_GRID (operation->priv->grid), entry, 1, row, 1, 1);
480 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
481 operation->priv->user_widgets = g_list_prepend (operation->priv->user_widgets, entry);
483 g_signal_connect (entry, "changed",
484 G_CALLBACK (pw_dialog_verify_input), user_data);
486 g_signal_connect (entry, "activate",
487 G_CALLBACK (pw_dialog_cycle_focus), user_data);
493 gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
494 const gchar *message,
495 const gchar *default_user,
496 const gchar *default_domain)
498 GtkMountOperationPrivate *priv;
502 GtkWidget *hbox, *main_vbox, *icon;
505 GtkWidget *content_area, *action_area;
506 gboolean can_anonymous;
509 const gchar *secondary;
510 PangoAttrList *attrs;
512 priv = operation->priv;
514 widget = gtk_dialog_new ();
515 dialog = GTK_DIALOG (widget);
516 window = GTK_WINDOW (widget);
518 priv->dialog = dialog;
520 content_area = gtk_dialog_get_content_area (dialog);
521 action_area = gtk_dialog_get_action_area (dialog);
523 /* Set the dialog up with HIG properties */
524 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
525 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
526 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
527 gtk_box_set_spacing (GTK_BOX (action_area), 6);
529 gtk_window_set_resizable (window, FALSE);
530 gtk_window_set_title (window, "");
531 gtk_window_set_icon_name (window, GTK_STOCK_DIALOG_AUTHENTICATION);
533 gtk_dialog_add_buttons (dialog,
534 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
535 _("Co_nnect"), GTK_RESPONSE_OK,
537 gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
539 gtk_dialog_set_alternative_button_order (dialog,
545 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
546 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
547 gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
549 icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
550 GTK_ICON_SIZE_DIALOG);
552 gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
553 gtk_widget_set_valign (icon, GTK_ALIGN_START);
554 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
556 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
557 gtk_box_pack_start (GTK_BOX (hbox), main_vbox, TRUE, TRUE, 0);
559 secondary = strstr (message, "\n");
560 if (secondary != NULL)
562 primary = g_strndup (message, secondary - message + 1);
566 primary = g_strdup (message);
569 label = gtk_label_new (primary);
570 gtk_widget_set_halign (label, GTK_ALIGN_START);
571 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
572 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
573 gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (label),
576 attrs = pango_attr_list_new ();
577 pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
578 gtk_label_set_attributes (GTK_LABEL (label), attrs);
579 pango_attr_list_unref (attrs);
581 if (secondary != NULL)
583 label = gtk_label_new (secondary);
584 gtk_widget_set_halign (label, GTK_ALIGN_START);
585 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
586 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
587 gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (label),
591 grid = gtk_grid_new ();
592 operation->priv->grid = grid;
593 gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
594 gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
595 gtk_widget_set_margin_bottom (grid, 12);
596 gtk_box_pack_start (GTK_BOX (main_vbox), grid, FALSE, FALSE, 0);
598 can_anonymous = priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
602 priv->anonymous_toggle = NULL;
609 label = gtk_label_new (_("Connect As"));
610 gtk_widget_set_halign (label, GTK_ALIGN_END);
611 gtk_widget_set_valign (label, GTK_ALIGN_START);
612 gtk_widget_set_hexpand (label, FALSE);
613 gtk_grid_attach (GTK_GRID (grid), label, 0, rows, 1, 1);
615 anon_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
616 gtk_grid_attach (GTK_GRID (grid), anon_box, 1, rows++, 1, 1);
618 choice = gtk_radio_button_new_with_mnemonic (NULL, _("_Anonymous"));
619 gtk_box_pack_start (GTK_BOX (anon_box),
622 g_signal_connect (choice, "toggled",
623 G_CALLBACK (pw_dialog_anonymous_toggled), operation);
624 priv->anonymous_toggle = choice;
626 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
627 choice = gtk_radio_button_new_with_mnemonic (group, _("Registered U_ser"));
628 gtk_box_pack_start (GTK_BOX (anon_box),
631 g_signal_connect (choice, "toggled",
632 G_CALLBACK (pw_dialog_anonymous_toggled), operation);
635 priv->username_entry = NULL;
637 if (priv->ask_flags & G_ASK_PASSWORD_NEED_USERNAME)
638 priv->username_entry = table_add_entry (operation, rows++, _("_Username"),
639 default_user, operation);
641 priv->domain_entry = NULL;
642 if (priv->ask_flags & G_ASK_PASSWORD_NEED_DOMAIN)
643 priv->domain_entry = table_add_entry (operation, rows++, _("_Domain"),
644 default_domain, operation);
646 priv->password_entry = NULL;
647 if (priv->ask_flags & G_ASK_PASSWORD_NEED_PASSWORD)
649 priv->password_entry = table_add_entry (operation, rows++, _("_Password"),
651 gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE);
654 if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
656 GtkWidget *remember_box;
659 GPasswordSave password_save;
661 remember_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
662 gtk_grid_attach (GTK_GRID (grid), remember_box, 0, rows++, 2, 1);
663 priv->user_widgets = g_list_prepend (priv->user_widgets, remember_box);
665 label = gtk_label_new ("");
666 gtk_container_add (GTK_CONTAINER (remember_box), label);
668 password_save = g_mount_operation_get_password_save (G_MOUNT_OPERATION (operation));
669 priv->password_save = password_save;
671 choice = gtk_radio_button_new_with_mnemonic (NULL, _("Forget password _immediately"));
672 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
673 password_save == G_PASSWORD_SAVE_NEVER);
674 g_object_set_data (G_OBJECT (choice), "password-save",
675 GINT_TO_POINTER (G_PASSWORD_SAVE_NEVER));
676 g_signal_connect (choice, "toggled",
677 G_CALLBACK (remember_button_toggled), operation);
678 gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
680 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
681 choice = gtk_radio_button_new_with_mnemonic (group, _("Remember password until you _logout"));
682 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
683 password_save == G_PASSWORD_SAVE_FOR_SESSION);
684 g_object_set_data (G_OBJECT (choice), "password-save",
685 GINT_TO_POINTER (G_PASSWORD_SAVE_FOR_SESSION));
686 g_signal_connect (choice, "toggled",
687 G_CALLBACK (remember_button_toggled), operation);
688 gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
690 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
691 choice = gtk_radio_button_new_with_mnemonic (group, _("Remember _forever"));
692 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
693 password_save == G_PASSWORD_SAVE_PERMANENTLY);
694 g_object_set_data (G_OBJECT (choice), "password-save",
695 GINT_TO_POINTER (G_PASSWORD_SAVE_PERMANENTLY));
696 g_signal_connect (choice, "toggled",
697 G_CALLBACK (remember_button_toggled), operation);
698 gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
701 g_signal_connect (G_OBJECT (dialog), "response",
702 G_CALLBACK (pw_dialog_got_response), operation);
706 /* The anonymous option will be active by default,
707 * ensure the toggled signal is emitted for it.
709 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (priv->anonymous_toggle));
711 else if (! pw_dialog_input_is_valid (operation))
712 gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, FALSE);
714 g_object_notify (G_OBJECT (operation), "is-showing");
716 if (priv->parent_window)
718 gtk_window_set_transient_for (window, priv->parent_window);
719 gtk_window_set_modal (window, TRUE);
721 else if (priv->screen)
722 gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
724 gtk_widget_show_all (GTK_WIDGET (dialog));
726 g_object_ref (operation);
730 call_password_proxy_cb (GObject *source,
734 _GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
735 GMountOperation *op = user_data;
736 GMountOperationResult result;
737 GVariant *result_details;
741 GError *error = NULL;
743 if (!_gtk_mount_operation_handler_call_ask_password_finish (proxy,
749 result = G_MOUNT_OPERATION_ABORTED;
750 g_warning ("Shell mount operation error: %s\n", error->message);
751 g_error_free (error);
755 g_variant_iter_init (&iter, result_details);
756 while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
758 if (strcmp (key, "password") == 0)
759 g_mount_operation_set_password (op, g_variant_get_string (value, NULL));
760 else if (strcmp (key, "password_save") == 0)
761 g_mount_operation_set_password_save (op, g_variant_get_uint32 (value));
765 gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
769 gtk_mount_operation_ask_password_do_proxy (GtkMountOperation *operation,
771 const char *default_user,
772 const char *default_domain)
775 g_sprintf(id, "GtkMountOperation%p", operation);
777 operation->priv->handler_showing = TRUE;
778 g_object_notify (G_OBJECT (operation), "is-showing");
780 /* keep a ref to the operation while the handler is showing */
781 g_object_ref (operation);
783 _gtk_mount_operation_handler_call_ask_password (operation->priv->handler, id,
784 message, "drive-harddisk",
785 default_user, default_domain,
786 operation->priv->ask_flags, NULL,
787 call_password_proxy_cb, operation);
791 gtk_mount_operation_ask_password (GMountOperation *mount_op,
793 const char *default_user,
794 const char *default_domain,
795 GAskPasswordFlags flags)
797 GtkMountOperation *operation;
798 GtkMountOperationPrivate *priv;
801 operation = GTK_MOUNT_OPERATION (mount_op);
802 priv = operation->priv;
803 priv->ask_flags = flags;
805 use_gtk = (operation->priv->handler == NULL) ||
806 (priv->ask_flags & G_ASK_PASSWORD_NEED_DOMAIN) ||
807 (priv->ask_flags & G_ASK_PASSWORD_NEED_USERNAME);
810 gtk_mount_operation_ask_password_do_gtk (operation, message, default_user, default_domain);
812 gtk_mount_operation_ask_password_do_proxy (operation, message, default_user, default_domain);
816 question_dialog_button_clicked (GtkDialog *dialog,
820 GtkMountOperationPrivate *priv;
821 GtkMountOperation *operation;
823 operation = GTK_MOUNT_OPERATION (op);
824 priv = operation->priv;
826 if (button_number >= 0)
828 g_mount_operation_set_choice (op, button_number);
829 g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
832 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
835 g_object_notify (G_OBJECT (operation), "is-showing");
836 gtk_widget_destroy (GTK_WIDGET (dialog));
841 gtk_mount_operation_ask_question_do_gtk (GtkMountOperation *op,
843 const char *choices[])
845 GtkMountOperationPrivate *priv;
847 const char *secondary = NULL;
851 g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
852 g_return_if_fail (message != NULL);
853 g_return_if_fail (choices != NULL);
857 primary = strstr (message, "\n");
860 secondary = primary + 1;
861 primary = g_strndup (message, primary - message);
864 dialog = gtk_message_dialog_new (priv->parent_window, 0,
865 GTK_MESSAGE_QUESTION,
866 GTK_BUTTONS_NONE, "%s",
867 primary != NULL ? primary : message);
871 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
874 /* First count the items in the list then
875 * add the buttons in reverse order */
877 while (choices[len] != NULL)
880 for (count = len - 1; count >= 0; count--)
881 gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
883 g_signal_connect (G_OBJECT (dialog), "response",
884 G_CALLBACK (question_dialog_button_clicked), op);
886 priv->dialog = GTK_DIALOG (dialog);
887 g_object_notify (G_OBJECT (op), "is-showing");
889 if (priv->parent_window == NULL && priv->screen)
890 gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
892 gtk_widget_show (dialog);
897 call_question_proxy_cb (GObject *source,
901 _GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
902 GMountOperation *op = user_data;
903 GMountOperationResult result;
904 GVariant *result_details;
908 GError *error = NULL;
910 if (!_gtk_mount_operation_handler_call_ask_question_finish (proxy,
916 result = G_MOUNT_OPERATION_ABORTED;
917 g_warning ("Shell mount operation error: %s\n", error->message);
918 g_error_free (error);
922 g_variant_iter_init (&iter, result_details);
923 while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
925 if (strcmp (key, "choice") == 0)
926 g_mount_operation_set_choice (op, g_variant_get_int32 (value));
930 gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
934 gtk_mount_operation_ask_question_do_proxy (GtkMountOperation *operation,
936 const char *choices[])
939 g_sprintf(id, "GtkMountOperation%p", operation);
941 operation->priv->handler_showing = TRUE;
942 g_object_notify (G_OBJECT (operation), "is-showing");
944 /* keep a ref to the operation while the handler is showing */
945 g_object_ref (operation);
947 _gtk_mount_operation_handler_call_ask_question (operation->priv->handler, id,
948 message, "drive-harddisk",
950 call_question_proxy_cb, operation);
954 gtk_mount_operation_ask_question (GMountOperation *op,
956 const char *choices[])
958 GtkMountOperation *operation;
961 operation = GTK_MOUNT_OPERATION (op);
962 use_gtk = (operation->priv->handler == NULL);
965 gtk_mount_operation_ask_question_do_gtk (operation, message, choices);
967 gtk_mount_operation_ask_question_do_proxy (operation, message, choices);
971 show_processes_button_clicked (GtkDialog *dialog,
975 GtkMountOperationPrivate *priv;
976 GtkMountOperation *operation;
978 operation = GTK_MOUNT_OPERATION (op);
979 priv = operation->priv;
981 if (button_number >= 0)
983 g_mount_operation_set_choice (op, button_number);
984 g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
987 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
990 g_object_notify (G_OBJECT (operation), "is-showing");
991 gtk_widget_destroy (GTK_WIDGET (dialog));
996 pid_equal (gconstpointer a,
1004 return GPOINTER_TO_INT(pb) - GPOINTER_TO_INT(pa);
1008 diff_sorted_arrays (GArray *array1,
1010 GCompareFunc compare,
1011 GArray *added_indices,
1012 GArray *removed_indices)
1020 elem_size = g_array_get_element_size (array1);
1021 g_assert (elem_size == g_array_get_element_size (array2));
1023 while (n1 < array1->len && n2 < array2->len)
1025 order = (*compare) (((const char*) array1->data) + n1 * elem_size,
1026 ((const char*) array2->data) + n2 * elem_size);
1029 g_array_append_val (removed_indices, n1);
1034 g_array_append_val (added_indices, n2);
1044 while (n1 < array1->len)
1046 g_array_append_val (removed_indices, n1);
1049 while (n2 < array2->len)
1051 g_array_append_val (added_indices, n2);
1058 add_pid_to_process_list_store (GtkMountOperation *mount_operation,
1059 GtkMountOperationLookupContext *lookup_context,
1060 GtkListStore *list_store,
1063 gchar *command_line;
1071 command_line = NULL;
1072 _gtk_mount_operation_lookup_info (lookup_context,
1080 name = g_strdup_printf (_("Unknown Application (PID %d)"), pid);
1082 if (command_line == NULL)
1083 command_line = g_strdup ("");
1087 GtkIconTheme *theme;
1088 theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (mount_operation->priv->dialog)));
1089 pixbuf = gtk_icon_theme_load_icon (theme,
1090 "application-x-executable",
1096 markup = g_strdup_printf ("<b>%s</b>\n"
1097 "<small>%s</small>",
1101 gtk_list_store_append (list_store, &iter);
1102 gtk_list_store_set (list_store, &iter,
1109 g_object_unref (pixbuf);
1112 g_free (command_line);
1116 remove_pid_from_process_list_store (GtkMountOperation *mount_operation,
1117 GtkListStore *list_store,
1123 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
1127 gtk_tree_model_get (GTK_TREE_MODEL (list_store),
1132 if (pid_of_item == pid)
1134 gtk_list_store_remove (list_store, &iter);
1138 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
1144 update_process_list_store (GtkMountOperation *mount_operation,
1145 GtkListStore *list_store,
1149 GtkMountOperationLookupContext *lookup_context;
1150 GArray *current_pids;
1151 GArray *pid_indices_to_add;
1152 GArray *pid_indices_to_remove;
1156 /* Just removing all items and adding new ones will screw up the
1157 * focus handling in the treeview - so compute the delta, and add/remove
1158 * items as appropriate
1160 current_pids = g_array_new (FALSE, FALSE, sizeof (GPid));
1161 pid_indices_to_add = g_array_new (FALSE, FALSE, sizeof (gint));
1162 pid_indices_to_remove = g_array_new (FALSE, FALSE, sizeof (gint));
1164 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
1168 gtk_tree_model_get (GTK_TREE_MODEL (list_store),
1173 g_array_append_val (current_pids, pid);
1175 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
1178 g_array_sort (current_pids, pid_equal);
1179 g_array_sort (processes, pid_equal);
1181 diff_sorted_arrays (current_pids, processes, pid_equal, pid_indices_to_add, pid_indices_to_remove);
1183 for (n = 0; n < pid_indices_to_remove->len; n++)
1185 pid = g_array_index (current_pids, GPid, n);
1186 remove_pid_from_process_list_store (mount_operation, list_store, pid);
1189 if (pid_indices_to_add->len > 0)
1191 lookup_context = _gtk_mount_operation_lookup_context_get (gtk_widget_get_display (mount_operation->priv->process_tree_view));
1192 for (n = 0; n < pid_indices_to_add->len; n++)
1194 pid = g_array_index (processes, GPid, n);
1195 add_pid_to_process_list_store (mount_operation, lookup_context, list_store, pid);
1197 _gtk_mount_operation_lookup_context_free (lookup_context);
1200 /* select the first item, if we went from a zero to a non-zero amount of processes */
1201 if (current_pids->len == 0 && pid_indices_to_add->len > 0)
1203 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
1205 GtkTreeSelection *tree_selection;
1206 tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (mount_operation->priv->process_tree_view));
1207 gtk_tree_selection_select_iter (tree_selection, &iter);
1211 g_array_unref (current_pids);
1212 g_array_unref (pid_indices_to_add);
1213 g_array_unref (pid_indices_to_remove);
1217 on_end_process_activated (GtkMenuItem *item,
1220 GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1221 GtkTreeSelection *selection;
1226 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
1228 if (!gtk_tree_selection_get_selected (selection,
1233 gtk_tree_model_get (GTK_TREE_MODEL (op->priv->process_list_store),
1238 /* TODO: We might want to either
1240 * - Be smart about things and send SIGKILL rather than SIGTERM if
1241 * this is the second time the user requests killing a process
1243 * - Or, easier (but worse user experience), offer both "End Process"
1244 * and "Terminate Process" options
1246 * But that's not how things work right now....
1249 if (!_gtk_mount_operation_kill_process (pid_to_kill, &error))
1254 /* Use GTK_DIALOG_DESTROY_WITH_PARENT here since the parent dialog can be
1255 * indeed be destroyed via the GMountOperation::abort signal... for example,
1256 * this is triggered if the user yanks the device while we are showing
1259 dialog = gtk_message_dialog_new (GTK_WINDOW (op->priv->dialog),
1260 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1263 _("Unable to end process"));
1264 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1268 gtk_widget_show_all (dialog);
1269 response = gtk_dialog_run (GTK_DIALOG (dialog));
1271 /* GTK_RESPONSE_NONE means the dialog were programmatically destroy, e.g. that
1272 * GTK_DIALOG_DESTROY_WITH_PARENT kicked in - so it would trigger a warning to
1273 * destroy the dialog in that case
1275 if (response != GTK_RESPONSE_NONE)
1276 gtk_widget_destroy (dialog);
1278 g_error_free (error);
1286 do_popup_menu_for_process_tree_view (GtkWidget *widget,
1287 GdkEventButton *event,
1288 GtkMountOperation *op)
1294 gboolean popped_up_menu;
1296 popped_up_menu = FALSE;
1298 menu = gtk_menu_new ();
1300 item = gtk_image_menu_item_new_with_mnemonic (_("_End Process"));
1301 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1302 gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
1303 g_signal_connect (item, "activate",
1304 G_CALLBACK (on_end_process_activated),
1306 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1307 gtk_widget_show_all (menu);
1312 GtkTreeSelection *selection;
1314 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (op->priv->process_tree_view),
1322 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
1323 gtk_tree_selection_select_path (selection, path);
1324 gtk_tree_path_free (path);
1328 /* don't popup a menu if the user right-clicked in an area with no rows */
1332 button = event->button;
1333 event_time = event->time;
1338 event_time = gtk_get_current_event_time ();
1341 gtk_menu_popup (GTK_MENU (menu),
1349 popped_up_menu = TRUE;
1352 return popped_up_menu;
1356 on_popup_menu_for_process_tree_view (GtkWidget *widget,
1359 GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1360 return do_popup_menu_for_process_tree_view (widget, NULL, op);
1364 on_button_press_event_for_process_tree_view (GtkWidget *widget,
1365 GdkEventButton *event,
1368 GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
1373 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
1375 ret = do_popup_menu_for_process_tree_view (widget, event, op);
1382 create_show_processes_dialog (GtkMountOperation *op,
1383 const char *message,
1384 const char *choices[])
1386 GtkMountOperationPrivate *priv;
1388 const char *secondary = NULL;
1392 GtkWidget *tree_view;
1393 GtkWidget *scrolled_window;
1395 GtkWidget *content_area;
1396 GtkTreeViewColumn *column;
1397 GtkCellRenderer *renderer;
1398 GtkListStore *list_store;
1403 primary = strstr (message, "\n");
1406 secondary = primary + 1;
1407 primary = g_strndup (message, primary - message);
1410 dialog = gtk_dialog_new ();
1412 if (priv->parent_window != NULL)
1413 gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->parent_window);
1414 gtk_window_set_title (GTK_WINDOW (dialog), "");
1416 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1417 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
1418 gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
1419 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
1421 if (secondary != NULL)
1423 s = g_strdup_printf ("<big><b>%s</b></big>\n\n%s", primary, secondary);
1427 s = g_strdup_printf ("%s", primary);
1430 label = gtk_label_new (NULL);
1431 gtk_label_set_markup (GTK_LABEL (label), s);
1433 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1435 /* First count the items in the list then
1436 * add the buttons in reverse order */
1438 while (choices[len] != NULL)
1441 for (count = len - 1; count >= 0; count--)
1442 gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
1444 g_signal_connect (G_OBJECT (dialog), "response",
1445 G_CALLBACK (show_processes_button_clicked), op);
1447 priv->dialog = GTK_DIALOG (dialog);
1448 g_object_notify (G_OBJECT (op), "is-showing");
1450 if (priv->parent_window == NULL && priv->screen)
1451 gtk_window_set_screen (GTK_WINDOW (dialog), priv->screen);
1453 tree_view = gtk_tree_view_new ();
1454 /* TODO: should use EM's when gtk+ RI patches land */
1455 gtk_widget_set_size_request (tree_view,
1459 column = gtk_tree_view_column_new ();
1460 renderer = gtk_cell_renderer_pixbuf_new ();
1461 gtk_tree_view_column_pack_start (column, renderer, FALSE);
1462 gtk_tree_view_column_set_attributes (column, renderer,
1465 renderer = gtk_cell_renderer_text_new ();
1466 g_object_set (renderer,
1467 "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
1468 "ellipsize-set", TRUE,
1470 gtk_tree_view_column_pack_start (column, renderer, TRUE);
1471 gtk_tree_view_column_set_attributes (column, renderer,
1474 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
1475 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
1478 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1479 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1481 GTK_POLICY_AUTOMATIC);
1482 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
1484 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
1485 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
1487 g_signal_connect (tree_view, "popup-menu",
1488 G_CALLBACK (on_popup_menu_for_process_tree_view),
1490 g_signal_connect (tree_view, "button-press-event",
1491 G_CALLBACK (on_button_press_event_for_process_tree_view),
1494 list_store = gtk_list_store_new (3,
1499 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store));
1501 priv->process_list_store = list_store;
1502 priv->process_tree_view = tree_view;
1503 /* set pointers to NULL when dialog goes away */
1504 g_object_add_weak_pointer (G_OBJECT (list_store), (gpointer *) &priv->process_list_store);
1505 g_object_add_weak_pointer (G_OBJECT (tree_view), (gpointer *) &priv->process_tree_view);
1507 g_object_unref (list_store);
1514 call_processes_proxy_cb (GObject *source,
1518 _GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
1519 GMountOperation *op = user_data;
1520 GMountOperationResult result;
1521 GVariant *result_details;
1525 GError *error = NULL;
1527 if (!_gtk_mount_operation_handler_call_show_processes_finish (proxy,
1533 result = G_MOUNT_OPERATION_ABORTED;
1534 g_warning ("Shell mount operation error: %s\n", error->message);
1535 g_error_free (error);
1539 /* If the request was unhandled it means we called the method again;
1540 * in this case, just return and wait for the next response.
1542 if (result == G_MOUNT_OPERATION_UNHANDLED)
1545 g_variant_iter_init (&iter, result_details);
1546 while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
1548 if (strcmp (key, "choice") == 0)
1549 g_mount_operation_set_choice (op, g_variant_get_int32 (value));
1553 gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
1557 gtk_mount_operation_show_processes_do_proxy (GtkMountOperation *operation,
1558 const char *message,
1560 const char *choices[])
1563 g_sprintf(id, "GtkMountOperation%p", operation);
1565 operation->priv->handler_showing = TRUE;
1566 g_object_notify (G_OBJECT (operation), "is-showing");
1568 /* keep a ref to the operation while the handler is showing */
1569 g_object_ref (operation);
1571 _gtk_mount_operation_handler_call_show_processes (operation->priv->handler, id,
1572 message, "drive-harddisk",
1573 g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
1574 processes->data, processes->len,
1577 call_processes_proxy_cb, operation);
1581 gtk_mount_operation_show_processes_do_gtk (GtkMountOperation *op,
1582 const char *message,
1584 const char *choices[])
1586 GtkMountOperationPrivate *priv;
1587 GtkWidget *dialog = NULL;
1589 g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1590 g_return_if_fail (message != NULL);
1591 g_return_if_fail (processes != NULL);
1592 g_return_if_fail (choices != NULL);
1596 if (priv->process_list_store == NULL)
1598 /* need to create the dialog */
1599 dialog = create_show_processes_dialog (op, message, choices);
1602 /* otherwise, we're showing the dialog, assume messages+choices hasn't changed */
1604 update_process_list_store (op,
1605 priv->process_list_store,
1610 gtk_widget_show_all (dialog);
1616 gtk_mount_operation_show_processes (GMountOperation *op,
1617 const char *message,
1619 const char *choices[])
1622 GtkMountOperation *operation;
1625 operation = GTK_MOUNT_OPERATION (op);
1626 use_gtk = (operation->priv->handler == NULL);
1629 gtk_mount_operation_show_processes_do_gtk (operation, message, processes, choices);
1631 gtk_mount_operation_show_processes_do_proxy (operation, message, processes, choices);
1635 gtk_mount_operation_aborted (GMountOperation *op)
1637 GtkMountOperationPrivate *priv;
1639 priv = GTK_MOUNT_OPERATION (op)->priv;
1641 if (priv->dialog != NULL)
1643 gtk_widget_destroy (GTK_WIDGET (priv->dialog));
1644 priv->dialog = NULL;
1645 g_object_notify (G_OBJECT (op), "is-showing");
1646 g_object_unref (op);
1649 if (priv->handler != NULL)
1651 _gtk_mount_operation_handler_call_close (priv->handler, NULL, NULL, NULL);
1653 priv->handler_showing = FALSE;
1654 g_object_notify (G_OBJECT (op), "is-showing");
1659 * gtk_mount_operation_new:
1660 * @parent: (allow-none): transient parent of the window, or %NULL
1662 * Creates a new #GtkMountOperation
1664 * Returns: a new #GtkMountOperation
1669 gtk_mount_operation_new (GtkWindow *parent)
1671 GMountOperation *mount_operation;
1673 mount_operation = g_object_new (GTK_TYPE_MOUNT_OPERATION,
1674 "parent", parent, NULL);
1676 return mount_operation;
1680 * gtk_mount_operation_is_showing:
1681 * @op: a #GtkMountOperation
1683 * Returns whether the #GtkMountOperation is currently displaying
1686 * Returns: %TRUE if @op is currently displaying a window
1691 gtk_mount_operation_is_showing (GtkMountOperation *op)
1693 g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), FALSE);
1695 return op->priv->dialog != NULL;
1699 * gtk_mount_operation_set_parent:
1700 * @op: a #GtkMountOperation
1701 * @parent: (allow-none): transient parent of the window, or %NULL
1703 * Sets the transient parent for windows shown by the
1704 * #GtkMountOperation.
1709 gtk_mount_operation_set_parent (GtkMountOperation *op,
1712 GtkMountOperationPrivate *priv;
1714 g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1715 g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
1719 if (priv->parent_window == parent)
1722 if (priv->parent_window)
1724 g_signal_handlers_disconnect_by_func (priv->parent_window,
1725 gtk_widget_destroyed,
1726 &priv->parent_window);
1727 priv->parent_window = NULL;
1732 priv->parent_window = g_object_ref (parent);
1734 g_signal_connect (parent, "destroy",
1735 G_CALLBACK (gtk_widget_destroyed),
1736 &priv->parent_window);
1739 gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), parent);
1742 g_object_notify (G_OBJECT (op), "parent");
1746 * gtk_mount_operation_get_parent:
1747 * @op: a #GtkMountOperation
1749 * Gets the transient parent used by the #GtkMountOperation
1751 * Returns: (transfer none): the transient parent for windows shown by @op
1756 gtk_mount_operation_get_parent (GtkMountOperation *op)
1758 g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
1760 return op->priv->parent_window;
1764 * gtk_mount_operation_set_screen:
1765 * @op: a #GtkMountOperation
1766 * @screen: a #GdkScreen
1768 * Sets the screen to show windows of the #GtkMountOperation on.
1773 gtk_mount_operation_set_screen (GtkMountOperation *op,
1776 GtkMountOperationPrivate *priv;
1778 g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
1779 g_return_if_fail (GDK_IS_SCREEN (screen));
1783 if (priv->screen == screen)
1787 g_object_unref (priv->screen);
1789 priv->screen = g_object_ref (screen);
1792 gtk_window_set_screen (GTK_WINDOW (priv->dialog), screen);
1794 g_object_notify (G_OBJECT (op), "screen");
1798 * gtk_mount_operation_get_screen:
1799 * @op: a #GtkMountOperation
1801 * Gets the screen on which windows of the #GtkMountOperation
1804 * Returns: (transfer none): the screen on which windows of @op are shown
1809 gtk_mount_operation_get_screen (GtkMountOperation *op)
1811 GtkMountOperationPrivate *priv;
1813 g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
1818 return gtk_window_get_screen (GTK_WINDOW (priv->dialog));
1819 else if (priv->parent_window)
1820 return gtk_window_get_screen (GTK_WINDOW (priv->parent_window));
1821 else if (priv->screen)
1822 return priv->screen;
1824 return gdk_screen_get_default ();