mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-04 15:49:09 +00:00
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
This commit is contained in:
parent
33fab30e57
commit
fb0b2a777b
|
@ -54,7 +54,6 @@
|
|||
#include <kmessagebox.h>
|
||||
#include <knewmenu.h>
|
||||
#include <konqmimedata.h>
|
||||
#include <konq_undo.h>
|
||||
#include <kpropertiesdialog.h>
|
||||
#include <kprotocolinfo.h>
|
||||
#include <ktoggleaction.h>
|
||||
|
@ -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 <hausmann@kde.org>
|
||||
// Copyright (C) 2006 David Faure <faure@kde.org>
|
||||
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"
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue