#include "dolphin_generalsettings.h"
#include <KBookmark>
-#include <KBookmarkGroup>
#include <KBookmarkManager>
-#include <KDebug>
+#include "dolphindebug.h"
#include <QIcon>
-#include <kprotocolinfo.h>
+#include <KProtocolInfo>
#include <KLocalizedString>
-#include <KComponentData>
#include <QStandardPaths>
#include <KUser>
#include <KAboutData>
Baloo::IndexerConfig config;
m_fileIndexingEnabled = config.fileIndexingEnabled();
#endif
- const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kfileplaces/bookmarks.xml");
- m_bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces");
+ const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel";
+ m_bookmarkManager = KBookmarkManager::managerForExternalFile(file);
createSystemBookmarks();
initializeAvailableDevices();
connect(m_bookmarkManager, &KBookmarkManager::changed,
m_updateBookmarksTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
- connect(m_bookmarkManager, &KBookmarkManager::bookmarksChanged,
- m_updateBookmarksTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
}
PlacesItemModel::~PlacesItemModel()
{
- saveBookmarks();
qDeleteAll(m_bookmarkedItems);
m_bookmarkedItems.clear();
}
}
#ifdef PLACESITEMMODEL_DEBUG
- kDebug() << "Changed visibility of hidden items";
+ qCDebug(DolphinDebug) << "Changed visibility of hidden items";
showModelState();
#endif
}
{
const PlacesItem* item = placesItem(index);
if (item && item->device().is<Solid::OpticalDisc>()) {
- return new QAction(QIcon::fromTheme("media-eject"), i18nc("@item", "Eject '%1'", item->text()), 0);
+ return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject '%1'", item->text()), 0);
}
return 0;
text = i18nc("@item", "Release '%1'", label);
} else if (removable || hotPluggable) {
text = i18nc("@item", "Safely Remove '%1'", label);
- iconName = "media-eject";
+ iconName = QStringLiteral("media-eject");
} else {
text = i18nc("@item", "Unmount '%1'", label);
- iconName = "media-eject";
+ iconName = QStringLiteral("media-eject");
}
if (iconName.isEmpty()) {
QDataStream stream(&itemData, QIODevice::WriteOnly);
- foreach (int index, indexes) {
+ for (int index : indexes) {
const QUrl itemUrl = placesItem(index)->url();
if (itemUrl.isValid()) {
urls << itemUrl;
const int dropIndex = groupedDropIndex(index, newItem);
insertItem(dropIndex, newItem);
- } else if (mimeData->hasFormat("text/uri-list")) {
+ } else if (mimeData->hasFormat(QStringLiteral("text/uri-list"))) {
// One or more items must be added to the model
const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
for (int i = urls.count() - 1; i >= 0; --i) {
}
if ((url.isLocalFile() && !QFileInfo(url.toLocalFile()).isDir())
- || url.scheme() == "trash") {
+ || url.scheme() == QLatin1String("trash")) {
// Only directories outside the trash are allowed
continue;
}
}
#ifdef PLACESITEMMODEL_DEBUG
- kDebug() << "Inserted item" << index;
+ qCDebug(DolphinDebug) << "Inserted item" << index;
showModelState();
#endif
}
m_bookmarkedItems.removeAt(boomarkIndex);
#ifdef PLACESITEMMODEL_DEBUG
- kDebug() << "Removed item" << index;
+ qCDebug(DolphinDebug) << "Removed item" << index;
showModelState();
#endif
}
if (changedRoles.contains("isHidden")) {
if (!m_hiddenItemsShown && changedItem->isHidden()) {
m_hiddenItemToRemove = index;
- QTimer::singleShot(0, this, SLOT(hideItem()));
+ QTimer::singleShot(0, this, static_cast<void (PlacesItemModel::*)()>(&PlacesItemModel::hideItem));
}
}
}
// a hidden item. The content of the bookmark might
// have been changed, so an update is done.
found = true;
- if (newBookmark.metaDataItem("UDI").isEmpty()) {
+ if (newBookmark.metaDataItem(QStringLiteral("UDI")).isEmpty()) {
item->setBookmark(newBookmark);
item->setText(i18nc("KFile System Bookmarks", newBookmark.text().toUtf8().constData()));
}
}
if (!found) {
- const QString udi = newBookmark.metaDataItem("UDI");
+ const QString udi = newBookmark.metaDataItem(QStringLiteral("UDI"));
/*
* See Bug 304878
}
// Create items for devices that have not been stored as bookmark yet
+ devicesItems.reserve(devicesItems.count() + devices.count());
foreach (const QString& udi, devices) {
const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi);
devicesItems.append(new PlacesItem(bookmark));
}
#ifdef PLACESITEMMODEL_DEBUG
- kDebug() << "Loaded bookmarks";
+ qCDebug(DolphinDebug) << "Loaded bookmarks";
showModelState();
#endif
}
bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark,
const QSet<QString>& availableDevices) const
{
- const QString udi = bookmark.metaDataItem("UDI");
+ const QString udi = bookmark.metaDataItem(QStringLiteral("UDI"));
const QUrl url = bookmark.url();
- const QString appName = bookmark.metaDataItem("OnlyInApp");
+ const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp"));
const bool deviceAvailable = availableDevices.contains(udi);
const bool allowedHere = (appName.isEmpty()
// for "Recently Saved" and "Search For" should be a setting available only
// in the Places Panel (see description of AppNamePrefix for more details).
const QString appName = KAboutData::applicationData().componentName() + AppNamePrefix;
- bookmark.setMetaDataItem("OnlyInApp", appName);
+ bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), appName);
}
PlacesItem* item = new PlacesItem(bookmark);
props.setViewMode(DolphinView::IconsView);
props.setPreviewsShown(true);
props.setVisibleRoles({"text"});
- } else if (data.url.scheme() == "timeline") {
+ } else if (data.url.scheme() == QLatin1String("timeline")) {
props.setViewMode(DolphinView::DetailsView);
- props.setVisibleRoles({"text", "date"});
+ props.setVisibleRoles({"text", "modificationtime"});
}
}
}
// done here is because otherwise switching the language would not result in retranslating the
// bookmarks.
m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile(KUser().homeDir()),
- "user-home",
+ QStringLiteral("user-home"),
I18N_NOOP2("KFile System Bookmarks", "Home")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("remote:/"),
- "network-workgroup",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("remote:/")),
+ QStringLiteral("network-workgroup"),
I18N_NOOP2("KFile System Bookmarks", "Network")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile("/"),
- "folder-red",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile(QStringLiteral("/")),
+ QStringLiteral("folder-red"),
I18N_NOOP2("KFile System Bookmarks", "Root")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("trash:/"),
- "user-trash",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("trash:/")),
+ QStringLiteral("user-trash"),
I18N_NOOP2("KFile System Bookmarks", "Trash")));
if (m_fileIndexingEnabled) {
- m_systemBookmarks.append(SystemBookmarkData(QUrl("timeline:/today"),
- "go-jump-today",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/today")),
+ QStringLiteral("go-jump-today"),
I18N_NOOP2("KFile System Bookmarks", "Today")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("timeline:/yesterday"),
- "view-calendar-day",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/yesterday")),
+ QStringLiteral("view-calendar-day"),
I18N_NOOP2("KFile System Bookmarks", "Yesterday")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("timeline:/thismonth"),
- "view-calendar-month",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/thismonth")),
+ QStringLiteral("view-calendar-month"),
I18N_NOOP2("KFile System Bookmarks", "This Month")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("timeline:/lastmonth"),
- "view-calendar-month",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/lastmonth")),
+ QStringLiteral("view-calendar-month"),
I18N_NOOP2("KFile System Bookmarks", "Last Month")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/documents"),
- "folder-txt",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/documents")),
+ QStringLiteral("folder-text"),
I18N_NOOP2("KFile System Bookmarks", "Documents")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/images"),
- "folder-image",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/images")),
+ QStringLiteral("folder-images"),
I18N_NOOP2("KFile System Bookmarks", "Images")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/audio"),
- "folder-sound",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/audio")),
+ QStringLiteral("folder-sound"),
I18N_NOOP2("KFile System Bookmarks", "Audio Files")));
- m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/videos"),
- "folder-video",
+ m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/videos")),
+ QStringLiteral("folder-videos"),
I18N_NOOP2("KFile System Bookmarks", "Videos")));
}
void PlacesItemModel::initializeAvailableDevices()
{
- QString predicate("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]"
+ QString predicate(QStringLiteral("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]"
" OR "
"[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]"
" OR "
"OpticalDisc.availableContent & 'Audio' ]"
" OR "
- "StorageAccess.ignored == false ]");
+ "StorageAccess.ignored == false ]"));
- if (KProtocolInfo::isKnownProtocol("mtp")) {
+ if (KProtocolInfo::isKnownProtocol(QStringLiteral("mtp"))) {
predicate.prepend("[");
predicate.append(" OR PortableMediaPlayer.supportedProtocols == 'mtp']");
}
bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark& b1, const KBookmark& b2)
{
- const QString udi1 = b1.metaDataItem("UDI");
- const QString udi2 = b2.metaDataItem("UDI");
+ const QString udi1 = b1.metaDataItem(QStringLiteral("UDI"));
+ const QString udi2 = b2.metaDataItem(QStringLiteral("UDI"));
if (!udi1.isEmpty() && !udi2.isEmpty()) {
return udi1 == udi2;
} else {
- return b1.metaDataItem("ID") == b2.metaDataItem("ID");
+ return b1.metaDataItem(QStringLiteral("ID")) == b2.metaDataItem(QStringLiteral("ID"));
}
}
const int year = date.year();
const int month = date.month();
const int day = date.day();
- timelineUrl = "timeline:/" + timelineDateString(year, month) +
- '/' + timelineDateString(year, month, day);
+ timelineUrl = QUrl("timeline:/" + timelineDateString(year, month) +
+ '/' + timelineDateString(year, month, day));
} else if (path.endsWith(QLatin1String("thismonth"))) {
const QDate date = QDate::currentDate();
- timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
+ timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month()));
} else if (path.endsWith(QLatin1String("lastmonth"))) {
const QDate date = QDate::currentDate().addMonths(-1);
- timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
+ timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month()));
} else {
Q_ASSERT(path.endsWith(QLatin1String("today")));
- timelineUrl= url;
+ timelineUrl = url;
}
return timelineUrl;
#ifdef HAVE_BALOO
const QString path = url.toDisplayString(QUrl::PreferLocalFile);
if (path.endsWith(QLatin1String("documents"))) {
- searchUrl = searchUrlForType("Document");
+ searchUrl = searchUrlForType(QStringLiteral("Document"));
} else if (path.endsWith(QLatin1String("images"))) {
- searchUrl = searchUrlForType("Image");
+ searchUrl = searchUrlForType(QStringLiteral("Image"));
} else if (path.endsWith(QLatin1String("audio"))) {
- searchUrl = searchUrlForType("Audio");
+ searchUrl = searchUrlForType(QStringLiteral("Audio"));
} else if (path.endsWith(QLatin1String("videos"))) {
- searchUrl = searchUrlForType("Video");
+ searchUrl = searchUrlForType(QStringLiteral("Video"));
} else {
Q_ASSERT(false);
}
QUrl PlacesItemModel::searchUrlForType(const QString& type)
{
Baloo::Query query;
- query.addType("File");
query.addType(type);
return query.toSearchUrl();
#ifdef PLACESITEMMODEL_DEBUG
void PlacesItemModel::showModelState()
{
- kDebug() << "=================================";
- kDebug() << "Model:";
- kDebug() << "hidden-index model-index text";
+ 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]) {
- kDebug() << i << "(Hidden) " << " " << m_bookmarkedItems[i]->dataValue("text").toString();
+ qCDebug(DolphinDebug) << i << "(Hidden) " << " " << m_bookmarkedItems[i]->dataValue("text").toString();
} else {
if (item(modelIndex)) {
- kDebug() << i << " " << modelIndex << " " << item(modelIndex)->dataValue("text").toString();
+ qCDebug(DolphinDebug) << i << " " << modelIndex << " " << item(modelIndex)->dataValue("text").toString();
} else {
- kDebug() << i << " " << modelIndex << " " << "(not available yet)";
+ qCDebug(DolphinDebug) << i << " " << modelIndex << " " << "(not available yet)";
}
++modelIndex;
}
}
- kDebug();
- kDebug() << "Bookmarks:";
+ qCDebug(DolphinDebug);
+ qCDebug(DolphinDebug) << "Bookmarks:";
int bookmarkIndex = 0;
KBookmarkGroup root = m_bookmarkManager->root();
const QString udi = bookmark.metaDataItem("UDI");
const QString text = udi.isEmpty() ? bookmark.text() : udi;
if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) {
- kDebug() << bookmarkIndex << "(Hidden)" << text;
+ qCDebug(DolphinDebug) << bookmarkIndex << "(Hidden)" << text;
} else {
- kDebug() << bookmarkIndex << " " << text;
+ qCDebug(DolphinDebug) << bookmarkIndex << " " << text;
}
bookmark = root.next(bookmark);