Changeset View
Changeset View
Standalone View
Standalone View
src/panels/places/placespanel.cpp
Show All 38 Lines | |||||
39 | #include "views/draganddrophelper.h" | 39 | #include "views/draganddrophelper.h" | ||
40 | 40 | | |||
41 | #include <KFilePlacesModel> | 41 | #include <KFilePlacesModel> | ||
42 | #include <KIO/DropJob> | 42 | #include <KIO/DropJob> | ||
43 | #include <KIO/EmptyTrashJob> | 43 | #include <KIO/EmptyTrashJob> | ||
44 | #include <KIO/Job> | 44 | #include <KIO/Job> | ||
45 | #include <KIconLoader> | 45 | #include <KIconLoader> | ||
46 | #include <KLocalizedString> | 46 | #include <KLocalizedString> | ||
47 | #include <KMountPoint> | ||||
47 | 48 | | |||
48 | #include <QGraphicsSceneDragDropEvent> | 49 | #include <QGraphicsSceneDragDropEvent> | ||
49 | #include <QIcon> | 50 | #include <QIcon> | ||
50 | #include <QMenu> | 51 | #include <QMenu> | ||
51 | #include <QMimeData> | 52 | #include <QMimeData> | ||
52 | #include <QVBoxLayout> | 53 | #include <QVBoxLayout> | ||
53 | 54 | | |||
54 | PlacesPanel::PlacesPanel(QWidget* parent) : | 55 | PlacesPanel::PlacesPanel(QWidget* parent) : | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 177 | if (isDevice) { | |||
177 | ejectAction = m_model->ejectAction(index); | 178 | ejectAction = m_model->ejectAction(index); | ||
178 | if (ejectAction) { | 179 | if (ejectAction) { | ||
179 | ejectAction->setParent(&menu); | 180 | ejectAction->setParent(&menu); | ||
180 | menu.addAction(ejectAction); | 181 | menu.addAction(ejectAction); | ||
181 | } | 182 | } | ||
182 | 183 | | |||
183 | teardownAction = m_model->teardownAction(index); | 184 | teardownAction = m_model->teardownAction(index); | ||
184 | if (teardownAction) { | 185 | if (teardownAction) { | ||
186 | // Disable teardown option for root and home partitions | ||||
elvisangelaccio: Please use a descriptive name for the variable (e.g. `mountPoint`). | |||||
Small optimization: we could do the mount points lookup (which isn't a trivial operation) only if we are sure item->url() is not the root path. elvisangelaccio: Small optimization: we could do the mount points lookup (which isn't a trivial operation) only… | |||||
187 | bool teardownEnabled = item->url() != QUrl::fromLocalFile(QDir::rootPath()); | ||||
188 | if (teardownEnabled) { | ||||
189 | KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(QDir::homePath()); | ||||
190 | if (mountPoint && item->url() == QUrl::fromLocalFile(mountPoint->mountPoint())) { | ||||
191 | teardownEnabled = false; | ||||
192 | } | ||||
193 | } | ||||
194 | teardownAction->setEnabled(teardownEnabled); | ||||
195 | | ||||
185 | teardownAction->setParent(&menu); | 196 | teardownAction->setParent(&menu); | ||
186 | menu.addAction(teardownAction); | 197 | menu.addAction(teardownAction); | ||
We should not hardcode "/home" here, but derive it from the user home directory. bruns: We should not hardcode "/home" here, but derive it from the user home directory. | |||||
187 | } | 198 | } | ||
188 | 199 | | |||
189 | if (item->storageSetupNeeded()) { | 200 | if (item->storageSetupNeeded()) { | ||
190 | mountAction = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount")); | 201 | mountAction = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount")); | ||
191 | } | 202 | } | ||
192 | 203 | | |||
193 | if (teardownAction || ejectAction || mountAction) { | 204 | if (teardownAction || ejectAction || mountAction) { | ||
194 | menu.addSeparator(); | 205 | menu.addSeparator(); | ||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |
Please use a descriptive name for the variable (e.g. mountPoint).