1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on KFilePlacesModel from kdelibs: *
5 * Copyright (C) 2007 Kevin Ottens <ervin@kde.org> *
6 * Copyright (C) 2007 David Faure <faure@kde.org> *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
24 #include "placesitemmodel.h"
26 #include "dolphin_generalsettings.h"
27 #include "dolphindebug.h"
28 #include "dolphinplacesmodelsingleton.h"
29 #include "placesitem.h"
30 #include "placesitemsignalhandler.h"
31 #include "views/dolphinview.h"
32 #include "views/viewproperties.h"
35 #include <KLocalizedString>
36 #include <KUrlMimeData>
37 #include <Solid/DeviceNotifier>
38 #include <Solid/OpticalDrive>
46 static QList
<QUrl
> balooURLs
= {
47 QUrl(QStringLiteral("timeline:/today")),
48 QUrl(QStringLiteral("timeline:/yesterday")),
49 QUrl(QStringLiteral("timeline:/thismonth")),
50 QUrl(QStringLiteral("timeline:/lastmonth")),
51 QUrl(QStringLiteral("search:/documents")),
52 QUrl(QStringLiteral("search:/images")),
53 QUrl(QStringLiteral("search:/audio")),
54 QUrl(QStringLiteral("search:/videos"))
58 PlacesItemModel::PlacesItemModel(QObject
* parent
) :
59 KStandardItemModel(parent
),
60 m_hiddenItemsShown(false),
61 m_deviceToTearDown(nullptr),
62 m_storageSetupInProgress(),
63 m_sourceModel(DolphinPlacesModelSingleton::instance().placesModel())
67 initializeDefaultViewProperties();
69 connect(m_sourceModel
, &KFilePlacesModel::rowsInserted
, this, &PlacesItemModel::onSourceModelRowsInserted
);
70 connect(m_sourceModel
, &KFilePlacesModel::rowsAboutToBeRemoved
, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved
);
71 connect(m_sourceModel
, &KFilePlacesModel::dataChanged
, this, &PlacesItemModel::onSourceModelDataChanged
);
72 connect(m_sourceModel
, &KFilePlacesModel::rowsAboutToBeMoved
, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved
);
73 connect(m_sourceModel
, &KFilePlacesModel::rowsMoved
, this, &PlacesItemModel::onSourceModelRowsMoved
);
74 connect(m_sourceModel
, &KFilePlacesModel::groupHiddenChanged
, this, &PlacesItemModel::onSourceModelGroupHiddenChanged
);
77 PlacesItemModel::~PlacesItemModel()
81 void PlacesItemModel::createPlacesItem(const QString
& text
,
83 const QString
& iconName
,
86 m_sourceModel
->addPlace(text
, url
, iconName
, {}, mapToSource(after
));
89 PlacesItem
* PlacesItemModel::placesItem(int index
) const
91 return dynamic_cast<PlacesItem
*>(item(index
));
94 int PlacesItemModel::hiddenCount() const
96 return m_sourceModel
->hiddenCount();
99 void PlacesItemModel::setHiddenItemsShown(bool show
)
101 if (m_hiddenItemsShown
== show
) {
105 m_hiddenItemsShown
= show
;
108 for (int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
109 const QModelIndex index
= m_sourceModel
->index(r
, 0);
110 if (!m_sourceModel
->isHidden(index
)) {
113 addItemFromSourceModel(index
);
116 for (int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
117 const QModelIndex index
= m_sourceModel
->index(r
, 0);
118 if (m_sourceModel
->isHidden(index
)) {
119 removeItemByIndex(index
);
124 #ifdef PLACESITEMMODEL_DEBUG
125 qCDebug(DolphinDebug
) << "Changed visibility of hidden items";
130 bool PlacesItemModel::hiddenItemsShown() const
132 return m_hiddenItemsShown
;
135 int PlacesItemModel::closestItem(const QUrl
& url
) const
137 return mapFromSource(m_sourceModel
->closestItem(url
));
140 // look for the correct position for the item based on source model
141 void PlacesItemModel::insertSortedItem(PlacesItem
* item
)
147 const KBookmark iBookmark
= item
->bookmark();
148 const QString iBookmarkId
= bookmarkId(iBookmark
);
149 QModelIndex sourceIndex
;
152 for(int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
153 sourceIndex
= m_sourceModel
->index(r
, 0);
154 const KBookmark sourceBookmark
= m_sourceModel
->bookmarkForIndex(sourceIndex
);
156 if (bookmarkId(sourceBookmark
) == iBookmarkId
) {
160 if (m_hiddenItemsShown
|| !m_sourceModel
->isHidden(sourceIndex
)) {
165 m_indexMap
.insert(pos
, sourceIndex
);
166 insertItem(pos
, item
);
169 void PlacesItemModel::onItemInserted(int index
)
171 KStandardItemModel::onItemInserted(index
);
172 #ifdef PLACESITEMMODEL_DEBUG
173 qCDebug(DolphinDebug
) << "Inserted item" << index
;
178 void PlacesItemModel::onItemRemoved(int index
, KStandardItem
* removedItem
)
180 m_indexMap
.removeAt(index
);
182 KStandardItemModel::onItemRemoved(index
, removedItem
);
183 #ifdef PLACESITEMMODEL_DEBUG
184 qCDebug(DolphinDebug
) << "Removed item" << index
;
189 void PlacesItemModel::onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
)
191 const QModelIndex sourceIndex
= mapToSource(index
);
192 const PlacesItem
*changedItem
= placesItem(mapFromSource(sourceIndex
));
194 if (!changedItem
|| !sourceIndex
.isValid()) {
195 qWarning() << "invalid item changed signal";
198 if (changedRoles
.contains("isHidden")) {
199 if (m_sourceModel
->isHidden(sourceIndex
) != changedItem
->isHidden()) {
200 m_sourceModel
->setPlaceHidden(sourceIndex
, changedItem
->isHidden());
202 m_sourceModel
->refresh();
205 KStandardItemModel::onItemChanged(index
, changedRoles
);
208 QAction
* PlacesItemModel::ejectAction(int index
) const
210 const PlacesItem
* item
= placesItem(index
);
211 if (item
&& item
->device().is
<Solid::OpticalDisc
>()) {
212 return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject"), nullptr);
218 QAction
* PlacesItemModel::teardownAction(int index
) const
220 const PlacesItem
* item
= placesItem(index
);
225 Solid::Device device
= item
->device();
226 const bool providesTearDown
= device
.is
<Solid::StorageAccess
>() &&
227 device
.as
<Solid::StorageAccess
>()->isAccessible();
228 if (!providesTearDown
) {
232 Solid::StorageDrive
* drive
= device
.as
<Solid::StorageDrive
>();
234 drive
= device
.parent().as
<Solid::StorageDrive
>();
237 bool hotPluggable
= false;
238 bool removable
= false;
240 hotPluggable
= drive
->isHotpluggable();
241 removable
= drive
->isRemovable();
246 if (device
.is
<Solid::OpticalDisc
>()) {
247 text
= i18nc("@item", "Release");
248 } else if (removable
|| hotPluggable
) {
249 text
= i18nc("@item", "Safely Remove");
250 iconName
= QStringLiteral("media-eject");
252 text
= i18nc("@item", "Unmount");
253 iconName
= QStringLiteral("media-eject");
256 if (iconName
.isEmpty()) {
257 return new QAction(text
, nullptr);
260 return new QAction(QIcon::fromTheme(iconName
), text
, nullptr);
263 void PlacesItemModel::requestEject(int index
)
265 const PlacesItem
* item
= placesItem(index
);
267 Solid::OpticalDrive
* drive
= item
->device().parent().as
<Solid::OpticalDrive
>();
269 connect(drive
, &Solid::OpticalDrive::ejectDone
,
270 this, &PlacesItemModel::slotStorageTearDownDone
);
273 const QString label
= item
->text();
274 const QString message
= i18nc("@info", "The device '%1' is not a disk and cannot be ejected.", label
);
275 emit
errorMessage(message
);
280 void PlacesItemModel::requestTearDown(int index
)
282 const PlacesItem
* item
= placesItem(index
);
284 Solid::StorageAccess
*tmp
= item
->device().as
<Solid::StorageAccess
>();
286 m_deviceToTearDown
= tmp
;
287 // disconnect the Solid::StorageAccess::teardownRequested
288 // to prevent emitting PlacesItemModel::storageTearDownExternallyRequested
289 // after we have emitted PlacesItemModel::storageTearDownRequested
290 disconnect(tmp
, &Solid::StorageAccess::teardownRequested
,
291 item
->signalHandler(), &PlacesItemSignalHandler::onTearDownRequested
);
292 emit
storageTearDownRequested(tmp
->filePath());
297 bool PlacesItemModel::storageSetupNeeded(int index
) const
299 const PlacesItem
* item
= placesItem(index
);
300 return item
? item
->storageSetupNeeded() : false;
303 void PlacesItemModel::requestStorageSetup(int index
)
305 const PlacesItem
* item
= placesItem(index
);
310 Solid::Device device
= item
->device();
311 const bool setup
= device
.is
<Solid::StorageAccess
>()
312 && !m_storageSetupInProgress
.contains(device
.as
<Solid::StorageAccess
>())
313 && !device
.as
<Solid::StorageAccess
>()->isAccessible();
315 Solid::StorageAccess
* access
= device
.as
<Solid::StorageAccess
>();
317 m_storageSetupInProgress
[access
] = index
;
319 connect(access
, &Solid::StorageAccess::setupDone
,
320 this, &PlacesItemModel::slotStorageSetupDone
);
326 QMimeData
* PlacesItemModel::createMimeData(const KItemSet
& indexes
) const
331 QDataStream
stream(&itemData
, QIODevice::WriteOnly
);
333 for (int index
: indexes
) {
334 const QUrl itemUrl
= placesItem(index
)->url();
335 if (itemUrl
.isValid()) {
341 QMimeData
* mimeData
= new QMimeData();
342 if (!urls
.isEmpty()) {
343 mimeData
->setUrls(urls
);
345 // #378954: prevent itemDropEvent() drops if there isn't a source url.
346 mimeData
->setData(blacklistItemDropEventMimeType(), QByteArrayLiteral("true"));
348 mimeData
->setData(internalMimeType(), itemData
);
353 bool PlacesItemModel::supportsDropping(int index
) const
355 return index
>= 0 && index
< count();
358 void PlacesItemModel::dropMimeDataBefore(int index
, const QMimeData
* mimeData
)
360 if (mimeData
->hasFormat(internalMimeType())) {
361 // The item has been moved inside the view
362 QByteArray itemData
= mimeData
->data(internalMimeType());
363 QDataStream
stream(&itemData
, QIODevice::ReadOnly
);
367 m_sourceModel
->movePlace(oldIndex
, index
);
368 } else if (mimeData
->hasFormat(QStringLiteral("text/uri-list"))) {
369 // One or more items must be added to the model
370 const QList
<QUrl
> urls
= KUrlMimeData::urlsFromMimeData(mimeData
);
371 for (int i
= urls
.count() - 1; i
>= 0; --i
) {
372 const QUrl
& url
= urls
[i
];
374 QString text
= url
.fileName();
375 if (text
.isEmpty()) {
379 if ((url
.isLocalFile() && !QFileInfo(url
.toLocalFile()).isDir())
380 || url
.scheme() == QLatin1String("trash")) {
381 // Only directories outside the trash are allowed
385 createPlacesItem(text
, url
, KIO::iconNameForUrl(url
), qMax(0, index
- 1));
388 // will save bookmark alteration and fix sort if that is broken by the drag/drop operation
392 void PlacesItemModel::addItemFromSourceModel(const QModelIndex
&index
)
394 if (!m_hiddenItemsShown
&& m_sourceModel
->isHidden(index
)) {
398 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(index
);
399 Q_ASSERT(!bookmark
.isNull());
400 PlacesItem
*item
= itemFromBookmark(bookmark
);
402 item
= new PlacesItem(bookmark
);
404 updateItem(item
, index
);
405 insertSortedItem(item
);
407 if (m_sourceModel
->isDevice(index
)) {
408 connect(item
->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested
,
409 this, &PlacesItemModel::storageTearDownExternallyRequested
);
413 void PlacesItemModel::removeItemByIndex(const QModelIndex
&sourceIndex
)
415 QString id
= bookmarkId(m_sourceModel
->bookmarkForIndex(sourceIndex
));
417 for (int i
= 0, iMax
= count(); i
< iMax
; ++i
) {
418 if (bookmarkId(placesItem(i
)->bookmark()) == id
) {
425 QString
PlacesItemModel::bookmarkId(const KBookmark
&bookmark
) const
427 QString id
= bookmark
.metaDataItem(QStringLiteral("UDI"));
429 id
= bookmark
.metaDataItem(QStringLiteral("ID"));
434 void PlacesItemModel::initializeDefaultViewProperties() const
436 for(int i
= 0, iMax
= m_sourceModel
->rowCount(); i
< iMax
; i
++) {
437 const QModelIndex index
= m_sourceModel
->index(i
, 0);
438 const PlacesItem
*item
= placesItem(mapFromSource(index
));
443 // Create default view-properties for all "Search For" and "Recently Saved" bookmarks
444 // in case the user has not already created custom view-properties for a corresponding
446 const bool createDefaultViewProperties
= item
->isSearchOrTimelineUrl() && !GeneralSettings::self()->globalViewProps();
447 if (createDefaultViewProperties
) {
448 const QUrl itemUrl
= item
->url();
449 ViewProperties
props(KFilePlacesModel::convertedUrl(itemUrl
));
450 if (!props
.exist()) {
451 const QString path
= itemUrl
.path();
452 if (path
== QLatin1String("/documents")) {
453 props
.setViewMode(DolphinView::DetailsView
);
454 props
.setPreviewsShown(false);
455 props
.setVisibleRoles({"text", "path"});
456 } else if (path
== QLatin1String("/images")) {
457 props
.setViewMode(DolphinView::IconsView
);
458 props
.setPreviewsShown(true);
459 props
.setVisibleRoles({"text", "imageSize"});
460 } else if (path
== QLatin1String("/audio")) {
461 props
.setViewMode(DolphinView::DetailsView
);
462 props
.setPreviewsShown(false);
463 props
.setVisibleRoles({"text", "artist", "album"});
464 } else if (path
== QLatin1String("/videos")) {
465 props
.setViewMode(DolphinView::IconsView
);
466 props
.setPreviewsShown(true);
467 props
.setVisibleRoles({"text"});
468 } else if (itemUrl
.scheme() == QLatin1String("timeline")) {
469 props
.setViewMode(DolphinView::DetailsView
);
470 props
.setVisibleRoles({"text", "modificationtime"});
478 void PlacesItemModel::updateItem(PlacesItem
*item
, const QModelIndex
&index
)
480 item
->setGroup(index
.data(KFilePlacesModel::GroupRole
).toString());
481 item
->setIcon(index
.data(KFilePlacesModel::IconNameRole
).toString());
482 item
->setGroupHidden(index
.data(KFilePlacesModel::GroupHiddenRole
).toBool());
485 void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error
, const QVariant
& errorData
)
487 if (error
&& errorData
.isValid()) {
488 emit
errorMessage(errorData
.toString());
490 m_deviceToTearDown
->disconnect();
491 m_deviceToTearDown
= nullptr;
494 void PlacesItemModel::slotStorageSetupDone(Solid::ErrorType error
,
495 const QVariant
& errorData
,
500 const int index
= m_storageSetupInProgress
.take(sender());
501 const PlacesItem
* item
= placesItem(index
);
506 if (error
!= Solid::NoError
) {
507 if (errorData
.isValid()) {
508 emit
errorMessage(i18nc("@info", "An error occurred while accessing '%1', the system responded: %2",
510 errorData
.toString()));
512 emit
errorMessage(i18nc("@info", "An error occurred while accessing '%1'",
515 emit
storageSetupDone(index
, false);
517 emit
storageSetupDone(index
, true);
521 void PlacesItemModel::onSourceModelRowsInserted(const QModelIndex
&parent
, int first
, int last
)
523 for (int i
= first
; i
<= last
; i
++) {
524 const QModelIndex index
= m_sourceModel
->index(i
, 0, parent
);
525 addItemFromSourceModel(index
);
529 void PlacesItemModel::onSourceModelRowsAboutToBeRemoved(const QModelIndex
&parent
, int first
, int last
)
531 for(int r
= first
; r
<= last
; r
++) {
532 const QModelIndex index
= m_sourceModel
->index(r
, 0, parent
);
533 int oldIndex
= mapFromSource(index
);
534 if (oldIndex
!= -1) {
535 removeItem(oldIndex
);
540 void PlacesItemModel::onSourceModelRowsAboutToBeMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
)
542 Q_UNUSED(destination
);
545 for(int r
= start
; r
<= end
; r
++) {
546 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0, parent
);
548 removeItem(mapFromSource(sourceIndex
));
552 void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
)
554 Q_UNUSED(destination
);
557 const int blockSize
= (end
- start
) + 1;
559 for (int r
= start
; r
<= end
; r
++) {
560 // insert the moved item in the new position
561 const int targetRow
= row
+ (start
- r
) - (r
< row
? blockSize
: 0);
562 const QModelIndex targetIndex
= m_sourceModel
->index(targetRow
, 0, destination
);
564 addItemFromSourceModel(targetIndex
);
568 void PlacesItemModel::onSourceModelDataChanged(const QModelIndex
&topLeft
, const QModelIndex
&bottomRight
, const QVector
<int> &roles
)
572 for (int r
= topLeft
.row(); r
<= bottomRight
.row(); r
++) {
573 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0);
574 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(sourceIndex
);
575 PlacesItem
*placeItem
= itemFromBookmark(bookmark
);
577 if (placeItem
&& (!m_hiddenItemsShown
&& m_sourceModel
->isHidden(sourceIndex
))) {
578 //hide item if it became invisible
579 removeItem(index(placeItem
));
583 if (!placeItem
&& (m_hiddenItemsShown
|| !m_sourceModel
->isHidden(sourceIndex
))) {
584 //show item if it became visible
585 addItemFromSourceModel(sourceIndex
);
589 if (placeItem
&& !m_sourceModel
->isDevice(sourceIndex
)) {
590 placeItem
->setText(bookmark
.text());
591 placeItem
->setIcon(sourceIndex
.data(KFilePlacesModel::IconNameRole
).toString());
592 placeItem
->setUrl(m_sourceModel
->url(sourceIndex
));
593 placeItem
->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"),
594 bookmark
.metaDataItem(QStringLiteral("OnlyInApp")));
595 // must update the bookmark object
596 placeItem
->setBookmark(bookmark
);
601 void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group
, bool hidden
)
603 for(const QModelIndex
&sourceIndex
: m_sourceModel
->groupIndexes(group
)) {
604 PlacesItem
*item
= placesItem(mapFromSource(sourceIndex
));
606 item
->setGroupHidden(hidden
);
611 void PlacesItemModel::cleanupBookmarks()
613 // KIO model now provides support for baloo urls, and because of that we
614 // need to remove old URLs that were visible only in Dolphin to avoid duplication
617 const QModelIndex sourceIndex
= m_sourceModel
->index(row
, 0);
618 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(sourceIndex
);
619 const QUrl url
= bookmark
.url();
620 const QString appName
= bookmark
.metaDataItem(QStringLiteral("OnlyInApp"));
622 if ((appName
== KAboutData::applicationData().componentName() ||
623 appName
== KAboutData::applicationData().componentName() + DolphinPlacesModelSingleton::applicationNameSuffix()) && balooURLs
.contains(url
)) {
624 qCDebug(DolphinDebug
) << "Removing old baloo url:" << url
;
625 m_sourceModel
->removePlace(sourceIndex
);
629 } while (row
< m_sourceModel
->rowCount());
632 void PlacesItemModel::loadBookmarks()
634 for(int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
635 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0);
636 if (m_hiddenItemsShown
|| !m_sourceModel
->isHidden(sourceIndex
)) {
637 addItemFromSourceModel(sourceIndex
);
641 #ifdef PLACESITEMMODEL_DEBUG
642 qCDebug(DolphinDebug
) << "Loaded bookmarks";
647 void PlacesItemModel::clear() {
648 KStandardItemModel::clear();
651 void PlacesItemModel::proceedWithTearDown()
653 Q_ASSERT(m_deviceToTearDown
);
655 connect(m_deviceToTearDown
, &Solid::StorageAccess::teardownDone
,
656 this, &PlacesItemModel::slotStorageTearDownDone
);
657 m_deviceToTearDown
->teardown();
660 void PlacesItemModel::deleteItem(int index
)
662 QModelIndex sourceIndex
= mapToSource(index
);
663 Q_ASSERT(sourceIndex
.isValid());
664 m_sourceModel
->removePlace(sourceIndex
);
667 void PlacesItemModel::refresh()
669 m_sourceModel
->refresh();
672 void PlacesItemModel::hideItem(int index
)
674 PlacesItem
* shownItem
= placesItem(index
);
679 shownItem
->setHidden(true);
682 QString
PlacesItemModel::internalMimeType() const
684 return "application/x-dolphinplacesmodel-" +
685 QString::number((qptrdiff
)this);
688 int PlacesItemModel::groupedDropIndex(int index
, const PlacesItem
* item
) const
692 int dropIndex
= index
;
693 const QString group
= item
->group();
695 const int itemCount
= count();
697 dropIndex
= itemCount
;
700 // Search nearest previous item with the same group
701 int previousIndex
= -1;
702 for (int i
= dropIndex
- 1; i
>= 0; --i
) {
703 if (placesItem(i
)->group() == group
) {
709 // Search nearest next item with the same group
711 for (int i
= dropIndex
; i
< count(); ++i
) {
712 if (placesItem(i
)->group() == group
) {
718 // Adjust the drop-index to be inserted to the
719 // nearest item with the same group.
720 if (previousIndex
>= 0 && nextIndex
>= 0) {
721 dropIndex
= (dropIndex
- previousIndex
< nextIndex
- dropIndex
) ?
722 previousIndex
+ 1 : nextIndex
;
723 } else if (previousIndex
>= 0) {
724 dropIndex
= previousIndex
+ 1;
725 } else if (nextIndex
>= 0) {
726 dropIndex
= nextIndex
;
732 bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark
& b1
, const KBookmark
& b2
)
734 const QString udi1
= b1
.metaDataItem(QStringLiteral("UDI"));
735 const QString udi2
= b2
.metaDataItem(QStringLiteral("UDI"));
736 if (!udi1
.isEmpty() && !udi2
.isEmpty()) {
739 return b1
.metaDataItem(QStringLiteral("ID")) == b2
.metaDataItem(QStringLiteral("ID"));
743 int PlacesItemModel::mapFromSource(const QModelIndex
&index
) const
745 if (!index
.isValid()) {
749 return m_indexMap
.indexOf(index
);
752 bool PlacesItemModel::isDir(int index
) const
758 KFilePlacesModel::GroupType
PlacesItemModel::groupType(int row
) const
760 return m_sourceModel
->groupType(mapToSource(row
));
763 bool PlacesItemModel::isGroupHidden(KFilePlacesModel::GroupType type
) const
765 return m_sourceModel
->isGroupHidden(type
);
768 void PlacesItemModel::setGroupHidden(KFilePlacesModel::GroupType type
, bool hidden
)
770 return m_sourceModel
->setGroupHidden(type
, hidden
);
773 QModelIndex
PlacesItemModel::mapToSource(int row
) const
775 return m_indexMap
.value(row
);
778 PlacesItem
*PlacesItemModel::itemFromBookmark(const KBookmark
&bookmark
) const
780 const QString id
= bookmarkId(bookmark
);
781 for (int i
= 0, iMax
= count(); i
< iMax
; i
++) {
782 PlacesItem
*item
= placesItem(i
);
783 const KBookmark itemBookmark
= item
->bookmark();
784 if (bookmarkId(itemBookmark
) == id
) {
791 #ifdef PLACESITEMMODEL_DEBUG
792 void PlacesItemModel::showModelState()
794 qCDebug(DolphinDebug
) << "=================================";
795 qCDebug(DolphinDebug
) << "Model:";
796 qCDebug(DolphinDebug
) << "hidden-index model-index text";
798 for (int i
= 0; i
< m_bookmarkedItems
.count(); ++i
) {
799 if (m_bookmarkedItems
[i
]) {
800 qCDebug(DolphinDebug
) << i
<< "(Hidden) " << " " << m_bookmarkedItems
[i
]->dataValue("text").toString();
802 if (item(modelIndex
)) {
803 qCDebug(DolphinDebug
) << i
<< " " << modelIndex
<< " " << item(modelIndex
)->dataValue("text").toString();
805 qCDebug(DolphinDebug
) << i
<< " " << modelIndex
<< " " << "(not available yet)";
811 qCDebug(DolphinDebug
);
812 qCDebug(DolphinDebug
) << "Bookmarks:";
814 int bookmarkIndex
= 0;
815 KBookmarkGroup root
= m_bookmarkManager
->root();
816 KBookmark bookmark
= root
.first();
817 while (!bookmark
.isNull()) {
818 const QString udi
= bookmark
.metaDataItem("UDI");
819 const QString text
= udi
.isEmpty() ? bookmark
.text() : udi
;
820 if (bookmark
.metaDataItem("IsHidden") == QLatin1String("true")) {
821 qCDebug(DolphinDebug
) << bookmarkIndex
<< "(Hidden)" << text
;
823 qCDebug(DolphinDebug
) << bookmarkIndex
<< " " << text
;
826 bookmark
= root
.next(bookmark
);