kio Library: kurlrequesterdlg.cpp Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kurlrequesterdlg.cpp

    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., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020
    00021 #include <sys/stat.h>
    00022 #include <unistd.h>
    00023
    00024 #include <qlabel.h>
    00025 #include <qlayout.h>
    00026 #include <qstring.h>
    00027 #include <qtoolbutton.h>
    00028
    00029 #include <kaccel.h>
    00030 #include <kfiledialog.h>
    00031 #include <kglobal.h>
    00032 #include <kiconloader.h>
    00033 #include <klineedit.h>
    00034 #include <klocale.h>
    00035 #include <krecentdocument.h>
    00036 #include <kurl.h>
    00037 #include <kurlrequester.h>
    00038
    00039 #include "kurlrequesterdlg.h"
    00040
    00041
    00042 KURLRequesterDlg::KURLRequesterDlg( const QString& urlName, QWidget *parent,
    00043         const char *name, bool modal )
    00044     :   KDialogBase( Plain, QString::null, Ok|Cancel|User1, Ok, parent, name,
    00045                 modal, true, KStdGuiItem::clear() )
    00046 {
    00047   initDialog(i18n( "Location:" ), urlName);
    00048 }
    00049
    00050 KURLRequesterDlg::KURLRequesterDlg( const QString& urlName, const QString& _text, QWidget *parent, const char *name, bool modal )
    00051     :   KDialogBase( Plain, QString::null, Ok|Cancel|User1, Ok, parent, name,
    00052                 modal, true, KStdGuiItem::clear() )
    00053 {
    00054   initDialog(_text, urlName);
    00055 }
    00056
    00057 KURLRequesterDlg::~KURLRequesterDlg()
    00058 {
    00059 }
    00060
    00061 void KURLRequesterDlg::initDialog(const QString &text,const QString &urlName)
    00062 {
    00063    QVBoxLayout * topLayout = new QVBoxLayout( plainPage(), 0,
    00064             spacingHint() );
    00065
    00066     QLabel * label = new QLabel( text , plainPage() );
    00067     topLayout->addWidget( label );
    00068
    00069     urlRequester_ = new KURLRequester( urlName, plainPage(), "urlRequester" );
    00070     urlRequester_->setMinimumWidth( urlRequester_->sizeHint().width() * 3 );
    00071     topLayout->addWidget( urlRequester_ );
    00072     urlRequester_->setFocus();
    00073     connect( urlRequester_->lineEdit(), SIGNAL(textChanged(const QString&)),
    00074              SLOT(slotTextChanged(const QString&)) );
    00075     bool state = !urlName.isEmpty();
    00076     enableButtonOK( state );
    00077     enableButton( KDialogBase::User1, state );
    00078     /*
    00079     KFile::Mode mode = static_cast<KFile::Mode>( KFile::File |
    00080             KFile::ExistingOnly );
    00081     urlRequester_->setMode( mode );
    00082     */
    00083     connect( this, SIGNAL( user1Clicked() ), SLOT( slotClear() ) );
    00084 }
    00085
    00086 void KURLRequesterDlg::slotTextChanged(const QString & text)
    00087 {
    00088     bool state = !text.stripWhiteSpace().isEmpty();
    00089     enableButtonOK( state );
    00090     enableButton( KDialogBase::User1, state );
    00091 }
    00092
    00093 void KURLRequesterDlg::slotClear()
    00094 {
    00095     urlRequester_->clear();
    00096 }
    00097
    00098 KURL KURLRequesterDlg::selectedURL() const
    00099 {
    00100     if ( result() == QDialog::Accepted )
    00101         return KURL::fromPathOrURL( urlRequester_->url() );
    00102     else
    00103         return KURL();
    00104 }
    00105
    00106
    00107 KURL KURLRequesterDlg::getURL(const QString& dir, QWidget *parent,
    00108         const QString& caption)
    00109 {
    00110     KURLRequesterDlg dlg(dir, parent, "filedialog", true);
    00111
    00112     dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
    00113
    00114     dlg.exec();
    00115
    00116     const KURL& url = dlg.selectedURL();
    00117     if (url.isValid())
    00118         KRecentDocument::add(url);
    00119
    00120     return url;
    00121 }
    00122
    00123 KFileDialog * KURLRequesterDlg::fileDialog()
    00124 {
    00125     return urlRequester_->fileDialog();
    00126 }
    00127
    00128 KURLRequester * KURLRequesterDlg::urlRequester()
    00129 {
    00130     return urlRequester_;
    00131 }
    00132
    00133 #include "kurlrequesterdlg.moc"
    00134
    00135 // vim:ts=4:sw=4:tw=78

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:24:05 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003