[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/KDE/4.8] kio/kio: Set the parent widget for message boxes created in KIO::SlaveInterface::m
From:       Dawit Alemayehu <adawit () kde ! org>
Date:       2012-04-30 23:45:45
Message-ID: 20120430234545.34178A60BB () git ! kde ! org
[Download RAW message or body]

Git commit 0057256b1a0a601346f3a343bbbec81bf2e48fe3 by Dawit Alemayehu.
Committed on 01/05/2012 at 01:17.
Pushed by adawit into branch 'KDE/4.8'.

Set the parent widget for message boxes created in KIO::SlaveInterface::messageBox.

REVIEW: 104351

M  +10   -0    kio/kio/scheduler.cpp
M  +22   -8    kio/kio/slaveinterface.cpp
M  +17   -0    kio/kio/slaveinterface.h
M  +4    -1    kio/kio/slaveinterface_p.h

http://commits.kde.org/kdelibs/0057256b1a0a601346f3a343bbbec81bf2e48fe3

diff --git a/kio/kio/scheduler.cpp b/kio/kio/scheduler.cpp
index 8d144bb..802f8b8 100644
--- a/kio/kio/scheduler.cpp
+++ b/kio/kio/scheduler.cpp
@@ -536,6 +536,10 @@ Slave *ProtoQueue::createSlave(const QString &protocol, SimpleJob *job, const KU
     QString errortext;
     Slave *slave = Slave::createSlave(protocol, url, error, errortext);
     if (slave) {
+        // Set the parent widget the slave should use to display message boxes.
+        if (job && job->ui()) {
+            slave->setWindow(job->ui()->window());
+        }
         scheduler()->connect(slave, SIGNAL(slaveDied(KIO::Slave*)),
                              SLOT(slotSlaveDied(KIO::Slave*)));
         scheduler()->connect(slave, SIGNAL(slaveStatus(pid_t,QByteArray,QString,bool)),
@@ -1222,6 +1226,12 @@ Slave *SchedulerPrivate::heldSlaveForJob(SimpleJob *job)
         kDebug(7006) << "HOLD: Reusing klauncher held slave (" << slave << ")";
     }
 
+    // Reset the parent widget the ioslave should use when displaying message
+    // boxes after being put on hold.
+    if (slave && job->ui()) {
+        slave->setWindow(job->ui()->window());
+    }
+
     return slave;
 }
 
diff --git a/kio/kio/slaveinterface.cpp b/kio/kio/slaveinterface.cpp
index d2f9f93..86727bf 100644
--- a/kio/kio/slaveinterface.cpp
+++ b/kio/kio/slaveinterface.cpp
@@ -400,6 +400,18 @@ void SlaveInterface::messageBox( int type, const QString &text, const QString &c
     }
 }
 
+void SlaveInterface::setWindow (QWidget* window)
+{
+    Q_D(SlaveInterface);
+    d->parentWindow = window;
+}
+
+QWidget* SlaveInterface::window() const
+{
+    const Q_D(SlaveInterface);
+    return d->parentWindow;
+}
+
 int SlaveInterfacePrivate::messageBox(int type, const QString &text,
                                       const QString &caption, const QString &buttonYes,
                                       const QString &buttonNo, const QString &dontAskAgainName)
@@ -411,7 +423,7 @@ int SlaveInterfacePrivate::messageBox(int type, const QString &text,
 
     // SMELL: the braindead way to support button icons
     KGuiItem buttonYesGui, buttonNoGui;
-    
+
     if (buttonYes == i18n("&Details"))
         buttonYesGui = KGuiItem(buttonYes, "help-about");
     else if (buttonYes == i18n("&Forever"))
@@ -429,32 +441,32 @@ int SlaveInterfacePrivate::messageBox(int type, const QString &text,
     switch (type) {
     case KIO::SlaveBase::QuestionYesNo:
         result = KMessageBox::questionYesNo(
-                     0, text, caption, buttonYesGui,
+                     parentWindow, text, caption, buttonYesGui,
                      buttonNoGui, dontAskAgainName);
         break;
     case KIO::SlaveBase::WarningYesNo:
         result = KMessageBox::warningYesNo(
-                     0, text, caption, buttonYesGui,
+                     parentWindow, text, caption, buttonYesGui,
                      buttonNoGui, dontAskAgainName);
         break;
     case KIO::SlaveBase::WarningContinueCancel:
         result = KMessageBox::warningContinueCancel(
-                     0, text, caption, buttonYesGui,
+                     parentWindow, text, caption, buttonYesGui,
                      KStandardGuiItem::cancel(), dontAskAgainName);
         break;
     case KIO::SlaveBase::WarningYesNoCancel:
         result = KMessageBox::warningYesNoCancel(
-                     0, text, caption, buttonYesGui, buttonNoGui,
+                     parentWindow, text, caption, buttonYesGui, buttonNoGui,
                      KStandardGuiItem::cancel(), dontAskAgainName);
         break;
     case KIO::SlaveBase::Information:
-        KMessageBox::information(0, text, caption, dontAskAgainName);
+        KMessageBox::information(parentWindow, text, caption, dontAskAgainName);
         result = 1; // whatever
         break;
     case KIO::SlaveBase::SSLMessageBox:
     {
         KIO::MetaData meta = sslMetaData;
-        KSslInfoDialog *kid = new KSslInfoDialog(0);
+        QPointer<KSslInfoDialog> kid (new KSslInfoDialog(parentWindow));
         //### this is boilerplate code and appears in khtml_part.cpp almost unchanged!
         QStringList sl = meta["ssl_peer_chain"].split('\x01', QString::SkipEmptyParts);
         QList<QSslCertificate> certChain;
@@ -476,6 +488,7 @@ int SlaveInterfacePrivate::messageBox(int type, const QString &text,
                             meta["ssl_cipher_used_bits"].toInt(),
                             meta["ssl_cipher_bits"].toInt(),
                             KSslInfoDialog::errorsFromString(meta["ssl_cert_errors"]));
+
             kDebug(7024) << "Showing SSL Info dialog";
             kid->exec();
             kDebug(7024) << "SSL Info dialog closed";
@@ -486,10 +499,11 @@ int SlaveInterfacePrivate::messageBox(int type, const QString &text,
         }
         // KSslInfoDialog deletes itself (Qt::WA_DeleteOnClose).
         result = 1; // whatever
+        delete kid;
         break;
     }
     default:
-        kWarning() << "unknown type" << type;
+        kWarning(7024) << "Unknown type" << type;
         result = 0;
         break;
     }
diff --git a/kio/kio/slaveinterface.h b/kio/kio/slaveinterface.h
index 3cdc2ae..4bfcec8 100644
--- a/kio/kio/slaveinterface.h
+++ b/kio/kio/slaveinterface.h
@@ -114,6 +114,23 @@ public:
     void setOffset( KIO::filesize_t offset );
     KIO::filesize_t offset() const;
 
+    /**
+     * Returns the top level window used as parent when displaying
+     * dialogs.
+     *
+     * @see setWindow
+     * @since 4.8.2
+     */
+    QWidget* window() const;
+
+    /**
+     * Sets the top level window used as a parent when displaying
+     * dialogs.
+     * @see window
+     * @since 4.8.2
+     */
+    void setWindow(QWidget* window);
+
 Q_SIGNALS:
     ///////////
     // Messages sent by the slave
diff --git a/kio/kio/slaveinterface_p.h b/kio/kio/slaveinterface_p.h
index e2ccfe0..4c3ffae 100644
--- a/kio/kio/slaveinterface_p.h
+++ b/kio/kio/slaveinterface_p.h
@@ -26,12 +26,14 @@
 
 static const unsigned int max_nums = 8;
 
+class QWidget;
+
 class KIO::SlaveInterfacePrivate
 {
 public:
     SlaveInterfacePrivate()
         : connection(0), filesize(0), offset(0), last_time(0),
-          nums(0), slave_calcs_speed(false)
+          nums(0), slave_calcs_speed(false), parentWindow(0)
     {
         start_time.tv_sec = 0;
         start_time.tv_usec = 0;
@@ -55,6 +57,7 @@ public:
     struct timeval start_time;
     uint nums;
     bool slave_calcs_speed;
+    QWidget* parentWindow;
 
     int messageBox(int type, const QString &text, const QString &caption,
                  const QString &buttonYes, const QString &buttonNo, const QString &dontAskAgainName);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic