Changeset View
Changeset View
Standalone View
Standalone View
src/filescanner.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | #include <Baloo/File> | 32 | #include <Baloo/File> | ||
33 | 33 | | |||
34 | #endif | 34 | #endif | ||
35 | 35 | | |||
36 | #endif | 36 | #endif | ||
37 | 37 | | |||
38 | #include <QFileInfo> | 38 | #include <QFileInfo> | ||
39 | #include <QLocale> | ||||
39 | 40 | | |||
40 | class FileScannerPrivate | 41 | class FileScannerPrivate | ||
41 | { | 42 | { | ||
42 | public: | 43 | public: | ||
43 | 44 | | |||
44 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | 45 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | ||
45 | KFileMetaData::ExtractorCollection mAllExtractors; | 46 | KFileMetaData::ExtractorCollection mAllExtractors; | ||
46 | 47 | | |||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 107 | #else | |||
107 | Q_UNUSED(match) | 108 | Q_UNUSED(match) | ||
108 | Q_UNUSED(trackData) | 109 | Q_UNUSED(trackData) | ||
109 | #endif | 110 | #endif | ||
110 | } | 111 | } | ||
111 | 112 | | |||
112 | void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) | 113 | void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) | ||
113 | { | 114 | { | ||
114 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | 115 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | ||
116 | auto artistString = checkForMultipleEntries(KFileMetaData::Property::Artist); | ||||
117 | auto albumArtistString = checkForMultipleEntries(KFileMetaData::Property::AlbumArtist); | ||||
118 | auto genreString = checkForMultipleEntries(KFileMetaData::Property::Genre); | ||||
119 | auto composerString = checkForMultipleEntries(KFileMetaData::Property::Composer); | ||||
mgallien: There is a typo in the variable name | |||||
120 | auto lyricistString = checkForMultipleEntries(KFileMetaData::Property::Lyricist); | ||||
121 | | ||||
115 | auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); | 122 | auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); | ||
116 | auto durationProperty = d->mAllProperties.find(KFileMetaData::Property::Duration); | 123 | auto durationProperty = d->mAllProperties.find(KFileMetaData::Property::Duration); | ||
117 | auto artistProperty = d->mAllProperties.find(KFileMetaData::Property::Artist); | | |||
118 | auto albumProperty = d->mAllProperties.find(KFileMetaData::Property::Album); | 124 | auto albumProperty = d->mAllProperties.find(KFileMetaData::Property::Album); | ||
119 | auto albumArtistProperty = d->mAllProperties.find(KFileMetaData::Property::AlbumArtist); | | |||
120 | auto trackNumberProperty = d->mAllProperties.find(KFileMetaData::Property::TrackNumber); | 125 | auto trackNumberProperty = d->mAllProperties.find(KFileMetaData::Property::TrackNumber); | ||
121 | auto discNumberProperty = d->mAllProperties.find(KFileMetaData::Property::DiscNumber); | 126 | auto discNumberProperty = d->mAllProperties.find(KFileMetaData::Property::DiscNumber); | ||
122 | auto genreProperty = d->mAllProperties.find(KFileMetaData::Property::Genre); | | |||
123 | auto yearProperty = d->mAllProperties.find(KFileMetaData::Property::ReleaseYear); | 127 | auto yearProperty = d->mAllProperties.find(KFileMetaData::Property::ReleaseYear); | ||
124 | auto composerProperty = d->mAllProperties.find(KFileMetaData::Property::Composer); | | |||
125 | auto lyricistProperty = d->mAllProperties.find(KFileMetaData::Property::Lyricist); | | |||
126 | auto lyricsProperty = d->mAllProperties.find(KFileMetaData::Property::Lyrics); | 128 | auto lyricsProperty = d->mAllProperties.find(KFileMetaData::Property::Lyrics); | ||
127 | auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); | 129 | auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); | ||
128 | auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); | 130 | auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); | ||
129 | auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); | 131 | auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); | ||
130 | auto commentProperty = d->mAllProperties.find(KFileMetaData::Property::Comment); | 132 | auto commentProperty = d->mAllProperties.find(KFileMetaData::Property::Comment); | ||
131 | auto ratingProperty = d->mAllProperties.find(KFileMetaData::Property::Rating); | 133 | auto ratingProperty = d->mAllProperties.find(KFileMetaData::Property::Rating); | ||
132 | #if !defined Q_OS_ANDROID | 134 | #if !defined Q_OS_ANDROID | ||
133 | auto fileData = KFileMetaData::UserMetaData(localFileName); | 135 | auto fileData = KFileMetaData::UserMetaData(localFileName); | ||
134 | #endif | 136 | #endif | ||
135 | 137 | | |||
136 | if (albumProperty != d->mAllProperties.end()) { | 138 | if (!artistString.isEmpty()) { | ||
137 | trackData.setAlbumName(albumProperty->toString()); | 139 | trackData.setArtist(artistString); | ||
140 | } | ||||
141 | | ||||
142 | if (!albumArtistString.isEmpty()) { | ||||
143 | trackData.setAlbumArtist(albumArtistString); | ||||
144 | } | ||||
145 | | ||||
146 | if (genreString.isEmpty()) { | ||||
147 | trackData.setGenre(genreString); | ||||
148 | } | ||||
149 | | ||||
150 | if (composerString.isEmpty()) { | ||||
151 | trackData.setComposer(composerString); | ||||
138 | } | 152 | } | ||
139 | 153 | | |||
140 | if (artistProperty != d->mAllProperties.end()) { | 154 | if (lyricistString.isEmpty()) { | ||
141 | trackData.setArtist(artistProperty->toStringList().join(QStringLiteral(", "))); | 155 | trackData.setLyricist(lyricistString); | ||
156 | } | ||||
157 | | ||||
158 | if (albumProperty != d->mAllProperties.end()) { | ||||
159 | trackData.setAlbumName(albumProperty->toString()); | ||||
142 | } | 160 | } | ||
143 | 161 | | |||
144 | if (durationProperty != d->mAllProperties.end()) { | 162 | if (durationProperty != d->mAllProperties.end()) { | ||
145 | trackData.setDuration(QTime::fromMSecsSinceStartOfDay(int(1000 * durationProperty->toDouble()))); | 163 | trackData.setDuration(QTime::fromMSecsSinceStartOfDay(int(1000 * durationProperty->toDouble()))); | ||
146 | } | 164 | } | ||
147 | 165 | | |||
148 | if (titleProperty != d->mAllProperties.end()) { | 166 | if (titleProperty != d->mAllProperties.end()) { | ||
149 | trackData.setTitle(titleProperty->toString()); | 167 | trackData.setTitle(titleProperty->toString()); | ||
150 | } | 168 | } | ||
151 | 169 | | |||
152 | if (trackNumberProperty != d->mAllProperties.end()) { | 170 | if (trackNumberProperty != d->mAllProperties.end()) { | ||
153 | trackData.setTrackNumber(trackNumberProperty->toInt()); | 171 | trackData.setTrackNumber(trackNumberProperty->toInt()); | ||
154 | } | 172 | } | ||
155 | 173 | | |||
156 | if (discNumberProperty != d->mAllProperties.end()) { | 174 | if (discNumberProperty != d->mAllProperties.end()) { | ||
157 | trackData.setDiscNumber(discNumberProperty->toInt()); | 175 | trackData.setDiscNumber(discNumberProperty->toInt()); | ||
158 | } | 176 | } | ||
159 | 177 | | |||
160 | if (albumArtistProperty != d->mAllProperties.end()) { | | |||
161 | trackData.setAlbumArtist(albumArtistProperty->toStringList().join(QStringLiteral(", "))); | | |||
162 | } | | |||
163 | | ||||
164 | if (yearProperty != d->mAllProperties.end()) { | 178 | if (yearProperty != d->mAllProperties.end()) { | ||
165 | trackData.setYear(yearProperty->toInt()); | 179 | trackData.setYear(yearProperty->toInt()); | ||
166 | } | 180 | } | ||
167 | 181 | | |||
168 | if (channelsProperty != d->mAllProperties.end()) { | 182 | if (channelsProperty != d->mAllProperties.end()) { | ||
169 | trackData.setChannels(channelsProperty->toInt()); | 183 | trackData.setChannels(channelsProperty->toInt()); | ||
170 | } | 184 | } | ||
171 | 185 | | |||
172 | if (bitRateProperty != d->mAllProperties.end()) { | 186 | if (bitRateProperty != d->mAllProperties.end()) { | ||
173 | trackData.setBitRate(bitRateProperty->toInt()); | 187 | trackData.setBitRate(bitRateProperty->toInt()); | ||
174 | } | 188 | } | ||
175 | 189 | | |||
176 | if (sampleRateProperty != d->mAllProperties.end()) { | 190 | if (sampleRateProperty != d->mAllProperties.end()) { | ||
177 | trackData.setSampleRate(sampleRateProperty->toInt()); | 191 | trackData.setSampleRate(sampleRateProperty->toInt()); | ||
178 | } | 192 | } | ||
179 | 193 | | |||
194 | <<<<<<< HEAD | ||||
180 | if (genreProperty != d->mAllProperties.end()) { | 195 | if (genreProperty != d->mAllProperties.end()) { | ||
181 | trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); | 196 | trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); | ||
182 | } | 197 | } | ||
183 | 198 | | |||
184 | if (composerProperty != d->mAllProperties.end()) { | 199 | if (composerProperty != d->mAllProperties.end()) { | ||
185 | trackData.setComposer(composerProperty->toStringList().join(QStringLiteral(", "))); | 200 | trackData.setComposer(composerProperty->toStringList().join(QStringLiteral(", "))); | ||
186 | } | 201 | } | ||
187 | 202 | | |||
188 | if (lyricistProperty != d->mAllProperties.end()) { | 203 | if (lyricistProperty != d->mAllProperties.end()) { | ||
189 | trackData.setLyricist(lyricistProperty->toStringList().join(QStringLiteral(", "))); | 204 | trackData.setLyricist(lyricistProperty->toStringList().join(QStringLiteral(", "))); | ||
190 | } | 205 | } | ||
191 | 206 | | |||
192 | if (lyricsProperty != d->mAllProperties.end()) { | 207 | if (lyricsProperty != d->mAllProperties.end()) { | ||
193 | trackData.setLyrics(lyricsProperty->toString()); | 208 | trackData.setLyrics(lyricsProperty->toString()); | ||
194 | } | 209 | } | ||
195 | 210 | | |||
211 | ======= | ||||
212 | >>>>>>> Check for string lists and multi-values in property map | ||||
196 | if (trackData.artist().isEmpty()) { | 213 | if (trackData.artist().isEmpty()) { | ||
197 | trackData.setArtist(trackData.albumArtist()); | 214 | trackData.setArtist(trackData.albumArtist()); | ||
198 | } | 215 | } | ||
199 | 216 | | |||
200 | #if !defined Q_OS_ANDROID | 217 | #if !defined Q_OS_ANDROID | ||
201 | QString comment = fileData.userComment(); | 218 | QString comment = fileData.userComment(); | ||
202 | if (!comment.isEmpty()) { | 219 | if (!comment.isEmpty()) { | ||
203 | trackData.setComment(comment); | 220 | trackData.setComment(comment); | ||
Show All 26 Lines | 243 | #endif | |||
230 | } | 247 | } | ||
231 | 248 | | |||
232 | trackData.setValid(true); | 249 | trackData.setValid(true); | ||
233 | #else | 250 | #else | ||
234 | Q_UNUSED(localFileName) | 251 | Q_UNUSED(localFileName) | ||
235 | Q_UNUSED(trackData) | 252 | Q_UNUSED(trackData) | ||
236 | #endif | 253 | #endif | ||
237 | } | 254 | } | ||
255 | | ||||
256 | QString FileScanner::checkForMultipleEntries(KFileMetaData::Property::Property property) | ||||
257 | { | ||||
258 | if (d->mAllProperties.count(property) > 1) { | ||||
I am afraid that for most cases the concerned properties will be single valued and this code path will be slower than previous code. mgallien: I am afraid that for most cases the concerned properties will be single valued and this code… | |||||
259 | auto propertyList = d->mAllProperties.values(property); | ||||
260 | return QLocale().createSeparatedList(QVariant(propertyList).toStringList()); | ||||
261 | } else { | ||||
262 | auto variantResult = d->mAllProperties.find(property); | ||||
263 | if (variantResult != d->mAllProperties.end()) { | ||||
264 | auto value = variantResult.value(); | ||||
265 | if (value.type() == QVariant::List || value.type() == QVariant::StringList) { | ||||
266 | return QLocale().createSeparatedList(value.toStringList()); | ||||
267 | } else { | ||||
268 | return value.toString(); | ||||
269 | } | ||||
270 | } else { | ||||
271 | return QString(); | ||||
272 | } | ||||
273 | } | ||||
274 | } |
There is a typo in the variable name