comparison contact.cpp @ 7:017925589d4c

Contact (formerly ContactT) now use shared data
author Goffi <goffi@goffi.org>
date Sun, 14 Aug 2011 18:03:54 +0200
parents 48045176d1c6
children
comparison
equal deleted inserted replaced
6:48045176d1c6 7:017925589d4c
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include "contact.h" 19 #include "contact.h"
20 #include <QDebug>
20 21
21 ContactT::ContactT() 22 ContactData::ContactData()
22 :m_connected(false), m_presence_to(false), m_presence_from(false), m_presence_ask(false) 23 :m_connected(false), m_presence_to(false), m_presence_from(false), m_presence_ask(false)
23 { 24 {
24 } 25 }
25 26
26 ContactT::~ContactT() 27 ContactData::ContactData(const ContactData& other)
28 :QSharedData(other), jid(other.jid), groups(other.groups), m_connected(other.m_connected),
29 m_presence_to(other.m_presence_to), m_presence_from(other.m_presence_from),
30 m_presence_ask(other.m_presence_ask), m_profile(other.m_profile), m_name(other.m_name)
27 { 31 {
28 } 32 }
29 33
30 34
31 void ContactT::setProfile(const QString& profile) { 35 Contact::Contact()
32 m_profile = profile; 36 {
37 d = new ContactData;
33 } 38 }
34 39
35 const QString& ContactT::getProfile() const { 40 Contact::Contact(const Contact& other)
36 return m_profile; 41 : d(other.d)
42 {
37 } 43 }
38 44
39 void ContactT::setAttributes(const QHash<QString, QString>& attr) { 45 Jid& Contact::getJid() {
40 m_name = attr.value("name"); 46 return d->jid;
41 m_presence_to = attr.value("to") == "True";
42 m_presence_from = attr.value("from") == "True";
43 m_presence_ask = attr.value("ask") == "True";
44 } 47 }
45 48
46 QHash<QString, QString> ContactT::getAttributes() const { 49 const Jid& Contact::getJid() const {
50 return d->jid;
51 }
52
53 QList<QString>& Contact::getGroups() {
54 return d->groups;
55 }
56
57 const QList<QString>& Contact::getGroups() const {
58 return d->groups;
59 }
60
61 void Contact::setProfile(const QString& profile)
62 {
63 d->m_profile = profile;
64 }
65
66 const QString& Contact::getProfile() const
67 {
68 return d->m_profile;
69 }
70
71 void Contact::setAttributes(const QHash<QString, QString>& attr)
72 {
73 d->m_name = attr.value("name");
74 d->m_presence_to = attr.value("to") == "True";
75 d->m_presence_from = attr.value("from") == "True";
76 d->m_presence_ask = attr.value("ask") == "True";
77 }
78
79 QHash<QString, QString> Contact::getAttributes() const
80 {
47 QHash<QString, QString> attr; 81 QHash<QString, QString> attr;
48 if (jid.isValid()) { 82 if (d->jid.isValid()) {
49 attr["name"] = m_name; 83 attr["name"] = d->m_name;
50 attr["to"] = m_presence_to ? "True" : "False"; 84 attr["to"] = d->m_presence_to ? "True" : "False";
51 attr["from"] = m_presence_from ? "True" : "False"; 85 attr["from"] = d->m_presence_from ? "True" : "False";
52 attr["ask"] = m_presence_ask ? "True" : "False"; 86 attr["ask"] = d->m_presence_ask ? "True" : "False";
53 } 87 }
54 88
55 return attr; 89 return attr;
56 } 90 }
57 91
58 const QString& ContactT::getName() const { 92 const QString& Contact::getName() const
59 return m_name; 93 {
94 return d->m_name;
60 } 95 }
61 96
62 bool ContactT::isConnected() { 97 void Contact::setName(const QString& name)
63 return m_connected; 98 {
99 d->m_name = name;
64 } 100 }
65 101
102 bool Contact::isConnected()
103 {
104 return d->m_connected;
105 }
106