]> 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 a2d37b085561080add782e625222772ca4dae75a..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"
 
@@ -64,7 +71,7 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_nameLabel(0),
     m_metaDataWidget(0),
     m_metaDataArea(0),
-    m_enabledPlugins()
+    m_placesItemModel(0)
 {
     parent->installEventFilter(this);
 
@@ -90,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);
@@ -103,10 +108,14 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_nameLabel->setAlignment(Qt::AlignHCenter);
     m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
-    const bool showPreview = InformationPanelSettings::showPreview();
-    m_preview->setVisible(showPreview);
+    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)));
@@ -138,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()
@@ -152,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)
@@ -174,42 +185,32 @@ void InformationPanelContent::showItem(const KFileItem& item)
                 m_outdatedPreviewTimer->start();
             }
 
-            if (m_enabledPlugins.isEmpty()) {
-                const KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
-                m_enabledPlugins = globalConfig.readEntry("Plugins", QStringList()
-                                                                     << "directorythumbnail"
-                                                                     << "imagethumbnail"
-                                                                     << "jpegthumbnail");
+            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);
             }
 
-            KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, m_preview->width(), m_preview->height(),
-                                                    0, 0, false, true, &m_enabledPlugins);
-
-            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)));
         }
     }
 
-    if (m_metaDataWidget != 0) {
+    if (m_metaDataWidget) {
         m_metaDataWidget->show();
         m_metaDataWidget->setItems(KFileItemList() << item);
     }
 
-    if (InformationPanelSettings::showPreview()) {
+    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 {
@@ -234,7 +235,7 @@ void InformationPanelContent::showItems(const KFileItemList& items)
     m_preview->setPixmap(icon);
     setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", items.count()));
 
-    if (m_metaDataWidget != 0) {
+    if (m_metaDataWidget) {
         m_metaDataWidget->setItems(items);
     }
 
@@ -276,7 +277,7 @@ void InformationPanelContent::configureSettings(const QList<QAction*>& customCon
     QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview"));
     previewAction->setIcon(KIcon("view-preview"));
     previewAction->setCheckable(true);
-    previewAction->setChecked(InformationPanelSettings::showPreview());
+    previewAction->setChecked(InformationPanelSettings::previewsShown());
 
     QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure..."));
     configureAction->setIcon(KIcon("configure"));
@@ -289,14 +290,14 @@ void InformationPanelContent::configureSettings(const QList<QAction*>& customCon
     // Open the popup and adjust the settings for the
     // selected action.
     QAction* action = popup.exec(QCursor::pos());
-    if (action == 0) {
+    if (!action) {
         return;
     }
 
     const bool isChecked = action->isChecked();
     if (action == previewAction) {
         m_preview->setVisible(isChecked);
-        InformationPanelSettings::setShowPreview(isChecked);
+        InformationPanelSettings::setPreviewsShown(isChecked);
     } else if (action == configureAction) {
         FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog();
         dialog->setDescription(i18nc("@label::textbox",
@@ -315,7 +316,8 @@ void InformationPanelContent::showIcon(const KFileItem& item)
     m_outdatedPreviewTimer->stop();
     m_pendingPreview = false;
     if (!applyPlace(item.targetUrl())) {
-        m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous));
+        KIcon icon(item.iconName(), KIconLoader::global(), item.overlays());
+        m_preview->setPixmap(icon.pixmap(KIconLoader::SizeEnormous));
     }
 }
 
@@ -323,10 +325,11 @@ void InformationPanelContent::showPreview(const KFileItem& item,
                                           const QPixmap& pixmap)
 {
     m_outdatedPreviewTimer->stop();
-
     Q_UNUSED(item);
     if (m_pendingPreview) {
-        m_preview->setPixmap(pixmap);
+        QPixmap p = pixmap;
+        KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop);
+        m_preview->setPixmap(p);
         m_pendingPreview = false;
     }
 }
@@ -340,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()
@@ -359,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,14 +413,14 @@ void InformationPanelContent::adjustWidgetSizes(int width)
 
     // The metadata widget also contains a text widget which may return
     // a large preferred width.
-    if (m_metaDataWidget != 0) {
+    if (m_metaDataWidget) {
         m_metaDataWidget->setMaximumWidth(maxWidth);
     }
 
     // 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));
     }