Merge lp:~ken-vandine/content-hub/pasteboard into lp:content-hub

Proposed by Ken VanDine
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
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

To post a comment you must log in.
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 MimeDataSerialization 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

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

Subscribers

People subscribed via source and target branches