| 1 | /* |
|---|
| 2 | * QuteCom, a voice over Internet phone |
|---|
| 3 | * Copyright (C) 2010 Mbdsys |
|---|
| 4 | * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include <coipmanager_base/serializer/OscarAccountXMLSerializer.h> |
|---|
| 21 | |
|---|
| 22 | #include <coipmanager_base/account/OscarAccount.h> |
|---|
| 23 | |
|---|
| 24 | #include <util/String.h> |
|---|
| 25 | |
|---|
| 26 | #include <QtXml> |
|---|
| 27 | |
|---|
| 28 | OscarAccountXMLSerializer::OscarAccountXMLSerializer(OscarAccount & account) |
|---|
| 29 | : IAccountXMLSerializer(account) { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | std::string OscarAccountXMLSerializer::serialize() { |
|---|
| 33 | std::string result; |
|---|
| 34 | |
|---|
| 35 | OscarAccount & myAccount = (OscarAccount &) _account; |
|---|
| 36 | |
|---|
| 37 | result += "<oscar.server>" + myAccount.getServer() + "</oscar.server>"; |
|---|
| 38 | result += "<oscar.port>" + String::fromNumber(myAccount.getServerPort()) + "</oscar.port>"; |
|---|
| 39 | result += "<oscar.encoding>" + myAccount.getEncoding() + "</oscar.encoding>"; |
|---|
| 40 | |
|---|
| 41 | return result; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | bool OscarAccountXMLSerializer::unserialize(QDomElement * rootElt) { |
|---|
| 45 | OscarAccount & myAccount = (OscarAccount &) _account; |
|---|
| 46 | |
|---|
| 47 | // Retrieving server |
|---|
| 48 | myAccount.setServer(rootElt->firstChildElement("oscar.server").text().toStdString()); |
|---|
| 49 | |
|---|
| 50 | // Retrieving server port |
|---|
| 51 | myAccount.setServerPort(rootElt->firstChildElement("oscar.port").text().toInt()); |
|---|
| 52 | |
|---|
| 53 | // Retrieving encoding |
|---|
| 54 | myAccount.setEncoding(rootElt->firstChildElement("oscar.encoding").text().toStdString()); |
|---|
| 55 | |
|---|
| 56 | return true; |
|---|
| 57 | } |
|---|