~mzanetti/+junk/ubtd

« back to all changes in this revision

Viewing changes to shareplugin/bttransfer.cpp

  • Committer: Michael Zanetti
  • Date: 2016-04-14 23:34:10 UTC
  • Revision ID: michael.zanetti@canonical.com-20160414233410-17jg7ez3w1qc5e16
make it work, polish a bit, 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
BtTransfer::BtTransfer(QObject *parent) :
10
10
    QObject(parent),
11
 
    m_dbus(QDBusConnection::sessionBus()),
12
 
    m_manager("org.openobex.client", "/", "org.openobex.Client", m_dbus)
 
11
    reply(0),
 
12
    m_progress(0),
 
13
    m_finished(false),
 
14
    m_error(QBluetoothTransferReply::NoError)
13
15
{
14
16
}
15
17
 
18
20
    return m_progress;
19
21
}
20
22
 
 
23
bool BtTransfer::finished() const
 
24
{
 
25
    return m_finished;
 
26
}
 
27
 
 
28
bool BtTransfer::error() const
 
29
{
 
30
    return m_error != QBluetoothTransferReply::NoError;
 
31
}
 
32
 
21
33
void BtTransfer::sendFile(const QString &address, const QString &fileName)
22
34
{
23
 
    // Not working atm... TODO: Figure if this is working with BlueZ 5
24
 
//    qDebug() << "Begin sharing file: " << address << fileName;
25
 
//    QBluetoothAddress btAddress = QBluetoothAddress(address);
26
 
//    QBluetoothTransferRequest request(btAddress);
27
 
//    QFile *file = new QFile(fileName);
28
 
//    reply = manager.put(request, file);
29
 
//    connect(reply, SIGNAL(transferProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
30
 
 
31
 
    ObexAgent *agent = new ObexAgent();
32
 
 
33
 
    QVariantMap deviceMap;
34
 
    deviceMap.insert(QString::fromLatin1("Destination"), address);
35
 
 
36
 
    QStringList files;
37
 
    files << fileName;
38
 
 
39
 
 
40
 
    QDBusObjectPath path(DBUS_ADAPTER_AGENT_PATH);
41
 
 
42
 
 
43
 
    QDBusReply<void > reply = m_manager.call("SendFiles", qVariantFromValue(deviceMap), files, qVariantFromValue(path));
44
 
    if (!reply.isValid())
45
 
        qWarning() << "Error registering agent for the default adapter:" << reply.error();
46
 
    else
47
 
        qDebug() << "sending...";
48
 
 
 
35
    qDebug() << "Begin sharing file: " << address << fileName;
 
36
    QBluetoothAddress btAddress = QBluetoothAddress(address);
 
37
    QBluetoothTransferRequest request(btAddress);
 
38
    QFile *file = new QFile(fileName);
 
39
    reply = manager.put(request, file);
 
40
    connect(reply, SIGNAL(transferProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
 
41
    connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), this, SLOT(transferFinished(QBluetoothTransferReply*)));
 
42
    connect(reply, SIGNAL(error(QBluetoothTransferReply::TransferError)), this, SLOT(transferError(QBluetoothTransferReply::TransferError)));
49
43
}
50
44
 
51
45
void BtTransfer::updateProgress(qint64 transferred, qint64 total)
53
47
    m_progress = ((float)transferred)/((float)total);
54
48
    emit progressChanged();
55
49
}
 
50
 
 
51
void BtTransfer::transferFinished(QBluetoothTransferReply *reply)
 
52
{
 
53
    reply->deleteLater();
 
54
    this->reply = 0;
 
55
    m_finished = true;
 
56
    emit finishedChanged();
 
57
}
 
58
 
 
59
void BtTransfer::transferError(QBluetoothTransferReply::TransferError lastError)
 
60
{
 
61
    m_error = lastError;
 
62
    emit errorChanged();
 
63
}