summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorMateusz Kaduk <mateusz.kaduk@gmail.com>2005-06-19 08:24:03 +0000
committerMateusz Kaduk <mateusz.kaduk@gmail.com>2005-06-19 08:24:03 +0000
commit1f86c22c35d2de5e9c71d9627adc18f780347f30 (patch)
tree5b77026f3dcd90ef4844212ec2f21b2d4c636b0f /src/resources
parent38c882f43782a536cf69e82c1214de95063c3ef4 (diff)
downloadmana-1f86c22c35d2de5e9c71d9627adc18f780347f30.tar.gz
mana-1f86c22c35d2de5e9c71d9627adc18f780347f30.tar.bz2
mana-1f86c22c35d2de5e9c71d9627adc18f780347f30.tar.xz
mana-1f86c22c35d2de5e9c71d9627adc18f780347f30.zip
Saving buddy in xml file
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/buddylist.cpp51
-rw-r--r--src/resources/buddylist.h9
2 files changed, 59 insertions, 1 deletions
diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp
index 226551c7..c3098b67 100644
--- a/src/resources/buddylist.cpp
+++ b/src/resources/buddylist.cpp
@@ -26,14 +26,56 @@
BuddyList::BuddyList()
{
+ // Open buddy file
+ buddyXmlwriterFilename("buddy.xml");
+
+ // Load buddy from file
+ // TODO
}
BuddyList::~BuddyList()
{
+ int rc;
+
+ /* Close last element. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ std::cerr << "buddyXmlwriterFilename: Error at xmlTextWriterEndElement" << std::endl;
+ return;
+ }
+
+ xmlFreeTextWriter(writer);
+}
+void BuddyList::buddyXmlwriterFilename(const char *uri)
+{
+ int rc;
+
+ // Create a new XmlWriter for uri, with no compression
+ writer = xmlNewTextWriterFilename(uri, 0);
+ if (writer == NULL) {
+ std::cerr << "buddyXmlwriterFilename: Error creating the xml writer" << std::endl;
+ return;
+ }
+
+ // Start with the xml default version and UTF-8 encoding
+ rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
+ if (rc < 0) {
+ std::cerr << "buddyXmlwriterFilename: Error at xmlTextWriterStartDocument" << std::endl;
+ return;
+ }
+
+ // Start with the root named "LIST"
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "LIST");
+ if (rc < 0) {
+ std::cerr << "buddyXmlwriterFilename: Error at xmlTextWriterStartElement" << std::endl;
+ return;
+ }
}
bool BuddyList::addBuddy(const std::string buddy)
{
+ int rc;
+
for (buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
{
// Buddy already exist
@@ -43,6 +85,13 @@ bool BuddyList::addBuddy(const std::string buddy)
// Buddy doesnt exist, add it
buddylist.push_back(buddy);
+ // Store buddy as a child of "PEOPLE"
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "PEOPLE", (xmlChar *) buddy.c_str());
+ if (rc < 0) {
+ std::cerr << "buddyXmlwriterFilename: Error at xmlTextWriterWriteElement" << std::endl;
+ return false;
+ }
+
return true;
}
@@ -70,7 +119,7 @@ int BuddyList::getNumberOfElements(void)
std::string BuddyList::getElementAt(int number)
{
- if (number <= buddylist.size() - 1)
+ if (number <= (int) buddylist.size() - 1)
{
buddyit = buddylist.begin();
std::advance(buddyit, number);
diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h
index d0598747..0987bc30 100644
--- a/src/resources/buddylist.h
+++ b/src/resources/buddylist.h
@@ -27,6 +27,8 @@
#include <guichan.hpp>
#include <list>
#include <string>
+#include <libxml/encoding.h>
+#include <libxml/xmlwriter.h>
class BuddyList : public gcn::ListModel {
public:
@@ -61,8 +63,15 @@ class BuddyList : public gcn::ListModel {
std::string getElementAt(int number);
private:
+
+ /**
+ * Create a new XmlWriter for uri
+ */
+ void buddyXmlwriterFilename(const char *uri);
+
std::list<std::string> buddylist; /**< Buddy list */
std::list<std::string>::iterator buddyit; /**< Iterator */
+ xmlTextWriterPtr writer;
};
#endif /* _TMW_BUDDYLIST_H */