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

« back to all changes in this revision

Viewing changes to import/Ubuntu/Content/contentpeer.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:
14
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 */
16
16
 
 
17
#include "../../../src/com/ubuntu/content/debug.h"
 
18
#include "contenthandler.h"
 
19
#include "contenthub.h"
 
20
#include "contenticonprovider.h"
17
21
#include "contentpeer.h"
 
22
#include "contenttype.h"
18
23
 
19
24
#include <com/ubuntu/content/peer.h>
20
 
 
21
 
#include <QDebug>
 
25
#include <QIcon>
22
26
 
23
27
/*!
24
28
 * \qmltype ContentPeer
36
40
 
37
41
ContentPeer::ContentPeer(QObject *parent)
38
42
    : QObject(parent),
39
 
      m_peer(0)
 
43
      m_peer(0),
 
44
      m_handler(ContentHandler::Source),
 
45
      m_contentType(ContentType::Unknown),
 
46
      m_selectionType(ContentTransfer::Single),
 
47
      m_explicit_peer(false)
40
48
{
41
 
    qDebug() << Q_FUNC_INFO;
 
49
    TRACE() << Q_FUNC_INFO;
 
50
 
 
51
    m_hub = cuc::Hub::Client::instance();
42
52
}
43
53
 
44
54
/*!
45
55
 * \qmlproperty string ContentPeer::name
46
56
 *
47
 
 * Returns user friendly name of the peer
 
57
 * Returns user friendly name of the peer.
48
58
 */
49
59
QString ContentPeer::name()
50
60
{
51
 
    qDebug() << Q_FUNC_INFO;
 
61
    TRACE() << Q_FUNC_INFO;
52
62
    return m_peer.name();
53
63
}
54
64
 
55
65
/*!
56
66
 * \qmlproperty string ContentPeer::appId
57
 
 *
58
 
 * Returns the Application id
 
67
 * When set, this property allows for a specific application to be used as a peer.
59
68
 */
60
69
const QString &ContentPeer::appId() const
61
70
{
62
 
    qDebug() << Q_FUNC_INFO;
 
71
    TRACE() << Q_FUNC_INFO;
63
72
    return m_peer.id();
64
73
}
65
74
 
66
75
/*!
 
76
 * \brief ContentPeer::setAppId
 
77
 * \internal
 
78
 * Sets the Application id
 
79
 */
 
80
void ContentPeer::setAppId(const QString& appId)
 
81
{
 
82
    TRACE() << Q_FUNC_INFO << appId;
 
83
    this->setPeer(cuc::Peer{appId});
 
84
}
 
85
 
 
86
QImage &ContentPeer::icon()
 
87
{
 
88
    TRACE() << Q_FUNC_INFO;
 
89
    return m_icon;
 
90
}
 
91
 
 
92
/*!
67
93
 * \brief ContentPeer::peer
68
94
 * \internal
69
95
 */
76
102
 * \brief ContentPeer::setPeer
77
103
 * \internal
78
104
 */
79
 
void ContentPeer::setPeer(const cuc::Peer &peer)
 
105
void ContentPeer::setPeer(const cuc::Peer &peer, bool explicitPeer)
80
106
{
 
107
    TRACE() << Q_FUNC_INFO;
81
108
    m_peer = peer;
 
109
    m_explicit_peer = explicitPeer;
 
110
    if (peer.iconData().isEmpty())
 
111
    {
 
112
        if (QIcon::hasThemeIcon(peer.iconName().toUtf8()))
 
113
            m_icon = QIcon::fromTheme(peer.iconName().toUtf8()).pixmap(256).toImage();
 
114
    } else
 
115
        m_icon.loadFromData(peer.iconData());
 
116
    ContentIconProvider *iconProvider = ContentIconProvider::instance();
 
117
    iconProvider->addImage(appId(), m_icon);
 
118
 
82
119
    Q_EMIT nameChanged();
83
120
    Q_EMIT appIdChanged();
84
121
}
 
122
 
 
123
/*!
 
124
 * \qmlproperty ContentHandler ContentPeer::handler
 
125
 * Specifies which ContentHandler this peer should support (e.g. Source, Destination, Share).
 
126
 */
 
127
ContentHandler::Handler ContentPeer::handler()
 
128
{
 
129
    TRACE() << Q_FUNC_INFO;
 
130
    return m_handler;
 
131
}
 
132
 
 
133
/*!
 
134
 * \brief ContentPeer::setHandler
 
135
 * \internal
 
136
 */
 
137
void ContentPeer::setHandler(ContentHandler::Handler handler)
 
138
{   
 
139
    TRACE() << Q_FUNC_INFO;
 
140
    m_handler = handler;
 
141
 
 
142
    Q_EMIT handlerChanged();
 
143
}
 
144
 
 
145
/*!
 
146
 * \qmlproperty ContentType ContentPeer::contentType
 
147
 * Specifies the ContentType this peer should support.
 
148
 */
 
149
ContentType::Type ContentPeer::contentType() 
 
150
{
 
151
    TRACE() << Q_FUNC_INFO;
 
152
    return m_contentType;
 
153
}
 
154
 
 
155
/*!
 
156
 * \brief ContentPeer::setContentType
 
157
 * \internal
 
158
 */
 
159
void ContentPeer::setContentType(ContentType::Type contentType)
 
160
{   
 
161
    TRACE() << Q_FUNC_INFO;
 
162
    m_contentType = contentType;
 
163
 
 
164
    if(!m_explicit_peer) {
 
165
        const cuc::Type &hubType = ContentType::contentType2HubType(m_contentType);
 
166
        setPeer(m_hub->default_source_for_type(hubType), false);
 
167
    }
 
168
 
 
169
    Q_EMIT contentTypeChanged();
 
170
}
 
171
 
 
172
/*!
 
173
 * \qmlproperty ContentTransfer.SelectionType ContentPeer::selectionType
 
174
 * Specifies whether this peer is allowed to return multiple items.
 
175
 */
 
176
ContentTransfer::SelectionType ContentPeer::selectionType()
 
177
{
 
178
    TRACE() << Q_FUNC_INFO;
 
179
    return m_selectionType;
 
180
}
 
181
 
 
182
/*!
 
183
 * \brief ContentPeer::setSelectionType
 
184
 * \internal
 
185
 */
 
186
void ContentPeer::setSelectionType(ContentTransfer::SelectionType selectionType)
 
187
{
 
188
    TRACE() << Q_FUNC_INFO;
 
189
    m_selectionType = selectionType;
 
190
 
 
191
    Q_EMIT selectionTypeChanged();
 
192
}
 
193
 
 
194
/*!
 
195
 * \brief ContentPeer::isDefaultPeer
 
196
 * \internal
 
197
 */
 
198
bool ContentPeer::isDefaultPeer()
 
199
{
 
200
    TRACE() << Q_FUNC_INFO;
 
201
    return m_peer.isDefaultPeer();
 
202
}
 
203
 
 
204
/*!
 
205
 * \qmlmethod ContentPeer::request()
 
206
 *
 
207
 * \brief Request an active transfer from this ContentPeer.
 
208
 */
 
209
ContentTransfer *ContentPeer::request()
 
210
{   
 
211
    TRACE() << Q_FUNC_INFO;
 
212
    return request(nullptr);
 
213
}
 
214
 
 
215
/*!
 
216
 * \qmlmethod ContentPeer::request(ContentStore)
 
217
 *
 
218
 * \brief Request to an active transfer from this ContentPeer and use
 
219
 * a ContentStore for permanent storage.
 
220
 */
 
221
ContentTransfer *ContentPeer::request(ContentStore *store)
 
222
{
 
223
    TRACE() << Q_FUNC_INFO;
 
224
 
 
225
    ContentHub *contentHub = ContentHub::instance();
 
226
    ContentTransfer *qmlTransfer = NULL;
 
227
    if(m_handler == ContentHandler::Source) {
 
228
        qmlTransfer = contentHub->importContent(m_peer);
 
229
    } else if (m_handler == ContentHandler::Destination) {
 
230
        qmlTransfer = contentHub->exportContent(m_peer);
 
231
    } else if (m_handler == ContentHandler::Share) {
 
232
        qmlTransfer = contentHub->shareContent(m_peer);
 
233
    }
 
234
 
 
235
    qmlTransfer->setSelectionType(m_selectionType);
 
236
    if(store) {
 
237
        store->updateStore(m_contentType);
 
238
        qmlTransfer->setStore(store);
 
239
    }
 
240
    
 
241
    /* We only need to start it for import requests */
 
242
    if (m_handler == ContentHandler::Source)
 
243
        qmlTransfer->start();
 
244
 
 
245
    return qmlTransfer;
 
246
}