]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanel.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / panels / information / informationpanel.cpp
index 1b8724f46568c566b529d0b542e81d2fe5d999e4..84b706b99817c54916f11c8482e7c348b139b0e7 100644 (file)
@@ -35,6 +35,9 @@
 #include <kseparator.h>
 
 #ifdef HAVE_NEPOMUK
+
+#define DISABLE_NEPOMUK_LEGACY
+
 #include <Nepomuk/Resource>
 #include <Nepomuk/Types/Property>
 #include <Nepomuk/Variant>
@@ -202,6 +205,12 @@ void InformationPanel::resizeEvent(QResizeEvent* event)
         const int maxWidth = event->size().width() - KDialog::spacingHint() * 4;
         m_nameLabel->setMaximumWidth(maxWidth);
 
+        // The metadata widget also contains a text widget which may return
+        // a large preferred width.
+        if (m_metaDataWidget != 0) {
+            m_metaDataWidget->setMaximumWidth(maxWidth);
+        }
+
         // try to increase the preview as large as possible
         m_preview->setSizeHint(QSize(maxWidth, maxWidth));
         m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done
@@ -274,7 +283,7 @@ void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
     QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
     while (it != properties.constEnd()) {
         Nepomuk::Types::Property prop(it.key());
-        const QString key = prop.label();
+        const QString key = prop.name();
 
         // Meta information provided by Nepomuk that is already
         // available from KFileItem should not be configurable.
@@ -296,7 +305,7 @@ void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
         }
 
         if (!skip) {
-            const QString label = key; // TODO
+            const QString label = tunedLabel(prop.label());
             QAction* action = new QAction(label, &popup);
             action->setCheckable(true);
             action->setChecked(settings.readEntry(key, true));
@@ -345,10 +354,12 @@ void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
         showMetaInfo();
     }
 
-    const bool visible = m_metaDataWidget->isRatingVisible() ||
-                         m_metaDataWidget->isCommentVisible() ||
-                         m_metaDataWidget->areTagsVisible();
-    m_metaDataSeparator->setVisible(visible);
+    if (m_metaDataWidget != 0) {
+        const bool visible = m_metaDataWidget->isRatingVisible() ||
+                             m_metaDataWidget->isCommentVisible() ||
+                             m_metaDataWidget->areTagsVisible();
+        m_metaDataSeparator->setVisible(visible);
+    }
 #endif
 }
 
@@ -438,25 +449,9 @@ void InformationPanel::showPreview(const KFileItem& item,
 
 void InformationPanel::slotFileRenamed(const QString& source, const QString& dest)
 {
-    const KUrl sourceUrl = KUrl(source);
-
-    // Verify whether the renamed item is selected. If this is the case, the
-    // selection must be updated with the renamed item.
-    bool isSelected = false;
-    for (int i = m_selection.size() - 1; i >= 0; --i) {
-        if (m_selection[i].url() == sourceUrl) {
-            m_selection.removeAt(i);
-            isSelected = true;
-            break;
-        }
-    }
-
-    if ((m_shownUrl == sourceUrl) || isSelected) {
+    if (m_shownUrl == KUrl(source)) {
         m_shownUrl = KUrl(dest);
         m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
-        if (isSelected) {
-            m_selection.append(m_fileItem);
-        }
         showItemInfo();
     }
 }
@@ -589,11 +584,12 @@ void InformationPanel::showMetaInfo()
             QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
             while (it != properties.constEnd()) {
                 Nepomuk::Types::Property prop(it.key());
-                const QString label = prop.label();
-                if (settings.readEntry(label, true)) {
-                    // TODO: use Nepomuk::formatValue(res, prop) if available
+                if (settings.readEntry(prop.name(), true)) {
+                    // TODO #1: use Nepomuk::formatValue(res, prop) if available
                     // instead of it.value().toString()
-                    m_metaTextLabel->add(label, it.value().toString());
+                    // TODO #2: using tunedLabel() is a workaround for KDE 4.3 until
+                    // we get translated labels
+                    m_metaTextLabel->add(tunedLabel(prop.label()) + ':', it.value().toString());
                 }
                 ++it;
             }
@@ -678,14 +674,20 @@ void InformationPanel::initMetaInfoSettings(KConfigGroup& group)
     if (!group.readEntry("initialized", false)) {
         // The resource file is read the first time. Assure
         // that some meta information is disabled per default.
-        group.writeEntry("fileExtension", false);
-        group.writeEntry("url", false);
-        group.writeEntry("sourceModified", false);
-        group.writeEntry("parentUrl", false);
-        group.writeEntry("size", false);
-        group.writeEntry("mime type", false);
-        group.writeEntry("depth", false);
-        group.writeEntry("name", false);
+
+        static const char* disabledProperties[] = {
+            "asText", "contentSize", "depth", "fileExtension",
+            "fileName", "fileSize", "isPartOf", "mimetype", "name",
+            "parentUrl", "plainTextContent", "sourceModified",
+            "size", "url",
+            0 // mandatory last entry
+        };
+
+        int i = 0;
+        while (disabledProperties[i] != 0) {
+            group.writeEntry(disabledProperties[i], false);
+            ++i;
+        }
 
         // mark the group as initialized
         group.writeEntry("initialized", true);
@@ -707,7 +709,7 @@ void InformationPanel::updatePhononWidget()
                                                            // thinks it supports PNG images
         if (usePhonon) {
             m_phononWidget->show();
-            PhononWidget::Mode mode = mimeType.startsWith("video")
+            PhononWidget::Mode mode = mimeType.startsWith(QLatin1String("video"))
                                       ? PhononWidget::Video
                                       : PhononWidget::Audio;
             m_phononWidget->setMode(mode);
@@ -722,6 +724,25 @@ void InformationPanel::updatePhononWidget()
     }
 }
 
+QString InformationPanel::tunedLabel(const QString& label) const
+{
+    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];
+            }
+        }
+    }
+    return tunedLabel;
+}
+
 void InformationPanel::init()
 {
     m_infoTimer = new QTimer(this);
@@ -775,6 +796,7 @@ void InformationPanel::init()
         // rating, comment and tags
         m_metaDataWidget = new MetaDataWidget(this);
         m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+        m_metaDataWidget->setMaximumWidth(KIconLoader::SizeEnormous);
 
         const bool showRating  = InformationPanelSettings::showRating();
         const bool showComment = InformationPanelSettings::showComment();