~thalexander/unity/update-fsf-address

« back to all changes in this revision

Viewing changes to launcher/TrashLauncherIcon.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:
1
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
2
/*
3
 
 * Copyright (C) 2010-2013 Canonical Ltd
 
3
 * Copyright (C) 2010-2015 Canonical Ltd
4
4
 *
5
5
 * This program is free software: you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License version 3 as
24
24
#include "config.h"
25
25
#include <glib/gi18n-lib.h>
26
26
#include <NuxCore/Logger.h>
 
27
#include <UnityCore/DesktopUtilities.h>
27
28
#include <zeitgeist.h>
28
29
 
29
30
#include "QuicklistMenuItemLabel.h"
39
40
  DECLARE_LOGGER(logger, "unity.launcher.icon.trash");
40
41
  const std::string ZEITGEIST_UNITY_ACTOR = "application://compiz.desktop";
41
42
  const std::string TRASH_URI = "trash:";
 
43
  const std::string TRASH_PATH = "file://" + DesktopUtilities::GetUserTrashDirectory();
42
44
}
43
45
 
44
 
TrashLauncherIcon::TrashLauncherIcon(FileManager::Ptr const& fmo)
45
 
  : SimpleLauncherIcon(IconType::TRASH)
 
46
TrashLauncherIcon::TrashLauncherIcon(FileManager::Ptr const& fm)
 
47
  : WindowedLauncherIcon(IconType::TRASH)
 
48
  , StorageLauncherIcon(GetIconType(), fm ? fm : GnomeFileManager::Get())
46
49
  , empty_(true)
47
 
  , file_manager_(fmo ? fmo : GnomeFileManager::Get())
48
50
{
49
51
  tooltip_text = _("Trash");
50
52
  icon_name = "user-trash";
51
53
  position = Position::END;
52
54
  SetQuirk(Quirk::VISIBLE, true);
53
55
  SkipQuirkAnimation(Quirk::VISIBLE);
54
 
 
55
 
  SetQuirk(Quirk::RUNNING, file_manager_->IsTrashOpened());
56
56
  SetShortcut('t');
57
57
 
58
58
  glib::Object<GFile> location(g_file_new_for_uri(TRASH_URI.c_str()));
67
67
  }
68
68
  else
69
69
  {
70
 
    trash_changed_signal_.Connect(trash_monitor_, "changed",
 
70
    glib_signals_.Add<void, GFileMonitor*, GFile*, GFile*, GFileMonitorEvent>(trash_monitor_, "changed",
71
71
    [this] (GFileMonitor*, GFile*, GFile*, GFileMonitorEvent) {
72
72
      UpdateTrashIcon();
73
73
    });
74
74
  }
75
75
 
76
 
  file_manager_->locations_changed.connect(sigc::mem_fun(this, &TrashLauncherIcon::OnOpenedLocationsChanged));
77
 
 
78
76
  UpdateTrashIcon();
79
 
}
80
 
 
81
 
void TrashLauncherIcon::OnOpenedLocationsChanged()
82
 
{
83
 
  SetQuirk(Quirk::RUNNING, file_manager_->IsTrashOpened());
 
77
  UpdateStorageWindows();
 
78
}
 
79
 
 
80
WindowList TrashLauncherIcon::GetStorageWindows() const
 
81
{
 
82
  auto windows = file_manager_->WindowsForLocation(TRASH_URI);
 
83
  auto const& path_wins = file_manager_->WindowsForLocation(TRASH_PATH);
 
84
  windows.insert(end(windows), begin(path_wins), end(path_wins));
 
85
  return windows;
 
86
}
 
87
 
 
88
void TrashLauncherIcon::OpenInstanceLauncherIcon(Time timestamp)
 
89
{
 
90
  file_manager_->OpenTrash(timestamp);
84
91
}
85
92
 
86
93
AbstractLauncherIcon::MenuItemsVector TrashLauncherIcon::GetMenus()
92
99
  dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Empty Trash…"));
93
100
  dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, !empty_);
94
101
  dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
95
 
  empty_activated_signal_.Connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
 
102
  glib_signals_.Add<void, DbusmenuMenuitem*, unsigned>(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
96
103
  [this] (DbusmenuMenuitem*, unsigned timestamp) {
97
104
    file_manager_->EmptyTrash(timestamp);
98
105
  });
99
106
 
100
107
  result.push_back(menu_item);
101
108
 
 
109
  if (IsRunning())
 
110
  {
 
111
    auto const& windows_items = GetWindowsMenuItems();
 
112
    if (!windows_items.empty())
 
113
    {
 
114
      menu_item = dbusmenu_menuitem_new();
 
115
      dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
 
116
      result.push_back(menu_item);
 
117
 
 
118
      result.insert(end(result), begin(windows_items), end(windows_items));
 
119
    }
 
120
 
 
121
    menu_item = dbusmenu_menuitem_new();
 
122
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
 
123
    result.push_back(menu_item);
 
124
 
 
125
    menu_item = dbusmenu_menuitem_new();
 
126
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Quit"));
 
127
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
 
128
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
 
129
    result.push_back(menu_item);
 
130
 
 
131
    glib_signals_.Add<void, DbusmenuMenuitem*, unsigned>(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {
 
132
      Quit();
 
133
    });
 
134
  }
 
135
 
102
136
  return result;
103
137
}
104
138
 
105
 
void TrashLauncherIcon::ActivateLauncherIcon(ActionArg arg)
106
 
{
107
 
  SimpleLauncherIcon::ActivateLauncherIcon(arg);
108
 
  file_manager_->OpenTrash(arg.timestamp);
109
 
}
110
 
 
111
139
void TrashLauncherIcon::UpdateTrashIcon()
112
140
{
113
141
  glib::Object<GFile> location(g_file_new_for_uri(TRASH_URI.c_str()));