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