]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.cpp
Disable additional properties per default as discussed with Sebastian TrĂ¼g.
[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 #1: use Nepomuk::formatValue(res, prop) if available
587 // instead of it.value().toString()
588 // TODO #2: using tunedLabel() is a workaround for KDE 4.3 until
589 // we get translated labels
590 m_metaTextLabel->add(tunedLabel(label), it.value().toString());
591 }
592 ++it;
593 }
594 #endif
595 }
596
597 if (m_metaDataWidget != 0) {
598 m_metaDataWidget->setFile(item.targetUrl());
599 }
600 }
601
602 updatePhononWidget();
603 }
604
605 KFileItem InformationPanel::fileItem() const
606 {
607 if (!m_fileItem.isNull()) {
608 return m_fileItem;
609 }
610
611 if (!m_selection.isEmpty()) {
612 Q_ASSERT(m_selection.count() == 1);
613 return m_selection.first();
614 }
615
616 // no item is hovered and no selection has been done: provide
617 // an item for the directory represented by m_shownUrl
618 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
619 item.refresh();
620 return item;
621 }
622
623 bool InformationPanel::showMultipleSelectionInfo() const
624 {
625 return m_fileItem.isNull() && (m_selection.count() > 1);
626 }
627
628 bool InformationPanel::isEqualToShownUrl(const KUrl& url) const
629 {
630 return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash);
631 }
632
633 void InformationPanel::setNameLabelText(const QString& text)
634 {
635 QTextOption textOption;
636 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
637
638 QTextLayout textLayout(text);
639 textLayout.setFont(m_nameLabel->font());
640 textLayout.setTextOption(textOption);
641
642 QString wrappedText;
643 wrappedText.reserve(text.length());
644
645 // wrap the text to fit into the width of m_nameLabel
646 textLayout.beginLayout();
647 QTextLine line = textLayout.createLine();
648 while (line.isValid()) {
649 line.setLineWidth(m_nameLabel->width());
650 wrappedText += text.mid(line.textStart(), line.textLength());
651
652 line = textLayout.createLine();
653 if (line.isValid()) {
654 wrappedText += QChar::LineSeparator;
655 }
656 }
657 textLayout.endLayout();
658
659 m_nameLabel->setText(wrappedText);
660 }
661
662 void InformationPanel::reset()
663 {
664 m_selection.clear();
665 m_shownUrl = url();
666 m_fileItem = KFileItem();
667 showItemInfo();
668 }
669
670 void InformationPanel::initMetaInfoSettings(KConfigGroup& group)
671 {
672 if (!group.readEntry("initialized", false)) {
673 // The resource file is read the first time. Assure
674 // that some meta information is disabled per default.
675
676 static const char* disabledProperties[] = {
677 "asText", "contentSize", "depth", "fileExtension",
678 "fileName", "fileSize", "isPartOf", "mimetype", "name",
679 "parentUrl", "plainTextContent", "sourceModified",
680 "size", "url",
681 0 // mandatory last entry
682 };
683
684 int i = 0;
685 while (disabledProperties[i] != 0) {
686 group.writeEntry(disabledProperties[i], false);
687 ++i;
688 }
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(QLatin1String("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 QString InformationPanel::tunedLabel(const QString& label) const
726 {
727 QString tunedLabel;
728 const int labelLength = label.length();
729 if (labelLength > 0) {
730 tunedLabel.reserve(labelLength);
731 tunedLabel = label[0].toUpper();
732 for (int i = 1; i < labelLength; ++i) {
733 if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) {
734 tunedLabel += ' ';
735 tunedLabel += label[i].toLower();
736 } else {
737 tunedLabel += label[i];
738 }
739 }
740 }
741 return tunedLabel;
742 }
743
744 void InformationPanel::init()
745 {
746 m_infoTimer = new QTimer(this);
747 m_infoTimer->setInterval(300);
748 m_infoTimer->setSingleShot(true);
749 connect(m_infoTimer, SIGNAL(timeout()),
750 this, SLOT(slotInfoTimeout()));
751
752 // Initialize timer for disabling an outdated preview with a small
753 // delay. This prevents flickering if the new preview can be generated
754 // within a very small timeframe.
755 m_outdatedPreviewTimer = new QTimer(this);
756 m_outdatedPreviewTimer->setInterval(300);
757 m_outdatedPreviewTimer->setSingleShot(true);
758 connect(m_outdatedPreviewTimer, SIGNAL(timeout()),
759 this, SLOT(markOutdatedPreview()));
760
761 QVBoxLayout* layout = new QVBoxLayout;
762 layout->setSpacing(KDialog::spacingHint());
763
764 // name
765 m_nameLabel = new QLabel(this);
766 QFont font = m_nameLabel->font();
767 font.setBold(true);
768 m_nameLabel->setFont(font);
769 m_nameLabel->setAlignment(Qt::AlignHCenter);
770 m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
771 m_nameLabel->setMaximumWidth(KIconLoader::SizeEnormous);
772
773 // preview
774 const int minPreviewWidth = KIconLoader::SizeEnormous + KIconLoader::SizeMedium;
775
776 m_preview = new PixmapViewer(this);
777 m_preview->setMinimumWidth(minPreviewWidth);
778 m_preview->setMinimumHeight(KIconLoader::SizeEnormous);
779
780 m_phononWidget = new PhononWidget(this);
781 m_phononWidget->setMinimumWidth(minPreviewWidth);
782 connect(m_phononWidget, SIGNAL(playingStarted()),
783 this, SLOT(slotPlayingStarted()));
784 connect(m_phononWidget, SIGNAL(playingStopped()),
785 this, SLOT(slotPlayingStopped()));
786
787 m_previewSeparator = new KSeparator(this);
788
789 const bool showPreview = InformationPanelSettings::showPreview();
790 m_preview->setVisible(showPreview);
791 m_previewSeparator->setVisible(showPreview);
792
793 if (MetaDataWidget::metaDataAvailable()) {
794 // rating, comment and tags
795 m_metaDataWidget = new MetaDataWidget(this);
796 m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
797 m_metaDataWidget->setMaximumWidth(KIconLoader::SizeEnormous);
798
799 const bool showRating = InformationPanelSettings::showRating();
800 const bool showComment = InformationPanelSettings::showComment();
801 const bool showTags = InformationPanelSettings::showTags();
802
803 m_metaDataWidget->setRatingVisible(showRating);
804 m_metaDataWidget->setCommentVisible(showComment);
805 m_metaDataWidget->setTagsVisible(showTags);
806
807 m_metaDataSeparator = new KSeparator(this);
808 m_metaDataSeparator->setVisible(showRating || showComment || showTags);
809 }
810
811 // general meta text information
812 m_metaTextLabel = new MetaTextLabel(this);
813 m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
814
815 m_metaTextArea = new QScrollArea(this);
816 m_metaTextArea->setWidget(m_metaTextLabel);
817 m_metaTextArea->setWidgetResizable(true);
818 m_metaTextArea->setFrameShape(QFrame::NoFrame);
819
820 QWidget* viewport = m_metaTextArea->viewport();
821 viewport->installEventFilter(this);
822
823 QPalette palette = viewport->palette();
824 palette.setColor(viewport->backgroundRole(), QColor(Qt::transparent));
825 viewport->setPalette(palette);
826
827 layout->addWidget(m_nameLabel);
828 layout->addWidget(new KSeparator(this));
829 layout->addWidget(m_preview);
830 layout->addWidget(m_phononWidget);
831 layout->addWidget(m_previewSeparator);
832 if (m_metaDataWidget != 0) {
833 layout->addWidget(m_metaDataWidget);
834 layout->addWidget(m_metaDataSeparator);
835 }
836 layout->addWidget(m_metaTextArea);
837 setLayout(layout);
838
839 org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(),
840 QDBusConnection::sessionBus(), this);
841 connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString)));
842 connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString)));
843 connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList)));
844 connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList)));
845 connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString)));
846 connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString)));
847
848 m_initialized = true;
849 }
850
851 #include "informationpanel.moc"