]>
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 "settings/dolphinsettings.h"
23 #include "dolphin_folderspanelsettings.h"
24 #include "dolphin_generalsettings.h"
25 #include "paneltreeview.h"
26 #include "treeviewcontextmenu.h"
28 #include <KFilePlacesModel>
31 #include <konq_operations.h>
33 #include <QApplication>
35 #include <QItemSelection>
36 #include <QModelIndex>
42 #include <views/dolphinview.h>
43 #include <views/folderexpander.h>
44 #include <views/renamedialog.h>
46 FoldersPanel::FoldersPanel(QWidget
* parent
) :
48 m_setLeafVisible(false),
49 m_mouseButtons(Qt::NoButton
),
56 setLayoutDirection(Qt::LeftToRight
);
59 FoldersPanel::~FoldersPanel()
61 FoldersPanelSettings::self()->writeConfig();
63 //delete m_proxyModel;
65 //delete m_dolphinModel;
71 void FoldersPanel::setHiddenFilesShown(bool show
)
73 FoldersPanelSettings::setHiddenFilesShown(show
);
75 m_dirLister
->setShowingDotFiles(show
);
76 m_dirLister
->openUrl(m_dirLister
->url(), KDirLister::Reload
);
80 bool FoldersPanel::hiddenFilesShown() const
82 return FoldersPanelSettings::hiddenFilesShown();
85 void FoldersPanel::setAutoScrolling(bool enable
)
87 m_treeView
->setAutoHorizontalScroll(enable
);
88 FoldersPanelSettings::setAutoScrolling(enable
);
91 bool FoldersPanel::autoScrolling() const
93 return FoldersPanelSettings::autoScrolling();
96 void FoldersPanel::rename(const KFileItem
& item
)
98 if (DolphinSettings::instance().generalSettings()->renameInline()) {
99 //const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
100 //const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
101 //m_treeView->edit(proxyIndex);
103 RenameDialog
* dialog
= new RenameDialog(this, KFileItemList() << item
);
104 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
107 dialog
->activateWindow();
111 bool FoldersPanel::urlChanged()
113 if (!url().isValid() || url().protocol().contains("search")) {
114 // Skip results shown by a search, as possible identical
115 // directory names are useless without parent-path information.
120 m_setLeafVisible
= true;
127 void FoldersPanel::showEvent(QShowEvent
* event
)
129 if (event
->spontaneous()) {
130 Panel::showEvent(event
);
135 // Postpone the creating of the dir lister to the first show event.
136 // This assures that no performance and memory overhead is given when the TreeView is not
137 // used at all (see FoldersPanel::setUrl()).
138 m_dirLister
= new KDirLister();
139 m_dirLister
->setDirOnlyMode(true);
140 m_dirLister
->setAutoUpdate(true);
141 m_dirLister
->setMainWindow(window());
142 m_dirLister
->setDelayedMimeTypes(true);
143 m_dirLister
->setAutoErrorHandlingEnabled(false, this);
144 m_dirLister
->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown());
145 connect(m_dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
147 /*Q_ASSERT(!m_dolphinModel);
148 m_dolphinModel = new DolphinModel(this);
149 m_dolphinModel->setDirLister(m_dirLister);
150 m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory);
151 connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
152 this, SLOT(expandToDir(const QModelIndex&)));
154 Q_ASSERT(!m_proxyModel);
155 m_proxyModel = new DolphinSortFilterProxyModel(this);
156 m_proxyModel->setSourceModel(m_dolphinModel);
158 Q_ASSERT(!m_treeView);
159 m_treeView = new PanelTreeView(this);
160 m_treeView->setModel(m_proxyModel);
161 m_proxyModel->setSorting(DolphinView::SortByName);
162 m_proxyModel->setSortOrder(Qt::AscendingOrder);
163 m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
165 new FolderExpander(m_treeView, m_proxyModel);
167 connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
168 this, SLOT(updateActiveView(const QModelIndex&)));
169 connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)),
170 this, SLOT(dropUrls(const QModelIndex&, QDropEvent*)));
171 connect(m_treeView, SIGNAL(pressed(const QModelIndex&)),
172 this, SLOT(updateMouseButtons()));
174 connect(m_treeView->horizontalScrollBar(), SIGNAL(sliderMoved(int)),
175 this, SLOT(slotHorizontalScrollBarMoved(int)));
176 connect(m_treeView->verticalScrollBar(), SIGNAL(valueChanged(int)),
177 this, SLOT(slotVerticalScrollBarMoved(int)));
179 QVBoxLayout* layout = new QVBoxLayout(this);
180 layout->setMargin(0);
181 layout->addWidget(m_treeView);*/
185 Panel::showEvent(event
);
188 void FoldersPanel::contextMenuEvent(QContextMenuEvent
* event
)
190 Panel::contextMenuEvent(event
);
193 /*const QModelIndex index = m_treeView->indexAt(event->pos());
194 if (index.isValid()) {
195 const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
196 item = m_dolphinModel->itemForIndex(dolphinModelIndex);
199 QPointer
<TreeViewContextMenu
> contextMenu
= new TreeViewContextMenu(this, item
);
204 void FoldersPanel::keyPressEvent(QKeyEvent
* event
)
206 const int key
= event
->key();
207 if ((key
== Qt::Key_Enter
) || (key
== Qt::Key_Return
)) {
209 updateActiveView(m_treeView
->currentIndex());
211 Panel::keyPressEvent(event
);
215 void FoldersPanel::updateActiveView(const QModelIndex
& index
)
218 /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
219 const KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
220 if (!item.isNull()) {
221 emit changeUrl(item.url(), m_mouseButtons);
225 void FoldersPanel::dropUrls(const QModelIndex
& index
, QDropEvent
* event
)
228 if (index
.isValid()) {
229 /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
230 KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
231 Q_ASSERT(!item.isNull());
234 //DragAndDropHelper::instance().dropUrls(item, item.url(), event, this);
239 void FoldersPanel::expandToDir(const QModelIndex
& index
)
241 m_treeView
->setExpanded(index
, true);
242 selectLeafDirectory();
245 void FoldersPanel::scrollToLeaf()
247 /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
248 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
249 if (proxyIndex.isValid()) {
250 m_treeView->scrollTo(proxyIndex);
254 void FoldersPanel::updateMouseButtons()
256 m_mouseButtons
= QApplication::mouseButtons();
259 void FoldersPanel::slotDirListerCompleted()
261 // m_treeView->resizeColumnToContents(DolphinModel::Name);
264 void FoldersPanel::slotHorizontalScrollBarMoved(int value
)
267 // Disable the auto-scrolling until the vertical scrollbar has
268 // been moved by the user.
269 m_treeView
->setAutoHorizontalScroll(false);
272 void FoldersPanel::slotVerticalScrollBarMoved(int value
)
275 // Enable the auto-scrolling again (it might have been disabled by
276 // moving the horizontal scrollbar).
277 m_treeView
->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
280 void FoldersPanel::loadTree(const KUrl
& url
)
282 Q_ASSERT(m_dirLister
);
286 if (url
.isLocalFile()) {
287 // use the root directory as base for local URLs (#150941)
288 baseUrl
= QDir::rootPath();
290 // clear the path for non-local URLs and use it as base
292 baseUrl
.setPath(QString('/'));
295 if (m_dirLister
->url() != baseUrl
) {
297 m_dirLister
->openUrl(baseUrl
, KDirLister::Reload
);
299 //m_dolphinModel->expandToUrl(m_leafDir);
302 void FoldersPanel::selectLeafDirectory()
304 /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
305 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
307 if (proxyIndex.isValid()) {
308 QItemSelectionModel* selModel = m_treeView->selectionModel();
309 selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
311 if (m_setLeafVisible) {
312 // Invoke scrollToLeaf() asynchronously. This assures that
313 // the horizontal scrollbar is shown after resizing the column
314 // (otherwise the scrollbar might hide the leaf).
315 QTimer::singleShot(0, this, SLOT(scrollToLeaf()));
316 m_setLeafVisible = false;
321 #include "folderspanel.moc"