697.5.2
by Neil Jagdish Patel
some initial device support |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2010 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
|
|
18 |
*/
|
|
19 |
||
20 |
#include "DeviceLauncherIcon.h" |
|
21 |
||
22 |
#include "ubus-server.h" |
|
23 |
#include "UBusMessages.h" |
|
24 |
||
697.4.26
by Neil Jagdish Patel
Make eject work |
25 |
#include <glib/gi18n-lib.h> |
26 |
||
697.4.23
by Neil Jagdish Patel
Make icons show up |
27 |
#define DEFAULT_ICON "drive-removable-media"
|
28 |
||
697.5.2
by Neil Jagdish Patel
some initial device support |
29 |
DeviceLauncherIcon::DeviceLauncherIcon (Launcher *launcher, GVolume *volume) |
30 |
: SimpleLauncherIcon(launcher), |
|
31 |
_volume (volume) |
|
32 |
{
|
|
697.4.23
by Neil Jagdish Patel
Make icons show up |
33 |
g_signal_connect (_volume, "removed", |
34 |
G_CALLBACK (&DeviceLauncherIcon::OnRemoved), this); |
|
35 |
||
36 |
UpdateDeviceIcon (); |
|
37 |
||
38 |
}
|
|
39 |
||
40 |
DeviceLauncherIcon::~DeviceLauncherIcon() |
|
41 |
{
|
|
42 |
||
43 |
}
|
|
44 |
||
45 |
void
|
|
46 |
DeviceLauncherIcon::UpdateDeviceIcon () |
|
47 |
{
|
|
48 |
{
|
|
49 |
gchar *name; |
|
50 |
gchar *escape; |
|
51 |
||
52 |
name = g_volume_get_name (_volume); |
|
53 |
escape = g_markup_escape_text (name, -1); |
|
54 |
||
55 |
SetTooltipText (escape); |
|
56 |
||
57 |
g_free (escape); |
|
58 |
g_free (name); |
|
59 |
}
|
|
60 |
||
61 |
{
|
|
62 |
GIcon *icon; |
|
871.4.31
by Neil Jagdish Patel
Make LauncherIcon GIcon aware |
63 |
gchar *icon_string; |
697.4.23
by Neil Jagdish Patel
Make icons show up |
64 |
|
65 |
icon = g_volume_get_icon (_volume); |
|
871.4.31
by Neil Jagdish Patel
Make LauncherIcon GIcon aware |
66 |
icon_string = g_icon_to_string (icon); |
67 |
||
68 |
SetIconName (icon_string); |
|
697.4.26
by Neil Jagdish Patel
Make eject work |
69 |
|
70 |
g_object_unref (icon); |
|
871.4.31
by Neil Jagdish Patel
Make LauncherIcon GIcon aware |
71 |
g_free (icon_string); |
697.4.23
by Neil Jagdish Patel
Make icons show up |
72 |
}
|
73 |
||
697.5.2
by Neil Jagdish Patel
some initial device support |
74 |
SetQuirk (QUIRK_VISIBLE, true); |
75 |
SetQuirk (QUIRK_RUNNING, false); |
|
76 |
SetIconType (TYPE_DEVICE); |
|
77 |
}
|
|
78 |
||
79 |
nux::Color |
|
80 |
DeviceLauncherIcon::BackgroundColor () |
|
81 |
{
|
|
82 |
return nux::Color (0xFF333333); |
|
83 |
}
|
|
84 |
||
85 |
nux::Color |
|
86 |
DeviceLauncherIcon::GlowColor () |
|
87 |
{
|
|
88 |
return nux::Color (0xFF333333); |
|
89 |
}
|
|
90 |
||
91 |
void
|
|
92 |
DeviceLauncherIcon::OnMouseClick (int button) |
|
93 |
{
|
|
94 |
SimpleLauncherIcon::OnMouseClick (button); |
|
95 |
||
96 |
if (button == 1) |
|
97 |
{
|
|
873.1.2
by Didier Roche
fix for activating places, devices, trash on keynav (and so, will work on shortcut as well) (LP: #723141) |
98 |
ActivateLauncherIcon (); |
697.5.2
by Neil Jagdish Patel
some initial device support |
99 |
}
|
100 |
}
|
|
101 |
||
102 |
std::list<DbusmenuMenuitem *> |
|
103 |
DeviceLauncherIcon::GetMenus () |
|
104 |
{
|
|
105 |
std::list<DbusmenuMenuitem *> result; |
|
106 |
DbusmenuMenuitem *menu_item; |
|
107 |
||
108 |
menu_item = dbusmenu_menuitem_new (); |
|
697.4.26
by Neil Jagdish Patel
Make eject work |
109 |
dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Open")); |
697.5.2
by Neil Jagdish Patel
some initial device support |
110 |
dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
111 |
dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); |
|
112 |
g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
|
113 |
G_CALLBACK (&DeviceLauncherIcon::OnOpen), this); |
|
114 |
result.push_back (menu_item); |
|
115 |
||
697.4.26
by Neil Jagdish Patel
Make eject work |
116 |
if (g_volume_can_eject (_volume)) |
117 |
{
|
|
118 |
menu_item = dbusmenu_menuitem_new (); |
|
119 |
dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Eject")); |
|
120 |
dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
|
121 |
dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); |
|
122 |
g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
|
123 |
G_CALLBACK (&DeviceLauncherIcon::OnEject), this); |
|
124 |
result.push_back (menu_item); |
|
125 |
}
|
|
126 |
||
697.5.2
by Neil Jagdish Patel
some initial device support |
127 |
return result; |
128 |
}
|
|
129 |
||
130 |
void
|
|
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
131 |
DeviceLauncherIcon::ShowMount (GMount *mount) |
697.5.2
by Neil Jagdish Patel
some initial device support |
132 |
{
|
697.4.24
by Neil Jagdish Patel
show volumes that are already mounted |
133 |
gchar *name; |
134 |
||
135 |
name = g_volume_get_name (_volume); |
|
136 |
if (G_IS_MOUNT (mount)) |
|
137 |
{
|
|
138 |
GFile *root; |
|
139 |
||
140 |
root = g_mount_get_root (mount); |
|
141 |
if (G_IS_FILE (root)) |
|
142 |
{
|
|
143 |
gchar *uri; |
|
144 |
GError *error = NULL; |
|
145 |
||
146 |
uri = g_file_get_uri (root); |
|
147 |
||
148 |
g_app_info_launch_default_for_uri (uri, NULL, &error); |
|
149 |
if (error) |
|
150 |
{
|
|
151 |
g_warning ("Cannot open volume '%s': Unable to show %s: %s", name, uri, error->message); |
|
152 |
g_error_free (error); |
|
153 |
}
|
|
154 |
||
155 |
g_free (uri); |
|
156 |
g_object_unref (root); |
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
g_warning ("Cannot open volume '%s': Mount has no root", name); |
|
161 |
}
|
|
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
162 |
}
|
163 |
else
|
|
164 |
{
|
|
697.4.26
by Neil Jagdish Patel
Make eject work |
165 |
g_warning ("Cannot open volume '%s': Mount-point is invalid", name); |
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
166 |
}
|
167 |
||
697.4.26
by Neil Jagdish Patel
Make eject work |
168 |
g_free (name); |
169 |
}
|
|
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
170 |
|
171 |
void
|
|
873.1.2
by Didier Roche
fix for activating places, devices, trash on keynav (and so, will work on shortcut as well) (LP: #723141) |
172 |
DeviceLauncherIcon::ActivateLauncherIcon () |
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
173 |
{
|
174 |
GMount *mount; |
|
175 |
gchar *name; |
|
176 |
||
177 |
SetQuirk (QUIRK_STARTING, true); |
|
178 |
||
179 |
name = g_volume_get_name (_volume); |
|
180 |
mount = g_volume_get_mount (_volume); |
|
181 |
if (G_IS_MOUNT (mount)) |
|
182 |
{
|
|
183 |
ShowMount (mount); |
|
697.4.24
by Neil Jagdish Patel
show volumes that are already mounted |
184 |
g_object_unref (mount); |
185 |
}
|
|
186 |
else
|
|
187 |
{
|
|
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
188 |
g_volume_mount (_volume, |
189 |
(GMountMountFlags)0, |
|
190 |
NULL, |
|
191 |
NULL, |
|
192 |
(GAsyncReadyCallback)&DeviceLauncherIcon::OnMountReady, |
|
193 |
this); |
|
697.4.24
by Neil Jagdish Patel
show volumes that are already mounted |
194 |
}
|
195 |
||
196 |
g_free (name); |
|
697.5.2
by Neil Jagdish Patel
some initial device support |
197 |
}
|
198 |
||
199 |
void
|
|
697.4.25
by Neil Jagdish Patel
Support mounting drives that need mounting before showing them |
200 |
DeviceLauncherIcon::OnMountReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self) |
201 |
{
|
|
202 |
GError *error = NULL; |
|
203 |
||
204 |
if (g_volume_mount_finish (self->_volume, result, &error)) |
|
205 |
{
|
|
206 |
GMount *mount; |
|
207 |
||
208 |
mount = g_volume_get_mount (self->_volume); |
|
209 |
self->ShowMount (mount); |
|
210 |
||
211 |
g_object_unref (mount); |
|
212 |
}
|
|
213 |
else
|
|
214 |
{
|
|
215 |
gchar *name; |
|
216 |
||
217 |
name = g_volume_get_name (self->_volume); |
|
218 |
g_warning ("Cannot open volume '%s': %s", |
|
219 |
name, |
|
220 |
error ? error->message : "Mount operation failed"); |
|
221 |
g_error_free (error); |
|
222 |
}
|
|
223 |
}
|
|
224 |
||
225 |
void
|
|
697.4.26
by Neil Jagdish Patel
Make eject work |
226 |
DeviceLauncherIcon::OnEjectReady (GObject *object, |
227 |
GAsyncResult *result, |
|
228 |
DeviceLauncherIcon *self) |
|
229 |
{
|
|
230 |
g_volume_eject_with_operation_finish (self->_volume, result, NULL); |
|
231 |
}
|
|
232 |
||
233 |
void
|
|
234 |
DeviceLauncherIcon::Eject () |
|
235 |
{
|
|
236 |
g_debug ("%s", G_STRLOC); |
|
237 |
g_volume_eject_with_operation (_volume, |
|
238 |
(GMountUnmountFlags)0, |
|
239 |
NULL, |
|
240 |
NULL, |
|
241 |
(GAsyncReadyCallback)OnEjectReady, |
|
242 |
this); |
|
243 |
g_debug ("%s", G_STRLOC); |
|
244 |
}
|
|
245 |
||
246 |
void
|
|
697.5.2
by Neil Jagdish Patel
some initial device support |
247 |
DeviceLauncherIcon::OnOpen (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self) |
248 |
{
|
|
873.1.2
by Didier Roche
fix for activating places, devices, trash on keynav (and so, will work on shortcut as well) (LP: #723141) |
249 |
self->ActivateLauncherIcon (); |
697.5.2
by Neil Jagdish Patel
some initial device support |
250 |
}
|
251 |
||
252 |
void
|
|
697.4.26
by Neil Jagdish Patel
Make eject work |
253 |
DeviceLauncherIcon::OnEject (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self) |
254 |
{
|
|
255 |
g_debug ("%s", G_STRLOC); |
|
256 |
self->Eject (); |
|
257 |
g_debug ("%s", G_STRLOC); |
|
258 |
}
|
|
259 |
||
260 |
void
|
|
697.5.2
by Neil Jagdish Patel
some initial device support |
261 |
DeviceLauncherIcon::OnRemoved (GVolume *volume, DeviceLauncherIcon *self) |
262 |
{
|
|
263 |
self->Remove (); |
|
264 |
}
|