]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemeditdialog.cpp
0fae3f248239b3bb18efea6f87c2faba971e4a78
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 <k4aboutdata.h>
30 #include <KIconButton>
32 #include <KLocalizedString>
34 #include <KUrlRequester>
35 #include <KComponentData>
38 #include <QFormLayout>
39 #include <QVBoxLayout>
40 #include <QDialogButtonBox>
41 #include <QPushButton>
43 PlacesItemEditDialog::PlacesItemEditDialog(QWidget
* parent
) :
56 void PlacesItemEditDialog::setIcon(const QString
& icon
)
61 QString
PlacesItemEditDialog::icon() const
63 return m_iconButton
->icon();
66 void PlacesItemEditDialog::setText(const QString
& text
)
71 QString
PlacesItemEditDialog::text() const
73 QString text
= m_textEdit
->text();
75 const KUrl url
= m_urlEdit
->url();
76 text
= url
.fileName().isEmpty() ? url
.prettyUrl() : url
.fileName();
81 void PlacesItemEditDialog::setUrl(const KUrl
& url
)
86 KUrl
PlacesItemEditDialog::url() const
88 return m_urlEdit
->url();
91 void PlacesItemEditDialog::setAllowGlobal(bool allow
)
93 m_allowGlobal
= allow
;
96 bool PlacesItemEditDialog::allowGlobal() const
101 bool PlacesItemEditDialog::event(QEvent
* event
)
103 if (event
->type() == QEvent::Polish
) {
106 return QWidget::event(event
);
109 void PlacesItemEditDialog::slotUrlChanged(const QString
& text
)
111 m_okButton
->setEnabled(!text
.isEmpty());
114 PlacesItemEditDialog::~PlacesItemEditDialog()
118 void PlacesItemEditDialog::initialize()
120 QDialogButtonBox
*buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok
|QDialogButtonBox::Cancel
);
121 m_okButton
= buttonBox
->button(QDialogButtonBox::Ok
);
122 m_okButton
->setDefault(true);
123 m_okButton
->setShortcut(Qt::CTRL
| Qt::Key_Return
);
124 connect(buttonBox
, SIGNAL(accepted()), this, SLOT(accept()));
125 connect(buttonBox
, SIGNAL(rejected()), this, SLOT(reject()));
127 m_okButton
->setDefault(true);
129 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
130 setLayout(mainLayout
);
131 QWidget
* mainWidget
= new QWidget(this);
132 mainLayout
->addWidget(mainWidget
);
133 mainLayout
->addWidget(buttonBox
);
135 QVBoxLayout
* vBox
= new QVBoxLayout(mainWidget
);
137 QFormLayout
* formLayout
= new QFormLayout();
138 vBox
->addLayout( formLayout
);
140 m_textEdit
= new KLineEdit(mainWidget
);
141 formLayout
->addRow(i18nc("@label", "Label:"), m_textEdit
);
142 m_textEdit
->setText(m_text
);
143 m_textEdit
->setClickMessage(i18n("Enter descriptive label here"));
145 m_urlEdit
= new KUrlRequester(m_url
.prettyUrl(), mainWidget
);
146 m_urlEdit
->setMode(KFile::Directory
);
147 formLayout
->addRow(i18nc("@label", "Location:"), m_urlEdit
);
148 // Provide room for at least 40 chars (average char width is half of height)
149 m_urlEdit
->setMinimumWidth(m_urlEdit
->fontMetrics().height() * (40 / 2));
150 connect(m_urlEdit
->lineEdit(), &KLineEdit::textChanged
, this, &PlacesItemEditDialog::slotUrlChanged
);
152 m_iconButton
= new KIconButton(mainWidget
);
153 formLayout
->addRow(i18nc("@label", "Choose an icon:"), m_iconButton
);
154 m_iconButton
->setIconSize(IconSize(KIconLoader::Desktop
));
155 m_iconButton
->setIconType(KIconLoader::NoGroup
, KIconLoader::Place
);
156 if (m_icon
.isEmpty()) {
157 m_iconButton
->setIcon(KMimeType::iconNameForUrl(m_url
));
159 m_iconButton
->setIcon(m_icon
);
164 if (KGlobal::mainComponent().aboutData()) {
165 appName
= KGlobal::mainComponent().aboutData()->programName();
167 if (appName
.isEmpty()) {
168 appName
= KGlobal::mainComponent().componentName();
170 m_appLocal
= new QCheckBox( i18n("&Only show when using this application (%1)", appName
), mainWidget
);
171 m_appLocal
->setChecked(false);
172 vBox
->addWidget(m_appLocal
);
175 if (m_text
.isEmpty()) {
176 m_urlEdit
->setFocus();
178 m_textEdit
->setFocus();