1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Reanimate drag and drop support for the URL navigator.

svn path=/trunk/playground/utils/dolphin/; revision=620633
This commit is contained in:
Peter Penz 2007-01-06 19:51:48 +00:00
parent ddc11d9a26
commit 86ad5d0a63
5 changed files with 73 additions and 84 deletions

View File

@ -181,8 +181,9 @@ void DolphinContextMenu::openItemContextMenu()
const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction);
for (int i = 0; i < count; ++i) {
QAction* action = dolphin->actionCollection()->action(KStandardAction::stdName(actionNames[i]));
if (action)
if (action != 0) {
popup->addAction(action);
}
}
popup->insertSeparator();
@ -204,7 +205,7 @@ void DolphinContextMenu::openItemContextMenu()
// insert 'Bookmark this folder...' entry
// urls is a list of selected items, so insert boolmark menu if
// urls contains only one item, i.e. no multiple selection made
QAction *bookmarkAction = 0;
QAction* bookmarkAction = 0;
if (m_fileInfo->isDir() && (urls.count() == 1)) {
bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
}

View File

@ -114,9 +114,10 @@ void DolphinMainWindow::setActiveView(DolphinView* view)
}
void DolphinMainWindow::dropUrls(const KUrl::List& urls,
const KUrl& destination)
const KUrl& destination)
{
int selectedIndex = -1;
m_dropDestination = destination;
m_droppedUrls = urls;
/* KDE4-TODO
const ButtonState keyboardState = KApplication::keyboardMouseState();
@ -141,49 +142,22 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls,
// no shortcut is used, hence open a popup menu
KMenu popup(this);
popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
popup.insertSeparator();
popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
popup.setAccel(i18n("Escape"), 3);
QAction* moveAction = popup.addAction(SmallIcon("goto"), i18n("&Move Here"));
connect(moveAction, SIGNAL(triggered()), this, SLOT(moveDroppedItems()));
QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" ));
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems()));
QAction* linkAction = popup.addAction(i18n("&Link Here"));
connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems()));
QAction* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel"));
popup.insertSeparator(cancelAction);
/* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
popup.exec(QCursor::pos());
selectedIndex = 0; // KD4-TODO: use QAction instead of switch below
// See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
}
if (selectedIndex < 0) {
return;
}
switch (selectedIndex) {
case 0: {
// 'Move Here' has been selected
updateViewProperties(urls);
moveUrls(urls, destination);
break;
}
case 1: {
// 'Copy Here' has been selected
updateViewProperties(urls);
copyUrls(urls, destination);
break;
}
case 2: {
// 'Link Here' has been selected
KIO::Job* job = KIO::link(urls, destination);
addPendingUndoJob(job, DolphinCommand::Link, urls, destination);
break;
}
default:
// 'Cancel' has been selected
break;
}
m_droppedUrls.clear();
}
void DolphinMainWindow::refreshViews()
@ -315,6 +289,22 @@ void DolphinMainWindow::openNewMainWindow()
DolphinApplication::app()->createMainWindow()->show();
}
void DolphinMainWindow::moveDroppedItems()
{
moveUrls(m_droppedUrls, m_dropDestination);
}
void DolphinMainWindow::copyDroppedItems()
{
copyUrls(m_droppedUrls, m_dropDestination);
}
void DolphinMainWindow::linkDroppedItems()
{
KIO::Job* job = KIO::link(m_droppedUrls, m_dropDestination);
addPendingUndoJob(job, DolphinCommand::Link, m_droppedUrls, m_dropDestination);
}
void DolphinMainWindow::closeEvent(QCloseEvent* event)
{
// KDE4-TODO
@ -1545,30 +1535,6 @@ void DolphinMainWindow::updateGoActions()
goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
}
void DolphinMainWindow::updateViewProperties(const KUrl::List& urls)
{
if (urls.isEmpty()) {
return;
}
// Updating the view properties might take up to several seconds
// when dragging several thousand Urls. Writing a KIO slave for this
// use case is not worth the effort, but at least the main widget
// must be disabled and a progress should be shown.
ProgressIndicator progressIndicator(this,
i18n("Updating view properties..."),
QString::null,
urls.count());
KUrl::List::ConstIterator end = urls.end();
for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) {
progressIndicator.execOperation();
ViewProperties props(*it);
props.save();
}
}
void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
{
KIO::Job* job = KIO::copy(source, dest);

View File

@ -358,6 +358,24 @@ private slots:
/** Open a new main window. */
void openNewMainWindow();
/**
* Moves the items indicated by m_droppedUrls to the URL
* m_destination.
*/
void moveDroppedItems();
/**
* Copies the items indicated by m_droppedUrls to the URL
* m_destination.
*/
void copyDroppedItems();
/**
* Links the items indicated by m_droppedUrls to the URL
* m_destination.
*/
void linkDroppedItems();
private:
DolphinMainWindow();
void init();
@ -371,7 +389,6 @@ private:
void updateEditActions();
void updateViewActions();
void updateGoActions();
void updateViewProperties(const KUrl::List& urls);
void copyUrls(const KUrl::List& source, const KUrl& dest);
void moveUrls(const KUrl::List& source, const KUrl& dest);
void addPendingUndoJob(KIO::Job* job,
@ -392,6 +409,9 @@ private:
QSplitter* m_splitter;
DolphinView* m_activeView;
KUrl m_dropDestination;
KUrl::List m_droppedUrls;
/**
* DolphinMainWindowsupports only one or two views, which
* are handled internally as primary and secondary view.

View File

@ -18,21 +18,20 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef UrlBUTTON_H
#define UrlBUTTON_H
#ifndef URLBUTTON_H
#define URLBUTTON_H
#include <qpushbutton.h>
//Added by qt3to4:
#include <QEvent>
#include <QPushButton>
class KUrl;
class UrlNavigator;
class QPainter;
/**
* @brief Base class for buttons of the Url navigator.
* @brief Base class for buttons of the URL navigator.
*
* Each button of the Url navigator contains an Url, which
* Each button of the URL navigator contains an URL, which
* is set as soon as the button has been clicked.
*
* @author Peter Penz

View File

@ -209,28 +209,31 @@ void UrlNavigatorButton::dropEvent(QDropEvent* event)
return;
}
KUrl::List urls;
/* KDE4-TODO:
if (KUrlDrag::decode(event, urls) && !urls.isEmpty()) {
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
if (!urls.isEmpty()) {
event->acceptProposedAction();
setDisplayHintEnabled(DraggedHint, true);
QString path(urlNavigator()->url().prettyUrl());
path = path.section('/', 0, m_index);
path = path.section('/', 0, m_index + 2);
Dolphin::mainWin().dropUrls(urls, KUrl(path));
DolphinMainWindow* win = urlNavigator()->dolphinView()->mainWindow();
win->dropUrls(urls, KUrl(path));
setDisplayHintEnabled(DraggedHint, false);
update();
}*/
}
}
void UrlNavigatorButton::dragEnterEvent(QDragEnterEvent* event)
{
/* KDE4-TODO:
event->accept(KUrlDrag::canDecode(event));
if (event->mimeData()->hasUrls()) {
setDisplayHintEnabled(DraggedHint, true);
event->acceptProposedAction();
setDisplayHintEnabled(DraggedHint, true);*/
update();
update();
}
}
void UrlNavigatorButton::dragLeaveEvent(QDragLeaveEvent* event)