mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +00:00
[PlacesPanel] Port to KFilePlaceEditDialog
Summary: This patch ports away from the old PlacesItemEditDialog copy, which doesn't honour the "applicationLocal" checkbox. KFilePlaceEditDialog was not exported by KIO, but it will be starting from 5.53 BUG: 376619 FIXED-IN: 19.03.80 Test Plan: * Create a new place ("Add Entry" from the panel context menu) and check the "only show in dolphin" checkbox * Edit an existing (global) place and check the "only show in dolphin" checkbox Reviewers: #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D16824
This commit is contained in:
parent
2a96387f76
commit
b5df5f4d95
|
@ -8,7 +8,7 @@ set (KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATI
|
|||
project(Dolphin VERSION ${KDE_APPLICATIONS_VERSION})
|
||||
|
||||
set(QT_MIN_VERSION "5.8.0")
|
||||
set(KF5_MIN_VERSION "5.43.0")
|
||||
set(KF5_MIN_VERSION "5.53.0")
|
||||
|
||||
# ECM setup
|
||||
find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
|
||||
|
|
|
@ -201,7 +201,6 @@ set(dolphinstatic_SRCS
|
|||
filterbar/filterbar.cpp
|
||||
panels/places/placespanel.cpp
|
||||
panels/places/placesitem.cpp
|
||||
panels/places/placesitemeditdialog.cpp
|
||||
panels/places/placesitemlistgroupheader.cpp
|
||||
panels/places/placesitemlistwidget.cpp
|
||||
panels/places/placesitemmodel.cpp
|
||||
|
|
|
@ -1,174 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
|
||||
* *
|
||||
* Based on KFilePlaceEditDialog from kdelibs: *
|
||||
* Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org> *
|
||||
* Copyright (C) 2007 Kevin Ottens <ervin@kde.org> * *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include "placesitemeditdialog.h"
|
||||
|
||||
#include "dolphindebug.h"
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KFile>
|
||||
#include <KIconButton>
|
||||
#include <KLocalizedString>
|
||||
#include <KUrlRequester>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QEvent>
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QMimeDatabase>
|
||||
|
||||
PlacesItemEditDialog::PlacesItemEditDialog(QWidget* parent) :
|
||||
QDialog(parent),
|
||||
m_icon(),
|
||||
m_text(),
|
||||
m_url(),
|
||||
m_allowGlobal(false),
|
||||
m_urlEdit(nullptr),
|
||||
m_textEdit(nullptr),
|
||||
m_iconButton(nullptr),
|
||||
m_appLocal(nullptr),
|
||||
m_buttonBox(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::setIcon(const QString& icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
QString PlacesItemEditDialog::icon() const
|
||||
{
|
||||
return m_iconButton ? m_iconButton->icon() : m_icon;
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::setText(const QString& text)
|
||||
{
|
||||
m_text = text;
|
||||
}
|
||||
|
||||
QString PlacesItemEditDialog::text() const
|
||||
{
|
||||
QString text = m_textEdit->text();
|
||||
if (text.isEmpty()) {
|
||||
const QUrl url = m_urlEdit->url();
|
||||
text = url.fileName().isEmpty() ? url.toDisplayString(QUrl::PreferLocalFile) : url.fileName();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::setUrl(const QUrl& url)
|
||||
{
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
QUrl PlacesItemEditDialog::url() const
|
||||
{
|
||||
return m_urlEdit->url();
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::setAllowGlobal(bool allow)
|
||||
{
|
||||
m_allowGlobal = allow;
|
||||
}
|
||||
|
||||
bool PlacesItemEditDialog::allowGlobal() const
|
||||
{
|
||||
return m_allowGlobal;
|
||||
}
|
||||
|
||||
bool PlacesItemEditDialog::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::Polish) {
|
||||
initialize();
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::slotUrlChanged(const QString& text)
|
||||
{
|
||||
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
|
||||
}
|
||||
|
||||
PlacesItemEditDialog::~PlacesItemEditDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void PlacesItemEditDialog::initialize()
|
||||
{
|
||||
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
|
||||
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &PlacesItemEditDialog::accept);
|
||||
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &PlacesItemEditDialog::reject);
|
||||
setModal(true);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
setLayout(mainLayout);
|
||||
QWidget* mainWidget = new QWidget(this);
|
||||
mainLayout->addWidget(mainWidget);
|
||||
mainLayout->addWidget(m_buttonBox);
|
||||
|
||||
QVBoxLayout* vBox = new QVBoxLayout(mainWidget);
|
||||
|
||||
QFormLayout* formLayout = new QFormLayout();
|
||||
vBox->addLayout( formLayout );
|
||||
|
||||
m_textEdit = new QLineEdit(mainWidget);
|
||||
formLayout->addRow(i18nc("@label", "Label:"), m_textEdit);
|
||||
m_textEdit->setText(m_text);
|
||||
m_textEdit->setPlaceholderText(i18n("Enter descriptive label here"));
|
||||
|
||||
m_urlEdit = new KUrlRequester(m_url, mainWidget);
|
||||
m_urlEdit->setMode(KFile::Directory);
|
||||
formLayout->addRow(i18nc("@label", "Location:"), m_urlEdit);
|
||||
// Provide room for at least 40 chars (average char width is half of height)
|
||||
m_urlEdit->setMinimumWidth(m_urlEdit->fontMetrics().height() * (40 / 2));
|
||||
connect(m_urlEdit, &KUrlRequester::textChanged, this, &PlacesItemEditDialog::slotUrlChanged);
|
||||
|
||||
if (m_url.scheme() != QLatin1String("trash")) {
|
||||
m_iconButton = new KIconButton(mainWidget);
|
||||
formLayout->addRow(i18nc("@label", "Choose an icon:"), m_iconButton);
|
||||
m_iconButton->setIconSize(IconSize(KIconLoader::Desktop));
|
||||
m_iconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Place);
|
||||
if (m_icon.isEmpty()) {
|
||||
QMimeDatabase db;
|
||||
m_iconButton->setIcon(db.mimeTypeForUrl(m_url).iconName());
|
||||
} else {
|
||||
m_iconButton->setIcon(m_icon);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_allowGlobal) {
|
||||
const QString appName = KAboutData::applicationData().displayName();
|
||||
m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), mainWidget );
|
||||
m_appLocal->setChecked(false);
|
||||
vBox->addWidget(m_appLocal);
|
||||
}
|
||||
|
||||
if (m_text.isEmpty()) {
|
||||
m_urlEdit->setFocus();
|
||||
} else {
|
||||
m_textEdit->setFocus();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
|
||||
* *
|
||||
* Based on KFilePlaceEditDialog from kdelibs: *
|
||||
* Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org> *
|
||||
* Copyright (C) 2007 Kevin Ottens <ervin@kde.org> * *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef PLACESITEMEDITDIALOG_H
|
||||
#define PLACESITEMEDITDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QUrl>
|
||||
|
||||
class KIconButton;
|
||||
class KUrlRequester;
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
class QDialogButtonBox;
|
||||
|
||||
class PlacesItemEditDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlacesItemEditDialog(QWidget* parent = nullptr);
|
||||
~PlacesItemEditDialog() override;
|
||||
|
||||
void setIcon(const QString& icon);
|
||||
QString icon() const;
|
||||
|
||||
void setText(const QString& text);
|
||||
QString text() const;
|
||||
|
||||
void setUrl(const QUrl& url);
|
||||
QUrl url() const;
|
||||
|
||||
void setAllowGlobal(bool allow);
|
||||
bool allowGlobal() const;
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void slotUrlChanged(const QString& text);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
QString m_icon;
|
||||
QString m_text;
|
||||
QUrl m_url;
|
||||
bool m_allowGlobal;
|
||||
|
||||
KUrlRequester* m_urlEdit;
|
||||
QLineEdit* m_textEdit;
|
||||
KIconButton* m_iconButton;
|
||||
QCheckBox* m_appLocal;
|
||||
QDialogButtonBox *m_buttonBox;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -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,6 +37,7 @@
|
|||
#include "trash/dolphintrash.h"
|
||||
#include "views/draganddrophelper.h"
|
||||
|
||||
#include <KFilePlaceEditDialog>
|
||||
#include <KFilePlacesModel>
|
||||
#include <KIO/DropJob>
|
||||
#include <KIO/EmptyTrashJob>
|
||||
|
@ -474,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<PlacesItemEditDialog> dialog = new PlacesItemEditDialog(this);
|
||||
dialog->setWindowTitle(i18nc("@title:window", "Add Places Entry"));
|
||||
dialog->setAllowGlobal(true);
|
||||
dialog->setUrl(url);
|
||||
QPointer<KFilePlaceEditDialog> 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;
|
||||
|
@ -489,17 +488,17 @@ void PlacesPanel::addEntry()
|
|||
void PlacesPanel::editEntry(int index)
|
||||
{
|
||||
QHash<QByteArray, QVariant> data = m_model->data(index);
|
||||
const QUrl url = m_model->data(index).value("url").toUrl();
|
||||
const QString text = m_model->data(index).value("text").toString();
|
||||
const bool applicationLocal = !m_model->data(index).value("applicationName").toString().isEmpty();
|
||||
|
||||
QPointer<PlacesItemEditDialog> 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<KFilePlaceEditDialog> dialog = new KFilePlaceEditDialog(true, url, text, QString(), 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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user