KCommentWidget::KCommentWidget(QWidget* parent) :
QWidget(parent),
+ m_readOnly(false),
m_label(0),
m_comment()
{
void KCommentWidget::setText(const QString& comment)
{
- if (comment.isEmpty()) {
- m_label->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
+ QString text;
+ if (comment.isEmpty()) {
+ if (m_readOnly) {
+ text = "-";
+ } else {
+ text = "<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>";
+ }
} else {
- m_label->setText("<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
+ if (m_readOnly) {
+ text = comment;
+ } else {
+ text = "<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>";
+ }
}
+
+ m_label->setText(text);
m_comment = comment;
}
return m_comment;
}
+void KCommentWidget::setReadOnly(bool readOnly)
+{
+ m_readOnly = readOnly;
+ setText(m_comment);
+}
+
+bool KCommentWidget::isReadOnly() const
+{
+ return m_readOnly;
+}
+
void KCommentWidget::slotLinkActivated(const QString& link)
{
KDialog dialog(this, Qt::Dialog);
void setText(const QString& comment);
QString text() const;
+ /**
+ * If set to true, the comment cannot be changed by the user.
+ * Per default read-only is disabled.
+ */
+ // TODO: provide common interface class for metadatawidgets
+ void setReadOnly(bool readOnly);
+ bool isReadOnly() const;
+
signals:
void commentChanged(const QString& comment);
void slotLinkActivated(const QString& link);
private:
+ bool m_readOnly;
QLabel* m_label;
QString m_comment;
};
#include <kglobal.h>
#include <klocale.h>
-#include <nepomuk/variant.h>
#include <nepomuk/resource.h>
KLoadMetaDataThread::KLoadMetaDataThread() :
m_rating(0),
m_comment(),
m_tags(),
- m_metaInfoLabels(),
- m_metaInfoValues(),
+ m_items(),
m_files(),
m_urls(),
m_canceled(false)
if (first && (m_urls.count() == 1)) {
// TODO: show shared meta information instead
// of not showing anything on multiple selections
- QHash<QUrl, Nepomuk::Variant> properties = file.properties();
- QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
- while (it != properties.constEnd()) {
+ QHash<QUrl, Nepomuk::Variant> variants = file.properties();
+ QHash<QUrl, Nepomuk::Variant>::const_iterator it = variants.constBegin();
+ while (it != variants.constEnd()) {
Nepomuk::Types::Property prop(it.key());
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 (4.4?) until
- // we get translated labels
- m_metaInfoLabels.append(tunedLabel(prop.label()));
- m_metaInfoValues.append(formatValue(it.value()));
+ Item item;
+ item.name = prop.name();
+ item.label = tunedLabel(prop.label());
+ item.value = formatValue(it.value());
+ m_items.append(item);
}
++it;
}
return m_tags;
}
-QList<QString> KLoadMetaDataThread::metaInfoLabels() const
+QList<KLoadMetaDataThread::Item> KLoadMetaDataThread::items() const
{
- return m_metaInfoLabels;
-}
-
-QList<QString> KLoadMetaDataThread::metaInfoValues() const
-{
- return m_metaInfoValues;
+ return m_items;
}
QMap<KUrl, Nepomuk::Resource> KLoadMetaDataThread::files() const
deleteLater();
}
-QString KLoadMetaDataThread::tunedLabel(const QString& label) const
+QString KLoadMetaDataThread::tunedLabel(const QString& label) const
{
QString tunedLabel;
const int labelLength = label.length();
return tunedLabel + ':';
}
-
-// This is a short hack until we have a proper formatting facility in Nepomuk
-// here we simply handle the most common formatting situations that do not look nice
-// when using Nepomuk::Variant::toString()
-QString KLoadMetaDataThread::formatValue(const Nepomuk::Variant& value)
+QString KLoadMetaDataThread::formatValue(const Nepomuk::Variant& value)
{
if (value.isDateTime()) {
- return KGlobal::locale()->formatDateTime( value.toDateTime(), KLocale::FancyLongDate );
- }
- else if (value.isResource()) {
+ return KGlobal::locale()->formatDateTime(value.toDateTime(), KLocale::FancyLongDate);
+ } else if (value.isResource()) {
return value.toResource().genericLabel();
- }
- else if (value.isResourceList()) {
- QStringList ll;
+ } else if (value.isResourceList()) {
+ QStringList list;
foreach(const Nepomuk::Resource& res, value.toResourceList()) {
- ll << res.genericLabel();
+ list << res.genericLabel();
}
- return ll.join(QLatin1String(";\n"));
- }
- else {
+ return list.join(QLatin1String(";\n"));
+ } else {
return value.toString();
}
}
#define DISABLE_NEPOMUK_LEGACY
#include <nepomuk/property.h>
#include <nepomuk/tag.h>
+#include <nepomuk/variant.h>
#include <kurl.h>
#include <QList>
Q_OBJECT
public:
+ struct Item
+ {
+ QString name;
+ QString label;
+ QString value;
+ };
+
KLoadMetaDataThread();
virtual ~KLoadMetaDataThread();
int rating() const;
QString comment() const;
QList<Nepomuk::Tag> tags() const;
- QList<QString> metaInfoLabels() const;
- QList<QString> metaInfoValues() const;
+ QList<Item> items() const;
QMap<KUrl, Nepomuk::Resource> files() const;
private slots:
private:
/**
- * Assures that the settings for the meta information
- * are initialized with proper default values.
- */
- void initMetaInfoSettings(KConfigGroup& group);
-
- /**
- * Temporary helper method for KDE 4.3 as we currently don't get
- * translated labels for Nepmok literals: Replaces camelcase labels
+ * Temporary helper method there is a way to get translated
+ * labels for Nepmok literals: Replaces camelcase labels
* like "fileLocation" by "File Location:".
*/
QString tunedLabel(const QString& label) const;
/**
- * Temporary helper method which tries to pretty print
- * values.
+ * Temporary helper method until there is a proper formatting facility in Nepomuk.
+ * Here we simply handle the most common formatting situations that do not look nice
+ * when using Nepomuk::Variant::toString().
*/
QString formatValue(const Nepomuk::Variant& value);
int m_rating;
QString m_comment;
QList<Nepomuk::Tag> m_tags;
- QList<QString> m_metaInfoLabels;
- QList<QString> m_metaInfoValues;
+ QList<Item> m_items;
QMap<KUrl, Nepomuk::Resource> m_files;
KUrl::List m_urls;
*/
void startChangeDataJob(KJob* job);
- bool m_isSizeVisible;
+ bool m_sizeVisible;
+ bool m_readOnly;
MetaDataTypes m_visibleDataTypes;
QList<KFileItem> m_fileItems;
QList<Row> m_rows;
};
KMetaDataWidget::Private::Private(KMetaDataWidget* parent) :
- m_isSizeVisible(true),
+ m_sizeVisible(true),
+ m_readOnly(false),
m_visibleDataTypes(TypeData | SizeData | ModifiedData | OwnerData |
PermissionsData | RatingData | TagsData | CommentData),
m_fileItems(),
(m_visibleDataTypes & KMetaDataWidget::TypeData) &&
settings.readEntry("type", true));
- // Cache in m_isSizeVisible whether the size should be shown. This
+ // Cache in m_sizeVisible whether the size should be shown. This
// is necessary as the size is temporary hidden when the target
// file item is a directory.
- m_isSizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) &&
+ m_sizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) &&
settings.readEntry("size", true);
- setRowVisible(m_sizeInfo, m_isSizeVisible);
+ setRowVisible(m_sizeInfo, m_sizeVisible);
setRowVisible(m_modifiedInfo,
(m_visibleDataTypes & KMetaDataWidget::ModifiedData) &&
const int rowCount = m_rows.count();
Q_ASSERT(rowCount >= index);
- Q_ASSERT(m_loadMetaDataThread->metaInfoLabels().count() == m_loadMetaDataThread->metaInfoValues().count());
- const int metaInfoCount = m_loadMetaDataThread->metaInfoLabels().count();
- for (int i = 0; i < metaInfoCount; ++i) {
- const QList<QString> metaInfoLabels = m_loadMetaDataThread->metaInfoLabels();
- const QList<QString> metaInfoValues = m_loadMetaDataThread->metaInfoValues();
+ const QList<KLoadMetaDataThread::Item> items = m_loadMetaDataThread->items();
+ foreach (const KLoadMetaDataThread::Item& item, items) {
if (index < rowCount) {
// adjust texts of the current row
- m_rows[index].label->setText(metaInfoLabels[i]);
+ m_rows[index].label->setText(item.label);
QLabel* infoValueLabel = qobject_cast<QLabel*>(m_rows[index].infoWidget);
Q_ASSERT(infoValueLabel != 0);
- infoValueLabel->setText(metaInfoValues[i]);
+ infoValueLabel->setText(item.value);
} else {
// create new row
- QLabel* infoLabel = new QLabel(metaInfoLabels[i], q);
- QLabel* infoValue = new QLabel(metaInfoValues[i], q);
+ QLabel* infoLabel = new QLabel(item.label, q);
+ QLabel* infoValue = new QLabel(item.value, q);
addRow(infoLabel, infoValue);
}
++index;
}
- if (metaInfoCount > 0) {
+ if (items.count() > 0) {
--index;
}
// remove rows that are not needed anymore
- for (int i = rowCount - 1; i > index; --i) {
+ for (int i = m_rows.count() - 1; i > index; --i) {
delete m_rows[i].label;
delete m_rows[i].infoWidget;
m_rows.pop_back();
} else {
d->m_typeInfo->setText(item.mimeComment());
d->m_sizeInfo->setText(KIO::convertSize(item.size()));
- d->setRowVisible(d->m_sizeInfo, d->m_isSizeVisible);
+ d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
}
d->m_modifiedInfo->setText(KGlobal::locale()->formatDateTime(item.time(KFileItem::ModificationTime), KLocale::FancyLongDate));
d->m_ownerInfo->setText(item.user());
// calculate the size of all items and show this
// information to the user
d->m_sizeLabel->setText(i18nc("@label", "Total Size:"));
- d->setRowVisible(d->m_sizeInfo, d->m_isSizeVisible);
+ d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
quint64 totalSize = 0;
foreach (const KFileItem& item, items) {
return d->m_fileItems;
}
+void KMetaDataWidget::setReadOnly(bool readOnly)
+{
+ d->m_readOnly = readOnly;
+#ifdef HAVE_NEPOMUK
+ // TODO: encapsulate this code as part of a metadata-model for KDE 4.5
+ d->m_taggingWidget->setReadOnly(readOnly);
+ d->m_commentWidget->setReadOnly(readOnly);
+#endif
+}
+
+bool KMetaDataWidget::isReadOnly() const
+{
+ return d->m_readOnly;
+}
+
void KMetaDataWidget::setVisibleDataTypes(MetaDataTypes data)
{
d->m_visibleDataTypes = data;
KFileItemList items() const;
+ /**
+ * If set to true, data like comment, tag or rating cannot be changed by the user.
+ * Per default read-only is disabled.
+ */
+ void setReadOnly(bool readOnly);
+ bool isReadOnly() const;
+
/**
* Specifies which kind of data types should be shown (@see KMetaDataWidget::Data).
* Example: metaDataWidget->setVisibleDataTypes(KMetaDataWidget::TypeData | KMetaDataWidget::ModifiedData);
KTaggingWidget::KTaggingWidget(QWidget* parent) :
QWidget(parent),
+ m_readOnly(false),
m_label(0),
m_tags(),
m_tagsText()
first = false;
}
+ QString text;
if (m_tagsText.isEmpty()) {
- m_label->setText("<a href=\"addTags\">" + i18nc("@label", "Add Tags...") + "</a>");
+ if (m_readOnly) {
+ text = "-";
+ } else {
+ text = "<a href=\"addTags\">" + i18nc("@label", "Add Tags...") + "</a>";
+ }
} else {
- m_label->setText("<p>" + m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a></p>");
+ if (m_readOnly) {
+ text = m_tagsText;
+ } else {
+ text = "<p>" + m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a></p>";
+ }
}
+ m_label->setText(text);
}
QList<Nepomuk::Tag> KTaggingWidget::tags() const
return m_tags;
}
+void KTaggingWidget::setReadOnly(bool readOnly)
+{
+ m_readOnly = readOnly;
+ setTags(m_tags);
+}
+
+bool KTaggingWidget::isReadOnly() const
+{
+ return m_readOnly;
+}
+
void KTaggingWidget::slotLinkActivated(const QString& link)
{
Q_UNUSED(link);
void setTags(const QList<Nepomuk::Tag>& tags);
QList<Nepomuk::Tag> tags() const;
+ /**
+ * If set to true, the tags cannot be changed by the user.
+ * Per default read-only is disabled.
+ */
+ // TODO: provide common interface class for metadatawidgets
+ void setReadOnly(bool readOnly);
+ bool isReadOnly() const;
+
signals:
void tagsChanged(const QList<Nepomuk::Tag>& tags);
void slotLinkActivated(const QString& link);
private:
+ bool m_readOnly;
QLabel* m_label;
QList<Nepomuk::Tag> m_tags;
QString m_tagsText;
KMetaDataWidget* metaDataWidget = new KMetaDataWidget(tipContent);
metaDataWidget->setItem(m_item);
metaDataWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ metaDataWidget->setReadOnly(true);
QHBoxLayout* tipLayout = new QHBoxLayout(tipContent);
tipLayout->setMargin(0);