]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* allow editing of tags
authorPeter Penz <peter.penz19@gmail.com>
Fri, 16 Oct 2009 22:53:27 +0000 (22:53 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 16 Oct 2009 22:53:27 +0000 (22:53 +0000)
* minor adjustments for the default settings of visible meta data

svn path=/trunk/KDE/kdebase/apps/; revision=1036296

src/panels/information/edittagsdialog.cpp
src/panels/information/edittagsdialog_p.h
src/panels/information/metadataconfigurationdialog.cpp
src/panels/information/metadatawidget.cpp
src/panels/information/taggingwidget.cpp

index baa8a66fcce93f7b97fc58abf94b12829d65956b..75c51fa0038d9cb263715c566135402973c94ad1 100644 (file)
 
 #include "edittagsdialog_p.h"
 
+#include <klineedit.h>
 #include <klocale.h>
 
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QListWidget>
+#include <QVBoxLayout>
+#include <QWidget>
+
 EditTagsDialog::EditTagsDialog(const QList<Nepomuk::Tag>& tags,
                                QWidget* parent,
                                Qt::WFlags flags) :
     KDialog(parent, flags),
-    m_tags(tags)
+    m_tags(tags),
+    m_tagsList(0),
+    m_newTagItem(0),
+    m_newTagEdit(0)
 {
 
     const QString caption = (tags.count() > 0) ?
@@ -34,6 +44,35 @@ EditTagsDialog::EditTagsDialog(const QList<Nepomuk::Tag>& tags,
     setCaption(caption);
     setButtons(KDialog::Ok | KDialog::Cancel);
     setDefaultButton(KDialog::Ok);
+
+    QWidget* mainWidget = new QWidget(this);
+    QVBoxLayout* topLayout = new QVBoxLayout(mainWidget);
+
+    QLabel* label = new QLabel(i18nc("@label:textbox",
+                                     "Configure which tags should "
+                                     "be applied."), this);
+
+    m_tagsList = new QListWidget(this);
+    m_tagsList->setSortingEnabled(true);
+    m_tagsList->setSelectionMode(QAbstractItemView::NoSelection);
+
+    QLabel* newTagLabel = new QLabel(i18nc("@label", "Create new tag:"));
+    m_newTagEdit = new KLineEdit(this);
+    m_newTagEdit->setClearButtonShown(true);
+    connect(m_newTagEdit, SIGNAL(textEdited(const QString&)),
+            this, SLOT(slotTextEdited(const QString&)));
+
+    QHBoxLayout* newTagLayout = new QHBoxLayout();
+    newTagLayout->addWidget(newTagLabel);
+    newTagLayout->addWidget(m_newTagEdit, 1);
+
+    topLayout->addWidget(label);
+    topLayout->addWidget(m_tagsList);
+    topLayout->addLayout(newTagLayout);
+
+    setMainWidget(mainWidget);
+
+    loadTags();
 }
 
 EditTagsDialog::~EditTagsDialog()
@@ -45,4 +84,96 @@ QList<Nepomuk::Tag> EditTagsDialog::tags() const
     return m_tags;
 }
 
+void EditTagsDialog::slotButtonClicked(int button)
+{
+    if (button == KDialog::Ok) {
+        // update m_tags with the checked values, so
+        // that the caller of the EditTagsDialog can
+        // receive the tags by EditTagsDialog::tags()
+        m_tags.clear();
+
+        const int count = m_tagsList->count();
+        for (int i = 0; i < count; ++i) {
+            QListWidgetItem* item = m_tagsList->item(i);
+            if (item->checkState() == Qt::Checked) {
+                Nepomuk::Tag tag;
+                tag.setLabel(item->data(Qt::UserRole).toString());
+                m_tags.append(tag);
+            }
+        }
+
+        accept();
+    } else {
+        KDialog::slotButtonClicked(button);
+    }
+}
+
+void EditTagsDialog::slotTextEdited(const QString& text)
+{
+    // Remove unnecessary spaces from a new tag is
+    // mandatory, as the user cannot see the difference
+    // between a tag "Test" and "Test ".
+    const QString tagText = text.simplified();
+    if (tagText.isEmpty()) {
+        removeNewTagItem();
+        return;
+    }
+
+    // Check whether the new tag already exists. If this
+    // is the case, remove the new tag item.
+    const int count = m_tagsList->count();
+    for (int i = 0; i < count; ++i) {
+        const QListWidgetItem* item = m_tagsList->item(i);
+        const bool remove = (item->text() == tagText) &&
+                            ((m_newTagItem == 0) || (m_newTagItem != item));
+        if (remove) {
+            m_tagsList->scrollToItem(item);
+            removeNewTagItem();
+            return;
+        }
+    }
+
+    // There is no tag in the list with the the passed text.
+    if (m_newTagItem == 0) {
+        m_newTagItem = new QListWidgetItem(tagText, m_tagsList);
+    } else {
+        m_newTagItem->setText(tagText);
+    }
+    m_newTagItem->setData(Qt::UserRole, tagText);
+    m_newTagItem->setCheckState(Qt::Checked);
+    m_tagsList->scrollToItem(m_newTagItem);
+}
+
+void EditTagsDialog::loadTags()
+{
+    // load all available tags and mark those tags as checked
+    // that have been passed to the EditTagsDialog
+    QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
+    foreach (const Nepomuk::Tag& tag, tags) {
+        const QString label = tag.label();
+
+        QListWidgetItem* item = new QListWidgetItem(label, m_tagsList);
+        item->setData(Qt::UserRole, label);
+
+        bool check = false;
+        foreach (const Nepomuk::Tag& selectedTag, m_tags) {
+            if (selectedTag.label() == label) {
+                check = true;
+                break;
+            }
+        }
+        item->setCheckState(check ? Qt::Checked : Qt::Unchecked);
+    }
+}
+
+void EditTagsDialog::removeNewTagItem()
+{
+    if (m_newTagItem != 0) {
+        const int row = m_tagsList->row(m_newTagItem);
+        m_tagsList->takeItem(row);
+        delete m_newTagItem;
+        m_newTagItem = 0;
+    }
+}
+
 #include "edittagsdialog_p.moc"
index 4dd0935f2b76e160d13ae3b2893706fdce56ed20..f72d5d84ddb0a90a4a989a70f26333ea21b1f5c7 100644 (file)
 
 #include <Nepomuk/Tag>
 
+class KLineEdit;
+class QListWidget;
+class QListWidgetItem;
+
 /**
  * @brief Dialog to edit a list of Nepomuk tags.
  *
@@ -43,8 +47,21 @@ public:
 
     QList<Nepomuk::Tag> tags() const;
 
+protected slots:
+    virtual void slotButtonClicked(int button);
+
+private slots:
+    void slotTextEdited(const QString& text);
+
+private:
+    void loadTags();
+    void removeNewTagItem();
+
 private:
     QList<Nepomuk::Tag> m_tags;
+    QListWidget* m_tagsList;
+    QListWidgetItem* m_newTagItem;
+    KLineEdit* m_newTagEdit;
 };
 
 #endif
index f3bb929da76f7bf7e275ee277acfc344d1a5e9a2..ec6f4d1a2dd565035027ce3ce46e5489103972d4 100644 (file)
@@ -86,7 +86,6 @@ void MetaDataConfigurationDialog::Private::loadMetaData()
         item->setData(Qt::UserRole, key);
         const bool show = settings.readEntry(key, true);
         item->setCheckState(show ? Qt::Checked : Qt::Unchecked);
-
     }
 
 #ifdef HAVE_NEPOMUK
@@ -105,13 +104,29 @@ void MetaDataConfigurationDialog::Private::loadMetaData()
         const QString key = prop.name();
 
         // Meta information provided by Nepomuk that is already
-        // available from KFileItem should not be configurable.
-        bool skip = (key == "contentSize") ||
-                    (key == "fileExtension") ||
-                    (key == "name") ||
-                    (key == "lastModified") ||
-                    (key == "size") ||
-                    (key == "mimeType");
+        // available from KFileItem as "fixed item" (see above)
+        // should not be shown as second entry.
+        static const char* hiddenProperties[] = {
+            "contentSize",   // = fixed item "size"
+            "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 (!skip) {
             // const QString label = tunedLabel(prop.label());
             const QString label = prop.label() + " --- " + key;
@@ -187,5 +202,4 @@ void MetaDataConfigurationDialog::slotButtonClicked(int button)
     }
 }
 
-
 #include "metadataconfigurationdialog.moc"
index dfd63a05d884424a3c0dd5575d0f9e350965f70a..4228ea4eabfa6058f7eb9f1330bdcede932f0068 100644 (file)
@@ -290,9 +290,9 @@ void MetaDataWidget::Private::initMetaInfoSettings()
 
         static const char* disabledProperties[] = {
             "asText", "contentSize", "created", "depth", "description", "fileExtension",
-            "fileName", "fileSize", "isPartOf", "lastModified", "mimeType", "name",
-            "parentUrl", "permissions", "plainTextContent", "owner", "sourceModified",
-            "url",
+            "fileName", "fileSize", "hasTag", "isPartOf", "lastModified", "mimeType", "name",
+            "numericRating", "parentUrl", "permissions", "plainTextContent", "owner",
+            "sourceModified", "url",
             0 // mandatory last entry
         };
 
@@ -385,6 +385,8 @@ void MetaDataWidget::Private::slotRatingChanged(unsigned int rating)
 void MetaDataWidget::Private::slotTagsChanged(const QList<Nepomuk::Tag>& tags)
 {
 #ifdef HAVE_NEPOMUK
+    m_taggingWidget->setTags(tags);
+
     QMutexLocker locker(&m_mutex);
     Nepomuk::MassUpdateJob* job =
             Nepomuk::MassUpdateJob::tagResources(m_sharedData.files.values(), tags);
index 057b17e551e0710ac4df570ef01568b81a2e7c26..1c081f07cf3b9d32dcaea52b5bae3562ffee8213 100644 (file)
@@ -69,7 +69,6 @@ void TaggingWidget::setTags(const QList<Nepomuk::Tag>& tags)
     } else {
         m_label->setText("<p>" + m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a></p>");
     }
-
 }
 
 QList<Nepomuk::Tag> TaggingWidget::tags() const