┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2009-10-16 22:53:27 +0000
committerPeter Penz <[email protected]>2009-10-16 22:53:27 +0000
commite512e98b41f5d69b9e263ca703d75383e705ff05 (patch)
treebe9aa712daf290a38971d85c48941f6fdb1dc106 /src/panels
parentee088814864ba506173ecdd2003b11b081a10644 (diff)
* allow editing of tags
* minor adjustments for the default settings of visible meta data svn path=/trunk/KDE/kdebase/apps/; revision=1036296
Diffstat (limited to 'src/panels')
-rw-r--r--src/panels/information/edittagsdialog.cpp133
-rw-r--r--src/panels/information/edittagsdialog_p.h17
-rw-r--r--src/panels/information/metadataconfigurationdialog.cpp32
-rw-r--r--src/panels/information/metadatawidget.cpp8
-rw-r--r--src/panels/information/taggingwidget.cpp1
5 files changed, 177 insertions, 14 deletions
diff --git a/src/panels/information/edittagsdialog.cpp b/src/panels/information/edittagsdialog.cpp
index baa8a66fc..75c51fa00 100644
--- a/src/panels/information/edittagsdialog.cpp
+++ b/src/panels/information/edittagsdialog.cpp
@@ -19,13 +19,23 @@
#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"
diff --git a/src/panels/information/edittagsdialog_p.h b/src/panels/information/edittagsdialog_p.h
index 4dd0935f2..f72d5d84d 100644
--- a/src/panels/information/edittagsdialog_p.h
+++ b/src/panels/information/edittagsdialog_p.h
@@ -24,6 +24,10 @@
#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
diff --git a/src/panels/information/metadataconfigurationdialog.cpp b/src/panels/information/metadataconfigurationdialog.cpp
index f3bb929da..ec6f4d1a2 100644
--- a/src/panels/information/metadataconfigurationdialog.cpp
+++ b/src/panels/information/metadataconfigurationdialog.cpp
@@ -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"
diff --git a/src/panels/information/metadatawidget.cpp b/src/panels/information/metadatawidget.cpp
index dfd63a05d..4228ea4ea 100644
--- a/src/panels/information/metadatawidget.cpp
+++ b/src/panels/information/metadatawidget.cpp
@@ -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);
diff --git a/src/panels/information/taggingwidget.cpp b/src/panels/information/taggingwidget.cpp
index 057b17e55..1c081f07c 100644
--- a/src/panels/information/taggingwidget.cpp
+++ b/src/panels/information/taggingwidget.cpp
@@ -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