]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemeditdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on KFilePlaceEditDialog from kdelibs: *
5 * Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org> *
6 * Copyright (C) 2007 Kevin Ottens <ervin@kde.org> * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
24 #include "placesitemeditdialog.h"
26 #include "dolphindebug.h"
30 #include <KIconButton>
31 #include <KLocalizedString>
32 #include <KUrlRequester>
35 #include <QDialogButtonBox>
37 #include <QFormLayout>
39 #include <QMimeDatabase>
41 PlacesItemEditDialog::PlacesItemEditDialog(QWidget
* parent
) :
49 m_iconButton(nullptr),
55 void PlacesItemEditDialog::setIcon(const QString
& icon
)
60 QString
PlacesItemEditDialog::icon() const
62 return m_iconButton
? m_iconButton
->icon() : m_icon
;
65 void PlacesItemEditDialog::setText(const QString
& text
)
70 QString
PlacesItemEditDialog::text() const
72 QString text
= m_textEdit
->text();
74 const QUrl url
= m_urlEdit
->url();
75 text
= url
.fileName().isEmpty() ? url
.toDisplayString(QUrl::PreferLocalFile
) : url
.fileName();
80 void PlacesItemEditDialog::setUrl(const QUrl
& url
)
85 QUrl
PlacesItemEditDialog::url() const
87 return m_urlEdit
->url();
90 void PlacesItemEditDialog::setAllowGlobal(bool allow
)
92 m_allowGlobal
= allow
;
95 bool PlacesItemEditDialog::allowGlobal() const
100 bool PlacesItemEditDialog::event(QEvent
* event
)
102 if (event
->type() == QEvent::Polish
) {
105 return QWidget::event(event
);
108 void PlacesItemEditDialog::slotUrlChanged(const QString
& text
)
110 m_buttonBox
->button(QDialogButtonBox::Ok
)->setEnabled(!text
.isEmpty());
113 PlacesItemEditDialog::~PlacesItemEditDialog()
117 void PlacesItemEditDialog::initialize()
119 m_buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok
|QDialogButtonBox::Cancel
, this);
120 connect(m_buttonBox
, &QDialogButtonBox::accepted
, this, &PlacesItemEditDialog::accept
);
121 connect(m_buttonBox
, &QDialogButtonBox::rejected
, this, &PlacesItemEditDialog::reject
);
124 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
125 setLayout(mainLayout
);
126 QWidget
* mainWidget
= new QWidget(this);
127 mainLayout
->addWidget(mainWidget
);
128 mainLayout
->addWidget(m_buttonBox
);
130 QVBoxLayout
* vBox
= new QVBoxLayout(mainWidget
);
132 QFormLayout
* formLayout
= new QFormLayout();
133 vBox
->addLayout( formLayout
);
135 m_textEdit
= new QLineEdit(mainWidget
);
136 formLayout
->addRow(i18nc("@label", "Label:"), m_textEdit
);
137 m_textEdit
->setText(m_text
);
138 m_textEdit
->setPlaceholderText(i18n("Enter descriptive label here"));
140 m_urlEdit
= new KUrlRequester(m_url
, mainWidget
);
141 m_urlEdit
->setMode(KFile::Directory
);
142 formLayout
->addRow(i18nc("@label", "Location:"), m_urlEdit
);
143 // Provide room for at least 40 chars (average char width is half of height)
144 m_urlEdit
->setMinimumWidth(m_urlEdit
->fontMetrics().height() * (40 / 2));
145 connect(m_urlEdit
, &KUrlRequester::textChanged
, this, &PlacesItemEditDialog::slotUrlChanged
);
147 if (m_url
.scheme() != QLatin1String("trash")) {
148 m_iconButton
= new KIconButton(mainWidget
);
149 formLayout
->addRow(i18nc("@label", "Choose an icon:"), m_iconButton
);
150 m_iconButton
->setIconSize(IconSize(KIconLoader::Desktop
));
151 m_iconButton
->setIconType(KIconLoader::NoGroup
, KIconLoader::Place
);
152 if (m_icon
.isEmpty()) {
154 m_iconButton
->setIcon(db
.mimeTypeForUrl(m_url
).iconName());
156 m_iconButton
->setIcon(m_icon
);
161 const QString appName
= KAboutData::applicationData().displayName();
162 m_appLocal
= new QCheckBox( i18n("&Only show when using this application (%1)", appName
), mainWidget
);
163 m_appLocal
->setChecked(false);
164 vBox
->addWidget(m_appLocal
);
167 if (m_text
.isEmpty()) {
168 m_urlEdit
->setFocus();
170 m_textEdit
->setFocus();