]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanel.cpp
Fixed issue that when renaming an item that still the old item name will be shown...
[dolphin.git] / src / panels / information / informationpanel.cpp
index 389fb4a52cfe88277fab1ab97a8960aacd15199a..adf53348fd105e7207930f7211e90eb17fd3e52f 100644 (file)
@@ -31,6 +31,7 @@
 #include <kglobalsettings.h>
 #include <kfilemetainfo.h>
 #include <kiconeffect.h>
+#include <kmenu.h>
 #include <kseparator.h>
 #include <kiconloader.h>
 
@@ -58,6 +59,7 @@
 #include <QVBoxLayout>
 
 #include "settings/dolphinsettings.h"
+#include "informationpaneldialog.h"
 #include "metadatawidget.h"
 #include "metatextlabel.h"
 #include "phononwidget.h"
@@ -78,7 +80,8 @@ InformationPanel::InformationPanel(QWidget* parent) :
     m_phononWidget(0),
     m_metaDataWidget(0),
     m_metaTextArea(0),
-    m_metaTextLabel(0)
+    m_metaTextLabel(0),
+    m_dialog(0)
 {
 }
 
@@ -207,6 +210,23 @@ bool InformationPanel::eventFilter(QObject* obj, QEvent* event)
     return Panel::eventFilter(obj, event);
 }
 
+void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
+{
+    Panel::contextMenuEvent(event);
+
+    KMenu popup(this);
+    popup.addAction(i18nc("@action:inmenu", "Configure..."));
+    if (popup.exec(QCursor::pos()) != 0) {
+        if (m_dialog == 0) {
+            m_dialog = new InformationPanelDialog(this);
+            m_dialog->setAttribute(Qt::WA_DeleteOnClose);
+            m_dialog->show();
+        } else {
+            m_dialog->raise();
+        }
+    }
+}
+
 void InformationPanel::showItemInfo()
 {
     if (!isVisible()) {
@@ -293,11 +313,26 @@ void InformationPanel::showPreview(const KFileItem& item,
 
 void InformationPanel::slotFileRenamed(const QString& source, const QString& dest)
 {
-    if (m_shownUrl == KUrl(source)) {
-        // the currently shown file has been renamed, hence update the item information
-        // for the renamed file
-        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest));
-        requestDelayedItemInfo(item);
+    const KUrl sourceUrl = KUrl(source);
+
+    // Verify whether the renamed item is selected. If this is the case, the
+    // selection must be updated with the renamed item.
+    bool isSelected = false;
+    for (int i = m_selection.size() - 1; i >= 0; --i) {
+        if (m_selection[i].url() == sourceUrl) {
+            m_selection.removeAt(i);
+            isSelected = true;
+            break;
+        }
+    }
+
+    if ((m_shownUrl == sourceUrl) || isSelected) {
+        m_shownUrl = KUrl(dest);
+        m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl);
+        if (isSelected) {
+            m_selection.append(m_fileItem);
+        }
+        showItemInfo();
     }
 }
 
@@ -327,8 +362,7 @@ void InformationPanel::slotFilesRemoved(const QStringList& files)
         if (m_shownUrl == KUrl(fileName)) {
             // the currently shown item has been removed, show
             // the parent directory as fallback
-            m_shownUrl = url();
-            showItemInfo();
+            reset();
             break;
         }
     }
@@ -349,8 +383,7 @@ void InformationPanel::slotLeftDirectory(const QString& directory)
         // has been unmounted. In this case no directory change will be
         // done in Dolphin, but the Information Panel must be updated to
         // indicate an invalid directory.
-        m_shownUrl = url();
-        showItemInfo();
+        reset();
     }
 }
 
@@ -399,6 +432,9 @@ void InformationPanel::showMetaInfo()
             }
         }
         m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
+
+        delete m_phononWidget;
+        m_phononWidget = 0;
     } else {
         const KFileItem item = fileItem();
         if (item.isDir()) {
@@ -502,6 +538,14 @@ void InformationPanel::setNameLabelText(const QString& text)
     m_nameLabel->setText(wrappedText);
 }
 
+void InformationPanel::reset()
+{
+    m_selection.clear();
+    m_shownUrl = url();
+    m_fileItem = KFileItem();
+    showItemInfo();
+}
+
 void InformationPanel::init()
 {
     const int spacing = KDialog::spacingHint();