Changeset View
Changeset View
Standalone View
Standalone View
mtp/shared/kmtpfile.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This file is part of the KMTP framework, part of the KDE project. | ||||
3 | | ||||
4 | Copyright (C) 2018 Andreas Krutzler <andreas.krutzler@gmx.net> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Lesser General Public | ||||
8 | License as published by the Free Software Foundation; either | ||||
9 | version 2.1 of the License, or (at your option) version 3, or any | ||||
10 | later version accepted by the membership of KDE e.V. (or its | ||||
11 | successor approved by the membership of KDE e.V.), which shall | ||||
12 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
13 | | ||||
14 | This library is distributed in the hope that it will be useful, | ||||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
17 | Lesser General Public License for more details. | ||||
18 | | ||||
19 | You should have received a copy of the GNU Lesser General Public | ||||
20 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
21 | */ | ||||
22 | | ||||
23 | #include "kmtpfile.h" | ||||
24 | | ||||
25 | KMTPFile::KMTPFile() | ||||
26 | : m_itemId(0), | ||||
27 | m_parentId(0), | ||||
28 | m_storageId(0), | ||||
29 | m_filesize(0), | ||||
30 | m_modificationdate(0) | ||||
31 | { | ||||
32 | } | ||||
33 | | ||||
34 | KMTPFile::KMTPFile(quint32 itemId, | ||||
35 | quint32 parentId, | ||||
36 | quint32 storageId, | ||||
37 | const char *filename, | ||||
38 | quint64 filesize, | ||||
39 | qint64 modificationdate, | ||||
40 | const QString &filetype) | ||||
41 | : m_itemId(itemId), | ||||
42 | m_parentId(parentId), | ||||
43 | m_storageId(storageId), | ||||
44 | m_filename(QString::fromUtf8(filename)), | ||||
45 | m_filesize(filesize), | ||||
46 | m_modificationdate(modificationdate), | ||||
47 | m_filetype(filetype) | ||||
48 | { | ||||
49 | | ||||
50 | } | ||||
51 | | ||||
52 | bool KMTPFile::isValid() const | ||||
53 | { | ||||
54 | return m_itemId != 0; | ||||
55 | } | ||||
56 | | ||||
57 | bool KMTPFile::isFolder() const | ||||
58 | { | ||||
59 | return m_filetype == QLatin1String("inode/directory"); | ||||
60 | } | ||||
61 | | ||||
62 | quint32 KMTPFile::itemId() const | ||||
63 | { | ||||
64 | return m_itemId; | ||||
65 | } | ||||
66 | | ||||
67 | quint32 KMTPFile::parentId() const | ||||
68 | { | ||||
69 | return m_parentId; | ||||
70 | } | ||||
71 | | ||||
72 | quint32 KMTPFile::storageId() const | ||||
73 | { | ||||
74 | return m_storageId; | ||||
75 | } | ||||
76 | | ||||
77 | QString KMTPFile::filename() const | ||||
78 | { | ||||
79 | return m_filename; | ||||
80 | } | ||||
81 | | ||||
82 | quint64 KMTPFile::filesize() const | ||||
83 | { | ||||
84 | return m_filesize; | ||||
85 | } | ||||
86 | | ||||
87 | qint64 KMTPFile::modificationdate() const | ||||
88 | { | ||||
89 | return m_modificationdate; | ||||
90 | } | ||||
91 | | ||||
92 | QString KMTPFile::filetype() const | ||||
93 | { | ||||
94 | return m_filetype; | ||||
95 | } | ||||
96 | | ||||
97 | QDBusArgument &operator<<(QDBusArgument &argument, const KMTPFile &mtpFile) | ||||
98 | { | ||||
99 | argument.beginStructure(); | ||||
100 | argument << mtpFile.m_itemId | ||||
101 | << mtpFile.m_parentId | ||||
102 | << mtpFile.m_storageId | ||||
103 | << mtpFile.m_filename | ||||
104 | << mtpFile.m_filesize | ||||
105 | << mtpFile.m_modificationdate | ||||
106 | << mtpFile.m_filetype; | ||||
107 | argument.endStructure(); | ||||
108 | return argument; | ||||
109 | } | ||||
110 | | ||||
111 | const QDBusArgument &operator>>(const QDBusArgument &argument, KMTPFile &mtpFile) | ||||
112 | { | ||||
113 | argument.beginStructure(); | ||||
114 | argument >> mtpFile.m_itemId | ||||
115 | >> mtpFile.m_parentId | ||||
116 | >> mtpFile.m_storageId | ||||
117 | >> mtpFile.m_filename | ||||
118 | >> mtpFile.m_filesize | ||||
119 | >> mtpFile.m_modificationdate | ||||
120 | >> mtpFile.m_filetype; | ||||
121 | argument.endStructure(); | ||||
122 | return argument; | ||||
123 | } | ||||
124 | | ||||
125 | QDBusArgument &operator<<(QDBusArgument &argument, const KMTPFileList &list) | ||||
126 | { | ||||
127 | argument.beginArray(qMetaTypeId<KMTPFile>()); | ||||
128 | for (const KMTPFile &file : list) { | ||||
129 | argument << file; | ||||
130 | } | ||||
131 | argument.endArray(); | ||||
132 | return argument; | ||||
133 | } | ||||
134 | | ||||
135 | const QDBusArgument &operator>>(const QDBusArgument &argument, KMTPFileList &list) | ||||
136 | { | ||||
137 | argument.beginArray(); | ||||
138 | list.clear(); | ||||
139 | while (!argument.atEnd()) { | ||||
140 | KMTPFile file; | ||||
141 | argument >> file; | ||||
142 | list.append(file); | ||||
143 | } | ||||
144 | | ||||
145 | argument.endArray(); | ||||
146 | return argument; | ||||
147 | } |