Changeset View
Changeset View
Standalone View
Standalone View
kcms/baloo/filteredfoldermodel.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 40 | QStringList addTrailingSlashes(const QStringList& input) { | |||
---|---|---|---|---|---|
48 | return output; | 48 | return output; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | QString makeHomePretty(const QString& url) { | 51 | QString makeHomePretty(const QString& url) { | ||
52 | if (url.startsWith(QDir::homePath())) | 52 | if (url.startsWith(QDir::homePath())) | ||
53 | return QString(url).replace(0, QDir::homePath().length(), QStringLiteral("~")); | 53 | return QString(url).replace(0, QDir::homePath().length(), QStringLiteral("~")); | ||
54 | return url; | 54 | return url; | ||
55 | } | 55 | } | ||
56 | | ||||
57 | bool ignoredMountPoint(const QString& mountPoint) { | ||||
58 | if (mountPoint == QLatin1String("/")) | ||||
59 | return true; | ||||
60 | | ||||
61 | if (mountPoint.startsWith(QLatin1String("/boot"))) | ||||
62 | return true; | ||||
63 | | ||||
64 | if (mountPoint.startsWith(QLatin1String("/tmp"))) | ||||
65 | return true; | ||||
66 | | ||||
67 | // The user's home directory is forcibly added so we can ignore /home | ||||
68 | // if /home actually contains the home directory | ||||
69 | return mountPoint.startsWith(QLatin1String("/home")) && | ||||
70 | QDir::homePath().startsWith(QLatin1String("/home")); | ||||
71 | } | ||||
56 | } | 72 | } | ||
57 | 73 | | |||
58 | FilteredFolderModel::FilteredFolderModel(BalooSettings *settings, QObject *parent) | 74 | FilteredFolderModel::FilteredFolderModel(BalooSettings *settings, QObject *parent) | ||
59 | : QAbstractListModel(parent) | 75 | : QAbstractListModel(parent) | ||
60 | , m_settings(settings) | 76 | , m_settings(settings) | ||
61 | { | 77 | { | ||
62 | } | 78 | } | ||
63 | 79 | | |||
64 | void FilteredFolderModel::updateDirectoryList() | 80 | void FilteredFolderModel::updateDirectoryList() | ||
65 | { | 81 | { | ||
66 | beginResetModel(); | 82 | beginResetModel(); | ||
67 | 83 | | |||
68 | m_mountPoints.clear(); | 84 | m_mountPoints.clear(); | ||
69 | 85 | | |||
70 | QList<Solid::Device> devices = Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess); | 86 | QList<Solid::Device> devices = Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess); | ||
71 | 87 | | |||
72 | for (const Solid::Device& dev : devices) { | 88 | for (const Solid::Device& dev : devices) { | ||
73 | const Solid::StorageAccess* sa = dev.as<Solid::StorageAccess>(); | 89 | const Solid::StorageAccess* sa = dev.as<Solid::StorageAccess>(); | ||
74 | if (!sa->isAccessible()) | 90 | if (!sa->isAccessible()) | ||
75 | continue; | 91 | continue; | ||
76 | 92 | | |||
77 | const QString mountPath = sa->filePath(); | 93 | const QString mountPath = sa->filePath(); | ||
78 | if (!shouldShowMountPoint(mountPath)) | 94 | if (ignoredMountPoint(mountPath)) | ||
79 | continue; | 95 | continue; | ||
80 | 96 | | |||
81 | m_mountPoints.append(mountPath); | 97 | m_mountPoints.append(mountPath); | ||
82 | } | 98 | } | ||
83 | m_mountPoints.append(QDir::homePath()); | 99 | m_mountPoints.append(QDir::homePath()); | ||
84 | m_mountPoints = addTrailingSlashes(m_mountPoints); | 100 | m_mountPoints = addTrailingSlashes(m_mountPoints); | ||
85 | 101 | | |||
86 | QStringList includeList = addTrailingSlashes(m_settings->folders()); | 102 | QStringList includeList = addTrailingSlashes(m_settings->folders()); | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 200 | { | |||
204 | } | 220 | } | ||
205 | 221 | | |||
206 | if (name.endsWith(QLatin1Char('/'))) { | 222 | if (name.endsWith(QLatin1Char('/'))) { | ||
207 | name = name.mid(0, name.size() - 1); | 223 | name = name.mid(0, name.size() - 1); | ||
208 | } | 224 | } | ||
209 | return name; | 225 | return name; | ||
210 | } | 226 | } | ||
211 | 227 | | |||
212 | bool FilteredFolderModel::shouldShowMountPoint(const QString& mountPoint) | | |||
213 | { | | |||
214 | if (mountPoint == QLatin1String("/")) | | |||
215 | return false; | | |||
216 | | ||||
217 | if (mountPoint.startsWith(QLatin1String("/boot"))) | | |||
218 | return false; | | |||
219 | | ||||
220 | if (mountPoint.startsWith(QLatin1String("/tmp"))) | | |||
221 | return false; | | |||
222 | | ||||
223 | // The user's home directory is forcibly added so we can ignore /home | | |||
224 | // if /home actually contains the home directory | | |||
225 | return !(mountPoint.startsWith(QLatin1String("/home")) || !QDir::homePath().startsWith(QLatin1String("/home"))); | | |||
226 | } | | |||
227 | | ||||
228 | QHash<int, QByteArray> FilteredFolderModel::roleNames() const | 228 | QHash<int, QByteArray> FilteredFolderModel::roleNames() const | ||
229 | { | 229 | { | ||
230 | return { | 230 | return { | ||
231 | {Url, "url"}, | 231 | {Url, "url"}, | ||
232 | {Folder, "folder"}, | 232 | {Folder, "folder"}, | ||
233 | {Qt::DecorationRole, "decoration"} | 233 | {Qt::DecorationRole, "decoration"} | ||
234 | }; | 234 | }; | ||
235 | } | 235 | } | ||
Show All 20 Lines |