Merge lp:~didrocks/unity/only-one-trash-confirmdialog into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1153
Proposed branch: lp:~didrocks/unity/only-one-trash-confirmdialog
Merge into: lp:unity
Diff against target: 127 lines (+43/-13)
2 files modified
src/TrashLauncherIcon.cpp (+40/-13)
src/TrashLauncherIcon.h (+3/-0)
To merge this branch: bzr merge lp:~didrocks/unity/only-one-trash-confirmdialog
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+57881@code.launchpad.net

Description of the change

make the trash look good: only one instance, handled in a more async way (LP:
#761643)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/TrashLauncherIcon.cpp'
2--- src/TrashLauncherIcon.cpp 2011-03-29 15:24:14 +0000
3+++ src/TrashLauncherIcon.cpp 2011-04-15 14:14:32 +0000
4@@ -39,6 +39,8 @@
5 SetQuirk (QUIRK_RUNNING, false);
6 SetIconType (TYPE_TRASH);
7 SetShortcut ('t');
8+ _confirm_dialog = NULL;
9+ _on_confirm_dialog_close_id = 0;
10
11 m_TrashMonitor = g_file_monitor_directory (g_file_new_for_uri("trash:///"),
12 G_FILE_MONITOR_NONE,
13@@ -60,6 +62,12 @@
14 _on_trash_changed_handler_id);
15
16 g_object_unref (m_TrashMonitor);
17+
18+ if (_on_confirm_dialog_close_id)
19+ g_signal_handler_disconnect ((gpointer) _confirm_dialog, _on_confirm_dialog_close_id);
20+
21+ if (_confirm_dialog)
22+ gtk_widget_destroy (_confirm_dialog);
23 }
24
25 nux::Color
26@@ -107,12 +115,33 @@
27 g_error_free (error);
28 }
29
30+void
31+TrashLauncherIcon::OnConfirmDialogClose (GtkDialog *dialog,
32+ gint response,
33+ gpointer user_data)
34+{
35+ TrashLauncherIcon *self = (TrashLauncherIcon*)user_data;
36+
37+ if (response == GTK_RESPONSE_OK)
38+ g_thread_create ((GThreadFunc)&TrashLauncherIcon::EmptyTrashAction, NULL, FALSE, NULL);
39+
40+ if (self->_confirm_dialog)
41+ gtk_widget_destroy (GTK_WIDGET(self->_confirm_dialog));
42+
43+ self->_confirm_dialog = NULL;
44+ self->_on_confirm_dialog_close_id = 0;
45+}
46+
47 void
48 TrashLauncherIcon::OnEmptyTrash(DbusmenuMenuitem *item, int time, TrashLauncherIcon *self)
49 {
50 GConfClient *client;
51- GtkWidget *dialog;
52 bool ask_confirmation;
53+
54+ if (self->_confirm_dialog != NULL) {
55+ gtk_window_present_with_time (GTK_WINDOW (self->_confirm_dialog), time);
56+ return;
57+ }
58
59 client = gconf_client_get_default ();
60 ask_confirmation = gconf_client_get_bool (client, ASK_CONFIRMATION_KEY, NULL);
61@@ -120,27 +149,24 @@
62
63 if (ask_confirmation)
64 {
65- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
66- GTK_MESSAGE_WARNING,
67- GTK_BUTTONS_CANCEL,
68- NULL);
69+ self->_confirm_dialog = gtk_message_dialog_new (NULL, GtkDialogFlags(0),
70+ GTK_MESSAGE_WARNING,
71+ GTK_BUTTONS_CANCEL,
72+ NULL);
73
74- g_object_set (GTK_DIALOG (dialog),
75+ g_object_set (GTK_DIALOG (self->_confirm_dialog),
76 "text", _("Empty all items from Trash?"),
77 "secondary-text", _("All items in the Trash will be permanently deleted."),
78 NULL);
79- gtk_dialog_add_button (GTK_DIALOG (dialog), _("Empty Trash"), GTK_RESPONSE_OK );
80+ gtk_dialog_add_button (GTK_DIALOG (self->_confirm_dialog), _("Empty Trash"), GTK_RESPONSE_OK);
81+ self->_on_confirm_dialog_close_id = g_signal_connect (self->_confirm_dialog, "response", (GCallback)&TrashLauncherIcon::OnConfirmDialogClose, self);
82+ gtk_widget_show_all (self->_confirm_dialog);
83 }
84
85 QuicklistManager::Default ()->HideQuicklist (self->_quicklist);
86
87- if (!ask_confirmation || gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
88- {
89+ if (!ask_confirmation)
90 g_thread_create ((GThreadFunc)&TrashLauncherIcon::EmptyTrashAction, NULL, FALSE, NULL);
91- }
92-
93- if (ask_confirmation)
94- gtk_widget_destroy (dialog);
95
96 }
97
98@@ -217,6 +243,7 @@
99 GIcon *icon;
100 gchar *icon_name;
101
102+ // FIXME: should use the generic LoadIcon function (not taking from the unity theme)
103 info = g_file_query_info_finish (G_FILE (source), res, NULL);
104
105 if (info != NULL) {
106
107=== modified file 'src/TrashLauncherIcon.h'
108--- src/TrashLauncherIcon.h 2011-03-29 15:24:14 +0000
109+++ src/TrashLauncherIcon.h 2011-04-15 14:14:32 +0000
110@@ -40,8 +40,10 @@
111
112 private:
113 gulong _on_trash_changed_handler_id;
114+ gulong _on_confirm_dialog_close_id;
115 GFileMonitor *m_TrashMonitor;
116 gboolean _empty;
117+ GtkWidget *_confirm_dialog;
118
119 void ActivateLauncherIcon ();
120 std::list<DbusmenuMenuitem *> GetMenus ();
121@@ -50,6 +52,7 @@
122 static void OnTrashChanged (GFileMonitor *monitor, GFile *file, GFile *other_file,
123 GFileMonitorEvent event_type, gpointer data);
124 static void OnEmptyTrash (DbusmenuMenuitem *item, int time, TrashLauncherIcon *self);
125+ static void OnConfirmDialogClose (GtkDialog *dialog, gint response, gpointer user_data);
126 static void EmptyTrashAction ();
127 static void RecursiveDelete (GFile *location);
128