2 ircaccount.cpp - IRC Account
4 Copyright (c) 2002 by Nick Betcher <nbetcher@kde.org>
5 Copyright (c) 2003-2004 by Jason Keirstead <jason@keirstead.org>
6 Copyright (c) 2003-2007 by Michel Hermier <michel.hermier@gmail.com>
8 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
10 *************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 *************************************************************************
20 #include "ircnetwork.h"
23 #include <kstandarddirs.h> // for locate
28 struct IRC::Networks::Private
{
29 IRC::NetworkList networks
;
45 Networks
*Networks::self()
47 static Networks
*self
= new IRC::Networks
;
51 const NetworkList
&Networks::networks() const
56 void Networks::slotReadNetworks()
60 QFile
xmlFile( KStandardDirs::locate( "appdata", "ircnetworks.xml" ) );
61 xmlFile
.open( QIODevice::ReadOnly
);
66 doc
.setContent( &xmlFile
);
67 QDomElement networkNode
= doc
.documentElement().firstChild().toElement();
68 while( !networkNode
.isNull () )
72 QDomElement networkChild
= networkNode
.firstChild().toElement();
73 while( !networkChild
.isNull() )
75 if( networkChild
.tagName() == "name" )
76 network
.name
= networkChild
.text();
77 else if( networkChild
.tagName() == "description" )
78 network
.description
= networkChild
.text();
79 else if( networkChild
.tagName() == "servers" )
81 QDomElement server
= networkChild
.firstChild().toElement();
82 while( !server
.isNull() )
86 QDomElement serverChild
= server
.firstChild().toElement();
87 while( !serverChild
.isNull() )
89 if( serverChild
.tagName() == "host" )
90 host
.host
= serverChild
.text();
91 else if( serverChild
.tagName() == "port" )
92 host
.port
= serverChild
.text().toInt();
93 else if( serverChild
.tagName() == "useSSL" )
94 host
.ssl
= ( serverChild
.text() == "true" );
96 serverChild
= serverChild
.nextSibling().toElement();
99 network
.hosts
.append( host
);
100 // d->hosts.insert( host->host, host );
101 server
= server
.nextSibling().toElement();
104 networkChild
= networkChild
.nextSibling().toElement();
107 d
->networks
.append(network
);
108 networkNode
= networkNode
.nextSibling().toElement();
115 bool Networks::slotSaveNetworkConfig() const
118 // store any changes in the UI
119 storeCurrentNetwork();
120 kDebug( 14120 ) << m_uiCurrentHostSelection;
123 QDomDocument doc("irc-networks");
124 QDomNode root = doc.appendChild( doc.createElement("networks") );
126 foreach(const Network &network, d->networks)
128 QDomNode networkNode = root.appendChild( doc.createElement("network") );
129 QDomNode nameNode = networkNode.appendChild( doc.createElement("name") );
130 nameNode.appendChild( doc.createTextNode( net->name ) );
132 QDomNode descNode = networkNode.appendChild( doc.createElement("description") );
133 descNode.appendChild( doc.createTextNode( net->description ) );
135 QDomNode serversNode = networkNode.appendChild( doc.createElement("servers") );
137 foreach(const Host &host, network.host)
139 QDomNode serverNode = serversNode.appendChild( doc.createElement("server") );
141 QDomNode hostNode = serverNode.appendChild( doc.createElement("host") );
142 hostNode.appendChild( doc.createTextNode( (*it2)->host ) );
144 QDomNode portNode = serverNode.appendChild( doc.createElement("port" ) );
145 portNode.appendChild( doc.createTextNode( QString::number( (*it2)->port ) ) );
147 QDomNode sslNode = serverNode.appendChild( doc.createElement("useSSL") );
148 sslNode.appendChild( doc.createTextNode( (*it2)->ssl ? "true" : "false" ) );
152 // kDebug(14121) << doc.toString(4);
153 QFile xmlFile( KStandardDirs::locateLocal( "appdata", "ircnetworks.xml" ) );
155 if (xmlFile.open(QIODevice::WriteOnly))
157 QTextStream stream( &xmlFile );
158 stream << doc.toString(4);
163 kDebug(14121) << "Failed to save the Networks definition file";
167 void Networks::addNetwork( IRCNetwork *network )
169 m_networks.insert( network->name, network );
170 // slotSaveNetworkConfig();
174 #include "ircnetwork.moc"