~thalexander/unity/update-fsf-address

« back to all changes in this revision

Viewing changes to launcher/LauncherController.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2016-03-07 18:51:47 UTC
  • mfrom: (4080 unity)
  • mto: This revision was merged to the branch mainline in revision 4085.
  • Revision ID: mail@3v1n0.net-20160307185147-0p1m89up4tqfb6w1
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "config.h"
23
23
#include <glib/gi18n-lib.h>
 
24
#include <boost/algorithm/string.hpp>
24
25
 
25
26
#include <Nux/Nux.h>
26
27
#include <Nux/HLayout.h>
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"
59
62
  "<node>"
60
63
  "  <interface name='com.canonical.Unity.Launcher'>"
61
64
  ""
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'/>"
70
68
  "    </method>"
71
69
  ""
102
100
 
103
101
  return FavoriteStore::URI_PREFIX_APP + DesktopUtilities::GetDesktopID(desktop_path);
104
102
}
105
 
 
106
103
}
107
104
 
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)
150
148
 
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
#else
153
154
  wm.viewport_layout_changed.connect(sigc::group(sigc::mem_fun(this, &Controller::Impl::UpdateNumWorkspaces), sigc::_1 * sigc::_2));
 
155
#endif
154
156
  average_color_connection_ = wm.average_color.changed.connect([this] (nux::Color const& color) {
155
157
    parent_->options()->background_color = color;
156
158
  });
338
340
  return launcher;
339
341
}
340
342
 
 
343
ApplicationLauncherIcon* Controller::Impl::CreateAppLauncherIcon(ApplicationPtr const& app)
 
344
{
 
345
  auto const& desktop_file = app->desktop_file();
 
346
 
 
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"))
 
351
  {
 
352
    return new FileManagerLauncherIcon(app, device_section_);
 
353
  }
 
354
 
 
355
  return new ApplicationLauncherIcon(app);
 
356
}
 
357
 
341
358
void Controller::Impl::OnLauncherAddRequest(std::string const& icon_uri, AbstractLauncherIcon::Ptr const& icon_before)
342
359
{
343
360
  std::string app_uri;
485
502
}
486
503
 
487
504
void
488
 
Controller::Impl::OnLauncherAddRequestSpecial(std::string const& path,
489
 
                                              std::string const& aptdaemon_trans_id,
490
 
                                              std::string const& icon_path,
491
 
                                              int icon_x,
492
 
                                              int icon_y,
493
 
                                              int icon_size)
 
505
Controller::Impl::OnLauncherAddRequestSpecial(std::string const& appstream_app_id,
 
506
                                              std::string const& aptdaemon_trans_id)
494
507
{
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())
498
510
    return;
499
511
 
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); });
502
514
 
503
515
  if (icon != model_->end())
504
516
    return;
505
517
 
506
 
  auto const& result = CreateSCLauncherIcon(path, aptdaemon_trans_id, icon_path);
 
518
  auto const& result = CreateSCLauncherIcon(appstream_app_id, aptdaemon_trans_id);
507
519
 
508
520
  if (result)
509
521
  {
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));
513
 
 
514
 
    if (icon_x > 0 || icon_y > 0)
515
 
    {
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);
520
 
      });
521
 
    }
522
 
    else
523
 
    {
524
 
      result->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
525
 
    }
 
523
    result->SetQuirk(AbstractLauncherIcon::Quirk::VISIBLE, true);
526
524
  }
527
525
}
528
526
 
834
832
  if (app->sticky() || app->seen())
835
833
    return;
836
834
 
837
 
  AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
 
835
  AbstractLauncherIcon::Ptr icon(CreateAppLauncherIcon(app));
838
836
  RegisterIcon(icon, GetLastIconPriority<ApplicationLauncherIcon>(local::RUNNING_APPS_URI));
839
837
}
840
838
 
871
869
    if (!app || app->seen())
872
870
      return result;
873
871
 
874
 
    result = AbstractLauncherIcon::Ptr(new ApplicationLauncherIcon(app));
 
872
    result = AbstractLauncherIcon::Ptr(CreateAppLauncherIcon(app));
875
873
  }
876
874
  else if (icon_uri.find(FavoriteStore::URI_PREFIX_DEVICE) == 0)
877
875
  {
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); });
881
879
 
923
921
  return AbstractLauncherIcon::Ptr();
924
922
}
925
923
 
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)
929
926
{
930
 
  SoftwareCenterLauncherIcon::Ptr result;
931
 
 
932
 
  ApplicationPtr app = ApplicationManager::Default().GetApplicationForDesktopFile(file_path);
933
 
  if (!app)
934
 
    return result;
935
 
 
936
 
  if (app->seen)
937
 
    return result;
938
 
 
939
 
  result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);
940
 
 
941
 
  return result;
 
927
  ApplicationPtr app = std::make_shared<appstream::Application>(appstream_app_id);
 
928
  return SoftwareCenterLauncherIcon::Ptr(new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id));
942
929
}
943
930
 
944
931
void Controller::Impl::AddRunningApps()
950
937
                     << (app->seen() ? "yes" : "no");
951
938
    if (!app->seen())
952
939
    {
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_);
956
943
    }
960
947
void Controller::Impl::AddDevices()
961
948
{
962
949
  auto& fav_store = FavoriteStore::Instance();
963
 
  for (auto const& icon : device_section_.GetIcons())
 
950
  for (auto const& icon : device_section_->GetIcons())
964
951
  {
965
952
    if (!icon->IsSticky() && !fav_store.IsFavorite(icon->RemoteUri()))
966
953
    {
1040
1027
  ApplicationManager::Default().application_started
1041
1028
    .connect(sigc::mem_fun(this, &Impl::OnApplicationStarted));
1042
1029
 
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));
1113
1100
 
1114
1101
  for (auto icon : *(pimpl->model_))
1115
1102
  {
1116
 
    if (icon->ShowInSwitcher(current))
 
1103
    //otherwise we get two desktop icons in the switcher.
 
1104
    if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
1117
1105
    {
1118
 
      //otherwise we get two desktop icons in the switcher.
1119
 
      if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
1120
 
      {
1121
 
        results.push_back(icon);
1122
 
      }
 
1106
      results.push_back(icon);
1123
1107
    }
1124
1108
  }
1125
1109
  return results;
1530
1514
 
1531
1515
GVariant* Controller::Impl::OnDBusMethodCall(std::string const& method, GVariant *parameters)
1532
1516
{
1533
 
  if (method == "AddLauncherItemFromPosition")
 
1517
  if (method == "AddLauncherItem")
1534
1518
  {
1535
 
    glib::String icon, icon_title, desktop_file, aptdaemon_task;
1536
 
    gint icon_x, icon_y, icon_size;
1537
 
 
1538
 
    g_variant_get(parameters, "(ssiiiss)", &icon_title, &icon, &icon_x, &icon_y,
1539
 
                                           &icon_size, &desktop_file, &aptdaemon_task);
1540
 
 
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());
1543
1522
  }
1544
1523
  else if (method == "UpdateLauncherIconFavoriteState")
1545
1524
  {