X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/652d08c9242ed51d86dba3b2afda9d3b2e9a9cd7..14bae32f371663d172e1dd39d98080fd8695d991:/src/views/dolphinviewcontroller.cpp diff --git a/src/views/dolphinviewcontroller.cpp b/src/views/dolphinviewcontroller.cpp index 6ef32f07f..e182e48c1 100644 --- a/src/views/dolphinviewcontroller.cpp +++ b/src/views/dolphinviewcontroller.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Peter Penz * + * Copyright (C) 2010 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -20,8 +20,8 @@ #include "dolphinviewcontroller.h" #include "zoomlevelinfo.h" -#include -#include +#include +#include #include #include #include @@ -53,14 +53,14 @@ void DolphinViewController::requestUrlChange(const KUrl& url) void DolphinViewController::setItemView(QAbstractItemView* view) { - if (m_itemView != 0) { + if (m_itemView) { disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)), this, SLOT(updateMouseButtonState())); } m_itemView = view; - if (m_itemView != 0) { + if (m_itemView) { // TODO: this is a workaround until Qt-issue 176832 has been fixed connect(m_itemView, SIGNAL(pressed(const QModelIndex&)), this, SLOT(updateMouseButtonState())); @@ -84,11 +84,9 @@ void DolphinViewController::requestActivation() emit activated(); } -void DolphinViewController::indicateDroppedUrls(const KFileItem& destItem, - const KUrl& destPath, - QDropEvent* event) +void DolphinViewController::indicateDroppedUrls(const KFileItem& destItem, QDropEvent* event) { - emit urlsDropped(destItem, destPath, event); + emit urlsDropped(destItem, m_dolphinView->url(), event); } @@ -128,7 +126,9 @@ QList DolphinViewController::versionControlActions(const KFileItemList void DolphinViewController::handleKeyPressEvent(QKeyEvent* event) { - Q_ASSERT(m_itemView != 0); + if (!m_itemView) { + return; + } const QItemSelectionModel* selModel = m_itemView->selectionModel(); const QModelIndex currentIndex = selModel->currentIndex(); @@ -139,10 +139,8 @@ void DolphinViewController::handleKeyPressEvent(QKeyEvent* event) return; } - // Collect the non-directory files into a list and - // call runPreferredApplications for that list. - // Several selected directories are opened in separate tabs, - // one selected directory will get opened in the view. + // Collect selected files and selected directories + // as two separate lists. QModelIndexList dirQueue; const QModelIndexList indexList = selModel->selectedIndexes(); KFileItemList fileOpenList; @@ -154,14 +152,20 @@ void DolphinViewController::handleKeyPressEvent(QKeyEvent* event) } } - KFileItemActions fileItemActions; - fileItemActions.runPreferredApplications(fileOpenList, "DesktopEntryName != 'dolphin'"); + // Handle selected files + if (fileOpenList.count() == 1) { + emit itemTriggered(fileOpenList.first()); + } else { + KFileItemActions fileItemActions; + fileItemActions.runPreferredApplications(fileOpenList, "DesktopEntryName != 'dolphin'"); + } - if (dirQueue.length() == 1) { - // open directory in the view + // Handle selected directories + if (dirQueue.count() == 1) { + // Open directory in the view emit itemTriggered(itemForIndex(dirQueue[0])); } else { - // open directories in separate tabs + // Open directories in separate tabs foreach(const QModelIndex& dir, dirQueue) { emit tabRequested(itemForIndex(dir).url()); } @@ -194,12 +198,16 @@ void DolphinViewController::emitItemTriggered(const KFileItem& item) KFileItem DolphinViewController::itemForIndex(const QModelIndex& index) const { - Q_ASSERT(m_itemView != 0); + if (m_itemView) { + QAbstractProxyModel* proxyModel = static_cast(m_itemView->model()); + if (proxyModel) { + KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + const QModelIndex dirIndex = proxyModel->mapToSource(index); + return dirModel->itemForIndex(dirIndex); + } + } - QAbstractProxyModel* proxyModel = static_cast(m_itemView->model()); - KDirModel* dirModel = static_cast(proxyModel->sourceModel()); - const QModelIndex dirIndex = proxyModel->mapToSource(index); - return dirModel->itemForIndex(dirIndex); + return KFileItem(); } void DolphinViewController::triggerItem(const QModelIndex& index) @@ -208,7 +216,7 @@ void DolphinViewController::triggerItem(const QModelIndex& index) const KFileItem item = itemForIndex(index); if (index.isValid() && (index.column() == KDirModel::Name)) { emit itemTriggered(item); - } else { + } else if (m_itemView) { m_itemView->clearSelection(); emit itemEntered(KFileItem()); }