1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
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 "dolphincontroller.h"
22 #include <kdirmodel.h>
23 #include <QAbstractProxyModel>
24 #include <QApplication>
28 DolphinController::DolphinController(DolphinView
* dolphinView
) :
30 m_zoomInPossible(false),
31 m_zoomOutPossible(false),
34 m_dolphinView(dolphinView
),
39 DolphinController::~DolphinController()
43 void DolphinController::setUrl(const KUrl
& url
)
51 void DolphinController::setItemView(QAbstractItemView
* view
)
53 if (m_itemView
!= 0) {
54 disconnect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
55 this, SLOT(updateOpenTabState()));
60 if (m_itemView
!= 0) {
61 // TODO: this is a workaround until Qt-issue 176832 has been fixed
62 connect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
63 this, SLOT(updateOpenTabState()));
67 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
70 emit
requestUrlChange(url
);
74 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
77 emit
requestContextMenu(pos
);
80 void DolphinController::requestActivation()
85 void DolphinController::indicateDroppedUrls(const KUrl::List
& urls
,
87 const KFileItem
& destItem
)
89 emit
urlsDropped(urls
, destPath
, destItem
);
93 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
95 emit
sortingChanged(sorting
);
98 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
100 emit
sortOrderChanged(order
);
103 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
105 emit
additionalInfoChanged(info
);
108 void DolphinController::indicateActivationChange(bool active
)
110 emit
activationChanged(active
);
113 void DolphinController::triggerZoomIn()
118 void DolphinController::triggerZoomOut()
123 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
125 Q_ASSERT(m_itemView
!= 0);
127 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
128 const QModelIndex currentIndex
= selModel
->currentIndex();
129 const bool trigger
= currentIndex
.isValid()
130 && (event
->key() == Qt::Key_Return
)
131 && (selModel
->selectedIndexes().count() > 0);
133 const QModelIndexList indexList
= selModel
->selectedIndexes();
134 foreach (const QModelIndex
& index
, indexList
) {
140 void DolphinController::replaceUrlByClipboard()
142 const QClipboard
* clipboard
= QApplication::clipboard();
144 if (clipboard
->mimeData(QClipboard::Selection
)->hasText()) {
145 text
= clipboard
->mimeData(QClipboard::Selection
)->text();
146 } else if (clipboard
->mimeData(QClipboard::Clipboard
)->hasText()) {
147 text
= clipboard
->mimeData(QClipboard::Clipboard
)->text();
149 if (!text
.isEmpty() && QDir::isAbsolutePath(text
)) {
150 m_dolphinView
->setUrl(KUrl(text
));
154 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
156 Q_ASSERT(m_itemView
!= 0);
158 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
159 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
160 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
161 return dirModel
->itemForIndex(dirIndex
);
164 void DolphinController::triggerItem(const QModelIndex
& index
)
166 const bool openTab
= m_openTab
;
169 const KFileItem item
= itemForIndex(index
);
170 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
171 if (openTab
&& (item
.isDir() || m_dolphinView
->isTabsForFilesEnabled())) {
172 emit
tabRequested(item
.url());
174 emit
itemTriggered(item
);
177 m_itemView
->clearSelection();
179 emit
itemEntered(KFileItem());
184 void DolphinController::emitItemEntered(const QModelIndex
& index
)
186 KFileItem item
= itemForIndex(index
);
187 if (!item
.isNull()) {
188 emit
itemEntered(item
);
192 void DolphinController::emitViewportEntered()
194 emit
viewportEntered();
197 void DolphinController::updateOpenTabState()
199 m_openTab
= QApplication::mouseButtons() & Qt::MidButton
;
202 #include "dolphincontroller.moc"