* show an information message in the statusbar, if items are dragged into the same directory
TODO: although the signal seems to get connected correctly, the slot DolphinMainWindow::showInformationMessage() is not invoked when the signal is emitted -> will debug this later, it is important that the new string is added before the message freeze
svn path=/trunk/KDE/kdebase/apps/; revision=881627
void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
{
- DragAndDropHelper::startDrag(this, supportedActions, m_view->m_controller);
+ DragAndDropHelper::instance().startDrag(this, supportedActions, m_view->m_controller);
}
void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
{
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
event->acceptProposedAction();
}
}
}
setDirtyRegion(m_dropRect);
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
// accept url drops, independently from the destination item
event->acceptProposedAction();
}
void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
{
- DragAndDropHelper::startDrag(this, supportedActions, m_controller);
+ DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
m_band.show = false;
}
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
{
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
event->acceptProposedAction();
}
setDirtyRegion(m_dropRect);
}
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
// accept url drops, independently from the destination item
event->acceptProposedAction();
}
void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
- DragAndDropHelper::dropUrls(KFileItem(), dest, event, parent);
+ DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent);
}
void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url)
// TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll
// fix this in KDE 4.1
KCategorizedView::startDrag(supportedActions);
- DragAndDropHelper::startDrag(this, supportedActions, m_controller);
+ DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
}
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
{
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
event->acceptProposedAction();
}
}
m_dropRect.setSize(QSize()); // set as invalid
}
}
- if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
+ if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
// accept url drops, independently from the destination item
event->acceptProposedAction();
}
#include "dolphin_generalsettings.h"
#include "dolphin_iconsmodesettings.h"
+#include "draganddrophelper.h"
#include <kaction.h>
#include <kactioncollection.h>
#include <QSplitter>
#include <QDockWidget>
-#include <kdebug.h>
-
DolphinMainWindow::DolphinMainWindow(int id) :
KXmlGuiWindow(0),
m_newMenu(0),
connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
this, SLOT(showCommand(CommandType)));
connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
- this, SLOT(slotHandlePlacesError(const QString&)));
+ this, SLOT(showErrorMessage(const QString&)));
+ connect(&DragAndDropHelper::instance(), SIGNAL(informationMessage(const QString&)),
+ this, SLOT(showInformationMessage(const QString&)));
}
DolphinMainWindow::~DolphinMainWindow()
close();
}
-void DolphinMainWindow::slotHandlePlacesError(const QString &message)
+void DolphinMainWindow::showErrorMessage(const QString& message)
{
if (!message.isEmpty()) {
DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
}
}
+void DolphinMainWindow::showInformationMessage(const QString& message)
+{
+ if (!message.isEmpty()) {
+ DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+ statusBar->setMessage(message, DolphinStatusBar::Information);
+ }
+}
+
void DolphinMainWindow::slotUndoAvailable(bool available)
{
QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
/** Updates the 'Create New...' sub menu. */
void updateNewMenu();
- /**
- * Shows the error information from the places model
- * in the status bar.
- */
- void slotHandlePlacesError(const QString &message);
+ /** Shows the error message in the status bar of the active view. */
+ void showErrorMessage(const QString& message);
+
+ /** Shows the information message in the status bar of the active view. */
+ void showInformationMessage(const QString& message);
/**
* Updates the state of the 'Undo' menu action dependent
const KUrl& destPath,
QDropEvent* event)
{
- DragAndDropHelper::dropUrls(destItem, destPath, event, this);
+ DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
{
- DragAndDropHelper::dropUrls(KFileItem(), destination, event, this);
+ DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
}
void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
#include <kdirmodel.h>
#include <kfileitem.h>
#include <kicon.h>
+#include <klocale.h>
#include <konq_operations.h>
#include <QAbstractItemView>
#include <QtDBus>
#include <QDrag>
-bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData)
+class DragAndDropHelperSingleton
+{
+public:
+ DragAndDropHelper instance;
+};
+K_GLOBAL_STATIC(DragAndDropHelperSingleton, s_dragAndDropHelper)
+
+DragAndDropHelper& DragAndDropHelper::instance()
+{
+ return s_dragAndDropHelper->instance;
+}
+
+bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData) const
{
return mimeData->hasUrls() || mimeData->hasFormat("application/x-kde-dndextract");
}
} else {
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
const KUrl sourceDir = KUrl(urls.first().directory());
- if (sourceDir != destination) {
- if (dropToItem) {
- KonqOperations::doDrop(destItem, destination, event, widget);
- } else {
- KonqOperations::doDrop(KFileItem(), destination, event, widget);
- }
+ if (sourceDir == destination) {
+ const QString msg = i18ncp("@info:status",
+ "The dropped item is already inside the folder %2",
+ "The dropped items are already inside the folder %2",
+ urls.count(), destination.fileName());
+ emit informationMessage(msg);
+ } else if (dropToItem) {
+ KonqOperations::doDrop(destItem, destination, event, widget);
+ } else {
+ KonqOperations::doDrop(KFileItem(), destination, event, widget);
}
}
}
+
+DragAndDropHelper::DragAndDropHelper()
+{
+}
+
+#include "draganddrophelper.moc"
#ifndef DRAGANDDROPHELPER_H
#define DRAGANDDROPHELPER_H
-#include <QtCore/Qt>
+#include <QObject>
class DolphinController;
class KFileItem;
* DolphinColumnView and SidebarTreeView to have a consistent
* drag and drop behavior between all views.
*/
-class DragAndDropHelper
+class DragAndDropHelper : public QObject
{
+ Q_OBJECT
public:
+ static DragAndDropHelper& instance();
+
/**
* Returns true, if Dolphin supports the dragging of
* the given mime data.
*/
- static bool isMimeDataSupported(const QMimeData* mimeData);
+ bool isMimeDataSupported(const QMimeData* mimeData) const;
/**
* Creates a drag object for the view \a itemView for all selected items.
*/
- static void startDrag(QAbstractItemView* itemView,
- Qt::DropActions supportedActions,
- DolphinController* controller = 0);
+ void startDrag(QAbstractItemView* itemView,
+ Qt::DropActions supportedActions,
+ DolphinController* controller = 0);
/**
* Handles the dropping of URLs to the given
* @param event Drop event.
* @param widget Source widget where the dragging has been started.
*/
- static void dropUrls(const KFileItem& destItem,
- const KUrl& destPath,
- QDropEvent* event,
- QWidget* widget);
+ void dropUrls(const KFileItem& destItem,
+ const KUrl& destPath,
+ QDropEvent* event,
+ QWidget* widget);
+signals:
+ void informationMessage(const QString& msg);
+
+private:
+ DragAndDropHelper();
+
+ friend class DragAndDropHelperSingleton;
};
#endif
void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
{
- DragAndDropHelper::startDrag(this, supportedActions);
+ DragAndDropHelper::instance().startDrag(this, supportedActions);
}
void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
Q_ASSERT(!item.isNull());
if (item.isDir()) {
- DragAndDropHelper::dropUrls(item, item.url(), event, this);
+ DragAndDropHelper::instance().dropUrls(item, item.url(), event, this);
}
}
}