]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.cpp
The feature freeze is near: Add video support to the Information Panel. Phonon is...
[dolphin.git] / src / panels / information / informationpanel.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program 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 *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "informationpanel.h"
21
22 #include <config-nepomuk.h>
23
24 #include <kdialog.h>
25 #include <kdirnotify.h>
26 #include <kfileitem.h>
27 #include <kfilemetainfo.h>
28 #include <kfileplacesmodel.h>
29 #include <kglobalsettings.h>
30 #include <kio/previewjob.h>
31 #include <kiconeffect.h>
32 #include <kiconloader.h>
33 #include <klocale.h>
34 #include <kmenu.h>
35 #include <kseparator.h>
36
37 #ifdef HAVE_NEPOMUK
38 #include <Nepomuk/Resource>
39 #include <Nepomuk/Types/Property>
40 #include <Nepomuk/Variant>
41 #endif
42
43 #include <Phonon/BackendCapabilities>
44 #include <Phonon/MediaObject>
45 #include <Phonon/SeekSlider>
46
47 #include <QEvent>
48 #include <QInputDialog>
49 #include <QLabel>
50 #include <QPainter>
51 #include <QPixmap>
52 #include <QResizeEvent>
53 #include <QScrollArea>
54 #include <QTextLayout>
55 #include <QTextLine>
56 #include <QTimer>
57 #include <QScrollBar>
58 #include <QVBoxLayout>
59
60 #include "dolphin_informationpanelsettings.h"
61 #include "settings/dolphinsettings.h"
62 #include "metadatawidget.h"
63 #include "metatextlabel.h"
64 #include "phononwidget.h"
65 #include "pixmapviewer.h"
66
67 /**
68 * Helper function for sorting items with qSort() in
69 * InformationPanel::contextMenu().
70 */
71 bool lessThan(const QAction* action1, const QAction* action2)
72 {
73 return action1->text() < action2->text();
74 }
75
76
77 InformationPanel::InformationPanel(QWidget* parent) :
78 Panel(parent),
79 m_initialized(false),
80 m_pendingPreview(false),
81 m_infoTimer(0),
82 m_outdatedPreviewTimer(0),
83 m_shownUrl(),
84 m_urlCandidate(),
85 m_fileItem(),
86 m_selection(),
87 m_nameLabel(0),
88 m_preview(0),
89 m_previewSeparator(0),
90 m_phononWidget(0),
91 m_metaDataWidget(0),
92 m_metaDataSeparator(0),
93 m_metaTextArea(0),
94 m_metaTextLabel(0)
95 {
96 }
97
98 InformationPanel::~InformationPanel()
99 {
100 InformationPanelSettings::self()->writeConfig();
101 }
102
103 QSize InformationPanel::sizeHint() const
104 {
105 QSize size = Panel::sizeHint();
106 size.setWidth(minimumSizeHint().width());
107 return size;
108 }
109
110 void InformationPanel::setUrl(const KUrl& url)
111 {
112 Panel::setUrl(url);
113 if (url.isValid() && !isEqualToShownUrl(url)) {
114 if (isVisible()) {
115 cancelRequest();
116 m_shownUrl = url;
117 showItemInfo();
118 } else {
119 m_shownUrl = url;
120 }
121 }
122 }
123
124 void InformationPanel::setSelection(const KFileItemList& selection)
125 {
126 if (!isVisible()) {
127 return;
128 }
129
130 if ((selection.count() == 0) && (m_selection.count() == 0)) {
131 // The selection has not really changed, only the current index.
132 // QItemSelectionModel emits a signal in this case and it is less
133 // expensive doing the check this way instead of patching
134 // DolphinView::emitSelectionChanged().
135 return;
136 }
137
138 m_selection = selection;
139
140 const int count = selection.count();
141 if (count == 0) {
142 if (!isEqualToShownUrl(url())) {
143 m_shownUrl = url();
144 showItemInfo();
145 }
146 } else {
147 if ((count == 1) && !selection.first().url().isEmpty()) {
148 m_urlCandidate = selection.first().url();
149 }
150 m_infoTimer->start();
151 }
152 }
153
154 void InformationPanel::requestDelayedItemInfo(const KFileItem& item)
155 {
156 if (!isVisible()) {
157 return;
158 }
159
160 cancelRequest();
161
162 m_fileItem = KFileItem();
163 if (item.isNull()) {
164 // The cursor is above the viewport. If files are selected,
165 // show information regarding the selection.
166 if (m_selection.size() > 0) {
167 m_pendingPreview = false;
168 m_infoTimer->start();
169 }
170 } else {
171 const KUrl url = item.url();
172 if (url.isValid() && !isEqualToShownUrl(url)) {
173 m_urlCandidate = item.url();
174 m_fileItem = item;
175 m_infoTimer->start();
176 }
177 }
178 }
179
180 void InformationPanel::showEvent(QShowEvent* event)
181 {
182 Panel::showEvent(event);
183 if (!event->spontaneous()) {
184 if (!m_initialized) {
185 // do a delayed initialization so that no performance
186 // penalty is given when Dolphin is started with a closed
187 // Information Panel
188 init();
189 }
190 showItemInfo();
191 }
192 }
193
194 void InformationPanel::resizeEvent(QResizeEvent* event)
195 {
196 if (isVisible()) {
197 // If the text inside the name label or the info label cannot
198 // get wrapped, then the maximum width of the label is increased
199 // so that the width of the information panel gets increased.
200 // To prevent this, the maximum width is adjusted to
201 // the current width of the panel.
202 const int maxWidth = event->size().width() - KDialog::spacingHint() * 4;
203 m_nameLabel->setMaximumWidth(maxWidth);
204
205 // try to increase the preview as large as possible
206 m_preview->setSizeHint(QSize(maxWidth, maxWidth));
207 m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done
208 m_infoTimer->start();
209 }
210 Panel::resizeEvent(event);
211 }
212
213 bool InformationPanel::eventFilter(QObject* obj, QEvent* event)
214 {
215 // Check whether the size of the meta text area has changed and adjust
216 // the fixed width in a way that no horizontal scrollbar needs to be shown.
217 if ((obj == m_metaTextArea->viewport()) && (event->type() == QEvent::Resize)) {
218 QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
219 m_metaTextLabel->setFixedWidth(resizeEvent->size().width());
220 }
221 return Panel::eventFilter(obj, event);
222 }
223
224 void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
225 {
226 Panel::contextMenuEvent(event);
227
228 #ifdef HAVE_NEPOMUK
229 if (showMultipleSelectionInfo()) {
230 return;
231 }
232
233 KMenu popup(this);
234
235 QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview"));
236 previewAction->setIcon(KIcon("view-preview"));
237 previewAction->setCheckable(true);
238 previewAction->setChecked(InformationPanelSettings::showPreview());
239
240 const bool metaDataAvailable = MetaDataWidget::metaDataAvailable();
241
242 QAction* ratingAction = popup.addAction(i18nc("@action:inmenu", "Rating"));
243 ratingAction->setIcon(KIcon("rating"));
244 ratingAction->setCheckable(true);
245 ratingAction->setChecked(InformationPanelSettings::showRating());
246 ratingAction->setEnabled(metaDataAvailable);
247
248 QAction* commentAction = popup.addAction(i18nc("@action:inmenu", "Comment"));
249 commentAction->setIcon(KIcon("text-plain"));
250 commentAction->setCheckable(true);
251 commentAction->setChecked(InformationPanelSettings::showComment());
252 commentAction->setEnabled(metaDataAvailable);
253
254 QAction* tagsAction = popup.addAction(i18nc("@action:inmenu", "Tags"));
255 tagsAction->setCheckable(true);
256 tagsAction->setChecked(InformationPanelSettings::showTags());
257 tagsAction->setEnabled(metaDataAvailable);
258
259 KConfig config("kmetainformationrc", KConfig::NoGlobals);
260 KConfigGroup settings = config.group("Show");
261 initMetaInfoSettings(settings);
262
263 QList<QAction*> actions;
264
265 // Get all meta information labels that are available for
266 // the currently shown file item and add them to the popup.
267 Nepomuk::Resource res(fileItem().url());
268 QHash<QUrl, Nepomuk::Variant> properties = res.properties();
269 QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
270 while (it != properties.constEnd()) {
271 Nepomuk::Types::Property prop(it.key());
272 const QString key = prop.label();
273
274 // Meta information provided by Nepomuk that is already
275 // available from KFileItem should not be configurable.
276 bool skip = (key == "fileExtension") ||
277 (key == "name") ||
278 (key == "sourceModified") ||
279 (key == "size") ||
280 (key == "mime type");
281 if (!skip) {
282 // Check whether there is already a meta information
283 // having the same label. In this case don't show it
284 // twice in the menu.
285 foreach (const QAction* action, actions) {
286 if (action->data().toString() == key) {
287 skip = true;
288 break;
289 }
290 }
291 }
292
293 if (!skip) {
294 const QString label = key; // TODO
295 QAction* action = new QAction(label, &popup);
296 action->setCheckable(true);
297 action->setChecked(settings.readEntry(key, true));
298 action->setData(key);
299 actions.append(action);
300 }
301
302 ++it;
303 }
304
305 if (actions.count() > 0) {
306 popup.addSeparator();
307
308 // add all items alphabetically sorted to the popup
309 qSort(actions.begin(), actions.end(), lessThan);
310 foreach (QAction* action, actions) {
311 popup.addAction(action);
312 }
313 }
314
315 // Open the popup and adjust the settings for the
316 // selected action.
317 QAction* action = popup.exec(QCursor::pos());
318 if (action == 0) {
319 return;
320 }
321
322 const bool isChecked = action->isChecked();
323 if (action == previewAction) {
324 m_preview->setVisible(isChecked);
325 m_previewSeparator->setVisible(isChecked);
326 InformationPanelSettings::setShowPreview(isChecked);
327 updatePhononWidget();
328 } else if (action == ratingAction) {
329 m_metaDataWidget->setRatingVisible(isChecked);
330 InformationPanelSettings::setShowRating(isChecked);
331 } else if (action == commentAction) {
332 m_metaDataWidget->setCommentVisible(isChecked);
333 InformationPanelSettings::setShowComment(isChecked);
334 } else if (action == tagsAction) {
335 m_metaDataWidget->setTagsVisible(isChecked);
336 InformationPanelSettings::setShowTags(isChecked);
337 } else {
338 settings.writeEntry(action->data().toString(), action->isChecked());
339 settings.sync();
340 showMetaInfo();
341 }
342
343 const bool visible = m_metaDataWidget->isRatingVisible() ||
344 m_metaDataWidget->isCommentVisible() ||
345 m_metaDataWidget->areTagsVisible();
346 m_metaDataSeparator->setVisible(visible);
347 #endif
348 }
349
350 void InformationPanel::showItemInfo()
351 {
352 if (!isVisible()) {
353 return;
354 }
355
356 cancelRequest();
357
358 if (showMultipleSelectionInfo()) {
359 KIconLoader iconLoader;
360 QPixmap icon = iconLoader.loadIcon("dialog-information",
361 KIconLoader::NoGroup,
362 KIconLoader::SizeEnormous);
363 m_preview->setPixmap(icon);
364 setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count()));
365 m_shownUrl = KUrl();
366 } else {
367 const KFileItem item = fileItem();
368 const KUrl itemUrl = item.url();
369 if (!applyPlace(itemUrl)) {
370 // try to get a preview pixmap from the item...
371 m_pendingPreview = true;
372
373 // Mark the currently shown preview as outdated. This is done
374 // with a small delay to prevent a flickering when the next preview
375 // can be shown within a short timeframe.
376 m_outdatedPreviewTimer->start();
377
378 KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item,
379 m_preview->width(),
380 m_preview->height(),
381 0,
382 0,
383 false,
384 true);
385
386 connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
387 this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
388 connect(job, SIGNAL(failed(const KFileItem&)),
389 this, SLOT(showIcon(const KFileItem&)));
390
391 setNameLabelText(itemUrl.fileName());
392 }
393 }
394
395 showMetaInfo();
396 }
397
398 void InformationPanel::slotInfoTimeout()
399 {
400 m_shownUrl = m_urlCandidate;
401 showItemInfo();
402 }
403
404 void InformationPanel::markOutdatedPreview()
405 {
406 KIconEffect iconEffect;
407 QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(),
408 KIconLoader::Desktop,
409 KIconLoader::DisabledState);
410 m_preview->setPixmap(disabledPixmap);
411 }
412
413 void InformationPanel::showIcon(const KFileItem& item)
414 {
415 m_outdatedPreviewTimer->stop();
416 m_pendingPreview = false;
417 if (!applyPlace(item.url())) {
418 m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous));
419 }
420 }
421
422 void InformationPanel::showPreview(const KFileItem& item,
423 const QPixmap& pixmap)
424 {
425 m_outdatedPreviewTimer->stop();
426
427 Q_UNUSED(item);
428 if (m_pendingPreview) {
429 m_preview->setPixmap(pixmap);
430 m_pendingPreview = false;
431 }
432 }
433
434 void InformationPanel::slotFileRenamed(const QString& source, const QString& dest)
435 {
436 const KUrl sourceUrl = KUrl(source);
437
438 // Verify whether the renamed item is selected. If this is the case, the
439 // selection must be updated with the renamed item.
440 bool isSelected = false;
441 for (int i = m_selection.size() - 1; i >= 0; --i) {
442 if (m_selection[i].url() == sourceUrl) {
443 m_selection.removeAt(i);
444 isSelected = true;
445 break;
446 }
447 }
448
449 if ((m_shownUrl == sourceUrl) || isSelected) {
450 m_shownUrl = KUrl(dest);
451 m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
452 if (isSelected) {
453 m_selection.append(m_fileItem);
454 }
455 showItemInfo();
456 }
457 }
458
459 void InformationPanel::slotFilesAdded(const QString& directory)
460 {
461 if (m_shownUrl == KUrl(directory)) {
462 // If the 'trash' icon changes because the trash has been emptied or got filled,
463 // the signal filesAdded("trash:/") will be emitted.
464 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory));
465 requestDelayedItemInfo(item);
466 }
467 }
468
469 void InformationPanel::slotFilesChanged(const QStringList& files)
470 {
471 foreach (const QString& fileName, files) {
472 if (m_shownUrl == KUrl(fileName)) {
473 showItemInfo();
474 break;
475 }
476 }
477 }
478
479 void InformationPanel::slotFilesRemoved(const QStringList& files)
480 {
481 foreach (const QString& fileName, files) {
482 if (m_shownUrl == KUrl(fileName)) {
483 // the currently shown item has been removed, show
484 // the parent directory as fallback
485 reset();
486 break;
487 }
488 }
489 }
490
491 void InformationPanel::slotEnteredDirectory(const QString& directory)
492 {
493 if (m_shownUrl == KUrl(directory)) {
494 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory));
495 requestDelayedItemInfo(item);
496 }
497 }
498
499 void InformationPanel::slotLeftDirectory(const QString& directory)
500 {
501 if (m_shownUrl == KUrl(directory)) {
502 // The signal 'leftDirectory' is also emitted when a media
503 // has been unmounted. In this case no directory change will be
504 // done in Dolphin, but the Information Panel must be updated to
505 // indicate an invalid directory.
506 reset();
507 }
508 }
509
510 void InformationPanel::slotPlayingStarted()
511 {
512 m_preview->setVisible(m_phononWidget->mode() != PhononWidget::Video);
513 }
514
515 void InformationPanel::slotPlayingStopped()
516 {
517 m_preview->setVisible(true);
518 }
519
520 bool InformationPanel::applyPlace(const KUrl& url)
521 {
522 KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
523 int count = placesModel->rowCount();
524
525 for (int i = 0; i < count; ++i) {
526 QModelIndex index = placesModel->index(i, 0);
527
528 if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
529 setNameLabelText(placesModel->text(index));
530 m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128));
531 return true;
532 }
533 }
534
535 return false;
536 }
537
538 void InformationPanel::cancelRequest()
539 {
540 m_infoTimer->stop();
541 }
542
543 void InformationPanel::showMetaInfo()
544 {
545 m_metaTextLabel->clear();
546
547 if (showMultipleSelectionInfo()) {
548 if (m_metaDataWidget != 0) {
549 KUrl::List urls;
550 foreach (const KFileItem& item, m_selection) {
551 urls.append(item.targetUrl());
552 }
553 m_metaDataWidget->setFiles(urls);
554 }
555
556 quint64 totalSize = 0;
557 foreach (const KFileItem& item, m_selection) {
558 // Only count the size of files, not dirs to match what
559 // DolphinViewContainer::selectionStatusBarText() does.
560 if (!item.isDir() && !item.isLink()) {
561 totalSize += item.size();
562 }
563 }
564 m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
565 } else {
566 const KFileItem item = fileItem();
567 if (item.isDir()) {
568 m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder"));
569 m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
570 } else {
571 m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment());
572
573 m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size()));
574 m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
575
576 #ifdef HAVE_NEPOMUK
577 KConfig config("kmetainformationrc", KConfig::NoGlobals);
578 KConfigGroup settings = config.group("Show");
579 initMetaInfoSettings(settings);
580
581 Nepomuk::Resource res(item.url());
582
583 QHash<QUrl, Nepomuk::Variant> properties = res.properties();
584 QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
585 while (it != properties.constEnd()) {
586 Nepomuk::Types::Property prop(it.key());
587 const QString label = prop.label();
588 if (settings.readEntry(label, true)) {
589 // TODO: use Nepomuk::formatValue(res, prop) if available
590 // instead of it.value().toString()
591 m_metaTextLabel->add(label, it.value().toString());
592 }
593 ++it;
594 }
595 #endif
596 }
597
598 if (m_metaDataWidget != 0) {
599 m_metaDataWidget->setFile(item.targetUrl());
600 }
601 }
602
603 updatePhononWidget();
604 }
605
606 KFileItem InformationPanel::fileItem() const
607 {
608 if (!m_fileItem.isNull()) {
609 return m_fileItem;
610 }
611
612 if (!m_selection.isEmpty()) {
613 Q_ASSERT(m_selection.count() == 1);
614 return m_selection.first();
615 }
616
617 // no item is hovered and no selection has been done: provide
618 // an item for the directory represented by m_shownUrl
619 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
620 item.refresh();
621 return item;
622 }
623
624 bool InformationPanel::showMultipleSelectionInfo() const
625 {
626 return m_fileItem.isNull() && (m_selection.count() > 1);
627 }
628
629 bool InformationPanel::isEqualToShownUrl(const KUrl& url) const
630 {
631 return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash);
632 }
633
634 void InformationPanel::setNameLabelText(const QString& text)
635 {
636 QTextOption textOption;
637 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
638
639 QTextLayout textLayout(text);
640 textLayout.setFont(m_nameLabel->font());
641 textLayout.setTextOption(textOption);
642
643 QString wrappedText;
644 wrappedText.reserve(text.length());
645
646 // wrap the text to fit into the width of m_nameLabel
647 textLayout.beginLayout();
648 QTextLine line = textLayout.createLine();
649 while (line.isValid()) {
650 line.setLineWidth(m_nameLabel->width());
651 wrappedText += text.mid(line.textStart(), line.textLength());
652
653 line = textLayout.createLine();
654 if (line.isValid()) {
655 wrappedText += QChar::LineSeparator;
656 }
657 }
658 textLayout.endLayout();
659
660 m_nameLabel->setText(wrappedText);
661 }
662
663 void InformationPanel::reset()
664 {
665 m_selection.clear();
666 m_shownUrl = url();
667 m_fileItem = KFileItem();
668 showItemInfo();
669 }
670
671 void InformationPanel::initMetaInfoSettings(KConfigGroup& group)
672 {
673 if (!group.readEntry("initialized", false)) {
674 // The resource file is read the first time. Assure
675 // that some meta information is disabled per default.
676 group.writeEntry("fileExtension", false);
677 group.writeEntry("url", false);
678 group.writeEntry("sourceModified", false);
679 group.writeEntry("parentUrl", false);
680 group.writeEntry("size", false);
681 group.writeEntry("mime type", false);
682 group.writeEntry("depth", false);
683 group.writeEntry("name", false);
684
685 // mark the group as initialized
686 group.writeEntry("initialized", true);
687 }
688 }
689
690 void InformationPanel::updatePhononWidget()
691 {
692 const bool multipleSelections = showMultipleSelectionInfo();
693 const bool showPreview = InformationPanelSettings::showPreview();
694
695 if (multipleSelections || !showPreview) {
696 m_phononWidget->hide();
697 } else if (!multipleSelections && showPreview) {
698 const KFileItem item = fileItem();
699 const QString mimeType = item.mimetype();
700 if (Phonon::BackendCapabilities::isMimeTypeAvailable(mimeType)) {
701 m_phononWidget->show();
702 PhononWidget::Mode mode = mimeType.startsWith("video")
703 ? PhononWidget::Video
704 : PhononWidget::Audio;
705 m_phononWidget->setMode(mode);
706 m_phononWidget->setUrl(item.url());
707 } else {
708 m_phononWidget->hide();
709 m_preview->setVisible(true);
710 }
711 }
712 }
713
714 void InformationPanel::init()
715 {
716 const int spacing = KDialog::spacingHint();
717
718 m_infoTimer = new QTimer(this);
719 m_infoTimer->setInterval(300);
720 m_infoTimer->setSingleShot(true);
721 connect(m_infoTimer, SIGNAL(timeout()),
722 this, SLOT(slotInfoTimeout()));
723
724 // Initialize timer for disabling an outdated preview with a small
725 // delay. This prevents flickering if the new preview can be generated
726 // within a very small timeframe.
727 m_outdatedPreviewTimer = new QTimer(this);
728 m_outdatedPreviewTimer->setInterval(300);
729 m_outdatedPreviewTimer->setSingleShot(true);
730 connect(m_outdatedPreviewTimer, SIGNAL(timeout()),
731 this, SLOT(markOutdatedPreview()));
732
733 QVBoxLayout* layout = new QVBoxLayout;
734 layout->setSpacing(spacing);
735
736 // name
737 m_nameLabel = new QLabel(this);
738 QFont font = m_nameLabel->font();
739 font.setBold(true);
740 m_nameLabel->setFont(font);
741 m_nameLabel->setAlignment(Qt::AlignHCenter);
742 m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
743
744 // preview
745 m_preview = new PixmapViewer(this);
746 m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium);
747 m_preview->setMinimumHeight(KIconLoader::SizeEnormous);
748
749 m_phononWidget = new PhononWidget(this);
750 connect(m_phononWidget, SIGNAL(playingStarted()),
751 this, SLOT(slotPlayingStarted()));
752 connect(m_phononWidget, SIGNAL(playingStopped()),
753 this, SLOT(slotPlayingStopped()));
754
755 m_previewSeparator = new KSeparator(this);
756
757 const bool showPreview = InformationPanelSettings::showPreview();
758 m_preview->setVisible(showPreview);
759 m_previewSeparator->setVisible(showPreview);
760
761 if (MetaDataWidget::metaDataAvailable()) {
762 // rating, comment and tags
763 m_metaDataWidget = new MetaDataWidget(this);
764 m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
765
766 const bool showRating = InformationPanelSettings::showRating();
767 const bool showComment = InformationPanelSettings::showComment();
768 const bool showTags = InformationPanelSettings::showTags();
769
770 m_metaDataWidget->setRatingVisible(showRating);
771 m_metaDataWidget->setCommentVisible(showComment);
772 m_metaDataWidget->setTagsVisible(showTags);
773
774 m_metaDataSeparator = new KSeparator(this);
775 m_metaDataSeparator->setVisible(showRating || showComment || showTags);
776 }
777
778 // general meta text information
779 m_metaTextLabel = new MetaTextLabel(this);
780 m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
781
782 m_metaTextArea = new QScrollArea(this);
783 m_metaTextArea->setWidget(m_metaTextLabel);
784 m_metaTextArea->setWidgetResizable(true);
785 m_metaTextArea->setFrameShape(QFrame::NoFrame);
786
787 QWidget* viewport = m_metaTextArea->viewport();
788 viewport->installEventFilter(this);
789
790 QPalette palette = viewport->palette();
791 palette.setColor(viewport->backgroundRole(), QColor(Qt::transparent));
792 viewport->setPalette(palette);
793
794 layout->addWidget(m_nameLabel);
795 layout->addWidget(new KSeparator(this));
796 layout->addWidget(m_preview);
797 layout->addWidget(m_phononWidget);
798 layout->addWidget(m_previewSeparator);
799 if (m_metaDataWidget != 0) {
800 layout->addWidget(m_metaDataWidget);
801 layout->addWidget(m_metaDataSeparator);
802 }
803 layout->addWidget(m_metaTextArea);
804 setLayout(layout);
805
806 org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(),
807 QDBusConnection::sessionBus(), this);
808 connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString)));
809 connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString)));
810 connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList)));
811 connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList)));
812 connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString)));
813 connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString)));
814
815 m_initialized = true;
816 }
817
818 #include "informationpanel.moc"