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

List:       kde-commits
Subject:    kdelibs/kioslave/http
From:       Waldo Bastian <bastian () kde ! org>
Date:       2005-02-16 14:17:49
Message-ID: 20050216141749.CCD8A1D1CF () office ! kde ! org
[Download RAW message or body]

CVS commit by waba: 

* Fix "offline" & "use cache if possible" cache modes: Don't attempt to
verify expired cache entries
* Automatic offline support: Automatically switch to offline cache mode when
network is offline as indicated by kded networkstatus module.


  M +33 -3     http.cc   1.636
  M +2 -0      http.h   1.165


--- kdelibs/kioslave/http/http.cc  #1.635:1.636
@@ -1698,4 +1698,28 @@ void HTTPProtocol::httpError()
 }
 
+bool HTTPProtocol::isOffline(const KURL &url)
+{
+  const int NetWorkStatusUnknown = 1;
+  const int NetWorkStatusOnline = 8;
+  QCString replyType;
+  QByteArray params;
+  QByteArray reply;
+
+  QDataStream stream(params, IO_WriteOnly);
+  stream << url.url();
+
+  if ( dcopClient()->call( "kded", "networkstatus", "status(QString)",
+                           params, replyType, reply ) && (replyType == "int") )
+  {
+     int result;
+     QDataStream stream2( reply, IO_ReadOnly );
+     stream2 >> result;
+     kdDebug(7113) << "(" << m_pid << ") networkstatus status = " << result << endl;
+     return (result != NetWorkStatusUnknown) && (result != NetWorkStatusOnline);
+  }
+  kdDebug(7113) << "(" << m_pid << ") networkstatus <unreachable>" << endl;
+  return false; // On error, assume we are online
+}
+
 void HTTPProtocol::multiGet(const QByteArray &data)
 {
@@ -2056,4 +2080,8 @@ bool HTTPProtocol::httpOpen()
      m_request.fcache = checkCacheEntry( );
 
+     bool bOffline = isOffline(m_request.doProxy ? m_proxyURL : m_request.url);
+     if (bOffline && (m_request.cache != KIO::CC_Reload))
+        m_request.cache = KIO::CC_CacheOnly;
+
      if (m_request.cache == CC_Reload && m_request.fcache)
      {
@@ -2062,4 +2090,6 @@ bool HTTPProtocol::httpOpen()
         m_request.fcache = 0;
      }
+     if ((m_request.cache == KIO::CC_CacheOnly) || (m_request.cache == KIO::CC_Cache))
+        m_request.bMustRevalidate = false;
 
      m_request.bCachedWrite = true;
@@ -2080,7 +2110,7 @@ bool HTTPProtocol::httpOpen()
      }
 
-     if (m_request.cache == CC_CacheOnly)
+     if ((m_request.cache == CC_CacheOnly) || bOffline)
      {
-        error( ERR_DOES_NOT_EXIST, m_request.url.url() );
+        error( ERR_COULD_NOT_CONNECT, m_request.url.url() );
         return false;
      }

--- kdelibs/kioslave/http/http.h  #1.164:1.165
@@ -246,4 +246,6 @@ public:
   void httpError(); // Generate error message based on response code
 
+  bool isOffline(const KURL &url); // Check network status
+
 protected slots:
   void slotData(const QByteArray &);


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

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