mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: properly initialize KUrlRequester::KUrlRequesterPrivate members
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
10f13e8bab
commit
278d608836
2 changed files with 86 additions and 87 deletions
|
@ -75,10 +75,15 @@ class KUrlRequester::KUrlRequesterPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KUrlRequesterPrivate(KUrlRequester *parent)
|
KUrlRequesterPrivate(KUrlRequester *parent)
|
||||||
: m_parent(parent),
|
: m_startDirCustomized(false),
|
||||||
edit(0),
|
m_parent(parent),
|
||||||
combo(0),
|
edit(nullptr),
|
||||||
fileDialogMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly)
|
combo(nullptr),
|
||||||
|
fileDialogMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly),
|
||||||
|
myButton(nullptr),
|
||||||
|
myFileDialog(nullptr),
|
||||||
|
myCompletion(nullptr),
|
||||||
|
fileDialogModality(Qt::ApplicationModal)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<KUrl>("KUrl");
|
qRegisterMetaType<KUrl>("KUrl");
|
||||||
}
|
}
|
||||||
|
@ -206,32 +211,35 @@ public:
|
||||||
|
|
||||||
|
|
||||||
KUrlRequester::KUrlRequester( QWidget *editWidget, QWidget *parent)
|
KUrlRequester::KUrlRequester( QWidget *editWidget, QWidget *parent)
|
||||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
: KHBox(parent),
|
||||||
|
d(new KUrlRequesterPrivate(this))
|
||||||
{
|
{
|
||||||
// must have this as parent
|
// must have this as parent
|
||||||
editWidget->setParent( this );
|
editWidget->setParent(this);
|
||||||
d->combo = qobject_cast<KComboBox*>( editWidget );
|
d->combo = qobject_cast<KComboBox*>(editWidget);
|
||||||
d->edit = qobject_cast<KLineEdit*>( editWidget );
|
d->edit = qobject_cast<KLineEdit*>(editWidget);
|
||||||
if ( d->edit ) {
|
if (d->edit) {
|
||||||
d->edit->setClearButtonShown( true );
|
d->edit->setClearButtonShown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->init();
|
d->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KUrlRequester::KUrlRequester( QWidget *parent)
|
KUrlRequester::KUrlRequester(QWidget *parent)
|
||||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
: KHBox(parent),
|
||||||
|
d(new KUrlRequesterPrivate(this))
|
||||||
{
|
{
|
||||||
d->init();
|
d->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KUrlRequester::KUrlRequester( const KUrl& url, QWidget *parent)
|
KUrlRequester::KUrlRequester(const KUrl &url, QWidget *parent)
|
||||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
: KHBox(parent),
|
||||||
|
d(new KUrlRequesterPrivate(this))
|
||||||
{
|
{
|
||||||
d->init();
|
d->init();
|
||||||
setUrl( url );
|
setUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
KUrlRequester::~KUrlRequester()
|
KUrlRequester::~KUrlRequester()
|
||||||
|
@ -245,10 +253,7 @@ void KUrlRequester::KUrlRequesterPrivate::init()
|
||||||
m_parent->setMargin(0);
|
m_parent->setMargin(0);
|
||||||
m_parent->setSpacing(-1); // use default spacing
|
m_parent->setSpacing(-1); // use default spacing
|
||||||
|
|
||||||
myFileDialog = 0L;
|
if (!combo && !edit) {
|
||||||
fileDialogModality = Qt::ApplicationModal;
|
|
||||||
|
|
||||||
if ( !combo && !edit ) {
|
|
||||||
edit = new KLineEdit( m_parent );
|
edit = new KLineEdit( m_parent );
|
||||||
edit->setClearButtonShown( true );
|
edit->setClearButtonShown( true );
|
||||||
}
|
}
|
||||||
|
@ -271,7 +276,6 @@ void KUrlRequester::KUrlRequesterPrivate::init()
|
||||||
m_parent->connect(myButton, SIGNAL(clicked()), m_parent, SLOT(_k_slotOpenDialog()));
|
m_parent->connect(myButton, SIGNAL(clicked()), m_parent, SLOT(_k_slotOpenDialog()));
|
||||||
|
|
||||||
m_startDir = KUrl::fromPath(QDir::currentPath());
|
m_startDir = KUrl::fromPath(QDir::currentPath());
|
||||||
m_startDirCustomized = false;
|
|
||||||
|
|
||||||
myCompletion = new KUrlCompletion();
|
myCompletion = new KUrlCompletion();
|
||||||
updateCompletionStartDir(m_startDir);
|
updateCompletionStartDir(m_startDir);
|
||||||
|
@ -293,7 +297,7 @@ void KUrlRequester::setText(const QString& text)
|
||||||
d->setText(text);
|
d->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KUrlRequester::setStartDir(const KUrl& startDir)
|
void KUrlRequester::setStartDir(const KUrl &startDir)
|
||||||
{
|
{
|
||||||
d->m_startDir = startDir;
|
d->m_startDir = startDir;
|
||||||
d->m_startDirCustomized = true;
|
d->m_startDirCustomized = true;
|
||||||
|
@ -302,12 +306,12 @@ void KUrlRequester::setStartDir(const KUrl& startDir)
|
||||||
|
|
||||||
void KUrlRequester::changeEvent(QEvent *e)
|
void KUrlRequester::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e->type()==QEvent::WindowTitleChange) {
|
if (e->type()==QEvent::WindowTitleChange) {
|
||||||
if (d->myFileDialog) {
|
if (d->myFileDialog) {
|
||||||
d->myFileDialog->setCaption(windowTitle());
|
d->myFileDialog->setCaption(windowTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KHBox::changeEvent(e);
|
KHBox::changeEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
KUrl KUrlRequester::url() const
|
KUrl KUrlRequester::url() const
|
||||||
|
@ -327,57 +331,54 @@ QString KUrlRequester::text() const
|
||||||
|
|
||||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
||||||
{
|
{
|
||||||
if ( myFileDialog )
|
if (myFileDialog) {
|
||||||
if ( myFileDialog->isVisible() )
|
if (myFileDialog->isVisible()) {
|
||||||
{
|
|
||||||
//The file dialog is already being shown, raise it and exit
|
//The file dialog is already being shown, raise it and exit
|
||||||
myFileDialog->raise();
|
myFileDialog->raise();
|
||||||
myFileDialog->activateWindow();
|
myFileDialog->activateWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ((fileDialogMode & KFile::Directory) && !(fileDialogMode & KFile::File)) ||
|
if ( ((fileDialogMode & KFile::Directory) && !(fileDialogMode & KFile::File)) ||
|
||||||
/* catch possible fileDialog()->setMode( KFile::Directory ) changes */
|
/* catch possible fileDialog()->setMode( KFile::Directory ) changes */
|
||||||
(myFileDialog && (myFileDialog->mode() & KFile::Directory) &&
|
(myFileDialog && (myFileDialog->mode() & KFile::Directory) &&
|
||||||
(myFileDialog->mode() & (KFile::File | KFile::Files)) == 0) )
|
(myFileDialog->mode() & (KFile::File | KFile::Files)) == 0)) {
|
||||||
{
|
const KUrl openUrl = (!m_parent->url().isEmpty() && !m_parent->url().isRelative()) ? m_parent->url() : m_startDir;
|
||||||
const KUrl openUrl = (!m_parent->url().isEmpty() && !m_parent->url().isRelative() )
|
|
||||||
? m_parent->url() : m_startDir;
|
|
||||||
|
|
||||||
KUrl newurl;
|
KUrl newurl;
|
||||||
if (fileDialogMode & KFile::LocalOnly)
|
if (fileDialogMode & KFile::LocalOnly) {
|
||||||
newurl = KFileDialog::getExistingDirectory( openUrl, m_parent);
|
newurl = KFileDialog::getExistingDirectory(openUrl, m_parent);
|
||||||
else
|
} else {
|
||||||
newurl = KFileDialog::getExistingDirectoryUrl( openUrl, m_parent);
|
newurl = KFileDialog::getExistingDirectoryUrl(openUrl, m_parent);
|
||||||
|
|
||||||
if ( newurl.isValid() )
|
|
||||||
{
|
|
||||||
m_parent->setUrl( newurl );
|
|
||||||
emit m_parent->urlSelected( url() );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
if (newurl.isValid()) {
|
||||||
{
|
m_parent->setUrl(newurl);
|
||||||
emit m_parent->openFileDialog( m_parent );
|
emit m_parent->urlSelected(url());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit m_parent->openFileDialog(m_parent);
|
||||||
|
|
||||||
//Creates the fileDialog if it doesn't exist yet
|
//Creates the fileDialog if it doesn't exist yet
|
||||||
KFileDialog *dlg = m_parent->fileDialog();
|
KFileDialog* dlg = m_parent->fileDialog();
|
||||||
|
|
||||||
if ( !url().isEmpty() && !url().isRelative() ) {
|
if (!url().isEmpty() && !url().isRelative()) {
|
||||||
KUrl u( url() );
|
KUrl u( url() );
|
||||||
// If we won't be able to list it (e.g. http), then don't try :)
|
// If we won't be able to list it (e.g. http), then don't try :)
|
||||||
if ( KProtocolManager::supportsListing( u ) )
|
if (KProtocolManager::supportsListing(u)) {
|
||||||
dlg->setSelection( u.url() );
|
dlg->setSelection(u.url());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dlg->setUrl(m_startDir);
|
dlg->setUrl(m_startDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update the file dialog window modality
|
//Update the file dialog window modality
|
||||||
if ( dlg->windowModality() != fileDialogModality )
|
if (dlg->windowModality() != fileDialogModality) {
|
||||||
dlg->setWindowModality(fileDialogModality);
|
dlg->setWindowModality(fileDialogModality);
|
||||||
|
}
|
||||||
|
|
||||||
if ( fileDialogModality == Qt::NonModal )
|
if (fileDialogModality == Qt::NonModal) {
|
||||||
{
|
|
||||||
dlg->show();
|
dlg->show();
|
||||||
} else {
|
} else {
|
||||||
dlg->exec();
|
dlg->exec();
|
||||||
|
@ -387,18 +388,17 @@ void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
||||||
|
|
||||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotFileDialogFinished()
|
void KUrlRequester::KUrlRequesterPrivate::_k_slotFileDialogFinished()
|
||||||
{
|
{
|
||||||
if ( !myFileDialog )
|
if (!myFileDialog) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( myFileDialog->result() == QDialog::Accepted )
|
if (myFileDialog->result() == QDialog::Accepted) {
|
||||||
{
|
|
||||||
KUrl newUrl = myFileDialog->selectedUrl();
|
KUrl newUrl = myFileDialog->selectedUrl();
|
||||||
if ( newUrl.isValid() )
|
if (newUrl.isValid()) {
|
||||||
{
|
m_parent->setUrl(newUrl);
|
||||||
m_parent->setUrl( newUrl );
|
emit m_parent->urlSelected(url());
|
||||||
emit m_parent->urlSelected( url() );
|
|
||||||
// remember url as defaultStartDir and update startdir for autocompletion
|
// remember url as defaultStartDir and update startdir for autocompletion
|
||||||
if ( newUrl.isLocalFile() && !m_startDirCustomized ) {
|
if (newUrl.isLocalFile() && !m_startDirCustomized) {
|
||||||
m_startDir = newUrl;
|
m_startDir = newUrl;
|
||||||
m_startDir.setPath(m_startDir.directory());
|
m_startDir.setPath(m_startDir.directory());
|
||||||
updateCompletionStartDir(m_startDir);
|
updateCompletionStartDir(m_startDir);
|
||||||
|
@ -407,13 +407,13 @@ void KUrlRequester::KUrlRequesterPrivate::_k_slotFileDialogFinished()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KUrlRequester::setMode( KFile::Modes mode)
|
void KUrlRequester::setMode(KFile::Modes mode)
|
||||||
{
|
{
|
||||||
Q_ASSERT( (mode & KFile::Files) == 0 );
|
Q_ASSERT( (mode & KFile::Files) == 0);
|
||||||
d->fileDialogMode = mode;
|
d->fileDialogMode = mode;
|
||||||
if ( (mode & KFile::Directory) && !(mode & KFile::File) )
|
if ((mode & KFile::Directory) && !(mode & KFile::File)) {
|
||||||
d->myCompletion->setMode( KUrlCompletion::DirCompletion );
|
d->myCompletion->setMode( KUrlCompletion::DirCompletion );
|
||||||
|
}
|
||||||
if (d->myFileDialog) {
|
if (d->myFileDialog) {
|
||||||
d->myFileDialog->setMode(d->fileDialogMode);
|
d->myFileDialog->setMode(d->fileDialogMode);
|
||||||
}
|
}
|
||||||
|
@ -447,43 +447,42 @@ KFileDialog * KUrlRequester::fileDialog() const
|
||||||
d->myFileDialog->setWindowModality(d->fileDialogModality);
|
d->myFileDialog->setWindowModality(d->fileDialogModality);
|
||||||
connect(d->myFileDialog, SIGNAL(finished()), SLOT(_k_slotFileDialogFinished()));
|
connect(d->myFileDialog, SIGNAL(finished()), SLOT(_k_slotFileDialogFinished()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->myFileDialog;
|
return d->myFileDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KUrlRequester::clear()
|
void KUrlRequester::clear()
|
||||||
{
|
{
|
||||||
d->setText( QString() );
|
d->setText(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
KLineEdit * KUrlRequester::lineEdit() const
|
KLineEdit* KUrlRequester::lineEdit() const
|
||||||
{
|
{
|
||||||
return d->edit;
|
return d->edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
KComboBox * KUrlRequester::comboBox() const
|
KComboBox* KUrlRequester::comboBox() const
|
||||||
{
|
{
|
||||||
return d->combo;
|
return d->combo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotUpdateUrl()
|
void KUrlRequester::KUrlRequesterPrivate::_k_slotUpdateUrl()
|
||||||
{
|
{
|
||||||
KUrl u( KUrl::fromPath( QDir::currentPath() + '/' ), url().url() );
|
KUrl u(KUrl::fromPath(QDir::currentPath() + '/'), url().url());
|
||||||
myButton->setURL( u );
|
myButton->setURL(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KUrlRequester::eventFilter( QObject *obj, QEvent *ev )
|
bool KUrlRequester::eventFilter(QObject *obj, QEvent *ev)
|
||||||
{
|
{
|
||||||
if ( ( d->edit == obj ) || ( d->combo == obj ) )
|
if (d->edit == obj || d->combo == obj) {
|
||||||
{
|
if (ev->type() == QEvent::FocusIn || ev->type() == QEvent::FocusOut) {
|
||||||
if (( ev->type() == QEvent::FocusIn ) || ( ev->type() == QEvent::FocusOut ))
|
|
||||||
// Forward focusin/focusout events to the urlrequester; needed by file form element in khtml
|
// Forward focusin/focusout events to the urlrequester; needed by file form element in khtml
|
||||||
QApplication::sendEvent( this, ev );
|
QApplication::sendEvent(this, ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QWidget::eventFilter( obj, ev );
|
return QWidget::eventFilter(obj, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
KPushButton * KUrlRequester::button() const
|
KPushButton* KUrlRequester::button() const
|
||||||
{
|
{
|
||||||
return d->myButton;
|
return d->myButton;
|
||||||
}
|
}
|
||||||
|
@ -495,8 +494,9 @@ KUrlCompletion *KUrlRequester::completionObject() const
|
||||||
|
|
||||||
void KUrlRequester::setClickMessage(const QString& msg)
|
void KUrlRequester::setClickMessage(const QString& msg)
|
||||||
{
|
{
|
||||||
if(d->edit)
|
if (d->edit) {
|
||||||
d->edit->setClickMessage(msg);
|
d->edit->setClickMessage(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KUrlRequester::clickMessage() const
|
QString KUrlRequester::clickMessage() const
|
||||||
|
@ -522,12 +522,12 @@ const KEditListWidget::CustomEditor& KUrlRequester::customEditor()
|
||||||
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
|
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
|
||||||
|
|
||||||
KLineEdit *edit = d->edit;
|
KLineEdit *edit = d->edit;
|
||||||
if ( !edit && d->combo )
|
if (!edit && d->combo )
|
||||||
edit = qobject_cast<KLineEdit*>( d->combo->lineEdit() );
|
edit = qobject_cast<KLineEdit*>(d->combo->lineEdit());
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if ( !edit ) {
|
if ( !edit ) {
|
||||||
kWarning() << "KUrlRequester's lineedit is not a KLineEdit!??\n";
|
kWarning() << "KUrlRequester's lineedit is not a KLineEdit!??";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,6 @@ private:
|
||||||
Q_PRIVATE_SLOT(d, void _k_slotUpdateUrl())
|
Q_PRIVATE_SLOT(d, void _k_slotUpdateUrl())
|
||||||
Q_PRIVATE_SLOT(d, void _k_slotOpenDialog())
|
Q_PRIVATE_SLOT(d, void _k_slotOpenDialog())
|
||||||
Q_PRIVATE_SLOT(d, void _k_slotFileDialogFinished())
|
Q_PRIVATE_SLOT(d, void _k_slotFileDialogFinished())
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class KIO_EXPORT KUrlComboRequester : public KUrlRequester
|
class KIO_EXPORT KUrlComboRequester : public KUrlRequester
|
||||||
|
|
Loading…
Add table
Reference in a new issue