1 # Description: Use an alert window for flushing instead of notifications. Ubuntu's notify-osd does not support infinite timeouts, thus we cannot use notifications.
2 # Ubuntu: https://launchpad.net/bugs/332600
3 --- gnome-mount-0.8/src/gnome-mount.c 2009-03-17 12:18:21.320203571 +0100
4 +++ gnome-mount-0.8.new/src/gnome-mount.c 2009-03-17 12:37:13.208201193 +0100
5 @@ -1583,16 +1583,115 @@
7 static guint unmount_cache_timeout_id = -1;
9 -static NotifyNotification *unmount_note = NULL;
10 +static GtkWidget *unmount_flush_window = NULL;
11 +static GtkWidget *unmount_flush_label_top = NULL;
12 +static GtkWidget *unmount_flush_label_bottom = NULL;
13 +static GtkWidget *unmount_flush_progress = NULL;
15 static gboolean unmount_note_is_eject = FALSE;
16 static char *unmount_note_drive_name = NULL;
19 +unmount_cache_progress_func (gpointer data)
21 + if (!GTK_WIDGET_VISIBLE (unmount_flush_progress))
24 + gtk_progress_bar_pulse (unmount_flush_progress);
25 + g_main_context_iteration (NULL, FALSE);
30 -unmount_note_close_func (NotifyNotification *note, gpointer user_data)
31 +create_unmount_flush_window ()
33 - g_debug ("in unmount_note_close_func()");
34 - unmount_note = NULL;
35 + GtkWidget *vbox1, *vbox2;
38 + gint win_width, win_height;
40 + unmount_flush_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
41 + gtk_window_set_title (GTK_WINDOW (unmount_flush_window), unmount_note_drive_name);
42 + gtk_window_set_resizable (GTK_WINDOW (unmount_flush_window), FALSE);
43 + gtk_window_set_focus_on_map (GTK_WINDOW (unmount_flush_window), FALSE);
44 + gtk_window_set_icon_name (GTK_WINDOW (unmount_flush_window), "gnome-dev-harddisk");
46 + gtk_window_set_position (GTK_WINDOW (unmount_flush_window), GTK_WIN_POS_CENTER_ALWAYS);
47 + /* alternate implementation: make window appear in the lower right corner */
49 + gtk_window_set_gravity (GTK_WINDOW (unmount_flush_window), GDK_GRAVITY_SOUTH_EAST);
50 + gtk_window_move (GTK_WINDOW (unmount_flush_window),
51 + gdk_screen_width(), gdk_screen_height());
54 + vbox1 = gtk_vbox_new (FALSE, 0);
55 + gtk_container_add (GTK_CONTAINER (unmount_flush_window), vbox1);
57 + table1 = gtk_table_new (2, 3, FALSE);
58 + gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, FALSE, 0);
59 + gtk_container_set_border_width (GTK_CONTAINER (table1), 12);
61 + vbox2 = gtk_vbox_new (FALSE, 0);
62 + gtk_table_attach (GTK_TABLE (table1), vbox2, 2, 3, 0, 1,
63 + (GtkAttachOptions) (GTK_FILL),
64 + (GtkAttachOptions) (GTK_FILL), 0, 0);
66 + unmount_flush_label_top = gtk_label_new (_("Writing data to device"));
67 + gtk_label_set_line_wrap (GTK_LABEL (unmount_flush_label_top), TRUE);
68 + gtk_box_pack_start (GTK_BOX (vbox2), unmount_flush_label_top, FALSE, FALSE, 0);
69 + gtk_misc_set_alignment (GTK_MISC (unmount_flush_label_top), 0, 0);
71 + unmount_flush_progress = gtk_progress_bar_new ();
72 + gtk_box_pack_start (GTK_BOX (vbox2), unmount_flush_progress, FALSE, FALSE, 6);
74 + unmount_flush_label_bottom = gtk_label_new (_("To prevent data loss, wait until this has finished before disconnecting."));
75 + gtk_table_attach (GTK_TABLE (table1), unmount_flush_label_bottom, 2, 3, 1, 2,
76 + (GtkAttachOptions) (GTK_FILL),
77 + (GtkAttachOptions) (0), 0, 0);
78 + gtk_label_set_line_wrap (GTK_LABEL (unmount_flush_label_bottom), TRUE);
79 + gtk_misc_set_alignment (GTK_MISC (unmount_flush_label_bottom), 0, 0.5);
80 + gtk_label_set_width_chars (GTK_LABEL (unmount_flush_label_bottom), 40);
82 + icon = gtk_image_new_from_icon_name ("gnome-dev-harddisk", /* TODO: use appropriate icon */
83 + GTK_ICON_SIZE_DIALOG);
85 + gtk_table_attach (GTK_TABLE (table1), icon, 0, 1, 0, 1,
86 + (GtkAttachOptions) (0),
87 + (GtkAttachOptions) (0), 0, 0);
88 + gtk_misc_set_alignment (GTK_MISC (icon), 0, 0.5);
89 + gtk_misc_set_padding (GTK_MISC (icon), 12, 12);
91 + gtk_widget_show_all (unmount_flush_window);
92 + /* do not show a close button; gtk_window_set_deletable() doesn't work at least under compiz :-( */
93 + gdk_window_set_functions (unmount_flush_window->window, GDK_FUNC_MOVE|GDK_FUNC_MINIMIZE);
95 + /* prevent window from being auto-resized in finish_unmount_flush_window() */
96 + gtk_window_get_size (GTK_WINDOW (unmount_flush_window), &win_width, &win_height);
97 + gtk_widget_set_size_request (unmount_flush_window, win_width, win_height);
98 + gtk_window_resize (GTK_WINDOW (unmount_flush_window), win_width, win_height);
100 + /* timer for updating progress bar */
101 + g_timeout_add (100, unmount_cache_progress_func, NULL);
105 +finish_unmount_flush_window ()
110 + message = g_strdup_printf (_("The device %s is now safe to remove."),
111 + unmount_note_drive_name);
112 + gtk_label_set_text(unmount_flush_label_top, message);
113 + gtk_widget_hide (unmount_flush_label_bottom);
114 + gtk_widget_hide (unmount_flush_progress);
116 + /* wait 4 seconds, then hide the dialog */
117 + for (delay = 40; delay; --delay) {
118 + g_main_context_iteration (NULL, FALSE);
121 + gtk_widget_hide(unmount_flush_window);
125 @@ -1600,31 +1699,9 @@
127 char *drive_name = data;
129 -#ifdef ENABLE_NOTIFY
134 + create_unmount_flush_window();
136 - g_debug ("putting up Flushing Cache notification");
138 - summary = _("Writing data to device");
139 - message = g_strdup_printf (_("There is data that needs to be written to the device %s before it can be removed. Please do not remove the media or disconnect the drive."), unmount_note_drive_name);
140 - unmount_note = notify_notification_new (summary,
142 - "gnome-dev-harddisk", /* TODO: use appropriate icon */
144 - if (unmount_note == NULL) {
145 - g_warning ("Cannot create note for unmount cache sync");
147 - notify_notification_set_timeout (unmount_note, NOTIFY_EXPIRES_NEVER);
148 - g_signal_connect (unmount_note, "closed", G_CALLBACK (unmount_note_close_func), NULL);
149 - notify_notification_show (unmount_note, NULL);
159 @@ -1636,30 +1713,19 @@
160 g_strchug (unmount_note_drive_name);
161 g_debug ("Setting up 750ms timer for Flushing Cache dialog");
162 unmount_cache_timeout_id = g_timeout_add (750, unmount_cache_timeout_func, NULL);
163 - unmount_note = NULL;
167 unmount_cache_timeout_cancel (gboolean was_success)
169 g_source_remove (unmount_cache_timeout_id);
170 - if (unmount_note != NULL) {
171 + if (unmount_flush_window != NULL) {
176 g_debug ("Updating Flushing Cache notification");
178 - summary = _("Device is now safe to remove");
179 - message = g_strdup_printf (_("The device %s is now safe to remove."),
180 - unmount_note_drive_name);
181 - notify_notification_update (unmount_note,
184 - "gnome-dev-harddisk"); /* TODO: use appropriate icon */
186 - notify_notification_set_timeout (unmount_note, NOTIFY_EXPIRES_DEFAULT);
187 - notify_notification_show (unmount_note, NULL);
188 + finish_unmount_flush_window();