From: Peter Penz Date: Fri, 26 Feb 2010 22:03:32 +0000 (+0000) Subject: Meta data configuration cleanups: X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/77d9413d075104a797569d56d2a97016daa6540c Meta data configuration cleanups: - Use RDF labels internally. - Provide better default settings, which meta data are hidden. - Allow to configure which meta data is shown also if Nepomuk is turned off. svn path=/trunk/KDE/kdebase/apps/; revision=1096571 --- diff --git a/src/panels/information/kloadmetadatathread.cpp b/src/panels/information/kloadmetadatathread.cpp index eeb9f5146..5886775b6 100644 --- a/src/panels/information/kloadmetadatathread.cpp +++ b/src/panels/information/kloadmetadatathread.cpp @@ -98,16 +98,17 @@ void KLoadMetaDataThread::run() m_tags = file.tags(); } - NfoTranslator& nfo = NfoTranslator::instance(); + const NfoTranslator& nfo = NfoTranslator::instance(); if (first && (m_urls.count() == 1)) { // get cached meta data by checking the indexed files QHash variants = file.properties(); QHash::const_iterator it = variants.constBegin(); while (it != variants.constEnd()) { Nepomuk::Types::Property prop(it.key()); - if (settings.readEntry(prop.name(), true)) { + const QString uriString = prop.uri().toString(); + if (settings.readEntry(uriString, true)) { Item item; - item.name = prop.uri().toString(); + item.name = uriString; item.label = nfo.translation(prop.uri()); item.value = formatValue(it.value()); m_items.append(item); @@ -121,11 +122,14 @@ void KLoadMetaDataThread::run() KFileMetaInfo metaInfo(m_urls.first()); const QHash metaInfoItems = metaInfo.items(); foreach (const KFileMetaInfoItem& metaInfoItem, metaInfoItems) { - Item item; - item.name = metaInfoItem.name(); - item.label = nfo.translation(metaInfoItem.name()); - item.value = metaInfoItem.value().toString(); - m_items.append(item); + const QString uriString = metaInfoItem.name(); + if (settings.readEntry(uriString, true)) { + Item item; + item.name = uriString; + item.label = nfo.translation(metaInfoItem.name()); + item.value = metaInfoItem.value().toString(); + m_items.append(item); + } } } } diff --git a/src/panels/information/kmetadataconfigurationdialog.cpp b/src/panels/information/kmetadataconfigurationdialog.cpp index e614a35fe..4b791af5a 100644 --- a/src/panels/information/kmetadataconfigurationdialog.cpp +++ b/src/panels/information/kmetadataconfigurationdialog.cpp @@ -17,6 +17,11 @@ *****************************************************************************/ #include "kmetadataconfigurationdialog.h" + +#include "nfotranslator.h" + +#include +#include #include "kmetadatawidget.h" #include @@ -41,7 +46,7 @@ public: void init(); void loadMetaData(); - QString tunedLabel(const QString& label) const; + void addItem(const QUrl& uri); int m_visibleDataTypes; QLabel* m_descriptionLabel; @@ -99,13 +104,13 @@ void KMetaDataConfigurationDialog::Private::loadMetaData() // Add fixed meta data items where the visibility does not // depend on the currently used URL. KMetaDataWidget::MetaDataTypes visibleDataTypes = KMetaDataWidget::TypeData | - KMetaDataWidget::SizeData | - KMetaDataWidget::ModifiedData | - KMetaDataWidget::OwnerData | - KMetaDataWidget::PermissionsData | - KMetaDataWidget::RatingData | - KMetaDataWidget::TagsData | - KMetaDataWidget::CommentData; + KMetaDataWidget::SizeData | + KMetaDataWidget::ModifiedData | + KMetaDataWidget::OwnerData | + KMetaDataWidget::PermissionsData | + KMetaDataWidget::RatingData | + KMetaDataWidget::TagsData | + KMetaDataWidget::CommentData; if (m_metaDataWidget != 0) { visibleDataTypes = m_metaDataWidget->visibleDataTypes(); } @@ -113,30 +118,30 @@ void KMetaDataConfigurationDialog::Private::loadMetaData() typedef QPair FixedItem; QList fixedItems; if (visibleDataTypes & KMetaDataWidget::TypeData) { - fixedItems.append(FixedItem("type", i18nc("@item::inlistbox", "Type"))); + fixedItems.append(FixedItem("kfileitem#type", i18nc("@item::inlistbox", "Type"))); } if (visibleDataTypes & KMetaDataWidget::SizeData) { - fixedItems.append(FixedItem("size", i18nc("@item::inlistbox", "Size"))); + fixedItems.append(FixedItem("kfileitem#size", i18nc("@item::inlistbox", "Size"))); } if (visibleDataTypes & KMetaDataWidget::ModifiedData) { - fixedItems.append(FixedItem("modified", i18nc("@item::inlistbox", "Modified"))); + fixedItems.append(FixedItem("kfileitem#modified", i18nc("@item::inlistbox", "Modified"))); } if (visibleDataTypes & KMetaDataWidget::OwnerData) { - fixedItems.append(FixedItem("owner", i18nc("@item::inlistbox", "Owner"))); + fixedItems.append(FixedItem("kfileitem#owner", i18nc("@item::inlistbox", "Owner"))); } if (visibleDataTypes & KMetaDataWidget::PermissionsData) { - fixedItems.append(FixedItem("permissions", i18nc("@item::inlistbox", "Permissions"))); + fixedItems.append(FixedItem("kfileitem#permissions", i18nc("@item::inlistbox", "Permissions"))); } #ifdef HAVE_NEPOMUK if (Nepomuk::ResourceManager::instance()->init() == 0) { if (visibleDataTypes & KMetaDataWidget::RatingData) { - fixedItems.append(FixedItem("rating", i18nc("@item::inlistbox", "Rating"))); + fixedItems.append(FixedItem("kfileitem#rating", i18nc("@item::inlistbox", "Rating"))); } if (visibleDataTypes & KMetaDataWidget::TagsData) { - fixedItems.append(FixedItem("tags", i18nc("@item::inlistbox", "Tags"))); + fixedItems.append(FixedItem("kfileitem#tags", i18nc("@item::inlistbox", "Tags"))); } if (visibleDataTypes & KMetaDataWidget::CommentData) { - fixedItems.append(FixedItem("comment", i18nc("@item::inlistbox", "Comment"))); + fixedItems.append(FixedItem("kfileitem#comment", i18nc("@item::inlistbox", "Comment"))); } } #endif @@ -151,10 +156,6 @@ void KMetaDataConfigurationDialog::Private::loadMetaData() } #ifdef HAVE_NEPOMUK - if (Nepomuk::ResourceManager::instance()->init() != 0) { - return; - } - // Get all meta information labels that are available for // the currently shown file item and add them to the list. if (m_metaDataWidget == 0) { @@ -168,73 +169,64 @@ void KMetaDataConfigurationDialog::Private::loadMetaData() // TODO: handle als usecases for more than one item: return; } - Nepomuk::Resource res(items.first().nepomukUri()); + Nepomuk::Resource res(items.first().nepomukUri()); QHash properties = res.properties(); - QHash::const_iterator it = properties.constBegin(); - while (it != properties.constEnd()) { - Nepomuk::Types::Property prop(it.key()); - const QString key = prop.name(); - - // Meta information provided by Nepomuk that is already - // available from KFileItem as "fixed item" (see above) - // should not be shown as second entry. - static const char* const hiddenProperties[] = { - "contentSize", // = fixed item "size" - "description", // = fixed item "comment" - "fileExtension", // ~ fixed item "type" - "hasTag", // = fixed item "tags" - "name", // not shown as part of the meta data widget - "lastModified", // = fixed item "modified" - "size", // = fixed item "size" - "mimeType", // = fixed item "type" - "numericRating", // = fixed item "rating" - 0 // mandatory last entry - }; - bool skip = false; - int i = 0; - while (hiddenProperties[i] != 0) { - if (key == hiddenProperties[i]) { - skip = true; - break; - } - ++i; + if (properties.isEmpty()) { + // the file is not indexed or Nepomuk is disabled + KFileMetaInfo metaInfo(items.first().url()); + const QHash metaInfoItems = metaInfo.items(); + foreach (const KFileMetaInfoItem& metaInfoItem, metaInfoItems) { + addItem(metaInfoItem.name()); } - if (!skip) { - // TODO #1: use Nepomuk::formatValue(res, prop) if available - // instead of it.value().toString() - // TODO #2: using tunedLabel() is a workaround for KDE 4.3 (4.4?) until - // we get translated labels - const QString label = tunedLabel(prop.label()); - QListWidgetItem* item = new QListWidgetItem(label, m_metaDataList); - item->setData(Qt::UserRole, key); - const bool show = settings.readEntry(key, true); - item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + } else { + // show meta information provided by Nepomuk + QHash::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + Nepomuk::Types::Property prop(it.key()); + addItem(prop.uri()); + ++it; } - - ++it; } #endif } -QString KMetaDataConfigurationDialog::Private::tunedLabel(const QString& label) const +void KMetaDataConfigurationDialog::Private::addItem(const QUrl& uri) { - QString tunedLabel; - const int labelLength = label.length(); - if (labelLength > 0) { - tunedLabel.reserve(labelLength); - tunedLabel = label[0].toUpper(); - for (int i = 1; i < labelLength; ++i) { - if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) { - tunedLabel += ' '; - tunedLabel += label[i].toLower(); - } else { - tunedLabel += label[i]; - } + // Meta information provided by Nepomuk that is already + // available from KFileItem as "fixed item" (see above) + // should not be shown as second entry. + static const char* const hiddenProperties[] = { + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", // = fixed item kfileitem#comment + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", // = fixed item kfileitem#size + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", // = fixed item kfileitem#modified + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent" // hide this property always + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", // = fixed item kfileitem#type + "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName", // hide this property always + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", // = fixed item kfileitem#type + 0 // mandatory last entry + }; + + int i = 0; + const QString key = uri.toString(); + while (hiddenProperties[i] != 0) { + if (key == QLatin1String(hiddenProperties[i])) { + // the item is hidden + return; } + ++i; } - return tunedLabel; + + // the item is not hidden, add it to the list + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + + const QString label = NfoTranslator::instance().translation(uri); + QListWidgetItem* item = new QListWidgetItem(label, m_metaDataList); + item->setData(Qt::UserRole, key); + const bool show = settings.readEntry(key, true); + item->setCheckState(show ? Qt::Checked : Qt::Unchecked); } KMetaDataConfigurationDialog::KMetaDataConfigurationDialog(QWidget* parent, diff --git a/src/panels/information/kmetadatawidget.cpp b/src/panels/information/kmetadatawidget.cpp index 8d66dfadc..14a784af4 100644 --- a/src/panels/information/kmetadatawidget.cpp +++ b/src/panels/information/kmetadatawidget.cpp @@ -269,7 +269,7 @@ void KMetaDataWidget::Private::setRowVisible(QWidget* infoWidget, bool visible) void KMetaDataWidget::Private::initMetaInfoSettings() { - const int currentVersion = 2; // increase version, if the blacklist of disabled + const int currentVersion = 3; // increase version, if the blacklist of disabled // properties should be updated KConfig config("kmetainformationrc", KConfig::NoGlobals); @@ -278,16 +278,36 @@ void KMetaDataWidget::Private::initMetaInfoSettings() // that some meta information is disabled per default. // clear old info - config.deleteGroup( "Show" ); + config.deleteGroup("Show"); KConfigGroup settings = config.group("Show"); - // trueg: KDE 4.5: use a blacklist of actual rdf properties - static const char* const disabledProperties[] = { - "asText", "contentSize", "created", "depth", "description", "fileExtension", - "fileName", "fileSize", "hasTag", "lastModified", "mimeType", "name", - "numericRating", "parentUrl", "permissions", "plainTextContent", "owner", - "sourceModified", "url", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent", + "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url", + "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate", + "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels", + "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", + "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + "kfileitem#owner", + "kfileitem#permissions", 0 // mandatory last entry }; @@ -307,13 +327,13 @@ void KMetaDataWidget::Private::updateRowsVisibility() setRowVisible(m_typeInfo, (m_visibleDataTypes & KMetaDataWidget::TypeData) && - settings.readEntry("type", true)); + settings.readEntry("kfileitem#type", true)); // Cache in m_sizeVisible whether the size should be shown. This // is necessary as the size is temporary hidden when the target // file item is a directory. m_sizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) && - settings.readEntry("size", true); + settings.readEntry("kfileitem#size", true); bool visible = m_sizeVisible; if (visible && (m_fileItems.count() == 1)) { // don't show the size information, if one directory is shown @@ -324,29 +344,29 @@ void KMetaDataWidget::Private::updateRowsVisibility() setRowVisible(m_modifiedInfo, (m_visibleDataTypes & KMetaDataWidget::ModifiedData) && - settings.readEntry("modified", true)); + settings.readEntry("kfileitem#modified", true)); setRowVisible(m_ownerInfo, (m_visibleDataTypes & KMetaDataWidget::OwnerData) && - settings.readEntry("owner", true)); + settings.readEntry("kfileitem#owner", true)); setRowVisible(m_permissionsInfo, (m_visibleDataTypes & KMetaDataWidget::PermissionsData) && - settings.readEntry("permissions", true)); + settings.readEntry("kfileitem#permissions", true)); #ifdef HAVE_NEPOMUK if (m_nepomukActivated) { setRowVisible(m_ratingWidget, (m_visibleDataTypes & KMetaDataWidget::RatingData) && - settings.readEntry("rating", true)); + settings.readEntry("kfileitem#rating", true)); setRowVisible(m_taggingWidget, (m_visibleDataTypes & KMetaDataWidget::TagsData) && - settings.readEntry("tags", true)); + settings.readEntry("kfileitem#tags", true)); setRowVisible(m_commentWidget, (m_visibleDataTypes & KMetaDataWidget::CommentData) && - settings.readEntry("comment", true)); + settings.readEntry("kfileitem#comment", true)); } #endif } diff --git a/src/panels/information/nfotranslator.cpp b/src/panels/information/nfotranslator.cpp index 434f6362f..3910d80f0 100644 --- a/src/panels/information/nfotranslator.cpp +++ b/src/panels/information/nfotranslator.cpp @@ -32,9 +32,11 @@ static const TranslationTuple g_translations[] = { { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", I18N_NOOP2("@label", "Comment") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated", I18N_NOOP2("@label creation date", "Created") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", I18N_NOOP2("@label file content size", "Size") }, + { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends", I18N_NOOP2("@label file depends from", "Depends") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf", I18N_NOOP2("@label parent directory", "Part of") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", I18N_NOOP2("@label modified date of file", "Modified") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", I18N_NOOP2("@label", "MIME Type") }, + { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent", I18N_NOOP2("@label", "Content") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title", I18N_NOOP2("@label music title", "Title") }, { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url", I18N_NOOP2("@label file URL", "Location") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator", I18N_NOOP2("@label", "Creator") }, @@ -47,6 +49,7 @@ static const TranslationTuple g_translations[] = { { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", I18N_NOOP2("@label", "Height") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#interlaceMode", I18N_NOOP2("@label", "Interlace Mode") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", I18N_NOOP2("@label number of lines", "Lines") }, + { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#programmingLanguage", I18N_NOOP2("@label", "Programming Language") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#sampleRate", I18N_NOOP2("@label", "Sample Rate") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", I18N_NOOP2("@label", "Width") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", I18N_NOOP2("@label number of words", "Words") }, @@ -55,12 +58,13 @@ static const TranslationTuple g_translations[] = { { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime", I18N_NOOP2("@label EXIF", "Exposure Time") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash", I18N_NOOP2("@label EXIF", "Flash") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength", I18N_NOOP2("@label EXIF", "Focal Length") }, + { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm", I18N_NOOP2("@label EXIF", "Focal Length 35 mm") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", I18N_NOOP2("@label EXIF", "ISO Speed Ratings") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make", I18N_NOOP2("@label EXIF", "Make") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", I18N_NOOP2("@label EXIF", "Metering Mode") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model", I18N_NOOP2("@label EXIF", "Model") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", I18N_NOOP2("@label EXIF", "Orientation") }, - { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", I18N_NOOP2("@label", "White Balance") }, + { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", I18N_NOOP2("@label EXIF", "White Balance") }, { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#genre", I18N_NOOP2("@label music genre", "Genre") }, { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", I18N_NOOP2("@label music album", "Album") }, { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", I18N_NOOP2("@label music track number", "Track") },