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

List:       kde-core-devel
Subject:    [PATCH] Emit warnings from Job,
From:       Kévin_Ottens <ervin () ipsquad ! net>
Date:       2005-07-13 16:23:38
Message-ID: 200507131823.43288.ervin () ipsquad ! net
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hello,

Could someone review the attached patch?

It basically adds a warning() signal to Job class, and allow to avoid Job 
instances to display themselves warning messages. The resulting message box 
was crashing forwarding ioslaves.

Moreover ForwardingSlaveBase class is modified to forward the new warning() 
signal coming from Job instances.

It is needed in order to close BR:105369

I wait approval before committing.

Regards.
-- 
Kévin 'ervin' Ottens, http://ervin.ipsquad.net
"Ni le maître sans disciple, Ni le disciple sans maître,
Ne font reculer l'ignorance."

["forward_warnings.diff" (text/x-diff)]

Index: kio/kio/jobclasses.h
===================================================================
--- kio/kio/jobclasses.h	(revision 433385)
+++ kio/kio/jobclasses.h	(working copy)
@@ -178,6 +178,30 @@
         bool isAutoErrorHandlingEnabled() const;
 
         /**
+         * Enable or disable the automatic warning handling. When automatic
+         * warning handling is enabled and an error occurs, then a message box
+         * is displayed with the warning message
+         *
+         * The default is true.
+         *
+         * See also isAutoWarningHandlingEnabled , showErrorDialog
+         *
+         * @param enable enable or disable automatic warning handling
+         * @see isAutoWarningHandlingEnabled()
+         * @since 3.5
+         */
+        void setAutoWarningHandlingEnabled( bool enable );
+
+        /**
+         * Returns whether automatic warning handling is enabled or disabled.
+         * See also setAutoWarningHandlingEnabled .
+         * @return true if automatic warning handling is enabled
+         * @see setAutoWarningHandlingEnabled()
+         * @since 3.5
+         */
+        bool isAutoWarningHandlingEnabled() const;
+
+        /**
          * Enable or disable the message display from the job.
          *
          * The default is true.
@@ -319,6 +343,14 @@
         // KDE4: Separate rich-text string from plain-text string, for different \
widgets.  
         /**
+         * Emitted to display a warning about this job, as sent by the slave.
+         * @param job the job that emitted this signal
+         * @param msg the info message
+         */
+        void warning( KIO::Job *job, const QString & msg );
+        // KDE4: Separate rich-text string from plain-text string, for different \
widgets. +
+        /**
          * Emitted when the slave successfully connected to the host.
          * There is no guarantee the slave will send this, and this is
          * currently unused (in the applications).
Index: kio/kio/job.cpp
===================================================================
--- kio/kio/job.cpp	(revision 433777)
+++ kio/kio/job.cpp	(working copy)
@@ -81,11 +81,13 @@
 class Job::JobPrivate
 {
 public:
-    JobPrivate() : m_autoErrorHandling( false ), m_interactive( true ), m_parentJob( \
0L ), m_extraFlags(0), +    JobPrivate() : m_autoErrorHandling( false ), \
m_autoWarningHandling( true ), +                   m_interactive( true ), \
m_parentJob( 0L ), m_extraFlags(0),  m_processedSize(0)
                    {}
 
     bool m_autoErrorHandling;
+    bool m_autoWarningHandling;
     bool m_interactive;
     QGuardedPtr<QWidget> m_errorParentWidget;
     // Maybe we could use the QObject parent/child mechanism instead
@@ -314,6 +316,16 @@
   return d->m_autoErrorHandling;
 }
 
+void Job::setAutoWarningHandlingEnabled( bool enable )
+{
+  d->m_autoWarningHandling = enable;
+}
+
+bool Job::isAutoWarningHandlingEnabled() const
+{
+  return d->m_autoWarningHandling;
+}
+
 void Job::setInteractive(bool enable)
 {
   d->m_interactive = enable;
@@ -566,16 +578,19 @@
 
 void SimpleJob::slotWarning( const QString & errorText )
 {
-    if (!isInteractive()) return;
-
-    static uint msgBoxDisplayed = 0;
-    if ( msgBoxDisplayed == 0 ) // don't bomb the user with message boxes, only one \
at a time +    if (isAutoWarningHandlingEnabled())
     {
-        msgBoxDisplayed++;
-        KMessageBox::information( 0L, errorText );
-        msgBoxDisplayed--;
+        static uint msgBoxDisplayed = 0;
+        if ( msgBoxDisplayed == 0 ) // don't bomb the user with message boxes, only \
one at a time +        {
+            msgBoxDisplayed++;
+            KMessageBox::information( 0L, errorText );
+            msgBoxDisplayed--;
+        }
+        // otherwise just discard it.
     }
-    // otherwise just discard it.
+
+    emit warning( this, errorText );
 }
 
 void SimpleJob::slotInfoMessage( const QString & msg )
Index: kio/kio/forwardingslavebase.h
===================================================================
--- kio/kio/forwardingslavebase.h	(revision 433385)
+++ kio/kio/forwardingslavebase.h	(working copy)
@@ -174,6 +174,7 @@
 private slots:
     // KIO::Job
     void slotResult(KIO::Job *job);
+    void slotWarning(KIO::Job *job, const QString &msg);
     void slotInfoMessage(KIO::Job *job, const QString &msg);
     void slotTotalSize(KIO::Job *job, KIO::filesize_t size);
     void slotProcessedSize(KIO::Job *job, KIO::filesize_t size);
Index: kio/kio/forwardingslavebase.cpp
===================================================================
--- kio/kio/forwardingslavebase.cpp	(revision 433385)
+++ kio/kio/forwardingslavebase.cpp	(working copy)
@@ -342,8 +342,14 @@
 
 void ForwardingSlaveBase::connectJob(KIO::Job *job)
 {
+    // We will forward the warning message, no need to let the job
+    // display it itself
+    job->setAutoWarningHandlingEnabled(false);
+
     connect( job, SIGNAL( result(KIO::Job *) ),
              this, SLOT( slotResult(KIO::Job *) ) );
+    connect( job, SIGNAL( warning(KIO::Job *, const QString &) ),
+             this, SLOT( slotWarning(KIO::Job *, const QString &) ) );
     connect( job, SIGNAL( infoMessage(KIO::Job *, const QString &) ),
              this, SLOT( slotInfoMessage(KIO::Job *, const QString &) ) );
     connect( job, SIGNAL( totalSize(KIO::Job *, KIO::filesize_t) ),
@@ -404,6 +410,11 @@
     qApp->eventLoop()->exitLoop();
 }
 
+void ForwardingSlaveBase::slotWarning(KIO::Job* /*job*/, const QString &msg)
+{
+    warning(msg);
+}
+
 void ForwardingSlaveBase::slotInfoMessage(KIO::Job* /*job*/, const QString &msg)
 {
     infoMessage(msg);


[Attachment #6 (application/pgp-signature)]

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

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