# HG changeset patch # User Goffi # Date 1313179717 -7200 # Node ID 48045176d1c64f0a99b59920574687dd2da2a9fc # Parent 0412dc960e3a317a1b184c59491a5fa8c6f96dd4 ContactT and Ji improvments diff -r 0412dc960e3a -r 48045176d1c6 bellaciao.cpp --- a/bellaciao.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/bellaciao.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -18,7 +18,6 @@ #include "bellaciao.h" #include "settings.h" -#include "jid.h" Bellaciao* Bellaciao::_instance=0; @@ -75,11 +74,13 @@ void Bellaciao::fillContactList(const QString& profile) { - const QList& contacts = m_bridge->getContacts(profile); - foreach(const ContactT &contact, contacts) - m_contactList->addContact(contact.jid); + for (int i=0; iaddContact(contact); + } } @@ -94,8 +95,12 @@ void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile) { - Jid jid = Jid(s_jid); - m_contactList->addContact(jid); + ContactT contact; + contact.jid.fromString(s_jid); + contact.setAttributes(attributes); + contact.groups = groups; + contact.setProfile(profile); + m_contactList->addContact(contact); } void Bellaciao::quit() diff -r 0412dc960e3a -r 48045176d1c6 bellaciao.h --- a/bellaciao.h Fri Aug 12 22:05:50 2011 +0200 +++ b/bellaciao.h Fri Aug 12 22:08:37 2011 +0200 @@ -25,6 +25,7 @@ #include "contact_list.h" #include "bridge.h" #include "session.h" +#include "contact.h" class Bellaciao : public QMainWindow, private Ui::MainWindow { diff -r 0412dc960e3a -r 48045176d1c6 bridge.cpp --- a/bridge.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/bridge.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -29,7 +29,6 @@ Bridge* Bridge::getBridge() { if (_bridge_instance == 0) { - qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType< QList >(); diff -r 0412dc960e3a -r 48045176d1c6 contact.cpp --- a/contact.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/contact.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -19,8 +19,8 @@ #include "contact.h" ContactT::ContactT() + :m_connected(false), m_presence_to(false), m_presence_from(false), m_presence_ask(false) { - connected = false; } ContactT::~ContactT() @@ -28,8 +28,38 @@ } -bool ContactT::isConnected() { - return connected; +void ContactT::setProfile(const QString& profile) { + m_profile = profile; +} + +const QString& ContactT::getProfile() const { + return m_profile; +} + +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"; } +QHash ContactT::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"; + } + return attr; +} + +const QString& ContactT::getName() const { + return m_name; +} + +bool ContactT::isConnected() { + return m_connected; +} + diff -r 0412dc960e3a -r 48045176d1c6 contact.h --- a/contact.h Fri Aug 12 22:05:50 2011 +0200 +++ b/contact.h Fri Aug 12 22:08:37 2011 +0200 @@ -19,24 +19,29 @@ #ifndef CONTACT_H #define CONTACT_H +#include #include "jid.h" -#include - -typedef QHash StringDict; class ContactT { public: ContactT(); ~ContactT(); + QList groups; Jid jid; - StringDict attributes; - QList groups; + void setProfile(const QString& profile); + const QString& getProfile() const; + void setAttributes(const QHash& attr); + QHash getAttributes() const; + const QString& getName() const; bool isConnected(); private: - bool connected; + bool m_connected; + bool m_presence_to, m_presence_from, m_presence_ask; + QString m_profile, m_name; + }; diff -r 0412dc960e3a -r 48045176d1c6 contact_list.cpp --- a/contact_list.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/contact_list.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -31,9 +31,10 @@ } -void ContactList::addContact(const Jid& jid) +void ContactList::addContact(const ContactT& contact) { - new QListWidgetItem(jid.getString(), listWidget); + const QString &txt = contact.getName().isEmpty() ? contact.jid.getString() : contact.getName(); + new QListWidgetItem(txt, listWidget); } void ContactList::clear() diff -r 0412dc960e3a -r 48045176d1c6 contact_list.h --- a/contact_list.h Fri Aug 12 22:05:50 2011 +0200 +++ b/contact_list.h Fri Aug 12 22:08:37 2011 +0200 @@ -20,14 +20,14 @@ #define CONTACTLIST_H #include -#include "jid.h" +#include "contact.h" class ContactList : public QDockWidget { Q_OBJECT public: ContactList(QWidget* parent = 0); - void addContact(const Jid& jid); + void addContact(const ContactT& contact); void clear(); private: QWidget* mainWidget; diff -r 0412dc960e3a -r 48045176d1c6 dbus_types.cpp --- a/dbus_types.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/dbus_types.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -35,14 +35,19 @@ QDBusArgument &operator<<(QDBusArgument &argument, const ContactT &contact) { argument.beginStructure(); - argument << contact.jid << contact.attributes << contact.groups; + StringDict attr = contact.getAttributes(); + argument << contact.jid << attr << contact.groups; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, ContactT &contact) { argument.beginStructure(); - argument >> contact.jid >> contact.attributes >> contact.groups; + argument >> contact.jid; + StringDict attr; + argument >> attr; + contact.setAttributes(attr); + argument >> contact.groups; argument.endStructure(); return argument; } diff -r 0412dc960e3a -r 48045176d1c6 dbus_types.h --- a/dbus_types.h Fri Aug 12 22:05:50 2011 +0200 +++ b/dbus_types.h Fri Aug 12 22:08:37 2011 +0200 @@ -53,7 +53,6 @@ typedef QHash ActionResultExtDataT; -Q_DECLARE_METATYPE(Jid); Q_DECLARE_METATYPE(StringDict); Q_DECLARE_METATYPE(ContactT); Q_DECLARE_METATYPE(QList); diff -r 0412dc960e3a -r 48045176d1c6 jid.cpp --- a/jid.cpp Fri Aug 12 22:05:50 2011 +0200 +++ b/jid.cpp Fri Aug 12 22:08:37 2011 +0200 @@ -124,7 +124,16 @@ m_resource = resource; } -bool Jid::isValid() +const bool& Jid::isValid() const { return m_valid; } + +Jid& Jid::operator=(const Jid& other) +{ + m_user = other.getUser(); + m_domain = other.getDomain(); + m_resource = other.getResource(); + + return *this; +} diff -r 0412dc960e3a -r 48045176d1c6 jid.h --- a/jid.h Fri Aug 12 22:05:50 2011 +0200 +++ b/jid.h Fri Aug 12 22:08:37 2011 +0200 @@ -37,7 +37,8 @@ void setUser(const QString& user); void setDomain(const QString& domain); void setResource(const QString& resource); - bool isValid(); + const bool& isValid() const; + Jid& operator=(const Jid& other); private: bool m_valid;