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