32
33
#include "DesktopLauncherIcon.h"
33
34
#include "VolumeLauncherIcon.h"
34
35
#include "FavoriteStore.h"
36
#include "FileManagerLauncherIcon.h"
35
37
#include "HudLauncherIcon.h"
36
38
#include "LauncherController.h"
37
39
#include "LauncherControllerPrivate.h"
39
41
#include "ExpoLauncherIcon.h"
40
42
#include "TrashLauncherIcon.h"
41
43
#include "BFBLauncherIcon.h"
44
#include "unity-shared/AppStreamApplication.h"
42
45
#include "unity-shared/IconRenderer.h"
43
46
#include "unity-shared/UScreen.h"
44
47
#include "unity-shared/UBusMessages.h"
60
63
" <interface name='com.canonical.Unity.Launcher'>"
62
" <method name='AddLauncherItemFromPosition'>"
63
" <arg type='s' name='title' direction='in'/>"
64
" <arg type='s' name='icon' direction='in'/>"
65
" <arg type='i' name='icon_x' direction='in'/>"
66
" <arg type='i' name='icon_y' direction='in'/>"
67
" <arg type='i' name='icon_size' direction='in'/>"
68
" <arg type='s' name='desktop_file' direction='in'/>"
65
" <method name='AddLauncherItem'>"
66
" <arg type='s' name='appstream_app_id' direction='in'/>"
69
67
" <arg type='s' name='aptdaemon_task' direction='in'/>"
103
101
return FavoriteStore::URI_PREFIX_APP + DesktopUtilities::GetDesktopID(desktop_path);
108
105
Controller::Impl::Impl(Controller* parent, XdndManager::Ptr const& xdnd_manager, ui::EdgeBarrierController::Ptr const& edge_barriers)
109
106
: parent_(parent)
110
107
, model_(std::make_shared<LauncherModel>())
111
108
, xdnd_manager_(xdnd_manager)
109
, device_section_(std::make_shared<DeviceLauncherSection>())
112
110
, expo_icon_(new ExpoLauncherIcon())
113
111
, desktop_icon_(new DesktopLauncherIcon())
114
112
, edge_barriers_(edge_barriers)
151
149
WindowManager& wm = WindowManager::Default();
152
150
wm.window_focus_changed.connect(sigc::mem_fun(this, &Controller::Impl::OnWindowFocusChanged));
151
#if SIGCXX_MAJOR_VERSION >= 2 && SIGCXX_MINOR_VERSION >= 5
152
wm.viewport_layout_changed.connect(sigc::track_obj([this] (int w, int h) { UpdateNumWorkspaces(w * h); }, *this));
153
154
wm.viewport_layout_changed.connect(sigc::group(sigc::mem_fun(this, &Controller::Impl::UpdateNumWorkspaces), sigc::_1 * sigc::_2));
154
156
average_color_connection_ = wm.average_color.changed.connect([this] (nux::Color const& color) {
155
157
parent_->options()->background_color = color;
343
ApplicationLauncherIcon* Controller::Impl::CreateAppLauncherIcon(ApplicationPtr const& app)
345
auto const& desktop_file = app->desktop_file();
347
if (boost::algorithm::ends_with(desktop_file, "org.gnome.Nautilus.desktop") ||
348
boost::algorithm::ends_with(desktop_file, "nautilus.desktop") ||
349
boost::algorithm::ends_with(desktop_file, "nautilus-folder-handler.desktop") ||
350
boost::algorithm::ends_with(desktop_file, "nautilus-home.desktop"))
352
return new FileManagerLauncherIcon(app, device_section_);
355
return new ApplicationLauncherIcon(app);
341
358
void Controller::Impl::OnLauncherAddRequest(std::string const& icon_uri, AbstractLauncherIcon::Ptr const& icon_before)
343
360
std::string app_uri;
488
Controller::Impl::OnLauncherAddRequestSpecial(std::string const& path,
489
std::string const& aptdaemon_trans_id,
490
std::string const& icon_path,
505
Controller::Impl::OnLauncherAddRequestSpecial(std::string const& appstream_app_id,
506
std::string const& aptdaemon_trans_id)
495
// Check if desktop file was supplied, or if it's set to SC's agent
496
// See https://bugs.launchpad.net/unity/+bug/1002440
497
if (path.empty() || path == local::SOFTWARE_CENTER_AGENT)
508
// Check if desktop file was supplied
509
if (appstream_app_id.empty())
500
512
auto const& icon = std::find_if(model_->begin(), model_->end(),
501
[&path](AbstractLauncherIcon::Ptr const& i) { return (i->DesktopFile() == path); });
513
[&appstream_app_id](AbstractLauncherIcon::Ptr const& i) { return (i->DesktopFile() == appstream_app_id); });
503
515
if (icon != model_->end())
506
auto const& result = CreateSCLauncherIcon(path, aptdaemon_trans_id, icon_path);
518
auto const& result = CreateSCLauncherIcon(appstream_app_id, aptdaemon_trans_id);
510
// Setting the icon position and adding it to the model, makes the launcher
511
// to compute its center
512
522
RegisterIcon(result, GetLastIconPriority<ApplicationLauncherIcon>("", true));
514
if (icon_x > 0 || icon_y > 0)
516
// This will ensure that the center of the new icon is set, so that
517
// the animation could be done properly.
518
sources_.AddIdle([this, icon_x, icon_y, result] {
519
return !result->Animate(CurrentLauncher(), icon_x, icon_y);
524
result->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
523
result->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
834
832
if (app->sticky() || app->seen())
837
AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
835
AbstractLauncherIcon::Ptr icon(CreateAppLauncherIcon(app));
838
836
RegisterIcon(icon, GetLastIconPriority<ApplicationLauncherIcon>(local::RUNNING_APPS_URI));
871
869
if (!app || app->seen())
874
result = AbstractLauncherIcon::Ptr(new ApplicationLauncherIcon(app));
872
result = AbstractLauncherIcon::Ptr(CreateAppLauncherIcon(app));
876
874
else if (icon_uri.find(FavoriteStore::URI_PREFIX_DEVICE) == 0)
878
auto const& devices = device_section_.GetIcons();
876
auto const& devices = device_section_->GetIcons();
879
877
auto const& icon = std::find_if(devices.begin(), devices.end(),
880
878
[&icon_uri](AbstractLauncherIcon::Ptr const& i) { return (i->RemoteUri() == icon_uri); });
923
921
return AbstractLauncherIcon::Ptr();
926
SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::string const& file_path,
927
std::string const& aptdaemon_trans_id,
928
std::string const& icon_path)
924
SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::string const& appstream_app_id,
925
std::string const& aptdaemon_trans_id)
930
SoftwareCenterLauncherIcon::Ptr result;
932
ApplicationPtr app = ApplicationManager::Default().GetApplicationForDesktopFile(file_path);
939
result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);
927
ApplicationPtr app = std::make_shared<appstream::Application>(appstream_app_id);
928
return SoftwareCenterLauncherIcon::Ptr(new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id));
944
931
void Controller::Impl::AddRunningApps()
950
937
<< (app->seen() ? "yes" : "no");
951
938
if (!app->seen())
953
AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
940
AbstractLauncherIcon::Ptr icon(CreateAppLauncherIcon(app));
954
941
icon->SkipQuirkAnimation(AbstractLauncherIcon::Quirk::VISIBLE);
955
942
RegisterIcon(icon, ++sort_priority_);
960
947
void Controller::Impl::AddDevices()
962
949
auto& fav_store = FavoriteStore::Instance();
963
for (auto const& icon : device_section_.GetIcons())
950
for (auto const& icon : device_section_->GetIcons())
965
952
if (!icon->IsSticky() && !fav_store.IsFavorite(icon->RemoteUri()))
1040
1027
ApplicationManager::Default().application_started
1041
1028
.connect(sigc::mem_fun(this, &Impl::OnApplicationStarted));
1043
device_section_.icon_added.connect(sigc::mem_fun(this, &Impl::OnDeviceIconAdded));
1030
device_section_->icon_added.connect(sigc::mem_fun(this, &Impl::OnDeviceIconAdded));
1044
1031
favorite_store.favorite_added.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteAdded));
1045
1032
favorite_store.favorite_removed.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteRemoved));
1046
1033
favorite_store.reordered.connect(sigc::mem_fun(this, &Impl::ResetIconPriorities));
1114
1101
for (auto icon : *(pimpl->model_))
1116
if (icon->ShowInSwitcher(current))
1103
//otherwise we get two desktop icons in the switcher.
1104
if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
1118
//otherwise we get two desktop icons in the switcher.
1119
if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
1121
results.push_back(icon);
1106
results.push_back(icon);
1125
1109
return results;
1531
1515
GVariant* Controller::Impl::OnDBusMethodCall(std::string const& method, GVariant *parameters)
1533
if (method == "AddLauncherItemFromPosition")
1517
if (method == "AddLauncherItem")
1535
glib::String icon, icon_title, desktop_file, aptdaemon_task;
1536
gint icon_x, icon_y, icon_size;
1538
g_variant_get(parameters, "(ssiiiss)", &icon_title, &icon, &icon_x, &icon_y,
1539
&icon_size, &desktop_file, &aptdaemon_task);
1541
OnLauncherAddRequestSpecial(desktop_file.Str(), aptdaemon_task.Str(),
1542
icon.Str(), icon_x, icon_y, icon_size);
1519
glib::String appstream_app_id, aptdaemon_trans_id;
1520
g_variant_get(parameters, "(ss)", &appstream_app_id, &aptdaemon_trans_id);
1521
OnLauncherAddRequestSpecial(appstream_app_id.Str(), aptdaemon_trans_id.Str());
1544
1523
else if (method == "UpdateLauncherIconFavoriteState")