* adjusted Dolphin to use KonqOperations::doDrop() instead of using a custom implementation

* used new signals jobRecordingStarted() and jobRecordingFinished from FileUndoManager to inform the user in the statusbar when a recorded command has been finished

svn path=/trunk/KDE/kdebase/apps/; revision=866777
This commit is contained in:
Peter Penz 2008-10-01 21:39:35 +00:00
parent db2013a2fd
commit aa0b09dac4
11 changed files with 74 additions and 140 deletions

View file

@ -20,25 +20,12 @@
#include "dolphindropcontroller.h"
#include <kfileitem.h>
#include <klocale.h>
#include <kicon.h>
#include <QApplication>
#include <kdebug.h>
#include <kmenu.h>
#include <konq_operations.h>
DolphinDropController::DolphinDropController(QWidget* parentWidget)
: QObject(parentWidget), m_parentWidget(parentWidget)
{
}
DolphinDropController::~DolphinDropController()
{
}
void DolphinDropController::dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event)
QDropEvent* event,
QWidget* widget)
{
const bool dropToItem = !destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile());
const KUrl destination = dropToItem ? destItem.url() : destPath;
@ -47,13 +34,9 @@ void DolphinDropController::dropUrls(const KFileItem& destItem,
const KUrl sourceDir = KUrl(urls.first().directory());
if (sourceDir != destination) {
if (dropToItem) {
KonqOperations::doDrop(destItem, destination, event, m_parentWidget);
KonqOperations::doDrop(destItem, destination, event, widget);
} else {
KonqOperations::doDrop(KFileItem(), destination, event, m_parentWidget);
KonqOperations::doDrop(KFileItem(), destination, event, widget);
}
}
// TODO: emit doingOperation, so that the main window gets informed about
// about the finished operations
}
#include "dolphindropcontroller.moc"
}

View file

@ -20,25 +20,19 @@
#ifndef DOLPHINDROPCONTROLLER_H
#define DOLPHINDROPCONTROLLER_H
#include <QObject>
#include <kio/fileundomanager.h>
#include "libdolphin_export.h"
class QDropEvent;
class QWidget;
class KUrl;
class KFileItem;
/**
* @brief Handler for drop events, shared between DolphinView and TreeViewSidebarPage
*/
class LIBDOLPHINPRIVATE_EXPORT DolphinDropController : public QObject
class LIBDOLPHINPRIVATE_EXPORT DolphinDropController
{
Q_OBJECT
public:
explicit DolphinDropController(QWidget* parentWidget);
virtual ~DolphinDropController();
/**
* Handles the dropping of URLs to the given
* destination. A context menu with the options
@ -46,21 +40,13 @@ public:
* 'Cancel' is offered to the user.
* @param destItem Item of the destination (can be null, see KFileItem::isNull()).
* @param destPath Path of the destination.
* @param event Drop event
* @param event Drop event.
* @param widget Source widget where the dragging has been started.
*/
void dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event);
signals:
/**
* Is emitted when renaming, copying, moving, linking etc.
* Used for feedback in the mainwindow.
*/
void doingOperation(KIO::FileUndoManager::CommandType type);
private:
QWidget* m_parentWidget;
static void dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event,
QWidget* widget);
};
#endif // DOLPHINDROPCONTROLLER_H

View file

@ -45,11 +45,7 @@ void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event)
void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
DolphinDropController dropController(parent);
// forward doingOperation signal up to the mainwindow
connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)));
dropController.dropUrls(KFileItem(), dest, event);
DolphinDropController::dropUrls(KFileItem(), dest, event, parent);
}
void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url)

View file

@ -110,6 +110,10 @@ DolphinMainWindow::DolphinMainWindow(int id) :
this, SLOT(slotUndoAvailable(bool)));
connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
this, SLOT(slotUndoTextChanged(const QString&)));
connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
this, SLOT(clearStatusBar()));
connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
this, SLOT(showCommand(CommandType)));
connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
this, SLOT(slotHandlePlacesError(const QString&)));
}
@ -134,10 +138,39 @@ void DolphinMainWindow::toggleViews()
m_viewTab[m_tabIndex].secondaryView = container;
}
void DolphinMainWindow::slotDoingOperation(KIO::FileUndoManager::CommandType commandType)
void DolphinMainWindow::showCommand(CommandType command)
{
clearStatusBar();
m_undoCommandTypes.append(commandType);
DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
switch (command) {
case KIO::FileUndoManager::Copy:
statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Move:
statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Link:
statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Trash:
statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Rename:
statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Mkdir:
statusBar->setMessage(i18nc("@info:status", "Created folder."),
DolphinStatusBar::OperationCompleted);
break;
default:
break;
}
}
void DolphinMainWindow::refreshViews()
@ -157,16 +190,6 @@ void DolphinMainWindow::refreshViews()
setActiveViewContainer(activeViewContainer);
}
void DolphinMainWindow::dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event)
{
DolphinDropController dropController(this);
connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
dropController.dropUrls(destItem, destPath, event);
}
void DolphinMainWindow::pasteIntoFolder()
{
m_activeViewContainer->view()->pasteIntoFolder();
@ -380,42 +403,6 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
if (undoAction != 0) {
undoAction->setEnabled(available);
}
if (available && (m_undoCommandTypes.count() > 0)) {
const KIO::FileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
switch (command) {
case KIO::FileUndoManager::Copy:
statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Move:
statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Link:
statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Trash:
statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Rename:
statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
DolphinStatusBar::OperationCompleted);
break;
case KIO::FileUndoManager::Mkdir:
statusBar->setMessage(i18nc("@info:status", "Created folder."),
DolphinStatusBar::OperationCompleted);
break;
default:
break;
}
}
}
void DolphinMainWindow::slotUndoTextChanged(const QString& text)
@ -1059,8 +1046,6 @@ void DolphinMainWindow::setupDockWidgets()
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
this, SLOT(changeSelection(KFileItemList)));
connect(treeWidget, SIGNAL(urlsDropped(KFileItem, KUrl, QDropEvent*)),
this, SLOT(dropUrls(KFileItem, KUrl, QDropEvent*)));
// setup "Terminal"
#ifndef Q_OS_WIN
@ -1174,8 +1159,6 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
this, SLOT(slotRequestItemInfo(KFileItem)));
connect(view, SIGNAL(activated()),
this, SLOT(toggleActiveView()));
connect(view, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
connect(view, SIGNAL(tabRequested(const KUrl&)),
this, SLOT(openNewTab(const KUrl&)));

View file

@ -34,6 +34,8 @@
#include <QtCore/QList>
typedef KIO::FileUndoManager::CommandType CommandType;
class KAction;
class DolphinViewActionHandler;
class DolphinApplication;
@ -104,14 +106,6 @@ public:
KAction* showMenuBarAction() const;
public slots:
/**
* Handles the dropping of URLs to the given
* destination. This is only called by the TreeViewSidebarPage.
*/
void dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event);
/**
* Pastes the clipboard data into the currently selected folder
* of the active view. If not exactly one folder is selected,
@ -314,8 +308,11 @@ private slots:
/** Toggles the active view if two views are shown within the main window. */
void toggleActiveView();
/** Called when the view is doing a file operation, like renaming, copying, moving etc. */
void slotDoingOperation(KIO::FileUndoManager::CommandType type);
/**
* Indicates in the statusbar that the execution of the command \a command
* has been finished.
*/
void showCommand(CommandType command);
/**
* Activates the tab with the index \a index, which means that the current view
@ -423,9 +420,6 @@ private:
QList<ViewTab> m_viewTab;
DolphinViewActionHandler* m_actionHandler;
/// remember pending undo operations until they are finished
QList<KIO::FileUndoManager::CommandType> m_undoCommandTypes;
};
inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const

View file

@ -558,7 +558,6 @@ void DolphinView::renameSelectedItems()
KUrl newUrl = oldUrl;
newUrl.setFileName(name);
KonqOperations::rename(this, oldUrl, newUrl);
emit doingOperation(KIO::FileUndoManager::Rename);
}
}
}
@ -588,14 +587,12 @@ void DolphinView::renameSelectedItems()
KUrl newUrl = oldUrl;
newUrl.setFileName(newName);
KonqOperations::rename(this, oldUrl, newUrl);
emit doingOperation(KIO::FileUndoManager::Rename);
}
}
}
void DolphinView::trashSelectedItems()
{
emit doingOperation(KIO::FileUndoManager::Trash);
const KUrl::List list = simplifiedSelectedUrls();
KonqOperations::del(this, KonqOperations::TRASH, list);
}
@ -820,11 +817,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event)
{
DolphinDropController dropController(this);
// forward doingOperation signal up to the mainwindow
connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)));
dropController.dropUrls(destItem, destPath, event);
DolphinDropController::dropUrls(destItem, destPath, event, this);
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
@ -1252,11 +1245,9 @@ void DolphinView::pasteToUrl(const KUrl& url)
const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
if (KonqMimeData::decodeIsCutSelection(mimeData)) {
KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url);
emit doingOperation(KIO::FileUndoManager::Move);
clipboard->clear();
} else {
KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url);
emit doingOperation(KIO::FileUndoManager::Copy);
}
}

View file

@ -513,12 +513,6 @@ signals:
*/
void startedPathLoading(const KUrl& url);
/**
* Is emitted when renaming, copying, moving, linking etc.
* Used for feedback in the mainwindow.
*/
void doingOperation(KIO::FileUndoManager::CommandType type);
protected:
/** @see QWidget::mouseReleaseEvent */
virtual void mouseReleaseEvent(QMouseEvent* event);

View file

@ -46,6 +46,7 @@
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
#include "dolphindropcontroller.h"
#include "dolphinstatusbar.h"
#include "dolphinmainwindow.h"
#include "dolphindirlister.h"
@ -80,8 +81,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
m_topLayout->setMargin(0);
m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this);
connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl&, QDropEvent*)),
this, SLOT(dropUrls(const KUrl&, QDropEvent*)));
connect(m_urlNavigator, SIGNAL(activated()),
this, SLOT(activate()));
@ -406,6 +407,11 @@ void DolphinViewContainer::saveRootUrl(const KUrl& url)
m_urlNavigator->saveRootUrl(m_view->rootUrl());
}
void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
{
DolphinDropController::dropUrls(KFileItem(), destination, event, this);
}
void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
{
KUrl url = item.targetUrl();

View file

@ -201,6 +201,12 @@ private slots:
* into the URL navigator.
*/
void saveRootUrl(const KUrl& url);
/**
* Is connected with the URL navigator and drops the URLs
* above the destination \a destination.
*/
void dropUrls(const KUrl& destination, QDropEvent* event);
private:
/**

View file

@ -19,6 +19,7 @@
#include "treeviewsidebarpage.h"
#include "dolphindropcontroller.h"
#include "dolphinmodel.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
@ -210,7 +211,7 @@ void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event)
KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
Q_ASSERT(!item.isNull());
if (item.isDir()) {
emit urlsDropped(item, item.url(), event);
DolphinDropController::dropUrls(item, item.url(), event, this);
}
}
}

View file

@ -68,12 +68,6 @@ signals:
*/
void changeSelection(const KFileItemList& selection);
/**
* This signal is emitted whenever a drop action on this widget needs the
* MainWindow's attention.
*/
void urlsDropped(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event);
public slots:
/**
* Changes the current selection inside the tree to \a url.