Merge lp:~3v1n0/unity/dash-files-open into lp:unity/7.0

Proposed by Marco Trevisan (Treviño) on 2013-05-02
Status: Work in progress
Proposed branch: lp:~3v1n0/unity/dash-files-open
Merge into: lp:unity/7.0
Diff against target: 596 lines (+172/-76)
12 files modified
UnityCore/Lens.cpp (+10/-2)
dash/DashController.cpp (+1/-2)
dash/DashView.cpp (+26/-12)
dash/DashView.h (+5/-1)
dash/StandaloneDash.cpp (+1/-3)
tests/test_dash_view.cpp (+17/-3)
tests/test_lens.cpp (+28/-10)
tests/test_mock_filemanager.h (+4/-3)
tests/test_service_lens.cpp (+14/-7)
unity-shared/FileManager.h (+7/-3)
unity-shared/GnomeFileManager.cpp (+51/-26)
unity-shared/GnomeFileManager.h (+8/-4)
To merge this branch: bzr merge lp:~3v1n0/unity/dash-files-open
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-05-02
Unity Team 2013-05-02 Pending
Review via email: mp+162008@code.launchpad.net

Commit message

Lens: if a lens returns a "goto-uri" parameter, activate that instead of the activated uri

DashView: use FileManager to launch an activated location, in case opening it.

Description of the change

We use the "goto-uri" parameter that a Lens can return to activate the lens-parsed location, using FileManager with correct timestamp to open or launch files.

This depends on lp:~3v1n0/unity-lens-files/delegate-activation/+merge/162007

To post a comment you must log in.
lp:~3v1n0/unity/dash-files-open updated on 2013-05-02
3318. By Marco Trevisan (Treviño) on 2013-05-02

TestDashView: use our beloved beef

3319. By Marco Trevisan (Treviño) on 2013-05-02

TestLensService: update to support goto-uri redirection

3320. By Marco Trevisan (Treviño) on 2013-05-02

TestLens: add activation redirection test

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

3320. By Marco Trevisan (Treviño) on 2013-05-02

TestLens: add activation redirection test

3319. By Marco Trevisan (Treviño) on 2013-05-02

TestLensService: update to support goto-uri redirection

3318. By Marco Trevisan (Treviño) on 2013-05-02

TestDashView: use our beloved beef

3317. By Marco Trevisan (Treviño) on 2013-05-01

TestDashView: add tests for Filemanager Launch and Opening

3316. By Marco Trevisan (Treviño) on 2013-05-01

DashView: use FileManager to launch an activated location, in case opening it.

3315. By Marco Trevisan (Treviño) on 2013-05-01

Lens: if a lens returns a "goto-uri" parameter, activate that instead of the activated uri

3314. By Marco Trevisan (Treviño) on 2013-05-01

GnomeFileManager: add Launch Implementation, to launch a file with default handler

3313. By Marco Trevisan (Treviño) on 2013-04-23

GnomeFileManager: add Utility function to get the Launch Context

3312. By Marco Trevisan (Treviño) on 2013-04-22

GnomeFileManager: If the requested location is not mounted, we open the file-manager

If the requested position is not mounted, we open the file-manager waiting it to mount
the requested location.

3311. By Marco Trevisan (Treviño) on 2013-04-22

FileManager: return a bool on Open methods.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/Lens.cpp'
2--- UnityCore/Lens.cpp 2013-03-21 19:11:44 +0000
3+++ UnityCore/Lens.cpp 2013-05-02 01:34:26 +0000
4@@ -509,7 +509,7 @@
5 guint32 handled;
6 GVariant* hints_variant;
7 Hints hints;
8-
9+
10 g_variant_get(parameters, "((su@a{sv}))", &uri, &handled, &hints_variant);
11
12 glib::Variant dict (hints_variant, glib::StealRef());
13@@ -536,7 +536,15 @@
14 }
15 else
16 {
17- owner_->activated.emit(uri.Str(), static_cast<HandledType>(handled), hints);
18+ auto activated_uri = uri.Str();
19+
20+ auto iter = hints.find("goto-uri");
21+ if (iter != hints.end())
22+ {
23+ activated_uri = "goto-uri:" + iter->second.GetString();
24+ }
25+
26+ owner_->activated.emit(activated_uri, static_cast<HandledType>(handled), hints);
27 }
28 }
29
30
31=== modified file 'dash/DashController.cpp'
32--- dash/DashController.cpp 2013-04-10 20:59:51 +0000
33+++ dash/DashController.cpp 2013-05-02 01:34:26 +0000
34@@ -23,7 +23,6 @@
35 #include <Nux/HLayout.h>
36 #include <UnityCore/GLibWrapper.h>
37
38-#include "ApplicationStarterImp.h"
39 #include "unity-shared/DashStyle.h"
40 #include "unity-shared/PanelStyle.h"
41 #include "unity-shared/UBusMessages.h"
42@@ -140,7 +139,7 @@
43
44 void Controller::SetupDashView()
45 {
46- view_ = new DashView(std::make_shared<FilesystemLenses>(), std::make_shared<ApplicationStarterImp>());
47+ view_ = new DashView(std::make_shared<FilesystemLenses>());
48 AddChild(view_);
49
50 nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);
51
52=== modified file 'dash/DashView.cpp'
53--- dash/DashView.cpp 2013-04-12 16:01:19 +0000
54+++ dash/DashView.cpp 2013-05-02 01:34:26 +0000
55@@ -20,6 +20,7 @@
56
57 #include "DashView.h"
58 #include "DashViewPrivate.h"
59+#include "ApplicationStarterImp.h"
60 #include "FilterExpanderLabel.h"
61
62 #include <math.h>
63@@ -31,6 +32,7 @@
64 #include <UnityCore/GLibWrapper.h>
65 #include <UnityCore/RadioOptionFilter.h>
66
67+#include "unity-shared/GnomeFileManager.h"
68 #include "unity-shared/DashStyle.h"
69 #include "unity-shared/KeyboardUtil.h"
70 #include "unity-shared/PreviewStyle.h"
71@@ -56,6 +58,10 @@
72 const int GROUP_HEADING_HEIGHT = 24;
73
74 const int PREVIEW_ICON_SPLIT_OFFSCREEN_OFFSET = 10;
75+
76+const std::string RESULT_APPLICATION_PREFIX = "application://";
77+const std::string RESULT_RUNNER_PREFIX = "unity-runner://";
78+const std::string RESULT_DIRECTORY_PREFIX = "directory://";
79 }
80
81 // This is so we can access some protected members in nux::VLayout and
82@@ -109,11 +115,12 @@
83
84 NUX_IMPLEMENT_OBJECT_TYPE(DashView);
85
86-DashView::DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter)
87+DashView::DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter, FileManager::Ptr const& file_manager)
88 : nux::View(NUX_TRACKER_LOCATION)
89 , lenses_(lenses)
90 , home_lens_(new HomeLens(_("Home"), _("Home screen"), _("Search your computer and online sources")))
91- , application_starter_(application_starter)
92+ , application_starter_(application_starter ? application_starter : std::make_shared<ApplicationStarterImp>())
93+ , file_manager_(file_manager ? file_manager : GnomeFileManager::Get())
94 , preview_container_(nullptr)
95 , preview_displaying_(false)
96 , preview_navigation_mode_(previews::Navigation::NONE)
97@@ -1380,18 +1387,25 @@
98
99 LOG_DEBUG(logger) << "Fallback activating " << uri;
100
101- if (g_str_has_prefix(uri.c_str(), "application://"))
102- {
103- std::string const& appname = uri.substr(14);
104- return application_starter_->Launch(appname, last_activated_timestamp_);
105- }
106- else if (g_str_has_prefix(uri.c_str(), "unity-runner://"))
107- {
108- std::string const& appname = uri.substr(15);
109- return application_starter_->Launch(appname, last_activated_timestamp_);
110+ if (uri.find(RESULT_APPLICATION_PREFIX) == 0)
111+ {
112+ std::string const& appname = uri.substr(RESULT_APPLICATION_PREFIX.size());
113+ return application_starter_->Launch(appname, last_activated_timestamp_);
114+ }
115+ else if (uri.find(RESULT_RUNNER_PREFIX) == 0)
116+ {
117+ std::string const& appname = uri.substr(RESULT_RUNNER_PREFIX.size());
118+ return application_starter_->Launch(appname, last_activated_timestamp_);
119+ }
120+ else if (uri.find(RESULT_DIRECTORY_PREFIX) == 0)
121+ {
122+ std::string const& directory = uri.substr(RESULT_DIRECTORY_PREFIX.size());
123+ return file_manager_->Open(directory, last_activated_timestamp_);
124 }
125 else
126- return gtk_show_uri(NULL, uri.c_str(), last_activated_timestamp_, NULL);
127+ {
128+ return file_manager_->Launch(uri, last_activated_timestamp_);
129+ }
130
131 return false;
132 }
133
134=== modified file 'dash/DashView.h'
135--- dash/DashView.h 2013-04-10 18:26:42 +0000
136+++ dash/DashView.h 2013-05-02 01:34:26 +0000
137@@ -37,6 +37,7 @@
138
139 #include "unity-shared/BackgroundEffectHelper.h"
140 #include "unity-shared/BGHash.h"
141+#include "unity-shared/FileManager.h"
142 #include "unity-shared/Introspectable.h"
143 #include "unity-shared/OverlayRenderer.h"
144 #include "unity-shared/SearchBar.h"
145@@ -59,7 +60,9 @@
146 typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews;
147
148 public:
149- DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter);
150+ DashView(Lenses::Ptr const& lenses,
151+ ApplicationStarter::Ptr const& application_starter = nullptr,
152+ FileManager::Ptr const& file_manager = nullptr);
153 ~DashView();
154
155 void AboutToShow();
156@@ -139,6 +142,7 @@
157 LensViews lens_views_;
158
159 ApplicationStarter::Ptr application_starter_;
160+ FileManager::Ptr file_manager_;
161
162 // View related
163 PreviewStateMachine preview_state_machine_;
164
165=== modified file 'dash/StandaloneDash.cpp'
166--- dash/StandaloneDash.cpp 2013-03-12 15:21:19 +0000
167+++ dash/StandaloneDash.cpp 2013-05-02 01:34:26 +0000
168@@ -28,7 +28,6 @@
169 #include <NuxCore/AnimationController.h>
170 #include <NuxCore/Logger.h>
171
172-#include "ApplicationStarterImp.h"
173 #include "unity-shared/BGHash.h"
174 #include "unity-shared/FontSettings.h"
175 #include "DashView.h"
176@@ -65,8 +64,7 @@
177 {
178 layout = new nux::HLayout(NUX_TRACKER_LOCATION);
179
180- DashView* view = new DashView(std::make_shared<unity::dash::FilesystemLenses>(),
181- std::make_shared<unity::ApplicationStarterImp>());
182+ DashView* view = new DashView(std::make_shared<unity::dash::FilesystemLenses>());
183 view->DisableBlur();
184 view->SetMinMaxSize(WIDTH, HEIGHT);
185 layout->AddView (view, 1, nux::MINOR_POSITION_CENTER);
186
187=== modified file 'tests/test_dash_view.cpp'
188--- tests/test_dash_view.cpp 2013-03-12 21:45:58 +0000
189+++ tests/test_dash_view.cpp 2013-05-02 01:34:26 +0000
190@@ -20,11 +20,11 @@
191
192 #include <UnityCore/Lenses.h>
193
194-#include "ApplicationStarter.h"
195 #include "DashView.h"
196 #include "unity-shared/DashStyle.h"
197 #include "unity-shared/PanelStyle.h"
198 #include "unity-shared/UnitySettings.h"
199+#include "test_mock_filemanager.h"
200
201 #include "mock-lenses.h"
202
203@@ -43,7 +43,8 @@
204 TestDashView()
205 : lenses_(std::make_shared<testmocks::ThreeMockTestLenses>())
206 , application_starter_(std::make_shared<MockApplicationStarter>())
207- , dash_view_(new DashView(lenses_, application_starter_))
208+ , file_manager_(std::make_shared<NiceMock<unity::MockFileManager>>())
209+ , dash_view_(new DashView(lenses_, application_starter_, file_manager_))
210 {}
211
212 unity::Settings unity_settings_;
213@@ -51,11 +52,12 @@
214 unity::panel::Style panel_style;
215 Lenses::Ptr lenses_;
216 MockApplicationStarter::Ptr application_starter_;
217+ unity::MockFileManager::Ptr file_manager_;
218 nux::ObjectPtr<DashView> dash_view_;
219 };
220
221
222-TEST_F(TestDashView, LensActivatedSignal)
223+TEST_F(TestDashView, LensActivatedApplication)
224 {
225 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
226 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:application://uri", NOT_HANDLED, Lens::Hints());
227@@ -64,4 +66,16 @@
228 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:unity-runner://uri", NOT_HANDLED, Lens::Hints());
229 }
230
231+TEST_F(TestDashView, LensActivatedDirectory)
232+{
233+ EXPECT_CALL(*file_manager_, Open("file:///dir/file.ext", _));
234+ lenses_->GetLensAtIndex(0)->activated.emit("goto-uri:directory://file:///dir/file.ext", NOT_HANDLED, Lens::Hints());
235+}
236+
237+TEST_F(TestDashView, LensActivatedAny)
238+{
239+ EXPECT_CALL(*file_manager_, Launch("file:///dir/file.ext", _));
240+ lenses_->GetLensAtIndex(0)->activated.emit("0xdeadbeef:file:///dir/file.ext", NOT_HANDLED, Lens::Hints());
241+}
242+
243 }
244
245=== modified file 'tests/test_lens.cpp'
246--- tests/test_lens.cpp 2013-03-04 11:31:36 +0000
247+++ tests/test_lens.cpp 2013-05-02 01:34:26 +0000
248@@ -1,4 +1,3 @@
249-#include <boost/lexical_cast.hpp>
250 #include <gtest/gtest.h>
251 #include <glib-object.h>
252
253@@ -66,13 +65,13 @@
254 ASSERT_EQ(model->count(), n_rows);
255 }
256
257- std::string PopulateAndGetFirstResultURI()
258+ std::string PopulateAndGetFirstResultURI(bool redirect = false)
259 {
260 Results::Ptr results = lens_->results;
261
262- lens_->Search("Test Search String", nullptr);
263+ lens_->Search(redirect ? "redirect" : "Test Search String", nullptr);
264 WaitForModel<Result>(results.get(), 5);
265-
266+
267 Result result = results->RowAtIndex(0);
268 return result.uri;
269 }
270@@ -134,18 +133,18 @@
271
272 for (unsigned int i = 0; i < 5; i++)
273 {
274- std::string name("Test Search String" + boost::lexical_cast<std::string>(i));
275+ std::string name("Test Search String" + std::to_string(i));
276
277 Result result = results->RowAtIndex(i);
278
279 std::string uri = result.uri;
280- EXPECT_TRUE(uri.find("file:///test"));
281+ EXPECT_TRUE(uri.find("file:///test/"+std::to_string(i)));
282 EXPECT_EQ(result.icon_hint, "gtk-apply");
283 EXPECT_EQ(result.category_index, i);
284 EXPECT_EQ(result.mimetype, "text/html");
285 EXPECT_EQ(result.name, name);
286 EXPECT_EQ(result.comment, "kamstrup likes ponies");
287- EXPECT_EQ(result.dnd_uri, "file:///test");
288+ EXPECT_EQ(result.dnd_uri, "file:///test/"+std::to_string(i));
289 }
290 }
291
292@@ -158,18 +157,18 @@
293
294 for (unsigned int i = 0; i < 10; i++)
295 {
296- std::string name("Test Global Search String" + boost::lexical_cast<std::string>(i));
297+ std::string name("Test Global Search String" + std::to_string(i));
298
299 Result result = results->RowAtIndex(i);
300
301 std::string uri = result.uri;
302- EXPECT_TRUE(uri.find("file:///test"));
303+ EXPECT_TRUE(uri.find("file:///test/"+std::to_string(i)));
304 EXPECT_EQ(result.icon_hint, "gtk-apply");
305 EXPECT_EQ(result.category_index, i);
306 EXPECT_EQ(result.mimetype, "text/html");
307 EXPECT_EQ(result.name, name);
308 EXPECT_EQ(result.comment, "kamstrup likes ponies");
309- EXPECT_EQ(result.dnd_uri, "file:///test");
310+ EXPECT_EQ(result.dnd_uri, "file:///test/"+std::to_string(i));
311 }
312 }
313
314@@ -193,6 +192,25 @@
315 Utils::WaitUntil(activated);
316 }
317
318+TEST_F(TestLens, TestActivationRedirect)
319+{
320+ std::string uri = PopulateAndGetFirstResultURI(true);
321+
322+ bool activated = false;
323+ auto activated_cb = [&activated, &uri] (std::string const& uri_,
324+ HandledType handled,
325+ Lens::Hints const& hints)
326+ {
327+ EXPECT_EQ(uri_, "goto-uri:"+uri.substr(uri.find(":")+1));
328+ EXPECT_EQ(handled, HandledType::HIDE_DASH);
329+ activated = true;
330+ };
331+ lens_->activated.connect(activated_cb);
332+
333+ lens_->Activate(uri);
334+ Utils::WaitUntil(activated);
335+}
336+
337 TEST_F(TestLens, TestPreview)
338 {
339 std::string uri = PopulateAndGetFirstResultURI();
340
341=== modified file 'tests/test_mock_filemanager.h'
342--- tests/test_mock_filemanager.h 2013-03-29 17:44:12 +0000
343+++ tests/test_mock_filemanager.h 2013-05-02 01:34:26 +0000
344@@ -29,9 +29,10 @@
345 {
346 typedef std::shared_ptr<MockFileManager> Ptr;
347
348- MOCK_METHOD2(Open, void(std::string const& uri, unsigned long long time));
349- MOCK_METHOD2(OpenActiveChild, void(std::string const& uri, unsigned long long time));
350- MOCK_METHOD1(OpenTrash, void(unsigned long long time));
351+ MOCK_METHOD2(Open, bool(std::string const& uri, unsigned long long time));
352+ MOCK_METHOD2(OpenActiveChild, bool(std::string const& uri, unsigned long long time));
353+ MOCK_METHOD1(OpenTrash, bool(unsigned long long time));
354+ MOCK_METHOD2(Launch, bool(std::string const& uri, unsigned long long time));
355 MOCK_METHOD1(EmptyTrash, void(unsigned long long time));
356 MOCK_CONST_METHOD0(OpenedLocations, std::vector<std::string>());
357 MOCK_CONST_METHOD1(IsPrefixOpened, bool(std::string const& uri));
358
359=== modified file 'tests/test_service_lens.cpp'
360--- tests/test_service_lens.cpp 2013-03-04 11:31:36 +0000
361+++ tests/test_service_lens.cpp 2013-05-02 01:34:26 +0000
362@@ -118,21 +118,22 @@
363 int num_items = search_type == UNITY_SEARCH_TYPE_GLOBAL ? 10 : 5;
364
365 DeeModel* model = (DeeModel*)unity_lens_search_get_results_model(search);
366+ bool redirect = (g_strcmp0(unity_lens_search_get_search_string(search), "redirect") == 0);
367+
368+ dee_model_clear(model);
369
370 for (i = 0; i < num_items; i++)
371 {
372- gchar* name = g_strdup_printf("%s%d",
373- unity_lens_search_get_search_string(search),
374- i);
375+ std::string name = unity_lens_search_get_search_string(search) + std::to_string(i);
376+ std::string uri = (redirect ? "file:///test/redirect/" : "file:///test/") + std::to_string(i);
377 dee_model_append(model,
378- "file:///test",
379+ uri.c_str(),
380 "gtk-apply",
381 i,
382 "text/html",
383- name,
384+ name.c_str(),
385 "kamstrup likes ponies",
386- "file:///test");
387- g_free(name);
388+ uri.c_str());
389 }
390
391 unity_lens_search_finished (search);
392@@ -140,11 +141,17 @@
393
394 static UnityActivationResponse* on_activate_uri(UnityScope* scope, const char* uri, Lens* self)
395 {
396+ if (strstr(uri, "/redirect/"))
397+ return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, uri);
398+
399 return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, "");
400 }
401
402 static UnityActivationResponse* preview_action_activated(UnityPreviewAction* action, const char* uri)
403 {
404+ if (strstr(uri, "/redirect/"))
405+ return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, uri);
406+
407 return unity_activation_response_new(UNITY_HANDLED_TYPE_SHOW_DASH, "");
408 }
409
410
411=== modified file 'unity-shared/FileManager.h'
412--- unity-shared/FileManager.h 2013-04-10 22:13:44 +0000
413+++ unity-shared/FileManager.h 2013-05-02 01:34:26 +0000
414@@ -37,13 +37,17 @@
415 FileManager() = default;
416 virtual ~FileManager() {}
417
418- virtual void Open(std::string const& uri, unsigned long long timestamp = 0) = 0;
419- virtual void OpenActiveChild(std::string const& uri, unsigned long long timestamp = 0) = 0;
420- virtual void OpenTrash(unsigned long long timestamp) = 0;
421+ virtual bool Open(std::string const& uri, unsigned long long timestamp = 0) = 0;
422+ virtual bool OpenActiveChild(std::string const& uri, unsigned long long timestamp = 0) = 0;
423+ virtual bool OpenTrash(unsigned long long timestamp) = 0;
424+
425+ virtual bool Launch(std::string const& uri, unsigned long long timestamp = 0) = 0;
426+
427 virtual std::vector<std::string> OpenedLocations() const = 0;
428 virtual bool IsPrefixOpened(std::string const& uri) const = 0;
429 virtual bool IsTrashOpened() const = 0;
430 virtual bool IsDeviceOpened() const = 0;
431+
432 virtual void EmptyTrash(unsigned long long timestamp = 0) = 0;
433
434 sigc::signal<void> locations_changed;
435
436=== modified file 'unity-shared/GnomeFileManager.cpp'
437--- unity-shared/GnomeFileManager.cpp 2013-03-29 17:44:12 +0000
438+++ unity-shared/GnomeFileManager.cpp 2013-05-02 01:34:26 +0000
439@@ -36,6 +36,7 @@
440 const std::string TRASH_URI = "trash:";
441 const std::string TRASH_PATH = "file://" + DesktopUtilities::GetUserDataDirectory() + "/Trash/files";
442 const std::string DEVICES_PREFIX = "file:///media/" + std::string(g_get_user_name());
443+const std::string FOLDER_TYPE = "inode/directory";
444 }
445
446 struct GnomeFileManager::Impl
447@@ -93,6 +94,15 @@
448 return "";
449 }
450
451+ static glib::Object<GAppLaunchContext> GetLaunchContext(long long timestamp)
452+ {
453+ GdkDisplay* display = gdk_display_get_default();
454+ glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
455+ gdk_app_launch_context_set_timestamp(context, timestamp);
456+
457+ return glib::object_cast<GAppLaunchContext>(context);
458+ }
459+
460 GnomeFileManager* parent_;
461 glib::DBusProxy filemanager_proxy_;
462 std::vector<std::string> opened_locations_;
463@@ -112,46 +122,67 @@
464 GnomeFileManager::~GnomeFileManager()
465 {}
466
467-void GnomeFileManager::Open(std::string const& uri, unsigned long long timestamp)
468+bool GnomeFileManager::Launch(std::string const& uri, unsigned long long timestamp)
469 {
470 if (uri.empty())
471 {
472- LOG_ERROR(logger) << "Impossible to open an empty location";
473- return;
474+ LOG_ERROR(logger) << "Impossible to launch the application for an empty location";
475+ return false;
476 }
477
478 glib::Error error;
479- GdkDisplay* display = gdk_display_get_default();
480- glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
481-
482- if (timestamp > 0)
483- gdk_app_launch_context_set_timestamp(context, timestamp);
484-
485- auto const& gcontext = glib::object_cast<GAppLaunchContext>(context);
486+ auto const& gcontext = Impl::GetLaunchContext(timestamp);
487 g_app_info_launch_default_for_uri(uri.c_str(), gcontext, &error);
488
489 if (error)
490 {
491- LOG_ERROR(logger) << "Impossible to open the location: " << error.Message();
492- }
493-}
494-
495-void GnomeFileManager::OpenActiveChild(std::string const& uri, unsigned long long timestamp)
496+ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED))
497+ {
498+ /* If the location is not mounted, then we open the file-manager to make
499+ * it mount the requested position */
500+ return Open(uri, timestamp);
501+ }
502+
503+ LOG_ERROR(logger) << "Impossible to launch the location: " << error;
504+ return false;
505+ }
506+
507+ return true;
508+}
509+
510+bool GnomeFileManager::Open(std::string const& uri, unsigned long long timestamp)
511+{
512+ glib::Error error;
513+ glib::Object<GAppInfo> app_info(g_app_info_get_default_for_type(FOLDER_TYPE.c_str(), TRUE));
514+ std::shared_ptr<GList> uris(g_list_append(nullptr, const_cast<char*>(uri.c_str())), g_list_free);
515+
516+ g_app_info_launch_uris(app_info, uris.get(), Impl::GetLaunchContext(timestamp), &error);
517+
518+ if (error)
519+ {
520+ LOG_ERROR(logger) << "Impossible to open the location: " << error;
521+ return false;
522+ }
523+
524+ return true;
525+}
526+
527+bool GnomeFileManager::OpenActiveChild(std::string const& uri, unsigned long long timestamp)
528 {
529 auto const& opened = impl_->GetOpenedPrefix(uri);
530
531- Open(opened.empty() ? uri : opened, timestamp);
532+ return Open(opened.empty() ? uri : opened, timestamp);
533 }
534
535-void GnomeFileManager::OpenTrash(unsigned long long timestamp)
536+bool GnomeFileManager::OpenTrash(unsigned long long timestamp)
537 {
538 if (IsPrefixOpened(TRASH_PATH))
539 {
540- OpenActiveChild(TRASH_PATH, timestamp);
541+ return OpenActiveChild(TRASH_PATH, timestamp);
542 }
543 else
544 {
545- OpenActiveChild(TRASH_URI, timestamp);
546+ return OpenActiveChild(TRASH_URI, timestamp);
547 }
548 }
549
550@@ -163,17 +194,11 @@
551
552 if (app_info)
553 {
554- GdkDisplay* display = gdk_display_get_default();
555- glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
556-
557- if (timestamp > 0)
558- gdk_app_launch_context_set_timestamp(context, timestamp);
559-
560- auto const& gcontext = glib::object_cast<GAppLaunchContext>(context);
561 auto proxy = std::make_shared<glib::DBusProxy>("org.gnome.NautilusApplication",
562 "/org/gnome/NautilusApplication",
563 "org.gtk.Application");
564
565+ auto const& gcontext = Impl::GetLaunchContext(timestamp);
566 glib::String context_string(g_app_launch_context_get_startup_notify_id(gcontext, app_info, nullptr));
567
568 if (context_string && g_utf8_validate(context_string, -1, nullptr))
569
570=== modified file 'unity-shared/GnomeFileManager.h'
571--- unity-shared/GnomeFileManager.h 2013-03-29 17:44:12 +0000
572+++ unity-shared/GnomeFileManager.h 2013-05-02 01:34:26 +0000
573@@ -32,15 +32,19 @@
574 static FileManager::Ptr Get();
575 ~GnomeFileManager();
576
577- void Open(std::string const& uri, unsigned long long timestamp);
578- void OpenActiveChild(std::string const& uri, unsigned long long timestamp);
579- void OpenTrash(unsigned long long timestamp);
580- void EmptyTrash(unsigned long long timestamp);
581+ bool Open(std::string const& uri, unsigned long long timestamp);
582+ bool OpenActiveChild(std::string const& uri, unsigned long long timestamp);
583+ bool OpenTrash(unsigned long long timestamp);
584+
585+ bool Launch(std::string const& uri, unsigned long long timestamp);
586+
587 std::vector<std::string> OpenedLocations() const;
588 bool IsPrefixOpened(std::string const& uri) const;
589 bool IsTrashOpened() const;
590 bool IsDeviceOpened() const;
591
592+ void EmptyTrash(unsigned long long timestamp);
593+
594 private:
595 GnomeFileManager();
596 void Activate(unsigned long long timestamp);

Subscribers

People subscribed via source and target branches