From fb0b2a777ba8064d4afc3e4e38a80d3505b49d0a Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 25 Jan 2007 19:37:19 +0000 Subject: [PATCH] Use custom implementation of KonqUndoManager::UiInterface for Dolphin. This allows that error messages are shown inside the status bar of Dolphin (otherwise a modal error dialog containing an "OK" button would be opened). svn path=/trunk/playground/utils/dolphin/; revision=627130 --- src/dolphinmainwindow.cpp | 54 +++++++++++++++++++++++++++++++++++---- src/dolphinmainwindow.h | 26 +++++++++++++------ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index cf224971ee..203a85b384 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -82,9 +81,12 @@ DolphinMainWindow::DolphinMainWindow() : KonqUndoManager::incRef(); - connect(KonqUndoManager::self(), SIGNAL(undoAvailable(bool)), + KonqUndoManager* undoManager = KonqUndoManager::self(); + undoManager->setUiInterface(new UndoUiInterface(this)); + + connect(undoManager, SIGNAL(undoAvailable(bool)), this, SLOT(slotUndoAvailable(bool))); - connect(KonqUndoManager::self(), SIGNAL(undoTextChanged(const QString&)), + connect(undoManager, SIGNAL(undoTextChanged(const QString&)), this, SLOT(slotUndoTextChanged(const QString&))); } @@ -182,8 +184,7 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls, break; case Qt::LinkAction: - KonqOperations::copy(this, KonqOperations::LINK, urls, destination); - m_undoOperations.append(KonqOperations::LINK); + linkUrls(urls, destination); break; default: @@ -1244,6 +1245,12 @@ void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest) m_undoOperations.append(KonqOperations::MOVE); } +void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest) +{ + KonqOperations::copy(this, KonqOperations::LINK, source, dest); + m_undoOperations.append(KonqOperations::LINK); +} + void DolphinMainWindow::clearStatusBar() { m_activeView->statusBar()->clear(); @@ -1273,4 +1280,41 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) } +DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : + m_mainWin(mainWin) +{ + assert(m_mainWin != 0); +} + +DolphinMainWindow::UndoUiInterface::~UndoUiInterface() +{ +} + +void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) +{ + DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar(); + statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); +} + +bool DolphinMainWindow::UndoUiInterface::copiedFileWasModified(const KUrl& src, + const KUrl& dest, + time_t /*srcTime*/, + time_t destTime) +{ + // The following code has been taken from libkonq/konq_undo.cc + // Copyright (C) 2000 Simon Hausmann + // Copyright (C) 2006 David Faure + const QDateTime destDt = QDateTime::fromTime_t(destTime); + const QString timeStr = KGlobal::locale()->formatDateTime(destDt, true /* short */); + return KMessageBox::warningContinueCancel( + m_mainWin, + i18n( "The file %1 was copied from %2, but since then it has apparently been modified at %3.\n" + "Undoing the copy will delete the file, and all modifications will be lost.\n" + "Are you sure you want to delete %4?", dest.pathOrUrl(), src.pathOrUrl(), timeStr, dest.pathOrUrl()), + i18n( "Undo File Copy Confirmation" ), + KStandardGuiItem::cont(), + QString(), + KMessageBox::Notify | KMessageBox::Dangerous ) == KMessageBox::Continue; +} + #include "dolphinmainwindow.moc" diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 804192aa4c..ac10a37b45 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -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 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; }; };