#include "dolphin_generalsettings.h"
#include "dolphindebug.h"
+#include "dolphinplacesmodelsingleton.h"
#include "placesitem.h"
#include "placesitemsignalhandler.h"
#include "views/dolphinview.h"
#include <QTimer>
namespace {
- // A suffix to the application-name of the stored bookmarks is
- // added, which is only read by PlacesItemModel.
- const QString AppNameSuffix = QStringLiteral("-places-panel");
static QList<QUrl> balooURLs = {
QUrl(QStringLiteral("timeline:/today")),
QUrl(QStringLiteral("timeline:/yesterday")),
m_hiddenItemsShown(false),
m_deviceToTearDown(nullptr),
m_storageSetupInProgress(),
- m_sourceModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + AppNameSuffix, this))
+ m_sourceModel(DolphinPlacesModelSingleton::instance().placesModel())
{
cleanupBookmarks();
loadBookmarks();
initializeDefaultViewProperties();
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged);
+ connect(m_sourceModel, &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted);
+ connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved);
+ connect(m_sourceModel, &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged);
+ connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved);
+ connect(m_sourceModel, &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved);
+ connect(m_sourceModel, &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged);
}
PlacesItemModel::~PlacesItemModel()
}
}
}
-
-#ifdef PLACESITEMMODEL_DEBUG
- qCDebug(DolphinDebug) << "Changed visibility of hidden items";
- showModelState();
-#endif
}
bool PlacesItemModel::hiddenItemsShown() const
void PlacesItemModel::onItemInserted(int index)
{
KStandardItemModel::onItemInserted(index);
-#ifdef PLACESITEMMODEL_DEBUG
- qCDebug(DolphinDebug) << "Inserted item" << index;
- showModelState();
-#endif
}
void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem)
m_indexMap.removeAt(index);
KStandardItemModel::onItemRemoved(index, removedItem);
-#ifdef PLACESITEMMODEL_DEBUG
- qCDebug(DolphinDebug) << "Removed item" << index;
- showModelState();
-#endif
}
void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRoles)
const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index);
Q_ASSERT(!bookmark.isNull());
- PlacesItem *item = itemFromBookmark(bookmark);
- if (!item) {
- item = new PlacesItem(bookmark);
- }
+ PlacesItem *item = new PlacesItem(bookmark);
updateItem(item, index);
insertSortedItem(item);
} else if (path == QLatin1String("/images")) {
props.setViewMode(DolphinView::IconsView);
props.setPreviewsShown(true);
- props.setVisibleRoles({"text", "imageSize"});
+ props.setVisibleRoles({"text", "height", "width"});
} else if (path == QLatin1String("/audio")) {
props.setViewMode(DolphinView::DetailsView);
props.setPreviewsShown(false);
void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden)
{
- for(const QModelIndex &sourceIndex : m_sourceModel->groupIndexes(group)) {
+ const auto groupIndexes = m_sourceModel->groupIndexes(group);
+ for (const QModelIndex &sourceIndex : groupIndexes) {
PlacesItem *item = placesItem(mapFromSource(sourceIndex));
if (item) {
item->setGroupHidden(hidden);
const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp"));
if ((appName == KAboutData::applicationData().componentName() ||
- appName == KAboutData::applicationData().componentName() + AppNameSuffix) && balooURLs.contains(url)) {
+ appName == KAboutData::applicationData().componentName() + DolphinPlacesModelSingleton::applicationNameSuffix()) && balooURLs.contains(url)) {
qCDebug(DolphinDebug) << "Removing old baloo url:" << url;
m_sourceModel->removePlace(sourceIndex);
} else {
addItemFromSourceModel(sourceIndex);
}
}
-
-#ifdef PLACESITEMMODEL_DEBUG
- qCDebug(DolphinDebug) << "Loaded bookmarks";
- showModelState();
-#endif
}
void PlacesItemModel::clear() {
return nullptr;
}
-#ifdef PLACESITEMMODEL_DEBUG
-void PlacesItemModel::showModelState()
-{
- qCDebug(DolphinDebug) << "=================================";
- qCDebug(DolphinDebug) << "Model:";
- qCDebug(DolphinDebug) << "hidden-index model-index text";
- int modelIndex = 0;
- for (int i = 0; i < m_bookmarkedItems.count(); ++i) {
- if (m_bookmarkedItems[i]) {
- qCDebug(DolphinDebug) << i << "(Hidden) " << " " << m_bookmarkedItems[i]->dataValue("text").toString();
- } else {
- if (item(modelIndex)) {
- qCDebug(DolphinDebug) << i << " " << modelIndex << " " << item(modelIndex)->dataValue("text").toString();
- } else {
- qCDebug(DolphinDebug) << i << " " << modelIndex << " " << "(not available yet)";
- }
- ++modelIndex;
- }
- }
-
- qCDebug(DolphinDebug);
- qCDebug(DolphinDebug) << "Bookmarks:";
-
- int bookmarkIndex = 0;
- KBookmarkGroup root = m_bookmarkManager->root();
- KBookmark bookmark = root.first();
- while (!bookmark.isNull()) {
- const QString udi = bookmark.metaDataItem("UDI");
- const QString text = udi.isEmpty() ? bookmark.text() : udi;
- if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) {
- qCDebug(DolphinDebug) << bookmarkIndex << "(Hidden)" << text;
- } else {
- qCDebug(DolphinDebug) << bookmarkIndex << " " << text;
- }
-
- bookmark = root.next(bookmark);
- ++bookmarkIndex;
- }
-}
-#endif
-