]> cloud.milkyroute.net Git - dolphin.git/commitdiff
provide a context menu for the Information Panel, which allows to show/hide meta...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 10 Mar 2009 19:04:45 +0000 (19:04 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 10 Mar 2009 19:04:45 +0000 (19:04 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=937910

src/CMakeLists.txt
src/panels/information/informationpanel.cpp
src/panels/information/informationpanel.h
src/panels/information/informationpaneldialog.cpp [deleted file]
src/panels/information/informationpaneldialog.h [deleted file]

index d6cc3e7550a0572cca0d30f4dad509280d126202..c1daf5e8b9c3d783b21d716be754cfee97dabb99 100644 (file)
@@ -102,7 +102,6 @@ set(dolphin_SRCS
     panels/information/commentwidget.cpp
     panels/information/commenteditwidget.cpp
     panels/information/informationpanel.cpp
-    panels/information/informationpaneldialog.cpp
     panels/information/metadatawidget.cpp
     panels/information/metatextlabel.cpp
     panels/information/phononwidget.cpp
index adf53348fd105e7207930f7211e90eb17fd3e52f..a28b37a9e4e75cbc27d0ba95446a5864a2f3fc4d 100644 (file)
 
 #include <kdialog.h>
 #include <kdirnotify.h>
-#include <kfileplacesmodel.h>
-#include <klocale.h>
-#include <kstandarddirs.h>
-#include <kio/previewjob.h>
 #include <kfileitem.h>
-#include <kglobalsettings.h>
 #include <kfilemetainfo.h>
+#include <kfileplacesmodel.h>
+#include <kglobalsettings.h>
+#include <kio/previewjob.h>
 #include <kiconeffect.h>
+#include <kiconloader.h>
+#include <klocale.h>
 #include <kmenu.h>
 #include <kseparator.h>
-#include <kiconloader.h>
 
 #ifdef HAVE_NEPOMUK
 #include <Nepomuk/Resource>
 #include <QVBoxLayout>
 
 #include "settings/dolphinsettings.h"
-#include "informationpaneldialog.h"
 #include "metadatawidget.h"
 #include "metatextlabel.h"
 #include "phononwidget.h"
 #include "pixmapviewer.h"
 
+/**
+ * Helper function for sorting items with qSort() in
+ * InformationPanel::contextMenu().
+ */
+bool lessThan(const QAction* action1, const QAction* action2)
+{
+    return action1->text() < action2->text();
+}
+
+
 InformationPanel::InformationPanel(QWidget* parent) :
     Panel(parent),
     m_initialized(false),
@@ -80,8 +88,7 @@ InformationPanel::InformationPanel(QWidget* parent) :
     m_phononWidget(0),
     m_metaDataWidget(0),
     m_metaTextArea(0),
-    m_metaTextLabel(0),
-    m_dialog(0)
+    m_metaTextLabel(0)
 {
 }
 
@@ -214,17 +221,79 @@ void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
 {
     Panel::contextMenuEvent(event);
 
+#ifdef HAVE_NEPOMUK
+    if (showMultipleSelectionInfo()) {
+        return;
+    }
+
     KMenu popup(this);
-    popup.addAction(i18nc("@action:inmenu", "Configure..."));
-    if (popup.exec(QCursor::pos()) != 0) {
-        if (m_dialog == 0) {
-            m_dialog = new InformationPanelDialog(this);
-            m_dialog->setAttribute(Qt::WA_DeleteOnClose);
-            m_dialog->show();
-        } else {
-            m_dialog->raise();
+    popup.addTitle(i18nc("@title:menu", "Shown Information"));
+
+    KConfig config("kmetainformationrc", KConfig::NoGlobals);
+    KConfigGroup settings = config.group("Show");
+    initMetaInfoSettings(settings);
+
+    QList<QAction*> actions;
+
+    // Get all meta information labels that are available for
+    // the currently shown file item and add them to the popup.
+    Nepomuk::Resource res(fileItem().url());
+    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.label();
+
+        // Meta information provided by Nepomuk that is already
+        // available from KFileItem should not be configurable.
+        bool skip = (key == "fileExtension") ||
+                    (key == "name") ||
+                    (key == "sourceModified") ||
+                    (key == "size") ||
+                    (key == "mime type");
+        if (!skip) {
+            // Check whether there is already a meta information
+            // having the same label. In this case don't show it
+            // twice in the menu.
+            foreach (const QAction* action, actions) {
+                if (action->data().toString() == key) {
+                    skip = true;
+                    break;
+                }
+            }
         }
+
+        if (!skip) {
+            const QString label = key; // TODO
+            QAction* action = new QAction(label, &popup);
+            action->setCheckable(true);
+            action->setChecked(settings.readEntry(key, true));
+            action->setData(key);
+            actions.append(action);
+        }
+
+        ++it;
+    }
+
+    if (actions.count() == 0) {
+        return;
+    }
+
+    // add all items alphabetically sorted to the popup
+    qSort(actions.begin(), actions.end(), lessThan);
+    foreach (QAction* action, actions) {
+        popup.addAction(action);
+    }
+
+    // Open the popup and adjust the settings for the
+    // selected action.
+    QAction* action = popup.exec(QCursor::pos());
+    if (action != 0) {
+        settings.writeEntry(action->data().toString(), action->isChecked());
+        settings.sync();
+        showMetaInfo();
     }
+#endif
 }
 
 void InformationPanel::showItemInfo()
@@ -447,15 +516,22 @@ void InformationPanel::showMetaInfo()
             m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
 
 #ifdef HAVE_NEPOMUK
+            KConfig config("kmetainformationrc", KConfig::NoGlobals);
+            KConfigGroup settings = config.group("Show");
+            initMetaInfoSettings(settings);
+
             Nepomuk::Resource res(item.url());
 
             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());
-                // TODO: use Nepomuk::formatValue(res, prop) if available
-                // instead of it.value().toString()
-                m_metaTextLabel->add(prop.label(), it.value().toString());
+                const QString label = prop.label();
+                if (settings.readEntry(label, true)) {
+                    // TODO: use Nepomuk::formatValue(res, prop) if available
+                    // instead of it.value().toString()
+                    m_metaTextLabel->add(label, it.value().toString());
+                }
                 ++it;
             }
 #endif
@@ -546,6 +622,25 @@ void InformationPanel::reset()
     showItemInfo();
 }
 
+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);
+
+        // mark the group as initialized
+        group.writeEntry("initialized", true);
+    }
+}
+
 void InformationPanel::init()
 {
     const int spacing = KDialog::spacingHint();
index bc37f812ae4a3dde7e085c2c0042ed1f3328e30f..e8e497f985f7b6c2083b21a049f1e3f06d232216 100644 (file)
 #define INFORMATIONPANEL_H
 
 #include <panels/panel.h>
-#include <panels/information/informationpaneldialog.h>
 
 #include <QPushButton>
 #include <QPixmap>
 #include <QEvent>
 #include <QLabel>
 #include <QList>
-#include <QPointer>
 
+#include <kconfig.h>
 #include <kurl.h>
 #include <kmimetype.h>
 #include <kdesktopfileactions.h>
@@ -183,6 +182,12 @@ private:
      */
     void reset();
 
+    /**
+     * Assures that the settings for the meta information
+     * are initialized with proper default values.
+     */
+    void initMetaInfoSettings(KConfigGroup& group);
+
     void init();
 
 private:
@@ -202,8 +207,6 @@ private:
 
     QScrollArea* m_metaTextArea;
     MetaTextLabel* m_metaTextLabel;
-
-    QPointer<InformationPanelDialog> m_dialog;
 };
 
 #endif // INFORMATIONPANEL_H
diff --git a/src/panels/information/informationpaneldialog.cpp b/src/panels/information/informationpaneldialog.cpp
deleted file mode 100644 (file)
index 0922197..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
-
-#include "informationpaneldialog.h"
-
-#include <klocale.h>
-#include <kiconloader.h>
-
-#include <QVBoxLayout>
-
-InformationPanelDialog::InformationPanelDialog(QWidget* parent) :
-    KDialog(parent),
-    m_isDirty(false)
-{
-    setCaption(i18nc("@title:window", "Information Panel"));
-    setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
-
-    QWidget* main = new QWidget();
-    // ...
-    Q_UNUSED(main);
-    QVBoxLayout* topLayout = new QVBoxLayout();
-    // ...
-    Q_UNUSED(topLayout);
-
-    connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
-    connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
-
-    main->setLayout(topLayout);
-    setMainWidget(main);
-
-    const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
-                                    "InformationPanelDialog");
-    restoreDialogSize(dialogConfig);
-
-    loadSettings();
-}
-
-InformationPanelDialog::~InformationPanelDialog()
-{
-    KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
-                              "InformationPanelDialog");
-    saveDialogSize(dialogConfig, KConfigBase::Persistent);
-}
-
-void InformationPanelDialog::slotOk()
-{
-    // ...
-    accept();
-}
-
-void InformationPanelDialog::slotApply()
-{
-    // ...
-    markAsDirty(false);
-}
-
-void InformationPanelDialog::markAsDirty(bool isDirty)
-{
-    m_isDirty = isDirty;
-    enableButtonApply(isDirty);
-}
-
-void InformationPanelDialog::loadSettings()
-{
-}
-
-#include "informationpaneldialog.moc"
diff --git a/src/panels/information/informationpaneldialog.h b/src/panels/information/informationpaneldialog.h
deleted file mode 100644 (file)
index 8ed5327..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
-
-#ifndef INFORMATIONPANELDIALOG_H
-#define INFORMATIONPANELDIALOG_H
-
-#include <kdialog.h>
-
-/**
- * @brief Dialog for adjusting the Information Panel settings.
- */
-class InformationPanelDialog : public KDialog
-{
-    Q_OBJECT
-
-public:
-    explicit InformationPanelDialog(QWidget* parent);
-    virtual ~InformationPanelDialog();
-
-private slots:
-    void slotOk();
-    void slotApply();
-    void markAsDirty(bool isDirty);
-
-private:
-    void loadSettings();
-
-private:
-    bool m_isDirty;
-};
-
-#endif