]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanelcontent.cpp
Fix information panel interpreting html tags
[dolphin.git] / src / panels / information / informationpanelcontent.cpp
index a82319ef990fcd3d4831cf3d6fbe9ace7e5a4d44..9b0dd0092f4806695fad9137c770403ae572bfa9 100644 (file)
@@ -21,9 +21,8 @@
 
 #include <KDialog>
 #include <KFileItem>
-#include <kfilemetadatawidget.h>
-#include <KFilePlacesModel>
 #include <KGlobalSettings>
+#include <KIO/JobUiDelegate>
 #include <KIO/PreviewJob>
 #include <KIconEffect>
 #include <KIconLoader>
 #include <kseparator.h>
 #include <KStringHandler>
 
+#ifndef HAVE_NEPOMUK
+#include <KFileMetaDataWidget>
+#else
+#include <nepomuk2/filemetadatawidget.h>
+#endif
+
+#include <panels/places/placesitem.h>
+#include <panels/places/placesitemmodel.h>
+
 #include <Phonon/BackendCapabilities>
 #include <Phonon/MediaObject>
 #include <Phonon/SeekSlider>
@@ -52,7 +60,6 @@
 #include "filemetadataconfigurationdialog.h"
 #include "phononwidget.h"
 #include "pixmapviewer.h"
-#include "views/dolphinplacesmodel.h"
 
 InformationPanelContent::InformationPanelContent(QWidget* parent) :
     QWidget(parent),
@@ -63,7 +70,8 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_phononWidget(0),
     m_nameLabel(0),
     m_metaDataWidget(0),
-    m_metaDataArea(0)
+    m_metaDataArea(0),
+    m_placesItemModel(0)
 {
     parent->installEventFilter(this);
 
@@ -89,23 +97,26 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_phononWidget = new PhononWidget(parent);
     m_phononWidget->hide();
     m_phononWidget->setMinimumWidth(minPreviewWidth);
-    connect(m_phononWidget, SIGNAL(playingStarted()),
-            this, SLOT(slotPlayingStarted()));
-    connect(m_phononWidget, SIGNAL(playingStopped()),
-            this, SLOT(slotPlayingStopped()));
+    connect(m_phononWidget, SIGNAL(hasVideoChanged(bool)),
+            this, SLOT(slotHasVideoChanged(bool)));
 
     // name
     m_nameLabel = new QLabel(parent);
     QFont font = m_nameLabel->font();
     font.setBold(true);
     m_nameLabel->setFont(font);
+    m_nameLabel->setTextFormat(Qt::PlainText);
     m_nameLabel->setAlignment(Qt::AlignHCenter);
     m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
     const bool previewsShown = InformationPanelSettings::previewsShown();
     m_preview->setVisible(previewsShown);
 
+#ifndef HAVE_NEPOMUK
     m_metaDataWidget = new KFileMetaDataWidget(parent);
+#else
+    m_metaDataWidget = new Nepomuk2::FileMetaDataWidget(parent);
+#endif
     m_metaDataWidget->setFont(KGlobalSettings::smallestReadableFont());
     m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
     connect(m_metaDataWidget, SIGNAL(urlActivated(KUrl)), this, SIGNAL(urlActivated(KUrl)));
@@ -137,6 +148,8 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     layout->addWidget(m_nameLabel);
     layout->addWidget(new KSeparator());
     layout->addWidget(m_metaDataArea);
+
+    m_placesItemModel = new PlacesItemModel(this);
 }
 
 InformationPanelContent::~InformationPanelContent()
@@ -176,6 +189,9 @@ void InformationPanelContent::showItem(const KFileItem& item)
             KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
             job->setScaleType(KIO::PreviewJob::Unscaled);
             job->setIgnoreMaximumSize(item.isLocalFile());
+            if (job->ui()) {
+                job->ui()->setWindow(this);
+            }
 
             connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
                     this, SLOT(showPreview(KFileItem,QPixmap)));
@@ -191,17 +207,11 @@ void InformationPanelContent::showItem(const KFileItem& item)
 
     if (InformationPanelSettings::previewsShown()) {
         const QString mimeType = item.mimetype();
-        const bool usePhonon = Phonon::BackendCapabilities::isMimeTypeAvailable(mimeType) &&
-                               (mimeType != "image/png");  // TODO: workaround, as Phonon
-                                                           // thinks it supports PNG images
+        const bool usePhonon = mimeType.startsWith("audio/") || mimeType.startsWith("video/");
         if (usePhonon) {
             m_phononWidget->show();
-            PhononWidget::Mode mode = mimeType.startsWith(QLatin1String("video"))
-                                      ? PhononWidget::Video
-                                      : PhononWidget::Audio;
-            m_phononWidget->setMode(mode);
             m_phononWidget->setUrl(item.targetUrl());
-            if ((mode == PhononWidget::Video) && m_preview->isVisible()) {
+            if (m_preview->isVisible()) {
                 m_phononWidget->setVideoSize(m_preview->size());
             }
         } else {
@@ -334,14 +344,9 @@ void InformationPanelContent::markOutdatedPreview()
     m_preview->setPixmap(disabledPixmap);
 }
 
-void InformationPanelContent::slotPlayingStarted()
+void InformationPanelContent::slotHasVideoChanged(bool hasVideo)
 {
-    m_preview->setVisible(m_phononWidget->mode() != PhononWidget::Video);
-}
-
-void InformationPanelContent::slotPlayingStopped()
-{
-    m_preview->setVisible(true);
+    m_preview->setVisible(!hasVideo);
 }
 
 void InformationPanelContent::refreshMetaData()
@@ -353,15 +358,12 @@ void InformationPanelContent::refreshMetaData()
 
 bool InformationPanelContent::applyPlace(const KUrl& url)
 {
-    KFilePlacesModel* placesModel = DolphinPlacesModel::instance();
-    const int count = placesModel->rowCount();
-
+    const int count = m_placesItemModel->count();
     for (int i = 0; i < count; ++i) {
-        QModelIndex index = placesModel->index(i, 0);
-
-        if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
-            setNameLabelText(placesModel->text(index));
-            m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128));
+        const PlacesItem* item = m_placesItemModel->placesItem(i);
+        if (item->url().equals(url, KUrl::CompareWithoutTrailingSlash)) {
+            setNameLabelText(item->text());
+            m_preview->setPixmap(KIcon(item->icon()).pixmap(128, 128));
             return true;
         }
     }
@@ -419,7 +421,7 @@ void InformationPanelContent::adjustWidgetSizes(int width)
     // try to increase the preview as large as possible
     m_preview->setSizeHint(QSize(maxWidth, maxWidth));
 
-    if (m_phononWidget->isVisible() && (m_phononWidget->mode() == PhononWidget::Video)) {
+    if (m_phononWidget->isVisible()) {
         // assure that the size of the video player is the same as the preview size
         m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth));
     }