2
* Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18
#include <contentcommunicator.h>
21
#include <QTemporaryFile>
24
#include <com/ubuntu/content/hub.h>
25
#include <com/ubuntu/content/item.h>
26
#include <com/ubuntu/content/transfer.h>
28
using namespace com::ubuntu::content;
31
* \brief ContentCommunicator::ContentCommunicator
34
ContentCommunicator::ContentCommunicator(QObject *parent)
35
: ImportExportHandler(parent),
38
Hub *hub = Hub::Client::instance();
40
hub->register_import_export_handler(this);
42
qWarning() << "Fail to get Hub client instance";
49
void ContentCommunicator::handle_import(content::Transfer *)
51
qDebug() << Q_FUNC_INFO << "address book app does not import content";
57
void ContentCommunicator::handle_export(content::Transfer *transfer)
59
if (m_transfer != 0) {
60
qWarning() << "address book app does only one content export at a time";
67
m_transfer = transfer;
68
connect(m_transfer, SIGNAL(selectionTypeChanged()), SIGNAL(multipleItemsChanged()));
70
qWarning() << "Transfer pointer is null in handle_export";
72
Q_EMIT contactRequested();
73
Q_EMIT activeChanged();
74
Q_EMIT multipleItemsChanged();
78
* \brief ContentCommunicator::cancelTransfer aborts the current transfer
80
void ContentCommunicator::cancelTransfer()
83
qWarning() << "No ongoing transfer to cancel";
89
Q_EMIT activeChanged();
93
* \brief ContentCommunicator::returnContacts returns the given contacts
94
* via content hub to the requester
97
void ContentCommunicator::returnContacts(const QUrl &contactsFile)
100
qWarning() << "No ongoing transfer to return a contact";
105
items << contactsFile;
106
m_transfer->charge(items);
108
Q_EMIT activeChanged();
111
bool ContentCommunicator::isActive() const
113
return (m_transfer != 0);
116
bool ContentCommunicator::isMultipleItems() const
118
return (m_transfer && m_transfer->selectionType() == Transfer::multiple);
121
QUrl ContentCommunicator::createTemporaryFile() const
123
QTemporaryFile tmp(QDir::tempPath() + "/vcard_XXXXXX.vcf");
124
tmp.setAutoRemove(false);
126
qWarning() << "Fail to create temporary file for vcard.";
129
QString tmpFileName = tmp.fileName();
131
return QUrl::fromLocalFile(tmpFileName);