Merge lp:~3v1n0/unity/launcher-draggable-icons-6.0 into lp:unity/6.0

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2692
Proposed branch: lp:~3v1n0/unity/launcher-draggable-icons-6.0
Merge into: lp:unity/6.0
Diff against target: 7558 lines (+3857/-1097)
72 files modified
UnityCore/DesktopUtilities.cpp (+29/-9)
UnityCore/DesktopUtilities.h (+1/-0)
UnityCore/GLibDBusProxy.cpp (+0/-4)
com.canonical.Unity.gschema.xml (+3/-3)
launcher/AbstractLauncherIcon.h (+16/-2)
launcher/BFBLauncherIcon.cpp (+1/-0)
launcher/BamfLauncherIcon.cpp (+31/-48)
launcher/BamfLauncherIcon.h (+0/-1)
launcher/CMakeLists.txt (+1/-0)
launcher/DesktopLauncherIcon.cpp (+19/-6)
launcher/DesktopLauncherIcon.h (+4/-12)
launcher/DeviceLauncherSection.cpp (+14/-7)
launcher/DeviceLauncherSection.h (+3/-5)
launcher/DndData.cpp (+5/-5)
launcher/DndData.h (+1/-1)
launcher/ExpoLauncherIcon.cpp (+64/-0)
launcher/ExpoLauncherIcon.h (+45/-0)
launcher/FavoriteStore.cpp (+93/-4)
launcher/FavoriteStore.h (+21/-8)
launcher/FavoriteStoreGSettings.cpp (+67/-68)
launcher/FavoriteStoreGSettings.h (+7/-4)
launcher/FavoriteStorePrivate.cpp (+14/-0)
launcher/FavoriteStorePrivate.h (+3/-1)
launcher/HudLauncherIcon.cpp (+2/-1)
launcher/Launcher.cpp (+83/-108)
launcher/Launcher.h (+5/-8)
launcher/LauncherController.cpp (+526/-341)
launcher/LauncherController.h (+1/-3)
launcher/LauncherControllerPrivate.h (+28/-41)
launcher/LauncherIcon.cpp (+31/-4)
launcher/LauncherIcon.h (+5/-9)
launcher/LauncherModel.cpp (+34/-32)
launcher/MockLauncherIcon.h (+11/-15)
launcher/SoftwareCenterLauncherIcon.cpp (+27/-38)
launcher/SoftwareCenterLauncherIcon.h (+1/-1)
launcher/SpacerLauncherIcon.cpp (+1/-1)
launcher/SpacerLauncherIcon.h (+0/-4)
launcher/StandaloneLauncher.cpp (+1/-1)
launcher/TrashLauncherIcon.cpp (+1/-0)
launcher/VolumeLauncherIcon.cpp (+34/-4)
launcher/VolumeLauncherIcon.h (+3/-0)
manual-tests/Launcher.txt (+15/-0)
panel/PanelMenuView.h (+0/-1)
plugins/unityshell/src/unityshell.cpp (+5/-7)
plugins/unityshell/unityshell.xml.in (+0/-6)
tests/CMakeLists.txt (+19/-11)
tests/gmockvolume.c (+4/-3)
tests/test_bamf_launcher_icon.cpp (+70/-2)
tests/test_bfb_launcher_icon.cpp (+11/-8)
tests/test_desktop_launcher_icon.cpp (+80/-0)
tests/test_desktop_utilities.cpp (+52/-22)
tests/test_device_launcher_section.cpp (+19/-54)
tests/test_expo_launcher_icon.cpp (+58/-0)
tests/test_favorite_store.cpp (+111/-0)
tests/test_favorite_store_gsettings.cpp (+52/-29)
tests/test_hud_launcher_icon.cpp (+53/-0)
tests/test_launcher.cpp (+226/-15)
tests/test_launcher_controller.cpp (+1246/-44)
tests/test_launcher_icon.cpp (+113/-0)
tests/test_launcher_model.cpp (+182/-40)
tests/test_main.cpp (+1/-0)
tests/test_main_xless.cpp (+1/-1)
tests/test_mock_devices.h (+93/-0)
tests/test_software_center_launcher_icon.cpp (+74/-0)
tests/test_trash_launcher_icon.cpp (+39/-0)
tests/test_volume_launcher_icon.cpp (+67/-46)
unity-shared/PluginAdapter.h (+2/-0)
unity-shared/PluginAdapterCompiz.cpp (+5/-0)
unity-shared/PluginAdapterStandalone.cpp (+15/-7)
unity-shared/WindowManager.cpp (+5/-0)
unity-shared/WindowManager.h (+1/-0)
unity-standalone/StandaloneUnity.cpp (+2/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/launcher-draggable-icons-6.0
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Brandon Schaefer (community) Approve
Review via email: mp+124838@code.launchpad.net

Commit message

LauncherController, FavoriteStore, Launcher, Icons: always use sort priority based on favorites to get positioned on launcher

This is the continuum of the work started in lp:~3v1n0/unity/keep-priority-launcher-model, here we use the launcher icons priority to correctly order the icons in the launcher, based on the position that they have in the favorite store.

The unity launcher favorite store now handles not only desktop paths or id but also (mostly) icons uris (such as application://desktop-id or unity://desktop-icon or device://uuid); these values are used by LauncherController to dispose these icons in the launchers.

To do this, I had to change AbstractLauncherIcon to define a position property that now LauncherModel uses together with the icon priority (that is now set by default to the icon type but then can change during the usage, or based on favorites).

The icons ordering has changed a lot: now the favorites control everything (except BFB and trash) and we add the icons based on their defined position. Added two special places: "unity://running-apps" and "unity://devices" that optionally defines where these kind of icons should be placed. This is not strict by the way, because if these uris are not defined we add them by default at the bottom of the launcher main model.

When a new Device or Application icon is added to the launcher, we append it to the list of the non-sticky devices or applications.

Favorites reordering, removal or additions have been refactored to fit to our new system; when we save the favorites, the position of the "running-apps" or "attached-devices" is computed based on where the first icon of this type is placed.

The expo icon is handled differently, since it is not added if we have no workspaces available; it also updates its visibility based on the workspaces settings.

SoftwareCenterLauncher icons are now handled differently: we now fully consider them as sticky application icons, so we firstly add them to the model (setting their priority based on the last sticky icon we have), then we animate them. They already know where they should go, based on model calculations (also fixed a bug that caused them not to get the overlay shourtcut when added).

See other commit messages for more info, they should be quite comprehensive.

----

Testing: updated and added a lot of new unit tests to cover (hopefully) all the changes I've done (that's mostly why this diff is so big, since the real changes are less than the half of the changed code) and to test the areas that we never tested before, just few stats:

test-gtest: added 13 new test cases (+5%)
test-gtest-xless: added 94 new test cases (+56%)

Description of the change

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Looks go to me. +1

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

Approve as discussed on IRC.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1337/console reported an error when processing this lp:~3v1n0/unity/launcher-draggable-icons-6.0 branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/DesktopUtilities.cpp'
--- UnityCore/DesktopUtilities.cpp 2012-06-01 09:33:15 +0000
+++ UnityCore/DesktopUtilities.cpp 2012-09-18 15:52:46 +0000
@@ -19,8 +19,10 @@
19*/19*/
2020
21#include <algorithm>21#include <algorithm>
22#include <memory>
2223
23#include <glib.h>24#include <glib.h>
25#include <gio/gdesktopappinfo.h>
2426
25#include "DesktopUtilities.h"27#include "DesktopUtilities.h"
26#include "GLibWrapper.h"28#include "GLibWrapper.h"
@@ -119,23 +121,41 @@
119 return GetDesktopID(data_dirs, desktop_path);121 return GetDesktopID(data_dirs, desktop_path);
120}122}
121123
124std::string DesktopUtilities::GetDesktopPathById(std::string const& desktop_id)
125{
126 if (desktop_id.empty())
127 return "";
128
129 glib::Object<GDesktopAppInfo> info;
130
131 if (desktop_id.find(G_DIR_SEPARATOR_S) != std::string::npos)
132 info = g_desktop_app_info_new_from_filename(desktop_id.c_str());
133 else
134 info = g_desktop_app_info_new(desktop_id.c_str());
135
136 if (info)
137 {
138 const char* filename = g_desktop_app_info_get_filename(info);
139
140 if (filename)
141 return filename;
142 }
143
144 return "";
145}
122146
123std::string DesktopUtilities::GetBackgroundColor(std::string const& desktop_path)147std::string DesktopUtilities::GetBackgroundColor(std::string const& desktop_path)
124{148{
125 GKeyFile* key_file = g_key_file_new();149 std::shared_ptr<GKeyFile> key_file(g_key_file_new(), g_key_file_free);
126150
127 glib::Error error;151 glib::Error error;
128 g_key_file_load_from_file(key_file, desktop_path.c_str(), static_cast<GKeyFileFlags>(0), &error);152 g_key_file_load_from_file(key_file.get(), desktop_path.c_str(), static_cast<GKeyFileFlags>(0), &error);
129153
130 if (error)154 if (error)
131 {
132 g_key_file_free(key_file);
133 return "";155 return "";
134 }156
135157 glib::String value(g_key_file_get_string(key_file.get(), "Desktop Entry", "X-Unity-IconBackgroundColor", &error));
136 glib::String value(g_key_file_get_string(key_file, "Desktop Entry", "X-Unity-IconBackgroundColor", &error));158
137
138 g_key_file_free(key_file);
139 return value.Str();159 return value.Str();
140}160}
141161
142162
=== modified file 'UnityCore/DesktopUtilities.h'
--- UnityCore/DesktopUtilities.h 2012-05-25 07:37:21 +0000
+++ UnityCore/DesktopUtilities.h 2012-09-18 15:52:46 +0000
@@ -36,6 +36,7 @@
36 static std::string GetDesktopID(std::string const& desktop_path);36 static std::string GetDesktopID(std::string const& desktop_path);
37 static std::string GetDesktopID(std::vector<std::string> const& default_paths,37 static std::string GetDesktopID(std::vector<std::string> const& default_paths,
38 std::string const& desktop_path);38 std::string const& desktop_path);
39 static std::string GetDesktopPathById(std::string const& desktop_id);
3940
40 static std::string GetBackgroundColor(std::string const& desktop_path);41 static std::string GetBackgroundColor(std::string const& desktop_path);
41};42};
4243
=== modified file 'UnityCore/GLibDBusProxy.cpp'
--- UnityCore/GLibDBusProxy.cpp 2012-07-17 13:42:48 +0000
+++ UnityCore/GLibDBusProxy.cpp 2012-09-18 15:52:46 +0000
@@ -90,7 +90,6 @@
9090
91 glib::Object<GDBusProxy> proxy_;91 glib::Object<GDBusProxy> proxy_;
92 glib::Object<GCancellable> cancellable_;92 glib::Object<GCancellable> cancellable_;
93 guint watcher_id_;
94 bool connected_;93 bool connected_;
9594
96 glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> g_signal_connection_;95 glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> g_signal_connection_;
@@ -113,7 +112,6 @@
113 , bus_type_(bus_type)112 , bus_type_(bus_type)
114 , flags_(flags)113 , flags_(flags)
115 , cancellable_(g_cancellable_new())114 , cancellable_(g_cancellable_new())
116 , watcher_id_(0)
117 , connected_(false)115 , connected_(false)
118{116{
119 StartReconnectionTimeout();117 StartReconnectionTimeout();
@@ -122,8 +120,6 @@
122DBusProxy::Impl::~Impl()120DBusProxy::Impl::~Impl()
123{121{
124 g_cancellable_cancel(cancellable_);122 g_cancellable_cancel(cancellable_);
125 if (watcher_id_)
126 g_bus_unwatch_name(watcher_id_);
127}123}
128124
129void DBusProxy::Impl::StartReconnectionTimeout()125void DBusProxy::Impl::StartReconnectionTimeout()
130126
=== modified file 'com.canonical.Unity.gschema.xml'
--- com.canonical.Unity.gschema.xml 2012-08-31 09:15:33 +0000
+++ com.canonical.Unity.gschema.xml 2012-09-18 15:52:46 +0000
@@ -44,9 +44,9 @@
44 </schema>44 </schema>
45 <schema path="/com/canonical/unity/launcher/" id="com.canonical.Unity.Launcher" gettext-domain="unity">45 <schema path="/com/canonical/unity/launcher/" id="com.canonical.Unity.Launcher" gettext-domain="unity">
46 <key type="as" name="favorites">46 <key type="as" name="favorites">
47 <default>[ 'ubiquity-gtkui.desktop', 'nautilus-home.desktop', 'firefox.desktop', 'libreoffice-writer.desktop', 'libreoffice-calc.desktop', 'libreoffice-impress.desktop', 'ubuntu-software-center.desktop', 'ubuntuone-installer.desktop', 'gnome-control-center.desktop' ]</default>47 <default>[ 'application://ubiquity-gtkui.desktop', 'application://nautilus-home.desktop', 'application://firefox.desktop', 'application://libreoffice-writer.desktop', 'application://libreoffice-calc.desktop', 'application://libreoffice-impress.desktop', 'application://ubuntu-software-center.desktop', 'application://ubuntuone-installer.desktop', 'application://gnome-control-center.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices' ]</default>
48 <summary>List of desktop file ids for favorites on the launcher.</summary>48 <summary>List of items that should be shown by default in the launcher</summary>
49 <description>These applications are shown in the Launcher by default.</description>49 <description>These items can be application://desktop-id.desktop, device://uiid and unity://special-id (including unity://running-apps that specifies the position of the ran applications, unity://devices the position of the attached devices, unity://expo-icon the position of the workspace switcher and unity://show-desktop-icon the position of the show-desktop icon); the order of this list determines the launcher items position.</description>
50 </key>50 </key>
51 <key type="s" name="favorite-migration">51 <key type="s" name="favorite-migration">
52 <default>''</default>52 <default>''</default>
5353
=== modified file 'launcher/AbstractLauncherIcon.h'
--- launcher/AbstractLauncherIcon.h 2012-08-15 02:51:33 +0000
+++ launcher/AbstractLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -93,6 +93,7 @@
93 DESKTOP,93 DESKTOP,
94 PLACE,94 PLACE,
95 DEVICE,95 DEVICE,
96 SPACER,
96 TRASH,97 TRASH,
97 END98 END
98 };99 };
@@ -117,10 +118,18 @@
117 LAST118 LAST
118 };119 };
119120
121 enum class Position
122 {
123 BEGIN,
124 FLOATING,
125 END
126 };
127
120 virtual ~AbstractLauncherIcon() {}128 virtual ~AbstractLauncherIcon() {}
121129
122 nux::Property<std::string> tooltip_text;130 nux::Property<std::string> tooltip_text;
123 nux::Property<bool> tooltip_enabled;131 nux::Property<bool> tooltip_enabled;
132 nux::Property<Position> position;
124133
125 virtual void HideTooltip() = 0;134 virtual void HideTooltip() = 0;
126135
@@ -158,8 +167,6 @@
158167
159 virtual const bool WindowVisibleOnViewport() = 0;168 virtual const bool WindowVisibleOnViewport() = 0;
160169
161 virtual bool IsSpacer() = 0;
162
163 virtual float PresentUrgency() = 0;170 virtual float PresentUrgency() = 0;
164171
165 virtual float GetProgress() = 0;172 virtual float GetProgress() = 0;
@@ -211,6 +218,11 @@
211218
212 virtual void UnStick() = 0;219 virtual void UnStick() = 0;
213220
221 static int DefaultPriority(IconType type)
222 {
223 return static_cast<int>(type) * 1000;
224 }
225
214 sigc::signal<void, int, int, unsigned long> mouse_down;226 sigc::signal<void, int, int, unsigned long> mouse_down;
215 sigc::signal<void, int, int, unsigned long> mouse_up;227 sigc::signal<void, int, int, unsigned long> mouse_up;
216 sigc::signal<void, int, int, unsigned long> mouse_click;228 sigc::signal<void, int, int, unsigned long> mouse_click;
@@ -221,6 +233,8 @@
221 sigc::signal<void, AbstractLauncherIcon::Ptr> remove;233 sigc::signal<void, AbstractLauncherIcon::Ptr> remove;
222 sigc::signal<void, nux::ObjectPtr<nux::View>> tooltip_visible;234 sigc::signal<void, nux::ObjectPtr<nux::View>> tooltip_visible;
223 sigc::signal<void> visibility_changed;235 sigc::signal<void> visibility_changed;
236 sigc::signal<void> position_saved;
237 sigc::signal<void> position_forgot;
224238
225 sigc::connection needs_redraw_connection;239 sigc::connection needs_redraw_connection;
226 sigc::connection on_icon_added_connection;240 sigc::connection on_icon_added_connection;
227241
=== modified file 'launcher/BFBLauncherIcon.cpp'
--- launcher/BFBLauncherIcon.cpp 2012-08-15 02:51:33 +0000
+++ launcher/BFBLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -36,6 +36,7 @@
36{36{
37 tooltip_text = _("Dash Home");37 tooltip_text = _("Dash Home");
38 icon_name = PKGDATADIR"/launcher_bfb.png";38 icon_name = PKGDATADIR"/launcher_bfb.png";
39 position = Position::BEGIN;
39 SetQuirk(Quirk::VISIBLE, true);40 SetQuirk(Quirk::VISIBLE, true);
40 SetQuirk(Quirk::RUNNING, false);41 SetQuirk(Quirk::RUNNING, false);
4142
4243
=== modified file 'launcher/BamfLauncherIcon.cpp'
--- launcher/BamfLauncherIcon.cpp 2012-08-21 21:46:54 +0000
+++ launcher/BamfLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -74,11 +74,7 @@
74 tooltip_text = BamfName();74 tooltip_text = BamfName();
75 icon_name = (icon ? icon.Str() : DEFAULT_ICON);75 icon_name = (icon ? icon.Str() : DEFAULT_ICON);
7676
77 if (IsSticky())77 SetQuirk(Quirk::VISIBLE, bamf_view_user_visible(bamf_view));
78 SetQuirk(Quirk::VISIBLE, true);
79 else
80 SetQuirk(Quirk::VISIBLE, bamf_view_user_visible(bamf_view));
81
82 SetQuirk(Quirk::ACTIVE, bamf_view_is_active(bamf_view));78 SetQuirk(Quirk::ACTIVE, bamf_view_is_active(bamf_view));
83 SetQuirk(Quirk::RUNNING, bamf_view_is_running(bamf_view));79 SetQuirk(Quirk::RUNNING, bamf_view_is_running(bamf_view));
8480
@@ -95,7 +91,7 @@
95 sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-removed",91 sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-removed",
96 [&] (BamfView*, BamfView*) { EnsureWindowState(); });92 [&] (BamfView*, BamfView*) { EnsureWindowState(); });
97 _gsignals.Add(sig);93 _gsignals.Add(sig);
98 94
99 sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-moved",95 sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-moved",
100 [&] (BamfView *, BamfView *) {96 [&] (BamfView *, BamfView *) {
101 EnsureWindowState();97 EnsureWindowState();
@@ -173,9 +169,12 @@
173169
174BamfLauncherIcon::~BamfLauncherIcon()170BamfLauncherIcon::~BamfLauncherIcon()
175{171{
176 if (_bamf_app)172 if (_bamf_app.IsType(BAMF_TYPE_APPLICATION))
173 {
174 bamf_view_set_sticky(BAMF_VIEW(_bamf_app.RawPtr()), FALSE);
177 g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()),175 g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()),
178 g_quark_from_static_string("unity-seen"), nullptr);176 g_quark_from_static_string("unity-seen"), nullptr);
177 }
179}178}
180179
181void BamfLauncherIcon::Remove()180void BamfLauncherIcon::Remove()
@@ -201,11 +200,6 @@
201 return bamf_view_is_sticky(BAMF_VIEW(_bamf_app.RawPtr()));200 return bamf_view_is_sticky(BAMF_VIEW(_bamf_app.RawPtr()));
202}201}
203202
204bool BamfLauncherIcon::IsVisible() const
205{
206 return GetQuirk(Quirk::VISIBLE);
207}
208
209bool BamfLauncherIcon::IsActive() const203bool BamfLauncherIcon::IsActive() const
210{204{
211 return GetQuirk(Quirk::ACTIVE);205 return GetQuirk(Quirk::ACTIVE);
@@ -235,7 +229,6 @@
235 wm->Activate(arg.target);229 wm->Activate(arg.target);
236 return;230 return;
237 }231 }
238
239232
240 /* We should check each child to see if there is233 /* We should check each child to see if there is
241 * an unmapped (!= minimized) window around and234 * an unmapped (!= minimized) window around and
@@ -638,22 +631,22 @@
638 GList* children;631 GList* children;
639632
640 BamfView *focusable_child = BAMF_VIEW (bamf_application_get_focusable_child (_bamf_app.RawPtr()));633 BamfView *focusable_child = BAMF_VIEW (bamf_application_get_focusable_child (_bamf_app.RawPtr()));
641 634
642 if (focusable_child != NULL)635 if (focusable_child != NULL)
643 {636 {
644 Window xid;637 Window xid;
645 638
646 if (BAMF_IS_WINDOW (focusable_child))639 if (BAMF_IS_WINDOW (focusable_child))
647 xid = bamf_window_get_xid (BAMF_WINDOW(focusable_child));640 xid = bamf_window_get_xid (BAMF_WINDOW(focusable_child));
648 else if (BAMF_IS_TAB (focusable_child))641 else if (BAMF_IS_TAB (focusable_child))
649 {642 {
650 BamfTab *focusable_tab = BAMF_TAB (focusable_child);643 BamfTab *focusable_tab = BAMF_TAB (focusable_child);
651 644
652 xid = bamf_tab_get_xid (focusable_tab);645 xid = bamf_tab_get_xid (focusable_tab);
653 646
654 bamf_tab_raise (focusable_tab);647 bamf_tab_raise (focusable_tab);
655 }648 }
656 649
657 windows.push_back(xid);650 windows.push_back(xid);
658 return windows;651 return windows;
659 }652 }
@@ -662,7 +655,7 @@
662 if (g_strcmp0 (bamf_application_get_application_type (_bamf_app.RawPtr()), "webapp") == 0)655 if (g_strcmp0 (bamf_application_get_application_type (_bamf_app.RawPtr()), "webapp") == 0)
663 {656 {
664 OpenInstanceLauncherIcon(arg);657 OpenInstanceLauncherIcon(arg);
665 658
666 return windows;659 return windows;
667 }660 }
668 }661 }
@@ -762,13 +755,13 @@
762 {755 {
763 /* BamfTab does not support the monitor interface...so a bit of a nasty hack here. */756 /* BamfTab does not support the monitor interface...so a bit of a nasty hack here. */
764 xid = bamf_tab_get_xid (static_cast<BamfTab*>(l->data));757 xid = bamf_tab_get_xid (static_cast<BamfTab*>(l->data));
765 758
766 if (WindowManager::Default()->IsWindowOnCurrentDesktop(xid) == false)759 if (WindowManager::Default()->IsWindowOnCurrentDesktop(xid) == false)
767 continue;760 continue;
768 761
769 for (int j = 0; j < max_num_monitors; j++)762 for (int j = 0; j < max_num_monitors; j++)
770 monitors[j] = true;763 monitors[j] = true;
771 764
772 continue;765 continue;
773 }766 }
774767
@@ -939,30 +932,28 @@
939932
940void BamfLauncherIcon::Stick(bool save)933void BamfLauncherIcon::Stick(bool save)
941{934{
935 SimpleLauncherIcon::Stick(save);
936
942 if (IsSticky())937 if (IsSticky())
943 return;938 return;
944939
945 std::string const& desktop_file = DesktopFile();
946 bamf_view_set_sticky(BAMF_VIEW(_bamf_app.RawPtr()), true);940 bamf_view_set_sticky(BAMF_VIEW(_bamf_app.RawPtr()), true);
947
948 if (save && !desktop_file.empty())
949 FavoriteStore::Instance().AddFavorite(desktop_file, -1);
950}941}
951942
952void BamfLauncherIcon::UnStick()943void BamfLauncherIcon::UnStick()
953{944{
945 SimpleLauncherIcon::UnStick();
946
954 if (!IsSticky())947 if (!IsSticky())
955 return;948 return;
956949
957 std::string const& desktop_file = DesktopFile();
958 BamfView* view = BAMF_VIEW(_bamf_app.RawPtr());950 BamfView* view = BAMF_VIEW(_bamf_app.RawPtr());
959 bamf_view_set_sticky(view, false);951 bamf_view_set_sticky(view, false);
960952
961 if (bamf_view_is_closed(view) || !bamf_view_user_visible(view))953 SetQuirk(Quirk::VISIBLE, bamf_view_user_visible(view));
954
955 if (bamf_view_is_closed(view))
962 Remove();956 Remove();
963
964 if (!desktop_file.empty())
965 FavoriteStore::Instance().RemoveFavorite(desktop_file);
966}957}
967958
968void BamfLauncherIcon::ToggleSticky()959void BamfLauncherIcon::ToggleSticky()
@@ -1227,12 +1218,11 @@
1227{1218{
1228 if (_remote_uri.empty())1219 if (_remote_uri.empty())
1229 {1220 {
1230 const std::string prefix = "application://";
1231 std::string const& desktop_id = GetDesktopID();1221 std::string const& desktop_id = GetDesktopID();
12321222
1233 if (!desktop_id.empty())1223 if (!desktop_id.empty())
1234 {1224 {
1235 _remote_uri = prefix + desktop_id;1225 _remote_uri = FavoriteStore::URI_PREFIX_APP + desktop_id;
1236 }1226 }
1237 }1227 }
12381228
@@ -1384,32 +1374,25 @@
1384 if (desktop_file.empty())1374 if (desktop_file.empty())
1385 return;1375 return;
13861376
1387 GKeyFile* key_file = g_key_file_new();1377 std::shared_ptr<GKeyFile> key_file(g_key_file_new(), g_key_file_free);
1388 glib::Error error;1378 glib::Error error;
13891379
1390 g_key_file_load_from_file(key_file, desktop_file.c_str(), (GKeyFileFlags) 0, &error);1380 g_key_file_load_from_file(key_file.get(), desktop_file.c_str(), (GKeyFileFlags) 0, &error);
13911381
1392 if (error)1382 if (error)
1393 {
1394 g_key_file_free(key_file);
1395 return;1383 return;
1396 }1384
13971385 std::shared_ptr<char*> mimes(g_key_file_get_string_list(key_file.get(), "Desktop Entry", "MimeType", nullptr, nullptr),
1398 char** mimes = g_key_file_get_string_list(key_file, "Desktop Entry", "MimeType", nullptr, nullptr);1386 g_strfreev);
1387
1399 if (!mimes)1388 if (!mimes)
1400 {
1401 g_key_file_free(key_file);
1402 return;1389 return;
1403 }
14041390
1405 for (int i = 0; mimes[i]; i++)1391 for (int i = 0; mimes.get()[i]; i++)
1406 {1392 {
1407 unity::glib::String super_type(g_content_type_from_mime_type(mimes[i]));1393 unity::glib::String super_type(g_content_type_from_mime_type(mimes.get()[i]));
1408 _supported_types.insert(super_type.Str());1394 _supported_types.insert(super_type.Str());
1409 }1395 }
1410
1411 g_key_file_free(key_file);
1412 g_strfreev(mimes);
1413 }1396 }
1414}1397}
14151398
14161399
=== modified file 'launcher/BamfLauncherIcon.h'
--- launcher/BamfLauncherIcon.h 2012-08-20 06:37:21 +0000
+++ launcher/BamfLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -48,7 +48,6 @@
48 std::string DesktopFile();48 std::string DesktopFile();
4949
50 bool IsSticky() const;50 bool IsSticky() const;
51 bool IsVisible() const;
52 bool IsActive() const;51 bool IsActive() const;
53 bool IsRunning() const;52 bool IsRunning() const;
54 bool IsUrgent() const;53 bool IsUrgent() const;
5554
=== modified file 'launcher/CMakeLists.txt'
--- launcher/CMakeLists.txt 2012-08-25 15:54:29 +0000
+++ launcher/CMakeLists.txt 2012-09-18 15:52:46 +0000
@@ -42,6 +42,7 @@
42 DevicesSettingsImp.cpp42 DevicesSettingsImp.cpp
43 DndData.cpp43 DndData.cpp
44 EdgeBarrierController.cpp44 EdgeBarrierController.cpp
45 ExpoLauncherIcon.cpp
45 FavoriteStore.cpp46 FavoriteStore.cpp
46 FavoriteStoreGSettings.cpp47 FavoriteStoreGSettings.cpp
47 FavoriteStorePrivate.cpp48 FavoriteStorePrivate.cpp
4849
=== modified file 'launcher/DesktopLauncherIcon.cpp'
--- launcher/DesktopLauncherIcon.cpp 2012-08-02 13:16:06 +0000
+++ launcher/DesktopLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -19,6 +19,7 @@
1919
20#include "DesktopLauncherIcon.h"20#include "DesktopLauncherIcon.h"
21#include "unity-shared/WindowManager.h"21#include "unity-shared/WindowManager.h"
22#include "FavoriteStore.h"
2223
23#include <glib/gi18n-lib.h>24#include <glib/gi18n-lib.h>
2425
@@ -28,17 +29,14 @@
28{29{
2930
30DesktopLauncherIcon::DesktopLauncherIcon()31DesktopLauncherIcon::DesktopLauncherIcon()
31 : SimpleLauncherIcon(IconType::DESKTOP)32 : SimpleLauncherIcon(IconType::DESKTOP)
32 , show_in_switcher_(true)33 , show_in_switcher_(true)
33{34{
34 tooltip_text = _("Show Desktop");35 tooltip_text = _("Show Desktop");
35 icon_name = "desktop";36 icon_name = "desktop";
36 SetQuirk(Quirk::VISIBLE, true);37 SetQuirk(Quirk::VISIBLE, true);
37 SetQuirk(Quirk::RUNNING, false);38 SetQuirk(Quirk::RUNNING, false);
38}39 SetShortcut('d');
39
40DesktopLauncherIcon::~DesktopLauncherIcon()
41{
42}40}
4341
44void42void
@@ -53,5 +51,20 @@
53 return "DesktopLauncherIcon";51 return "DesktopLauncherIcon";
54}52}
5553
54std::string DesktopLauncherIcon::GetRemoteUri()
55{
56 return FavoriteStore::URI_PREFIX_UNITY + "desktop-icon";
57}
58
59void DesktopLauncherIcon::SetShowInSwitcher(bool show_in_switcher)
60{
61 show_in_switcher_ = show_in_switcher;
62}
63
64bool DesktopLauncherIcon::ShowInSwitcher(bool current)
65{
66 return show_in_switcher_;
67}
68
56} // namespace launcher69} // namespace launcher
57} // namespace unity70} // namespace unity
5871
=== modified file 'launcher/DesktopLauncherIcon.h'
--- launcher/DesktopLauncherIcon.h 2012-05-07 19:52:54 +0000
+++ launcher/DesktopLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -29,24 +29,16 @@
2929
30class DesktopLauncherIcon : public SimpleLauncherIcon30class DesktopLauncherIcon : public SimpleLauncherIcon
31{31{
32
33public:32public:
34 DesktopLauncherIcon();33 DesktopLauncherIcon();
35 ~DesktopLauncherIcon();34
3635 void SetShowInSwitcher(bool show_in_switcher);
37 void SetShowInSwitcher(bool show_in_switcher)36 bool ShowInSwitcher(bool current);
38 {
39 show_in_switcher_ = show_in_switcher;
40 }
41
42 bool ShowInSwitcher(bool current)
43 {
44 return show_in_switcher_;
45 }
4637
47protected:38protected:
48 void ActivateLauncherIcon(ActionArg arg);39 void ActivateLauncherIcon(ActionArg arg);
49 std::string GetName() const;40 std::string GetName() const;
41 std::string GetRemoteUri();
5042
51private:43private:
52 bool show_in_switcher_;44 bool show_in_switcher_;
5345
=== modified file 'launcher/DeviceLauncherSection.cpp'
--- launcher/DeviceLauncherSection.cpp 2012-08-28 17:28:02 +0000
+++ launcher/DeviceLauncherSection.cpp 2012-09-18 15:52:46 +0000
@@ -38,10 +38,7 @@
38 monitor_->volume_added.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded));38 monitor_->volume_added.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded));
39 monitor_->volume_removed.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved));39 monitor_->volume_removed.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved));
4040
41 device_populate_idle_.Run([this] () {41 PopulateEntries();
42 PopulateEntries();
43 return false;
44 });
45}42}
4643
47void DeviceLauncherSection::PopulateEntries()44void DeviceLauncherSection::PopulateEntries()
@@ -60,11 +57,11 @@
60 if (map_.find(volume) != map_.end())57 if (map_.find(volume) != map_.end())
61 return;58 return;
6259
63 VolumeLauncherIcon::Ptr icon(new VolumeLauncherIcon(std::make_shared<VolumeImp>(volume, file_manager_opener_, device_notification_display_),60 auto vol = std::make_shared<VolumeImp>(volume, file_manager_opener_, device_notification_display_);
64 devices_settings_));61 VolumeLauncherIcon::Ptr icon(new VolumeLauncherIcon(vol, devices_settings_));
6562
66 map_[volume] = icon;63 map_[volume] = icon;
67 IconAdded.emit(icon);64 icon_added.emit(icon);
68}65}
6966
70void DeviceLauncherSection::OnVolumeRemoved(glib::Object<GVolume> const& volume)67void DeviceLauncherSection::OnVolumeRemoved(glib::Object<GVolume> const& volume)
@@ -76,5 +73,15 @@
76 map_.erase(volume_it);73 map_.erase(volume_it);
77}74}
7875
76std::vector<VolumeLauncherIcon::Ptr> DeviceLauncherSection::GetIcons() const
77{
78 std::vector<VolumeLauncherIcon::Ptr> icons;
79
80 for (auto const& it : map_)
81 icons.push_back(it.second);
82
83 return icons;
84}
85
79}86}
80}87}
8188
=== modified file 'launcher/DeviceLauncherSection.h'
--- launcher/DeviceLauncherSection.h 2012-08-22 09:03:25 +0000
+++ launcher/DeviceLauncherSection.h 2012-09-18 15:52:46 +0000
@@ -23,8 +23,6 @@
23#include <map>23#include <map>
24#include <memory>24#include <memory>
2525
26#include <UnityCore/GLibSource.h>
27
28#include "AbstractVolumeMonitorWrapper.h"26#include "AbstractVolumeMonitorWrapper.h"
29#include "DevicesSettings.h"27#include "DevicesSettings.h"
30#include "DeviceNotificationDisplay.h"28#include "DeviceNotificationDisplay.h"
@@ -42,7 +40,9 @@
42 DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor,40 DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor,
43 DevicesSettings::Ptr devices_settings);41 DevicesSettings::Ptr devices_settings);
4442
45 sigc::signal<void, AbstractLauncherIcon::Ptr> IconAdded;43 std::vector<VolumeLauncherIcon::Ptr> GetIcons() const;
44
45 sigc::signal<void, AbstractLauncherIcon::Ptr> icon_added;
4646
47private:47private:
48 void PopulateEntries();48 void PopulateEntries();
@@ -55,8 +55,6 @@
55 DevicesSettings::Ptr devices_settings_;55 DevicesSettings::Ptr devices_settings_;
56 FileManagerOpener::Ptr file_manager_opener_;56 FileManagerOpener::Ptr file_manager_opener_;
57 DeviceNotificationDisplay::Ptr device_notification_display_;57 DeviceNotificationDisplay::Ptr device_notification_display_;
58
59 glib::Idle device_populate_idle_;
60};58};
6159
62}60}
6361
=== modified file 'launcher/DndData.cpp'
--- launcher/DndData.cpp 2012-07-09 14:11:06 +0000
+++ launcher/DndData.cpp 2012-09-18 15:52:46 +0000
@@ -27,12 +27,12 @@
27#include <UnityCore/GLibWrapper.h>27#include <UnityCore/GLibWrapper.h>
2828
29namespace unity {29namespace unity {
30 30
31void DndData::Fill(char* uris)31void DndData::Fill(const char* uris)
32{ 32{
33 Reset();33 Reset();
34 34
35 char* pch = strtok (uris, "\r\n");35 const char* pch = strtok (const_cast<char*>(uris), "\r\n");
36 while (pch)36 while (pch)
37 {37 {
38 glib::String content_type(g_content_type_guess(pch,38 glib::String content_type(g_content_type_guess(pch,
3939
=== modified file 'launcher/DndData.h'
--- launcher/DndData.h 2012-05-07 19:52:54 +0000
+++ launcher/DndData.h 2012-09-18 15:52:46 +0000
@@ -32,7 +32,7 @@
32 /**32 /**
33 * Fills the object given a list of uris.33 * Fills the object given a list of uris.
34 **/34 **/
35 void Fill(char* uris);35 void Fill(const char* uris);
36 36
37 /**37 /**
38 * Resets the object. Call this function when no longer need data38 * Resets the object. Call this function when no longer need data
3939
=== added file 'launcher/ExpoLauncherIcon.cpp'
--- launcher/ExpoLauncherIcon.cpp 1970-01-01 00:00:00 +0000
+++ launcher/ExpoLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -0,0 +1,64 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18 */
19
20#include "ExpoLauncherIcon.h"
21#include "unity-shared/WindowManager.h"
22#include "FavoriteStore.h"
23
24#include <glib/gi18n-lib.h>
25
26namespace unity
27{
28namespace launcher
29{
30
31ExpoLauncherIcon::ExpoLauncherIcon()
32 : SimpleLauncherIcon(IconType::EXPO)
33{
34 tooltip_text = _("Workspace Switcher");
35 icon_name = "workspace-switcher";
36 SetQuirk(Quirk::VISIBLE, false);
37 SetQuirk(Quirk::RUNNING, false);
38 SetShortcut('s');
39}
40
41void ExpoLauncherIcon::ActivateLauncherIcon(ActionArg arg)
42{
43 SimpleLauncherIcon::ActivateLauncherIcon(arg);
44 WindowManager::Default()->InitiateExpo();
45}
46
47void ExpoLauncherIcon::Stick(bool save)
48{
49 SimpleLauncherIcon::Stick(save);
50 SetQuirk(Quirk::VISIBLE, (WindowManager::Default()->WorkspaceCount() > 1));
51}
52
53std::string ExpoLauncherIcon::GetName() const
54{
55 return "ExpoLauncherIcon";
56}
57
58std::string ExpoLauncherIcon::GetRemoteUri()
59{
60 return FavoriteStore::URI_PREFIX_UNITY + "expo-icon";
61}
62
63} // namespace launcher
64} // namespace unity
065
=== added file 'launcher/ExpoLauncherIcon.h'
--- launcher/ExpoLauncherIcon.h 1970-01-01 00:00:00 +0000
+++ launcher/ExpoLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -0,0 +1,45 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18 */
19
20#ifndef EXPO_LAUNCHER_ICON_H
21#define EXPO_LAUNCHER_ICON_H
22
23#include "SimpleLauncherIcon.h"
24
25namespace unity
26{
27namespace launcher
28{
29
30class ExpoLauncherIcon : public SimpleLauncherIcon
31{
32public:
33 ExpoLauncherIcon();
34 void Stick(bool save);
35
36protected:
37 void ActivateLauncherIcon(ActionArg arg);
38 std::string GetName() const;
39 std::string GetRemoteUri();
40};
41
42}
43}
44
45#endif // EXPO_LAUNCHER_ICON_H
046
=== modified file 'launcher/FavoriteStore.cpp'
--- launcher/FavoriteStore.cpp 2012-05-07 19:52:54 +0000
+++ launcher/FavoriteStore.cpp 2012-09-18 15:52:46 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3* Copyright (C) 2010 Canonical Ltd3* Copyright (C) 2010-2012 Canonical Ltd
4*4*
5* This program is free software: you can redistribute it and/or modify5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as6* it under the terms of the GNU General Public License version 3 as
@@ -15,19 +15,29 @@
15* along with this program. If not, see <http://www.gnu.org/licenses/>.15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*16*
17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18* Marco Trevisan <marco.trevisan@canonical.com>
18*/19*/
1920
20#include <NuxCore/Logger.h>21#include <NuxCore/Logger.h>
21#include "FavoriteStoreGSettings.h"22#include <glib.h>
23
24#include "FavoriteStore.h"
25#include "FavoriteStorePrivate.h"
2226
23namespace unity27namespace unity
24{28{
25namespace29namespace
26{30{
27 nux::logging::Logger logger("unity.favouritestore");31nux::logging::Logger logger("unity.favorite.store");
28 FavoriteStore* favoritestore_instance = nullptr;32FavoriteStore* favoritestore_instance = nullptr;
33const std::string PREFIX_SEPARATOR = "://";
29}34}
3035
36const std::string FavoriteStore::URI_PREFIX_APP = "application://";
37const std::string FavoriteStore::URI_PREFIX_FILE = "file://";
38const std::string FavoriteStore::URI_PREFIX_DEVICE = "device://";
39const std::string FavoriteStore::URI_PREFIX_UNITY = "unity://";
40
31FavoriteStore::FavoriteStore()41FavoriteStore::FavoriteStore()
32{42{
33 if (favoritestore_instance)43 if (favoritestore_instance)
@@ -56,4 +66,83 @@
56 return *favoritestore_instance;66 return *favoritestore_instance;
57}67}
5868
69bool FavoriteStore::IsValidFavoriteUri(std::string const& uri)
70{
71 if (uri.empty())
72 return false;
73
74 if (uri.find(URI_PREFIX_APP) == 0 || uri.find(URI_PREFIX_FILE) == 0)
75 {
76 return internal::impl::IsDesktopFilePath(uri);
77 }
78 else if (uri.find(URI_PREFIX_DEVICE) == 0)
79 {
80 return uri.length() > URI_PREFIX_DEVICE.length();
81 }
82 else if (uri.find(URI_PREFIX_UNITY) == 0)
83 {
84 return uri.length() > URI_PREFIX_UNITY.length();
85 }
86
87 return false;
88}
89
90std::string FavoriteStore::ParseFavoriteFromUri(std::string const& uri) const
91{
92 if (uri.empty())
93 return "";
94
95 std::string fav = uri;
96 auto prefix_pos = fav.find(PREFIX_SEPARATOR);
97
98 if (prefix_pos == std::string::npos)
99 {
100 // We assume that favorites with no prefix, but with a .desktop suffix are applications
101 if (internal::impl::IsDesktopFilePath(uri))
102 {
103 fav = URI_PREFIX_APP + fav;
104 prefix_pos = URI_PREFIX_APP.length();
105 }
106 }
107 else
108 {
109 prefix_pos += PREFIX_SEPARATOR.length();
110 }
111
112 // Matches application://desktop-id.desktop or application:///path/to/file.desktop
113 if (fav.find(URI_PREFIX_APP) == 0 || fav.find(URI_PREFIX_FILE) == 0)
114 {
115 std::string const& fav_value = fav.substr(prefix_pos);
116
117 if (fav_value.empty())
118 {
119 LOG_WARNING(logger) << "Unable to load Favorite for uri '" << fav << "'";
120 return "";
121 }
122
123 if (fav_value[0] == '/' || fav.find(URI_PREFIX_FILE) == 0)
124 {
125 if (g_file_test(fav_value.c_str(), G_FILE_TEST_EXISTS))
126 {
127 return fav;
128 }
129 else
130 {
131 LOG_WARNING(logger) << "Unable to load desktop file: " << fav_value;
132 }
133 }
134 else
135 {
136 return URI_PREFIX_APP + fav_value;
137 }
138 }
139 else if (IsValidFavoriteUri(fav))
140 {
141 return fav;
142 }
143
144 LOG_WARNING(logger) << "Unable to load Favorite for uri '" << fav << "'";
145 return "";
146}
147
59}148}
60149
=== modified file 'launcher/FavoriteStore.h'
--- launcher/FavoriteStore.h 2012-05-07 19:52:54 +0000
+++ launcher/FavoriteStore.h 2012-09-18 15:52:46 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3* Copyright (C) 2010 Canonical Ltd3* Copyright (C) 2010-2012 Canonical Ltd
4*4*
5* This program is free software: you can redistribute it and/or modify5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as6* it under the terms of the GNU General Public License version 3 as
@@ -15,6 +15,7 @@
15* along with this program. If not, see <http://www.gnu.org/licenses/>.15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*16*
17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18* Marco Trevisan <marco.trevisan@canonical.com>
18*/19*/
1920
20#ifndef UNITY_FAVORITE_STORE_H21#ifndef UNITY_FAVORITE_STORE_H
@@ -42,26 +43,38 @@
4243
43 static FavoriteStore& Instance();44 static FavoriteStore& Instance();
4445
45 virtual FavoriteList const& GetFavorites() = 0;46 virtual FavoriteList const& GetFavorites() const = 0;
4647
47 // These will NOT emit the relevant signals, so bare that in mind48 // These will NOT emit the relevant signals, so bare that in mind
48 // i.e. don't hope that you can add stuff and hook the view up to49 // i.e. don't hope that you can add stuff and hook the view up to
49 // favorite_added events to update the view. The signals only emit if50 // favorite_added events to update the view. The signals only emit if
50 // there has been a change on the GSettings object from an external51 // there has been a change on the GSettings object from an external
51 // source52 // source
52 virtual void AddFavorite(std::string const& desktop_path, int position) = 0;53 virtual void AddFavorite(std::string const& icon_uri, int position) = 0;
53 virtual void RemoveFavorite(std::string const& desktop_path) = 0;54 virtual void RemoveFavorite(std::string const& icon_uri) = 0;
54 virtual void MoveFavorite(std::string const& desktop_path, int position) = 0;55 virtual void MoveFavorite(std::string const& icon_uri, int position) = 0;
55 virtual void SetFavorites(FavoriteList const& desktop_paths) = 0;56 virtual bool IsFavorite(std::string const& icon_uri) const = 0;
57 virtual int FavoritePosition(std::string const& icon_uri) const = 0;
58 virtual void SetFavorites(FavoriteList const& icon_uris) = 0;
5659
57 // Signals60 // Signals
58 // These only emit if something has changed the GSettings object externally61 // These only emit if something has changed the GSettings object externally
5962
60 //desktop_path, position, before/after63 //icon_uri, position, before/after
61 sigc::signal<void, std::string const&, std::string const&, bool> favorite_added;64 sigc::signal<void, std::string const&, std::string const&, bool> favorite_added;
62 //desktop_path65 //icon_uri
63 sigc::signal<void, std::string const&> favorite_removed;66 sigc::signal<void, std::string const&> favorite_removed;
64 sigc::signal<void> reordered;67 sigc::signal<void> reordered;
68
69 static const std::string URI_PREFIX_APP;
70 static const std::string URI_PREFIX_FILE;
71 static const std::string URI_PREFIX_DEVICE;
72 static const std::string URI_PREFIX_UNITY;
73
74 static bool IsValidFavoriteUri(std::string const& uri);
75
76protected:
77 std::string ParseFavoriteFromUri(std::string const& uri) const;
65};78};
6679
67}80}
6881
=== modified file 'launcher/FavoriteStoreGSettings.cpp'
--- launcher/FavoriteStoreGSettings.cpp 2012-08-15 17:22:33 +0000
+++ launcher/FavoriteStoreGSettings.cpp 2012-09-18 15:52:46 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3* Copyright (C) 2010 Canonical Ltd3* Copyright (C) 2010-2012 Canonical Ltd
4*4*
5* This program is free software: you can redistribute it and/or modify5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as6* it under the terms of the GNU General Public License version 3 as
@@ -15,9 +15,9 @@
15* along with this program. If not, see <http://www.gnu.org/licenses/>.15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*16*
17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18* Marco Trevisan <marco.trevisan@canonical.com>
18*/19*/
1920
20#include <gio/gdesktopappinfo.h>
21#include <NuxCore/Logger.h>21#include <NuxCore/Logger.h>
22#include <UnityCore/DesktopUtilities.h>22#include <UnityCore/DesktopUtilities.h>
2323
@@ -40,7 +40,7 @@
4040
41namespace41namespace
42{42{
43nux::logging::Logger logger("unity.favorites");43nux::logging::Logger logger("unity.favorite.store.gsettings");
44const std::string SETTINGS_NAME = "com.canonical.Unity.Launcher";44const std::string SETTINGS_NAME = "com.canonical.Unity.Launcher";
45const std::string SETTINGS_KEY = "favorites";45const std::string SETTINGS_KEY = "favorites";
46}46}
@@ -59,117 +59,89 @@
5959
60void FavoriteStoreGSettings::Refresh()60void FavoriteStoreGSettings::Refresh()
61{61{
62 FillList(favorites_);62 FillList();
63}63}
6464
65void FavoriteStoreGSettings::FillList(FavoriteList& list)65void FavoriteStoreGSettings::FillList()
66{66{
67 list.clear();67 favorites_.clear();
6868 std::shared_ptr<gchar*> favs(g_settings_get_strv(settings_, SETTINGS_KEY.c_str()));
69 gchar** favs = g_settings_get_strv(settings_, SETTINGS_KEY.c_str());69
7070 for (int i = 0; favs.get()[i]; ++i)
71 for (int i = 0; favs[i] != NULL; ++i)
72 {71 {
73 // We will be storing either full /path/to/desktop/files or foo.desktop id's72 std::string const& fav = ParseFavoriteFromUri(favs.get()[i]);
74 if (favs[i][0] == '/')
75 {
76 if (g_file_test(favs[i], G_FILE_TEST_EXISTS))
77 {
78 list.push_back(favs[i]);
79 }
80 else
81 {
82 LOG_WARNING(logger) << "Unable to load desktop file: "
83 << favs[i];
84 }
85 }
86 else
87 {
88 glib::Object<GDesktopAppInfo> info(g_desktop_app_info_new(favs[i]));
89 const char* filename = 0;
90 if (info)
91 filename = g_desktop_app_info_get_filename(info);
9273
93 if (filename)74 if (!fav.empty())
94 {75 favorites_.push_back(fav);
95 list.push_back(filename);
96 }
97 else
98 {
99 LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '" << favs[i] << "'";
100 }
101 }
102 }76 }
103
104 g_strfreev(favs);
105}77}
10678
107FavoriteList const& FavoriteStoreGSettings::GetFavorites()79FavoriteList const& FavoriteStoreGSettings::GetFavorites() const
108{80{
109 return favorites_;81 return favorites_;
110}82}
11183
112void FavoriteStoreGSettings::AddFavorite(std::string const& desktop_path, int position)84void FavoriteStoreGSettings::AddFavorite(std::string const& icon_uri, int position)
113{85{
114 int size = favorites_.size();86 std::string const& fav = ParseFavoriteFromUri(icon_uri);
115 if (desktop_path.empty() || position > size)87
88 if (fav.empty() || position > static_cast<int>(favorites_.size()))
116 return;89 return;
11790
118 if (position < 0)91 if (position < 0)
119 {92 {
120 // It goes on the end.93 // It goes on the end.
121 favorites_.push_back(desktop_path);94 favorites_.push_back(fav);
122 }95 }
123 else96 else
124 {97 {
125 FavoriteList::iterator pos = favorites_.begin();98 FavoriteList::iterator pos = favorites_.begin();
126 std::advance(pos, position);99 std::advance(pos, position);
127 favorites_.insert(pos, desktop_path);100 favorites_.insert(pos, fav);
128 }101 }
129102
130 SaveFavorites(favorites_);103 SaveFavorites(favorites_);
131 Refresh();104 Refresh();
132}105}
133106
134void FavoriteStoreGSettings::RemoveFavorite(std::string const& desktop_path)107void FavoriteStoreGSettings::RemoveFavorite(std::string const& icon_uri)
135{108{
136 if (desktop_path.empty() || desktop_path[0] != '/')109 std::string const& fav = ParseFavoriteFromUri(icon_uri);
110
111 if (fav.empty())
137 return;112 return;
138113
139 FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), desktop_path);114 FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), fav);
140 if (pos == favorites_.end())115 if (pos == favorites_.end())
141 {
142 return;116 return;
143 }
144117
145 favorites_.erase(pos);118 favorites_.erase(pos);
146 SaveFavorites(favorites_);119 SaveFavorites(favorites_);
147 Refresh();120 Refresh();
148}121}
149122
150void FavoriteStoreGSettings::MoveFavorite(std::string const& desktop_path, int position)123void FavoriteStoreGSettings::MoveFavorite(std::string const& icon_uri, int position)
151{124{
152 int size = favorites_.size();125 std::string const& fav = ParseFavoriteFromUri(icon_uri);
153 if (desktop_path.empty() || position > size)126
127 if (fav.empty() || position > static_cast<int>(favorites_.size()))
154 return;128 return;
155129
156 FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), desktop_path);130 FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), fav);
157 if (pos == favorites_.end())131 if (pos == favorites_.end())
158 {
159 return;132 return;
160 }
161133
162 favorites_.erase(pos);134 favorites_.erase(pos);
163 if (position < 0)135 if (position < 0)
164 {136 {
165 // It goes on the end.137 // It goes on the end.
166 favorites_.push_back(desktop_path);138 favorites_.push_back(fav);
167 }139 }
168 else140 else
169 {141 {
170 FavoriteList::iterator insert_pos = favorites_.begin();142 FavoriteList::iterator insert_pos = favorites_.begin();
171 std::advance(insert_pos, position);143 std::advance(insert_pos, position);
172 favorites_.insert(insert_pos, desktop_path);144 favorites_.insert(insert_pos, fav);
173 }145 }
174146
175 SaveFavorites(favorites_);147 SaveFavorites(favorites_);
@@ -186,26 +158,34 @@
186{158{
187 const int size = favorites.size();159 const int size = favorites.size();
188 const char* favs[size + 1];160 const char* favs[size + 1];
189 favs[size] = NULL;
190161
191 int index = 0;
192 // Since we don't always save the full path, we store the values we are162 // Since we don't always save the full path, we store the values we are
193 // actually going to save in a different list.163 // actually going to save in a different list.
194 auto system_dirs = DesktopUtilities::GetDataDirectories();
195 FavoriteList values;164 FavoriteList values;
196 for (FavoriteList::const_iterator i = favorites.begin(), end = favorites.end();165 int index = 0;
197 i != end; ++i, ++index)166
167 for (auto const& fav_uri : favorites)
198 {168 {
169 std::string const& fav = ParseFavoriteFromUri(fav_uri);
170 if (fav.empty())
171 {
172 LOG_WARNING(logger) << "Impossible to add favorite '" << fav_uri << "' to store";
173 continue;
174 }
175
199 // By using insert we get the iterator to the newly inserted string value.176 // By using insert we get the iterator to the newly inserted string value.
200 // That way we can use the c_str() method to access the const char* for177 // That way we can use the c_str() method to access the const char* for
201 // the string that we are going to save. This way we know that the pointer178 // the string that we are going to save. This way we know that the pointer
202 // is valid for the lifetime of the favs array usage in the method call to179 // is valid for the lifetime of the favs array usage in the method call to
203 // set the settings, and that we aren't referencing a temporary.180 // set the settings, and that we aren't referencing a temporary.
204 std::string const& desktop_id = DesktopUtilities::GetDesktopID(system_dirs, *i);181 FavoriteList::iterator iter = values.insert(values.end(), fav);
205 FavoriteList::iterator iter = values.insert(values.end(), desktop_id);
206 favs[index] = iter->c_str();182 favs[index] = iter->c_str();
183 ++index;
207 }184 }
208185
186 for (int i = index; i <= size; ++i)
187 favs[i] = nullptr;
188
209 ignore_signals_ = ignore;189 ignore_signals_ = ignore;
210 if (!g_settings_set_strv(settings_, SETTINGS_KEY.c_str(), favs))190 if (!g_settings_set_strv(settings_, SETTINGS_KEY.c_str(), favs))
211 {191 {
@@ -220,7 +200,7 @@
220 return;200 return;
221201
222 FavoriteList old(favorites_);202 FavoriteList old(favorites_);
223 FillList(favorites_);203 FillList();
224204
225 auto newbies = impl::GetNewbies(old, favorites_);205 auto newbies = impl::GetNewbies(old, favorites_);
226206
@@ -243,7 +223,26 @@
243223
244 if (impl::NeedToBeReordered(old, favorites_))224 if (impl::NeedToBeReordered(old, favorites_))
245 reordered.emit();225 reordered.emit();
246226}
227
228bool FavoriteStoreGSettings::IsFavorite(std::string const& icon_uri) const
229{
230 return std::find(favorites_.begin(), favorites_.end(), icon_uri) != favorites_.end();
231}
232
233int FavoriteStoreGSettings::FavoritePosition(std::string const& icon_uri) const
234{
235 int index = 0;
236
237 for (auto const& fav : favorites_)
238 {
239 if (fav == icon_uri)
240 return index;
241
242 ++index;
243 }
244
245 return -1;
247}246}
248247
249} // namespace internal248} // namespace internal
250249
=== modified file 'launcher/FavoriteStoreGSettings.h'
--- launcher/FavoriteStoreGSettings.h 2012-08-01 18:12:10 +0000
+++ launcher/FavoriteStoreGSettings.h 2012-09-18 15:52:46 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3* Copyright (C) 2010 Canonical Ltd3* Copyright (C) 2010-2012 Canonical Ltd
4*4*
5* This program is free software: you can redistribute it and/or modify5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as6* it under the terms of the GNU General Public License version 3 as
@@ -15,6 +15,7 @@
15* along with this program. If not, see <http://www.gnu.org/licenses/>.15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*16*
17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18* Marco Trevisan <marco.trevisan@canonical.com>
18*/19*/
1920
20#ifndef FAVORITE_STORE_GSETTINGS_H21#ifndef FAVORITE_STORE_GSETTINGS_H
@@ -38,17 +39,19 @@
38public:39public:
39 FavoriteStoreGSettings();40 FavoriteStoreGSettings();
4041
41 virtual FavoriteList const& GetFavorites();42 virtual FavoriteList const& GetFavorites() const;
42 virtual void AddFavorite(std::string const& desktop_path, int position);43 virtual void AddFavorite(std::string const& desktop_path, int position);
43 virtual void RemoveFavorite(std::string const& desktop_path);44 virtual void RemoveFavorite(std::string const& desktop_path);
44 virtual void MoveFavorite(std::string const& desktop_path, int position);45 virtual void MoveFavorite(std::string const& desktop_path, int position);
46 virtual bool IsFavorite(std::string const& icon_uri) const;
47 virtual int FavoritePosition(std::string const& icon_uri) const;
48 virtual void SetFavorites(FavoriteList const& desktop_paths);
45 void SaveFavorites(FavoriteList const& favorites, bool ignore = true);49 void SaveFavorites(FavoriteList const& favorites, bool ignore = true);
46 virtual void SetFavorites(FavoriteList const& desktop_paths);
4750
48private:51private:
49 void Refresh();52 void Refresh();
50 void Changed();53 void Changed();
51 void FillList(FavoriteList& list);54 void FillList();
5255
53 FavoriteList favorites_;56 FavoriteList favorites_;
54 bool ignore_signals_;57 bool ignore_signals_;
5558
=== modified file 'launcher/FavoriteStorePrivate.cpp'
--- launcher/FavoriteStorePrivate.cpp 2012-05-07 19:52:54 +0000
+++ launcher/FavoriteStorePrivate.cpp 2012-09-18 15:52:46 +0000
@@ -124,6 +124,20 @@
124 return false;124 return false;
125}125}
126126
127bool IsDesktopFilePath(std::string const& path)
128{
129 static const std::string desktop_ext = ".desktop";
130 auto path_len = path.length();
131 auto desktop_length = desktop_ext.length();
132
133 if (path_len > desktop_length)
134 {
135 return path.compare(path_len - desktop_length, desktop_length, desktop_ext) == 0;
136 }
137
138 return false;
139}
140
127141
128} // namespace impl142} // namespace impl
129} // namespace internal143} // namespace internal
130144
=== modified file 'launcher/FavoriteStorePrivate.h'
--- launcher/FavoriteStorePrivate.h 2012-05-07 19:52:54 +0000
+++ launcher/FavoriteStorePrivate.h 2012-09-18 15:52:46 +0000
@@ -32,13 +32,15 @@
3232
33std::vector<std::string> GetNewbies(std::list<std::string> const& old, std::list<std::string> const& fresh);33std::vector<std::string> GetNewbies(std::list<std::string> const& old, std::list<std::string> const& fresh);
3434
35void GetSignalAddedInfo(std::list<std::string> const& favs, std::vector<std::string> const& newbies, 35void GetSignalAddedInfo(std::list<std::string> const& favs, std::vector<std::string> const& newbies,
36 std::string const& path, std::string& position, bool& before);36 std::string const& path, std::string& position, bool& before);
3737
38std::vector<std::string> GetRemoved(std::list<std::string> const& old, std::list<std::string> const& fresh);38std::vector<std::string> GetRemoved(std::list<std::string> const& old, std::list<std::string> const& fresh);
3939
40bool NeedToBeReordered(std::list<std::string> const& old, std::list<std::string> const& fresh);40bool NeedToBeReordered(std::list<std::string> const& old, std::list<std::string> const& fresh);
4141
42bool IsDesktopFilePath(std::string const& path);
43
4244
43} // namespace impl45} // namespace impl
44} // namespace internal46} // namespace internal
4547
=== modified file 'launcher/HudLauncherIcon.cpp'
--- launcher/HudLauncherIcon.cpp 2012-08-22 08:17:33 +0000
+++ launcher/HudLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -45,6 +45,7 @@
45{45{
46 tooltip_text = _("HUD");46 tooltip_text = _("HUD");
47 icon_name = PKGDATADIR"/launcher_bfb.png";47 icon_name = PKGDATADIR"/launcher_bfb.png";
48 position = Position::BEGIN;
48 SetQuirk(Quirk::VISIBLE, false);49 SetQuirk(Quirk::VISIBLE, false);
49 SetQuirk(Quirk::RUNNING, false);50 SetQuirk(Quirk::RUNNING, false);
50 SetQuirk(Quirk::ACTIVE, true);51 SetQuirk(Quirk::ACTIVE, true);
@@ -121,7 +122,7 @@
121122
122void HudLauncherIcon::ActivateLauncherIcon(ActionArg arg)123void HudLauncherIcon::ActivateLauncherIcon(ActionArg arg)
123{124{
124 if (GetQuirk(Quirk::VISIBLE))125 if (IsVisible())
125 {126 {
126 ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);127 ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);
127 }128 }
128129
=== modified file 'launcher/Launcher.cpp'
--- launcher/Launcher.cpp 2012-09-04 15:56:50 +0000
+++ launcher/Launcher.cpp 2012-09-18 15:52:46 +0000
@@ -54,6 +54,7 @@
54#include <UnityCore/GLibWrapper.h>54#include <UnityCore/GLibWrapper.h>
55#include <UnityCore/Variant.h>55#include <UnityCore/Variant.h>
5656
57#include <boost/algorithm/string.hpp>
57#include <sigc++/sigc++.h>58#include <sigc++/sigc++.h>
5859
59namespace unity60namespace unity
@@ -106,6 +107,7 @@
106 nux::ObjectPtr<DNDCollectionWindow> const& collection_window,107 nux::ObjectPtr<DNDCollectionWindow> const& collection_window,
107 NUX_FILE_LINE_DECL)108 NUX_FILE_LINE_DECL)
108 : View(NUX_FILE_LINE_PARAM)109 : View(NUX_FILE_LINE_PARAM)
110 , display(nux::GetGraphicsDisplay()->GetX11Display())
109 , monitor(0)111 , monitor(0)
110 , _parent(parent)112 , _parent(parent)
111 , _active_quicklist(nullptr)113 , _active_quicklist(nullptr)
@@ -116,6 +118,7 @@
116 , _data_checked(false)118 , _data_checked(false)
117 , _steal_drag(false)119 , _steal_drag(false)
118 , _drag_edge_touching(false)120 , _drag_edge_touching(false)
121 , _initial_drag_animation(false)
119 , _dash_is_open(false)122 , _dash_is_open(false)
120 , _hud_is_open(false)123 , _hud_is_open(false)
121 , _folded_angle(1.0f)124 , _folded_angle(1.0f)
@@ -462,9 +465,8 @@
462 return true;465 return true;
463466
464 // animations happening on specific icons467 // animations happening on specific icons
465 LauncherModel::iterator it;468 for (auto const &icon : *_model)
466 for (it = _model->begin(); it != _model->end(); ++it)469 if (IconNeedsAnimation(icon, current))
467 if (IconNeedsAnimation(*it, current))
468 return true;470 return true;
469471
470 return false;472 return false;
@@ -495,10 +497,10 @@
495497
496 if (icon->GetIconType() == AbstractLauncherIcon::IconType::HUD)498 if (icon->GetIconType() == AbstractLauncherIcon::IconType::HUD)
497 {499 {
498 return (icon->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)) ? 1.0f : 0.0f;500 return icon->IsVisible() ? 1.0f : 0.0f;
499 }501 }
500502
501 if (icon->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE))503 if (icon->IsVisible())
502 {504 {
503 struct timespec icon_visible_time = icon->GetQuirkTime(AbstractLauncherIcon::Quirk::VISIBLE);505 struct timespec icon_visible_time = icon->GetQuirkTime(AbstractLauncherIcon::Quirk::VISIBLE);
504 int enter_ms = unity::TimeUtil::TimeDelta(&current, &icon_visible_time);506 int enter_ms = unity::TimeUtil::TimeDelta(&current, &icon_visible_time);
@@ -891,8 +893,11 @@
891893
892 if (GetActionState() == ACTION_DRAG_ICON ||894 if (GetActionState() == ACTION_DRAG_ICON ||
893 (_drag_window && _drag_window->Animating()) ||895 (_drag_window && _drag_window->Animating()) ||
894 icon->IsSpacer())896 icon->GetIconType() == AbstractLauncherIcon::IconType::SPACER)
897 {
895 arg.skip = true;898 arg.skip = true;
899 }
900
896 size_modifier *= DragThresholdProgress(current);901 size_modifier *= DragThresholdProgress(current);
897 }902 }
898903
@@ -932,11 +937,12 @@
932937
933 icon->SetCenter(nux::Point3(roundf(center.x), roundf(center.y), roundf(center.z)), monitor, parent_abs_geo);938 icon->SetCenter(nux::Point3(roundf(center.x), roundf(center.y), roundf(center.z)), monitor, parent_abs_geo);
934939
935 // FIXME: this is a hack, we should have a look why SetAnimationTarget is necessary in SetAnimationTarget940 // FIXME: this is a hack, to avoid that we set the target to the end of the icon
936 // we should ideally just need it at start to set the target
937 if (!_initial_drag_animation && icon == _drag_icon && _drag_window && _drag_window->Animating())941 if (!_initial_drag_animation && icon == _drag_icon && _drag_window && _drag_window->Animating())
938 _drag_window->SetAnimationTarget(static_cast<int>(_drag_icon->GetCenter(monitor).x),942 {
939 static_cast<int>(_drag_icon->GetCenter(monitor).y));943 auto const& icon_center = _drag_icon->GetCenter(monitor);
944 _drag_window->SetAnimationTarget(icon_center.x, icon_center.y);
945 }
940946
941 center.y += (half_size * size_modifier) + spacing; // move to end947 center.y += (half_size * size_modifier) + spacing; // move to end
942}948}
@@ -953,10 +959,10 @@
953nux::Color FullySaturateColor (nux::Color color)959nux::Color FullySaturateColor (nux::Color color)
954{960{
955 float max = std::max<float>(color.red, std::max<float>(color.green, color.blue));961 float max = std::max<float>(color.red, std::max<float>(color.green, color.blue));
962
956 if (max > 0.0f)963 if (max > 0.0f)
957 {
958 color = color * (1.0f / max);964 color = color * (1.0f / max);
959 }965
960 return color;966 return color;
961}967}
962968
@@ -1396,8 +1402,8 @@
13961402
1397void Launcher::OnPluginStateChanged()1403void Launcher::OnPluginStateChanged()
1398{1404{
1399 _hide_machine.SetQuirk (LauncherHideMachine::EXPO_ACTIVE, WindowManager::Default ()->IsExpoActive ());1405 _hide_machine.SetQuirk(LauncherHideMachine::EXPO_ACTIVE, WindowManager::Default()->IsExpoActive());
1400 _hide_machine.SetQuirk (LauncherHideMachine::SCALE_ACTIVE, WindowManager::Default ()->IsScaleActive ());1406 _hide_machine.SetQuirk(LauncherHideMachine::SCALE_ACTIVE, WindowManager::Default()->IsScaleActive());
1401}1407}
14021408
1403LauncherHideMode Launcher::GetHideMode() const1409LauncherHideMode Launcher::GetHideMode() const
@@ -1669,11 +1675,6 @@
1669 return _model;1675 return _model;
1670}1676}
16711677
1672void Launcher::SetDevicesSettings(DevicesSettings::Ptr devices_settings)
1673{
1674 devices_settings_ = devices_settings;
1675}
1676
1677void Launcher::EnsureIconOnScreen(AbstractLauncherIcon::Ptr selection)1678void Launcher::EnsureIconOnScreen(AbstractLauncherIcon::Ptr selection)
1678{1679{
1679 nux::Geometry const& geo = GetGeometry();1680 nux::Geometry const& geo = GetGeometry();
@@ -1681,7 +1682,7 @@
1681 int natural_y = 0;1682 int natural_y = 0;
1682 for (auto icon : *_model)1683 for (auto icon : *_model)
1683 {1684 {
1684 if (!icon->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) || !icon->IsVisibleOnMonitor(monitor))1685 if (!icon->IsVisible() || !icon->IsVisibleOnMonitor(monitor))
1685 continue;1686 continue;
16861687
1687 if (icon == selection)1688 if (icon == selection)
@@ -1953,7 +1954,7 @@
1953 EnsureAnimation();1954 EnsureAnimation();
1954}1955}
19551956
1956bool Launcher::StartIconDragTimeout()1957bool Launcher::StartIconDragTimeout(int x, int y)
1957{1958{
1958 // if we are still waiting…1959 // if we are still waiting…
1959 if (GetActionState() == ACTION_NONE)1960 if (GetActionState() == ACTION_NONE)
@@ -1964,7 +1965,7 @@
1964 _icon_under_mouse = nullptr;1965 _icon_under_mouse = nullptr;
1965 }1966 }
1966 _initial_drag_animation = true;1967 _initial_drag_animation = true;
1967 StartIconDragRequest(GetMouseX(), GetMouseY());1968 StartIconDragRequest(x, y);
1968 }1969 }
19691970
1970 return false;1971 return false;
@@ -1972,26 +1973,27 @@
19721973
1973void Launcher::StartIconDragRequest(int x, int y)1974void Launcher::StartIconDragRequest(int x, int y)
1974{1975{
1975 nux::Geometry geo = GetAbsoluteGeometry();1976 nux::Geometry const& abs_geo = GetAbsoluteGeometry();
1976 AbstractLauncherIcon::Ptr drag_icon = MouseIconIntersection((int)(GetGeometry().width / 2.0f), y);1977 AbstractLauncherIcon::Ptr drag_icon = MouseIconIntersection(abs_geo.width / 2.0f, y);
1977
1978 x += geo.x;
1979 y += geo.y;
1980
19811978
1982 // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying1979 // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying
1983 // on an internal Launcher property then1980 // on an internal Launcher property then
1984 bool can_drag = (_model->IconHasSister(drag_icon) || drag_icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE);1981 if (drag_icon && _last_button_press == 1 && drag_icon->position() == AbstractLauncherIcon::Position::FLOATING)
1985 if (drag_icon && _last_button_press == 1 && can_drag)
1986 {1982 {
1983 auto const& icon_center = drag_icon->GetCenter(monitor);
1984 x += abs_geo.x;
1985 y += abs_geo.y;
1986
1987 SetActionState(ACTION_DRAG_ICON);1987 SetActionState(ACTION_DRAG_ICON);
1988 StartIconDrag(drag_icon);1988 StartIconDrag(drag_icon);
1989 UpdateDragWindowPosition(drag_icon->GetCenter(monitor).x, drag_icon->GetCenter(monitor).y);1989 UpdateDragWindowPosition(icon_center.x, icon_center.y);
1990
1990 if (_initial_drag_animation)1991 if (_initial_drag_animation)
1991 {1992 {
1992 _drag_window->SetAnimationTarget(x, y);1993 _drag_window->SetAnimationTarget(x, y);
1993 _drag_window->StartAnimation();1994 _drag_window->StartAnimation();
1994 }1995 }
1996
1995 EnsureAnimation();1997 EnsureAnimation();
1996 }1998 }
1997 else1999 else
@@ -2008,6 +2010,7 @@
20082010
2009 _hide_machine.SetQuirk(LauncherHideMachine::INTERNAL_DND_ACTIVE, true);2011 _hide_machine.SetQuirk(LauncherHideMachine::INTERNAL_DND_ACTIVE, true);
2010 _drag_icon = icon;2012 _drag_icon = icon;
2013 _drag_icon_position = _model->IconIndex(icon);
20112014
2012 HideDragWindow();2015 HideDragWindow();
2013 _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);2016 _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);
@@ -2031,15 +2034,20 @@
2031 {2034 {
2032 hovered_icon->SetQuirk(AbstractLauncherIcon::Quirk::PULSE_ONCE, true);2035 hovered_icon->SetQuirk(AbstractLauncherIcon::Quirk::PULSE_ONCE, true);
20332036
2034 launcher_removerequest.emit(_drag_icon);2037 remove_request.emit(_drag_icon);
20352038
2036 HideDragWindow();2039 HideDragWindow();
2037 EnsureAnimation();2040 EnsureAnimation();
2038 }2041 }
2039 else2042 else
2040 {2043 {
2041 if (!_drag_window->Cancelled())2044 if (!_drag_window->Cancelled() && _model->IconIndex(_drag_icon) != _drag_icon_position)
2045 {
2046 if (_drag_icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE)
2047 _drag_icon->Stick(false);
2048
2042 _model->Save();2049 _model->Save();
2050 }
20432051
2044 if (_drag_window->on_anim_completed.connected())2052 if (_drag_window->on_anim_completed.connected())
2045 _drag_window->on_anim_completed.disconnect();2053 _drag_window->on_anim_completed.disconnect();
@@ -2103,15 +2111,11 @@
2103 return;2111 return;
21042112
2105 auto const& launcher_geo = GetGeometry();2113 auto const& launcher_geo = GetGeometry();
2106 auto hovered_icon = MouseIconIntersection((launcher_geo.x + launcher_geo.width) / 2.0, y - GetAbsoluteY());2114 auto const& hovered_icon = MouseIconIntersection((launcher_geo.x + launcher_geo.width) / 2.0, y - GetAbsoluteY());
2107 struct timespec current;2115 struct timespec current;
2108 clock_gettime(CLOCK_MONOTONIC, &current);2116 clock_gettime(CLOCK_MONOTONIC, &current);
2109 float progress = DragThresholdProgress(current);2117 float progress = DragThresholdProgress(current);
21102118
2111 // Icons of different types can't be mixed, so let's avoid this.
2112 if (hovered_icon && hovered_icon->GetIconType() != _drag_icon->GetIconType())
2113 hovered_icon = nullptr;
2114
2115 if (hovered_icon && _drag_icon != hovered_icon)2119 if (hovered_icon && _drag_icon != hovered_icon)
2116 {2120 {
2117 if (progress >= 1.0f)2121 if (progress >= 1.0f)
@@ -2130,12 +2134,8 @@
2130 {2134 {
2131 auto const& icon = *it;2135 auto const& icon = *it;
21322136
2133 if (!icon->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) ||2137 if (!icon->IsVisible() || !icon->IsVisibleOnMonitor(monitor))
2134 !icon->IsVisibleOnMonitor(monitor) ||
2135 icon->GetIconType() != _drag_icon->GetIconType())
2136 {
2137 continue;2138 continue;
2138 }
21392139
2140 if (y >= icon->GetCenter(monitor).y)2140 if (y >= icon->GetCenter(monitor).y)
2141 {2141 {
@@ -2216,7 +2216,9 @@
2216 }2216 }
2217 else2217 else
2218 {2218 {
2219 StartIconDragRequest(x, y);2219 // We we can safely start the icon drag, from the original mouse-down position
2220 sources_.Remove(START_DRAGICON_DURATION);
2221 StartIconDragRequest(x - _dnd_delta_x, y - _dnd_delta_y);
2220 }2222 }
2221 }2223 }
2222 else if (GetActionState() == ACTION_DRAG_LAUNCHER)2224 else if (GetActionState() == ACTION_DRAG_LAUNCHER)
@@ -2226,7 +2228,7 @@
2226 }2228 }
2227 else if (GetActionState() == ACTION_DRAG_ICON)2229 else if (GetActionState() == ACTION_DRAG_ICON)
2228 {2230 {
2229 nux::Geometry geo = GetAbsoluteGeometry();2231 nux::Geometry const& geo = GetAbsoluteGeometry();
2230 UpdateDragWindowPosition(geo.x + x, geo.y + y);2232 UpdateDragWindowPosition(geo.x + x, geo.y + y);
2231 }2233 }
22322234
@@ -2405,7 +2407,7 @@
2405 {2407 {
2406 _icon_mouse_down = launcher_icon;2408 _icon_mouse_down = launcher_icon;
2407 // if MouseUp after the time ended -> it's an icon drag, otherwise, it's starting an app2409 // if MouseUp after the time ended -> it's an icon drag, otherwise, it's starting an app
2408 auto cb_func = sigc::mem_fun(this, &Launcher::StartIconDragTimeout);2410 auto cb_func = sigc::bind(sigc::mem_fun(this, &Launcher::StartIconDragTimeout), x, y);
2409 sources_.AddTimeout(START_DRAGICON_DURATION, cb_func, START_DRAGICON_TIMEOUT);2411 sources_.AddTimeout(START_DRAGICON_DURATION, cb_func, START_DRAGICON_TIMEOUT);
24102412
2411 launcher_icon->mouse_down.emit(nux::GetEventButton(button_flags), monitor, key_flags);2413 launcher_icon->mouse_down.emit(nux::GetEventButton(button_flags), monitor, key_flags);
@@ -2452,7 +2454,7 @@
24522454
2453 for (it = _model->begin(); it != _model->end(); ++it)2455 for (it = _model->begin(); it != _model->end(); ++it)
2454 {2456 {
2455 if (!(*it)->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) || !(*it)->IsVisibleOnMonitor(monitor))2457 if (!(*it)->IsVisible() || !(*it)->IsVisibleOnMonitor(monitor))
2456 continue;2458 continue;
24572459
2458 nux::Point2 screen_coord [4];2460 nux::Point2 screen_coord [4];
@@ -2537,35 +2539,41 @@
2537 nux::GetWindowCompositor().RestoreRenderingSurface();2539 nux::GetWindowCompositor().RestoreRenderingSurface();
2538}2540}
25392541
2542bool Launcher::DndIsSpecialRequest(std::string const& uri) const
2543{
2544 return (boost::algorithm::ends_with(uri, ".desktop") || uri.find("device://") == 0);
2545}
2546
2540void Launcher::OnDNDDataCollected(const std::list<char*>& mimes)2547void Launcher::OnDNDDataCollected(const std::list<char*>& mimes)
2541{2548{
2542 _dnd_data.Reset();2549 _dnd_data.Reset();
25432550
2544 unity::glib::String uri_list_const(g_strdup("text/uri-list"));2551 const std::string uri_list = "text/uri-list";
2552 auto& display = nux::GetWindowThread()->GetGraphicsDisplay();
25452553
2546 for (auto it : mimes)2554 for (auto const& mime : mimes)
2547 {2555 {
2548 if (!g_str_equal(it, uri_list_const.Value()))2556 if (mime != uri_list)
2549 continue;2557 continue;
25502558
2551 _dnd_data.Fill(nux::GetWindowThread()->GetGraphicsDisplay().GetDndData(uri_list_const.Value()));2559 _dnd_data.Fill(display.GetDndData(const_cast<char*>(uri_list.c_str())));
2552 break;2560 break;
2553 }2561 }
25542562
2555 _hide_machine.SetQuirk(LauncherHideMachine::EXTERNAL_DND_ACTIVE, true);2563 _hide_machine.SetQuirk(LauncherHideMachine::EXTERNAL_DND_ACTIVE, true);
25562564
2557 for (auto it : _dnd_data.Uris())2565 auto const& uris = _dnd_data.Uris();
2566 if (std::find_if(uris.begin(), uris.end(), [this] (std::string const& uri)
2567 {return DndIsSpecialRequest(uri);}) != uris.end())
2558 {2568 {
2559 if (g_str_has_suffix(it.c_str(), ".desktop") || g_str_has_prefix(it.c_str(), "device://"))2569 _steal_drag = true;
2560 {2570
2561 _steal_drag = true;2571 if (IsOverlayOpen())
2562 break;2572 SaturateIcons();
2563 }
2564 }2573 }
25652574 else
2566 if (!_steal_drag)
2567 {2575 {
2568 for (auto it : *_model)2576 for (auto const& it : *_model)
2569 {2577 {
2570 if (it->ShouldHighlightOnDrag(_dnd_data))2578 if (it->ShouldHighlightOnDrag(_dnd_data))
2571 {2579 {
@@ -2579,11 +2587,6 @@
2579 }2587 }
2580 }2588 }
2581 }2589 }
2582 else
2583 {
2584 if (IsOverlayOpen())
2585 SaturateIcons();
2586 }
2587}2590}
25882591
2589void Launcher::ProcessDndEnter()2592void Launcher::ProcessDndEnter()
@@ -2651,32 +2654,29 @@
26512654
2652void Launcher::ProcessDndMove(int x, int y, std::list<char*> mimes)2655void Launcher::ProcessDndMove(int x, int y, std::list<char*> mimes)
2653{2656{
2654 nux::Area* parent = GetToplevel();
2655 unity::glib::String uri_list_const(g_strdup("text/uri-list"));
2656
2657 if (!_data_checked)2657 if (!_data_checked)
2658 {2658 {
2659 const std::string uri_list = "text/uri-list";
2659 _data_checked = true;2660 _data_checked = true;
2660 _dnd_data.Reset();2661 _dnd_data.Reset();
2662 auto& display = nux::GetWindowThread()->GetGraphicsDisplay();
26612663
2662 // get the data2664 // get the data
2663 for (auto it : mimes)2665 for (auto const& mime : mimes)
2664 {2666 {
2665 if (!g_str_equal(it, uri_list_const.Value()))2667 if (mime != uri_list)
2666 continue;2668 continue;
26672669
2668 _dnd_data.Fill(nux::GetWindowThread()->GetGraphicsDisplay().GetDndData(uri_list_const.Value()));2670 _dnd_data.Fill(display.GetDndData(const_cast<char*>(uri_list.c_str())));
2669 break;2671 break;
2670 }2672 }
26712673
2672 // see if the launcher wants this one2674 // see if the launcher wants this one
2673 for (auto it : _dnd_data.Uris())2675 auto const& uris = _dnd_data.Uris();
2676 if (std::find_if(uris.begin(), uris.end(), [this] (std::string const& uri)
2677 {return DndIsSpecialRequest(uri);}) != uris.end())
2674 {2678 {
2675 if (g_str_has_suffix(it.c_str(), ".desktop") || g_str_has_prefix(it.c_str(), "device://"))2679 _steal_drag = true;
2676 {
2677 _steal_drag = true;
2678 break;
2679 }
2680 }2680 }
26812681
2682 // only set hover once we know our first x/y2682 // only set hover once we know our first x/y
@@ -2685,7 +2685,7 @@
26852685
2686 if (!_steal_drag)2686 if (!_steal_drag)
2687 {2687 {
2688 for (auto it : *_model)2688 for (auto const& it : *_model)
2689 {2689 {
2690 if (it->ShouldHighlightOnDrag(_dnd_data))2690 if (it->ShouldHighlightOnDrag(_dnd_data))
2691 it->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, false);2691 it->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, false);
@@ -2695,7 +2695,7 @@
2695 }2695 }
2696 }2696 }
26972697
2698 SetMousePosition(x - parent->GetGeometry().x, y - parent->GetGeometry().y);2698 SetMousePosition(x - _parent->GetGeometry().x, y - _parent->GetGeometry().y);
26992699
2700 if (!IsOverlayOpen() && _mouse_position.x == 0 && _mouse_position.y <= (_parent->GetGeometry().height - _icon_size - 2 * _space_between_icons) && !_drag_edge_touching)2700 if (!IsOverlayOpen() && _mouse_position.x == 0 && _mouse_position.y <= (_parent->GetGeometry().height - _icon_size - 2 * _space_between_icons) && !_drag_edge_touching)
2701 {2701 {
@@ -2722,7 +2722,7 @@
2722 if (hovered_icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH)2722 if (hovered_icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH)
2723 _steal_drag = false;2723 _steal_drag = false;
27242724
2725 if (hovered_icon->GetIconType() == AbstractLauncherIcon::IconType::APPLICATION || hovered_icon->GetIconType() == AbstractLauncherIcon::IconType::EXPO)2725 if (hovered_icon->position() == AbstractLauncherIcon::Position::FLOATING)
2726 hovered_icon_is_appropriate = true;2726 hovered_icon_is_appropriate = true;
2727 }2727 }
27282728
@@ -2732,7 +2732,6 @@
2732 if (!_dnd_hovered_icon && hovered_icon_is_appropriate)2732 if (!_dnd_hovered_icon && hovered_icon_is_appropriate)
2733 {2733 {
2734 _dnd_hovered_icon = new SpacerLauncherIcon(monitor());2734 _dnd_hovered_icon = new SpacerLauncherIcon(monitor());
2735 _dnd_hovered_icon->SetSortPriority(G_MAXINT);
2736 _model->AddIcon(_dnd_hovered_icon);2735 _model->AddIcon(_dnd_hovered_icon);
2737 _model->ReorderBefore(_dnd_hovered_icon, hovered_icon, true);2736 _model->ReorderBefore(_dnd_hovered_icon, hovered_icon, true);
2738 }2737 }
@@ -2787,34 +2786,10 @@
2787{2786{
2788 if (_steal_drag)2787 if (_steal_drag)
2789 {2788 {
2790 for (auto it : _dnd_data.Uris())2789 for (auto const& uri : _dnd_data.Uris())
2791 {2790 {
2792 if (g_str_has_suffix(it.c_str(), ".desktop"))2791 if (DndIsSpecialRequest(uri))
2793 {2792 add_request.emit(uri, _dnd_hovered_icon);
2794 char* path = nullptr;
2795
2796 if (g_str_has_prefix(it.c_str(), "application://"))
2797 {
2798 const char* tmp = it.c_str() + strlen("application://");
2799 unity::glib::String tmp2(g_strdup_printf("file:///usr/share/applications/%s", tmp));
2800 path = g_filename_from_uri(tmp2.Value(), NULL, NULL);
2801 }
2802 else if (g_str_has_prefix(it.c_str(), "file://"))
2803 {
2804 path = g_filename_from_uri(it.c_str(), NULL, NULL);
2805 }
2806
2807 if (path)
2808 {
2809 launcher_addrequest.emit(path, _dnd_hovered_icon);
2810 g_free(path);
2811 }
2812 }
2813 else if (devices_settings_ && g_str_has_prefix(it.c_str(), "device://"))
2814 {
2815 const gchar* uuid = it.c_str() + 9;
2816 devices_settings_->TryToUnblacklist(uuid);
2817 }
2818 }2793 }
2819 }2794 }
2820 else if (_dnd_hovered_icon && _drag_action != nux::DNDACTION_NONE)2795 else if (_dnd_hovered_icon && _drag_action != nux::DNDACTION_NONE)
28212796
=== modified file 'launcher/Launcher.h'
--- launcher/Launcher.h 2012-09-01 14:00:19 +0000
+++ launcher/Launcher.h 2012-09-18 15:52:46 +0000
@@ -83,8 +83,6 @@
83 void SetModel(LauncherModel::Ptr model);83 void SetModel(LauncherModel::Ptr model);
84 LauncherModel::Ptr GetModel() const;84 LauncherModel::Ptr GetModel() const;
8585
86 void SetDevicesSettings(DevicesSettings::Ptr devices_settings);
87
88 void StartKeyShowLauncher();86 void StartKeyShowLauncher();
89 void EndKeyShowLauncher();87 void EndKeyShowLauncher();
9088
@@ -121,9 +119,8 @@
121 int GetDragDelta() const;119 int GetDragDelta() const;
122 void SetHover(bool hovered);120 void SetHover(bool hovered);
123121
124 sigc::signal<void, char*, AbstractLauncherIcon::Ptr> launcher_addrequest;122 sigc::signal<void, std::string const&, AbstractLauncherIcon::Ptr> add_request;
125 sigc::signal<void, AbstractLauncherIcon::Ptr> launcher_removerequest;123 sigc::signal<void, AbstractLauncherIcon::Ptr> remove_request;
126 sigc::signal<void, AbstractLauncherIcon::Ptr> icon_animation_complete;
127 sigc::signal<void> selection_change;124 sigc::signal<void> selection_change;
128 sigc::signal<void> hidden_changed;125 sigc::signal<void> hidden_changed;
129 sigc::signal<void> sc_launcher_icon_animation;126 sigc::signal<void> sc_launcher_icon_animation;
@@ -199,7 +196,7 @@
199 void OnSelectionChanged(AbstractLauncherIcon::Ptr selection);196 void OnSelectionChanged(AbstractLauncherIcon::Ptr selection);
200197
201 bool StrutHack();198 bool StrutHack();
202 bool StartIconDragTimeout();199 bool StartIconDragTimeout(int x, int y);
203 bool OnScrollTimeout();200 bool OnScrollTimeout();
204 bool OnUpdateDragManagerTimeout();201 bool OnUpdateDragManagerTimeout();
205202
@@ -319,6 +316,7 @@
319 void DndReset();316 void DndReset();
320 void DndHoveredIconReset();317 void DndHoveredIconReset();
321 void DndTimeoutSetup();318 void DndTimeoutSetup();
319 bool DndIsSpecialRequest(std::string const& uri) const;
322320
323 LauncherModel::Ptr _model;321 LauncherModel::Ptr _model;
324 nux::BaseWindow* _parent;322 nux::BaseWindow* _parent;
@@ -371,6 +369,7 @@
371 int _launcher_drag_delta_min;369 int _launcher_drag_delta_min;
372 int _enter_y;370 int _enter_y;
373 int _last_button_press;371 int _last_button_press;
372 int _drag_icon_position;
374 float _drag_out_delta_x;373 float _drag_out_delta_x;
375 bool _drag_gesture_ongoing;374 bool _drag_gesture_ongoing;
376 float _last_reveal_progress;375 float _last_reveal_progress;
@@ -395,8 +394,6 @@
395 ui::AbstractIconRenderer::Ptr icon_renderer;394 ui::AbstractIconRenderer::Ptr icon_renderer;
396 BackgroundEffectHelper bg_effect_helper_;395 BackgroundEffectHelper bg_effect_helper_;
397396
398 DevicesSettings::Ptr devices_settings_;
399
400 UBusManager ubus_;397 UBusManager ubus_;
401 glib::SourceManager sources_;398 glib::SourceManager sources_;
402399
403400
=== modified file 'launcher/LauncherController.cpp'
--- launcher/LauncherController.cpp 2012-09-11 09:59:25 +0000
+++ launcher/LauncherController.cpp 2012-09-18 15:52:46 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010, 2011 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as6 * it under the terms of the GNU General Public License version 3 as
@@ -16,6 +16,7 @@
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Tim Penhey <tim.penhey@canonical.com>18 * Tim Penhey <tim.penhey@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#include <glib/gi18n-lib.h>22#include <glib/gi18n-lib.h>
@@ -25,6 +26,7 @@
25#include <Nux/HLayout.h>26#include <Nux/HLayout.h>
26#include <Nux/BaseWindow.h>27#include <Nux/BaseWindow.h>
27#include <NuxCore/Logger.h>28#include <NuxCore/Logger.h>
29#include <UnityCore/DesktopUtilities.h>
2830
29#include "LauncherOptions.h"31#include "LauncherOptions.h"
30#include "BamfLauncherIcon.h"32#include "BamfLauncherIcon.h"
@@ -35,6 +37,7 @@
35#include "LauncherController.h"37#include "LauncherController.h"
36#include "LauncherControllerPrivate.h"38#include "LauncherControllerPrivate.h"
37#include "SoftwareCenterLauncherIcon.h"39#include "SoftwareCenterLauncherIcon.h"
40#include "ExpoLauncherIcon.h"
38#include "unity-shared/WindowManager.h"41#include "unity-shared/WindowManager.h"
39#include "TrashLauncherIcon.h"42#include "TrashLauncherIcon.h"
40#include "BFBLauncherIcon.h"43#include "BFBLauncherIcon.h"
@@ -82,63 +85,45 @@
82 const std::string KEYPRESS_TIMEOUT = "keypress-timeout";85 const std::string KEYPRESS_TIMEOUT = "keypress-timeout";
83 const std::string LABELS_TIMEOUT = "label-show-timeout";86 const std::string LABELS_TIMEOUT = "label-show-timeout";
84 const std::string HIDE_TIMEOUT = "hide-timeout";87 const std::string HIDE_TIMEOUT = "hide-timeout";
85}88
86}89 const std::string SOFTWARE_CENTER_AGENT = "software-center-agent";
8790
8891 const std::string RUNNING_APPS_URI = FavoriteStore::URI_PREFIX_UNITY + "running-apps";
92 const std::string DEVICES_URI = FavoriteStore::URI_PREFIX_UNITY + "devices";
93}
94}
8995
90GDBusInterfaceVTable Controller::Impl::interface_vtable =96GDBusInterfaceVTable Controller::Impl::interface_vtable =
91 { Controller::Impl::OnDBusMethodCall, NULL, NULL};97 { Controller::Impl::OnDBusMethodCall, NULL, NULL};
9298
93Controller::Impl::Impl(Display* display, Controller* parent)99
100Controller::Impl::Impl(Controller* parent)
94 : parent_(parent)101 : parent_(parent)
95 , model_(new LauncherModel())102 , model_(std::make_shared<LauncherModel>())
96 , sort_priority_(0)
97 , volume_monitor_(new VolumeMonitorWrapper)
98 , devices_settings_(new DevicesSettingsImp)
99 , device_section_(volume_monitor_, devices_settings_)
100 , show_desktop_icon_(false)
101 , display_(display)
102 , matcher_(bamf_matcher_get_default())103 , matcher_(bamf_matcher_get_default())
104 , device_section_(std::make_shared<VolumeMonitorWrapper>(), std::make_shared<DevicesSettingsImp>())
105 , expo_icon_(new ExpoLauncherIcon())
106 , desktop_icon_(new DesktopLauncherIcon())
107 , sort_priority_(AbstractLauncherIcon::DefaultPriority(AbstractLauncherIcon::IconType::APPLICATION))
108 , launcher_open(false)
109 , launcher_keynav(false)
110 , launcher_grabbed(false)
111 , reactivate_keynav(false)
112 , keynav_restore_window_(true)
113 , launcher_key_press_time_(0)
114 , dbus_owner_(g_bus_own_name(G_BUS_TYPE_SESSION, DBUS_NAME.c_str(), G_BUS_NAME_OWNER_FLAGS_NONE,
115 OnBusAcquired, nullptr, nullptr, this, nullptr))
103{116{
104 edge_barriers_.options = parent_->options();117 edge_barriers_.options = parent_->options();
105118
106 UScreen* uscreen = UScreen::GetDefault();119 UScreen* uscreen = UScreen::GetDefault();
107 auto monitors = uscreen->GetMonitors();120 EnsureLaunchers(uscreen->GetPrimaryMonitor(), uscreen->GetMonitors());
108 int primary = uscreen->GetPrimaryMonitor();121
109122 SetupIcons();
110 launcher_open = false;
111 launcher_keynav = false;
112 launcher_grabbed = false;
113 reactivate_keynav = false;
114 keynav_restore_window_ = true;
115
116 EnsureLaunchers(primary, monitors);
117
118 launcher_ = launchers[0];
119 device_section_.IconAdded.connect(sigc::mem_fun(this, &Impl::OnIconAdded));
120
121 num_workspaces_ = WindowManager::Default()->WorkspaceCount();
122 if (num_workspaces_ > 1)
123 {
124 InsertExpoAction();
125 }
126
127 // Insert the "Show Desktop" launcher icon in the launcher...
128 if (show_desktop_icon_)
129 InsertDesktopIcon();
130
131 InsertTrash();
132
133 sources_.AddTimeout(500, [&] { SetupBamf(); return false; });
134123
135 remote_model_.entry_added.connect(sigc::mem_fun(this, &Impl::OnLauncherEntryRemoteAdded));124 remote_model_.entry_added.connect(sigc::mem_fun(this, &Impl::OnLauncherEntryRemoteAdded));
136 remote_model_.entry_removed.connect(sigc::mem_fun(this, &Impl::OnLauncherEntryRemoteRemoved));125 remote_model_.entry_removed.connect(sigc::mem_fun(this, &Impl::OnLauncherEntryRemoteRemoved));
137126
138 FavoriteStore::Instance().favorite_added.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteAdded));
139 FavoriteStore::Instance().favorite_removed.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteRemoved));
140 FavoriteStore::Instance().reordered.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreReordered));
141
142 LauncherHideMode hide_mode = parent_->options()->hide_mode;127 LauncherHideMode hide_mode = parent_->options()->hide_mode;
143 BFBLauncherIcon* bfb = new BFBLauncherIcon(hide_mode);128 BFBLauncherIcon* bfb = new BFBLauncherIcon(hide_mode);
144 RegisterIcon(AbstractLauncherIcon::Ptr(bfb));129 RegisterIcon(AbstractLauncherIcon::Ptr(bfb));
@@ -146,35 +131,27 @@
146 HudLauncherIcon* hud = new HudLauncherIcon(hide_mode);131 HudLauncherIcon* hud = new HudLauncherIcon(hide_mode);
147 RegisterIcon(AbstractLauncherIcon::Ptr(hud));132 RegisterIcon(AbstractLauncherIcon::Ptr(hud));
148133
149 parent_->options()->hide_mode.changed.connect([bfb,hud](LauncherHideMode mode) {134 TrashLauncherIcon* trash = new TrashLauncherIcon();
135 RegisterIcon(AbstractLauncherIcon::Ptr(trash));
136
137 parent_->options()->hide_mode.changed.connect([bfb, hud](LauncherHideMode mode) {
150 bfb->SetHideMode(mode);138 bfb->SetHideMode(mode);
151 hud->SetHideMode(mode);139 hud->SetHideMode(mode);
152 });140 });
153141
154 desktop_icon_ = AbstractLauncherIcon::Ptr(new DesktopLauncherIcon());
155
156 uscreen->changed.connect(sigc::mem_fun(this, &Controller::Impl::OnScreenChanged));142 uscreen->changed.connect(sigc::mem_fun(this, &Controller::Impl::OnScreenChanged));
157143
158 WindowManager& plugin_adapter = *(WindowManager::Default());144 WindowManager& plugin_adapter = *(WindowManager::Default());
159 plugin_adapter.window_focus_changed.connect (sigc::mem_fun (this, &Controller::Impl::OnWindowFocusChanged));145 plugin_adapter.window_focus_changed.connect(sigc::mem_fun(this, &Controller::Impl::OnWindowFocusChanged));
160
161 launcher_key_press_time_ = 0;
162146
163 ubus.RegisterInterest(UBUS_QUICKLIST_END_KEY_NAV, [&](GVariant * args) {147 ubus.RegisterInterest(UBUS_QUICKLIST_END_KEY_NAV, [&](GVariant * args) {
164 if (reactivate_keynav)148 if (reactivate_keynav)
165 parent_->KeyNavGrab();149 parent_->KeyNavGrab();
166 model_->SetSelection(reactivate_index);150
151 model_->SetSelection(reactivate_index);
167 });152 });
168153
169 parent_->AddChild(model_.get());154 parent_->AddChild(model_.get());
170
171 uscreen->resuming.connect([&]() -> void {
172 for (auto launcher : launchers)
173 launcher->QueueDraw();
174 });
175
176 dbus_owner_ = g_bus_own_name(G_BUS_TYPE_SESSION, DBUS_NAME.c_str(), G_BUS_NAME_OWNER_FLAGS_NONE,
177 OnBusAcquired, nullptr, nullptr, this, nullptr);
178}155}
179156
180Controller::Impl::~Impl()157Controller::Impl::~Impl()
@@ -182,9 +159,9 @@
182 // Since the launchers are in a window which adds a reference to the159 // Since the launchers are in a window which adds a reference to the
183 // launcher, we need to make sure the base windows are unreferenced160 // launcher, we need to make sure the base windows are unreferenced
184 // otherwise the launchers never die.161 // otherwise the launchers never die.
185 for (auto launcher_ptr : launchers)162 for (auto const& launcher_ptr : launchers)
186 {163 {
187 if (launcher_ptr.IsValid())164 if (launcher_ptr)
188 launcher_ptr->GetParent()->UnReference();165 launcher_ptr->GetParent()->UnReference();
189 }166 }
190167
@@ -198,7 +175,7 @@
198 unsigned int launchers_size = launchers.size();175 unsigned int launchers_size = launchers.size();
199 unsigned int last_launcher = 0;176 unsigned int last_launcher = 0;
200177
201 for (unsigned int i = 0; i < num_launchers; i++, last_launcher++)178 for (unsigned int i = 0; i < num_launchers; ++i, ++last_launcher)
202 {179 {
203 if (i >= launchers_size)180 if (i >= launchers_size)
204 {181 {
@@ -232,6 +209,7 @@
232 }209 }
233 }210 }
234211
212 launcher_ = launchers[0];
235 launchers.resize(num_launchers);213 launchers.resize(num_launchers);
236}214}
237215
@@ -240,7 +218,7 @@
240 EnsureLaunchers(primary_monitor, monitors);218 EnsureLaunchers(primary_monitor, monitors);
241}219}
242220
243void Controller::Impl::OnWindowFocusChanged (guint32 xid)221void Controller::Impl::OnWindowFocusChanged(guint32 xid)
244{222{
245 static bool keynav_first_focus = false;223 static bool keynav_first_focus = false;
246224
@@ -264,11 +242,9 @@
264 nux::BaseWindow* launcher_window = new nux::BaseWindow(TEXT("LauncherWindow"));242 nux::BaseWindow* launcher_window = new nux::BaseWindow(TEXT("LauncherWindow"));
265243
266 Launcher* launcher = new Launcher(launcher_window, nux::ObjectPtr<DNDCollectionWindow>(new DNDCollectionWindow));244 Launcher* launcher = new Launcher(launcher_window, nux::ObjectPtr<DNDCollectionWindow>(new DNDCollectionWindow));
267 launcher->display = display_;
268 launcher->monitor = monitor;245 launcher->monitor = monitor;
269 launcher->options = parent_->options();246 launcher->options = parent_->options();
270 launcher->SetModel(model_);247 launcher->SetModel(model_);
271 launcher->SetDevicesSettings(devices_settings_);
272248
273 nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);249 nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);
274 layout->AddView(launcher, 1);250 layout->AddView(launcher, 1);
@@ -283,58 +259,103 @@
283 launcher_window->InputWindowEnableStruts(parent_->options()->hide_mode == LAUNCHER_HIDE_NEVER);259 launcher_window->InputWindowEnableStruts(parent_->options()->hide_mode == LAUNCHER_HIDE_NEVER);
284 launcher_window->SetEnterFocusInputArea(launcher);260 launcher_window->SetEnterFocusInputArea(launcher);
285261
286 launcher->launcher_addrequest.connect(sigc::mem_fun(this, &Impl::OnLauncherAddRequest));262 launcher->add_request.connect(sigc::mem_fun(this, &Impl::OnLauncherAddRequest));
287 launcher->launcher_removerequest.connect(sigc::mem_fun(this, &Impl::OnLauncherRemoveRequest));263 launcher->remove_request.connect(sigc::mem_fun(this, &Impl::OnLauncherRemoveRequest));
288
289 launcher->icon_animation_complete.connect(sigc::mem_fun(this, &Impl::OnSCIconAnimationComplete));
290264
291 parent_->AddChild(launcher);265 parent_->AddChild(launcher);
292266
293 return launcher;267 return launcher;
294}268}
295269
296void Controller::Impl::OnLauncherAddRequest(char* path, AbstractLauncherIcon::Ptr before)270void Controller::Impl::OnLauncherAddRequest(std::string const& icon_uri, AbstractLauncherIcon::Ptr icon_before)
297{271{
298 for (auto it : model_->GetSublist<BamfLauncherIcon> ())272 std::string app_uri;
299 {273
300 if (path && path == it->DesktopFile())274 if (icon_uri.find(FavoriteStore::URI_PREFIX_FILE) == 0)
301 {275 {
302 it->Stick();276 auto const& desktop_path = icon_uri.substr(FavoriteStore::URI_PREFIX_FILE.length());
303 model_->ReorderBefore(it, before, false);277 app_uri = FavoriteStore::URI_PREFIX_APP + DesktopUtilities::GetDesktopID(desktop_path);
304 Save();278 }
305 return;279
306 }280 auto const& icon = GetIconByUri(app_uri.empty() ? icon_uri : app_uri);
307 }281
308282 if (icon)
309 AbstractLauncherIcon::Ptr result = CreateFavorite(path);283 {
310 if (result)284 icon->Stick(false);
311 {285 model_->ReorderAfter(icon, icon_before);
312 RegisterIcon(result);286 }
313 if (before)287 else
314 model_->ReorderBefore(result, before, false);288 {
315 }289 if (icon_before)
316290 RegisterIcon(CreateFavoriteIcon(icon_uri), icon_before->SortPriority());
317 Save();291 else
318}292 RegisterIcon(CreateFavoriteIcon(icon_uri));
319293 }
320void Controller::Impl::Save()294
321{295 SaveIconsOrder();
322 unity::FavoriteList desktop_paths;296}
323297
324 // Updates gsettings favorites.298void Controller::Impl::AddFavoriteKeepingOldPosition(FavoriteList& icons, std::string const& icon_uri) const
325 auto launchers = model_->GetSublist<BamfLauncherIcon> ();299{
326 for (auto icon : launchers)300 auto const& favorites = FavoriteStore::Instance().GetFavorites();
301 auto it = std::find(favorites.rbegin(), favorites.rend(), icon_uri);
302
303 FavoriteList::reverse_iterator icons_it = icons.rbegin();
304
305 while (it != favorites.rend())
306 {
307 icons_it = std::find(icons.rbegin(), icons.rend(), *it);
308
309 if (icons_it != icons.rend())
310 break;
311
312 ++it;
313 }
314
315 icons.insert(icons_it.base(), icon_uri);
316}
317
318void Controller::Impl::SaveIconsOrder()
319{
320 FavoriteList icons;
321 bool found_first_running_app = false;
322 bool found_first_device = false;
323
324 for (auto const& icon : *model_)
327 {325 {
328 if (!icon->IsSticky())326 if (!icon->IsSticky())
327 {
328 if (!icon->IsVisible())
329 continue;
330
331 if (!found_first_running_app && icon->GetIconType() == AbstractLauncherIcon::IconType::APPLICATION)
332 {
333 found_first_running_app = true;
334 icons.push_back(local::RUNNING_APPS_URI);
335 }
336
337 if (!found_first_device && icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE)
338 {
339 found_first_device = true;
340 icons.push_back(local::DEVICES_URI);
341 }
342
329 continue;343 continue;
330344 }
331 std::string const& desktop_file = icon->DesktopFile();345
332346 std::string const& remote_uri = icon->RemoteUri();
333 if (!desktop_file.empty())347
334 desktop_paths.push_back(desktop_file);348 if (!remote_uri.empty())
349 icons.push_back(remote_uri);
335 }350 }
336351
337 unity::FavoriteStore::Instance().SetFavorites(desktop_paths);352 if (!found_first_running_app)
353 AddFavoriteKeepingOldPosition(icons, local::RUNNING_APPS_URI);
354
355 if (!found_first_device)
356 AddFavoriteKeepingOldPosition(icons, local::DEVICES_URI);
357
358 FavoriteStore::Instance().SetFavorites(icons);
338}359}
339360
340void361void
@@ -345,64 +366,53 @@
345 int icon_y,366 int icon_y,
346 int icon_size)367 int icon_size)
347{368{
348 auto bamf_icons = model_->GetSublist<BamfLauncherIcon>();
349 for (auto icon : bamf_icons)
350 {
351 if (icon->DesktopFile() == path)
352 return;
353 }
354
355 // Check if desktop file was supplied, or if it's set to SC's agent369 // Check if desktop file was supplied, or if it's set to SC's agent
356 // See https://bugs.launchpad.net/unity/+bug/1002440370 // See https://bugs.launchpad.net/unity/+bug/1002440
357 if (path.empty() || path == "software-center-agent")371 if (path.empty() || path == local::SOFTWARE_CENTER_AGENT)
358 return;372 return;
359373
360 SoftwareCenterLauncherIcon::Ptr result = CreateSCLauncherIcon(path, aptdaemon_trans_id, icon_path);374 auto const& icon = std::find_if(model_->begin(), model_->end(),
361375 [&path](AbstractLauncherIcon::Ptr const& i) { return (i->DesktopFile() == path); });
362 CurrentLauncher()->ForceReveal(true);376
377 if (icon != model_->end())
378 return;
379
380 auto const& result = CreateSCLauncherIcon(path, aptdaemon_trans_id, icon_path);
363381
364 if (result)382 if (result)
365 {383 {
366 result->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, false);384 // Setting the icon position and adding it to the model, makes the launcher
367 result->Animate(CurrentLauncher(), icon_x, icon_y, icon_size);385 // to compute its center
368 RegisterIcon(result);386 RegisterIcon(result, GetLastIconPriority<BamfLauncherIcon>("", true));
369 Save();387
388 // This will ensure that the center of the new icon is set, so that
389 // the animation could be done properly.
390 sources_.AddIdle([this, icon_x, icon_y, result] {
391 result->Animate(CurrentLauncher(), icon_x, icon_y);
392 return false;
393 });
370 }394 }
371}395}
372396
373void Controller::Impl::OnSCIconAnimationComplete(AbstractLauncherIcon::Ptr icon)
374{
375 icon->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
376 launcher_->ForceReveal(false);
377}
378
379void Controller::Impl::SortAndUpdate()397void Controller::Impl::SortAndUpdate()
380{398{
381 gint shortcut = 1;399 unsigned shortcut = 1;
382400
383 auto launchers = model_->GetSublist<BamfLauncherIcon> ();401 for (auto const& icon : model_->GetSublist<BamfLauncherIcon>())
384 for (auto icon : launchers)
385 {402 {
386 if (shortcut <= 10 && icon->IsVisible())403 if (shortcut <= 10 && icon->IsVisible())
387 {404 {
388 std::stringstream shortcut_string;405 icon->SetShortcut(std::to_string(shortcut % 10)[0]);
389 shortcut_string << (shortcut % 10);
390 icon->SetShortcut(shortcut_string.str()[0]);
391 ++shortcut;406 ++shortcut;
392 }407 }
393 // reset shortcut
394 else408 else
395 {409 {
410 // reset shortcut
396 icon->SetShortcut(0);411 icon->SetShortcut(0);
397 }412 }
398 }413 }
399}414}
400415
401void Controller::Impl::OnIconAdded(AbstractLauncherIcon::Ptr icon)
402{
403 this->RegisterIcon(icon);
404}
405
406void Controller::Impl::OnIconRemoved(AbstractLauncherIcon::Ptr icon)416void Controller::Impl::OnIconRemoved(AbstractLauncherIcon::Ptr icon)
407{417{
408 SortAndUpdate();418 SortAndUpdate();
@@ -428,10 +438,13 @@
428 {438 {
429 auto device_icon = dynamic_cast<VolumeLauncherIcon*>(icon.GetPointer());439 auto device_icon = dynamic_cast<VolumeLauncherIcon*>(icon.GetPointer());
430440
431 if (device_icon && device_icon->CanEject())441 if (device_icon)
432 device_icon->EjectAndShowNotification();442 {
433 else if (device_icon && device_icon->CanStop())443 if (device_icon->CanEject())
434 device_icon->StopDrive();444 device_icon->EjectAndShowNotification();
445 else if (device_icon->CanStop())
446 device_icon->StopDrive();
447 }
435448
436 break;449 break;
437 }450 }
@@ -442,63 +455,63 @@
442455
443void Controller::Impl::OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry)456void Controller::Impl::OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry)
444{457{
445 for (auto icon : *model_)458 if (entry->AppUri().empty())
446 {459 return;
447 if (!icon || icon->RemoteUri().empty())460
448 continue;461 auto const& apps_icons = model_->GetSublist<BamfLauncherIcon>();
449462 auto const& icon = std::find_if(apps_icons.begin(), apps_icons.end(),
450 if (entry->AppUri() == icon->RemoteUri())463 [&entry](AbstractLauncherIcon::Ptr const& i) { return (i->RemoteUri() == entry->AppUri()); });
451 {464
452 icon->InsertEntryRemote(entry);465 if (icon != apps_icons.end())
453 }466 (*icon)->InsertEntryRemote(entry);
454 }
455}467}
456468
457void Controller::Impl::OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry)469void Controller::Impl::OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry)
458{470{
459 for (auto icon : *model_)471 for (auto const& icon : *model_)
460 {
461 icon->RemoveEntryRemote(entry);472 icon->RemoveEntryRemote(entry);
462 }
463}473}
464474
465void Controller::Impl::OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before)475void Controller::Impl::OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before)
466{476{
467 auto bamf_list = model_->GetSublist<BamfLauncherIcon>();477 if (entry == local::RUNNING_APPS_URI || entry == local::DEVICES_URI)
468 AbstractLauncherIcon::Ptr other;478 {
469 if (bamf_list.size() > 0)479 // Since the running apps and the devices are always shown, when added to
470 other = *(bamf_list.begin());480 // the model, we only have to re-order them
481 ResetIconPriorities();
482 return;
483 }
484
485 AbstractLauncherIcon::Ptr other = *(model_->begin());
471486
472 if (!pos.empty())487 if (!pos.empty())
473 {488 {
474 for (auto it : bamf_list)489 for (auto const& it : *model_)
475 {490 {
476 if (it->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) && pos == it->DesktopFile())491 if (it->IsVisible() && pos == it->RemoteUri())
477 other = it;492 other = it;
478 }493 }
479 }494 }
480495
481 for (auto it : bamf_list)496 AbstractLauncherIcon::Ptr const& fav = GetIconByUri(entry);
497 if (fav)
482 {498 {
483 if (entry == it->DesktopFile())499 fav->Stick(false);
484 {500
485 it->Stick(false);501 if (before)
486 if (!before)502 model_->ReorderBefore(fav, other, false);
487 model_->ReorderAfter(it, other);503 else
488 else504 model_->ReorderAfter(fav, other);
489 model_->ReorderBefore(it, other, false);
490 return;
491 }
492 }505 }
493506 else
494 AbstractLauncherIcon::Ptr result = CreateFavorite(entry.c_str());
495 if (result)
496 {507 {
508 AbstractLauncherIcon::Ptr const& result = CreateFavoriteIcon(entry);
497 RegisterIcon(result);509 RegisterIcon(result);
498 if (!before)510
511 if (before)
512 model_->ReorderBefore(result, other, false);
513 else
499 model_->ReorderAfter(result, other);514 model_->ReorderAfter(result, other);
500 else
501 model_->ReorderBefore(result, other, false);
502 }515 }
503516
504 SortAndUpdate();517 SortAndUpdate();
@@ -506,104 +519,132 @@
506519
507void Controller::Impl::OnFavoriteStoreFavoriteRemoved(std::string const& entry)520void Controller::Impl::OnFavoriteStoreFavoriteRemoved(std::string const& entry)
508{521{
509 for (auto icon : model_->GetSublist<BamfLauncherIcon> ())522 if (entry == local::RUNNING_APPS_URI || entry == local::DEVICES_URI)
510 {523 {
511 if (icon->DesktopFile() == entry)524 // Since the running apps and the devices are always shown, when added to
512 {525 // the model, we only have to re-order them
513 icon->UnStick();526 ResetIconPriorities();
514 break;527 return;
515 }528 }
529
530 auto const& icon = GetIconByUri(entry);
531 if (icon)
532 {
533 icon->UnStick();
534
535 // When devices are removed from favorites, they should be re-ordered (not removed)
536 if (icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE)
537 ResetIconPriorities();
516 }538 }
517}539}
518540
519void Controller::Impl::OnFavoriteStoreReordered()541void Controller::Impl::ResetIconPriorities()
520{542{
521 FavoriteList const& favs = FavoriteStore::Instance().GetFavorites();543 FavoriteList const& favs = FavoriteStore::Instance().GetFavorites();
522 auto bamf_list = model_->GetSublist<BamfLauncherIcon>();544 auto const& apps_icons = model_->GetSublist<BamfLauncherIcon>();
523545 auto const& volumes_icons = model_->GetSublist<VolumeLauncherIcon>();
524 int i = 0;546 bool running_apps_found = false;
525 for (auto it : favs)547 bool volumes_found = false;
526 {548
527 auto icon = std::find_if(bamf_list.begin(), bamf_list.end(),549 for (auto const& fav : favs)
528 [&it](AbstractLauncherIcon::Ptr x) { return (x->DesktopFile() == it); });550 {
529551 if (fav == local::RUNNING_APPS_URI)
530 if (icon != bamf_list.end())552 {
531 {553 for (auto const& ico : apps_icons)
532 (*icon)->SetSortPriority(i++);554 {
533 }555 if (!ico->IsSticky())
534 }556 ico->SetSortPriority(++sort_priority_);
535557 }
536 for (auto it : bamf_list)558
537 {559 running_apps_found = true;
538 if (!it->IsSticky())560 continue;
539 it->SetSortPriority(i++);561 }
562 else if (fav == local::DEVICES_URI)
563 {
564 for (auto const& ico : volumes_icons)
565 {
566 if (!ico->IsSticky())
567 ico->SetSortPriority(++sort_priority_);
568 }
569
570 volumes_found = true;
571 continue;
572 }
573
574 auto const& icon = GetIconByUri(fav);
575
576 if (icon)
577 icon->SetSortPriority(++sort_priority_);
578 }
579
580 if (!running_apps_found)
581 {
582 for (auto const& ico : apps_icons)
583 {
584 if (!ico->IsSticky())
585 ico->SetSortPriority(++sort_priority_);
586 }
587 }
588
589 if (!volumes_found)
590 {
591 for (auto const& ico : volumes_icons)
592 {
593 if (!ico->IsSticky())
594 ico->SetSortPriority(++sort_priority_);
595 }
540 }596 }
541597
542 model_->Sort();598 model_->Sort();
543}599}
544600
545void Controller::Impl::OnExpoActivated()
546{
547 WindowManager::Default()->InitiateExpo();
548}
549
550void Controller::Impl::InsertTrash()
551{
552 AbstractLauncherIcon::Ptr icon(new TrashLauncherIcon());
553 RegisterIcon(icon);
554}
555
556void Controller::Impl::UpdateNumWorkspaces(int workspaces)601void Controller::Impl::UpdateNumWorkspaces(int workspaces)
557{602{
558 if ((num_workspaces_ == 0) && (workspaces > 0))603 bool visible = expo_icon_->IsVisible();
559 {604 bool wp_enabled = (workspaces > 1);
560 InsertExpoAction();605
561 }606 if (wp_enabled && !visible)
562 else if ((num_workspaces_ > 0) && (workspaces == 0))607 {
563 {608 if (FavoriteStore::Instance().IsFavorite(expo_icon_->RemoteUri()))
564 RemoveExpoAction();609 {
565 }610 expo_icon_->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
566611 }
567 num_workspaces_ = workspaces;612 }
568}613 else if (!wp_enabled && visible)
569614 {
570void Controller::Impl::InsertExpoAction()615 expo_icon_->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, false);
571{616 }
572 expo_icon_ = AbstractLauncherIcon::Ptr(new SimpleLauncherIcon(AbstractLauncherIcon::IconType::EXPO));617}
573618
574 SimpleLauncherIcon* icon = static_cast<SimpleLauncherIcon*>(expo_icon_.GetPointer());619void Controller::Impl::RegisterIcon(AbstractLauncherIcon::Ptr icon, int priority)
575 icon->tooltip_text = _("Workspace Switcher");620{
576 icon->icon_name = "workspace-switcher";621 if (!icon || model_->IconIndex(icon) >= 0)
577 icon->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);622 return;
578 icon->SetQuirk(AbstractLauncherIcon::Quirk::RUNNING, false);623
579 icon->SetShortcut('s');624 if (priority != std::numeric_limits<int>::min())
580625 icon->SetSortPriority(priority);
581 on_expoicon_activate_connection_ = icon->activate.connect(sigc::mem_fun(this, &Impl::OnExpoActivated));626
582627 icon->position_saved.connect([this] {
583628 // These calls must be done in order: first we save the new sticky icons
584 RegisterIcon(expo_icon_);629 // then we re-order the model so that there won't be two icons with the same
585}630 // priority
586631 SaveIconsOrder();
587void Controller::Impl::RemoveExpoAction()632 ResetIconPriorities();
588{633 });
589 if (on_expoicon_activate_connection_)634
590 on_expoicon_activate_connection_.disconnect();635 std::string const& icon_uri = icon->RemoteUri();
591 model_->RemoveIcon(expo_icon_);636 icon->position_forgot.connect([this, icon_uri] {
592}637 FavoriteStore::Instance().RemoveFavorite(icon_uri);
593638 });
594void Controller::Impl::InsertDesktopIcon()639
595{640 if (icon->GetIconType() == AbstractLauncherIcon::IconType::APPLICATION)
596 RegisterIcon(desktop_icon_);641 {
597}642 icon->visibility_changed.connect(sigc::mem_fun(this, &Impl::SortAndUpdate));
598643 SortAndUpdate();
599void Controller::Impl::RemoveDesktopIcon()644 }
600{645
601 model_->RemoveIcon(desktop_icon_);
602}
603
604void Controller::Impl::RegisterIcon(AbstractLauncherIcon::Ptr icon)
605{
606 model_->AddIcon(icon);646 model_->AddIcon(icon);
647
607 std::string const& path = icon->DesktopFile();648 std::string const& path = icon->DesktopFile();
608649
609 if (!path.empty())650 if (!path.empty())
@@ -615,7 +656,59 @@
615 }656 }
616}657}
617658
618/* static private */659template<typename IconType>
660int Controller::Impl::GetLastIconPriority(std::string const& favorite_uri, bool sticky)
661{
662 auto const& icons = model_->GetSublist<IconType>();
663 int icon_prio = std::numeric_limits<int>::min();
664
665 AbstractLauncherIcon::Ptr last_icon;
666
667 // Get the last (non)-sticky icon position (if available)
668 for (auto it = icons.rbegin(); it != icons.rend(); ++it)
669 {
670 auto const& icon = *it;
671 bool update_last_icon = ((!last_icon && !sticky) || sticky);
672
673 if (update_last_icon || icon->IsSticky() == sticky)
674 {
675 last_icon = icon;
676
677 if (icon->IsSticky() == sticky)
678 break;
679 }
680 }
681
682 if (last_icon)
683 {
684 icon_prio = last_icon->SortPriority();
685
686 if (sticky && last_icon->IsSticky() != sticky)
687 icon_prio -= 1;
688 }
689 else if (!favorite_uri.empty())
690 {
691 // If we have no applications opened, we must guess it position by favorites
692 for (auto const& fav : FavoriteStore::Instance().GetFavorites())
693 {
694 if (fav == favorite_uri)
695 {
696 if (icon_prio == std::numeric_limits<int>::min())
697 icon_prio = (*model_->begin())->SortPriority() - 1;
698
699 break;
700 }
701
702 auto const& icon = GetIconByUri(fav);
703
704 if (icon)
705 icon_prio = icon->SortPriority();
706 }
707 }
708
709 return icon_prio;
710}
711
619void Controller::Impl::OnViewOpened(BamfMatcher* matcher, BamfView* view)712void Controller::Impl::OnViewOpened(BamfMatcher* matcher, BamfView* view)
620{713{
621 if (!BAMF_IS_APPLICATION(view))714 if (!BAMF_IS_APPLICATION(view))
@@ -630,35 +723,111 @@
630 }723 }
631724
632 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));725 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
633 icon->visibility_changed.connect(sigc::mem_fun(this, &Impl::SortAndUpdate));726 RegisterIcon(icon, GetLastIconPriority<BamfLauncherIcon>(local::RUNNING_APPS_URI));
634 icon->SetSortPriority(sort_priority_++);727}
635 RegisterIcon(icon);728
636 SortAndUpdate();729void Controller::Impl::OnDeviceIconAdded(AbstractLauncherIcon::Ptr icon)
637}730{
638731 RegisterIcon(icon, GetLastIconPriority<VolumeLauncherIcon>(local::DEVICES_URI));
639AbstractLauncherIcon::Ptr Controller::Impl::CreateFavorite(const char* file_path)732}
640{733
641 BamfApplication* app;734AbstractLauncherIcon::Ptr Controller::Impl::CreateFavoriteIcon(std::string const& icon_uri)
735{
642 AbstractLauncherIcon::Ptr result;736 AbstractLauncherIcon::Ptr result;
643737
644 app = bamf_matcher_get_application_for_desktop_file(matcher_, file_path, true);738 if (!FavoriteStore::IsValidFavoriteUri(icon_uri))
645 if (!app)739 {
646 return result;740 LOG_WARNING(logger) << "Ignoring favorite '" << icon_uri << "'.";
647741 return result;
648 if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))742 }
649 {743
650 bamf_view_set_sticky(BAMF_VIEW(app), true);744 std::string desktop_id;
651 return result;745
652 }746 if (icon_uri.find(FavoriteStore::URI_PREFIX_APP) == 0)
653747 {
654 bamf_view_set_sticky(BAMF_VIEW(app), true);748 desktop_id = icon_uri.substr(FavoriteStore::URI_PREFIX_APP.size());
655 AbstractLauncherIcon::Ptr icon (new BamfLauncherIcon(app));749 }
656 icon->SetSortPriority(sort_priority_++);750 else if (icon_uri.find(FavoriteStore::URI_PREFIX_FILE) == 0)
657 result = icon;751 {
752 desktop_id = icon_uri.substr(FavoriteStore::URI_PREFIX_FILE.size());
753 }
754
755 if (!desktop_id.empty())
756 {
757 BamfApplication* app;
758 std::string const& desktop_path = DesktopUtilities::GetDesktopPathById(desktop_id);
759
760 app = bamf_matcher_get_application_for_desktop_file(matcher_, desktop_path.c_str(), true);
761
762 if (!app)
763 return result;
764
765 if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
766 {
767 bamf_view_set_sticky(BAMF_VIEW(app), true);
768 return result;
769 }
770
771 result = AbstractLauncherIcon::Ptr(new BamfLauncherIcon(app));
772 }
773 else if (icon_uri.find(FavoriteStore::URI_PREFIX_DEVICE) == 0)
774 {
775 auto const& devices = device_section_.GetIcons();
776 auto const& icon = std::find_if(devices.begin(), devices.end(),
777 [&icon_uri](AbstractLauncherIcon::Ptr const& i) { return (i->RemoteUri() == icon_uri); });
778
779 if (icon == devices.end())
780 {
781 // Using an idle to remove the favorite, not to erase while iterating
782 sources_.AddIdle([this, icon_uri] {
783 FavoriteStore::Instance().RemoveFavorite(icon_uri);
784 return false;
785 });
786
787 return result;
788 }
789
790 result = *icon;
791 }
792 else if (desktop_icon_->RemoteUri() == icon_uri)
793 {
794 result = desktop_icon_;
795 }
796 else if (expo_icon_->RemoteUri() == icon_uri)
797 {
798 result = expo_icon_;
799 }
800
801 if (result)
802 {
803 if (!result->IsSticky())
804 result->Stick(false);
805 else
806 {
807 LOG_ERROR(logger) << "Ignoring favorite '" << icon_uri << "': it's already on the launcher!";
808 result = nullptr;
809 }
810 }
658811
659 return result;812 return result;
660}813}
661814
815AbstractLauncherIcon::Ptr Controller::Impl::GetIconByUri(std::string const& icon_uri)
816{
817 if (icon_uri.empty())
818 return AbstractLauncherIcon::Ptr();
819
820 auto const& icon = std::find_if(model_->begin(), model_->end(),
821 [&icon_uri](AbstractLauncherIcon::Ptr const& i) { return (i->RemoteUri() == icon_uri); });
822
823 if (icon != model_->end())
824 {
825 return *icon;
826 }
827
828 return AbstractLauncherIcon::Ptr();
829}
830
662SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::string const& file_path,831SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::string const& file_path,
663 std::string const& aptdaemon_trans_id,832 std::string const& aptdaemon_trans_id,
664 std::string const& icon_path)833 std::string const& icon_path)
@@ -678,50 +847,79 @@
678847
679 bamf_view_set_sticky(BAMF_VIEW(app), true);848 bamf_view_set_sticky(BAMF_VIEW(app), true);
680 result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);849 result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);
681 result->SetSortPriority(sort_priority_++);
682850
683 return result;851 return result;
684}852}
685853
686void Controller::Impl::SetupBamf()854void Controller::Impl::AddRunningApps()
687{855{
688 GList* apps, *l;856 std::shared_ptr<GList> apps(bamf_matcher_get_applications(matcher_), g_list_free);
689 BamfApplication* app;857
690858 for (GList *l = apps.get(); l; l = l->next)
691 FavoriteList const& favs = FavoriteStore::Instance().GetFavorites();859 {
692860 if (!BAMF_IS_APPLICATION(l->data))
693 for (FavoriteList::const_iterator i = favs.begin(), end = favs.end();861 continue;
694 i != end; ++i)862
695 {863 BamfApplication* app = BAMF_APPLICATION(l->data);
696 AbstractLauncherIcon::Ptr fav = CreateFavorite(i->c_str());864
697865 if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
698 if (fav)866 continue;
699 {867
700 fav->SetSortPriority(sort_priority_++);868 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
701 RegisterIcon(fav);869 RegisterIcon(icon, ++sort_priority_);
702 }870 }
703 }871}
704872
705 apps = bamf_matcher_get_applications(matcher_);873void Controller::Impl::AddDevices()
874{
875 auto& fav_store = FavoriteStore::Instance();
876 for (auto const& icon : device_section_.GetIcons())
877 {
878 if (!icon->IsSticky() && !fav_store.IsFavorite(icon->RemoteUri()))
879 RegisterIcon(icon, ++sort_priority_);
880 }
881}
882
883void Controller::Impl::SetupIcons()
884{
885 auto& favorite_store = FavoriteStore::Instance();
886 FavoriteList const& favs = favorite_store.GetFavorites();
887 bool running_apps_added = false;
888 bool devices_added = false;
889
890 for (auto const& fav_uri : favs)
891 {
892 if (fav_uri == local::RUNNING_APPS_URI)
893 {
894 AddRunningApps();
895 running_apps_added = true;
896 continue;
897 }
898 else if (fav_uri == local::DEVICES_URI)
899 {
900 AddDevices();
901 devices_added = true;
902 continue;
903 }
904
905 RegisterIcon(CreateFavoriteIcon(fav_uri), ++sort_priority_);
906 }
907
908 if (!running_apps_added)
909 AddRunningApps();
910
911 if (!devices_added)
912 AddDevices();
913
706 view_opened_signal_.Connect(matcher_, "view-opened", sigc::mem_fun(this, &Impl::OnViewOpened));914 view_opened_signal_.Connect(matcher_, "view-opened", sigc::mem_fun(this, &Impl::OnViewOpened));
707915 device_section_.icon_added.connect(sigc::mem_fun(this, &Impl::OnDeviceIconAdded));
708 for (l = apps; l; l = l->next)916 favorite_store.favorite_added.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteAdded));
709 {917 favorite_store.favorite_removed.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteRemoved));
710 app = BAMF_APPLICATION(l->data);918 favorite_store.reordered.connect(sigc::mem_fun(this, &Impl::ResetIconPriorities));
711
712 if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
713 continue;
714
715 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
716 icon->SetSortPriority(sort_priority_++);
717 RegisterIcon(icon);
718 }
719 g_list_free(apps);
720 SortAndUpdate();
721919
722 model_->order_changed.connect(sigc::mem_fun(this, &Impl::SortAndUpdate));920 model_->order_changed.connect(sigc::mem_fun(this, &Impl::SortAndUpdate));
723 model_->icon_removed.connect(sigc::mem_fun(this, &Impl::OnIconRemoved));921 model_->icon_removed.connect(sigc::mem_fun(this, &Impl::OnIconRemoved));
724 model_->saved.connect(sigc::mem_fun(this, &Impl::Save));922 model_->saved.connect(sigc::mem_fun(this, &Impl::SaveIconsOrder));
725}923}
726924
727void Controller::Impl::SendHomeActivationRequest()925void Controller::Impl::SendHomeActivationRequest()
@@ -729,10 +927,10 @@
729 ubus.SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, g_variant_new("(sus)", "home.lens", dash::NOT_HANDLED, ""));927 ubus.SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, g_variant_new("(sus)", "home.lens", dash::NOT_HANDLED, ""));
730}928}
731929
732Controller::Controller(Display* display)930Controller::Controller()
733 : options(Options::Ptr(new Options()))931 : options(Options::Ptr(new Options()))
734 , multiple_launchers(true)932 , multiple_launchers(true)
735 , pimpl(new Impl(display, this))933 , pimpl(new Impl(this))
736{934{
737 multiple_launchers.changed.connect([&](bool value) -> void {935 multiple_launchers.changed.connect([&](bool value) -> void {
738 UScreen* uscreen = UScreen::GetDefault();936 UScreen* uscreen = UScreen::GetDefault();
@@ -814,19 +1012,6 @@
814 pimpl->launcher_->GetParent()->PushToFront();1012 pimpl->launcher_->GetParent()->PushToFront();
815}1013}
8161014
817void Controller::SetShowDesktopIcon(bool show_desktop_icon)
818{
819 if (pimpl->show_desktop_icon_ == show_desktop_icon)
820 return;
821
822 pimpl->show_desktop_icon_ = show_desktop_icon;
823
824 if (pimpl->show_desktop_icon_)
825 pimpl->InsertDesktopIcon();
826 else
827 pimpl->RemoveDesktopIcon();
828}
829
830int Controller::Impl::MonitorWithMouse()1015int Controller::Impl::MonitorWithMouse()
831{1016{
832 UScreen* uscreen = UScreen::GetDefault();1017 UScreen* uscreen = UScreen::GetDefault();
@@ -1110,7 +1295,7 @@
1110 timespec current;1295 timespec current;
1111 clock_gettime(CLOCK_MONOTONIC, &current);1296 clock_gettime(CLOCK_MONOTONIC, &current);
11121297
1113 unity::variant::BuilderWrapper(builder)1298 variant::BuilderWrapper(builder)
1114 .add("key_nav_is_active", KeyNavIsActive())1299 .add("key_nav_is_active", KeyNavIsActive())
1115 .add("key_nav_launcher_monitor", pimpl->keyboard_launcher_.IsValid() ? pimpl->keyboard_launcher_->monitor : -1)1300 .add("key_nav_launcher_monitor", pimpl->keyboard_launcher_.IsValid() ? pimpl->keyboard_launcher_->monitor : -1)
1116 .add("key_nav_selection", pimpl->model_->SelectionIndex())1301 .add("key_nav_selection", pimpl->model_->SelectionIndex())
11171302
=== modified file 'launcher/LauncherController.h'
--- launcher/LauncherController.h 2012-08-11 09:16:21 +0000
+++ launcher/LauncherController.h 2012-09-18 15:52:46 +0000
@@ -47,7 +47,7 @@
47 nux::Property<Options::Ptr> options;47 nux::Property<Options::Ptr> options;
48 nux::Property<bool> multiple_launchers;48 nux::Property<bool> multiple_launchers;
4949
50 Controller(Display* display);50 Controller();
51 ~Controller();51 ~Controller();
5252
53 Launcher& launcher() const;53 Launcher& launcher() const;
@@ -61,8 +61,6 @@
6161
62 void PushToFront();62 void PushToFront();
6363
64 void SetShowDesktopIcon(bool show_desktop_icon);
65
66 bool AboutToShowDash(int was_tap, int when) const;64 bool AboutToShowDash(int was_tap, int when) const;
6765
68 void HandleLauncherKeyPress(int when);66 void HandleLauncherKeyPress(int when);
6967
=== modified file 'launcher/LauncherControllerPrivate.h'
--- launcher/LauncherControllerPrivate.h 2012-08-17 13:07:53 +0000
+++ launcher/LauncherControllerPrivate.h 2012-09-18 15:52:46 +0000
@@ -46,59 +46,53 @@
46class Controller::Impl46class Controller::Impl
47{47{
48public:48public:
49 Impl(Display* display, Controller* parent);49 Impl(Controller* parent);
50 ~Impl();50 ~Impl();
5151
52 void UpdateNumWorkspaces(int workspaces);52 void UpdateNumWorkspaces(int workspaces);
5353
54 Launcher* CreateLauncher(int monitor);54 Launcher* CreateLauncher(int monitor);
5555
56 void Save();56 void SaveIconsOrder();
57 void SortAndUpdate();57 void SortAndUpdate();
5858
59 nux::ObjectPtr<Launcher> CurrentLauncher();59 nux::ObjectPtr<Launcher> CurrentLauncher();
6060
61 void OnIconAdded(AbstractLauncherIcon::Ptr icon);61 template<typename IconType>
62 int GetLastIconPriority(std::string const& favorite_uri = "", bool sticky = false);
63 void AddFavoriteKeepingOldPosition(FavoriteList& icons, std::string const& icon_uri) const;
64
62 void OnIconRemoved(AbstractLauncherIcon::Ptr icon);65 void OnIconRemoved(AbstractLauncherIcon::Ptr icon);
66 void OnDeviceIconAdded(AbstractLauncherIcon::Ptr icon);
6367
64 void OnLauncherAddRequest(char* path, AbstractLauncherIcon::Ptr before);68 void OnLauncherAddRequest(std::string const& icon_uri, AbstractLauncherIcon::Ptr before);
65 void OnLauncherAddRequestSpecial(std::string const& path, std::string const& aptdaemon_trans_id,69 void OnLauncherAddRequestSpecial(std::string const& path, std::string const& aptdaemon_trans_id,
66 std::string const& icon_path, int icon_x, int icon_y, int icon_size);70 std::string const& icon_path, int icon_x, int icon_y, int icon_size);
67 void OnLauncherRemoveRequest(AbstractLauncherIcon::Ptr icon);71 void OnLauncherRemoveRequest(AbstractLauncherIcon::Ptr icon);
68 void OnSCIconAnimationComplete(AbstractLauncherIcon::Ptr icon);
6972
70 void OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry);73 void OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry);
71 void OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry);74 void OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry);
7275
73 void OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before);76 void OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before);
74 void OnFavoriteStoreFavoriteRemoved(std::string const& entry);77 void OnFavoriteStoreFavoriteRemoved(std::string const& entry);
75 void OnFavoriteStoreReordered();78 void ResetIconPriorities();
76
77
78 void InsertExpoAction();
79 void RemoveExpoAction();
80
81 void InsertDesktopIcon();
82 void RemoveDesktopIcon();
8379
84 void SendHomeActivationRequest();80 void SendHomeActivationRequest();
8581
86 int MonitorWithMouse();82 int MonitorWithMouse();
8783
88 void InsertTrash();84 void RegisterIcon(AbstractLauncherIcon::Ptr icon, int priority = std::numeric_limits<int>::min());
8985
90 void RegisterIcon(AbstractLauncherIcon::Ptr icon);86 AbstractLauncherIcon::Ptr CreateFavoriteIcon(std::string const& icon_uri);
9187 AbstractLauncherIcon::Ptr GetIconByUri(std::string const& icon_uri);
92 AbstractLauncherIcon::Ptr CreateFavorite(const char* file_path);
93
94 SoftwareCenterLauncherIcon::Ptr CreateSCLauncherIcon(std::string const& file_path, std::string const& aptdaemon_trans_id, std::string const& icon_path);88 SoftwareCenterLauncherIcon::Ptr CreateSCLauncherIcon(std::string const& file_path, std::string const& aptdaemon_trans_id, std::string const& icon_path);
9589
96 void SetupBamf();90 void SetupIcons();
91 void AddRunningApps();
92 void AddDevices();
9793
98 void EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors);94 void EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors);
9995
100 void OnExpoActivated();
101
102 void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors);96 void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors);
10397
104 void OnWindowFocusChanged (guint32 xid);98 void OnWindowFocusChanged (guint32 xid);
@@ -123,38 +117,31 @@
123117
124 Controller* parent_;118 Controller* parent_;
125 LauncherModel::Ptr model_;119 LauncherModel::Ptr model_;
120 glib::Object<BamfMatcher> matcher_;
126 nux::ObjectPtr<Launcher> launcher_;121 nux::ObjectPtr<Launcher> launcher_;
127 nux::ObjectPtr<Launcher> keyboard_launcher_;122 nux::ObjectPtr<Launcher> keyboard_launcher_;
128 int sort_priority_;
129 AbstractVolumeMonitorWrapper::Ptr volume_monitor_;
130 DevicesSettingsImp::Ptr devices_settings_;
131 DeviceLauncherSection device_section_;123 DeviceLauncherSection device_section_;
132 LauncherEntryRemoteModel remote_model_;124 LauncherEntryRemoteModel remote_model_;
133 AbstractLauncherIcon::Ptr expo_icon_;125 AbstractLauncherIcon::Ptr expo_icon_;
134 AbstractLauncherIcon::Ptr desktop_icon_;126 AbstractLauncherIcon::Ptr desktop_icon_;
135 int num_workspaces_;
136 bool show_desktop_icon_;
137 Display* display_;
138
139 bool launcher_open;
140 bool launcher_keynav;
141 bool launcher_grabbed;
142 bool reactivate_keynav;
143 int reactivate_index;
144 bool keynav_restore_window_;
145 int launcher_key_press_time_;
146 unsigned int dbus_owner_;
147
148 ui::EdgeBarrierController edge_barriers_;127 ui::EdgeBarrierController edge_barriers_;
149
150 LauncherList launchers;128 LauncherList launchers;
151129
152 glib::Object<BamfMatcher> matcher_;130 unsigned sort_priority_;
131 bool launcher_open;
132 bool launcher_keynav;
133 bool launcher_grabbed;
134 bool reactivate_keynav;
135 int reactivate_index;
136 bool keynav_restore_window_;
137 int launcher_key_press_time_;
138 unsigned dbus_owner_;
139
140
153 glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;141 glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;
154 glib::SourceManager sources_;142 glib::SourceManager sources_;
155 UBusManager ubus;143 UBusManager ubus;
156144
157 sigc::connection on_expoicon_activate_connection_;
158 sigc::connection launcher_key_press_connection_;145 sigc::connection launcher_key_press_connection_;
159 sigc::connection launcher_event_outside_connection_;146 sigc::connection launcher_event_outside_connection_;
160};147};
161148
=== modified file 'launcher/LauncherIcon.cpp'
--- launcher/LauncherIcon.cpp 2012-08-15 02:51:33 +0000
+++ launcher/LauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -74,10 +74,11 @@
7474
75LauncherIcon::LauncherIcon(IconType type)75LauncherIcon::LauncherIcon(IconType type)
76 : _icon_type(type)76 : _icon_type(type)
77 , _sticky(false)
77 , _remote_urgent(false)78 , _remote_urgent(false)
78 , _present_urgency(0)79 , _present_urgency(0)
79 , _progress(0)80 , _progress(0)
80 , _sort_priority(0)81 , _sort_priority(DefaultPriority(type))
81 , _last_monitor(0)82 , _last_monitor(0)
82 , _background_color(nux::color::White)83 , _background_color(nux::color::White)
83 , _glow_color(nux::color::White)84 , _glow_color(nux::color::White)
@@ -89,7 +90,7 @@
89 , _saved_center(max_num_monitors)90 , _saved_center(max_num_monitors)
90 , _allow_quicklist_to_show(true)91 , _allow_quicklist_to_show(true)
91{92{
92 for (unsigned i = 0; i < unsigned(Quirk::LAST); i++)93 for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i)
93 {94 {
94 _quirks[i] = false;95 _quirks[i] = false;
95 _quirk_times[i].tv_sec = 0;96 _quirk_times[i].tv_sec = 0;
@@ -107,10 +108,10 @@
107 tooltip_text.SetSetterFunction(sigc::mem_fun(this, &LauncherIcon::SetTooltipText));108 tooltip_text.SetSetterFunction(sigc::mem_fun(this, &LauncherIcon::SetTooltipText));
108 tooltip_text = "blank";109 tooltip_text = "blank";
109110
111 position = Position::FLOATING;
112
110 // FIXME: the abstraction is already broken, should be fixed for O113 // FIXME: the abstraction is already broken, should be fixed for O
111 // right now, hooking the dynamic quicklist the less ugly possible way114 // right now, hooking the dynamic quicklist the less ugly possible way
112
113
114 mouse_enter.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));115 mouse_enter.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));
115 mouse_leave.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));116 mouse_leave.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));
116 mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));117 mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));
@@ -517,6 +518,7 @@
517518
518 if (!_tooltip)519 if (!_tooltip)
519 LoadTooltip();520 LoadTooltip();
521 _tooltip->SetText(tooltip_text());
520 _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);522 _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
521 _tooltip->ShowWindow(!tooltip_text().empty());523 _tooltip->ShowWindow(!tooltip_text().empty());
522 tooltip_visible.emit(_tooltip);524 tooltip_visible.emit(_tooltip);
@@ -1179,6 +1181,31 @@
1179 remove.emit(AbstractLauncherIcon::Ptr(this));1181 remove.emit(AbstractLauncherIcon::Ptr(this));
1180}1182}
11811183
1184void LauncherIcon::Stick(bool save)
1185{
1186 if (_sticky)
1187 return;
1188
1189 _sticky = true;
1190
1191 if (save)
1192 position_saved.emit();
1193
1194 SetQuirk(Quirk::VISIBLE, true);
1195}
1196
1197void LauncherIcon::UnStick()
1198{
1199 if (!_sticky)
1200 return;
1201
1202 _sticky = false;
1203
1204 position_forgot.emit();
1205
1206 SetQuirk(Quirk::VISIBLE, false);
1207}
1208
11821209
1183} // namespace launcher1210} // namespace launcher
1184} // namespace unity1211} // namespace unity
11851212
=== modified file 'launcher/LauncherIcon.h'
--- launcher/LauncherIcon.h 2012-08-15 02:51:33 +0000
+++ launcher/LauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -108,11 +108,6 @@
108108
109 const bool WindowVisibleOnViewport();109 const bool WindowVisibleOnViewport();
110110
111 virtual bool IsSpacer()
112 {
113 return false;
114 };
115
116 float PresentUrgency();111 float PresentUrgency();
117112
118 float GetProgress();113 float GetProgress();
@@ -188,9 +183,9 @@
188183
189 virtual std::string DesktopFile() { return std::string(""); }184 virtual std::string DesktopFile() { return std::string(""); }
190185
191 virtual bool IsSticky() const { return false; }186 virtual bool IsSticky() const { return _sticky; }
192187
193 virtual bool IsVisible() const { return false; }188 virtual bool IsVisible() const { return GetQuirk(Quirk::VISIBLE); }
194189
195 virtual bool IsVisibleOnMonitor(int monitor) const;190 virtual bool IsVisibleOnMonitor(int monitor) const;
196191
@@ -198,9 +193,9 @@
198193
199 virtual void AboutToRemove() {}194 virtual void AboutToRemove() {}
200195
201 virtual void Stick(bool save = true) {}196 virtual void Stick(bool save = true);
202197
203 virtual void UnStick() {}198 virtual void UnStick();
204199
205protected:200protected:
206 std::vector<nux::Point3> GetCenters();201 std::vector<nux::Point3> GetCenters();
@@ -313,6 +308,7 @@
313308
314 void OnTooltipEnabledChanged(bool value);309 void OnTooltipEnabledChanged(bool value);
315310
311 bool _sticky;
316 bool _remote_urgent;312 bool _remote_urgent;
317 float _present_urgency;313 float _present_urgency;
318 float _progress;314 float _progress;
319315
=== modified file 'launcher/LauncherModel.cpp'
--- launcher/LauncherModel.cpp 2012-09-04 15:51:31 +0000
+++ launcher/LauncherModel.cpp 2012-09-18 15:52:46 +0000
@@ -56,14 +56,14 @@
5656
57bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const57bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const
58{58{
59 return icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH;59 return icon->position() == AbstractLauncherIcon::Position::END;
60}60}
6161
62bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second)62bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second)
63{63{
64 if (first->GetIconType() < second->GetIconType())64 if (first->position() < second->position())
65 return true;65 return true;
66 else if (first->GetIconType() > second->GetIconType())66 else if (first->position() > second->position())
67 return false;67 return false;
6868
69 return first->SortPriority() < second->SortPriority();69 return first->SortPriority() < second->SortPriority();
@@ -163,25 +163,11 @@
163 if (!icon)163 if (!icon)
164 return false;164 return false;
165165
166 const_iterator it;166 auto const& container = IconShouldShelf(icon) ? _inner_shelf : _inner_main;
167 const_iterator end;167
168168 for (auto const& icon_it : container)
169 if (IconShouldShelf(icon))169 {
170 {170 if (icon_it != icon && icon_it->GetIconType() == icon->GetIconType())
171 it = _inner_shelf.begin();
172 end = _inner_shelf.end();
173 }
174 else
175 {
176 it = _inner_main.begin();
177 end = _inner_main.end();
178 }
179
180 for (; it != end; ++it)
181 {
182 AbstractLauncherIcon::Ptr const& iter_icon = *it;
183
184 if (iter_icon != icon && iter_icon->GetIconType() == icon->GetIconType())
185 return true;171 return true;
186 }172 }
187173
@@ -193,16 +179,20 @@
193 if (icon == other || icon.IsNull() || other.IsNull())179 if (icon == other || icon.IsNull() || other.IsNull())
194 return;180 return;
195181
196 if (icon->GetIconType() != other->GetIconType())182 if (icon->position() != other->position())
197 return;183 return;
198184
199 icon->SetSortPriority(other->SortPriority() + 1);185 icon->SetSortPriority(other->SortPriority() + 1);
200186
201 for (auto it = std::next(std::find(begin(), end(), other)); it != end(); ++it)187 for (auto it = std::next(std::find(begin(), end(), other)); it != end(); ++it)
202 {188 {
189 auto const& icon_it = *it;
190
191 if (icon_it == icon)
192 continue;
193
203 // Increasing the priority of the icons next to the other one194 // Increasing the priority of the icons next to the other one
204 auto const& icon_it = *it;195 int new_priority = icon_it->SortPriority() + 2;
205 int new_priority = icon_it->SortPriority() + 1;
206 icon_it->SetSortPriority(new_priority);196 icon_it->SetSortPriority(new_priority);
207 }197 }
208198
@@ -214,7 +204,7 @@
214 if (icon == other || icon.IsNull() || other.IsNull())204 if (icon == other || icon.IsNull() || other.IsNull())
215 return;205 return;
216206
217 if (icon->GetIconType() != other->GetIconType())207 if (icon->position() != other->position())
218 return;208 return;
219209
220 bool found_target = false;210 bool found_target = false;
@@ -228,7 +218,13 @@
228 continue;218 continue;
229 }219 }
230220
231 int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1);221 int old_priority = icon_it->SortPriority();
222 int new_priority = old_priority + (found_target ? 1 : -1);
223
224 // We need to reduce the priority of all the icons previous to 'other'
225 if (icon_it != other && !found_target && other->SortPriority() == old_priority)
226 new_priority -= 1;
227
232 icon_it->SetSortPriority(new_priority);228 icon_it->SetSortPriority(new_priority);
233229
234 if (icon_it == other)230 if (icon_it == other)
@@ -237,7 +233,7 @@
237 icon_it->SaveCenter();233 icon_it->SaveCenter();
238234
239 center = !center;235 center = !center;
240 new_priority = new_priority - 1;236 new_priority += -1;
241 icon->SetSortPriority(new_priority);237 icon->SetSortPriority(new_priority);
242238
243 if (animate && center)239 if (animate && center)
@@ -260,7 +256,7 @@
260 if (icon == other || icon.IsNull() || other.IsNull())256 if (icon == other || icon.IsNull() || other.IsNull())
261 return;257 return;
262258
263 if (icon->GetIconType() != other->GetIconType())259 if (icon->position() != other->position())
264 return;260 return;
265261
266 bool found_icon = false;262 bool found_icon = false;
@@ -276,7 +272,13 @@
276 continue;272 continue;
277 }273 }
278274
279 int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1);275 int old_priority = icon_it->SortPriority();
276 int new_priority = old_priority + (found_target ? 1 : -1);
277
278 // We need to reduce the priority of all the icons previous to 'other'
279 if (icon_it != other && !found_target && other->SortPriority() == old_priority)
280 new_priority -= 1;
281
280 icon_it->SetSortPriority(new_priority);282 icon_it->SetSortPriority(new_priority);
281283
282 if (icon_it == other)284 if (icon_it == other)
@@ -285,7 +287,7 @@
285 icon_it->SaveCenter();287 icon_it->SaveCenter();
286288
287 center = !center;289 center = !center;
288 new_priority = new_priority + (found_icon ? 1 : -1);290 new_priority += found_icon ? 1 : -1;
289 icon->SetSortPriority(new_priority);291 icon->SetSortPriority(new_priority);
290292
291 if (animate && center)293 if (animate && center)
@@ -377,7 +379,7 @@
377379
378 for (auto const& current : _inner)380 for (auto const& current : _inner)
379 {381 {
380 if (current->GetIconType() != icon->GetIconType())382 if (current->position() != icon->position())
381 continue;383 continue;
382384
383 if (!found_target)385 if (!found_target)
384386
=== modified file 'launcher/MockLauncherIcon.h'
--- launcher/MockLauncherIcon.h 2012-09-04 14:13:16 +0000
+++ launcher/MockLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -45,20 +45,20 @@
45 NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon);45 NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon);
46public:46public:
47 MockLauncherIcon(IconType type = IconType::APPLICATION)47 MockLauncherIcon(IconType type = IconType::APPLICATION)
48 : type_(type)48 : icon_(0)
49 , sort_priority_(0)49 , type_(type)
50 , icon_(0)50 , sort_priority_(DefaultPriority(type))
51 , remote_uri_("fake")
51 {52 {
52 tooltip_text = "Mock Icon";53 tooltip_text = "Mock Icon";
54 position = Position::FLOATING;
5355
54 for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i)56 for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i)
55 {
56 quirks_[i] = false;57 quirks_[i] = false;
57 }
58 }58 }
5959
60 std::string GetName() const { return "MockLauncherIcon"; }60 std::string GetName() const { return "MockLauncherIcon"; }
6161
62 void AddProperties(GVariantBuilder* builder) {}62 void AddProperties(GVariantBuilder* builder) {}
6363
64 void HideTooltip() {}64 void HideTooltip() {}
@@ -180,11 +180,6 @@
180 return true;180 return true;
181 }181 }
182182
183 bool IsSpacer()
184 {
185 return false;
186 }
187
188 float PresentUrgency()183 float PresentUrgency()
189 {184 {
190 return 0.0f;185 return 0.0f;
@@ -244,7 +239,7 @@
244239
245 std::string RemoteUri()240 std::string RemoteUri()
246 {241 {
247 return "fake";242 return remote_uri_;
248 }243 }
249244
250 nux::BaseTexture* TextureForSize(int size)245 nux::BaseTexture* TextureForSize(int size)
@@ -293,9 +288,9 @@
293 bool IsVisible() const { return false; }288 bool IsVisible() const { return false; }
294289
295 void AboutToRemove() {}290 void AboutToRemove() {}
296291
297 void Stick(bool save = true) {}292 void Stick(bool save = true) {}
298293
299 void UnStick() {}294 void UnStick() {}
300295
301private:296private:
@@ -346,12 +341,13 @@
346 return result;341 return result;
347 }342 }
348343
344 nux::BaseTexture* icon_;
349 IconType type_;345 IconType type_;
350 int sort_priority_;346 int sort_priority_;
351 nux::BaseTexture* icon_;
352 bool quirks_[unsigned(Quirk::LAST)];347 bool quirks_[unsigned(Quirk::LAST)];
353 timespec quirk_times_[unsigned(Quirk::LAST)];348 timespec quirk_times_[unsigned(Quirk::LAST)];
354 std::map<int, nux::Point3> center_;349 std::map<int, nux::Point3> center_;
350 std::string remote_uri_;
355};351};
356352
357}353}
358354
=== modified file 'launcher/SoftwareCenterLauncherIcon.cpp'
--- launcher/SoftwareCenterLauncherIcon.cpp 2012-08-02 13:16:06 +0000
+++ launcher/SoftwareCenterLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -45,23 +45,19 @@
45, needs_urgent_(false)45, needs_urgent_(false)
46, aptdaemon_trans_id_(aptdaemon_trans_id)46, aptdaemon_trans_id_(aptdaemon_trans_id)
47{47{
4848 SetQuirk(Quirk::VISIBLE, false);
49 aptdaemon_trans_.Connect("PropertyChanged", sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnPropertyChanged));49 aptdaemon_trans_.Connect("PropertyChanged", sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnPropertyChanged));
50 aptdaemon_trans_.Connect("Finished", sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnFinished));50 aptdaemon_trans_.Connect("Finished", sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnFinished));
5151
52 icon_name = icon_path;52 if (!icon_path.empty())
53 icon_name = icon_path;
54
53 if (!aptdaemon_trans_id_.empty()) // Application is being installed, or hasn't been installed yet55 if (!aptdaemon_trans_id_.empty()) // Application is being installed, or hasn't been installed yet
54 tooltip_text = _("Waiting to install");56 tooltip_text = _("Waiting to install");
55}57}
5658
57void SoftwareCenterLauncherIcon::Animate(nux::ObjectPtr<Launcher> launcher,59void SoftwareCenterLauncherIcon::Animate(nux::ObjectPtr<Launcher> const& launcher, int start_x, int start_y)
58 int icon_x,
59 int icon_y,
60 int icon_size)
61{60{
62 int target_x = 0;
63 int target_y = 0;
64
65 launcher_ = launcher;61 launcher_ = launcher;
6662
67 icon_texture_ = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(63 icon_texture_ = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(
@@ -72,30 +68,15 @@
7268
73 drag_window_ = new LauncherDragWindow(icon_texture_);69 drag_window_ = new LauncherDragWindow(icon_texture_);
7470
71 launcher->ForceReveal(true);
75 launcher->RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(),72 launcher->RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(),
76 AbstractLauncherIcon::Ptr(this),73 AbstractLauncherIcon::Ptr(this),
77 icon_texture_);74 icon_texture_);
7875
79 drag_window_->SetBaseXY(icon_x, icon_y);76 auto const& icon_center = GetCenter(launcher->monitor());
77 drag_window_->SetBaseXY(start_x, start_y);
80 drag_window_->ShowWindow(true);78 drag_window_->ShowWindow(true);
8179 drag_window_->SetAnimationTarget(icon_center.x, icon_center.y + (launcher->GetIconSize() / 2));
82 // Find out the center of last BamfLauncherIcon with non-zero co-ordinates
83 auto bamf_icons = launcher->GetModel()->GetSublist<BamfLauncherIcon>();
84 //TODO: don't iterate through them and pick the last one, just use back() to get the last one.
85 for (auto current_bamf_icon : bamf_icons)
86 {
87 auto icon_center = current_bamf_icon->GetCenter(launcher->monitor);
88
89 if (icon_center.x != 0 && icon_center.y != 0)
90 {
91 target_x = icon_center.x;
92 target_y = icon_center.y;
93 }
94 }
95
96 target_y = target_y + (launcher->GetIconSize() / 2);
97 drag_window_->SetAnimationTarget(target_x, target_y);
98
99 drag_window_->on_anim_completed = drag_window_->anim_completed.connect(sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnDragAnimationFinished));80 drag_window_->on_anim_completed = drag_window_->anim_completed.connect(sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnDragAnimationFinished));
100 drag_window_->StartAnimation();81 drag_window_->StartAnimation();
101}82}
@@ -103,23 +84,29 @@
103void SoftwareCenterLauncherIcon::OnDragAnimationFinished()84void SoftwareCenterLauncherIcon::OnDragAnimationFinished()
104{85{
105 drag_window_->ShowWindow(false);86 drag_window_->ShowWindow(false);
106 launcher_->icon_animation_complete.emit(AbstractLauncherIcon::Ptr(this));
107 drag_window_ = nullptr;87 drag_window_ = nullptr;
88 launcher_->ForceReveal(false);
89 launcher_ = nullptr;
90 icon_texture_ = nullptr;
91 SetQuirk(Quirk::VISIBLE, true);
108}92}
10993
110void SoftwareCenterLauncherIcon::ActivateLauncherIcon(ActionArg arg)94void SoftwareCenterLauncherIcon::ActivateLauncherIcon(ActionArg arg)
111{95{
112 if (finished_)96 if (finished_)
113 {97 {
114 if (needs_urgent_)98 if (needs_urgent_)
115 {99 {
116 SetQuirk(Quirk::URGENT, false);100 SetQuirk(Quirk::URGENT, false);
117 needs_urgent_ = false;101 needs_urgent_ = false;
118 }102 }
119 BamfLauncherIcon::ActivateLauncherIcon(arg);103
104 BamfLauncherIcon::ActivateLauncherIcon(arg);
120 }105 }
121 else106 else
122 SetQuirk(Quirk::STARTING, false);107 {
108 SetQuirk(Quirk::STARTING, false);
109 }
123}110}
124111
125void SoftwareCenterLauncherIcon::OnFinished(GVariant *params)112void SoftwareCenterLauncherIcon::OnFinished(GVariant *params)
@@ -135,7 +122,9 @@
135 SetProgress(0.0f);122 SetProgress(0.0f);
136 finished_ = true;123 finished_ = true;
137 needs_urgent_ = true;124 needs_urgent_ = true;
138 } else {125 }
126 else
127 {
139 // failure condition, remove icon again128 // failure condition, remove icon again
140 UnStick();129 UnStick();
141 }130 }
@@ -167,7 +156,7 @@
167156
168std::string SoftwareCenterLauncherIcon::GetName() const157std::string SoftwareCenterLauncherIcon::GetName() const
169{158{
170 return "SoftwareCenterLauncherIcon";159 return "SoftwareCenterLauncherIcon";
171}160}
172161
173}162}
174163
=== modified file 'launcher/SoftwareCenterLauncherIcon.h'
--- launcher/SoftwareCenterLauncherIcon.h 2012-07-25 03:11:05 +0000
+++ launcher/SoftwareCenterLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -42,7 +42,7 @@
42 std::string const& aptdaemon_trans_id,42 std::string const& aptdaemon_trans_id,
43 std::string const& icon_path);43 std::string const& icon_path);
4444
45 void Animate(nux::ObjectPtr<Launcher> launcher, int icon_x, int icon_y, int icon_size);45 void Animate(nux::ObjectPtr<Launcher> const& launcher, int start_x, int start_y);
4646
47 std::string GetName() const;47 std::string GetName() const;
4848
4949
=== modified file 'launcher/SpacerLauncherIcon.cpp'
--- launcher/SpacerLauncherIcon.cpp 2012-08-02 13:16:06 +0000
+++ launcher/SpacerLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -28,7 +28,7 @@
28{28{
2929
30SpacerLauncherIcon::SpacerLauncherIcon(int monitor)30SpacerLauncherIcon::SpacerLauncherIcon(int monitor)
31 : SingleMonitorLauncherIcon(IconType::APPLICATION, monitor)31 : SingleMonitorLauncherIcon(IconType::SPACER, monitor)
32{32{
33 SetQuirk(Quirk::VISIBLE, true);33 SetQuirk(Quirk::VISIBLE, true);
34 SetQuirk(Quirk::RUNNING, false);34 SetQuirk(Quirk::RUNNING, false);
3535
=== modified file 'launcher/SpacerLauncherIcon.h'
--- launcher/SpacerLauncherIcon.h 2012-05-07 19:52:54 +0000
+++ launcher/SpacerLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -32,10 +32,6 @@
32public:32public:
33 SpacerLauncherIcon(int monitor);33 SpacerLauncherIcon(int monitor);
3434
35 bool IsSpacer()
36 {
37 return true;
38 }
39protected:35protected:
40 std::string GetName() const;36 std::string GetName() const;
41};37};
4238
=== modified file 'launcher/StandaloneLauncher.cpp'
--- launcher/StandaloneLauncher.cpp 2012-08-15 02:51:33 +0000
+++ launcher/StandaloneLauncher.cpp 2012-09-18 15:52:46 +0000
@@ -45,7 +45,7 @@
45void ThreadWidgetInit(nux::NThread* thread, void* InitData)45void ThreadWidgetInit(nux::NThread* thread, void* InitData)
46{46{
47// launcherWindow->SetGeometry (nux::Geometry(0, 0, 300, 800));47// launcherWindow->SetGeometry (nux::Geometry(0, 0, 300, 800));
48 controller.reset(new launcher::Controller(0));48 controller.reset(new launcher::Controller());
49}49}
5050
51int main(int argc, char** argv)51int main(int argc, char** argv)
5252
=== modified file 'launcher/TrashLauncherIcon.cpp'
--- launcher/TrashLauncherIcon.cpp 2012-09-07 09:19:33 +0000
+++ launcher/TrashLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -48,6 +48,7 @@
48{48{
49 tooltip_text = _("Trash");49 tooltip_text = _("Trash");
50 icon_name = "user-trash";50 icon_name = "user-trash";
51 position = Position::END;
51 SetQuirk(Quirk::VISIBLE, true);52 SetQuirk(Quirk::VISIBLE, true);
52 SetQuirk(Quirk::RUNNING, false);53 SetQuirk(Quirk::RUNNING, false);
53 SetShortcut('t');54 SetShortcut('t');
5455
=== modified file 'launcher/VolumeLauncherIcon.cpp'
--- launcher/VolumeLauncherIcon.cpp 2012-08-28 17:42:25 +0000
+++ launcher/VolumeLauncherIcon.cpp 2012-09-18 15:52:46 +0000
@@ -26,6 +26,7 @@
26#include "DevicesSettings.h"26#include "DevicesSettings.h"
27#include "Volume.h"27#include "Volume.h"
28#include "VolumeLauncherIcon.h"28#include "VolumeLauncherIcon.h"
29#include "FavoriteStore.h"
2930
30namespace unity31namespace unity
31{32{
@@ -36,7 +37,7 @@
3637
37nux::logging::Logger logger("unity.launcher");38nux::logging::Logger logger("unity.launcher");
3839
39const unsigned int volume_changed_timeout = 500;40const unsigned int volume_changed_timeout = 500;
4041
41}42}
4243
@@ -61,7 +62,7 @@
61 }62 }
6263
63 ~Impl()64 ~Impl()
64 { 65 {
65 volume_changed_conn_.disconnect();66 volume_changed_conn_.disconnect();
66 volume_removed_conn_.disconnect();67 volume_removed_conn_.disconnect();
67 settings_changed_conn_.disconnect();68 settings_changed_conn_.disconnect();
@@ -83,7 +84,7 @@
8384
84 void UpdateKeepInLauncher()85 void UpdateKeepInLauncher()
85 {86 {
86 auto identifier = volume_->GetIdentifier();87 auto const& identifier = volume_->GetIdentifier();
87 keep_in_launcher_ = !devices_settings_->IsABlacklistedDevice(identifier);88 keep_in_launcher_ = !devices_settings_->IsABlacklistedDevice(identifier);
88 }89 }
8990
@@ -104,6 +105,7 @@
104 if (devices_settings_->IsABlacklistedDevice(volume_->GetIdentifier()))105 if (devices_settings_->IsABlacklistedDevice(volume_->GetIdentifier()))
105 devices_settings_->TryToUnblacklist(volume_->GetIdentifier());106 devices_settings_->TryToUnblacklist(volume_->GetIdentifier());
106107
108 parent_->UnStick();
107 parent_->Remove();109 parent_->Remove();
108 }110 }
109111
@@ -163,7 +165,8 @@
163 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);165 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
164166
165 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {167 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {
166 auto identifier = volume_->GetIdentifier();168 auto const& identifier = volume_->GetIdentifier();
169 parent_->UnStick();
167 devices_settings_->TryToBlacklist(identifier);170 devices_settings_->TryToBlacklist(identifier);
168 }));171 }));
169172
@@ -239,6 +242,16 @@
239 menu.push_back(menu_item);242 menu.push_back(menu_item);
240 }243 }
241244
245 std::string GetRemoteUri()
246 {
247 auto const& identifier = volume_->GetIdentifier();
248
249 if (identifier.empty())
250 return "";
251
252 return FavoriteStore::URI_PREFIX_DEVICE + identifier;
253 }
254
242 VolumeLauncherIcon* parent_;255 VolumeLauncherIcon* parent_;
243 bool keep_in_launcher_;256 bool keep_in_launcher_;
244 Volume::Ptr volume_;257 Volume::Ptr volume_;
@@ -293,6 +306,23 @@
293 return pimpl_->GetMenus();306 return pimpl_->GetMenus();
294}307}
295308
309std::string VolumeLauncherIcon::GetRemoteUri()
310{
311 return pimpl_->GetRemoteUri();
312}
313
314void VolumeLauncherIcon::Stick(bool save)
315{
316 SimpleLauncherIcon::Stick(save);
317 pimpl_->devices_settings_->TryToUnblacklist(pimpl_->volume_->GetIdentifier());
318}
319
320void VolumeLauncherIcon::UnStick()
321{
322 SimpleLauncherIcon::UnStick();
323 SetQuirk(Quirk::VISIBLE, true);
324}
325
296//326//
297// Introspection327// Introspection
298//328//
299329
=== modified file 'launcher/VolumeLauncherIcon.h'
--- launcher/VolumeLauncherIcon.h 2012-08-28 17:28:02 +0000
+++ launcher/VolumeLauncherIcon.h 2012-09-18 15:52:46 +0000
@@ -43,7 +43,10 @@
43 void EjectAndShowNotification(); // TODO: rename to private virtual void DoDropToTrash();43 void EjectAndShowNotification(); // TODO: rename to private virtual void DoDropToTrash();
44 bool CanStop() const;44 bool CanStop() const;
45 void StopDrive();45 void StopDrive();
46 void Stick(bool save = true);
47 void UnStick();
46 MenuItemsVector GetMenus();48 MenuItemsVector GetMenus();
49 std::string GetRemoteUri();
4750
48protected:51protected:
49 virtual void ActivateLauncherIcon(ActionArg arg);52 virtual void ActivateLauncherIcon(ActionArg arg);
5053
=== modified file 'manual-tests/Launcher.txt'
--- manual-tests/Launcher.txt 2012-09-17 12:16:31 +0000
+++ manual-tests/Launcher.txt 2012-09-18 15:52:46 +0000
@@ -191,6 +191,21 @@
191 it, and the any pips for running apps show again.191 it, and the any pips for running apps show again.
192192
193193
194Dragging fixed icons does not reorder an icon above or below
195------------------------------------------------------------
196This test is about not reordering when dragging fixed icons.
197
198#. Move the mouse so it is over the BFB launcher icon
199#. Press and hold the mouse button
200#. Try to drag the icon to the right of the launcher.
201#. Move the mouse down at least to the height of the second launcher icon
202 keeping the mouse pressed.
203#. Release
204
205Outcome:
206 * No icon should be dragged.
207
208
194Dragged launcher icons out of the launcher are properly drawn209Dragged launcher icons out of the launcher are properly drawn
195-------------------------------------------------------------210-------------------------------------------------------------
196This test ensures that the launcher icons out of the launcher are properly drawn211This test ensures that the launcher icons out of the launcher are properly drawn
197212
=== modified file 'panel/PanelMenuView.h'
--- panel/PanelMenuView.h 2012-08-22 04:30:28 +0000
+++ panel/PanelMenuView.h 2012-09-18 15:52:46 +0000
@@ -136,7 +136,6 @@
136 glib::Object<BamfMatcher> _matcher;136 glib::Object<BamfMatcher> _matcher;
137137
138 nux::TextureLayer* _title_layer;138 nux::TextureLayer* _title_layer;
139 nux::HLayout* _menu_layout;
140 nux::ObjectPtr<WindowButtons> _window_buttons;139 nux::ObjectPtr<WindowButtons> _window_buttons;
141 nux::ObjectPtr<PanelTitlebarGrabArea> _titlebar_grab_area;140 nux::ObjectPtr<PanelTitlebarGrabArea> _titlebar_grab_area;
142 nux::ObjectPtr<nux::BaseTexture> _title_texture;141 nux::ObjectPtr<nux::BaseTexture> _title_texture;
143142
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-09-17 10:20:33 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-09-18 15:52:46 +0000
@@ -266,7 +266,6 @@
266 optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));266 optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
267 optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));267 optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
268 optionSetShortcutOverlayNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));268 optionSetShortcutOverlayNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
269 optionSetShowDesktopIconNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
270 optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));269 optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));
271 optionSetShowLauncherTerminate(boost::bind(&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));270 optionSetShowLauncherTerminate(boost::bind(&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));
272 optionSetKeyboardFocusInitiate(boost::bind(&UnityScreen::setKeyboardFocusKeyInitiate, this, _1, _2, _3));271 optionSetKeyboardFocusInitiate(boost::bind(&UnityScreen::setKeyboardFocusKeyInitiate, this, _1, _2, _3));
@@ -2842,9 +2841,6 @@
2842 enable_shortcut_overlay_ = optionGetShortcutOverlay();2841 enable_shortcut_overlay_ = optionGetShortcutOverlay();
2843 shortcut_controller_->SetEnabled(enable_shortcut_overlay_);2842 shortcut_controller_->SetEnabled(enable_shortcut_overlay_);
2844 break;2843 break;
2845 case UnityshellOptions::ShowDesktopIcon:
2846 launcher_controller_->SetShowDesktopIcon(optionGetShowDesktopIcon());
2847 break;
2848 case UnityshellOptions::DecayRate:2844 case UnityshellOptions::DecayRate:
2849 launcher_options->edge_decay_rate = optionGetDecayRate() * 100;2845 launcher_options->edge_decay_rate = optionGetDecayRate() * 100;
2850 break;2846 break;
@@ -2917,11 +2913,13 @@
2917 CompOption::Value& v)2913 CompOption::Value& v)
2918{2914{
2919 bool status = screen->setOptionForPlugin(plugin, name, v);2915 bool status = screen->setOptionForPlugin(plugin, name, v);
2916
2920 if (status)2917 if (status)
2921 {2918 {
2922 if (strcmp(plugin, "core") == 0 && strcmp(name, "hsize") == 0)2919 if (strcmp(plugin, "core") == 0)
2923 {2920 {
2924 launcher_controller_->UpdateNumWorkspaces(screen->vpSize().width() * screen->vpSize().height());2921 if (strcmp(name, "hsize") == 0 || strcmp(name, "vsize") == 0)
2922 launcher_controller_->UpdateNumWorkspaces(screen->vpSize().width() * screen->vpSize().height());
2925 }2923 }
2926 }2924 }
2927 return status;2925 return status;
@@ -2952,7 +2950,7 @@
2952void UnityScreen::initLauncher()2950void UnityScreen::initLauncher()
2953{2951{
2954 Timer timer;2952 Timer timer;
2955 launcher_controller_ = std::make_shared<launcher::Controller>(screen->dpy());2953 launcher_controller_ = std::make_shared<launcher::Controller>();
2956 AddChild(launcher_controller_.get());2954 AddChild(launcher_controller_.get());
29572955
2958 switcher_controller_ = std::make_shared<switcher::Controller>();2956 switcher_controller_ = std::make_shared<switcher::Controller>();
29592957
=== modified file 'plugins/unityshell/unityshell.xml.in'
--- plugins/unityshell/unityshell.xml.in 2012-08-17 14:44:05 +0000
+++ plugins/unityshell/unityshell.xml.in 2012-09-18 15:52:46 +0000
@@ -400,12 +400,6 @@
400 <default>true</default>400 <default>true</default>
401 </option>401 </option>
402402
403 <option name="show_desktop_icon" type="bool">
404 <_short>Show "Desktop Icon" in the launcher</_short>
405 <_long>Enable/Disable "Show Desktop Icon" in the launcher.</_long>
406 <default>false</default>
407 </option>
408
409 <option name="menus_fadein" type="int">403 <option name="menus_fadein" type="int">
410 <_short>Menus Fade-in duration</_short>404 <_short>Menus Fade-in duration</_short>
411 <_long>Duration (in milliseconds) of the menus fade-in animation, used when the mouse goes over the top-panel.</_long>405 <_long>Duration (in milliseconds) of the menus fade-in animation, used when the mouse goes over the top-panel.</_long>
412406
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-09-13 14:41:57 +0000
+++ tests/CMakeLists.txt 2012-09-18 15:52:46 +0000
@@ -3,16 +3,16 @@
3#3#
4# Data4# Data
5#5#
6configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/ubuntuone-installer.desktop6configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/ubuntuone-installer.desktop
7 ${CMAKE_BINARY_DIR}/tests/data/ubuntuone-installer.desktop)7 ${CMAKE_BINARY_DIR}/tests/data/applications/ubuntuone-installer.desktop)
8configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/ubuntu-software-center.desktop8configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/ubuntu-software-center.desktop
9 ${CMAKE_BINARY_DIR}/tests/data/ubuntu-software-center.desktop)9 ${CMAKE_BINARY_DIR}/tests/data/applications/ubuntu-software-center.desktop)
10configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/update-manager.desktop10configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/update-manager.desktop
11 ${CMAKE_BINARY_DIR}/tests/data/update-manager.desktop)11 ${CMAKE_BINARY_DIR}/tests/data/applications/update-manager.desktop)
12configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/bzr-handle-patch.desktop12configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/bzr-handle-patch.desktop
13 ${CMAKE_BINARY_DIR}/tests/data/bzr-handle-patch.desktop)13 ${CMAKE_BINARY_DIR}/tests/data/applications/bzr-handle-patch.desktop)
14configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/no-icon.desktop14configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/no-icon.desktop
15 ${CMAKE_BINARY_DIR}/tests/data/no-icon.desktop)15 ${CMAKE_BINARY_DIR}/tests/data/applications/no-icon.desktop)
16#16#
17# Unit tests17# Unit tests
18#18#
@@ -136,6 +136,7 @@
136 test_indicator_entry.cpp136 test_indicator_entry.cpp
137 test_indicators.cpp137 test_indicators.cpp
138 test_introspection.cpp138 test_introspection.cpp
139 test_favorite_store.cpp
139 test_favorite_store_gsettings.cpp140 test_favorite_store_gsettings.cpp
140 test_favorite_store_private.cpp141 test_favorite_store_private.cpp
141 test_home_lens.cpp142 test_home_lens.cpp
@@ -200,20 +201,23 @@
200# Tests that require X201# Tests that require X
201 add_executable(test-gtest202 add_executable(test-gtest
202 test_main.cpp203 test_main.cpp
203 test_bamflaunchericon.cpp204 test_bamf_launcher_icon.cpp
204 test_bfb_launcher_icon.cpp205 test_bfb_launcher_icon.cpp
205 test_dashview_impl.cpp206 test_dashview_impl.cpp
207 test_desktop_launcher_icon.cpp
206 test_edge_barrier_controller.cpp208 test_edge_barrier_controller.cpp
207 test_launcher.cpp209 test_launcher.cpp
208 test_device_launcher_section.cpp210 test_device_launcher_section.cpp
209 test_lensview_impl.cpp211 test_lensview_impl.cpp
210 test_hud_button.cpp212 test_hud_button.cpp
211 test_hud_controller.cpp213 test_hud_controller.cpp
214 test_hud_launcher_icon.cpp
212 test_hud_view.cpp215 test_hud_view.cpp
213 test_icon_loader.cpp216 test_icon_loader.cpp
214 test_im_text_entry.cpp217 test_im_text_entry.cpp
215 test_launcher_controller.cpp218 test_launcher_controller.cpp
216 test_launcher_drag_window.cpp219 test_launcher_drag_window.cpp
220 test_launcher_icon.cpp
217 test_keyboard_util.cpp221 test_keyboard_util.cpp
218 test_panel_style.cpp222 test_panel_style.cpp
219 test_previews_application.cpp223 test_previews_application.cpp
@@ -225,10 +229,13 @@
225 test_quicklist_view.cpp229 test_quicklist_view.cpp
226 test_resultviewgrid.cpp230 test_resultviewgrid.cpp
227 test_single_monitor_launcher_icon.cpp231 test_single_monitor_launcher_icon.cpp
232 test_software_center_launcher_icon.cpp
233 test_expo_launcher_icon.cpp
228 test_switcher_controller.cpp234 test_switcher_controller.cpp
229 test_switcher_model.cpp235 test_switcher_model.cpp
230 test_texture_cache.cpp236 test_texture_cache.cpp
231 test_thumbnail_generator.cpp237 test_thumbnail_generator.cpp
238 test_trash_launcher_icon.cpp
232 test_launcher_minimize_speed.cpp239 test_launcher_minimize_speed.cpp
233 test_volume_imp.cpp240 test_volume_imp.cpp
234 test_volume_launcher_icon.cpp241 test_volume_launcher_icon.cpp
@@ -272,6 +279,7 @@
272 ${CMAKE_SOURCE_DIR}/launcher/DevicesSettingsImp.cpp279 ${CMAKE_SOURCE_DIR}/launcher/DevicesSettingsImp.cpp
273 ${CMAKE_SOURCE_DIR}/launcher/DndData.cpp280 ${CMAKE_SOURCE_DIR}/launcher/DndData.cpp
274 ${CMAKE_SOURCE_DIR}/launcher/EdgeBarrierController.cpp281 ${CMAKE_SOURCE_DIR}/launcher/EdgeBarrierController.cpp
282 ${CMAKE_SOURCE_DIR}/launcher/ExpoLauncherIcon.cpp
275 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStore.cpp283 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStore.cpp
276 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStoreGSettings.cpp284 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStoreGSettings.cpp
277 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStorePrivate.cpp285 ${CMAKE_SOURCE_DIR}/launcher/FavoriteStorePrivate.cpp
278286
=== added directory 'tests/data/applications'
=== renamed file 'tests/data/bzr-handle-patch.desktop' => 'tests/data/applications/bzr-handle-patch.desktop'
=== renamed file 'tests/data/no-icon.desktop' => 'tests/data/applications/no-icon.desktop'
=== renamed file 'tests/data/ubuntu-software-center.desktop' => 'tests/data/applications/ubuntu-software-center.desktop'
=== renamed file 'tests/data/ubuntuone-installer.desktop' => 'tests/data/applications/ubuntuone-installer.desktop'
=== renamed file 'tests/data/update-manager.desktop' => 'tests/data/applications/update-manager.desktop'
=== modified file 'tests/gmockvolume.c'
--- tests/gmockvolume.c 2012-09-18 11:09:48 +0000
+++ tests/gmockvolume.c 2012-09-18 15:52:46 +0000
@@ -89,10 +89,11 @@
89static void89static void
90g_mock_volume_init (GMockVolume *mock_volume)90g_mock_volume_init (GMockVolume *mock_volume)
91{91{
92 mock_volume->name = g_strdup("");92 guint32 uuid = g_random_int();
93 mock_volume->name = g_strdup_printf("MockVolume %u", uuid);
93 mock_volume->icon = g_icon_new_for_string("", NULL);94 mock_volume->icon = g_icon_new_for_string("", NULL);
94 mock_volume->uuid = g_strdup("");95 mock_volume->uuid = g_strdup_printf("%u", uuid);
95 mock_volume->label = g_strdup("");96 mock_volume->label = g_strdup_printf("MockVolumeLabel");
96 mock_volume->mount = NULL;97 mock_volume->mount = NULL;
97}98}
9899
99100
=== renamed file 'tests/test_bamflaunchericon.cpp' => 'tests/test_bamf_launcher_icon.cpp'
--- tests/test_bamflaunchericon.cpp 2012-07-16 20:05:59 +0000
+++ tests/test_bamf_launcher_icon.cpp 2012-09-18 15:52:46 +0000
@@ -23,16 +23,19 @@
23#include <gmock/gmock.h>23#include <gmock/gmock.h>
2424
25#include <UnityCore/GLibWrapper.h>25#include <UnityCore/GLibWrapper.h>
26#include <UnityCore/DesktopUtilities.h>
2627
27#include "BamfLauncherIcon.h"28#include "BamfLauncherIcon.h"
29#include "FavoriteStore.h"
2830
29using namespace unity;31using namespace unity;
32using namespace unity::launcher;
3033
31namespace34namespace
32{35{
3336
34const std::string USC_DESKTOP = BUILDDIR"/tests/data/ubuntu-software-center.desktop";37const std::string USC_DESKTOP = BUILDDIR"/tests/data/applications/ubuntu-software-center.desktop";
35const std::string NO_ICON_DESKTOP = BUILDDIR"/tests/data/no-icon.desktop";38const std::string NO_ICON_DESKTOP = BUILDDIR"/tests/data/applications/no-icon.desktop";
3639
37class TestBamfLauncherIcon : public testing::Test40class TestBamfLauncherIcon : public testing::Test
38{41{
@@ -61,6 +64,11 @@
61 nux::ObjectPtr<launcher::BamfLauncherIcon> empty_app;64 nux::ObjectPtr<launcher::BamfLauncherIcon> empty_app;
62};65};
6366
67TEST_F(TestBamfLauncherIcon, Position)
68{
69 EXPECT_EQ(usc_icon->position(), AbstractLauncherIcon::Position::FLOATING);
70}
71
64TEST_F(TestBamfLauncherIcon, TestCustomBackgroundColor)72TEST_F(TestBamfLauncherIcon, TestCustomBackgroundColor)
65{73{
66 nux::Color const& color = usc_icon->BackgroundColor();74 nux::Color const& color = usc_icon->BackgroundColor();
@@ -78,4 +86,64 @@
78 EXPECT_EQ(empty_app->icon_name.Get(), "application-default-icon");86 EXPECT_EQ(empty_app->icon_name.Get(), "application-default-icon");
79}87}
8088
89TEST_F(TestBamfLauncherIcon, Stick)
90{
91 BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
92 ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
93
94 bool saved = false;
95 usc_icon->position_saved.connect([&saved] {saved = true;});
96
97 usc_icon->Stick(false);
98 EXPECT_TRUE(bamf_view_is_sticky(bamf_app));
99 EXPECT_TRUE(usc_icon->IsSticky());
100 EXPECT_TRUE(usc_icon->IsVisible());
101 EXPECT_FALSE(saved);
102
103 usc_icon->Stick(true);
104 EXPECT_FALSE(saved);
105 bamf_view_set_sticky(bamf_app, FALSE);
106}
107
108TEST_F(TestBamfLauncherIcon, StickAndSave)
109{
110 BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
111 ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
112
113 bool saved = false;
114 usc_icon->position_saved.connect([&saved] {saved = true;});
115
116 usc_icon->Stick(true);
117 EXPECT_TRUE(bamf_view_is_sticky(bamf_app));
118 EXPECT_TRUE(usc_icon->IsSticky());
119 EXPECT_TRUE(usc_icon->IsVisible());
120 EXPECT_TRUE(saved);
121 bamf_view_set_sticky(bamf_app, FALSE);
122}
123
124TEST_F(TestBamfLauncherIcon, Unstick)
125{
126 BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
127 ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
128
129 bool forgot = false;
130 usc_icon->position_forgot.connect([&forgot] {forgot = true;});
131
132 usc_icon->Stick(false);
133 ASSERT_TRUE(bamf_view_is_sticky(bamf_app));
134 ASSERT_TRUE(usc_icon->IsSticky());
135
136 usc_icon->UnStick();
137 EXPECT_FALSE(bamf_view_is_sticky(bamf_app));
138 EXPECT_FALSE(usc_icon->IsSticky());
139 EXPECT_FALSE(usc_icon->IsVisible());
140 EXPECT_TRUE(forgot);
141}
142
143TEST_F(TestBamfLauncherIcon, RemoteUri)
144{
145 EXPECT_EQ(usc_icon->RemoteUri(), FavoriteStore::URI_PREFIX_APP + DesktopUtilities::GetDesktopID(USC_DESKTOP));
146 EXPECT_TRUE(empty_app->RemoteUri().empty());
147}
148
81}149}
82150
=== modified file 'tests/test_bfb_launcher_icon.cpp'
--- tests/test_bfb_launcher_icon.cpp 2012-08-14 15:13:19 +0000
+++ tests/test_bfb_launcher_icon.cpp 2012-09-18 15:52:46 +0000
@@ -33,18 +33,21 @@
33 MockBFBLauncherIcon()33 MockBFBLauncherIcon()
34 : BFBLauncherIcon(LauncherHideMode::LAUNCHER_HIDE_NEVER)34 : BFBLauncherIcon(LauncherHideMode::LAUNCHER_HIDE_NEVER)
35 {}35 {}
36
37 AbstractLauncherIcon::MenuItemsVector GetMenus()
38 {
39 return BFBLauncherIcon::GetMenus();
40 }
41};36};
4237
43TEST(TestBFBLauncherIcon, OverlayMenus)38struct TestBFBLauncherIcon : testing::Test
44{39{
45 MockBFBLauncherIcon bfb;40 MockBFBLauncherIcon bfb;
4641};
47 for (auto menu_item : bfb.GetMenus())42
43TEST_F(TestBFBLauncherIcon, Position)
44{
45 EXPECT_EQ(bfb.position, AbstractLauncherIcon::Position::BEGIN);
46}
47
48TEST_F(TestBFBLauncherIcon, OverlayMenus)
49{
50 for (auto menu_item : bfb.Menus())
48 {51 {
49 bool overlay_item = dbusmenu_menuitem_property_get_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY);52 bool overlay_item = dbusmenu_menuitem_property_get_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY);
50 ASSERT_TRUE(overlay_item);53 ASSERT_TRUE(overlay_item);
5154
=== added file 'tests/test_desktop_launcher_icon.cpp'
--- tests/test_desktop_launcher_icon.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_desktop_launcher_icon.cpp 2012-09-18 15:52:46 +0000
@@ -0,0 +1,80 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21
22#include "PluginAdapter.h"
23#include "DesktopLauncherIcon.h"
24
25using namespace unity;
26using namespace unity::launcher;
27
28namespace
29{
30
31struct TestDesktopLauncherIcon : testing::Test
32{
33 DesktopLauncherIcon icon;
34};
35
36TEST_F(TestDesktopLauncherIcon, Type)
37{
38 EXPECT_EQ(icon.GetIconType(), AbstractLauncherIcon::IconType::DESKTOP);
39}
40
41TEST_F(TestDesktopLauncherIcon, Shortcut)
42{
43 EXPECT_EQ(icon.GetShortcut(), 'd');
44}
45
46TEST_F(TestDesktopLauncherIcon, Position)
47{
48 EXPECT_EQ(icon.position(), AbstractLauncherIcon::Position::FLOATING);
49}
50
51TEST_F(TestDesktopLauncherIcon, ActivateToggleShowDesktop)
52{
53 auto plugin_adapter = PluginAdapter::Default();
54
55 ASSERT_FALSE(plugin_adapter->InShowDesktop());
56
57 icon.Activate(ActionArg());
58 ASSERT_TRUE(plugin_adapter->InShowDesktop());
59
60 icon.Activate(ActionArg());
61 EXPECT_FALSE(plugin_adapter->InShowDesktop());
62}
63
64TEST_F(TestDesktopLauncherIcon, ShowInSwitcher)
65{
66 EXPECT_TRUE(icon.ShowInSwitcher(false));
67 EXPECT_TRUE(icon.ShowInSwitcher(true));
68
69 icon.SetShowInSwitcher(false);
70
71 EXPECT_FALSE(icon.ShowInSwitcher(false));
72 EXPECT_FALSE(icon.ShowInSwitcher(true));
73}
74
75TEST_F(TestDesktopLauncherIcon, RemoteUri)
76{
77 EXPECT_EQ(icon.RemoteUri(), "unity://desktop-icon");
78}
79
80}
081
=== modified file 'tests/test_desktop_utilities.cpp'
--- tests/test_desktop_utilities.cpp 2012-06-01 09:33:15 +0000
+++ tests/test_desktop_utilities.cpp 2012-09-18 15:52:46 +0000
@@ -30,7 +30,9 @@
30using testing::Eq;30using testing::Eq;
3131
32namespace {32namespace {
33 33
34const std::string LOCAL_DATA_DIR = BUILDDIR"/tests/data";
35
34TEST(TestDesktopUtilitiesDesktopID, TestEmptyValues)36TEST(TestDesktopUtilitiesDesktopID, TestEmptyValues)
35{37{
36 std::vector<std::string> empty_list;38 std::vector<std::string> empty_list;
@@ -88,71 +90,99 @@
88 Eq("subdir-to.desktop"));90 Eq("subdir-to.desktop"));
89 EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/this/path/applications/subdir1/subdir2/to.desktop"),91 EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/this/path/applications/subdir1/subdir2/to.desktop"),
90 Eq("subdir1-subdir2-to.desktop"));92 Eq("subdir1-subdir2-to.desktop"));
93 EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/this/path/applications/subdir1/subdir2-to.desktop"),
94 Eq("subdir1-subdir2-to.desktop"));
91}95}
9296
93TEST(TestDesktopUtilitiesDataDirectories, TestGetUserDataDirectory)97TEST(TestDesktopUtilitiesDataDirectories, TestGetUserDataDirectory)
94{98{
95 const gchar* old_home = g_getenv("XDG_DATA_HOME");99 const gchar* env = g_getenv("XDG_DATA_HOME");
100 std::string old_home = env ? env : "";
101
96 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);102 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);
97103
98 std::string const& user_data_dir = DesktopUtilities::GetUserDataDirectory();104 std::string const& user_data_dir = DesktopUtilities::GetUserDataDirectory();
99105
100 g_setenv("XDG_DATA_HOME", old_home, TRUE);106 g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);
101107
102 EXPECT_THAT(user_data_dir, Eq("UnityUserConfig"));108 EXPECT_THAT(user_data_dir, Eq("UnityUserConfig"));
103}109}
104110
105TEST(TestDesktopUtilitiesDataDirectories, TestGetSystemDataDirectory)111TEST(TestDesktopUtilitiesDataDirectories, TestGetSystemDataDirectory)
106{112{
107 const gchar* old_dirs = g_getenv("XDG_DATA_DIRS");113 const gchar* env = g_getenv("XDG_DATA_DIRS");
108 g_setenv("XDG_DATA_DIRS", "dir1:dir2::dir3:dir4", TRUE);114 std::string old_dirs = env ? env : "";
115 g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);
109116
110 std::vector<std::string> const& system_dirs = DesktopUtilities::GetSystemDataDirectories();117 std::vector<std::string> const& system_dirs = DesktopUtilities::GetSystemDataDirectories();
111118
112 g_setenv("XDG_DATA_DIRS", old_dirs, TRUE);119 g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);
113120
114 ASSERT_THAT(system_dirs.size(), Eq(4));121 ASSERT_THAT(system_dirs.size(), Eq(5));
115 EXPECT_THAT(system_dirs[0], Eq("dir1"));122 EXPECT_THAT(system_dirs[0], Eq("dir1"));
116 EXPECT_THAT(system_dirs[1], Eq("dir2"));123 EXPECT_THAT(system_dirs[1], Eq("dir2"));
117 EXPECT_THAT(system_dirs[2], Eq("dir3"));124 EXPECT_THAT(system_dirs[2], Eq("dir3"));
118 EXPECT_THAT(system_dirs[3], Eq("dir4"));125 EXPECT_THAT(system_dirs[3], Eq("dir4"));
126 EXPECT_THAT(system_dirs[4], Eq(LOCAL_DATA_DIR));
119}127}
120128
121TEST(TestDesktopUtilitiesDataDirectories, TestGetDataDirectory)129TEST(TestDesktopUtilitiesDataDirectories, TestGetDataDirectory)
122{130{
123 const gchar* old_dirs = g_getenv("XDG_DATA_DIRS");131 const gchar* env = g_getenv("XDG_DATA_DIRS");
124 g_setenv("XDG_DATA_DIRS", "dir1:dir2::dir3:dir4", TRUE);132 std::string old_dirs = env ? env : "";
125 const gchar* old_home = g_getenv("XDG_DATA_HOME");133 env = g_getenv("XDG_DATA_HOME");
134 std::string old_home = env ? env : "";
135
136 g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);
126 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);137 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);
127138
128 std::vector<std::string> const& data_dirs = DesktopUtilities::GetDataDirectories();139 std::vector<std::string> const& data_dirs = DesktopUtilities::GetDataDirectories();
129140
130 g_setenv("XDG_DATA_DIRS", old_dirs, TRUE);141 g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);
131 g_setenv("XDG_DATA_HOME", old_home, TRUE);142 g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);
132143
133 ASSERT_THAT(data_dirs.size(), Eq(5));144 ASSERT_THAT(data_dirs.size(), Eq(6));
134 EXPECT_THAT(data_dirs[0], Eq("dir1"));145 EXPECT_THAT(data_dirs[0], Eq("dir1"));
135 EXPECT_THAT(data_dirs[1], Eq("dir2"));146 EXPECT_THAT(data_dirs[1], Eq("dir2"));
136 EXPECT_THAT(data_dirs[2], Eq("dir3"));147 EXPECT_THAT(data_dirs[2], Eq("dir3"));
137 EXPECT_THAT(data_dirs[3], Eq("dir4"));148 EXPECT_THAT(data_dirs[3], Eq("dir4"));
138 EXPECT_THAT(data_dirs[4], Eq("UnityUserConfig"));149 EXPECT_THAT(data_dirs[4], Eq(LOCAL_DATA_DIR));
139}150 EXPECT_THAT(data_dirs[5], Eq("UnityUserConfig"));
140151}
141TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColor)152
142{153TEST(TestDesktopUtilities, TestGetDesktopPathById)
143 std::string const& color = DesktopUtilities::GetBackgroundColor(BUILDDIR"/tests/data/ubuntu-software-center.desktop");154{
155 const gchar* env = g_getenv("XDG_DATA_DIRS");
156 std::string old_dirs = env ? env : "";
157 env = g_getenv("XDG_DATA_HOME");
158 std::string old_home = env ? env : "";
159
160 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR.c_str(), TRUE);
161 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);
162
163 std::string const& file = DesktopUtilities::GetDesktopPathById("ubuntu-software-center.desktop");
164
165 g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);
166 g_setenv("XDG_DATA_HOME", old_dirs.c_str(), TRUE);
167
168 EXPECT_EQ(file, LOCAL_DATA_DIR + "/applications/ubuntu-software-center.desktop");
169}
170
171TEST(TestDesktopUtilities, TestGetBackgroundColor)
172{
173 std::string const& color = DesktopUtilities::GetBackgroundColor(LOCAL_DATA_DIR+"/applications/ubuntu-software-center.desktop");
144174
145 EXPECT_EQ(color, "#aabbcc");175 EXPECT_EQ(color, "#aabbcc");
146}176}
147177
148TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColorNoKey)178TEST(TestDesktopUtilities, TestGetBackgroundColorNoKey)
149{179{
150 std::string const& color = DesktopUtilities::GetBackgroundColor(BUILDDIR"/tests/data/update-manager.desktop");180 std::string const& color = DesktopUtilities::GetBackgroundColor(LOCAL_DATA_DIR+"/applications/update-manager.desktop");
151181
152 EXPECT_TRUE(color.empty());182 EXPECT_TRUE(color.empty());
153}183}
154184
155TEST(TestDesktopUtilitiesDataDirectories, TestGetBackgroundColorNoFile)185TEST(TestDesktopUtilities, TestGetBackgroundColorNoFile)
156{186{
157 std::string const& color = DesktopUtilities::GetBackgroundColor("hello-world.desktop");187 std::string const& color = DesktopUtilities::GetBackgroundColor("hello-world.desktop");
158188
159189
=== modified file 'tests/test_device_launcher_section.cpp'
--- tests/test_device_launcher_section.cpp 2012-08-17 15:53:06 +0000
+++ tests/test_device_launcher_section.cpp 2012-09-18 15:52:46 +0000
@@ -21,17 +21,16 @@
21 */21 */
2222
23#include <gmock/gmock.h>23#include <gmock/gmock.h>
24
25#include "DevicesSettings.h"
26#include "test_mock_devices.h"
27#include "test_utils.h"
28
24using namespace testing;29using namespace testing;
25
26#include "DeviceLauncherSection.h"
27#include "DevicesSettings.h"
28#include "AbstractVolumeMonitorWrapper.h"
29using namespace unity;
30using namespace unity::launcher;30using namespace unity::launcher;
3131
32#include "gmockvolume.h"32namespace unity
33#include "test_utils.h"33{
34
35namespace34namespace
36{35{
3736
@@ -50,72 +49,38 @@
50 bool icon_added;49 bool icon_added;
51};50};
5251
53class MockVolumeMonitorWrapper : public AbstractVolumeMonitorWrapper52struct TestDeviceLauncherSection : Test
54{53{
55public:
56 typedef std::shared_ptr<MockVolumeMonitorWrapper> Ptr;
57
58 MockVolumeMonitorWrapper()
59 : volume1(G_VOLUME(g_mock_volume_new()))
60 , volume2(G_VOLUME(g_mock_volume_new()))
61 {
62 }
63
64 VolumeList GetVolumes()
65 {
66 VolumeList ret;
67
68 ret.push_back(volume1);
69 ret.push_back(volume2);
70
71 return ret;
72 }
73
74 glib::Object<GVolume> volume1;
75 glib::Object<GVolume> volume2;
76};
77
78class MockDevicesSettings : public DevicesSettings
79{
80 MOCK_CONST_METHOD1(IsABlacklistedDevice, bool(std::string const& uuid));
81 MOCK_METHOD1(TryToBlacklist, void(std::string const& uuid));
82 MOCK_METHOD1(TryToUnblacklist, void(std::string const& uuid));
83};
84
85class TestDeviceLauncherSection : public Test
86{
87public:
88 TestDeviceLauncherSection()54 TestDeviceLauncherSection()
89 : monitor_(new MockVolumeMonitorWrapper)55 : monitor_(new MockVolumeMonitorWrapper)
90 , devices_settings_(new MockDevicesSettings)56 , devices_settings_(new MockDevicesSettings)
91 , section_(monitor_, devices_settings_)57 , section_(monitor_, devices_settings_)
92 {}58 {}
9359
94 void SetUp()
95 {
96 // Make sure PopulateEntries is called.
97 Utils::WaitForTimeoutMSec(1500);
98 }
99
100 MockVolumeMonitorWrapper::Ptr monitor_;60 MockVolumeMonitorWrapper::Ptr monitor_;
101 DevicesSettings::Ptr devices_settings_;61 DevicesSettings::Ptr devices_settings_;
102 DeviceLauncherSection section_;62 DeviceLauncherSection section_;
103};63};
10464
10565TEST_F(TestDeviceLauncherSection, NoDuplicates)
106TEST_F(TestDeviceLauncherSection, TestNoDuplicates)
107{66{
108 std::shared_ptr<EventListener> listener(new EventListener);67 std::shared_ptr<EventListener> listener(new EventListener);
109 section_.IconAdded.connect(sigc::mem_fun(*listener, &EventListener::OnIconAdded));68 section_.icon_added.connect(sigc::mem_fun(*listener, &EventListener::OnIconAdded));
11069
111 // Emit the signal volume_added for each volume.70 // Emit the signal volume_added for each volume.
112 monitor_->volume_added.emit(monitor_->volume1);71 monitor_->volume_added.emit(*(std::next(monitor_->volumes_.begin(), 0)));
113 monitor_->volume_added.emit(monitor_->volume2);72 monitor_->volume_added.emit(*(std::next(monitor_->volumes_.begin(), 1)));
11473
115 Utils::WaitForTimeoutMSec(500);74 Utils::WaitForTimeoutMSec(500);
11675
117 EXPECT_EQ(listener->icon_added, false);76 EXPECT_EQ(listener->icon_added, false);
118}77}
11978
79TEST_F(TestDeviceLauncherSection, GetIcons)
80{
81 EXPECT_EQ(section_.GetIcons().size(), 2);
82}
83
84}
120}85}
12186
12287
=== added file 'tests/test_expo_launcher_icon.cpp'
--- tests/test_expo_launcher_icon.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_expo_launcher_icon.cpp 2012-09-18 15:52:46 +0000
@@ -0,0 +1,58 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21
22#include "ExpoLauncherIcon.h"
23#include "PluginAdapter.h"
24
25using namespace unity;
26using namespace unity::launcher;
27
28namespace
29{
30struct TestExpoLauncherIcon : testing::Test
31{
32 ExpoLauncherIcon icon;
33};
34
35TEST_F(TestExpoLauncherIcon, ActivateToggleExpo)
36{
37 auto plugin_adapter = PluginAdapter::Default();
38
39 ASSERT_FALSE(plugin_adapter->IsExpoActive());
40
41 icon.Activate(ActionArg());
42 ASSERT_TRUE(plugin_adapter->IsExpoActive());
43
44 icon.Activate(ActionArg());
45 EXPECT_FALSE(plugin_adapter->IsExpoActive());
46}
47
48TEST_F(TestExpoLauncherIcon, Position)
49{
50 EXPECT_EQ(icon.position(), AbstractLauncherIcon::Position::FLOATING);
51}
52
53TEST_F(TestExpoLauncherIcon, RemoteUri)
54{
55 EXPECT_EQ(icon.RemoteUri(), "unity://expo-icon");
56}
57
58}
059
=== added file 'tests/test_favorite_store.cpp'
--- tests/test_favorite_store.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_favorite_store.cpp 2012-09-18 15:52:46 +0000
@@ -0,0 +1,111 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21#include <config.h>
22
23#include "FavoriteStore.h"
24
25using namespace unity;
26
27namespace
28{
29class MockFavoriteStore : public FavoriteStore
30{
31public:
32 FavoriteList const& GetFavorites() const { return fav_list_; }
33 void AddFavorite(std::string const& icon_uri, int position) {}
34 void RemoveFavorite(std::string const& icon_uri) {}
35 void MoveFavorite(std::string const& icon_uri, int position) {}
36 bool IsFavorite(std::string const& icon_uri) const { return false; }
37 int FavoritePosition(std::string const& icon_uri) const { return -1; }
38 void SetFavorites(FavoriteList const& icon_uris) {}
39
40 std::string ParseFavoriteFromUri(std::string const& uri) const
41 {
42 return FavoriteStore::ParseFavoriteFromUri(uri);
43 }
44
45private:
46 FavoriteList fav_list_;
47};
48
49struct TestFavoriteStore : public testing::Test
50{
51 MockFavoriteStore favorite_store;
52};
53
54TEST_F(TestFavoriteStore, Construction)
55{
56 FavoriteStore& instance = FavoriteStore::Instance();
57 EXPECT_EQ(&instance, &favorite_store);
58}
59
60TEST_F(TestFavoriteStore, UriPrefixes)
61{
62 EXPECT_EQ(FavoriteStore::URI_PREFIX_APP, "application://");
63 EXPECT_EQ(FavoriteStore::URI_PREFIX_FILE, "file://");
64 EXPECT_EQ(FavoriteStore::URI_PREFIX_DEVICE, "device://");
65 EXPECT_EQ(FavoriteStore::URI_PREFIX_UNITY, "unity://");
66}
67
68TEST_F(TestFavoriteStore, IsValidFavoriteUri)
69{
70 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri(""));
71 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("invalid-favorite"));
72 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("/path/to/desktop_file"));
73 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("desktop_file"));
74 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("file:///path/to/desktop_file"));
75 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("application://desktop_file"));
76 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("application://"));
77 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("device://"));
78 EXPECT_FALSE(FavoriteStore::IsValidFavoriteUri("unity://"));
79
80 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("device://uuid"));
81 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("file:///path/to/desktop_file.desktop"));
82 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("application://desktop_file.desktop"));
83 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("device://a"));
84 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("unity://b"));
85 EXPECT_TRUE(FavoriteStore::IsValidFavoriteUri("application://c.desktop"));
86}
87
88TEST_F(TestFavoriteStore, ParseFavoriteFromUri)
89{
90 const std::string VALID_DESKTOP_PATH = BUILDDIR"/tests/data/applications/ubuntu-software-center.desktop";
91 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("file.desktop"), "application://file.desktop");
92 EXPECT_EQ(favorite_store.ParseFavoriteFromUri(VALID_DESKTOP_PATH), "application://"+VALID_DESKTOP_PATH);
93
94 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("application://file.desktop"), "application://file.desktop");
95 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("application://"+VALID_DESKTOP_PATH), "application://"+VALID_DESKTOP_PATH);
96 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("file://"+VALID_DESKTOP_PATH), "file://"+VALID_DESKTOP_PATH);
97
98 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("unity://uri"), "unity://uri");
99 EXPECT_EQ(favorite_store.ParseFavoriteFromUri("device://uuid"), "device://uuid");
100
101 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("file").empty());
102 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("/path/to/file").empty());
103 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("/path/to/file.desktop").empty());
104 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("application:///path/to/file.desktop").empty());
105 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("file:///path/to/file.desktop").empty());
106 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("file://file.desktop").empty());
107 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("unity://").empty());
108 EXPECT_TRUE(favorite_store.ParseFavoriteFromUri("device://").empty());
109}
110
111}
0112
=== modified file 'tests/test_favorite_store_gsettings.cpp'
--- tests/test_favorite_store_gsettings.cpp 2012-08-02 12:13:38 +0000
+++ tests/test_favorite_store_gsettings.cpp 2012-09-18 15:52:46 +0000
@@ -21,18 +21,12 @@
2121
22#include <config.h>22#include <config.h>
2323
24#include <algorithm>
25#include <memory>
26#include <string>
27
28#define G_SETTINGS_ENABLE_BACKEND
29#include <gio/gsettingsbackend.h>
30#include <gmock/gmock.h>24#include <gmock/gmock.h>
31#include <glib.h>25#include <glib.h>
3226
33#include "FavoriteStore.h"27#include "FavoriteStore.h"
34#include "FavoriteStoreGSettings.h"28#include "FavoriteStoreGSettings.h"
35#include "FavoriteStorePrivate.h"29
36#include <UnityCore/GLibWrapper.h>30#include <UnityCore/GLibWrapper.h>
3731
38using namespace unity;32using namespace unity;
@@ -45,14 +39,16 @@
45const gchar* SETTINGS_KEY = "favorites";39const gchar* SETTINGS_KEY = "favorites";
46const gchar* SCHEMA_DIRECTORY = BUILDDIR"/settings";40const gchar* SCHEMA_DIRECTORY = BUILDDIR"/settings";
4741
48const char* base_store_favs[] = { BUILDDIR"/tests/data/ubuntuone-installer.desktop",42const char* base_store_favs[] = { BUILDDIR"/tests/data/applications/ubuntuone-installer.desktop",
49 BUILDDIR"/tests/data/ubuntu-software-center.desktop",43 "file://" BUILDDIR "/tests/data/applications/ubuntu-software-center.desktop",
50 BUILDDIR"/tests/data/update-manager.desktop",44 "application://" BUILDDIR "/tests/data/applications/update-manager.desktop",
45 "unity://test-icon",
46 "device://uuid",
51 NULL47 NULL
52 };48 };
53const int n_base_store_favs = G_N_ELEMENTS(base_store_favs) - 1; /* NULL */49const int n_base_store_favs = G_N_ELEMENTS(base_store_favs) - 1; /* NULL */
5450
55const std::string other_desktop = BUILDDIR"/tests/data/bzr-handle-patch.desktop";51const std::string other_desktop = "application://" BUILDDIR "/tests/data/applications/bzr-handle-patch.desktop";
5652
57// Utilities53// Utilities
58std::string const& at(FavoriteList const& favs, int index)54std::string const& at(FavoriteList const& favs, int index)
@@ -110,9 +106,9 @@
110 FavoriteList const& favs = settings.GetFavorites();106 FavoriteList const& favs = settings.GetFavorites();
111107
112 ASSERT_EQ(favs.size(), n_base_store_favs);108 ASSERT_EQ(favs.size(), n_base_store_favs);
113 EXPECT_TRUE(ends_with(at(favs, 0), base_store_favs[0]));109 EXPECT_TRUE(ends_with(at(favs, 0), FavoriteStore::URI_PREFIX_APP+base_store_favs[0]));
114 EXPECT_TRUE(ends_with(at(favs, 1), base_store_favs[1]));110 EXPECT_TRUE(ends_with(at(favs, 1), base_store_favs[1]));
115 EXPECT_TRUE(at(favs, 2) == base_store_favs[2]);111 EXPECT_EQ(at(favs, 2), base_store_favs[2]);
116}112}
117113
118TEST_F(TestFavoriteStoreGSettings, TestAddFavorite)114TEST_F(TestFavoriteStoreGSettings, TestAddFavorite)
@@ -122,7 +118,7 @@
122 settings.AddFavorite(other_desktop, 0);118 settings.AddFavorite(other_desktop, 0);
123 FavoriteList const& favs = settings.GetFavorites();119 FavoriteList const& favs = settings.GetFavorites();
124 ASSERT_EQ(favs.size(), n_base_store_favs + 1);120 ASSERT_EQ(favs.size(), n_base_store_favs + 1);
125 EXPECT_TRUE(other_desktop == at(favs, 0));121 EXPECT_EQ(other_desktop, at(favs, 0));
126}122}
127123
128TEST_F(TestFavoriteStoreGSettings, TestAddFavoritePosition)124TEST_F(TestFavoriteStoreGSettings, TestAddFavoritePosition)
@@ -132,7 +128,7 @@
132 settings.AddFavorite(other_desktop, 2);128 settings.AddFavorite(other_desktop, 2);
133 FavoriteList const& favs = settings.GetFavorites();129 FavoriteList const& favs = settings.GetFavorites();
134 ASSERT_EQ(favs.size(), n_base_store_favs + 1);130 ASSERT_EQ(favs.size(), n_base_store_favs + 1);
135 EXPECT_TRUE(other_desktop == at(favs, 2));131 EXPECT_EQ(other_desktop, at(favs, 2));
136}132}
137133
138TEST_F(TestFavoriteStoreGSettings,TestAddFavoriteLast)134TEST_F(TestFavoriteStoreGSettings,TestAddFavoriteLast)
@@ -142,7 +138,7 @@
142 settings.AddFavorite(other_desktop, -1);138 settings.AddFavorite(other_desktop, -1);
143 FavoriteList const& favs = settings.GetFavorites();139 FavoriteList const& favs = settings.GetFavorites();
144 ASSERT_EQ(favs.size(), n_base_store_favs + 1);140 ASSERT_EQ(favs.size(), n_base_store_favs + 1);
145 EXPECT_TRUE(other_desktop == favs.back());141 EXPECT_EQ(other_desktop, favs.back());
146}142}
147143
148TEST_F(TestFavoriteStoreGSettings,TestAddFavoriteOutOfRange)144TEST_F(TestFavoriteStoreGSettings,TestAddFavoriteOutOfRange)
@@ -178,13 +174,13 @@
178 FavoriteStore &settings = FavoriteStore::Instance();174 FavoriteStore &settings = FavoriteStore::Instance();
179175
180 FavoriteList const& favs = settings.GetFavorites();176 FavoriteList const& favs = settings.GetFavorites();
181 settings.RemoveFavorite("");177 settings.RemoveFavorite(" ");
182 EXPECT_EQ(favs.size(), n_base_store_favs);178 EXPECT_EQ(favs.size(), n_base_store_favs);
183179
184 settings.RemoveFavorite("foo.desktop");180 settings.RemoveFavorite("application://foo.desktop");
185 EXPECT_EQ(favs.size(), n_base_store_favs);181 EXPECT_EQ(favs.size(), n_base_store_favs);
186182
187 settings.RemoveFavorite("/this/desktop/doesnt/exist/hopefully.desktop");183 settings.RemoveFavorite("application:///this/desktop/doesnt/exist/hopefully.desktop");
188 EXPECT_EQ(favs.size(), n_base_store_favs);184 EXPECT_EQ(favs.size(), n_base_store_favs);
189}185}
190186
@@ -198,7 +194,7 @@
198194
199 ASSERT_EQ(favs.size(), n_base_store_favs);195 ASSERT_EQ(favs.size(), n_base_store_favs);
200 EXPECT_EQ(at(favs, 0), base_store_favs[2]);196 EXPECT_EQ(at(favs, 0), base_store_favs[2]);
201 EXPECT_TRUE(ends_with(at(favs, 1), base_store_favs[0]));197 EXPECT_TRUE(ends_with(at(favs, 1), FavoriteStore::URI_PREFIX_APP+base_store_favs[0]));
202 EXPECT_TRUE(ends_with(at(favs, 2), base_store_favs[1]));198 EXPECT_TRUE(ends_with(at(favs, 2), base_store_favs[1]));
203}199}
204200
@@ -212,7 +208,7 @@
212 settings.MoveFavorite(at(favs, 0), 100);208 settings.MoveFavorite(at(favs, 0), 100);
213209
214 ASSERT_EQ(favs.size(), n_base_store_favs);210 ASSERT_EQ(favs.size(), n_base_store_favs);
215 EXPECT_TRUE(ends_with(at(favs, 0), base_store_favs[0]));211 EXPECT_TRUE(ends_with(at(favs, 0), FavoriteStore::URI_PREFIX_APP+base_store_favs[0]));
216 EXPECT_TRUE(ends_with(at(favs, 1), base_store_favs[1]));212 EXPECT_TRUE(ends_with(at(favs, 1), base_store_favs[1]));
217 EXPECT_EQ(at(favs, 2), base_store_favs[2]);213 EXPECT_EQ(at(favs, 2), base_store_favs[2]);
218}214}
@@ -239,7 +235,7 @@
239 favorite_store->SaveFavorites(favs, false);235 favorite_store->SaveFavorites(favs, false);
240236
241 ASSERT_TRUE(signal_received);237 ASSERT_TRUE(signal_received);
242 EXPECT_EQ(position, base_store_favs[0]);238 EXPECT_EQ(position, FavoriteStore::URI_PREFIX_APP+base_store_favs[0]);
243 EXPECT_TRUE(before);239 EXPECT_TRUE(before);
244}240}
245241
@@ -322,12 +318,12 @@
322{318{
323 FavoriteStore &settings = FavoriteStore::Instance();319 FavoriteStore &settings = FavoriteStore::Instance();
324 bool signal_received = false;320 bool signal_received = false;
325 std::string path_removed;321 std::vector<std::string> paths_removed;
326322
327 settings.favorite_removed.connect([&](std::string const& path)323 settings.favorite_removed.connect([&](std::string const& path)
328 {324 {
329 signal_received = true;325 signal_received = true;
330 path_removed = path;326 paths_removed.push_back(path);
331 });327 });
332328
333 FavoriteList favs;329 FavoriteList favs;
@@ -336,7 +332,10 @@
336 favorite_store->SaveFavorites(favs, false);332 favorite_store->SaveFavorites(favs, false);
337333
338 ASSERT_TRUE(signal_received);334 ASSERT_TRUE(signal_received);
339 EXPECT_EQ(path_removed, base_store_favs[1]);335 ASSERT_EQ(paths_removed.size(), 3);
336 EXPECT_EQ(paths_removed[0], base_store_favs[4]);
337 EXPECT_EQ(paths_removed[1], base_store_favs[1]);
338 EXPECT_EQ(paths_removed[2], base_store_favs[3]);
340}339}
341340
342TEST_F(TestFavoriteStoreGSettings, TestFavoriteReordered)341TEST_F(TestFavoriteStoreGSettings, TestFavoriteReordered)
@@ -464,4 +463,28 @@
464 EXPECT_TRUE(reordered_received);463 EXPECT_TRUE(reordered_received);
465}464}
466465
466TEST_F(TestFavoriteStoreGSettings, TestIsFavorite)
467{
468 EXPECT_TRUE(favorite_store->IsFavorite(FavoriteStore::URI_PREFIX_APP+base_store_favs[0]));
469
470 for (int i = 1; i < n_base_store_favs; i++)
471 {
472 ASSERT_TRUE(favorite_store->IsFavorite(base_store_favs[i]));
473 }
474
475 EXPECT_FALSE(favorite_store->IsFavorite("unity://invalid-favorite"));
476}
477
478TEST_F(TestFavoriteStoreGSettings, TestFavoritePosition)
479{
480 EXPECT_EQ(favorite_store->FavoritePosition(FavoriteStore::URI_PREFIX_APP+base_store_favs[0]), 0);
481
482 for (int i = 1; i < n_base_store_favs; i++)
483 {
484 ASSERT_EQ(favorite_store->FavoritePosition(base_store_favs[i]), i);
485 }
486
487 EXPECT_EQ(favorite_store->FavoritePosition("unity://invalid-favorite"), -1);
488}
489
467} // anonymous namespace490} // anonymous namespace
468491
=== added file 'tests/test_hud_launcher_icon.cpp'
--- tests/test_hud_launcher_icon.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_hud_launcher_icon.cpp 2012-09-18 15:52:46 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21
22#include "HudLauncherIcon.h"
23
24using namespace unity;
25using namespace unity::launcher;
26
27namespace
28{
29
30class MockHudLauncherIcon : public HudLauncherIcon
31{
32public:
33 MockHudLauncherIcon()
34 : HudLauncherIcon(LauncherHideMode::LAUNCHER_HIDE_NEVER)
35 {}
36};
37
38struct TestHudLauncherIcon : testing::Test
39{
40 MockHudLauncherIcon hud;
41};
42
43TEST_F(TestHudLauncherIcon, Type)
44{
45 EXPECT_EQ(hud.GetIconType(), AbstractLauncherIcon::IconType::HUD);
46}
47
48TEST_F(TestHudLauncherIcon, Position)
49{
50 EXPECT_EQ(hud.position(), AbstractLauncherIcon::Position::BEGIN);
51}
52
53}
054
=== modified file 'tests/test_launcher.cpp'
--- tests/test_launcher.cpp 2012-09-04 14:26:23 +0000
+++ tests/test_launcher.cpp 2012-09-18 15:52:46 +0000
@@ -48,8 +48,12 @@
48{48{
49public:49public:
50 typedef nux::ObjectPtr<MockMockLauncherIcon> Ptr;50 typedef nux::ObjectPtr<MockMockLauncherIcon> Ptr;
51 MockMockLauncherIcon(IconType type = IconType::APPLICATION)
52 : MockLauncherIcon(type)
53 {}
5154
52 MOCK_METHOD1(ShouldHighlightOnDrag, bool(DndData const&));55 MOCK_METHOD1(ShouldHighlightOnDrag, bool(DndData const&));
56 MOCK_METHOD1(Stick, void(bool));
53};57};
5458
55}59}
@@ -57,7 +61,7 @@
57class TestLauncher : public Test61class TestLauncher : public Test
58{62{
59public:63public:
60 class MockLauncher : public launcher::Launcher64 class MockLauncher : public Launcher
61 {65 {
62 public:66 public:
63 MockLauncher(nux::BaseWindow* parent, nux::ObjectPtr<DNDCollectionWindow> const& collection_window)67 MockLauncher(nux::BaseWindow* parent, nux::ObjectPtr<DNDCollectionWindow> const& collection_window)
@@ -92,6 +96,11 @@
92 Launcher::ShowDragWindow();96 Launcher::ShowDragWindow();
93 }97 }
9498
99 void EndIconDrag()
100 {
101 Launcher::EndIconDrag();
102 }
103
95 void UpdateDragWindowPosition(int x, int y)104 void UpdateDragWindowPosition(int x, int y)
96 {105 {
97 Launcher::UpdateDragWindowPosition(x, y);106 Launcher::UpdateDragWindowPosition(x, y);
@@ -106,6 +115,55 @@
106 {115 {
107 Launcher::ResetMouseDragState();116 Launcher::ResetMouseDragState();
108 }117 }
118
119 bool DndIsSpecialRequest(std::string const& uri) const
120 {
121 return Launcher::DndIsSpecialRequest(uri);
122 }
123
124 int GetDragIconPosition() const
125 {
126 return _drag_icon_position;
127 }
128
129 void ProcessDndEnter()
130 {
131 Launcher::ProcessDndEnter();
132 }
133
134 void ProcessDndLeave()
135 {
136 Launcher::ProcessDndLeave();
137 }
138
139 void ProcessDndMove(int x, int y, std::list<char*> mimes)
140 {
141 Launcher::ProcessDndMove(x, y, mimes);
142 }
143
144 void FakeProcessDndMove(int x, int y, std::list<std::string> uris)
145 {
146 _dnd_data.Reset();
147
148 std::string data_uri;
149 for (std::string const& uri : uris)
150 data_uri += uri+"\r\n";
151
152 _dnd_data.Fill(data_uri.c_str());
153
154 if (std::find_if(_dnd_data.Uris().begin(), _dnd_data.Uris().end(), [this] (std::string const& uri)
155 {return DndIsSpecialRequest(uri);}) != _dnd_data.Uris().end())
156 {
157 _steal_drag = true;
158 }
159
160 _dnd_hovered_icon = MouseIconIntersection(x, y);
161 }
162
163 void ProcessDndDrop(int x, int y)
164 {
165 Launcher::ProcessDndDrop(x, y);
166 }
109 };167 };
110168
111 TestLauncher()169 TestLauncher()
@@ -119,6 +177,29 @@
119 launcher_->SetModel(model_);177 launcher_->SetModel(model_);
120 }178 }
121179
180 std::vector<MockMockLauncherIcon::Ptr> AddMockIcons(unsigned number)
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches