summaryrefslogtreecommitdiff
path: root/src/resources/buddylist.cpp
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/buddylist.cpp
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/buddylist.cpp')
-rw-r--r--src/resources/buddylist.cpp51
1 files changed, 50 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);