Merge lp:~3v1n0/unity/volume-icon-dnd into lp:unity
- volume-icon-dnd
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Brandon Schaefer |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3558 |
Proposed branch: | lp:~3v1n0/unity/volume-icon-dnd |
Merge into: | lp:unity |
Prerequisite: | lp:~3v1n0/unity/volume-filemanager-in-icon |
Diff against target: |
695 lines (+166/-103) 9 files modified
launcher/ApplicationLauncherIcon.cpp (+3/-13) launcher/ApplicationLauncherIcon.h (+0/-1) launcher/VolumeLauncherIcon.cpp (+40/-4) launcher/VolumeLauncherIcon.h (+4/-1) tests/test_mock_filemanager.h (+1/-0) tests/test_volume_launcher_icon.cpp (+82/-84) unity-shared/FileManager.h (+2/-0) unity-shared/GnomeFileManager.cpp (+32/-0) unity-shared/GnomeFileManager.h (+2/-0) |
To merge this branch: | bzr merge lp:~3v1n0/unity/volume-icon-dnd |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Brandon Schaefer (community) | Approve | ||
Andrea Azzarone (community) | Needs Information | ||
Review via email: mp+189687@code.launchpad.net |
This proposal supersedes a proposal from 2013-10-07.
Commit message
VolumeLauncherIcon: copy files to device on DnD
Use filemanager to perform the copy action. If needed, delay the procedure until we
don't have the volume mounted (using a magic utility function to share the code).
Description of the change
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> Why not using g_file_copy_*?
Because using it would have needed to add a progress handler inside unity (progress bar over the icon + quicklist items to manage it?) separated to the nautilus one.
Using nautilus, we get instead for free the ability to copy files having a progress dialog and a dialog handling the file conflicts. All this keeping the consistency with the normal copy operation we'd have using the system tools.
So, until we don't reimplement all this inside unity, I think that using the environment facilities is better.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3571
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Brandon Schaefer (brandontschaefer) wrote : | # |
LGTM
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3572
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Andrea Azzarone (azzar1) wrote : | # |
Ok makes sense :D
Preview Diff
1 | === modified file 'launcher/ApplicationLauncherIcon.cpp' | |||
2 | --- launcher/ApplicationLauncherIcon.cpp 2013-10-04 03:55:52 +0000 | |||
3 | +++ launcher/ApplicationLauncherIcon.cpp 2013-10-07 22:37:56 +0000 | |||
4 | @@ -1112,16 +1112,6 @@ | |||
5 | 1112 | return _remote_uri; | 1112 | return _remote_uri; |
6 | 1113 | } | 1113 | } |
7 | 1114 | 1114 | ||
8 | 1115 | std::set<std::string> ApplicationLauncherIcon::ValidateUrisForLaunch(DndData const& uris) | ||
9 | 1116 | { | ||
10 | 1117 | std::set<std::string> result; | ||
11 | 1118 | |||
12 | 1119 | for (auto uri : uris.Uris()) | ||
13 | 1120 | result.insert(uri); | ||
14 | 1121 | |||
15 | 1122 | return result; | ||
16 | 1123 | } | ||
17 | 1124 | |||
18 | 1125 | void ApplicationLauncherIcon::OnDndHovered() | 1115 | void ApplicationLauncherIcon::OnDndHovered() |
19 | 1126 | { | 1116 | { |
20 | 1127 | // for now, let's not do this, it turns out to be quite buggy | 1117 | // for now, let's not do this, it turns out to be quite buggy |
21 | @@ -1159,7 +1149,7 @@ | |||
22 | 1159 | { | 1149 | { |
23 | 1160 | if (IsFileManager()) | 1150 | if (IsFileManager()) |
24 | 1161 | { | 1151 | { |
26 | 1162 | for (auto uri : dnd_data.Uris()) | 1152 | for (auto const& uri : dnd_data.Uris()) |
27 | 1163 | { | 1153 | { |
28 | 1164 | if (boost::algorithm::starts_with(uri, "file://")) | 1154 | if (boost::algorithm::starts_with(uri, "file://")) |
29 | 1165 | return true; | 1155 | return true; |
30 | @@ -1185,7 +1175,7 @@ | |||
31 | 1185 | nux::DndAction ApplicationLauncherIcon::OnQueryAcceptDrop(DndData const& dnd_data) | 1175 | nux::DndAction ApplicationLauncherIcon::OnQueryAcceptDrop(DndData const& dnd_data) |
32 | 1186 | { | 1176 | { |
33 | 1187 | #ifdef USE_X11 | 1177 | #ifdef USE_X11 |
35 | 1188 | return ValidateUrisForLaunch(dnd_data).empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY; | 1178 | return dnd_data.Uris().empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY; |
36 | 1189 | #else | 1179 | #else |
37 | 1190 | return nux::DNDACTION_NONE; | 1180 | return nux::DNDACTION_NONE; |
38 | 1191 | #endif | 1181 | #endif |
39 | @@ -1194,7 +1184,7 @@ | |||
40 | 1194 | void ApplicationLauncherIcon::OnAcceptDrop(DndData const& dnd_data) | 1184 | void ApplicationLauncherIcon::OnAcceptDrop(DndData const& dnd_data) |
41 | 1195 | { | 1185 | { |
42 | 1196 | auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; | 1186 | auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; |
44 | 1197 | OpenInstanceWithUris(ValidateUrisForLaunch(dnd_data), timestamp); | 1187 | OpenInstanceWithUris(dnd_data.Uris(), timestamp); |
45 | 1198 | } | 1188 | } |
46 | 1199 | 1189 | ||
47 | 1200 | bool ApplicationLauncherIcon::ShowInSwitcher(bool current) | 1190 | bool ApplicationLauncherIcon::ShowInSwitcher(bool current) |
48 | 1201 | 1191 | ||
49 | === modified file 'launcher/ApplicationLauncherIcon.h' | |||
50 | --- launcher/ApplicationLauncherIcon.h 2013-09-11 10:18:31 +0000 | |||
51 | +++ launcher/ApplicationLauncherIcon.h 2013-10-07 22:37:56 +0000 | |||
52 | @@ -93,7 +93,6 @@ | |||
53 | 93 | nux::DndAction OnQueryAcceptDrop(DndData const& dnd_data); | 93 | nux::DndAction OnQueryAcceptDrop(DndData const& dnd_data); |
54 | 94 | 94 | ||
55 | 95 | MenuItemsVector GetMenus(); | 95 | MenuItemsVector GetMenus(); |
56 | 96 | std::set<std::string> ValidateUrisForLaunch(DndData const& dnd_data); | ||
57 | 97 | 96 | ||
58 | 98 | std::string GetRemoteUri() const; | 97 | std::string GetRemoteUri() const; |
59 | 99 | 98 | ||
60 | 100 | 99 | ||
61 | === modified file 'launcher/VolumeLauncherIcon.cpp' | |||
62 | --- launcher/VolumeLauncherIcon.cpp 2013-10-07 16:49:04 +0000 | |||
63 | +++ launcher/VolumeLauncherIcon.cpp 2013-10-07 22:37:56 +0000 | |||
64 | @@ -133,13 +133,13 @@ | |||
65 | 133 | volume_->StopDrive(); | 133 | volume_->StopDrive(); |
66 | 134 | } | 134 | } |
67 | 135 | 135 | ||
69 | 136 | void OpenInFileManager(uint64_t timestamp) | 136 | void DoActionWhenMounted(std::function<void()> const& callback) |
70 | 137 | { | 137 | { |
71 | 138 | if (!volume_->IsMounted()) | 138 | if (!volume_->IsMounted()) |
72 | 139 | { | 139 | { |
73 | 140 | auto conn = std::make_shared<sigc::connection>(); | 140 | auto conn = std::make_shared<sigc::connection>(); |
76 | 141 | *conn = volume_->mounted.connect([this, conn, timestamp] { | 141 | *conn = volume_->mounted.connect([this, conn, callback] { |
77 | 142 | file_manager_->OpenActiveChild(volume_->GetUri(), timestamp); | 142 | callback(); |
78 | 143 | conn->disconnect(); | 143 | conn->disconnect(); |
79 | 144 | }); | 144 | }); |
80 | 145 | connections_.Add(*conn); | 145 | connections_.Add(*conn); |
81 | @@ -147,8 +147,22 @@ | |||
82 | 147 | } | 147 | } |
83 | 148 | else | 148 | else |
84 | 149 | { | 149 | { |
85 | 150 | callback(); | ||
86 | 151 | } | ||
87 | 152 | } | ||
88 | 153 | |||
89 | 154 | void OpenInFileManager(uint64_t timestamp) | ||
90 | 155 | { | ||
91 | 156 | DoActionWhenMounted([this, timestamp] { | ||
92 | 150 | file_manager_->OpenActiveChild(volume_->GetUri(), timestamp); | 157 | file_manager_->OpenActiveChild(volume_->GetUri(), timestamp); |
94 | 151 | } | 158 | }); |
95 | 159 | } | ||
96 | 160 | |||
97 | 161 | void CopyFilesToVolume(std::set<std::string> const& files, uint64_t timestamp) | ||
98 | 162 | { | ||
99 | 163 | DoActionWhenMounted([this, files, timestamp] { | ||
100 | 164 | file_manager_->CopyFiles(files, volume_->GetUri(), timestamp); | ||
101 | 165 | }); | ||
102 | 152 | } | 166 | } |
103 | 153 | 167 | ||
104 | 154 | MenuItemsVector GetMenus() | 168 | MenuItemsVector GetMenus() |
105 | @@ -374,6 +388,28 @@ | |||
106 | 374 | SetQuirk(Quirk::VISIBLE, true); | 388 | SetQuirk(Quirk::VISIBLE, true); |
107 | 375 | } | 389 | } |
108 | 376 | 390 | ||
109 | 391 | bool VolumeLauncherIcon::OnShouldHighlightOnDrag(DndData const& dnd_data) | ||
110 | 392 | { | ||
111 | 393 | for (auto const& uri : dnd_data.Uris()) | ||
112 | 394 | { | ||
113 | 395 | if (uri.find("file://") == 0) | ||
114 | 396 | return true; | ||
115 | 397 | } | ||
116 | 398 | |||
117 | 399 | return false; | ||
118 | 400 | } | ||
119 | 401 | |||
120 | 402 | nux::DndAction VolumeLauncherIcon::OnQueryAcceptDrop(DndData const& dnd_data) | ||
121 | 403 | { | ||
122 | 404 | return dnd_data.Uris().empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY; | ||
123 | 405 | } | ||
124 | 406 | |||
125 | 407 | void VolumeLauncherIcon::OnAcceptDrop(DndData const& dnd_data) | ||
126 | 408 | { | ||
127 | 409 | auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; | ||
128 | 410 | pimpl_->CopyFilesToVolume(dnd_data.Uris(), timestamp); | ||
129 | 411 | } | ||
130 | 412 | |||
131 | 377 | // | 413 | // |
132 | 378 | // Introspection | 414 | // Introspection |
133 | 379 | // | 415 | // |
134 | 380 | 416 | ||
135 | === modified file 'launcher/VolumeLauncherIcon.h' | |||
136 | --- launcher/VolumeLauncherIcon.h 2013-10-07 16:26:18 +0000 | |||
137 | +++ launcher/VolumeLauncherIcon.h 2013-10-07 22:37:56 +0000 | |||
138 | @@ -53,7 +53,10 @@ | |||
139 | 53 | std::string GetRemoteUri() const; | 53 | std::string GetRemoteUri() const; |
140 | 54 | 54 | ||
141 | 55 | protected: | 55 | protected: |
143 | 56 | virtual void ActivateLauncherIcon(ActionArg arg); | 56 | void ActivateLauncherIcon(ActionArg arg); |
144 | 57 | bool OnShouldHighlightOnDrag(DndData const&); | ||
145 | 58 | void OnAcceptDrop(DndData const&); | ||
146 | 59 | nux::DndAction OnQueryAcceptDrop(DndData const&); | ||
147 | 57 | 60 | ||
148 | 58 | // Introspection | 61 | // Introspection |
149 | 59 | virtual std::string GetName() const; | 62 | virtual std::string GetName() const; |
150 | 60 | 63 | ||
151 | === modified file 'tests/test_mock_filemanager.h' | |||
152 | --- tests/test_mock_filemanager.h 2013-10-07 16:26:18 +0000 | |||
153 | +++ tests/test_mock_filemanager.h 2013-10-07 22:37:56 +0000 | |||
154 | @@ -36,6 +36,7 @@ | |||
155 | 36 | MOCK_METHOD1(OpenTrash, void(uint64_t time)); | 36 | MOCK_METHOD1(OpenTrash, void(uint64_t time)); |
156 | 37 | MOCK_METHOD1(TrashFile, bool(std::string const& uri)); | 37 | MOCK_METHOD1(TrashFile, bool(std::string const& uri)); |
157 | 38 | MOCK_METHOD1(EmptyTrash, void(uint64_t time)); | 38 | MOCK_METHOD1(EmptyTrash, void(uint64_t time)); |
158 | 39 | MOCK_METHOD3(CopyFiles, void(std::set<std::string> const& files, std::string const& dest, uint64_t time)); | ||
159 | 39 | MOCK_CONST_METHOD0(OpenedLocations, std::vector<std::string>()); | 40 | MOCK_CONST_METHOD0(OpenedLocations, std::vector<std::string>()); |
160 | 40 | MOCK_CONST_METHOD1(IsPrefixOpened, bool(std::string const& uri)); | 41 | MOCK_CONST_METHOD1(IsPrefixOpened, bool(std::string const& uri)); |
161 | 41 | MOCK_CONST_METHOD0(IsTrashOpened, bool()); | 42 | MOCK_CONST_METHOD0(IsTrashOpened, bool()); |
162 | 42 | 43 | ||
163 | === modified file 'tests/test_volume_launcher_icon.cpp' | |||
164 | --- tests/test_volume_launcher_icon.cpp 2013-10-07 16:49:04 +0000 | |||
165 | +++ tests/test_volume_launcher_icon.cpp 2013-10-07 22:37:56 +0000 | |||
166 | @@ -42,10 +42,6 @@ | |||
167 | 42 | { | 42 | { |
168 | 43 | SetupVolumeDefaultBehavior(); | 43 | SetupVolumeDefaultBehavior(); |
169 | 44 | SetupSettingsDefaultBehavior(); | 44 | SetupSettingsDefaultBehavior(); |
170 | 45 | } | ||
171 | 46 | |||
172 | 47 | void CreateIcon() | ||
173 | 48 | { | ||
174 | 49 | icon_ = new NiceMock<VolumeLauncherIcon>(volume_, settings_, notifications_, file_manager_); | 45 | icon_ = new NiceMock<VolumeLauncherIcon>(volume_, settings_, notifications_, file_manager_); |
175 | 50 | } | 46 | } |
176 | 51 | 47 | ||
177 | @@ -88,13 +84,25 @@ | |||
178 | 88 | std::string old_lang_; | 84 | std::string old_lang_; |
179 | 89 | }; | 85 | }; |
180 | 90 | 86 | ||
181 | 87 | struct TestVolumeLauncherIconDelayedConstruction : TestVolumeLauncherIcon | ||
182 | 88 | { | ||
183 | 89 | TestVolumeLauncherIconDelayedConstruction() | ||
184 | 90 | { | ||
185 | 91 | icon_ = nullptr; | ||
186 | 92 | } | ||
187 | 93 | |||
188 | 94 | void CreateIcon() | ||
189 | 95 | { | ||
190 | 96 | icon_ = new NiceMock<VolumeLauncherIcon>(volume_, settings_, notifications_, file_manager_); | ||
191 | 97 | } | ||
192 | 98 | }; | ||
193 | 99 | |||
194 | 91 | TEST_F(TestVolumeLauncherIcon, TestIconType) | 100 | TEST_F(TestVolumeLauncherIcon, TestIconType) |
195 | 92 | { | 101 | { |
196 | 93 | CreateIcon(); | ||
197 | 94 | EXPECT_EQ(icon_->GetIconType(), AbstractLauncherIcon::IconType::DEVICE); | 102 | EXPECT_EQ(icon_->GetIconType(), AbstractLauncherIcon::IconType::DEVICE); |
198 | 95 | } | 103 | } |
199 | 96 | 104 | ||
201 | 97 | TEST_F(TestVolumeLauncherIcon, TestRunningOnClosed) | 105 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestRunningOnClosed) |
202 | 98 | { | 106 | { |
203 | 99 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false)); | 107 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false)); |
204 | 100 | CreateIcon(); | 108 | CreateIcon(); |
205 | @@ -102,7 +110,7 @@ | |||
206 | 102 | EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); | 110 | EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); |
207 | 103 | } | 111 | } |
208 | 104 | 112 | ||
210 | 105 | TEST_F(TestVolumeLauncherIcon, TestRunningOnOpened) | 113 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestRunningOnOpened) |
211 | 106 | { | 114 | { |
212 | 107 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true)); | 115 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true)); |
213 | 108 | CreateIcon(); | 116 | CreateIcon(); |
214 | @@ -112,7 +120,6 @@ | |||
215 | 112 | 120 | ||
216 | 113 | TEST_F(TestVolumeLauncherIcon, FilemanagerSignalDisconnection) | 121 | TEST_F(TestVolumeLauncherIcon, FilemanagerSignalDisconnection) |
217 | 114 | { | 122 | { |
218 | 115 | CreateIcon(); | ||
219 | 116 | ASSERT_FALSE(file_manager_->locations_changed.empty()); | 123 | ASSERT_FALSE(file_manager_->locations_changed.empty()); |
220 | 117 | icon_ = nullptr; | 124 | icon_ = nullptr; |
221 | 118 | EXPECT_TRUE(file_manager_->locations_changed.empty()); | 125 | EXPECT_TRUE(file_manager_->locations_changed.empty()); |
222 | @@ -120,8 +127,6 @@ | |||
223 | 120 | 127 | ||
224 | 121 | TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedClosed) | 128 | TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedClosed) |
225 | 122 | { | 129 | { |
226 | 123 | CreateIcon(); | ||
227 | 124 | |||
228 | 125 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false)); | 130 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(false)); |
229 | 126 | file_manager_->locations_changed.emit(); | 131 | file_manager_->locations_changed.emit(); |
230 | 127 | EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); | 132 | EXPECT_FALSE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); |
231 | @@ -129,8 +134,6 @@ | |||
232 | 129 | 134 | ||
233 | 130 | TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedOpened) | 135 | TEST_F(TestVolumeLauncherIcon, TestRunningStateOnLocationChangedOpened) |
234 | 131 | { | 136 | { |
235 | 132 | CreateIcon(); | ||
236 | 133 | |||
237 | 134 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true)); | 137 | ON_CALL(*file_manager_, IsPrefixOpened(volume_->GetUri())).WillByDefault(Return(true)); |
238 | 135 | file_manager_->locations_changed.emit(); | 138 | file_manager_->locations_changed.emit(); |
239 | 136 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); | 139 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::RUNNING)); |
240 | @@ -138,39 +141,30 @@ | |||
241 | 138 | 141 | ||
242 | 139 | TEST_F(TestVolumeLauncherIcon, TestPosition) | 142 | TEST_F(TestVolumeLauncherIcon, TestPosition) |
243 | 140 | { | 143 | { |
244 | 141 | CreateIcon(); | ||
245 | 142 | |||
246 | 143 | EXPECT_EQ(icon_->position(), AbstractLauncherIcon::Position::FLOATING); | 144 | EXPECT_EQ(icon_->position(), AbstractLauncherIcon::Position::FLOATING); |
247 | 144 | } | 145 | } |
248 | 145 | 146 | ||
249 | 146 | TEST_F(TestVolumeLauncherIcon, TestTooltipText) | 147 | TEST_F(TestVolumeLauncherIcon, TestTooltipText) |
250 | 147 | { | 148 | { |
254 | 148 | CreateIcon(); | 149 | EXPECT_EQ(volume_->GetName(), icon_->tooltip_text()); |
252 | 149 | |||
253 | 150 | ASSERT_EQ(icon_->tooltip_text, "Test Name"); | ||
255 | 151 | } | 150 | } |
256 | 152 | 151 | ||
257 | 153 | TEST_F(TestVolumeLauncherIcon, TestIconName) | 152 | TEST_F(TestVolumeLauncherIcon, TestIconName) |
258 | 154 | { | 153 | { |
262 | 155 | CreateIcon(); | 154 | EXPECT_EQ(volume_->GetIconName(), icon_->icon_name()); |
260 | 156 | |||
261 | 157 | ASSERT_EQ(icon_->icon_name, "Test Icon Name"); | ||
263 | 158 | } | 155 | } |
264 | 159 | 156 | ||
265 | 160 | TEST_F(TestVolumeLauncherIcon, TestVisibility_InitiallyMountedVolume) | 157 | TEST_F(TestVolumeLauncherIcon, TestVisibility_InitiallyMountedVolume) |
266 | 161 | { | 158 | { |
267 | 162 | CreateIcon(); | ||
268 | 163 | |||
269 | 164 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)); | 159 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)); |
270 | 165 | } | 160 | } |
271 | 166 | 161 | ||
272 | 167 | TEST_F(TestVolumeLauncherIcon, RemoteUri) | 162 | TEST_F(TestVolumeLauncherIcon, RemoteUri) |
273 | 168 | { | 163 | { |
274 | 169 | CreateIcon(); | ||
275 | 170 | EXPECT_EQ(icon_->GetRemoteUri(), FavoriteStore::URI_PREFIX_DEVICE + volume_->GetIdentifier()); | 164 | EXPECT_EQ(icon_->GetRemoteUri(), FavoriteStore::URI_PREFIX_DEVICE + volume_->GetIdentifier()); |
276 | 171 | } | 165 | } |
277 | 172 | 166 | ||
279 | 173 | TEST_F(TestVolumeLauncherIcon, TestVisibility_InitiallyMountedBlacklistedVolume) | 167 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestVisibility_InitiallyMountedBlacklistedVolume) |
280 | 174 | { | 168 | { |
281 | 175 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) | 169 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) |
282 | 176 | .WillRepeatedly(Return(true)); | 170 | .WillRepeatedly(Return(true)); |
283 | @@ -181,7 +175,7 @@ | |||
284 | 181 | } | 175 | } |
285 | 182 | 176 | ||
286 | 183 | 177 | ||
288 | 184 | TEST_F(TestVolumeLauncherIcon, TestVisibility_InitiallyUnmountedVolume) | 178 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestVisibility_InitiallyUnmountedVolume) |
289 | 185 | { | 179 | { |
290 | 186 | EXPECT_CALL(*volume_, IsMounted()) | 180 | EXPECT_CALL(*volume_, IsMounted()) |
291 | 187 | .WillRepeatedly(Return(false)); | 181 | .WillRepeatedly(Return(false)); |
292 | @@ -192,7 +186,7 @@ | |||
293 | 192 | } | 186 | } |
294 | 193 | 187 | ||
295 | 194 | 188 | ||
297 | 195 | TEST_F(TestVolumeLauncherIcon, TestVisibility_InitiallyUnmountedBlacklistedVolume) | 189 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestVisibility_InitiallyUnmountedBlacklistedVolume) |
298 | 196 | { | 190 | { |
299 | 197 | EXPECT_CALL(*volume_, IsMounted()) | 191 | EXPECT_CALL(*volume_, IsMounted()) |
300 | 198 | .WillRepeatedly(Return(false)); | 192 | .WillRepeatedly(Return(false)); |
301 | @@ -207,8 +201,6 @@ | |||
302 | 207 | 201 | ||
303 | 208 | TEST_F(TestVolumeLauncherIcon, TestSettingsChangedSignal) | 202 | TEST_F(TestVolumeLauncherIcon, TestSettingsChangedSignal) |
304 | 209 | { | 203 | { |
305 | 210 | CreateIcon(); | ||
306 | 211 | |||
307 | 212 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) | 204 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) |
308 | 213 | .WillRepeatedly(Return(true)); | 205 | .WillRepeatedly(Return(true)); |
309 | 214 | settings_->changed.emit(); | 206 | settings_->changed.emit(); |
310 | @@ -218,8 +210,6 @@ | |||
311 | 218 | 210 | ||
312 | 219 | TEST_F(TestVolumeLauncherIcon, TestVisibilityAfterUnmount) | 211 | TEST_F(TestVolumeLauncherIcon, TestVisibilityAfterUnmount) |
313 | 220 | { | 212 | { |
314 | 221 | CreateIcon(); | ||
315 | 222 | |||
316 | 223 | EXPECT_CALL(*volume_, IsMounted()) | 213 | EXPECT_CALL(*volume_, IsMounted()) |
317 | 224 | .WillRepeatedly(Return(false)); | 214 | .WillRepeatedly(Return(false)); |
318 | 225 | 215 | ||
319 | @@ -231,7 +221,7 @@ | |||
320 | 231 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)); | 221 | EXPECT_TRUE(icon_->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)); |
321 | 232 | } | 222 | } |
322 | 233 | 223 | ||
324 | 234 | TEST_F(TestVolumeLauncherIcon, TestVisibilityAfterUnmount_BlacklistedVolume) | 224 | TEST_F(TestVolumeLauncherIconDelayedConstruction, TestVisibilityAfterUnmount_BlacklistedVolume) |
325 | 235 | { | 225 | { |
326 | 236 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) | 226 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) |
327 | 237 | .WillRepeatedly(Return(true)); | 227 | .WillRepeatedly(Return(true)); |
328 | @@ -254,16 +244,12 @@ | |||
329 | 254 | EXPECT_CALL(*volume_, GetIdentifier()) | 244 | EXPECT_CALL(*volume_, GetIdentifier()) |
330 | 255 | .WillRepeatedly(Return("")); | 245 | .WillRepeatedly(Return("")); |
331 | 256 | 246 | ||
332 | 257 | CreateIcon(); | ||
333 | 258 | |||
334 | 259 | for (auto menuitem : icon_->GetMenus()) | 247 | for (auto menuitem : icon_->GetMenus()) |
335 | 260 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); | 248 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); |
336 | 261 | } | 249 | } |
337 | 262 | 250 | ||
338 | 263 | TEST_F(TestVolumeLauncherIcon, TestUnlockFromLauncherMenuItem_Success) | 251 | TEST_F(TestVolumeLauncherIcon, TestUnlockFromLauncherMenuItem_Success) |
339 | 264 | { | 252 | { |
340 | 265 | CreateIcon(); | ||
341 | 266 | |||
342 | 267 | auto menuitem = GetMenuItemAtIndex(4); | 253 | auto menuitem = GetMenuItemAtIndex(4); |
343 | 268 | 254 | ||
344 | 269 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); | 255 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); |
345 | @@ -284,8 +270,6 @@ | |||
346 | 284 | 270 | ||
347 | 285 | TEST_F(TestVolumeLauncherIcon, TestUnlockFromLauncherMenuItem_Failure) | 271 | TEST_F(TestVolumeLauncherIcon, TestUnlockFromLauncherMenuItem_Failure) |
348 | 286 | { | 272 | { |
349 | 287 | CreateIcon(); | ||
350 | 288 | |||
351 | 289 | auto menuitem = GetMenuItemAtIndex(4); | 273 | auto menuitem = GetMenuItemAtIndex(4); |
352 | 290 | 274 | ||
353 | 291 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); | 275 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unlock from Launcher"); |
354 | @@ -302,8 +286,6 @@ | |||
355 | 302 | 286 | ||
356 | 303 | TEST_F(TestVolumeLauncherIcon, TestOpenMenuItem) | 287 | TEST_F(TestVolumeLauncherIcon, TestOpenMenuItem) |
357 | 304 | { | 288 | { |
358 | 305 | CreateIcon(); | ||
359 | 306 | |||
360 | 307 | auto menuitem = GetMenuItemAtIndex(0); | 289 | auto menuitem = GetMenuItemAtIndex(0); |
361 | 308 | 290 | ||
362 | 309 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Open"); | 291 | ASSERT_STREQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Open"); |
363 | @@ -312,6 +294,8 @@ | |||
364 | 312 | 294 | ||
365 | 313 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); | 295 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); |
366 | 314 | uint64_t time = g_random_int(); | 296 | uint64_t time = g_random_int(); |
367 | 297 | |||
368 | 298 | InSequence seq; | ||
369 | 315 | EXPECT_CALL(*volume_, Mount()); | 299 | EXPECT_CALL(*volume_, Mount()); |
370 | 316 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); | 300 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); |
371 | 317 | 301 | ||
372 | @@ -320,8 +304,6 @@ | |||
373 | 320 | 304 | ||
374 | 321 | TEST_F(TestVolumeLauncherIcon, TestNameMenuItem) | 305 | TEST_F(TestVolumeLauncherIcon, TestNameMenuItem) |
375 | 322 | { | 306 | { |
376 | 323 | CreateIcon(); | ||
377 | 324 | |||
378 | 325 | auto menuitem = GetMenuItemAtIndex(2); | 307 | auto menuitem = GetMenuItemAtIndex(2); |
379 | 326 | 308 | ||
380 | 327 | EXPECT_EQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "<b>" + volume_->GetName() + "</b>"); | 309 | EXPECT_EQ(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "<b>" + volume_->GetName() + "</b>"); |
381 | @@ -331,6 +313,8 @@ | |||
382 | 331 | 313 | ||
383 | 332 | uint64_t time = g_random_int(); | 314 | uint64_t time = g_random_int(); |
384 | 333 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); | 315 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); |
385 | 316 | |||
386 | 317 | InSequence seq; | ||
387 | 334 | EXPECT_CALL(*volume_, Mount()); | 318 | EXPECT_CALL(*volume_, Mount()); |
388 | 335 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); | 319 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); |
389 | 336 | 320 | ||
390 | @@ -339,8 +323,6 @@ | |||
391 | 339 | 323 | ||
392 | 340 | TEST_F(TestVolumeLauncherIcon, TestEjectMenuItem_NotEjectableVolume) | 324 | TEST_F(TestVolumeLauncherIcon, TestEjectMenuItem_NotEjectableVolume) |
393 | 341 | { | 325 | { |
394 | 342 | CreateIcon(); | ||
395 | 343 | |||
396 | 344 | for (auto menuitem : icon_->GetMenus()) | 326 | for (auto menuitem : icon_->GetMenus()) |
397 | 345 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Eject"); | 327 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Eject"); |
398 | 346 | } | 328 | } |
399 | @@ -350,8 +332,6 @@ | |||
400 | 350 | EXPECT_CALL(*volume_, CanBeEjected()) | 332 | EXPECT_CALL(*volume_, CanBeEjected()) |
401 | 351 | .WillRepeatedly(Return(true)); | 333 | .WillRepeatedly(Return(true)); |
402 | 352 | 334 | ||
403 | 353 | CreateIcon(); | ||
404 | 354 | |||
405 | 355 | auto menuitem = GetMenuItemAtIndex(5); | 335 | auto menuitem = GetMenuItemAtIndex(5); |
406 | 356 | 336 | ||
407 | 357 | EXPECT_CALL(*volume_, Eject()); | 337 | EXPECT_CALL(*volume_, Eject()); |
408 | @@ -366,8 +346,6 @@ | |||
409 | 366 | 346 | ||
410 | 367 | TEST_F(TestVolumeLauncherIcon, TestEjectMenuItem_NotStoppableVolume) | 347 | TEST_F(TestVolumeLauncherIcon, TestEjectMenuItem_NotStoppableVolume) |
411 | 368 | { | 348 | { |
412 | 369 | CreateIcon(); | ||
413 | 370 | |||
414 | 371 | for (auto menuitem : icon_->GetMenus()) | 349 | for (auto menuitem : icon_->GetMenus()) |
415 | 372 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Safely remove"); | 350 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Safely remove"); |
416 | 373 | } | 351 | } |
417 | @@ -377,8 +355,6 @@ | |||
418 | 377 | EXPECT_CALL(*volume_, CanBeStopped()) | 355 | EXPECT_CALL(*volume_, CanBeStopped()) |
419 | 378 | .WillRepeatedly(Return(true)); | 356 | .WillRepeatedly(Return(true)); |
420 | 379 | 357 | ||
421 | 380 | CreateIcon(); | ||
422 | 381 | |||
423 | 382 | auto menuitem = GetMenuItemAtIndex(5); | 358 | auto menuitem = GetMenuItemAtIndex(5); |
424 | 383 | 359 | ||
425 | 384 | EXPECT_CALL(*volume_, StopDrive()) | 360 | EXPECT_CALL(*volume_, StopDrive()) |
426 | @@ -396,8 +372,6 @@ | |||
427 | 396 | EXPECT_CALL(*volume_, IsMounted()) | 372 | EXPECT_CALL(*volume_, IsMounted()) |
428 | 397 | .WillRepeatedly(Return(false)); | 373 | .WillRepeatedly(Return(false)); |
429 | 398 | 374 | ||
430 | 399 | CreateIcon(); | ||
431 | 400 | |||
432 | 401 | for (auto menuitem : icon_->GetMenus()) | 375 | for (auto menuitem : icon_->GetMenus()) |
433 | 402 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); | 376 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); |
434 | 403 | } | 377 | } |
435 | @@ -408,11 +382,6 @@ | |||
436 | 408 | EXPECT_CALL(*volume_, CanBeEjected()) | 382 | EXPECT_CALL(*volume_, CanBeEjected()) |
437 | 409 | .WillRepeatedly(Return(true)); | 383 | .WillRepeatedly(Return(true)); |
438 | 410 | 384 | ||
439 | 411 | EXPECT_CALL(*volume_, IsMounted()) | ||
440 | 412 | .WillRepeatedly(Return(true)); | ||
441 | 413 | |||
442 | 414 | CreateIcon(); | ||
443 | 415 | |||
444 | 416 | for (auto menuitem : icon_->GetMenus()) | 385 | for (auto menuitem : icon_->GetMenus()) |
445 | 417 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); | 386 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); |
446 | 418 | } | 387 | } |
447 | @@ -422,22 +391,12 @@ | |||
448 | 422 | EXPECT_CALL(*volume_, CanBeStopped()) | 391 | EXPECT_CALL(*volume_, CanBeStopped()) |
449 | 423 | .WillRepeatedly(Return(true)); | 392 | .WillRepeatedly(Return(true)); |
450 | 424 | 393 | ||
451 | 425 | EXPECT_CALL(*volume_, IsMounted()) | ||
452 | 426 | .WillRepeatedly(Return(true)); | ||
453 | 427 | |||
454 | 428 | CreateIcon(); | ||
455 | 429 | |||
456 | 430 | for (auto menuitem : icon_->GetMenus()) | 394 | for (auto menuitem : icon_->GetMenus()) |
457 | 431 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); | 395 | ASSERT_STRNE(dbusmenu_menuitem_property_get(menuitem, DBUSMENU_MENUITEM_PROP_LABEL), "Unmount"); |
458 | 432 | } | 396 | } |
459 | 433 | 397 | ||
460 | 434 | TEST_F(TestVolumeLauncherIcon, TestUnmountMenuItem) | 398 | TEST_F(TestVolumeLauncherIcon, TestUnmountMenuItem) |
461 | 435 | { | 399 | { |
462 | 436 | EXPECT_CALL(*volume_, IsMounted()) | ||
463 | 437 | .WillRepeatedly(Return(true)); | ||
464 | 438 | |||
465 | 439 | CreateIcon(); | ||
466 | 440 | |||
467 | 441 | auto menuitem = GetMenuItemAtIndex(5); | 400 | auto menuitem = GetMenuItemAtIndex(5); |
468 | 442 | 401 | ||
469 | 443 | EXPECT_CALL(*volume_, Unmount()) | 402 | EXPECT_CALL(*volume_, Unmount()) |
470 | @@ -452,8 +411,6 @@ | |||
471 | 452 | 411 | ||
472 | 453 | TEST_F(TestVolumeLauncherIcon, TestCanBeEject) | 412 | TEST_F(TestVolumeLauncherIcon, TestCanBeEject) |
473 | 454 | { | 413 | { |
474 | 455 | CreateIcon(); | ||
475 | 456 | |||
476 | 457 | EXPECT_CALL(*volume_, CanBeEjected()) | 414 | EXPECT_CALL(*volume_, CanBeEjected()) |
477 | 458 | .WillRepeatedly(Return(true)); | 415 | .WillRepeatedly(Return(true)); |
478 | 459 | ASSERT_TRUE(icon_->CanEject()); | 416 | ASSERT_TRUE(icon_->CanEject()); |
479 | @@ -469,8 +426,6 @@ | |||
480 | 469 | EXPECT_CALL(*volume_, CanBeEjected()) | 426 | EXPECT_CALL(*volume_, CanBeEjected()) |
481 | 470 | .WillRepeatedly(Return(true)); | 427 | .WillRepeatedly(Return(true)); |
482 | 471 | 428 | ||
483 | 472 | CreateIcon(); | ||
484 | 473 | |||
485 | 474 | EXPECT_CALL(*volume_, Eject()); | 429 | EXPECT_CALL(*volume_, Eject()); |
486 | 475 | EXPECT_CALL(*notifications_, Display(volume_->GetIconName(), volume_->GetName())); | 430 | EXPECT_CALL(*notifications_, Display(volume_->GetIconName(), volume_->GetName())); |
487 | 476 | icon_->EjectAndShowNotification(); | 431 | icon_->EjectAndShowNotification(); |
488 | @@ -478,8 +433,6 @@ | |||
489 | 478 | 433 | ||
490 | 479 | TEST_F(TestVolumeLauncherIcon, OnRemoved) | 434 | TEST_F(TestVolumeLauncherIcon, OnRemoved) |
491 | 480 | { | 435 | { |
492 | 481 | CreateIcon(); | ||
493 | 482 | |||
494 | 483 | EXPECT_CALL(*settings_, TryToBlacklist(_)) | 436 | EXPECT_CALL(*settings_, TryToBlacklist(_)) |
495 | 484 | .Times(0); | 437 | .Times(0); |
496 | 485 | EXPECT_CALL(*settings_, TryToUnblacklist(_)) | 438 | EXPECT_CALL(*settings_, TryToUnblacklist(_)) |
497 | @@ -492,7 +445,6 @@ | |||
498 | 492 | { | 445 | { |
499 | 493 | EXPECT_CALL(*volume_, CanBeRemoved()) | 446 | EXPECT_CALL(*volume_, CanBeRemoved()) |
500 | 494 | .WillRepeatedly(Return(true)); | 447 | .WillRepeatedly(Return(true)); |
501 | 495 | CreateIcon(); | ||
502 | 496 | 448 | ||
503 | 497 | EXPECT_CALL(*settings_, TryToBlacklist(_)) | 449 | EXPECT_CALL(*settings_, TryToBlacklist(_)) |
504 | 498 | .Times(0); | 450 | .Times(0); |
505 | @@ -508,7 +460,6 @@ | |||
506 | 508 | .WillRepeatedly(Return(true)); | 460 | .WillRepeatedly(Return(true)); |
507 | 509 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) | 461 | EXPECT_CALL(*settings_, IsABlacklistedDevice(_)) |
508 | 510 | .WillRepeatedly(Return(true)); | 462 | .WillRepeatedly(Return(true)); |
509 | 511 | CreateIcon(); | ||
510 | 512 | 463 | ||
511 | 513 | EXPECT_CALL(*settings_, TryToBlacklist(_)) | 464 | EXPECT_CALL(*settings_, TryToBlacklist(_)) |
512 | 514 | .Times(0); | 465 | .Times(0); |
513 | @@ -520,8 +471,6 @@ | |||
514 | 520 | 471 | ||
515 | 521 | TEST_F(TestVolumeLauncherIcon, Stick) | 472 | TEST_F(TestVolumeLauncherIcon, Stick) |
516 | 522 | { | 473 | { |
517 | 523 | CreateIcon(); | ||
518 | 524 | |||
519 | 525 | bool saved = false; | 474 | bool saved = false; |
520 | 526 | icon_->position_saved.connect([&saved] {saved = true;}); | 475 | icon_->position_saved.connect([&saved] {saved = true;}); |
521 | 527 | 476 | ||
522 | @@ -534,8 +483,6 @@ | |||
523 | 534 | 483 | ||
524 | 535 | TEST_F(TestVolumeLauncherIcon, StickAndSave) | 484 | TEST_F(TestVolumeLauncherIcon, StickAndSave) |
525 | 536 | { | 485 | { |
526 | 537 | CreateIcon(); | ||
527 | 538 | |||
528 | 539 | bool saved = false; | 486 | bool saved = false; |
529 | 540 | icon_->position_saved.connect([&saved] {saved = true;}); | 487 | icon_->position_saved.connect([&saved] {saved = true;}); |
530 | 541 | 488 | ||
531 | @@ -548,8 +495,6 @@ | |||
532 | 548 | 495 | ||
533 | 549 | TEST_F(TestVolumeLauncherIcon, Unstick) | 496 | TEST_F(TestVolumeLauncherIcon, Unstick) |
534 | 550 | { | 497 | { |
535 | 551 | CreateIcon(); | ||
536 | 552 | |||
537 | 553 | bool forgot = false; | 498 | bool forgot = false; |
538 | 554 | icon_->position_forgot.connect([&forgot] {forgot = true;}); | 499 | icon_->position_forgot.connect([&forgot] {forgot = true;}); |
539 | 555 | 500 | ||
540 | @@ -566,9 +511,8 @@ | |||
541 | 566 | 511 | ||
542 | 567 | TEST_F(TestVolumeLauncherIcon, ActivateMounted) | 512 | TEST_F(TestVolumeLauncherIcon, ActivateMounted) |
543 | 568 | { | 513 | { |
544 | 569 | CreateIcon(); | ||
545 | 570 | |||
546 | 571 | uint64_t time = g_random_int(); | 514 | uint64_t time = g_random_int(); |
547 | 515 | InSequence seq; | ||
548 | 572 | EXPECT_CALL(*volume_, Mount()).Times(0); | 516 | EXPECT_CALL(*volume_, Mount()).Times(0); |
549 | 573 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); | 517 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); |
550 | 574 | icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time)); | 518 | icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time)); |
551 | @@ -576,13 +520,67 @@ | |||
552 | 576 | 520 | ||
553 | 577 | TEST_F(TestVolumeLauncherIcon, ActivateUnmounted) | 521 | TEST_F(TestVolumeLauncherIcon, ActivateUnmounted) |
554 | 578 | { | 522 | { |
555 | 579 | CreateIcon(); | ||
556 | 580 | |||
557 | 581 | uint64_t time = g_random_int(); | 523 | uint64_t time = g_random_int(); |
558 | 582 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); | 524 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); |
559 | 525 | InSequence seq; | ||
560 | 583 | EXPECT_CALL(*volume_, Mount()); | 526 | EXPECT_CALL(*volume_, Mount()); |
561 | 584 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); | 527 | EXPECT_CALL(*file_manager_, OpenActiveChild(volume_->GetUri(), time)); |
562 | 585 | icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time)); | 528 | icon_->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, time)); |
563 | 586 | } | 529 | } |
564 | 587 | 530 | ||
565 | 531 | TEST_F(TestVolumeLauncherIcon, ShouldHighlightOnDragFilesValid) | ||
566 | 532 | { | ||
567 | 533 | DndData data; | ||
568 | 534 | std::string data_string = "file://file1\ndir2/file2\nfile://file3\nfile://dirN/fileN"; | ||
569 | 535 | data.Fill(data_string.c_str()); | ||
570 | 536 | EXPECT_TRUE(icon_->ShouldHighlightOnDrag(data)); | ||
571 | 537 | } | ||
572 | 538 | |||
573 | 539 | TEST_F(TestVolumeLauncherIcon, ShouldHighlightOnDragFilesInvalid) | ||
574 | 540 | { | ||
575 | 541 | DndData data; | ||
576 | 542 | std::string data_string = "file1\ndir2/file2\napplication://file3\nunity://lens"; | ||
577 | 543 | data.Fill(data_string.c_str()); | ||
578 | 544 | EXPECT_FALSE(icon_->ShouldHighlightOnDrag(data)); | ||
579 | 545 | } | ||
580 | 546 | |||
581 | 547 | TEST_F(TestVolumeLauncherIcon, QueryAcceptDrop) | ||
582 | 548 | { | ||
583 | 549 | DndData data; | ||
584 | 550 | EXPECT_EQ(nux::DNDACTION_NONE, icon_->QueryAcceptDrop(data)); | ||
585 | 551 | |||
586 | 552 | std::string data_string = "file://foo/file"; | ||
587 | 553 | data.Fill(data_string.c_str()); | ||
588 | 554 | EXPECT_EQ(nux::DNDACTION_COPY, icon_->QueryAcceptDrop(data)); | ||
589 | 555 | } | ||
590 | 556 | |||
591 | 557 | TEST_F(TestVolumeLauncherIcon, AcceptDropUnmounted) | ||
592 | 558 | { | ||
593 | 559 | DndData data; | ||
594 | 560 | std::string data_string = "file://file1\ndir2/file2\nfile://file3\nfile://dirN/fileN"; | ||
595 | 561 | data.Fill(data_string.c_str()); | ||
596 | 562 | auto time = g_random_int(); | ||
597 | 563 | nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp = time; | ||
598 | 564 | |||
599 | 565 | InSequence seq; | ||
600 | 566 | ON_CALL(*volume_, IsMounted()).WillByDefault(Return(false)); | ||
601 | 567 | EXPECT_CALL(*volume_, Mount()); | ||
602 | 568 | EXPECT_CALL(*file_manager_, CopyFiles(data.Uris(), volume_->GetUri(), time)); | ||
603 | 569 | icon_->AcceptDrop(data); | ||
604 | 570 | } | ||
605 | 571 | |||
606 | 572 | TEST_F(TestVolumeLauncherIcon, AcceptDropMounted) | ||
607 | 573 | { | ||
608 | 574 | DndData data; | ||
609 | 575 | std::string data_string = "file://file1\ndir2/file2\nfile://file3\nfile://dirN/fileN"; | ||
610 | 576 | data.Fill(data_string.c_str()); | ||
611 | 577 | auto time = g_random_int(); | ||
612 | 578 | nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp = time; | ||
613 | 579 | |||
614 | 580 | InSequence seq; | ||
615 | 581 | EXPECT_CALL(*volume_, Mount()).Times(0); | ||
616 | 582 | EXPECT_CALL(*file_manager_, CopyFiles(data.Uris(), volume_->GetUri(), time)); | ||
617 | 583 | icon_->AcceptDrop(data); | ||
618 | 584 | } | ||
619 | 585 | |||
620 | 588 | } | 586 | } |
621 | 589 | 587 | ||
622 | === modified file 'unity-shared/FileManager.h' | |||
623 | --- unity-shared/FileManager.h 2013-09-05 16:22:56 +0000 | |||
624 | +++ unity-shared/FileManager.h 2013-10-07 22:37:56 +0000 | |||
625 | @@ -25,6 +25,7 @@ | |||
626 | 25 | #include <vector> | 25 | #include <vector> |
627 | 26 | #include <string> | 26 | #include <string> |
628 | 27 | #include <vector> | 27 | #include <vector> |
629 | 28 | #include <set> | ||
630 | 28 | #include <sigc++/sigc++.h> | 29 | #include <sigc++/sigc++.h> |
631 | 29 | 30 | ||
632 | 30 | namespace unity | 31 | namespace unity |
633 | @@ -45,6 +46,7 @@ | |||
634 | 45 | virtual bool IsPrefixOpened(std::string const& uri) const = 0; | 46 | virtual bool IsPrefixOpened(std::string const& uri) const = 0; |
635 | 46 | virtual bool IsTrashOpened() const = 0; | 47 | virtual bool IsTrashOpened() const = 0; |
636 | 47 | virtual bool IsDeviceOpened() const = 0; | 48 | virtual bool IsDeviceOpened() const = 0; |
637 | 49 | virtual void CopyFiles(std::set<std::string> const& uris, std::string const& dest, uint64_t timestamp = 0) = 0; | ||
638 | 48 | virtual bool TrashFile(std::string const& uri) = 0; | 50 | virtual bool TrashFile(std::string const& uri) = 0; |
639 | 49 | virtual void EmptyTrash(uint64_t timestamp = 0) = 0; | 51 | virtual void EmptyTrash(uint64_t timestamp = 0) = 0; |
640 | 50 | 52 | ||
641 | 51 | 53 | ||
642 | === modified file 'unity-shared/GnomeFileManager.cpp' | |||
643 | --- unity-shared/GnomeFileManager.cpp 2013-10-07 13:29:56 +0000 | |||
644 | +++ unity-shared/GnomeFileManager.cpp 2013-10-07 22:37:56 +0000 | |||
645 | @@ -220,6 +220,38 @@ | |||
646 | 220 | proxy->CallBegin("EmptyTrash", nullptr, [proxy] (GVariant*, glib::Error const&) {}); | 220 | proxy->CallBegin("EmptyTrash", nullptr, [proxy] (GVariant*, glib::Error const&) {}); |
647 | 221 | } | 221 | } |
648 | 222 | 222 | ||
649 | 223 | void GnomeFileManager::CopyFiles(std::set<std::string> const& uris, std::string const& dest, uint64_t timestamp) | ||
650 | 224 | { | ||
651 | 225 | if (uris.empty() || dest.empty()) | ||
652 | 226 | return; | ||
653 | 227 | |||
654 | 228 | bool found_valid = false; | ||
655 | 229 | GVariantBuilder b; | ||
656 | 230 | g_variant_builder_init(&b, G_VARIANT_TYPE("(ass)")); | ||
657 | 231 | g_variant_builder_open(&b, G_VARIANT_TYPE("as")); | ||
658 | 232 | |||
659 | 233 | for (auto const& uri : uris) | ||
660 | 234 | { | ||
661 | 235 | if (uri.find(FILE_SCHEMA) == 0) | ||
662 | 236 | { | ||
663 | 237 | found_valid = true; | ||
664 | 238 | g_variant_builder_add(&b, "s", uri.c_str()); | ||
665 | 239 | } | ||
666 | 240 | } | ||
667 | 241 | |||
668 | 242 | g_variant_builder_close(&b); | ||
669 | 243 | g_variant_builder_add(&b, "s", dest.c_str()); | ||
670 | 244 | glib::Variant parameters(g_variant_builder_end(&b)); | ||
671 | 245 | |||
672 | 246 | if (found_valid) | ||
673 | 247 | { | ||
674 | 248 | // Passing the proxy to the lambda we ensure that it will be destroyed when needed | ||
675 | 249 | auto const& proxy = impl_->NautilusOperationsProxy(); | ||
676 | 250 | proxy->CallBegin("CopyURIs", parameters, [proxy] (GVariant*, glib::Error const&) {}); | ||
677 | 251 | Activate(timestamp); | ||
678 | 252 | } | ||
679 | 253 | } | ||
680 | 254 | |||
681 | 223 | std::vector<std::string> GnomeFileManager::OpenedLocations() const | 255 | std::vector<std::string> GnomeFileManager::OpenedLocations() const |
682 | 224 | { | 256 | { |
683 | 225 | return impl_->opened_locations_; | 257 | return impl_->opened_locations_; |
684 | 226 | 258 | ||
685 | === modified file 'unity-shared/GnomeFileManager.h' | |||
686 | --- unity-shared/GnomeFileManager.h 2013-09-05 16:22:56 +0000 | |||
687 | +++ unity-shared/GnomeFileManager.h 2013-10-07 22:37:56 +0000 | |||
688 | @@ -35,6 +35,8 @@ | |||
689 | 35 | void Open(std::string const& uri, uint64_t timestamp); | 35 | void Open(std::string const& uri, uint64_t timestamp); |
690 | 36 | void OpenActiveChild(std::string const& uri, uint64_t timestamp); | 36 | void OpenActiveChild(std::string const& uri, uint64_t timestamp); |
691 | 37 | void OpenTrash(uint64_t timestamp); | 37 | void OpenTrash(uint64_t timestamp); |
692 | 38 | |||
693 | 39 | void CopyFiles(std::set<std::string> const& uris, std::string const& dest, uint64_t timestamp); | ||
694 | 38 | bool TrashFile(std::string const& uri); | 40 | bool TrashFile(std::string const& uri); |
695 | 39 | void EmptyTrash(uint64_t timestamp); | 41 | void EmptyTrash(uint64_t timestamp); |
696 | 40 | 42 |
Why not using g_file_copy_*?