diff options
-rw-r--r-- | src/bluetooth/qbluetoothtransferreply.cpp | 2 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothtransferreply.h | 4 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothtransferreply_qnx.cpp | 70 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothtransferreply_qnx_p.h | 6 |
4 files changed, 62 insertions, 20 deletions
diff --git a/src/bluetooth/qbluetoothtransferreply.cpp b/src/bluetooth/qbluetoothtransferreply.cpp index ae97c639..9acd917d 100644 --- a/src/bluetooth/qbluetoothtransferreply.cpp +++ b/src/bluetooth/qbluetoothtransferreply.cpp @@ -68,6 +68,8 @@ QT_BEGIN_NAMESPACE \value FileNotFoundError Unable to open the file specified \value HostNotFoundError Unable to connect to the target host \value UserCanceledTransferError User terminated the transfer + \value IODeviceNotReadableError File was not open before initiating the sending command + \value ResourceBusyError Unable to access the resource. */ diff --git a/src/bluetooth/qbluetoothtransferreply.h b/src/bluetooth/qbluetoothtransferreply.h index 42571ca4..33910fd9 100644 --- a/src/bluetooth/qbluetoothtransferreply.h +++ b/src/bluetooth/qbluetoothtransferreply.h @@ -61,7 +61,9 @@ public: UnknownError, FileNotFoundError, HostNotFoundError, - UserCanceledTransferError + UserCanceledTransferError, + IODeviceNotReadableError, + ResourceBusyError }; diff --git a/src/bluetooth/qbluetoothtransferreply_qnx.cpp b/src/bluetooth/qbluetoothtransferreply_qnx.cpp index bc15fbde..3f22d536 100644 --- a/src/bluetooth/qbluetoothtransferreply_qnx.cpp +++ b/src/bluetooth/qbluetoothtransferreply_qnx.cpp @@ -56,8 +56,11 @@ #include <QtCore/private/qcore_unix_p.h> #include <QTime> +#include <QDir> +#include <QCoreApplication> -//static const QLatin1String agentPath("/shared/tmp/opp"); +static const QString agentPath(QStringLiteral("/accounts/1000/shared/misc/")); +static bool busy; QT_BEGIN_NAMESPACE @@ -69,7 +72,6 @@ QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const Q { setRequest(request); setManager(parent); - ppsRegisterControl(); //qsrand(QTime::currentTime().msec()); //m_agent_path = agentPath; @@ -87,6 +89,8 @@ QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const Q */ QBluetoothTransferReplyQnx::~QBluetoothTransferReplyQnx() { + removeTempFile(); + delete tempfile; ppsUnregisterControl(this); } @@ -98,19 +102,39 @@ bool QBluetoothTransferReplyQnx::start() QFile *file = qobject_cast<QFile *>(source); if (!file){ -// tempfile = new QTemporaryFile(this ); -// tempfile->open(); - -// QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(); -// QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone())); + // Deleting temporary files in case of app crash + QDir directory(agentPath); + QString appName = QStringLiteral("Qt5OPP_tmp") + QCoreApplication::applicationName(); + if (directory.exists(appName) && !busy) { + QFile file(agentPath + appName); + file.remove(); + } + else if (directory.exists(appName) && busy) { + m_errorStr = QBluetoothTransferReply::tr("Resurce busy."); + m_error = QBluetoothTransferReply::ResourceBusyError; + m_finished = true; + m_running = false; + Q_EMIT finished(this); + return false; + } + if (!source->isReadable()) { + m_errorStr = QBluetoothTransferReply::tr("QIODevice cannot be read." + "Make sure it is open for reading."); + m_error = QBluetoothTransferReply::IODeviceNotReadableError; + m_finished = true; + m_running = false; + Q_EMIT finished(this); + return false; + } + QString fileName = agentPath + QStringLiteral("Qt5OPP_tmp"); + tempfile = new QFile(fileName); + tempfile->open(QIODevice::WriteOnly); -// QFuture<bool> results = QtConcurrent::run(QBluetoothTransferReplyQnx::copyToTempFile, tempfile, source); -// watcher->setFuture(results); - //QTemporaryFile does not work properly yet - m_error = QBluetoothTransferReply::UnknownError; - m_finished = true; - m_running = false; - Q_EMIT finished(this); + QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(); + QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone())); + QFuture<bool> results = QtConcurrent::run(QBluetoothTransferReplyQnx::copyToTempFile, tempfile, source); + watcher->setFuture(results); + busy = true; } else { if (!file->exists()) { @@ -139,7 +163,7 @@ bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from) char *block = new char[4096]; int size; - while ((size = from->read(block, 4096))) { + while ((size = from->read(block, 4096)) > 0) { if (size != to->write(block, size)) return false; } @@ -150,14 +174,14 @@ bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from) void QBluetoothTransferReplyQnx::copyDone() { - qCDebug(QT_BT_QNX) << "Copy done"; startOPP(tempfile->fileName()); QObject::sender()->deleteLater(); } void QBluetoothTransferReplyQnx::startOPP(QString filename) { - qCDebug(QT_BT_QNX) << "Sending Push object command"; + qCDebug(QT_BT_QNX) << "Sending push object command" + << request().address().toString() << filename; ppsSendOpp("push_object", filename.toUtf8(), request().address(), this); } @@ -183,6 +207,7 @@ void QBluetoothTransferReplyQnx::controlEvent(ppsResult result) { if (result.msg == QStringLiteral("opp_cancelled")) { qCDebug(QT_BT_QNX) << "opp cancelled" << result.errorMsg << result.error; + removeTempFile(); if (m_running) return; m_finished = true; @@ -215,6 +240,7 @@ void QBluetoothTransferReplyQnx::controlEvent(ppsResult result) Q_EMIT transferProgress(sentBytes, totalBytes); } else if (result.msg == QStringLiteral("opp_complete")) { qCDebug(QT_BT_QNX) << "opp complete"; + removeTempFile(); m_finished = true; m_running = false; Q_EMIT finished(this); @@ -242,6 +268,16 @@ void QBluetoothTransferReplyQnx::abort() //not supported yet } +void QBluetoothTransferReplyQnx::removeTempFile() +{ + if (tempfile) { + if (tempfile->exists()) { + tempfile->remove(); + busy = false; + } + } +} + #include "moc_qbluetoothtransferreply_qnx_p.cpp" QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothtransferreply_qnx_p.h b/src/bluetooth/qbluetoothtransferreply_qnx_p.h index 4522c8bf..903545c2 100644 --- a/src/bluetooth/qbluetoothtransferreply_qnx_p.h +++ b/src/bluetooth/qbluetoothtransferreply_qnx_p.h @@ -50,11 +50,12 @@ #include "qbluetoothtransferreply.h" -#include <QTemporaryFile> #include <QSocketNotifier> #include "qnx/ppshelpers_p.h" +QT_FORWARD_DECLARE_CLASS(QFile) + QT_BEGIN_NAMESPACE class Q_BLUETOOTH_EXPORT QBluetoothTransferReplyQnx : public QBluetoothTransferReply @@ -80,7 +81,8 @@ private Q_SLOTS: private: void startOPP(QString filename); - QTemporaryFile *tempfile; + void removeTempFile(); + QFile *tempfile; QIODevice *source; bool m_running; |