1 | /* |
---|---|
2 | * BluezQt - Asynchronous Bluez wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #include "obexfiletransferentry.h" |
10 | |
11 | #include <QDateTime> |
12 | #include <QVariant> |
13 | |
14 | namespace BluezQt |
15 | { |
16 | class ObexFileTransferEntryPrivate |
17 | { |
18 | public: |
19 | QString m_name; |
20 | QString m_label; |
21 | ObexFileTransferEntry::Type m_type; |
22 | quint64 m_size; |
23 | QString m_permissions; |
24 | QString m_memoryType; |
25 | QDateTime m_modified; |
26 | }; |
27 | |
28 | static QDateTime dateTimeFromTransfer(const QString &value) |
29 | { |
30 | return QDateTime::fromString(string: value, QStringLiteral("yyyyMMddThhmmssZ")); |
31 | } |
32 | |
33 | ObexFileTransferEntry::ObexFileTransferEntry() |
34 | : d(new ObexFileTransferEntryPrivate) |
35 | { |
36 | d->m_type = Invalid; |
37 | d->m_size = 0; |
38 | } |
39 | |
40 | ObexFileTransferEntry::ObexFileTransferEntry(const QVariantMap &properties) |
41 | : d(new ObexFileTransferEntryPrivate) |
42 | { |
43 | d->m_name = properties.value(QStringLiteral("Name")).toString(); |
44 | d->m_label = properties.value(QStringLiteral("Label")).toString(); |
45 | d->m_size = properties.value(QStringLiteral("Size")).toUInt(); |
46 | d->m_permissions = properties.value(QStringLiteral("User-perm")).toString(); |
47 | d->m_memoryType = properties.value(QStringLiteral("Mem-type")).toString(); |
48 | d->m_modified = dateTimeFromTransfer(value: properties.value(QStringLiteral("Modified")).toString()); |
49 | |
50 | const QString &type = properties.value(QStringLiteral("Type")).toString(); |
51 | if (type == QLatin1String("folder")) { |
52 | d->m_type = ObexFileTransferEntry::Folder; |
53 | } else if (type == QLatin1String("file")) { |
54 | d->m_type = ObexFileTransferEntry::File; |
55 | } else { |
56 | d->m_type = ObexFileTransferEntry::Invalid; |
57 | } |
58 | } |
59 | |
60 | ObexFileTransferEntry::~ObexFileTransferEntry() |
61 | { |
62 | } |
63 | |
64 | ObexFileTransferEntry::ObexFileTransferEntry(const ObexFileTransferEntry &other) |
65 | : d(other.d) |
66 | { |
67 | } |
68 | |
69 | ObexFileTransferEntry &ObexFileTransferEntry::operator=(const ObexFileTransferEntry &other) |
70 | { |
71 | if (d != other.d) { |
72 | d = other.d; |
73 | } |
74 | return *this; |
75 | } |
76 | |
77 | bool ObexFileTransferEntry::isValid() const |
78 | { |
79 | return d->m_type != Invalid; |
80 | } |
81 | |
82 | QString ObexFileTransferEntry::name() const |
83 | { |
84 | return d->m_name; |
85 | } |
86 | |
87 | QString ObexFileTransferEntry::label() const |
88 | { |
89 | return d->m_label; |
90 | } |
91 | |
92 | ObexFileTransferEntry::Type ObexFileTransferEntry::type() const |
93 | { |
94 | return d->m_type; |
95 | } |
96 | |
97 | quint64 ObexFileTransferEntry::size() const |
98 | { |
99 | return d->m_size; |
100 | } |
101 | |
102 | QString ObexFileTransferEntry::permissions() const |
103 | { |
104 | return d->m_permissions; |
105 | } |
106 | |
107 | QString ObexFileTransferEntry::memoryType() const |
108 | { |
109 | return d->m_memoryType; |
110 | } |
111 | |
112 | QDateTime ObexFileTransferEntry::modificationTime() const |
113 | { |
114 | return d->m_modified; |
115 | } |
116 | |
117 | } // namespace BluezQt |
118 |