]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Reanimated cut-, copy- and paste- functionality as preparation for moving to KonqUndo...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 17 Dec 2006 11:52:26 +0000 (11:52 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 17 Dec 2006 11:52:26 +0000 (11:52 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=614325

src/dolphinmainwindow.cpp
src/undomanager.cpp
src/undomanager.h

index 0c527bb5182ec3854058a8b228444a61773b4b81..dd985fc1d1c939dfb75b5c704ebcee00e6cce6c3 100644 (file)
@@ -657,33 +657,33 @@ void DolphinMainWindow::cut()
     // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
     // in libkonq
     m_clipboardContainsCutData = true;
-    /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
-                                       widget());
-    QApplication::clipboard()->setData(data);*/
+
+    QMimeData* mimeData = new QMimeData();
+    const KUrl::List selectedUrls = m_activeView->selectedUrls();
+    selectedUrls.populateMimeData(mimeData);
+
+    QApplication::clipboard()->setMimeData(mimeData);
 }
 
 void DolphinMainWindow::copy()
 {
     m_clipboardContainsCutData = false;
-    /* KDE4-TODO:
-    Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
-                                     widget());
-    QApplication::clipboard()->setData(data);*/
+
+    QMimeData* mimeData = new QMimeData();
+    const KUrl::List selectedUrls = m_activeView->selectedUrls();
+    selectedUrls.populateMimeData(mimeData);
+
+    QApplication::clipboard()->setMimeData(mimeData);
 }
 
 void DolphinMainWindow::paste()
 {
-    /* KDE4-TODO:   - see KonqOperations::doPaste
     QClipboard* clipboard = QApplication::clipboard();
-    QMimeSource* data = clipboard->data();
-    if (!KUrlDrag::canDecode(data)) {
-        return;
-    }
+    const QMimeData* mimeData = clipboard->mimeData();
 
     clearStatusBar();
 
-    KUrl::List sourceUrls;
-    KUrlDrag::decode(data, sourceUrls);
+    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
 
     // per default the pasting is done into the current Url of the view
     KUrl destUrl(m_activeView->url());
@@ -702,8 +702,12 @@ void DolphinMainWindow::paste()
         }
     }
 
-
-    updateViewProperties(sourceUrls);
+    // TODO #1: use libkonq commands (see doPaste() implementation
+    // KIO::Job* job = KIO::pasteClipboard(destUrl, this, false);
+    // ...
+    // TODO #2: this boolean doesn't work between instances of dolphin or with konqueror or with other
+    // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
+    // in libkonq
     if (m_clipboardContainsCutData) {
         moveUrls(sourceUrls, destUrl);
         m_clipboardContainsCutData = false;
@@ -711,7 +715,7 @@ void DolphinMainWindow::paste()
     }
     else {
         copyUrls(sourceUrls, destUrl);
-    }*/
+    }
 }
 
 void DolphinMainWindow::updatePasteAction()
@@ -723,13 +727,12 @@ void DolphinMainWindow::updatePasteAction()
 
     QString text(i18n("Paste"));
     QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* data = clipboard->mimeData();
-    /* KDE4-TODO:
-    if (KUrlDrag::canDecode(data)) {
+    const QMimeData* mimeData = clipboard->mimeData();
+
+    KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+    if (!urls.isEmpty()) {
         pasteAction->setEnabled(true);
 
-        KUrl::List urls;
-        KUrlDrag::decode(data, urls);
         const int count = urls.count();
         if (count == 1) {
             pasteAction->setText(i18n("Paste 1 File"));
@@ -738,10 +741,10 @@ void DolphinMainWindow::updatePasteAction()
             pasteAction->setText(i18n("Paste %1 Files").arg(count));
         }
     }
-    else {*/
+    else {
         pasteAction->setEnabled(false);
         pasteAction->setText(i18n("Paste"));
-    //}
+    }
 
     if (pasteAction->isEnabled()) {
         KUrl::List urls = m_activeView->selectedUrls();
@@ -1597,9 +1600,9 @@ void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
 }
 
 void DolphinMainWindow::addPendingUndoJob(KIO::Job* job,
-                                DolphinCommand::Type commandType,
-                                const KUrl::List& source,
-                                const KUrl& dest)
+                                          DolphinCommand::Type commandType,
+                                          const KUrl::List& source,
+                                          const KUrl& dest)
 {
     connect(job, SIGNAL(result(KJob*)),
             this, SLOT(addUndoOperation(KJob*)));
index e6946cfe31af4209493d04730e6a190b39f95452..30e0dba35c4d183053ee50d2982bde55fca85b01 100644 (file)
@@ -76,13 +76,15 @@ void UndoManager::addCommand(const DolphinCommand& command)
 {
     ++m_historyIndex;
 
+    QList<DolphinCommand>::iterator it = m_history.begin();
+    it += m_historyIndex;
     if (m_recordMacro) {
         DolphinCommand macroCommand = command;
         macroCommand.m_macroIndex = m_macroCounter;
-        m_history.insert(m_history.at(m_historyIndex), macroCommand);
+        m_history.insert(it, macroCommand);
     }
     else {
-        m_history.insert(m_history.at(m_historyIndex), command);
+        m_history.insert(it, command);
     }
 
     emit undoAvailable(true);
@@ -125,7 +127,7 @@ void UndoManager::undo(DolphinMainWindow* mainWindow)
     calcStepsCount(macroCount, progressCount);
 
     /*
-     * KDE4, ### TODO Only here to avoid possible crash 
+     * KDE4, ### TODO Only here to avoid possible crash
      */
     ProgressIndicator progressIndicator(mainWindow, i18n("Executing undo operation..."),
                                         i18n("Executed undo operation."),
index c3cfda56ecc1f3aaaf4f3fbf99b8f0a64b2d259c..baed41947a5bbb6bcf4e6840e1cd7f03a6efd47a 100644 (file)
 #ifndef UNDOMANAGER_H
 #define UNDOMANAGER_H
 
-#include <qobject.h>
+#include <QObject>
 #include <QPointer>
-#include <q3valuelist.h>
+#include <QList>
+
 #include <kurl.h>
 #include <kio/jobclasses.h>
 
@@ -127,7 +128,7 @@ public slots:
     /**
      * Performs a redo operation on the last command where an undo
      * operation has been applied.
-     * 
+     *
      * @param mainwindow The mainwindow where to show progress
      */
     void redo(DolphinMainWindow* mainwindow);
@@ -182,7 +183,7 @@ private:
     bool m_recordMacro;
     int m_historyIndex;
     int m_macroCounter;
-    Q3ValueList<DolphinCommand> m_history;
+    QList<DolphinCommand> m_history;
 
     /**
      * Dependent from the current history index \a m_historyIndex