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
=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt 2013-08-27 22:15:29 +0000
+++ examples/CMakeLists.txt 2016-06-02 17:19:28 +0000
@@ -16,3 +16,4 @@
1616
17add_subdirectory(importer)17add_subdirectory(importer)
18add_subdirectory(exporter)18add_subdirectory(exporter)
19add_subdirectory(pasteboard)
1920
=== added directory 'examples/pasteboard'
=== added file 'examples/pasteboard/CMakeLists.txt'
--- examples/pasteboard/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ examples/pasteboard/CMakeLists.txt 2016-06-02 17:19:28 +0000
@@ -0,0 +1,55 @@
1# Copyright © 2016 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License version 3 as
5# published by the Free Software Foundation.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#
15# Authored by: Ken VanDine <ken.vandine@canonical.com>
16
17include_directories(${CMAKE_CURRENT_BINARY_DIR})
18
19add_executable(
20 copy-to-pasteboard
21
22 copy.cpp
23)
24
25qt5_use_modules(copy-to-pasteboard Core Gui DBus)
26
27set_target_properties(
28 copy-to-pasteboard
29 PROPERTIES
30 AUTOMOC TRUE
31)
32
33target_link_libraries(
34 copy-to-pasteboard
35 content-hub
36)
37
38add_executable(
39 paste-from-pasteboard
40
41 paste.cpp
42)
43
44qt5_use_modules(paste-from-pasteboard Core Gui DBus)
45
46set_target_properties(
47 paste-from-pasteboard
48 PROPERTIES
49 AUTOMOC TRUE
50)
51
52target_link_libraries(
53 paste-from-pasteboard
54 content-hub
55)
056
=== added file 'examples/pasteboard/copy.cpp'
--- examples/pasteboard/copy.cpp 1970-01-01 00:00:00 +0000
+++ examples/pasteboard/copy.cpp 2016-06-02 17:19:28 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18
19#include <QCoreApplication>
20#include <QDebug>
21#include <QStringList>
22#include <com/ubuntu/content/hub.h>
23#include <com/ubuntu/content/paste.h>
24
25namespace cuc = com::ubuntu::content;
26
27int main(int argc, char *argv[])
28{
29 QCoreApplication a(argc, argv);
30 if (qgetenv("APP_ID").isEmpty()) {
31 qputenv("APP_ID", "copy-to-pasteboard");
32 }
33
34 QString text("Some text");
35
36 if (a.arguments().size() > 1)
37 text = a.arguments().at(1);
38
39 const char * data = text.toStdString().c_str();
40 auto hub = cuc::Hub::Client::instance();
41
42 auto paste = hub->create_paste(data);
43 qDebug() << paste->id() << ":" << text;
44}
045
=== added file 'examples/pasteboard/paste.cpp'
--- examples/pasteboard/paste.cpp 1970-01-01 00:00:00 +0000
+++ examples/pasteboard/paste.cpp 2016-06-02 17:19:28 +0000
@@ -0,0 +1,45 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18
19#include <QCoreApplication>
20#include <QStringList>
21#include <com/ubuntu/content/hub.h>
22
23namespace cuc = com::ubuntu::content;
24
25int main(int argc, char *argv[])
26{
27 QCoreApplication a(argc, argv);
28 if (qgetenv("APP_ID").isEmpty()) {
29 qputenv("APP_ID", "paste-from-pasteboard");
30 }
31
32 QString id("latest");
33
34 if (a.arguments().size() > 1)
35 id = a.arguments().at(1);
36
37 auto hub = cuc::Hub::Client::instance();
38 const char* buf = NULL;
39 if (id == "latest")
40 buf = hub->latest_paste_buf();
41 else
42 buf = hub->paste_buf_by_id(id.toInt());
43 qDebug() << id << ":" << buf;
44 return 0;
45}
046
=== modified file 'import/Ubuntu/Content/CMakeLists.txt'
--- import/Ubuntu/Content/CMakeLists.txt 2015-10-24 00:24:30 +0000
+++ import/Ubuntu/Content/CMakeLists.txt 2016-06-02 17:19:28 +0000
@@ -101,7 +101,7 @@
101endif()101endif()
102102
103add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes103add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes
104 COMMAND ${QT_INSTALL_BINS}/qmlplugindump -notrelocatable Ubuntu.Content 1.1 ../../ > ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes104 COMMAND ${QT_INSTALL_BINS}/qmlplugindump -noinstantiate -notrelocatable Ubuntu.Content 1.1 ../../ > ${CMAKE_CURRENT_BINARY_DIR}/plugins.qmltypes
105 DEPENDS ${PLUGIN}105 DEPENDS ${PLUGIN}
106 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"106 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
107)107)
108108
=== modified file 'include/com/ubuntu/content/hub.h'
--- include/com/ubuntu/content/hub.h 2015-09-29 13:15:58 +0000
+++ include/com/ubuntu/content/hub.h 2016-06-02 17:19:28 +0000
@@ -34,6 +34,7 @@
34class ImportExportHandler;34class ImportExportHandler;
35class Store;35class Store;
36class Transfer;36class Transfer;
37class Paste;
3738
38class Hub : public QObject39class Hub : public QObject
39{40{
@@ -66,6 +67,9 @@
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);
67 Q_INVOKABLE virtual bool has_pending(QString peer_id);68 Q_INVOKABLE virtual bool has_pending(QString peer_id);
68 Q_INVOKABLE virtual Peer peer_for_app_id(QString app_id);69 Q_INVOKABLE virtual Peer peer_for_app_id(QString app_id);
70 Q_INVOKABLE virtual Paste* create_paste(const char * data);
71 Q_INVOKABLE virtual const char* latest_paste_buf();
72 Q_INVOKABLE virtual const char* paste_buf_by_id(int id);
69 73
70 protected:74 protected:
71 Hub(QObject* = nullptr);75 Hub(QObject* = nullptr);
7276
=== added file 'include/com/ubuntu/content/paste.h'
--- include/com/ubuntu/content/paste.h 1970-01-01 00:00:00 +0000
+++ include/com/ubuntu/content/paste.h 2016-06-02 17:19:28 +0000
@@ -0,0 +1,98 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18#ifndef COM_UBUNTU_CONTENT_PASTE_H_
19#define COM_UBUNTU_CONTENT_PASTE_H_
20
21#include <com/ubuntu/content/item.h>
22
23#include <QObject>
24#include <QSharedPointer>
25#include <QVector>
26#include <QString>
27
28namespace com
29{
30namespace ubuntu
31{
32namespace content
33{
34namespace detail
35{
36class Handler;
37}
38}
39}
40}
41
42namespace com
43{
44namespace ubuntu
45{
46namespace content
47{
48class Item;
49
50class Paste : public QObject
51{
52 Q_OBJECT
53 Q_ENUMS(State)
54 Q_PROPERTY(int id READ id)
55 Q_PROPERTY(State state READ state NOTIFY stateChanged)
56 Q_PROPERTY(QVector<Item> items READ collect WRITE charge)
57 Q_PROPERTY(QString source READ source)
58
59 public:
60 enum State
61 {
62 created,
63 charged,
64 saved,
65 collected,
66 aborted,
67 finalized
68 };
69
70 Paste(const Paste&) = delete;
71 virtual ~Paste();
72
73 Paste& operator=(const Paste&) = delete;
74
75 Q_INVOKABLE virtual int id() const;
76 Q_INVOKABLE virtual State state() const;
77 Q_INVOKABLE virtual bool abort();
78 Q_INVOKABLE virtual bool finalize();
79 Q_INVOKABLE virtual bool charge(const QVector<Item>& items);
80 Q_INVOKABLE virtual QVector<Item> collect();
81 Q_INVOKABLE virtual QString source() const;
82
83 Q_SIGNAL void stateChanged();
84
85 private:
86 struct Private;
87 friend struct Private;
88 friend class Hub;
89 friend class com::ubuntu::content::detail::Handler;
90 QSharedPointer<Private> d;
91
92 Paste(const QSharedPointer<Private>&, QObject* parent = nullptr);
93};
94}
95}
96}
97
98#endif // COM_UBUNTU_CONTENT_PASTE_H_
099
=== modified file 'src/com/ubuntu/content/CMakeLists.txt'
--- src/com/ubuntu/content/CMakeLists.txt 2015-09-23 14:45:09 +0000
+++ src/com/ubuntu/content/CMakeLists.txt 2016-06-02 17:19:28 +0000
@@ -47,6 +47,13 @@
47 detail/transfer.h com::ubuntu::content::detail::Transfer)47 detail/transfer.h com::ubuntu::content::detail::Transfer)
4848
49qt5_add_dbus_interface(49qt5_add_dbus_interface(
50 CONTENT_PASTE_STUB ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml
51 ContentPasteInterface)
52qt5_add_dbus_adaptor(
53 CONTENT_PASTE_SKELETON ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml
54 detail/paste.h com::ubuntu::content::detail::Paste)
55
56qt5_add_dbus_interface(
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
51 ContentHandlerInterface)58 ContentHandlerInterface)
52qt5_add_dbus_adaptor(59qt5_add_dbus_adaptor(
@@ -56,6 +63,7 @@
56qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/hub.h)63qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/hub.h)
57qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/import_export_handler.h)64qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/import_export_handler.h)
58qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/item.h)65qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/item.h)
66qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/paste.h)
59qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/peer.h)67qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/peer.h)
60qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/store.h)68qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/store.h)
61qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/transfer.h)69qt5_wrap_cpp(CONTENT_HUB_MOCS ${CMAKE_SOURCE_DIR}/include/com/ubuntu/content/transfer.h)
@@ -67,6 +75,7 @@
67 hub.cpp75 hub.cpp
68 import_export_handler.cpp76 import_export_handler.cpp
69 item.cpp77 item.cpp
78 paste.cpp
70 peer.cpp79 peer.cpp
71 store.cpp80 store.cpp
72 transfer.cpp81 transfer.cpp
@@ -75,6 +84,7 @@
75 debug.cpp84 debug.cpp
7685
77 detail/app_manager.cpp86 detail/app_manager.cpp
87 detail/paste.cpp
78 detail/service.cpp88 detail/service.cpp
79 detail/transfer.cpp89 detail/transfer.cpp
80 detail/handler.cpp90 detail/handler.cpp
@@ -83,6 +93,8 @@
83 ${CONTENT_HUB_MOCS}93 ${CONTENT_HUB_MOCS}
84 ${CONTENT_SERVICE_STUB}94 ${CONTENT_SERVICE_STUB}
85 ${CONTENT_SERVICE_SKELETON}95 ${CONTENT_SERVICE_SKELETON}
96 ${CONTENT_PASTE_STUB}
97 ${CONTENT_PASTE_SKELETON}
86 ${CONTENT_TRANSFER_STUB}98 ${CONTENT_TRANSFER_STUB}
87 ${CONTENT_TRANSFER_SKELETON}99 ${CONTENT_TRANSFER_SKELETON}
88 ${CONTENT_HANDLER_STUB}100 ${CONTENT_HANDLER_STUB}
89101
=== added file 'src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml'
--- src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml 1970-01-01 00:00:00 +0000
+++ src/com/ubuntu/content/detail/com.ubuntu.content.Paste.xml 2016-06-02 17:19:28 +0000
@@ -0,0 +1,26 @@
1<node>
2 <interface name="com.ubuntu.content.dbus.Paste">
3 <signal name="StateChanged">
4 <arg name="state" type="i"/>
5 </signal>
6 <method name="Id">
7 <arg name="id" type="i" direction="out" />
8 </method>
9 <method name="State">
10 <arg name="state" type="i" direction="out" />
11 </method>
12 <method name="Abort">
13 </method>
14 <method name="Finalize">
15 </method>
16 <method name="Charge">
17 <arg name="items" type="av" direction="in" />
18 </method>
19 <method name="Collect">
20 <arg name="items" type="av" direction="out" />
21 </method>
22 <method name="source">
23 <arg name="source" type="s" direction="out" />
24 </method>
25 </interface>
26</node>
027
=== modified file 'src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml'
--- src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml 2015-09-29 13:15:58 +0000
+++ src/com/ubuntu/content/detail/com.ubuntu.content.Service.xml 2016-06-02 17:19:28 +0000
@@ -36,6 +36,19 @@
36 <arg name="type_id" type="s" direction="in" />36 <arg name="type_id" type="s" direction="in" />
37 <arg name="transfer_object" type="o" direction="out" />37 <arg name="transfer_object" type="o" direction="out" />
38 </method>38 </method>
39 <method name="CreatePaste">
40 <arg name="app_id" type="s" direction="in" />
41 <arg name="paste_object" type="o" direction="out" />
42 </method>
43 <method name="GetLatestPaste">
44 <arg name="app_id" type="s" direction="in" />
45 <arg name="paste_object" type="o" direction="out" />
46 </method>
47 <method name="GetPaste">
48 <arg name="id" type="s" direction="in" />
49 <arg name="app_id" type="s" direction="in" />
50 <arg name="paste_object" type="o" direction="out" />
51 </method>
39 <method name="RegisterImportExportHandler">52 <method name="RegisterImportExportHandler">
40 <arg name="peer_id" type="s" direction="in" />53 <arg name="peer_id" type="s" direction="in" />
41 <arg name="handler_object" type="o" direction="in" />54 <arg name="handler_object" type="o" direction="in" />
4255
=== added file 'src/com/ubuntu/content/detail/paste.cpp'
--- src/com/ubuntu/content/detail/paste.cpp 1970-01-01 00:00:00 +0000
+++ src/com/ubuntu/content/detail/paste.cpp 2016-06-02 17:19:28 +0000
@@ -0,0 +1,166 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18
19#include "debug.h"
20#include "paste.h"
21#include "utils.cpp"
22
23#include <QFileInfo>
24#include <com/ubuntu/content/hub.h>
25#include <com/ubuntu/content/store.h>
26#include <com/ubuntu/content/paste.h>
27#include <ubuntu/download_manager/download.h>
28#include <ubuntu/download_manager/manager.h>
29
30namespace cuc = com::ubuntu::content;
31namespace cucd = com::ubuntu::content::detail;
32
33struct cucd::Paste::Private
34{
35 Private(const int id,
36 const QString& source):
37 state(cuc::Paste::created),
38 id(id),
39 source(source)
40 {
41 }
42
43 cuc::Paste::State state;
44 const int id;
45 const QString source;
46 QString destination;
47 QVariantList items;
48};
49
50cucd::Paste::Paste(const int id,
51 const QString& source,
52 QObject* parent) :
53 QObject(parent), d(new Private(id, source))
54{
55 TRACE() << __PRETTY_FUNCTION__;
56}
57
58cucd::Paste::~Paste()
59{
60 TRACE() << __PRETTY_FUNCTION__;
61}
62
63/* unique id of the paste */
64int cucd::Paste::Id()
65{
66 TRACE() << __PRETTY_FUNCTION__;
67 return d->id;
68}
69
70/* returns the add_id of the source app */
71QString cucd::Paste::source()
72{
73 TRACE() << __PRETTY_FUNCTION__;
74 return d->source;
75}
76
77/* returns the add_id of the destination app */
78QString cucd::Paste::destination()
79{
80 TRACE() << __PRETTY_FUNCTION__;
81 if (d->destination.isEmpty())
82 return d->source;
83 return d->destination;
84}
85
86void cucd::Paste::setDestination(QString& dest)
87{
88 TRACE() << __PRETTY_FUNCTION__;
89 d->destination = dest;
90}
91
92/* returns the object path for the paste */
93QString cucd::Paste::path()
94{
95 TRACE() << Q_FUNC_INFO << "destination:" << destination();
96 static const QString path_pattern{"/pastes/%1/%2"};
97 QString path = path_pattern
98 .arg(sanitize_id(destination()))
99 .arg(d->id);
100 return path;
101}
102
103int cucd::Paste::State()
104{
105 TRACE() << __PRETTY_FUNCTION__;
106 return d->state;
107}
108
109void cucd::Paste::Abort()
110{
111 TRACE() << __PRETTY_FUNCTION__;
112
113 if (d->state == cuc::Paste::aborted)
114 return;
115
116 d->items.clear();
117 d->state = cuc::Paste::aborted;
118 Q_EMIT(StateChanged(d->state));
119}
120
121void cucd::Paste::Charge(const QVariantList& items)
122{
123 TRACE() << __PRETTY_FUNCTION__ << "STATE:" << d->state;
124
125 if (d->state == cuc::Paste::charged)
126 return;
127
128 QVariantList ret;
129 Q_FOREACH(QVariant iv, items) {
130 cuc::Item item = qdbus_cast<Item>(iv);
131 ret.append(QVariant::fromValue(item));
132 }
133 if (ret.count() <= 0) {
134 qWarning() << "Failed to charge items, aborting";
135 d->state = cuc::Paste::aborted;
136 } else {
137 d->items = ret;
138 d->state = cuc::Paste::charged;
139 }
140 Q_EMIT(StateChanged(d->state));
141}
142
143QVariantList cucd::Paste::Collect()
144{
145 TRACE() << __PRETTY_FUNCTION__;
146
147 if (d->state != cuc::Paste::collected)
148 {
149 d->state = cuc::Paste::collected;
150 Q_EMIT(StateChanged(d->state));
151 }
152
153 return d->items;
154}
155
156void cucd::Paste::Finalize()
157{
158 TRACE() << __PRETTY_FUNCTION__;
159
160 if (d->state == cuc::Paste::finalized)
161 return;
162
163 d->items.clear();
164 d->state = cuc::Paste::finalized;
165 Q_EMIT(StateChanged(d->state));
166}
0167
=== added file 'src/com/ubuntu/content/detail/paste.h'
--- src/com/ubuntu/content/detail/paste.h 1970-01-01 00:00:00 +0000
+++ src/com/ubuntu/content/detail/paste.h 2016-06-02 17:19:28 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18#ifndef PASTE_H_
19#define PASTE_H_
20
21#include <QDir>
22#include <QObject>
23#include <QtDBus/QDBusMessage>
24#include <QtDBus/QDBusContext>
25
26namespace com
27{
28namespace ubuntu
29{
30namespace content
31{
32namespace detail
33{
34class Paste : public QObject, protected QDBusContext
35{
36 Q_OBJECT
37 Q_PROPERTY(int State READ State NOTIFY StateChanged)
38 Q_PROPERTY(int id READ Id)
39 Q_PROPERTY(QString source READ source)
40
41 public:
42 Paste(const int, const QString&, QObject* parent = nullptr);
43 Paste(const Paste&) = delete;
44 virtual ~Paste();
45
46 Paste& operator=(const Paste&) = delete;
47
48Q_SIGNALS:
49 void StateChanged(int State);
50
51 public Q_SLOTS:
52 int State();
53 void Charge(const QVariantList&);
54 QVariantList Collect();
55 void Abort();
56 void Finalize();
57 int Id();
58 QString source();
59 QString destination();
60 void setDestination(QString&);
61 QString path();
62
63 private:
64 struct Private;
65 QScopedPointer<Private> d;
66
67};
68}
69}
70}
71}
72
73#endif // PASTE_H_
074
=== modified file 'src/com/ubuntu/content/detail/service.cpp'
--- src/com/ubuntu/content/detail/service.cpp 2016-01-29 17:20:58 +0000
+++ src/com/ubuntu/content/detail/service.cpp 2016-06-02 17:19:28 +0000
@@ -23,6 +23,8 @@
23#include "service.h"23#include "service.h"
24#include "peer_registry.h"24#include "peer_registry.h"
25#include "i18n.h"25#include "i18n.h"
26#include "paste.h"
27#include "pasteadaptor.h"
26#include "transfer.h"28#include "transfer.h"
27#include "transferadaptor.h"29#include "transferadaptor.h"
28#include "utils.cpp"30#include "utils.cpp"
@@ -33,6 +35,7 @@
33#include <libnotify/notify.h>35#include <libnotify/notify.h>
3436
35#include <com/ubuntu/content/item.h>37#include <com/ubuntu/content/item.h>
38#include <com/ubuntu/content/paste.h>
36#include <com/ubuntu/content/peer.h>39#include <com/ubuntu/content/peer.h>
37#include <com/ubuntu/content/type.h>40#include <com/ubuntu/content/type.h>
38#include <com/ubuntu/content/transfer.h>41#include <com/ubuntu/content/transfer.h>
@@ -79,6 +82,7 @@
79 QDBusConnection connection;82 QDBusConnection connection;
80 QSharedPointer<cucd::PeerRegistry> registry;83 QSharedPointer<cucd::PeerRegistry> registry;
81 QSet<cucd::Transfer*> active_transfers;84 QSet<cucd::Transfer*> active_transfers;
85 QList<cucd::Paste*> active_pastes;
82 QSet<RegHandler*> handlers;86 QSet<RegHandler*> handlers;
83 QSharedPointer<cua::ApplicationManager> app_manager;87 QSharedPointer<cua::ApplicationManager> app_manager;
8488
@@ -302,6 +306,74 @@
302 return CreateTransfer(peer_id, src_id, cuc::Transfer::Share, type_id);306 return CreateTransfer(peer_id, src_id, cuc::Transfer::Share, type_id);
303}307}
304308
309QDBusObjectPath cucd::Service::CreatePaste(const QString& app_id)
310{
311 TRACE() << Q_FUNC_INFO << app_id;
312 static size_t import_counter{0}; import_counter++;
313
314 QUuid uuid{QUuid::createUuid()};
315
316 auto paste = new cucd::Paste(import_counter, app_id, this);
317 new PasteAdaptor(paste);
318 d->active_pastes.append(paste);
319
320 auto path = paste->path();
321 if (not d->connection.registerObject(path, paste))
322 qWarning() << "Problem registering object for path: " << path;
323
324 connect(paste, SIGNAL(StateChanged(int)), this, SLOT(handle_pastes(int)));
325 return QDBusObjectPath{path};
326}
327
328QDBusObjectPath cucd::Service::GetLatestPaste(const QString& app_id)
329{
330 TRACE() << Q_FUNC_INFO << app_id;
331 if (d->active_pastes.isEmpty())
332 return QDBusObjectPath();
333
334 QString dest_id = app_id;
335 if (dest_id.isEmpty())
336 {
337 TRACE() << Q_FUNC_INFO << "APP_ID isnt' set, attempting to get it from AppArmor";
338 dest_id = aa_profile(this->message().service());
339 }
340
341 auto paste = d->active_pastes.last();
342 d->connection.unregisterObject(paste->path());
343 paste->setDestination(dest_id);
344 auto path = paste->path();
345 if (not d->connection.registerObject(path, paste))
346 qWarning() << "Problem registering object for path: " << path;
347 return QDBusObjectPath(paste->path());
348}
349
350QDBusObjectPath cucd::Service::GetPaste(const QString& id, const QString& app_id)
351{
352 TRACE() << Q_FUNC_INFO << id;
353 if (d->active_pastes.isEmpty())
354 return QDBusObjectPath();
355
356 QString dest_id = app_id;
357 if (dest_id.isEmpty())
358 {
359 TRACE() << Q_FUNC_INFO << "APP_ID isnt' set, attempting to get it from AppArmor";
360 dest_id = aa_profile(this->message().service());
361 }
362
363 Q_FOREACH (cucd::Paste *p, d->active_pastes)
364 {
365 if (p->Id() == id.toInt()) {
366 d->connection.unregisterObject(p->path());
367 p->setDestination(dest_id);
368 auto path = p->path();
369 if (not d->connection.registerObject(path, p))
370 qWarning() << "Problem registering object for path: " << path;
371 return QDBusObjectPath(path);
372 }
373 }
374 return QDBusObjectPath();
375}
376
305QDBusObjectPath cucd::Service::CreateTransfer(const QString& dest_id, const QString& src_id, int dir, const QString& type_id)377QDBusObjectPath cucd::Service::CreateTransfer(const QString& dest_id, const QString& src_id, int dir, const QString& type_id)
306{378{
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;
@@ -539,6 +611,29 @@
539 }611 }
540}612}
541613
614void cucd::Service::handle_pastes(int state)
615{
616 TRACE() << Q_FUNC_INFO;
617 cucd::Paste *paste = static_cast<cucd::Paste*>(sender());
618 TRACE() << Q_FUNC_INFO << "STATE:" << paste->State();
619
620 if (state == cuc::Paste::charged)
621 {
622 TRACE() << Q_FUNC_INFO << "charged";
623 auto path = paste->path();
624 TRACE() << Q_FUNC_INFO << "Unregistering path:" << path;
625 d->connection.unregisterObject(path);
626 }
627
628 if (state == cuc::Paste::collected)
629 {
630 TRACE() << Q_FUNC_INFO << "collected";
631 auto path = paste->path();
632 TRACE() << Q_FUNC_INFO << "Unregistering path:" << path;
633 d->connection.unregisterObject(path);
634 }
635}
636
542void cucd::Service::handler_unregistered(const QString& s)637void cucd::Service::handler_unregistered(const QString& s)
543{638{
544 TRACE() << Q_FUNC_INFO << s;639 TRACE() << Q_FUNC_INFO << s;
545640
=== modified file 'src/com/ubuntu/content/detail/service.h'
--- src/com/ubuntu/content/detail/service.h 2015-09-29 13:15:58 +0000
+++ src/com/ubuntu/content/detail/service.h 2016-06-02 17:19:28 +0000
@@ -61,6 +61,9 @@
61 QDBusObjectPath CreateImportFromPeer(const QString&, const QString&, const QString&);61 QDBusObjectPath CreateImportFromPeer(const QString&, const QString&, const QString&);
62 QDBusObjectPath CreateExportToPeer(const QString&, const QString&, const QString&);62 QDBusObjectPath CreateExportToPeer(const QString&, const QString&, const QString&);
63 QDBusObjectPath CreateShareToPeer(const QString&, const QString&, const QString&);63 QDBusObjectPath CreateShareToPeer(const QString&, const QString&, const QString&);
64 QDBusObjectPath CreatePaste(const QString&);
65 QDBusObjectPath GetLatestPaste(const QString&);
66 QDBusObjectPath GetPaste(const QString&, const QString&);
6467
65 void RegisterImportExportHandler(const QString&, const QDBusObjectPath& handler);68 void RegisterImportExportHandler(const QString&, const QDBusObjectPath& handler);
66 void HandlerActive(const QString&);69 void HandlerActive(const QString&);
@@ -79,6 +82,7 @@
79 private Q_SLOTS:82 private Q_SLOTS:
80 void handle_imports(int);83 void handle_imports(int);
81 void handle_exports(int);84 void handle_exports(int);
85 void handle_pastes(int);
82 void handler_unregistered(const QString&);86 void handler_unregistered(const QString&);
83 QDBusObjectPath CreateTransfer(const QString&, const QString&, int, const QString&);87 QDBusObjectPath CreateTransfer(const QString&, const QString&, int, const QString&);
84 void download_notify(com::ubuntu::content::detail::Transfer*);88 void download_notify(com::ubuntu::content::detail::Transfer*);
8589
=== modified file 'src/com/ubuntu/content/hub.cpp'
--- src/com/ubuntu/content/hub.cpp 2015-10-23 12:37:24 +0000
+++ src/com/ubuntu/content/hub.cpp 2016-06-02 17:19:28 +0000
@@ -21,6 +21,7 @@
21#include "ContentServiceInterface.h"21#include "ContentServiceInterface.h"
22#include "ContentHandlerInterface.h"22#include "ContentHandlerInterface.h"
23#include "handleradaptor.h"23#include "handleradaptor.h"
24#include "paste_p.h"
24#include "transfer_p.h"25#include "transfer_p.h"
25#include "utils.cpp"26#include "utils.cpp"
2627
@@ -331,3 +332,54 @@
331 auto peer = reply.value();332 auto peer = reply.value();
332 return qdbus_cast<cuc::Peer>(peer.variant());333 return qdbus_cast<cuc::Peer>(peer.variant());
333}334}
335
336cuc::Paste* cuc::Hub::create_paste(const char * data) {
337 /* This needs to be replaced with a better way to get the APP_ID */
338 QString id = app_id();
339 TRACE() << Q_FUNC_INFO << id;
340
341 auto reply = d->service->CreatePaste(id);
342 reply.waitForFinished();
343
344 cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this);
345 auto item = cuc::Item();
346 item.setStream(QByteArray(data));
347 QVector<cuc::Item> items;
348 items << item;
349 paste->charge(items);
350 return paste;
351}
352
353const char* cuc::Hub::latest_paste_buf() {
354 TRACE() << Q_FUNC_INFO;
355 const char* ret = NULL;
356 QString dest_id = app_id();
357 TRACE() << Q_FUNC_INFO << dest_id;
358 auto reply = d->service->GetLatestPaste(dest_id);
359 reply.waitForFinished();
360
361 cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this);
362 auto items = paste->collect();
363 if (items.count() > 0) {
364 auto item = items.first();
365 ret = item.stream().constData();
366 }
367 return ret;
368}
369
370const char* cuc::Hub::paste_buf_by_id(int id) {
371 TRACE() << Q_FUNC_INFO;
372 const char* ret = NULL;
373 QString dest_id = app_id();
374 auto reply = d->service->GetPaste(QString::number(id), dest_id);
375 reply.waitForFinished();
376
377 cuc::Paste *paste = cuc::Paste::Private::make_paste(reply.value(), this);
378 auto items = paste->collect();
379 if (items.count() > 0) {
380 auto item = items.first();
381 ret = item.stream().constData();
382 }
383 return ret;
384}
385
334386
=== added file 'src/com/ubuntu/content/paste.cpp'
--- src/com/ubuntu/content/paste.cpp 1970-01-01 00:00:00 +0000
+++ src/com/ubuntu/content/paste.cpp 2016-06-02 17:19:28 +0000
@@ -0,0 +1,74 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18
19#include <com/ubuntu/content/paste.h>
20
21#include "paste_p.h"
22#include "utils.cpp"
23
24namespace cuc = com::ubuntu::content;
25
26cuc::Paste::Paste(const QSharedPointer<cuc::Paste::Private>& d, QObject* parent)
27 : QObject(parent),
28 d(d)
29{
30 QObject::connect(d->remote_paste,
31 SIGNAL (StateChanged(int)),
32 this,
33 SIGNAL (stateChanged()));
34}
35
36cuc::Paste::~Paste()
37{
38 TRACE() << Q_FUNC_INFO;
39}
40
41int cuc::Paste::id() const
42{
43 return d->id();
44}
45
46cuc::Paste::State cuc::Paste::state() const
47{
48 return d->state();
49}
50
51bool cuc::Paste::abort()
52{
53 return d->abort();
54}
55
56bool cuc::Paste::charge(const QVector<cuc::Item>& items)
57{
58 return d->charge(items);
59}
60
61QVector<cuc::Item> cuc::Paste::collect()
62{
63 return d->collect();
64}
65
66bool cuc::Paste::finalize()
67{
68 return d->finalize();
69}
70
71QString cuc::Paste::source() const
72{
73 return d->source();
74}
075
=== added file 'src/com/ubuntu/content/paste_p.h'
--- src/com/ubuntu/content/paste_p.h 1970-01-01 00:00:00 +0000
+++ src/com/ubuntu/content/paste_p.h 2016-06-02 17:19:28 +0000
@@ -0,0 +1,138 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18#ifndef COM_UBUNTU_CONTENT_PASTE_P_H_
19#define COM_UBUNTU_CONTENT_PASTE_P_H_
20
21#include "common.h"
22#include "ContentPasteInterface.h"
23
24#include <com/ubuntu/content/item.h>
25#include <com/ubuntu/content/paste.h>
26
27#include <QObject>
28#include <QVector>
29
30namespace com
31{
32namespace ubuntu
33{
34namespace content
35{
36class Paste::Private : public QObject
37{
38 Q_OBJECT
39 public:
40 static Paste* make_paste(const QDBusObjectPath& paste, QObject* parent)
41 {
42 QSharedPointer<Private> d{new Private{paste, parent}};
43 return new Paste{d, parent};
44 }
45
46 Private(const QDBusObjectPath& paste, QObject* parent)
47 : QObject(parent),
48 remote_paste(
49 new com::ubuntu::content::dbus::Paste(
50 HUB_SERVICE_NAME,
51 paste.path(),
52 QDBusConnection::sessionBus(), this))
53 {
54 }
55
56 int id()
57 {
58 auto reply = remote_paste->Id();
59 reply.waitForFinished();
60
61 return reply.value();
62 }
63
64 State state()
65 {
66 auto reply = remote_paste->State();
67 reply.waitForFinished();
68
69 if (reply.isError())
70 return Paste::aborted;
71
72 return static_cast<Paste::State>(reply.value());
73 }
74
75 bool abort()
76 {
77 auto reply = remote_paste->Abort();
78 reply.waitForFinished();
79
80 return not reply.isError();
81 }
82
83 bool finalize()
84 {
85 auto reply = remote_paste->Finalize();
86 reply.waitForFinished();
87
88 return not reply.isError();
89 }
90
91 bool charge(const QVector<Item>& items)
92 {
93 QVariantList itemVariants;
94 Q_FOREACH(const Item& item, items)
95 {
96 itemVariants << QVariant::fromValue(item);
97 }
98 auto reply = remote_paste->Charge(itemVariants);
99 reply.waitForFinished();
100
101 return not reply.isError();
102 }
103
104 QVector<Item> collect()
105 {
106 QVector<Item> result;
107
108 auto reply = remote_paste->Collect();
109 reply.waitForFinished();
110
111 if (reply.isError())
112 return result;
113
114 auto items = reply.value();
115
116 Q_FOREACH(const QVariant& itemVariant, items)
117 {
118 result << qdbus_cast<Item>(itemVariant);
119 }
120
121 return result;
122 }
123
124 QString source()
125 {
126 auto reply = remote_paste->source();
127 reply.waitForFinished();
128
129 return static_cast<QString>(reply.value());
130 }
131
132 com::ubuntu::content::dbus::Paste* remote_paste;
133};
134}
135}
136}
137
138#endif // COM_UBUNTU_CONTENT_PASTE_P_H_
0139
=== modified file 'tests/acceptance-tests/CMakeLists.txt'
--- tests/acceptance-tests/CMakeLists.txt 2015-06-29 13:46:54 +0000
+++ tests/acceptance-tests/CMakeLists.txt 2016-06-02 17:19:28 +0000
@@ -41,6 +41,12 @@
41)41)
4242
43add_executable(43add_executable(
44 app_hub_communication_paste
45 app_hub_communication_paste.cpp
46 ${MOCS}
47)
48
49add_executable(
44 app_hub_communication_handler50 app_hub_communication_handler
45 app_hub_communication_handler.cpp51 app_hub_communication_handler.cpp
46 ${MOCS}52 ${MOCS}
@@ -72,6 +78,7 @@
72qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test)78qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test)
73qt5_use_modules(app_hub_communication_stores Core Gui DBus Test)79qt5_use_modules(app_hub_communication_stores Core Gui DBus Test)
74qt5_use_modules(app_hub_communication_transfer Core Gui DBus Test)80qt5_use_modules(app_hub_communication_transfer Core Gui DBus Test)
81qt5_use_modules(app_hub_communication_paste Core Gui DBus Test)
75qt5_use_modules(app_hub_communication_handler Core Gui DBus Test)82qt5_use_modules(app_hub_communication_handler Core Gui DBus Test)
76qt5_use_modules(test_utils Core Test)83qt5_use_modules(test_utils Core Test)
77qt5_use_modules(test_hook Core Gui DBus Test)84qt5_use_modules(test_hook Core Gui DBus Test)
@@ -81,6 +88,7 @@
81target_link_libraries(app_hub_communication_known_sources content-hub gmock gtest gtest_main)88target_link_libraries(app_hub_communication_known_sources content-hub gmock gtest gtest_main)
82target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)89target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)
83target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main)90target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main)
91target_link_libraries(app_hub_communication_paste content-hub gmock gtest gtest_main)
84target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main)92target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main)
85target_link_libraries(test_utils content-hub gmock gtest gtest_main)93target_link_libraries(test_utils content-hub gmock gtest gtest_main)
86target_link_libraries(test_types content-hub gmock gtest gtest_main)94target_link_libraries(test_types content-hub gmock gtest gtest_main)
@@ -90,6 +98,7 @@
90add_test(app_hub_communication_known_sources app_hub_communication_known_sources)98add_test(app_hub_communication_known_sources app_hub_communication_known_sources)
91add_test(app_hub_communication_stores app_hub_communication_stores)99add_test(app_hub_communication_stores app_hub_communication_stores)
92add_test(app_hub_communication_transfer app_hub_communication_transfer)100add_test(app_hub_communication_transfer app_hub_communication_transfer)
101add_test(app_hub_communication_paste app_hub_communication_transfer)
93add_test(app_hub_communication_handler app_hub_communication_handler)102add_test(app_hub_communication_handler app_hub_communication_handler)
94add_test(test_utils test_utils)103add_test(test_utils test_utils)
95add_test(test_types test_types)104add_test(test_types test_types)
96105
=== added file 'tests/acceptance-tests/app_hub_communication_paste.cpp'
--- tests/acceptance-tests/app_hub_communication_paste.cpp 1970-01-01 00:00:00 +0000
+++ tests/acceptance-tests/app_hub_communication_paste.cpp 2016-06-02 17:19:28 +0000
@@ -0,0 +1,136 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18
19#include "app_manager_mock.h"
20#include "test_harness.h"
21#include "../cross_process_sync.h"
22#include "../fork_and_run.h"
23
24#include <com/ubuntu/content/hub.h>
25#include <com/ubuntu/content/item.h>
26#include <com/ubuntu/content/paste.h>
27
28#include "com/ubuntu/content/detail/peer_registry.h"
29#include "com/ubuntu/content/detail/service.h"
30#include "com/ubuntu/content/serviceadaptor.h"
31
32#include <gmock/gmock.h>
33#include <gtest/gtest.h>
34
35#include <QCoreApplication>
36#include <QtDBus/QDBusConnection>
37#include <QStandardPaths>
38#include <QTemporaryDir>
39#include <QtTest/QTest>
40
41#include <thread>
42
43namespace cua = com::ubuntu::ApplicationManager;
44namespace cuc = com::ubuntu::content;
45namespace cucd = com::ubuntu::content::detail;
46
47void PrintTo(const QString& s, ::std::ostream* os) {
48 *os << std::string(qPrintable(s));
49}
50
51namespace
52{
53QString service_name{"com.ubuntu.content.dbus.Service"};
54
55struct MockedPeerRegistry : public cucd::PeerRegistry
56{
57 MockedPeerRegistry() : cucd::PeerRegistry()
58 {
59 using namespace ::testing;
60
61 ON_CALL(*this, default_source_for_type(_)).WillByDefault(Return(cuc::Peer::unknown()));
62 ON_CALL(*this, install_default_source_for_type(_,_)).WillByDefault(Return(false));
63 ON_CALL(*this, install_source_for_type(_,_)).WillByDefault(Return(false));
64 }
65
66 MOCK_METHOD1(default_source_for_type, cuc::Peer(cuc::Type t));
67 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
68 MOCK_METHOD2(enumerate_known_sources_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
69 MOCK_METHOD2(enumerate_known_destinations_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
70 MOCK_METHOD2(enumerate_known_shares_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
71 MOCK_METHOD2(install_default_source_for_type, bool(cuc::Type, cuc::Peer));
72 MOCK_METHOD2(install_source_for_type, bool(cuc::Type, cuc::Peer));
73 MOCK_METHOD2(install_destination_for_type, bool(cuc::Type, cuc::Peer));
74 MOCK_METHOD2(install_share_for_type, bool(cuc::Type, cuc::Peer));
75 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
76 MOCK_METHOD1(peer_is_legacy, bool(QString));
77};
78}
79
80TEST(Hub, transfer_creation_and_states_work)
81{
82 using namespace ::testing;
83
84 test::CrossProcessSync sync;
85
86 auto parent = [&sync]()
87 {
88 int argc = 0;
89 QCoreApplication app{argc, nullptr};
90
91 QDBusConnection connection = QDBusConnection::sessionBus();
92
93 auto mock = new ::testing::NiceMock<MockedPeerRegistry>{};
94
95 QSharedPointer<cucd::PeerRegistry> registry{mock};
96 auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
97 cucd::Service implementation(connection, registry, app_manager, &app);
98 new ServiceAdaptor(std::addressof(implementation));
99
100 ASSERT_TRUE(connection.registerService(service_name));
101 ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation)));
102
103 sync.signal_ready();
104
105 app.exec();
106
107 connection.unregisterObject("/");
108 connection.unregisterService(service_name);
109 };
110
111 auto child = [&sync]()
112 {
113 int argc = 0;
114 QCoreApplication app(argc, nullptr);
115
116 sync.wait_for_signal_ready();
117
118 test::TestHarness harness;
119 harness.add_test_case([]()
120 {
121 qputenv("APP_ID", "some-app");
122 const char * data = "some text";
123 auto hub = cuc::Hub::Client::instance();
124
125 auto paste = hub->create_paste(data);
126 ASSERT_TRUE(paste != nullptr);
127 EXPECT_EQ(QString(data), QString(hub->latest_paste_buf()));
128 EXPECT_EQ(QString(data), QString(hub->paste_buf_by_id(1)));
129
130 hub->quit();
131 });
132 EXPECT_EQ(0, QTest::qExec(std::addressof(harness)));
133 };
134
135 EXPECT_EQ(EXIT_SUCCESS, test::fork_and_run(child, parent));
136}

Subscribers

People subscribed via source and target branches