00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include <iostream>
00025
#include "gm/tree.h"
00026
#include "gm/xml.h"
00027
#include "gm/contact.h"
00028
00029
namespace GNUMessenger {
00030
00031 Folder::Folder(): XMLNode()
00032 {
00033 XMLNode::setName(
"folder");
00034
00035 }
00036
00037 Folder::Folder(
const Folder& folder)
00038 : XMLNode(folder)
00039 {
00040
00041 }
00042
00043 Folder::Folder(
const string& xml)
00044 {
00045 *
this << xml;
00046
#if 0
00047
try
00048 {
00049
XMLParser p(xml);
00050 *
this = p.get_root();
00051 }
00052
catch(XMLParser::ParseFailure &e)
00053 {
00054 LOG_THROW(e.what(), ParseFailure);
00055 }
00056
00057
if (name() !=
"folder")
00058 LOG_THROW(
"Folder::Folder(XMLNode) - data is not folder type", InvalidChild);
00059
#endif
00060
}
00061
00062 Folder::~Folder()
00063 {
00064
00065 }
00066
00067 Contact Folder::addContact(
const string& name)
00068 {
00069
for (
unsigned int i = 1; i <= numChildren(
"contact"); i++)
00070 {
00071
if (child(
"contact", i).property(
"name") == name)
00072
return Contact(child(
"contact", i));
00073 }
00074
00075
return Contact(addChild(
"contact").setProperty(
"name", name));
00076 }
00077
00078 Contact Folder::addContact(
const Contact& contact)
00079 {
00080
for (
unsigned int i = 1; i <= numChildren(
"contact"); i++)
00081 {
00082
if (child(
"contact", i).property(
"name") == contact.name())
00083
return Contact(child(
"contact", i));
00084 }
00085
00086
return Contact(addChild(contact));
00087 }
00088
00089 Folder Folder::addFolder(
const string& name)
00090 {
00091
for (
unsigned int i = 1; i <= numChildren(
"folder"); i++)
00092 {
00093
if (child(
"folder", i).property(
"name") == name)
00094
return Folder(child(
"folder", i));
00095 }
00096
00097
return Folder(addChild(
"folder").setProperty(
"name", name));
00098
00099 }
00100
00101 Folder Folder::addFolder(
const Folder& name)
00102 {
00103
return Folder(addChild(name));
00104 }
00105
00106 Contact Folder::getContact(
const string& name)
const
00107
{
00108
for (
unsigned int i = 1; i <= numChildren(
"contact"); i++)
00109 {
00110
if (child(
"contact", i).property(
"name") == name)
00111
return Contact(child(
"contact", i));
00112 }
00113
00114 LOG_THROW(
"This contact does not exist", InvalidChild);
00115
return Contact();
00116 }
00117
00118 Folder Folder::getFolder(
const string& name)
const
00119
{
00120
if (property(
"name") == name)
00121
return *
this;
00122
00123
for (
unsigned int i = 1; i <= numChildren(
"folder"); i++)
00124 {
00125
if (child(
"folder", i).property(
"name") == name)
00126
return Folder(child(
"folder", i));
00127 }
00128
00129 LOG_THROW(
"This folder does not exist.", InvalidChild);
00130
return Folder();
00131
00132 }
00133
00134 Folder& Folder::operator=(
const Folder &other)
00135 {
00136 other.
m_xmlData->ref();
00137
00138
if (m_xmlData && m_xmlData->deref())
00139 {
00140
delete m_xmlData;
00141 m_xmlData=0;
00142 }
00143
00144 m_xmlData=other.
m_xmlData;
00145
00146
return *
this;
00147 }
00148
00149
Contact Folder::contactAt(
int index)
const
00150
{
00151
return Contact(
child(
"contact", index));
00152 }
00153
00154 Folder Folder::folderAt(
int index)
const
00155
{
00156
return Folder(
child(
"folder", index));
00157 }
00158
00159 }