# HG changeset patch # User Goffi # Date 1313337834 -7200 # Node ID 017925589d4cacae33da493fd7791f1af821f7f0 # Parent 48045176d1c64f0a99b59920574687dd2da2a9fc Contact (formerly ContactT) now use shared data diff -r 48045176d1c6 -r 017925589d4c bellaciao.cpp --- a/bellaciao.cpp Fri Aug 12 22:08:37 2011 +0200 +++ b/bellaciao.cpp Sun Aug 14 18:03:54 2011 +0200 @@ -74,14 +74,17 @@ void Bellaciao::fillContactList(const QString& profile) { - const QList& contacts = m_bridge->getContacts(profile); + //We first get the whole contact list + const QList& contacts = m_bridge->getContacts(profile); for (int i=0; iaddContact(contact); } + //Then add connected contacts + } //slots @@ -95,10 +98,10 @@ void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile) { - ContactT contact; - contact.jid.fromString(s_jid); + Contact contact; + contact.getJid().fromString(s_jid); contact.setAttributes(attributes); - contact.groups = groups; + contact.getGroups() = groups; contact.setProfile(profile); m_contactList->addContact(contact); } diff -r 48045176d1c6 -r 017925589d4c bridge.cpp --- a/bridge.cpp Fri Aug 12 22:08:37 2011 +0200 +++ b/bridge.cpp Sun Aug 14 18:03:54 2011 +0200 @@ -32,8 +32,8 @@ qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType< QList >(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType< QList >(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType< QList >(); _bridge_instance = new Bridge("org.goffi.SAT", "/org/goffi/SAT/bridge", QDBusConnection::sessionBus()); } diff -r 48045176d1c6 -r 017925589d4c contact.cpp --- a/contact.cpp Fri Aug 12 22:08:37 2011 +0200 +++ b/contact.cpp Sun Aug 14 18:03:54 2011 +0200 @@ -17,49 +17,90 @@ */ #include "contact.h" +#include -ContactT::ContactT() +ContactData::ContactData() :m_connected(false), m_presence_to(false), m_presence_from(false), m_presence_ask(false) { } -ContactT::~ContactT() +ContactData::ContactData(const ContactData& other) + :QSharedData(other), jid(other.jid), groups(other.groups), m_connected(other.m_connected), + m_presence_to(other.m_presence_to), m_presence_from(other.m_presence_from), + m_presence_ask(other.m_presence_ask), m_profile(other.m_profile), m_name(other.m_name) { } -void ContactT::setProfile(const QString& profile) { - m_profile = profile; +Contact::Contact() +{ + d = new ContactData; +} + +Contact::Contact(const Contact& other) + : d(other.d) +{ } -const QString& ContactT::getProfile() const { - return m_profile; +Jid& Contact::getJid() { + return d->jid; +} + +const Jid& Contact::getJid() const { + return d->jid; +} + +QList& Contact::getGroups() { + return d->groups; +} + +const QList& Contact::getGroups() const { + return d->groups; } -void ContactT::setAttributes(const QHash& attr) { - m_name = attr.value("name"); - m_presence_to = attr.value("to") == "True"; - m_presence_from = attr.value("from") == "True"; - m_presence_ask = attr.value("ask") == "True"; +void Contact::setProfile(const QString& profile) +{ + d->m_profile = profile; +} + +const QString& Contact::getProfile() const +{ + return d->m_profile; } -QHash ContactT::getAttributes() const { +void Contact::setAttributes(const QHash& attr) +{ + d->m_name = attr.value("name"); + d->m_presence_to = attr.value("to") == "True"; + d->m_presence_from = attr.value("from") == "True"; + d->m_presence_ask = attr.value("ask") == "True"; +} + +QHash Contact::getAttributes() const +{ QHash attr; - if (jid.isValid()) { - attr["name"] = m_name; - attr["to"] = m_presence_to ? "True" : "False"; - attr["from"] = m_presence_from ? "True" : "False"; - attr["ask"] = m_presence_ask ? "True" : "False"; + if (d->jid.isValid()) { + attr["name"] = d->m_name; + attr["to"] = d->m_presence_to ? "True" : "False"; + attr["from"] = d->m_presence_from ? "True" : "False"; + attr["ask"] = d->m_presence_ask ? "True" : "False"; } return attr; } -const QString& ContactT::getName() const { - return m_name; +const QString& Contact::getName() const +{ + return d->m_name; } -bool ContactT::isConnected() { - return m_connected; +void Contact::setName(const QString& name) +{ + d->m_name = name; } +bool Contact::isConnected() +{ + return d->m_connected; +} + diff -r 48045176d1c6 -r 017925589d4c contact.h --- a/contact.h Fri Aug 12 22:08:37 2011 +0200 +++ b/contact.h Sun Aug 14 18:03:54 2011 +0200 @@ -19,25 +19,20 @@ #ifndef CONTACT_H #define CONTACT_H -#include +#include +#include +#include +#include #include "jid.h" -class ContactT { +class ContactData: public QSharedData +{ public: - ContactT(); - ~ContactT(); - QList groups; + ContactData(); + ContactData(const ContactData& other); + Jid jid; - void setProfile(const QString& profile); - const QString& getProfile() const; - void setAttributes(const QHash& attr); - QHash getAttributes() const; - const QString& getName() const; - - bool isConnected(); - - - private: + QList groups; bool m_connected; bool m_presence_to, m_presence_from, m_presence_ask; QString m_profile, m_name; @@ -45,5 +40,26 @@ }; +class Contact { + public: + Contact(); + Contact(const Contact &other); + + Jid& getJid(); + const Jid& getJid() const; + QList& getGroups(); + const QList& getGroups() const; + void setProfile(const QString& profile); + const QString& getProfile() const; + void setAttributes(const QHash& attr); + QHash getAttributes() const; + const QString& getName() const; + void setName(const QString& name); + bool isConnected(); + + private: + QExplicitlySharedDataPointer d; +}; + #endif diff -r 48045176d1c6 -r 017925589d4c contact_list.cpp --- a/contact_list.cpp Fri Aug 12 22:08:37 2011 +0200 +++ b/contact_list.cpp Sun Aug 14 18:03:54 2011 +0200 @@ -31,13 +31,16 @@ } -void ContactList::addContact(const ContactT& contact) +void ContactList::addContact(const Contact& contact) { - const QString &txt = contact.getName().isEmpty() ? contact.jid.getString() : contact.getName(); + const QString & _jid = contact.getJid().getBareString(); + m_contactMap.insert(_jid, contact); + const QString &txt = contact.getName().isEmpty() ? contact.getJid().getString() : contact.getName(); new QListWidgetItem(txt, listWidget); } void ContactList::clear() { listWidget->clear(); + m_contactMap.clear(); } diff -r 48045176d1c6 -r 017925589d4c contact_list.h --- a/contact_list.h Fri Aug 12 22:08:37 2011 +0200 +++ b/contact_list.h Sun Aug 14 18:03:54 2011 +0200 @@ -27,11 +27,12 @@ public: ContactList(QWidget* parent = 0); - void addContact(const ContactT& contact); + void addContact(const Contact& contact); void clear(); private: QWidget* mainWidget; QListWidget* listWidget; + QMap m_contactMap; }; #endif diff -r 48045176d1c6 -r 017925589d4c dbus_types.cpp --- a/dbus_types.cpp Fri Aug 12 22:08:37 2011 +0200 +++ b/dbus_types.cpp Sun Aug 14 18:03:54 2011 +0200 @@ -32,22 +32,22 @@ return argument; } -QDBusArgument &operator<<(QDBusArgument &argument, const ContactT &contact) +QDBusArgument &operator<<(QDBusArgument &argument, const Contact &contact) { argument.beginStructure(); StringDict attr = contact.getAttributes(); - argument << contact.jid << attr << contact.groups; + argument << contact.getJid() << attr << contact.getGroups(); argument.endStructure(); return argument; } -const QDBusArgument &operator>>(const QDBusArgument &argument, ContactT &contact) +const QDBusArgument &operator>>(const QDBusArgument &argument, Contact &contact) { argument.beginStructure(); - argument >> contact.jid; + argument >> contact.getJid(); StringDict attr; argument >> attr; contact.setAttributes(attr); - argument >> contact.groups; + argument >> contact.getGroups(); argument.endStructure(); return argument; } diff -r 48045176d1c6 -r 017925589d4c dbus_types.h --- a/dbus_types.h Fri Aug 12 22:08:37 2011 +0200 +++ b/dbus_types.h Sun Aug 14 18:03:54 2011 +0200 @@ -54,8 +54,8 @@ typedef QHash ActionResultExtDataT; Q_DECLARE_METATYPE(StringDict); -Q_DECLARE_METATYPE(ContactT); -Q_DECLARE_METATYPE(QList); +Q_DECLARE_METATYPE(Contact); +Q_DECLARE_METATYPE(QList); Q_DECLARE_METATYPE(HistoryT); Q_DECLARE_METATYPE(PresenceStatusT); Q_DECLARE_METATYPE(MenuT); @@ -64,8 +64,8 @@ QDBusArgument &operator<<(QDBusArgument &argument, const Jid &jid); const QDBusArgument &operator>>(const QDBusArgument &argument, Jid &jid); -QDBusArgument &operator<<(QDBusArgument &argument, const ContactT &contact); -const QDBusArgument &operator>>(const QDBusArgument &argument, ContactT &contact); +QDBusArgument &operator<<(QDBusArgument &argument, const Contact &contact); +const QDBusArgument &operator>>(const QDBusArgument &argument, Contact &contact); QDBusArgument &operator<<(QDBusArgument &argument, const MenuT &menu); const QDBusArgument &operator>>(const QDBusArgument &argument, MenuT &menu); QDBusArgument &operator<<(QDBusArgument &argument, const MessageT &message); diff -r 48045176d1c6 -r 017925589d4c org.goffi.sat.xml --- a/org.goffi.sat.xml Fri Aug 12 22:08:37 2011 +0200 +++ b/org.goffi.sat.xml Sun Aug 14 18:03:54 2011 +0200 @@ -83,7 +83,7 @@ - +