fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kfile / kfileplaceeditdialog.cpp
blob0f418dac82395d2848824973dc8d55e28756df91
1 /* This file is part of the KDE libraries
2 Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
3 Copyright (C) 2007 Kevin Ottens <ervin@kde.org>
5 library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation, version 2.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "kfileplaceeditdialog.h"
22 #include <kaboutdata.h>
23 #include <kconfig.h>
24 #include <kdebug.h>
25 #include <kglobal.h>
26 #include <kicondialog.h>
27 #include <kiconloader.h>
28 #include <kcomponentdata.h>
29 #include <klineedit.h>
30 #include <klocale.h>
31 #include <kmimetype.h>
32 #include <kio/global.h>
33 #include <kprotocolinfo.h>
34 #include <kstringhandler.h>
35 #include <kurlrequester.h>
37 #include <QtCore/QMimeData>
38 #include <QtGui/QApplication>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/qdrawutil.h>
41 #include <QtGui/QFontMetrics>
42 #include <QtGui/QGridLayout>
43 #include <QtGui/QItemDelegate>
44 #include <QtGui/QLabel>
45 #include <QtGui/QMenu>
46 #include <QtGui/QPainter>
47 #include <QtGui/QStyle>
49 #include <unistd.h>
50 #include <kvbox.h>
51 #include <kconfiggroup.h>
54 bool KFilePlaceEditDialog::getInformation(bool allowGlobal, KUrl& url,
55 QString& description, QString& icon,
56 bool& appLocal, int iconSize,
57 QWidget *parent )
59 KFilePlaceEditDialog *dialog = new KFilePlaceEditDialog(allowGlobal, url,
60 description, icon,
61 appLocal,
62 iconSize, parent );
63 if ( dialog->exec() == QDialog::Accepted ) {
64 // set the return parameters
65 url = dialog->url();
66 description = dialog->description();
67 icon = dialog->icon();
68 appLocal = dialog->applicationLocal();
70 delete dialog;
71 return true;
74 delete dialog;
75 return false;
78 KFilePlaceEditDialog::KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
79 const QString& description,
80 const QString &icon, bool appLocal,
81 int iconSize,
82 QWidget *parent)
83 : KDialog( parent )
85 setCaption( i18n("Edit Places Entry") );
86 setButtons( Ok | Cancel );
87 setModal(true);
88 setDefaultButton(Ok);
89 showButtonSeparator(true);
91 QWidget *wdg = new QWidget( this );
92 QVBoxLayout *box = new QVBoxLayout( wdg );
93 box->setSpacing( spacingHint() );
95 QGridLayout *layout = new QGridLayout();
96 layout->setSpacing( spacingHint() );
97 box->addLayout( layout );
99 QString whatsThisText = i18n("<qt>This is the text that will appear in the Places panel.<br /><br />"
100 "The description should consist of one or two words "
101 "that will help you remember what this entry refers to.</qt>");
102 QLabel *label = new QLabel( i18n("&Description:"), wdg );
103 layout->addWidget( label, 0, 0 );
105 m_edit = new KLineEdit( wdg );
106 layout->addWidget( m_edit, 0, 1 );
107 m_edit->setText( description.isEmpty() ? url.fileName() : description );
108 label->setBuddy( m_edit );
109 label->setWhatsThis(whatsThisText );
110 m_edit->setWhatsThis(whatsThisText );
112 whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<br /><br />"
113 "%1<br />http://www.kde.org<br />ftp://ftp.kde.org/pub/kde/stable<br /><br />"
114 "By clicking on the button next to the text edit box you can browse to an "
115 "appropriate URL.</qt>", QDir::homePath());
116 label = new QLabel( i18n("&Location:"), wdg );
117 layout->addWidget( label, 1, 0 );
118 m_urlEdit = new KUrlRequester( url.prettyUrl(), wdg );
119 m_urlEdit->setMode( KFile::Directory );
120 layout->addWidget( m_urlEdit, 1, 1 );
121 label->setBuddy( m_urlEdit );
122 label->setWhatsThis(whatsThisText );
123 m_urlEdit->setWhatsThis(whatsThisText );
125 whatsThisText = i18n("<qt>This is the icon that will appear in the Places panel.<br /><br />"
126 "Click on the button to select a different icon.</qt>");
127 label = new QLabel( i18n("Choose an &icon:"), wdg );
128 layout->addWidget( label, 2, 0 );
129 m_iconButton = new KIconButton( wdg );
130 layout->addWidget( m_iconButton, 2, 1 );
131 m_iconButton->setObjectName( QLatin1String( "icon button" ) );
132 m_iconButton->setIconSize( iconSize );
133 if ( icon.isEmpty() )
134 m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
135 else
136 m_iconButton->setIcon( icon );
137 label->setBuddy( m_iconButton );
138 label->setWhatsThis(whatsThisText );
139 m_iconButton->setWhatsThis(whatsThisText );
141 if ( allowGlobal ) {
142 QString appName;
143 if ( KGlobal::mainComponent().aboutData() )
144 appName = KGlobal::mainComponent().aboutData()->programName();
145 if ( appName.isEmpty() )
146 appName = KGlobal::mainComponent().componentName();
147 m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), wdg );
148 m_appLocal->setChecked( appLocal );
149 m_appLocal->setWhatsThis(i18n("<qt>Select this setting if you want this "
150 "entry to show only when using the current application (%1).<br /><br />"
151 "If this setting is not selected, the entry will be available in all "
152 "applications.</qt>",
153 appName));
154 box->addWidget(m_appLocal);
156 else
157 m_appLocal = 0L;
158 connect(m_urlEdit->lineEdit(),SIGNAL(textChanged ( const QString & )),this,SLOT(urlChanged(const QString & )));
159 m_edit->setFocus();
160 setMainWidget( wdg );
163 KFilePlaceEditDialog::~KFilePlaceEditDialog()
167 void KFilePlaceEditDialog::urlChanged(const QString & text )
169 enableButtonOk( !text.isEmpty() );
172 KUrl KFilePlaceEditDialog::url() const
174 return m_urlEdit->url();
177 QString KFilePlaceEditDialog::description() const
179 return m_edit->text();
182 const QString &KFilePlaceEditDialog::icon() const
184 return m_iconButton->icon();
187 bool KFilePlaceEditDialog::applicationLocal() const
189 if ( !m_appLocal )
190 return true;
192 return m_appLocal->isChecked();
196 #include "kfileplaceeditdialog.moc"