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