1 /***************************************************************************
2 * Copyright (C) 2009 by Frank Reininghaus (frank78ac@googlemail.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 "dolphindetailsviewexpander.h"
22 #include "dolphindetailsview.h"
23 #include "dolphinmodel.h"
24 #include "dolphinsortfilterproxymodel.h"
29 DolphinDetailsViewExpander::DolphinDetailsViewExpander(DolphinDetailsView
* parent
,
30 const QSet
<KUrl
>& urlsToExpand
) :
32 m_detailsView(parent
),
37 Q_ASSERT(parent
!= 0);
39 m_proxyModel
= qobject_cast
<const DolphinSortFilterProxyModel
*>(parent
->model());
40 Q_ASSERT(m_proxyModel
!= 0);
42 m_dolphinModel
= qobject_cast
<const DolphinModel
*>(m_proxyModel
->sourceModel());
43 Q_ASSERT(m_dolphinModel
!= 0);
45 m_dirLister
= m_dolphinModel
->dirLister();
46 Q_ASSERT(m_dirLister
!= 0);
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
);
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()));
57 DolphinDetailsViewExpander::~DolphinDetailsViewExpander()
61 void DolphinDetailsViewExpander::stop()
63 disconnect(m_dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
67 void DolphinDetailsViewExpander::slotDirListerCompleted()
71 while(!m_urlsToExpand
.isEmpty() && !dirIndex
.isValid()) {
72 const KUrl url
= m_urlsToExpand
.takeFirst();
73 dirIndex
= m_dolphinModel
->indexForUrl(url
);
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
);