Warning, file /frameworks/bluez-qt/src/obextransfer.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "obextransfer.h" 0010 #include "macros.h" 0011 #include "obexmanager.h" 0012 #include "obexsession.h" 0013 #include "obextransfer_p.h" 0014 #include "pendingcall.h" 0015 #include "utils.h" 0016 0017 namespace BluezQt 0018 { 0019 static ObexTransfer::Status stringToStatus(const QString &status) 0020 { 0021 if (status == QLatin1String("queued")) { 0022 return ObexTransfer::Queued; 0023 } else if (status == QLatin1String("active")) { 0024 return ObexTransfer::Active; 0025 } else if (status == QLatin1String("suspended")) { 0026 return ObexTransfer::Suspended; 0027 } else if (status == QLatin1String("complete")) { 0028 return ObexTransfer::Complete; 0029 } else if (status == QLatin1String("error")) { 0030 return ObexTransfer::Error; 0031 } 0032 return ObexTransfer::Unknown; 0033 } 0034 0035 ObexTransferPrivate::ObexTransferPrivate(const QString &path, const QVariantMap &properties) 0036 : QObject() 0037 , m_dbusProperties(nullptr) 0038 , m_status(ObexTransfer::Error) 0039 , m_time(0) 0040 , m_size(0) 0041 , m_transferred(0) 0042 , m_suspendable(false) 0043 { 0044 m_bluezTransfer = new BluezTransfer(Strings::orgBluezObex(), path, DBusConnection::orgBluezObex(), this); 0045 0046 if (Instance::obexManager()) { 0047 connect(Instance::obexManager(), &ObexManager::sessionRemoved, this, &ObexTransferPrivate::sessionRemoved); 0048 } 0049 0050 init(properties); 0051 } 0052 0053 void ObexTransferPrivate::init(const QVariantMap &properties) 0054 { 0055 m_dbusProperties = new DBusProperties(Strings::orgBluezObex(), m_bluezTransfer->path(), DBusConnection::orgBluezObex(), this); 0056 0057 connect(m_dbusProperties, &DBusProperties::PropertiesChanged, this, &ObexTransferPrivate::propertiesChanged, Qt::QueuedConnection); 0058 0059 // Init properties 0060 m_status = stringToStatus(properties.value(QStringLiteral("Status")).toString()); 0061 m_name = properties.value(QStringLiteral("Name")).toString(); 0062 m_type = properties.value(QStringLiteral("Type")).toString(); 0063 m_time = properties.value(QStringLiteral("Time")).toUInt(); 0064 m_size = properties.value(QStringLiteral("Size")).toUInt(); 0065 m_transferred = properties.value(QStringLiteral("Transferred")).toUInt(); 0066 m_fileName = properties.value(QStringLiteral("Filename")).toString(); 0067 } 0068 0069 void ObexTransferPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) 0070 { 0071 Q_UNUSED(invalidated) 0072 0073 if (interface != Strings::orgBluezObexTransfer1()) { 0074 return; 0075 } 0076 0077 QVariantMap::const_iterator i; 0078 for (i = changed.constBegin(); i != changed.constEnd(); ++i) { 0079 const QVariant &value = i.value(); 0080 const QString &property = i.key(); 0081 0082 if (property == QLatin1String("Status")) { 0083 PROPERTY_CHANGED2(m_status, stringToStatus(value.toString()), statusChanged); 0084 } else if (property == QLatin1String("Transferred")) { 0085 PROPERTY_CHANGED(m_transferred, toUInt, transferredChanged); 0086 } else if (property == QLatin1String("Filename")) { 0087 PROPERTY_CHANGED(m_fileName, toString, fileNameChanged); 0088 } 0089 } 0090 } 0091 0092 void ObexTransferPrivate::sessionRemoved(const ObexSessionPtr &session) 0093 { 0094 if (!m_bluezTransfer->path().startsWith(session->objectPath().path())) { 0095 return; 0096 } 0097 0098 // Change status to Error if org.bluez.obex crashes 0099 if (m_status != ObexTransfer::Complete && m_status != ObexTransfer::Error) { 0100 m_status = ObexTransfer::Error; 0101 Q_EMIT q.lock()->statusChanged(m_status); 0102 } 0103 } 0104 0105 ObexTransfer::ObexTransfer(const QString &path, const QVariantMap &properties) 0106 : QObject() 0107 , d(new ObexTransferPrivate(path, properties)) 0108 { 0109 } 0110 0111 ObexTransfer::~ObexTransfer() 0112 { 0113 delete d; 0114 } 0115 0116 ObexTransferPtr ObexTransfer::toSharedPtr() const 0117 { 0118 return d->q.toStrongRef(); 0119 } 0120 0121 QDBusObjectPath ObexTransfer::objectPath() const 0122 { 0123 return QDBusObjectPath(d->m_bluezTransfer->path()); 0124 } 0125 0126 ObexTransfer::Status ObexTransfer::status() const 0127 { 0128 return d->m_status; 0129 } 0130 0131 QString ObexTransfer::name() const 0132 { 0133 return d->m_name; 0134 } 0135 0136 QString ObexTransfer::type() const 0137 { 0138 return d->m_type; 0139 } 0140 0141 quint64 ObexTransfer::time() const 0142 { 0143 return d->m_time; 0144 } 0145 0146 quint64 ObexTransfer::size() const 0147 { 0148 return d->m_size; 0149 } 0150 0151 quint64 ObexTransfer::transferred() const 0152 { 0153 return d->m_transferred; 0154 } 0155 0156 QString ObexTransfer::fileName() const 0157 { 0158 return d->m_fileName; 0159 } 0160 0161 bool ObexTransfer::isSuspendable() const 0162 { 0163 return d->m_suspendable; 0164 } 0165 0166 PendingCall *ObexTransfer::cancel() 0167 { 0168 return new PendingCall(d->m_bluezTransfer->Cancel(), PendingCall::ReturnVoid, this); 0169 } 0170 0171 PendingCall *ObexTransfer::suspend() 0172 { 0173 return new PendingCall(d->m_bluezTransfer->Suspend(), PendingCall::ReturnVoid, this); 0174 } 0175 0176 PendingCall *ObexTransfer::resume() 0177 { 0178 return new PendingCall(d->m_bluezTransfer->Resume(), PendingCall::ReturnVoid, this); 0179 } 0180 0181 } // namespace BluezQt 0182 0183 #include "moc_obextransfer.cpp" 0184 #include "moc_obextransfer_p.cpp"