]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/kmetadatawidget.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / panels / information / kmetadatawidget.cpp
1 /*****************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * *
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. *
8 * *
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. *
13 * *
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 *****************************************************************************/
19
20 #include "kmetadatawidget.h"
21
22 #include <kconfig.h>
23 #include <kconfiggroup.h>
24 #include <kfileitem.h>
25 #include <kglobalsettings.h>
26 #include <kglobal.h>
27 #include <klocale.h>
28
29 #include <QEvent>
30 #include <QFontMetrics>
31 #include <QGridLayout>
32 #include <QLabel>
33 #include <QList>
34 #include <QString>
35
36 #include <config-nepomuk.h>
37 #ifdef HAVE_NEPOMUK
38 #define DISABLE_NEPOMUK_LEGACY
39
40 #include "kcommentwidget_p.h"
41 #include "kloadmetadatathread_p.h"
42 #include "ktaggingwidget_p.h"
43
44 #include <nepomuk/kratingwidget.h>
45 #include <nepomuk/resource.h>
46 #include <nepomuk/resourcemanager.h>
47 #include <nepomuk/property.h>
48 #include <nepomuk/tag.h>
49 #include <nepomuk/variant.h>
50 #include "nepomukmassupdatejob_p.h"
51
52 #include <QMutex>
53 #include <QSpacerItem>
54 #include <QThread>
55 #else
56 namespace Nepomuk
57 {
58 typedef int Tag;
59 }
60 #endif
61
62 class KMetaDataWidget::Private
63 {
64 public:
65 struct Row
66 {
67 QLabel* label;
68 QWidget* infoWidget;
69 };
70
71 Private(KMetaDataWidget* parent);
72 ~Private();
73
74 void addRow(QLabel* label, QWidget* infoWidget);
75 void removeMetaInfoRows();
76 void setRowVisible(QWidget* infoWidget, bool visible);
77
78 /**
79 * Initializes the configuration file "kmetainformationrc"
80 * with proper default settings for the first start in
81 * an uninitialized environment.
82 */
83 void initMetaInfoSettings();
84
85 /**
86 * Parses the configuration file "kmetainformationrc" and
87 * updates the visibility of all rows.
88 */
89 void updateRowsVisibility();
90
91 void slotLoadingFinished();
92
93 void slotRatingChanged(unsigned int rating);
94 void slotTagsChanged(const QList<Nepomuk::Tag>& tags);
95 void slotCommentChanged(const QString& comment);
96
97 void slotMetaDataUpdateDone();
98 void slotLinkActivated(const QString& link);
99
100 void slotTagActivated(const Nepomuk::Tag& tag);
101
102 #ifdef HAVE_NEPOMUK
103 /**
104 * Disables the metadata widget and starts the job that
105 * changes the meta data asynchronously. After the job
106 * has been finished, the metadata widget gets enabled again.
107 */
108 void startChangeDataJob(KJob* job);
109
110 /**
111 * Merges items like 'width' and 'height' as one item.
112 */
113 QList<KLoadMetaDataThread::Item> mergedItems(const QList<KLoadMetaDataThread::Item>& items);
114 #endif
115
116 bool m_sizeVisible;
117 bool m_readOnly;
118 bool m_nepomukActivated;
119 MetaDataTypes m_visibleDataTypes;
120 QList<KFileItem> m_fileItems;
121 QList<Row> m_rows;
122
123 QGridLayout* m_gridLayout;
124
125 QLabel* m_typeInfo;
126 QLabel* m_sizeLabel;
127 QLabel* m_sizeInfo;
128 QLabel* m_modifiedInfo;
129 QLabel* m_ownerInfo;
130 QLabel* m_permissionsInfo;
131
132 #ifdef HAVE_NEPOMUK
133 KRatingWidget* m_ratingWidget;
134 KTaggingWidget* m_taggingWidget;
135 KCommentWidget* m_commentWidget;
136
137 QMap<KUrl, Nepomuk::Resource> m_files;
138
139 KLoadMetaDataThread* m_loadMetaDataThread;
140 #endif
141
142 private:
143 KMetaDataWidget* const q;
144 };
145
146 KMetaDataWidget::Private::Private(KMetaDataWidget* parent) :
147 m_sizeVisible(true),
148 m_readOnly(false),
149 m_nepomukActivated(false),
150 m_visibleDataTypes(TypeData | SizeData | ModifiedData | OwnerData |
151 PermissionsData | RatingData | TagsData | CommentData),
152 m_fileItems(),
153 m_rows(),
154 m_gridLayout(0),
155 m_typeInfo(0),
156 m_sizeLabel(0),
157 m_sizeInfo(0),
158 m_modifiedInfo(0),
159 m_ownerInfo(0),
160 m_permissionsInfo(0),
161 #ifdef HAVE_NEPOMUK
162 m_ratingWidget(0),
163 m_taggingWidget(0),
164 m_commentWidget(0),
165 m_files(),
166 m_loadMetaDataThread(0),
167 #endif
168 q(parent)
169 {
170 const QFontMetrics fontMetrics(KGlobalSettings::smallestReadableFont());
171
172 m_gridLayout = new QGridLayout(parent);
173 m_gridLayout->setMargin(0);
174 m_gridLayout->setSpacing(fontMetrics.height() / 4);
175
176 m_typeInfo = new QLabel(parent);
177 m_sizeLabel = new QLabel(parent);
178 m_sizeInfo = new QLabel(parent);
179 m_modifiedInfo = new QLabel(parent);
180 m_ownerInfo = new QLabel(parent);
181 m_permissionsInfo = new QLabel(parent);
182
183 #ifdef HAVE_NEPOMUK
184 m_nepomukActivated = (Nepomuk::ResourceManager::instance()->init() == 0);
185 if (m_nepomukActivated) {
186 m_ratingWidget = new KRatingWidget(parent);
187 m_ratingWidget->setFixedHeight(fontMetrics.height());
188 const Qt::Alignment align = (parent->layoutDirection() == Qt::LeftToRight) ?
189 Qt::AlignLeft : Qt::AlignRight;
190 m_ratingWidget->setAlignment(align);
191 connect(m_ratingWidget, SIGNAL(ratingChanged(unsigned int)),
192 q, SLOT(slotRatingChanged(unsigned int)));
193
194 m_taggingWidget = new KTaggingWidget(parent);
195 connect(m_taggingWidget, SIGNAL(tagsChanged(const QList<Nepomuk::Tag>&)),
196 q, SLOT(slotTagsChanged(const QList<Nepomuk::Tag>&)));
197 connect(m_taggingWidget, SIGNAL(tagActivated(const Nepomuk::Tag&)),
198 q, SLOT(slotTagActivated(const Nepomuk::Tag&)));
199
200 m_commentWidget = new KCommentWidget(parent);
201 connect(m_commentWidget, SIGNAL(commentChanged(const QString&)),
202 q, SLOT(slotCommentChanged(const QString&)));
203 }
204 #endif
205
206 initMetaInfoSettings();
207 }
208
209 KMetaDataWidget::Private::~Private()
210 {
211 #ifdef HAVE_NEPOMUK
212 if (m_loadMetaDataThread != 0) {
213 disconnect(m_loadMetaDataThread, SIGNAL(finished()), q, SLOT(slotLoadingFinished()));
214 m_loadMetaDataThread->cancelAndDelete();
215 m_loadMetaDataThread = 0;
216 }
217 #endif
218 }
219
220 void KMetaDataWidget::Private::addRow(QLabel* label, QWidget* infoWidget)
221 {
222 Row row;
223 row.label = label;
224 row.infoWidget = infoWidget;
225 m_rows.append(row);
226
227 const QFont smallFont = KGlobalSettings::smallestReadableFont();
228 // use a brighter color for the label and a small font size
229 QPalette palette = label->palette();
230 const QPalette::ColorRole role = q->foregroundRole();
231 QColor textColor = palette.color(role);
232 textColor.setAlpha(128);
233 palette.setColor(role, textColor);
234 label->setPalette(palette);
235 label->setForegroundRole(role);
236 label->setFont(smallFont);
237 label->setWordWrap(true);
238 label->setAlignment(Qt::AlignTop | Qt::AlignRight);
239
240 infoWidget->setForegroundRole(role);
241 QLabel* infoLabel = qobject_cast<QLabel*>(infoWidget);
242 if (infoLabel != 0) {
243 infoLabel->setFont(smallFont);
244 infoLabel->setWordWrap(true);
245 infoLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
246 }
247
248 // add the row to grid layout
249 const int rowIndex = m_rows.count();
250 m_gridLayout->addWidget(label, rowIndex, 0, Qt::AlignRight);
251 const int spacerWidth = QFontMetrics(smallFont).size(Qt::TextSingleLine, " ").width();
252 m_gridLayout->addItem(new QSpacerItem(spacerWidth, 1), rowIndex, 1);
253 m_gridLayout->addWidget(infoWidget, rowIndex, 2, Qt::AlignLeft);
254 }
255
256 void KMetaDataWidget::Private::setRowVisible(QWidget* infoWidget, bool visible)
257 {
258 foreach (const Row& row, m_rows) {
259 if (row.infoWidget == infoWidget) {
260 row.label->setVisible(visible);
261 row.infoWidget->setVisible(visible);
262 return;
263 }
264 }
265 }
266
267
268 void KMetaDataWidget::Private::initMetaInfoSettings()
269 {
270 const int currentVersion = 1; // increase version, if the blacklist of disabled
271 // properties should be updated
272
273 KConfig config("kmetainformationrc", KConfig::NoGlobals);
274 if (config.group("Misc").readEntry("version", 0) < currentVersion) {
275 // The resource file is read the first time. Assure
276 // that some meta information is disabled per default.
277
278 // clear old info
279 config.deleteGroup( "Show" );
280 KConfigGroup settings = config.group("Show");
281
282 // trueg: KDE 4.5: use a blacklist of actual rdf properties
283
284 static const char* disabledProperties[] = {
285 "asText", "contentSize", "created", "depth", "description", "fileExtension",
286 "fileName", "fileSize", "hasTag", "isPartOf", "lastModified", "mimeType", "name",
287 "numericRating", "parentUrl", "permissions", "plainTextContent", "owner",
288 "sourceModified", "url",
289 0 // mandatory last entry
290 };
291
292 for (int i = 0; disabledProperties[i] != 0; ++i) {
293 settings.writeEntry(disabledProperties[i], false);
294 }
295
296 // mark the group as initialized
297 config.group("Misc").writeEntry("version", currentVersion);
298 }
299 }
300
301 void KMetaDataWidget::Private::updateRowsVisibility()
302 {
303 KConfig config("kmetainformationrc", KConfig::NoGlobals);
304 KConfigGroup settings = config.group("Show");
305
306 setRowVisible(m_typeInfo,
307 (m_visibleDataTypes & KMetaDataWidget::TypeData) &&
308 settings.readEntry("type", true));
309
310 // Cache in m_sizeVisible whether the size should be shown. This
311 // is necessary as the size is temporary hidden when the target
312 // file item is a directory.
313 m_sizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) &&
314 settings.readEntry("size", true);
315 setRowVisible(m_sizeInfo, m_sizeVisible);
316
317 setRowVisible(m_modifiedInfo,
318 (m_visibleDataTypes & KMetaDataWidget::ModifiedData) &&
319 settings.readEntry("modified", true));
320
321 setRowVisible(m_ownerInfo,
322 (m_visibleDataTypes & KMetaDataWidget::OwnerData) &&
323 settings.readEntry("owner", true));
324
325 setRowVisible(m_permissionsInfo,
326 (m_visibleDataTypes & KMetaDataWidget::PermissionsData) &&
327 settings.readEntry("permissions", true));
328
329 #ifdef HAVE_NEPOMUK
330 if (m_nepomukActivated) {
331 setRowVisible(m_ratingWidget,
332 (m_visibleDataTypes & KMetaDataWidget::RatingData) &&
333 settings.readEntry("rating", true));
334
335 setRowVisible(m_taggingWidget,
336 (m_visibleDataTypes & KMetaDataWidget::TagsData) &&
337 settings.readEntry("tags", true));
338
339 setRowVisible(m_commentWidget,
340 (m_visibleDataTypes & KMetaDataWidget::CommentData) &&
341 settings.readEntry("comment", true));
342 }
343 #endif
344 }
345
346 void KMetaDataWidget::Private::slotLoadingFinished()
347 {
348 #ifdef HAVE_NEPOMUK
349 if (m_loadMetaDataThread == 0) {
350 // The signal finished() has been emitted, but the thread has been marked
351 // as invalid in the meantime. Just ignore the signal in this case.
352 return;
353 }
354
355 Q_ASSERT(m_ratingWidget != 0);
356 Q_ASSERT(m_commentWidget != 0);
357 Q_ASSERT(m_taggingWidget != 0);
358 m_ratingWidget->setRating(m_loadMetaDataThread->rating());
359 m_commentWidget->setText(m_loadMetaDataThread->comment());
360 m_taggingWidget->setTags(m_loadMetaDataThread->tags());
361
362 // Show the remaining meta information as text. The number
363 // of required rows may very. Existing rows are reused to
364 // prevent flickering.
365 int index = 8; // TODO: don't hardcode this value here
366 const int rowCount = m_rows.count();
367 Q_ASSERT(rowCount >= index);
368
369 const QList<KLoadMetaDataThread::Item> items = mergedItems(m_loadMetaDataThread->items());
370 foreach (const KLoadMetaDataThread::Item& item, items) {
371 const QString itemLabel = item.label;
372 QString itemValue = item.value;
373 if (item.value.startsWith("<a href=")) {
374 // use the text color for the value-links, to create a visual difference
375 // to the semantically different links like "Change..."
376 const QColor linkColor = q->palette().text().color();
377 QString decoration;
378 if (m_readOnly) {
379 decoration = QString::fromLatin1("text-decoration:none;");
380 }
381 const QString styleText = QString::fromLatin1("style=\"color:%1;%2\" ")
382 .arg(linkColor.name())
383 .arg(decoration);
384 itemValue.insert(3 /* after "<a "*/, styleText);
385 }
386 if (index < rowCount) {
387 // adjust texts of the current row
388 m_rows[index].label->setText(itemLabel);
389 QLabel* infoValueLabel = qobject_cast<QLabel*>(m_rows[index].infoWidget);
390 Q_ASSERT(infoValueLabel != 0);
391 infoValueLabel->setText(itemValue);
392 } else {
393 // create new row
394 QLabel* infoLabel = new QLabel(itemLabel, q);
395 QLabel* infoValue = new QLabel(itemValue, q);
396 connect(infoValue, SIGNAL(linkActivated(QString)),
397 q, SLOT(slotLinkActivated(QString)));
398 addRow(infoLabel, infoValue);
399 }
400 ++index;
401 }
402 if (items.count() > 0) {
403 --index;
404 }
405
406 // remove rows that are not needed anymore
407 for (int i = m_rows.count() - 1; i >= index; --i) {
408 delete m_rows[i].label;
409 delete m_rows[i].infoWidget;
410 m_rows.pop_back();
411 }
412
413 m_files = m_loadMetaDataThread->files();
414
415 delete m_loadMetaDataThread;
416 m_loadMetaDataThread = 0;
417 #endif
418
419 q->updateGeometry();
420 }
421
422 void KMetaDataWidget::Private::slotRatingChanged(unsigned int rating)
423 {
424 #ifdef HAVE_NEPOMUK
425 Nepomuk::MassUpdateJob* job =
426 Nepomuk::MassUpdateJob::rateResources(m_files.values(), rating);
427 startChangeDataJob(job);
428 #else
429 Q_UNUSED(rating);
430 #endif
431 }
432
433 void KMetaDataWidget::Private::slotTagsChanged(const QList<Nepomuk::Tag>& tags)
434 {
435 #ifdef HAVE_NEPOMUK
436 m_taggingWidget->setTags(tags);
437
438 Nepomuk::MassUpdateJob* job =
439 Nepomuk::MassUpdateJob::tagResources(m_files.values(), tags);
440 startChangeDataJob(job);
441 #else
442 Q_UNUSED(tags);
443 #endif
444 }
445
446 void KMetaDataWidget::Private::slotCommentChanged(const QString& comment)
447 {
448 #ifdef HAVE_NEPOMUK
449 Nepomuk::MassUpdateJob* job =
450 Nepomuk::MassUpdateJob::commentResources(m_files.values(), comment);
451 startChangeDataJob(job);
452 #else
453 Q_UNUSED(comment);
454 #endif
455 }
456
457 void KMetaDataWidget::Private::slotTagActivated(const Nepomuk::Tag& tag)
458 {
459 #ifdef HAVE_NEPOMUK
460 emit q->urlActivated(tag.resourceUri());
461 #else
462 Q_UNUSED(tag);
463 #endif
464 }
465
466 void KMetaDataWidget::Private::slotMetaDataUpdateDone()
467 {
468 #ifdef HAVE_NEPOMUK
469 q->setEnabled(true);
470 #endif
471 }
472
473 void KMetaDataWidget::Private::slotLinkActivated(const QString& link)
474 {
475 emit q->urlActivated(KUrl(link));
476 }
477
478 #ifdef HAVE_NEPOMUK
479 void KMetaDataWidget::Private::startChangeDataJob(KJob* job)
480 {
481 connect(job, SIGNAL(result(KJob*)),
482 q, SLOT(slotMetaDataUpdateDone()));
483 q->setEnabled(false); // no updates during execution
484 job->start();
485 }
486
487 QList<KLoadMetaDataThread::Item>
488 KMetaDataWidget::Private::mergedItems(const QList<KLoadMetaDataThread::Item>& items)
489 {
490 // TODO: Currently only "width" and "height" are merged as "width x height". If
491 // other kind of merges should be done too, a more general approach is required.
492 QList<KLoadMetaDataThread::Item> mergedItems;
493
494 KLoadMetaDataThread::Item width;
495 KLoadMetaDataThread::Item height;
496
497 foreach (const KLoadMetaDataThread::Item& item, items) {
498 if (item.name == "width") {
499 width = item;
500 } else if (item.name == "height") {
501 height = item;
502 } else {
503 // insert the item sorted by the label
504 bool inserted = false;
505 int i = 0;
506 const int count = mergedItems.count();
507 while (!inserted && (i < count)) {
508 if (item.label < mergedItems[i].label) {
509 mergedItems.insert(i, item);
510 inserted = true;
511 }
512 ++i;
513 }
514 if (!inserted) {
515 mergedItems.append(item);
516 }
517 }
518 }
519
520 const bool foundWidth = !width.name.isEmpty();
521 const bool foundHeight = !height.name.isEmpty();
522 if (foundWidth && !foundHeight) {
523 mergedItems.insert(0, width);
524 } else if (foundHeight && !foundWidth) {
525 mergedItems.insert(0, height);
526 } else if (foundWidth && foundHeight) {
527 KLoadMetaDataThread::Item size;
528 size.label = i18nc("@label", "Width x Height:");
529 size.value = width.value + " x " + height.value;
530 mergedItems.insert(0, size);
531 }
532
533 return mergedItems;
534 }
535 #endif
536
537 KMetaDataWidget::KMetaDataWidget(QWidget* parent) :
538 QWidget(parent),
539 d(new Private(this))
540 {
541 }
542
543 KMetaDataWidget::~KMetaDataWidget()
544 {
545 delete d;
546 }
547
548 void KMetaDataWidget::setItem(const KFileItem& item)
549 {
550 // update values for "type", "size", "modified",
551 // "owner" and "permissions" synchronously
552 d->m_sizeLabel->setText(i18nc("@label", "Size:"));
553 if (item.isDir()) {
554 d->m_typeInfo->setText(i18nc("@label", "Folder"));
555 d->setRowVisible(d->m_sizeInfo, false);
556 } else {
557 d->m_typeInfo->setText(item.mimeComment());
558 d->m_sizeInfo->setText(KIO::convertSize(item.size()));
559 d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
560 }
561 d->m_modifiedInfo->setText(KGlobal::locale()->formatDateTime(item.time(KFileItem::ModificationTime), KLocale::FancyLongDate));
562 d->m_ownerInfo->setText(item.user());
563 d->m_permissionsInfo->setText(item.permissionsString());
564
565 setItems(KFileItemList() << item);
566 }
567
568 void KMetaDataWidget::setItems(const KFileItemList& items)
569 {
570 d->m_fileItems = items;
571
572 if (items.count() > 1) {
573 // calculate the size of all items and show this
574 // information to the user
575 d->m_sizeLabel->setText(i18nc("@label", "Total Size:"));
576 d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
577
578 quint64 totalSize = 0;
579 foreach (const KFileItem& item, items) {
580 if (!item.isDir() && !item.isLink()) {
581 totalSize += item.size();
582 }
583 }
584 d->m_sizeInfo->setText(KIO::convertSize(totalSize));
585 }
586
587 #ifdef HAVE_NEPOMUK
588 if (d->m_nepomukActivated) {
589 QList<KUrl> urls;
590 foreach (const KFileItem& item, items) {
591 const KUrl url = item.nepomukUri();
592 if (url.isValid()) {
593 urls.append(url);
594 }
595 }
596
597 if (d->m_loadMetaDataThread != 0) {
598 disconnect(d->m_loadMetaDataThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished()));
599 d->m_loadMetaDataThread->cancelAndDelete();
600 }
601
602 d->m_loadMetaDataThread = new KLoadMetaDataThread();
603 connect(d->m_loadMetaDataThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished()));
604 d->m_loadMetaDataThread->load(urls);
605 }
606 #endif
607 }
608
609 void KMetaDataWidget::setItem(const KUrl& url)
610 {
611 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
612 item.refresh();
613 setItem(item);
614 }
615
616 void KMetaDataWidget::setItems(const QList<KUrl>& urls)
617 {
618 KFileItemList items;
619 foreach (const KUrl& url, urls) {
620 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
621 item.refresh();
622 items.append(item);
623 }
624 setItems(items);
625 }
626
627 KFileItemList KMetaDataWidget::items() const
628 {
629 return d->m_fileItems;
630 }
631
632 void KMetaDataWidget::setReadOnly(bool readOnly)
633 {
634 d->m_readOnly = readOnly;
635 #ifdef HAVE_NEPOMUK
636 // TODO: encapsulate this code as part of a metadata-model for KDE 4.5
637 if (d->m_taggingWidget)
638 d->m_taggingWidget->setReadOnly(readOnly);
639 if (d->m_commentWidget)
640 d->m_commentWidget->setReadOnly(readOnly);
641 #endif
642 }
643
644 bool KMetaDataWidget::isReadOnly() const
645 {
646 return d->m_readOnly;
647 }
648
649 void KMetaDataWidget::setVisibleDataTypes(MetaDataTypes data)
650 {
651 d->m_visibleDataTypes = data;
652 d->updateRowsVisibility();
653 }
654
655 KMetaDataWidget::MetaDataTypes KMetaDataWidget::visibleDataTypes() const
656 {
657 return d->m_visibleDataTypes;
658 }
659
660 QSize KMetaDataWidget::sizeHint() const
661 {
662 const int fixedWidth = 200;
663
664 int height = d->m_gridLayout->margin() * 2 +
665 d->m_gridLayout->spacing() * (d->m_rows.count() - 1);
666
667 foreach (const Private::Row& row, d->m_rows) {
668 if (row.infoWidget != 0) {
669 int rowHeight = row.infoWidget->heightForWidth(fixedWidth / 2);
670 if (rowHeight <= 0) {
671 rowHeight = row.infoWidget->sizeHint().height();
672 }
673 height += rowHeight;
674 }
675 }
676
677 return QSize(fixedWidth, height);
678 }
679
680 bool KMetaDataWidget::event(QEvent* event)
681 {
682 if (event->type() == QEvent::Polish) {
683 // The adding of rows is not done in the constructor. This allows the
684 // client of KMetaDataWidget to set a proper foreground role which
685 // will be respected by the rows.
686
687 d->addRow(new QLabel(i18nc("@label", "Type:"), this), d->m_typeInfo);
688 d->addRow(d->m_sizeLabel, d->m_sizeInfo);
689 d->addRow(new QLabel(i18nc("@label", "Modified:"), this), d->m_modifiedInfo);
690 d->addRow(new QLabel(i18nc("@label", "Owner:"), this), d->m_ownerInfo);
691 d->addRow(new QLabel(i18nc("@label", "Permissions:"), this), d->m_permissionsInfo);
692
693 #ifdef HAVE_NEPOMUK
694 if (d->m_nepomukActivated) {
695 d->addRow(new QLabel(i18nc("@label", "Rating:"), this), d->m_ratingWidget);
696 d->addRow(new QLabel(i18nc("@label", "Tags:"), this), d->m_taggingWidget);
697 d->addRow(new QLabel(i18nc("@label", "Comment:"), this), d->m_commentWidget);
698 }
699 #endif
700
701 d->updateRowsVisibility();
702 }
703
704 return QWidget::event(event);
705 }
706
707 #include "kmetadatawidget.moc"