]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.cpp
fixed issue that the video preview size was wrong during resizing the information...
[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 if (m_phononWidget->isVisible() && (m_phononWidget->mode() == PhononWidget::Video)) {
211 // assure that the size of the video player is the same as the preview size
212 m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth));
213 }
214 }
215 Panel::resizeEvent(event);
216 }
217
218 bool InformationPanel::eventFilter(QObject* obj, QEvent* event)
219 {
220 // Check whether the size of the meta text area has changed and adjust
221 // the fixed width in a way that no horizontal scrollbar needs to be shown.
222 if ((obj == m_metaTextArea->viewport()) && (event->type() == QEvent::Resize)) {
223 QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
224 m_metaTextLabel->setFixedWidth(resizeEvent->size().width());
225 }
226 return Panel::eventFilter(obj, event);
227 }
228
229 void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
230 {
231 Panel::contextMenuEvent(event);
232
233 #ifdef HAVE_NEPOMUK
234 if (showMultipleSelectionInfo()) {
235 return;
236 }
237
238 KMenu popup(this);
239
240 QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview"));
241 previewAction->setIcon(KIcon("view-preview"));
242 previewAction->setCheckable(true);
243 previewAction->setChecked(InformationPanelSettings::showPreview());
244
245 const bool metaDataAvailable = MetaDataWidget::metaDataAvailable();
246
247 QAction* ratingAction = popup.addAction(i18nc("@action:inmenu", "Rating"));
248 ratingAction->setIcon(KIcon("rating"));
249 ratingAction->setCheckable(true);
250 ratingAction->setChecked(InformationPanelSettings::showRating());
251 ratingAction->setEnabled(metaDataAvailable);
252
253 QAction* commentAction = popup.addAction(i18nc("@action:inmenu", "Comment"));
254 commentAction->setIcon(KIcon("text-plain"));
255 commentAction->setCheckable(true);
256 commentAction->setChecked(InformationPanelSettings::showComment());
257 commentAction->setEnabled(metaDataAvailable);
258
259 QAction* tagsAction = popup.addAction(i18nc("@action:inmenu", "Tags"));
260 tagsAction->setCheckable(true);
261 tagsAction->setChecked(InformationPanelSettings::showTags());
262 tagsAction->setEnabled(metaDataAvailable);
263
264 KConfig config("kmetainformationrc", KConfig::NoGlobals);
265 KConfigGroup settings = config.group("Show");
266 initMetaInfoSettings(settings);
267
268 QList<QAction*> actions;
269
270 // Get all meta information labels that are available for
271 // the currently shown file item and add them to the popup.
272 Nepomuk::Resource res(fileItem().url());
273 QHash<QUrl, Nepomuk::Variant> properties = res.properties();
274 QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
275 while (it != properties.constEnd()) {
276 Nepomuk::Types::Property prop(it.key());
277 const QString key = prop.label();
278
279 // Meta information provided by Nepomuk that is already
280 // available from KFileItem should not be configurable.
281 bool skip = (key == "fileExtension") ||
282 (key == "name") ||
283 (key == "sourceModified") ||
284 (key == "size") ||
285 (key == "mime type");
286 if (!skip) {
287 // Check whether there is already a meta information
288 // having the same label. In this case don't show it
289 // twice in the menu.
290 foreach (const QAction* action, actions) {
291 if (action->data().toString() == key) {
292 skip = true;
293 break;
294 }
295 }
296 }
297
298 if (!skip) {
299 const QString label = key; // TODO
300 QAction* action = new QAction(label, &popup);
301 action->setCheckable(true);
302 action->setChecked(settings.readEntry(key, true));
303 action->setData(key);
304 actions.append(action);
305 }
306
307 ++it;
308 }
309
310 if (actions.count() > 0) {
311 popup.addSeparator();
312
313 // add all items alphabetically sorted to the popup
314 qSort(actions.begin(), actions.end(), lessThan);
315 foreach (QAction* action, actions) {
316 popup.addAction(action);
317 }
318 }
319
320 // Open the popup and adjust the settings for the
321 // selected action.
322 QAction* action = popup.exec(QCursor::pos());
323 if (action == 0) {
324 return;
325 }
326
327 const bool isChecked = action->isChecked();
328 if (action == previewAction) {
329 m_preview->setVisible(isChecked);
330 m_previewSeparator->setVisible(isChecked);
331 InformationPanelSettings::setShowPreview(isChecked);
332 updatePhononWidget();
333 } else if (action == ratingAction) {
334 m_metaDataWidget->setRatingVisible(isChecked);
335 InformationPanelSettings::setShowRating(isChecked);
336 } else if (action == commentAction) {
337 m_metaDataWidget->setCommentVisible(isChecked);
338 InformationPanelSettings::setShowComment(isChecked);
339 } else if (action == tagsAction) {
340 m_metaDataWidget->setTagsVisible(isChecked);
341 InformationPanelSettings::setShowTags(isChecked);
342 } else {
343 settings.writeEntry(action->data().toString(), action->isChecked());
344 settings.sync();
345 showMetaInfo();
346 }
347
348 const bool visible = m_metaDataWidget->isRatingVisible() ||
349 m_metaDataWidget->isCommentVisible() ||
350 m_metaDataWidget->areTagsVisible();
351 m_metaDataSeparator->setVisible(visible);
352 #endif
353 }
354
355 void InformationPanel::showItemInfo()
356 {
357 if (!isVisible()) {
358 return;
359 }
360
361 cancelRequest();
362
363 if (showMultipleSelectionInfo()) {
364 KIconLoader iconLoader;
365 QPixmap icon = iconLoader.loadIcon("dialog-information",
366 KIconLoader::NoGroup,
367 KIconLoader::SizeEnormous);
368 m_preview->setPixmap(icon);
369 setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count()));
370 m_shownUrl = KUrl();
371 } else {
372 const KFileItem item = fileItem();
373 const KUrl itemUrl = item.url();
374 if (!applyPlace(itemUrl)) {
375 // try to get a preview pixmap from the item...
376 m_pendingPreview = true;
377
378 // Mark the currently shown preview as outdated. This is done
379 // with a small delay to prevent a flickering when the next preview
380 // can be shown within a short timeframe.
381 m_outdatedPreviewTimer->start();
382
383 KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item,
384 m_preview->width(),
385 m_preview->height(),
386 0,
387 0,
388 false,
389 true);
390
391 connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
392 this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
393 connect(job, SIGNAL(failed(const KFileItem&)),
394 this, SLOT(showIcon(const KFileItem&)));
395
396 setNameLabelText(itemUrl.fileName());
397 }
398 }
399
400 showMetaInfo();
401 }
402
403 void InformationPanel::slotInfoTimeout()
404 {
405 m_shownUrl = m_urlCandidate;
406 showItemInfo();
407 }
408
409 void InformationPanel::markOutdatedPreview()
410 {
411 KIconEffect iconEffect;
412 QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(),
413 KIconLoader::Desktop,
414 KIconLoader::DisabledState);
415 m_preview->setPixmap(disabledPixmap);
416 }
417
418 void InformationPanel::showIcon(const KFileItem& item)
419 {
420 m_outdatedPreviewTimer->stop();
421 m_pendingPreview = false;
422 if (!applyPlace(item.url())) {
423 m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous));
424 }
425 }
426
427 void InformationPanel::showPreview(const KFileItem& item,
428 const QPixmap& pixmap)
429 {
430 m_outdatedPreviewTimer->stop();
431
432 Q_UNUSED(item);
433 if (m_pendingPreview) {
434 m_preview->setPixmap(pixmap);
435 m_pendingPreview = false;
436 }
437 }
438
439 void InformationPanel::slotFileRenamed(const QString& source, const QString& dest)
440 {
441 const KUrl sourceUrl = KUrl(source);
442
443 // Verify whether the renamed item is selected. If this is the case, the
444 // selection must be updated with the renamed item.
445 bool isSelected = false;
446 for (int i = m_selection.size() - 1; i >= 0; --i) {
447 if (m_selection[i].url() == sourceUrl) {
448 m_selection.removeAt(i);
449 isSelected = true;
450 break;
451 }
452 }
453
454 if ((m_shownUrl == sourceUrl) || isSelected) {
455 m_shownUrl = KUrl(dest);
456 m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
457 if (isSelected) {
458 m_selection.append(m_fileItem);
459 }
460 showItemInfo();
461 }
462 }
463
464 void InformationPanel::slotFilesAdded(const QString& directory)
465 {
466 if (m_shownUrl == KUrl(directory)) {
467 // If the 'trash' icon changes because the trash has been emptied or got filled,
468 // the signal filesAdded("trash:/") will be emitted.
469 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory));
470 requestDelayedItemInfo(item);
471 }
472 }
473
474 void InformationPanel::slotFilesChanged(const QStringList& files)
475 {
476 foreach (const QString& fileName, files) {
477 if (m_shownUrl == KUrl(fileName)) {
478 showItemInfo();
479 break;
480 }
481 }
482 }
483
484 void InformationPanel::slotFilesRemoved(const QStringList& files)
485 {
486 foreach (const QString& fileName, files) {
487 if (m_shownUrl == KUrl(fileName)) {
488 // the currently shown item has been removed, show
489 // the parent directory as fallback
490 reset();
491 break;
492 }
493 }
494 }
495
496 void InformationPanel::slotEnteredDirectory(const QString& directory)
497 {
498 if (m_shownUrl == KUrl(directory)) {
499 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory));
500 requestDelayedItemInfo(item);
501 }
502 }
503
504 void InformationPanel::slotLeftDirectory(const QString& directory)
505 {
506 if (m_shownUrl == KUrl(directory)) {
507 // The signal 'leftDirectory' is also emitted when a media
508 // has been unmounted. In this case no directory change will be
509 // done in Dolphin, but the Information Panel must be updated to
510 // indicate an invalid directory.
511 reset();
512 }
513 }
514
515 void InformationPanel::slotPlayingStarted()
516 {
517 m_preview->setVisible(m_phononWidget->mode() != PhononWidget::Video);
518 }
519
520 void InformationPanel::slotPlayingStopped()
521 {
522 m_preview->setVisible(true);
523 }
524
525 bool InformationPanel::applyPlace(const KUrl& url)
526 {
527 KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
528 int count = placesModel->rowCount();
529
530 for (int i = 0; i < count; ++i) {
531 QModelIndex index = placesModel->index(i, 0);
532
533 if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
534 setNameLabelText(placesModel->text(index));
535 m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128));
536 return true;
537 }
538 }
539
540 return false;
541 }
542
543 void InformationPanel::cancelRequest()
544 {
545 m_infoTimer->stop();
546 }
547
548 void InformationPanel::showMetaInfo()
549 {
550 m_metaTextLabel->clear();
551
552 if (showMultipleSelectionInfo()) {
553 if (m_metaDataWidget != 0) {
554 KUrl::List urls;
555 foreach (const KFileItem& item, m_selection) {
556 urls.append(item.targetUrl());
557 }
558 m_metaDataWidget->setFiles(urls);
559 }
560
561 quint64 totalSize = 0;
562 foreach (const KFileItem& item, m_selection) {
563 // Only count the size of files, not dirs to match what
564 // DolphinViewContainer::selectionStatusBarText() does.
565 if (!item.isDir() && !item.isLink()) {
566 totalSize += item.size();
567 }
568 }
569 m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
570 } else {
571 const KFileItem item = fileItem();
572 if (item.isDir()) {
573 m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder"));
574 m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
575 } else {
576 m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment());
577
578 m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size()));
579 m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
580
581 #ifdef HAVE_NEPOMUK
582 KConfig config("kmetainformationrc", KConfig::NoGlobals);
583 KConfigGroup settings = config.group("Show");
584 initMetaInfoSettings(settings);
585
586 Nepomuk::Resource res(item.url());
587
588 QHash<QUrl, Nepomuk::Variant> properties = res.properties();
589 QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
590 while (it != properties.constEnd()) {
591 Nepomuk::Types::Property prop(it.key());
592 const QString label = prop.label();
593 if (settings.readEntry(label, true)) {
594 // TODO: use Nepomuk::formatValue(res, prop) if available
595 // instead of it.value().toString()
596 m_metaTextLabel->add(label, it.value().toString());
597 }
598 ++it;
599 }
600 #endif
601 }
602
603 if (m_metaDataWidget != 0) {
604 m_metaDataWidget->setFile(item.targetUrl());
605 }
606 }
607
608 updatePhononWidget();
609 }
610
611 KFileItem InformationPanel::fileItem() const
612 {
613 if (!m_fileItem.isNull()) {
614 return m_fileItem;
615 }
616
617 if (!m_selection.isEmpty()) {
618 Q_ASSERT(m_selection.count() == 1);
619 return m_selection.first();
620 }
621
622 // no item is hovered and no selection has been done: provide
623 // an item for the directory represented by m_shownUrl
624 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
625 item.refresh();
626 return item;
627 }
628
629 bool InformationPanel::showMultipleSelectionInfo() const
630 {
631 return m_fileItem.isNull() && (m_selection.count() > 1);
632 }
633
634 bool InformationPanel::isEqualToShownUrl(const KUrl& url) const
635 {
636 return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash);
637 }
638
639 void InformationPanel::setNameLabelText(const QString& text)
640 {
641 QTextOption textOption;
642 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
643
644 QTextLayout textLayout(text);
645 textLayout.setFont(m_nameLabel->font());
646 textLayout.setTextOption(textOption);
647
648 QString wrappedText;
649 wrappedText.reserve(text.length());
650
651 // wrap the text to fit into the width of m_nameLabel
652 textLayout.beginLayout();
653 QTextLine line = textLayout.createLine();
654 while (line.isValid()) {
655 line.setLineWidth(m_nameLabel->width());
656 wrappedText += text.mid(line.textStart(), line.textLength());
657
658 line = textLayout.createLine();
659 if (line.isValid()) {
660 wrappedText += QChar::LineSeparator;
661 }
662 }
663 textLayout.endLayout();
664
665 m_nameLabel->setText(wrappedText);
666 }
667
668 void InformationPanel::reset()
669 {
670 m_selection.clear();
671 m_shownUrl = url();
672 m_fileItem = KFileItem();
673 showItemInfo();
674 }
675
676 void InformationPanel::initMetaInfoSettings(KConfigGroup& group)
677 {
678 if (!group.readEntry("initialized", false)) {
679 // The resource file is read the first time. Assure
680 // that some meta information is disabled per default.
681 group.writeEntry("fileExtension", false);
682 group.writeEntry("url", false);
683 group.writeEntry("sourceModified", false);
684 group.writeEntry("parentUrl", false);
685 group.writeEntry("size", false);
686 group.writeEntry("mime type", false);
687 group.writeEntry("depth", false);
688 group.writeEntry("name", false);
689
690 // mark the group as initialized
691 group.writeEntry("initialized", true);
692 }
693 }
694
695 void InformationPanel::updatePhononWidget()
696 {
697 const bool multipleSelections = showMultipleSelectionInfo();
698 const bool showPreview = InformationPanelSettings::showPreview();
699
700 if (multipleSelections || !showPreview) {
701 m_phononWidget->hide();
702 } else if (!multipleSelections && showPreview) {
703 const KFileItem item = fileItem();
704 const QString mimeType = item.mimetype();
705 const bool usePhonon = Phonon::BackendCapabilities::isMimeTypeAvailable(mimeType) &&
706 (mimeType != "image/png"); // TODO: workaround, as Phonon
707 // thinks it supports PNG images
708 if (usePhonon) {
709 m_phononWidget->show();
710 PhononWidget::Mode mode = mimeType.startsWith("video")
711 ? PhononWidget::Video
712 : PhononWidget::Audio;
713 m_phononWidget->setMode(mode);
714 m_phononWidget->setUrl(item.url());
715 if ((mode == PhononWidget::Video) && m_preview->isVisible()) {
716 m_phononWidget->setVideoSize(m_preview->size());
717 }
718 } else {
719 m_phononWidget->hide();
720 m_preview->setVisible(true);
721 }
722 }
723 }
724
725 void InformationPanel::init()
726 {
727 m_infoTimer = new QTimer(this);
728 m_infoTimer->setInterval(300);
729 m_infoTimer->setSingleShot(true);
730 connect(m_infoTimer, SIGNAL(timeout()),
731 this, SLOT(slotInfoTimeout()));
732
733 // Initialize timer for disabling an outdated preview with a small
734 // delay. This prevents flickering if the new preview can be generated
735 // within a very small timeframe.
736 m_outdatedPreviewTimer = new QTimer(this);
737 m_outdatedPreviewTimer->setInterval(300);
738 m_outdatedPreviewTimer->setSingleShot(true);
739 connect(m_outdatedPreviewTimer, SIGNAL(timeout()),
740 this, SLOT(markOutdatedPreview()));
741
742 QVBoxLayout* layout = new QVBoxLayout;
743 layout->setSpacing(KDialog::spacingHint());
744
745 // name
746 m_nameLabel = new QLabel(this);
747 QFont font = m_nameLabel->font();
748 font.setBold(true);
749 m_nameLabel->setFont(font);
750 m_nameLabel->setAlignment(Qt::AlignHCenter);
751 m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
752 m_nameLabel->setMaximumWidth(KIconLoader::SizeEnormous);
753
754 // preview
755 const int minPreviewWidth = KIconLoader::SizeEnormous + KIconLoader::SizeMedium;
756
757 m_preview = new PixmapViewer(this);
758 m_preview->setMinimumWidth(minPreviewWidth);
759 m_preview->setMinimumHeight(KIconLoader::SizeEnormous);
760
761 m_phononWidget = new PhononWidget(this);
762 m_phononWidget->setMinimumWidth(minPreviewWidth);
763 connect(m_phononWidget, SIGNAL(playingStarted()),
764 this, SLOT(slotPlayingStarted()));
765 connect(m_phononWidget, SIGNAL(playingStopped()),
766 this, SLOT(slotPlayingStopped()));
767
768 m_previewSeparator = new KSeparator(this);
769
770 const bool showPreview = InformationPanelSettings::showPreview();
771 m_preview->setVisible(showPreview);
772 m_previewSeparator->setVisible(showPreview);
773
774 if (MetaDataWidget::metaDataAvailable()) {
775 // rating, comment and tags
776 m_metaDataWidget = new MetaDataWidget(this);
777 m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
778
779 const bool showRating = InformationPanelSettings::showRating();
780 const bool showComment = InformationPanelSettings::showComment();
781 const bool showTags = InformationPanelSettings::showTags();
782
783 m_metaDataWidget->setRatingVisible(showRating);
784 m_metaDataWidget->setCommentVisible(showComment);
785 m_metaDataWidget->setTagsVisible(showTags);
786
787 m_metaDataSeparator = new KSeparator(this);
788 m_metaDataSeparator->setVisible(showRating || showComment || showTags);
789 }
790
791 // general meta text information
792 m_metaTextLabel = new MetaTextLabel(this);
793 m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
794
795 m_metaTextArea = new QScrollArea(this);
796 m_metaTextArea->setWidget(m_metaTextLabel);
797 m_metaTextArea->setWidgetResizable(true);
798 m_metaTextArea->setFrameShape(QFrame::NoFrame);
799
800 QWidget* viewport = m_metaTextArea->viewport();
801 viewport->installEventFilter(this);
802
803 QPalette palette = viewport->palette();
804 palette.setColor(viewport->backgroundRole(), QColor(Qt::transparent));
805 viewport->setPalette(palette);
806
807 layout->addWidget(m_nameLabel);
808 layout->addWidget(new KSeparator(this));
809 layout->addWidget(m_preview);
810 layout->addWidget(m_phononWidget);
811 layout->addWidget(m_previewSeparator);
812 if (m_metaDataWidget != 0) {
813 layout->addWidget(m_metaDataWidget);
814 layout->addWidget(m_metaDataSeparator);
815 }
816 layout->addWidget(m_metaTextArea);
817 setLayout(layout);
818
819 org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(),
820 QDBusConnection::sessionBus(), this);
821 connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString)));
822 connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString)));
823 connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList)));
824 connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList)));
825 connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString)));
826 connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString)));
827
828 m_initialized = true;
829 }
830
831 #include "informationpanel.moc"