]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/folders/folderspanel.cpp
1 /***************************************************************************
2 * Copyright (C) 2006-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 "folderspanel.h"
22 #include "dolphin_folderspanelsettings.h"
23 #include "dolphin_generalsettings.h"
24 #include "paneltreeview.h"
25 #include "treeviewcontextmenu.h"
29 #include <konq_operations.h>
31 #include <QApplication>
33 #include <QItemSelection>
34 #include <QModelIndex>
40 #include <views/dolphinview.h>
41 #include <views/folderexpander.h>
42 #include <views/renamedialog.h>
44 FoldersPanel::FoldersPanel(QWidget
* parent
) :
46 m_setLeafVisible(false),
47 m_mouseButtons(Qt::NoButton
),
54 setLayoutDirection(Qt::LeftToRight
);
57 FoldersPanel::~FoldersPanel()
59 FoldersPanelSettings::self()->writeConfig();
61 //delete m_proxyModel;
63 //delete m_dolphinModel;
69 void FoldersPanel::setHiddenFilesShown(bool show
)
71 FoldersPanelSettings::setHiddenFilesShown(show
);
73 m_dirLister
->setShowingDotFiles(show
);
74 m_dirLister
->openUrl(m_dirLister
->url(), KDirLister::Reload
);
78 bool FoldersPanel::hiddenFilesShown() const
80 return FoldersPanelSettings::hiddenFilesShown();
83 void FoldersPanel::setAutoScrolling(bool enable
)
85 m_treeView
->setAutoHorizontalScroll(enable
);
86 FoldersPanelSettings::setAutoScrolling(enable
);
89 bool FoldersPanel::autoScrolling() const
91 return FoldersPanelSettings::autoScrolling();
94 void FoldersPanel::rename(const KFileItem
& item
)
96 // TODO: Inline renaming is not supported anymore in Dolphin 2.0
97 if (false /* GeneralSettings::renameInline() */) {
98 //const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
99 //const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
100 //m_treeView->edit(proxyIndex);
102 RenameDialog
* dialog
= new RenameDialog(this, KFileItemList() << item
);
103 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
106 dialog
->activateWindow();
110 bool FoldersPanel::urlChanged()
112 if (!url().isValid() || url().protocol().contains("search")) {
113 // Skip results shown by a search, as possible identical
114 // directory names are useless without parent-path information.
119 m_setLeafVisible
= true;
126 void FoldersPanel::showEvent(QShowEvent
* event
)
128 if (event
->spontaneous()) {
129 Panel::showEvent(event
);
134 // Postpone the creating of the dir lister to the first show event.
135 // This assures that no performance and memory overhead is given when the TreeView is not
136 // used at all (see FoldersPanel::setUrl()).
137 m_dirLister
= new KDirLister();
138 m_dirLister
->setDirOnlyMode(true);
139 m_dirLister
->setAutoUpdate(true);
140 m_dirLister
->setMainWindow(window());
141 m_dirLister
->setDelayedMimeTypes(true);
142 m_dirLister
->setAutoErrorHandlingEnabled(false, this);
143 m_dirLister
->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown());
144 connect(m_dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
146 /*Q_ASSERT(!m_dolphinModel);
147 m_dolphinModel = new DolphinModel(this);
148 m_dolphinModel->setDirLister(m_dirLister);
149 m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory);
150 connect(m_dolphinModel, SIGNAL(expand(QModelIndex)),
151 this, SLOT(expandToDir(QModelIndex)));
153 Q_ASSERT(!m_proxyModel);
154 m_proxyModel = new DolphinSortFilterProxyModel(this);
155 m_proxyModel->setSourceModel(m_dolphinModel);
157 Q_ASSERT(!m_treeView);
158 m_treeView = new PanelTreeView(this);
159 m_treeView->setModel(m_proxyModel);
160 m_proxyModel->setSorting(DolphinView::SortByName);
161 m_proxyModel->setSortOrder(Qt::AscendingOrder);
162 m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
164 new FolderExpander(m_treeView, m_proxyModel);
166 connect(m_treeView, SIGNAL(clicked(QModelIndex)),
167 this, SLOT(updateActiveView(QModelIndex)));
168 connect(m_treeView, SIGNAL(urlsDropped(QModelIndex,QDropEvent*)),
169 this, SLOT(dropUrls(QModelIndex,QDropEvent*)));
170 connect(m_treeView, SIGNAL(pressed(QModelIndex)),
171 this, SLOT(updateMouseButtons()));
173 connect(m_treeView->horizontalScrollBar(), SIGNAL(sliderMoved(int)),
174 this, SLOT(slotHorizontalScrollBarMoved(int)));
175 connect(m_treeView->verticalScrollBar(), SIGNAL(valueChanged(int)),
176 this, SLOT(slotVerticalScrollBarMoved(int)));
178 QVBoxLayout* layout = new QVBoxLayout(this);
179 layout->setMargin(0);
180 layout->addWidget(m_treeView);*/
184 Panel::showEvent(event
);
187 void FoldersPanel::contextMenuEvent(QContextMenuEvent
* event
)
189 Panel::contextMenuEvent(event
);
192 /*const QModelIndex index = m_treeView->indexAt(event->pos());
193 if (index.isValid()) {
194 const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
195 item = m_dolphinModel->itemForIndex(dolphinModelIndex);
198 QPointer
<TreeViewContextMenu
> contextMenu
= new TreeViewContextMenu(this, item
);
203 void FoldersPanel::keyPressEvent(QKeyEvent
* event
)
205 const int key
= event
->key();
206 if ((key
== Qt::Key_Enter
) || (key
== Qt::Key_Return
)) {
208 updateActiveView(m_treeView
->currentIndex());
210 Panel::keyPressEvent(event
);
214 void FoldersPanel::updateActiveView(const QModelIndex
& index
)
217 /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
218 const KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
219 if (!item.isNull()) {
220 emit changeUrl(item.url(), m_mouseButtons);
224 void FoldersPanel::dropUrls(const QModelIndex
& index
, QDropEvent
* event
)
227 if (index
.isValid()) {
228 /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
229 KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
230 Q_ASSERT(!item.isNull());
233 //DragAndDropHelper::instance().dropUrls(item, item.url(), event, this);
238 void FoldersPanel::expandToDir(const QModelIndex
& index
)
240 m_treeView
->setExpanded(index
, true);
241 selectLeafDirectory();
244 void FoldersPanel::scrollToLeaf()
246 /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
247 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
248 if (proxyIndex.isValid()) {
249 m_treeView->scrollTo(proxyIndex);
253 void FoldersPanel::updateMouseButtons()
255 m_mouseButtons
= QApplication::mouseButtons();
258 void FoldersPanel::slotDirListerCompleted()
260 // m_treeView->resizeColumnToContents(DolphinModel::Name);
263 void FoldersPanel::slotHorizontalScrollBarMoved(int value
)
266 // Disable the auto-scrolling until the vertical scrollbar has
267 // been moved by the user.
268 m_treeView
->setAutoHorizontalScroll(false);
271 void FoldersPanel::slotVerticalScrollBarMoved(int value
)
274 // Enable the auto-scrolling again (it might have been disabled by
275 // moving the horizontal scrollbar).
276 m_treeView
->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
279 void FoldersPanel::loadTree(const KUrl
& url
)
281 Q_ASSERT(m_dirLister
);
285 if (url
.isLocalFile()) {
286 // use the root directory as base for local URLs (#150941)
287 baseUrl
= QDir::rootPath();
289 // clear the path for non-local URLs and use it as base
291 baseUrl
.setPath(QString('/'));
294 if (m_dirLister
->url() != baseUrl
) {
296 m_dirLister
->openUrl(baseUrl
, KDirLister::Reload
);
298 //m_dolphinModel->expandToUrl(m_leafDir);
301 void FoldersPanel::selectLeafDirectory()
303 /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
304 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
306 if (proxyIndex.isValid()) {
307 QItemSelectionModel* selModel = m_treeView->selectionModel();
308 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
310 if (m_setLeafVisible) {
311 // Invoke scrollToLeaf() asynchronously. This assures that
312 // the horizontal scrollbar is shown after resizing the column
313 // (otherwise the scrollbar might hide the leaf).
314 QTimer::singleShot(0, this, SLOT(scrollToLeaf()));
315 m_setLeafVisible = false;
320 #include "folderspanel.moc"