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,7 +211,8 @@ 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);
|
||||||
|
@ -221,14 +227,16 @@ KUrlRequester::KUrlRequester( QWidget *editWidget, QWidget *parent)
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -245,9 +253,6 @@ 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;
|
|
||||||
fileDialogModality = Qt::ApplicationModal;
|
|
||||||
|
|
||||||
if (!combo && !edit) {
|
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);
|
||||||
|
@ -327,37 +331,33 @@ 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() )
|
if (newurl.isValid()) {
|
||||||
{
|
|
||||||
m_parent->setUrl(newurl);
|
m_parent->setUrl(newurl);
|
||||||
emit m_parent->urlSelected(url());
|
emit m_parent->urlSelected(url());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
emit m_parent->openFileDialog(m_parent);
|
emit m_parent->openFileDialog(m_parent);
|
||||||
|
|
||||||
//Creates the fileDialog if it doesn't exist yet
|
//Creates the fileDialog if it doesn't exist yet
|
||||||
|
@ -366,18 +366,19 @@ void KUrlRequester::KUrlRequesterPrivate::_k_slotOpenDialog()
|
||||||
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,14 +388,13 @@ 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
|
||||||
|
@ -411,9 +411,9 @@ 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,7 +447,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,12 +473,12 @@ void KUrlRequester::KUrlRequesterPrivate::_k_slotUpdateUrl()
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,9 +494,10 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -527,7 +527,7 @@ const KEditListWidget::CustomEditor& KUrlRequester::customEditor()
|
||||||
|
|
||||||
#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