***************************************************************************/
#include "favoriteboards.h"
+#include "board.h"
+
+#include <qdom.h>
+
using namespace Kita;
FavoriteBoards* FavoriteBoards::instance = 0;
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 );
+ }
}
#include <kurl.h>
+class QDomNode;
+
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 );
};
};