~ubuntu-branches/ubuntu/trusty/content-hub/trusty-proposed

« back to all changes in this revision

Viewing changes to import/Ubuntu/Content/contenttransfer.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Ken VanDine, Ubuntu daily release
  • Date: 2014-03-21 00:46:57 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20140321004657-5w0p7mj1qn9lrrj3
Tags: 0.0+14.04.20140321-0ubuntu1
[ Ken VanDine ]
* Adds support for multiple handler types: source, destination and
  share. Enforce single transfer per peer, if a second transfer
  request is made from a peer that already has an unfinished transfer,
  cancel the previous one. This is needed as long as apps are required
  to be single instance.
* If the transfer isn't persistent, attempt to hardlink instead of
  copying. If the link fails, fallback to a copy.
* If the default source is set to anything other than a click appId
  triplet, fallback to the legacy APP_ID. Changed default source for
  contacts to the legacy APP_ID for address-book-app

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "contenttransfer.h"
18
18
#include "contentitem.h"
 
19
#include "../../../src/com/ubuntu/content/debug.h"
19
20
 
20
21
#include <com/ubuntu/content/item.h>
21
22
 
22
 
#include <QDebug>
23
 
 
24
23
/*!
25
24
 * \qmltype ContentTransfer
26
25
 * \instantiates ContentTransfer
39
38
      m_selectionType(Single),
40
39
      m_store(0)
41
40
{
42
 
    qDebug() << Q_FUNC_INFO;
 
41
    TRACE() << Q_FUNC_INFO;
43
42
}
44
43
 
45
44
/*!
76
75
 */
77
76
ContentTransfer::State ContentTransfer::state() const
78
77
{
79
 
    qDebug() << Q_FUNC_INFO;
 
78
    TRACE() << Q_FUNC_INFO;
80
79
    return m_state;
81
80
}
82
81
 
83
82
void ContentTransfer::setState(ContentTransfer::State state)
84
83
{
85
 
    qDebug() << Q_FUNC_INFO;
 
84
    TRACE() << Q_FUNC_INFO << state;
86
85
    if (!m_transfer)
87
86
        return;
88
87
 
89
 
    if (state == Charged && m_state == InProgress && m_direction == Export) {
 
88
    if (state == Charged && m_state == InProgress) {
 
89
        TRACE() << Q_FUNC_INFO << "Charged";
90
90
        QVector<cuc::Item> hubItems;
91
91
        hubItems.reserve(m_items.size());
92
 
        foreach (const ContentItem *citem, m_items) {
 
92
        Q_FOREACH (const ContentItem *citem, m_items) {
93
93
            hubItems.append(citem->item());
94
94
        }
95
95
        m_transfer->charge(hubItems);
96
 
    }
 
96
        return;
 
97
    } else if (state == Aborted) {
 
98
        TRACE() << Q_FUNC_INFO << "Aborted";
 
99
        m_transfer->abort();
 
100
    } else
 
101
        updateState();
97
102
}
98
103
 
99
104
/*!
112
117
  \row
113
118
    \li ContentTransfer.Export
114
119
    \li Transfer is a request to export content.
 
120
  \row
 
121
    \li ContentTransfer.Share
 
122
    \li Transfer is a request to share content.
115
123
  \endtable
116
124
 */
117
125
ContentTransfer::Direction ContentTransfer::direction() const
144
152
 
145
153
void ContentTransfer::setSelectionType(ContentTransfer::SelectionType type)
146
154
{
147
 
    qDebug() << Q_FUNC_INFO << type;
 
155
    TRACE() << Q_FUNC_INFO << type;
148
156
    if (!m_transfer)
149
157
        return;
150
158
 
160
168
 */
161
169
QQmlListProperty<ContentItem> ContentTransfer::items()
162
170
{
163
 
    qDebug() << Q_FUNC_INFO;
164
 
    if (m_state == Charged && m_direction == Import) {
 
171
    TRACE() << Q_FUNC_INFO;
 
172
    if (m_state == Charged) {
165
173
        collectItems();
166
174
    }
167
175
    return QQmlListProperty<ContentItem>(this, m_items);
174
182
 */
175
183
bool ContentTransfer::start()
176
184
{
177
 
    qDebug() << Q_FUNC_INFO;
 
185
    TRACE() << Q_FUNC_INFO << m_transfer->id() << ":" << m_state;
178
186
    if (m_state == Created) {
179
187
        return m_transfer->start();
180
188
    } else {
190
198
 */
191
199
bool ContentTransfer::finalize()
192
200
{
193
 
    qDebug() << Q_FUNC_INFO;
 
201
    TRACE() << Q_FUNC_INFO;
194
202
    return m_transfer->finalize();
195
203
}
196
204
 
200
208
 */
201
209
const QString ContentTransfer::store() const
202
210
{
203
 
    qDebug() << Q_FUNC_INFO;
 
211
    TRACE() << Q_FUNC_INFO;
204
212
    return m_transfer->store().uri();
205
213
}
206
214
 
207
215
void ContentTransfer::setStore(ContentStore* contentStore)
208
216
{
209
 
    qDebug() << Q_FUNC_INFO;
 
217
    TRACE() << Q_FUNC_INFO;
210
218
 
211
219
    if (!m_transfer)
212
220
    {
213
221
        qWarning() << Q_FUNC_INFO << "invalid transfer";
214
222
        return;
215
223
    }
216
 
    m_transfer->setStore(contentStore->store());
 
224
 
 
225
    if(contentStore->store() != nullptr) {
 
226
        m_transfer->setStore(contentStore->store());
 
227
    }
217
228
}
218
229
 
219
230
/*!
222
233
 */
223
234
com::ubuntu::content::Transfer *ContentTransfer::transfer() const
224
235
{
225
 
    qDebug() << Q_FUNC_INFO;
 
236
    TRACE() << Q_FUNC_INFO;
226
237
    return m_transfer;
227
238
}
228
239
 
230
241
 * \brief ContentTransfer::setTransfer
231
242
 * \internal
232
243
 */
233
 
void ContentTransfer::setTransfer(com::ubuntu::content::Transfer *transfer, Direction direction)
 
244
void ContentTransfer::setTransfer(com::ubuntu::content::Transfer *transfer)
234
245
{
235
246
    if (m_transfer) {
236
247
        qWarning() << Q_FUNC_INFO << "the transfer object was already set";
242
253
        return;
243
254
    }
244
255
 
245
 
    qDebug() << Q_FUNC_INFO;
246
 
 
247
 
    m_direction = direction;
248
256
    m_transfer = transfer;
 
257
    m_direction = static_cast<ContentTransfer::Direction>(transfer->direction());
 
258
    TRACE() << Q_FUNC_INFO << "Direction:" << m_direction;
 
259
 
 
260
    connect(m_transfer, SIGNAL(selectionTypeChanged()), this, SLOT(updateSelectionType()));
 
261
    connect(m_transfer, SIGNAL(storeChanged()), this, SLOT(updateStore()));
 
262
    connect(m_transfer, SIGNAL(stateChanged()), this, SLOT(updateState()));
249
263
 
250
264
    updateSelectionType();
251
265
    updateStore();
252
266
    updateState();
253
 
 
254
 
    if (m_state == Charged && m_direction == Import)
255
 
        collectItems();
256
 
 
257
 
    connect(m_transfer, SIGNAL(selectionTypeChanged()), this, SLOT(updateSelectionType()));
258
 
    connect(m_transfer, SIGNAL(storeChanged()), this, SLOT(updateStore()));
259
 
    connect(m_transfer, SIGNAL(stateChanged()), this, SLOT(updateState()));
260
267
}
261
268
 
262
269
/*!
265
272
 */
266
273
void ContentTransfer::collectItems()
267
274
{
268
 
    qDebug() << Q_FUNC_INFO;
269
 
    if (m_state != Charged || m_direction != Import)
 
275
    TRACE() << Q_FUNC_INFO;
 
276
    if (m_state != Charged)
270
277
        return;
271
278
 
272
279
    qDeleteAll(m_items);
273
280
    m_items.clear();
274
281
 
275
282
    QVector<cuc::Item> transfereditems = m_transfer->collect();
276
 
    foreach (const cuc::Item &hubItem, transfereditems) {
 
283
    Q_FOREACH (const cuc::Item &hubItem, transfereditems) {
277
284
        ContentItem *qmlItem = new ContentItem(this);
278
285
        qmlItem->setItem(hubItem);
279
286
        m_items.append(qmlItem);
287
294
 */
288
295
void ContentTransfer::updateState()
289
296
{
290
 
    qDebug() << Q_FUNC_INFO;
 
297
    TRACE() << Q_FUNC_INFO << m_transfer->state();
 
298
 
291
299
    if (!m_transfer)
 
300
    {
 
301
        TRACE() << Q_FUNC_INFO << "Invalid transfer";
292
302
        return;
 
303
    }
293
304
 
294
305
    m_state = static_cast<ContentTransfer::State>(m_transfer->state());
295
306
    Q_EMIT stateChanged();
301
312
 */
302
313
void ContentTransfer::updateSelectionType()
303
314
{
304
 
    qDebug() << Q_FUNC_INFO;
 
315
    TRACE() << Q_FUNC_INFO;
305
316
    if (!m_transfer)
 
317
    {
 
318
        TRACE() << Q_FUNC_INFO << "Invalid transfer";
306
319
        return;
 
320
    }
307
321
 
308
322
    m_selectionType = static_cast<ContentTransfer::SelectionType>(m_transfer->selectionType());
309
323
    Q_EMIT selectionTypeChanged();
316
330
 */
317
331
void ContentTransfer::updateStore()
318
332
{
319
 
    qDebug() << Q_FUNC_INFO;
 
333
    TRACE() << Q_FUNC_INFO;
320
334
    if (!m_transfer)
 
335
    {
 
336
        TRACE() << Q_FUNC_INFO << "Invalid transfer";
321
337
        return;
 
338
    }
322
339
 
323
340
    m_store = m_transfer->store();
324
341
    Q_EMIT storeChanged();