Merge lp:~ken-vandine/content-hub/pasteboard into lp:content-hub
- pasteboard
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~ken-vandine/content-hub/pasteboard |
Merge into: | lp:content-hub |
Diff against target: |
1288 lines (+1046/-1) 19 files modified
examples/CMakeLists.txt (+1/-0) examples/pasteboard/CMakeLists.txt (+55/-0) examples/pasteboard/copy.cpp (+44/-0) examples/pasteboard/paste.cpp (+45/-0) import/Ubuntu/Content/CMakeLists.txt (+1/-1) include/com/ubuntu/content/hub.h (+4/-0) include/com/ubuntu/content/paste.h (+98/-0) src/com/ubuntu/content/CMakeLists.txt (+12/-0) src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml (+26/-0) src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml (+13/-0) src/com/ubuntu/content/detail/paste.cpp (+166/-0) src/com/ubuntu/content/detail/paste.h (+73/-0) src/com/ubuntu/content/detail/service.cpp (+95/-0) src/com/ubuntu/content/detail/service.h (+4/-0) src/com/ubuntu/content/hub.cpp (+52/-0) src/com/ubuntu/content/paste.cpp (+74/-0) src/com/ubuntu/content/paste_p.h (+138/-0) tests/acceptance-tests/CMakeLists.txt (+9/-0) tests/acceptance-tests/app_hub_communication_paste.cpp (+136/-0) |
To merge this branch: | bzr merge lp:~ken-vandine/content-hub/pasteboard |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+296351@code.launchpad.net |
Commit message
Pasteboard implementation
Description of the change
Pasteboard implementation
- 283. By Ken VanDine
-
fixed header
- 284. By Ken VanDine
-
Removed unused code
- 285. By Ken VanDine
-
Use UAL to ensure the app_id is correct
- 286. By Ken VanDine
-
UAL build fixes
- 287. By Ken VanDine
-
Don't block on returning paste if it doesn't exist
- 288. By Ken VanDine
-
Don't warn on empty pasteboard
- 289. By Ken VanDine
-
Use QMimeData for the Paste payload
- 290. By Ken VanDine
-
removed commented out line
- 291. By Ken VanDine
-
refactored a bit to include the mimeData when calling CreatePaste, cuts down a dbus round trip
- 292. By Ken VanDine
-
Verify app_id_matches for CreatePaste as well
- 293. By Ken VanDine
-
removed unused uuid
- 294. By Ken VanDine
-
Added Hub::pasteFormats property which contains a list of mimetypes available to paste from the pasteboard
- 295. By Ken VanDine
-
merged trunk
- 296. By Ken VanDine
-
Merged API improvements from Daniel d'Andrada, including making createPaste async
- 297. By Ken VanDine
-
Fix from Daniel d'Andrada for memory leak in cuc::Hub:
:createPaste - 298. By Ken VanDine
-
merged trunk
- 299. By Ken VanDine
-
Added pasteboardChanged signal emitted when the stack has changed
- 300. By Ken VanDine
-
Merged fixes from dandrader
- 301. By Ken VanDine
-
Version bump to reflect Pasteboard implemention
- 302. By Ken VanDine
-
Fix app_id_matches()
- 303. By Ken VanDine
-
Only check if the appId matches for creating pastes
- 304. By Ken VanDine
-
spelling
- 305. By Ken VanDine
-
Only send paste to an app that is currently focused, thanks to Daniel d'Andrada
- 306. By Ken VanDine
-
Limit stack size to 5
- 307. By Ken VanDine
-
Remove public API state from Paste
- 308. By Ken VanDine
-
Don't check isPidFocused from Unity8 while under testing
- 309. By Ken VanDine
-
Don't register Paste object path when requesting a paste, we control access to that via isPidFocus from Unity8
- 310. By Ken VanDine
-
Return a bool from CreatePaste and don't register object path during CreatePaste
- 311. By Ken VanDine
-
removed unneeded handle_pastes
- 312. By Ken VanDine
-
Updated version
- 313. By Ken VanDine
-
Ported MimeDataSeriali
zation from qtmir - 314. By Ken VanDine
-
Make app_id matches non-fatal for CreatePaste
- 315. By Ken VanDine
-
merged trunk
- 316. By Ken VanDine
-
Daniel d'Andrada 2016-08-23 Authenticate using surface ids instead of process ids
- 317. By Ken VanDine
-
Daniel d'Andrada 2016-08-24 Improve PasteFormatsChanged
Unmerged revisions
Preview Diff
1 | === modified file 'examples/CMakeLists.txt' | |||
2 | --- examples/CMakeLists.txt 2013-08-27 22:15:29 +0000 | |||
3 | +++ examples/CMakeLists.txt 2016-06-02 17:19:28 +0000 | |||
4 | @@ -16,3 +16,4 @@ | |||
5 | 16 | 16 | ||
6 | 17 | add_subdirectory(importer) | 17 | add_subdirectory(importer) |
7 | 18 | add_subdirectory(exporter) | 18 | add_subdirectory(exporter) |
8 | 19 | add_subdirectory(pasteboard) | ||
9 | 19 | 20 | ||
10 | === added directory 'examples/pasteboard' | |||
11 | === added file 'examples/pasteboard/CMakeLists.txt' | |||
12 | --- examples/pasteboard/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
13 | +++ examples/pasteboard/CMakeLists.txt 2016-06-02 17:19:28 +0000 | |||
14 | @@ -0,0 +1,55 @@ | |||
15 | 1 | # Copyright © 2016 Canonical Ltd. | ||
16 | 2 | # | ||
17 | 3 | # This program is free software: you can redistribute it and/or modify | ||
18 | 4 | # it under the terms of the GNU General Public License version 3 as | ||
19 | 5 | # published by the Free Software Foundation. | ||
20 | 6 | # | ||
21 | 7 | # This program is distributed in the hope that it will be useful, | ||
22 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
23 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
24 | 10 | # GNU General Public License for more details. | ||
25 | 11 | # | ||
26 | 12 | # You should have received a copy of the GNU General Public License | ||
27 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
28 | 14 | # | ||
29 | 15 | # Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
30 | 16 | |||
31 | 17 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
32 | 18 | |||
33 | 19 | add_executable( | ||
34 | 20 | copy-to-pasteboard | ||
35 | 21 | |||
36 | 22 | copy.cpp | ||
37 | 23 | ) | ||
38 | 24 | |||
39 | 25 | qt5_use_modules(copy-to-pasteboard Core Gui DBus) | ||
40 | 26 | |||
41 | 27 | set_target_properties( | ||
42 | 28 | copy-to-pasteboard | ||
43 | 29 | PROPERTIES | ||
44 | 30 | AUTOMOC TRUE | ||
45 | 31 | ) | ||
46 | 32 | |||
47 | 33 | target_link_libraries( | ||
48 | 34 | copy-to-pasteboard | ||
49 | 35 | content-hub | ||
50 | 36 | ) | ||
51 | 37 | |||
52 | 38 | add_executable( | ||
53 | 39 | paste-from-pasteboard | ||
54 | 40 | |||
55 | 41 | paste.cpp | ||
56 | 42 | ) | ||
57 | 43 | |||
58 | 44 | qt5_use_modules(paste-from-pasteboard Core Gui DBus) | ||
59 | 45 | |||
60 | 46 | set_target_properties( | ||
61 | 47 | paste-from-pasteboard | ||
62 | 48 | PROPERTIES | ||
63 | 49 | AUTOMOC TRUE | ||
64 | 50 | ) | ||
65 | 51 | |||
66 | 52 | target_link_libraries( | ||
67 | 53 | paste-from-pasteboard | ||
68 | 54 | content-hub | ||
69 | 55 | ) | ||
70 | 0 | 56 | ||
71 | === added file 'examples/pasteboard/copy.cpp' | |||
72 | --- examples/pasteboard/copy.cpp 1970-01-01 00:00:00 +0000 | |||
73 | +++ examples/pasteboard/copy.cpp 2016-06-02 17:19:28 +0000 | |||
74 | @@ -0,0 +1,44 @@ | |||
75 | 1 | /* | ||
76 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
77 | 3 | * | ||
78 | 4 | * This program is free software; you can redistribute it and/or modify | ||
79 | 5 | * it under the terms of the GNU General Public License as published by | ||
80 | 6 | * the Free Software Foundation; version 3. | ||
81 | 7 | * | ||
82 | 8 | * This program is distributed in the hope that it will be useful, | ||
83 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
84 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
85 | 11 | * GNU General Public License for more details. | ||
86 | 12 | * | ||
87 | 13 | * You should have received a copy of the GNU General Public License | ||
88 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
89 | 15 | * | ||
90 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
91 | 17 | */ | ||
92 | 18 | |||
93 | 19 | #include <QCoreApplication> | ||
94 | 20 | #include <QDebug> | ||
95 | 21 | #include <QStringList> | ||
96 | 22 | #include <com/ubuntu/content/hub.h> | ||
97 | 23 | #include <com/ubuntu/content/paste.h> | ||
98 | 24 | |||
99 | 25 | namespace cuc = com::ubuntu::content; | ||
100 | 26 | |||
101 | 27 | int main(int argc, char *argv[]) | ||
102 | 28 | { | ||
103 | 29 | QCoreApplication a(argc, argv); | ||
104 | 30 | if (qgetenv("APP_ID").isEmpty()) { | ||
105 | 31 | qputenv("APP_ID", "copy-to-pasteboard"); | ||
106 | 32 | } | ||
107 | 33 | |||
108 | 34 | QString text("Some text"); | ||
109 | 35 | |||
110 | 36 | if (a.arguments().size() > 1) | ||
111 | 37 | text = a.arguments().at(1); | ||
112 | 38 | |||
113 | 39 | const char * data = text.toStdString().c_str(); | ||
114 | 40 | auto hub = cuc::Hub::Client::instance(); | ||
115 | 41 | |||
116 | 42 | auto paste = hub->create_paste(data); | ||
117 | 43 | qDebug() << paste->id() << ":" << text; | ||
118 | 44 | } | ||
119 | 0 | 45 | ||
120 | === added file 'examples/pasteboard/paste.cpp' | |||
121 | --- examples/pasteboard/paste.cpp 1970-01-01 00:00:00 +0000 | |||
122 | +++ examples/pasteboard/paste.cpp 2016-06-02 17:19:28 +0000 | |||
123 | @@ -0,0 +1,45 @@ | |||
124 | 1 | /* | ||
125 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
126 | 3 | * | ||
127 | 4 | * This program is free software; you can redistribute it and/or modify | ||
128 | 5 | * it under the terms of the GNU General Public License as published by | ||
129 | 6 | * the Free Software Foundation; version 3. | ||
130 | 7 | * | ||
131 | 8 | * This program is distributed in the hope that it will be useful, | ||
132 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
133 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
134 | 11 | * GNU General Public License for more details. | ||
135 | 12 | * | ||
136 | 13 | * You should have received a copy of the GNU General Public License | ||
137 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
138 | 15 | * | ||
139 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
140 | 17 | */ | ||
141 | 18 | |||
142 | 19 | #include <QCoreApplication> | ||
143 | 20 | #include <QStringList> | ||
144 | 21 | #include <com/ubuntu/content/hub.h> | ||
145 | 22 | |||
146 | 23 | namespace cuc = com::ubuntu::content; | ||
147 | 24 | |||
148 | 25 | int main(int argc, char *argv[]) | ||
149 | 26 | { | ||
150 | 27 | QCoreApplication a(argc, argv); | ||
151 | 28 | if (qgetenv("APP_ID").isEmpty()) { | ||
152 | 29 | qputenv("APP_ID", "paste-from-pasteboard"); | ||
153 | 30 | } | ||
154 | 31 | |||
155 | 32 | QString id("latest"); | ||
156 | 33 | |||
157 | 34 | if (a.arguments().size() > 1) | ||
158 | 35 | id = a.arguments().at(1); | ||
159 | 36 | |||
160 | 37 | auto hub = cuc::Hub::Client::instance(); | ||
161 | 38 | const char* buf = NULL; | ||
162 | 39 | if (id == "latest") | ||
163 | 40 | buf = hub->latest_paste_buf(); | ||
164 | 41 | else | ||
165 | 42 | buf = hub->paste_buf_by_id(id.toInt()); | ||
166 | 43 | qDebug() << id << ":" << buf; | ||
167 | 44 | return 0; | ||
168 | 45 | } | ||
169 | 0 | 46 | ||
170 | === modified file 'import/Ubuntu/Content/CMakeLists.txt' | |||
171 | --- import/Ubuntu/Content/CMakeLists.txt 2015-10-24 00:24:30 +0000 | |||
172 | +++ import/Ubuntu/Content/CMakeLists.txt 2016-06-02 17:19:28 +0000 | |||
173 | @@ -101,7 +101,7 @@ | |||
174 | 101 | endif() | 101 | endif() |
175 | 102 | 102 | ||
176 | 103 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes | 103 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes |
178 | 104 | COMMAND ${QT_INSTALL_BINS}/qmlplugindump -notrelocatable Ubuntu.Content 1.1 ../../ > ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes | 104 | COMMAND ${QT_INSTALL_BINS}/qmlplugindump -noinstantiate -notrelocatable Ubuntu.Content 1.1 ../../ > ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes |
179 | 105 | DEPENDS ${PLUGIN} | 105 | DEPENDS ${PLUGIN} |
180 | 106 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | 106 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
181 | 107 | ) | 107 | ) |
182 | 108 | 108 | ||
183 | === modified file 'include/com/ubuntu/content/hub.h' | |||
184 | --- include/com/ubuntu/content/hub.h 2015-09-29 13:15:58 +0000 | |||
185 | +++ include/com/ubuntu/content/hub.h 2016-06-02 17:19:28 +0000 | |||
186 | @@ -34,6 +34,7 @@ | |||
187 | 34 | class ImportExportHandler; | 34 | class ImportExportHandler; |
188 | 35 | class Store; | 35 | class Store; |
189 | 36 | class Transfer; | 36 | class Transfer; |
190 | 37 | class Paste; | ||
191 | 37 | 38 | ||
192 | 38 | class Hub : public QObject | 39 | class Hub : public QObject |
193 | 39 | { | 40 | { |
194 | @@ -66,6 +67,9 @@ | |||
195 | 66 | Q_INVOKABLE virtual Transfer* create_share_to_peer_for_type(Peer peer, Type type); | 67 | Q_INVOKABLE virtual Transfer* create_share_to_peer_for_type(Peer peer, Type type); |
196 | 67 | Q_INVOKABLE virtual bool has_pending(QString peer_id); | 68 | Q_INVOKABLE virtual bool has_pending(QString peer_id); |
197 | 68 | Q_INVOKABLE virtual Peer peer_for_app_id(QString app_id); | 69 | Q_INVOKABLE virtual Peer peer_for_app_id(QString app_id); |
198 | 70 | Q_INVOKABLE virtual Paste* create_paste(const char * data); | ||
199 | 71 | Q_INVOKABLE virtual const char* latest_paste_buf(); | ||
200 | 72 | Q_INVOKABLE virtual const char* paste_buf_by_id(int id); | ||
201 | 69 | 73 | ||
202 | 70 | protected: | 74 | protected: |
203 | 71 | Hub(QObject* = nullptr); | 75 | Hub(QObject* = nullptr); |
204 | 72 | 76 | ||
205 | === added file 'include/com/ubuntu/content/paste.h' | |||
206 | --- include/com/ubuntu/content/paste.h 1970-01-01 00:00:00 +0000 | |||
207 | +++ include/com/ubuntu/content/paste.h 2016-06-02 17:19:28 +0000 | |||
208 | @@ -0,0 +1,98 @@ | |||
209 | 1 | /* | ||
210 | 2 | * Copyright © 2016 Canonical Ltd. | ||
211 | 3 | * | ||
212 | 4 | * This program is free software: you can redistribute it and/or modify | ||
213 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
214 | 6 | * published by the Free Software Foundation. | ||
215 | 7 | * | ||
216 | 8 | * This program is distributed in the hope that it will be useful, | ||
217 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
218 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
219 | 11 | * GNU Lesser General Public License for more details. | ||
220 | 12 | * | ||
221 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
222 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
223 | 15 | * | ||
224 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
225 | 17 | */ | ||
226 | 18 | #ifndef COM_UBUNTU_CONTENT_PASTE_H_ | ||
227 | 19 | #define COM_UBUNTU_CONTENT_PASTE_H_ | ||
228 | 20 | |||
229 | 21 | #include <com/ubuntu/content/item.h> | ||
230 | 22 | |||
231 | 23 | #include <QObject> | ||
232 | 24 | #include <QSharedPointer> | ||
233 | 25 | #include <QVector> | ||
234 | 26 | #include <QString> | ||
235 | 27 | |||
236 | 28 | namespace com | ||
237 | 29 | { | ||
238 | 30 | namespace ubuntu | ||
239 | 31 | { | ||
240 | 32 | namespace content | ||
241 | 33 | { | ||
242 | 34 | namespace detail | ||
243 | 35 | { | ||
244 | 36 | class Handler; | ||
245 | 37 | } | ||
246 | 38 | } | ||
247 | 39 | } | ||
248 | 40 | } | ||
249 | 41 | |||
250 | 42 | namespace com | ||
251 | 43 | { | ||
252 | 44 | namespace ubuntu | ||
253 | 45 | { | ||
254 | 46 | namespace content | ||
255 | 47 | { | ||
256 | 48 | class Item; | ||
257 | 49 | |||
258 | 50 | class Paste : public QObject | ||
259 | 51 | { | ||
260 | 52 | Q_OBJECT | ||
261 | 53 | Q_ENUMS(State) | ||
262 | 54 | Q_PROPERTY(int id READ id) | ||
263 | 55 | Q_PROPERTY(State state READ state NOTIFY stateChanged) | ||
264 | 56 | Q_PROPERTY(QVector<Item> items READ collect WRITE charge) | ||
265 | 57 | Q_PROPERTY(QString source READ source) | ||
266 | 58 | |||
267 | 59 | public: | ||
268 | 60 | enum State | ||
269 | 61 | { | ||
270 | 62 | created, | ||
271 | 63 | charged, | ||
272 | 64 | saved, | ||
273 | 65 | collected, | ||
274 | 66 | aborted, | ||
275 | 67 | finalized | ||
276 | 68 | }; | ||
277 | 69 | |||
278 | 70 | Paste(const Paste&) = delete; | ||
279 | 71 | virtual ~Paste(); | ||
280 | 72 | |||
281 | 73 | Paste& operator=(const Paste&) = delete; | ||
282 | 74 | |||
283 | 75 | Q_INVOKABLE virtual int id() const; | ||
284 | 76 | Q_INVOKABLE virtual State state() const; | ||
285 | 77 | Q_INVOKABLE virtual bool abort(); | ||
286 | 78 | Q_INVOKABLE virtual bool finalize(); | ||
287 | 79 | Q_INVOKABLE virtual bool charge(const QVector<Item>& items); | ||
288 | 80 | Q_INVOKABLE virtual QVector<Item> collect(); | ||
289 | 81 | Q_INVOKABLE virtual QString source() const; | ||
290 | 82 | |||
291 | 83 | Q_SIGNAL void stateChanged(); | ||
292 | 84 | |||
293 | 85 | private: | ||
294 | 86 | struct Private; | ||
295 | 87 | friend struct Private; | ||
296 | 88 | friend class Hub; | ||
297 | 89 | friend class com::ubuntu::content::detail::Handler; | ||
298 | 90 | QSharedPointer<Private> d; | ||
299 | 91 | |||
300 | 92 | Paste(const QSharedPointer<Private>&, QObject* parent = nullptr); | ||
301 | 93 | }; | ||
302 | 94 | } | ||
303 | 95 | } | ||
304 | 96 | } | ||
305 | 97 | |||
306 | 98 | #endif // COM_UBUNTU_CONTENT_PASTE_H_ | ||
307 | 0 | 99 | ||
308 | === modified file 'src/com/ubuntu/content/CMakeLists.txt' | |||
309 | --- src/com/ubuntu/content/CMakeLists.txt 2015-09-23 14:45:09 +0000 | |||
310 | +++ src/com/ubuntu/content/CMakeLists.txt 2016-06-02 17:19:28 +0000 | |||
311 | @@ -47,6 +47,13 @@ | |||
312 | 47 | detail/transfer.h com::ubuntu::content::detail::Transfer) | 47 | detail/transfer.h com::ubuntu::content::detail::Transfer) |
313 | 48 | 48 | ||
314 | 49 | qt5_add_dbus_interface( | 49 | qt5_add_dbus_interface( |
315 | 50 | CONTENT_PASTE_STUB ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml | ||
316 | 51 | ContentPasteInterface) | ||
317 | 52 | qt5_add_dbus_adaptor( | ||
318 | 53 | CONTENT_PASTE_SKELETON ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml | ||
319 | 54 | detail/paste.h com::ubuntu::content::detail::Paste) | ||
320 | 55 | |||
321 | 56 | qt5_add_dbus_interface( | ||
322 | 50 | CONTENT_HANDLER_STUB ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Handler.xml | 57 | CONTENT_HANDLER_STUB ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Handler.xml |
323 | 51 | ContentHandlerInterface) | 58 | ContentHandlerInterface) |
324 | 52 | qt5_add_dbus_adaptor( | 59 | qt5_add_dbus_adaptor( |
325 | @@ -56,6 +63,7 @@ | |||
326 | 56 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/hub.h) | 63 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/hub.h) |
327 | 57 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/import_export_handler.h) | 64 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/import_export_handler.h) |
328 | 58 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/item.h) | 65 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/item.h) |
329 | 66 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/paste.h) | ||
330 | 59 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/peer.h) | 67 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/peer.h) |
331 | 60 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/store.h) | 68 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/store.h) |
332 | 61 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/transfer.h) | 69 | qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/transfer.h) |
333 | @@ -67,6 +75,7 @@ | |||
334 | 67 | hub.cpp | 75 | hub.cpp |
335 | 68 | import_export_handler.cpp | 76 | import_export_handler.cpp |
336 | 69 | item.cpp | 77 | item.cpp |
337 | 78 | paste.cpp | ||
338 | 70 | peer.cpp | 79 | peer.cpp |
339 | 71 | store.cpp | 80 | store.cpp |
340 | 72 | transfer.cpp | 81 | transfer.cpp |
341 | @@ -75,6 +84,7 @@ | |||
342 | 75 | debug.cpp | 84 | debug.cpp |
343 | 76 | 85 | ||
344 | 77 | detail/app_manager.cpp | 86 | detail/app_manager.cpp |
345 | 87 | detail/paste.cpp | ||
346 | 78 | detail/service.cpp | 88 | detail/service.cpp |
347 | 79 | detail/transfer.cpp | 89 | detail/transfer.cpp |
348 | 80 | detail/handler.cpp | 90 | detail/handler.cpp |
349 | @@ -83,6 +93,8 @@ | |||
350 | 83 | ${CONTENT_HUB_MOCS} | 93 | ${CONTENT_HUB_MOCS} |
351 | 84 | ${CONTENT_SERVICE_STUB} | 94 | ${CONTENT_SERVICE_STUB} |
352 | 85 | ${CONTENT_SERVICE_SKELETON} | 95 | ${CONTENT_SERVICE_SKELETON} |
353 | 96 | ${CONTENT_PASTE_STUB} | ||
354 | 97 | ${CONTENT_PASTE_SKELETON} | ||
355 | 86 | ${CONTENT_TRANSFER_STUB} | 98 | ${CONTENT_TRANSFER_STUB} |
356 | 87 | ${CONTENT_TRANSFER_SKELETON} | 99 | ${CONTENT_TRANSFER_SKELETON} |
357 | 88 | ${CONTENT_HANDLER_STUB} | 100 | ${CONTENT_HANDLER_STUB} |
358 | 89 | 101 | ||
359 | === added file 'src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml' | |||
360 | --- src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml 1970-01-01 00:00:00 +0000 | |||
361 | +++ src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml 2016-06-02 17:19:28 +0000 | |||
362 | @@ -0,0 +1,26 @@ | |||
363 | 1 | <node> | ||
364 | 2 | <interface name="com.ubuntu.content.dbus.Paste"> | ||
365 | 3 | <signal name="StateChanged"> | ||
366 | 4 | <arg name="state" type="i"/> | ||
367 | 5 | </signal> | ||
368 | 6 | <method name="Id"> | ||
369 | 7 | <arg name="id" type="i" direction="out" /> | ||
370 | 8 | </method> | ||
371 | 9 | <method name="State"> | ||
372 | 10 | <arg name="state" type="i" direction="out" /> | ||
373 | 11 | </method> | ||
374 | 12 | <method name="Abort"> | ||
375 | 13 | </method> | ||
376 | 14 | <method name="Finalize"> | ||
377 | 15 | </method> | ||
378 | 16 | <method name="Charge"> | ||
379 | 17 | <arg name="items" type="av" direction="in" /> | ||
380 | 18 | </method> | ||
381 | 19 | <method name="Collect"> | ||
382 | 20 | <arg name="items" type="av" direction="out" /> | ||
383 | 21 | </method> | ||
384 | 22 | <method name="source"> | ||
385 | 23 | <arg name="source" type="s" direction="out" /> | ||
386 | 24 | </method> | ||
387 | 25 | </interface> | ||
388 | 26 | </node> | ||
389 | 0 | 27 | ||
390 | === modified file 'src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml' | |||
391 | --- src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml 2015-09-29 13:15:58 +0000 | |||
392 | +++ src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml 2016-06-02 17:19:28 +0000 | |||
393 | @@ -36,6 +36,19 @@ | |||
394 | 36 | <arg name="type_id" type="s" direction="in" /> | 36 | <arg name="type_id" type="s" direction="in" /> |
395 | 37 | <arg name="transfer_object" type="o" direction="out" /> | 37 | <arg name="transfer_object" type="o" direction="out" /> |
396 | 38 | </method> | 38 | </method> |
397 | 39 | <method name="CreatePaste"> | ||
398 | 40 | <arg name="app_id" type="s" direction="in" /> | ||
399 | 41 | <arg name="paste_object" type="o" direction="out" /> | ||
400 | 42 | </method> | ||
401 | 43 | <method name="GetLatestPaste"> | ||
402 | 44 | <arg name="app_id" type="s" direction="in" /> | ||
403 | 45 | <arg name="paste_object" type="o" direction="out" /> | ||
404 | 46 | </method> | ||
405 | 47 | <method name="GetPaste"> | ||
406 | 48 | <arg name="id" type="s" direction="in" /> | ||
407 | 49 | <arg name="app_id" type="s" direction="in" /> | ||
408 | 50 | <arg name="paste_object" type="o" direction="out" /> | ||
409 | 51 | </method> | ||
410 | 39 | <method name="RegisterImportExportHandler"> | 52 | <method name="RegisterImportExportHandler"> |
411 | 40 | <arg name="peer_id" type="s" direction="in" /> | 53 | <arg name="peer_id" type="s" direction="in" /> |
412 | 41 | <arg name="handler_object" type="o" direction="in" /> | 54 | <arg name="handler_object" type="o" direction="in" /> |
413 | 42 | 55 | ||
414 | === added file 'src/com/ubuntu/content/detail/paste.cpp' | |||
415 | --- src/com/ubuntu/content/detail/paste.cpp 1970-01-01 00:00:00 +0000 | |||
416 | +++ src/com/ubuntu/content/detail/paste.cpp 2016-06-02 17:19:28 +0000 | |||
417 | @@ -0,0 +1,166 @@ | |||
418 | 1 | /* | ||
419 | 2 | * Copyright © 2013 Canonical Ltd. | ||
420 | 3 | * | ||
421 | 4 | * This program is free software: you can redistribute it and/or modify | ||
422 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
423 | 6 | * published by the Free Software Foundation. | ||
424 | 7 | * | ||
425 | 8 | * This program is distributed in the hope that it will be useful, | ||
426 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
427 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
428 | 11 | * GNU Lesser General Public License for more details. | ||
429 | 12 | * | ||
430 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
431 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
432 | 15 | * | ||
433 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | ||
434 | 17 | */ | ||
435 | 18 | |||
436 | 19 | #include "debug.h" | ||
437 | 20 | #include "paste.h" | ||
438 | 21 | #include "utils.cpp" | ||
439 | 22 | |||
440 | 23 | #include <QFileInfo> | ||
441 | 24 | #include <com/ubuntu/content/hub.h> | ||
442 | 25 | #include <com/ubuntu/content/store.h> | ||
443 | 26 | #include <com/ubuntu/content/paste.h> | ||
444 | 27 | #include <ubuntu/download_manager/download.h> | ||
445 | 28 | #include <ubuntu/download_manager/manager.h> | ||
446 | 29 | |||
447 | 30 | namespace cuc = com::ubuntu::content; | ||
448 | 31 | namespace cucd = com::ubuntu::content::detail; | ||
449 | 32 | |||
450 | 33 | struct cucd::Paste::Private | ||
451 | 34 | { | ||
452 | 35 | Private(const int id, | ||
453 | 36 | const QString& source): | ||
454 | 37 | state(cuc::Paste::created), | ||
455 | 38 | id(id), | ||
456 | 39 | source(source) | ||
457 | 40 | { | ||
458 | 41 | } | ||
459 | 42 | |||
460 | 43 | cuc::Paste::State state; | ||
461 | 44 | const int id; | ||
462 | 45 | const QString source; | ||
463 | 46 | QString destination; | ||
464 | 47 | QVariantList items; | ||
465 | 48 | }; | ||
466 | 49 | |||
467 | 50 | cucd::Paste::Paste(const int id, | ||
468 | 51 | const QString& source, | ||
469 | 52 | QObject* parent) : | ||
470 | 53 | QObject(parent), d(new Private(id, source)) | ||
471 | 54 | { | ||
472 | 55 | TRACE() << __PRETTY_FUNCTION__; | ||
473 | 56 | } | ||
474 | 57 | |||
475 | 58 | cucd::Paste::~Paste() | ||
476 | 59 | { | ||
477 | 60 | TRACE() << __PRETTY_FUNCTION__; | ||
478 | 61 | } | ||
479 | 62 | |||
480 | 63 | /* unique id of the paste */ | ||
481 | 64 | int cucd::Paste::Id() | ||
482 | 65 | { | ||
483 | 66 | TRACE() << __PRETTY_FUNCTION__; | ||
484 | 67 | return d->id; | ||
485 | 68 | } | ||
486 | 69 | |||
487 | 70 | /* returns the add_id of the source app */ | ||
488 | 71 | QString cucd::Paste::source() | ||
489 | 72 | { | ||
490 | 73 | TRACE() << __PRETTY_FUNCTION__; | ||
491 | 74 | return d->source; | ||
492 | 75 | } | ||
493 | 76 | |||
494 | 77 | /* returns the add_id of the destination app */ | ||
495 | 78 | QString cucd::Paste::destination() | ||
496 | 79 | { | ||
497 | 80 | TRACE() << __PRETTY_FUNCTION__; | ||
498 | 81 | if (d->destination.isEmpty()) | ||
499 | 82 | return d->source; | ||
500 | 83 | return d->destination; | ||
501 | 84 | } | ||
502 | 85 | |||
503 | 86 | void cucd::Paste::setDestination(QString& dest) | ||
504 | 87 | { | ||
505 | 88 | TRACE() << __PRETTY_FUNCTION__; | ||
506 | 89 | d->destination = dest; | ||
507 | 90 | } | ||
508 | 91 | |||
509 | 92 | /* returns the object path for the paste */ | ||
510 | 93 | QString cucd::Paste::path() | ||
511 | 94 | { | ||
512 | 95 | TRACE() << Q_FUNC_INFO << "destination:" << destination(); | ||
513 | 96 | static const QString path_pattern{"/pastes/%1/%2"}; | ||
514 | 97 | QString path = path_pattern | ||
515 | 98 | .arg(sanitize_id(destination())) | ||
516 | 99 | .arg(d->id); | ||
517 | 100 | return path; | ||
518 | 101 | } | ||
519 | 102 | |||
520 | 103 | int cucd::Paste::State() | ||
521 | 104 | { | ||
522 | 105 | TRACE() << __PRETTY_FUNCTION__; | ||
523 | 106 | return d->state; | ||
524 | 107 | } | ||
525 | 108 | |||
526 | 109 | void cucd::Paste::Abort() | ||
527 | 110 | { | ||
528 | 111 | TRACE() << __PRETTY_FUNCTION__; | ||
529 | 112 | |||
530 | 113 | if (d->state == cuc::Paste::aborted) | ||
531 | 114 | return; | ||
532 | 115 | |||
533 | 116 | d->items.clear(); | ||
534 | 117 | d->state = cuc::Paste::aborted; | ||
535 | 118 | Q_EMIT(StateChanged(d->state)); | ||
536 | 119 | } | ||
537 | 120 | |||
538 | 121 | void cucd::Paste::Charge(const QVariantList& items) | ||
539 | 122 | { | ||
540 | 123 | TRACE() << __PRETTY_FUNCTION__ << "STATE:" << d->state; | ||
541 | 124 | |||
542 | 125 | if (d->state == cuc::Paste::charged) | ||
543 | 126 | return; | ||
544 | 127 | |||
545 | 128 | QVariantList ret; | ||
546 | 129 | Q_FOREACH(QVariant iv, items) { | ||
547 | 130 | cuc::Item item = qdbus_cast<Item>(iv); | ||
548 | 131 | ret.append(QVariant::fromValue(item)); | ||
549 | 132 | } | ||
550 | 133 | if (ret.count() <= 0) { | ||
551 | 134 | qWarning() << "Failed to charge items, aborting"; | ||
552 | 135 | d->state = cuc::Paste::aborted; | ||
553 | 136 | } else { | ||
554 | 137 | d->items = ret; | ||
555 | 138 | d->state = cuc::Paste::charged; | ||
556 | 139 | } | ||
557 | 140 | Q_EMIT(StateChanged(d->state)); | ||
558 | 141 | } | ||
559 | 142 | |||
560 | 143 | QVariantList cucd::Paste::Collect() | ||
561 | 144 | { | ||
562 | 145 | TRACE() << __PRETTY_FUNCTION__; | ||
563 | 146 | |||
564 | 147 | if (d->state != cuc::Paste::collected) | ||
565 | 148 | { | ||
566 | 149 | d->state = cuc::Paste::collected; | ||
567 | 150 | Q_EMIT(StateChanged(d->state)); | ||
568 | 151 | } | ||
569 | 152 | |||
570 | 153 | return d->items; | ||
571 | 154 | } | ||
572 | 155 | |||
573 | 156 | void cucd::Paste::Finalize() | ||
574 | 157 | { | ||
575 | 158 | TRACE() << __PRETTY_FUNCTION__; | ||
576 | 159 | |||
577 | 160 | if (d->state == cuc::Paste::finalized) | ||
578 | 161 | return; | ||
579 | 162 | |||
580 | 163 | d->items.clear(); | ||
581 | 164 | d->state = cuc::Paste::finalized; | ||
582 | 165 | Q_EMIT(StateChanged(d->state)); | ||
583 | 166 | } | ||
584 | 0 | 167 | ||
585 | === added file 'src/com/ubuntu/content/detail/paste.h' | |||
586 | --- src/com/ubuntu/content/detail/paste.h 1970-01-01 00:00:00 +0000 | |||
587 | +++ src/com/ubuntu/content/detail/paste.h 2016-06-02 17:19:28 +0000 | |||
588 | @@ -0,0 +1,73 @@ | |||
589 | 1 | /* | ||
590 | 2 | * Copyright © 2016 Canonical Ltd. | ||
591 | 3 | * | ||
592 | 4 | * This program is free software: you can redistribute it and/or modify | ||
593 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
594 | 6 | * published by the Free Software Foundation. | ||
595 | 7 | * | ||
596 | 8 | * This program is distributed in the hope that it will be useful, | ||
597 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
598 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
599 | 11 | * GNU Lesser General Public License for more details. | ||
600 | 12 | * | ||
601 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
602 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
603 | 15 | * | ||
604 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
605 | 17 | */ | ||
606 | 18 | #ifndef PASTE_H_ | ||
607 | 19 | #define PASTE_H_ | ||
608 | 20 | |||
609 | 21 | #include <QDir> | ||
610 | 22 | #include <QObject> | ||
611 | 23 | #include <QtDBus/QDBusMessage> | ||
612 | 24 | #include <QtDBus/QDBusContext> | ||
613 | 25 | |||
614 | 26 | namespace com | ||
615 | 27 | { | ||
616 | 28 | namespace ubuntu | ||
617 | 29 | { | ||
618 | 30 | namespace content | ||
619 | 31 | { | ||
620 | 32 | namespace detail | ||
621 | 33 | { | ||
622 | 34 | class Paste : public QObject, protected QDBusContext | ||
623 | 35 | { | ||
624 | 36 | Q_OBJECT | ||
625 | 37 | Q_PROPERTY(int State READ State NOTIFY StateChanged) | ||
626 | 38 | Q_PROPERTY(int id READ Id) | ||
627 | 39 | Q_PROPERTY(QString source READ source) | ||
628 | 40 | |||
629 | 41 | public: | ||
630 | 42 | Paste(const int, const QString&, QObject* parent = nullptr); | ||
631 | 43 | Paste(const Paste&) = delete; | ||
632 | 44 | virtual ~Paste(); | ||
633 | 45 | |||
634 | 46 | Paste& operator=(const Paste&) = delete; | ||
635 | 47 | |||
636 | 48 | Q_SIGNALS: | ||
637 | 49 | void StateChanged(int State); | ||
638 | 50 | |||
639 | 51 | public Q_SLOTS: | ||
640 | 52 | int State(); | ||
641 | 53 | void Charge(const QVariantList&); | ||
642 | 54 | QVariantList Collect(); | ||
643 | 55 | void Abort(); | ||
644 | 56 | void Finalize(); | ||
645 | 57 | int Id(); | ||
646 | 58 | QString source(); | ||
647 | 59 | QString destination(); | ||
648 | 60 | void setDestination(QString&); | ||
649 | 61 | QString path(); | ||
650 | 62 | |||
651 | 63 | private: | ||
652 | 64 | struct Private; | ||
653 | 65 | QScopedPointer<Private> d; | ||
654 | 66 | |||
655 | 67 | }; | ||
656 | 68 | } | ||
657 | 69 | } | ||
658 | 70 | } | ||
659 | 71 | } | ||
660 | 72 | |||
661 | 73 | #endif // PASTE_H_ | ||
662 | 0 | 74 | ||
663 | === modified file 'src/com/ubuntu/content/detail/service.cpp' | |||
664 | --- src/com/ubuntu/content/detail/service.cpp 2016-01-29 17:20:58 +0000 | |||
665 | +++ src/com/ubuntu/content/detail/service.cpp 2016-06-02 17:19:28 +0000 | |||
666 | @@ -23,6 +23,8 @@ | |||
667 | 23 | #include "service.h" | 23 | #include "service.h" |
668 | 24 | #include "peer_registry.h" | 24 | #include "peer_registry.h" |
669 | 25 | #include "i18n.h" | 25 | #include "i18n.h" |
670 | 26 | #include "paste.h" | ||
671 | 27 | #include "pasteadaptor.h" | ||
672 | 26 | #include "transfer.h" | 28 | #include "transfer.h" |
673 | 27 | #include "transferadaptor.h" | 29 | #include "transferadaptor.h" |
674 | 28 | #include "utils.cpp" | 30 | #include "utils.cpp" |
675 | @@ -33,6 +35,7 @@ | |||
676 | 33 | #include <libnotify/notify.h> | 35 | #include <libnotify/notify.h> |
677 | 34 | 36 | ||
678 | 35 | #include <com/ubuntu/content/item.h> | 37 | #include <com/ubuntu/content/item.h> |
679 | 38 | #include <com/ubuntu/content/paste.h> | ||
680 | 36 | #include <com/ubuntu/content/peer.h> | 39 | #include <com/ubuntu/content/peer.h> |
681 | 37 | #include <com/ubuntu/content/type.h> | 40 | #include <com/ubuntu/content/type.h> |
682 | 38 | #include <com/ubuntu/content/transfer.h> | 41 | #include <com/ubuntu/content/transfer.h> |
683 | @@ -79,6 +82,7 @@ | |||
684 | 79 | QDBusConnection connection; | 82 | QDBusConnection connection; |
685 | 80 | QSharedPointer<cucd::PeerRegistry> registry; | 83 | QSharedPointer<cucd::PeerRegistry> registry; |
686 | 81 | QSet<cucd::Transfer*> active_transfers; | 84 | QSet<cucd::Transfer*> active_transfers; |
687 | 85 | QList<cucd::Paste*> active_pastes; | ||
688 | 82 | QSet<RegHandler*> handlers; | 86 | QSet<RegHandler*> handlers; |
689 | 83 | QSharedPointer<cua::ApplicationManager> app_manager; | 87 | QSharedPointer<cua::ApplicationManager> app_manager; |
690 | 84 | 88 | ||
691 | @@ -302,6 +306,74 @@ | |||
692 | 302 | return CreateTransfer(peer_id, src_id, cuc::Transfer::Share, type_id); | 306 | return CreateTransfer(peer_id, src_id, cuc::Transfer::Share, type_id); |
693 | 303 | } | 307 | } |
694 | 304 | 308 | ||
695 | 309 | QDBusObjectPath cucd::Service::CreatePaste(const QString& app_id) | ||
696 | 310 | { | ||
697 | 311 | TRACE() << Q_FUNC_INFO << app_id; | ||
698 | 312 | static size_t import_counter{0}; import_counter++; | ||
699 | 313 | |||
700 | 314 | QUuid uuid{QUuid::createUuid()}; | ||
701 | 315 | |||
702 | 316 | auto paste = new cucd::Paste(import_counter, app_id, this); | ||
703 | 317 | new PasteAdaptor(paste); | ||
704 | 318 | d->active_pastes.append(paste); | ||
705 | 319 | |||
706 | 320 | auto path = paste->path(); | ||
707 | 321 | if (not d->connection.registerObject(path, paste)) | ||
708 | 322 | qWarning() << "Problem registering object for path: " << path; | ||
709 | 323 | |||
710 | 324 | connect(paste, SIGNAL(StateChanged(int)), this, SLOT(handle_pastes(int))); | ||
711 | 325 | return QDBusObjectPath{path}; | ||
712 | 326 | } | ||
713 | 327 | |||
714 | 328 | QDBusObjectPath cucd::Service::GetLatestPaste(const QString& app_id) | ||
715 | 329 | { | ||
716 | 330 | TRACE() << Q_FUNC_INFO << app_id; | ||
717 | 331 | if (d->active_pastes.isEmpty()) | ||
718 | 332 | return QDBusObjectPath(); | ||
719 | 333 | |||
720 | 334 | QString dest_id = app_id; | ||
721 | 335 | if (dest_id.isEmpty()) | ||
722 | 336 | { | ||
723 | 337 | TRACE() << Q_FUNC_INFO << "APP_ID isnt' set, attempting to get it from AppArmor"; | ||
724 | 338 | dest_id = aa_profile(this->message().service()); | ||
725 | 339 | } | ||
726 | 340 | |||
727 | 341 | auto paste = d->active_pastes.last(); | ||
728 | 342 | d->connection.unregisterObject(paste->path()); | ||
729 | 343 | paste->setDestination(dest_id); | ||
730 | 344 | auto path = paste->path(); | ||
731 | 345 | if (not d->connection.registerObject(path, paste)) | ||
732 | 346 | qWarning() << "Problem registering object for path: " << path; | ||
733 | 347 | return QDBusObjectPath(paste->path()); | ||
734 | 348 | } | ||
735 | 349 | |||
736 | 350 | QDBusObjectPath cucd::Service::GetPaste(const QString& id, const QString& app_id) | ||
737 | 351 | { | ||
738 | 352 | TRACE() << Q_FUNC_INFO << id; | ||
739 | 353 | if (d->active_pastes.isEmpty()) | ||
740 | 354 | return QDBusObjectPath(); | ||
741 | 355 | |||
742 | 356 | QString dest_id = app_id; | ||
743 | 357 | if (dest_id.isEmpty()) | ||
744 | 358 | { | ||
745 | 359 | TRACE() << Q_FUNC_INFO << "APP_ID isnt' set, attempting to get it from AppArmor"; | ||
746 | 360 | dest_id = aa_profile(this->message().service()); | ||
747 | 361 | } | ||
748 | 362 | |||
749 | 363 | Q_FOREACH (cucd::Paste *p, d->active_pastes) | ||
750 | 364 | { | ||
751 | 365 | if (p->Id() == id.toInt()) { | ||
752 | 366 | d->connection.unregisterObject(p->path()); | ||
753 | 367 | p->setDestination(dest_id); | ||
754 | 368 | auto path = p->path(); | ||
755 | 369 | if (not d->connection.registerObject(path, p)) | ||
756 | 370 | qWarning() << "Problem registering object for path: " << path; | ||
757 | 371 | return QDBusObjectPath(path); | ||
758 | 372 | } | ||
759 | 373 | } | ||
760 | 374 | return QDBusObjectPath(); | ||
761 | 375 | } | ||
762 | 376 | |||
763 | 305 | QDBusObjectPath cucd::Service::CreateTransfer(const QString& dest_id, const QString& src_id, int dir, const QString& type_id) | 377 | QDBusObjectPath cucd::Service::CreateTransfer(const QString& dest_id, const QString& src_id, int dir, const QString& type_id) |
764 | 306 | { | 378 | { |
765 | 307 | TRACE() << Q_FUNC_INFO << "DEST:" << dest_id << "SRC:" << src_id << "DIRECTION:" << dir; | 379 | TRACE() << Q_FUNC_INFO << "DEST:" << dest_id << "SRC:" << src_id << "DIRECTION:" << dir; |
766 | @@ -539,6 +611,29 @@ | |||
767 | 539 | } | 611 | } |
768 | 540 | } | 612 | } |
769 | 541 | 613 | ||
770 | 614 | void cucd::Service::handle_pastes(int state) | ||
771 | 615 | { | ||
772 | 616 | TRACE() << Q_FUNC_INFO; | ||
773 | 617 | cucd::Paste *paste = static_cast<cucd::Paste*>(sender()); | ||
774 | 618 | TRACE() << Q_FUNC_INFO << "STATE:" << paste->State(); | ||
775 | 619 | |||
776 | 620 | if (state == cuc::Paste::charged) | ||
777 | 621 | { | ||
778 | 622 | TRACE() << Q_FUNC_INFO << "charged"; | ||
779 | 623 | auto path = paste->path(); | ||
780 | 624 | TRACE() << Q_FUNC_INFO << "Unregistering path:" << path; | ||
781 | 625 | d->connection.unregisterObject(path); | ||
782 | 626 | } | ||
783 | 627 | |||
784 | 628 | if (state == cuc::Paste::collected) | ||
785 | 629 | { | ||
786 | 630 | TRACE() << Q_FUNC_INFO << "collected"; | ||
787 | 631 | auto path = paste->path(); | ||
788 | 632 | TRACE() << Q_FUNC_INFO << "Unregistering path:" << path; | ||
789 | 633 | d->connection.unregisterObject(path); | ||
790 | 634 | } | ||
791 | 635 | } | ||
792 | 636 | |||
793 | 542 | void cucd::Service::handler_unregistered(const QString& s) | 637 | void cucd::Service::handler_unregistered(const QString& s) |
794 | 543 | { | 638 | { |
795 | 544 | TRACE() << Q_FUNC_INFO << s; | 639 | TRACE() << Q_FUNC_INFO << s; |
796 | 545 | 640 | ||
797 | === modified file 'src/com/ubuntu/content/detail/service.h' | |||
798 | --- src/com/ubuntu/content/detail/service.h 2015-09-29 13:15:58 +0000 | |||
799 | +++ src/com/ubuntu/content/detail/service.h 2016-06-02 17:19:28 +0000 | |||
800 | @@ -61,6 +61,9 @@ | |||
801 | 61 | QDBusObjectPath CreateImportFromPeer(const QString&, const QString&, const QString&); | 61 | QDBusObjectPath CreateImportFromPeer(const QString&, const QString&, const QString&); |
802 | 62 | QDBusObjectPath CreateExportToPeer(const QString&, const QString&, const QString&); | 62 | QDBusObjectPath CreateExportToPeer(const QString&, const QString&, const QString&); |
803 | 63 | QDBusObjectPath CreateShareToPeer(const QString&, const QString&, const QString&); | 63 | QDBusObjectPath CreateShareToPeer(const QString&, const QString&, const QString&); |
804 | 64 | QDBusObjectPath CreatePaste(const QString&); | ||
805 | 65 | QDBusObjectPath GetLatestPaste(const QString&); | ||
806 | 66 | QDBusObjectPath GetPaste(const QString&, const QString&); | ||
807 | 64 | 67 | ||
808 | 65 | void RegisterImportExportHandler(const QString&, const QDBusObjectPath& handler); | 68 | void RegisterImportExportHandler(const QString&, const QDBusObjectPath& handler); |
809 | 66 | void HandlerActive(const QString&); | 69 | void HandlerActive(const QString&); |
810 | @@ -79,6 +82,7 @@ | |||
811 | 79 | private Q_SLOTS: | 82 | private Q_SLOTS: |
812 | 80 | void handle_imports(int); | 83 | void handle_imports(int); |
813 | 81 | void handle_exports(int); | 84 | void handle_exports(int); |
814 | 85 | void handle_pastes(int); | ||
815 | 82 | void handler_unregistered(const QString&); | 86 | void handler_unregistered(const QString&); |
816 | 83 | QDBusObjectPath CreateTransfer(const QString&, const QString&, int, const QString&); | 87 | QDBusObjectPath CreateTransfer(const QString&, const QString&, int, const QString&); |
817 | 84 | void download_notify(com::ubuntu::content::detail::Transfer*); | 88 | void download_notify(com::ubuntu::content::detail::Transfer*); |
818 | 85 | 89 | ||
819 | === modified file 'src/com/ubuntu/content/hub.cpp' | |||
820 | --- src/com/ubuntu/content/hub.cpp 2015-10-23 12:37:24 +0000 | |||
821 | +++ src/com/ubuntu/content/hub.cpp 2016-06-02 17:19:28 +0000 | |||
822 | @@ -21,6 +21,7 @@ | |||
823 | 21 | #include "ContentServiceInterface.h" | 21 | #include "ContentServiceInterface.h" |
824 | 22 | #include "ContentHandlerInterface.h" | 22 | #include "ContentHandlerInterface.h" |
825 | 23 | #include "handleradaptor.h" | 23 | #include "handleradaptor.h" |
826 | 24 | #include "paste_p.h" | ||
827 | 24 | #include "transfer_p.h" | 25 | #include "transfer_p.h" |
828 | 25 | #include "utils.cpp" | 26 | #include "utils.cpp" |
829 | 26 | 27 | ||
830 | @@ -331,3 +332,54 @@ | |||
831 | 331 | auto peer = reply.value(); | 332 | auto peer = reply.value(); |
832 | 332 | return qdbus_cast<cuc::Peer>(peer.variant()); | 333 | return qdbus_cast<cuc::Peer>(peer.variant()); |
833 | 333 | } | 334 | } |
834 | 335 | |||
835 | 336 | cuc::Paste* cuc::Hub::create_paste(const char * data) { | ||
836 | 337 | /* This needs to be replaced with a better way to get the APP_ID */ | ||
837 | 338 | QString id = app_id(); | ||
838 | 339 | TRACE() << Q_FUNC_INFO << id; | ||
839 | 340 | |||
840 | 341 | auto reply = d->service->CreatePaste(id); | ||
841 | 342 | reply.waitForFinished(); | ||
842 | 343 | |||
843 | 344 | cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this); | ||
844 | 345 | auto item = cuc::Item(); | ||
845 | 346 | item.setStream(QByteArray(data)); | ||
846 | 347 | QVector<cuc::Item> items; | ||
847 | 348 | items << item; | ||
848 | 349 | paste->charge(items); | ||
849 | 350 | return paste; | ||
850 | 351 | } | ||
851 | 352 | |||
852 | 353 | const char* cuc::Hub::latest_paste_buf() { | ||
853 | 354 | TRACE() << Q_FUNC_INFO; | ||
854 | 355 | const char* ret = NULL; | ||
855 | 356 | QString dest_id = app_id(); | ||
856 | 357 | TRACE() << Q_FUNC_INFO << dest_id; | ||
857 | 358 | auto reply = d->service->GetLatestPaste(dest_id); | ||
858 | 359 | reply.waitForFinished(); | ||
859 | 360 | |||
860 | 361 | cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this); | ||
861 | 362 | auto items = paste->collect(); | ||
862 | 363 | if (items.count() > 0) { | ||
863 | 364 | auto item = items.first(); | ||
864 | 365 | ret = item.stream().constData(); | ||
865 | 366 | } | ||
866 | 367 | return ret; | ||
867 | 368 | } | ||
868 | 369 | |||
869 | 370 | const char* cuc::Hub::paste_buf_by_id(int id) { | ||
870 | 371 | TRACE() << Q_FUNC_INFO; | ||
871 | 372 | const char* ret = NULL; | ||
872 | 373 | QString dest_id = app_id(); | ||
873 | 374 | auto reply = d->service->GetPaste(QString::number(id), dest_id); | ||
874 | 375 | reply.waitForFinished(); | ||
875 | 376 | |||
876 | 377 | cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this); | ||
877 | 378 | auto items = paste->collect(); | ||
878 | 379 | if (items.count() > 0) { | ||
879 | 380 | auto item = items.first(); | ||
880 | 381 | ret = item.stream().constData(); | ||
881 | 382 | } | ||
882 | 383 | return ret; | ||
883 | 384 | } | ||
884 | 385 | |||
885 | 334 | 386 | ||
886 | === added file 'src/com/ubuntu/content/paste.cpp' | |||
887 | --- src/com/ubuntu/content/paste.cpp 1970-01-01 00:00:00 +0000 | |||
888 | +++ src/com/ubuntu/content/paste.cpp 2016-06-02 17:19:28 +0000 | |||
889 | @@ -0,0 +1,74 @@ | |||
890 | 1 | /* | ||
891 | 2 | * Copyright © 2016 Canonical Ltd. | ||
892 | 3 | * | ||
893 | 4 | * This program is free software: you can redistribute it and/or modify | ||
894 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
895 | 6 | * published by the Free Software Foundation. | ||
896 | 7 | * | ||
897 | 8 | * This program is distributed in the hope that it will be useful, | ||
898 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
899 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
900 | 11 | * GNU Lesser General Public License for more details. | ||
901 | 12 | * | ||
902 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
903 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
904 | 15 | * | ||
905 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
906 | 17 | */ | ||
907 | 18 | |||
908 | 19 | #include <com/ubuntu/content/paste.h> | ||
909 | 20 | |||
910 | 21 | #include "paste_p.h" | ||
911 | 22 | #include "utils.cpp" | ||
912 | 23 | |||
913 | 24 | namespace cuc = com::ubuntu::content; | ||
914 | 25 | |||
915 | 26 | cuc::Paste::Paste(const QSharedPointer<cuc::Paste::Private>& d, QObject* parent) | ||
916 | 27 | : QObject(parent), | ||
917 | 28 | d(d) | ||
918 | 29 | { | ||
919 | 30 | QObject::connect(d->remote_paste, | ||
920 | 31 | SIGNAL (StateChanged(int)), | ||
921 | 32 | this, | ||
922 | 33 | SIGNAL (stateChanged())); | ||
923 | 34 | } | ||
924 | 35 | |||
925 | 36 | cuc::Paste::~Paste() | ||
926 | 37 | { | ||
927 | 38 | TRACE() << Q_FUNC_INFO; | ||
928 | 39 | } | ||
929 | 40 | |||
930 | 41 | int cuc::Paste::id() const | ||
931 | 42 | { | ||
932 | 43 | return d->id(); | ||
933 | 44 | } | ||
934 | 45 | |||
935 | 46 | cuc::Paste::State cuc::Paste::state() const | ||
936 | 47 | { | ||
937 | 48 | return d->state(); | ||
938 | 49 | } | ||
939 | 50 | |||
940 | 51 | bool cuc::Paste::abort() | ||
941 | 52 | { | ||
942 | 53 | return d->abort(); | ||
943 | 54 | } | ||
944 | 55 | |||
945 | 56 | bool cuc::Paste::charge(const QVector<cuc::Item>& items) | ||
946 | 57 | { | ||
947 | 58 | return d->charge(items); | ||
948 | 59 | } | ||
949 | 60 | |||
950 | 61 | QVector<cuc::Item> cuc::Paste::collect() | ||
951 | 62 | { | ||
952 | 63 | return d->collect(); | ||
953 | 64 | } | ||
954 | 65 | |||
955 | 66 | bool cuc::Paste::finalize() | ||
956 | 67 | { | ||
957 | 68 | return d->finalize(); | ||
958 | 69 | } | ||
959 | 70 | |||
960 | 71 | QString cuc::Paste::source() const | ||
961 | 72 | { | ||
962 | 73 | return d->source(); | ||
963 | 74 | } | ||
964 | 0 | 75 | ||
965 | === added file 'src/com/ubuntu/content/paste_p.h' | |||
966 | --- src/com/ubuntu/content/paste_p.h 1970-01-01 00:00:00 +0000 | |||
967 | +++ src/com/ubuntu/content/paste_p.h 2016-06-02 17:19:28 +0000 | |||
968 | @@ -0,0 +1,138 @@ | |||
969 | 1 | /* | ||
970 | 2 | * Copyright © 2016 Canonical Ltd. | ||
971 | 3 | * | ||
972 | 4 | * This program is free software: you can redistribute it and/or modify | ||
973 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
974 | 6 | * published by the Free Software Foundation. | ||
975 | 7 | * | ||
976 | 8 | * This program is distributed in the hope that it will be useful, | ||
977 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
978 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
979 | 11 | * GNU Lesser General Public License for more details. | ||
980 | 12 | * | ||
981 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
982 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
983 | 15 | * | ||
984 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
985 | 17 | */ | ||
986 | 18 | #ifndef COM_UBUNTU_CONTENT_PASTE_P_H_ | ||
987 | 19 | #define COM_UBUNTU_CONTENT_PASTE_P_H_ | ||
988 | 20 | |||
989 | 21 | #include "common.h" | ||
990 | 22 | #include "ContentPasteInterface.h" | ||
991 | 23 | |||
992 | 24 | #include <com/ubuntu/content/item.h> | ||
993 | 25 | #include <com/ubuntu/content/paste.h> | ||
994 | 26 | |||
995 | 27 | #include <QObject> | ||
996 | 28 | #include <QVector> | ||
997 | 29 | |||
998 | 30 | namespace com | ||
999 | 31 | { | ||
1000 | 32 | namespace ubuntu | ||
1001 | 33 | { | ||
1002 | 34 | namespace content | ||
1003 | 35 | { | ||
1004 | 36 | class Paste::Private : public QObject | ||
1005 | 37 | { | ||
1006 | 38 | Q_OBJECT | ||
1007 | 39 | public: | ||
1008 | 40 | static Paste* make_paste(const QDBusObjectPath& paste, QObject* parent) | ||
1009 | 41 | { | ||
1010 | 42 | QSharedPointer<Private> d{new Private{paste, parent}}; | ||
1011 | 43 | return new Paste{d, parent}; | ||
1012 | 44 | } | ||
1013 | 45 | |||
1014 | 46 | Private(const QDBusObjectPath& paste, QObject* parent) | ||
1015 | 47 | : QObject(parent), | ||
1016 | 48 | remote_paste( | ||
1017 | 49 | new com::ubuntu::content::dbus::Paste( | ||
1018 | 50 | HUB_SERVICE_NAME, | ||
1019 | 51 | paste.path(), | ||
1020 | 52 | QDBusConnection::sessionBus(), this)) | ||
1021 | 53 | { | ||
1022 | 54 | } | ||
1023 | 55 | |||
1024 | 56 | int id() | ||
1025 | 57 | { | ||
1026 | 58 | auto reply = remote_paste->Id(); | ||
1027 | 59 | reply.waitForFinished(); | ||
1028 | 60 | |||
1029 | 61 | return reply.value(); | ||
1030 | 62 | } | ||
1031 | 63 | |||
1032 | 64 | State state() | ||
1033 | 65 | { | ||
1034 | 66 | auto reply = remote_paste->State(); | ||
1035 | 67 | reply.waitForFinished(); | ||
1036 | 68 | |||
1037 | 69 | if (reply.isError()) | ||
1038 | 70 | return Paste::aborted; | ||
1039 | 71 | |||
1040 | 72 | return static_cast<Paste::State>(reply.value()); | ||
1041 | 73 | } | ||
1042 | 74 | |||
1043 | 75 | bool abort() | ||
1044 | 76 | { | ||
1045 | 77 | auto reply = remote_paste->Abort(); | ||
1046 | 78 | reply.waitForFinished(); | ||
1047 | 79 | |||
1048 | 80 | return not reply.isError(); | ||
1049 | 81 | } | ||
1050 | 82 | |||
1051 | 83 | bool finalize() | ||
1052 | 84 | { | ||
1053 | 85 | auto reply = remote_paste->Finalize(); | ||
1054 | 86 | reply.waitForFinished(); | ||
1055 | 87 | |||
1056 | 88 | return not reply.isError(); | ||
1057 | 89 | } | ||
1058 | 90 | |||
1059 | 91 | bool charge(const QVector<Item>& items) | ||
1060 | 92 | { | ||
1061 | 93 | QVariantList itemVariants; | ||
1062 | 94 | Q_FOREACH(const Item& item, items) | ||
1063 | 95 | { | ||
1064 | 96 | itemVariants << QVariant::fromValue(item); | ||
1065 | 97 | } | ||
1066 | 98 | auto reply = remote_paste->Charge(itemVariants); | ||
1067 | 99 | reply.waitForFinished(); | ||
1068 | 100 | |||
1069 | 101 | return not reply.isError(); | ||
1070 | 102 | } | ||
1071 | 103 | |||
1072 | 104 | QVector<Item> collect() | ||
1073 | 105 | { | ||
1074 | 106 | QVector<Item> result; | ||
1075 | 107 | |||
1076 | 108 | auto reply = remote_paste->Collect(); | ||
1077 | 109 | reply.waitForFinished(); | ||
1078 | 110 | |||
1079 | 111 | if (reply.isError()) | ||
1080 | 112 | return result; | ||
1081 | 113 | |||
1082 | 114 | auto items = reply.value(); | ||
1083 | 115 | |||
1084 | 116 | Q_FOREACH(const QVariant& itemVariant, items) | ||
1085 | 117 | { | ||
1086 | 118 | result << qdbus_cast<Item>(itemVariant); | ||
1087 | 119 | } | ||
1088 | 120 | |||
1089 | 121 | return result; | ||
1090 | 122 | } | ||
1091 | 123 | |||
1092 | 124 | QString source() | ||
1093 | 125 | { | ||
1094 | 126 | auto reply = remote_paste->source(); | ||
1095 | 127 | reply.waitForFinished(); | ||
1096 | 128 | |||
1097 | 129 | return static_cast<QString>(reply.value()); | ||
1098 | 130 | } | ||
1099 | 131 | |||
1100 | 132 | com::ubuntu::content::dbus::Paste* remote_paste; | ||
1101 | 133 | }; | ||
1102 | 134 | } | ||
1103 | 135 | } | ||
1104 | 136 | } | ||
1105 | 137 | |||
1106 | 138 | #endif // COM_UBUNTU_CONTENT_PASTE_P_H_ | ||
1107 | 0 | 139 | ||
1108 | === modified file 'tests/acceptance-tests/CMakeLists.txt' | |||
1109 | --- tests/acceptance-tests/CMakeLists.txt 2015-06-29 13:46:54 +0000 | |||
1110 | +++ tests/acceptance-tests/CMakeLists.txt 2016-06-02 17:19:28 +0000 | |||
1111 | @@ -41,6 +41,12 @@ | |||
1112 | 41 | ) | 41 | ) |
1113 | 42 | 42 | ||
1114 | 43 | add_executable( | 43 | add_executable( |
1115 | 44 | app_hub_communication_paste | ||
1116 | 45 | app_hub_communication_paste.cpp | ||
1117 | 46 | ${MOCS} | ||
1118 | 47 | ) | ||
1119 | 48 | |||
1120 | 49 | add_executable( | ||
1121 | 44 | app_hub_communication_handler | 50 | app_hub_communication_handler |
1122 | 45 | app_hub_communication_handler.cpp | 51 | app_hub_communication_handler.cpp |
1123 | 46 | ${MOCS} | 52 | ${MOCS} |
1124 | @@ -72,6 +78,7 @@ | |||
1125 | 72 | qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test) | 78 | qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test) |
1126 | 73 | qt5_use_modules(app_hub_communication_stores Core Gui DBus Test) | 79 | qt5_use_modules(app_hub_communication_stores Core Gui DBus Test) |
1127 | 74 | qt5_use_modules(app_hub_communication_transfer Core Gui DBus Test) | 80 | qt5_use_modules(app_hub_communication_transfer Core Gui DBus Test) |
1128 | 81 | qt5_use_modules(app_hub_communication_paste Core Gui DBus Test) | ||
1129 | 75 | qt5_use_modules(app_hub_communication_handler Core Gui DBus Test) | 82 | qt5_use_modules(app_hub_communication_handler Core Gui DBus Test) |
1130 | 76 | qt5_use_modules(test_utils Core Test) | 83 | qt5_use_modules(test_utils Core Test) |
1131 | 77 | qt5_use_modules(test_hook Core Gui DBus Test) | 84 | qt5_use_modules(test_hook Core Gui DBus Test) |
1132 | @@ -81,6 +88,7 @@ | |||
1133 | 81 | target_link_libraries(app_hub_communication_known_sources content-hub gmock gtest gtest_main) | 88 | target_link_libraries(app_hub_communication_known_sources content-hub gmock gtest gtest_main) |
1134 | 82 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) | 89 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) |
1135 | 83 | target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main) | 90 | target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main) |
1136 | 91 | target_link_libraries(app_hub_communication_paste content-hub gmock gtest gtest_main) | ||
1137 | 84 | target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main) | 92 | target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main) |
1138 | 85 | target_link_libraries(test_utils content-hub gmock gtest gtest_main) | 93 | target_link_libraries(test_utils content-hub gmock gtest gtest_main) |
1139 | 86 | target_link_libraries(test_types content-hub gmock gtest gtest_main) | 94 | target_link_libraries(test_types content-hub gmock gtest gtest_main) |
1140 | @@ -90,6 +98,7 @@ | |||
1141 | 90 | add_test(app_hub_communication_known_sources app_hub_communication_known_sources) | 98 | add_test(app_hub_communication_known_sources app_hub_communication_known_sources) |
1142 | 91 | add_test(app_hub_communication_stores app_hub_communication_stores) | 99 | add_test(app_hub_communication_stores app_hub_communication_stores) |
1143 | 92 | add_test(app_hub_communication_transfer app_hub_communication_transfer) | 100 | add_test(app_hub_communication_transfer app_hub_communication_transfer) |
1144 | 101 | add_test(app_hub_communication_paste app_hub_communication_transfer) | ||
1145 | 93 | add_test(app_hub_communication_handler app_hub_communication_handler) | 102 | add_test(app_hub_communication_handler app_hub_communication_handler) |
1146 | 94 | add_test(test_utils test_utils) | 103 | add_test(test_utils test_utils) |
1147 | 95 | add_test(test_types test_types) | 104 | add_test(test_types test_types) |
1148 | 96 | 105 | ||
1149 | === added file 'tests/acceptance-tests/app_hub_communication_paste.cpp' | |||
1150 | --- tests/acceptance-tests/app_hub_communication_paste.cpp 1970-01-01 00:00:00 +0000 | |||
1151 | +++ tests/acceptance-tests/app_hub_communication_paste.cpp 2016-06-02 17:19:28 +0000 | |||
1152 | @@ -0,0 +1,136 @@ | |||
1153 | 1 | /* | ||
1154 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1155 | 3 | * | ||
1156 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1157 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1158 | 6 | * published by the Free Software Foundation. | ||
1159 | 7 | * | ||
1160 | 8 | * This program is distributed in the hope that it will be useful, | ||
1161 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1162 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1163 | 11 | * GNU Lesser General Public License for more details. | ||
1164 | 12 | * | ||
1165 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1166 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1167 | 15 | * | ||
1168 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
1169 | 17 | */ | ||
1170 | 18 | |||
1171 | 19 | #include "app_manager_mock.h" | ||
1172 | 20 | #include "test_harness.h" | ||
1173 | 21 | #include "../cross_process_sync.h" | ||
1174 | 22 | #include "../fork_and_run.h" | ||
1175 | 23 | |||
1176 | 24 | #include <com/ubuntu/content/hub.h> | ||
1177 | 25 | #include <com/ubuntu/content/item.h> | ||
1178 | 26 | #include <com/ubuntu/content/paste.h> | ||
1179 | 27 | |||
1180 | 28 | #include "com/ubuntu/content/detail/peer_registry.h" | ||
1181 | 29 | #include "com/ubuntu/content/detail/service.h" | ||
1182 | 30 | #include "com/ubuntu/content/serviceadaptor.h" | ||
1183 | 31 | |||
1184 | 32 | #include <gmock/gmock.h> | ||
1185 | 33 | #include <gtest/gtest.h> | ||
1186 | 34 | |||
1187 | 35 | #include <QCoreApplication> | ||
1188 | 36 | #include <QtDBus/QDBusConnection> | ||
1189 | 37 | #include <QStandardPaths> | ||
1190 | 38 | #include <QTemporaryDir> | ||
1191 | 39 | #include <QtTest/QTest> | ||
1192 | 40 | |||
1193 | 41 | #include <thread> | ||
1194 | 42 | |||
1195 | 43 | namespace cua = com::ubuntu::ApplicationManager; | ||
1196 | 44 | namespace cuc = com::ubuntu::content; | ||
1197 | 45 | namespace cucd = com::ubuntu::content::detail; | ||
1198 | 46 | |||
1199 | 47 | void PrintTo(const QString& s, ::std::ostream* os) { | ||
1200 | 48 | *os << std::string(qPrintable(s)); | ||
1201 | 49 | } | ||
1202 | 50 | |||
1203 | 51 | namespace | ||
1204 | 52 | { | ||
1205 | 53 | QString service_name{"com.ubuntu.content.dbus.Service"}; | ||
1206 | 54 | |||
1207 | 55 | struct MockedPeerRegistry : public cucd::PeerRegistry | ||
1208 | 56 | { | ||
1209 | 57 | MockedPeerRegistry() : cucd::PeerRegistry() | ||
1210 | 58 | { | ||
1211 | 59 | using namespace ::testing; | ||
1212 | 60 | |||
1213 | 61 | ON_CALL(*this, default_source_for_type(_)).WillByDefault(Return(cuc::Peer::unknown())); | ||
1214 | 62 | ON_CALL(*this, install_default_source_for_type(_,_)).WillByDefault(Return(false)); | ||
1215 | 63 | ON_CALL(*this, install_source_for_type(_,_)).WillByDefault(Return(false)); | ||
1216 | 64 | } | ||
1217 | 65 | |||
1218 | 66 | MOCK_METHOD1(default_source_for_type, cuc::Peer(cuc::Type t)); | ||
1219 | 67 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | ||
1220 | 68 | MOCK_METHOD2(enumerate_known_sources_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
1221 | 69 | MOCK_METHOD2(enumerate_known_destinations_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
1222 | 70 | MOCK_METHOD2(enumerate_known_shares_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
1223 | 71 | MOCK_METHOD2(install_default_source_for_type, bool(cuc::Type, cuc::Peer)); | ||
1224 | 72 | MOCK_METHOD2(install_source_for_type, bool(cuc::Type, cuc::Peer)); | ||
1225 | 73 | MOCK_METHOD2(install_destination_for_type, bool(cuc::Type, cuc::Peer)); | ||
1226 | 74 | MOCK_METHOD2(install_share_for_type, bool(cuc::Type, cuc::Peer)); | ||
1227 | 75 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
1228 | 76 | MOCK_METHOD1(peer_is_legacy, bool(QString)); | ||
1229 | 77 | }; | ||
1230 | 78 | } | ||
1231 | 79 | |||
1232 | 80 | TEST(Hub, transfer_creation_and_states_work) | ||
1233 | 81 | { | ||
1234 | 82 | using namespace ::testing; | ||
1235 | 83 | |||
1236 | 84 | test::CrossProcessSync sync; | ||
1237 | 85 | |||
1238 | 86 | auto parent = [&sync]() | ||
1239 | 87 | { | ||
1240 | 88 | int argc = 0; | ||
1241 | 89 | QCoreApplication app{argc, nullptr}; | ||
1242 | 90 | |||
1243 | 91 | QDBusConnection connection = QDBusConnection::sessionBus(); | ||
1244 | 92 | |||
1245 | 93 | auto mock = new ::testing::NiceMock<MockedPeerRegistry>{}; | ||
1246 | 94 | |||
1247 | 95 | QSharedPointer<cucd::PeerRegistry> registry{mock}; | ||
1248 | 96 | auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager()); | ||
1249 | 97 | cucd::Service implementation(connection, registry, app_manager, &app); | ||
1250 | 98 | new ServiceAdaptor(std::addressof(implementation)); | ||
1251 | 99 | |||
1252 | 100 | ASSERT_TRUE(connection.registerService(service_name)); | ||
1253 | 101 | ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation))); | ||
1254 | 102 | |||
1255 | 103 | sync.signal_ready(); | ||
1256 | 104 | |||
1257 | 105 | app.exec(); | ||
1258 | 106 | |||
1259 | 107 | connection.unregisterObject("/"); | ||
1260 | 108 | connection.unregisterService(service_name); | ||
1261 | 109 | }; | ||
1262 | 110 | |||
1263 | 111 | auto child = [&sync]() | ||
1264 | 112 | { | ||
1265 | 113 | int argc = 0; | ||
1266 | 114 | QCoreApplication app(argc, nullptr); | ||
1267 | 115 | |||
1268 | 116 | sync.wait_for_signal_ready(); | ||
1269 | 117 | |||
1270 | 118 | test::TestHarness harness; | ||
1271 | 119 | harness.add_test_case([]() | ||
1272 | 120 | { | ||
1273 | 121 | qputenv("APP_ID", "some-app"); | ||
1274 | 122 | const char * data = "some text"; | ||
1275 | 123 | auto hub = cuc::Hub::Client::instance(); | ||
1276 | 124 | |||
1277 | 125 | auto paste = hub->create_paste(data); | ||
1278 | 126 | ASSERT_TRUE(paste != nullptr); | ||
1279 | 127 | EXPECT_EQ(QString(data), QString(hub->latest_paste_buf())); | ||
1280 | 128 | EXPECT_EQ(QString(data), QString(hub->paste_buf_by_id(1))); | ||
1281 | 129 | |||
1282 | 130 | hub->quit(); | ||
1283 | 131 | }); | ||
1284 | 132 | EXPECT_EQ(0, QTest::qExec(std::addressof(harness))); | ||
1285 | 133 | }; | ||
1286 | 134 | |||
1287 | 135 | EXPECT_EQ(EXIT_SUCCESS, test::fork_and_run(child, parent)); | ||
1288 | 136 | } |