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

Proposed by Jamal Fanaian
Status: Merged
Approved by: Alex Launi
Approved revision: no longer in the source branch.
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
src/TrashLauncherIcon.cpp (+65/-2)
src/TrashLauncherIcon.h (+7/-0)
To merge this branch: bzr merge lp:~jamalta/unity/683241-recyclebin-icon
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve
Jason Smith 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.
Revision history for this message
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
Revision history for this message
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

Revision history for this message
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

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