]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphindetailsviewexpander.cpp
Use capitalized KDE includes
[dolphin.git] / src / views / dolphindetailsviewexpander.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Frank Reininghaus (frank78ac@googlemail.com) *
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 "dolphindetailsviewexpander.h"
21
22 #include "dolphindetailsview.h"
23 #include "dolphinmodel.h"
24 #include "dolphinsortfilterproxymodel.h"
25
26 #include <KDirLister>
27 #include <KDirModel>
28
29 DolphinDetailsViewExpander::DolphinDetailsViewExpander(DolphinDetailsView* parent,
30 const QSet<KUrl>& urlsToExpand) :
31 QObject(parent),
32 m_detailsView(parent),
33 m_dirLister(0),
34 m_dolphinModel(0),
35 m_proxyModel(0)
36 {
37 Q_ASSERT(parent != 0);
38
39 m_proxyModel = qobject_cast<const DolphinSortFilterProxyModel*>(parent->model());
40 Q_ASSERT(m_proxyModel != 0);
41
42 m_dolphinModel = qobject_cast<const DolphinModel*>(m_proxyModel->sourceModel());
43 Q_ASSERT(m_dolphinModel != 0);
44
45 m_dirLister = m_dolphinModel->dirLister();
46 Q_ASSERT(m_dirLister != 0);
47
48 // The URLs must be sorted. E.g. /home/user/ cannot be expanded before /home/
49 // because it is not known to the dir model before.
50 m_urlsToExpand = urlsToExpand.toList();
51 qSort(m_urlsToExpand);
52
53 // The dir lister must have completed the folder listing before a subfolder can be expanded.
54 connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
55 }
56
57 DolphinDetailsViewExpander::~DolphinDetailsViewExpander()
58 {
59 }
60
61 void DolphinDetailsViewExpander::stop()
62 {
63 disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
64 deleteLater();
65 }
66
67 void DolphinDetailsViewExpander::slotDirListerCompleted()
68 {
69 QModelIndex dirIndex;
70
71 while(!m_urlsToExpand.isEmpty() && !dirIndex.isValid()) {
72 const KUrl url = m_urlsToExpand.takeFirst();
73 dirIndex = m_dolphinModel->indexForUrl(url);
74 }
75
76 if(dirIndex.isValid()) {
77 // A valid model index was found. Note that only one item is expanded in each call of this slot
78 // because expanding any item will trigger KDirLister::openUrl(...) via KDirModel::fetchMore(...),
79 // and we can only continue when the dir lister is done.
80 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
81 m_detailsView->expand(proxyIndex);
82 }
83 else {
84 emit completed();
85 stop();
86 }
87 }