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