1 /***************************************************************************
2 * Copyright (C) 2011 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 "kfileitemmodel.h"
24 #include <KStringHandler>
29 #define KFILEITEMMODEL_DEBUG
31 KFileItemModel::KFileItemModel(KDirLister
* dirLister
, QObject
* parent
) :
32 KItemModelBase(QByteArray(), "name", parent
),
33 m_dirLister(dirLister
),
34 m_naturalSorting(true),
35 m_sortFoldersFirst(true),
38 m_caseSensitivity(Qt::CaseInsensitive
),
43 m_minimumUpdateIntervalTimer(0),
44 m_maximumUpdateIntervalTimer(0),
45 m_pendingItemsToInsert(),
46 m_pendingItemsToDelete(),
47 m_rootExpansionLevel(-1)
50 m_requestRole
[NameRole
] = true;
51 m_requestRole
[IsDirRole
] = true;
55 connect(dirLister
, SIGNAL(canceled()), this, SLOT(slotCanceled()));
56 connect(dirLister
, SIGNAL(completed()), this, SLOT(slotCompleted()));
57 connect(dirLister
, SIGNAL(newItems(KFileItemList
)), this, SLOT(slotNewItems(KFileItemList
)));
58 connect(dirLister
, SIGNAL(itemsDeleted(KFileItemList
)), this, SLOT(slotItemsDeleted(KFileItemList
)));
59 connect(dirLister
, SIGNAL(clear()), this, SLOT(slotClear()));
60 connect(dirLister
, SIGNAL(clear(KUrl
)), this, SLOT(slotClear(KUrl
)));
62 // Although the layout engine of KItemListView is fast it is very inefficient to e.g.
63 // emit 50 itemsInserted()-signals each 100 ms. m_minimumUpdateIntervalTimer assures that updates
64 // are done in 1 second intervals for equal operations.
65 m_minimumUpdateIntervalTimer
= new QTimer(this);
66 m_minimumUpdateIntervalTimer
->setInterval(1000);
67 m_minimumUpdateIntervalTimer
->setSingleShot(true);
68 connect(m_minimumUpdateIntervalTimer
, SIGNAL(timeout()), this, SLOT(dispatchPendingItems()));
70 // For slow KIO-slaves like used for searching it makes sense to show results periodically even
71 // before the completed() or canceled() signal has been emitted.
72 m_maximumUpdateIntervalTimer
= new QTimer(this);
73 m_maximumUpdateIntervalTimer
->setInterval(2000);
74 m_maximumUpdateIntervalTimer
->setSingleShot(true);
75 connect(m_maximumUpdateIntervalTimer
, SIGNAL(timeout()), this, SLOT(dispatchPendingItems()));
77 Q_ASSERT(m_minimumUpdateIntervalTimer
->interval() <= m_maximumUpdateIntervalTimer
->interval());
80 KFileItemModel::~KFileItemModel()
84 int KFileItemModel::count() const
86 return m_data
.count();
89 QHash
<QByteArray
, QVariant
> KFileItemModel::data(int index
) const
91 if (index
>= 0 && index
< count()) {
92 return m_data
.at(index
);
94 return QHash
<QByteArray
, QVariant
>();
97 bool KFileItemModel::setData(int index
, const QHash
<QByteArray
, QVariant
>& values
)
99 if (index
>= 0 && index
< count()) {
100 QHash
<QByteArray
, QVariant
> currentValue
= m_data
.at(index
);
102 QSet
<QByteArray
> changedRoles
;
103 QHashIterator
<QByteArray
, QVariant
> it(values
);
104 while (it
.hasNext()) {
106 const QByteArray role
= it
.key();
107 const QVariant value
= it
.value();
109 if (currentValue
[role
] != value
) {
110 currentValue
[role
] = value
;
111 changedRoles
.insert(role
);
115 if (!changedRoles
.isEmpty()) {
116 m_data
[index
] = currentValue
;
117 emit
itemsChanged(KItemRangeList() << KItemRange(index
, 1), changedRoles
);
125 bool KFileItemModel::supportsGrouping() const
130 bool KFileItemModel::supportsSorting() const
135 KFileItem
KFileItemModel::fileItem(int index
) const
137 if (index
>= 0 && index
< count()) {
138 return m_sortedItems
.at(index
);
144 int KFileItemModel::index(const KFileItem
& item
) const
150 return m_items
.value(item
, -1);
153 void KFileItemModel::clear()
158 void KFileItemModel::setRoles(const QSet
<QByteArray
>& roles
)
161 const bool supportedExpanding
= m_requestRole
[IsExpandedRole
] && m_requestRole
[ExpansionLevelRole
];
162 const bool willSupportExpanding
= roles
.contains("isExpanded") && roles
.contains("expansionLevel");
163 if (supportedExpanding
&& !willSupportExpanding
) {
164 // No expanding is supported anymore. Take care to delete all items that have an expansion level
165 // that is not 0 (and hence are part of an expanded item).
166 removeExpandedItems();
171 QSetIterator
<QByteArray
> it(roles
);
172 while (it
.hasNext()) {
173 const QByteArray
& role
= it
.next();
174 m_requestRole
[roleIndex(role
)] = true;
178 // Update m_data with the changed requested roles
179 const int maxIndex
= count() - 1;
180 for (int i
= 0; i
<= maxIndex
; ++i
) {
181 m_data
[i
] = retrieveData(m_sortedItems
.at(i
));
184 kWarning() << "TODO: Emitting itemsChanged() with no information what has changed!";
185 emit
itemsChanged(KItemRangeList() << KItemRange(0, count()), QSet
<QByteArray
>());
189 QSet
<QByteArray
> KFileItemModel::roles() const
191 QSet
<QByteArray
> roles
;
192 for (int i
= 0; i
< RolesCount
; ++i
) {
193 if (m_requestRole
[i
]) {
196 case NameRole
: roles
.insert("name"); break;
197 case SizeRole
: roles
.insert("size"); break;
198 case DateRole
: roles
.insert("date"); break;
199 case PermissionsRole
: roles
.insert("permissions"); break;
200 case OwnerRole
: roles
.insert("owner"); break;
201 case GroupRole
: roles
.insert("group"); break;
202 case TypeRole
: roles
.insert("type"); break;
203 case DestinationRole
: roles
.insert("destination"); break;
204 case PathRole
: roles
.insert("path"); break;
205 case IsDirRole
: roles
.insert("isDir"); break;
206 case IsExpandedRole
: roles
.insert("isExpanded"); break;
207 case ExpansionLevelRole
: roles
.insert("expansionLevel"); break;
208 default: Q_ASSERT(false); break;
215 bool KFileItemModel::setExpanded(int index
, bool expanded
)
217 if (isExpanded(index
) == expanded
|| index
< 0 || index
>= count()) {
221 QHash
<QByteArray
, QVariant
> values
;
222 values
.insert("isExpanded", expanded
);
223 if (!setData(index
, values
)) {
228 const KUrl url
= m_sortedItems
.at(index
).url();
229 KDirLister
* dirLister
= m_dirLister
.data();
231 dirLister
->openUrl(url
, KDirLister::Keep
);
235 KFileItemList itemsToRemove
;
236 const int expansionLevel
= data(index
)["expansionLevel"].toInt();
238 while (index
< count() && data(index
)["expansionLevel"].toInt() > expansionLevel
) {
239 itemsToRemove
.append(m_sortedItems
.at(index
));
242 removeItems(itemsToRemove
);
249 bool KFileItemModel::isExpanded(int index
) const
251 if (index
>= 0 && index
< count()) {
252 return m_data
.at(index
).value("isExpanded").toBool();
257 bool KFileItemModel::isExpandable(int index
) const
259 if (index
>= 0 && index
< count()) {
260 return m_sortedItems
.at(index
).isDir();
265 void KFileItemModel::onGroupRoleChanged(const QByteArray
& current
, const QByteArray
& previous
)
268 m_groupRole
= roleIndex(current
);
271 void KFileItemModel::onSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
)
274 const int itemCount
= count();
275 if (itemCount
<= 0) {
279 m_sortRole
= roleIndex(current
);
281 KFileItemList sortedItems
= m_sortedItems
;
282 m_sortedItems
.clear();
285 emit
itemsRemoved(KItemRangeList() << KItemRange(0, itemCount
));
287 sort(sortedItems
.begin(), sortedItems
.end());
289 foreach (const KFileItem
& item
, sortedItems
) {
290 m_sortedItems
.append(item
);
291 m_items
.insert(item
, index
);
292 m_data
.append(retrieveData(item
));
297 emit
itemsInserted(KItemRangeList() << KItemRange(0, itemCount
));
300 void KFileItemModel::slotCompleted()
302 if (m_minimumUpdateIntervalTimer
->isActive()) {
303 // dispatchPendingItems() will be called when the timer
308 dispatchPendingItems();
309 m_minimumUpdateIntervalTimer
->start();
312 void KFileItemModel::slotCanceled()
314 m_minimumUpdateIntervalTimer
->stop();
315 m_maximumUpdateIntervalTimer
->stop();
316 dispatchPendingItems();
319 void KFileItemModel::slotNewItems(const KFileItemList
& items
)
321 if (!m_pendingItemsToDelete
.isEmpty()) {
322 removeItems(m_pendingItemsToDelete
);
323 m_pendingItemsToDelete
.clear();
325 m_pendingItemsToInsert
.append(items
);
327 if (useMaximumUpdateInterval() && !m_maximumUpdateIntervalTimer
->isActive()) {
328 // Assure that items get dispatched if no completed() or canceled() signal is
329 // emitted during the maximum update interval.
330 m_maximumUpdateIntervalTimer
->start();
334 void KFileItemModel::slotItemsDeleted(const KFileItemList
& items
)
336 if (!m_pendingItemsToInsert
.isEmpty()) {
337 insertItems(m_pendingItemsToInsert
);
338 m_pendingItemsToInsert
.clear();
340 m_pendingItemsToDelete
.append(items
);
343 void KFileItemModel::slotClear()
345 #ifdef KFILEITEMMODEL_DEBUG
346 kDebug() << "Clearing all items";
349 m_minimumUpdateIntervalTimer
->stop();
350 m_maximumUpdateIntervalTimer
->stop();
351 m_pendingItemsToInsert
.clear();
352 m_pendingItemsToDelete
.clear();
354 m_rootExpansionLevel
= -1;
356 const int removedCount
= m_data
.count();
357 if (removedCount
> 0) {
358 m_sortedItems
.clear();
361 emit
itemsRemoved(KItemRangeList() << KItemRange(0, removedCount
));
365 void KFileItemModel::slotClear(const KUrl
& url
)
370 void KFileItemModel::dispatchPendingItems()
372 if (!m_pendingItemsToInsert
.isEmpty()) {
373 Q_ASSERT(m_pendingItemsToDelete
.isEmpty());
374 insertItems(m_pendingItemsToInsert
);
375 m_pendingItemsToInsert
.clear();
376 } else if (!m_pendingItemsToDelete
.isEmpty()) {
377 Q_ASSERT(m_pendingItemsToInsert
.isEmpty());
378 removeItems(m_pendingItemsToDelete
);
379 m_pendingItemsToDelete
.clear();
383 void KFileItemModel::insertItems(const KFileItemList
& items
)
385 if (items
.isEmpty()) {
389 #ifdef KFILEITEMMODEL_DEBUG
392 kDebug() << "===========================================================";
393 kDebug() << "Inserting" << items
.count() << "items";
396 KFileItemList sortedItems
= items
;
397 sort(sortedItems
.begin(), sortedItems
.end());
399 #ifdef KFILEITEMMODEL_DEBUG
400 kDebug() << "[TIME] Sorting:" << timer
.elapsed();
403 KItemRangeList itemRanges
;
406 int insertedAtIndex
= -1;
407 int insertedCount
= 0;
408 while (sourceIndex
< sortedItems
.count()) {
409 // Find target index from m_items to insert the current item
411 const int previousTargetIndex
= targetIndex
;
412 while (targetIndex
< m_sortedItems
.count()) {
413 if (!lessThan(m_sortedItems
.at(targetIndex
), sortedItems
.at(sourceIndex
))) {
419 if (targetIndex
- previousTargetIndex
> 0 && insertedAtIndex
>= 0) {
420 itemRanges
<< KItemRange(insertedAtIndex
, insertedCount
);
421 insertedAtIndex
= targetIndex
;
425 // Insert item at the position targetIndex
426 const KFileItem item
= sortedItems
.at(sourceIndex
);
427 m_sortedItems
.insert(targetIndex
, item
);
428 m_data
.insert(targetIndex
, retrieveData(item
));
429 // m_items will be inserted after the loop (see comment below)
432 if (insertedAtIndex
< 0) {
433 insertedAtIndex
= targetIndex
;
439 // The indexes of all m_items must be adjusted, not only the index
441 for (int i
= 0; i
< m_sortedItems
.count(); ++i
) {
442 m_items
.insert(m_sortedItems
.at(i
), i
);
445 itemRanges
<< KItemRange(insertedAtIndex
, insertedCount
);
446 emit
itemsInserted(itemRanges
);
448 #ifdef KFILEITEMMODEL_DEBUG
449 kDebug() << "[TIME] Inserting of" << items
.count() << "items:" << timer
.elapsed();
453 void KFileItemModel::removeItems(const KFileItemList
& items
)
455 if (items
.isEmpty()) {
459 #ifdef KFILEITEMMODEL_DEBUG
460 kDebug() << "Removing " << items
.count() << "items";
463 KFileItemList sortedItems
= items
;
464 sort(sortedItems
.begin(), sortedItems
.end());
466 QList
<int> indexesToRemove
;
467 indexesToRemove
.reserve(items
.count());
469 // Calculate the item ranges that will get deleted
470 KItemRangeList itemRanges
;
471 int removedAtIndex
= -1;
472 int removedCount
= 0;
474 foreach (const KFileItem
& itemToRemove
, sortedItems
) {
475 const int previousTargetIndex
= targetIndex
;
476 while (targetIndex
< m_sortedItems
.count()) {
477 if (m_sortedItems
.at(targetIndex
) == itemToRemove
) {
482 if (targetIndex
>= m_sortedItems
.count()) {
483 kWarning() << "Item that should be deleted has not been found!";
487 if (targetIndex
- previousTargetIndex
> 0 && removedAtIndex
>= 0) {
488 itemRanges
<< KItemRange(removedAtIndex
, removedCount
);
489 removedAtIndex
= targetIndex
;
493 indexesToRemove
.append(targetIndex
);
494 if (removedAtIndex
< 0) {
495 removedAtIndex
= targetIndex
;
502 for (int i
= indexesToRemove
.count() - 1; i
>= 0; --i
) {
503 const int indexToRemove
= indexesToRemove
.at(i
);
504 m_items
.remove(m_sortedItems
.at(indexToRemove
));
505 m_sortedItems
.removeAt(indexToRemove
);
506 m_data
.removeAt(indexToRemove
);
509 // The indexes of all m_items must be adjusted, not only the index
510 // of the removed items
511 for (int i
= 0; i
< m_sortedItems
.count(); ++i
) {
512 m_items
.insert(m_sortedItems
.at(i
), i
);
516 m_rootExpansionLevel
= -1;
519 itemRanges
<< KItemRange(removedAtIndex
, removedCount
);
520 emit
itemsRemoved(itemRanges
);
523 void KFileItemModel::removeExpandedItems()
526 KFileItemList expandedItems
;
528 const int maxIndex
= m_data
.count() - 1;
529 for (int i
= 0; i
<= maxIndex
; ++i
) {
530 if (m_data
.at(i
).value("expansionLevel").toInt() > 0) {
531 const KFileItem fileItem
= m_sortedItems
.at(i
);
532 expandedItems
.append(fileItem
);
536 // The m_rootExpansionLevel may not get reset before all items with
537 // a bigger expansionLevel have been removed.
538 Q_ASSERT(m_rootExpansionLevel
>= 0);
539 removeItems(expandedItems
);
541 m_rootExpansionLevel
= -1;
544 void KFileItemModel::resetRoles()
546 for (int i
= 0; i
< RolesCount
; ++i
) {
547 m_requestRole
[i
] = false;
551 KFileItemModel::Role
KFileItemModel::roleIndex(const QByteArray
& role
) const
553 static QHash
<QByteArray
, Role
> rolesHash
;
554 if (rolesHash
.isEmpty()) {
555 rolesHash
.insert("name", NameRole
);
556 rolesHash
.insert("size", SizeRole
);
557 rolesHash
.insert("date", DateRole
);
558 rolesHash
.insert("permissions", PermissionsRole
);
559 rolesHash
.insert("owner", OwnerRole
);
560 rolesHash
.insert("group", GroupRole
);
561 rolesHash
.insert("type", TypeRole
);
562 rolesHash
.insert("destination", DestinationRole
);
563 rolesHash
.insert("path", PathRole
);
564 rolesHash
.insert("isDir", IsDirRole
);
565 rolesHash
.insert("isExpanded", IsExpandedRole
);
566 rolesHash
.insert("expansionLevel", ExpansionLevelRole
);
568 return rolesHash
.value(role
, NoRole
);
571 QHash
<QByteArray
, QVariant
> KFileItemModel::retrieveData(const KFileItem
& item
) const
573 // It is important to insert only roles that are fast to retrieve. E.g.
574 // KFileItem::iconName() can be very expensive if the MIME-type is unknown
575 // and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
576 QHash
<QByteArray
, QVariant
> data
;
577 data
.insert("iconPixmap", QPixmap());
579 const bool isDir
= item
.isDir();
580 if (m_requestRole
[IsDirRole
]) {
581 data
.insert("isDir", isDir
);
584 if (m_requestRole
[NameRole
]) {
585 data
.insert("name", item
.name());
588 if (m_requestRole
[SizeRole
]) {
590 data
.insert("size", QVariant());
592 data
.insert("size", item
.size());
596 if (m_requestRole
[DateRole
]) {
597 // Don't use KFileItem::timeString() as this is too expensive when
598 // having several thousands of items. Instead the formatting of the
599 // date-time will be done on-demand by the view when the date will be shown.
600 const KDateTime dateTime
= item
.time(KFileItem::ModificationTime
);
601 data
.insert("date", dateTime
.dateTime());
604 if (m_requestRole
[PermissionsRole
]) {
605 data
.insert("permissions", item
.permissionsString());
608 if (m_requestRole
[OwnerRole
]) {
609 data
.insert("owner", item
.user());
612 if (m_requestRole
[GroupRole
]) {
613 data
.insert("group", item
.group());
616 if (m_requestRole
[DestinationRole
]) {
617 QString destination
= item
.linkDest();
618 if (destination
.isEmpty()) {
619 destination
= i18nc("@item:intable", "No destination");
621 data
.insert("destination", destination
);
624 if (m_requestRole
[PathRole
]) {
625 data
.insert("path", item
.localPath());
628 if (m_requestRole
[IsExpandedRole
]) {
629 data
.insert("isExpanded", false);
632 if (m_requestRole
[ExpansionLevelRole
]) {
633 if (m_rootExpansionLevel
< 0) {
634 KDirLister
* dirLister
= m_dirLister
.data();
636 const QString rootDir
= dirLister
->url().directory(KUrl::AppendTrailingSlash
);
637 m_rootExpansionLevel
= rootDir
.count('/');
640 const QString dir
= item
.url().directory(KUrl::AppendTrailingSlash
);
641 const int level
= dir
.count('/') - m_rootExpansionLevel
- 1;
642 data
.insert("expansionLevel", level
);
645 if (item
.isMimeTypeKnown()) {
646 data
.insert("iconName", item
.iconName());
648 if (m_requestRole
[TypeRole
]) {
649 data
.insert("type", item
.mimeComment());
656 bool KFileItemModel::lessThan(const KFileItem
& a
, const KFileItem
& b
) const
660 if (m_rootExpansionLevel
>= 0) {
661 result
= expansionLevelsCompare(a
, b
);
663 // The items have parents with different expansion levels
668 if (m_sortFoldersFirst
) {
669 const bool isDirA
= a
.isDir();
670 const bool isDirB
= b
.isDir();
671 if (isDirA
&& !isDirB
) {
673 } else if (!isDirA
&& isDirB
) {
678 switch (m_sortRole
) {
680 result
= stringCompare(a
.text(), b
.text());
682 // KFileItem::text() may not be unique in case UDS_DISPLAY_NAME is used
683 result
= stringCompare(a
.name(m_caseSensitivity
== Qt::CaseInsensitive
),
684 b
.name(m_caseSensitivity
== Qt::CaseInsensitive
));
690 const KDateTime dateTimeA
= a
.time(KFileItem::ModificationTime
);
691 const KDateTime dateTimeB
= b
.time(KFileItem::ModificationTime
);
692 if (dateTimeA
< dateTimeB
) {
694 } else if (dateTimeA
> dateTimeB
) {
705 // It must be assured that the sort order is always unique even if two values have been
706 // equal. In this case a comparison of the URL is done which is unique in all cases
707 // within KDirLister.
708 result
= QString::compare(a
.url().url(), b
.url().url(), Qt::CaseSensitive
);
714 void KFileItemModel::sort(const KFileItemList::iterator
& startIterator
, const KFileItemList::iterator
& endIterator
)
716 KFileItemList::iterator start
= startIterator
;
717 KFileItemList::iterator end
= endIterator
;
719 // The implementation is based on qSortHelper() from qalgorithms.h
720 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
721 // In opposite to qSort() it allows to use a member-function for the comparison of elements.
723 int span
= int(end
- start
);
729 KFileItemList::iterator low
= start
, high
= end
- 1;
730 KFileItemList::iterator pivot
= start
+ span
/ 2;
732 if (lessThan(*end
, *start
)) {
739 if (lessThan(*pivot
, *start
)) {
740 qSwap(*pivot
, *start
);
742 if (lessThan(*end
, *pivot
)) {
752 while (low
< high
&& lessThan(*low
, *end
)) {
756 while (high
> low
&& lessThan(*end
, *high
)) {
768 if (lessThan(*low
, *end
)) {
780 int KFileItemModel::stringCompare(const QString
& a
, const QString
& b
) const
782 // Taken from KDirSortFilterProxyModel (kdelibs/kfile/kdirsortfilterproxymodel.*)
783 // Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>
784 // Copyright (C) 2006 by Dominic Battre <dominic@battre.de>
785 // Copyright (C) 2006 by Martin Pool <mbp@canonical.com>
787 if (m_caseSensitivity
== Qt::CaseInsensitive
) {
788 const int result
= m_naturalSorting
? KStringHandler::naturalCompare(a
, b
, Qt::CaseInsensitive
)
789 : QString::compare(a
, b
, Qt::CaseInsensitive
);
791 // Only return the result, if the strings are not equal. If they are equal by a case insensitive
792 // comparison, still a deterministic sort order is required. A case sensitive
793 // comparison is done as fallback.
798 return m_naturalSorting
? KStringHandler::naturalCompare(a
, b
, Qt::CaseSensitive
)
799 : QString::compare(a
, b
, Qt::CaseSensitive
);
802 int KFileItemModel::expansionLevelsCompare(const KFileItem
& a
, const KFileItem
& b
) const
804 const KUrl urlA
= a
.url();
805 const KUrl urlB
= b
.url();
806 if (urlA
.directory() == urlB
.directory()) {
807 // Both items have the same directory as parent
811 // Check whether one item is the parent of the other item
812 if (urlA
.isParentOf(urlB
)) {
814 } else if (urlB
.isParentOf(urlA
)) {
818 // Determine the maximum common path of both items and
819 // remember the index in 'index'
820 const QString pathA
= urlA
.path();
821 const QString pathB
= urlB
.path();
823 const int maxIndex
= qMin(pathA
.length(), pathB
.length()) - 1;
825 while (index
<= maxIndex
&& pathA
.at(index
) == pathB
.at(index
)) {
828 if (index
> maxIndex
) {
831 while (pathA
.at(index
) != QLatin1Char('/') && index
> 0) {
835 // Determine the first sub-path after the common path and
836 // check whether it represents a directory or already a file
838 const QString subPathA
= subPath(a
, pathA
, index
, &isDirA
);
840 const QString subPathB
= subPath(b
, pathB
, index
, &isDirB
);
842 if (isDirA
&& !isDirB
) {
844 } else if (!isDirA
&& isDirB
) {
848 return stringCompare(subPathA
, subPathB
);
851 QString
KFileItemModel::subPath(const KFileItem
& item
,
852 const QString
& itemPath
,
857 const int pathIndex
= itemPath
.indexOf('/', start
+ 1);
858 *isDir
= (pathIndex
> 0) || item
.isDir();
859 return itemPath
.mid(start
, pathIndex
- start
);
862 bool KFileItemModel::useMaximumUpdateInterval() const
864 const KDirLister
* dirLister
= m_dirLister
.data();
865 return dirLister
&& !dirLister
->url().isLocalFile();
868 #include "kfileitemmodel.moc"