]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanelcontent.cpp
Dolphin Information Panel: Use Nepomuk2::FileMetadataWidget
[dolphin.git] / src / panels / information / informationpanelcontent.cpp
index 7de6052e037e4a118a26372b1bfd50241ecfb662..355a571967d44b47bad72af9ebdad46a4eb9c91b 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>
 
+#include <nepomuk2/filemetadatawidget.h>
+
+#include <panels/places/placesitem.h>
+#include <panels/places/placesitemmodel.h>
+
 #include <Phonon/BackendCapabilities>
 #include <Phonon/MediaObject>
 #include <Phonon/SeekSlider>
@@ -52,7 +56,6 @@
 #include "filemetadataconfigurationdialog.h"
 #include "phononwidget.h"
 #include "pixmapviewer.h"
-#include "views/dolphinplacesmodel.h"
 
 InformationPanelContent::InformationPanelContent(QWidget* parent) :
     QWidget(parent),
@@ -63,7 +66,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 +93,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 +107,7 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     const bool previewsShown = InformationPanelSettings::previewsShown();
     m_preview->setVisible(previewsShown);
 
-    m_metaDataWidget = new KFileMetaDataWidget(parent);
+    m_metaDataWidget = new Nepomuk2::FileMetaDataWidget(parent);
     m_metaDataWidget->setFont(KGlobalSettings::smallestReadableFont());
     m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
     connect(m_metaDataWidget, SIGNAL(urlActivated(KUrl)), this, SIGNAL(urlActivated(KUrl)));
@@ -137,6 +139,8 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     layout->addWidget(m_nameLabel);
     layout->addWidget(new KSeparator());
     layout->addWidget(m_metaDataArea);
+
+    m_placesItemModel = new PlacesItemModel(this);
 }
 
 InformationPanelContent::~InformationPanelContent()
@@ -173,8 +177,12 @@ 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(KFileItem,QPixmap)),
                     this, SLOT(showPreview(KFileItem,QPixmap)));
@@ -190,17 +198,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 +335,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 +349,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;
         }
     }
@@ -418,7 +412,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));
     }