]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Meta data configuration cleanups:
authorPeter Penz <peter.penz19@gmail.com>
Fri, 26 Feb 2010 22:03:32 +0000 (22:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 26 Feb 2010 22:03:32 +0000 (22:03 +0000)
- 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

src/panels/information/kloadmetadatathread.cpp
src/panels/information/kmetadataconfigurationdialog.cpp
src/panels/information/kmetadatawidget.cpp
src/panels/information/nfotranslator.cpp

index eeb9f51468dd78b11c228d531fdb0f153c8ef73c..5886775b67df91189705f1fbe8aec34a9ae4459f 100644 (file)
@@ -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<QUrl, Nepomuk::Variant> variants = file.properties();
             QHash<QUrl, Nepomuk::Variant>::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<QString, KFileMetaInfoItem> 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);
+                    }
                 }
             }
         }
index e614a35fe8d2ee8cca357e28e23dcce6600cf69b..4b791af5a884f6c5438ff6fc889cec6d012248d8 100644 (file)
  *****************************************************************************/
 
 #include "kmetadataconfigurationdialog.h"
+
+#include "nfotranslator.h"
+
+#include <kfilemetainfo.h>
+#include <kfilemetainfoitem.h>
 #include "kmetadatawidget.h"
 #include <klocale.h>
 
@@ -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<QString, QString> FixedItem;
     QList<FixedItem> 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<QUrl, Nepomuk::Variant> properties = res.properties();
-    QHash<QUrl, Nepomuk::Variant>::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<QString, KFileMetaInfoItem> 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<QUrl, Nepomuk::Variant>::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,
index 8d66dfadcaea24b33a6e1e4bf423425d26b3c219..14a784af46fa3476d70d80b814db6b0734c32d37 100644 (file)
@@ -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
 }
index 434f6362f503905be6923a2fcfb2535f1fe484f8..3910d80f050cfaf9065070eddfbfe6156fbabcf4 100644 (file)
@@ -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") },