2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2012 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: Andrea Azzarone <andrea.azzarone@canonical.com>
|
|
18 |
*/
|
|
19 |
||
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
20 |
#include <gio/gio.h> |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
21 |
#include <gtk/gtk.h> |
22 |
#include <UnityCore/GLibSignal.h> |
|
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
23 |
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
24 |
#include "VolumeImp.h" |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
25 |
|
26 |
namespace unity |
|
27 |
{
|
|
28 |
namespace launcher |
|
29 |
{
|
|
30 |
||
31 |
//
|
|
32 |
// Start private implementation
|
|
33 |
//
|
|
34 |
||
3270.3.1
by Marco Trevisan (Treviño)
VolumeImp: disconnect from file-manager signal on destruction |
35 |
class VolumeImp::Impl : public sigc::trackable |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
36 |
{
|
37 |
public: |
|
3555.2.9
by Marco Trevisan (Treviño)
Volume: remove FileManager instance, handle opened status in VolumeLauncherIcon |
38 |
Impl(glib::Object<GVolume> const& volume, VolumeImp* parent) |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
39 |
: parent_(parent) |
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
40 |
, volume_(volume) |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
41 |
{
|
42 |
signal_volume_changed_.Connect(volume_, "changed", [this] (GVolume*) { |
|
43 |
parent_->changed.emit(); |
|
44 |
});
|
|
2540.12.23
by Andrea Azzarone
Remove OnRemoved fun. |
45 |
|
46 |
signal_volume_removed_.Connect(volume_, "removed", [this] (GVolume*) { |
|
3212.3.26
by Marco Trevisan (Treviño)
Volume: add IsOpened method and opened signal that matches the file-manager status |
47 |
parent_->removed.emit(); |
48 |
});
|
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
49 |
}
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
50 |
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
51 |
bool CanBeEjected() const |
52 |
{
|
|
53 |
return g_volume_can_eject(volume_) != FALSE; |
|
54 |
}
|
|
55 |
||
4067.3.3
by Andrea Azzarone
Make sure a volume can be formatted. |
56 |
bool CanBeFormatted() const |
57 |
{
|
|
58 |
return !GetUnixDevicePath().empty(); |
|
59 |
}
|
|
60 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
61 |
bool CanBeRemoved() const |
62 |
{
|
|
63 |
glib::Object<GDrive> drive(g_volume_get_drive(volume_)); |
|
64 |
return drive && g_drive_is_media_removable(drive) != FALSE; |
|
65 |
}
|
|
66 |
||
67 |
bool CanBeStopped() const |
|
68 |
{
|
|
69 |
glib::Object<GDrive> drive(g_volume_get_drive(volume_)); |
|
70 |
return drive && g_drive_can_stop(drive) != FALSE; |
|
71 |
}
|
|
72 |
||
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
73 |
std::string GetName() const |
74 |
{
|
|
75 |
return glib::String(g_volume_get_name(volume_)).Str(); |
|
76 |
}
|
|
77 |
||
78 |
std::string GetIconName() const |
|
79 |
{
|
|
80 |
glib::Object<GIcon> icon(g_volume_get_icon(volume_)); |
|
81 |
return glib::String(g_icon_to_string(icon)).Str(); |
|
82 |
}
|
|
83 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
84 |
std::string GetIdentifier() const |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
85 |
{
|
2702.1.2
by Andrea Azzarone
Use uuid+label as ID. |
86 |
glib::String label(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_LABEL)); |
87 |
glib::String uuid(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UUID)); |
|
88 |
||
4121.4.1
by Andrea Azzarone
Fallback to volume name if no other identifier is available. |
89 |
if (!label && !uuid) |
90 |
return GetName(); |
|
91 |
else
|
|
92 |
return uuid.Str() + "-" + label.Str(); |
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
93 |
}
|
94 |
||
4067.3.2
by Andrea Azzarone
Add format option. |
95 |
std::string GetUnixDevicePath() const |
96 |
{
|
|
97 |
glib::String ret(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); |
|
98 |
return ret.Str(); |
|
99 |
}
|
|
100 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
101 |
bool HasSiblings() const |
102 |
{
|
|
103 |
glib::Object<GDrive> drive(g_volume_get_drive(volume_)); |
|
104 |
||
105 |
if (!drive) |
|
106 |
return false; |
|
107 |
||
108 |
GList* volumes = g_drive_get_volumes(drive); |
|
2540.12.15
by Andrea Azzarone
Merge trunk. |
109 |
bool has_sibilings = volumes && volumes->next; |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
110 |
|
111 |
if (volumes) |
|
112 |
g_list_free_full(volumes, g_object_unref); |
|
113 |
||
114 |
return has_sibilings; |
|
115 |
}
|
|
116 |
||
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
117 |
bool IsMounted() const |
118 |
{
|
|
119 |
glib::Object<GMount> mount(g_volume_get_mount(volume_)); |
|
120 |
return static_cast<bool>(mount); |
|
121 |
}
|
|
122 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
123 |
void Eject() |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
124 |
{
|
125 |
if (!CanBeEjected()) |
|
126 |
return; |
|
127 |
||
128 |
glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(nullptr)); |
|
129 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
130 |
g_volume_eject_with_operation(volume_, G_MOUNT_UNMOUNT_NONE, mount_op, cancellable_, |
131 |
[] (GObject* object, GAsyncResult* res, gpointer data) { |
|
132 |
if (g_volume_eject_with_operation_finish(G_VOLUME(object), res, nullptr)) |
|
133 |
static_cast<Impl*>(data)->parent_->ejected.emit(); |
|
134 |
}, this); |
|
135 |
}
|
|
136 |
||
137 |
void Mount() |
|
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
138 |
{
|
2784.1.1
by Andrea Azzarone
Use GMountOperation when mounting a volume. |
139 |
glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(nullptr)); |
140 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
141 |
g_volume_mount(volume_, G_MOUNT_MOUNT_NONE, mount_op, cancellable_, |
142 |
[] (GObject* object, GAsyncResult* res, gpointer data) { |
|
143 |
if (g_volume_mount_finish(G_VOLUME(object), res, nullptr)) |
|
144 |
static_cast<Impl*>(data)->parent_->mounted.emit(); |
|
145 |
}, this); |
|
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
146 |
}
|
147 |
||
3212.3.26
by Marco Trevisan (Treviño)
Volume: add IsOpened method and opened signal that matches the file-manager status |
148 |
std::string GetUri() const |
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
149 |
{
|
150 |
glib::Object<GMount> mount(g_volume_get_mount(volume_)); |
|
3212.3.26
by Marco Trevisan (Treviño)
Volume: add IsOpened method and opened signal that matches the file-manager status |
151 |
|
152 |
if (!mount.IsType(G_TYPE_MOUNT)) |
|
153 |
return std::string(); |
|
154 |
||
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
155 |
glib::Object<GFile> root(g_mount_get_root(mount)); |
156 |
||
3212.3.26
by Marco Trevisan (Treviño)
Volume: add IsOpened method and opened signal that matches the file-manager status |
157 |
if (!root.IsType(G_TYPE_FILE)) |
158 |
return std::string(); |
|
159 |
||
160 |
return glib::String(g_file_get_uri(root)).Str(); |
|
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
161 |
}
|
162 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
163 |
void StopDrive() |
164 |
{
|
|
165 |
if (!CanBeStopped()) |
|
166 |
return; |
|
167 |
||
168 |
glib::Object<GDrive> drive(g_volume_get_drive(volume_)); |
|
169 |
glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(NULL)); |
|
170 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
171 |
g_drive_stop(drive, G_MOUNT_UNMOUNT_NONE, mount_op, cancellable_, |
172 |
[] (GObject* object, GAsyncResult* res, gpointer data) { |
|
173 |
if (g_drive_stop_finish(G_DRIVE(object), res, nullptr)) |
|
174 |
static_cast<Impl*>(data)->parent_->stopped.emit(); |
|
175 |
}, this); |
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
176 |
}
|
177 |
||
178 |
void Unmount() |
|
179 |
{
|
|
180 |
if (!IsMounted()) |
|
181 |
return; |
|
182 |
||
183 |
glib::Object<GMount> mount(g_volume_get_mount(volume_)); |
|
184 |
glib::Object<GMountOperation> op(gtk_mount_operation_new(nullptr)); |
|
185 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
186 |
g_mount_unmount_with_operation(mount, G_MOUNT_UNMOUNT_NONE, op, cancellable_, |
187 |
[] (GObject* object, GAsyncResult* res, gpointer data) { |
|
188 |
if (g_mount_unmount_with_operation_finish(G_MOUNT(object), res, nullptr)) |
|
189 |
static_cast<Impl*>(data)->parent_->unmounted.emit(); |
|
190 |
}, this); |
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
191 |
}
|
192 |
||
193 |
VolumeImp* parent_; |
|
3227.3.17
by Marco Trevisan (Treviño)
VolumeImp: use glib::Cancellable |
194 |
glib::Cancellable cancellable_; |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
195 |
glib::Object<GVolume> volume_; |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
196 |
|
197 |
glib::Signal<void, GVolume*> signal_volume_changed_; |
|
2540.12.24
by Andrea Azzarone
Fix typo. |
198 |
glib::Signal<void, GVolume*> signal_volume_removed_; |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
199 |
};
|
200 |
||
201 |
//
|
|
202 |
// End private implementation
|
|
2540.12.5
by Andrea Azzarone
Add TestMountAndOpenInFileManager method and test it. |
203 |
//
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
204 |
|
3555.2.9
by Marco Trevisan (Treviño)
Volume: remove FileManager instance, handle opened status in VolumeLauncherIcon |
205 |
VolumeImp::VolumeImp(glib::Object<GVolume> const& volume) |
206 |
: pimpl(new Impl(volume, this)) |
|
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
207 |
{}
|
208 |
||
209 |
VolumeImp::~VolumeImp() |
|
210 |
{}
|
|
211 |
||
212 |
bool VolumeImp::CanBeEjected() const |
|
213 |
{
|
|
214 |
return pimpl->CanBeEjected(); |
|
215 |
}
|
|
216 |
||
4067.3.3
by Andrea Azzarone
Make sure a volume can be formatted. |
217 |
bool VolumeImp::CanBeFormatted() const |
218 |
{
|
|
219 |
return pimpl->CanBeFormatted(); |
|
220 |
}
|
|
221 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
222 |
bool VolumeImp::CanBeRemoved() const |
223 |
{
|
|
224 |
return pimpl->CanBeRemoved(); |
|
225 |
}
|
|
226 |
||
227 |
bool VolumeImp::CanBeStopped() const |
|
228 |
{
|
|
229 |
return pimpl->CanBeStopped(); |
|
230 |
}
|
|
231 |
||
232 |
std::string VolumeImp::GetName() const |
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
233 |
{
|
234 |
return pimpl->GetName(); |
|
235 |
}
|
|
236 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
237 |
std::string VolumeImp::GetIconName() const |
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
238 |
{
|
239 |
return pimpl->GetIconName(); |
|
240 |
}
|
|
241 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
242 |
std::string VolumeImp::GetIdentifier() const |
243 |
{
|
|
244 |
return pimpl->GetIdentifier(); |
|
245 |
}
|
|
246 |
||
4067.3.2
by Andrea Azzarone
Add format option. |
247 |
std::string VolumeImp::GetUnixDevicePath() const |
248 |
{
|
|
249 |
return pimpl->GetUnixDevicePath(); |
|
250 |
}
|
|
251 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
252 |
std::string VolumeImp::GetUri() const |
253 |
{
|
|
254 |
return pimpl->GetUri(); |
|
255 |
}
|
|
256 |
||
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
257 |
bool VolumeImp::HasSiblings() const |
258 |
{
|
|
259 |
return pimpl->HasSiblings(); |
|
260 |
}
|
|
261 |
||
262 |
bool VolumeImp::IsMounted() const |
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
263 |
{
|
264 |
return pimpl->IsMounted(); |
|
265 |
}
|
|
266 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
267 |
void VolumeImp::Mount() |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
268 |
{
|
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
269 |
pimpl->Mount(); |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
270 |
}
|
271 |
||
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
272 |
void VolumeImp::Eject() |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
273 |
{
|
3555.2.8
by Marco Trevisan (Treviño)
Volume: move FileManager and Notification actions to VolumeLauncherIcon |
274 |
pimpl->Eject(); |
2540.12.7
by Andrea Azzarone
Move device settings from a favorite list to a blacklist. |
275 |
}
|
276 |
||
277 |
void VolumeImp::StopDrive() |
|
278 |
{
|
|
279 |
pimpl->StopDrive(); |
|
280 |
}
|
|
281 |
||
282 |
void VolumeImp::Unmount() |
|
283 |
{
|
|
284 |
pimpl->Unmount(); |
|
2540.12.1
by Andrea Azzarone
Add unity::launcher::Volume interface class with its implementation. |
285 |
}
|
286 |
||
287 |
} // namespace launcher |
|
288 |
} // namespace unity |