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 // TODO: this is a workaround until Qt-issue 176832 has been fixed
61 connect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
62 this, SLOT(updateOpenTabState()));
65 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
68 emit
requestUrlChange(url
);
72 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
75 emit
requestContextMenu(pos
);
78 void DolphinController::requestActivation()
83 void DolphinController::indicateDroppedUrls(const KUrl::List
& urls
,
85 const KFileItem
& destItem
)
87 emit
urlsDropped(urls
, destPath
, destItem
);
91 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
93 emit
sortingChanged(sorting
);
96 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
98 emit
sortOrderChanged(order
);
101 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
103 emit
additionalInfoChanged(info
);
106 void DolphinController::indicateActivationChange(bool active
)
108 emit
activationChanged(active
);
111 void DolphinController::triggerZoomIn()
116 void DolphinController::triggerZoomOut()
121 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
123 Q_ASSERT(m_itemView
!= 0);
125 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
126 const QModelIndex currentIndex
= selModel
->currentIndex();
127 const bool trigger
= currentIndex
.isValid()
128 && (event
->key() == Qt::Key_Return
)
129 && (selModel
->selectedIndexes().count() > 0);
131 const QModelIndexList indexList
= selModel
->selectedIndexes();
132 foreach (const QModelIndex
& index
, indexList
) {
138 void DolphinController::replaceUrlByClipboard()
140 const QClipboard
* clipboard
= QApplication::clipboard();
142 if (clipboard
->mimeData(QClipboard::Selection
)->hasText()) {
143 text
= clipboard
->mimeData(QClipboard::Selection
)->text();
144 } else if (clipboard
->mimeData(QClipboard::Clipboard
)->hasText()) {
145 text
= clipboard
->mimeData(QClipboard::Clipboard
)->text();
147 if (!text
.isEmpty() && QDir::isAbsolutePath(text
)) {
148 m_dolphinView
->setUrl(KUrl(text
));
152 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
154 Q_ASSERT(m_itemView
!= 0);
156 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
157 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
158 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
159 return dirModel
->itemForIndex(dirIndex
);
162 void DolphinController::triggerItem(const QModelIndex
& index
)
164 const bool openTab
= m_openTab
;
167 const KFileItem item
= itemForIndex(index
);
168 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
169 if (openTab
&& (item
.isDir() || m_dolphinView
->isTabsForFilesEnabled())) {
170 emit
tabRequested(item
.url());
172 emit
itemTriggered(item
);
175 m_itemView
->clearSelection();
177 emit
itemEntered(KFileItem());
182 void DolphinController::emitItemEntered(const QModelIndex
& index
)
184 KFileItem item
= itemForIndex(index
);
185 if (!item
.isNull()) {
186 emit
itemEntered(item
);
190 void DolphinController::emitViewportEntered()
192 emit
viewportEntered();
195 void DolphinController::updateOpenTabState()
197 m_openTab
= QApplication::mouseButtons() & Qt::MidButton
;
200 #include "dolphincontroller.moc"