~mzanetti/+junk/ubtd

« back to all changes in this revision

Viewing changes to shareplugin/bttransfer.cpp

  • Committer: Michael Zanetti
  • Date: 2016-08-21 10:28:36 UTC
  • Revision ID: michael.zanetti@canonical.com-20160821102836-mam1manqthov2um9
improve!

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    return m_error != QBluetoothTransferReply::NoError;
31
31
}
32
32
 
 
33
QString BtTransfer::currentFile() const
 
34
{
 
35
    if (!reply || m_queue.isEmpty()) {
 
36
        return QString();
 
37
    }
 
38
    return m_queue.first().second;
 
39
}
 
40
 
33
41
void BtTransfer::sendFile(const QString &address, const QString &fileName)
34
42
{
35
 
    qDebug() << "Begin sharing file: " << address << fileName;
36
 
    QBluetoothAddress btAddress = QBluetoothAddress(address);
37
 
    QBluetoothTransferRequest request(btAddress);
38
 
    QFile *file = new QFile(fileName);
 
43
    qDebug() << "Queuing send operation: " << address << fileName;
 
44
    m_queue.append(qMakePair<QBluetoothAddress, QString>(QBluetoothAddress(address), fileName));
 
45
    processQueue();
 
46
}
 
47
 
 
48
void BtTransfer::processQueue()
 
49
{
 
50
    if (reply) {
 
51
        qWarning() << "Still busy sending... Not starting another send operation.";
 
52
        return;
 
53
    }
 
54
    if (m_queue.isEmpty()) {
 
55
        return;
 
56
    }
 
57
    QPair<QBluetoothAddress, QString> item = m_queue.first();
 
58
    qDebug() << "Starting sending for:" << item.first << item.second;
 
59
    QBluetoothTransferRequest request(item.first);
 
60
    QFile *file = new QFile(item.second);
39
61
    reply = manager.put(request, file);
40
62
    connect(reply, SIGNAL(transferProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
41
63
    connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), this, SLOT(transferFinished(QBluetoothTransferReply*)));
51
73
void BtTransfer::transferFinished(QBluetoothTransferReply *reply)
52
74
{
53
75
    reply->deleteLater();
 
76
    m_queue.takeFirst();
54
77
    this->reply = 0;
55
 
    m_finished = true;
56
 
    emit finishedChanged();
 
78
    if (m_queue.isEmpty()) {
 
79
        m_finished = true;
 
80
        emit finishedChanged();
 
81
    } else {
 
82
        processQueue();
 
83
    }
 
84
    emit progressChanged();
57
85
}
58
86
 
59
87
void BtTransfer::transferError(QBluetoothTransferReply::TransferError lastError)
60
88
{
61
89
    m_error = lastError;
 
90
    reply->deleteLater();
 
91
    reply = 0;
62
92
    emit errorChanged();
 
93
    emit progressChanged();
63
94
}