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"
25 #include "placesitemsignalhandler.h"
27 #include "dolphin_generalsettings.h"
30 #include <KBookmarkManager>
31 #include "dolphindebug.h"
33 #include <KProtocolInfo>
34 #include <KLocalizedString>
35 #include <QStandardPaths>
37 #include "placesitem.h"
42 #include <KUrlMimeData>
43 #include <KFilePlacesModel>
45 #include <Solid/Device>
46 #include <Solid/DeviceNotifier>
47 #include <Solid/OpticalDisc>
48 #include <Solid/OpticalDrive>
49 #include <Solid/StorageAccess>
50 #include <Solid/StorageDrive>
52 #include <views/dolphinview.h>
53 #include <views/viewproperties.h>
56 // Hence a prefix to the application-name of the stored bookmarks is
57 // added, which is only read by PlacesItemModel.
58 const char AppNamePrefix
[] = "-places-panel";
61 PlacesItemModel::PlacesItemModel(QObject
* parent
) :
62 KStandardItemModel(parent
),
63 m_hiddenItemsShown(false),
64 m_deviceToTearDown(nullptr),
65 m_storageSetupInProgress(),
66 m_sourceModel(new KFilePlacesModel(this))
69 initializeDefaultViewProperties();
71 connect(m_sourceModel
.data(), &KFilePlacesModel::rowsInserted
, this, &PlacesItemModel::onSourceModelRowsInserted
);
72 connect(m_sourceModel
.data(), &KFilePlacesModel::rowsAboutToBeRemoved
, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved
);
73 connect(m_sourceModel
.data(), &KFilePlacesModel::dataChanged
, this, &PlacesItemModel::onSourceModelDataChanged
);
74 connect(m_sourceModel
.data(), &KFilePlacesModel::rowsAboutToBeMoved
, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved
);
75 connect(m_sourceModel
.data(), &KFilePlacesModel::rowsMoved
, this, &PlacesItemModel::onSourceModelRowsMoved
);
76 connect(m_sourceModel
.data(), &KFilePlacesModel::groupHiddenChanged
, this, &PlacesItemModel::onSourceModelGroupHiddenChanged
);
79 PlacesItemModel::~PlacesItemModel()
83 void PlacesItemModel::createPlacesItem(const QString
& text
,
85 const QString
& iconName
,
88 m_sourceModel
->addPlace(text
, url
, iconName
, {}, mapToSource(after
));
91 PlacesItem
* PlacesItemModel::placesItem(int index
) const
93 return dynamic_cast<PlacesItem
*>(item(index
));
96 int PlacesItemModel::hiddenCount() const
98 return m_sourceModel
->hiddenCount();
101 void PlacesItemModel::setHiddenItemsShown(bool show
)
103 if (m_hiddenItemsShown
== show
) {
107 m_hiddenItemsShown
= show
;
110 for (int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
111 const QModelIndex index
= m_sourceModel
->index(r
, 0);
112 if (!m_sourceModel
->isHidden(index
)) {
115 addItemFromSourceModel(index
);
118 for (int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
119 const QModelIndex index
= m_sourceModel
->index(r
, 0);
120 if (m_sourceModel
->isHidden(index
)) {
121 removeItemByIndex(index
);
126 #ifdef PLACESITEMMODEL_DEBUG
127 qCDebug(DolphinDebug
) << "Changed visibility of hidden items";
132 bool PlacesItemModel::hiddenItemsShown() const
134 return m_hiddenItemsShown
;
137 int PlacesItemModel::closestItem(const QUrl
& url
) const
139 return mapFromSource(m_sourceModel
->closestItem(url
));
142 // look for the correct position for the item based on source model
143 void PlacesItemModel::insertSortedItem(PlacesItem
* item
)
149 const KBookmark iBookmark
= item
->bookmark();
150 const QString iBookmarkId
= bookmarkId(iBookmark
);
151 QModelIndex sourceIndex
;
154 for(int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
155 sourceIndex
= m_sourceModel
->index(r
, 0);
157 if (bookmarkId(m_sourceModel
->bookmarkForIndex(sourceIndex
)) == iBookmarkId
) {
161 if (!m_sourceModel
->isHidden(sourceIndex
)) {
166 m_indexMap
.insert(pos
, sourceIndex
);
167 insertItem(pos
, item
);
170 void PlacesItemModel::onItemInserted(int index
)
172 KStandardItemModel::onItemInserted(index
);
173 #ifdef PLACESITEMMODEL_DEBUG
174 qCDebug(DolphinDebug
) << "Inserted item" << index
;
179 void PlacesItemModel::onItemRemoved(int index
, KStandardItem
* removedItem
)
181 m_indexMap
.removeAt(index
);
183 KStandardItemModel::onItemRemoved(index
, removedItem
);
184 #ifdef PLACESITEMMODEL_DEBUG
185 qCDebug(DolphinDebug
) << "Removed item" << index
;
190 void PlacesItemModel::onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
)
192 const QModelIndex sourceIndex
= mapToSource(index
);
193 const PlacesItem
*changedItem
= placesItem(mapFromSource(sourceIndex
));
195 if (!changedItem
|| !sourceIndex
.isValid()) {
196 qWarning() << "invalid item changed signal";
199 if (changedRoles
.contains("isHidden")) {
200 if (m_sourceModel
->isHidden(sourceIndex
) != changedItem
->isHidden()) {
201 m_sourceModel
->setPlaceHidden(sourceIndex
, changedItem
->isHidden());
203 m_sourceModel
->refresh();
206 KStandardItemModel::onItemChanged(index
, changedRoles
);
209 QAction
* PlacesItemModel::ejectAction(int index
) const
211 const PlacesItem
* item
= placesItem(index
);
212 if (item
&& item
->device().is
<Solid::OpticalDisc
>()) {
213 return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject"), nullptr);
219 QAction
* PlacesItemModel::teardownAction(int index
) const
221 const PlacesItem
* item
= placesItem(index
);
226 Solid::Device device
= item
->device();
227 const bool providesTearDown
= device
.is
<Solid::StorageAccess
>() &&
228 device
.as
<Solid::StorageAccess
>()->isAccessible();
229 if (!providesTearDown
) {
233 Solid::StorageDrive
* drive
= device
.as
<Solid::StorageDrive
>();
235 drive
= device
.parent().as
<Solid::StorageDrive
>();
238 bool hotPluggable
= false;
239 bool removable
= false;
241 hotPluggable
= drive
->isHotpluggable();
242 removable
= drive
->isRemovable();
247 if (device
.is
<Solid::OpticalDisc
>()) {
248 text
= i18nc("@item", "Release");
249 } else if (removable
|| hotPluggable
) {
250 text
= i18nc("@item", "Safely Remove");
251 iconName
= QStringLiteral("media-eject");
253 text
= i18nc("@item", "Unmount");
254 iconName
= QStringLiteral("media-eject");
257 if (iconName
.isEmpty()) {
258 return new QAction(text
, nullptr);
261 return new QAction(QIcon::fromTheme(iconName
), text
, nullptr);
264 void PlacesItemModel::requestEject(int index
)
266 const PlacesItem
* item
= placesItem(index
);
268 Solid::OpticalDrive
* drive
= item
->device().parent().as
<Solid::OpticalDrive
>();
270 connect(drive
, &Solid::OpticalDrive::ejectDone
,
271 this, &PlacesItemModel::slotStorageTearDownDone
);
274 const QString label
= item
->text();
275 const QString message
= i18nc("@info", "The device '%1' is not a disk and cannot be ejected.", label
);
276 emit
errorMessage(message
);
281 void PlacesItemModel::requestTearDown(int index
)
283 const PlacesItem
* item
= placesItem(index
);
285 Solid::StorageAccess
*tmp
= item
->device().as
<Solid::StorageAccess
>();
287 m_deviceToTearDown
= tmp
;
288 // disconnect the Solid::StorageAccess::teardownRequested
289 // to prevent emitting PlacesItemModel::storageTearDownExternallyRequested
290 // after we have emitted PlacesItemModel::storageTearDownRequested
291 disconnect(tmp
, &Solid::StorageAccess::teardownRequested
,
292 item
->signalHandler(), &PlacesItemSignalHandler::onTearDownRequested
);
293 emit
storageTearDownRequested(tmp
->filePath());
298 bool PlacesItemModel::storageSetupNeeded(int index
) const
300 const PlacesItem
* item
= placesItem(index
);
301 return item
? item
->storageSetupNeeded() : false;
304 void PlacesItemModel::requestStorageSetup(int index
)
306 const PlacesItem
* item
= placesItem(index
);
311 Solid::Device device
= item
->device();
312 const bool setup
= device
.is
<Solid::StorageAccess
>()
313 && !m_storageSetupInProgress
.contains(device
.as
<Solid::StorageAccess
>())
314 && !device
.as
<Solid::StorageAccess
>()->isAccessible();
316 Solid::StorageAccess
* access
= device
.as
<Solid::StorageAccess
>();
318 m_storageSetupInProgress
[access
] = index
;
320 connect(access
, &Solid::StorageAccess::setupDone
,
321 this, &PlacesItemModel::slotStorageSetupDone
);
327 QMimeData
* PlacesItemModel::createMimeData(const KItemSet
& indexes
) const
332 QDataStream
stream(&itemData
, QIODevice::WriteOnly
);
334 for (int index
: indexes
) {
335 const QUrl itemUrl
= placesItem(index
)->url();
336 if (itemUrl
.isValid()) {
342 QMimeData
* mimeData
= new QMimeData();
343 if (!urls
.isEmpty()) {
344 mimeData
->setUrls(urls
);
346 // #378954: prevent itemDropEvent() drops if there isn't a source url.
347 mimeData
->setData(blacklistItemDropEventMimeType(), QByteArrayLiteral("true"));
349 mimeData
->setData(internalMimeType(), itemData
);
354 bool PlacesItemModel::supportsDropping(int index
) const
356 return index
>= 0 && index
< count();
359 void PlacesItemModel::dropMimeDataBefore(int index
, const QMimeData
* mimeData
)
361 if (mimeData
->hasFormat(internalMimeType())) {
362 // The item has been moved inside the view
363 QByteArray itemData
= mimeData
->data(internalMimeType());
364 QDataStream
stream(&itemData
, QIODevice::ReadOnly
);
368 m_sourceModel
->movePlace(oldIndex
, index
);
369 } else if (mimeData
->hasFormat(QStringLiteral("text/uri-list"))) {
370 // One or more items must be added to the model
371 const QList
<QUrl
> urls
= KUrlMimeData::urlsFromMimeData(mimeData
);
372 for (int i
= urls
.count() - 1; i
>= 0; --i
) {
373 const QUrl
& url
= urls
[i
];
375 QString text
= url
.fileName();
376 if (text
.isEmpty()) {
380 if ((url
.isLocalFile() && !QFileInfo(url
.toLocalFile()).isDir())
381 || url
.scheme() == QLatin1String("trash")) {
382 // Only directories outside the trash are allowed
386 createPlacesItem(text
, url
, KIO::iconNameForUrl(url
), qMax(0, index
- 1));
389 // will save bookmark alteration and fix sort if that is broken by the drag/drop operation
393 void PlacesItemModel::addItemFromSourceModel(const QModelIndex
&index
)
395 if (!m_hiddenItemsShown
&& m_sourceModel
->isHidden(index
)) {
399 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(index
);
400 Q_ASSERT(!bookmark
.isNull());
401 PlacesItem
*item
= new PlacesItem(bookmark
);
402 updateItem(item
, index
);
403 insertSortedItem(item
);
405 if (m_sourceModel
->isDevice(index
)) {
406 connect(item
->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested
,
407 this, &PlacesItemModel::storageTearDownExternallyRequested
);
411 void PlacesItemModel::removeItemByIndex(const QModelIndex
&sourceIndex
)
413 QString id
= bookmarkId(m_sourceModel
->bookmarkForIndex(sourceIndex
));
415 for (int i
= 0, iMax
= count(); i
< iMax
; ++i
) {
416 if (bookmarkId(placesItem(i
)->bookmark()) == id
) {
423 QString
PlacesItemModel::bookmarkId(const KBookmark
&bookmark
) const
425 QString id
= bookmark
.metaDataItem(QStringLiteral("UDI"));
427 id
= bookmark
.metaDataItem(QStringLiteral("ID"));
432 void PlacesItemModel::initializeDefaultViewProperties() const
434 for(int i
= 0, iMax
= m_sourceModel
->rowCount(); i
< iMax
; i
++) {
435 const QModelIndex index
= m_sourceModel
->index(i
, 0);
436 const PlacesItem
*item
= placesItem(mapFromSource(index
));
441 // Create default view-properties for all "Search For" and "Recently Saved" bookmarks
442 // in case the user has not already created custom view-properties for a corresponding
444 const bool createDefaultViewProperties
= item
->isSearchOrTimelineUrl() && !GeneralSettings::self()->globalViewProps();
445 if (createDefaultViewProperties
) {
446 const QUrl itemUrl
= item
->url();
447 ViewProperties
props(KFilePlacesModel::convertedUrl(itemUrl
));
448 if (!props
.exist()) {
449 const QString path
= itemUrl
.path();
450 if (path
== QLatin1String("/documents")) {
451 props
.setViewMode(DolphinView::DetailsView
);
452 props
.setPreviewsShown(false);
453 props
.setVisibleRoles({"text", "path"});
454 } else if (path
== QLatin1String("/images")) {
455 props
.setViewMode(DolphinView::IconsView
);
456 props
.setPreviewsShown(true);
457 props
.setVisibleRoles({"text", "imageSize"});
458 } else if (path
== QLatin1String("/audio")) {
459 props
.setViewMode(DolphinView::DetailsView
);
460 props
.setPreviewsShown(false);
461 props
.setVisibleRoles({"text", "artist", "album"});
462 } else if (path
== QLatin1String("/videos")) {
463 props
.setViewMode(DolphinView::IconsView
);
464 props
.setPreviewsShown(true);
465 props
.setVisibleRoles({"text"});
466 } else if (itemUrl
.scheme() == QLatin1String("timeline")) {
467 props
.setViewMode(DolphinView::DetailsView
);
468 props
.setVisibleRoles({"text", "modificationtime"});
476 void PlacesItemModel::updateItem(PlacesItem
*item
, const QModelIndex
&index
)
478 item
->setGroup(index
.data(KFilePlacesModel::GroupRole
).toString());
479 item
->setIcon(index
.data(KFilePlacesModel::IconNameRole
).toString());
480 item
->setGroupHidden(index
.data(KFilePlacesModel::GroupHiddenRole
).toBool());
483 void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error
, const QVariant
& errorData
)
485 if (error
&& errorData
.isValid()) {
486 emit
errorMessage(errorData
.toString());
488 m_deviceToTearDown
->disconnect();
489 m_deviceToTearDown
= nullptr;
492 void PlacesItemModel::slotStorageSetupDone(Solid::ErrorType error
,
493 const QVariant
& errorData
,
498 const int index
= m_storageSetupInProgress
.take(sender());
499 const PlacesItem
* item
= placesItem(index
);
504 if (error
!= Solid::NoError
) {
505 if (errorData
.isValid()) {
506 emit
errorMessage(i18nc("@info", "An error occurred while accessing '%1', the system responded: %2",
508 errorData
.toString()));
510 emit
errorMessage(i18nc("@info", "An error occurred while accessing '%1'",
513 emit
storageSetupDone(index
, false);
515 emit
storageSetupDone(index
, true);
519 void PlacesItemModel::onSourceModelRowsInserted(const QModelIndex
&parent
, int first
, int last
)
521 for (int i
= first
; i
<= last
; i
++) {
522 const QModelIndex index
= m_sourceModel
->index(i
, 0, parent
);
523 addItemFromSourceModel(index
);
527 void PlacesItemModel::onSourceModelRowsAboutToBeRemoved(const QModelIndex
&parent
, int first
, int last
)
529 for(int r
= first
; r
<= last
; r
++) {
530 const QModelIndex index
= m_sourceModel
->index(r
, 0, parent
);
531 int oldIndex
= mapFromSource(index
);
532 if (oldIndex
!= -1) {
533 removeItem(oldIndex
);
538 void PlacesItemModel::onSourceModelRowsAboutToBeMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
)
540 Q_UNUSED(destination
);
543 for(int r
= start
; r
<= end
; r
++) {
544 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0, parent
);
546 removeItem(mapFromSource(sourceIndex
));
550 void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
)
552 Q_UNUSED(destination
);
555 const int blockSize
= (end
- start
) + 1;
557 for (int r
= start
; r
<= end
; r
++) {
558 // insert the moved item in the new position
559 const int targetRow
= row
+ (start
- r
) - (r
< row
? blockSize
: 0);
560 const QModelIndex targetIndex
= m_sourceModel
->index(targetRow
, 0, destination
);
562 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(targetIndex
);
563 PlacesItem
*item
= new PlacesItem(bookmark
);
564 updateItem(item
, targetIndex
);
566 insertSortedItem(item
);
570 void PlacesItemModel::onSourceModelDataChanged(const QModelIndex
&topLeft
, const QModelIndex
&bottomRight
, const QVector
<int> &roles
)
574 for (int r
= topLeft
.row(); r
<= bottomRight
.row(); r
++) {
575 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0);
576 const KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(sourceIndex
);
577 PlacesItem
*placeItem
= itemFromBookmark(bookmark
);
579 if (placeItem
&& (!m_hiddenItemsShown
&& m_sourceModel
->isHidden(sourceIndex
))) {
580 //hide item if it became invisible
581 removeItem(index(placeItem
));
585 if (!placeItem
&& (m_hiddenItemsShown
|| !m_sourceModel
->isHidden(sourceIndex
))) {
586 //show item if it became visible
587 addItemFromSourceModel(sourceIndex
);
591 if (placeItem
&& !m_sourceModel
->isDevice(sourceIndex
)) {
592 placeItem
->setText(bookmark
.text());
593 placeItem
->setIcon(sourceIndex
.data(KFilePlacesModel::IconNameRole
).toString());
594 placeItem
->setUrl(m_sourceModel
->url(sourceIndex
));
595 placeItem
->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"),
596 bookmark
.metaDataItem(QStringLiteral("OnlyInApp")));
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::loadBookmarks()
613 for(int r
= 0, rMax
= m_sourceModel
->rowCount(); r
< rMax
; r
++) {
614 const QModelIndex sourceIndex
= m_sourceModel
->index(r
, 0);
615 KBookmark bookmark
= m_sourceModel
->bookmarkForIndex(sourceIndex
);
616 if (acceptBookmark(bookmark
) &&
617 (m_hiddenItemsShown
|| !m_sourceModel
->isHidden(sourceIndex
))) {
618 addItemFromSourceModel(sourceIndex
);
622 #ifdef PLACESITEMMODEL_DEBUG
623 qCDebug(DolphinDebug
) << "Loaded bookmarks";
628 bool PlacesItemModel::acceptBookmark(const KBookmark
& bookmark
) const
630 const QString udi
= bookmark
.metaDataItem(QStringLiteral("UDI"));
631 const QUrl url
= bookmark
.url();
632 const QString appName
= bookmark
.metaDataItem(QStringLiteral("OnlyInApp"));
633 const bool allowedHere
= (appName
.isEmpty()
634 || appName
== KAboutData::applicationData().componentName()
635 || appName
== KAboutData::applicationData().componentName() + AppNamePrefix
);
637 return (udi
.isEmpty() && allowedHere
);
640 void PlacesItemModel::clear() {
641 KStandardItemModel::clear();
644 void PlacesItemModel::proceedWithTearDown()
646 Q_ASSERT(m_deviceToTearDown
);
648 connect(m_deviceToTearDown
, &Solid::StorageAccess::teardownDone
,
649 this, &PlacesItemModel::slotStorageTearDownDone
);
650 m_deviceToTearDown
->teardown();
653 void PlacesItemModel::deleteItem(int index
)
655 QModelIndex sourceIndex
= mapToSource(index
);
656 Q_ASSERT(sourceIndex
.isValid());
657 m_sourceModel
->removePlace(sourceIndex
);
660 void PlacesItemModel::refresh()
662 m_sourceModel
->refresh();
665 void PlacesItemModel::hideItem(int index
)
667 PlacesItem
* shownItem
= placesItem(index
);
672 shownItem
->setHidden(true);
675 QString
PlacesItemModel::internalMimeType() const
677 return "application/x-dolphinplacesmodel-" +
678 QString::number((qptrdiff
)this);
681 int PlacesItemModel::groupedDropIndex(int index
, const PlacesItem
* item
) const
685 int dropIndex
= index
;
686 const QString group
= item
->group();
688 const int itemCount
= count();
690 dropIndex
= itemCount
;
693 // Search nearest previous item with the same group
694 int previousIndex
= -1;
695 for (int i
= dropIndex
- 1; i
>= 0; --i
) {
696 if (placesItem(i
)->group() == group
) {
702 // Search nearest next item with the same group
704 for (int i
= dropIndex
; i
< count(); ++i
) {
705 if (placesItem(i
)->group() == group
) {
711 // Adjust the drop-index to be inserted to the
712 // nearest item with the same group.
713 if (previousIndex
>= 0 && nextIndex
>= 0) {
714 dropIndex
= (dropIndex
- previousIndex
< nextIndex
- dropIndex
) ?
715 previousIndex
+ 1 : nextIndex
;
716 } else if (previousIndex
>= 0) {
717 dropIndex
= previousIndex
+ 1;
718 } else if (nextIndex
>= 0) {
719 dropIndex
= nextIndex
;
725 bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark
& b1
, const KBookmark
& b2
)
727 const QString udi1
= b1
.metaDataItem(QStringLiteral("UDI"));
728 const QString udi2
= b2
.metaDataItem(QStringLiteral("UDI"));
729 if (!udi1
.isEmpty() && !udi2
.isEmpty()) {
732 return b1
.metaDataItem(QStringLiteral("ID")) == b2
.metaDataItem(QStringLiteral("ID"));
736 int PlacesItemModel::mapFromSource(const QModelIndex
&index
) const
738 if (!index
.isValid()) {
742 return m_indexMap
.indexOf(index
);
745 bool PlacesItemModel::isDir(int index
) const
751 KFilePlacesModel::GroupType
PlacesItemModel::groupType(int row
) const
753 return m_sourceModel
->groupType(mapToSource(row
));
756 bool PlacesItemModel::isGroupHidden(KFilePlacesModel::GroupType type
) const
758 return m_sourceModel
->isGroupHidden(type
);
761 void PlacesItemModel::setGroupHidden(KFilePlacesModel::GroupType type
, bool hidden
)
763 return m_sourceModel
->setGroupHidden(type
, hidden
);
766 QModelIndex
PlacesItemModel::mapToSource(int row
) const
768 return m_indexMap
.value(row
);
771 PlacesItem
*PlacesItemModel::itemFromBookmark(const KBookmark
&bookmark
) const
773 const QString id
= bookmarkId(bookmark
);
774 for (int i
= 0, iMax
= count(); i
< iMax
; i
++) {
775 PlacesItem
*item
= placesItem(i
);
776 const KBookmark itemBookmark
= item
->bookmark();
777 if (bookmarkId(itemBookmark
) == id
) {
784 #ifdef PLACESITEMMODEL_DEBUG
785 void PlacesItemModel::showModelState()
787 qCDebug(DolphinDebug
) << "=================================";
788 qCDebug(DolphinDebug
) << "Model:";
789 qCDebug(DolphinDebug
) << "hidden-index model-index text";
791 for (int i
= 0; i
< m_bookmarkedItems
.count(); ++i
) {
792 if (m_bookmarkedItems
[i
]) {
793 qCDebug(DolphinDebug
) << i
<< "(Hidden) " << " " << m_bookmarkedItems
[i
]->dataValue("text").toString();
795 if (item(modelIndex
)) {
796 qCDebug(DolphinDebug
) << i
<< " " << modelIndex
<< " " << item(modelIndex
)->dataValue("text").toString();
798 qCDebug(DolphinDebug
) << i
<< " " << modelIndex
<< " " << "(not available yet)";
804 qCDebug(DolphinDebug
);
805 qCDebug(DolphinDebug
) << "Bookmarks:";
807 int bookmarkIndex
= 0;
808 KBookmarkGroup root
= m_bookmarkManager
->root();
809 KBookmark bookmark
= root
.first();
810 while (!bookmark
.isNull()) {
811 const QString udi
= bookmark
.metaDataItem("UDI");
812 const QString text
= udi
.isEmpty() ? bookmark
.text() : udi
;
813 if (bookmark
.metaDataItem("IsHidden") == QLatin1String("true")) {
814 qCDebug(DolphinDebug
) << bookmarkIndex
<< "(Hidden)" << text
;
816 qCDebug(DolphinDebug
) << bookmarkIndex
<< " " << text
;
819 bookmark
= root
.next(bookmark
);