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 <kguiitem.h> 00027 #include <klineedit.h> 00028 #include <klocale.h> 00029 #include <krecentdocument.h> 00030 #include <kurl.h> 00031 #include <kurlrequester.h> 00032 00033 class KUrlRequesterDialogPrivate 00034 { 00035 public: 00036 KUrlRequesterDialogPrivate(KUrlRequesterDialog *qq) 00037 : q(qq) 00038 { 00039 } 00040 00041 KUrlRequesterDialog *q; 00042 00043 void initDialog(const QString &text, const QString &url); 00044 00045 // slots 00046 void _k_slotClear(); 00047 void _k_slotTextChanged(const QString &); 00048 00049 KUrlRequester *urlRequester; 00050 }; 00051 00052 00053 KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, QWidget *parent) 00054 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this)) 00055 { 00056 setButtons( Ok | Cancel | User1 ); 00057 setButtonGuiItem( User1, KStandardGuiItem::clear() ); 00058 00059 d->initDialog(i18n("Location:"), urlName); 00060 } 00061 00062 KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, const QString& _text, QWidget *parent) 00063 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this)) 00064 { 00065 setButtons( Ok | Cancel | User1 ); 00066 setButtonGuiItem( User1, KStandardGuiItem::clear() ); 00067 00068 d->initDialog(_text, urlName); 00069 } 00070 00071 KUrlRequesterDialog::~KUrlRequesterDialog() 00072 { 00073 delete d; 00074 } 00075 00076 void KUrlRequesterDialogPrivate::initDialog(const QString &text,const QString &urlName) 00077 { 00078 q->setDefaultButton(KDialog::Ok); 00079 QWidget *plainPage = q->mainWidget(); 00080 QVBoxLayout * topLayout = new QVBoxLayout( plainPage ); 00081 topLayout->setMargin( 0 ); 00082 00083 QLabel * label = new QLabel( text , plainPage ); 00084 topLayout->addWidget( label ); 00085 00086 urlRequester = new KUrlRequester(urlName, plainPage); 00087 urlRequester->setMinimumWidth(urlRequester->sizeHint().width() * 3); 00088 topLayout->addWidget(urlRequester); 00089 urlRequester->setFocus(); 00090 QObject::connect(urlRequester->lineEdit(), SIGNAL(textChanged(QString)), 00091 q, SLOT(_k_slotTextChanged(QString))); 00092 bool state = !urlName.isEmpty(); 00093 q->enableButtonOk(state); 00094 q->enableButton(KDialog::User1, state); 00095 /* 00096 KFile::Mode mode = static_cast<KFile::Mode>( KFile::File | 00097 KFile::ExistingOnly ); 00098 urlRequester_->setMode( mode ); 00099 */ 00100 QObject::connect(q, SIGNAL(user1Clicked()), q, SLOT(_k_slotClear())); 00101 } 00102 00103 void KUrlRequesterDialogPrivate::_k_slotTextChanged(const QString & text) 00104 { 00105 bool state = !text.trimmed().isEmpty(); 00106 q->enableButtonOk(state); 00107 q->enableButton(KDialog::User1, state); 00108 } 00109 00110 void KUrlRequesterDialogPrivate::_k_slotClear() 00111 { 00112 urlRequester->clear(); 00113 } 00114 00115 KUrl KUrlRequesterDialog::selectedUrl() const 00116 { 00117 if ( result() == QDialog::Accepted ) 00118 return d->urlRequester->url(); 00119 else 00120 return KUrl(); 00121 } 00122 00123 00124 KUrl KUrlRequesterDialog::getUrl(const QString& dir, QWidget *parent, 00125 const QString& caption) 00126 { 00127 KUrlRequesterDialog dlg(dir, parent); 00128 00129 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00130 00131 dlg.exec(); 00132 00133 const KUrl& url = dlg.selectedUrl(); 00134 if (url.isValid()) 00135 KRecentDocument::add(url); 00136 00137 return url; 00138 } 00139 00140 KFileDialog * KUrlRequesterDialog::fileDialog() 00141 { 00142 return d->urlRequester->fileDialog(); 00143 } 00144 00145 KUrlRequester * KUrlRequesterDialog::urlRequester() 00146 { 00147 return d->urlRequester; 00148 } 00149 00150 #include "kurlrequesterdialog.moc" 00151 00152 // vim:ts=4:sw=4:tw=78
KDE 4.6 API Reference