KFile
kfileplaceeditdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kfileplaceeditdialog.h"
00021
00022 #include <kaboutdata.h>
00023 #include <kconfig.h>
00024 #include <kdebug.h>
00025 #include <kglobal.h>
00026 #include <kicondialog.h>
00027 #include <kiconloader.h>
00028 #include <kcomponentdata.h>
00029 #include <klineedit.h>
00030 #include <klocale.h>
00031 #include <kmimetype.h>
00032 #include <kio/global.h>
00033 #include <kprotocolinfo.h>
00034 #include <kstringhandler.h>
00035 #include <kurlrequester.h>
00036
00037 #include <QtCore/QMimeData>
00038 #include <QtGui/QApplication>
00039 #include <QtGui/QCheckBox>
00040 #include <QtGui/qdrawutil.h>
00041 #include <QtGui/QFontMetrics>
00042 #include <QtGui/QFormLayout>
00043 #include <QtGui/QItemDelegate>
00044 #include <QtGui/QLabel>
00045 #include <QtGui/QMenu>
00046 #include <QtGui/QPainter>
00047 #include <QtGui/QStyle>
00048
00049 #include <unistd.h>
00050 #include <kvbox.h>
00051 #include <kconfiggroup.h>
00052
00053
00054 bool KFilePlaceEditDialog::getInformation(bool allowGlobal, KUrl& url,
00055 QString& description, QString& icon,
00056 bool& appLocal, int iconSize,
00057 QWidget *parent )
00058 {
00059 KFilePlaceEditDialog *dialog = new KFilePlaceEditDialog(allowGlobal, url,
00060 description, icon,
00061 appLocal,
00062 iconSize, parent );
00063 if ( dialog->exec() == QDialog::Accepted ) {
00064
00065 url = dialog->url();
00066 description = dialog->description();
00067 icon = dialog->icon();
00068 appLocal = dialog->applicationLocal();
00069
00070 delete dialog;
00071 return true;
00072 }
00073
00074 delete dialog;
00075 return false;
00076 }
00077
00078 KFilePlaceEditDialog::KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
00079 const QString& description,
00080 const QString &icon, bool appLocal,
00081 int iconSize,
00082 QWidget *parent)
00083 : KDialog( parent )
00084 {
00085 setCaption( i18n("Edit Places Entry") );
00086 setButtons( Ok | Cancel );
00087 setModal(true);
00088 setDefaultButton(Ok);
00089 showButtonSeparator(true);
00090
00091 QWidget *wdg = new QWidget( this );
00092 QVBoxLayout *box = new QVBoxLayout( wdg );
00093
00094 QFormLayout *layout = new QFormLayout();
00095 box->addLayout( layout );
00096
00097 QString whatsThisText = i18n("<qt>This is the text that will appear in the Places panel.<br /><br />"
00098 "The description should consist of one or two words "
00099 "that will help you remember what this entry refers to.</qt>");
00100 m_edit = new KLineEdit( wdg );
00101 layout->addRow( i18n("&Description:"), m_edit );
00102 m_edit->setText( description.isEmpty() ? url.fileName() : description );
00103 m_edit->setWhatsThis( whatsThisText );
00104 layout->labelForField(m_edit)->setWhatsThis( whatsThisText );
00105
00106 whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<br /><br />"
00107 "%1<br />http://www.kde.org<br />ftp://ftp.kde.org/pub/kde/stable<br /><br />"
00108 "By clicking on the button next to the text edit box you can browse to an "
00109 "appropriate URL.</qt>", QDir::homePath());
00110 m_urlEdit = new KUrlRequester( url.prettyUrl(), wdg );
00111 m_urlEdit->setMode( KFile::Directory );
00112 layout->addRow( i18n("&Location:"), m_urlEdit );
00113 m_urlEdit->setWhatsThis( whatsThisText );
00114 layout->labelForField(m_urlEdit)->setWhatsThis( whatsThisText );
00115
00116 whatsThisText = i18n("<qt>This is the icon that will appear in the Places panel.<br /><br />"
00117 "Click on the button to select a different icon.</qt>");
00118 m_iconButton = new KIconButton( wdg );
00119 layout->addRow( i18n("Choose an &icon:"), m_iconButton );
00120 m_iconButton->setObjectName( QLatin1String( "icon button" ) );
00121 m_iconButton->setIconSize( iconSize );
00122 m_iconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place );
00123 if ( icon.isEmpty() )
00124 m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
00125 else
00126 m_iconButton->setIcon( icon );
00127 m_iconButton->setWhatsThis( whatsThisText );
00128 layout->labelForField(m_iconButton)->setWhatsThis( whatsThisText );
00129
00130 if ( allowGlobal ) {
00131 QString appName;
00132 if ( KGlobal::mainComponent().aboutData() )
00133 appName = KGlobal::mainComponent().aboutData()->programName();
00134 if ( appName.isEmpty() )
00135 appName = KGlobal::mainComponent().componentName();
00136 m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), wdg );
00137 m_appLocal->setChecked( appLocal );
00138 m_appLocal->setWhatsThis(i18n("<qt>Select this setting if you want this "
00139 "entry to show only when using the current application (%1).<br /><br />"
00140 "If this setting is not selected, the entry will be available in all "
00141 "applications.</qt>",
00142 appName));
00143 box->addWidget(m_appLocal);
00144 }
00145 else
00146 m_appLocal = 0L;
00147 connect(m_urlEdit->lineEdit(),SIGNAL(textChanged ( const QString & )),this,SLOT(urlChanged(const QString & )));
00148 m_edit->setFocus();
00149 setMainWidget( wdg );
00150 }
00151
00152 KFilePlaceEditDialog::~KFilePlaceEditDialog()
00153 {
00154 }
00155
00156 void KFilePlaceEditDialog::urlChanged(const QString & text )
00157 {
00158 enableButtonOk( !text.isEmpty() );
00159 }
00160
00161 KUrl KFilePlaceEditDialog::url() const
00162 {
00163 return m_urlEdit->url();
00164 }
00165
00166 QString KFilePlaceEditDialog::description() const
00167 {
00168 return m_edit->text();
00169 }
00170
00171 const QString &KFilePlaceEditDialog::icon() const
00172 {
00173 return m_iconButton->icon();
00174 }
00175
00176 bool KFilePlaceEditDialog::applicationLocal() const
00177 {
00178 if ( !m_appLocal )
00179 return true;
00180
00181 return m_appLocal->isChecked();
00182 }
00183
00184
00185 #include "kfileplaceeditdialog.moc"