Changeset View
Changeset View
Standalone View
Standalone View
src/filescanner.cpp
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 106 | #else | |||
---|---|---|---|---|---|
107 | Q_UNUSED(match) | 107 | Q_UNUSED(match) | ||
108 | Q_UNUSED(trackData) | 108 | Q_UNUSED(trackData) | ||
109 | #endif | 109 | #endif | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) | 112 | void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) | ||
113 | { | 113 | { | ||
114 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | 114 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | ||
115 | auto artistString = checkForMultipleEntries(KFileMetaData::Property::Artist); | ||||
116 | auto albumArtistString = checkForMultipleEntries(KFileMetaData::Property::AlbumArtist); | ||||
117 | auto genreString = checkForMultipleEntries(KFileMetaData::Property::Genre); | ||||
118 | auto copmoserString = checkForMultipleEntries(KFileMetaData::Property::Composer); | ||||
mgallien: There is a typo in the variable name | |||||
119 | auto lyricistString = checkForMultipleEntries(KFileMetaData::Property::Lyricist); | ||||
120 | | ||||
115 | auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); | 121 | auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); | ||
116 | auto durationProperty = d->mAllProperties.find(KFileMetaData::Property::Duration); | 122 | 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); | 123 | 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); | 124 | auto trackNumberProperty = d->mAllProperties.find(KFileMetaData::Property::TrackNumber); | ||
121 | auto discNumberProperty = d->mAllProperties.find(KFileMetaData::Property::DiscNumber); | 125 | 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); | 126 | 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 channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); | 127 | auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); | ||
127 | auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); | 128 | auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); | ||
128 | auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); | 129 | auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); | ||
129 | auto commentProperty = d->mAllProperties.find(KFileMetaData::Property::Comment); | 130 | auto commentProperty = d->mAllProperties.find(KFileMetaData::Property::Comment); | ||
130 | auto ratingProperty = d->mAllProperties.find(KFileMetaData::Property::Rating); | 131 | auto ratingProperty = d->mAllProperties.find(KFileMetaData::Property::Rating); | ||
131 | #if !defined Q_OS_ANDROID | 132 | #if !defined Q_OS_ANDROID | ||
132 | auto fileData = KFileMetaData::UserMetaData(localFileName); | 133 | auto fileData = KFileMetaData::UserMetaData(localFileName); | ||
133 | #endif | 134 | #endif | ||
134 | 135 | | |||
135 | if (albumProperty != d->mAllProperties.end()) { | 136 | if (!artistString.isEmpty()) { | ||
136 | trackData.setAlbumName(albumProperty->toString()); | 137 | trackData.setArtist(artistString); | ||
138 | } | ||||
139 | | ||||
140 | if (!albumArtistString.isEmpty()) { | ||||
141 | trackData.setAlbumArtist(albumArtistString); | ||||
142 | } | ||||
143 | | ||||
144 | if (genreString.isEmpty()) { | ||||
145 | trackData.setGenre(genreString); | ||||
137 | } | 146 | } | ||
138 | 147 | | |||
139 | if (artistProperty != d->mAllProperties.end()) { | 148 | if (copmoserString.isEmpty()) { | ||
140 | trackData.setArtist(artistProperty->toStringList().join(QStringLiteral(", "))); | 149 | trackData.setComposer(copmoserString); | ||
150 | } | ||||
151 | | ||||
152 | if (lyricistString.isEmpty()) { | ||||
153 | trackData.setLyricist(lyricistString); | ||||
154 | } | ||||
155 | | ||||
156 | if (albumProperty != d->mAllProperties.end()) { | ||||
157 | trackData.setAlbumName(albumProperty->toString()); | ||||
141 | } | 158 | } | ||
142 | 159 | | |||
143 | if (durationProperty != d->mAllProperties.end()) { | 160 | if (durationProperty != d->mAllProperties.end()) { | ||
144 | trackData.setDuration(QTime::fromMSecsSinceStartOfDay(int(1000 * durationProperty->toDouble()))); | 161 | trackData.setDuration(QTime::fromMSecsSinceStartOfDay(int(1000 * durationProperty->toDouble()))); | ||
145 | } | 162 | } | ||
146 | 163 | | |||
147 | if (titleProperty != d->mAllProperties.end()) { | 164 | if (titleProperty != d->mAllProperties.end()) { | ||
148 | trackData.setTitle(titleProperty->toString()); | 165 | trackData.setTitle(titleProperty->toString()); | ||
149 | } | 166 | } | ||
150 | 167 | | |||
151 | if (trackNumberProperty != d->mAllProperties.end()) { | 168 | if (trackNumberProperty != d->mAllProperties.end()) { | ||
152 | trackData.setTrackNumber(trackNumberProperty->toInt()); | 169 | trackData.setTrackNumber(trackNumberProperty->toInt()); | ||
153 | } | 170 | } | ||
154 | 171 | | |||
155 | if (discNumberProperty != d->mAllProperties.end()) { | 172 | if (discNumberProperty != d->mAllProperties.end()) { | ||
156 | trackData.setDiscNumber(discNumberProperty->toInt()); | 173 | trackData.setDiscNumber(discNumberProperty->toInt()); | ||
157 | } else { | 174 | } else { | ||
158 | trackData.setDiscNumber(1); | 175 | trackData.setDiscNumber(1); | ||
159 | } | 176 | } | ||
160 | 177 | | |||
161 | if (albumArtistProperty != d->mAllProperties.end()) { | | |||
162 | trackData.setAlbumArtist(albumArtistProperty->toStringList().join(QStringLiteral(", "))); | | |||
163 | } | | |||
164 | | ||||
165 | if (yearProperty != d->mAllProperties.end()) { | 178 | if (yearProperty != d->mAllProperties.end()) { | ||
166 | trackData.setYear(yearProperty->toInt()); | 179 | trackData.setYear(yearProperty->toInt()); | ||
167 | } | 180 | } | ||
168 | 181 | | |||
169 | if (channelsProperty != d->mAllProperties.end()) { | 182 | if (channelsProperty != d->mAllProperties.end()) { | ||
170 | trackData.setChannels(channelsProperty->toInt()); | 183 | trackData.setChannels(channelsProperty->toInt()); | ||
171 | } | 184 | } | ||
172 | 185 | | |||
173 | if (bitRateProperty != d->mAllProperties.end()) { | 186 | if (bitRateProperty != d->mAllProperties.end()) { | ||
174 | trackData.setBitRate(bitRateProperty->toInt()); | 187 | trackData.setBitRate(bitRateProperty->toInt()); | ||
175 | } | 188 | } | ||
176 | 189 | | |||
177 | if (sampleRateProperty != d->mAllProperties.end()) { | 190 | if (sampleRateProperty != d->mAllProperties.end()) { | ||
178 | trackData.setSampleRate(sampleRateProperty->toInt()); | 191 | trackData.setSampleRate(sampleRateProperty->toInt()); | ||
179 | } | 192 | } | ||
180 | 193 | | |||
181 | if (genreProperty != d->mAllProperties.end()) { | | |||
182 | trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); | | |||
183 | } | | |||
184 | | ||||
185 | if (composerProperty != d->mAllProperties.end()) { | | |||
186 | trackData.setComposer(composerProperty->toStringList().join(QStringLiteral(", "))); | | |||
187 | } | | |||
188 | | ||||
189 | if (lyricistProperty != d->mAllProperties.end()) { | | |||
190 | trackData.setLyricist(lyricistProperty->toStringList().join(QStringLiteral(", "))); | | |||
191 | } | | |||
192 | | ||||
193 | if (trackData.artist().isEmpty()) { | 194 | if (trackData.artist().isEmpty()) { | ||
194 | trackData.setArtist(trackData.albumArtist()); | 195 | trackData.setArtist(trackData.albumArtist()); | ||
195 | } | 196 | } | ||
196 | 197 | | |||
197 | #if !defined Q_OS_ANDROID | 198 | #if !defined Q_OS_ANDROID | ||
198 | QString comment = fileData.userComment(); | 199 | QString comment = fileData.userComment(); | ||
199 | if (!comment.isEmpty()) { | 200 | if (!comment.isEmpty()) { | ||
200 | trackData.setComment(comment); | 201 | trackData.setComment(comment); | ||
Show All 26 Lines | 224 | #endif | |||
227 | } | 228 | } | ||
228 | 229 | | |||
229 | trackData.setValid(true); | 230 | trackData.setValid(true); | ||
230 | #else | 231 | #else | ||
231 | Q_UNUSED(localFileName) | 232 | Q_UNUSED(localFileName) | ||
232 | Q_UNUSED(trackData) | 233 | Q_UNUSED(trackData) | ||
233 | #endif | 234 | #endif | ||
234 | } | 235 | } | ||
236 | | ||||
237 | | ||||
238 | QString FileScanner::checkForMultipleEntries(KFileMetaData::Property::Property property) | ||||
239 | { | ||||
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… | |||||
240 | QVariantList propertyList = d->mAllProperties.values(property); | ||||
241 | if (propertyList.isEmpty()) { | ||||
242 | return QString(); | ||||
243 | } | ||||
244 | if (propertyList.first().type() == QVariant::List || propertyList.first().type() == QVariant::StringList) { | ||||
245 | return propertyList.first().toStringList().join(QStringLiteral(", ")); | ||||
246 | } else { | ||||
247 | return QVariant(propertyList).toStringList().join(QStringLiteral(", ")); | ||||
248 | } | ||||
249 | } |
There is a typo in the variable name