Merge lp:~azzar1/unity/fix-808162 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1416
Proposed branch: lp:~azzar1/unity/fix-808162
Merge into: lp:unity
Diff against target: 393 lines (+75/-201)
2 files modified
plugins/unityshell/src/TrashLauncherIcon.cpp (+63/-192)
plugins/unityshell/src/TrashLauncherIcon.h (+12/-9)
To merge this branch: bzr merge lp:~azzar1/unity/fix-808162
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+72205@code.launchpad.net

Description of the change

Used Nautilus 3 DBus interface to fix bug #808162 and after all to have a clener file TrashLauncherIcon.cpp. Because the file is not so big i've uploaded the c++ style.

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

looks good to me, works well, thanks :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/TrashLauncherIcon.cpp'
2--- plugins/unityshell/src/TrashLauncherIcon.cpp 2011-08-09 17:29:42 +0000
3+++ plugins/unityshell/src/TrashLauncherIcon.cpp 2011-08-19 15:49:33 +0000
4@@ -15,25 +15,23 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Jason Smith <jason.smith@canonical.com>
8+ * Andrea Azzarone <azzaronea@gmail.com>
9 */
10
11 #include "TrashLauncherIcon.h"
12
13+#include <glib/gi18n-lib.h>
14 #include <Nux/WindowCompositor.h>
15
16-#include <gio/gio.h>
17-#include <glib/gi18n-lib.h>
18-#include <gconf/gconf-client.h>
19-
20 #include "Launcher.h"
21 #include "QuicklistManager.h"
22 #include "QuicklistMenuItemLabel.h"
23
24-
25-#define ASK_CONFIRMATION_KEY "/apps/nautilus/preferences/confirm_trash"
26+namespace unity {
27
28 TrashLauncherIcon::TrashLauncherIcon(Launcher* IconManager)
29- : SimpleLauncherIcon(IconManager)
30+ : SimpleLauncherIcon(IconManager)
31+ , proxy_("org.gnome.Nautilus", "/org/gnome/Nautilus", "org.gnome.Nautilus.FileOperations")
32 {
33 tooltip_text = _("Trash");
34 SetIconName("user-trash");
35@@ -41,55 +39,40 @@
36 SetQuirk(QUIRK_RUNNING, false);
37 SetIconType(TYPE_TRASH);
38 SetShortcut('t');
39- _confirm_dialog = NULL;
40- _on_confirm_dialog_close_id = 0;
41-
42- GFile* location = g_file_new_for_uri("trash:///");
43-
44- m_TrashMonitor = g_file_monitor_directory(location,
45+
46+ glib::Object<GFile> location(g_file_new_for_uri("trash:///"));
47+
48+ trash_monitor_ = g_file_monitor_directory(location,
49 G_FILE_MONITOR_NONE,
50 NULL,
51 NULL);
52
53- _on_trash_changed_handler_id = g_signal_connect(m_TrashMonitor,
54+ on_trash_changed_handler_id_ = g_signal_connect(trash_monitor_,
55 "changed",
56 G_CALLBACK(&TrashLauncherIcon::OnTrashChanged),
57 this);
58
59 UpdateTrashIcon();
60-
61- g_object_unref(location);
62 }
63
64 TrashLauncherIcon::~TrashLauncherIcon()
65 {
66- if (_on_trash_changed_handler_id != 0)
67- g_signal_handler_disconnect((gpointer) m_TrashMonitor,
68- _on_trash_changed_handler_id);
69-
70- g_object_unref(m_TrashMonitor);
71-
72- if (_on_confirm_dialog_close_id)
73- g_signal_handler_disconnect((gpointer) _confirm_dialog, _on_confirm_dialog_close_id);
74-
75- if (_confirm_dialog)
76- gtk_widget_destroy(_confirm_dialog);
77-}
78-
79-nux::Color
80-TrashLauncherIcon::BackgroundColor()
81-{
82- return nux::Color(0xFF333333);
83-}
84-
85-nux::Color
86-TrashLauncherIcon::GlowColor()
87-{
88- return nux::Color(0xFF333333);
89-}
90-
91-std::list<DbusmenuMenuitem*>
92-TrashLauncherIcon::GetMenus()
93+ if (on_trash_changed_handler_id_ != 0)
94+ g_signal_handler_disconnect((gpointer) trash_monitor_,
95+ on_trash_changed_handler_id_);
96+}
97+
98+nux::Color TrashLauncherIcon::BackgroundColor()
99+{
100+ return nux::Color(0xFF333333);
101+}
102+
103+nux::Color TrashLauncherIcon::GlowColor()
104+{
105+ return nux::Color(0xFF333333);
106+}
107+
108+std::list<DbusmenuMenuitem*> TrashLauncherIcon::GetMenus()
109 {
110 std::list<DbusmenuMenuitem*> result;
111 DbusmenuMenuitem* menu_item;
112@@ -99,7 +82,7 @@
113 g_object_ref(menu_item);
114
115 dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Empty Trash..."));
116- dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, !_empty);
117+ dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, !empty_);
118 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
119
120 g_signal_connect(menu_item,
121@@ -110,124 +93,21 @@
122 return result;
123 }
124
125-void
126-TrashLauncherIcon::ActivateLauncherIcon(ActionArg arg)
127+void TrashLauncherIcon::ActivateLauncherIcon(ActionArg arg)
128 {
129- GError* error = NULL;
130+ glib::Error error;
131
132 g_spawn_command_line_async("xdg-open trash://", &error);
133-
134- if (error)
135- g_error_free(error);
136-}
137-
138-void
139-TrashLauncherIcon::OnConfirmDialogClose(GtkDialog* dialog,
140- gint response,
141- gpointer user_data)
142-{
143- TrashLauncherIcon* self = (TrashLauncherIcon*)user_data;
144-
145- if (response == GTK_RESPONSE_OK)
146- g_thread_create((GThreadFunc)&TrashLauncherIcon::EmptyTrashAction, NULL, FALSE, NULL);
147-
148- if (self->_confirm_dialog)
149- gtk_widget_destroy(GTK_WIDGET(self->_confirm_dialog));
150-
151- self->_confirm_dialog = NULL;
152- self->_on_confirm_dialog_close_id = 0;
153-}
154-
155-void
156-TrashLauncherIcon::OnEmptyTrash(DbusmenuMenuitem* item, int time, TrashLauncherIcon* self)
157-{
158- GConfClient* client;
159- bool ask_confirmation;
160-
161- if (self->_confirm_dialog != NULL)
162- {
163- gtk_window_present_with_time(GTK_WINDOW(self->_confirm_dialog), time);
164- return;
165- }
166-
167- client = gconf_client_get_default();
168- ask_confirmation = gconf_client_get_bool(client, ASK_CONFIRMATION_KEY, NULL);
169- g_object_unref(client);
170-
171- if (ask_confirmation)
172- {
173- self->_confirm_dialog = gtk_message_dialog_new(NULL, GtkDialogFlags(0),
174- GTK_MESSAGE_WARNING,
175- GTK_BUTTONS_CANCEL,
176- NULL);
177-
178- g_object_set(GTK_DIALOG(self->_confirm_dialog),
179- "text", _("Empty all items from Trash?"),
180- "secondary-text", _("All items in the Trash will be permanently deleted."),
181- NULL);
182- gtk_dialog_add_button(GTK_DIALOG(self->_confirm_dialog), _("Empty Trash"), GTK_RESPONSE_OK);
183- self->_on_confirm_dialog_close_id = g_signal_connect(self->_confirm_dialog, "response", (GCallback)&TrashLauncherIcon::OnConfirmDialogClose, self);
184- gtk_widget_show_all(self->_confirm_dialog);
185- }
186-
187- QuicklistManager::Default()->HideQuicklist(self->_quicklist);
188-
189- if (!ask_confirmation)
190- g_thread_create((GThreadFunc)&TrashLauncherIcon::EmptyTrashAction, NULL, FALSE, NULL);
191-
192-}
193-
194-void
195-TrashLauncherIcon::EmptyTrashAction()
196-{
197- // This function runs in a different thread
198- // created in TrashLauncherIcon::OnEmptyTrash
199- GFile* location;
200- location = g_file_new_for_uri("trash:///");
201-
202- RecursiveDelete(location);
203-
204- g_object_unref(location);
205-
206-}
207-void
208-TrashLauncherIcon::RecursiveDelete(GFile* location)
209-{
210-
211- GFileInfo* info;
212- GFile* child;
213- GFileEnumerator* enumerator;
214-
215- enumerator = g_file_enumerate_children(location,
216- G_FILE_ATTRIBUTE_STANDARD_NAME ","
217- G_FILE_ATTRIBUTE_STANDARD_TYPE,
218- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
219- NULL,
220- NULL);
221- if (enumerator)
222- {
223- while ((info = g_file_enumerator_next_file(enumerator, NULL, NULL)) != NULL)
224- {
225- child = g_file_get_child(location, g_file_info_get_name(info));
226- if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) RecursiveDelete(child);
227-
228- g_file_delete(child, NULL, NULL);
229- g_object_unref(child);
230- g_object_unref(info);
231-
232- }
233-
234- g_file_enumerator_close(enumerator, NULL, NULL);
235- g_object_unref(enumerator);
236- }
237-
238-}
239-
240-void
241-TrashLauncherIcon::UpdateTrashIcon()
242-{
243- GFile* location;
244- location = g_file_new_for_uri("trash:///");
245+}
246+
247+void TrashLauncherIcon::OnEmptyTrash(DbusmenuMenuitem* item, int time, TrashLauncherIcon* self)
248+{
249+ self->proxy_.Call("EmptyTrash");
250+}
251+
252+void TrashLauncherIcon::UpdateTrashIcon()
253+{
254+ glib::Object<GFile> location(g_file_new_for_uri("trash:///"));
255
256 g_file_query_info_async(location,
257 G_FILE_ATTRIBUTE_STANDARD_ICON,
258@@ -237,62 +117,53 @@
259 &TrashLauncherIcon::UpdateTrashIconCb,
260 this);
261
262- g_object_unref(location);
263 }
264
265-void
266-TrashLauncherIcon::UpdateTrashIconCb(GObject* source,
267- GAsyncResult* res,
268- gpointer data)
269+void TrashLauncherIcon::UpdateTrashIconCb(GObject* source,
270+ GAsyncResult* res,
271+ gpointer data)
272 {
273 TrashLauncherIcon* self = (TrashLauncherIcon*) data;
274- GFileInfo* info;
275- GIcon* icon;
276- gchar* icon_name;
277
278 // FIXME: should use the generic LoadIcon function (not taking from the unity theme)
279- info = g_file_query_info_finish(G_FILE(source), res, NULL);
280-
281- if (info != NULL)
282- {
283- icon = g_file_info_get_icon(info);
284- icon_name = g_icon_to_string(icon);
285- self->SetIconName(icon_name);
286-
287- if (g_strcmp0(icon_name, "user-trash") == 0) self->_empty = TRUE;
288- else self->_empty = FALSE;
289-
290- g_object_unref(info);
291- g_free(icon_name);
292+ glib::Object<GFileInfo> info(g_file_query_info_finish(G_FILE(source), res, NULL));
293+
294+ if (info)
295+ {
296+ glib::Object<GIcon> icon(g_file_info_get_icon(info));
297+ glib::String icon_name(g_icon_to_string(icon));
298+
299+ self->SetIconName(icon_name.Value());
300+
301+ self->empty_ = g_strcmp0(icon_name.Value(), "user-trash") == 0;
302 }
303 }
304
305-void
306-TrashLauncherIcon::OnTrashChanged(GFileMonitor* monitor,
307- GFile* file,
308- GFile* other_file,
309- GFileMonitorEvent event_type,
310- gpointer data)
311+void TrashLauncherIcon::OnTrashChanged(GFileMonitor* monitor,
312+ GFile* file,
313+ GFile* other_file,
314+ GFileMonitorEvent event_type,
315+ gpointer data)
316 {
317 TrashLauncherIcon* self = (TrashLauncherIcon*) data;
318 self->UpdateTrashIcon();
319 }
320
321-nux::DndAction
322-TrashLauncherIcon::OnQueryAcceptDrop(unity::DndData& dnd_data)
323+
324+nux::DndAction TrashLauncherIcon::OnQueryAcceptDrop(unity::DndData& dnd_data)
325 {
326 return nux::DNDACTION_MOVE;
327 }
328
329-void
330-TrashLauncherIcon::OnAcceptDrop(unity::DndData& dnd_data)
331+void TrashLauncherIcon::OnAcceptDrop(unity::DndData& dnd_data)
332 {
333 for (auto it : dnd_data.Uris())
334 {
335- GFile* file = g_file_new_for_uri(it.c_str());
336+ glib::Object<GFile> file(g_file_new_for_uri(it.c_str()));
337 g_file_trash(file, NULL, NULL);
338- g_object_unref(file);
339 }
340
341 SetQuirk(LauncherIcon::QUIRK_PULSE_ONCE, true);
342 }
343+
344+} // namespace unity
345
346=== modified file 'plugins/unityshell/src/TrashLauncherIcon.h'
347--- plugins/unityshell/src/TrashLauncherIcon.h 2011-08-09 17:29:42 +0000
348+++ plugins/unityshell/src/TrashLauncherIcon.h 2011-08-19 15:49:33 +0000
349@@ -20,9 +20,15 @@
350 #ifndef TRASHLAUNCHERICON_H
351 #define TRASHLAUNCHERICON_H
352
353+#include <gio/gio.h>
354+#include <UnityCore/GLibDBusProxy.h>
355+#include <UnityCore/GLibWrapper.h>
356+
357 #include "DndData.h"
358 #include "SimpleLauncherIcon.h"
359
360+namespace unity {
361+
362 class TrashLauncherIcon : public SimpleLauncherIcon
363 {
364
365@@ -40,11 +46,10 @@
366 void OnAcceptDrop(unity::DndData& dnd_data);
367
368 private:
369- gulong _on_trash_changed_handler_id;
370- gulong _on_confirm_dialog_close_id;
371- GFileMonitor* m_TrashMonitor;
372- gboolean _empty;
373- GtkWidget* _confirm_dialog;
374+ gulong on_trash_changed_handler_id_;
375+ glib::Object<GFileMonitor> trash_monitor_;
376+ gboolean empty_;
377+ glib::DBusProxy proxy_;
378
379 void ActivateLauncherIcon(ActionArg arg);
380 std::list<DbusmenuMenuitem*> GetMenus();
381@@ -53,10 +58,8 @@
382 static void OnTrashChanged(GFileMonitor* monitor, GFile* file, GFile* other_file,
383 GFileMonitorEvent event_type, gpointer data);
384 static void OnEmptyTrash(DbusmenuMenuitem* item, int time, TrashLauncherIcon* self);
385- static void OnConfirmDialogClose(GtkDialog* dialog, gint response, gpointer user_data);
386- static void EmptyTrashAction();
387- static void RecursiveDelete(GFile* location);
388-
389 };
390
391+} // namespace unity
392+
393 #endif // TRASHLAUNCHERICON_H