]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanelcontent.cpp
Merge branch 'KDE/4.10'
[dolphin.git] / src / panels / information / informationpanelcontent.cpp
index 1084fa0855c351c46e30812b7342ad03c57d2f8a..0c4c62fc7c6f710cf0233e4b8f5378d3765b4bd3 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>
@@ -50,7 +58,6 @@
 
 #include "dolphin_informationpanelsettings.h"
 #include "filemetadataconfigurationdialog.h"
-#include "settings/dolphinsettings.h"
 #include "phononwidget.h"
 #include "pixmapviewer.h"
 
@@ -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,10 +97,8 @@ 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);
@@ -105,7 +111,11 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     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 +147,8 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     layout->addWidget(m_nameLabel);
     layout->addWidget(new KSeparator());
     layout->addWidget(m_metaDataArea);
+
+    m_placesItemModel = new PlacesItemModel(this);
 }
 
 InformationPanelContent::~InformationPanelContent()
@@ -151,7 +163,7 @@ void InformationPanelContent::showItem(const KFileItem& item)
     const KUrl itemUrl = item.url();
     const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty();
     if (!applyPlace(itemUrl)) {
-        setNameLabelText(item.text());
+        setNameLabelText(Qt::escape(item.text()));
         if (isSearchUrl) {
             // in the case of a search-URL the URL is not readable for humans
             // (at least not useful to show in the Information Panel)
@@ -173,13 +185,17 @@ void InformationPanelContent::showItem(const KFileItem& item)
                 m_outdatedPreviewTimer->start();
             }
 
-            KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
+            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(const KFileItem&, const QPixmap&)),
-                    this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
-            connect(job, SIGNAL(failed(const KFileItem&)),
-                    this, SLOT(showIcon(const KFileItem&)));
+            connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
+                    this, SLOT(showPreview(KFileItem,QPixmap)));
+            connect(job, SIGNAL(failed(KFileItem)),
+                    this, SLOT(showIcon(KFileItem)));
         }
     }
 
@@ -190,17 +206,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 {
@@ -333,14 +343,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()
@@ -352,15 +357,12 @@ void InformationPanelContent::refreshMetaData()
 
 bool InformationPanelContent::applyPlace(const KUrl& url)
 {
-    KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
-    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(Qt::escape(item->text()));
+            m_preview->setPixmap(KIcon(item->icon()).pixmap(128, 128));
             return true;
         }
     }
@@ -418,7 +420,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));
     }