File indexing completed on 2024-04-28 15:17:56

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014-2015 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 #ifndef BLUEZQT_OBEXTRANSFER_H
0010 #define BLUEZQT_OBEXTRANSFER_H
0011 
0012 #include <QObject>
0013 
0014 #include "bluezqt_export.h"
0015 #include "types.h"
0016 
0017 class QDBusObjectPath;
0018 
0019 namespace BluezQt
0020 {
0021 class PendingCall;
0022 
0023 /**
0024  * @class BluezQt::ObexTransfer obextransfer.h <BluezQt/ObexTransfer>
0025  *
0026  * OBEX transfer.
0027  *
0028  * This class represents transfer of one file.
0029  */
0030 class BLUEZQT_EXPORT ObexTransfer : public QObject
0031 {
0032     Q_OBJECT
0033 
0034     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
0035     Q_PROPERTY(QString name READ name)
0036     Q_PROPERTY(QString type READ type)
0037     Q_PROPERTY(quint64 time READ time)
0038     Q_PROPERTY(quint64 size READ size)
0039     Q_PROPERTY(quint64 transferred READ transferred NOTIFY transferredChanged)
0040     Q_PROPERTY(QString fileName READ fileName NOTIFY fileNameChanged)
0041     Q_PROPERTY(bool suspendable READ isSuspendable)
0042 
0043 public:
0044     /**
0045      * Status of transfer.
0046      */
0047     enum Status {
0048         /** Indicates that the transfer is queued. */
0049         Queued,
0050         /** Indicates that the transfer is active. */
0051         Active,
0052         /** Indicates that the transfer is suspended. */
0053         Suspended,
0054         /** Indicates that the transfer have completed successfully. */
0055         Complete,
0056         /** Indicates that the transfer have failed with error. */
0057         Error,
0058         /** Indicates that the transfer status is unknown. */
0059         Unknown,
0060     };
0061     Q_ENUM(Status)
0062 
0063     /**
0064      * Destroys an ObexTransfer object.
0065      */
0066     ~ObexTransfer() override;
0067 
0068     /**
0069      * Returns a shared pointer from this.
0070      *
0071      * @return ObexTransferPtr
0072      */
0073     ObexTransferPtr toSharedPtr() const;
0074 
0075     /**
0076      * D-Bus object path of the transfer.
0077      *
0078      * @return object path of transfer
0079      */
0080     QDBusObjectPath objectPath() const;
0081 
0082     /**
0083      * Returns the status of the transfer.
0084      *
0085      * @return status of transfer
0086      */
0087     Status status() const;
0088 
0089     /**
0090      * Returns the name of the transferred object.
0091      *
0092      * @return name of transferred object
0093      */
0094     QString name() const;
0095 
0096     /**
0097      * Returns the type of the transferred object.
0098      *
0099      * @return type of transferred object
0100      */
0101     QString type() const;
0102 
0103     /**
0104      * Returns the time of the transferred object.
0105      *
0106      * @return time of transferred object
0107      */
0108     quint64 time() const;
0109 
0110     /**
0111      * Returns the total size of the transferred object.
0112      *
0113      * @return size of transferred object
0114      */
0115     quint64 size() const;
0116 
0117     /**
0118      * Returns the number of bytes transferred.
0119      *
0120      * @return number of bytes transferred
0121      */
0122     quint64 transferred() const;
0123 
0124     /**
0125      * Returns the full name of the transferred file.
0126      *
0127      * @return full name of transferred file
0128      */
0129     QString fileName() const;
0130 
0131     /**
0132      * Returns whether the transfer is suspendable.
0133      *
0134      * @return true if transfer is suspendable
0135      */
0136     bool isSuspendable() const;
0137 
0138     /**
0139      * Stops the current transfer.
0140      *
0141      * Possible errors: PendingCall::NotAuthorized, PendingCall::InProgress
0142      *                  PendingCall::Failed
0143      *
0144      * @return void pending call
0145      */
0146     PendingCall *cancel();
0147 
0148     /**
0149      * Suspends the current transfer.
0150      *
0151      * Only suspendable transfers can be suspended.
0152      *
0153      * Possible errors: PendingCall::NotAuthorized, PendingCall::NotInProgress
0154      *
0155      * @see isSuspendable() const
0156      *
0157      * @return void pending call
0158      */
0159     PendingCall *suspend();
0160 
0161     /**
0162      * Resumes the current transfer.
0163      *
0164      * Possible errors: PendingCall::NotAuthorized, PendingCall::NotInProgress
0165      *
0166      * @return void pending call
0167      */
0168     PendingCall *resume();
0169 
0170 Q_SIGNALS:
0171     /**
0172      * Indicates that the status of transfer have changed.
0173      */
0174     void statusChanged(Status status);
0175 
0176     /**
0177      * Indicates that the number of transferred bytes have changed.
0178      */
0179     void transferredChanged(quint64 transferred);
0180 
0181     /**
0182      * Indicates that the name of transferred file have changed.
0183      */
0184     void fileNameChanged(const QString &fileName);
0185 
0186 private:
0187     BLUEZQT_NO_EXPORT explicit ObexTransfer(const QString &path, const QVariantMap &properties);
0188 
0189     class ObexTransferPrivate *const d;
0190 
0191     friend class ObexTransferPrivate;
0192     friend class ObexAgentAdaptor;
0193     friend class PendingCallPrivate;
0194 };
0195 
0196 } // namespace BluezQt
0197 
0198 #endif // BLUEZQT_OBEXTRANSFER_H