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