#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) ?
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()
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"
item->setData(Qt::UserRole, key);
const bool show = settings.readEntry(key, true);
item->setCheckState(show ? Qt::Checked : Qt::Unchecked);
-
}
#ifdef HAVE_NEPOMUK
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;
}
}
-
#include "metadataconfigurationdialog.moc"
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
};
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);