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:
|
||||
KUrlRequesterPrivate(KUrlRequester *parent)
|
||||
: m_parent(parent),
|
||||
edit(0),
|
||||
combo(0),
|
||||
fileDialogMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly)
|
||||
: m_startDirCustomized(false),
|
||||
m_parent(parent),
|
||||
edit(nullptr),
|
||||
combo(nullptr),
|
||||
fileDialogMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly),
|
||||
myButton(nullptr),
|
||||
myFileDialog(nullptr),
|
||||
myCompletion(nullptr),
|
||||
fileDialogModality(Qt::ApplicationModal)
|
||||
{
|
||||
qRegisterMetaType<KUrl>("KUrl");
|
||||
}
|
||||
|
@ -206,32 +211,35 @@ public:
|
|||
|
||||
|
||||
KUrlRequester::KUrlRequester( QWidget *editWidget, QWidget *parent)
|
||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
||||
: KHBox(parent),
|
||||
d(new KUrlRequesterPrivate(this))
|
||||
{
|
||||
// must have this as parent
|
||||
editWidget->setParent( this );
|
||||
d->combo = qobject_cast<KComboBox*>( editWidget );
|
||||
d->edit = qobject_cast<KLineEdit*>( editWidget );
|
||||
if ( d->edit ) {
|
||||
d->edit->setClearButtonShown( true );
|
||||
editWidget->setParent(this);
|
||||
d->combo = qobject_cast<KComboBox*>(editWidget);
|
||||
d->edit = qobject_cast<KLineEdit*>(editWidget);
|
||||
if (d->edit) {
|
||||
d->edit->setClearButtonShown(true);
|
||||
}
|
||||
|
||||
d->init();
|
||||
}
|
||||
|
||||
|
||||
KUrlRequester::KUrlRequester( QWidget *parent)
|
||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
||||
KUrlRequester::KUrlRequester(QWidget *parent)
|
||||
: KHBox(parent),
|
||||
d(new KUrlRequesterPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
|
||||
KUrlRequester::KUrlRequester( const KUrl& url, QWidget *parent)
|
||||
: KHBox( parent),d(new KUrlRequesterPrivate(this))
|
||||
KUrlRequester::KUrlRequester(const KUrl &url, QWidget *parent)
|
||||
: KHBox(parent),
|
||||
d(new KUrlRequesterPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
setUrl( url );
|
||||
setUrl(url);
|
||||
}
|
||||
|
||||
KUrlRequester::~KUrlRequester()
|
||||
|
@ -245,10 +253,7 @@ void KUrlRequester::KUrlRequesterPrivate::init()
|
|||
m_parent->setMargin(0);
|
||||
m_parent->setSpacing(-1); // use default spacing
|
||||
|
||||
myFileDialog = 0L;
|
||||
fileDialogModality = Qt::ApplicationModal;
|
||||
|
||||
if ( !combo && !edit ) {
|
||||
if (!combo && !edit) {
|
||||
edit = new KLineEdit( m_parent );
|
||||
edit->setClearButtonShown( true );
|
||||
}
|
||||
|
@ -271,7 +276,6 @@ void KUrlRequester::KUrlRequesterPrivate::init()
|
|||
m_parent->connect(myButton, SIGNAL(clicked()), m_parent, SLOT(_k_slotOpenDialog()));
|
||||
|
||||
m_startDir = KUrl::fromPath(QDir::currentPath());
|
||||
m_startDirCustomized = false;
|
||||
|
||||
myCompletion = new KUrlCompletion();
|
||||
updateCompletionStartDir(m_startDir);
|
||||
|
@ -293,7 +297,7 @@ void KUrlRequester::setText(const QString& text)
|
|||
d->setText(text);
|
||||
}
|
||||
|
||||
void KUrlRequester::setStartDir(const KUrl& startDir)
|
||||
void KUrlRequester::setStartDir(const KUrl &startDir)
|
||||
{
|
||||
d->m_startDir = startDir;
|
||||
d->m_startDirCustomized = true;
|
||||
|
@ -302,12 +306,12 @@ void KUrlRequester::setStartDir(const KUrl& startDir)
|
|||
|
||||
void KUrlRequester::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type()==QEvent::WindowTitleChange) {
|
||||
if (d->myFileDialog) {
|
||||
d->myFileDialog->setCaption(windowTitle());
|
||||
}
|
||||
}
|
||||
KHBox::changeEvent(e);
|
||||
if (e->type()==QEvent::WindowTitleChange) {
|
||||
if (d->myFileDialog) {
|
||||
d->myFileDialog->setCaption(windowTitle());
|
||||
}
|
||||
}
|
||||
KHBox::changeEvent(e);
|
||||
}
|
||||
|
||||
KUrl KUrlRequester::url() const
|
||||
|
@ -327,57 +331,54 @@ QString KUrlRequester::text() const
|
|||
|
||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
||||
{
|
||||
if ( myFileDialog )
|
||||
if ( myFileDialog->isVisible() )
|
||||
{
|
||||
if (myFileDialog) {
|
||||
if (myFileDialog->isVisible()) {
|
||||
//The file dialog is already being shown, raise it and exit
|
||||
myFileDialog->raise();
|
||||
myFileDialog->activateWindow();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ((fileDialogMode & KFile::Directory) && !(fileDialogMode & KFile::File)) ||
|
||||
/* catch possible fileDialog()->setMode( KFile::Directory ) changes */
|
||||
(myFileDialog && (myFileDialog->mode() & KFile::Directory) &&
|
||||
(myFileDialog->mode() & (KFile::File | KFile::Files)) == 0) )
|
||||
{
|
||||
const KUrl openUrl = (!m_parent->url().isEmpty() && !m_parent->url().isRelative() )
|
||||
? m_parent->url() : m_startDir;
|
||||
(myFileDialog->mode() & (KFile::File | KFile::Files)) == 0)) {
|
||||
const KUrl openUrl = (!m_parent->url().isEmpty() && !m_parent->url().isRelative()) ? m_parent->url() : m_startDir;
|
||||
|
||||
KUrl newurl;
|
||||
if (fileDialogMode & KFile::LocalOnly)
|
||||
newurl = KFileDialog::getExistingDirectory( openUrl, m_parent);
|
||||
else
|
||||
newurl = KFileDialog::getExistingDirectoryUrl( openUrl, m_parent);
|
||||
|
||||
if ( newurl.isValid() )
|
||||
{
|
||||
m_parent->setUrl( newurl );
|
||||
emit m_parent->urlSelected( url() );
|
||||
if (fileDialogMode & KFile::LocalOnly) {
|
||||
newurl = KFileDialog::getExistingDirectory(openUrl, m_parent);
|
||||
} else {
|
||||
newurl = KFileDialog::getExistingDirectoryUrl(openUrl, m_parent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit m_parent->openFileDialog( m_parent );
|
||||
|
||||
if (newurl.isValid()) {
|
||||
m_parent->setUrl(newurl);
|
||||
emit m_parent->urlSelected(url());
|
||||
}
|
||||
} else {
|
||||
emit m_parent->openFileDialog(m_parent);
|
||||
|
||||
//Creates the fileDialog if it doesn't exist yet
|
||||
KFileDialog *dlg = m_parent->fileDialog();
|
||||
KFileDialog* dlg = m_parent->fileDialog();
|
||||
|
||||
if ( !url().isEmpty() && !url().isRelative() ) {
|
||||
KUrl u( url() );
|
||||
// If we won't be able to list it (e.g. http), then don't try :)
|
||||
if ( KProtocolManager::supportsListing( u ) )
|
||||
dlg->setSelection( u.url() );
|
||||
if (!url().isEmpty() && !url().isRelative()) {
|
||||
KUrl u( url() );
|
||||
// If we won't be able to list it (e.g. http), then don't try :)
|
||||
if (KProtocolManager::supportsListing(u)) {
|
||||
dlg->setSelection(u.url());
|
||||
}
|
||||
} else {
|
||||
dlg->setUrl(m_startDir);
|
||||
dlg->setUrl(m_startDir);
|
||||
}
|
||||
|
||||
//Update the file dialog window modality
|
||||
if ( dlg->windowModality() != fileDialogModality )
|
||||
if (dlg->windowModality() != fileDialogModality) {
|
||||
dlg->setWindowModality(fileDialogModality);
|
||||
}
|
||||
|
||||
if ( fileDialogModality == Qt::NonModal )
|
||||
{
|
||||
if (fileDialogModality == Qt::NonModal) {
|
||||
dlg->show();
|
||||
} else {
|
||||
dlg->exec();
|
||||
|
@ -387,18 +388,17 @@ void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
|||
|
||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotFileDialogFinished()
|
||||
{
|
||||
if ( !myFileDialog )
|
||||
if (!myFileDialog) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( myFileDialog->result() == QDialog::Accepted )
|
||||
{
|
||||
if (myFileDialog->result() == QDialog::Accepted) {
|
||||
KUrl newUrl = myFileDialog->selectedUrl();
|
||||
if ( newUrl.isValid() )
|
||||
{
|
||||
m_parent->setUrl( newUrl );
|
||||
emit m_parent->urlSelected( url() );
|
||||
if (newUrl.isValid()) {
|
||||
m_parent->setUrl(newUrl);
|
||||
emit m_parent->urlSelected(url());
|
||||
// remember url as defaultStartDir and update startdir for autocompletion
|
||||
if ( newUrl.isLocalFile() && !m_startDirCustomized ) {
|
||||
if (newUrl.isLocalFile() && !m_startDirCustomized) {
|
||||
m_startDir = newUrl;
|
||||
m_startDir.setPath(m_startDir.directory());
|
||||
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;
|
||||
if ( (mode & KFile::Directory) && !(mode & KFile::File) )
|
||||
if ((mode & KFile::Directory) && !(mode & KFile::File)) {
|
||||
d->myCompletion->setMode( KUrlCompletion::DirCompletion );
|
||||
|
||||
}
|
||||
if (d->myFileDialog) {
|
||||
d->myFileDialog->setMode(d->fileDialogMode);
|
||||
}
|
||||
|
@ -447,43 +447,42 @@ KFileDialog * KUrlRequester::fileDialog() const
|
|||
d->myFileDialog->setWindowModality(d->fileDialogModality);
|
||||
connect(d->myFileDialog, SIGNAL(finished()), SLOT(_k_slotFileDialogFinished()));
|
||||
}
|
||||
|
||||
return d->myFileDialog;
|
||||
}
|
||||
|
||||
void KUrlRequester::clear()
|
||||
{
|
||||
d->setText( QString() );
|
||||
d->setText(QString());
|
||||
}
|
||||
|
||||
KLineEdit * KUrlRequester::lineEdit() const
|
||||
KLineEdit* KUrlRequester::lineEdit() const
|
||||
{
|
||||
return d->edit;
|
||||
}
|
||||
|
||||
KComboBox * KUrlRequester::comboBox() const
|
||||
KComboBox* KUrlRequester::comboBox() const
|
||||
{
|
||||
return d->combo;
|
||||
}
|
||||
|
||||
void KUrlRequester::KUrlRequesterPrivate::_k_slotUpdateUrl()
|
||||
{
|
||||
KUrl u( KUrl::fromPath( QDir::currentPath() + '/' ), url().url() );
|
||||
myButton->setURL( u );
|
||||
KUrl u(KUrl::fromPath(QDir::currentPath() + '/'), url().url());
|
||||
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 (( ev->type() == QEvent::FocusIn ) || ( ev->type() == QEvent::FocusOut ))
|
||||
if (d->edit == obj || d->combo == obj) {
|
||||
if (ev->type() == QEvent::FocusIn || ev->type() == QEvent::FocusOut) {
|
||||
// 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;
|
||||
}
|
||||
|
@ -495,8 +494,9 @@ KUrlCompletion *KUrlRequester::completionObject() const
|
|||
|
||||
void KUrlRequester::setClickMessage(const QString& msg)
|
||||
{
|
||||
if(d->edit)
|
||||
if (d->edit) {
|
||||
d->edit->setClickMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
QString KUrlRequester::clickMessage() const
|
||||
|
@ -522,12 +522,12 @@ const KEditListWidget::CustomEditor& KUrlRequester::customEditor()
|
|||
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
|
||||
|
||||
KLineEdit *edit = d->edit;
|
||||
if ( !edit && d->combo )
|
||||
edit = qobject_cast<KLineEdit*>( d->combo->lineEdit() );
|
||||
if (!edit && d->combo )
|
||||
edit = qobject_cast<KLineEdit*>(d->combo->lineEdit());
|
||||
|
||||
#ifndef NDEBUG
|
||||
if ( !edit ) {
|
||||
kWarning() << "KUrlRequester's lineedit is not a KLineEdit!??\n";
|
||||
kWarning() << "KUrlRequester's lineedit is not a KLineEdit!??";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -286,7 +286,6 @@ private:
|
|||
Q_PRIVATE_SLOT(d, void _k_slotUpdateUrl())
|
||||
Q_PRIVATE_SLOT(d, void _k_slotOpenDialog())
|
||||
Q_PRIVATE_SLOT(d, void _k_slotFileDialogFinished())
|
||||
|
||||
};
|
||||
|
||||
class KIO_EXPORT KUrlComboRequester : public KUrlRequester
|
||||
|
|
Loading…
Add table
Reference in a new issue