File indexing completed on 2024-04-28 03:52:05

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