]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* implement the DragAndDropHelper as singleton derived from QObject, so that emitting...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 8 Nov 2008 16:22:30 +0000 (16:22 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 8 Nov 2008 16:22:30 +0000 (16:22 +0000)
* show an information message in the statusbar, if items are dragged into the same directory

TODO: although the signal seems to get connected correctly, the slot DolphinMainWindow::showInformationMessage() is not invoked when the signal is emitted -> will debug this later, it is important that the new string is added before the message freeze

svn path=/trunk/KDE/kdebase/apps/; revision=881627

12 files changed:
src/dolphincolumnwidget.cpp
src/dolphindetailsview.cpp
src/dolphinfileplacesview.cpp
src/dolphiniconsview.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/dolphinviewcontainer.cpp
src/draganddrophelper.cpp
src/draganddrophelper.h
src/sidebartreeview.cpp
src/treeviewsidebarpage.cpp

index 8b0b267348bcfaa895c45e4896a3dec572532028..93c9cc23554619ffbb61116c68195a0b0f4511bd 100644 (file)
@@ -288,12 +288,12 @@ QStyleOptionViewItem DolphinColumnWidget::viewOptions() const
 
 void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
 {
-    DragAndDropHelper::startDrag(this, supportedActions, m_view->m_controller);
+    DragAndDropHelper::instance().startDrag(this, supportedActions, m_view->m_controller);
 }
 
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 }
@@ -322,7 +322,7 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event)
     }
     setDirtyRegion(m_dropRect);
 
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
index 3fa7ae196caf75d6e6bfb22502ac1497bf3c804e..f8379a7dabe2d7f11e6ddd21a5233a6bfc3617d7 100644 (file)
@@ -307,13 +307,13 @@ void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
 
 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
 {
-    DragAndDropHelper::startDrag(this, supportedActions, m_controller);
+    DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
     m_band.show = false;
 }
 
 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 
@@ -346,7 +346,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
         setDirtyRegion(m_dropRect);
     }
 
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
index c36820ef53f32e8ded13847a122a83b2e687be87..df3e6fd878f87df0e87e425784a7878d604e656a 100644 (file)
@@ -45,7 +45,7 @@ void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event)
 
 void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
 {
-    DragAndDropHelper::dropUrls(KFileItem(), dest, event, parent);
+    DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent);
 }
 
 void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url)
index e5578df328d4b6ed3299f946d5284ea6be2540cf..0dd7dd7190ebb85fd697180770d8220d38679b6d 100644 (file)
@@ -209,12 +209,12 @@ void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
     // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll
     // fix this in KDE 4.1
     KCategorizedView::startDrag(supportedActions);
-    DragAndDropHelper::startDrag(this, supportedActions, m_controller);
+    DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
 }
 
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 }
@@ -242,7 +242,7 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
             m_dropRect.setSize(QSize()); // set as invalid
         }
     }
-    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+    if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
index 0dc2ecb57bb898f2a6554e548e43580d48b939c4..3f0b215cca4b3cb96c4c85b9854b36762de30230 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "dolphin_generalsettings.h"
 #include "dolphin_iconsmodesettings.h"
+#include "draganddrophelper.h"
 
 #include <kaction.h>
 #include <kactioncollection.h>
@@ -82,8 +83,6 @@
 #include <QSplitter>
 #include <QDockWidget>
 
-#include <kdebug.h>
-
 DolphinMainWindow::DolphinMainWindow(int id) :
     KXmlGuiWindow(0),
     m_newMenu(0),
@@ -115,7 +114,9 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
             this, SLOT(showCommand(CommandType)));
     connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
-            this, SLOT(slotHandlePlacesError(const QString&)));
+            this, SLOT(showErrorMessage(const QString&)));
+    connect(&DragAndDropHelper::instance(), SIGNAL(informationMessage(const QString&)),
+            this, SLOT(showInformationMessage(const QString&)));
 }
 
 DolphinMainWindow::~DolphinMainWindow()
@@ -441,7 +442,7 @@ void DolphinMainWindow::quit()
     close();
 }
 
-void DolphinMainWindow::slotHandlePlacesError(const QString &message)
+void DolphinMainWindow::showErrorMessage(const QString& message)
 {
     if (!message.isEmpty()) {
         DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
@@ -449,6 +450,14 @@ void DolphinMainWindow::slotHandlePlacesError(const QString &message)
     }
 }
 
+void DolphinMainWindow::showInformationMessage(const QString& message)
+{
+    if (!message.isEmpty()) {
+        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+        statusBar->setMessage(message, DolphinStatusBar::Information);
+    }
+}
+
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
     QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
index c98d2386a3adc7cbd8e52c947698472ac86efbde..8cfdda34a2e8dfba4b3e28506b3fb8024b6ed0f3 100644 (file)
@@ -168,11 +168,11 @@ private slots:
     /** Updates the 'Create New...' sub menu. */
     void updateNewMenu();
 
-    /**
-     * Shows the error information from the places model
-     * in the status bar.
-     */
-    void slotHandlePlacesError(const QString &message);
+    /** Shows the error message in the status bar of the active view. */
+    void showErrorMessage(const QString& message);
+
+    /** Shows the information message in the status bar of the active view. */
+    void showInformationMessage(const QString& message);
 
     /**
      * Updates the state of the 'Undo' menu action dependent
index b74cbea530eaf6ff25d9e734811d1d7cd2e15a2b..8da92693672bd0246638940f2c94273c7ee680fe 100644 (file)
@@ -900,7 +900,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
                            const KUrl& destPath,
                            QDropEvent* event)
 {
-    DragAndDropHelper::dropUrls(destItem, destPath, event, this);
+    DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
index ad79d6bb1132aa4083ba82394506827d2bee3b54..82ed40d41d450bba3b512ff83b2df9693f8e3bf0 100644 (file)
@@ -369,7 +369,7 @@ void DolphinViewContainer::saveRootUrl(const KUrl& url)
 
 void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
 {
-    DragAndDropHelper::dropUrls(KFileItem(), destination, event, this);
+    DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
 }
 
 void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
index ded92bf04fef0d73db47b4166cdb458f3d389a2c..a4971a62cc7a08aa3088db773b74e49c384d986c 100644 (file)
@@ -24,6 +24,7 @@
 #include <kdirmodel.h>
 #include <kfileitem.h>
 #include <kicon.h>
+#include <klocale.h>
 #include <konq_operations.h>
 
 #include <QAbstractItemView>
 #include <QtDBus>
 #include <QDrag>
 
-bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData)
+class DragAndDropHelperSingleton
+{
+public:
+    DragAndDropHelper instance;
+};
+K_GLOBAL_STATIC(DragAndDropHelperSingleton, s_dragAndDropHelper)
+
+DragAndDropHelper& DragAndDropHelper::instance()
+{
+    return s_dragAndDropHelper->instance;
+}
+
+bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData) const
 {
     return mimeData->hasUrls() || mimeData->hasFormat("application/x-kde-dndextract");
 }
@@ -87,12 +100,22 @@ void DragAndDropHelper::dropUrls(const KFileItem& destItem,
     } else {                                
         const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
         const KUrl sourceDir = KUrl(urls.first().directory());
-        if (sourceDir != destination) {
-            if (dropToItem) {
-                KonqOperations::doDrop(destItem, destination, event, widget);
-            } else {
-                KonqOperations::doDrop(KFileItem(), destination, event, widget);
-            }
+        if (sourceDir == destination) {
+            const QString msg = i18ncp("@info:status",
+                                       "The dropped item is already inside the folder %2",
+                                       "The dropped items are already inside the folder %2",
+                                       urls.count(), destination.fileName());
+            emit informationMessage(msg);
+        } else if (dropToItem) {
+            KonqOperations::doDrop(destItem, destination, event, widget);
+        } else {
+            KonqOperations::doDrop(KFileItem(), destination, event, widget);
         }
     }
 }
+
+DragAndDropHelper::DragAndDropHelper()
+{
+}
+
+#include "draganddrophelper.moc"
index 920ff5135d06fe7f81091ad6dd6545ca222abb69..c6abd46c39b9fde8b2bce0ef0479226f7b720b6e 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef DRAGANDDROPHELPER_H
 #define DRAGANDDROPHELPER_H
 
-#include <QtCore/Qt>
+#include <QObject>
 
 class DolphinController;
 class KFileItem;
@@ -39,22 +39,25 @@ class QWidget;
  * DolphinColumnView and SidebarTreeView to have a consistent
  * drag and drop behavior between all views.
  */
-class DragAndDropHelper
+class DragAndDropHelper : public QObject
 {
+    Q_OBJECT
 
 public:
+    static DragAndDropHelper& instance();
+    
     /**
      * Returns true, if Dolphin supports the dragging of
      * the given mime data.
      */
-    static bool isMimeDataSupported(const QMimeData* mimeData);
+    bool isMimeDataSupported(const QMimeData* mimeData) const;
     
     /**
      * Creates a drag object for the view \a itemView for all selected items.
      */
-    static void startDrag(QAbstractItemView* itemView,
-                          Qt::DropActions supportedActions,
-                          DolphinController* controller = 0);
+    void startDrag(QAbstractItemView* itemView,
+                   Qt::DropActions supportedActions,
+                   DolphinController* controller = 0);
                           
     /**
      * Handles the dropping of URLs to the given
@@ -66,10 +69,17 @@ public:
      * @param event     Drop event.
      * @param widget    Source widget where the dragging has been started.
      */
-    static void dropUrls(const KFileItem& destItem,
-                         const KUrl& destPath,
-                         QDropEvent* event,
-                         QWidget* widget);
+    void dropUrls(const KFileItem& destItem,
+                  const KUrl& destPath,
+                  QDropEvent* event,
+                  QWidget* widget);
+signals:
+    void informationMessage(const QString& msg);
+    
+private:
+    DragAndDropHelper();
+    
+    friend class DragAndDropHelperSingleton;
 };
 
 #endif
index 00c98f6e7e7d7c89346fef4d5558eb31d00371f5..3b1b13bb1b3f6cbde2be62544bb635b88b2a7173 100644 (file)
@@ -90,7 +90,7 @@ bool SidebarTreeView::event(QEvent* event)
 
 void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
 {
-    DragAndDropHelper::startDrag(this, supportedActions);
+    DragAndDropHelper::instance().startDrag(this, supportedActions);
 }
 
 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
index 32779ffce8eb6ffd4a6b23c9d57f467149bc943b..04cef91ae440f901c8c6467255b7c200a1043c86 100644 (file)
@@ -207,7 +207,7 @@ void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event)
         KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
         Q_ASSERT(!item.isNull());
         if (item.isDir()) {
-            DragAndDropHelper::dropUrls(item, item.url(), event, this);
+            DragAndDropHelper::instance().dropUrls(item, item.url(), event, this);
         }
     }
 }