]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Reanimate drag and drop support for the URL navigator.
authorPeter Penz <peter.penz19@gmail.com>
Sat, 6 Jan 2007 19:51:48 +0000 (19:51 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 6 Jan 2007 19:51:48 +0000 (19:51 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=620633

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/urlbutton.h
src/urlnavigatorbutton.cpp

index 14ec8dcd4a27cb636edc9b385bd87ab9317b5e75..6c4dda80ab828467373125409d24e8b26e0c824c 100644 (file)
@@ -181,8 +181,9 @@ void DolphinContextMenu::openItemContextMenu()
     const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction);
     for (int i = 0; i < count; ++i) {
         QAction* action = dolphin->actionCollection()->action(KStandardAction::stdName(actionNames[i]));
     const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction);
     for (int i = 0; i < count; ++i) {
         QAction* action = dolphin->actionCollection()->action(KStandardAction::stdName(actionNames[i]));
-        if (action)
+        if (action != 0) {
             popup->addAction(action);
             popup->addAction(action);
+        }
     }
     popup->insertSeparator();
 
     }
     popup->insertSeparator();
 
@@ -204,7 +205,7 @@ void DolphinContextMenu::openItemContextMenu()
     // insert 'Bookmark this folder...' entry
     // urls is a list of selected items, so insert boolmark menu if
     // urls contains only one item, i.e. no multiple selection made
     // insert 'Bookmark this folder...' entry
     // urls is a list of selected items, so insert boolmark menu if
     // urls contains only one item, i.e. no multiple selection made
-    QAction *bookmarkAction = 0;
+    QActionbookmarkAction = 0;
     if (m_fileInfo->isDir() && (urls.count() == 1)) {
         bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
     }
     if (m_fileInfo->isDir() && (urls.count() == 1)) {
         bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
     }
index 15d9b02f1665084f6f1c72f2667ba89d93642496..96a919747e17fb53567929d885d7fb5bb9a8736a 100644 (file)
@@ -114,9 +114,10 @@ void DolphinMainWindow::setActiveView(DolphinView* view)
 }
 
 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
 }
 
 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
-                       const KUrl& destination)
+                                 const KUrl& destination)
 {
 {
-    int selectedIndex = -1;
+    m_dropDestination = destination;
+    m_droppedUrls = urls;
 
     /* KDE4-TODO
     const ButtonState keyboardState = KApplication::keyboardMouseState();
 
     /* KDE4-TODO
     const ButtonState keyboardState = KApplication::keyboardMouseState();
@@ -141,49 +142,22 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls,
         // no shortcut is used, hence open a popup menu
         KMenu popup(this);
 
         // no shortcut is used, hence open a popup menu
         KMenu popup(this);
 
-        popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
-        popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
-        popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
-        popup.insertSeparator();
-        popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
-        popup.setAccel(i18n("Escape"), 3);
+        QAction* moveAction = popup.addAction(SmallIcon("goto"), i18n("&Move Here"));
+        connect(moveAction, SIGNAL(triggered()), this, SLOT(moveDroppedItems()));
 
 
-        /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
-        popup.exec(QCursor::pos());
-        selectedIndex = 0; // KD4-TODO: use QAction instead of switch below
-        // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
-    }
-
-    if (selectedIndex < 0) {
-        return;
-    }
-
-    switch (selectedIndex) {
-        case 0: {
-            // 'Move Here' has been selected
-            updateViewProperties(urls);
-            moveUrls(urls, destination);
-            break;
-        }
+        QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" ));
+        connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems()));
 
 
-        case 1: {
-            // 'Copy Here' has been selected
-            updateViewProperties(urls);
-            copyUrls(urls, destination);
-            break;
-        }
+        QAction* linkAction = popup.addAction(i18n("&Link Here"));
+        connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems()));
 
 
-        case 2: {
-            // 'Link Here' has been selected
-            KIO::Job* job = KIO::link(urls, destination);
-            addPendingUndoJob(job, DolphinCommand::Link, urls, destination);
-            break;
-        }
+        QAction* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel"));
+        popup.insertSeparator(cancelAction);
 
 
-        default:
-            // 'Cancel' has been selected
-            break;
+        popup.exec(QCursor::pos());
     }
     }
+
+    m_droppedUrls.clear();
 }
 
 void DolphinMainWindow::refreshViews()
 }
 
 void DolphinMainWindow::refreshViews()
@@ -315,6 +289,22 @@ void DolphinMainWindow::openNewMainWindow()
     DolphinApplication::app()->createMainWindow()->show();
 }
 
     DolphinApplication::app()->createMainWindow()->show();
 }
 
+void DolphinMainWindow::moveDroppedItems()
+{
+    moveUrls(m_droppedUrls, m_dropDestination);
+}
+
+void DolphinMainWindow::copyDroppedItems()
+{
+    copyUrls(m_droppedUrls, m_dropDestination);
+}
+
+void DolphinMainWindow::linkDroppedItems()
+{
+    KIO::Job* job = KIO::link(m_droppedUrls, m_dropDestination);
+    addPendingUndoJob(job, DolphinCommand::Link, m_droppedUrls, m_dropDestination);
+}
+
 void DolphinMainWindow::closeEvent(QCloseEvent* event)
 {
     // KDE4-TODO
 void DolphinMainWindow::closeEvent(QCloseEvent* event)
 {
     // KDE4-TODO
@@ -1545,30 +1535,6 @@ void DolphinMainWindow::updateGoActions()
     goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
 }
 
     goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
 }
 
-void DolphinMainWindow::updateViewProperties(const KUrl::List& urls)
-{
-    if (urls.isEmpty()) {
-        return;
-    }
-
-    // Updating the view properties might take up to several seconds
-    // when dragging several thousand Urls. Writing a KIO slave for this
-    // use case is not worth the effort, but at least the main widget
-    // must be disabled and a progress should be shown.
-    ProgressIndicator progressIndicator(this,
-                                        i18n("Updating view properties..."),
-                                        QString::null,
-                                        urls.count());
-
-    KUrl::List::ConstIterator end = urls.end();
-    for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) {
-        progressIndicator.execOperation();
-
-        ViewProperties props(*it);
-        props.save();
-    }
-}
-
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
 {
     KIO::Job* job = KIO::copy(source, dest);
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
 {
     KIO::Job* job = KIO::copy(source, dest);
index b9a9db3d84e37c0e673cdba73c57992216a87533..fcfab60f04a1111daeab333292591192044943fd 100644 (file)
@@ -358,6 +358,24 @@ private slots:
     /** Open a new main window. */
     void openNewMainWindow();
 
     /** Open a new main window. */
     void openNewMainWindow();
 
+    /**
+     * Moves the items indicated by m_droppedUrls to the URL
+     * m_destination.
+     */
+    void moveDroppedItems();
+
+    /**
+     * Copies the items indicated by m_droppedUrls to the URL
+     * m_destination.
+     */
+    void copyDroppedItems();
+
+    /**
+     * Links the items indicated by m_droppedUrls to the URL
+     * m_destination.
+     */
+    void linkDroppedItems();
+
 private:
     DolphinMainWindow();
     void init();
 private:
     DolphinMainWindow();
     void init();
@@ -371,7 +389,6 @@ private:
     void updateEditActions();
     void updateViewActions();
     void updateGoActions();
     void updateEditActions();
     void updateViewActions();
     void updateGoActions();
-    void updateViewProperties(const KUrl::List& urls);
     void copyUrls(const KUrl::List& source, const KUrl& dest);
     void moveUrls(const KUrl::List& source, const KUrl& dest);
     void addPendingUndoJob(KIO::Job* job,
     void copyUrls(const KUrl::List& source, const KUrl& dest);
     void moveUrls(const KUrl::List& source, const KUrl& dest);
     void addPendingUndoJob(KIO::Job* job,
@@ -392,6 +409,9 @@ private:
     QSplitter* m_splitter;
     DolphinView* m_activeView;
 
     QSplitter* m_splitter;
     DolphinView* m_activeView;
 
+    KUrl m_dropDestination;
+    KUrl::List m_droppedUrls;
+
     /**
      * DolphinMainWindowsupports only one or two views, which
      * are handled internally as primary and secondary view.
     /**
      * DolphinMainWindowsupports only one or two views, which
      * are handled internally as primary and secondary view.
index 41d81c24b57f56cd1da177c94d6e91b192b7d58b..a52fdf463fdaa5cd1ff3a0c91d7b0547c3d91659 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef UrlBUTTON_H
-#define UrlBUTTON_H
+#ifndef URLBUTTON_H
+#define URLBUTTON_H
 
 
-#include <qpushbutton.h>
-//Added by qt3to4:
 #include <QEvent>
 #include <QEvent>
+#include <QPushButton>
 
 class KUrl;
 class UrlNavigator;
 class QPainter;
 
 /**
 
 class KUrl;
 class UrlNavigator;
 class QPainter;
 
 /**
- * @brief Base class for buttons of the Url navigator.
+ * @brief Base class for buttons of the URL navigator.
  *
  *
- * Each button of the Url navigator contains an Url, which
+ * Each button of the URL navigator contains an URL, which
  * is set as soon as the button has been clicked.
 *
  * @author Peter Penz
  * is set as soon as the button has been clicked.
 *
  * @author Peter Penz
index 44b7ae9669294e0328fa71f249d0262eca20076a..70c25b20b9a21038ad16c5f7cf064363a05456b0 100644 (file)
@@ -209,28 +209,31 @@ void UrlNavigatorButton::dropEvent(QDropEvent* event)
         return;
     }
 
         return;
     }
 
-    KUrl::List urls;
-    /* KDE4-TODO:
-    if (KUrlDrag::decode(event, urls) && !urls.isEmpty()) {
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (!urls.isEmpty()) {
+        event->acceptProposedAction();
+
         setDisplayHintEnabled(DraggedHint, true);
 
         QString path(urlNavigator()->url().prettyUrl());
         setDisplayHintEnabled(DraggedHint, true);
 
         QString path(urlNavigator()->url().prettyUrl());
-        path = path.section('/', 0, m_index);
+        path = path.section('/', 0, m_index + 2);
 
 
-        Dolphin::mainWin().dropUrls(urls, KUrl(path));
+        DolphinMainWindow* win = urlNavigator()->dolphinView()->mainWindow();
+        win->dropUrls(urls, KUrl(path));
 
         setDisplayHintEnabled(DraggedHint, false);
         update();
 
         setDisplayHintEnabled(DraggedHint, false);
         update();
-    }*/
+    }
 }
 
 void UrlNavigatorButton::dragEnterEvent(QDragEnterEvent* event)
 {
 }
 
 void UrlNavigatorButton::dragEnterEvent(QDragEnterEvent* event)
 {
-    /* KDE4-TODO:
-    event->accept(KUrlDrag::canDecode(event));
+    if (event->mimeData()->hasUrls()) {
+        setDisplayHintEnabled(DraggedHint, true);
+        event->acceptProposedAction();
 
 
-    setDisplayHintEnabled(DraggedHint, true);*/
-    update();
+        update();
+    }
 }
 
 void UrlNavigatorButton::dragLeaveEvent(QDragLeaveEvent* event)
 }
 
 void UrlNavigatorButton::dragLeaveEvent(QDragLeaveEvent* event)