~unity-team/unity/trunk

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/BamfLauncherIcon.cpp

  • Committer: Tarmac
  • Author(s): Andrea Azzarone
  • Date: 2012-04-25 00:32:14 UTC
  • mfrom: (2332.2.4 fix-880798)
  • Revision ID: tarmac-20120425003214-zbax4oylstfns0vm
Enable dnd for all launcher icons (and not just the ones matching the type).. Fixes: https://bugs.launchpad.net/bugs/880798. Approved by Marco Trevisan (Treviño).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *              Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
19
19
 */
20
20
 
 
21
#include <boost/algorithm/string.hpp>
 
22
 
21
23
#include <Nux/Nux.h>
22
24
#include <Nux/BaseWindow.h>
23
25
 
1069
1071
  return _remote_uri;
1070
1072
}
1071
1073
 
1072
 
std::set<std::string> BamfLauncherIcon::ValidateUrisForLaunch(unity::DndData& uris)
 
1074
std::set<std::string> BamfLauncherIcon::ValidateUrisForLaunch(DndData const& uris)
1073
1075
{
1074
1076
  std::set<std::string> result;
1075
 
  gboolean is_home_launcher = g_str_has_suffix(DesktopFile().c_str(), "nautilus-home.desktop");
1076
 
 
1077
 
  if (is_home_launcher)
1078
 
  {
1079
 
    for (auto k : uris.Uris())
1080
 
      result.insert(k);
1081
 
    return result;
1082
 
  }
1083
 
 
1084
 
  for (auto i : uris.Types())
1085
 
  {
1086
 
    for (auto j : GetSupportedTypes())
1087
 
    {
1088
 
      if (g_content_type_is_a(i.c_str(), j.c_str()))
1089
 
      {
1090
 
        for (auto k : uris.UrisByType(i))
1091
 
          result.insert(k);
1092
 
 
1093
 
        break;
1094
 
      }
1095
 
    }
1096
 
  }
 
1077
 
 
1078
  for (auto uri : uris.Uris())
 
1079
    result.insert(uri);
1097
1080
 
1098
1081
  return result;
1099
1082
}
1125
1108
  _dnd_hover_timer = 0;
1126
1109
}
1127
1110
 
1128
 
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop(unity::DndData& dnd_data)
 
1111
bool BamfLauncherIcon::OnShouldHighlightOnDrag(DndData const& dnd_data)
 
1112
{
 
1113
  bool is_home_launcher = boost::algorithm::ends_with(DesktopFile(), "nautilus-home.desktop") ||
 
1114
                          boost::algorithm::ends_with(DesktopFile(), "nautilus.desktop");
 
1115
 
 
1116
  if (is_home_launcher)
 
1117
  {
 
1118
    return true;
 
1119
  }
 
1120
 
 
1121
  for (auto type : dnd_data.Types())
 
1122
  {
 
1123
    for (auto supported_type : GetSupportedTypes())
 
1124
    {
 
1125
      if (g_content_type_is_a(type.c_str(), supported_type.c_str()))
 
1126
      {
 
1127
        if (!dnd_data.UrisByType(type).empty())
 
1128
          return true;
 
1129
      }
 
1130
    }
 
1131
  }
 
1132
 
 
1133
  return false; 
 
1134
}
 
1135
 
 
1136
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop(DndData const& dnd_data)
1129
1137
{
1130
1138
  return ValidateUrisForLaunch(dnd_data).empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY;
1131
1139
}
1132
1140
 
1133
 
void BamfLauncherIcon::OnAcceptDrop(unity::DndData& dnd_data)
 
1141
void BamfLauncherIcon::OnAcceptDrop(DndData const& dnd_data)
1134
1142
{
1135
1143
  OpenInstanceWithUris(ValidateUrisForLaunch(dnd_data));
1136
1144
}