From 3852f31c30faea6c305d65e6756797184b3776d5 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 16 Oct 2009 13:01:11 +0000 Subject: [PATCH] * improved interface + documentation of MetaDataWidget * provide a configuration dialog for adjusting the visibility of the meta data svn path=/trunk/KDE/kdebase/apps/; revision=1036058 --- src/CMakeLists.txt | 1 + src/panels/information/commentwidget.cpp | 3 +- .../dolphin_informationpanelsettings.kcfg | 12 -- .../information/informationpanelcontent.cpp | 96 +----------- .../metadataconfigurationdialog.cpp | 147 ++++++++++++++++++ .../metadataconfigurationdialog_p.h | 52 +++++++ src/panels/information/metadatawidget.cpp | 95 ++++++++++- src/panels/information/metadatawidget.h | 82 +++++++++- src/panels/information/taggingwidget.cpp | 3 +- 9 files changed, 374 insertions(+), 117 deletions(-) create mode 100644 src/panels/information/metadataconfigurationdialog.cpp create mode 100644 src/panels/information/metadataconfigurationdialog_p.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 173a769e4..596490ae9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -154,6 +154,7 @@ set(dolphin_SRCS ${dolphin_SRCS} panels/information/commentwidget.cpp panels/information/edittagsdialog.cpp + panels/information/metadataconfigurationdialog.cpp panels/information/nepomukmassupdatejob.cpp panels/information/taggingwidget.cpp ) diff --git a/src/panels/information/commentwidget.cpp b/src/panels/information/commentwidget.cpp index 673a8c30a..06a4c33be 100644 --- a/src/panels/information/commentwidget.cpp +++ b/src/panels/information/commentwidget.cpp @@ -81,8 +81,7 @@ void CommentWidget::slotLinkActivated(const QString& link) dialog.setButtons(KDialog::Ok | KDialog::Cancel); dialog.setDefaultButton(KDialog::Ok); - KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "EditCommentDialog"); + KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk EditCommentDialog"); dialog.restoreDialogSize(dialogConfig); if (dialog.exec() == QDialog::Accepted) { diff --git a/src/panels/information/dolphin_informationpanelsettings.kcfg b/src/panels/information/dolphin_informationpanelsettings.kcfg index ebd921eef..2bde1c4af 100644 --- a/src/panels/information/dolphin_informationpanelsettings.kcfg +++ b/src/panels/information/dolphin_informationpanelsettings.kcfg @@ -7,17 +7,5 @@ true - - - true - - - - true - - - - true - diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 2b26c55a8..dfa88be17 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -290,79 +290,8 @@ void InformationPanelContent::configureSettings() previewAction->setCheckable(true); previewAction->setChecked(InformationPanelSettings::showPreview()); - const bool metaDataAvailable = true; // MetaDataWidget::metaDataAvailable(); TODO - - QAction* ratingAction = popup.addAction(i18nc("@action:inmenu", "Rating")); - ratingAction->setIcon(KIcon("rating")); - ratingAction->setCheckable(true); - ratingAction->setChecked(InformationPanelSettings::showRating()); - ratingAction->setEnabled(metaDataAvailable); - - QAction* commentAction = popup.addAction(i18nc("@action:inmenu", "Comment")); - commentAction->setIcon(KIcon("text-plain")); - commentAction->setCheckable(true); - commentAction->setChecked(InformationPanelSettings::showComment()); - commentAction->setEnabled(metaDataAvailable); - - QAction* tagsAction = popup.addAction(i18nc("@action:inmenu", "Tags")); - tagsAction->setCheckable(true); - tagsAction->setChecked(InformationPanelSettings::showTags()); - tagsAction->setEnabled(metaDataAvailable); - - KConfig config("kmetainformationrc", KConfig::NoGlobals); - KConfigGroup settings = config.group("Show"); - - QList actions; - - // Get all meta information labels that are available for - // the currently shown file item and add them to the popup. - /*Nepomuk::Resource res(m_item.url()); - QHash properties = res.properties(); - QHash::const_iterator it = properties.constBegin(); - while (it != properties.constEnd()) { - Nepomuk::Types::Property prop(it.key()); - const QString key = prop.name(); - - // 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 = tunedLabel(prop.label()); - QAction* action = new QAction(label, &popup); - action->setCheckable(true); - action->setChecked(settings.readEntry(key, true)); - action->setData(key); - actions.append(action); - } - - ++it; - }*/ - - if (!actions.isEmpty()) { - popup.addSeparator(); - - // add all items alphabetically sorted to the popup - qSort(actions.begin(), actions.end(), lessThan); - foreach (QAction* action, actions) { - popup.addAction(action); - } - } + QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); + configureAction->setIcon(KIcon("configure")); // Open the popup and adjust the settings for the // selected action. @@ -376,27 +305,10 @@ void InformationPanelContent::configureSettings() m_preview->setVisible(isChecked); m_previewSeparator->setVisible(isChecked); InformationPanelSettings::setShowPreview(isChecked); - } else if (action == ratingAction) { - //m_metaDataWidget->setRatingVisible(isChecked); - InformationPanelSettings::setShowRating(isChecked); - } else if (action == commentAction) { - //m_metaDataWidget->setCommentVisible(isChecked); - InformationPanelSettings::setShowComment(isChecked); - } else if (action == tagsAction) { - //m_metaDataWidget->setTagsVisible(isChecked); - InformationPanelSettings::setShowTags(isChecked); - } else { - settings.writeEntry(action->data().toString(), action->isChecked()); - settings.sync(); + } else if (action == configureAction) { + m_metaDataWidget->openConfigurationDialog(); } - /*if (m_metaDataWidget != 0) { - const bool visible = m_metaDataWidget->isRatingVisible() || - m_metaDataWidget->isCommentVisible() || - m_metaDataWidget->areTagsVisible(); - m_metaDataSeparator->setVisible(visible); - }*/ - showItem(m_item); } diff --git a/src/panels/information/metadataconfigurationdialog.cpp b/src/panels/information/metadataconfigurationdialog.cpp new file mode 100644 index 000000000..42343780f --- /dev/null +++ b/src/panels/information/metadataconfigurationdialog.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * 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 "metadataconfigurationdialog_p.h" + +#include "metadatawidget.h" + +#include + +#define DISABLE_NEPOMUK_LEGACY +#include +#include +#include + +#include +#include +#include + +MetaDataConfigurationDialog::MetaDataConfigurationDialog(const KUrl& url, + QWidget* parent, + Qt::WFlags flags) : + KDialog(parent, flags), + m_url(url), + m_metaDataList(0) +{ + setCaption(i18nc("@title:window", "Configure Shown Data")); + 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 data should " + "be shown."), this); + + m_metaDataList = new QListWidget(this); + m_metaDataList->setSelectionMode(QAbstractItemView::NoSelection); + + topLayout->addWidget(label); + topLayout->addWidget(m_metaDataList); + + setMainWidget(mainWidget); + + loadMetaData(); +} + +MetaDataConfigurationDialog::~MetaDataConfigurationDialog() +{ +} + +void MetaDataConfigurationDialog::slotButtonClicked(int button) +{ + if (button == KDialog::Ok) { + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup showGroup = config.group("Show"); + + const int count = m_metaDataList->count(); + for (int i = 0; i < count; ++i) { + QListWidgetItem* item = m_metaDataList->item(i); + const bool show = (item->checkState() == Qt::Checked); + const QString key = item->data(Qt::UserRole).toString(); + showGroup.writeEntry(key, show); + } + + showGroup.sync(); + + accept(); + } else { + KDialog::slotButtonClicked(button); + } +} + +void MetaDataConfigurationDialog::loadMetaData() +{ + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + + // Add fixed meta data items where the visibility does not + // depend on the currently used URL. + typedef QPair FixedItem; + QList fixedItems; + fixedItems.append(FixedItem("type", i18nc("@item::inlistbox", "Type"))); + fixedItems.append(FixedItem("size", i18nc("@item::inlistbox", "Size"))); + fixedItems.append(FixedItem("modified", i18nc("@item::inlistbox", "Modified"))); + fixedItems.append(FixedItem("owner", i18nc("@item::inlistbox", "Owner"))); + fixedItems.append(FixedItem("permissions", i18nc("@item::inlistbox", "Permission"))); + fixedItems.append(FixedItem("rating", i18nc("@item::inlistbox", "Rating"))); + fixedItems.append(FixedItem("tags", i18nc("@item::inlistbox", "Tags"))); + fixedItems.append(FixedItem("comment", i18nc("@item::inlistbox", "Comment"))); + + foreach (const FixedItem& fixedItem, fixedItems) { + const QString key = fixedItem.first; + const QString label = fixedItem.second; + QListWidgetItem* item = new QListWidgetItem(label, m_metaDataList); + item->setData(Qt::UserRole, key); + const bool show = settings.readEntry(key, true); + item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + + } + + // Get all meta information labels that are available for + // the currently shown file item and add them to the list. + Nepomuk::Resource res(m_url); + QHash properties = res.properties(); + QHash::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + Nepomuk::Types::Property prop(it.key()); + const QString key = prop.name(); + + // 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) { + // const QString label = tunedLabel(prop.label()); + const QString label = prop.label(); + QListWidgetItem* item = new QListWidgetItem(label, m_metaDataList); + item->setData(Qt::UserRole, key); + const bool show = settings.readEntry(key, true); + item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + } + + ++it; + } +} + +#include "metadataconfigurationdialog_p.moc" diff --git a/src/panels/information/metadataconfigurationdialog_p.h b/src/panels/information/metadataconfigurationdialog_p.h new file mode 100644 index 000000000..b566bbde3 --- /dev/null +++ b/src/panels/information/metadataconfigurationdialog_p.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * 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 META_DATA_CONFIGURATION_DIALOG_H +#define META_DATA_CONFIGURATION_DIALOG_H + +#include +#include + +class QListWidget; + +/** + * @brief Dialog which allows to configure which meta data should be shown. + */ +class MetaDataConfigurationDialog : public KDialog +{ + Q_OBJECT + +public: + MetaDataConfigurationDialog(const KUrl& url, + QWidget* parent = 0, + Qt::WFlags flags = 0); + virtual ~MetaDataConfigurationDialog(); + +protected slots: + virtual void slotButtonClicked(int button); + +private: + void loadMetaData(); + +private: + KUrl m_url; + QListWidget* m_metaDataList; +}; + +#endif diff --git a/src/panels/information/metadatawidget.cpp b/src/panels/information/metadatawidget.cpp index 368d57e92..108728c79 100644 --- a/src/panels/information/metadatawidget.cpp +++ b/src/panels/information/metadatawidget.cpp @@ -35,6 +35,7 @@ #define DISABLE_NEPOMUK_LEGACY #include "commentwidget_p.h" + #include "metadataconfigurationdialog_p.h" #include "nepomukmassupdatejob_p.h" #include "taggingwidget_p.h" @@ -68,6 +69,12 @@ public: void removeMetaInfoRows(); void setRowVisible(QWidget* infoWidget, bool visible); + /** + * Parses the configuration file "kmetainformationrc" and + * updates the visibility of all rows. + */ + void updateRowsVisibility(); + void slotLoadingFinished(); void slotRatingChanged(unsigned int rating); void slotTagsChanged(const QList& tags); @@ -81,6 +88,7 @@ public: */ void startChangeDataJob(KJob* job); + QList m_fileItems; QList m_rows; QGridLayout* m_gridLayout; @@ -152,6 +160,7 @@ private: }; MetaDataWidget::Private::Private(MetaDataWidget* parent) : + m_fileItems(), m_rows(), m_gridLayout(0), m_typeInfo(0), @@ -207,6 +216,8 @@ MetaDataWidget::Private::Private(MetaDataWidget* parent) : m_loadFilesThread = new LoadFilesThread(&m_sharedData, &m_mutex); connect(m_loadFilesThread, SIGNAL(finished()), q, SLOT(slotLoadingFinished())); #endif + + updateRowsVisibility(); } MetaDataWidget::Private::~Private() @@ -260,6 +271,22 @@ void MetaDataWidget::Private::setRowVisible(QWidget* infoWidget, bool visible) } } +void MetaDataWidget::Private::updateRowsVisibility() +{ + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + setRowVisible(m_typeInfo, settings.readEntry("type", true)); + setRowVisible(m_sizeInfo, settings.readEntry("size", true)); + setRowVisible(m_modifiedInfo, settings.readEntry("modified", true)); + setRowVisible(m_ownerInfo, settings.readEntry("owner", true)); + setRowVisible(m_permissionsInfo, settings.readEntry("permissions", true)); +#ifdef HAVE_NEPOMUK + setRowVisible(m_ratingWidget, settings.readEntry("rating", true)); + setRowVisible(m_taggingWidget, settings.readEntry("tagging", true)); + setRowVisible(m_commentWidget, settings.readEntry("comment", true)); +#endif +} + void MetaDataWidget::Private::slotLoadingFinished() { #ifdef HAVE_NEPOMUK @@ -302,6 +329,8 @@ void MetaDataWidget::Private::slotLoadingFinished() delete m_rows[i].infoWidget; m_rows.pop_back(); } + + emit q->loadingFinished(); #endif } @@ -313,9 +342,8 @@ void MetaDataWidget::Private::slotRatingChanged(unsigned int rating) Nepomuk::MassUpdateJob::rateResources(m_sharedData.files.values(), rating); locker.unlock(); startChangeDataJob(job); -#else - Q_UNUSED(rating); #endif + emit q->ratingChanged(rating); } void MetaDataWidget::Private::slotTagsChanged(const QList& tags) @@ -326,9 +354,8 @@ void MetaDataWidget::Private::slotTagsChanged(const QList& tags) Nepomuk::MassUpdateJob::tagResources(m_sharedData.files.values(), tags); locker.unlock(); startChangeDataJob(job); -#else - Q_UNUSED(tags); #endif + emit q->tagsChanged(tags); } void MetaDataWidget::Private::slotCommentChanged(const QString& comment) @@ -339,9 +366,8 @@ void MetaDataWidget::Private::slotCommentChanged(const QString& comment) Nepomuk::MassUpdateJob::commentResources(m_sharedData.files.values(), comment); locker.unlock(); startChangeDataJob(job); -#else - Q_UNUSED(comment); #endif + emit q->commentChanged(comment); } void MetaDataWidget::Private::slotMetaDataUpdateDone() @@ -434,7 +460,7 @@ void MetaDataWidget::Private::LoadFilesThread::run() QHash::const_iterator it = properties.constBegin(); while (it != properties.constEnd()) { Nepomuk::Types::Property prop(it.key()); - if (true /*settings.readEntry(prop.name(), true)*/) { + if (settings.readEntry(prop.name(), true)) { // TODO #1: use Nepomuk::formatValue(res, prop) if available // instead of it.value().toString() // TODO #2: using tunedLabel() is a workaround for KDE 4.3 until @@ -468,7 +494,7 @@ void MetaDataWidget::Private::LoadFilesThread::initMetaInfoSettings(KConfigGroup "asText", "contentSize", "depth", "fileExtension", "fileName", "fileSize", "isPartOf", "mimetype", "name", "parentUrl", "plainTextContent", "sourceModified", - "size", "url", + "url", 0 // mandatory last entry }; @@ -537,6 +563,8 @@ void MetaDataWidget::setItem(const KFileItem& item) void MetaDataWidget::setItems(const KFileItemList& items) { + d->m_fileItems = items; + if (items.count() > 1) { // calculate the size of all items and show this // information to the user @@ -564,4 +592,55 @@ void MetaDataWidget::setItems(const KFileItemList& items) #endif } +void MetaDataWidget::openConfigurationDialog() +{ +#ifdef HAVE_NEPOMUK + if (d->m_fileItems.count() > 1) { + return; + } + const KUrl url = d->m_fileItems[0].nepomukUri(); + if (!url.isValid()) { + return; + } + + MetaDataConfigurationDialog dialog(url, this, Qt::Dialog); + KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk MetaDataConfigurationDialog"); + dialog.restoreDialogSize(dialogConfig); + if (dialog.exec() == KDialog::Accepted) { + d->updateRowsVisibility(); + } + dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent); +#endif +} + +unsigned int MetaDataWidget::rating() const +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker(&d->m_mutex); + return d->m_sharedData.rating; +#else + return 0; +#endif +} + +const QList MetaDataWidget::tags() const +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker(&d->m_mutex); + return d->m_sharedData.tags; +#else + return QList(); +#endif +} + +QString MetaDataWidget::comment() const +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker(&d->m_mutex); + return d->m_sharedData.comment; +#else + return QString(); +#endif +} + #include "metadatawidget.moc" diff --git a/src/panels/information/metadatawidget.h b/src/panels/information/metadatawidget.h index f12ce65d9..f1746030c 100644 --- a/src/panels/information/metadatawidget.h +++ b/src/panels/information/metadatawidget.h @@ -40,7 +40,13 @@ class KFileItem; class KFileItemList; /** - * @brief + * @brief Shows the meta data of one or more file items. + * + * Meta data like name, size, rating, comment, ... are + * shown as several rows containing a description and + * the meta data value. It is possible for the user + * to change specific meta data like rating, tags and + * comment. */ class MetaDataWidget : public QWidget { @@ -50,9 +56,83 @@ public: explicit MetaDataWidget(QWidget* parent = 0); virtual ~MetaDataWidget(); + /** + * Triggers the asynchronous loading of the meta data + * for the file item \p item. Connect to the signal + * loadingFinished() to be able to read the meta + * data. + */ void setItem(const KFileItem& item); + + /** + * Triggers the asynchronous loading of the meta data + * for the file items \p items. Connect to the signal + * loadingFinished() to be able to read the meta + * data. + */ void setItems(const KFileItemList& items); + /** + * Opens a dialog which allows to configure the visibility + * of meta data. + */ + void openConfigurationDialog(); + + /** + * Returns the rating for the currently set item(s). It is required + * to wait for the signal loadingFinished() or ratingChanged() + * to get a valid result. + */ + unsigned int rating() const; + + /** + * Returns the tags for the currently set item(s). It is required + * to wait for the signal loadingFinished() or tagsChanged() + * to get a valid result. + */ + const QList tags() const; + + /** + * Returns the comment for the currently set item(s). It is required + * to wait for the signal loadingFinished() or commentChanged() + * to get a valid result. + */ + QString comment() const; + +signals: + /** + * Is emitted if the loading of the meta data has been finished + * after invoking MetaDataWidget::setItem() or MetaDataWidget::setItems(). + */ + void loadingFinished(); + + /** + * Is emitted after the user has changed the rating. + * Note that the signal is not emitted if the rating has + * indirectly been changed by MetaDataWidget::setItem() or + * MetaDataWidget::setItems(). In this case connect to + * the signal loadingFinished() instead. + */ + void ratingChanged(const int rating); + + /** + * Is emitted after the user has changed the tags. + * Note that the signal is not emitted if the rating has + * indirectly been changed by MetaDataWidget::setItem() or + * MetaDataWidget::setItems(). In this case connect to + * the signal loadingFinished() instead. + */ + void tagsChanged(const QList& tags); + + /** + * Is emitted after the user has changed the comment. + * Note that the signal is not emitted if the rating has + * indirectly been changed by MetaDataWidget::setItem() or + * MetaDataWidget::setItems(). In this case connect to + * the signal loadingFinished() instead. + */ + void commentChanged(const QString& comment); + private: class Private; Private* d; diff --git a/src/panels/information/taggingwidget.cpp b/src/panels/information/taggingwidget.cpp index caba8fd41..057b17e55 100644 --- a/src/panels/information/taggingwidget.cpp +++ b/src/panels/information/taggingwidget.cpp @@ -82,8 +82,7 @@ void TaggingWidget::slotLinkActivated(const QString& link) Q_UNUSED(link); EditTagsDialog dialog(m_tags, this, Qt::Dialog); - KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "EditTagsDialog"); + KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk EditTagsDialog"); dialog.restoreDialogSize(dialogConfig); if (dialog.exec() == QDialog::Accepted) { -- 2.47.3