Commit c30ee2b6 authored by Dawit Alemayehu's avatar Dawit Alemayehu
Browse files

* In KIO::Scheduler attempt to find and use the window-id from the top most

  level window so that the ids used will not be from temporary short lived
  windows such as file dialogs.

* Set the window widget when calling KIO functions in KFileDialog and related
  classes so that password information is preserved for the entire life of the
  application from which the file dialog is launched instead of a short duration.

BUG: 179663
FIXED-IN: 4.7.4
REVIEW: 103226
parent ed3555e3
......@@ -758,8 +758,8 @@ bool KDirOperator::mkdir(const QString& directory, bool enterDirectory)
for (; it != dirs.end(); ++it) {
url.addPath(*it);
exists = KIO::NetAccess::exists(url, KIO::NetAccess::DestinationSide, 0);
writeOk = !exists && KIO::NetAccess::mkdir(url, topLevelWidget());
exists = KIO::NetAccess::exists(url, KIO::NetAccess::DestinationSide, this);
writeOk = !exists && KIO::NetAccess::mkdir(url, this);
}
if (exists) { // url was already existent
......@@ -820,7 +820,7 @@ KIO::DeleteJob * KDirOperator::del(const KFileItemList& items,
if (doIt) {
KIO::JobFlags flags = showProgress ? KIO::DefaultFlags : KIO::HideProgressInfo;
KIO::DeleteJob *job = KIO::del(urls, flags);
job->ui()->setWindow(topLevelWidget());
job->ui()->setWindow(this);
job->ui()->setAutoErrorHandlingEnabled(true);
return job;
}
......@@ -878,7 +878,7 @@ KIO::CopyJob * KDirOperator::trash(const KFileItemList& items,
if (doIt) {
KIO::JobFlags flags = showProgress ? KIO::DefaultFlags : KIO::HideProgressInfo;
KIO::CopyJob *job = KIO::trash(urls, flags);
job->ui()->setWindow(topLevelWidget());
job->ui()->setWindow(this);
job->ui()->setAutoErrorHandlingEnabled(true);
return job;
}
......
......@@ -149,8 +149,8 @@ void KDirSelectDialog::Private::slotMkdir()
for ( ; it != dirs.end(); ++it )
{
folderurl.addPath( *it );
exists = KIO::NetAccess::exists( folderurl, KIO::NetAccess::DestinationSide, 0 );
writeOk = !exists && KIO::NetAccess::mkdir( folderurl, m_parent->topLevelWidget() );
exists = KIO::NetAccess::exists( folderurl, KIO::NetAccess::DestinationSide, m_parent );
writeOk = !exists && KIO::NetAccess::mkdir( folderurl, m_parent );
}
if ( exists ) // url was already existent
......@@ -244,7 +244,7 @@ void KDirSelectDialog::Private::slotMoveToTrash()
KIO::JobUiDelegate job;
if (job.askDeleteConfirmation(KUrl::List() << url, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) {
KIO::CopyJob* copyJob = KIO::trash(url);
copyJob->ui()->setWindow(this->m_parent);
copyJob->ui()->setWindow(m_parent);
copyJob->ui()->setAutoErrorHandlingEnabled(true);
}
}
......@@ -255,7 +255,7 @@ void KDirSelectDialog::Private::slotDelete()
KIO::JobUiDelegate job;
if (job.askDeleteConfirmation(KUrl::List() << url, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) {
KIO::DeleteJob* deleteJob = KIO::del(url);
deleteJob->ui()->setWindow(this->m_parent);
deleteJob->ui()->setWindow(m_parent);
deleteJob->ui()->setAutoErrorHandlingEnabled(true);
}
}
......@@ -408,7 +408,7 @@ KUrl KDirSelectDialog::url() const
if ( comboUrl.isValid() ) {
KIO::StatJob *statJob = KIO::stat(comboUrl, KIO::HideProgressInfo);
const bool ok = KIO::NetAccess::synchronousRun(statJob, 0);
const bool ok = KIO::NetAccess::synchronousRun(statJob, d->m_parent);
if (ok && statJob->statResult().isDir()) {
return comboUrl;
}
......
......@@ -197,7 +197,7 @@ public:
* This method won't show any progress dialogs for stating, since
* they are very annoying when stating.
*/
static KUrl mostLocalUrl(const KUrl &url);
KUrl mostLocalUrl(const KUrl &url);
void setInlinePreviewShown(bool show);
......@@ -608,7 +608,7 @@ KFileWidget::KFileWidget( const KUrl& _startDir, QWidget *parent )
if ( filename.isEmpty() )
{
KIO::StatJob *statJob = KIO::stat(startDir, KIO::HideProgressInfo);
statRes = KIO::NetAccess::synchronousRun(statJob, 0);
statRes = KIO::NetAccess::synchronousRun(statJob, this);
kDebug(kfile_area) << "stat of" << startDir << "-> statRes" << statRes << "isDir" << statJob->statResult().isDir();
if (!statRes || !statJob->statResult().isDir()) {
filename = startDir.fileName();
......@@ -824,7 +824,7 @@ void KFileWidget::slotOk()
while (!res && start < locationEditCurrentTextList.count()) {
topMostUrl = locationEditCurrentTextList.at(start);
statJob = KIO::stat(topMostUrl, KIO::HideProgressInfo);
res = KIO::NetAccess::synchronousRun(statJob, 0);
res = KIO::NetAccess::synchronousRun(statJob, this);
start++;
}
......@@ -841,7 +841,7 @@ void KFileWidget::slotOk()
for (int i = start; i < locationEditCurrentTextList.count(); ++i) {
KUrl currUrl = locationEditCurrentTextList.at(i);
KIO::StatJob *statJob = KIO::stat(currUrl, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, this);
if (res) {
// again, we don't care about filenames
if (!statJob->statResult().isDir()) {
......@@ -887,7 +887,7 @@ void KFileWidget::slotOk()
KUrl url(locationEditCurrentText);
if (d->operationMode == Opening) {
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, this);
if (res) {
if (!statJob->statResult().isDir()) {
url.adjustPath(KUrl::RemoveTrailingSlash);
......@@ -902,7 +902,7 @@ void KFileWidget::slotOk()
directory.setFileName(QString());
//Check if the folder exists
KIO::StatJob * statJob = KIO::stat(directory, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, this);
if (res) {
if (statJob->statResult().isDir()) {
url.adjustPath(KUrl::RemoveTrailingSlash);
......@@ -939,7 +939,7 @@ void KFileWidget::slotOk()
d->url = url;
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, this);
if (!KAuthorized::authorizeUrlAction("open", KUrl(), url)) {
QString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, d->url.prettyUrl());
......@@ -967,7 +967,7 @@ void KFileWidget::slotOk()
while (it != locationEditCurrentTextList.constEnd()) {
KUrl checkUrl(*it);
KIO::StatJob *checkStatJob = KIO::stat(checkUrl, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(checkStatJob, 0);
bool res = KIO::NetAccess::synchronousRun(checkStatJob, this);
if (res && checkStatJob->statResult().isDir()) {
KMessageBox::sorry(this, i18n("More than one folder has been selected and this dialog does not accept folders, so it is not possible to decide which one to enter. Please select only one folder to list it."), i18n("More than one folder provided"));
return;
......@@ -1474,7 +1474,7 @@ bool KFileWidgetPrivate::toOverwrite(const KUrl &url)
// kDebug(kfile_area);
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, q);
if (res) {
int ret = KMessageBox::warningContinueCancel( q,
......@@ -2262,7 +2262,7 @@ void KFileWidgetPrivate::updateLocationEditExtension (const QString &lastExtensi
{
// exists?
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool result = KIO::NetAccess::synchronousRun(statJob, 0);
bool result = KIO::NetAccess::synchronousRun(statJob, q);
if (result)
{
// kDebug (kfile_area) << "\tfile exists";
......@@ -2357,7 +2357,7 @@ void KFileWidgetPrivate::appendExtension (KUrl &url)
// exists?
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, q);
if (res)
{
// kDebug (kfile_area) << "\tfile exists - won't append extension";
......@@ -2711,7 +2711,7 @@ KUrl KFileWidgetPrivate::mostLocalUrl(const KUrl &url)
}
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, 0);
bool res = KIO::NetAccess::synchronousRun(statJob, q);
if (!res) {
return url;
......
......@@ -347,13 +347,13 @@ public:
* is displayed. The URL belonging to this popup menu is stored here.
*/
KUrl::List m_popupFiles;
QStringList m_supportedMimeTypes;
QString m_tempFileToDelete; // set when a tempfile was created for a Type=URL desktop file
QString m_text;
bool m_viewShowsHiddenFiles;
KNewFileMenu* q;
KNewFileMenu* q;
class Strategy;
KNewFileMenuStrategy m_strategy;
......@@ -497,7 +497,7 @@ void KNewFileMenuPrivate::executeRealFileOrDir(const KNewFileMenuSingleton::Entr
void KNewFileMenuPrivate::executeSymLink(const KNewFileMenuSingleton::Entry& entry)
{
KNameAndUrlInputDialog* dlg = new KNameAndUrlInputDialog(i18n("File name:"), entry.comment, m_popupFiles.first(), m_parentWidget);
KNameAndUrlInputDialog* dlg = new KNameAndUrlInputDialog(i18n("File name:"), entry.comment, m_popupFiles.first(), m_parentWidget);
dlg->setModal(q->isModal());
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setCaption(i18n("Create Symlink"));
......@@ -550,12 +550,11 @@ void KNewFileMenuPrivate::executeStrategy()
kjob->ui()->setWindow(m_parentWidget);
QObject::connect(kjob, SIGNAL(result(KJob*)), q, SLOT(slotResult(KJob*)));
}
}
void KNewFileMenuPrivate::executeUrlDesktopFile(const KNewFileMenuSingleton::Entry& entry)
{
KNameAndUrlInputDialog* dlg = new KNameAndUrlInputDialog(i18n("File name:"), entry.comment, m_popupFiles.first(), m_parentWidget);
KNameAndUrlInputDialog* dlg = new KNameAndUrlInputDialog(i18n("File name:"), entry.comment, m_popupFiles.first(), m_parentWidget);
m_strategy.m_templatePath = entry.templatePath;
dlg->setModal(q->isModal());
dlg->setAttribute(Qt::WA_DeleteOnClose);
......@@ -762,20 +761,20 @@ void KNewFileMenuPrivate::_k_slotCreateDirectory(bool writeHiddenDir)
url.addPath( name );
}
}
if(!askAgain){
if (!askAgain) {
KIO::SimpleJob * job = KIO::mkdir(url);
job->setProperty("isMkdirJob", true); // KDE5: cast to MkdirJob in slotResult instead
job->ui()->setWindow(m_parentWidget);
job->ui()->setAutoErrorHandlingEnabled(true);
KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Mkdir, KUrl(), url, job );
if (job) {
// We want the error handling to be done by slotResult so that subclasses can reimplement it
job->ui()->setAutoErrorHandlingEnabled(false);
QObject::connect(job, SIGNAL(result(KJob *)), q, SLOT(slotResult(KJob *)));
}
}
}
}
else {
q->createDirectory(); // ask again for the name
}
......@@ -935,14 +934,13 @@ void KNewFileMenuPrivate::_k_slotUrlDesktopFile()
group.writeEntry("Icon", KProtocolInfo::icon(linkUrl.protocol()));
group.writePathEntry("URL", linkUrl.prettyUrl());
df.sync();
m_strategy.m_src = tempFileName;
m_strategy.m_tempFileToDelete = tempFileName;
executeStrategy();
}
KNewFileMenu::KNewFileMenu(KActionCollection* collection, const QString& name, QObject* parent)
: KActionMenu(KIcon("document-new"), i18n("Create New"), parent),
d(new KNewFileMenuPrivate(this))
......
......@@ -1288,14 +1288,36 @@ void SchedulerPrivate::checkSlaveOnHold(bool b)
m_checkOnHold = b;
}
/*
Returns the top most window associated with widget.
Unlike QWidget::window(), this function does its best to find and return the
main application window associated with the given widget.
If widget itself is a dialog or its parent is a dialog, and that dialog has a
parent widget then this function will iterate through all those widgets to
find the top most window, which most of the time is the main window of the
application. By contrast, QWidget::window() would simply return the first
file dialog it encountered since it is the "next ancestor widget that has (or
could have) a window-system frame".
*/
static QWidget* topLevelWindow(QWidget* widget)
{
QWidget* w = widget;
while (w && w->parentWidget()) {
w = w->parentWidget();
}
return (w ? w->window() : 0);
}
void SchedulerPrivate::registerWindow(QWidget *wid)
{
if (!wid)
return;
QWidget* window = wid->window();
QWidget* window = topLevelWindow(wid);
QObject *obj = static_cast<QObject *>(window);
if (!m_windowList.contains(obj))
{
// We must store the window Id because by the time
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment