1
/***************************************************************************
2
* Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18
***************************************************************************/
20
#include "dolphinviewcontroller.h"
21
#include "zoomlevelinfo.h"
24
#include <KFileItemActions>
25
#include <QAbstractProxyModel>
26
#include <QApplication>
30
Qt::MouseButtons DolphinViewController::m_mouseButtons = Qt::NoButton;
32
DolphinViewController::DolphinViewController(DolphinView* dolphinView) :
34
m_dolphinView(dolphinView),
36
m_versionControlActions()
40
DolphinViewController::~DolphinViewController()
44
const DolphinView* DolphinViewController::view() const
49
void DolphinViewController::requestUrlChange(const KUrl& url)
51
emit urlChangeRequested(url);
54
void DolphinViewController::setItemView(QAbstractItemView* view)
57
disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
58
this, SLOT(updateMouseButtonState()));
64
// TODO: this is a workaround until Qt-issue 176832 has been fixed
65
connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
66
this, SLOT(updateMouseButtonState()));
70
QAbstractItemView* DolphinViewController::itemView() const
75
void DolphinViewController::triggerContextMenuRequest(const QPoint& pos,
76
const QList<QAction*>& customActions)
79
emit requestContextMenu(pos, customActions);
82
void DolphinViewController::requestActivation()
87
void DolphinViewController::indicateDroppedUrls(const KFileItem& destItem, QDropEvent* event)
89
emit urlsDropped(destItem, m_dolphinView->url(), event);
93
void DolphinViewController::indicateSortingChange(DolphinView::Sorting sorting)
95
emit sortingChanged(sorting);
98
void DolphinViewController::indicateSortOrderChange(Qt::SortOrder order)
100
emit sortOrderChanged(order);
103
void DolphinViewController::indicateSortFoldersFirstChange(bool foldersFirst)
105
emit sortFoldersFirstChanged(foldersFirst);
108
void DolphinViewController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
110
emit additionalInfoChanged(info);
113
void DolphinViewController::setVersionControlActions(QList<QAction*> actions)
115
m_versionControlActions = actions;
118
QList<QAction*> DolphinViewController::versionControlActions(const KFileItemList& items)
120
emit requestVersionControlActions(items);
121
// All view implementations are connected with the signal requestVersionControlActions()
122
// (see ViewExtensionFactory) and will invoke DolphinViewController::setVersionControlActions(),
123
// so that the context dependent actions can be returned.
124
return m_versionControlActions;
127
void DolphinViewController::handleKeyPressEvent(QKeyEvent* event)
133
const QItemSelectionModel* selModel = m_itemView->selectionModel();
134
const QModelIndex currentIndex = selModel->currentIndex();
135
const bool trigger = currentIndex.isValid()
136
&& ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter))
137
&& !selModel->selectedIndexes().isEmpty();
142
// Collect selected files and selected directories
143
// as two separate lists.
144
QModelIndexList dirQueue;
145
const QModelIndexList indexList = selModel->selectedIndexes();
146
KFileItemList fileOpenList;
147
foreach (const QModelIndex& index, indexList) {
148
if (itemForIndex(index).isDir()) {
151
fileOpenList << itemForIndex(index);
155
// Handle selected files
156
if (fileOpenList.count() == 1) {
157
emit itemTriggered(fileOpenList.first());
159
KFileItemActions fileItemActions;
160
fileItemActions.runPreferredApplications(fileOpenList, "DesktopEntryName != 'dolphin'");
163
// Handle selected directories
164
if (dirQueue.count() == 1) {
165
// Open directory in the view
166
emit itemTriggered(itemForIndex(dirQueue[0]));
168
// Open directories in separate tabs
169
foreach(const QModelIndex& dir, dirQueue) {
170
emit tabRequested(itemForIndex(dir).url());
175
void DolphinViewController::replaceUrlByClipboard()
177
const QClipboard* clipboard = QApplication::clipboard();
179
if (clipboard->mimeData(QClipboard::Selection)->hasText()) {
180
text = clipboard->mimeData(QClipboard::Selection)->text();
181
} else if (clipboard->mimeData(QClipboard::Clipboard)->hasText()) {
182
text = clipboard->mimeData(QClipboard::Clipboard)->text();
184
if (!text.isEmpty() && QDir::isAbsolutePath(text)) {
185
m_dolphinView->setUrl(KUrl(text));
189
void DolphinViewController::requestToolTipHiding()
194
void DolphinViewController::emitItemTriggered(const KFileItem& item)
196
emit itemTriggered(item);
199
KFileItem DolphinViewController::itemForIndex(const QModelIndex& index) const
202
QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_itemView->model());
204
KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
205
const QModelIndex dirIndex = proxyModel->mapToSource(index);
206
return dirModel->itemForIndex(dirIndex);
213
void DolphinViewController::triggerItem(const QModelIndex& index)
215
if (m_mouseButtons & Qt::LeftButton) {
216
const KFileItem item = itemForIndex(index);
217
if (index.isValid() && (index.column() == KDirModel::Name)) {
218
emit itemTriggered(item);
219
} else if (m_itemView) {
220
m_itemView->clearSelection();
221
emit itemEntered(KFileItem());
226
void DolphinViewController::requestTab(const QModelIndex& index)
228
if (m_mouseButtons & Qt::MidButton) {
229
const KFileItem item = itemForIndex(index);
230
const bool validRequest = index.isValid() &&
231
(index.column() == KDirModel::Name) &&
232
(item.isDir() || m_dolphinView->isTabsForFilesEnabled());
234
emit tabRequested(item.url());
239
void DolphinViewController::emitItemEntered(const QModelIndex& index)
241
KFileItem item = itemForIndex(index);
242
if (!item.isNull()) {
243
emit itemEntered(item);
247
void DolphinViewController::emitViewportEntered()
249
emit viewportEntered();
252
void DolphinViewController::updateMouseButtonState()
254
m_mouseButtons = QApplication::mouseButtons();
257
#include "dolphinviewcontroller.moc"