Merge lp:~3v1n0/unity/volume-filemanager-in-icon into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
Merged at revision: 3557
Proposed branch: lp:~3v1n0/unity/volume-filemanager-in-icon
Merge into: lp:unity
Diff against target: 2005 lines (+507/-537)
26 files modified
UnityCore/ActionHandle.h (+57/-0)
UnityCore/CMakeLists.txt (+1/-0)
UnityCore/ConnectionManager.h (+7/-37)
launcher/DeviceLauncherSection.cpp (+11/-9)
launcher/DeviceLauncherSection.h (+3/-2)
launcher/LauncherController.cpp (+0/-1)
launcher/LauncherControllerPrivate.h (+0/-2)
launcher/Volume.h (+7/-4)
launcher/VolumeImp.cpp (+40/-105)
launcher/VolumeImp.h (+4/-7)
launcher/VolumeLauncherIcon.cpp (+46/-23)
launcher/VolumeLauncherIcon.h (+5/-3)
tests/CMakeLists.txt (+5/-3)
tests/gmockvolume.c (+6/-6)
tests/test_action_handle.cpp (+109/-0)
tests/test_connection_manager.cpp (+0/-81)
tests/test_device_launcher_section.cpp (+5/-3)
tests/test_icon_loader.cpp (+7/-7)
tests/test_launcher_controller.cpp (+6/-3)
tests/test_mock_devices.h (+18/-6)
tests/test_mock_filemanager.h (+2/-0)
tests/test_volume_imp.cpp (+32/-85)
tests/test_volume_launcher_icon.cpp (+83/-39)
unity-shared/GnomeFileManager.cpp (+15/-8)
unity-shared/IconLoader.cpp (+30/-82)
unity-shared/IconLoader.h (+8/-21)
To merge this branch: bzr merge lp:~3v1n0/unity/volume-filemanager-in-icon
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Christopher Townsend Approve
Review via email: mp+189662@code.launchpad.net

Commit message

Volume: remove FileManager instance, handle opened status in VolumeLauncherIcon

Description of the change

Don't mix the Volume wrapper with the filemanager handling of it, we should do this in the icon itself.

Some various cleanup (as moved the connection::handle to a more generic action::handle), unit tests updated. This is a prerequisite for fixing bug #838731

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Works. +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'UnityCore/ActionHandle.h'
2--- UnityCore/ActionHandle.h 1970-01-01 00:00:00 +0000
3+++ UnityCore/ActionHandle.h 2013-10-07 17:26:52 +0000
4@@ -0,0 +1,57 @@
5+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
6+/*
7+* Copyright (C) 2013 Canonical Ltd
8+*
9+* This program is free software: you can redistribute it and/or modify
10+* it under the terms of the GNU General Public License version 3 as
11+* published by the Free Software Foundation.
12+*
13+* This program is distributed in the hope that it will be useful,
14+* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+* GNU General Public License for more details.
17+*
18+* You should have received a copy of the GNU General Public License
19+* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+*
21+* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
22+*/
23+
24+#ifndef UNITY_ACTION_HANDLE_H
25+#define UNITY_ACTION_HANDLE_H
26+
27+#include <memory>
28+
29+namespace unity
30+{
31+namespace action
32+{
33+struct handle
34+{
35+ constexpr handle() : handle_(0) {}
36+ constexpr handle(uint64_t val) : handle_(val) {}
37+ constexpr operator uint64_t() const { return handle_; }
38+ inline handle& operator++() { ++handle_; return *this; }
39+ inline handle operator++(int) { auto tmp = *this; ++handle_; return tmp; }
40+ inline handle& operator--() { --handle_; return *this; }
41+ inline handle operator--(int) { auto tmp = *this; --handle_; return tmp; }
42+
43+private:
44+ uint64_t handle_;
45+};
46+} // action namespace
47+} // unity namespace
48+
49+namespace std
50+{
51+// Template specialization, needed for unordered_map
52+template<> struct hash<unity::action::handle>
53+{
54+ std::size_t operator()(unity::action::handle const& h) const
55+ {
56+ return std::hash<uint64_t>()(h);
57+ }
58+};
59+}
60+
61+#endif // UNITY_ACTION_HANDLE_H
62
63=== modified file 'UnityCore/CMakeLists.txt'
64--- UnityCore/CMakeLists.txt 2013-09-25 12:15:03 +0000
65+++ UnityCore/CMakeLists.txt 2013-10-07 17:26:52 +0000
66@@ -13,6 +13,7 @@
67 # Headers & Sources
68 #
69 set (CORE_HEADERS
70+ ActionHandle.h
71 ApplicationPreview.h
72 AppmenuIndicator.h
73 Categories.h
74
75=== modified file 'UnityCore/ConnectionManager.h'
76--- UnityCore/ConnectionManager.h 2013-07-01 21:48:01 +0000
77+++ UnityCore/ConnectionManager.h 2013-10-07 17:26:52 +0000
78@@ -23,43 +23,13 @@
79 #include <memory>
80 #include <unordered_map>
81 #include <sigc++/sigc++.h>
82-
83-namespace unity
84-{
85-namespace connection
86-{
87-struct handle
88-{
89- handle() : handle_(0) {}
90- handle(uint64_t val) : handle_(val) {}
91- operator uint64_t() const { return handle_; }
92- handle& operator++() { ++handle_; return *this; }
93- handle operator++(int) { auto tmp = *this; ++handle_; return tmp; }
94- handle& operator--() { --handle_; return *this; }
95- handle operator--(int) { auto tmp = *this; --handle_; return tmp; }
96-
97-private:
98- uint64_t handle_;
99-};
100-} // connection namespace
101-} // unity namespace
102-
103-namespace std
104-{
105-// Template specialization, needed for unordered_map
106-template<> struct hash<unity::connection::handle>
107-{
108- std::size_t operator()(unity::connection::handle const& h) const
109- {
110- return std::hash<uint64_t>()(h);
111- }
112-};
113-}
114-
115-namespace unity
116-{
117-namespace connection
118-{
119+#include "ActionHandle.h"
120+
121+namespace unity
122+{
123+namespace connection
124+{
125+typedef unity::action::handle handle;
126
127 class Wrapper
128 {
129
130=== modified file 'launcher/DeviceLauncherSection.cpp'
131--- launcher/DeviceLauncherSection.cpp 2013-03-27 19:53:00 +0000
132+++ launcher/DeviceLauncherSection.cpp 2013-10-07 17:26:52 +0000
133@@ -19,8 +19,9 @@
134
135 #include "DeviceLauncherSection.h"
136 #include "DeviceNotificationDisplayImp.h"
137-#include "DevicesSettings.h"
138+#include "DevicesSettingsImp.h"
139 #include "VolumeImp.h"
140+#include "VolumeMonitorWrapper.h"
141 #include "unity-shared/GnomeFileManager.h"
142
143 namespace unity
144@@ -28,12 +29,13 @@
145 namespace launcher
146 {
147
148-DeviceLauncherSection::DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor,
149- DevicesSettings::Ptr devices_settings)
150- : monitor_(volume_monitor)
151- , devices_settings_(devices_settings)
152+DeviceLauncherSection::DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr const& vm,
153+ DevicesSettings::Ptr const& ds,
154+ DeviceNotificationDisplay::Ptr const& notify)
155+ : monitor_(vm ? vm : std::make_shared<VolumeMonitorWrapper>())
156+ , devices_settings_(ds ? ds : std::make_shared<DevicesSettingsImp>())
157 , file_manager_(GnomeFileManager::Get())
158- , device_notification_display_(std::make_shared<DeviceNotificationDisplayImp>())
159+ , device_notification_display_(notify ? notify : std::make_shared<DeviceNotificationDisplayImp>())
160 {
161 monitor_->volume_added.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded));
162 monitor_->volume_removed.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved));
163@@ -43,7 +45,7 @@
164
165 void DeviceLauncherSection::PopulateEntries()
166 {
167- for (auto volume : monitor_->GetVolumes())
168+ for (auto const& volume : monitor_->GetVolumes())
169 TryToCreateAndAddIcon(volume);
170 }
171
172@@ -57,8 +59,8 @@
173 if (map_.find(volume) != map_.end())
174 return;
175
176- auto vol = std::make_shared<VolumeImp>(volume, file_manager_, device_notification_display_);
177- VolumeLauncherIcon::Ptr icon(new VolumeLauncherIcon(vol, devices_settings_));
178+ auto vol = std::make_shared<VolumeImp>(volume);
179+ VolumeLauncherIcon::Ptr icon(new VolumeLauncherIcon(vol, devices_settings_, device_notification_display_, file_manager_));
180
181 map_[volume] = icon;
182 icon_added.emit(icon);
183
184=== modified file 'launcher/DeviceLauncherSection.h'
185--- launcher/DeviceLauncherSection.h 2013-03-21 16:22:34 +0000
186+++ launcher/DeviceLauncherSection.h 2013-10-07 17:26:52 +0000
187@@ -37,8 +37,9 @@
188 class DeviceLauncherSection : public sigc::trackable
189 {
190 public:
191- DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor,
192- DevicesSettings::Ptr devices_settings);
193+ DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr const& volume_monitor = nullptr,
194+ DevicesSettings::Ptr const& devices_settings = nullptr,
195+ DeviceNotificationDisplay::Ptr const& notifications = nullptr);
196
197 std::vector<VolumeLauncherIcon::Ptr> GetIcons() const;
198
199
200=== modified file 'launcher/LauncherController.cpp'
201--- launcher/LauncherController.cpp 2013-09-24 20:18:42 +0000
202+++ launcher/LauncherController.cpp 2013-10-07 17:26:52 +0000
203@@ -108,7 +108,6 @@
204 : parent_(parent)
205 , model_(std::make_shared<LauncherModel>())
206 , xdnd_manager_(xdnd_manager)
207- , device_section_(std::make_shared<VolumeMonitorWrapper>(), std::make_shared<DevicesSettingsImp>())
208 , expo_icon_(new ExpoLauncherIcon())
209 , desktop_icon_(new DesktopLauncherIcon())
210 , edge_barriers_(edge_barriers)
211
212=== modified file 'launcher/LauncherControllerPrivate.h'
213--- launcher/LauncherControllerPrivate.h 2013-09-24 20:18:42 +0000
214+++ launcher/LauncherControllerPrivate.h 2013-10-07 17:26:52 +0000
215@@ -28,7 +28,6 @@
216
217 #include "AbstractLauncherIcon.h"
218 #include "DeviceLauncherSection.h"
219-#include "DevicesSettingsImp.h"
220 #ifdef USE_X11
221 #include "EdgeBarrierController.h"
222 #endif
223@@ -39,7 +38,6 @@
224 #include "LauncherModel.h"
225 #include "SoftwareCenterLauncherIcon.h"
226 #include "unity-shared/UBusWrapper.h"
227-#include "VolumeMonitorWrapper.h"
228 #include "XdndManager.h"
229
230 namespace unity
231
232=== modified file 'launcher/Volume.h'
233--- launcher/Volume.h 2013-05-17 22:53:57 +0000
234+++ launcher/Volume.h 2013-10-07 17:26:52 +0000
235@@ -44,18 +44,21 @@
236 virtual std::string GetName() const = 0;
237 virtual std::string GetIconName() const = 0;
238 virtual std::string GetIdentifier() const = 0;
239+ virtual std::string GetUri() const = 0;
240 virtual bool HasSiblings() const = 0;
241 virtual bool IsMounted() const = 0;
242- virtual bool IsOpened() const = 0;
243
244- virtual void EjectAndShowNotification() = 0;
245- virtual void MountAndOpenInFileManager(uint64_t timestamp = 0) = 0;
246+ virtual void Eject() = 0;
247+ virtual void Mount() = 0;
248 virtual void StopDrive() = 0;
249 virtual void Unmount() = 0;
250
251 sigc::signal<void> changed;
252 sigc::signal<void> removed;
253- sigc::signal<void, bool> opened;
254+ sigc::signal<void> mounted;
255+ sigc::signal<void> unmounted;
256+ sigc::signal<void> ejected;
257+ sigc::signal<void> stopped;
258
259 private:
260 Volume(Volume const&) = delete;
261
262=== modified file 'launcher/VolumeImp.cpp'
263--- launcher/VolumeImp.cpp 2013-05-17 22:53:57 +0000
264+++ launcher/VolumeImp.cpp 2013-10-07 17:26:52 +0000
265@@ -35,16 +35,9 @@
266 class VolumeImp::Impl : public sigc::trackable
267 {
268 public:
269- Impl(glib::Object<GVolume> const& volume,
270- FileManager::Ptr const& file_manager,
271- DeviceNotificationDisplay::Ptr const& device_notification_display,
272- VolumeImp* parent)
273+ Impl(glib::Object<GVolume> const& volume, VolumeImp* parent)
274 : parent_(parent)
275- , opened_(false)
276- , open_timestamp_(0)
277 , volume_(volume)
278- , file_manager_(file_manager)
279- , device_notification_display_(device_notification_display)
280 {
281 signal_volume_changed_.Connect(volume_, "changed", [this] (GVolume*) {
282 parent_->changed.emit();
283@@ -53,19 +46,6 @@
284 signal_volume_removed_.Connect(volume_, "removed", [this] (GVolume*) {
285 parent_->removed.emit();
286 });
287-
288- file_manager_->locations_changed.connect(sigc::mem_fun(this, &Impl::OnLocationChanged));
289- }
290-
291- void OnLocationChanged()
292- {
293- bool opened = file_manager_->IsPrefixOpened(GetUri());
294-
295- if (opened_ != opened)
296- {
297- opened_ = opened;
298- parent_->opened.emit(opened_);
299- }
300 }
301
302 bool CanBeEjected() const
303@@ -126,67 +106,29 @@
304 return static_cast<bool>(mount);
305 }
306
307- bool IsOpened() const
308- {
309- return opened_;
310- }
311-
312- void EjectAndShowNotification()
313+ void Eject()
314 {
315 if (!CanBeEjected())
316 return;
317
318 glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(nullptr));
319
320- g_volume_eject_with_operation(volume_,
321- (GMountUnmountFlags)0,
322- mount_op,
323- cancellable_,
324- (GAsyncReadyCallback)OnEjectReady,
325- this);
326- }
327-
328- static void OnEjectReady(GObject* object, GAsyncResult* result, Impl* self)
329- {
330- if (g_volume_eject_with_operation_finish(self->volume_, result, nullptr))
331- {
332- self->device_notification_display_->Display(self->GetIconName(), self->GetName());
333- }
334- }
335-
336- void MountAndOpenInFileManager(uint64_t timestamp)
337- {
338- open_timestamp_ = timestamp;
339-
340- if (!IsMounted())
341- MountAndOnFinishOpenInFileManager();
342- else
343- OpenInFileManager();
344- }
345-
346- void MountAndOnFinishOpenInFileManager()
347+ g_volume_eject_with_operation(volume_, G_MOUNT_UNMOUNT_NONE, mount_op, cancellable_,
348+ [] (GObject* object, GAsyncResult* res, gpointer data) {
349+ if (g_volume_eject_with_operation_finish(G_VOLUME(object), res, nullptr))
350+ static_cast<Impl*>(data)->parent_->ejected.emit();
351+ }, this);
352+ }
353+
354+ void Mount()
355 {
356 glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(nullptr));
357
358- g_volume_mount(volume_,
359- (GMountMountFlags) 0,
360- mount_op,
361- cancellable_,
362- (GAsyncReadyCallback) &Impl::OnMountFinish,
363- this);
364- }
365-
366- static void OnMountFinish(GObject* object,
367- GAsyncResult* result,
368- Impl* self)
369- {
370- if (g_volume_mount_finish(self->volume_, result, nullptr))
371- self->OpenInFileManager();
372- }
373-
374- void OpenInFileManager()
375- {
376- file_manager_->OpenActiveChild(GetUri(), open_timestamp_);
377+ g_volume_mount(volume_, G_MOUNT_MOUNT_NONE, mount_op, cancellable_,
378+ [] (GObject* object, GAsyncResult* res, gpointer data) {
379+ if (g_volume_mount_finish(G_VOLUME(object), res, nullptr))
380+ static_cast<Impl*>(data)->parent_->mounted.emit();
381+ }, this);
382 }
383
384 std::string GetUri() const
385@@ -212,10 +154,11 @@
386 glib::Object<GDrive> drive(g_volume_get_drive(volume_));
387 glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(NULL));
388
389- g_drive_stop(drive,
390- (GMountUnmountFlags)0,
391- mount_op,
392- cancellable_, nullptr, nullptr);
393+ g_drive_stop(drive, G_MOUNT_UNMOUNT_NONE, mount_op, cancellable_,
394+ [] (GObject* object, GAsyncResult* res, gpointer data) {
395+ if (g_drive_stop_finish(G_DRIVE(object), res, nullptr))
396+ static_cast<Impl*>(data)->parent_->stopped.emit();
397+ }, this);
398 }
399
400 void Unmount()
401@@ -226,22 +169,16 @@
402 glib::Object<GMount> mount(g_volume_get_mount(volume_));
403 glib::Object<GMountOperation> op(gtk_mount_operation_new(nullptr));
404
405- g_mount_unmount_with_operation(mount, (GMountUnmountFlags) 0, op, cancellable_,
406- &VolumeImp::Impl::FinishUmount, nullptr);
407- }
408-
409- static void FinishUmount(GObject* object, GAsyncResult* res, gpointer)
410- {
411- g_mount_unmount_with_operation_finish(G_MOUNT(object), res, nullptr);
412+ g_mount_unmount_with_operation(mount, G_MOUNT_UNMOUNT_NONE, op, cancellable_,
413+ [] (GObject* object, GAsyncResult* res, gpointer data) {
414+ if (g_mount_unmount_with_operation_finish(G_MOUNT(object), res, nullptr))
415+ static_cast<Impl*>(data)->parent_->unmounted.emit();
416+ }, this);
417 }
418
419 VolumeImp* parent_;
420- bool opened_;
421- uint64_t open_timestamp_;
422 glib::Cancellable cancellable_;
423 glib::Object<GVolume> volume_;
424- FileManager::Ptr file_manager_;
425- DeviceNotificationDisplay::Ptr device_notification_display_;
426
427 glib::Signal<void, GVolume*> signal_volume_changed_;
428 glib::Signal<void, GVolume*> signal_volume_removed_;
429@@ -251,10 +188,8 @@
430 // End private implementation
431 //
432
433-VolumeImp::VolumeImp(glib::Object<GVolume> const& volume,
434- FileManager::Ptr const& file_manager,
435- DeviceNotificationDisplay::Ptr const& device_notification_display)
436- : pimpl(new Impl(volume, file_manager, device_notification_display, this))
437+VolumeImp::VolumeImp(glib::Object<GVolume> const& volume)
438+ : pimpl(new Impl(volume, this))
439 {}
440
441 VolumeImp::~VolumeImp()
442@@ -290,6 +225,11 @@
443 return pimpl->GetIdentifier();
444 }
445
446+std::string VolumeImp::GetUri() const
447+{
448+ return pimpl->GetUri();
449+}
450+
451 bool VolumeImp::HasSiblings() const
452 {
453 return pimpl->HasSiblings();
454@@ -300,19 +240,14 @@
455 return pimpl->IsMounted();
456 }
457
458-bool VolumeImp::IsOpened() const
459-{
460- return pimpl->IsOpened();
461-}
462-
463-void VolumeImp::MountAndOpenInFileManager(uint64_t timestamp)
464-{
465- pimpl->MountAndOpenInFileManager(timestamp);
466-}
467-
468-void VolumeImp::EjectAndShowNotification()
469-{
470- pimpl->EjectAndShowNotification();
471+void VolumeImp::Mount()
472+{
473+ pimpl->Mount();
474+}
475+
476+void VolumeImp::Eject()
477+{
478+ pimpl->Eject();
479 }
480
481 void VolumeImp::StopDrive()
482
483=== modified file 'launcher/VolumeImp.h'
484--- launcher/VolumeImp.h 2013-05-17 22:53:57 +0000
485+++ launcher/VolumeImp.h 2013-10-07 17:26:52 +0000
486@@ -26,7 +26,6 @@
487
488 #include "DeviceNotificationDisplay.h"
489 #include "Volume.h"
490-#include "unity-shared/FileManager.h"
491
492 namespace unity
493 {
494@@ -38,9 +37,7 @@
495 public:
496 typedef std::shared_ptr<VolumeImp> Ptr;
497
498- VolumeImp(glib::Object<GVolume> const& volume,
499- FileManager::Ptr const& file_manager,
500- DeviceNotificationDisplay::Ptr const& device_notification_display);
501+ VolumeImp(glib::Object<GVolume> const&);
502 virtual ~VolumeImp();
503
504 virtual bool CanBeEjected() const;
505@@ -49,12 +46,12 @@
506 virtual std::string GetName() const;
507 virtual std::string GetIconName() const;
508 virtual std::string GetIdentifier() const;
509+ virtual std::string GetUri() const;
510 virtual bool HasSiblings() const;
511 virtual bool IsMounted() const;
512- virtual bool IsOpened() const;
513
514- virtual void EjectAndShowNotification();
515- virtual void MountAndOpenInFileManager(uint64_t timestamp);
516+ virtual void Eject();
517+ virtual void Mount();
518 virtual void StopDrive();
519 virtual void Unmount();
520
521
522=== modified file 'launcher/VolumeLauncherIcon.cpp'
523--- launcher/VolumeLauncherIcon.cpp 2013-08-05 13:59:08 +0000
524+++ launcher/VolumeLauncherIcon.cpp 2013-10-07 17:26:52 +0000
525@@ -25,8 +25,6 @@
526 #include <UnityCore/ConnectionManager.h>
527 #include <UnityCore/GLibSignal.h>
528
529-#include "DevicesSettings.h"
530-#include "Volume.h"
531 #include "VolumeLauncherIcon.h"
532 #include "FavoriteStore.h"
533
534@@ -34,12 +32,7 @@
535 {
536 namespace launcher
537 {
538-DECLARE_LOGGER(logger, "unity.launcher.icon");
539-namespace
540-{
541-const unsigned int volume_changed_timeout = 500;
542-
543-}
544+DECLARE_LOGGER(logger, "unity.launcher.icon.volume");
545
546 //
547 // Start private implementation
548@@ -51,10 +44,14 @@
549
550 Impl(Volume::Ptr const& volume,
551 DevicesSettings::Ptr const& devices_settings,
552+ DeviceNotificationDisplay::Ptr const& notification,
553+ FileManager::Ptr const& fm,
554 VolumeLauncherIcon* parent)
555 : parent_(parent)
556 , volume_(volume)
557 , devices_settings_(devices_settings)
558+ , notification_(notification)
559+ , file_manager_(fm)
560 {
561 UpdateIcon();
562 UpdateVisibility();
563@@ -65,7 +62,7 @@
564 {
565 parent_->tooltip_text = volume_->GetName();
566 parent_->icon_name = volume_->GetIconName();
567- parent_->SetQuirk(Quirk::RUNNING, volume_->IsOpened());
568+ parent_->SetQuirk(Quirk::RUNNING, file_manager_->IsPrefixOpened(volume_->GetUri()));
569 }
570
571 void UpdateVisibility()
572@@ -85,7 +82,7 @@
573 connections_.Add(volume_->changed.connect(sigc::mem_fun(this, &Impl::OnVolumeChanged)));
574 connections_.Add(volume_->removed.connect(sigc::mem_fun(this, &Impl::OnVolumeRemoved)));
575 connections_.Add(devices_settings_->changed.connect(sigc::mem_fun(this, &Impl::OnSettingsChanged)));
576- connections_.Add(volume_->opened.connect(sigc::hide(sigc::mem_fun(this, &Impl::UpdateIcon))));
577+ connections_.Add(file_manager_->locations_changed.connect(sigc::mem_fun(this, &Impl::UpdateIcon)));
578 }
579
580 void OnVolumeChanged()
581@@ -114,7 +111,16 @@
582
583 void EjectAndShowNotification()
584 {
585- return volume_->EjectAndShowNotification();
586+ if (!CanEject())
587+ return;
588+
589+ auto conn = std::make_shared<sigc::connection>();
590+ *conn = volume_->ejected.connect([this, conn] {
591+ notification_->Display(volume_->GetIconName(), volume_->GetName());
592+ conn->disconnect();
593+ });
594+ connections_.Add(*conn);
595+ volume_->Eject();
596 }
597
598 bool CanStop() const
599@@ -127,10 +133,22 @@
600 volume_->StopDrive();
601 }
602
603- void ActivateLauncherIcon(ActionArg arg)
604+ void OpenInFileManager(uint64_t timestamp)
605 {
606- parent_->SimpleLauncherIcon::ActivateLauncherIcon(arg);
607- volume_->MountAndOpenInFileManager(arg.timestamp);
608+ if (!volume_->IsMounted())
609+ {
610+ auto conn = std::make_shared<sigc::connection>();
611+ *conn = volume_->mounted.connect([this, conn, timestamp] {
612+ file_manager_->OpenActiveChild(volume_->GetUri(), timestamp);
613+ conn->disconnect();
614+ });
615+ connections_.Add(*conn);
616+ volume_->Mount();
617+ }
618+ else
619+ {
620+ file_manager_->OpenActiveChild(volume_->GetUri(), timestamp);
621+ }
622 }
623
624 MenuItemsVector GetMenus()
625@@ -161,9 +179,9 @@
626 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
627
628 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {
629- auto const& identifier = volume_->GetIdentifier();
630- parent_->UnStick();
631- devices_settings_->TryToBlacklist(identifier);
632+ auto const& identifier = volume_->GetIdentifier();
633+ parent_->UnStick();
634+ devices_settings_->TryToBlacklist(identifier);
635 }));
636
637 menu.push_back(menu_item);
638@@ -189,7 +207,7 @@
639 dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, true);
640
641 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, unsigned timestamp) {
642- volume_->MountAndOpenInFileManager(timestamp);
643+ OpenInFileManager(timestamp);
644 }));
645
646 menu.push_back(menu_item);
647@@ -204,7 +222,7 @@
648 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
649
650 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, unsigned timestamp) {
651- volume_->MountAndOpenInFileManager(timestamp);
652+ OpenInFileManager(timestamp);
653 }));
654
655 menu.push_back(menu_item);
656@@ -222,7 +240,7 @@
657 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
658
659 gsignals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, int) {
660- volume_->EjectAndShowNotification();
661+ EjectAndShowNotification();
662 }));
663
664 menu.push_back(menu_item);
665@@ -278,6 +296,8 @@
666 bool keep_in_launcher_;
667 Volume::Ptr volume_;
668 DevicesSettings::Ptr devices_settings_;
669+ DeviceNotificationDisplay::Ptr notification_;
670+ FileManager::Ptr file_manager_;
671
672 glib::SignalManager gsignals_;
673 connection::Manager connections_;
674@@ -288,9 +308,11 @@
675 //
676
677 VolumeLauncherIcon::VolumeLauncherIcon(Volume::Ptr const& volume,
678- DevicesSettings::Ptr const& devices_settings)
679+ DevicesSettings::Ptr const& devices_settings,
680+ DeviceNotificationDisplay::Ptr const& notification,
681+ FileManager::Ptr const& fm)
682 : SimpleLauncherIcon(IconType::DEVICE)
683- , pimpl_(new Impl(volume, devices_settings, this))
684+ , pimpl_(new Impl(volume, devices_settings, notification, fm, this))
685 {}
686
687 VolumeLauncherIcon::~VolumeLauncherIcon()
688@@ -326,7 +348,8 @@
689
690 void VolumeLauncherIcon::ActivateLauncherIcon(ActionArg arg)
691 {
692- pimpl_->ActivateLauncherIcon(arg);
693+ SimpleLauncherIcon::ActivateLauncherIcon(arg);
694+ pimpl_->OpenInFileManager(arg.timestamp);
695 }
696
697 AbstractLauncherIcon::MenuItemsVector VolumeLauncherIcon::GetMenus()
698
699=== modified file 'launcher/VolumeLauncherIcon.h'
700--- launcher/VolumeLauncherIcon.h 2013-08-05 13:59:08 +0000
701+++ launcher/VolumeLauncherIcon.h 2013-10-07 17:26:52 +0000
702@@ -23,7 +23,9 @@
703
704 #include "Volume.h"
705 #include "DevicesSettings.h"
706+#include "DeviceNotificationDisplay.h"
707 #include "SimpleLauncherIcon.h"
708+#include "unity-shared/FileManager.h"
709
710 namespace unity
711 {
712@@ -35,8 +37,8 @@
713 public:
714 typedef nux::ObjectPtr<VolumeLauncherIcon> Ptr;
715
716- VolumeLauncherIcon(Volume::Ptr const& volume,
717- DevicesSettings::Ptr const& devices_settings);
718+ VolumeLauncherIcon(Volume::Ptr const&, DevicesSettings::Ptr const&,
719+ DeviceNotificationDisplay::Ptr const&, FileManager::Ptr const&);
720 virtual ~VolumeLauncherIcon();
721
722 virtual void AboutToRemove();
723@@ -58,7 +60,7 @@
724
725 private:
726 class Impl;
727- std::shared_ptr<Impl> pimpl_;
728+ std::unique_ptr<Impl> pimpl_;
729 };
730
731 }
732
733=== modified file 'tests/CMakeLists.txt'
734--- tests/CMakeLists.txt 2013-09-26 21:20:47 +0000
735+++ tests/CMakeLists.txt 2013-10-07 17:26:52 +0000
736@@ -129,6 +129,7 @@
737 set (GTEST_XLESS_SOURCES
738 test_main_xless.cpp
739 mock-application.cpp
740+ test_action_handle.cpp
741 test_abstract_interface_generator.cpp
742 test_animation_utils.cpp
743 test_connection_manager.cpp
744@@ -164,6 +165,7 @@
745 test_time_util.cpp
746 test_ubus.cpp
747 test_unityshell_private.cpp
748+ test_volume_imp.cpp
749 ${UNITY_SRC}/UnityshellPrivate.cpp
750 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp
751 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp
752@@ -174,6 +176,7 @@
753
754 set (GTEST_XLESS_LIBS
755 gtest
756+ test-libs-c
757 unity-shared
758 unity-shared-standalone
759 launcher-lib
760@@ -309,7 +312,6 @@
761 test_unity_settings.cpp
762 test_unity_window_style.cpp
763 test_unity_window_view.cpp
764- test_volume_imp.cpp
765 test_volume_launcher_icon.cpp
766 test_window_buttons.cpp
767 test_xdnd_manager_imp.cpp
768@@ -321,14 +323,14 @@
769
770 # Build plain C files separately so they don't try to include the
771 # C++ pch.
772- add_library(test-gtest-plainc STATIC
773+ add_library(test-libs-c STATIC
774 bamf-mock-application.c
775 bamf-mock-window.c
776 gmockmount.c
777 gmockvolume.c
778 )
779 target_link_libraries(test-gtest
780- test-gtest-plainc
781+ test-libs-c
782 gtest
783 gmock
784 unity-shared
785
786=== modified file 'tests/gmockvolume.c'
787--- tests/gmockvolume.c 2012-11-06 18:19:09 +0000
788+++ tests/gmockvolume.c 2013-10-07 17:26:52 +0000
789@@ -233,8 +233,8 @@
790 mock_volume->last_mount_had_mount_op = (mount_operation != NULL);
791 g_mock_volume_set_mount(mock_volume, G_MOUNT(g_mock_mount_new()));
792
793- callback(NULL,
794- G_ASYNC_RESULT (g_simple_async_result_new (NULL, NULL, NULL, NULL)),
795+ callback(G_OBJECT (volume),
796+ G_ASYNC_RESULT (g_simple_async_result_new (G_OBJECT (volume), callback, user_data, NULL)),
797 user_data);
798 }
799
800@@ -253,10 +253,10 @@
801 GAsyncReadyCallback callback,
802 gpointer user_data)
803 {
804-
805- callback(NULL,
806- G_ASYNC_RESULT (g_simple_async_result_new (NULL, NULL, NULL, NULL)),
807- user_data);}
808+ callback(G_OBJECT (volume),
809+ G_ASYNC_RESULT (g_simple_async_result_new (G_OBJECT (volume), callback, user_data, NULL)),
810+ user_data);
811+}
812
813 static gboolean
814 g_mock_volume_eject_finish (GVolume *volume,
815
816=== added file 'tests/test_action_handle.cpp'
817--- tests/test_action_handle.cpp 1970-01-01 00:00:00 +0000
818+++ tests/test_action_handle.cpp 2013-10-07 17:26:52 +0000
819@@ -0,0 +1,109 @@
820+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
821+/*
822+ * Copyright (C) 2013 Canonical Ltd
823+ *
824+ * This program is free software: you can redistribute it and/or modify
825+ * it under the terms of the GNU General Public License version 3 as
826+ * published by the Free Software Foundation.
827+ *
828+ * This program is distributed in the hope that it will be useful,
829+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
830+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
831+ * GNU General Public License for more details.
832+ *
833+ * You should have received a copy of the GNU General Public License
834+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
835+ *
836+ * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
837+ */
838+
839+#include <gmock/gmock.h>
840+#include <UnityCore/ConnectionManager.h>
841+#include <glib.h>
842+
843+using namespace unity;
844+
845+namespace
846+{
847+
848+TEST(TestActionHandle, Initialization)
849+{
850+ action::handle handle;
851+ EXPECT_EQ(handle, 0);
852+
853+ uint64_t val = g_random_int();
854+ action::handle random = val;
855+ EXPECT_EQ(random, val);
856+}
857+
858+TEST(TestActionHandle, Assignment)
859+{
860+ action::handle handle;
861+ ASSERT_EQ(handle, 0);
862+
863+ uint64_t val = g_random_int();
864+ handle = val;
865+ EXPECT_EQ(handle, val);
866+}
867+
868+TEST(TestActionHandle, CastToScalarType)
869+{
870+ action::handle handle = 5;
871+ ASSERT_EQ(handle, 5);
872+
873+ int int_handle = handle;
874+ EXPECT_EQ(int_handle, 5);
875+
876+ unsigned uint_handle = handle;
877+ EXPECT_EQ(uint_handle, 5);
878+}
879+
880+TEST(TestActionHandle, PrefixIncrementOperator)
881+{
882+ action::handle handle;
883+ ASSERT_EQ(handle, 0);
884+
885+ for (auto i = 1; i <= 10; ++i)
886+ {
887+ ASSERT_EQ(++handle, i);
888+ ASSERT_EQ(handle, i);
889+ }
890+}
891+
892+TEST(TestActionHandle, PostfixIncrementOperator)
893+{
894+ action::handle handle;
895+ ASSERT_EQ(handle, 0);
896+
897+ for (auto i = 1; i <= 10; ++i)
898+ {
899+ ASSERT_EQ(handle++, i-1);
900+ ASSERT_EQ(handle, i);
901+ }
902+}
903+
904+TEST(TestActionHandle, PrefixDecrementOperator)
905+{
906+ action::handle handle(10);
907+ ASSERT_EQ(handle, 10);
908+
909+ for (auto i = 10; i > 0; --i)
910+ {
911+ ASSERT_EQ(--handle, i-1);
912+ ASSERT_EQ(handle, i-1);
913+ }
914+}
915+
916+TEST(TestActionHandle, PostfixDecrementOperator)
917+{
918+ action::handle handle(10);
919+ ASSERT_EQ(handle, 10);
920+
921+ for (auto i = 10; i > 0; --i)
922+ {
923+ ASSERT_EQ(handle--, i);
924+ ASSERT_EQ(handle, i-1);
925+ }
926+}
927+
928+} // Namespace
929
930=== modified file 'tests/test_connection_manager.cpp'
931--- tests/test_connection_manager.cpp 2013-07-01 19:36:01 +0000
932+++ tests/test_connection_manager.cpp 2013-10-07 17:26:52 +0000
933@@ -25,87 +25,6 @@
934
935 namespace
936 {
937-
938-TEST(TestConnectionHandle, Initialization)
939-{
940- connection::handle handle;
941- EXPECT_EQ(handle, 0);
942-
943- uint64_t val = g_random_int();
944- connection::handle random = val;
945- EXPECT_EQ(random, val);
946-}
947-
948-TEST(TestConnectionHandle, Assignment)
949-{
950- connection::handle handle;
951- ASSERT_EQ(handle, 0);
952-
953- uint64_t val = g_random_int();
954- handle = val;
955- EXPECT_EQ(handle, val);
956-}
957-
958-TEST(TestConnectionHandle, CastToScalarType)
959-{
960- connection::handle handle = 5;
961- ASSERT_EQ(handle, 5);
962-
963- int int_handle = handle;
964- EXPECT_EQ(int_handle, 5);
965-
966- unsigned uint_handle = handle;
967- EXPECT_EQ(uint_handle, 5);
968-}
969-
970-TEST(TestConnectionHandle, PrefixIncrementOperator)
971-{
972- connection::handle handle;
973- ASSERT_EQ(handle, 0);
974-
975- for (auto i = 1; i <= 10; ++i)
976- {
977- ASSERT_EQ(++handle, i);
978- ASSERT_EQ(handle, i);
979- }
980-}
981-
982-TEST(TestConnectionHandle, PostfixIncrementOperator)
983-{
984- connection::handle handle;
985- ASSERT_EQ(handle, 0);
986-
987- for (auto i = 1; i <= 10; ++i)
988- {
989- ASSERT_EQ(handle++, i-1);
990- ASSERT_EQ(handle, i);
991- }
992-}
993-
994-TEST(TestConnectionHandle, PrefixDecrementOperator)
995-{
996- connection::handle handle(10);
997- ASSERT_EQ(handle, 10);
998-
999- for (auto i = 10; i > 0; --i)
1000- {
1001- ASSERT_EQ(--handle, i-1);
1002- ASSERT_EQ(handle, i-1);
1003- }
1004-}
1005-
1006-TEST(TestConnectionHandle, PostfixDecrementOperator)
1007-{
1008- connection::handle handle(10);
1009- ASSERT_EQ(handle, 10);
1010-
1011- for (auto i = 10; i > 0; --i)
1012- {
1013- ASSERT_EQ(handle--, i);
1014- ASSERT_EQ(handle, i-1);
1015- }
1016-}
1017-
1018 connection::handle global_handle = 0;
1019
1020 struct SignalerObject
1021
1022=== modified file 'tests/test_device_launcher_section.cpp'
1023--- tests/test_device_launcher_section.cpp 2013-07-10 01:01:02 +0000
1024+++ tests/test_device_launcher_section.cpp 2013-10-07 17:26:52 +0000
1025@@ -52,13 +52,15 @@
1026 struct TestDeviceLauncherSection : Test
1027 {
1028 TestDeviceLauncherSection()
1029- : monitor_(new MockVolumeMonitorWrapper)
1030- , devices_settings_(new NiceMock<MockDevicesSettings>())
1031- , section_(monitor_, devices_settings_)
1032+ : monitor_(std::make_shared<MockVolumeMonitorWrapper>())
1033+ , devices_settings_(std::make_shared<NiceMock<MockDevicesSettings>>())
1034+ , notifications_(std::make_shared<MockDeviceNotificationDisplay::Nice>())
1035+ , section_(monitor_, devices_settings_, notifications_)
1036 {}
1037
1038 MockVolumeMonitorWrapper::Ptr monitor_;
1039 DevicesSettings::Ptr devices_settings_;
1040+ DeviceNotificationDisplay::Ptr notifications_;
1041 DeviceLauncherSection section_;
1042 };
1043
1044
1045=== modified file 'tests/test_icon_loader.cpp'
1046--- tests/test_icon_loader.cpp 2013-09-18 20:11:56 +0000
1047+++ tests/test_icon_loader.cpp 2013-10-07 17:26:52 +0000
1048@@ -97,12 +97,12 @@
1049
1050 void TearDown() override
1051 {
1052- for (int handle : handles_)
1053+ for (auto handle : handles_)
1054 icon_loader.DisconnectHandle(handle);
1055 }
1056
1057 IconLoader& icon_loader;
1058- std::vector<int> handles_;
1059+ std::vector<IconLoader::Handle> handles_;
1060 };
1061
1062 TEST_F(TestIconLoader, TestGetDefault)
1063@@ -115,7 +115,7 @@
1064 {
1065 LoadResult load_result;
1066
1067- int handle = icon_loader.LoadFromIconName("python", -1, 48, sigc::mem_fun(load_result,
1068+ auto handle = icon_loader.LoadFromIconName("python", -1, 48, sigc::mem_fun(load_result,
1069 &LoadResult::IconLoaded));
1070 handles_.push_back(handle);
1071
1072@@ -129,7 +129,7 @@
1073 {
1074 LoadResult load_result;
1075
1076- int handle = icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'cmake'%3E,%20'ribbon':%20%3C'foo'%3E%7D", -1, 48, sigc::mem_fun(load_result,
1077+ auto handle = icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'cmake'%3E,%20'ribbon':%20%3C'foo'%3E%7D", -1, 48, sigc::mem_fun(load_result,
1078 &LoadResult::IconLoaded));
1079 handles_.push_back(handle);
1080
1081@@ -143,7 +143,7 @@
1082 {
1083 LoadResult load_result;
1084
1085- int handle = icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'cmake'%3E,%20'colorize-value':%20%3Cuint32%204278190335%3E%7D", -1, 48, sigc::mem_fun(load_result,
1086+ auto handle = icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'cmake'%3E,%20'colorize-value':%20%3Cuint32%204278190335%3E%7D", -1, 48, sigc::mem_fun(load_result,
1087 &LoadResult::IconLoaded));
1088 handles_.push_back(handle);
1089
1090@@ -155,7 +155,7 @@
1091 TEST_F(TestIconLoader, TestGetOneIconManyTimes)
1092 {
1093 std::vector<LoadResult> results;
1094- std::vector<int> handles;
1095+ std::vector<IconLoader::Handle> handles;
1096 int i, load_count;
1097
1098 // 100 times should be good
1099@@ -208,7 +208,7 @@
1100 TEST_F(TestIconLoader, TestCancelSome)
1101 {
1102 std::vector<LoadResult> results;
1103- std::vector<int> handles;
1104+ std::vector<IconLoader::Handle> handles;
1105 int i = 0;
1106 int icon_count;
1107
1108
1109=== modified file 'tests/test_launcher_controller.cpp'
1110--- tests/test_launcher_controller.cpp 2013-09-25 00:48:03 +0000
1111+++ tests/test_launcher_controller.cpp 2013-10-07 17:26:52 +0000
1112@@ -39,6 +39,7 @@
1113 #include "test_utils.h"
1114 #include "test_uscreen_mock.h"
1115 #include "test_mock_devices.h"
1116+#include "test_mock_filemanager.h"
1117 #include "mock-application.h"
1118
1119
1120@@ -178,7 +179,9 @@
1121
1122 MockVolumeLauncherIcon()
1123 : VolumeLauncherIcon(Volume::Ptr(volume_ = new NiceMock<MockVolume>()),
1124- std::make_shared<NiceMock<MockDevicesSettings>>())
1125+ std::make_shared<MockDevicesSettings::Nice>(),
1126+ std::make_shared<MockDeviceNotificationDisplay::Nice>(),
1127+ std::make_shared<MockFileManager::Nice>())
1128 , uuid_(std::to_string(g_random_int()))
1129 {
1130 ON_CALL(*volume_, GetIdentifier()).WillByDefault(Return(uuid_));
1131@@ -1266,7 +1269,7 @@
1132 EXPECT_CALL(*(device_icon->volume_), CanBeStopped())
1133 .WillRepeatedly(Return(true));
1134
1135- EXPECT_CALL(*(device_icon->volume_), EjectAndShowNotification());
1136+ EXPECT_CALL(*(device_icon->volume_), Eject());
1137 EXPECT_CALL(*(device_icon->volume_), StopDrive()).Times(0);
1138
1139 lc.launcher().remove_request.emit(device_icon);
1140@@ -1282,7 +1285,7 @@
1141 .WillRepeatedly(Return(true));
1142
1143 EXPECT_CALL(*(device_icon->volume_), StopDrive());
1144- EXPECT_CALL(*(device_icon->volume_), EjectAndShowNotification()).Times(0);
1145+ EXPECT_CALL(*(device_icon->volume_), Eject()).Times(0);
1146
1147 lc.launcher().remove_request.emit(device_icon);
1148 }
1149
1150=== modified file 'tests/test_mock_devices.h'
1151--- tests/test_mock_devices.h 2013-05-17 22:53:57 +0000
1152+++ tests/test_mock_devices.h 2013-10-07 17:26:52 +0000
1153@@ -34,6 +34,8 @@
1154
1155 namespace unity
1156 {
1157+namespace
1158+{
1159
1160 struct MockVolumeMonitorWrapper : public AbstractVolumeMonitorWrapper
1161 {
1162@@ -56,6 +58,7 @@
1163 struct MockDevicesSettings : DevicesSettings
1164 {
1165 typedef std::shared_ptr<MockDevicesSettings> Ptr;
1166+ typedef testing::NiceMock<MockDevicesSettings> Nice;
1167
1168 MOCK_CONST_METHOD1(IsABlacklistedDevice, bool(std::string const& uuid));
1169 MOCK_METHOD1(TryToBlacklist, void(std::string const& uuid));
1170@@ -70,27 +73,36 @@
1171 {}
1172 };
1173
1174-class MockVolume : public Volume
1175+struct MockVolume : Volume
1176 {
1177-public:
1178 typedef std::shared_ptr<MockVolume> Ptr;
1179+ typedef testing::NiceMock<MockVolume> Nice;
1180
1181 MOCK_CONST_METHOD0(CanBeRemoved, bool(void));
1182 MOCK_CONST_METHOD0(CanBeStopped, bool(void));
1183 MOCK_CONST_METHOD0(GetName, std::string(void));
1184 MOCK_CONST_METHOD0(GetIconName, std::string(void));
1185 MOCK_CONST_METHOD0(GetIdentifier, std::string(void));
1186+ MOCK_CONST_METHOD0(GetUri, std::string(void));
1187 MOCK_CONST_METHOD0(HasSiblings, bool(void));
1188 MOCK_CONST_METHOD0(CanBeEjected, bool(void));
1189 MOCK_CONST_METHOD0(IsMounted, bool(void));
1190- MOCK_CONST_METHOD0(IsOpened, bool(void));
1191
1192- MOCK_METHOD0(EjectAndShowNotification, void(void));
1193- MOCK_METHOD1(MountAndOpenInFileManager, void(uint64_t));
1194+ MOCK_METHOD0(Eject, void());
1195+ MOCK_METHOD0(Mount, void());
1196 MOCK_METHOD0(StopDrive, void(void));
1197 MOCK_METHOD0(Unmount, void(void));
1198 };
1199
1200-}
1201+struct MockDeviceNotificationDisplay : DeviceNotificationDisplay
1202+{
1203+ typedef std::shared_ptr<MockDeviceNotificationDisplay> Ptr;
1204+ typedef testing::NiceMock<MockDeviceNotificationDisplay> Nice;
1205+
1206+ MOCK_METHOD2(Display, void(std::string const& icon_name, std::string const& volume_name));
1207+};
1208+
1209+} // anonymous namespace
1210+} // unity namespace
1211
1212 #endif
1213
1214=== modified file 'tests/test_mock_filemanager.h'
1215--- tests/test_mock_filemanager.h 2013-09-05 16:22:56 +0000
1216+++ tests/test_mock_filemanager.h 2013-10-07 17:26:52 +0000
1217@@ -20,6 +20,7 @@
1218 #ifndef TEST_MOCK_FILEMANAGER_H
1219 #define TEST_MOCK_FILEMANAGER_H
1220
1221+#include <gmock/gmock.h>
1222 #include "FileManager.h"
1223
1224 namespace unity
1225@@ -28,6 +29,7 @@
1226 struct MockFileManager : FileManager
1227 {
1228 typedef std::shared_ptr<MockFileManager> Ptr;
1229+ typedef testing::NiceMock<MockFileManager> Nice;
1230
1231 MOCK_METHOD2(Open, void(std::string const& uri, uint64_t time));
1232 MOCK_METHOD2(OpenActiveChild, void(std::string const& uri, uint64_t time));
1233
1234=== modified file 'tests/test_volume_imp.cpp'
1235--- tests/test_volume_imp.cpp 2013-05-17 22:53:57 +0000
1236+++ tests/test_volume_imp.cpp 2013-10-07 17:26:52 +0000
1237@@ -25,46 +25,27 @@
1238 #include "gmockmount.h"
1239 #include "gmockvolume.h"
1240 #include "launcher/VolumeImp.h"
1241-#include "test_utils.h"
1242-#include "test_mock_filemanager.h"
1243 using namespace unity;
1244
1245 namespace
1246 {
1247-
1248-class MockDeviceNotificationDisplay : public launcher::DeviceNotificationDisplay
1249-{
1250-public:
1251- typedef std::shared_ptr<MockDeviceNotificationDisplay> Ptr;
1252-
1253- MOCK_METHOD2(Display, void(std::string const& icon_name, std::string const& device_name));
1254-};
1255-
1256-class TestVolumeImp : public Test
1257-{
1258-public:
1259- void SetUp()
1260- {
1261- gvolume_ = g_mock_volume_new();
1262- file_manager_.reset(new NiceMock<MockFileManager>);
1263- device_notification_display_.reset(new MockDeviceNotificationDisplay);
1264- volume_.reset(new launcher::VolumeImp(glib::Object<GVolume>(G_VOLUME(gvolume_.RawPtr()), glib::AddRef()),
1265- file_manager_, device_notification_display_));
1266- }
1267+struct TestVolumeImp : Test
1268+{
1269+ TestVolumeImp()
1270+ : gvolume_(g_mock_volume_new())
1271+ , volume_(std::make_shared<launcher::VolumeImp>(glib::object_cast<GVolume>(gvolume_)))
1272+ {}
1273
1274 glib::Object<GMockVolume> gvolume_;
1275- MockFileManager::Ptr file_manager_;
1276- MockDeviceNotificationDisplay::Ptr device_notification_display_;
1277 launcher::VolumeImp::Ptr volume_;
1278 };
1279
1280-TEST_F(TestVolumeImp, TestCtor)
1281+TEST_F(TestVolumeImp, Ctor)
1282 {
1283 EXPECT_FALSE(volume_->IsMounted());
1284- EXPECT_FALSE(volume_->IsOpened());
1285 }
1286
1287-TEST_F(TestVolumeImp, TestCanBeEjected)
1288+TEST_F(TestVolumeImp, CanBeEjected)
1289 {
1290 EXPECT_FALSE(volume_->CanBeEjected());
1291
1292@@ -72,7 +53,7 @@
1293 EXPECT_TRUE(volume_->CanBeEjected());
1294 }
1295
1296-TEST_F(TestVolumeImp, TestGetName)
1297+TEST_F(TestVolumeImp, GetName)
1298 {
1299 std::string const volume_name("Test Device");
1300
1301@@ -82,7 +63,7 @@
1302 EXPECT_EQ(volume_->GetName(), volume_name);
1303 }
1304
1305-TEST_F(TestVolumeImp, TestGetIconName)
1306+TEST_F(TestVolumeImp, GetIconName)
1307 {
1308 std::string const icon_name("gnome-dev-cdrom");
1309
1310@@ -90,7 +71,7 @@
1311 EXPECT_EQ(volume_->GetIconName(), icon_name);
1312 }
1313
1314-TEST_F(TestVolumeImp, TestGetIdentifier)
1315+TEST_F(TestVolumeImp, GetIdentifier)
1316 {
1317 std::string const uuid = "uuid";
1318 std::string const label = "label";
1319@@ -101,7 +82,12 @@
1320 EXPECT_EQ(volume_->GetIdentifier(), uuid + "-" + label);
1321 }
1322
1323-TEST_F(TestVolumeImp, TestIsMounted)
1324+TEST_F(TestVolumeImp, GetUriUnMounted)
1325+{
1326+ EXPECT_TRUE(volume_->GetUri().empty());
1327+}
1328+
1329+TEST_F(TestVolumeImp, IsMounted)
1330 {
1331 g_mock_volume_set_mount(gvolume_, nullptr);
1332 ASSERT_FALSE(volume_->IsMounted());
1333@@ -110,65 +96,26 @@
1334 EXPECT_TRUE(volume_->IsMounted());
1335 }
1336
1337-TEST_F(TestVolumeImp, TestIsOpened)
1338-{
1339- volume_->MountAndOpenInFileManager(0);
1340-
1341- EXPECT_CALL(*file_manager_, IsPrefixOpened(ROOT_FILE_URI));
1342- ON_CALL(*file_manager_, IsPrefixOpened(_)).WillByDefault(Return(true));
1343- file_manager_->locations_changed.emit();
1344- EXPECT_TRUE(volume_->IsOpened());
1345-
1346- EXPECT_CALL(*file_manager_, IsPrefixOpened(ROOT_FILE_URI));
1347- ON_CALL(*file_manager_, IsPrefixOpened(_)).WillByDefault(Return(false));
1348- file_manager_->locations_changed.emit();
1349- EXPECT_FALSE(volume_->IsOpened());
1350-}
1351-
1352-TEST_F(TestVolumeImp, TestIsOpenedSignal)
1353-{
1354- ON_CALL(*file_manager_, IsPrefixOpened(_)).WillByDefault(Return(false));
1355-
1356- bool opened = false;
1357- volume_->opened.connect([&opened] (bool value) { opened = value; });
1358- file_manager_->locations_changed.emit();
1359-
1360- ASSERT_FALSE(opened);
1361-
1362- ON_CALL(*file_manager_, IsPrefixOpened(_)).WillByDefault(Return(true));
1363- file_manager_->locations_changed.emit();
1364- EXPECT_TRUE(opened);
1365-}
1366-
1367-TEST_F(TestVolumeImp, TestFilemanagerSignalDisconnection)
1368-{
1369- ASSERT_FALSE(file_manager_->locations_changed.empty());
1370- volume_.reset();
1371-
1372- EXPECT_TRUE(file_manager_->locations_changed.empty());
1373-}
1374-
1375-TEST_F(TestVolumeImp, TestEjectAndShowNotification)
1376-{
1377+TEST_F(TestVolumeImp, Eject)
1378+{
1379+ bool ejected = false;
1380 g_mock_volume_set_can_eject(gvolume_, TRUE);
1381-
1382- EXPECT_CALL(*device_notification_display_, Display(volume_->GetIconName(), volume_->GetName()))
1383- .Times(1);
1384-
1385- volume_->EjectAndShowNotification();
1386+ volume_->ejected.connect([&ejected] { ejected = true; });
1387+ volume_->Eject();
1388+ EXPECT_TRUE(ejected);
1389 }
1390
1391-TEST_F(TestVolumeImp, TestMountAndOpenInFileManager)
1392+TEST_F(TestVolumeImp, Mount)
1393 {
1394- uint64_t time = g_random_int();
1395- EXPECT_CALL(*file_manager_, OpenActiveChild(ROOT_FILE_URI, time));
1396-
1397- volume_->MountAndOpenInFileManager(time);
1398+ bool mounted = false;
1399+ volume_->mounted.connect([&mounted] { mounted = true; });
1400+ volume_->Mount();
1401 EXPECT_EQ(g_mock_volume_last_mount_had_mount_operation(gvolume_), TRUE);
1402 EXPECT_TRUE(volume_->IsMounted());
1403+ EXPECT_TRUE(mounted);
1404 }
1405
1406-TEST_F(TestVolumeImp, TestChangedSignal)
1407+TEST_F(TestVolumeImp, ChangedSignal)
1408 {
1409 bool callback_called = false;
1410 volume_->changed.connect([&]() {
1411@@ -176,10 +123,10 @@
1412 });
1413
1414 g_signal_emit_by_name(gvolume_, "changed", nullptr);
1415- Utils::WaitUntil(callback_called);
1416+ EXPECT_TRUE(callback_called);
1417 }
1418
1419-TEST_F(TestVolumeImp, TestRemovedSignal)
1420+TEST_F(TestVolumeImp, RemovedSignal)
1421 {
1422 bool callback_called = false;
1423 volume_->removed.connect([&]() {
1424@@ -187,7 +134,7 @@
1425 });
1426
1427 g_signal_emit_by_name(gvolume_, "removed", nullptr);
1428- Utils::WaitUntil(callback_called);
1429+ EXPECT_TRUE(callback_called);
1430 }
1431
1432 }
1433
1434=== modified file 'tests/test_volume_launcher_icon.cpp'
1435--- tests/test_volume_launcher_icon.cpp 2013-05-17 22:53:57 +0000
1436+++ tests/test_volume_launcher_icon.cpp 2013-10-07 17:26:52 +0000
1437@@ -25,6 +25,7 @@
1438 #include "FavoriteStore.h"
1439 #include "test_utils.h"
1440 #include "test_mock_devices.h"
1441+#include "test_mock_filemanager.h"
1442 using namespace unity;
1443 using namespace unity::launcher;
1444
1445@@ -33,18 +34,19 @@
1446
1447 struct TestVolumeLauncherIcon : public Test
1448 {
1449- virtual void SetUp()
1450+ TestVolumeLauncherIcon()
1451+ : volume_(std::make_shared<MockVolume::Nice>())
1452+ , settings_(std::make_shared<MockDevicesSettings::Nice>())
1453+ , notifications_(std::make_shared<MockDeviceNotificationDisplay::Nice>())
1454+ , file_manager_(std::make_shared<MockFileManager::Nice>())
1455 {
1456- volume_.reset(new NiceMock<MockVolume>);
1457- settings_.reset(new NiceMock<MockDevicesSettings>);
1458-
1459 SetupVolumeDefaultBehavior();
1460 SetupSettingsDefaultBehavior();
1461 }
1462
1463 void CreateIcon()
1464 {
1465- icon_ = new NiceMock<VolumeLauncherIcon>(volume_, settings_);
1466+ icon_ = new NiceMock<VolumeLauncherIcon>(volume_, settings_, notifications_, file_manager_);
1467 }
1468
1469 void SetupSettingsDefaultBehavior()
1470@@ -59,10 +61,14 @@
1471 ON_CALL(*volume_, GetName()).WillByDefault(Return("Test Name"));
1472 ON_CALL(*volume_, GetIconName()).WillByDefault(Return("Test Icon Name"));
1473 ON_CALL(*volume_, GetIdentifier()).WillByDefault(Return("Test Identifier"));
1474+ ON_CALL(*volume_, GetUri()).WillByDefault(Return("file:///media/user/device_uri"));
1475 ON_CALL(*volume_, HasSiblings()).WillByDefault(Return(false));
1476 ON_CALL(*volume_, CanBeEjected()).WillByDefault(Return(false));
1477 ON_CALL(*volume_, IsMounted()).WillByDefault(Return(true));
1478- ON_CALL(*volume_, IsOpened()) .WillByDefault(Return(true));
1479+ ON_CALL(*volume_, Mount()).WillByDefault(Invoke([this] { volume_->mounted.emit(); }));
1480+ ON_CALL(*volume_, Unmount()).WillByDefault(Invoke([this] { volume_->unmounted.emit(); }));
1481+ ON_CALL(*volume_, Eject()).WillByDefault(Invoke([this] { volume_->ejected.emit(); }));
1482+ ON_CALL(*volume_, StopDrive()).WillByDefault(Invoke([this] { volume_->stopped.emit(); }));
1483 }
1484
1485 glib::Object<DbusmenuMenuitem> GetMenuItemAtIndex(int index)
1486@@ -76,6 +82,8 @@
1487
1488 MockVolume::Ptr volume_;
1489 MockDevicesSettings::Ptr settings_;
1490+ MockDeviceNotificationDisplay::Ptr notifications_;
1491+ MockFileManager::Ptr file_manager_;
1492 VolumeLauncherIcon::Ptr icon_;
1493 std::string old_lang_;
1494 };
1495@@ -86,26 +94,47 @@
1496 EXPECT_EQ(icon_->GetIconType(), AbstractLauncherIcon::IconType::DEVICE);
1497 }
1498
1499-TEST_F(TestVolumeLauncherIcon, TestQuirks)
1500-{
1501- CreateIcon();
1502-
1503- EXPECT_EQ(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING), volume_->IsOpened());
1504-}
1505-
1506-TEST_F(TestVolumeLauncherIcon, TestRunningStateUpdatesOnOpenedState)
1507-{
1508- CreateIcon();
1509-
1510- ON_CALL(*volume_, IsOpened()).WillByDefault(Return(false));
1511- volume_->opened.emit(volume_->IsOpened());
1512- EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1513-
1514- ON_CALL(*volume_, IsOpened()).WillByDefault(Return(true));
1515- volume_->opened.emit(volume_->IsOpened());
1516- EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1517-}
1518-
1519+TEST_F(TestVolumeLauncherIcon, TestRunningOnClosed)
1520+{
1521+ ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false));
1522+ CreateIcon();
1523+
1524+ EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1525+}
1526+
1527+TEST_F(TestVolumeLauncherIcon, TestRunningOnOpened)
1528+{
1529+ ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true));
1530+ CreateIcon();
1531+
1532+ EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1533+}
1534+
1535+TEST_F(TestVolumeLauncherIcon, FilemanagerSignalDisconnection)
1536+{
1537+ CreateIcon();
1538+ ASSERT_FALSE(file_manager_->locations_changed.empty());
1539+ icon_ = nullptr;
1540+ EXPECT_TRUE(file_manager_->locations_changed.empty());
1541+}
1542+
1543+TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedClosed)
1544+{
1545+ CreateIcon();
1546+
1547+ ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false));
1548+ file_manager_->locations_changed.emit();
1549+ EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1550+}
1551+
1552+TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedOpened)
1553+{
1554+ CreateIcon();
1555+
1556+ ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true));
1557+ file_manager_->locations_changed.emit();
1558+ EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING));
1559+}
1560
1561 TEST_F(TestVolumeLauncherIcon, TestPosition)
1562 {
1563@@ -281,8 +310,10 @@
1564 EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE));
1565 EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(menuitem, DBUSMENU_MENUITEM_PROP_ENABLED));
1566
1567+ ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false));
1568 uint64_t time = g_random_int();
1569- EXPECT_CALL(*volume_, MountAndOpenInFileManager(time));
1570+ EXPECT_CALL(*volume_, Mount());
1571+ EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time));
1572
1573 dbusmenu_menuitem_handle_event(menuitem, DBUSMENU_MENUITEM_EVENT_ACTIVATED, nullptr, time);
1574 }
1575@@ -299,7 +330,9 @@
1576 EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(menuitem, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY));
1577
1578 uint64_t time = g_random_int();
1579- EXPECT_CALL(*volume_, MountAndOpenInFileManager(time));
1580+ ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false));
1581+ EXPECT_CALL(*volume_, Mount());
1582+ EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time));
1583
1584 dbusmenu_menuitem_handle_event(menuitem, DBUSMENU_MENUITEM_EVENT_ACTIVATED, nullptr, time);
1585 }
1586@@ -321,8 +354,8 @@
1587
1588 auto menuitem = GetMenuItemAtIndex(5);
1589
1590- EXPECT_CALL(*volume_, EjectAndShowNotification())
1591- .Times(1);
1592+ EXPECT_CALL(*volume_, Eject());
1593+ EXPECT_CALL(*notifications_, Display(volume_->GetIconName(), volume_->GetName()));
1594
1595 ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Eject");
1596 EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE));
1597@@ -438,9 +471,8 @@
1598
1599 CreateIcon();
1600
1601- EXPECT_CALL(*volume_, EjectAndShowNotification())
1602- .Times(1);
1603-
1604+ EXPECT_CALL(*volume_, Eject());
1605+ EXPECT_CALL(*notifications_, Display(volume_->GetIconName(), volume_->GetName()));
1606 icon_->EjectAndShowNotification();
1607 }
1608
1609@@ -532,12 +564,24 @@
1610 EXPECT_TRUE(forgot);
1611 }
1612
1613-TEST_F(TestVolumeLauncherIcon, Activate)
1614-{
1615- CreateIcon();
1616-
1617- uint64_t time = g_random_int();
1618- EXPECT_CALL(*volume_, MountAndOpenInFileManager(time));
1619+TEST_F(TestVolumeLauncherIcon, ActivateMounted)
1620+{
1621+ CreateIcon();
1622+
1623+ uint64_t time = g_random_int();
1624+ EXPECT_CALL(*volume_, Mount()).Times(0);
1625+ EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time));
1626+ icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time));
1627+}
1628+
1629+TEST_F(TestVolumeLauncherIcon, ActivateUnmounted)
1630+{
1631+ CreateIcon();
1632+
1633+ uint64_t time = g_random_int();
1634+ ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false));
1635+ EXPECT_CALL(*volume_, Mount());
1636+ EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time));
1637 icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time));
1638 }
1639
1640
1641=== modified file 'unity-shared/GnomeFileManager.cpp'
1642--- unity-shared/GnomeFileManager.cpp 2013-09-05 16:22:56 +0000
1643+++ unity-shared/GnomeFileManager.cpp 2013-10-07 17:26:52 +0000
1644@@ -34,8 +34,12 @@
1645 DECLARE_LOGGER(logger, "unity.filemanager.gnome");
1646
1647 const std::string TRASH_URI = "trash:";
1648-const std::string TRASH_PATH = "file://" + DesktopUtilities::GetUserDataDirectory() + "/Trash/files";
1649-const std::string DEVICES_PREFIX = "file:///media/" + std::string(g_get_user_name());
1650+const std::string FILE_SCHEMA = "file://";
1651+const std::string TRASH_PATH = FILE_SCHEMA + DesktopUtilities::GetUserDataDirectory() + "/Trash/files";
1652+const std::string DEVICES_PREFIX = FILE_SCHEMA + "/media/" + std::string(g_get_user_name());
1653+
1654+const std::string NAUTILUS_NAME = "org.gnome.Nautilus";
1655+const std::string NAUTILUS_PATH = "/org/gnome/Nautilus";
1656 }
1657
1658 struct GnomeFileManager::Impl
1659@@ -93,6 +97,12 @@
1660 return "";
1661 }
1662
1663+ glib::DBusProxy::Ptr NautilusOperationsProxy() const
1664+ {
1665+ return std::make_shared<glib::DBusProxy>(NAUTILUS_NAME, NAUTILUS_PATH,
1666+ "org.gnome.Nautilus.FileOperations");
1667+ }
1668+
1669 GnomeFileManager* parent_;
1670 glib::DBusProxy filemanager_proxy_;
1671 std::vector<std::string> opened_locations_;
1672@@ -170,9 +180,8 @@
1673 gdk_app_launch_context_set_timestamp(context, timestamp);
1674
1675 auto const& gcontext = glib::object_cast<GAppLaunchContext>(context);
1676- auto proxy = std::make_shared<glib::DBusProxy>("org.gnome.NautilusApplication",
1677- "/org/gnome/NautilusApplication",
1678- "org.gtk.Application");
1679+ auto proxy = std::make_shared<glib::DBusProxy>(NAUTILUS_NAME, NAUTILUS_PATH,
1680+ "org.freedesktop.Application");
1681
1682 glib::String context_string(g_app_launch_context_get_startup_notify_id(gcontext, app_info, nullptr));
1683
1684@@ -205,9 +214,7 @@
1685 void GnomeFileManager::EmptyTrash(uint64_t timestamp)
1686 {
1687 Activate(timestamp);
1688-
1689- auto proxy = std::make_shared<glib::DBusProxy>("org.gnome.Nautilus", "/org/gnome/Nautilus",
1690- "org.gnome.Nautilus.FileOperations");
1691+ auto const& proxy = impl_->NautilusOperationsProxy();
1692
1693 // Passing the proxy to the lambda we ensure that it will be destroyed when needed
1694 proxy->CallBegin("EmptyTrash", nullptr, [proxy] (GVariant*, glib::Error const&) {});
1695
1696=== modified file 'unity-shared/IconLoader.cpp'
1697--- unity-shared/IconLoader.cpp 2013-08-27 16:22:40 +0000
1698+++ unity-shared/IconLoader.cpp 2013-10-07 17:26:52 +0000
1699@@ -48,35 +48,17 @@
1700 class IconLoader::Impl
1701 {
1702 public:
1703- // The Handle typedef is used to explicitly indicate which integers are
1704- // infact our opaque handles.
1705- typedef int Handle;
1706 static const int FONT_SIZE = 8;
1707 static const int MIN_FONT_SIZE = 5;
1708
1709 Impl();
1710
1711- Handle LoadFromIconName(std::string const& icon_name,
1712- int max_width,
1713- int max_height,
1714- IconLoaderCallback slot);
1715-
1716- Handle LoadFromGIconString(std::string const& gicon_string,
1717- int max_width,
1718- int max_height,
1719- IconLoaderCallback slot);
1720-
1721- Handle LoadFromFilename(std::string const& filename,
1722- int max_width,
1723- int max_height,
1724- IconLoaderCallback slot);
1725-
1726- Handle LoadFromURI(std::string const& uri,
1727- int max_width,
1728- int max_height,
1729- IconLoaderCallback slot);
1730-
1731- void DisconnectHandle(Handle handle);
1732+ Handle LoadFromIconName(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1733+ Handle LoadFromGIconString(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1734+ Handle LoadFromFilename(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1735+ Handle LoadFromURI(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1736+
1737+ void DisconnectHandle(Handle);
1738
1739 static void CalculateTextHeight(int* width, int* height);
1740
1741@@ -103,7 +85,7 @@
1742 Impl* impl;
1743 gtk::IconInfo icon_info;
1744 bool no_cache;
1745- int helper_handle;
1746+ Handle helper_handle;
1747 std::list<IconLoaderTask::Ptr> shadow_tasks;
1748 glib::Object<GdkPixbuf> result;
1749 glib::Error error;
1750@@ -114,7 +96,7 @@
1751 int max_width_,
1752 int max_height_,
1753 std::string const& key_,
1754- IconLoaderCallback slot_,
1755+ IconLoaderCallback const& slot_,
1756 Handle handle_,
1757 Impl* self_)
1758 : type(type_), data(data_), max_width(max_width_)
1759@@ -797,14 +779,14 @@
1760 Handle ReturnCachedOrQueue(std::string const& data,
1761 int max_width,
1762 int max_height,
1763- IconLoaderCallback slot,
1764+ IconLoaderCallback const& slot,
1765 IconLoaderRequestType type);
1766
1767 Handle QueueTask(std::string const& key,
1768 std::string const& data,
1769 int max_width,
1770 int max_height,
1771- IconLoaderCallback slot,
1772+ IconLoaderCallback const& slot,
1773 IconLoaderRequestType type);
1774
1775 std::string Hash(std::string const& data, int max_width, int max_height);
1776@@ -813,7 +795,7 @@
1777 std::string const& data,
1778 int max_width,
1779 int max_height,
1780- IconLoaderCallback slot);
1781+ IconLoaderCallback const& slot);
1782
1783 // Looping idle callback function
1784 bool Iteration();
1785@@ -830,7 +812,7 @@
1786 * in the future... You've been warned! */
1787 std::map<std::string, IconLoaderTask::Ptr> queued_tasks_;
1788 std::queue<IconLoaderTask::Ptr> tasks_;
1789- std::map<Handle, IconLoaderTask::Ptr> task_map_;
1790+ std::unordered_map<Handle, IconLoaderTask::Ptr> task_map_;
1791 std::vector<IconLoaderTask*> finished_tasks_;
1792
1793 bool no_load_;
1794@@ -869,15 +851,12 @@
1795 #endif
1796 }
1797
1798-int IconLoader::Impl::LoadFromIconName(std::string const& icon_name,
1799- int max_width,
1800- int max_height,
1801- IconLoaderCallback slot)
1802+IconLoader::Handle IconLoader::Impl::LoadFromIconName(std::string const& icon_name, int max_width, int max_height, IconLoaderCallback const& slot)
1803 {
1804 if (no_load_ || icon_name.empty() || !slot ||
1805 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
1806 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
1807- return 0;
1808+ return Handle();
1809
1810 // We need to check this because of legacy desktop files
1811 if (icon_name[0] == '/')
1812@@ -889,29 +868,23 @@
1813 REQUEST_TYPE_ICON_NAME);
1814 }
1815
1816-int IconLoader::Impl::LoadFromGIconString(std::string const& gicon_string,
1817- int max_width,
1818- int max_height,
1819- IconLoaderCallback slot)
1820+IconLoader::Handle IconLoader::Impl::LoadFromGIconString(std::string const& gicon_string, int max_width, int max_height, IconLoaderCallback const& slot)
1821 {
1822 if (no_load_ || gicon_string.empty() || !slot ||
1823 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
1824 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
1825- return 0;
1826+ return Handle();
1827
1828 return ReturnCachedOrQueue(gicon_string, max_width, max_height, slot,
1829 REQUEST_TYPE_GICON_STRING);
1830 }
1831
1832-int IconLoader::Impl::LoadFromFilename(std::string const& filename,
1833- int max_width,
1834- int max_height,
1835- IconLoaderCallback slot)
1836+IconLoader::Handle IconLoader::Impl::LoadFromFilename(std::string const& filename, int max_width, int max_height, IconLoaderCallback const& slot)
1837 {
1838 if (no_load_ || filename.empty() || !slot ||
1839 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
1840 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
1841- return 0;
1842+ return Handle();
1843
1844 glib::Object<GFile> file(::g_file_new_for_path(filename.c_str()));
1845 glib::String uri(::g_file_get_uri(file));
1846@@ -919,15 +892,12 @@
1847 return LoadFromURI(uri.Str(), max_width, max_height, slot);
1848 }
1849
1850-int IconLoader::Impl::LoadFromURI(std::string const& uri,
1851- int max_width,
1852- int max_height,
1853- IconLoaderCallback slot)
1854+IconLoader::Handle IconLoader::Impl::LoadFromURI(std::string const& uri, int max_width, int max_height, IconLoaderCallback const& slot)
1855 {
1856 if (no_load_ || uri.empty() || !slot ||
1857 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
1858 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
1859- return 0;
1860+ return Handle();
1861
1862 return ReturnCachedOrQueue(uri, max_width, max_height, slot,
1863 REQUEST_TYPE_URI);
1864@@ -983,29 +953,19 @@
1865 // Private Methods
1866 //
1867
1868-int IconLoader::Impl::ReturnCachedOrQueue(std::string const& data,
1869- int max_width,
1870- int max_height,
1871- IconLoaderCallback slot,
1872- IconLoaderRequestType type)
1873+IconLoader::Handle IconLoader::Impl::ReturnCachedOrQueue(std::string const& data, int max_width, int max_height, IconLoaderCallback const& slot, IconLoaderRequestType type)
1874 {
1875- Handle result = 0;
1876 std::string key(Hash(data, max_width, max_height));
1877
1878 if (!CacheLookup(key, data, max_width, max_height, slot))
1879 {
1880- result = QueueTask(key, data, max_width, max_height, slot, type);
1881+ return QueueTask(key, data, max_width, max_height, slot, type);
1882 }
1883- return result;
1884+ return Handle();
1885 }
1886
1887
1888-int IconLoader::Impl::QueueTask(std::string const& key,
1889- std::string const& data,
1890- int max_width,
1891- int max_height,
1892- IconLoaderCallback slot,
1893- IconLoaderRequestType type)
1894+IconLoader::Handle IconLoader::Impl::QueueTask(std::string const& key, std::string const& data, int max_width, int max_height, IconLoaderCallback const& slot, IconLoaderRequestType type)
1895 {
1896 auto task = std::make_shared<IconLoaderTask>(type, data,
1897 max_width, max_height,
1898@@ -1056,7 +1016,7 @@
1899 std::string const& data,
1900 int max_width,
1901 int max_height,
1902- IconLoaderCallback slot)
1903+ IconLoaderCallback const& slot)
1904 {
1905 auto iter = cache_.find(key);
1906 bool found = iter != cache_.end();
1907@@ -1139,39 +1099,27 @@
1908 return default_loader;
1909 }
1910
1911-int IconLoader::LoadFromIconName(std::string const& icon_name,
1912- int max_width,
1913- int max_height,
1914- IconLoaderCallback slot)
1915+IconLoader::Handle IconLoader::LoadFromIconName(std::string const& icon_name, int max_width, int max_height, IconLoaderCallback const& slot)
1916 {
1917 return pimpl->LoadFromIconName(icon_name, max_width, max_height, slot);
1918 }
1919
1920-int IconLoader::LoadFromGIconString(std::string const& gicon_string,
1921- int max_width,
1922- int max_height,
1923- IconLoaderCallback slot)
1924+IconLoader::Handle IconLoader::LoadFromGIconString(std::string const& gicon_string, int max_width, int max_height, IconLoaderCallback const& slot)
1925 {
1926 return pimpl->LoadFromGIconString(gicon_string, max_width, max_height, slot);
1927 }
1928
1929-int IconLoader::LoadFromFilename(std::string const& filename,
1930- int max_width,
1931- int max_height,
1932- IconLoaderCallback slot)
1933+IconLoader::Handle IconLoader::LoadFromFilename(std::string const& filename, int max_width, int max_height, IconLoaderCallback const& slot)
1934 {
1935 return pimpl->LoadFromFilename(filename, max_width, max_height, slot);
1936 }
1937
1938-int IconLoader::LoadFromURI(std::string const& uri,
1939- int max_width,
1940- int max_height,
1941- IconLoaderCallback slot)
1942+IconLoader::Handle IconLoader::LoadFromURI(std::string const& uri, int max_width, int max_height, IconLoaderCallback const& slot)
1943 {
1944 return pimpl->LoadFromURI(uri, max_width, max_height, slot);
1945 }
1946
1947-void IconLoader::DisconnectHandle(int handle)
1948+void IconLoader::DisconnectHandle(Handle handle)
1949 {
1950 pimpl->DisconnectHandle(handle);
1951 }
1952
1953=== modified file 'unity-shared/IconLoader.h'
1954--- unity-shared/IconLoader.h 2012-09-12 15:07:07 +0000
1955+++ unity-shared/IconLoader.h 2013-10-07 17:26:52 +0000
1956@@ -24,6 +24,7 @@
1957
1958 #include <memory>
1959 #include <gtk/gtk.h>
1960+#include <UnityCore/ActionHandle.h>
1961 #include <UnityCore/GLibWrapper.h>
1962
1963 namespace unity
1964@@ -32,6 +33,7 @@
1965 class IconLoader : public boost::noncopyable
1966 {
1967 public:
1968+ typedef action::handle Handle;
1969 typedef std::function<void(std::string const&, int, int, glib::Object<GdkPixbuf> const&)> IconLoaderCallback;
1970
1971 IconLoader();
1972@@ -44,27 +46,12 @@
1973 * this is to disconnect the callback slot.
1974 */
1975
1976- int LoadFromIconName(std::string const& icon_name,
1977- int max_width,
1978- int max_height,
1979- IconLoaderCallback slot);
1980-
1981- int LoadFromGIconString(std::string const& gicon_string,
1982- int max_width,
1983- int max_height,
1984- IconLoaderCallback slot);
1985-
1986- int LoadFromFilename(std::string const& filename,
1987- int max_width,
1988- int max_height,
1989- IconLoaderCallback slot);
1990-
1991- int LoadFromURI(std::string const& uri,
1992- int max_width,
1993- int max_height,
1994- IconLoaderCallback slot);
1995-
1996- void DisconnectHandle(int handle);
1997+ Handle LoadFromIconName(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1998+ Handle LoadFromGIconString(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
1999+ Handle LoadFromFilename(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
2000+ Handle LoadFromURI(std::string const&, int max_width, int max_height, IconLoaderCallback const& slot);
2001+
2002+ void DisconnectHandle(Handle handle);
2003
2004 private:
2005 class Impl;