1 /*****************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at> *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License version 2 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Library General Public License for more details. *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *****************************************************************************/
20 #include "kmetadatawidget.h"
23 #include <kconfiggroup.h>
24 #include <kfileitem.h>
25 #include <kglobalsettings.h>
28 #include "kmetadatamodel.h"
29 #include "knfotranslator_p.h"
32 #include <QFontMetrics>
33 #include <QGridLayout>
38 #include <config-nepomuk.h>
40 #define DISABLE_NEPOMUK_LEGACY
42 #include "kcommentwidget_p.h"
43 #include "ktaggingwidget_p.h"
45 #include <nepomuk/kratingwidget.h>
46 #include <nepomuk/resource.h>
47 #include <nepomuk/resourcemanager.h>
48 #include <nepomuk/property.h>
49 #include <nepomuk/tag.h>
50 #include "nepomukmassupdatejob_p.h"
53 #include <QSpacerItem>
62 class KMetaDataWidget::Private
68 QLabel
* defaultValueWidget
;
69 QWidget
* customValueWidget
;
72 Private(KMetaDataWidget
* parent
);
75 void addRow(QLabel
* label
, QLabel
* valueWidget
);
76 void setCustomValueWidget(int rowIndex
, QWidget
* valueWidget
);
77 void setRowVisible(QWidget
* valueWidget
, bool visible
);
80 * Initializes the configuration file "kmetainformationrc"
81 * with proper default settings for the first start in
82 * an uninitialized environment.
84 void initMetaInfoSettings();
87 * Parses the configuration file "kmetainformationrc" and
88 * updates the visibility of all rows.
90 void updateRowsVisibility();
92 void slotLoadingFinished();
94 void slotRatingChanged(unsigned int rating
);
95 void slotTagsChanged(const QList
<Nepomuk::Tag
>& tags
);
96 void slotCommentChanged(const QString
& comment
);
98 void slotMetaDataUpdateDone();
99 void slotLinkActivated(const QString
& link
);
101 void slotTagActivated(const Nepomuk::Tag
& tag
);
105 * Disables the metadata widget and starts the job that
106 * changes the meta data asynchronously. After the job
107 * has been finished, the metadata widget gets enabled again.
109 void startChangeDataJob(KJob
* job
);
111 QList
<KUrl
> sortedKeys(const QHash
<KUrl
, Nepomuk::Variant
>& data
) const;
112 QList
<Nepomuk::Resource
> resourceList() const;
117 bool m_nepomukActivated
;
119 MetaDataTypes m_visibleDataTypes
;
120 QList
<KFileItem
> m_fileItems
;
123 KMetaDataModel
* m_model
;
125 QGridLayout
* m_gridLayout
;
130 QLabel
* m_modifiedInfo
;
132 QLabel
* m_permissionsInfo
;
135 KRatingWidget
* m_ratingWidget
;
136 KTaggingWidget
* m_taggingWidget
;
137 KCommentWidget
* m_commentWidget
;
141 KMetaDataWidget
* const q
;
144 KMetaDataWidget::Private::Private(KMetaDataWidget
* parent
) :
147 m_nepomukActivated(false),
149 m_visibleDataTypes(TypeData
| SizeData
| ModifiedData
| OwnerData
|
150 PermissionsData
| RatingData
| TagsData
| CommentData
),
160 m_permissionsInfo(0),
168 const QFontMetrics
fontMetrics(KGlobalSettings::smallestReadableFont());
170 m_gridLayout
= new QGridLayout(parent
);
171 m_gridLayout
->setMargin(0);
172 m_gridLayout
->setSpacing(fontMetrics
.height() / 4);
174 m_typeInfo
= new QLabel(parent
);
175 m_sizeLabel
= new QLabel(parent
);
176 m_sizeInfo
= new QLabel(parent
);
177 m_modifiedInfo
= new QLabel(parent
);
178 m_ownerInfo
= new QLabel(parent
);
179 m_permissionsInfo
= new QLabel(parent
);
182 m_nepomukActivated
= (Nepomuk::ResourceManager::instance()->init() == 0);
183 if (m_nepomukActivated
) {
184 m_ratingWidget
= new KRatingWidget(parent
);
185 m_ratingWidget
->setFixedHeight(fontMetrics
.height());
186 const Qt::Alignment align
= (parent
->layoutDirection() == Qt::LeftToRight
) ?
187 Qt::AlignLeft
: Qt::AlignRight
;
188 m_ratingWidget
->setAlignment(align
);
189 connect(m_ratingWidget
, SIGNAL(ratingChanged(unsigned int)),
190 q
, SLOT(slotRatingChanged(unsigned int)));
192 m_taggingWidget
= new KTaggingWidget(parent
);
193 connect(m_taggingWidget
, SIGNAL(tagsChanged(const QList
<Nepomuk::Tag
>&)),
194 q
, SLOT(slotTagsChanged(const QList
<Nepomuk::Tag
>&)));
195 connect(m_taggingWidget
, SIGNAL(tagActivated(const Nepomuk::Tag
&)),
196 q
, SLOT(slotTagActivated(const Nepomuk::Tag
&)));
198 m_commentWidget
= new KCommentWidget(parent
);
199 connect(m_commentWidget
, SIGNAL(commentChanged(const QString
&)),
200 q
, SLOT(slotCommentChanged(const QString
&)));
204 initMetaInfoSettings();
207 KMetaDataWidget::Private::~Private()
211 void KMetaDataWidget::Private::addRow(QLabel
* label
, QLabel
* valueWidget
)
215 row
.defaultValueWidget
= valueWidget
;
216 row
.customValueWidget
= 0;
219 const QFont smallFont
= KGlobalSettings::smallestReadableFont();
220 // use a brighter color for the label and a small font size
221 QPalette palette
= label
->palette();
222 const QPalette::ColorRole role
= q
->foregroundRole();
223 QColor textColor
= palette
.color(role
);
224 textColor
.setAlpha(128);
225 palette
.setColor(role
, textColor
);
226 label
->setPalette(palette
);
227 label
->setForegroundRole(role
);
228 label
->setFont(smallFont
);
229 label
->setWordWrap(true);
230 label
->setAlignment(Qt::AlignTop
| Qt::AlignRight
);
232 valueWidget
->setForegroundRole(role
);
233 valueWidget
->setFont(smallFont
);
234 valueWidget
->setWordWrap(true);
235 valueWidget
->setAlignment(Qt::AlignTop
| Qt::AlignLeft
);
237 // add the row to grid layout
238 const int rowIndex
= m_rows
.count() - 1;
239 m_gridLayout
->addWidget(label
, rowIndex
, 0, Qt::AlignRight
);
240 const int spacerWidth
= QFontMetrics(smallFont
).size(Qt::TextSingleLine
, " ").width();
241 m_gridLayout
->addItem(new QSpacerItem(spacerWidth
, 1), rowIndex
, 1);
242 m_gridLayout
->addWidget(valueWidget
, rowIndex
, 2, Qt::AlignLeft
);
245 void KMetaDataWidget::Private::setCustomValueWidget(int rowIndex
, QWidget
* valueWidget
)
247 Row
& row
= m_rows
[rowIndex
];
249 if (valueWidget
== 0) {
250 // remove current custom value widget from the grid and replace it
251 // by the default value widget
252 if (row
.customValueWidget
!= 0) {
253 row
.customValueWidget
->setVisible(false);
254 m_gridLayout
->removeWidget(row
.customValueWidget
);
256 m_gridLayout
->addWidget(row
.defaultValueWidget
, rowIndex
, 2, Qt::AlignLeft
);
257 row
.defaultValueWidget
->setVisible(true);
259 // remove the default value widget from the grid and replace it
260 // by the custom value widget
261 row
.defaultValueWidget
->setVisible(false);
262 m_gridLayout
->removeWidget(row
.defaultValueWidget
);
263 m_gridLayout
->addWidget(valueWidget
, rowIndex
, 2, Qt::AlignLeft
);
264 valueWidget
->setVisible(true);
267 row
.customValueWidget
= valueWidget
;
270 void KMetaDataWidget::Private::setRowVisible(QWidget
* valueWidget
, bool visible
)
272 foreach (const Row
& row
, m_rows
) {
273 const bool found
= (row
.defaultValueWidget
== valueWidget
) ||
274 (row
.customValueWidget
== valueWidget
);
276 row
.label
->setVisible(visible
);
277 if (row
.customValueWidget
!= 0) {
278 row
.customValueWidget
->setVisible(visible
);
279 row
.defaultValueWidget
->setVisible(false);
281 row
.defaultValueWidget
->setVisible(visible
);
288 void KMetaDataWidget::Private::initMetaInfoSettings()
290 const int currentVersion
= 3; // increase version, if the blacklist of disabled
291 // properties should be updated
293 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
294 if (config
.group("Misc").readEntry("version", 0) < currentVersion
) {
295 // The resource file is read the first time. Assure
296 // that some meta information is disabled per default.
299 config
.deleteGroup("Show");
300 KConfigGroup settings
= config
.group("Show");
302 static const char* const disabledProperties
[] = {
303 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment",
304 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize",
305 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends",
306 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf",
307 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified",
308 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType",
309 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent",
310 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url",
311 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate",
312 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels",
313 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName",
314 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue",
315 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue",
316 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime",
317 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash",
318 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength",
319 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm",
320 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings",
321 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make",
322 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode",
323 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model",
324 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation",
325 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance",
326 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#description",
327 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#hasTag",
328 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#lastModified",
329 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#numericRating",
330 "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
332 "kfileitem#permissions",
333 0 // mandatory last entry
336 for (int i
= 0; disabledProperties
[i
] != 0; ++i
) {
337 settings
.writeEntry(disabledProperties
[i
], false);
340 // mark the group as initialized
341 config
.group("Misc").writeEntry("version", currentVersion
);
345 void KMetaDataWidget::Private::updateRowsVisibility()
347 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
348 KConfigGroup settings
= config
.group("Show");
350 setRowVisible(m_typeInfo
,
351 (m_visibleDataTypes
& KMetaDataWidget::TypeData
) &&
352 settings
.readEntry("kfileitem#type", true));
354 // Cache in m_sizeVisible whether the size should be shown. This
355 // is necessary as the size is temporary hidden when the target
356 // file item is a directory.
357 m_sizeVisible
= (m_visibleDataTypes
& KMetaDataWidget::SizeData
) &&
358 settings
.readEntry("kfileitem#size", true);
359 bool visible
= m_sizeVisible
;
360 if (visible
&& (m_fileItems
.count() == 1)) {
361 // don't show the size information, if one directory is shown
362 const KFileItem item
= m_fileItems
.first();
363 visible
= !item
.isNull() && !item
.isDir();
365 setRowVisible(m_sizeInfo
, visible
);
367 setRowVisible(m_modifiedInfo
,
368 (m_visibleDataTypes
& KMetaDataWidget::ModifiedData
) &&
369 settings
.readEntry("kfileitem#modified", true));
371 setRowVisible(m_ownerInfo
,
372 (m_visibleDataTypes
& KMetaDataWidget::OwnerData
) &&
373 settings
.readEntry("kfileitem#owner", true));
375 setRowVisible(m_permissionsInfo
,
376 (m_visibleDataTypes
& KMetaDataWidget::PermissionsData
) &&
377 settings
.readEntry("kfileitem#permissions", true));
380 if (m_nepomukActivated
) {
381 setRowVisible(m_ratingWidget
,
382 (m_visibleDataTypes
& KMetaDataWidget::RatingData
) &&
383 settings
.readEntry("kfileitem#rating", true));
385 setRowVisible(m_taggingWidget
,
386 (m_visibleDataTypes
& KMetaDataWidget::TagsData
) &&
387 settings
.readEntry("kfileitem#tags", true));
389 setRowVisible(m_commentWidget
,
390 (m_visibleDataTypes
& KMetaDataWidget::CommentData
) &&
391 settings
.readEntry("kfileitem#comment", true));
396 void KMetaDataWidget::Private::slotLoadingFinished()
399 // Show the remaining meta information as text. The number
400 // of required rows may very. Existing rows are reused to
401 // prevent flickering.
402 int rowIndex
= m_fixedRowCount
;
404 const QHash
<KUrl
, Nepomuk::Variant
> data
= m_model
->data();
405 const QList
<KUrl
> keys
= sortedKeys(data
);
407 foreach (const KUrl
& key
, keys
) {
408 const Nepomuk::Variant value
= data
[key
];
409 const QString itemLabel
= q
->label(key
);
411 const bool valueApplied
= q
->setValue(key
, value
);
412 if (rowIndex
>= m_rows
.count()) {
413 // a new row must get created
414 QLabel
* label
= new QLabel(itemLabel
, q
);
415 QLabel
* valueWidget
= new QLabel(q
);
416 connect(valueWidget
, SIGNAL(linkActivated(QString
)),
417 q
, SLOT(slotLinkActivated(QString
)));
418 addRow(label
, valueWidget
);
421 Q_ASSERT(m_rows
[rowIndex
].label
!= 0);
422 Q_ASSERT(m_rows
[rowIndex
].defaultValueWidget
!= 0);
425 m_rows
[rowIndex
].label
->setText(itemLabel
);
429 setCustomValueWidget(rowIndex
, q
->valueWidget(key
));
431 QLabel
* valueWidget
= m_rows
[rowIndex
].defaultValueWidget
;
432 valueWidget
->setText(value
.toString());
433 setCustomValueWidget(rowIndex
, 0);
438 // remove rows that are not needed anymore
439 for (int i
= m_rows
.count() - 1; i
>= rowIndex
; --i
) {
440 delete m_rows
[i
].label
;
441 delete m_rows
[i
].defaultValueWidget
;
449 void KMetaDataWidget::Private::slotRatingChanged(unsigned int rating
)
452 Nepomuk::MassUpdateJob
* job
=
453 Nepomuk::MassUpdateJob::rateResources(resourceList(), rating
);
454 startChangeDataJob(job
);
460 void KMetaDataWidget::Private::slotTagsChanged(const QList
<Nepomuk::Tag
>& tags
)
463 m_taggingWidget
->setTags(tags
);
465 Nepomuk::MassUpdateJob
* job
=
466 Nepomuk::MassUpdateJob::tagResources(resourceList(), tags
);
467 startChangeDataJob(job
);
473 void KMetaDataWidget::Private::slotCommentChanged(const QString
& comment
)
476 Nepomuk::MassUpdateJob
* job
=
477 Nepomuk::MassUpdateJob::commentResources(resourceList(), comment
);
478 startChangeDataJob(job
);
484 void KMetaDataWidget::Private::slotTagActivated(const Nepomuk::Tag
& tag
)
487 emit q
->urlActivated(tag
.resourceUri());
493 void KMetaDataWidget::Private::slotMetaDataUpdateDone()
500 void KMetaDataWidget::Private::slotLinkActivated(const QString
& link
)
502 emit q
->urlActivated(KUrl(link
));
506 void KMetaDataWidget::Private::startChangeDataJob(KJob
* job
)
508 connect(job
, SIGNAL(result(KJob
*)),
509 q
, SLOT(slotMetaDataUpdateDone()));
510 q
->setEnabled(false); // no updates during execution
514 QList
<KUrl
> KMetaDataWidget::Private::sortedKeys(const QHash
<KUrl
, Nepomuk::Variant
>& data
) const
516 // Create a map, where the translated label prefixed with the
517 // sort priority acts as key. The data of each entry is the URI
518 // of the data. By this the all URIs are sorted by the sort priority
519 // and sub sorted by the translated labels.
520 QMap
<QString
, KUrl
> map
;
521 QHash
<KUrl
, Nepomuk::Variant
>::const_iterator hashIt
= data
.constBegin();
522 while (hashIt
!= data
.constEnd()) {
523 const KUrl uri
= hashIt
.key();
525 QString key
= q
->model()->group(uri
);
526 key
+= q
->label(uri
);
528 map
.insert(key
, uri
);
532 // Apply the URIs from the map to the list that will get returned.
533 // The list will then be alphabetically ordered by the translated labels of the URIs.
535 QMap
<QString
, KUrl
>::const_iterator mapIt
= map
.constBegin();
536 while (mapIt
!= map
.constEnd()) {
537 list
.append(mapIt
.value());
544 QList
<Nepomuk::Resource
> KMetaDataWidget::Private::resourceList() const
546 QList
<Nepomuk::Resource
> list
;
547 foreach (const KFileItem
& item
, m_fileItems
) {
548 const KUrl url
= item
.url();
549 list
.append(Nepomuk::Resource(url
));
555 KMetaDataWidget::KMetaDataWidget(QWidget
* parent
) :
561 KMetaDataWidget::~KMetaDataWidget()
566 void KMetaDataWidget::setItem(const KFileItem
& item
)
568 // update values for "type", "size", "modified",
569 // "owner" and "permissions" synchronously
570 d
->m_sizeLabel
->setText(i18nc("@label", "Size"));
572 d
->m_typeInfo
->setText(i18nc("@label", "Folder"));
573 d
->setRowVisible(d
->m_sizeInfo
, false);
575 d
->m_typeInfo
->setText(item
.mimeComment());
576 d
->m_sizeInfo
->setText(KIO::convertSize(item
.size()));
577 d
->setRowVisible(d
->m_sizeInfo
, d
->m_sizeVisible
);
579 d
->m_modifiedInfo
->setText(KGlobal::locale()->formatDateTime(item
.time(KFileItem::ModificationTime
), KLocale::FancyLongDate
));
580 d
->m_ownerInfo
->setText(item
.user());
581 d
->m_permissionsInfo
->setText(item
.permissionsString());
583 setItems(KFileItemList() << item
);
586 void KMetaDataWidget::setItems(const KFileItemList
& items
)
588 d
->m_fileItems
= items
;
589 if (d
->m_model
!= 0) {
590 d
->m_model
->setItems(items
);
593 if (items
.count() > 1) {
594 // calculate the size of all items and show this
595 // information to the user
596 d
->m_sizeLabel
->setText(i18nc("@label", "Total Size:"));
597 d
->setRowVisible(d
->m_sizeInfo
, d
->m_sizeVisible
);
599 quint64 totalSize
= 0;
600 foreach (const KFileItem
& item
, items
) {
601 if (!item
.isDir() && !item
.isLink()) {
602 totalSize
+= item
.size();
605 d
->m_sizeInfo
->setText(KIO::convertSize(totalSize
));
609 void KMetaDataWidget::setItem(const KUrl
& url
)
611 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
616 void KMetaDataWidget::setItems(const QList
<KUrl
>& urls
)
619 foreach (const KUrl
& url
, urls
) {
620 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
627 KFileItemList
KMetaDataWidget::items() const
629 return d
->m_fileItems
;
632 void KMetaDataWidget::setModel(KMetaDataModel
* model
)
634 if (d
->m_model
!= 0) {
635 disconnect(d
->m_model
, SIGNAL(loadingFinished()));
638 connect(d
->m_model
, SIGNAL(loadingFinished()), this, SLOT(slotLoadingFinished()));
641 KMetaDataModel
* KMetaDataWidget::model() const
646 void KMetaDataWidget::setReadOnly(bool readOnly
)
648 d
->m_readOnly
= readOnly
;
650 // TODO: encapsulate this code as part of a metadata-model for KDE 4.5
651 if (d
->m_taggingWidget
)
652 d
->m_taggingWidget
->setReadOnly(readOnly
);
653 if (d
->m_commentWidget
)
654 d
->m_commentWidget
->setReadOnly(readOnly
);
658 bool KMetaDataWidget::isReadOnly() const
660 return d
->m_readOnly
;
663 void KMetaDataWidget::setVisibleDataTypes(MetaDataTypes data
)
665 d
->m_visibleDataTypes
= data
;
666 d
->updateRowsVisibility();
669 KMetaDataWidget::MetaDataTypes
KMetaDataWidget::visibleDataTypes() const
671 return d
->m_visibleDataTypes
;
674 QSize
KMetaDataWidget::sizeHint() const
676 const int fixedWidth
= 200;
678 int height
= d
->m_gridLayout
->margin() * 2 +
679 d
->m_gridLayout
->spacing() * (d
->m_rows
.count() - 1);
681 foreach (const Private::Row
& row
, d
->m_rows
) {
682 QWidget
* valueWidget
= row
.defaultValueWidget
;
683 if (valueWidget
!= 0) {
684 if (row
.customValueWidget
!= 0) {
685 valueWidget
= row
.customValueWidget
;
688 int rowHeight
= valueWidget
->heightForWidth(fixedWidth
/ 2);
689 if (rowHeight
<= 0) {
690 rowHeight
= valueWidget
->sizeHint().height();
696 return QSize(fixedWidth
, height
);
700 QString
KMetaDataWidget::label(const KUrl
& metaDataUri
) const
703 const QString uri
= metaDataUri
.url();
704 if (uri
== QLatin1String("kfileitem#rating")) {
705 label
= i18nc("@label", "Rating");
706 } else if (uri
== QLatin1String("kfileitem#tags")) {
707 label
= i18nc("@label", "Tags");
708 } else if (uri
== QLatin1String("kfileitem#comment")) {
709 label
= i18nc("@label", "Comment");
711 label
= KNfoTranslator::instance().translation(metaDataUri
);
717 QWidget
* KMetaDataWidget::valueWidget(const KUrl
& metaDataUri
) const
721 if (d
->m_nepomukActivated
) {
722 const QString uri
= metaDataUri
.url();
723 if (uri
== QLatin1String("kfileitem#rating")) {
724 widget
= d
->m_ratingWidget
;
725 } else if (uri
== QLatin1String("kfileitem#tags")) {
726 widget
= d
->m_taggingWidget
;
727 } else if (uri
== QLatin1String("kfileitem#comment")) {
728 widget
= d
->m_commentWidget
;
735 bool KMetaDataWidget::setValue(const KUrl
& metaDataUri
, const Nepomuk::Variant
& value
)
737 if (d
->m_nepomukActivated
) {
738 QWidget
* widget
= valueWidget(metaDataUri
);
739 if (widget
== d
->m_ratingWidget
) {
740 d
->m_ratingWidget
->setRating(value
.toInt());
744 if (widget
== d
->m_taggingWidget
) {
745 QList
<Nepomuk::Variant
> variants
= value
.toVariantList();
746 QList
<Nepomuk::Tag
> tags
;
747 foreach (const Nepomuk::Variant
& variant
, variants
) {
748 const Nepomuk::Resource resource
= variant
.toResource();
749 tags
.append(static_cast<Nepomuk::Tag
>(resource
));
751 d
->m_taggingWidget
->setTags(tags
);
755 if (widget
== d
->m_commentWidget
) {
756 d
->m_commentWidget
->setText(value
.toString());
764 bool KMetaDataWidget::event(QEvent
* event
)
766 if (event
->type() == QEvent::Polish
) {
767 // The adding of rows is not done in the constructor. This allows the
768 // client of KMetaDataWidget to set a proper foreground role which
769 // will be respected by the rows.
771 d
->addRow(new QLabel(i18nc("@label file type", "Type"), this), d
->m_typeInfo
);
772 d
->addRow(d
->m_sizeLabel
, d
->m_sizeInfo
);
773 d
->addRow(new QLabel(i18nc("@label", "Modified"), this), d
->m_modifiedInfo
);
774 d
->addRow(new QLabel(i18nc("@label", "Owner"), this), d
->m_ownerInfo
);
775 d
->addRow(new QLabel(i18nc("@label", "Permissions"), this), d
->m_permissionsInfo
);
777 // The current number of rows represents meta data, that will be shown for
778 // all files. Dynamic meta data will be appended after those rows (see
779 // slotLoadingFinished()).
780 d
->m_fixedRowCount
= d
->m_rows
.count();
782 d
->updateRowsVisibility();
785 return QWidget::event(event
);
788 #include "kmetadatawidget.moc"