OSDN Git Service

reformat
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sun, 27 Jun 2004 15:06:24 +0000 (15:06 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sun, 27 Jun 2004 15:06:24 +0000 (15:06 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1206 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/libkita/access.cpp

index 4c58957..79999fa 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
-*   Copyright (C) 2003 by Hideki Ikemoto                                  *
-*   ikemo@wakaba.jp                                                       *
+*   Copyright (C) 2003-2004 by Hideki Ikemoto                             *
+*   ikemo@users.sourceforge.jp                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
@@ -43,7 +43,8 @@ QCString Access::getCacheData( const KURL& url )
     QString cachePath = Kita::Cache::getPath( url );
 
     QFile file( cachePath );
-    if ( !file.open( IO_ReadOnly ) ) {
+    if ( !file.open( IO_ReadOnly ) )
+    {
         return 0;
     }
     int dataSize = file.size();
@@ -58,23 +59,27 @@ QCString Access::getCacheData( const KURL& url )
 // partial data¤¬Æþ¤Ã¤Æ¤ë¤Î¤Ç¤½¤ì¤ò½ñ¤­´¹¤¨¤ë¡£
 void Access::writeCacheData( const KURL& url )
 {
-    if ( m_orgData.isNull() && responseCode() == 304 ) {
+    if ( m_orgData.isNull() && responseCode() == 304 )
+    {
         m_threadData = QString::null;
         m_orgData = m_threadData;
         return ;
-    } 
-    if ( ! m_orgData.isNull() && responseCode() == 304 ) {
+    }
+    if ( ! m_orgData.isNull() && responseCode() == 304 )
+    {
         m_threadData = m_orgData;
         return ;
     }
-    if ( ! m_orgData.isNull() && responseCode() == 206 ) {
+    if ( ! m_orgData.isNull() && responseCode() == 206 )
+    {
         m_threadData = m_orgData + m_threadData;
     }
     m_orgData = m_threadData;
-    if ( m_invalidDataReceived ) {
+    if ( m_invalidDataReceived )
+    {
         return;
     }
-    
+
     QString cachePath = Kita::Cache::getPath( url );
     FILE *fs = fopen( QFile::encodeName( cachePath ), "w" );
     if ( !fs ) return ;
@@ -88,7 +93,8 @@ void Access::writeCacheData( const KURL& url )
 QString Access::getupdate()
 {
     QString getURL = m_url.url();
-    if ( Kita::boardType( getURL ) == Board_MachiBBS ) {
+    if ( Kita::boardType( getURL ) == Board_MachiBBS )
+    {
         getURL = Kita::datToThread( getURL );
     }
 
@@ -97,7 +103,8 @@ QString Access::getupdate()
     m_firstReceive = FALSE;
     m_invalidDataReceived = FALSE;
 
-    if ( KURL( getURL ).protocol() != "k2ch" ) {
+    if ( KURL( getURL ).protocol() != "k2ch" )
+    {
         KIO::SlaveConfig::self() ->setConfigData( "http",
                 KURL( getURL ).host(),
                 "UserAgent",
@@ -113,8 +120,9 @@ QString Access::getupdate()
 
     // use 'HTTP-Headers' metadata.
     job->addMetaData( "PropagateHttpHeader", "true" );
-    if ( ! m_orgData.isNull() ) {
-       m_firstReceive = TRUE; /* remove first char. see also slotReceiveThreadData() */
+    if ( ! m_orgData.isNull() )
+    {
+        m_firstReceive = TRUE; /* remove first char. see also slotReceiveThreadData() */
         job->addMetaData( "resume", QString::number( m_orgData.length() - 1 ) );
         job->addMetaData( "AllowCompressedPage", "false" );
     }
@@ -131,13 +139,16 @@ void Access::make_cacheDir( const KURL& url )
     KURL cacheDir = KURL( cachePath, "." );
     KURL cacheDir2 = KURL( cacheDir, ".." );
     KURL cacheDir3 = KURL( cacheDir2, ".." );
-    if ( !KIO::NetAccess::exists( cacheDir3 ) ) {
+    if ( !KIO::NetAccess::exists( cacheDir3 ) )
+    {
         KIO::NetAccess::mkdir( cacheDir3 );
     }
-    if ( !KIO::NetAccess::exists( cacheDir2 ) ) {
+    if ( !KIO::NetAccess::exists( cacheDir2 ) )
+    {
         KIO::NetAccess::mkdir( cacheDir2 );
     }
-    if ( !KIO::NetAccess::exists( cacheDir ) ) {
+    if ( !KIO::NetAccess::exists( cacheDir ) )
+    {
         KIO::NetAccess::mkdir( cacheDir );
     }
 }
@@ -145,28 +156,35 @@ void Access::make_cacheDir( const KURL& url )
 void Access::slotThreadResult( KIO::Job* job )
 {
     m_currentJob = 0;
-    if ( job->error() ) {
+    if ( job->error() )
+    {
         job->showErrorDialog();
-    } else {
+    }
+    else
+    {
         m_header = job->queryMetaData( "HTTP-Headers" );
     }
-    
-    if ( m_threadData.length() ) {
-        if ( Kita::boardType( m_url.url() ) == Board_MachiBBS ) {
+
+    if ( m_threadData.length() )
+    {
+        if ( Kita::boardType( m_url.url() ) == Board_MachiBBS )
+        {
             // TODO: need to refactoring.
             parse_machiBBS();
             KURL url = m_url;
             writeCacheData( url );
             emit receiveData( m_threadData );
-        } else {
+        }
+        else
+        {
             KURL url = m_url;
             make_cacheDir( url );
             writeCacheData( url );
         }
     }
-    
-    if ( Kita::boardType( m_url.url() ) == Board_MachiBBS ) {
-    }
+
+    if ( Kita::boardType( m_url.url() ) == Board_MachiBBS )
+    {}
     emit finishLoad();
 }
 
@@ -177,14 +195,16 @@ void Access::parse_machiBBS()
     // pattern 1 (tokyo,kanagawa,...)
     QRegExp regexp( "<dt>(.*) .*<font color=\"#......\"><b> (.*) </b></font> .* (..../../..).* (..:..:..) ID:(.*)<br><dd>(.*)" );
     QRegExp regexp2( "<dt>(.*) .*<a href=\"mailto:(.*)\"><b> (.*) </B></a> .* (..../../..).* (..:..:..) ID:(.*)<br><dd>(.*)" );
-    
+
     // pattern 2 (hokkaido,...)
     QRegExp regexp3( "<dt>(.*) .*<font color=\"#......\"><b> (.*) </b></font> .* (..../../..).* (..:..:..) ID:(.*)<font size=.>\\[ .*" );
     QRegExp regexp4( " \\]</font><br><dd>(.*)" );
     QRegExp regexp5( "<dt>(.*) .*<a href=\"mailto:(.*)\"><b> (.*) </B></a> .* (..../../..).* (..:..:..) ID:(.*)<font size=.>\\[ .*" );
-    for ( QStringList::iterator it = lines.begin(); it != lines.end(); ++it ) {
+    for ( QStringList::iterator it = lines.begin(); it != lines.end(); ++it )
+    {
         QString line = (*it);
-        if ( regexp.search( line ) != -1 ) {
+        if ( regexp.search( line ) != -1 )
+        {
             int num = regexp.cap( 1 ).toInt();
             QString name = regexp.cap( 2 );
             QString date = regexp.cap( 3 );
@@ -192,9 +212,11 @@ void Access::parse_machiBBS()
             QString id = regexp.cap( 5 );
             QString message = regexp.cap( 6 );
             QString datStr = name + "<><>" + date + " " + time + " ID:" + id
-            + "<>" + message + "<>\n";
+                             + "<>" + message + "<>\n";
             ret += datStr;
-        } else if ( regexp2.search( line ) != -1 ) {
+        }
+        else if ( regexp2.search( line ) != -1 )
+        {
             int num = regexp2.cap( 1 ).toInt();
             QString mail = regexp2.cap( 2 );
             QString name = regexp2.cap( 3 );
@@ -203,13 +225,16 @@ void Access::parse_machiBBS()
             QString id = regexp2.cap( 6 );
             QString message = regexp2.cap( 7 );
             QString datStr = name + "<>" + mail + "<>" + date + " " + time + " ID:" + id
-            + "<>" + message + "<>\n";
+                             + "<>" + message + "<>\n";
             ret += datStr;
-        } else if ( regexp3.search( line ) != -1 ) {
+        }
+        else if ( regexp3.search( line ) != -1 )
+        {
             ++it;
             if ( it == lines.end() ) break;
             QString nextLine = (*it);
-            if ( regexp4.search( nextLine ) != -1 ) {
+            if ( regexp4.search( nextLine ) != -1 )
+            {
                 int num = regexp3.cap( 1 ).toInt();
                 QString name = regexp3.cap( 2 );
                 QString date = regexp3.cap( 3 );
@@ -217,14 +242,17 @@ void Access::parse_machiBBS()
                 QString id = regexp3.cap( 5 );
                 QString message = regexp4.cap( 1 );
                 QString datStr = name + "<><>" + date + " " + time + " ID:" + id
-                + "<>" + message + "<>\n";
+                                 + "<>" + message + "<>\n";
                 ret += datStr;
             }
-        } else if ( regexp5.search( line ) != -1 ) {
+        }
+        else if ( regexp5.search( line ) != -1 )
+        {
             ++it;
             if ( it == lines.end() ) break;
             QString nextLine = (*it);
-            if ( regexp4.search( nextLine ) != -1 ) {
+            if ( regexp4.search( nextLine ) != -1 )
+            {
                 int num = regexp5.cap( 1 ).toInt();
                 QString mail = regexp5.cap( 2 );
                 QString name = regexp5.cap( 3 );
@@ -233,7 +261,7 @@ void Access::parse_machiBBS()
                 QString id = regexp5.cap( 6 );
                 QString message = regexp4.cap( 1 );
                 QString datStr = name + "<>" + mail + "<>" + date + " " + time + " ID:" + id
-                + "<>" + message + "<>\n";
+                                 + "<>" + message + "<>\n";
                 ret += datStr;
             }
         }
@@ -258,15 +286,18 @@ void Access::slotReceiveThreadData( KIO::Job*, const QByteArray& data )
 {
     QString cstr( data );
     /* If this is the first call at resumption, remove LF at head. */
-    if(m_firstReceive) {
-        if ( cstr[0] != '\n' ) {
+    if(m_firstReceive)
+    {
+        if ( cstr[0] != '\n' )
+        {
             m_invalidDataReceived = TRUE;
         }
-       cstr = cstr.mid(1);
+        cstr = cstr.mid(1);
     }
     m_firstReceive = FALSE;
     m_threadData += cstr ;
-    if ( Kita::boardType( m_url.url() ) != Board_MachiBBS ) {
+    if ( Kita::boardType( m_url.url() ) != Board_MachiBBS )
+    {
         emit receiveData( cstr );
     }
 }
@@ -289,10 +320,13 @@ int Access::serverTime()
     QStringList headerList = QStringList::split( "\n", m_header );
     QRegExp regexp( "Date: (...), (..) (...) (....) (..:..:..) .*" );
     QString dateStr = headerList.grep( regexp ) [ 0 ];
-    if ( regexp.search( dateStr ) == -1 ) {
+    if ( regexp.search( dateStr ) == -1 )
+    {
         // invalid date format
         return QDateTime::currentDateTime().toTime_t();
-    } else {
+    }
+    else
+    {
         // I hate this format ;p
         QString usLocalDateStr = regexp.cap( 1 ) + " " + regexp.cap( 3 ) + " " +
                                  regexp.cap( 2 ) + " " + regexp.cap( 5 ) + " " +
@@ -311,10 +345,13 @@ int Access::responseCode()
     QStringList headerList = QStringList::split( "\n", m_header );
     QRegExp regexp( "HTTP/1\\.[01] ([0-9]+) .*" );
     QString dateStr = headerList.grep( regexp ) [ 0 ];
-    if ( regexp.search( dateStr ) == -1 ) {
+    if ( regexp.search( dateStr ) == -1 )
+    {
         // invalid response
         return 0;
-    } else {
+    }
+    else
+    {
         return regexp.cap( 1 ).toInt();
     }
 }
@@ -341,7 +378,8 @@ bool Access::deleteLog( const Thread* thread, QWidget* parent )
                                "Kita",
                                "Do you want to delete Log ?",
                                QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
-            == QMessageBox::Ok ) {
+            == QMessageBox::Ok )
+    {
 
         KURL url = thread->datURL();
         QString str = Kita::Cache::getPath( url );