OSDN Git Service

impl FavoriteBoards::readFromXML
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sat, 14 Feb 2004 10:49:33 +0000 (10:49 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sat, 14 Feb 2004 10:49:33 +0000 (10:49 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@869 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/libkita/favoriteboards.cpp
kita/src/libkita/favoriteboards.h

index a58ba21..63d95c4 100644 (file)
@@ -9,6 +9,10 @@
 ***************************************************************************/
 #include "favoriteboards.h"
 
+#include "board.h"
+
+#include <qdom.h>
+
 using namespace Kita;
 
 FavoriteBoards* FavoriteBoards::instance = 0;
@@ -29,18 +33,60 @@ FavoriteBoards* FavoriteBoards::getInstance()
 
 void FavoriteBoards::append( KURL& url )
 {
-    if ( ! getInstance()->m_list.contains( url ) ) {
-        getInstance()->m_list.append( url );
+    if ( ! getInstance() ->m_list.contains( url ) ) {
+        getInstance() ->m_list.append( url );
     }
 }
 
 void FavoriteBoards::remove( KURL& url )
 {
-    if ( getInstance()->m_list.contains( url ) ) {
-        getInstance()->m_list.remove( url );
+    if ( getInstance() ->m_list.contains( url ) ) {
+        getInstance() ->m_list.remove( url );
+    }
+}
+
+const QValueList<KURL>& FavoriteBoards::boards()
+{
+    return getInstance() ->m_list;
+}
+
+bool FavoriteBoards::readFromXML( QString& xml )
+{
+    FavoriteBoards * instance = FavoriteBoards::getInstance();
+    instance->m_list.clear();
+
+    QDomDocument document;
+    if ( ! document.setContent( xml, true ) ) {
+        return false;
+    }
+    QDomElement root = document.documentElement();
+
+    QDomNode node = root.firstChild();
+    while ( ! node.isNull() ) {
+        if ( node.isElement() &&
+                node.nodeName() == QString( "board" ) &&
+                node.namespaceURI() == QString( "http://kita.sourceforge.jp/ns/board" ) ) {
+            processChildNode( node );
+        }
+        node = node.nextSibling();
     }
+    return true;
 }
 
-void FavoriteBoards::readFromXML( QString& xml )
+void FavoriteBoards::processChildNode( QDomNode& node )
 {
+    QDomNode urlNode = node.namedItem( "url" );
+    QDomNode nameNode = node.namedItem( "name" );
+    if ( ! urlNode.isElement() || ! nameNode.isElement() ) {
+        return ;
+    }
+
+    QString urlText = urlNode.toElement().text();
+    QString nameText = nameNode.toElement().text();
+
+    KURL url = KURL( urlText );
+    if ( url.isValid() ) {
+        Kita::Board::setName( urlText, nameText );
+        FavoriteBoards::append( url );
+    }
 }
index d4ce37c..fa59805 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <kurl.h>
 
+class QDomNode;
+
 namespace Kita
 {
     /**
@@ -23,12 +25,14 @@ namespace Kita
         QValueList<KURL> m_list;
         FavoriteBoards();
         ~FavoriteBoards();
+
+        static void processChildNode( QDomNode& node );
     public:
         static FavoriteBoards* getInstance();
         static void append( KURL& url );
         static void remove( KURL& url );
-        static const QValueList<KURL>& boards() { return getInstance()->m_list; }
-        static void readFromXML( QString& xml );
+        static const QValueList<KURL>& boards();
+        static bool readFromXML( QString& xml );
     };
 };