Merge lp:~jamalta/unity/683241-recyclebin-icon into lp:unity

Proposed by Jamal Fanaian on 2010-12-07
Status: Merged
Approved by: Alex Launi on 2010-12-07
Approved revision: 652
Merged at revision: 675
Proposed branch: lp:~jamalta/unity/683241-recyclebin-icon
Merge into: lp:unity
Diff against target: 110 lines (+72/-2) 2 files modified
To merge this branch: bzr merge lp:~jamalta/unity/683241-recyclebin-icon
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve on 2010-12-07
Jason Smith 2010-12-07 Pending
Review via email: mp+42917@code.launchpad.net

Description of the Change

Changing the trash icon depending on whether the trash is empty or not.

To post a comment you must log in.
Alex Launi (alexlauni) wrote :

Looks good. The only comment I have is a formatting comment (which I'll fix, don't worry about it). When you create the trash monitor, the first param should be on the same line as the constructor, and then the other params aligned.

review: Approve
Alex Launi (alexlauni) wrote :

One more thing; in order to do that I need to ask you to sign the canonical contributors agreement. Signing the single-page agreement is very easy and is typically done with a single email. For more information about this agreement, look here: http://www.canonical.com/contributors

Jamal Fanaian (jamalta) wrote :

I had already signed it, but not with this email. I've submitted the contribution with the new email address. Thanks!

Preview Diff

1=== modified file 'src/TrashLauncherIcon.cpp'
2--- src/TrashLauncherIcon.cpp 2010-11-24 18:59:55 +0000
3+++ src/TrashLauncherIcon.cpp 2010-12-07 08:24:58 +0000
4@@ -18,6 +18,8 @@
5
6 #include "TrashLauncherIcon.h"
7
8+#include <gio/gio.h>
9+
10 TrashLauncherIcon::TrashLauncherIcon (Launcher* IconManager)
11 : SimpleLauncherIcon(IconManager)
12 {
13@@ -26,6 +28,19 @@
14 SetQuirk (LAUNCHER_ICON_QUIRK_VISIBLE, true);
15 SetQuirk (LAUNCHER_ICON_QUIRK_RUNNING, false);
16 SetIconType (LAUNCHER_ICON_TYPE_TRASH);
17+
18+ m_TrashMonitor = g_file_monitor_directory (
19+ g_file_new_for_uri("trash:///"),
20+ G_FILE_MONITOR_NONE,
21+ NULL,
22+ NULL);
23+
24+ g_signal_connect(m_TrashMonitor,
25+ "changed",
26+ G_CALLBACK (&TrashLauncherIcon::OnTrashChanged),
27+ this);
28+
29+ UpdateTrashIcon ();
30 }
31
32 TrashLauncherIcon::~TrashLauncherIcon()
33@@ -38,10 +53,58 @@
34 if (button == 1)
35 {
36 GError *error = NULL;
37-
38+
39 g_spawn_command_line_async ("xdg-open trash://", &error);
40-
41+
42 if (error)
43 g_error_free (error);
44 }
45 }
46+
47+void
48+TrashLauncherIcon::UpdateTrashIcon ()
49+{
50+ GFile *location;
51+ location = g_file_new_for_uri ("trash:///");
52+
53+ g_file_query_info_async (location,
54+ G_FILE_ATTRIBUTE_STANDARD_ICON,
55+ G_FILE_QUERY_INFO_NONE,
56+ 0,
57+ NULL,
58+ &TrashLauncherIcon::UpdateTrashIconCb,
59+ this);
60+
61+ g_object_unref(location);
62+}
63+
64+void
65+TrashLauncherIcon::UpdateTrashIconCb (GObject *source,
66+ GAsyncResult *res,
67+ gpointer data)
68+{
69+ TrashLauncherIcon *self = (TrashLauncherIcon*) data;
70+ GFileInfo *info;
71+ GIcon *icon;
72+
73+ info = g_file_query_info_finish (G_FILE (source), res, NULL);
74+
75+ if (info != NULL) {
76+ icon = g_file_info_get_icon (info);
77+ self->SetIconName (g_icon_to_string (icon));
78+
79+ g_object_unref(info);
80+ }
81+}
82+
83+void
84+TrashLauncherIcon::OnTrashChanged (GFileMonitor *monitor,
85+ GFile *file,
86+ GFile *other_file,
87+ GFileMonitorEvent event_type,
88+ gpointer data)
89+{
90+ TrashLauncherIcon *self = (TrashLauncherIcon*) data;
91+ self->UpdateTrashIcon ();
92+}
93+
94
95=== modified file 'src/TrashLauncherIcon.h'
96--- src/TrashLauncherIcon.h 2010-11-24 18:59:55 +0000
97+++ src/TrashLauncherIcon.h 2010-12-07 08:24:58 +0000
98@@ -30,6 +30,13 @@
99
100 protected:
101 void OnMouseClick (int button);
102+ void UpdateTrashIcon ();
103+
104+private:
105+ GFileMonitor *m_TrashMonitor;
106+ static void UpdateTrashIconCb (GObject *source, GAsyncResult *res, gpointer data);
107+ static void OnTrashChanged (GFileMonitor *monitor, GFile *file, GFile *other_file,
108+ GFileMonitorEvent event_type, gpointer data);
109
110 };
111