KIO
kurlrequesterdialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Wilco Greven <greven@kde.org> 00003 00004 library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kurlrequesterdialog.h" 00021 00022 #include <QtGui/QLabel> 00023 #include <QtGui/QLayout> 00024 00025 #include <kfiledialog.h> 00026 #include <klineedit.h> 00027 #include <klocale.h> 00028 #include <krecentdocument.h> 00029 #include <kurl.h> 00030 #include <kurlrequester.h> 00031 00032 class KUrlRequesterDialogPrivate 00033 { 00034 public: 00035 KUrlRequesterDialogPrivate(KUrlRequesterDialog *qq) 00036 : q(qq) 00037 { 00038 } 00039 00040 KUrlRequesterDialog *q; 00041 00042 void initDialog(const QString &text, const QString &url); 00043 00044 // slots 00045 void _k_slotClear(); 00046 void _k_slotTextChanged(const QString &); 00047 00048 KUrlRequester *urlRequester; 00049 }; 00050 00051 00052 KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, QWidget *parent) 00053 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this)) 00054 { 00055 setButtons( Ok | Cancel | User1 ); 00056 setButtonGuiItem( User1, KStandardGuiItem::clear() ); 00057 00058 d->initDialog(i18n("Location:"), urlName); 00059 } 00060 00061 KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, const QString& _text, QWidget *parent) 00062 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this)) 00063 { 00064 setButtons( Ok | Cancel | User1 ); 00065 setButtonGuiItem( User1, KStandardGuiItem::clear() ); 00066 00067 d->initDialog(_text, urlName); 00068 } 00069 00070 KUrlRequesterDialog::~KUrlRequesterDialog() 00071 { 00072 delete d; 00073 } 00074 00075 void KUrlRequesterDialogPrivate::initDialog(const QString &text,const QString &urlName) 00076 { 00077 q->setDefaultButton(KDialog::Ok); 00078 QWidget *plainPage = q->mainWidget(); 00079 QVBoxLayout * topLayout = new QVBoxLayout( plainPage ); 00080 topLayout->setMargin( 0 ); 00081 00082 QLabel * label = new QLabel( text , plainPage ); 00083 topLayout->addWidget( label ); 00084 00085 urlRequester = new KUrlRequester(urlName, plainPage); 00086 urlRequester->setMinimumWidth(urlRequester->sizeHint().width() * 3); 00087 topLayout->addWidget(urlRequester); 00088 urlRequester->setFocus(); 00089 QObject::connect(urlRequester->lineEdit(), SIGNAL(textChanged(QString)), 00090 q, SLOT(_k_slotTextChanged(QString))); 00091 bool state = !urlName.isEmpty(); 00092 q->enableButtonOk(state); 00093 q->enableButton(KDialog::User1, state); 00094 /* 00095 KFile::Mode mode = static_cast<KFile::Mode>( KFile::File | 00096 KFile::ExistingOnly ); 00097 urlRequester_->setMode( mode ); 00098 */ 00099 QObject::connect(q, SIGNAL(user1Clicked()), q, SLOT(_k_slotClear())); 00100 } 00101 00102 void KUrlRequesterDialogPrivate::_k_slotTextChanged(const QString & text) 00103 { 00104 bool state = !text.trimmed().isEmpty(); 00105 q->enableButtonOk(state); 00106 q->enableButton(KDialog::User1, state); 00107 } 00108 00109 void KUrlRequesterDialogPrivate::_k_slotClear() 00110 { 00111 urlRequester->clear(); 00112 } 00113 00114 KUrl KUrlRequesterDialog::selectedUrl() const 00115 { 00116 if ( result() == QDialog::Accepted ) 00117 return d->urlRequester->url(); 00118 else 00119 return KUrl(); 00120 } 00121 00122 00123 KUrl KUrlRequesterDialog::getUrl(const QString& dir, QWidget *parent, 00124 const QString& caption) 00125 { 00126 KUrlRequesterDialog dlg(dir, parent); 00127 00128 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00129 00130 dlg.exec(); 00131 00132 const KUrl& url = dlg.selectedUrl(); 00133 if (url.isValid()) 00134 KRecentDocument::add(url); 00135 00136 return url; 00137 } 00138 00139 KFileDialog * KUrlRequesterDialog::fileDialog() 00140 { 00141 return d->urlRequester->fileDialog(); 00142 } 00143 00144 KUrlRequester * KUrlRequesterDialog::urlRequester() 00145 { 00146 return d->urlRequester; 00147 } 00148 00149 #include "kurlrequesterdialog.moc" 00150 00151 // vim:ts=4:sw=4:tw=78
KDE 4.7 API Reference