Changeset View
Changeset View
Standalone View
Standalone View
src/filemetadataprovider.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | 159 | { | |||
---|---|---|---|---|---|
161 | // not work, the modification date needs also to be adjusted... | 161 | // not work, the modification date needs also to be adjusted... | ||
162 | Q_ASSERT(m_fileItems.count() <= 1); | 162 | Q_ASSERT(m_fileItems.count() <= 1); | ||
163 | if (m_fileItems.count() == 1) { | 163 | if (m_fileItems.count() == 1) { | ||
164 | const KFileItem& item = m_fileItems.first(); | 164 | const KFileItem& item = m_fileItems.first(); | ||
165 | 165 | | |||
166 | if (item.isDir()) { | 166 | if (item.isDir()) { | ||
167 | const int count = subDirectoriesCount(item.url().path()); | 167 | const int count = subDirectoriesCount(item.url().path()); | ||
168 | if (count == -1) { | 168 | if (count == -1) { | ||
169 | m_data.insert("kfileitem#size", i18nc("unknown file size", "Unknown")); | 169 | m_data.insert(QStringLiteral("kfileitem#size"), i18nc("unknown file size", "Unknown")); | ||
170 | } else { | 170 | } else { | ||
171 | const QString itemCountString = i18ncp("@item:intable", "%1 item", "%1 items", count); | 171 | const QString itemCountString = i18ncp("@item:intable", "%1 item", "%1 items", count); | ||
172 | m_data.insert("kfileitem#size", itemCountString); | 172 | m_data.insert(QStringLiteral("kfileitem#size"), itemCountString); | ||
173 | } | 173 | } | ||
174 | } else { | 174 | } else { | ||
175 | KFormat format; | 175 | KFormat format; | ||
176 | m_data.insert("kfileitem#size", format.formatByteSize(item.size())); | 176 | m_data.insert(QStringLiteral("kfileitem#size"), format.formatByteSize(item.size())); | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | m_data.insert("kfileitem#type", item.mimeComment()); | 179 | m_data.insert(QStringLiteral("kfileitem#type"), item.mimeComment()); | ||
180 | m_data.insert("kfileitem#modified", item.time(KFileItem::ModificationTime)); | 180 | m_data.insert(QStringLiteral("kfileitem#modified"), item.time(KFileItem::ModificationTime)); | ||
181 | QDateTime creationTime = item.time(KFileItem::CreationTime); | 181 | QDateTime creationTime = item.time(KFileItem::CreationTime); | ||
182 | if (creationTime.isValid()) { | 182 | if (creationTime.isValid()) { | ||
183 | m_data.insert("kfileitem#created", creationTime); | 183 | m_data.insert(QStringLiteral("kfileitem#created"), creationTime); | ||
184 | } | 184 | } | ||
185 | m_data.insert("kfileitem#accessed", item.time(KFileItem::AccessTime)); | 185 | m_data.insert(QStringLiteral("kfileitem#accessed"), item.time(KFileItem::AccessTime)); | ||
186 | m_data.insert("kfileitem#owner", item.user()); | 186 | m_data.insert(QStringLiteral("kfileitem#owner"), item.user()); | ||
187 | m_data.insert("kfileitem#group", item.group()); | 187 | m_data.insert(QStringLiteral("kfileitem#group"), item.group()); | ||
188 | m_data.insert("kfileitem#permissions", item.permissionsString()); | 188 | m_data.insert(QStringLiteral("kfileitem#permissions"), item.permissionsString()); | ||
189 | } | 189 | } | ||
190 | } | 190 | } | ||
191 | 191 | | |||
192 | void FileMetaDataProvider::insertFilesListBasicData() | 192 | void FileMetaDataProvider::insertFilesListBasicData() | ||
193 | { | 193 | { | ||
194 | // If all directories | 194 | // If all directories | ||
195 | Q_ASSERT(m_fileItems.count() > 1); | 195 | Q_ASSERT(m_fileItems.count() > 1); | ||
196 | bool allDirectories = true; | 196 | bool allDirectories = true; | ||
197 | for (const KFileItem& item : qAsConst(m_fileItems)) { | 197 | for (const KFileItem& item : qAsConst(m_fileItems)) { | ||
198 | allDirectories &= item.isDir(); | 198 | allDirectories &= item.isDir(); | ||
199 | if (!allDirectories) { | 199 | if (!allDirectories) { | ||
200 | break; | 200 | break; | ||
201 | } | 201 | } | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | if (allDirectories) { | 204 | if (allDirectories) { | ||
205 | int count = 0; | 205 | int count = 0; | ||
206 | for (const KFileItem& item : qAsConst(m_fileItems)) { | 206 | for (const KFileItem& item : qAsConst(m_fileItems)) { | ||
207 | count += subDirectoriesCount(item.url().path()); | 207 | count += subDirectoriesCount(item.url().path()); | ||
208 | } | 208 | } | ||
209 | const QString itemCountString = i18ncp("@item:intable", "%1 item", "%1 items", count); | 209 | const QString itemCountString = i18ncp("@item:intable", "%1 item", "%1 items", count); | ||
210 | m_data.insert("kfileitem#totalSize", itemCountString); | 210 | m_data.insert(QStringLiteral("kfileitem#totalSize"), itemCountString); | ||
211 | 211 | | |||
212 | } else { | 212 | } else { | ||
213 | // Calculate the size of all items | 213 | // Calculate the size of all items | ||
214 | quint64 totalSize = 0; | 214 | quint64 totalSize = 0; | ||
215 | for (const KFileItem& item : qAsConst(m_fileItems)) { | 215 | for (const KFileItem& item : qAsConst(m_fileItems)) { | ||
216 | if (!item.isDir() && !item.isLink()) { | 216 | if (!item.isDir() && !item.isLink()) { | ||
217 | totalSize += item.size(); | 217 | totalSize += item.size(); | ||
218 | } | 218 | } | ||
219 | } | 219 | } | ||
220 | KFormat format; | 220 | KFormat format; | ||
221 | m_data.insert("kfileitem#totalSize", format.formatByteSize(totalSize)); | 221 | m_data.insert(QStringLiteral("kfileitem#totalSize"), format.formatByteSize(totalSize)); | ||
222 | } | 222 | } | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | void FileMetaDataProvider::insertEditableData() | 225 | void FileMetaDataProvider::insertEditableData() | ||
226 | { | 226 | { | ||
227 | if (!m_readOnly) { | 227 | if (!m_readOnly) { | ||
228 | if (!m_data.contains("tags")) { | 228 | if (!m_data.contains(QStringLiteral("tags"))) { | ||
229 | m_data.insert("tags", QVariant()); | 229 | m_data.insert(QStringLiteral("tags"), QVariant()); | ||
230 | } | 230 | } | ||
231 | if (!m_data.contains("rating")) { | 231 | if (!m_data.contains(QStringLiteral("rating"))) { | ||
232 | m_data.insert("rating", 0); | 232 | m_data.insert(QStringLiteral("rating"), 0); | ||
233 | } | 233 | } | ||
234 | if (!m_data.contains("userComment")) { | 234 | if (!m_data.contains(QStringLiteral("userComment"))) { | ||
235 | m_data.insert("userComment", QVariant()); | 235 | m_data.insert(QStringLiteral("userComment"), QVariant()); | ||
236 | } | 236 | } | ||
237 | } | 237 | } | ||
238 | } | 238 | } | ||
239 | 239 | | |||
240 | void FileMetaDataProvider::insertCommonData(const QList<QVariantMap>& files) | 240 | void FileMetaDataProvider::insertCommonData(const QList<QVariantMap>& files) | ||
241 | { | 241 | { | ||
242 | // | 242 | // | ||
243 | // Only report the stuff that is common to all the files | 243 | // Only report the stuff that is common to all the files | ||
244 | // | 244 | // | ||
245 | QSet<QString> allProperties; | 245 | QSet<QString> allProperties; | ||
246 | QList<QVariantMap> propertyList; | 246 | QList<QVariantMap> propertyList; | ||
247 | foreach (const QVariantMap& fileData, files) { | 247 | foreach (const QVariantMap& fileData, files) { | ||
248 | propertyList << fileData; | 248 | propertyList << fileData; | ||
249 | allProperties.unite(fileData.uniqueKeys().toSet()); | 249 | allProperties.unite(fileData.uniqueKeys().toSet()); | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | // Special handling for certain properties | 252 | // Special handling for certain properties | ||
253 | totalPropertyAndInsert("duration", propertyList, allProperties); | 253 | totalPropertyAndInsert(QStringLiteral("duration"), propertyList, allProperties); | ||
254 | totalPropertyAndInsert("characterCount", propertyList, allProperties); | 254 | totalPropertyAndInsert(QStringLiteral("characterCount"), propertyList, allProperties); | ||
255 | totalPropertyAndInsert("wordCount", propertyList, allProperties); | 255 | totalPropertyAndInsert(QStringLiteral("wordCount"), propertyList, allProperties); | ||
256 | totalPropertyAndInsert("lineCount", propertyList, allProperties); | 256 | totalPropertyAndInsert(QStringLiteral("lineCount"), propertyList, allProperties); | ||
257 | 257 | | |||
258 | foreach (const QString& propUri, allProperties) { | 258 | foreach (const QString& propUri, allProperties) { | ||
259 | foreach (const QVariantMap& map, propertyList) { | 259 | foreach (const QVariantMap& map, propertyList) { | ||
260 | QVariantMap::const_iterator it = map.find(propUri); | 260 | QVariantMap::const_iterator it = map.find(propUri); | ||
261 | if (it == map.constEnd()) { | 261 | if (it == map.constEnd()) { | ||
262 | m_data.remove(propUri); | 262 | m_data.remove(propUri); | ||
263 | break; | 263 | break; | ||
264 | } | 264 | } | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 372 | } else if (items.size() == 1) { | |||
373 | setFileItem(); | 373 | setFileItem(); | ||
374 | } else { | 374 | } else { | ||
375 | setFileItems(); | 375 | setFileItems(); | ||
376 | } | 376 | } | ||
377 | } | 377 | } | ||
378 | 378 | | |||
379 | QString FileMetaDataProvider::label(const QString& metaDataLabel) const | 379 | QString FileMetaDataProvider::label(const QString& metaDataLabel) const | ||
380 | { | 380 | { | ||
381 | struct TranslationItem { | 381 | static QHash<QString, QString> hash = { | ||
382 | const char* const key; | 382 | { QStringLiteral("kfileitem#comment"), i18nc("@label", "Comment") }, | ||
383 | const char* const context; | 383 | { QStringLiteral("kfileitem#created"), i18nc("@label", "Created") }, | ||
384 | const char* const value; | 384 | { QStringLiteral("kfileitem#accessed"), i18nc("@label", "Accessed") }, | ||
385 | { QStringLiteral("kfileitem#modified"), i18nc("@label", "Modified") }, | ||||
386 | { QStringLiteral("kfileitem#owner"), i18nc("@label", "Owner") }, | ||||
387 | { QStringLiteral("kfileitem#group"), i18nc("@label", "Group") }, | ||||
388 | { QStringLiteral("kfileitem#permissions"), i18nc("@label", "Permissions") }, | ||||
389 | { QStringLiteral("kfileitem#rating"), i18nc("@label", "Rating") }, | ||||
390 | { QStringLiteral("kfileitem#size"), i18nc("@label", "Size") }, | ||||
391 | { QStringLiteral("kfileitem#tags"), i18nc("@label", "Tags") }, | ||||
392 | { QStringLiteral("kfileitem#totalSize"), i18nc("@label", "Total Size") }, | ||||
393 | { QStringLiteral("kfileitem#type"), i18nc("@label", "Type") }, | ||||
394 | { QStringLiteral("tags"), i18nc("@label", "Tags") }, | ||||
395 | { QStringLiteral("rating"), i18nc("@label", "Rating") }, | ||||
396 | { QStringLiteral("userComment"), i18nc("@label", "Comment") }, | ||||
397 | { QStringLiteral("originUrl"), i18nc("@label", "Downloaded From") }, | ||||
385 | }; | 398 | }; | ||
386 | 399 | | |||
387 | static const TranslationItem translations[] = { | | |||
388 | { "kfileitem#comment", I18N_NOOP2_NOSTRIP("@label", "Comment") }, | | |||
389 | { "kfileitem#created", I18N_NOOP2_NOSTRIP("@label", "Created") }, | | |||
390 | { "kfileitem#accessed", I18N_NOOP2_NOSTRIP("@label", "Accessed") }, | | |||
391 | { "kfileitem#modified", I18N_NOOP2_NOSTRIP("@label", "Modified") }, | | |||
392 | { "kfileitem#owner", I18N_NOOP2_NOSTRIP("@label", "Owner") }, | | |||
393 | { "kfileitem#group", I18N_NOOP2_NOSTRIP("@label", "Group") }, | | |||
394 | { "kfileitem#permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions") }, | | |||
395 | { "kfileitem#rating", I18N_NOOP2_NOSTRIP("@label", "Rating") }, | | |||
396 | { "kfileitem#size", I18N_NOOP2_NOSTRIP("@label", "Size") }, | | |||
397 | { "kfileitem#tags", I18N_NOOP2_NOSTRIP("@label", "Tags") }, | | |||
398 | { "kfileitem#totalSize", I18N_NOOP2_NOSTRIP("@label", "Total Size") }, | | |||
399 | { "kfileitem#type", I18N_NOOP2_NOSTRIP("@label", "Type") }, | | |||
400 | { "tags", I18N_NOOP2_NOSTRIP("@label", "Tags") }, | | |||
401 | { "rating", I18N_NOOP2_NOSTRIP("@label", "Rating") }, | | |||
402 | { "userComment", I18N_NOOP2_NOSTRIP("@label", "Comment") }, | | |||
403 | { "originUrl", I18N_NOOP2_NOSTRIP("@label", "Downloaded From") }, | | |||
404 | { nullptr, nullptr, nullptr} // Mandatory last entry | | |||
405 | }; | | |||
406 | | ||||
407 | static QHash<QString, QString> hash; | | |||
408 | if (hash.isEmpty()) { | | |||
409 | const TranslationItem* item = &translations[0]; | | |||
410 | while (item->key != nullptr) { | | |||
411 | hash.insert(item->key, i18nc(item->context, item->value)); | | |||
412 | ++item; | | |||
413 | } | | |||
414 | } | | |||
415 | | ||||
416 | QString value = hash.value(metaDataLabel); | 400 | QString value = hash.value(metaDataLabel); | ||
417 | if (value.isEmpty()) { | 401 | if (value.isEmpty()) { | ||
418 | value = KFileMetaData::PropertyInfo::fromName(metaDataLabel).displayName(); | 402 | value = KFileMetaData::PropertyInfo::fromName(metaDataLabel).displayName(); | ||
419 | } | 403 | } | ||
420 | 404 | | |||
421 | return value; | 405 | return value; | ||
422 | } | 406 | } | ||
423 | 407 | | |||
424 | QString FileMetaDataProvider::group(const QString& label) const | 408 | QString FileMetaDataProvider::group(const QString& label) const | ||
425 | { | 409 | { | ||
426 | static QHash<QString, QString> uriGrouper; | 410 | static QHash<QString, QString> uriGrouper = { | ||
427 | if (uriGrouper.isEmpty()) { | 411 | | ||
bruns: You can use an initializer list here, like in `FileMetaDataProvider::label(...)` | |||||
428 | // KFileItem Data | 412 | // KFileItem Data | ||
429 | uriGrouper.insert(QLatin1String("kfileitem#type"), QLatin1String("0FileItemA")); | 413 | { QStringLiteral("kfileitem#type"), QStringLiteral("0FileItemA") }, | ||
430 | uriGrouper.insert(QLatin1String("kfileitem#size"), QLatin1String("0FileItemB")); | 414 | { QStringLiteral("kfileitem#size"), QStringLiteral("0FileItemB") }, | ||
431 | uriGrouper.insert(QLatin1String("kfileitem#totalSize"), QLatin1String("0FileItemB")); | 415 | { QStringLiteral("kfileitem#totalSize"), QStringLiteral("0FileItemB") }, | ||
432 | uriGrouper.insert(QLatin1String("kfileitem#modified"), QLatin1String("0FileItemC")); | 416 | { QStringLiteral("kfileitem#modified"), QStringLiteral("0FileItemC") }, | ||
433 | uriGrouper.insert(QLatin1String("kfileitem#accessed"), QLatin1String("0FileItemD")); | 417 | { QStringLiteral("kfileitem#accessed"), QStringLiteral("0FileItemD") }, | ||
434 | uriGrouper.insert(QLatin1String("kfileitem#created"), QLatin1String("0FileItemE")); | 418 | { QStringLiteral("kfileitem#created"), QStringLiteral("0FileItemE") }, | ||
435 | uriGrouper.insert(QLatin1String("kfileitem#owner"), QLatin1String("0FileItemF")); | 419 | { QStringLiteral("kfileitem#owner"), QStringLiteral("0FileItemF") }, | ||
436 | uriGrouper.insert(QLatin1String("kfileitem#group"), QLatin1String("0FileItemG")); | 420 | { QStringLiteral("kfileitem#group"), QStringLiteral("0FileItemG") }, | ||
437 | uriGrouper.insert(QLatin1String("kfileitem#permissions"), QLatin1String("0FileItemH")); | 421 | { QStringLiteral("kfileitem#permissions"), QStringLiteral("0FileItemH") }, | ||
438 | 422 | | |||
439 | // Editable Data | 423 | // Editable Data | ||
440 | uriGrouper.insert(QLatin1String("tags"), QLatin1String("1EditableDataA")); | 424 | { QStringLiteral("tags"), QStringLiteral("1EditableDataA") }, | ||
441 | uriGrouper.insert(QLatin1String("rating"), QLatin1String("1EditableDataB")); | 425 | { QStringLiteral("rating"), QStringLiteral("1EditableDataB") }, | ||
442 | uriGrouper.insert(QLatin1String("userComment"), QLatin1String("1EditableDataC")); | 426 | { QStringLiteral("userComment"), QStringLiteral("1EditableDataC") }, | ||
443 | 427 | | |||
444 | // Image Data | 428 | // Image Data | ||
445 | uriGrouper.insert(QLatin1String("width"), QLatin1String("2ImageA")); | 429 | { QStringLiteral("width"), QStringLiteral("2ImageA") }, | ||
446 | uriGrouper.insert(QLatin1String("height"), QLatin1String("2ImageB")); | 430 | { QStringLiteral("height"), QStringLiteral("2ImageB") }, | ||
447 | uriGrouper.insert(QLatin1String("photoFNumber"), QLatin1String("2ImageC")); | 431 | { QStringLiteral("photoFNumber"), QStringLiteral("2ImageC") }, | ||
448 | uriGrouper.insert(QLatin1String("photoExposureTime"), QLatin1String("2ImageD")); | 432 | { QStringLiteral("photoExposureTime"), QStringLiteral("2ImageD") }, | ||
449 | uriGrouper.insert(QLatin1String("photoExposureBiasValue"), QLatin1String("2ImageE")); | 433 | { QStringLiteral("photoExposureBiasValue"), QStringLiteral("2ImageE") }, | ||
450 | uriGrouper.insert(QLatin1String("photoISOSpeedRatings"), QLatin1String("2ImageF")); | 434 | { QStringLiteral("photoISOSpeedRatings"), QStringLiteral("2ImageF") }, | ||
451 | uriGrouper.insert(QLatin1String("photoFocalLength"), QLatin1String("2ImageG")); | 435 | { QStringLiteral("photoFocalLength"), QStringLiteral("2ImageG") }, | ||
452 | uriGrouper.insert(QLatin1String("photoFocalLengthIn35mmFilm"), QLatin1String("2ImageH")); | 436 | { QStringLiteral("photoFocalLengthIn35mmFilm"), QStringLiteral("2ImageH") }, | ||
453 | uriGrouper.insert(QLatin1String("photoFlash"), QLatin1String("2ImageI")); | 437 | { QStringLiteral("photoFlash"), QStringLiteral("2ImageI") }, | ||
454 | uriGrouper.insert(QLatin1String("imageOrientation"), QLatin1String("2ImageJ")); | 438 | { QStringLiteral("imageOrientation"), QStringLiteral("2ImageJ") }, | ||
455 | uriGrouper.insert(QLatin1String("photoGpsLatitude"), QLatin1String("2ImageK")); | 439 | { QStringLiteral("photoGpsLatitude"), QStringLiteral("2ImageK") }, | ||
456 | uriGrouper.insert(QLatin1String("photoGpsLongitude"), QLatin1String("2ImageL")); | 440 | { QStringLiteral("photoGpsLongitude"), QStringLiteral("2ImageL") }, | ||
457 | uriGrouper.insert(QLatin1String("photoGpsAltitude"), QLatin1String("2ImageM")); | 441 | { QStringLiteral("photoGpsAltitude"), QStringLiteral("2ImageM") }, | ||
458 | uriGrouper.insert(QLatin1String("manufacturer"), QLatin1String("2ImageN")); | 442 | { QStringLiteral("manufacturer"), QStringLiteral("2ImageN") }, | ||
459 | uriGrouper.insert(QLatin1String("model"), QLatin1String("2ImageO")); | 443 | { QStringLiteral("model"), QStringLiteral("2ImageO") }, | ||
460 | 444 | | |||
461 | // Media Data | 445 | // Media Data | ||
462 | uriGrouper.insert("title", QLatin1String("3MediaA")); | 446 | { QStringLiteral("title"), QStringLiteral("3MediaA") }, | ||
463 | uriGrouper.insert("artist", QLatin1String("3MediaB")); | 447 | { QStringLiteral("artist"), QStringLiteral("3MediaB") }, | ||
464 | uriGrouper.insert("album", QLatin1String("3MediaC")); | 448 | { QStringLiteral("album"), QStringLiteral("3MediaC") }, | ||
465 | uriGrouper.insert("albumArtist", QLatin1String("3MediaD")); | 449 | { QStringLiteral("albumArtist"), QStringLiteral("3MediaD") }, | ||
466 | uriGrouper.insert("genre", QLatin1String("3MediaE")); | 450 | { QStringLiteral("genre"), QStringLiteral("3MediaE") }, | ||
467 | uriGrouper.insert("trackNumber", QLatin1String("3MediaF")); | 451 | { QStringLiteral("trackNumber"), QStringLiteral("3MediaF") }, | ||
468 | uriGrouper.insert("discNumber", QLatin1String("3MediaG")); | 452 | { QStringLiteral("discNumber"), QStringLiteral("3MediaG") }, | ||
469 | uriGrouper.insert("releaseYear", QLatin1String("3MediaH")); | 453 | { QStringLiteral("releaseYear"), QStringLiteral("3MediaH") }, | ||
470 | uriGrouper.insert("duration", QLatin1String("3MediaI")); | 454 | { QStringLiteral("duration"), QStringLiteral("3MediaI") }, | ||
471 | uriGrouper.insert("sampleRate", QLatin1String("3MediaJ")); | 455 | { QStringLiteral("sampleRate"), QStringLiteral("3MediaJ") }, | ||
472 | uriGrouper.insert("bitRate", QLatin1String("3MediaK")); | 456 | { QStringLiteral("bitRate"), QStringLiteral("3MediaK") }, | ||
473 | 457 | | |||
474 | // Miscellaneous Data | 458 | // Miscellaneous Data | ||
475 | uriGrouper.insert("originUrl", QLatin1String("4MiscA")); | 459 | { QStringLiteral("originUrl"), QStringLiteral("4MiscA") }, | ||
476 | } | 460 | }; | ||
477 | 461 | | |||
478 | const QString val = uriGrouper.value(label); | 462 | const QString val = uriGrouper.value(label); | ||
479 | if (val.isEmpty()) { | 463 | if (val.isEmpty()) { | ||
480 | return "lastGroup"; | 464 | return QStringLiteral("lastGroup"); | ||
481 | } | 465 | } | ||
482 | return val; | 466 | return val; | ||
483 | } | 467 | } | ||
484 | 468 | | |||
485 | KFileItemList FileMetaDataProvider::items() const | 469 | KFileItemList FileMetaDataProvider::items() const | ||
486 | { | 470 | { | ||
487 | return m_fileItems; | 471 | return m_fileItems; | ||
488 | } | 472 | } | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
You can use an initializer list here, like in FileMetaDataProvider::label(...)