X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f16fbcba4e9ed3cd48cb2c1a40c01daf1d511f4b..0bc919bd4758a84ccc0928ff784223984ec5df88:/src/panels/places/placespanel.cpp diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 216b76038..a2f0e0655 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -30,7 +30,6 @@ #include "kitemviews/kitemlistselectionmanager.h" #include "kitemviews/kstandarditem.h" #include "placesitem.h" -#include "placesitemeditdialog.h" #include "placesitemlistgroupheader.h" #include "placesitemlistwidget.h" #include "placesitemmodel.h" @@ -38,22 +37,20 @@ #include "trash/dolphintrash.h" #include "views/draganddrophelper.h" -#include -#include +#include #include #include #include #include -#include #include -#include #include -#include -#include +#include +#include #include #include #include +#include #include PlacesPanel::PlacesPanel(QWidget* parent) : @@ -96,8 +93,8 @@ bool PlacesPanel::urlChanged() void PlacesPanel::readSettings() { if (m_controller) { - const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; - m_controller->setAutoActivationDelay(delay); + const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; + m_controller->setAutoActivationDelay(delay); } } @@ -142,7 +139,7 @@ void PlacesPanel::showEvent(QShowEvent* event) container->setEnabledFrame(false); QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(container); selectClosestItem(); @@ -174,11 +171,26 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) QAction* editAction = nullptr; QAction* teardownAction = nullptr; QAction* ejectAction = nullptr; - - const QString label = item->text(); + QAction* mountAction = nullptr; const bool isDevice = !item->udi().isEmpty(); const bool isTrash = (item->url().scheme() == QLatin1String("trash")); + if (isTrash) { + emptyTrashAction = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash")); + emptyTrashAction->setEnabled(item->icon() == QLatin1String("user-trash-full")); + menu.addSeparator(); + } + + QAction* openInNewWindowAction = menu.addAction(QIcon::fromTheme(QStringLiteral("window-new")), i18nc("@item:inmenu", "Open in New Window")); + QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@item:inmenu", "Open in New Tab")); + QAction* propertiesAction = nullptr; + if (item->url().isLocalFile()) { + propertiesAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18nc("@action:inmenu", "Properties")); + } + if (!isDevice && !isTrash) { + menu.addSeparator(); + } + if (isDevice) { ejectAction = m_model->ejectAction(index); if (ejectAction) { @@ -188,29 +200,31 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) teardownAction = m_model->teardownAction(index); if (teardownAction) { + // Disable teardown option for root and home partitions + bool teardownEnabled = item->url() != QUrl::fromLocalFile(QDir::rootPath()); + if (teardownEnabled) { + KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(QDir::homePath()); + if (mountPoint && item->url() == QUrl::fromLocalFile(mountPoint->mountPoint())) { + teardownEnabled = false; + } + } + teardownAction->setEnabled(teardownEnabled); + teardownAction->setParent(&menu); menu.addAction(teardownAction); } - if (teardownAction || ejectAction) { - menu.addSeparator(); + if (item->storageSetupNeeded()) { + mountAction = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount")); } - } else { - if (isTrash) { - emptyTrashAction = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash")); - emptyTrashAction->setEnabled(item->icon() == QLatin1String("user-trash-full")); + + if (teardownAction || ejectAction || mountAction) { menu.addSeparator(); } } - QAction* openInNewWindowAction = menu.addAction(QIcon::fromTheme("window-new"), i18nc("@item:inmenu", "Open in New Window")); - QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@item:inmenu", "Open in New Tab")); - if (!isDevice && !isTrash) { - menu.addSeparator(); - } - if (!isDevice) { - editAction = menu.addAction(QIcon::fromTheme("document-properties"), i18nc("@item:inmenu", "Edit...")); + editAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-entry")), i18nc("@item:inmenu", "Edit...")); } QAction* removeAction = nullptr; @@ -218,7 +232,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove")); } - QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide")); + QAction* hideAction = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Hide")); hideAction->setCheckable(true); hideAction->setChecked(item->isHidden()); @@ -244,16 +258,25 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) m_model->deleteItem(index); } else if (action == hideAction) { item->setHidden(hideAction->isChecked()); + if (!m_model->hiddenCount()) { + showHiddenEntries(false); + } } else if (action == openInNewWindowAction) { Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(m_model->data(index).value("url").toUrl())}, this); } else if (action == openInNewTabAction) { // TriggerItem does set up the storage first and then it will // emit the slotItemMiddleClicked signal, because of Qt::MiddleButton. triggerItem(index, Qt::MiddleButton); + } else if (action == mountAction) { + m_model->requestStorageSetup(index); } else if (action == teardownAction) { m_model->requestTearDown(index); } else if (action == ejectAction) { m_model->requestEject(index); + } else if (action == propertiesAction) { + KPropertiesDialog* dialog = new KPropertiesDialog(item->url(), this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } } } @@ -267,12 +290,11 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) QAction* addAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@item:inmenu", "Add Entry...")); - QAction* showAllAction = nullptr; - if (m_model->hiddenCount() > 0) { - showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries")); - showAllAction->setCheckable(true); - showAllAction->setChecked(m_model->hiddenItemsShown()); - } + QAction* showAllAction = menu.addAction(i18nc("@item:inmenu", "Show Hidden Places")); + showAllAction->setCheckable(true); + showAllAction->setChecked(m_model->hiddenItemsShown()); + showAllAction->setIcon(QIcon::fromTheme(m_model->hiddenItemsShown() ? QStringLiteral("visibility") : QStringLiteral("hint"))); + showAllAction->setEnabled(m_model->hiddenCount()); buildGroupContextMenu(&menu, m_controller->indexCloseToMousePressedPosition()); @@ -293,7 +315,7 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) {KIconLoader::SizeLarge, I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")} }; - QMap iconSizeActionMap; + QHash iconSizeActionMap; QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu); for (int i = 0; i < iconSizeCount; ++i) { @@ -320,7 +342,7 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) if (action == addAction) { addEntry(); } else if (action == showAllAction) { - m_model->setHiddenItemsShown(showAllAction->isChecked()); + showHiddenEntries(showAllAction->isChecked()); } else if (iconSizeActionMap.contains(action)) { m_view->setIconSize(iconSizeActionMap.value(action)); } @@ -336,12 +358,15 @@ QAction *PlacesPanel::buildGroupContextMenu(QMenu *menu, int index) } KFilePlacesModel::GroupType groupType = m_model->groupType(index); - QAction *hideGroupAction = menu->addAction(i18nc("@item:inmenu", "Hide Section '%1'", m_model->item(index)->group())); + QAction *hideGroupAction = menu->addAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Hide Section '%1'", m_model->item(index)->group())); hideGroupAction->setCheckable(true); hideGroupAction->setChecked(m_model->isGroupHidden(groupType)); connect(hideGroupAction, &QAction::triggered, this, [this, groupType, hideGroupAction]{ m_model->setGroupHidden(groupType, hideGroupAction->isChecked()); + if (!m_model->hiddenCount()) { + showHiddenEntries(false); + } }); return hideGroupAction; @@ -449,13 +474,12 @@ void PlacesPanel::addEntry() { const int index = m_controller->selectionManager()->currentItem(); const QUrl url = m_model->data(index).value("url").toUrl(); + const QString text = url.fileName().isEmpty() ? url.toDisplayString(QUrl::PreferLocalFile) : url.fileName(); - QPointer dialog = new PlacesItemEditDialog(this); - dialog->setWindowTitle(i18nc("@title:window", "Add Places Entry")); - dialog->setAllowGlobal(true); - dialog->setUrl(url); + QPointer dialog = new KFilePlaceEditDialog(true, url, text, QString(), true, false, KIconLoader::SizeMedium, this); if (dialog->exec() == QDialog::Accepted) { - m_model->createPlacesItem(dialog->text(), dialog->url(), dialog->icon()); + const QString appName = dialog->applicationLocal() ? QCoreApplication::applicationName() : QString(); + m_model->createPlacesItem(dialog->label(), dialog->url(), dialog->icon(), appName); } delete dialog; @@ -464,17 +488,18 @@ void PlacesPanel::addEntry() void PlacesPanel::editEntry(int index) { QHash data = m_model->data(index); + const QUrl url = data.value("url").toUrl(); + const QString text = data.value("text").toString(); + const QString iconName = data.value("iconName").toString(); + const bool applicationLocal = !data.value("applicationName").toString().isEmpty(); - QPointer dialog = new PlacesItemEditDialog(this); - dialog->setWindowTitle(i18nc("@title:window", "Edit Places Entry")); - dialog->setIcon(data.value("iconName").toString()); - dialog->setText(data.value("text").toString()); - dialog->setUrl(data.value("url").toUrl()); - dialog->setAllowGlobal(true); + QPointer dialog = new KFilePlaceEditDialog(true, url, text, iconName, true, applicationLocal, KIconLoader::SizeMedium, this); if (dialog->exec() == QDialog::Accepted) { PlacesItem* oldItem = m_model->placesItem(index); if (oldItem) { - oldItem->setText(dialog->text()); + const QString appName = dialog->applicationLocal() ? QCoreApplication::applicationName() : QString(); + oldItem->setApplicationName(appName); + oldItem->setText(dialog->label()); oldItem->setUrl(dialog->url()); oldItem->setIcon(dialog->icon()); m_model->refresh(); @@ -521,3 +546,17 @@ void PlacesPanel::triggerItem(int index, Qt::MouseButton button) } } } + +void PlacesPanel::showHiddenEntries(bool shown) +{ + m_model->setHiddenItemsShown(shown); + emit showHiddenEntriesChanged(shown); +} + +int PlacesPanel::hiddenListCount() +{ + if(!m_model) { + return 0; + } + return m_model->hiddenCount(); +}