]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemmodel.cpp
Fix sorting-issue when "Sort folders first" is disabled
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.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 "kfileitemmodel.h"
21
22 #include <KDirLister>
23 #include <KDirModel>
24 #include <KGlobalSettings>
25 #include <KLocale>
26 #include <KStringHandler>
27 #include <KDebug>
28
29 #include <QMimeData>
30 #include <QTimer>
31
32 // #define KFILEITEMMODEL_DEBUG
33
34 KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) :
35 KItemModelBase("name", parent),
36 m_dirLister(dirLister),
37 m_naturalSorting(KGlobalSettings::naturalSorting()),
38 m_sortFoldersFirst(true),
39 m_sortRole(NameRole),
40 m_roles(),
41 m_caseSensitivity(Qt::CaseInsensitive),
42 m_itemData(),
43 m_items(),
44 m_filter(),
45 m_filteredItems(),
46 m_requestRole(),
47 m_maximumUpdateIntervalTimer(0),
48 m_resortAllItemsTimer(0),
49 m_pendingItemsToInsert(),
50 m_groups(),
51 m_expandedParentsCountRoot(UninitializedExpandedParentsCountRoot),
52 m_expandedUrls(),
53 m_urlsToExpand()
54 {
55 // Apply default roles that should be determined
56 resetRoles();
57 m_requestRole[NameRole] = true;
58 m_requestRole[IsDirRole] = true;
59 m_roles.insert("name");
60 m_roles.insert("isDir");
61
62 Q_ASSERT(dirLister);
63
64 connect(dirLister, SIGNAL(canceled()), this, SLOT(slotCanceled()));
65 connect(dirLister, SIGNAL(completed(KUrl)), this, SLOT(slotCompleted()));
66 connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(slotNewItems(KFileItemList)));
67 connect(dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SLOT(slotItemsDeleted(KFileItemList)));
68 connect(dirLister, SIGNAL(refreshItems(QList<QPair<KFileItem,KFileItem> >)), this, SLOT(slotRefreshItems(QList<QPair<KFileItem,KFileItem> >)));
69 connect(dirLister, SIGNAL(clear()), this, SLOT(slotClear()));
70 connect(dirLister, SIGNAL(clear(KUrl)), this, SLOT(slotClear(KUrl)));
71
72 // For slow KIO-slaves like used for searching it makes sense to show results periodically even
73 // before the completed() or canceled() signal has been emitted.
74 m_maximumUpdateIntervalTimer = new QTimer(this);
75 m_maximumUpdateIntervalTimer->setInterval(2000);
76 m_maximumUpdateIntervalTimer->setSingleShot(true);
77 connect(m_maximumUpdateIntervalTimer, SIGNAL(timeout()), this, SLOT(dispatchPendingItemsToInsert()));
78
79 // When changing the value of an item which represents the sort-role a resorting must be
80 // triggered. Especially in combination with KFileItemModelRolesUpdater this might be done
81 // for a lot of items within a quite small timeslot. To prevent expensive resortings the
82 // resorting is postponed until the timer has been exceeded.
83 m_resortAllItemsTimer = new QTimer(this);
84 m_resortAllItemsTimer->setInterval(500);
85 m_resortAllItemsTimer->setSingleShot(true);
86 connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems()));
87
88 connect(KGlobalSettings::self(), SIGNAL(naturalSortingChanged()), this, SLOT(slotNaturalSortingChanged()));
89 }
90
91 KFileItemModel::~KFileItemModel()
92 {
93 qDeleteAll(m_itemData);
94 m_itemData.clear();
95 }
96
97 int KFileItemModel::count() const
98 {
99 return m_itemData.count();
100 }
101
102 QHash<QByteArray, QVariant> KFileItemModel::data(int index) const
103 {
104 if (index >= 0 && index < count()) {
105 return m_itemData.at(index)->values;
106 }
107 return QHash<QByteArray, QVariant>();
108 }
109
110 bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant>& values)
111 {
112 if (index < 0 || index >= count()) {
113 return false;
114 }
115
116 QHash<QByteArray, QVariant> currentValues = m_itemData.at(index)->values;
117
118 // Determine which roles have been changed
119 QSet<QByteArray> changedRoles;
120 QHashIterator<QByteArray, QVariant> it(values);
121 while (it.hasNext()) {
122 it.next();
123 const QByteArray role = it.key();
124 const QVariant value = it.value();
125
126 if (currentValues[role] != value) {
127 currentValues[role] = value;
128 changedRoles.insert(role);
129 }
130 }
131
132 if (changedRoles.isEmpty()) {
133 return false;
134 }
135
136 m_itemData[index]->values = currentValues;
137 emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
138
139 if (changedRoles.contains(sortRole())) {
140 m_resortAllItemsTimer->start();
141 }
142
143 return true;
144 }
145
146 void KFileItemModel::setSortFoldersFirst(bool foldersFirst)
147 {
148 if (foldersFirst != m_sortFoldersFirst) {
149 m_sortFoldersFirst = foldersFirst;
150 resortAllItems();
151 }
152 }
153
154 bool KFileItemModel::sortFoldersFirst() const
155 {
156 return m_sortFoldersFirst;
157 }
158
159 void KFileItemModel::setShowHiddenFiles(bool show)
160 {
161 KDirLister* dirLister = m_dirLister.data();
162 if (dirLister) {
163 dirLister->setShowingDotFiles(show);
164 dirLister->emitChanges();
165 if (show) {
166 slotCompleted();
167 }
168 }
169 }
170
171 bool KFileItemModel::showHiddenFiles() const
172 {
173 const KDirLister* dirLister = m_dirLister.data();
174 return dirLister ? dirLister->showingDotFiles() : false;
175 }
176
177 void KFileItemModel::setShowFoldersOnly(bool enabled)
178 {
179 KDirLister* dirLister = m_dirLister.data();
180 if (dirLister) {
181 dirLister->setDirOnlyMode(enabled);
182 }
183 }
184
185 bool KFileItemModel::showFoldersOnly() const
186 {
187 KDirLister* dirLister = m_dirLister.data();
188 return dirLister ? dirLister->dirOnlyMode() : false;
189 }
190
191 QMimeData* KFileItemModel::createMimeData(const QSet<int>& indexes) const
192 {
193 QMimeData* data = new QMimeData();
194
195 // The following code has been taken from KDirModel::mimeData()
196 // (kdelibs/kio/kio/kdirmodel.cpp)
197 // Copyright (C) 2006 David Faure <faure@kde.org>
198 KUrl::List urls;
199 KUrl::List mostLocalUrls;
200 bool canUseMostLocalUrls = true;
201
202 QSetIterator<int> it(indexes);
203 while (it.hasNext()) {
204 const int index = it.next();
205 const KFileItem item = fileItem(index);
206 if (!item.isNull()) {
207 urls << item.url();
208
209 bool isLocal;
210 mostLocalUrls << item.mostLocalUrl(isLocal);
211 if (!isLocal) {
212 canUseMostLocalUrls = false;
213 }
214 }
215 }
216
217 const bool different = canUseMostLocalUrls && mostLocalUrls != urls;
218 urls = KDirModel::simplifiedUrlList(urls); // TODO: Check if we still need KDirModel for this in KDE 5.0
219 if (different) {
220 mostLocalUrls = KDirModel::simplifiedUrlList(mostLocalUrls);
221 urls.populateMimeData(mostLocalUrls, data);
222 } else {
223 urls.populateMimeData(data);
224 }
225
226 return data;
227 }
228
229 int KFileItemModel::indexForKeyboardSearch(const QString& text, int startFromIndex) const
230 {
231 startFromIndex = qMax(0, startFromIndex);
232 for (int i = startFromIndex; i < count(); ++i) {
233 if (data(i)["name"].toString().startsWith(text, Qt::CaseInsensitive)) {
234 return i;
235 }
236 }
237 for (int i = 0; i < startFromIndex; ++i) {
238 if (data(i)["name"].toString().startsWith(text, Qt::CaseInsensitive)) {
239 return i;
240 }
241 }
242 return -1;
243 }
244
245 bool KFileItemModel::supportsDropping(int index) const
246 {
247 const KFileItem item = fileItem(index);
248 return !item.isNull() && (item.isDir() || item.isDesktopFile());
249 }
250
251 QString KFileItemModel::roleDescription(const QByteArray& role) const
252 {
253 static QHash<QByteArray, QString> description;
254 if (description.isEmpty()) {
255 int count = 0;
256 const RoleInfoMap* map = rolesInfoMap(count);
257 for (int i = 0; i < count; ++i) {
258 description.insert(map[i].role, map[i].roleTranslation);
259 }
260 }
261
262 return description.value(role);
263 }
264
265 QList<QPair<int, QVariant> > KFileItemModel::groups() const
266 {
267 if (!m_itemData.isEmpty() && m_groups.isEmpty()) {
268 #ifdef KFILEITEMMODEL_DEBUG
269 QElapsedTimer timer;
270 timer.start();
271 #endif
272 switch (typeForRole(sortRole())) {
273 case NameRole: m_groups = nameRoleGroups(); break;
274 case SizeRole: m_groups = sizeRoleGroups(); break;
275 case DateRole: m_groups = dateRoleGroups(); break;
276 case PermissionsRole: m_groups = permissionRoleGroups(); break;
277 case OwnerRole: m_groups = genericStringRoleGroups("owner"); break;
278 case GroupRole: m_groups = genericStringRoleGroups("group"); break;
279 case TypeRole: m_groups = genericStringRoleGroups("type"); break;
280 case DestinationRole: m_groups = genericStringRoleGroups("destination"); break;
281 case PathRole: m_groups = genericStringRoleGroups("path"); break;
282 case CommentRole: m_groups = genericStringRoleGroups("comment"); break;
283 case TagsRole: m_groups = genericStringRoleGroups("tags"); break;
284 case RatingRole: m_groups = ratingRoleGroups(); break;
285 case NoRole: break;
286 case IsDirRole: break;
287 case IsExpandedRole: break;
288 case ExpandedParentsCountRole: break;
289 default: Q_ASSERT(false); break;
290 }
291
292 #ifdef KFILEITEMMODEL_DEBUG
293 kDebug() << "[TIME] Calculating groups for" << count() << "items:" << timer.elapsed();
294 #endif
295 }
296
297 return m_groups;
298 }
299
300 KFileItem KFileItemModel::fileItem(int index) const
301 {
302 if (index >= 0 && index < count()) {
303 return m_itemData.at(index)->item;
304 }
305
306 return KFileItem();
307 }
308
309 KFileItem KFileItemModel::fileItem(const KUrl& url) const
310 {
311 const int index = m_items.value(url, -1);
312 if (index >= 0) {
313 return m_itemData.at(index)->item;
314 }
315 return KFileItem();
316 }
317
318 int KFileItemModel::index(const KFileItem& item) const
319 {
320 if (item.isNull()) {
321 return -1;
322 }
323
324 return m_items.value(item.url(), -1);
325 }
326
327 int KFileItemModel::index(const KUrl& url) const
328 {
329 KUrl urlToFind = url;
330 urlToFind.adjustPath(KUrl::RemoveTrailingSlash);
331 return m_items.value(urlToFind, -1);
332 }
333
334 KFileItem KFileItemModel::rootItem() const
335 {
336 const KDirLister* dirLister = m_dirLister.data();
337 if (dirLister) {
338 return dirLister->rootItem();
339 }
340 return KFileItem();
341 }
342
343 void KFileItemModel::clear()
344 {
345 slotClear();
346 }
347
348 void KFileItemModel::setRoles(const QSet<QByteArray>& roles)
349 {
350 if (m_roles == roles) {
351 return;
352 }
353 m_roles = roles;
354
355 if (count() > 0) {
356 const bool supportedExpanding = m_requestRole[ExpandedParentsCountRole];
357 const bool willSupportExpanding = roles.contains("expandedParentsCount");
358 if (supportedExpanding && !willSupportExpanding) {
359 // No expanding is supported anymore. Take care to delete all items that have an expansion level
360 // that is not 0 (and hence are part of an expanded item).
361 removeExpandedItems();
362 }
363 }
364
365 m_groups.clear();
366 resetRoles();
367
368 QSetIterator<QByteArray> it(roles);
369 while (it.hasNext()) {
370 const QByteArray& role = it.next();
371 m_requestRole[typeForRole(role)] = true;
372 }
373
374 if (count() > 0) {
375 // Update m_data with the changed requested roles
376 const int maxIndex = count() - 1;
377 for (int i = 0; i <= maxIndex; ++i) {
378 m_itemData[i]->values = retrieveData(m_itemData.at(i)->item);
379 }
380
381 kWarning() << "TODO: Emitting itemsChanged() with no information what has changed!";
382 emit itemsChanged(KItemRangeList() << KItemRange(0, count()), QSet<QByteArray>());
383 }
384 }
385
386 QSet<QByteArray> KFileItemModel::roles() const
387 {
388 return m_roles;
389 }
390
391 bool KFileItemModel::setExpanded(int index, bool expanded)
392 {
393 if (!isExpandable(index) || isExpanded(index) == expanded) {
394 return false;
395 }
396
397 QHash<QByteArray, QVariant> values;
398 values.insert("isExpanded", expanded);
399 if (!setData(index, values)) {
400 return false;
401 }
402
403 KDirLister* dirLister = m_dirLister.data();
404 const KUrl url = m_itemData.at(index)->item.url();
405 if (expanded) {
406 m_expandedUrls.insert(url);
407
408 if (dirLister) {
409 dirLister->openUrl(url, KDirLister::Keep);
410 return true;
411 }
412 } else {
413 m_expandedUrls.remove(url);
414
415 if (dirLister) {
416 dirLister->stop(url);
417 }
418
419 KFileItemList itemsToRemove;
420 const int expandedParentsCount = data(index)["expandedParentsCount"].toInt();
421 ++index;
422 while (index < count() && data(index)["expandedParentsCount"].toInt() > expandedParentsCount) {
423 itemsToRemove.append(m_itemData.at(index)->item);
424 ++index;
425 }
426 removeItems(itemsToRemove);
427 return true;
428 }
429
430 return false;
431 }
432
433 bool KFileItemModel::isExpanded(int index) const
434 {
435 if (index >= 0 && index < count()) {
436 return m_itemData.at(index)->values.value("isExpanded").toBool();
437 }
438 return false;
439 }
440
441 bool KFileItemModel::isExpandable(int index) const
442 {
443 if (index >= 0 && index < count()) {
444 return m_itemData.at(index)->values.value("isExpandable").toBool();
445 }
446 return false;
447 }
448
449 int KFileItemModel::expandedParentsCount(int index) const
450 {
451 if (index >= 0 && index < count()) {
452 const int parentsCount = m_itemData.at(index)->values.value("expandedParentsCount").toInt();
453 if (parentsCount > 0) {
454 return parentsCount;
455 }
456 }
457 return 0;
458 }
459
460 QSet<KUrl> KFileItemModel::expandedUrls() const
461 {
462 return m_expandedUrls;
463 }
464
465 void KFileItemModel::restoreExpandedUrls(const QSet<KUrl>& urls)
466 {
467 m_urlsToExpand = urls;
468 }
469
470 void KFileItemModel::expandParentItems(const KUrl& url)
471 {
472 const KDirLister* dirLister = m_dirLister.data();
473 if (!dirLister) {
474 return;
475 }
476
477 const int pos = dirLister->url().path().length();
478
479 // Assure that each sub-path of the URL that should be
480 // expanded is added to m_urlsToExpand. KDirLister
481 // does not care whether the parent-URL has already been
482 // expanded.
483 KUrl urlToExpand = dirLister->url();
484 const QStringList subDirs = url.path().mid(pos).split(QDir::separator());
485 for (int i = 0; i < subDirs.count() - 1; ++i) {
486 urlToExpand.addPath(subDirs.at(i));
487 m_urlsToExpand.insert(urlToExpand);
488 }
489
490 // KDirLister::open() must called at least once to trigger an initial
491 // loading. The pending URLs that must be restored are handled
492 // in slotCompleted().
493 QSetIterator<KUrl> it2(m_urlsToExpand);
494 while (it2.hasNext()) {
495 const int idx = index(it2.next());
496 if (idx >= 0 && !isExpanded(idx)) {
497 setExpanded(idx, true);
498 break;
499 }
500 }
501 }
502
503 void KFileItemModel::setNameFilter(const QString& nameFilter)
504 {
505 if (m_filter.pattern() != nameFilter) {
506 dispatchPendingItemsToInsert();
507
508 m_filter.setPattern(nameFilter);
509
510 // Check which shown items from m_itemData must get
511 // hidden and hence moved to m_filteredItems.
512 KFileItemList newFilteredItems;
513
514 foreach (ItemData* itemData, m_itemData) {
515 if (!m_filter.matches(itemData->item)) {
516 // Only filter non-expanded items as child items may never
517 // exist without a parent item
518 if (!itemData->values.value("isExpanded").toBool()) {
519 newFilteredItems.append(itemData->item);
520 m_filteredItems.insert(itemData->item);
521 }
522 }
523 }
524
525 removeItems(newFilteredItems);
526
527 // Check which hidden items from m_filteredItems should
528 // get visible again and hence removed from m_filteredItems.
529 KFileItemList newVisibleItems;
530
531 QMutableSetIterator<KFileItem> it(m_filteredItems);
532 while (it.hasNext()) {
533 const KFileItem item = it.next();
534 if (m_filter.matches(item)) {
535 newVisibleItems.append(item);
536 m_filteredItems.remove(item);
537 }
538 }
539
540 insertItems(newVisibleItems);
541 }
542 }
543
544 QString KFileItemModel::nameFilter() const
545 {
546 return m_filter.pattern();
547 }
548
549 QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation()
550 {
551 static QList<RoleInfo> rolesInfo;
552 if (rolesInfo.isEmpty()) {
553 int count = 0;
554 const RoleInfoMap* map = rolesInfoMap(count);
555 for (int i = 0; i < count; ++i) {
556 if (map[i].roleType != NoRole) {
557 RoleInfo info;
558 info.role = map[i].role;
559 info.translation = map[i].roleTranslation;
560 info.group = map[i].groupTranslation;
561 rolesInfo.append(info);
562 }
563 }
564 }
565
566 return rolesInfo;
567 }
568
569 void KFileItemModel::onGroupedSortingChanged(bool current)
570 {
571 Q_UNUSED(current);
572 m_groups.clear();
573 }
574
575 void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous)
576 {
577 Q_UNUSED(previous);
578 m_sortRole = typeForRole(current);
579
580 #ifdef KFILEITEMMODEL_DEBUG
581 if (!m_requestRole[m_sortRole]) {
582 kWarning() << "The sort-role has been changed to a role that has not been received yet";
583 }
584 #endif
585
586 resortAllItems();
587 }
588
589 void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
590 {
591 Q_UNUSED(current);
592 Q_UNUSED(previous);
593 resortAllItems();
594 }
595
596 void KFileItemModel::resortAllItems()
597 {
598 m_resortAllItemsTimer->stop();
599
600 const int itemCount = count();
601 if (itemCount <= 0) {
602 return;
603 }
604
605 #ifdef KFILEITEMMODEL_DEBUG
606 QElapsedTimer timer;
607 timer.start();
608 kDebug() << "===========================================================";
609 kDebug() << "Resorting" << itemCount << "items";
610 #endif
611
612 // Remember the order of the current URLs so
613 // that it can be determined which indexes have
614 // been moved because of the resorting.
615 QList<KUrl> oldUrls;
616 oldUrls.reserve(itemCount);
617 foreach (const ItemData* itemData, m_itemData) {
618 oldUrls.append(itemData->item.url());
619 }
620
621 m_groups.clear();
622 m_items.clear();
623
624 // Resort the items
625 sort(m_itemData.begin(), m_itemData.end());
626 for (int i = 0; i < itemCount; ++i) {
627 m_items.insert(m_itemData.at(i)->item.url(), i);
628 }
629
630 // Determine the indexes that have been moved
631 QList<int> movedToIndexes;
632 movedToIndexes.reserve(itemCount);
633 for (int i = 0; i < itemCount; i++) {
634 const int newIndex = m_items.value(oldUrls.at(i).url());
635 movedToIndexes.append(newIndex);
636 }
637
638 // Don't check whether items have really been moved and always emit a
639 // itemsMoved() signal after resorting: In case of grouped items
640 // the groups might change even if the items themselves don't change their
641 // position. Let the receiver of the signal decide whether a check for moved
642 // items makes sense.
643 emit itemsMoved(KItemRange(0, itemCount), movedToIndexes);
644
645 #ifdef KFILEITEMMODEL_DEBUG
646 kDebug() << "[TIME] Resorting of" << itemCount << "items:" << timer.elapsed();
647 #endif
648 }
649
650 void KFileItemModel::slotCompleted()
651 {
652 dispatchPendingItemsToInsert();
653
654 if (!m_urlsToExpand.isEmpty()) {
655 // Try to find a URL that can be expanded.
656 // Note that the parent folder must be expanded before any of its subfolders become visible.
657 // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
658 // -> we expand the first visible URL we find in m_restoredExpandedUrls.
659 foreach(const KUrl& url, m_urlsToExpand) {
660 const int index = m_items.value(url, -1);
661 if (index >= 0) {
662 m_urlsToExpand.remove(url);
663 if (setExpanded(index, true)) {
664 // The dir lister has been triggered. This slot will be called
665 // again after the directory has been expanded.
666 return;
667 }
668 }
669 }
670
671 // None of the URLs in m_restoredExpandedUrls could be found in the model. This can happen
672 // if these URLs have been deleted in the meantime.
673 m_urlsToExpand.clear();
674 }
675
676 emit loadingCompleted();
677 }
678
679 void KFileItemModel::slotCanceled()
680 {
681 m_maximumUpdateIntervalTimer->stop();
682 dispatchPendingItemsToInsert();
683 }
684
685 void KFileItemModel::slotNewItems(const KFileItemList& items)
686 {
687 Q_ASSERT(!items.isEmpty());
688
689 if (m_requestRole[ExpandedParentsCountRole] && m_expandedParentsCountRoot >= 0) {
690 // To be able to compare whether the new items may be inserted as children
691 // of a parent item the pending items must be added to the model first.
692 dispatchPendingItemsToInsert();
693
694 KFileItem item = items.first();
695
696 // If the expanding of items is enabled, the call
697 // dirLister->openUrl(url, KDirLister::Keep) in KFileItemModel::setExpanded()
698 // might result in emitting the same items twice due to the Keep-parameter.
699 // This case happens if an item gets expanded, collapsed and expanded again
700 // before the items could be loaded for the first expansion.
701 const int index = m_items.value(item.url(), -1);
702 if (index >= 0) {
703 // The items are already part of the model.
704 return;
705 }
706
707 // KDirLister keeps the children of items that got expanded once even if
708 // they got collapsed again with KFileItemModel::setExpanded(false). So it must be
709 // checked whether the parent for new items is still expanded.
710 KUrl parentUrl = item.url().upUrl();
711 parentUrl.adjustPath(KUrl::RemoveTrailingSlash);
712 const int parentIndex = m_items.value(parentUrl, -1);
713 if (parentIndex >= 0 && !m_itemData[parentIndex]->values.value("isExpanded").toBool()) {
714 // The parent is not expanded.
715 return;
716 }
717 }
718
719 if (m_filter.pattern().isEmpty()) {
720 m_pendingItemsToInsert.append(items);
721 } else {
722 // The name-filter is active. Hide filtered items
723 // before inserting them into the model and remember
724 // the filtered items in m_filteredItems.
725 KFileItemList filteredItems;
726 foreach (const KFileItem& item, items) {
727 if (m_filter.matches(item)) {
728 filteredItems.append(item);
729 } else {
730 m_filteredItems.insert(item);
731 }
732 }
733
734 m_pendingItemsToInsert.append(filteredItems);
735 }
736
737 if (useMaximumUpdateInterval() && !m_maximumUpdateIntervalTimer->isActive()) {
738 // Assure that items get dispatched if no completed() or canceled() signal is
739 // emitted during the maximum update interval.
740 m_maximumUpdateIntervalTimer->start();
741 }
742 }
743
744 void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
745 {
746 dispatchPendingItemsToInsert();
747
748 KFileItemList itemsToRemove = items;
749 if (m_requestRole[ExpandedParentsCountRole] && m_expandedParentsCountRoot >= 0) {
750 // Assure that removing a parent item also results in removing all children
751 foreach (const KFileItem& item, items) {
752 itemsToRemove.append(childItems(item));
753 }
754 }
755
756 if (!m_filteredItems.isEmpty()) {
757 foreach (const KFileItem& item, itemsToRemove) {
758 m_filteredItems.remove(item);
759 }
760 }
761
762 removeItems(itemsToRemove);
763 }
764
765 void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items)
766 {
767 Q_ASSERT(!items.isEmpty());
768 #ifdef KFILEITEMMODEL_DEBUG
769 kDebug() << "Refreshing" << items.count() << "items";
770 #endif
771
772 m_groups.clear();
773
774 // Get the indexes of all items that have been refreshed
775 QList<int> indexes;
776 indexes.reserve(items.count());
777
778 QListIterator<QPair<KFileItem, KFileItem> > it(items);
779 while (it.hasNext()) {
780 const QPair<KFileItem, KFileItem>& itemPair = it.next();
781 const KFileItem& oldItem = itemPair.first;
782 const KFileItem& newItem = itemPair.second;
783 const int index = m_items.value(oldItem.url(), -1);
784 if (index >= 0) {
785 m_itemData[index]->item = newItem;
786 m_itemData[index]->values = retrieveData(newItem);
787 m_items.remove(oldItem.url());
788 m_items.insert(newItem.url(), index);
789 indexes.append(index);
790 }
791 }
792
793 // If the changed items have been created recently, they might not be in m_items yet.
794 // In that case, the list 'indexes' might be empty.
795 if (indexes.isEmpty()) {
796 return;
797 }
798
799 // Extract the item-ranges out of the changed indexes
800 qSort(indexes);
801
802 KItemRangeList itemRangeList;
803 int previousIndex = indexes.at(0);
804 int rangeIndex = previousIndex;
805 int rangeCount = 1;
806
807 const int maxIndex = indexes.count() - 1;
808 for (int i = 1; i <= maxIndex; ++i) {
809 const int currentIndex = indexes.at(i);
810 if (currentIndex == previousIndex + 1) {
811 ++rangeCount;
812 } else {
813 itemRangeList.append(KItemRange(rangeIndex, rangeCount));
814
815 rangeIndex = currentIndex;
816 rangeCount = 1;
817 }
818 previousIndex = currentIndex;
819 }
820
821 if (rangeCount > 0) {
822 itemRangeList.append(KItemRange(rangeIndex, rangeCount));
823 }
824
825 emit itemsChanged(itemRangeList, m_roles);
826
827 resortAllItems();
828 }
829
830 void KFileItemModel::slotClear()
831 {
832 #ifdef KFILEITEMMODEL_DEBUG
833 kDebug() << "Clearing all items";
834 #endif
835
836 m_filteredItems.clear();
837 m_groups.clear();
838
839 m_maximumUpdateIntervalTimer->stop();
840 m_resortAllItemsTimer->stop();
841 m_pendingItemsToInsert.clear();
842
843 m_expandedParentsCountRoot = UninitializedExpandedParentsCountRoot;
844
845 const int removedCount = m_itemData.count();
846 if (removedCount > 0) {
847 qDeleteAll(m_itemData);
848 m_itemData.clear();
849 m_items.clear();
850 emit itemsRemoved(KItemRangeList() << KItemRange(0, removedCount));
851 }
852
853 m_expandedUrls.clear();
854 }
855
856 void KFileItemModel::slotClear(const KUrl& url)
857 {
858 Q_UNUSED(url);
859 }
860
861 void KFileItemModel::slotNaturalSortingChanged()
862 {
863 m_naturalSorting = KGlobalSettings::naturalSorting();
864 resortAllItems();
865 }
866
867 void KFileItemModel::dispatchPendingItemsToInsert()
868 {
869 if (!m_pendingItemsToInsert.isEmpty()) {
870 insertItems(m_pendingItemsToInsert);
871 m_pendingItemsToInsert.clear();
872 }
873 }
874
875 void KFileItemModel::insertItems(const KFileItemList& items)
876 {
877 if (items.isEmpty()) {
878 return;
879 }
880
881 #ifdef KFILEITEMMODEL_DEBUG
882 QElapsedTimer timer;
883 timer.start();
884 kDebug() << "===========================================================";
885 kDebug() << "Inserting" << items.count() << "items";
886 #endif
887
888 m_groups.clear();
889
890 QList<ItemData*> sortedItems = createItemDataList(items);
891 sort(sortedItems.begin(), sortedItems.end());
892
893 #ifdef KFILEITEMMODEL_DEBUG
894 kDebug() << "[TIME] Sorting:" << timer.elapsed();
895 #endif
896
897 KItemRangeList itemRanges;
898 int targetIndex = 0;
899 int sourceIndex = 0;
900 int insertedAtIndex = -1; // Index for the current item-range
901 int insertedCount = 0; // Count for the current item-range
902 int previouslyInsertedCount = 0; // Sum of previously inserted items for all ranges
903 while (sourceIndex < sortedItems.count()) {
904 // Find target index from m_items to insert the current item
905 // in a sorted order
906 const int previousTargetIndex = targetIndex;
907 while (targetIndex < m_itemData.count()) {
908 if (!lessThan(m_itemData.at(targetIndex), sortedItems.at(sourceIndex))) {
909 break;
910 }
911 ++targetIndex;
912 }
913
914 if (targetIndex - previousTargetIndex > 0 && insertedAtIndex >= 0) {
915 itemRanges << KItemRange(insertedAtIndex, insertedCount);
916 previouslyInsertedCount += insertedCount;
917 insertedAtIndex = targetIndex - previouslyInsertedCount;
918 insertedCount = 0;
919 }
920
921 // Insert item at the position targetIndex by transfering
922 // the ownership of the item-data from sortedItems to m_itemData.
923 // m_items will be inserted after the loop (see comment below)
924 m_itemData.insert(targetIndex, sortedItems.at(sourceIndex));
925 ++insertedCount;
926
927 if (insertedAtIndex < 0) {
928 insertedAtIndex = targetIndex;
929 Q_ASSERT(previouslyInsertedCount == 0);
930 }
931 ++targetIndex;
932 ++sourceIndex;
933 }
934
935 // The indexes of all m_items must be adjusted, not only the index
936 // of the new items
937 const int itemDataCount = m_itemData.count();
938 for (int i = 0; i < itemDataCount; ++i) {
939 m_items.insert(m_itemData.at(i)->item.url(), i);
940 }
941
942 itemRanges << KItemRange(insertedAtIndex, insertedCount);
943 emit itemsInserted(itemRanges);
944
945 #ifdef KFILEITEMMODEL_DEBUG
946 kDebug() << "[TIME] Inserting of" << items.count() << "items:" << timer.elapsed();
947 #endif
948 }
949
950 void KFileItemModel::removeItems(const KFileItemList& items)
951 {
952 if (items.isEmpty()) {
953 return;
954 }
955
956 #ifdef KFILEITEMMODEL_DEBUG
957 kDebug() << "Removing " << items.count() << "items";
958 #endif
959
960 m_groups.clear();
961
962 QList<ItemData*> sortedItems;
963 sortedItems.reserve(items.count());
964 foreach (const KFileItem& item, items) {
965 const int index = m_items.value(item.url(), -1);
966 if (index >= 0) {
967 sortedItems.append(m_itemData.at(index));
968 }
969 }
970 sort(sortedItems.begin(), sortedItems.end());
971
972 QList<int> indexesToRemove;
973 indexesToRemove.reserve(items.count());
974
975 // Calculate the item ranges that will get deleted
976 KItemRangeList itemRanges;
977 int removedAtIndex = -1;
978 int removedCount = 0;
979 int targetIndex = 0;
980 foreach (const ItemData* itemData, sortedItems) {
981 const KFileItem& itemToRemove = itemData->item;
982
983 const int previousTargetIndex = targetIndex;
984 while (targetIndex < m_itemData.count()) {
985 if (m_itemData.at(targetIndex)->item.url() == itemToRemove.url()) {
986 break;
987 }
988 ++targetIndex;
989 }
990 if (targetIndex >= m_itemData.count()) {
991 kWarning() << "Item that should be deleted has not been found!";
992 return;
993 }
994
995 if (targetIndex - previousTargetIndex > 0 && removedAtIndex >= 0) {
996 itemRanges << KItemRange(removedAtIndex, removedCount);
997 removedAtIndex = targetIndex;
998 removedCount = 0;
999 }
1000
1001 indexesToRemove.append(targetIndex);
1002 if (removedAtIndex < 0) {
1003 removedAtIndex = targetIndex;
1004 }
1005 ++removedCount;
1006 ++targetIndex;
1007 }
1008
1009 // Delete the items
1010 for (int i = indexesToRemove.count() - 1; i >= 0; --i) {
1011 const int indexToRemove = indexesToRemove.at(i);
1012 ItemData* data = m_itemData.at(indexToRemove);
1013
1014 m_items.remove(data->item.url());
1015
1016 delete data;
1017 m_itemData.removeAt(indexToRemove);
1018 }
1019
1020 // The indexes of all m_items must be adjusted, not only the index
1021 // of the removed items
1022 const int itemDataCount = m_itemData.count();
1023 for (int i = 0; i < itemDataCount; ++i) {
1024 m_items.insert(m_itemData.at(i)->item.url(), i);
1025 }
1026
1027 if (count() <= 0) {
1028 m_expandedParentsCountRoot = UninitializedExpandedParentsCountRoot;
1029 }
1030
1031 itemRanges << KItemRange(removedAtIndex, removedCount);
1032 emit itemsRemoved(itemRanges);
1033 }
1034
1035 QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const KFileItemList& items) const
1036 {
1037 QList<ItemData*> itemDataList;
1038 itemDataList.reserve(items.count());
1039
1040 foreach (const KFileItem& item, items) {
1041 ItemData* itemData = new ItemData();
1042 itemData->item = item;
1043 itemData->values = retrieveData(item);
1044 itemData->parent = 0;
1045
1046 const bool determineParent = m_requestRole[ExpandedParentsCountRole]
1047 && itemData->values["expandedParentsCount"].toInt() > 0;
1048 if (determineParent) {
1049 KUrl parentUrl = item.url().upUrl();
1050 parentUrl.adjustPath(KUrl::RemoveTrailingSlash);
1051 const int parentIndex = m_items.value(parentUrl, -1);
1052 if (parentIndex >= 0) {
1053 itemData->parent = m_itemData.at(parentIndex);
1054 } else {
1055 kWarning() << "Parent item not found for" << item.url();
1056 }
1057 }
1058
1059 itemDataList.append(itemData);
1060 }
1061
1062 return itemDataList;
1063 }
1064
1065 void KFileItemModel::removeExpandedItems()
1066 {
1067 KFileItemList expandedItems;
1068
1069 const int maxIndex = m_itemData.count() - 1;
1070 for (int i = 0; i <= maxIndex; ++i) {
1071 const ItemData* itemData = m_itemData.at(i);
1072 if (itemData->values.value("expandedParentsCount").toInt() > 0) {
1073 expandedItems.append(itemData->item);
1074 }
1075 }
1076
1077 // The m_expandedParentsCountRoot may not get reset before all items with
1078 // a bigger count have been removed.
1079 Q_ASSERT(m_expandedParentsCountRoot >= 0);
1080 removeItems(expandedItems);
1081
1082 m_expandedParentsCountRoot = UninitializedExpandedParentsCountRoot;
1083 m_expandedUrls.clear();
1084 }
1085
1086 void KFileItemModel::resetRoles()
1087 {
1088 for (int i = 0; i < RolesCount; ++i) {
1089 m_requestRole[i] = false;
1090 }
1091 }
1092
1093 KFileItemModel::RoleType KFileItemModel::typeForRole(const QByteArray& role) const
1094 {
1095 static QHash<QByteArray, RoleType> roles;
1096 if (roles.isEmpty()) {
1097 // Insert user visible roles that can be accessed with
1098 // KFileItemModel::roleInformation()
1099 int count = 0;
1100 const RoleInfoMap* map = rolesInfoMap(count);
1101 for (int i = 0; i < count; ++i) {
1102 roles.insert(map[i].role, map[i].roleType);
1103 }
1104
1105 // Insert internal roles (take care to synchronize the implementation
1106 // with KFileItemModel::roleForType() in case if a change is done).
1107 roles.insert("isDir", IsDirRole);
1108 roles.insert("isExpanded", IsExpandedRole);
1109 roles.insert("isExpandable", IsExpandableRole);
1110 roles.insert("expandedParentsCount", ExpandedParentsCountRole);
1111
1112 Q_ASSERT(roles.count() == RolesCount);
1113 }
1114
1115 return roles.value(role, NoRole);
1116 }
1117
1118 QByteArray KFileItemModel::roleForType(RoleType roleType) const
1119 {
1120 static QHash<RoleType, QByteArray> roles;
1121 if (roles.isEmpty()) {
1122 // Insert user visible roles that can be accessed with
1123 // KFileItemModel::roleInformation()
1124 int count = 0;
1125 const RoleInfoMap* map = rolesInfoMap(count);
1126 for (int i = 0; i < count; ++i) {
1127 roles.insert(map[i].roleType, map[i].role);
1128 }
1129
1130 // Insert internal roles (take care to synchronize the implementation
1131 // with KFileItemModel::typeForRole() in case if a change is done).
1132 roles.insert(IsDirRole, "isDir");
1133 roles.insert(IsExpandedRole, "isExpanded");
1134 roles.insert(IsExpandableRole, "isExpandable");
1135 roles.insert(ExpandedParentsCountRole, "expandedParentsCount");
1136
1137 Q_ASSERT(roles.count() == RolesCount);
1138 };
1139
1140 return roles.value(roleType);
1141 }
1142
1143 QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item) const
1144 {
1145 // It is important to insert only roles that are fast to retrieve. E.g.
1146 // KFileItem::iconName() can be very expensive if the MIME-type is unknown
1147 // and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
1148 QHash<QByteArray, QVariant> data;
1149 data.insert("iconPixmap", QPixmap());
1150 data.insert("url", item.url());
1151
1152 const bool isDir = item.isDir();
1153 if (m_requestRole[IsDirRole]) {
1154 data.insert("isDir", isDir);
1155 }
1156
1157 if (m_requestRole[NameRole]) {
1158 data.insert("name", item.text());
1159 }
1160
1161 if (m_requestRole[SizeRole]) {
1162 if (isDir) {
1163 data.insert("size", QVariant());
1164 } else {
1165 data.insert("size", item.size());
1166 }
1167 }
1168
1169 if (m_requestRole[DateRole]) {
1170 // Don't use KFileItem::timeString() as this is too expensive when
1171 // having several thousands of items. Instead the formatting of the
1172 // date-time will be done on-demand by the view when the date will be shown.
1173 const KDateTime dateTime = item.time(KFileItem::ModificationTime);
1174 data.insert("date", dateTime.dateTime());
1175 }
1176
1177 if (m_requestRole[PermissionsRole]) {
1178 data.insert("permissions", item.permissionsString());
1179 }
1180
1181 if (m_requestRole[OwnerRole]) {
1182 data.insert("owner", item.user());
1183 }
1184
1185 if (m_requestRole[GroupRole]) {
1186 data.insert("group", item.group());
1187 }
1188
1189 if (m_requestRole[DestinationRole]) {
1190 QString destination = item.linkDest();
1191 if (destination.isEmpty()) {
1192 destination = i18nc("@item:intable", "No destination");
1193 }
1194 data.insert("destination", destination);
1195 }
1196
1197 if (m_requestRole[PathRole]) {
1198 QString path;
1199 if (item.url().protocol() == QLatin1String("trash")) {
1200 path = item.entry().stringValue(KIO::UDSEntry::UDS_EXTRA);
1201 } else {
1202 path = item.localPath();
1203 }
1204
1205 const int index = path.lastIndexOf(item.text());
1206 path = path.mid(0, index - 1);
1207 data.insert("path", path);
1208 }
1209
1210 if (m_requestRole[IsExpandedRole]) {
1211 data.insert("isExpanded", false);
1212 }
1213
1214 if (m_requestRole[IsExpandableRole]) {
1215 data.insert("isExpandable", item.isDir() && item.url() == item.targetUrl());
1216 }
1217
1218 if (m_requestRole[ExpandedParentsCountRole]) {
1219 if (m_expandedParentsCountRoot == UninitializedExpandedParentsCountRoot && m_dirLister.data()) {
1220 const KUrl rootUrl = m_dirLister.data()->url();
1221 const QString protocol = rootUrl.protocol();
1222 const bool forceExpandedParentsCountRoot = (protocol == QLatin1String("trash") ||
1223 protocol == QLatin1String("nepomuk") ||
1224 protocol == QLatin1String("remote") ||
1225 protocol.contains(QLatin1String("search")));
1226 if (forceExpandedParentsCountRoot) {
1227 m_expandedParentsCountRoot = ForceExpandedParentsCountRoot;
1228 } else {
1229 const QString rootDir = rootUrl.path(KUrl::AddTrailingSlash);
1230 m_expandedParentsCountRoot = rootDir.count('/');
1231 }
1232 }
1233
1234 if (m_expandedParentsCountRoot == ForceExpandedParentsCountRoot) {
1235 data.insert("expandedParentsCount", -1);
1236 } else {
1237 const QString dir = item.url().directory(KUrl::AppendTrailingSlash);
1238 const int level = dir.count('/') - m_expandedParentsCountRoot;
1239 data.insert("expandedParentsCount", level);
1240 }
1241 }
1242
1243 if (item.isMimeTypeKnown()) {
1244 data.insert("iconName", item.iconName());
1245
1246 if (m_requestRole[TypeRole]) {
1247 data.insert("type", item.mimeComment());
1248 }
1249 }
1250
1251 return data;
1252 }
1253
1254 bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b) const
1255 {
1256 int result = 0;
1257
1258 if (m_expandedParentsCountRoot >= 0) {
1259 result = expandedParentsCountCompare(a, b);
1260 if (result != 0) {
1261 // The items have parents with different expansion levels
1262 return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
1263 }
1264 }
1265
1266 if (m_sortFoldersFirst || m_sortRole == SizeRole) {
1267 const bool isDirA = a->item.isDir();
1268 const bool isDirB = b->item.isDir();
1269 if (isDirA && !isDirB) {
1270 return true;
1271 } else if (!isDirA && isDirB) {
1272 return false;
1273 }
1274 }
1275
1276 result = sortRoleCompare(a, b);
1277
1278 return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
1279 }
1280
1281 int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
1282 {
1283 const KFileItem& itemA = a->item;
1284 const KFileItem& itemB = b->item;
1285
1286 int result = 0;
1287
1288 switch (m_sortRole) {
1289 case NameRole:
1290 // The name role is handled as default fallback after the switch
1291 break;
1292
1293 case SizeRole: {
1294 if (itemA.isDir()) {
1295 // See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
1296 Q_ASSERT(itemB.isDir());
1297
1298 const QVariant valueA = a->values.value("size");
1299 const QVariant valueB = b->values.value("size");
1300 if (valueA.isNull() && valueB.isNull()) {
1301 result = 0;
1302 } else if (valueA.isNull()) {
1303 result = -1;
1304 } else if (valueB.isNull()) {
1305 result = +1;
1306 } else {
1307 result = valueA.toInt() - valueB.toInt();
1308 }
1309 } else {
1310 // See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
1311 Q_ASSERT(!itemB.isDir());
1312 const KIO::filesize_t sizeA = itemA.size();
1313 const KIO::filesize_t sizeB = itemB.size();
1314 if (sizeA > sizeB) {
1315 result = +1;
1316 } else if (sizeA < sizeB) {
1317 result = -1;
1318 } else {
1319 result = 0;
1320 }
1321 }
1322 break;
1323 }
1324
1325 case DateRole: {
1326 const KDateTime dateTimeA = itemA.time(KFileItem::ModificationTime);
1327 const KDateTime dateTimeB = itemB.time(KFileItem::ModificationTime);
1328 if (dateTimeA < dateTimeB) {
1329 result = -1;
1330 } else if (dateTimeA > dateTimeB) {
1331 result = +1;
1332 }
1333 break;
1334 }
1335
1336 case RatingRole: {
1337 result = a->values.value("rating").toInt() - b->values.value("rating").toInt();
1338 break;
1339 }
1340
1341 case PermissionsRole:
1342 case OwnerRole:
1343 case GroupRole:
1344 case TypeRole:
1345 case DestinationRole:
1346 case PathRole:
1347 case CommentRole:
1348 case TagsRole: {
1349 const QByteArray role = roleForType(m_sortRole);
1350 result = QString::compare(a->values.value(role).toString(),
1351 b->values.value(role).toString());
1352 break;
1353 }
1354
1355 default:
1356 break;
1357 }
1358
1359 if (result != 0) {
1360 // The current sort role was sufficient to define an order
1361 return result;
1362 }
1363
1364 // Fallback #1: Compare the text of the items
1365 result = stringCompare(itemA.text(), itemB.text());
1366 if (result != 0) {
1367 return result;
1368 }
1369
1370 // Fallback #2: KFileItem::text() may not be unique in case UDS_DISPLAY_NAME is used
1371 result = stringCompare(itemA.name(m_caseSensitivity == Qt::CaseInsensitive),
1372 itemB.name(m_caseSensitivity == Qt::CaseInsensitive));
1373 if (result != 0) {
1374 return result;
1375 }
1376
1377 // Fallback #3: It must be assured that the sort order is always unique even if two values have been
1378 // equal. In this case a comparison of the URL is done which is unique in all cases
1379 // within KDirLister.
1380 return QString::compare(itemA.url().url(), itemB.url().url(), Qt::CaseSensitive);
1381 }
1382
1383 void KFileItemModel::sort(QList<ItemData*>::iterator begin,
1384 QList<ItemData*>::iterator end)
1385 {
1386 // The implementation is based on qStableSortHelper() from qalgorithms.h
1387 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
1388 // In opposite to qStableSort() it allows to use a member-function for the comparison of elements.
1389
1390 const int span = end - begin;
1391 if (span < 2) {
1392 return;
1393 }
1394
1395 const QList<ItemData*>::iterator middle = begin + span / 2;
1396 sort(begin, middle);
1397 sort(middle, end);
1398 merge(begin, middle, end);
1399 }
1400
1401 void KFileItemModel::merge(QList<ItemData*>::iterator begin,
1402 QList<ItemData*>::iterator pivot,
1403 QList<ItemData*>::iterator end)
1404 {
1405 // The implementation is based on qMerge() from qalgorithms.h
1406 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
1407
1408 const int len1 = pivot - begin;
1409 const int len2 = end - pivot;
1410
1411 if (len1 == 0 || len2 == 0) {
1412 return;
1413 }
1414
1415 if (len1 + len2 == 2) {
1416 if (lessThan(*(begin + 1), *(begin))) {
1417 qSwap(*begin, *(begin + 1));
1418 }
1419 return;
1420 }
1421
1422 QList<ItemData*>::iterator firstCut;
1423 QList<ItemData*>::iterator secondCut;
1424 int len2Half;
1425 if (len1 > len2) {
1426 const int len1Half = len1 / 2;
1427 firstCut = begin + len1Half;
1428 secondCut = lowerBound(pivot, end, *firstCut);
1429 len2Half = secondCut - pivot;
1430 } else {
1431 len2Half = len2 / 2;
1432 secondCut = pivot + len2Half;
1433 firstCut = upperBound(begin, pivot, *secondCut);
1434 }
1435
1436 reverse(firstCut, pivot);
1437 reverse(pivot, secondCut);
1438 reverse(firstCut, secondCut);
1439
1440 const QList<ItemData*>::iterator newPivot = firstCut + len2Half;
1441 merge(begin, firstCut, newPivot);
1442 merge(newPivot, secondCut, end);
1443 }
1444
1445 QList<KFileItemModel::ItemData*>::iterator KFileItemModel::lowerBound(QList<ItemData*>::iterator begin,
1446 QList<ItemData*>::iterator end,
1447 const ItemData* value)
1448 {
1449 // The implementation is based on qLowerBound() from qalgorithms.h
1450 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
1451
1452 QList<ItemData*>::iterator middle;
1453 int n = int(end - begin);
1454 int half;
1455
1456 while (n > 0) {
1457 half = n >> 1;
1458 middle = begin + half;
1459 if (lessThan(*middle, value)) {
1460 begin = middle + 1;
1461 n -= half + 1;
1462 } else {
1463 n = half;
1464 }
1465 }
1466 return begin;
1467 }
1468
1469 QList<KFileItemModel::ItemData*>::iterator KFileItemModel::upperBound(QList<ItemData*>::iterator begin,
1470 QList<ItemData*>::iterator end,
1471 const ItemData* value)
1472 {
1473 // The implementation is based on qUpperBound() from qalgorithms.h
1474 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
1475
1476 QList<ItemData*>::iterator middle;
1477 int n = end - begin;
1478 int half;
1479
1480 while (n > 0) {
1481 half = n >> 1;
1482 middle = begin + half;
1483 if (lessThan(value, *middle)) {
1484 n = half;
1485 } else {
1486 begin = middle + 1;
1487 n -= half + 1;
1488 }
1489 }
1490 return begin;
1491 }
1492
1493 void KFileItemModel::reverse(QList<ItemData*>::iterator begin,
1494 QList<ItemData*>::iterator end)
1495 {
1496 // The implementation is based on qReverse() from qalgorithms.h
1497 // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
1498
1499 --end;
1500 while (begin < end) {
1501 qSwap(*begin++, *end--);
1502 }
1503 }
1504
1505 int KFileItemModel::stringCompare(const QString& a, const QString& b) const
1506 {
1507 // Taken from KDirSortFilterProxyModel (kdelibs/kfile/kdirsortfilterproxymodel.*)
1508 // Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>
1509 // Copyright (C) 2006 by Dominic Battre <dominic@battre.de>
1510 // Copyright (C) 2006 by Martin Pool <mbp@canonical.com>
1511
1512 if (m_caseSensitivity == Qt::CaseInsensitive) {
1513 const int result = m_naturalSorting ? KStringHandler::naturalCompare(a, b, Qt::CaseInsensitive)
1514 : QString::compare(a, b, Qt::CaseInsensitive);
1515 if (result != 0) {
1516 // Only return the result, if the strings are not equal. If they are equal by a case insensitive
1517 // comparison, still a deterministic sort order is required. A case sensitive
1518 // comparison is done as fallback.
1519 return result;
1520 }
1521 }
1522
1523 return m_naturalSorting ? KStringHandler::naturalCompare(a, b, Qt::CaseSensitive)
1524 : QString::compare(a, b, Qt::CaseSensitive);
1525 }
1526
1527 int KFileItemModel::expandedParentsCountCompare(const ItemData* a, const ItemData* b) const
1528 {
1529 const KUrl urlA = a->item.url();
1530 const KUrl urlB = b->item.url();
1531 if (urlA.directory() == urlB.directory()) {
1532 // Both items have the same directory as parent
1533 return 0;
1534 }
1535
1536 // Check whether one item is the parent of the other item
1537 if (urlA.isParentOf(urlB)) {
1538 return (sortOrder() == Qt::AscendingOrder) ? -1 : +1;
1539 } else if (urlB.isParentOf(urlA)) {
1540 return (sortOrder() == Qt::AscendingOrder) ? +1 : -1;
1541 }
1542
1543 // Determine the maximum common path of both items and
1544 // remember the index in 'index'
1545 const QString pathA = urlA.path();
1546 const QString pathB = urlB.path();
1547
1548 const int maxIndex = qMin(pathA.length(), pathB.length()) - 1;
1549 int index = 0;
1550 while (index <= maxIndex && pathA.at(index) == pathB.at(index)) {
1551 ++index;
1552 }
1553 if (index > maxIndex) {
1554 index = maxIndex;
1555 }
1556 while ((pathA.at(index) != QLatin1Char('/') || pathB.at(index) != QLatin1Char('/')) && index > 0) {
1557 --index;
1558 }
1559
1560 // Determine the first sub-path after the common path and
1561 // check whether it represents a directory or already a file
1562 bool isDirA = true;
1563 const QString subPathA = subPath(a->item, pathA, index, &isDirA);
1564 bool isDirB = true;
1565 const QString subPathB = subPath(b->item, pathB, index, &isDirB);
1566
1567 if (m_sortFoldersFirst || m_sortRole == SizeRole) {
1568 if (isDirA && !isDirB) {
1569 return (sortOrder() == Qt::AscendingOrder) ? -1 : +1;
1570 } else if (!isDirA && isDirB) {
1571 return (sortOrder() == Qt::AscendingOrder) ? +1 : -1;
1572 }
1573 }
1574
1575 // Compare the items of the parents that represent the first
1576 // different path after the common path.
1577 const QString parentPathA = pathA.left(index) + subPathA;
1578 const QString parentPathB = pathB.left(index) + subPathB;
1579
1580 const ItemData* parentA = a;
1581 while (parentA && parentA->item.url().path() != parentPathA) {
1582 parentA = parentA->parent;
1583 }
1584
1585 const ItemData* parentB = b;
1586 while (parentB && parentB->item.url().path() != parentPathB) {
1587 parentB = parentB->parent;
1588 }
1589
1590 if (parentA && parentB) {
1591 return sortRoleCompare(parentA, parentB);
1592 }
1593
1594 kWarning() << "Child items without parent detected:" << a->item.url() << b->item.url();
1595 return QString::compare(urlA.url(), urlB.url(), Qt::CaseSensitive);
1596 }
1597
1598 QString KFileItemModel::subPath(const KFileItem& item,
1599 const QString& itemPath,
1600 int start,
1601 bool* isDir) const
1602 {
1603 Q_ASSERT(isDir);
1604 const int pathIndex = itemPath.indexOf('/', start + 1);
1605 *isDir = (pathIndex > 0) || item.isDir();
1606 return itemPath.mid(start, pathIndex - start);
1607 }
1608
1609 bool KFileItemModel::useMaximumUpdateInterval() const
1610 {
1611 const KDirLister* dirLister = m_dirLister.data();
1612 return dirLister && !dirLister->url().isLocalFile();
1613 }
1614
1615 QList<QPair<int, QVariant> > KFileItemModel::nameRoleGroups() const
1616 {
1617 Q_ASSERT(!m_itemData.isEmpty());
1618
1619 const int maxIndex = count() - 1;
1620 QList<QPair<int, QVariant> > groups;
1621
1622 QString groupValue;
1623 QChar firstChar;
1624 bool isLetter = false;
1625 for (int i = 0; i <= maxIndex; ++i) {
1626 if (isChildItem(i)) {
1627 continue;
1628 }
1629
1630 const QString name = m_itemData.at(i)->values.value("name").toString();
1631
1632 // Use the first character of the name as group indication
1633 QChar newFirstChar = name.at(0).toUpper();
1634 if (newFirstChar == QLatin1Char('~') && name.length() > 1) {
1635 newFirstChar = name.at(1).toUpper();
1636 }
1637
1638 if (firstChar != newFirstChar) {
1639 QString newGroupValue;
1640 if (newFirstChar >= QLatin1Char('A') && newFirstChar <= QLatin1Char('Z')) {
1641 // Apply group 'A' - 'Z'
1642 newGroupValue = newFirstChar;
1643 isLetter = true;
1644 } else if (newFirstChar >= QLatin1Char('0') && newFirstChar <= QLatin1Char('9')) {
1645 // Apply group '0 - 9' for any name that starts with a digit
1646 newGroupValue = i18nc("@title:group Groups that start with a digit", "0 - 9");
1647 isLetter = false;
1648 } else {
1649 if (isLetter) {
1650 // If the current group is 'A' - 'Z' check whether a locale character
1651 // fits into the existing group.
1652 // TODO: This does not work in the case if e.g. the group 'O' starts with
1653 // an umlaut 'O' -> provide unit-test to document this known issue
1654 const QChar prevChar(firstChar.unicode() - ushort(1));
1655 const QChar nextChar(firstChar.unicode() + ushort(1));
1656 const QString currChar(newFirstChar);
1657 const bool partOfCurrentGroup = currChar.localeAwareCompare(prevChar) > 0 &&
1658 currChar.localeAwareCompare(nextChar) < 0;
1659 if (partOfCurrentGroup) {
1660 continue;
1661 }
1662 }
1663 newGroupValue = i18nc("@title:group", "Others");
1664 isLetter = false;
1665 }
1666
1667 if (newGroupValue != groupValue) {
1668 groupValue = newGroupValue;
1669 groups.append(QPair<int, QVariant>(i, newGroupValue));
1670 }
1671
1672 firstChar = newFirstChar;
1673 }
1674 }
1675 return groups;
1676 }
1677
1678 QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const
1679 {
1680 Q_ASSERT(!m_itemData.isEmpty());
1681
1682 const int maxIndex = count() - 1;
1683 QList<QPair<int, QVariant> > groups;
1684
1685 QString groupValue;
1686 for (int i = 0; i <= maxIndex; ++i) {
1687 if (isChildItem(i)) {
1688 continue;
1689 }
1690
1691 const KFileItem& item = m_itemData.at(i)->item;
1692 const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U;
1693 QString newGroupValue;
1694 if (!item.isNull() && item.isDir()) {
1695 newGroupValue = i18nc("@title:group Size", "Folders");
1696 } else if (fileSize < 5 * 1024 * 1024) {
1697 newGroupValue = i18nc("@title:group Size", "Small");
1698 } else if (fileSize < 10 * 1024 * 1024) {
1699 newGroupValue = i18nc("@title:group Size", "Medium");
1700 } else {
1701 newGroupValue = i18nc("@title:group Size", "Big");
1702 }
1703
1704 if (newGroupValue != groupValue) {
1705 groupValue = newGroupValue;
1706 groups.append(QPair<int, QVariant>(i, newGroupValue));
1707 }
1708 }
1709
1710 return groups;
1711 }
1712
1713 QList<QPair<int, QVariant> > KFileItemModel::dateRoleGroups() const
1714 {
1715 Q_ASSERT(!m_itemData.isEmpty());
1716
1717 const int maxIndex = count() - 1;
1718 QList<QPair<int, QVariant> > groups;
1719
1720 const QDate currentDate = KDateTime::currentLocalDateTime().date();
1721
1722 int yearForCurrentWeek = 0;
1723 int currentWeek = currentDate.weekNumber(&yearForCurrentWeek);
1724 if (yearForCurrentWeek == currentDate.year() + 1) {
1725 currentWeek = 53;
1726 }
1727
1728 QDate previousModifiedDate;
1729 QString groupValue;
1730 for (int i = 0; i <= maxIndex; ++i) {
1731 if (isChildItem(i)) {
1732 continue;
1733 }
1734
1735 const KDateTime modifiedTime = m_itemData.at(i)->item.time(KFileItem::ModificationTime);
1736 const QDate modifiedDate = modifiedTime.date();
1737 if (modifiedDate == previousModifiedDate) {
1738 // The current item is in the same group as the previous item
1739 continue;
1740 }
1741 previousModifiedDate = modifiedDate;
1742
1743 const int daysDistance = modifiedDate.daysTo(currentDate);
1744
1745 int yearForModifiedWeek = 0;
1746 int modifiedWeek = modifiedDate.weekNumber(&yearForModifiedWeek);
1747 if (yearForModifiedWeek == modifiedDate.year() + 1) {
1748 modifiedWeek = 53;
1749 }
1750
1751 QString newGroupValue;
1752 if (currentDate.year() == modifiedDate.year() && currentDate.month() == modifiedDate.month()) {
1753 if (modifiedWeek > currentWeek) {
1754 // Usecase: modified date = 2010-01-01, current date = 2010-01-22
1755 // modified week = 53, current week = 3
1756 modifiedWeek = 0;
1757 }
1758 switch (currentWeek - modifiedWeek) {
1759 case 0:
1760 switch (daysDistance) {
1761 case 0: newGroupValue = i18nc("@title:group Date", "Today"); break;
1762 case 1: newGroupValue = i18nc("@title:group Date", "Yesterday"); break;
1763 default: newGroupValue = modifiedTime.toString(i18nc("@title:group The week day name: %A", "%A"));
1764 }
1765 break;
1766 case 1:
1767 newGroupValue = i18nc("@title:group Date", "Last Week");
1768 break;
1769 case 2:
1770 newGroupValue = i18nc("@title:group Date", "Two Weeks Ago");
1771 break;
1772 case 3:
1773 newGroupValue = i18nc("@title:group Date", "Three Weeks Ago");
1774 break;
1775 case 4:
1776 case 5:
1777 newGroupValue = i18nc("@title:group Date", "Earlier this Month");
1778 break;
1779 default:
1780 Q_ASSERT(false);
1781 }
1782 } else {
1783 const QDate lastMonthDate = currentDate.addMonths(-1);
1784 if (lastMonthDate.year() == modifiedDate.year() && lastMonthDate.month() == modifiedDate.month()) {
1785 if (daysDistance == 1) {
1786 newGroupValue = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Yesterday (%B, %Y)"));
1787 } else if (daysDistance <= 7) {
1788 newGroupValue = modifiedTime.toString(i18nc("@title:group The week day name: %A, %B is full month name in current locale, and %Y is full year number", "%A (%B, %Y)"));
1789 } else if (daysDistance <= 7 * 2) {
1790 newGroupValue = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Last Week (%B, %Y)"));
1791 } else if (daysDistance <= 7 * 3) {
1792 newGroupValue = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Two Weeks Ago (%B, %Y)"));
1793 } else if (daysDistance <= 7 * 4) {
1794 newGroupValue = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Three Weeks Ago (%B, %Y)"));
1795 } else {
1796 newGroupValue = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Earlier on %B, %Y"));
1797 }
1798 } else {
1799 newGroupValue = modifiedTime.toString(i18nc("@title:group The month and year: %B is full month name in current locale, and %Y is full year number", "%B, %Y"));
1800 }
1801 }
1802
1803 if (newGroupValue != groupValue) {
1804 groupValue = newGroupValue;
1805 groups.append(QPair<int, QVariant>(i, newGroupValue));
1806 }
1807 }
1808
1809 return groups;
1810 }
1811
1812 QList<QPair<int, QVariant> > KFileItemModel::permissionRoleGroups() const
1813 {
1814 Q_ASSERT(!m_itemData.isEmpty());
1815
1816 const int maxIndex = count() - 1;
1817 QList<QPair<int, QVariant> > groups;
1818
1819 QString permissionsString;
1820 QString groupValue;
1821 for (int i = 0; i <= maxIndex; ++i) {
1822 if (isChildItem(i)) {
1823 continue;
1824 }
1825
1826 const ItemData* itemData = m_itemData.at(i);
1827 const QString newPermissionsString = itemData->values.value("permissions").toString();
1828 if (newPermissionsString == permissionsString) {
1829 continue;
1830 }
1831 permissionsString = newPermissionsString;
1832
1833 const QFileInfo info(itemData->item.url().pathOrUrl());
1834
1835 // Set user string
1836 QString user;
1837 if (info.permission(QFile::ReadUser)) {
1838 user = i18nc("@item:intext Access permission, concatenated", "Read, ");
1839 }
1840 if (info.permission(QFile::WriteUser)) {
1841 user += i18nc("@item:intext Access permission, concatenated", "Write, ");
1842 }
1843 if (info.permission(QFile::ExeUser)) {
1844 user += i18nc("@item:intext Access permission, concatenated", "Execute, ");
1845 }
1846 user = user.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : user.mid(0, user.count() - 2);
1847
1848 // Set group string
1849 QString group;
1850 if (info.permission(QFile::ReadGroup)) {
1851 group = i18nc("@item:intext Access permission, concatenated", "Read, ");
1852 }
1853 if (info.permission(QFile::WriteGroup)) {
1854 group += i18nc("@item:intext Access permission, concatenated", "Write, ");
1855 }
1856 if (info.permission(QFile::ExeGroup)) {
1857 group += i18nc("@item:intext Access permission, concatenated", "Execute, ");
1858 }
1859 group = group.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : group.mid(0, group.count() - 2);
1860
1861 // Set others string
1862 QString others;
1863 if (info.permission(QFile::ReadOther)) {
1864 others = i18nc("@item:intext Access permission, concatenated", "Read, ");
1865 }
1866 if (info.permission(QFile::WriteOther)) {
1867 others += i18nc("@item:intext Access permission, concatenated", "Write, ");
1868 }
1869 if (info.permission(QFile::ExeOther)) {
1870 others += i18nc("@item:intext Access permission, concatenated", "Execute, ");
1871 }
1872 others = others.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : others.mid(0, others.count() - 2);
1873
1874 const QString newGroupValue = i18nc("@title:group Files and folders by permissions", "User: %1 | Group: %2 | Others: %3", user, group, others);
1875 if (newGroupValue != groupValue) {
1876 groupValue = newGroupValue;
1877 groups.append(QPair<int, QVariant>(i, newGroupValue));
1878 }
1879 }
1880
1881 return groups;
1882 }
1883
1884 QList<QPair<int, QVariant> > KFileItemModel::ratingRoleGroups() const
1885 {
1886 Q_ASSERT(!m_itemData.isEmpty());
1887
1888 const int maxIndex = count() - 1;
1889 QList<QPair<int, QVariant> > groups;
1890
1891 int groupValue = -1;
1892 for (int i = 0; i <= maxIndex; ++i) {
1893 if (isChildItem(i)) {
1894 continue;
1895 }
1896 const int newGroupValue = m_itemData.at(i)->values.value("rating", 0).toInt();
1897 if (newGroupValue != groupValue) {
1898 groupValue = newGroupValue;
1899 groups.append(QPair<int, QVariant>(i, newGroupValue));
1900 }
1901 }
1902
1903 return groups;
1904 }
1905
1906 QList<QPair<int, QVariant> > KFileItemModel::genericStringRoleGroups(const QByteArray& role) const
1907 {
1908 Q_ASSERT(!m_itemData.isEmpty());
1909
1910 const int maxIndex = count() - 1;
1911 QList<QPair<int, QVariant> > groups;
1912
1913 bool isFirstGroupValue = true;
1914 QString groupValue;
1915 for (int i = 0; i <= maxIndex; ++i) {
1916 if (isChildItem(i)) {
1917 continue;
1918 }
1919 const QString newGroupValue = m_itemData.at(i)->values.value(role).toString();
1920 if (newGroupValue != groupValue || isFirstGroupValue) {
1921 groupValue = newGroupValue;
1922 groups.append(QPair<int, QVariant>(i, newGroupValue));
1923 isFirstGroupValue = false;
1924 }
1925 }
1926
1927 return groups;
1928 }
1929
1930 KFileItemList KFileItemModel::childItems(const KFileItem& item) const
1931 {
1932 KFileItemList items;
1933
1934 int index = m_items.value(item.url(), -1);
1935 if (index >= 0) {
1936 const int parentLevel = m_itemData.at(index)->values.value("expandedParentsCount").toInt();
1937 ++index;
1938 while (index < m_itemData.count() && m_itemData.at(index)->values.value("expandedParentsCount").toInt() > parentLevel) {
1939 items.append(m_itemData.at(index)->item);
1940 ++index;
1941 }
1942 }
1943
1944 return items;
1945 }
1946
1947 const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
1948 {
1949 static const RoleInfoMap rolesInfoMap[] = {
1950 // role roleType role translation group translation
1951 { 0, NoRole, 0, 0, 0, 0 },
1952 { "name", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), 0, 0 },
1953 { "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), 0, 0 },
1954 { "date", DateRole, I18N_NOOP2_NOSTRIP("@label", "Date"), 0, 0 },
1955 { "type", TypeRole, I18N_NOOP2_NOSTRIP("@label", "Type"), 0, 0 },
1956 { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), 0, 0 },
1957 { "tags", TagsRole, I18N_NOOP2_NOSTRIP("@label", "Tags"), 0, 0 },
1958 { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), 0, 0 },
1959 { "wordCount", WordCountRole, I18N_NOOP2_NOSTRIP("@label", "Word Count"), I18N_NOOP2_NOSTRIP("@label", "Document") },
1960 { "lineCount", LineCountRole, I18N_NOOP2_NOSTRIP("@label", "Line Count"), I18N_NOOP2_NOSTRIP("@label", "Document") },
1961 { "imageSize", ImageSizeRole, I18N_NOOP2_NOSTRIP("@label", "Image Size"), I18N_NOOP2_NOSTRIP("@label", "Image") },
1962 { "orientation", OrientationRole, I18N_NOOP2_NOSTRIP("@label", "Orientation"), I18N_NOOP2_NOSTRIP("@label", "Image") },
1963 { "artist", ArtistRole, I18N_NOOP2_NOSTRIP("@label", "Artist"), I18N_NOOP2_NOSTRIP("@label", "Music") },
1964 { "album", AlbumRole, I18N_NOOP2_NOSTRIP("@label", "Album"), I18N_NOOP2_NOSTRIP("@label", "Music") },
1965 { "duration", DurationRole, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Music") },
1966 { "track", TrackRole, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Music") },
1967 { "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1968 { "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1969 { "copiedFrom", CopiedFromRole, I18N_NOOP2_NOSTRIP("@label", "Copied From"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1970 { "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1971 { "owner", OwnerRole, I18N_NOOP2_NOSTRIP("@label", "Owner"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1972 { "group", GroupRole, I18N_NOOP2_NOSTRIP("@label", "Group"), I18N_NOOP2_NOSTRIP("@label", "Other") },
1973 };
1974
1975 count = sizeof(rolesInfoMap) / sizeof(RoleInfoMap);
1976 return rolesInfoMap;
1977 }
1978
1979 #include "kfileitemmodel.moc"