1
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2010-2013 Canonical Ltd
3
* Copyright (C) 2010-2015 Canonical Ltd
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
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();
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())
47
, file_manager_(fmo ? fmo : GnomeFileManager::Get())
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);
55
SetQuirk(Quirk::RUNNING, file_manager_->IsTrashOpened());
58
58
glib::Object<GFile> location(g_file_new_for_uri(TRASH_URI.c_str()));
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) {
76
file_manager_->locations_changed.connect(sigc::mem_fun(this, &TrashLauncherIcon::OnOpenedLocationsChanged));
81
void TrashLauncherIcon::OnOpenedLocationsChanged()
83
SetQuirk(Quirk::RUNNING, file_manager_->IsTrashOpened());
77
UpdateStorageWindows();
80
WindowList TrashLauncherIcon::GetStorageWindows() const
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));
88
void TrashLauncherIcon::OpenInstanceLauncherIcon(Time timestamp)
90
file_manager_->OpenTrash(timestamp);
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);
100
107
result.push_back(menu_item);
111
auto const& windows_items = GetWindowsMenuItems();
112
if (!windows_items.empty())
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);
118
result.insert(end(result), begin(windows_items), end(windows_items));
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);
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);
131
glib_signals_.Add<void, DbusmenuMenuitem*, unsigned>(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {
105
void TrashLauncherIcon::ActivateLauncherIcon(ActionArg arg)
107
SimpleLauncherIcon::ActivateLauncherIcon(arg);
108
file_manager_->OpenTrash(arg.timestamp);
111
139
void TrashLauncherIcon::UpdateTrashIcon()
113
141
glib::Object<GFile> location(g_file_new_for_uri(TRASH_URI.c_str()));