]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Use custom implementation of KonqUndoManager::UiInterface for Dolphin. This allows...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 25 Jan 2007 19:37:19 +0000 (19:37 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 25 Jan 2007 19:37:19 +0000 (19:37 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=627130

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h

index cf224971ee9a145299fd57f46f3593ef83425432..203a85b384286e05e57dd184655a5c5e33a677a1 100644 (file)
@@ -54,7 +54,6 @@
 #include <kmessagebox.h>\r
 #include <knewmenu.h>\r
 #include <konqmimedata.h>\r
-#include <konq_undo.h>\r
 #include <kpropertiesdialog.h>\r
 #include <kprotocolinfo.h>\r
 #include <ktoggleaction.h>\r
@@ -82,9 +81,12 @@ DolphinMainWindow::DolphinMainWindow() :
 \r
     KonqUndoManager::incRef();\r
 \r
-    connect(KonqUndoManager::self(), SIGNAL(undoAvailable(bool)),\r
+    KonqUndoManager* undoManager = KonqUndoManager::self();\r
+    undoManager->setUiInterface(new UndoUiInterface(this));\r
+\r
+    connect(undoManager, SIGNAL(undoAvailable(bool)),\r
             this, SLOT(slotUndoAvailable(bool)));\r
-    connect(KonqUndoManager::self(), SIGNAL(undoTextChanged(const QString&)),\r
+    connect(undoManager, SIGNAL(undoTextChanged(const QString&)),\r
             this, SLOT(slotUndoTextChanged(const QString&)));\r
 }\r
 \r
@@ -182,8 +184,7 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls,
             break;\r
 \r
         case Qt::LinkAction:\r
-            KonqOperations::copy(this, KonqOperations::LINK, urls, destination);\r
-            m_undoOperations.append(KonqOperations::LINK);\r
+            linkUrls(urls, destination);\r
             break;\r
 \r
         default:\r
@@ -1244,6 +1245,12 @@ void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
     m_undoOperations.append(KonqOperations::MOVE);\r
 }\r
 \r
+void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)\r
+{\r
+    KonqOperations::copy(this, KonqOperations::LINK, source, dest);\r
+    m_undoOperations.append(KonqOperations::LINK);\r
+}\r
+\r
 void DolphinMainWindow::clearStatusBar()\r
 {\r
     m_activeView->statusBar()->clear();\r
@@ -1273,4 +1280,41 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
 \r
 }\r
 \r
+DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :\r
+    m_mainWin(mainWin)\r
+{\r
+    assert(m_mainWin != 0);\r
+}\r
+\r
+DolphinMainWindow::UndoUiInterface::~UndoUiInterface()\r
+{\r
+}\r
+\r
+void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)\r
+{\r
+    DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar();\r
+    statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);\r
+}\r
+\r
+bool DolphinMainWindow::UndoUiInterface::copiedFileWasModified(const KUrl& src,\r
+                                                               const KUrl& dest,\r
+                                                               time_t /*srcTime*/,\r
+                                                               time_t destTime)\r
+{\r
+    // The following code has been taken from libkonq/konq_undo.cc\r
+    // Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>\r
+    // Copyright (C) 2006 David Faure <faure@kde.org>\r
+    const QDateTime destDt = QDateTime::fromTime_t(destTime);\r
+    const QString timeStr = KGlobal::locale()->formatDateTime(destDt, true /* short */);\r
+    return KMessageBox::warningContinueCancel(\r
+        m_mainWin,\r
+        i18n( "The file %1 was copied from %2, but since then it has apparently been modified at %3.\n"\r
+              "Undoing the copy will delete the file, and all modifications will be lost.\n"\r
+              "Are you sure you want to delete %4?", dest.pathOrUrl(), src.pathOrUrl(), timeStr, dest.pathOrUrl()),\r
+        i18n( "Undo File Copy Confirmation" ),\r
+        KStandardGuiItem::cont(),\r
+        QString(),\r
+        KMessageBox::Notify | KMessageBox::Dangerous ) == KMessageBox::Continue;\r
+}\r
+\r
 #include "dolphinmainwindow.moc"\r
index 804192aa4ca99d94ab2843e26d40aa7b781cfeab..ac10a37b458234e773895d99caed6339703075a6 100644 (file)
@@ -27,6 +27,7 @@
 #include <kmainwindow.h>
 #include <ksortablelist.h>
 #include <konq_operations.h>
+#include <konq_undo.h>
 
 #include <QList>
 
@@ -338,6 +339,7 @@ private:
     void updateGoActions();
     void copyUrls(const KUrl::List& source, const KUrl& dest);
     void moveUrls(const KUrl::List& source, const KUrl& dest);
+    void linkUrls(const KUrl::List& source, const KUrl& dest);
     void clearStatusBar();
 
     /**
@@ -367,14 +369,22 @@ private:
     /// remember pending undo operations until they are finished
     QList<KonqOperations::Operation> m_undoOperations;
 
-    /** Contains meta information for creating files. */
-    struct CreateFileEntry
-    {
-        QString name;
-        QString filePath;
-        QString templatePath;
-        QString icon;
-        QString comment;
+    /**
+     * Implements a custom error handling for the undo manager. This
+     * assures that all errors are shown in the status bar of Dolphin
+     * instead as modal error dialog with an OK button.
+     */
+    class UndoUiInterface : public KonqUndoManager::UiInterface {
+    public:
+        UndoUiInterface(DolphinMainWindow* mainWin);
+        virtual ~UndoUiInterface();
+        virtual void jobError(KIO::Job* job);
+        virtual bool copiedFileWasModified(const KUrl& src,
+                                           const KUrl& dest,
+                                           time_t srcTime,
+                                           time_t destTime);
+    private:
+        DolphinMainWindow* m_mainWin;
     };
 };