Merge lp:~ken-vandine/content-hub/download-manager-with-snapdecision into lp:content-hub

Proposed by Ken VanDine
Status: Superseded
Proposed branch: lp:~ken-vandine/content-hub/download-manager-with-snapdecision
Merge into: lp:content-hub
Diff against target: 783 lines (+426/-7)
19 files modified
CMakeLists.txt (+8/-3)
cmake/Translations.cmake (+41/-0)
debian/control (+2/-0)
import/Ubuntu/Content/contenttransfer.cpp (+27/-1)
import/Ubuntu/Content/contenttransfer.h (+8/-1)
include/com/ubuntu/content/transfer.h (+9/-1)
po/CMakeLists.txt (+3/-0)
po/POTFILES.in (+1/-0)
po/content-hub.pot (+30/-0)
src/com/ubuntu/content/CMakeLists.txt (+5/-0)
src/com/ubuntu/content/detail/com.ubuntu.content.Transfer.xml (+11/-0)
src/com/ubuntu/content/detail/i18n.cpp (+47/-0)
src/com/ubuntu/content/detail/i18n.h (+42/-0)
src/com/ubuntu/content/detail/service.cpp (+73/-0)
src/com/ubuntu/content/detail/transfer.cpp (+66/-0)
src/com/ubuntu/content/detail/transfer.h (+6/-0)
src/com/ubuntu/content/service/main.cpp (+3/-0)
src/com/ubuntu/content/transfer.cpp (+16/-0)
src/com/ubuntu/content/transfer_p.h (+28/-1)
To merge this branch: bzr merge lp:~ken-vandine/content-hub/download-manager-with-snapdecision
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+218322@code.launchpad.net

Description of the change

Use libnotify to send a snap decision with an Open action for downloads.

This also ands translation support, needed for the strings in the notification.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Are there any related MPs required for this MP to build/function as expected? Please list.

 * Yes
   - https://code.launchpad.net/~michael-sheldon/content-hub/download-manager-integration/+merge/217788

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)

 * Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?

 * Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/content-hub) on device or emulator?

 * Yes

If you changed the UI, was the change specified/approved by design?

 * This change adds a snap decision notification. This was added as an interim
   solution until we have final designs.

If you changed the packaging (debian), did you subscribe a core-dev to this MP?

 * Yes, just added libnotify as a build depends. I'm a core-dev.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-03-07 21:07:27 +0000
3+++ CMakeLists.txt 2014-05-05 19:54:30 +0000
4@@ -66,18 +66,23 @@
5 pkg_check_modules(NIH REQUIRED libnih)
6 pkg_check_modules(NIH_DBUS REQUIRED libnih-dbus)
7 pkg_check_modules(DBUS REQUIRED dbus-1)
8-
9-add_definitions( -DDEBUG_ENABLED )
10+pkg_check_modules(UBUNTU_DOWNLOAD_MANAGER REQUIRED ubuntu-download-manager-client)
11+pkg_check_modules(NOTIFY REQUIRED libnotify)
12+
13+add_definitions(-DDEBUG_ENABLED)
14+
15+set(GETTEXT_PACKAGE "content-hub")
16+add_definitions(-DI18N_DOMAIN="${GETTEXT_PACKAGE}")
17
18 set(CONTENT_HUB_VERSION_MAJOR 0)
19 set(CONTENT_HUB_VERSION_MINOR 0)
20 set(CONTENT_HUB_VERSION_PATCH 1)
21 set(CONTENT_HUB_VERSION "${CONTENT_HUB_VERSION_MAJOR}.${CONTENT_HUB_VERSION_MINOR}.${CONTENT_HUB_VERSION_PATCH}")
22
23-
24 include_directories(include)
25
26 add_subdirectory(doc)
27+add_subdirectory(po)
28 add_subdirectory(src)
29 add_subdirectory(import)
30 add_subdirectory(examples)
31
32=== added file 'cmake/Translations.cmake'
33--- cmake/Translations.cmake 1970-01-01 00:00:00 +0000
34+++ cmake/Translations.cmake 2014-05-05 19:54:30 +0000
35@@ -0,0 +1,41 @@
36+# Translations.cmake, CMake macros written for Marlin, feel free to re-use them
37+
38+macro(add_translations_directory NLS_PACKAGE)
39+ add_custom_target (i18n ALL)
40+ find_program (MSGFMT_EXECUTABLE msgfmt)
41+ file (GLOB PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.po)
42+ foreach (PO_INPUT ${PO_FILES})
43+ get_filename_component (PO_INPUT_BASE ${PO_INPUT} NAME_WE)
44+ set (MO_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PO_INPUT_BASE}.mo)
45+ add_custom_command (TARGET i18n COMMAND ${MSGFMT_EXECUTABLE} -o ${MO_OUTPUT} ${PO_INPUT})
46+
47+ install (FILES ${MO_OUTPUT} DESTINATION
48+ ${CMAKE_INSTALL_LOCALEDIR}/${PO_INPUT_BASE}/LC_MESSAGES
49+ RENAME ${NLS_PACKAGE}.mo)
50+ endforeach (PO_INPUT ${PO_FILES})
51+endmacro(add_translations_directory)
52+
53+
54+macro(add_translations_catalog NLS_PACKAGE)
55+ add_custom_target (pot COMMENT “Building translation catalog.”)
56+ find_program (XGETTEXT_EXECUTABLE xgettext)
57+
58+
59+ set(C_SOURCE "")
60+
61+ foreach(FILES_INPUT ${ARGN})
62+ file (GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${FILES_INPUT}/*.c)
63+ foreach(C_FILE ${SOURCE_FILES})
64+ set(C_SOURCE ${C_SOURCE} ${C_FILE})
65+ endforeach()
66+ file (GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${FILES_INPUT}/*.cpp)
67+ foreach(C_FILE ${SOURCE_FILES})
68+ set(C_SOURCE ${C_SOURCE} ${C_FILE})
69+ endforeach()
70+ endforeach()
71+
72+ add_custom_command (TARGET pot COMMAND
73+ ${XGETTEXT_EXECUTABLE} -d ${NLS_PACKAGE} -o ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_PACKAGE}.pot
74+ ${VALA_SOURCE} ${C_SOURCE} --keyword="_" --keyword="N_" --from-code=UTF-8
75+ )
76+endmacro()
77
78=== modified file 'debian/control'
79--- debian/control 2014-04-02 14:45:06 +0000
80+++ debian/control 2014-05-05 19:54:30 +0000
81@@ -11,6 +11,8 @@
82 libglib2.0-dev,
83 libgsettings-qt-dev,
84 libnih-dbus-dev,
85+ libnotify-dev,
86+ libubuntu-download-manager-client-dev,
87 libupstart-app-launch2-dev (>= 0.3+14.04.20140124),
88 qt5-default,
89 qtbase5-dev,
90
91=== modified file 'import/Ubuntu/Content/contenttransfer.cpp'
92--- import/Ubuntu/Content/contenttransfer.cpp 2014-04-10 16:38:11 +0000
93+++ import/Ubuntu/Content/contenttransfer.cpp 2014-05-05 19:54:30 +0000
94@@ -61,6 +61,12 @@
95 \li ContentTransfer.InProgress
96 \li Transfer is in progress.
97 \row
98+ \li ContentTransfer.Downloading
99+ \li Transfer is downloading item specified by downloadId.
100+ \row
101+ \li ContentTransfer.Downloaded
102+ \li Download specified by downloadId has completed.
103+ \row
104 \li ContentTransfer.Charged
105 \li Transfer is charged with items and ready to be collected.
106 \row
107@@ -86,7 +92,7 @@
108 if (!m_transfer)
109 return;
110
111- if (state == Charged && m_state == InProgress) {
112+ if (state == Charged && (m_state == InProgress || m_state == Downloaded)) {
113 TRACE() << Q_FUNC_INFO << "Charged";
114 QVector<cuc::Item> hubItems;
115 hubItems.reserve(m_items.size());
116@@ -95,6 +101,8 @@
117 }
118 m_transfer->charge(hubItems);
119 return;
120+ } else if (state == Downloading) {
121+ m_transfer->download();
122 } else if (state == Aborted) {
123 TRACE() << Q_FUNC_INFO << "Aborted";
124 m_transfer->abort();
125@@ -268,6 +276,24 @@
126 }
127
128 /*!
129+ * \qmlproperty string ContentTransfer::downloadId
130+ * The Download Manager ID of a SingleDownload, which will then be
131+ * transfered to the selected peer.
132+ */
133+QString ContentTransfer::downloadId()
134+{
135+ TRACE() << Q_FUNC_INFO;
136+ return m_transfer->downloadId();
137+}
138+
139+void ContentTransfer::setDownloadId(QString downloadId)
140+{
141+ TRACE() << Q_FUNC_INFO;
142+ m_transfer->setDownloadId(downloadId);
143+ Q_EMIT downloadIdChanged();
144+}
145+
146+/*!
147 * \brief ContentTransfer::collectItems gets the items out of the transfer object
148 * \internal
149 */
150
151=== modified file 'import/Ubuntu/Content/contenttransfer.h'
152--- import/Ubuntu/Content/contenttransfer.h 2014-02-19 16:41:30 +0000
153+++ import/Ubuntu/Content/contenttransfer.h 2014-05-05 19:54:30 +0000
154@@ -39,6 +39,7 @@
155 Q_PROPERTY(SelectionType selectionType READ selectionType WRITE setSelectionType NOTIFY selectionTypeChanged)
156 Q_PROPERTY(QString store READ store NOTIFY storeChanged)
157 Q_PROPERTY(QQmlListProperty<ContentItem> items READ items NOTIFY itemsChanged)
158+ Q_PROPERTY(QString downloadId READ downloadId WRITE setDownloadId NOTIFY downloadIdChanged)
159
160 public:
161 enum State {
162@@ -48,7 +49,9 @@
163 Charged = com::ubuntu::content::Transfer::charged,
164 Collected = com::ubuntu::content::Transfer::collected,
165 Aborted = com::ubuntu::content::Transfer::aborted,
166- Finalized = com::ubuntu::content::Transfer::finalized
167+ Finalized = com::ubuntu::content::Transfer::finalized,
168+ Downloading = com::ubuntu::content::Transfer::downloading,
169+ Downloaded = com::ubuntu::content::Transfer::downloaded
170 };
171 enum Direction {
172 Import = com::ubuntu::content::Transfer::Import,
173@@ -81,6 +84,9 @@
174 com::ubuntu::content::Transfer *transfer() const;
175 void setTransfer(com::ubuntu::content::Transfer *transfer);
176
177+ QString downloadId();
178+ void setDownloadId(QString downloadId);
179+
180 void collectItems();
181
182 Q_SIGNALS:
183@@ -88,6 +94,7 @@
184 void itemsChanged();
185 void selectionTypeChanged();
186 void storeChanged();
187+ void downloadIdChanged();
188
189 private Q_SLOTS:
190 void updateState();
191
192=== modified file 'include/com/ubuntu/content/transfer.h'
193--- include/com/ubuntu/content/transfer.h 2014-02-19 16:41:30 +0000
194+++ include/com/ubuntu/content/transfer.h 2014-05-05 19:54:30 +0000
195@@ -24,6 +24,7 @@
196 #include <QObject>
197 #include <QSharedPointer>
198 #include <QVector>
199+#include <QString>
200
201 namespace com
202 {
203@@ -59,6 +60,7 @@
204 Q_PROPERTY(Store store READ store NOTIFY storeChanged)
205 Q_PROPERTY(SelectionType selectionType READ selectionType WRITE setSelectionType NOTIFY selectionTypeChanged)
206 Q_PROPERTY(Direction direction READ direction)
207+ Q_PROPERTY(QString downloadId READ downloadId WRITE setDownloadId NOTIFY downloadIdChanged)
208
209 public:
210 enum State
211@@ -69,7 +71,9 @@
212 charged,
213 collected,
214 aborted,
215- finalized
216+ finalized,
217+ downloading,
218+ downloaded
219 };
220
221 enum SelectionType
222@@ -97,15 +101,19 @@
223 Q_INVOKABLE virtual bool start();
224 Q_INVOKABLE virtual bool abort();
225 Q_INVOKABLE virtual bool finalize();
226+ Q_INVOKABLE virtual bool download();
227 Q_INVOKABLE virtual bool charge(const QVector<Item>& items);
228 Q_INVOKABLE virtual QVector<Item> collect();
229 Q_INVOKABLE virtual Store store() const;
230 Q_INVOKABLE virtual bool setStore(const Store*);
231 Q_INVOKABLE virtual bool setSelectionType(const SelectionType&);
232+ Q_INVOKABLE virtual QString downloadId() const;
233+ Q_INVOKABLE virtual bool setDownloadId(const QString);
234
235 Q_SIGNAL void stateChanged();
236 Q_SIGNAL void storeChanged();
237 Q_SIGNAL void selectionTypeChanged();
238+ Q_SIGNAL void downloadIdChanged();
239
240 private:
241 struct Private;
242
243=== added directory 'po'
244=== added file 'po/CMakeLists.txt'
245--- po/CMakeLists.txt 1970-01-01 00:00:00 +0000
246+++ po/CMakeLists.txt 2014-05-05 19:54:30 +0000
247@@ -0,0 +1,3 @@
248+include (Translations)
249+add_translations_directory ("${GETTEXT_PACKAGE}")
250+add_translations_catalog ("${GETTEXT_PACKAGE}" ../src/com/ubuntu/content/detail)
251
252=== added file 'po/POTFILES.in'
253--- po/POTFILES.in 1970-01-01 00:00:00 +0000
254+++ po/POTFILES.in 2014-05-05 19:54:30 +0000
255@@ -0,0 +1,1 @@
256+src/com/ubuntu/content/detail/service.cpp
257
258=== added file 'po/content-hub.pot'
259--- po/content-hub.pot 1970-01-01 00:00:00 +0000
260+++ po/content-hub.pot 2014-05-05 19:54:30 +0000
261@@ -0,0 +1,30 @@
262+# SOME DESCRIPTIVE TITLE.
263+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
264+# This file is distributed under the same license as the PACKAGE package.
265+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
266+#
267+#, fuzzy
268+msgid ""
269+msgstr ""
270+"Project-Id-Version: PACKAGE VERSION\n"
271+"Report-Msgid-Bugs-To: \n"
272+"POT-Creation-Date: 2014-05-05 15:51-0400\n"
273+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
274+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
275+"Language-Team: LANGUAGE <LL@li.org>\n"
276+"Language: \n"
277+"MIME-Version: 1.0\n"
278+"Content-Type: text/plain; charset=CHARSET\n"
279+"Content-Transfer-Encoding: 8bit\n"
280+
281+#: ../src/com/ubuntu/content/detail/service.cpp:212
282+msgid "Download Complete"
283+msgstr ""
284+
285+#: ../src/com/ubuntu/content/detail/service.cpp:227
286+msgid "Open"
287+msgstr ""
288+
289+#: ../src/com/ubuntu/content/detail/service.cpp:234
290+msgid "Dismiss"
291+msgstr ""
292
293=== modified file 'src/com/ubuntu/content/CMakeLists.txt'
294--- src/com/ubuntu/content/CMakeLists.txt 2014-03-04 21:47:48 +0000
295+++ src/com/ubuntu/content/CMakeLists.txt 2014-05-05 19:54:30 +0000
296@@ -26,6 +26,8 @@
297 ${NIH_INCLUDE_DIRS}
298 ${NIH_DBUS_INCLUDE_DIRS}
299 ${UPSTART_LAUNCH_INCLUDE_DIRS}
300+ ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS}
301+ ${NOTIFY_INCLUDE_DIRS}
302 )
303
304 qt5_add_dbus_interface(
305@@ -74,6 +76,7 @@
306 detail/service.cpp
307 detail/transfer.cpp
308 detail/handler.cpp
309+ detail/i18n.cpp
310
311 ${CONTENT_HUB_MOCS}
312 ${CONTENT_SERVICE_STUB}
313@@ -100,6 +103,8 @@
314 ${NIH_LIBRARIES}
315 ${NIH_DBUS_LIBRARIES}
316 ${GIO_LIBRARIES}
317+ ${UBUNTU_DOWNLOAD_MANAGER_LIBRARIES}
318+ ${NOTIFY_LIBRARIES}
319 )
320
321 install(
322
323=== modified file 'src/com/ubuntu/content/detail/com.ubuntu.content.Transfer.xml'
324--- src/com/ubuntu/content/detail/com.ubuntu.content.Transfer.xml 2014-02-19 16:41:30 +0000
325+++ src/com/ubuntu/content/detail/com.ubuntu.content.Transfer.xml 2014-05-05 19:54:30 +0000
326@@ -17,6 +17,8 @@
327 </method>
328 <method name="Finalize">
329 </method>
330+ <method name="Download">
331+ </method>
332 <method name="Charge">
333 <arg name="items" type="as" direction="in" />
334 </method>
335@@ -41,6 +43,15 @@
336 <signal name="SelectionTypeChanged">
337 <arg name="selection_type" type="i"/>
338 </signal>
339+ <method name="DownloadId">
340+ <arg name="download_id" type="s" direction="out" />
341+ </method>
342+ <method name="SetDownloadId">
343+ <arg name="download_id" type="s" direction="in" />
344+ </method>
345+ <signal name="DownloadIdChanged">
346+ <arg name="download_id" type="s"/>
347+ </signal>
348 <method name="Direction">
349 <arg name="direction" type="i" direction="out" />
350 </method>
351
352=== added file 'src/com/ubuntu/content/detail/i18n.cpp'
353--- src/com/ubuntu/content/detail/i18n.cpp 1970-01-01 00:00:00 +0000
354+++ src/com/ubuntu/content/detail/i18n.cpp 2014-05-05 19:54:30 +0000
355@@ -0,0 +1,47 @@
356+/*
357+ * Copyright © 2014 Canonical Ltd.
358+ *
359+ * This program is free software: you can redistribute it and/or modify
360+ * it under the terms of the GNU Lesser General Public License version 3 as
361+ * published by the Free Software Foundation.
362+ *
363+ * This program is distributed in the hope that it will be useful,
364+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
365+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366+ * GNU Lesser General Public License for more details.
367+ *
368+ * You should have received a copy of the GNU Lesser General Public License
369+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
370+ *
371+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
372+ */
373+
374+#define NO_TR_OVERRIDE
375+#include "i18n.h"
376+
377+#include <libintl.h>
378+
379+namespace com
380+{
381+namespace ubuntu
382+{
383+namespace content
384+{
385+namespace detail
386+{
387+
388+void initTr(const char *domain, const char *localeDir)
389+{
390+ bindtextdomain(domain, localeDir);
391+ textdomain(domain);
392+}
393+
394+QString _(const char *text, const char *domain)
395+{
396+ return QString::fromUtf8(dgettext(domain, text));
397+}
398+
399+}
400+}
401+}
402+}
403
404=== added file 'src/com/ubuntu/content/detail/i18n.h'
405--- src/com/ubuntu/content/detail/i18n.h 1970-01-01 00:00:00 +0000
406+++ src/com/ubuntu/content/detail/i18n.h 2014-05-05 19:54:30 +0000
407@@ -0,0 +1,42 @@
408+/*
409+ * Copyright © 2014 Canonical Ltd.
410+ *
411+ * This program is free software: you can redistribute it and/or modify
412+ * it under the terms of the GNU Lesser General Public License version 3 as
413+ * published by the Free Software Foundation.
414+ *
415+ * This program is distributed in the hope that it will be useful,
416+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
417+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
418+ * GNU Lesser General Public License for more details.
419+ *
420+ * You should have received a copy of the GNU Lesser General Public License
421+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
422+ *
423+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
424+ */
425+
426+#ifndef I18N_H
427+#define I18N_H
428+
429+#include <QString>
430+
431+namespace com
432+{
433+namespace ubuntu
434+{
435+namespace content
436+{
437+namespace detail
438+{
439+
440+void initTr(const char *domain, const char *localeDir);
441+QString _(const char *text, const char *domain = 0);
442+
443+}
444+}
445+}
446+}
447+
448+#endif // I18N_H
449+
450
451=== modified file 'src/com/ubuntu/content/detail/service.cpp'
452--- src/com/ubuntu/content/detail/service.cpp 2014-03-24 19:29:56 +0000
453+++ src/com/ubuntu/content/detail/service.cpp 2014-05-05 19:54:30 +0000
454@@ -16,14 +16,22 @@
455 * Authored by: Thomas Voß <thomas.voss@canonical.com>
456 */
457
458+// NEEDED for libnotify include
459+#define QT_NO_KEYWORDS
460+
461 #include "debug.h"
462 #include "service.h"
463 #include "peer_registry.h"
464+#include "i18n.h"
465 #include "transfer.h"
466 #include "transferadaptor.h"
467 #include "utils.cpp"
468 #include "ContentHandlerInterface.h"
469
470+#include <glib.h>
471+#include <unistd.h>
472+#include <libnotify/notify.h>
473+
474 #include <com/ubuntu/content/peer.h>
475 #include <com/ubuntu/content/type.h>
476 #include <com/ubuntu/content/transfer.h>
477@@ -177,6 +185,65 @@
478 && st != cuc::Transfer::aborted);
479 }
480
481+void action_dismiss(NotifyNotification *notification, char *action, gpointer data)
482+{
483+ TRACE() << Q_FUNC_INFO;
484+ Q_UNUSED(notification);
485+ Q_UNUSED(action);
486+ Q_UNUSED(data);
487+}
488+
489+void action_accept(NotifyNotification *notification, char *action, gpointer data)
490+{
491+ TRACE() << Q_FUNC_INFO;
492+ Q_UNUSED(notification);
493+ Q_UNUSED(action);
494+
495+ cucd::Transfer* t = (cucd::Transfer*)data;
496+ t->Charge(QStringList());
497+}
498+
499+void download_notify (cucd::Transfer* t)
500+{
501+ TRACE() << Q_FUNC_INFO;
502+ notify_init(t->source().toStdString().c_str());
503+ NotifyNotification* notification;
504+
505+ notification = notify_notification_new (_("Download Complete"),
506+ "",
507+ "save");
508+
509+ notify_notification_set_hint_string(notification,
510+ "x-canonical-snap-decisions",
511+ "true");
512+
513+
514+ notify_notification_set_hint_string(notification,
515+ "x-canonical-private-button-tint",
516+ "true");
517+
518+ notify_notification_add_action (notification,
519+ "action_accept",
520+ _("Open"),
521+ action_accept,
522+ t,
523+ NULL);
524+
525+ notify_notification_add_action (notification,
526+ "action_dismiss",
527+ _("Dismiss"),
528+ action_dismiss,
529+ t,
530+ NULL);
531+
532+ GError *error = NULL;
533+ if (!notify_notification_show(notification, &error)) {
534+ qWarning() << "Failed to show snap decision:" << error->message;
535+ g_error_free (error);
536+ }
537+
538+}
539+
540 QDBusObjectPath cucd::Service::CreateExportToPeer(const QString& peer_id, const QString& app_id)
541 {
542 TRACE() << Q_FUNC_INFO;
543@@ -338,6 +405,12 @@
544 transfer->Handled();
545 }
546
547+ if (state == cuc::Transfer::downloaded)
548+ {
549+ TRACE() << Q_FUNC_INFO << "Downloaded";
550+ download_notify(transfer);
551+ }
552+
553 if (state == cuc::Transfer::charged)
554 {
555 TRACE() << Q_FUNC_INFO << "Charged";
556
557=== modified file 'src/com/ubuntu/content/detail/transfer.cpp'
558--- src/com/ubuntu/content/detail/transfer.cpp 2014-03-04 21:47:48 +0000
559+++ src/com/ubuntu/content/detail/transfer.cpp 2014-05-05 19:54:30 +0000
560@@ -23,6 +23,8 @@
561 #include <com/ubuntu/content/hub.h>
562 #include <com/ubuntu/content/store.h>
563 #include <com/ubuntu/content/transfer.h>
564+#include <ubuntu/download_manager/download.h>
565+#include <ubuntu/download_manager/manager.h>
566
567 namespace cuc = com::ubuntu::content;
568 namespace cucd = com::ubuntu::content::detail;
569@@ -52,6 +54,7 @@
570 int selection_type;
571 QStringList items;
572 bool source_started_by_content_hub;
573+ QString download_id;
574 };
575
576 cucd::Transfer::Transfer(const int id,
577@@ -145,6 +148,19 @@
578 if (d->state == cuc::Transfer::charged)
579 return;
580
581+ if (d->state == cuc::Transfer::downloading)
582+ {
583+ qWarning() << "Unable to charge, download still in progress.";
584+ return;
585+ }
586+
587+ if (d->state == cuc::Transfer::downloaded)
588+ {
589+ d->state = cuc::Transfer::charged;
590+ Q_EMIT(StateChanged(d->state));
591+ return;
592+ }
593+
594 QStringList ret;
595 Q_FOREACH(QString i, items)
596 ret.append(copy_to_store(i, d->store));
597@@ -165,6 +181,40 @@
598 Q_EMIT(StateChanged(d->state));
599 }
600
601+void cucd::Transfer::Download()
602+{
603+ TRACE() << __PRETTY_FUNCTION__;
604+ if(d->download_id.isEmpty())
605+ {
606+ return;
607+ }
608+
609+ Manager *downloadManager = Manager::createSessionManager();
610+ auto download = downloadManager->getDownloadForId(d->download_id);
611+ if (download == nullptr)
612+ {
613+ TRACE() << downloadManager->lastError();
614+ }
615+ else
616+ {
617+ QDir dir;
618+ dir.mkpath(d->store);
619+ download->setDestinationDir(d->store);
620+ connect(download, SIGNAL(finished(QString)), this, SLOT(DownloadComplete(QString)));
621+ download->start();
622+ d->state = cuc::Transfer::downloading;
623+ Q_EMIT(StateChanged(d->state));
624+ }
625+}
626+
627+void cucd::Transfer::DownloadComplete(QString destFilePath)
628+{
629+ TRACE() << __PRETTY_FUNCTION__;
630+ d->items.append(QUrl::fromLocalFile(destFilePath).toString());
631+ d->state = cuc::Transfer::downloaded;
632+ Q_EMIT(StateChanged(d->state));
633+}
634+
635 QStringList cucd::Transfer::Collect()
636 {
637 TRACE() << __PRETTY_FUNCTION__;
638@@ -226,6 +276,22 @@
639 Q_EMIT(SelectionTypeChanged(d->selection_type));
640 }
641
642+QString cucd::Transfer::DownloadId()
643+{
644+ TRACE() << Q_FUNC_INFO;
645+ return d->download_id;
646+}
647+
648+void cucd::Transfer::SetDownloadId(QString DownloadId)
649+{
650+ TRACE() << Q_FUNC_INFO;
651+ if (d->download_id == DownloadId)
652+ return;
653+
654+ d->download_id = DownloadId;
655+ Q_EMIT(DownloadIdChanged(d->download_id));
656+}
657+
658 /* returns the object path for the export */
659 QString cucd::Transfer::export_path()
660 {
661
662=== modified file 'src/com/ubuntu/content/detail/transfer.h'
663--- src/com/ubuntu/content/detail/transfer.h 2014-02-19 16:41:30 +0000
664+++ src/com/ubuntu/content/detail/transfer.h 2014-05-05 19:54:30 +0000
665@@ -35,6 +35,7 @@
666 Q_PROPERTY(int State READ State NOTIFY StateChanged)
667 Q_PROPERTY(QString Store READ Store WRITE SetStore NOTIFY StoreChanged)
668 Q_PROPERTY(int SelectionType READ SelectionType WRITE SetSelectionType NOTIFY SelectionTypeChanged)
669+ Q_PROPERTY(QString DownloadId READ DownloadId WRITE SetDownloadId NOTIFY DownloadIdChanged)
670 Q_PROPERTY(int id READ Id)
671 Q_PROPERTY(QString source READ source)
672 Q_PROPERTY(QString destination READ destination)
673@@ -54,6 +55,7 @@
674 void StateChanged(int State);
675 void StoreChanged(QString Store);
676 void SelectionTypeChanged(int SelectionType);
677+ void DownloadIdChanged(QString DownloadId);
678
679 public Q_SLOTS:
680 int State();
681@@ -73,6 +75,10 @@
682 QString destination();
683 QString export_path();
684 QString import_path();
685+ QString DownloadId();
686+ void SetDownloadId(QString DownloadId);
687+ void DownloadComplete(QString destFilePath);
688+ void Download();
689
690 private:
691 struct Private;
692
693=== modified file 'src/com/ubuntu/content/service/main.cpp'
694--- src/com/ubuntu/content/service/main.cpp 2014-03-27 16:03:14 +0000
695+++ src/com/ubuntu/content/service/main.cpp 2014-05-05 19:54:30 +0000
696@@ -24,6 +24,7 @@
697 #include "debug.h"
698 #include "common.h"
699 #include "registry.h"
700+#include "detail/i18n.h"
701 #include "detail/service.h"
702 #include "detail/peer_registry.h"
703 #include "serviceadaptor.h"
704@@ -45,6 +46,8 @@
705 int ret = 0;
706 QCoreApplication *app = new QCoreApplication(argc, argv);
707
708+ cucd::initTr(I18N_DOMAIN, NULL);
709+
710 /* read environment variables */
711 QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
712 if (environment.contains(QLatin1String("CONTENT_HUB_LOGGING_LEVEL"))) {
713
714=== modified file 'src/com/ubuntu/content/transfer.cpp'
715--- src/com/ubuntu/content/transfer.cpp 2014-03-04 21:47:48 +0000
716+++ src/com/ubuntu/content/transfer.cpp 2014-05-05 19:54:30 +0000
717@@ -106,3 +106,19 @@
718 {
719 return d->direction();
720 }
721+
722+QString cuc::Transfer::downloadId() const
723+{
724+ return d->downloadId();
725+}
726+
727+bool cuc::Transfer::setDownloadId(QString downloadId)
728+{
729+ return d->setDownloadId(downloadId);
730+}
731+
732+bool cuc::Transfer::download()
733+{
734+ return d->download();
735+}
736+
737
738=== modified file 'src/com/ubuntu/content/transfer_p.h'
739--- src/com/ubuntu/content/transfer_p.h 2014-02-19 16:41:30 +0000
740+++ src/com/ubuntu/content/transfer_p.h 2014-05-05 19:54:30 +0000
741@@ -117,7 +117,7 @@
742
743 return not reply.isError();
744 }
745-
746+
747 QVector<Item> collect()
748 {
749 QVector<Item> result;
750@@ -190,6 +190,33 @@
751 return static_cast<Transfer::Direction>(reply.value());
752 }
753
754+ QString downloadId()
755+ {
756+ auto reply = remote_transfer->DownloadId();
757+ reply.waitForFinished();
758+
759+ if (reply.isError())
760+ return QString();
761+
762+ return static_cast<QString>(reply.value());
763+ }
764+
765+ bool setDownloadId(QString downloadId)
766+ {
767+ auto reply = remote_transfer->SetDownloadId(downloadId);
768+ reply.waitForFinished();
769+
770+ return not reply.isError();
771+ }
772+
773+ bool download()
774+ {
775+ auto reply = remote_transfer->Download();
776+ reply.waitForFinished();
777+
778+ return not reply.isError();
779+ }
780+
781 com::ubuntu::content::dbus::Transfer* remote_transfer;
782 };
783 }

Subscribers

People subscribed via source and target branches