• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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     q->showButtonSeparator(true);
00080     QWidget *plainPage = q->mainWidget();
00081    QVBoxLayout * topLayout = new QVBoxLayout( plainPage );
00082    topLayout->setMargin( 0 );
00083     topLayout->setSpacing(KDialog::spacingHint());
00084 
00085     QLabel * label = new QLabel( text , plainPage );
00086     topLayout->addWidget( label );
00087 
00088     urlRequester = new KUrlRequester(urlName, plainPage);
00089     urlRequester->setMinimumWidth(urlRequester->sizeHint().width() * 3);
00090     topLayout->addWidget(urlRequester);
00091     urlRequester->setFocus();
00092     QObject::connect(urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
00093                      q, SLOT(_k_slotTextChanged(QString)));
00094     bool state = !urlName.isEmpty();
00095     q->enableButtonOk(state);
00096     q->enableButton(KDialog::User1, state);
00097     /*
00098     KFile::Mode mode = static_cast<KFile::Mode>( KFile::File |
00099             KFile::ExistingOnly );
00100     urlRequester_->setMode( mode );
00101     */
00102     QObject::connect(q, SIGNAL(user1Clicked()), q, SLOT(_k_slotClear()));
00103 }
00104 
00105 void KUrlRequesterDialogPrivate::_k_slotTextChanged(const QString & text)
00106 {
00107     bool state = !text.trimmed().isEmpty();
00108     q->enableButtonOk(state);
00109     q->enableButton(KDialog::User1, state);
00110 }
00111 
00112 void KUrlRequesterDialogPrivate::_k_slotClear()
00113 {
00114     urlRequester->clear();
00115 }
00116 
00117 KUrl KUrlRequesterDialog::selectedUrl() const
00118 {
00119     if ( result() == QDialog::Accepted )
00120         return d->urlRequester->url();
00121     else
00122         return KUrl();
00123 }
00124 
00125 
00126 KUrl KUrlRequesterDialog::getUrl(const QString& dir, QWidget *parent,
00127                               const QString& caption)
00128 {
00129     KUrlRequesterDialog dlg(dir, parent);
00130 
00131     dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption);
00132 
00133     dlg.exec();
00134 
00135     const KUrl& url = dlg.selectedUrl();
00136     if (url.isValid())
00137         KRecentDocument::add(url);
00138 
00139     return url;
00140 }
00141 
00142 KFileDialog * KUrlRequesterDialog::fileDialog()
00143 {
00144     return d->urlRequester->fileDialog();
00145 }
00146 
00147 KUrlRequester * KUrlRequesterDialog::urlRequester()
00148 {
00149     return d->urlRequester;
00150 }
00151 
00152 #include "kurlrequesterdialog.moc"
00153 
00154 // vim:ts=4:sw=4:tw=78

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal