Merge lp:~azzar1/unity/custom-bg-color-icon into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 2393
Proposed branch: lp:~azzar1/unity/custom-bg-color-icon
Merge into: lp:unity
Diff against target: 465 lines (+172/-13)
19 files modified
UnityCore/DesktopUtilities.cpp (+25/-2)
UnityCore/DesktopUtilities.h (+2/-0)
hud/HudIconTextureSource.cpp (+1/-1)
hud/HudIconTextureSource.h (+1/-1)
launcher/BFBLauncherIcon.cpp (+1/-1)
launcher/BFBLauncherIcon.h (+1/-1)
launcher/BamfLauncherIcon.cpp (+29/-0)
launcher/BamfLauncherIcon.h (+6/-0)
launcher/HudLauncherIcon.cpp (+1/-1)
launcher/HudLauncherIcon.h (+1/-1)
launcher/LauncherIcon.cpp (+1/-1)
launcher/LauncherIcon.h (+1/-1)
launcher/MockLauncherIcon.h (+1/-1)
tests/CMakeLists.txt (+5/-0)
tests/data/ubuntu-software-center.desktop (+1/-0)
tests/test_bamflaunchericon.cpp (+68/-0)
tests/test_desktop_utilities.cpp (+24/-0)
tests/test_main.cpp (+2/-1)
unity-shared/IconTextureSource.h (+1/-1)
To merge this branch: bzr merge lp:~azzar1/unity/custom-bg-color-icon
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Andrea Azzarone (community) Needs Resubmitting
Marco Trevisan (Treviño) Approve
Review via email: mp+107403@code.launchpad.net

Commit message

Adds support for X-Unity-IconBackgroundColor in the .desktop file.

Description of the change

This branch adds the ability to force the background color of a launcher icon using the X-Unity-IconBackgroundColor in the desktop file. So you can do something like:

X-Unity-IconBackgroundColor=#aabbcc

The hex string may be in one of these formats:
#rgb
#rrggbb
rgb
rrggbb

== Test ==
Unit tests added.

== Notes ==
Depends on lp:~andyrock/nux/color-html-notation

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi Andy,

A few things need fixing (I bet you never saw that coming!)

std::string DesktopUtilities::GetBackgroundColor(std::string const& desktop_path)

THis ^^ needs to be made const.

nux::Color BamfLauncherIcon::BackgroundColor()

This too.

Do we need better testing? Perhaps something in autopilot?

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Hi Andy,
>
>
> A few things need fixing (I bet you never saw that coming!)
>
> std::string DesktopUtilities::GetBackgroundColor(std::string const&
> desktop_path)
>

GetBackgroundColor is a static member. We'll never call GetBackgroundColor on a
const instance of DesktopUtilities. But it will be done.

>
> THis ^^ needs to be made const.
>
> nux::Color BamfLauncherIcon::BackgroundColor()
>
> This too.
>

This is a virtual member so I have to change all the BackgroundColor methods (SimpleLauncherIcon::Back...)

>
> Do we need better testing? Perhaps something in autopilot?

First of all we need to add a local .desktop file to the launcher (because we cannot edit a .desktop file in /usr/share/applications without being root)... It will be done.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Hi Andy,
>
>
> A few things need fixing (I bet you never saw that coming!)
>
> std::string DesktopUtilities::GetBackgroundColor(std::string const&
> desktop_path)

A static function/method cannot be const.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Unity code looks good to me.

review: Approve
Revision history for this message
Andrea Azzarone (azzar1) wrote :

AP test added.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

186 -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
187 +// -*- Mode: C++; indent-tamos-mode: nil; tab-width: 2 -*-

Ummm.... ??

422 +
423 +
424 +
425 +
426 +
427 +

Extra blank lines don't need to be there.

439 + def test_custom_background_color(self):
440 + """Tests X-Unity-IconBackgroundColor."""

Please change this docstring. I suggest the following:
"""THe X-Unity-IconBackgroundColor property must change the launcher icon's background color."""

441 + path = os.getenv("PYTHONPATH")
442 + if path == None:
443 + self.skipTest("Cannot run this test if PYTHONPATH has not been set.")

Don't do this. For a start, PYTHONPATH can be multiple directories, or it can be empty. Your test shouldn't rely on a specific configuration in order to run.
444 +
445 + desktop_file = os.path.join(path, "unity/tests/unity-test.desktop")
446 + desktop_file = os.path.realpath(desktop_file)

Again, this won't work if PYTHONPATH is empty or is set to multiple directories. If you *really* need to get the path of this file you can do:

os.path.dirname(__file__)

... which will give you something like '/home/thomi/code/canonical/unity/reviews/branchname/tests/autopilot/unity/tests/'.

447 +
448 + old_value = self.call_gsettings_cmd('get', 'com.canonical.Unity.Launcher', 'favorites')
449 + value = eval(old_value)

Can you please explain what's going on here? Generally speaking, calling 'eval' is a bad idea, and is especially bad when passing it a string that comes from elsewhere. What happens when I set that config option to 'import subprocess;subprocess.call("rm -rf".split())' ?

450 + value.append(desktop_file)
451 + self.addCleanup(self.call_gsettings_cmd, 'set', 'com.canonical.Unity.Launcher', 'favorites', old_value)
452 + self.call_gsettings_cmd('set', 'com.canonical.Unity.Launcher', 'favorites', str(value))

Again, I'm not sure what this is supposed to do. I'm sure that we can find a better way to do it though. The launcher emulator already has a method that allows you to add a custom .desktop file to the launcher - can you use that? If not, let me know what you need and I'll try and come up with a solution for you.

453 +
454 + icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
455 + self.assertThat(icon, NotEquals(None))
456 + self.assertThat(icon.bg_color_red, Eventually(Equals(0xaa)))
457 + self.assertThat(icon.bg_color_green, Eventually(Equals(0xbb)))
458 + self.assertThat(icon.bg_color_blue, Eventually(Equals(0xcc)))
459 + self.assertThat(icon.bg_color_alpha, Eventually(Equals(0xff)))
460 +

This part is fine however :)

review: Needs Fixing
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

...also, I notice in several places you've done this:

36 - std::vector<std::string> const& data_dirs = GetDataDirectories();
37 + std::vector<std::string> const data_dirs(GetDataDirectories());

i.e.-= changed it from returning a const ref of T to a const copy of T.

I can't see what the point if making the T const is. You're returning a copy, so why do you care what the caller does it with? I'd suggest either returning a straight copy, or, if you think it's performance critical, return a const ref like it was.

Cheers,

Revision history for this message
Tim Penhey (thumper) wrote :

launcher/TrashLauncherIcon.h has a lot of blank lines at the start :)

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> 186 -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
> 187 +// -*- Mode: C++; indent-tamos-mode: nil; tab-width: 2 -*-
>
> Ummm.... ??
>
> 422 +
> 423 +
> 424 +
> 425 +
> 426 +
> 427 +
>
>
> Extra blank lines don't need to be there.
>

Oos.

> 439 + def test_custom_background_color(self):
> 440 + """Tests X-Unity-IconBackgroundColor."""
>
> Please change this docstring. I suggest the following:
> """THe X-Unity-IconBackgroundColor property must change the launcher icon's
> background color."""
>
> 441 + path = os.getenv("PYTHONPATH")
> 442 + if path == None:
> 443 + self.skipTest("Cannot run this test if PYTHONPATH has not been
> set.")
>
> Don't do this. For a start, PYTHONPATH can be multiple directories, or it can
> be empty. Your test shouldn't rely on a specific configuration in order to
> run.
> 444 +
> 445 + desktop_file = os.path.join(path, "unity/tests/unity-test.desktop")
> 446 + desktop_file = os.path.realpath(desktop_file)
>
> Again, this won't work if PYTHONPATH is empty or is set to multiple
> directories. If you *really* need to get the path of this file you can do:
>
> os.path.dirname(__file__)
>
> ... which will give you something like '/home/thomi/code/canonical/unity/revie
> ws/branchname/tests/autopilot/unity/tests/'.
>
> 447 +
> 448 + old_value = self.call_gsettings_cmd('get',
> 'com.canonical.Unity.Launcher', 'favorites')
> 449 + value = eval(old_value)
>
> Can you please explain what's going on here? Generally speaking, calling
> 'eval' is a bad idea, and is especially bad when passing it a string that
> comes from elsewhere. What happens when I set that config option to 'import
> subprocess;subprocess.call("rm -rf".split())' ?
>
> 450 + value.append(desktop_file)
> 451 + self.addCleanup(self.call_gsettings_cmd, 'set',
> 'com.canonical.Unity.Launcher', 'favorites', old_value)
> 452 + self.call_gsettings_cmd('set', 'com.canonical.Unity.Launcher',
> 'favorites', str(value))
>
> Again, I'm not sure what this is supposed to do. I'm sure that we can find a
> better way to do it though. The launcher emulator already has a method that
> allows you to add a custom .desktop file to the launcher - can you use that?

No because we need a local .desktop file with a X-Unity-IconBackroundColor key
and we cannot edit a .desktop file in /usr/share/applications.

> If not, let me know what you need and I'll try and come up with a solution for
> you.
>

If you can find another way to test it (with AP) let me know :)

>
> 453 +
> 454 + icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
> 455 + self.assertThat(icon, NotEquals(None))
> 456 + self.assertThat(icon.bg_color_red, Eventually(Equals(0xaa)))
> 457 + self.assertThat(icon.bg_color_green, Eventually(Equals(0xbb)))
> 458 + self.assertThat(icon.bg_color_blue, Eventually(Equals(0xcc)))
> 459 + self.assertThat(icon.bg_color_alpha, Eventually(Equals(0xff)))
> 460 +
>
> This part is fine however :)

Revision history for this message
Andrea Azzarone (azzar1) wrote :

So what we have to do in the AP is:
#. Get a dekstop .file with X-Unity-IconBackroundColor key
#. Start the app
#. Get the icon app
#. Make sure the bg color icon is correct.

Any idea? Otherwise I'll try to write an unit test for this.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Ok I replaced the AP test with a unit one.

review: Needs Resubmitting
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi Andy,

Sorry, I didn't see your replies. For future reference, I'd rather you kept data file data in a python string (provided that it's very small, as a desktop file is), and inside the test write that data to a temporary file.

The unit test looks good to me.

review: Approve
Revision history for this message
Adolfo Jayme Barrientos (fitojb) wrote :

Linked to bug #962120

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/DesktopUtilities.cpp'
2--- UnityCore/DesktopUtilities.cpp 2012-03-30 16:56:05 +0000
3+++ UnityCore/DesktopUtilities.cpp 2012-06-06 16:00:26 +0000
4@@ -15,12 +15,15 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
8+* Andrea Azzarone <azzarone@gmail.com>
9 */
10
11+#include <algorithm>
12+
13 #include <glib.h>
14-#include <algorithm>
15
16 #include "DesktopUtilities.h"
17+#include "GLibWrapper.h"
18
19 namespace unity
20 {
21@@ -64,7 +67,7 @@
22 std::vector<std::string> DesktopUtilities::GetDataDirectories()
23 {
24 std::vector<std::string> dirs = GetSystemDataDirectories();
25- std::string const& user_directory = GetUserDataDirectory();
26+ std::string const& user_directory = GetUserDataDirectory();
27
28 dirs.push_back(user_directory);
29
30@@ -116,4 +119,24 @@
31 return GetDesktopID(data_dirs, desktop_path);
32 }
33
34+
35+std::string DesktopUtilities::GetBackgroundColor(std::string const& desktop_path)
36+{
37+ GKeyFile* key_file = g_key_file_new();
38+
39+ glib::Error error;
40+ g_key_file_load_from_file(key_file, desktop_path.c_str(), static_cast<GKeyFileFlags>(0), &error);
41+
42+ if (error)
43+ {
44+ g_key_file_free(key_file);
45+ return "";
46+ }
47+
48+ glib::String value(g_key_file_get_string(key_file, "Desktop Entry", "X-Unity-IconBackgroundColor", &error));
49+
50+ g_key_file_free(key_file);
51+ return value.Str();
52+}
53+
54 } // namespace unity
55
56=== modified file 'UnityCore/DesktopUtilities.h'
57--- UnityCore/DesktopUtilities.h 2012-03-30 16:56:05 +0000
58+++ UnityCore/DesktopUtilities.h 2012-06-06 16:00:26 +0000
59@@ -36,6 +36,8 @@
60 static std::string GetDesktopID(std::string const& desktop_path);
61 static std::string GetDesktopID(std::vector<std::string> const& default_paths,
62 std::string const& desktop_path);
63+
64+ static std::string GetBackgroundColor(std::string const& desktop_path);
65 };
66
67 } // namespace
68
69=== modified file 'hud/HudIconTextureSource.cpp'
70--- hud/HudIconTextureSource.cpp 2012-05-07 00:49:31 +0000
71+++ hud/HudIconTextureSource.cpp 2012-06-06 16:00:26 +0000
72@@ -98,7 +98,7 @@
73 }
74 }
75
76-nux::Color HudIconTextureSource::BackgroundColor()
77+nux::Color HudIconTextureSource::BackgroundColor() const
78 {
79 return bg_color;
80 }
81
82=== modified file 'hud/HudIconTextureSource.h'
83--- hud/HudIconTextureSource.h 2012-05-07 00:49:31 +0000
84+++ hud/HudIconTextureSource.h 2012-06-06 16:00:26 +0000
85@@ -34,7 +34,7 @@
86 HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture> texture);
87 ~HudIconTextureSource();
88
89- virtual nux::Color BackgroundColor();
90+ virtual nux::Color BackgroundColor() const;
91 virtual nux::BaseTexture* TextureForSize(int size);
92 virtual nux::Color GlowColor();
93 virtual nux::BaseTexture* Emblem();
94
95=== modified file 'launcher/BFBLauncherIcon.cpp'
96--- launcher/BFBLauncherIcon.cpp 2012-05-15 19:33:20 +0000
97+++ launcher/BFBLauncherIcon.cpp 2012-06-06 16:00:26 +0000
98@@ -80,7 +80,7 @@
99 }
100 }
101
102-nux::Color BFBLauncherIcon::BackgroundColor()
103+nux::Color BFBLauncherIcon::BackgroundColor() const
104 {
105 return background_color_;
106 }
107
108=== modified file 'launcher/BFBLauncherIcon.h'
109--- launcher/BFBLauncherIcon.h 2012-05-07 19:52:54 +0000
110+++ launcher/BFBLauncherIcon.h 2012-06-06 16:00:26 +0000
111@@ -38,7 +38,7 @@
112 public:
113 BFBLauncherIcon(LauncherHideMode hide_mode);
114
115- virtual nux::Color BackgroundColor();
116+ virtual nux::Color BackgroundColor() const;
117 virtual nux::Color GlowColor();
118
119 void ActivateLauncherIcon(ActionArg arg);
120
121=== modified file 'launcher/BamfLauncherIcon.cpp'
122--- launcher/BamfLauncherIcon.cpp 2012-05-23 17:34:11 +0000
123+++ launcher/BamfLauncherIcon.cpp 2012-06-06 16:00:26 +0000
124@@ -53,6 +53,8 @@
125 , _supported_types_filled(false)
126 , _fill_supported_types_id(0)
127 , _window_moved_id(0)
128+ , use_custom_bg_color_(false)
129+ , bg_color_(nux::color::White)
130 {
131 g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"),
132 GUINT_TO_POINTER(1));
133@@ -154,6 +156,7 @@
134 EnsureWindowState();
135 UpdateMenus();
136 UpdateDesktopFile();
137+ UpdateBackgroundColor();
138
139 // hack
140 SetProgress(0.0f);
141@@ -508,6 +511,7 @@
142 break;
143 case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
144 UpdateDesktopQuickList();
145+ UpdateBackgroundColor();
146 break;
147 default:
148 break;
149@@ -778,6 +782,23 @@
150 }
151 }
152
153+void BamfLauncherIcon::UpdateBackgroundColor()
154+{
155+ bool last_use_custom_bg_color = use_custom_bg_color_;
156+ nux::Color last_bg_color(bg_color_);
157+
158+ std::string const& color = DesktopUtilities::GetBackgroundColor(DesktopFile());
159+
160+ use_custom_bg_color_ = !color.empty();
161+
162+ if (use_custom_bg_color_)
163+ bg_color_ = nux::Color(color);
164+
165+ if (last_use_custom_bg_color != use_custom_bg_color_ ||
166+ last_bg_color != bg_color_)
167+ EmitNeedsRedraw();
168+}
169+
170 void BamfLauncherIcon::UpdateMenus()
171 {
172 GList* children, *l;
173@@ -1253,6 +1274,14 @@
174 return result;
175 }
176
177+nux::Color BamfLauncherIcon::BackgroundColor() const
178+{
179+ if (use_custom_bg_color_)
180+ return bg_color_;
181+
182+ return SimpleLauncherIcon::BackgroundColor();
183+}
184+
185 const std::set<std::string>& BamfLauncherIcon::GetSupportedTypes()
186 {
187 if (!_supported_types_filled)
188
189=== modified file 'launcher/BamfLauncherIcon.h'
190--- launcher/BamfLauncherIcon.h 2012-05-15 18:52:54 +0000
191+++ launcher/BamfLauncherIcon.h 2012-06-06 16:00:26 +0000
192@@ -60,6 +60,8 @@
193 virtual bool ShowInSwitcher(bool current);
194 virtual unsigned long long SwitcherPriority();
195
196+ virtual nux::Color BackgroundColor() const;
197+
198 std::vector<Window> Windows();
199 std::vector<Window> WindowsOnViewport();
200 std::vector<Window> WindowsForMonitor(int monitor);
201@@ -101,6 +103,7 @@
202
203 void EnsureWindowState();
204 void EnsureMenuItemsReady();
205+ void UpdateBackgroundColor();
206 void UpdateDesktopFile();
207 void UpdateMenus();
208 void UpdateDesktopQuickList();
209@@ -140,6 +143,9 @@
210 glib::Object<DbusmenuMenuitem> _menu_desktop_shortcuts;
211 glib::Object<GFileMonitor> _desktop_file_monitor;
212 glib::SignalManager _gsignals;
213+
214+ bool use_custom_bg_color_;
215+ nux::Color bg_color_;
216 };
217
218 }
219
220=== modified file 'launcher/HudLauncherIcon.cpp'
221--- launcher/HudLauncherIcon.cpp 2012-05-15 19:33:20 +0000
222+++ launcher/HudLauncherIcon.cpp 2012-06-06 16:00:26 +0000
223@@ -106,7 +106,7 @@
224 }
225 }
226
227-nux::Color HudLauncherIcon::BackgroundColor()
228+nux::Color HudLauncherIcon::BackgroundColor() const
229 {
230 return background_color_;
231 }
232
233=== modified file 'launcher/HudLauncherIcon.h'
234--- launcher/HudLauncherIcon.h 2012-05-07 19:52:54 +0000
235+++ launcher/HudLauncherIcon.h 2012-06-06 16:00:26 +0000
236@@ -36,7 +36,7 @@
237 public:
238 HudLauncherIcon(LauncherHideMode hide_mode);
239
240- virtual nux::Color BackgroundColor();
241+ virtual nux::Color BackgroundColor() const;
242 virtual nux::Color GlowColor();
243
244 void ActivateLauncherIcon(ActionArg arg);
245
246=== modified file 'launcher/LauncherIcon.cpp'
247--- launcher/LauncherIcon.cpp 2012-06-01 04:00:29 +0000
248+++ launcher/LauncherIcon.cpp 2012-06-06 16:00:26 +0000
249@@ -240,7 +240,7 @@
250 UpdateQuirkTime(QUIRK_LAST_ACTION);
251 }
252
253-nux::Color LauncherIcon::BackgroundColor()
254+nux::Color LauncherIcon::BackgroundColor() const
255 {
256 return _background_color;
257 }
258
259=== modified file 'launcher/LauncherIcon.h'
260--- launcher/LauncherIcon.h 2012-06-01 04:00:29 +0000
261+++ launcher/LauncherIcon.h 2012-06-06 16:00:26 +0000
262@@ -147,7 +147,7 @@
263
264 IconType GetIconType();
265
266- virtual nux::Color BackgroundColor();
267+ virtual nux::Color BackgroundColor() const;
268
269 virtual nux::Color GlowColor();
270
271
272=== modified file 'launcher/MockLauncherIcon.h'
273--- launcher/MockLauncherIcon.h 2012-05-07 19:52:54 +0000
274+++ launcher/MockLauncherIcon.h 2012-06-06 16:00:26 +0000
275@@ -219,7 +219,7 @@
276 return type_;
277 }
278
279- nux::Color BackgroundColor()
280+ nux::Color BackgroundColor() const
281 {
282 return nux::Color(0xFFAAAAAA);
283 }
284
285=== modified file 'tests/CMakeLists.txt'
286--- tests/CMakeLists.txt 2012-06-04 22:47:12 +0000
287+++ tests/CMakeLists.txt 2012-06-06 16:00:26 +0000
288@@ -198,6 +198,7 @@
289
290 # Tests that require X
291 add_executable(test-gtest
292+ test_bamflaunchericon.cpp
293 test_hud_button.cpp
294 test_dashview_impl.cpp
295 test_texture_cache.cpp
296@@ -221,10 +222,14 @@
297 ${CMAKE_SOURCE_DIR}/hud/HudPrivate.cpp
298 ${CMAKE_SOURCE_DIR}/hud/HudView.cpp
299 ${CMAKE_SOURCE_DIR}/launcher/AbstractLauncherIcon.cpp
300+ ${CMAKE_SOURCE_DIR}/launcher/BamfLauncherIcon.cpp
301 ${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp
302 ${CMAKE_SOURCE_DIR}/launcher/DNDCollectionWindow.cpp
303 ${CMAKE_SOURCE_DIR}/launcher/Decaymulator.cpp
304 ${CMAKE_SOURCE_DIR}/launcher/DndData.cpp
305+ ${CMAKE_SOURCE_DIR}/launcher/FavoriteStore.cpp
306+ ${CMAKE_SOURCE_DIR}/launcher/FavoriteStoreGSettings.cpp
307+ ${CMAKE_SOURCE_DIR}/launcher/FavoriteStorePrivate.cpp
308 ${CMAKE_SOURCE_DIR}/launcher/GeisAdapter.cpp
309 ${CMAKE_SOURCE_DIR}/launcher/Launcher.cpp
310 ${CMAKE_SOURCE_DIR}/launcher/LauncherDragWindow.cpp
311
312=== modified file 'tests/data/ubuntu-software-center.desktop'
313--- tests/data/ubuntu-software-center.desktop 2011-11-28 15:56:30 +0000
314+++ tests/data/ubuntu-software-center.desktop 2012-06-06 16:00:26 +0000
315@@ -10,3 +10,4 @@
316 MimeType=application/x-deb;application/x-debian-package;x-scheme-handler/apt;
317 StartupNotify=true
318 X-Ubuntu-Gettext-Domain=software-center
319+X-Unity-IconBackgroundColor=#aabbcc
320
321=== added file 'tests/test_bamflaunchericon.cpp'
322--- tests/test_bamflaunchericon.cpp 1970-01-01 00:00:00 +0000
323+++ tests/test_bamflaunchericon.cpp 2012-06-06 16:00:26 +0000
324@@ -0,0 +1,68 @@
325+/*
326+ * Copyright 2012 Canonical Ltd.
327+ *
328+ * This program is free software: you can redistribute it and/or modify it
329+ * under the terms of the GNU General Public License version 3, as published
330+ * by the Free Software Foundation.
331+ *
332+ * This program is distributed in the hope that it will be useful, but
333+ * WITHOUT ANY WARRANTY; without even the implied warranties of
334+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
335+ * PURPOSE. See the GNU General Public License for more details.
336+ *
337+ * You should have received a copy of the GNU General Public License
338+ * version 3 along with this program. If not, see
339+ * <http://www.gnu.org/licenses/>
340+ *
341+ * Authored by: Andrea Azzarone <azzarone@gmail.com>
342+ */
343+
344+#include <config.h>
345+#include <gmock/gmock.h>
346+
347+#include <UnityCore/GLibWrapper.h>
348+
349+#include "BamfLauncherIcon.h"
350+#include "unity-shared/WindowManager.h"
351+using namespace unity;
352+
353+namespace
354+{
355+
356+class TestBamfLauncherIcon : public testing::Test
357+{
358+public:
359+ virtual void SetUp()
360+ {
361+ WindowManager::SetDefault(WindowManager::Default());
362+
363+ bamf_matcher = bamf_matcher_get_default();
364+ bamf_app = bamf_matcher_get_application_for_desktop_file(bamf_matcher,
365+ BUILDDIR"/tests/data/ubuntu-software-center.desktop",
366+ TRUE);
367+
368+ usc_icon = new launcher::BamfLauncherIcon(bamf_app);
369+
370+ }
371+
372+ virtual void TearDown()
373+ {
374+ }
375+
376+ glib::Object<BamfMatcher> bamf_matcher;
377+ BamfApplication* bamf_app;
378+ nux::ObjectPtr<launcher::BamfLauncherIcon> usc_icon;
379+
380+};
381+
382+TEST_F(TestBamfLauncherIcon, TestCustomBackgroundColor)
383+{
384+ nux::Color const& color = usc_icon->BackgroundColor();
385+
386+ EXPECT_EQ(color.red, 0xaa / 255.0f);
387+ EXPECT_EQ(color.green, 0xbb / 255.0f);
388+ EXPECT_EQ(color.blue, 0xcc / 255.0f);
389+ EXPECT_EQ(color.alpha, 0xff / 255.0f);
390+}
391+
392+}
393
394=== modified file 'tests/test_desktop_utilities.cpp'
395--- tests/test_desktop_utilities.cpp 2012-03-31 10:31:01 +0000
396+++ tests/test_desktop_utilities.cpp 2012-06-06 16:00:26 +0000
397@@ -16,8 +16,11 @@
398 *
399 * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
400 * Tim Penhey <tim.penhey@canonical.com>
401+ * Andrea Azzarone <azzarone@gmail.com>
402 */
403
404+#include <config.h>
405+
406 #include <UnityCore/DesktopUtilities.h>
407
408 #include <glib.h>
409@@ -135,4 +138,25 @@
410 EXPECT_THAT(data_dirs[4], Eq("UnityUserConfig"));
411 }
412
413+TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColor)
414+{
415+ std::string const& color = DesktopUtilities::GetBackgroundColor(BUILDDIR"/tests/data/ubuntu-software-center.desktop");
416+
417+ EXPECT_EQ(color, "#aabbcc");
418+}
419+
420+TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColorNoKey)
421+{
422+ std::string const& color = DesktopUtilities::GetBackgroundColor(BUILDDIR"/tests/data/update-manager.desktop");
423+
424+ EXPECT_TRUE(color.empty());
425+}
426+
427+TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColorNoFile)
428+{
429+ std::string const& color = DesktopUtilities::GetBackgroundColor("hello-world.desktop");
430+
431+ EXPECT_TRUE(color.empty());
432+}
433+
434 } // anonymous namespace
435
436=== modified file 'tests/test_main.cpp'
437--- tests/test_main.cpp 2012-05-15 18:54:33 +0000
438+++ tests/test_main.cpp 2012-06-06 16:00:26 +0000
439@@ -1,12 +1,13 @@
440 #include <gtest/gtest.h>
441 #include <gio/gio.h>
442+#include <gtk/gtk.h>
443 #include <NuxCore/Logger.h>
444 #include <Nux/Nux.h>
445
446 int main(int argc, char** argv)
447 {
448 ::testing::InitGoogleTest(&argc, argv);
449- g_type_init();
450+ gtk_init(&argc, &argv);
451
452 nux::NuxInitialize (0);
453 nux::WindowThread* wnd_thread = nux::CreateNuxWindow("Tests", 300, 200, nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
454
455=== modified file 'unity-shared/IconTextureSource.h'
456--- unity-shared/IconTextureSource.h 2012-05-07 00:49:31 +0000
457+++ unity-shared/IconTextureSource.h 2012-06-06 16:00:26 +0000
458@@ -49,7 +49,7 @@
459
460 std::vector<nux::Vector4> & GetTransform(TransformIndex index, int monitor);
461
462- virtual nux::Color BackgroundColor() = 0;
463+ virtual nux::Color BackgroundColor() const = 0;
464
465 virtual nux::Color GlowColor() = 0;
466