From: Peter Penz Date: Sat, 6 Jan 2007 19:51:48 +0000 (+0000) Subject: Reanimate drag and drop support for the URL navigator. X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/86ad5d0a630654f81f4649f997dd6451f371f5f6?ds=inline Reanimate drag and drop support for the URL navigator. svn path=/trunk/playground/utils/dolphin/; revision=620633 --- diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 14ec8dcd4..6c4dda80a 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -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")); } diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 15d9b02f1..96a919747 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -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())); - /* 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; - } + QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" )); + connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems())); - case 1: { - // 'Copy Here' has been selected - updateViewProperties(urls); - copyUrls(urls, destination); - break; - } + QAction* linkAction = popup.addAction(i18n("&Link Here")); + connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems())); - case 2: { - // 'Link Here' has been selected - KIO::Job* job = KIO::link(urls, destination); - addPendingUndoJob(job, DolphinCommand::Link, urls, destination); - break; - } + QAction* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel")); + popup.insertSeparator(cancelAction); - default: - // 'Cancel' has been selected - break; + popup.exec(QCursor::pos()); } + + 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); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index b9a9db3d8..fcfab60f0 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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. diff --git a/src/urlbutton.h b/src/urlbutton.h index 41d81c24b..a52fdf463 100644 --- a/src/urlbutton.h +++ b/src/urlbutton.h @@ -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 -//Added by qt3to4: #include +#include 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 diff --git a/src/urlnavigatorbutton.cpp b/src/urlnavigatorbutton.cpp index 44b7ae966..70c25b20b 100644 --- a/src/urlnavigatorbutton.cpp +++ b/src/urlnavigatorbutton.cpp @@ -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)