Merge lp:~andreagrandi/unity-2d/main into lp:unity-2d/3.0

Proposed by Andrea Grandi
Status: Merged
Approved by: Ugo Riboni
Approved revision: 587
Merged at revision: 585
Proposed branch: lp:~andreagrandi/unity-2d/main
Merge into: lp:unity-2d/3.0
Diff against target: 128 lines (+54/-5)
2 files modified
launcher/UnityApplications/trash.cpp (+46/-4)
launcher/UnityApplications/trash.h (+8/-1)
To merge this branch: bzr merge lp:~andreagrandi/unity-2d/main
Reviewer Review Type Date Requested Status
Ugo Riboni (community) Approve
Review via email: mp+63312@code.launchpad.net

Description of the change

I've fixed bug #715611. Now when you delete something and you're using Unity-2D the Trash icon is updated as expected: if there are some files in the Trash the icon is the full Trash one, else is the empty one.

To post a comment you must log in.
Revision history for this message
Ugo Riboni (uriboni) wrote :

Hi, thanks for the patch :)
I tested it and it works well.

Here's a few things that need to be changed in the code (some are bugs, some are just style issues).

* You are never deleting the monitor that you create with
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
You should probably save it to a member variable and call g_object_unref on it in the Trash destructor.

* Can you please change the name of the function initTrashIcon to updateTrashIcon ? (It's updating the icon many times, not initializing it only once)

* You don't need to pass to fileChanged all the same arguments as fileChangedProxy. In fact you can just have fileChanged without any arguments and check if the event_type is the right type in fileChangedProxy.

* We have some coding guidelines in place and we can only accept software that conform to these. You can find the guidelines in the CODING file in the root of the lp:unity-2d repo.
For example you need to change function names like start_monitoring_trash with startMonitoringTrash, names of member variables to start with "m_" (like m_iconName instead of iconName), names of local variables like _this to something like currentInstance or something similar.
Please have a look at the guidelines for other coding standards we follow (like how to put parenthesis after if/else and so on).

* Finally, if you did not submit it already, you have to take care of accepting the Canonical contributor agreement. You can find instructions at http://www.canonical.com/contributors . Hopefully you are ok with that.

Thanks !

review: Needs Fixing
lp:~andreagrandi/unity-2d/main updated
584. By Andrea Grandi

Fix bug 715611 and some refactory

585. By Andrea Grandi

Fix some typo

Revision history for this message
Andrea Grandi (andreagrandi) wrote :

Hi,

> Hi, thanks for the patch :)
> I tested it and it works well.

nice to hear :)

> * You are never deleting the monitor that you create with
> monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
> You should probably save it to a member variable and call g_object_unref on it
> in the Trash destructor.

fixed

> * Can you please change the name of the function initTrashIcon to
> updateTrashIcon ? (It's updating the icon many times, not initializing it only
> once)

fixed

> * You don't need to pass to fileChanged all the same arguments as
> fileChangedProxy. In fact you can just have fileChanged without any arguments
> and check if the event_type is the right type in fileChangedProxy.

fixed

> * We have some coding guidelines in place and we can only accept software that
> conform to these. You can find the guidelines in the CODING file in the root
> of the lp:unity-2d repo.

read

> For example you need to change function names like start_monitoring_trash with
> startMonitoringTrash, names of member variables to start with "m_" (like
> m_iconName instead of iconName), names of local variables like _this to
> something like currentInstance or something similar.
> Please have a look at the guidelines for other coding standards we follow
> (like how to put parenthesis after if/else and so on).

fixed

> * Finally, if you did not submit it already, you have to take care of
> accepting the Canonical contributor agreement. You can find instructions at
> http://www.canonical.com/contributors . Hopefully you are ok with that.

done!

Please let me know if the new patch is ok :)

Revision history for this message
Ugo Riboni (uriboni) wrote :

All fixes are good, thanks for taking the time to do them.
There's just a few things missing:

68 + Trash* _this = static_cast<Trash*>(data);
69 +
70 + switch (event_type)
71 + {
72 + case (G_FILE_MONITOR_EVENT_DELETED || G_FILE_MONITOR_EVENT_CREATED):
73 + return _this->fileChanged();
74 + break;
75 + default: ;
76 + }

Please rename "_this" to "instance", and instead of the switch/case use a simpler and shorter if statement.

After you fix that, I will approve it and it will be merged into the trunk.

review: Needs Fixing
Revision history for this message
Ugo Riboni (uriboni) wrote :

Or maybe even better:

if (event_type == G_FILE_MONITOR_EVENT_DELETED || event_type == G_FILE_MONITOR_EVENT_CREATED) {
    (static_cast<Trash*>(data))->fileChanged();
}

lp:~andreagrandi/unity-2d/main updated
586. By Andrea Grandi

Refactory some code in Trash

Revision history for this message
Andrea Grandi (andreagrandi) wrote :

> All fixes are good, thanks for taking the time to do them.
> There's just a few things missing:
>
> 68 + Trash* _this = static_cast<Trash*>(data);
> 69 +
> 70 + switch (event_type)
> 71 + {
> 72 + case (G_FILE_MONITOR_EVENT_DELETED ||
> G_FILE_MONITOR_EVENT_CREATED):
> 73 + return _this->fileChanged();
> 74 + break;
> 75 + default: ;
> 76 + }
>
> Please rename "_this" to "instance", and instead of the switch/case use a
> simpler and shorter if statement.
>
> After you fix that, I will approve it and it will be merged into the trunk.

done, tested, committed! :)

Revision history for this message
Ugo Riboni (uriboni) wrote :

68 + if (event_type == G_FILE_MONITOR_EVENT_DELETED || event_type == G_FILE_MONITOR_EVENT_CREATED) {
69 + (static_cast<Trash*>(data))->fileChanged(); }

The closing brace should be on the next line(yes, i'm picky. sorry about that ;))

review: Needs Fixing
lp:~andreagrandi/unity-2d/main updated
587. By Andrea Grandi

Fix a closing brace

Revision history for this message
Andrea Grandi (andreagrandi) wrote :

> 68 + if (event_type == G_FILE_MONITOR_EVENT_DELETED || event_type ==
> G_FILE_MONITOR_EVENT_CREATED) {
> 69 + (static_cast<Trash*>(data))->fileChanged(); }
>
> The closing brace should be on the next line(yes, i'm picky. sorry about that
> ;))

fixed :P

Revision history for this message
Ugo Riboni (uriboni) wrote :

Everything is ok. Tested again and it's all working.
Approved and will be merged soon.
Thanks for all your work :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/UnityApplications/trash.cpp'
2--- launcher/UnityApplications/trash.cpp 2011-05-19 13:16:52 +0000
3+++ launcher/UnityApplications/trash.cpp 2011-06-07 09:36:36 +0000
4@@ -39,6 +39,8 @@
5 {
6 m_trash = g_file_new_for_uri(TRASH_URI);
7 setShortcutKey(Qt::Key_T);
8+ updateTrashIcon();
9+ startMonitoringTrash();
10 }
11
12 Trash::Trash(const Trash& other)
13@@ -47,6 +49,7 @@
14
15 Trash::~Trash()
16 {
17+ g_object_unref(m_monitor);
18 g_object_unref(m_trash);
19 }
20
21@@ -125,7 +128,7 @@
22 QString
23 Trash::icon() const
24 {
25- return "unity-icon-theme/user-trash";
26+ return m_iconName;
27 }
28
29 bool
30@@ -167,7 +170,7 @@
31 void
32 Trash::empty() const
33 {
34- recursive_delete(m_trash);
35+ recursiveDelete(m_trash);
36 }
37
38 int
39@@ -192,7 +195,7 @@
40 }
41
42 void
43-Trash::recursive_delete(GFile* dir)
44+Trash::recursiveDelete(GFile* dir)
45 {
46 GError* error = NULL;
47 QString attributes;
48@@ -215,7 +218,7 @@
49 while ((info = g_file_enumerator_next_file(children, NULL, &error)) != NULL) {
50 GFile* child = g_file_get_child(dir, g_file_info_get_name(info));
51 if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) {
52- recursive_delete(child);
53+ recursiveDelete(child);
54 }
55
56 /* If passed a GError* as third parameter, g_file_delete incorrectly
57@@ -326,3 +329,42 @@
58 return QVariant::fromValue(m_trash);
59 }
60
61+void
62+Trash::fileChangedProxy(GFileMonitor *file_monitor,
63+ GFile *child,
64+ GFile *other_file,
65+ GFileMonitorEvent event_type,
66+ gpointer data)
67+{
68+ if (event_type == G_FILE_MONITOR_EVENT_DELETED || event_type == G_FILE_MONITOR_EVENT_CREATED) {
69+ (static_cast<Trash*>(data))->fileChanged();
70+ }
71+}
72+
73+void
74+Trash::fileChanged()
75+{
76+ updateTrashIcon();
77+ emit iconChanged(icon());
78+}
79+
80+void
81+Trash::startMonitoringTrash(void)
82+{
83+ GFile *file;
84+
85+ file = g_file_new_for_uri ("trash://");
86+ m_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
87+ g_object_unref(file);
88+
89+ g_signal_connect(m_monitor, "changed", G_CALLBACK(Trash::fileChangedProxy), this);
90+}
91+
92+void
93+Trash::updateTrashIcon(void)
94+{
95+ if(count() == 0) {
96+ m_iconName = "unity-icon-theme/user-trash"; }
97+ else {
98+ m_iconName = "unity-icon-theme/user-trash-full"; }
99+}
100
101=== modified file 'launcher/UnityApplications/trash.h'
102--- launcher/UnityApplications/trash.h 2011-05-19 13:16:52 +0000
103+++ launcher/UnityApplications/trash.h 2011-06-07 09:36:36 +0000
104@@ -65,6 +65,9 @@
105 private Q_SLOTS:
106 void onEmptyTriggered();
107
108+ static void fileChangedProxy(GFileMonitor *file_monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data);
109+ void fileChanged();
110+
111 private:
112 void open() const;
113 void empty() const;
114@@ -73,9 +76,13 @@
115 QList<WnckWindow*> trashWindows() const;
116 bool isTrashWindow(WnckWindow* window) const;
117
118- static void recursive_delete(GFile* dir);
119+ static void recursiveDelete(GFile* dir);
120+ void startMonitoringTrash();
121+ void updateTrashIcon();
122
123+ QString m_iconName;
124 GFile* m_trash;
125+ GFileMonitor* m_monitor;
126 };
127
128 Q_DECLARE_METATYPE(Trash*)

Subscribers

People subscribed via source and target branches