From b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 26 Jun 2004 19:01:18 +0000 Subject: Initial revision --- (limited to 'microkde/kio/kfile') diff --git a/microkde/kio/kfile/kurlrequester.cpp b/microkde/kio/kfile/kurlrequester.cpp new file mode 100644 index 0000000..6d39308 --- a/dev/null +++ b/microkde/kio/kfile/kurlrequester.cpp @@ -0,0 +1,406 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999,2000,2001 Carsten Pfeiffer + + library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + + +#include +#ifdef _WIN32_ + +#else +#include +#endif +#include +//US #include + +#include + +//US #include +//US #include +#include +#include +#include +#include +#include +#include +#include +//US #include +//US #include +//US #include + + +#include "kurlrequester.h" + + +class KURLDragPushButton : public QPushButton +{ +public: + KURLDragPushButton( QWidget *parent, const char *name=0 ) + : QPushButton( parent, name ) { +//US setDragEnabled( true ); + } + ~KURLDragPushButton() {} + + void setURL( const KURL& url ) { + m_urls.clear(); + m_urls.append( url ); + } + + /* not needed so far + void setURLs( const KURL::List& urls ) { + m_urls = urls; + } + const KURL::List& urls() const { return m_urls; } + */ + +protected: +/*US + virtual QDragObject *dragObject() { + if ( m_urls.isEmpty() ) + return 0L; + + QDragObject *drag = KURLDrag::newDrag( m_urls, this, "url drag" ); + return drag; + } +*/ +private: + KURL::List m_urls; + +}; + + +/* +************************************************************************* +*/ + +class KURLRequester::KURLRequesterPrivate +{ +public: + KURLRequesterPrivate() { + edit = 0L; +//US combo = 0L; +//US fileDialogMode = KFile::File | KFile::ExistingOnly | KFile::LocalOnly; + } + + void setText( const QString& text ) { +/*US + if ( combo ) + { + if (combo->editable()) + { + combo->setEditText( text ); + } + else + { + combo->insertItem( text ); + combo->setCurrentItem( combo->count()-1 ); + } + } + else +*/ + { + edit->setText( text ); + } + } + + void connectSignals( QObject *receiver ) { + QObject *sender; +/*US if ( combo ) + sender = combo; + else +*/ + sender = edit; + + connect( sender, SIGNAL( textChanged( const QString& )), + receiver, SIGNAL( textChanged( const QString& ))); + connect( sender, SIGNAL( returnPressed() ), + receiver, SIGNAL( returnPressed() )); +//US connect( sender, SIGNAL( returnPressed( const QString& ) ), +//US receiver, SIGNAL( returnPressed( const QString& ) )); + } +/*US + void setCompletionObject( KCompletion *comp ) { + if ( combo ) + combo->setCompletionObject( comp ); + else + edit->setCompletionObject( comp ); + } +*/ + /** + * replaces ~user or $FOO, if necessary + */ + QString url() { + QString txt = /*US combo ? combo->currentText() : */ edit->text(); +/*US KURLCompletion *comp; + if ( combo ) + comp = dynamic_cast(combo->completionObject()); + else + comp = dynamic_cast(edit->completionObject()); + + if ( comp ) + return comp->replacedPath( txt ); + else +*/ + return txt; + } + + KLineEdit *edit; +//US KComboBox *combo; + int fileDialogMode; + QString fileDialogFilter; +}; + + +/*US +KURLRequester::KURLRequester( QWidget *editWidget, QWidget *parent, + const char *name ) + : QHBox( parent, name ) +{ + d = new KURLRequesterPrivate; + + // must have this as parent + editWidget->reparent( this, 0, QPoint(0,0) ); +//US d->edit = dynamic_cast( editWidget ); + d->edit = (KLineEdit*)( editWidget ); +//US d->combo = dynamic_cast( editWidget ); + + init(); +} +*/ + +KURLRequester::KURLRequester( QWidget *parent, const char *name ) + : QHBox( parent, name ) +{ + d = new KURLRequesterPrivate; + init(); +} + + +KURLRequester::KURLRequester( const QString& url, QWidget *parent, + const char *name ) + : QHBox( parent, name ) +{ + d = new KURLRequesterPrivate; + init(); + setURL( url ); +} + + +KURLRequester::~KURLRequester() +{ +//US delete myCompletion; + delete myFileDialog; + delete d; +} + + +void KURLRequester::init() +{ + myFileDialog = 0L; + myShowLocalProt = false; + + if (/*US !d->combo && */ !d->edit ) + d->edit = new KLineEdit( this, "KURLRequester::KLineEdit" ); + + myButton = new KURLDragPushButton( this, "kfile button"); + QIconSet iconSet = SmallIconSet("fileopen"); + QPixmap pixMap = iconSet.pixmap( QIconSet::Small, QIconSet::Normal ); + myButton->setIconSet( iconSet ); + myButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 ); +//US QToolTip::add(myButton, i18n("Open file dialog")); + + connect( myButton, SIGNAL( pressed() ), SLOT( slotUpdateURL() )); + + setSpacing( KDialog::spacingHint() ); + + QWidget *widget = /*US d->combo ? (QWidget*) d->combo : */ (QWidget*) d->edit; + setFocusProxy( widget ); + + d->connectSignals( this ); + connect( myButton, SIGNAL( clicked() ), this, SLOT( slotOpenDialog() )); +/*US + myCompletion = new KURLCompletion(); + d->setCompletionObject( myCompletion ); + + KAccel *accel = new KAccel( this ); + accel->insert( KStdAccel::Open, this, SLOT( slotOpenDialog() )); + accel->readSettings(); +*/ +} + + +void KURLRequester::setURL( const QString& url ) +{ + bool hasLocalPrefix = (url.startsWith("file:")); + + if ( !myShowLocalProt && hasLocalPrefix ) + d->setText( url.mid( 5, url.length()-5 )); + else + d->setText( url ); +} + +void KURLRequester::setCaption( const QString& caption ) +{ +//US fileDialog()->setCaption( caption ); +//US QWidget::setCaption( caption ); +} + +QString KURLRequester::url() const +{ + return d->url(); +} + + +void KURLRequester::slotOpenDialog() +{ + emit openFileDialog( this ); + +//US use our special KFIleDialog instead + KURL u( url() ); + //QString fn = u.url(); + QString fn = d->edit->text(); + fn = KFileDialog::getSaveFileName( fn, "Save backup filename", this ); + + if ( fn == "" ) + return; + + setURL( fn ); + emit urlSelected( d->url() ); +/*US + KFileDialog *dlg = fileDialog(); + if ( !d->url().isEmpty() ) { + KURL u( url() ); + // If we won't be able to list it (e.g. http), then don't try :) + if ( KProtocolInfo::supportsListing( u.protocol() ) ) + dlg->setSelection( u.url() ); + } + + if ( dlg->exec() == QDialog::Accepted ) + { + setURL( dlg->selectedURL().prettyURL() ); + emit urlSelected( d->url() ); + } +*/ + +} + +void KURLRequester::setMode(unsigned int mode) +{ +/*US + Q_ASSERT( (mode & KFile::Files) == 0 ); + d->fileDialogMode = mode; + if ( (mode & KFile::Directory) && !(mode & KFile::File) ) + myCompletion->setMode( KURLCompletion::DirCompletion ); + + if (myFileDialog) + myFileDialog->setMode( d->fileDialogMode ); +*/ +} + +void KURLRequester::setFilter(const QString &filter) +{ +/*US + d->fileDialogFilter = filter; + if (myFileDialog) + myFileDialog->setFilter( d->fileDialogFilter ); +*/ +} + +KFileDialog * KURLRequester::fileDialog() const +{ +/*US + if ( !myFileDialog ) { + QWidget *p = parentWidget(); + myFileDialog = new KFileDialog( QString::null, QString::null, p, + "file dialog", true ); + + myFileDialog->setMode( d->fileDialogMode ); + myFileDialog->setFilter( d->fileDialogFilter ); + } + + return myFileDialog; +*/ + return 0; +} + + +void KURLRequester::setShowLocalProtocol( bool b ) +{ + if ( myShowLocalProt == b ) + return; + + myShowLocalProt = b; + setURL( url() ); +} + +void KURLRequester::clear() +{ + d->setText( QString::null ); +} + +KLineEdit * KURLRequester::lineEdit() const +{ + return d->edit; +} +/*US +KComboBox * KURLRequester::comboBox() const +{ + return d->combo; +} +*/ +void KURLRequester::slotUpdateURL() +{ + // bin compat, myButton is declared as QPushButton +//US KURL u( QDir::currentDirPath() + '/', url() ); + KURL u( url() ); + (static_cast( myButton))->setURL( u ); +} + +QPushButton * KURLRequester::button() const +{ + return myButton; +} +/*US +KEditListBox::CustomEditor KURLRequester::customEditor() +{ + setSizePolicy(QSizePolicy( QSizePolicy::Preferred, + QSizePolicy::Fixed)); + + KLineEdit *edit = d->edit; + if ( !edit && d->combo ) + edit = dynamic_cast( d->combo->lineEdit() ); + +#ifndef NDEBUG + if ( !edit ) + kdWarning() << "KURLRequester's lineedit is not a KLineEdit!??\n"; +#endif + + KEditListBox::CustomEditor editor( this, edit ); + return editor; +} +*/ +void KURLRequester::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +/*US +KURLComboRequester::KURLComboRequester( QWidget *parent, + const char *name ) + : KURLRequester( new KComboBox(false), parent, name) +{ +} +*/ + +//US #include "kurlrequester.moc" diff --git a/microkde/kio/kfile/kurlrequester.h b/microkde/kio/kfile/kurlrequester.h new file mode 100644 index 0000000..3253dd5 --- a/dev/null +++ b/microkde/kio/kfile/kurlrequester.h @@ -0,0 +1,269 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999,2000,2001 Carsten Pfeiffer + + library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + + +#ifndef KURLREQUESTER_H +#define KURLREQUESTER_H + +#include + +#include +//US #include +//US #include +#include + +//US class KComboBox; + +class KFileDialog; +class KLineEdit; +//US class KURLCompletion; +class KURLDragPushButton; + +class QPushButton; +class QString; +class QTimer; + +/** + * This class is a widget showing a lineedit and a button, which invokes a + * filedialog. File name completion is available in the lineedit. + * + * The defaults for the filedialog are to ask for one existing local file, i.e. + * KFileDialog::setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly ) + * The default filter is "*", i.e. show all files, and the start directory is + * the current working directory, or the last directory where a file has been + * selected. + * + * You can change this behavior by using @ref setMode() or @ref setFilter(). + * + * @short A widget to request a filename/url from the user + * @author Carsten Pfeiffer + */ +class KURLRequester : public QHBox +{ + Q_OBJECT + Q_PROPERTY( QString url READ url WRITE setURL ) + +public: + /** + * Constructs a KURLRequester widget. + */ + KURLRequester( QWidget *parent=0, const char *name=0 ); + + /** + * Constructs a KURLRequester widget with the initial URL @p url. + */ + KURLRequester( const QString& url, QWidget *parent=0, const char *name=0 ); + + /** + * Special constructor, which creates a KURLRequester widget with a custom + * edit-widget. The edit-widget can be either a KComboBox or a KLineEdit + * (or inherited thereof). Note: for geometry management reasons, the + * edit-widget is reparented to have the KURLRequester as parent. + * @param modal specifies whether the filedialog should be opened as modal + * or not. + */ +//US KURLRequester( QWidget *editWidget, QWidget *parent, const char *name=0 ); + /** + * Destructs the KURLRequester. + */ + ~KURLRequester(); + + /** + * @returns the current url in the lineedit. May be malformed, if the user + * entered something weird. ~user or environment variables are substituted + * for local files. + */ + QString url() const; + + /** + * Enables/disables showing file:/ in the lineedit, when a local file has + * been selected in the filedialog or was set via @ref setURL(). + * Default is false, not showing file:/ + * @see #showLocalProtocol + */ + void setShowLocalProtocol( bool b ); + + /** + * Sets the mode of the file dialog. + * Note: you can only select one file with the filedialog, + * so KFile::Files doesn't make much sense. + * @see KFileDialog::setMode() + */ + void setMode( unsigned int m ); + + /** + * Sets the filter for the file dialog. + * @see KFileDialog::setFilter() + */ + void setFilter( const QString& filter ); + + /** + * @returns whether local files will be prefixed with file:/ in the + * lineedit + * @see #setShowLocalProtocol + */ + bool showLocalProtocol() const { return myShowLocalProt; } + + /** + * @returns a pointer to the filedialog + * You can use this to customize the dialog, e.g. to specify a filter. + * Never returns 0L. + */ + virtual KFileDialog * fileDialog() const; + + /** + * @returns a pointer to the lineedit, either the default one, or the + * special one, if you used the special constructor. + * + * It is provided so that you can e.g. set an own completion object + * (e.g. @ref KShellCompletion) into it. + */ + KLineEdit * lineEdit() const; + + /** + * @returns a pointer to the combobox, in case you have set one using the + * special constructor. Returns 0L otherwise. + */ +//US KComboBox * comboBox() const; + + /** + * @returns a pointer to the pushbutton. It is provided so that you can + * specify an own pixmap or a text, if you really need to. + */ + QPushButton * button() const; + + /** + * @returns the KURLCompletion object used in the lineedit/combobox. + */ +//US KURLCompletion *completionObject() const { return myCompletion; } + + /** + * @returns an object, suitable for use with KEditListBox. It allows you + * to put this KURLRequester into a KEditListBox. + * Basically, do it like this: + *
+     * KURLRequester *req = new KURLRequester( someWidget );
+     * [...]
+     * KEditListBox *editListBox = new KEditListBox( i18n("Some Title"), req->customEditor(), someWidget );
+     * 
+ * @since 3.1 + */ +//US KEditListBox::CustomEditor customEditor(); + +public slots: + /** + * Sets the url in the lineedit to @p url. Depending on the state of + * @ref showLocalProtocol(), file:/ on local files will be shown or not. + * @since 3.1 + */ + void setURL( const QString& url ); + + /** + * @reimp + * Sets the caption of the file dialog. + * @since 3.1 + */ + virtual void setCaption( const QString& caption ); + + /** + * Clears the lineedit/combobox. + */ + void clear(); + +signals: + // forwards from LineEdit + /** + * Emitted when the text in the lineedit changes. + * The parameter contains the contents of the lineedit. + * @since 3.1 + */ + void textChanged( const QString& ); + + /** + * Emitted when return or enter was pressed in the lineedit. + */ + void returnPressed(); + + /** + * Emitted when return or enter was pressed in the lineedit. + * The parameter contains the contents of the lineedit. + */ + void returnPressed( const QString& ); + + /** + * Emitted before the filedialog is going to open. Connect + * to this signal to "configure" the filedialog, e.g. set the + * filefilter, the mode, a preview-widget, etc. It's usually + * not necessary to set a URL for the filedialog, as it will + * get set properly from the editfield contents. + * + * If you use multiple KURLRequesters, you can connect all of them + * to the same slot and use the given KURLRequester pointer to know + * which one is going to open. + */ + void openFileDialog( KURLRequester * ); + + /** + * Emitted when the user changed the URL via the file dialog. + * The parameter contains the contents of the lineedit. + */ + void urlSelected( const QString& ); + +protected: + void init(); + +//US KURLCompletion * myCompletion; + + +private: + KURLDragPushButton * myButton; + bool myShowLocalProt; + mutable KFileDialog * myFileDialog; + + +protected slots: + /** + * Called when the button is pressed to open the filedialog. + * Also called when @ref KStdAccel::Open (default is Ctrl-O) is pressed. + */ + void slotOpenDialog(); + +private slots: + void slotUpdateURL(); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KURLRequesterPrivate; + KURLRequesterPrivate *d; +}; +/*US +class KURLComboRequester : public KURLRequester // For use in Qt Designer +{ + Q_OBJECT +public: +*/ + /** + * Constructs a KURLRequester widget with a combobox. + */ +/*US + KURLComboRequester( QWidget *parent=0, const char *name=0 ); +}; +*/ + +#endif // KURLREQUESTER_H -- cgit v0.9.0.2