]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.cpp
Bump the priority of Dolphin an application for the inode/directory mimetype. This...
[dolphin.git] / src / dolphincontroller.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphincontroller.h"
21
22 #include <kdirmodel.h>
23 #include <QAbstractProxyModel>
24
25 DolphinController::DolphinController(DolphinView* dolphinView) :
26 QObject(dolphinView),
27 m_zoomInPossible(false),
28 m_zoomOutPossible(false),
29 m_url(),
30 m_dolphinView(dolphinView),
31 m_itemView(0)
32 {
33 }
34
35 DolphinController::~DolphinController()
36 {
37 }
38
39 void DolphinController::setUrl(const KUrl& url)
40 {
41 if (m_url != url) {
42 m_url = url;
43 emit urlChanged(url);
44 }
45 }
46
47 void DolphinController::setItemView(QAbstractItemView* view)
48 {
49 m_itemView = view;
50 }
51
52 void DolphinController::triggerUrlChangeRequest(const KUrl& url)
53 {
54 if (m_url != url) {
55 emit requestUrlChange(url);
56 }
57 }
58
59 void DolphinController::triggerContextMenuRequest(const QPoint& pos)
60 {
61 emit activated();
62 emit requestContextMenu(pos);
63 }
64
65 void DolphinController::requestActivation()
66 {
67 emit activated();
68 }
69
70 void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
71 const KUrl& destPath,
72 const KFileItem& destItem)
73 {
74 emit urlsDropped(urls, destPath, destItem);
75 }
76
77
78 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting)
79 {
80 emit sortingChanged(sorting);
81 }
82
83 void DolphinController::indicateSortOrderChange(Qt::SortOrder order)
84 {
85 emit sortOrderChanged(order);
86 }
87
88 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
89 {
90 emit additionalInfoChanged(info);
91 }
92
93 void DolphinController::indicateActivationChange(bool active)
94 {
95 emit activationChanged(active);
96 }
97
98 void DolphinController::triggerZoomIn()
99 {
100 emit zoomIn();
101 }
102
103 void DolphinController::triggerZoomOut()
104 {
105 emit zoomOut();
106 }
107
108 void DolphinController::handleKeyPressEvent(QKeyEvent* event)
109 {
110 Q_ASSERT(m_itemView != 0);
111
112 const QItemSelectionModel* selModel = m_itemView->selectionModel();
113 const QModelIndex currentIndex = selModel->currentIndex();
114 const bool trigger = currentIndex.isValid()
115 && (event->key() == Qt::Key_Return)
116 && (selModel->selectedIndexes().count() > 0);
117 if (trigger) {
118 const QModelIndexList indexList = selModel->selectedIndexes();
119 foreach (const QModelIndex& index, indexList) {
120 triggerItem(index);
121 }
122 }
123 }
124
125 KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
126 {
127 Q_ASSERT(m_itemView != 0);
128
129 QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_itemView->model());
130 KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
131 const QModelIndex dirIndex = proxyModel->mapToSource(index);
132 return dirModel->itemForIndex(dirIndex);
133 }
134
135 void DolphinController::triggerItem(const QModelIndex& index)
136 {
137 const KFileItem item = itemForIndex(index);
138 if (index.isValid() && (index.column() == KDirModel::Name)) {
139 emit itemTriggered(item);
140 } else {
141 m_itemView->clearSelection();
142 emit itemEntered(item);
143 }
144 }
145
146 void DolphinController::emitItemEntered(const QModelIndex& index)
147 {
148 KFileItem item = itemForIndex(index);
149 if (!item.isNull()) {
150 emit itemEntered(item);
151 }
152 }
153
154 void DolphinController::emitViewportEntered()
155 {
156 emit viewportEntered();
157 }
158
159 #include "dolphincontroller.moc"