File kwin-background-focus-handling.diff of Package kdelibs3

--- kio/kio/jobclasses.h
+++ kio/kio/jobclasses.h
@@ -227,6 +227,13 @@
 	 * @see setWindow()
          */
         QWidget *window() const;
+        
+        /**
+         * Updates the last user action timestamp to the given time.
+         * See KApplication::updateUserTimestamp() .
+         * @since 3.5.6
+         */
+        void updateUserTimestamp( unsigned long time );
 
         /**
          * Set the parent Job.
@@ -482,6 +489,11 @@
 
         /**
          * @internal
+         */
+        unsigned long userTimestamp() const;
+
+        /**
+         * @internal
          * Some extra storage space for jobs that don't have their own
          * private d pointer.
          */
--- kio/kio/job.cpp
+++ kio/kio/job.cpp
@@ -40,6 +40,11 @@
 }
 #include <qtimer.h>
 #include <qfile.h>
+#if defined Q_WS_X11
+#include <netwm.h>
+#include <fixx11h.h>
+#endif
+
 
 #include <kapplication.h>
 #include <kglobal.h>
@@ -83,7 +88,7 @@
 public:
     JobPrivate() : m_autoErrorHandling( false ), m_autoWarningHandling( true ),
                    m_interactive( true ), m_parentJob( 0L ), m_extraFlags(0),
-                   m_processedSize(0)
+                   m_processedSize(0), m_userTimestamp(0)
                    {}
 
     bool m_autoErrorHandling;
@@ -95,6 +100,7 @@
     Job* m_parentJob;
     int m_extraFlags;
     KIO::filesize_t m_processedSize;
+    unsigned long m_userTimestamp;
 };
 
 Job::Job(bool showProgressInfo) : QObject(0, "job"), m_error(0), m_percent(0)
@@ -106,6 +112,7 @@
     if ( showProgressInfo )
     {
         m_progressId = Observer::self()->newJob( this, true );
+        addMetaData("progress-id", QString::number(m_progressId));
         //kdDebug(7007) << "Created job " << this << " with progress info -- m_progressId=" << m_progressId << endl;
         // Connect global progress info signals
         connect( this, SIGNAL( percent( KIO::Job*, unsigned long ) ),
@@ -122,6 +129,8 @@
     // Don't exit while this job is running
     if (kapp)
         kapp->ref();
+    if (kapp)
+        updateUserTimestamp( kapp->userTimestamp());
 }
 
 Job::~Job()
@@ -166,6 +175,7 @@
        job->mergeMetaData(m_outgoingMetaData);
 
     job->setWindow( m_window );
+    job->updateUserTimestamp( d->m_userTimestamp );
 }
 
 void Job::removeSubjob( Job *job )
@@ -347,6 +357,19 @@
   return m_window;
 }
 
+void Job::updateUserTimestamp( unsigned long time )
+{
+#if defined Q_WS_X11
+  if( d->m_userTimestamp == 0 || NET::timestampCompare( time, d->m_userTimestamp ) > 0 )
+      d->m_userTimestamp = time;
+#endif
+}
+
+unsigned long Job::userTimestamp() const
+{
+    return d->m_userTimestamp;
+}
+
 void Job::setParentJob(Job* job)
 {
   Q_ASSERT(d->m_parentJob == 0L);
@@ -507,6 +530,11 @@
        QString id;
        addMetaData("window-id", id.setNum((ulong)m_window->winId()));
     }
+    if (userTimestamp())
+    {
+       QString id;
+       addMetaData("user-timestamp", id.setNum(userTimestamp()));
+    }
 
     QString sslSession = KSSLCSessionCache::getSessionForURL(m_url);
     if ( !sslSession.isNull() )
--- kio/kio/slavebase.cpp
+++ kio/kio/slavebase.cpp
@@ -58,6 +58,8 @@
 #include "kio/ioslave_defaults.h"
 #include "kio/slaveinterface.h"
 
+#include "uiserver_stub.h"
+
 #ifndef NDEBUG
 #ifdef HAVE_BACKTRACE
 #include <execinfo.h>
@@ -820,20 +822,31 @@
     QByteArray reply;
     AuthInfo authResult;
     long windowId = metaData("window-id").toLong();
+    long progressId = metaData("progress-id").toLong();
+    unsigned long userTimestamp = metaData("user-timestamp").toULong();
 
-    kdDebug(7019) << "SlaveBase::openPassDlg window-id=" << windowId << endl;
+    kdDebug(7019) << "SlaveBase::openPassDlg window-id=" << windowId << " progress-id=" << progressId << endl;
 
     (void) dcopClient(); // Make sure to have a dcop client.
 
+    UIServer_stub uiserver( "kio_uiserver", "UIServer" );
+    if (progressId)
+      uiserver.setJobVisible( progressId, false );
+
     QDataStream stream(params, IO_WriteOnly);
 
     if (metaData("no-auth-prompt").lower() == "true")
-       stream << info << QString("<NoAuthPrompt>") << windowId << s_seqNr;
+       stream << info << QString("<NoAuthPrompt>") << windowId << s_seqNr << userTimestamp;
     else
-       stream << info << errorMsg << windowId << s_seqNr;
+       stream << info << errorMsg << windowId << s_seqNr << userTimestamp;
 
-    if (!d->dcopClient->call( "kded", "kpasswdserver", "queryAuthInfo(KIO::AuthInfo, QString, long int, long int)",
-                               params, replyType, reply ) )
+    bool callOK = d->dcopClient->call( "kded", "kpasswdserver", "queryAuthInfo(KIO::AuthInfo, QString, long int, long int, unsigned long int)",
+                                        params, replyType, reply );
+
+    if (progressId)
+      uiserver.setJobVisible( progressId, true );
+
+    if (!callOK)
     {
        kdWarning(7019) << "Can't communicate with kded_kpasswdserver!" << endl;
        return false;
@@ -1157,15 +1170,16 @@
     QByteArray reply;
     AuthInfo authResult;
     long windowId = metaData("window-id").toLong();
+    unsigned long userTimestamp = metaData("user-timestamp").toULong();
 
     kdDebug(7019) << "SlaveBase::checkCachedAuthInfo window = " << windowId << " url = " << info.url.url() << endl;
 
     (void) dcopClient(); // Make sure to have a dcop client.
 
     QDataStream stream(params, IO_WriteOnly);
-    stream << info << windowId;
+    stream << info << windowId << userTimestamp;
 
-    if ( !d->dcopClient->call( "kded", "kpasswdserver", "checkAuthInfo(KIO::AuthInfo, long int)",
+    if ( !d->dcopClient->call( "kded", "kpasswdserver", "checkAuthInfo(KIO::AuthInfo, long int, unsigned long int)",
                                params, replyType, reply ) )
     {
        kdWarning(7019) << "Can't communicate with kded_kpasswdserver!" << endl;
--- kio/kpasswdserver/kpasswdserver.cpp
+++ kio/kpasswdserver/kpasswdserver.cpp
@@ -178,8 +178,16 @@
 KIO::AuthInfo
 KPasswdServer::checkAuthInfo(KIO::AuthInfo info, long windowId)
 {
+    return checkAuthInfo(info, windowId, 0);
+}
+
+KIO::AuthInfo
+KPasswdServer::checkAuthInfo(KIO::AuthInfo info, long windowId, unsigned long usertime)
+{
     kdDebug(130) << "KPasswdServer::checkAuthInfo: User= " << info.username
               << ", WindowId = " << windowId << endl;
+    if( usertime != 0 )
+        kapp->updateUserTimestamp( usertime );
 
     QString key = createCacheKey(info);
 
@@ -237,10 +245,18 @@
 KIO::AuthInfo
 KPasswdServer::queryAuthInfo(KIO::AuthInfo info, QString errorMsg, long windowId, long seqNr)
 {
+    return queryAuthInfo(info, errorMsg, windowId, seqNr, 0 );
+}
+
+KIO::AuthInfo
+KPasswdServer::queryAuthInfo(KIO::AuthInfo info, QString errorMsg, long windowId, long seqNr, unsigned long usertime)
+{
     kdDebug(130) << "KPasswdServer::queryAuthInfo: User= " << info.username
               << ", Message= " << info.prompt << ", WindowId = " << windowId << endl;
     if ( !info.password.isEmpty() ) // should we really allow the caller to pre-fill the password?
         kdDebug(130) <<  "password was set by caller" << endl;
+    if( usertime != 0 )
+        kapp->updateUserTimestamp( usertime );
 
     QString key = createCacheKey(info);
     Request *request = new Request;
--- kio/kpasswdserver/kpasswdserver.h
+++ kio/kpasswdserver/kpasswdserver.h
@@ -45,7 +45,10 @@
   ~KPasswdServer();
 
 k_dcop:
+  // KDE4 merge
+  KIO::AuthInfo checkAuthInfo(KIO::AuthInfo, long, unsigned long);
   KIO::AuthInfo checkAuthInfo(KIO::AuthInfo, long);
+  KIO::AuthInfo queryAuthInfo(KIO::AuthInfo, QString, long, long, unsigned long);
   KIO::AuthInfo queryAuthInfo(KIO::AuthInfo, QString, long, long);
   void addAuthInfo(KIO::AuthInfo, long);
 
openSUSE Build Service is sponsored by