${dolphin_SRCS}
panels/information/commentwidget.cpp
panels/information/edittagsdialog.cpp
+ panels/information/metadataconfigurationdialog.cpp
panels/information/nepomukmassupdatejob.cpp
panels/information/taggingwidget.cpp
)
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) {
<label>Show preview</label>
<default>true</default>
</entry>
- <entry name="showRating" type="Bool">
- <label>Show rating</label>
- <default>true</default>
- </entry>
- <entry name="showComment" type="Bool">
- <label>Show comment</label>
- <default>true</default>
- </entry>
- <entry name="showTags" type="Bool">
- <label>Show tags</label>
- <default>true</default>
- </entry>
</group>
</kcfg>
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<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(m_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());
- 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.
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);
}
--- /dev/null
+/***************************************************************************
+ * 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 "metadataconfigurationdialog_p.h"
+
+#include "metadatawidget.h"
+
+#include <klocale.h>
+
+#define DISABLE_NEPOMUK_LEGACY
+#include <Nepomuk/Resource>
+#include <Nepomuk/Types/Property>
+#include <Nepomuk/Variant>
+
+#include <QLabel>
+#include <QListWidget>
+#include <QVBoxLayout>
+
+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<QString, QString> FixedItem;
+ QList<FixedItem> 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<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.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"
--- /dev/null
+/***************************************************************************
+ * 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 META_DATA_CONFIGURATION_DIALOG_H
+#define META_DATA_CONFIGURATION_DIALOG_H
+
+#include <kdialog.h>
+#include <kurl.h>
+
+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
#define DISABLE_NEPOMUK_LEGACY
#include "commentwidget_p.h"
+ #include "metadataconfigurationdialog_p.h"
#include "nepomukmassupdatejob_p.h"
#include "taggingwidget_p.h"
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<Nepomuk::Tag>& tags);
*/
void startChangeDataJob(KJob* job);
+ QList<KFileItem> m_fileItems;
QList<Row> m_rows;
QGridLayout* m_gridLayout;
};
MetaDataWidget::Private::Private(MetaDataWidget* parent) :
+ m_fileItems(),
m_rows(),
m_gridLayout(0),
m_typeInfo(0),
m_loadFilesThread = new LoadFilesThread(&m_sharedData, &m_mutex);
connect(m_loadFilesThread, SIGNAL(finished()), q, SLOT(slotLoadingFinished()));
#endif
+
+ updateRowsVisibility();
}
MetaDataWidget::Private::~Private()
}
}
+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
delete m_rows[i].infoWidget;
m_rows.pop_back();
}
+
+ emit q->loadingFinished();
#endif
}
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<Nepomuk::Tag>& 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)
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()
QHash<QUrl, Nepomuk::Variant>::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
"asText", "contentSize", "depth", "fileExtension",
"fileName", "fileSize", "isPartOf", "mimetype", "name",
"parentUrl", "plainTextContent", "sourceModified",
- "size", "url",
+ "url",
0 // mandatory last entry
};
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
#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<Nepomuk::Tag> MetaDataWidget::tags() const
+{
+#ifdef HAVE_NEPOMUK
+ QMutexLocker locker(&d->m_mutex);
+ return d->m_sharedData.tags;
+#else
+ return QList<Nepomuk::Tag>();
+#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"
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
{
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<Nepomuk::Tag> 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<Nepomuk::Tag>& 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;
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) {