Merge lp:~mvo/unity/sc-launcher-integration-fixes into lp:unity

Proposed by Michael Vogt
Status: Merged
Approved by: Michael Terry
Approved revision: no longer in the source branch.
Merged at revision: 2974
Proposed branch: lp:~mvo/unity/sc-launcher-integration-fixes
Merge into: lp:unity
Diff against target: 491 lines (+234/-27)
11 files modified
launcher/ApplicationLauncherIcon.cpp (+8/-3)
launcher/ApplicationLauncherIcon.h (+7/-4)
launcher/LauncherIcon.cpp (+5/-3)
launcher/SoftwareCenterLauncherIcon.cpp (+82/-1)
launcher/SoftwareCenterLauncherIcon.h (+2/-2)
po/unity.pot (+1/-1)
tests/CMakeLists.txt (+5/-1)
tests/data/applications/kde4/afile.desktop (+37/-0)
tests/test_main.cpp (+8/-0)
tests/test_software_center_launcher_icon.cpp (+78/-12)
unity-shared/DebugDBusInterface.cpp (+1/-0)
To merge this branch: bzr merge lp:~mvo/unity/sc-launcher-integration-fixes
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Michael Vogt (community) Needs Resubmitting
PS Jenkins bot continuous-integration Pending
Review via email: mp+134931@code.launchpad.net

Commit message

Software center launcher integration fixes. This will setup the correct desktop file when software-center applications "fly" into the launcher.

Description of the change

This branch adds support for "native" software center unity launcher integration.

This means that when a application is installed via software-center (and soon via the dash) the icon of
that application will "fly" into the launcher and the launcher will track progress. Once the application
is installed the "temp" desktop file is replaced with the "real" desktop file of the installed app.

The reason this swapping needs to be done is to ensure that unity tracks the real application and not
the copy from app-install-data-ubuntu, e.g. to ensure that on uninstall the application is removed.

I would appreciated a initial review and feedback on this as I had to change bit in "ApplicationLauncherIcon"
from private to protected to make it possible to update the data from SoftwareCenterLauncherIcon.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Setting to Needs-review now to get feedback and get it merged if its good. There will be another
branch on top of this one that adds support for installs from software-center-agent.

Revision history for this message
Michael Vogt (mvo) wrote :

Trevinho was kind enough to give me some feedback on irc that I want to address here :)

<Trevinho> mvo: another thing.. instead of adding FRIEND_TEST(TestSoftwareCenterLauncherIcon, DesktopFileTransformTrivial); and making unity directly depending on gtest when building, just mock the class in the tests so that you cana ccess to protected members (or, just add a friend class TestSoftwareCenterLauncherIcon; definition in the header)

I looked at this now and gtest_prod.h is very lean and basicly is just the lines:
  #define FRIEND_TEST(test_case_name, test_name) friend class test_case_name##_##test_name##_Test
So it should be fine to include it even in the production code. Plus there is a build-dependency on libgtest-dev already so that should be ok too (as long as I'm not overlooking anything else).

Revision history for this message
Michael Vogt (mvo) wrote :

I added another test now and look forward to feedback. From my POV its merge-able now, but of course I'm happy to fix any issues.

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

> I looked at this now and gtest_prod.h is very lean and basicly is just the
> lines:
> #define FRIEND_TEST(test_case_name, test_name) friend class
> test_case_name##_##test_name##_Test
> So it should be fine to include it even in the production code. Plus there is
> a build-dependency on libgtest-dev already so that should be ok too (as long
> as I'm not overlooking anything else).

Yeah, but considering how is defined... I really prefer if you get rid of these macros and you just add at the end of the class a "friend class TestSoftwareCenterLauncherIcon" declaration. It's the same but cleaner (and it's how we're used to do in general) :)

The main thing I'd like to be changed, is the apt daemon to send a desktop-id instead, so that you can simply use DesktopUtilities::GetDesktopPathById in GetActualDesktopFileAfterInstall

review: Needs Fixing
Revision history for this message
Michael Vogt (mvo) wrote :

Hi Marco,

thanks for your review!

On Thu, Nov 22, 2012 at 02:14:30PM -0000, Marco Trevisan (Treviño) wrote:
> Review: Needs Fixing
>
> > I looked at this now and gtest_prod.h is very lean and basicly is just the
> > lines:
> > #define FRIEND_TEST(test_case_name, test_name) friend class
> > test_case_name##_##test_name##_Test
> > So it should be fine to include it even in the production code. Plus there is
> > a build-dependency on libgtest-dev already so that should be ok too (as long
> > as I'm not overlooking anything else).
>
> Yeah, but considering how is defined... I really prefer if you get rid of these macros and you just add at the end of the class a "friend class TestSoftwareCenterLauncherIcon" declaration. It's the same but cleaner (and it's how we're used to do in general) :)

Thanks for this explaination. I fixed this now in r2916 to use a Mock
instead of the FRIEND_TEST().

> The main thing I'd like to be changed, is the apt daemon to send a desktop-id instead, so that you can simply use DesktopUtilities::GetDesktopPathById in GetActualDesktopFileAfterInstall

I'm not sure I understand this (but I'm pretty new to unity, so that
is ok I hope :). The daemon will send a temp desktop file at first
because the real desktop file is not installed yet. That might be
/tmp/software-center-agent:dsfdsafdsaf:meep.desktop. So sending the
desktop-id would be sending
application:///tmp/software-center-agent:dsfdsafdsaf:meep.desktop
AIUI? Given that its a temp name and not in the xdg path it would
still send the full path? Or are you suggesting that it should create
the temp desktop file in a xdg .local dir?

Once the app is installed, the GetActualDesktopFileAfterInstall() will
take the rfind(":") part ("meep.desktop") and make that
/usr/share/applications/meep.desktop. At this point it would be
application://meep.desktop. But it needs to be the one in
/usr/share/applications because if its a temp/local one it won't go
away on remove of the application.

Could you please help me understanding how I should use
GetDesktopPathById() or how it will help here?

Thanks!,
 Michael

Revision history for this message
Michael Vogt (mvo) wrote :

From irc (just so that its recorded here):

<Trevinho> mvo: gave a look.. Basically I mean that once you've installed the app, then you can make apt to send to unity the desktop id of the new file... So this means "/tmp/software-center-agent:desktop-id.desktop" for instance... At this point you don't need to do all the manual search you're doing to get from it the real path... Just get the id substring and use the utility function
<mvo> Trevinho: ok, so that would mean that there needs to be a new dbus call for unity, right? to replace a existing launcher icon (the temp one that is just valid during the install) with the new one?
<Trevinho> mvo: imho that would be better, so that you can keep all the low level stuff there
<Trevinho> whie unity will be just informed with the actual result
<Trevinho> mvo: or just pass that during the "On-Finished" signal...
<mvo> Trevinho: ok, I will think about it
<Trevinho> mvo: but if you don't want to do that, it's fine to use the current way, but use the utility function for doing the real parsing
<mvo> Trevinho: ok, thanks. I would prefer to leave it as is for now, but I will use the utility function

I started working on this now but so far did not succeed to update the tests as for some reason XDG_DATA_HOME pointing to the local builddir is not quite working, I will keep poking at it.

Revision history for this message
Michael Vogt (mvo) wrote :

I figured out why setting XDG_DATA_HOME is not working reliable in my tests. Gio/Glib will setup its internal search path just once (see gio/gdesktopappinfo.c:get_appplications_search_path()) and cache it then.

But DesktopUtilities::GetDataDirectories()/GetSystemDataDirectories() does not do that. Which leads to confusing behaviour, i.e. when using g_desktop_app_info_new_* the dirs are only respected once in the tests, but all other code in the DesktopUtilities is honoring a more dynamic update approach.

Revision history for this message
Michael Vogt (mvo) wrote :

I see two ways around this:
- init the XDG_DATA_DIRS env very early globally (and hope that it does not break other stuff)
- reimplement g_desktop_app_info_new() inside GetDesktopPathById() to do the searching manually and then using g_desktop_app_info_new_from_filename()
(simply drop the tests, but that sounds like not exactly a good idea ;)

Feedback welcome.

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

> I see two ways around this:
> - init the XDG_DATA_DIRS env very early globally (and hope that it does not
> break other stuff)

Yeah, probably this is the best solution... I think we already moved the test .desktop files to a proper position, so it should be fine to just init this value in test_main*

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks again Marco!

I updated the code now to use DesktopUtilities::GetDesktopPathByID() and updated the tests and moved the init of the XDG_DATA_DIRS into test_main.cpp. Both the automatic tests and manual tests with applications from app-install-data-ubuntu and from purchases in the software-center work for me now with animation, update on finish to the right app and error handling (i.e. removal on cancel etc).

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

35 + if (_desktop_file.find("/usr/share/app-install/desktop") == 0)
136 + {

Wouldn't better to check if it contains "/share/app-install/desktop" avoiding prefixes?

Overall looks good now, but I'm not sure this is still working with the new AppManager in trunk.

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks Marco!

I removed the fix for the prefix now and do the check as you suggested.

Now I merged in trunk and resolved the conflicts and indeed, from the look of the code I'm pretty
sure this won't work anymore as the way the application is swapped from the temp desktop file to the
new final desktop file destination has changed completely.

Given that I wonder if maybe the approach reconsidered. I like your original idea of having two dbus calls,
one for setting the "in-progress" app with progress and all and once that is finished, swapping that for the
real one. I will look into that and see how feasible this is, it seems like its a cleaner approach anyway.

Cheers,
 Michael

Revision history for this message
Michael Vogt (mvo) wrote :

This is now ready again with the new ApplicationManager framework. The tests are ported too, only the "TEST_F(TestSoftwareCenterLauncherIcon, Animate)" case is missing as DNDCollectionWindow is gone and my naive
approach of replacing it with XndCollectionWindow does not work. I will keep exploring, but would appreciate
a look at the rest of the MP again.

Revision history for this message
Michael Vogt (mvo) :
review: Needs Resubmitting
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> This is now ready again with the new ApplicationManager framework. The tests
> are ported too, only the "TEST_F(TestSoftwareCenterLauncherIcon, Animate)"
> case is missing as DNDCollectionWindow is gone and my naive
> approach of replacing it with XndCollectionWindow does not work. I will keep
> exploring, but would appreciate
> a look at the rest of the MP again.

  nux::ObjectPtr<DNDCollectionWindow> cwin(new DNDCollectionWindow);
  nux::ObjectPtr<Launcher> launcher(new Launcher(win.GetPointer(), cwin));

just do:

  nux::ObjectPtr<Launcher> launcher(new Launcher(win.GetPointer()));

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks Andrea! I updated the code and re-enabled the last test.

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

Ok, now it's fine (sorry for the delays)... :)

Before of general approving (do it yourself when you're ready), remember to set a commit message and it would be also ince if you get rid of the tabs at:
272 + test_static_cairo_text.cpp

Thanks.

review: Approve
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks Marco! Excellent news. I fixed the tab in line 272 and set a commit message. I can't approve it myself, but it should be good now. Once this is merged I will upload the corresponding software-center branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/ApplicationLauncherIcon.cpp'
2--- launcher/ApplicationLauncherIcon.cpp 2012-11-29 01:50:21 +0000
3+++ launcher/ApplicationLauncherIcon.cpp 2012-12-11 15:42:23 +0000
4@@ -973,16 +973,21 @@
5 return DesktopUtilities::GetDesktopID(desktop_file);
6 }
7
8-std::string ApplicationLauncherIcon::GetRemoteUri()
9+void ApplicationLauncherIcon::UpdateRemoteUri()
10 {
11- if (_remote_uri.empty())
12- {
13 std::string const& desktop_id = GetDesktopID();
14
15 if (!desktop_id.empty())
16 {
17 _remote_uri = FavoriteStore::URI_PREFIX_APP + desktop_id;
18 }
19+}
20+
21+std::string ApplicationLauncherIcon::GetRemoteUri()
22+{
23+ if (_remote_uri.empty())
24+ {
25+ UpdateRemoteUri();
26 }
27
28 return _remote_uri;
29
30=== modified file 'launcher/ApplicationLauncherIcon.h'
31--- launcher/ApplicationLauncherIcon.h 2012-11-27 01:09:26 +0000
32+++ launcher/ApplicationLauncherIcon.h 2012-12-11 15:42:23 +0000
33@@ -89,6 +89,12 @@
34 bool HandlesSpread() { return true; }
35 std::string GetName() const;
36
37+protected:
38+ void UpdateDesktopFile();
39+ void UpdateRemoteUri();
40+ std::string _desktop_file;
41+ ApplicationPtr app_;
42+
43 private:
44 typedef unsigned long int WindowFilterMask;
45 enum WindowFilter
46@@ -102,7 +108,6 @@
47 void EnsureWindowState();
48 void EnsureMenuItemsReady();
49 void UpdateBackgroundColor();
50- void UpdateDesktopFile();
51 void UpdateMenus();
52 void UpdateDesktopQuickList();
53
54@@ -117,10 +122,8 @@
55 const std::set<std::string> GetSupportedTypes();
56 std::string GetDesktopID();
57
58- ApplicationPtr app_;
59-
60 std::string _remote_uri;
61- std::string _desktop_file;
62+ std::set<std::string> _supported_types;
63 std::map<std::string, glib::Object<DbusmenuClient>> _menu_clients;
64 std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items;
65 std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items_extra;
66
67=== modified file 'launcher/LauncherIcon.cpp'
68--- launcher/LauncherIcon.cpp 2012-12-03 15:34:23 +0000
69+++ launcher/LauncherIcon.cpp 2012-12-11 15:42:23 +0000
70@@ -1193,14 +1193,16 @@
71
72 void LauncherIcon::Stick(bool save)
73 {
74+ // allow save() even for already "_sticky" icons that may have been
75+ // made _sticky without "save" (like SoftwareCenterApplications)
76+ if (save)
77+ position_saved.emit();
78+
79 if (_sticky)
80 return;
81
82 _sticky = true;
83
84- if (save)
85- position_saved.emit();
86-
87 SetQuirk(Quirk::VISIBLE, true);
88 }
89
90
91=== modified file 'launcher/SoftwareCenterLauncherIcon.cpp'
92--- launcher/SoftwareCenterLauncherIcon.cpp 2012-11-28 22:05:07 +0000
93+++ launcher/SoftwareCenterLauncherIcon.cpp 2012-12-11 15:42:23 +0000
94@@ -16,15 +16,19 @@
95 *
96 * Authored by: Bilal Akhtar <bilalakhtar@ubuntu.com>
97 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
98+ * Michael Vogt <mvo@ubuntu.com>
99 */
100
101+#include "config.h"
102+
103 #include <NuxCore/Logger.h>
104-#include "config.h"
105+#include <glib.h>
106 #include <glib/gi18n-lib.h>
107 #include "SoftwareCenterLauncherIcon.h"
108 #include "Launcher.h"
109 #include "LauncherDragWindow.h"
110 #include "LauncherModel.h"
111+#include "DesktopUtilities.h"
112
113 namespace unity
114 {
115@@ -69,6 +73,14 @@
116 {
117 launcher_ = launcher;
118
119+ // FIXME: this needs testing, if there is no useful coordinates
120+ // then do not animate
121+ if(start_x <= 0 && start_y <= 0)
122+ {
123+ SetQuirk(Quirk::VISIBLE, true);
124+ return;
125+ }
126+
127 icon_texture_ = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(
128 launcher->GetWidth(),
129 launcher->GetWidth(),
130@@ -118,6 +130,63 @@
131 }
132 }
133
134+std::string SoftwareCenterLauncherIcon::GetActualDesktopFileAfterInstall()
135+{
136+ // Fixup the _desktop_file because the one we get from software-center
137+ // is not the final one, e.g. the s-c-agent does send a temp one and
138+ // app-install-data points to the "wrong" one in /usr/share/app-install
139+ //
140+ // So:
141+ // - if there is a desktop file already and it startswith
142+ // /usr/share/app-install/desktop, then transform to
143+ // /usr/share/application
144+ // - if there is a desktop file with prefix /tmp/software-center-agent:
145+ // transform to /usr/share/application
146+ // (its using "/tmp/software-center-agent:$random:$pkgname.desktop")
147+ // maybe:
148+ // - and search in /var/lib/apt/lists/$pkgname.list
149+ // for a desktop file that roughly matches what we want
150+ std::string filename = _desktop_file;
151+
152+ // take /usr/share/app-install/desktop/foo:subdir__bar.desktop
153+ // and tranform it
154+ if (_desktop_file.find("/share/app-install/desktop/") != std::string::npos)
155+ {
156+ filename = filename.substr(filename.rfind(":") + 1,
157+ filename.length() - filename.rfind(":"));
158+ // the app-install-data package encodes subdirs in a funny way, once
159+ // that is fixed, this code can be dropped
160+ if (filename.find("__") != std::string::npos)
161+ {
162+ int pos = filename.find("__");
163+ filename = filename.replace(pos, 2, "-");
164+ }
165+ filename = DesktopUtilities::GetDesktopPathById(filename);
166+ return filename;
167+ }
168+ else if (_desktop_file.find("/tmp/software-center-agent:") == 0)
169+ {
170+ // by convention the software-center-agent uses
171+ // /usr/share/applications/$pkgname.desktop
172+ // or
173+ // /usr/share/applications/extras-$pkgname.desktop
174+ std::string desktopf = filename.substr(filename.rfind(":") + 1,
175+ filename.length() - filename.rfind(":"));
176+ filename = DesktopUtilities::GetDesktopPathById(desktopf);
177+ if (filename.size() > 0)
178+ return filename;
179+ // now try extras-$pkgname.desktop
180+ filename = DesktopUtilities::GetDesktopPathById(std::string("extras-") + desktopf);
181+ if (filename.size() > 0)
182+ return filename;
183+
184+ // FIXME: test if there is a file now and if not, search
185+ // /var/lib/dpkg/info/$pkgname.list for a desktop file
186+ }
187+
188+ return _desktop_file;
189+}
190+
191 void SoftwareCenterLauncherIcon::OnFinished(GVariant *params)
192 {
193 glib::String exit_state;
194@@ -132,6 +201,18 @@
195 finished_ = true;
196 needs_urgent_ = true;
197
198+ // find and update to the real desktop file
199+ std::string new_desktop_path = GetActualDesktopFileAfterInstall();
200+
201+ // exchange the temp Application with the real one
202+ app_ = ApplicationManager::Default().GetApplicationForDesktopFile(new_desktop_path);
203+
204+ UpdateDesktopFile();
205+ UpdateRemoteUri();
206+
207+ // make it permanent
208+ Stick(true);
209+
210 _source_manager.AddIdle([this]()
211 {
212 ShowTooltip();
213
214=== modified file 'launcher/SoftwareCenterLauncherIcon.h'
215--- launcher/SoftwareCenterLauncherIcon.h 2012-11-23 04:05:35 +0000
216+++ launcher/SoftwareCenterLauncherIcon.h 2012-12-11 15:42:23 +0000
217@@ -47,11 +47,12 @@
218 std::string GetName() const;
219
220 protected:
221+ std::string GetActualDesktopFileAfterInstall();
222 void ActivateLauncherIcon(ActionArg arg);
223+ void OnFinished(GVariant *params);
224
225 private:
226 void OnPropertyChanged(GVariant* params);
227- void OnFinished(GVariant *params);
228 void OnDragAnimationFinished();
229
230 glib::DBusProxy aptdaemon_trans_;
231@@ -61,7 +62,6 @@
232 nux::ObjectPtr<Launcher> launcher_;
233 bool finished_;
234 bool needs_urgent_;
235-
236 std::string aptdaemon_trans_id_;
237 std::string app_title_;
238 };
239
240=== modified file 'po/unity.pot'
241--- po/unity.pot 2012-11-08 16:49:26 +0000
242+++ po/unity.pot 2012-12-11 15:42:23 +0000
243@@ -8,7 +8,7 @@
244 msgstr ""
245 "Project-Id-Version: PACKAGE VERSION\n"
246 "Report-Msgid-Bugs-To: ayatana-dev@lists.launchpad.net\n"
247-"POT-Creation-Date: 2012-11-08 12:05+0000\n"
248+"POT-Creation-Date: 2012-12-05 10:41+0100\n"
249 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
250 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
251 "Language-Team: LANGUAGE <LL@li.org>\n"
252
253=== modified file 'tests/CMakeLists.txt'
254--- tests/CMakeLists.txt 2012-12-11 02:33:06 +0000
255+++ tests/CMakeLists.txt 2012-12-11 15:42:23 +0000
256@@ -13,6 +13,9 @@
257 ${CMAKE_BINARY_DIR}/tests/data/applications/bzr-handle-patch.desktop)
258 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/no-icon.desktop
259 ${CMAKE_BINARY_DIR}/tests/data/applications/no-icon.desktop)
260+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/kde4/afile.desktop
261+ ${CMAKE_BINARY_DIR}/tests/data/applications/kde4/afile.desktop)
262+
263 #
264 # Unit tests
265 #
266@@ -237,7 +240,8 @@
267 test_single_monitor_launcher_icon.cpp
268 test_expo_launcher_icon.cpp
269 test_showdesktop_handler.cpp
270- test_static_cairo_text.cpp
271+ test_software_center_launcher_icon.cpp
272+ test_static_cairo_text.cpp
273 test_switcher_controller.cpp
274 test_switcher_model.cpp
275 test_texture_cache.cpp
276
277=== added directory 'tests/data/applications/kde4'
278=== added file 'tests/data/applications/kde4/afile.desktop'
279--- tests/data/applications/kde4/afile.desktop 1970-01-01 00:00:00 +0000
280+++ tests/data/applications/kde4/afile.desktop 2012-12-11 15:42:23 +0000
281@@ -0,0 +1,37 @@
282+[Desktop Entry]
283+X-AppInstall-Package=gedit
284+X-AppInstall-Popcon=78622
285+X-AppInstall-Section=main
286+
287+Name=gedit
288+GenericName=Text Editor
289+Comment=Edit text files
290+Exec=gedit %U
291+Terminal=false
292+Type=Application
293+StartupNotify=true
294+MimeType=text/plain;
295+Icon=accessories-text-editor
296+Categories=GNOME;GTK;Utility;TextEditor;
297+X-GNOME-DocPath=gedit/gedit.xml
298+X-GNOME-FullName=Text Editor
299+X-GNOME-Bugzilla-Bugzilla=GNOME
300+X-GNOME-Bugzilla-Product=gedit
301+X-GNOME-Bugzilla-Component=general
302+X-GNOME-Bugzilla-Version=3.6.0
303+X-GNOME-Bugzilla-ExtraInfoScript=/usr/share/gedit/gedit-bugreport
304+Actions=Window;Document;
305+Keywords=Text;Plaintext;Write;
306+
307+
308+[Desktop Action Window]
309+Name=Open a New Window
310+Exec=gedit --new-window
311+OnlyShowIn=Unity;
312+
313+[Desktop Action Document]
314+Name=Open a New Document
315+Exec=gedit --new-document
316+OnlyShowIn=Unity;
317+
318+X-Ubuntu-Gettext-Domain=app-install-data
319
320=== modified file 'tests/test_main.cpp'
321--- tests/test_main.cpp 2012-11-28 02:00:04 +0000
322+++ tests/test_main.cpp 2012-12-11 15:42:23 +0000
323@@ -3,12 +3,20 @@
324 #include <gtk/gtk.h>
325 #include <NuxCore/Logger.h>
326 #include <Nux/Nux.h>
327+#include <config.h>
328
329 #include "logger_helper.h"
330
331 int main(int argc, char** argv)
332 {
333 ::testing::InitGoogleTest(&argc, argv);
334+
335+ // init XDG_DATA_DIRS before GTK to point to the local test-dir as
336+ // the environment is only read once by glib and then cached
337+ const std::string LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
338+ g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR.c_str(), TRUE);
339+
340+
341 gtk_init(&argc, &argv);
342 setlocale(LC_ALL, "C");
343
344
345=== modified file 'tests/test_software_center_launcher_icon.cpp'
346--- tests/test_software_center_launcher_icon.cpp 2012-09-18 15:47:49 +0000
347+++ tests/test_software_center_launcher_icon.cpp 2012-12-11 15:42:23 +0000
348@@ -15,11 +15,16 @@
349 * <http://www.gnu.org/licenses/>
350 *
351 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
352+ * Michael Vogt <mvo@ubuntu.com>
353+ *
354+ * Run standalone with:
355+ * cd build && make test-gtest && ./test-gtest --gtest_filter=TestSoftwareCenterLauncherIcon.*
356 */
357
358 #include <config.h>
359 #include <gmock/gmock.h>
360
361+#include "ApplicationManager.h"
362 #include "SoftwareCenterLauncherIcon.h"
363 #include "Launcher.h"
364 #include "PanelStyle.h"
365@@ -29,28 +34,88 @@
366 using namespace unity;
367 using namespace unity::launcher;
368
369-namespace
370-{
371-const std::string USC_DESKTOP = BUILDDIR"/tests/data/applications/ubuntu-software-center.desktop";
372+namespace unity
373+{
374+namespace launcher
375+{
376+const std::string LOCAL_DATA_DIR = BUILDDIR"/tests/data";
377+const std::string USC_DESKTOP = LOCAL_DATA_DIR+"/applications/ubuntu-software-center.desktop";
378+
379+class MockSoftwareCenterLauncherIcon : public SoftwareCenterLauncherIcon
380+{
381+public:
382+ MockSoftwareCenterLauncherIcon(ApplicationPtr const& app,
383+ std::string const& aptdaemon_trans_id,
384+ std::string const& icon_path)
385+ : SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path)
386+ {}
387+
388+ using SoftwareCenterLauncherIcon::GetActualDesktopFileAfterInstall;
389+ using SoftwareCenterLauncherIcon::_desktop_file;
390+ using SoftwareCenterLauncherIcon::GetRemoteUri;
391+ using SoftwareCenterLauncherIcon::OnFinished;
392+
393+};
394
395 struct TestSoftwareCenterLauncherIcon : testing::Test
396 {
397+public:
398 TestSoftwareCenterLauncherIcon()
399- : bamf_matcher(bamf_matcher_get_default())
400- , usc(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), TRUE), glib::AddRef())
401- , icon(usc, "", "")
402+ : usc(ApplicationManager::Default().GetApplicationForDesktopFile(USC_DESKTOP))
403+ , icon(usc, "", "")
404 {}
405
406- glib::Object<BamfMatcher> bamf_matcher;
407- glib::Object<BamfApplication> usc;
408- SoftwareCenterLauncherIcon icon;
409+ ApplicationPtr usc;
410+ MockSoftwareCenterLauncherIcon icon;
411 };
412
413 TEST_F(TestSoftwareCenterLauncherIcon, Construction)
414 {
415 EXPECT_FALSE(icon.IsVisible());
416 EXPECT_EQ(icon.position(), AbstractLauncherIcon::Position::FLOATING);
417- EXPECT_EQ(icon.tooltip_text(), bamf_view_get_name(glib::object_cast<BamfView>(usc)));
418+ EXPECT_EQ(icon.tooltip_text(), usc->title());
419+}
420+
421+TEST_F(TestSoftwareCenterLauncherIcon, DesktopFileTransformTrivial)
422+{
423+ // no transformation needed
424+ EXPECT_EQ(icon.GetActualDesktopFileAfterInstall(), USC_DESKTOP);
425+}
426+
427+TEST_F(TestSoftwareCenterLauncherIcon, DesktopFileTransformAppInstall)
428+{
429+ // ensure that tranformation from app-install data desktop files works
430+ icon._desktop_file = "/usr/share/app-install/desktop/pkgname:kde4__afile.desktop";
431+ EXPECT_EQ(icon.GetActualDesktopFileAfterInstall(),
432+ BUILDDIR"/tests/data/applications/kde4/afile.desktop");
433+}
434+
435+TEST_F(TestSoftwareCenterLauncherIcon, DesktopFileTransformSCAgent)
436+{
437+ // now simualte data coming from the sc-agent
438+ icon._desktop_file = "/tmp/software-center-agent:VP2W9M:ubuntu-software-center.desktop";
439+ EXPECT_EQ(icon.GetActualDesktopFileAfterInstall(), USC_DESKTOP);
440+}
441+
442+// simulate a OnFinished signal from a /usr/share/app-install location
443+// and ensure that the remote uri is updated from temp location to
444+// the real location
445+TEST_F(TestSoftwareCenterLauncherIcon, OnFinished)
446+{
447+
448+ // simulate desktop file from app-install-data
449+ icon._desktop_file = "/usr/share/app-install/desktop/software-center:ubuntu-software-center.desktop";
450+
451+ // now simulate that the install was successful
452+ GVariant *params = g_variant_new("(s)", "exit-success");
453+ icon.OnFinished(params);
454+
455+ // and verify that both the desktop file and the remote uri gets updated
456+ EXPECT_EQ(icon._desktop_file, USC_DESKTOP);
457+ EXPECT_EQ(icon.GetRemoteUri(),
458+ "application://ubuntu-software-center.desktop");
459+
460+ g_variant_unref(params);
461 }
462
463 TEST_F(TestSoftwareCenterLauncherIcon, Animate)
464@@ -60,8 +125,7 @@
465 Settings settings;
466 panel::Style panel;
467 nux::ObjectPtr<nux::BaseWindow> win(new nux::BaseWindow(""));
468- nux::ObjectPtr<DNDCollectionWindow> cwin(new DNDCollectionWindow);
469- nux::ObjectPtr<Launcher> launcher(new Launcher(win.GetPointer(), cwin));
470+ nux::ObjectPtr<Launcher> launcher(new Launcher(win.GetPointer()));
471 launcher->options = Options::Ptr(new Options);
472 launcher->SetModel(LauncherModel::Ptr(new LauncherModel));
473
474@@ -72,3 +136,5 @@
475 }
476
477 }
478+
479+}
480
481=== modified file 'unity-shared/DebugDBusInterface.cpp'
482--- unity-shared/DebugDBusInterface.cpp 2012-11-22 11:21:27 +0000
483+++ unity-shared/DebugDBusInterface.cpp 2012-12-11 15:42:23 +0000
484@@ -21,6 +21,7 @@
485 #include <iostream>
486 #include <fstream>
487 #include <sstream>
488+#include <iostream>
489 #include <boost/algorithm/string.hpp>
490 #include <boost/algorithm/string/split.hpp>
491 #include <boost/algorithm/string/classification.hpp>