changeset 6:48045176d1c6

ContactT and Ji improvments
author Goffi <goffi@goffi.org>
date Fri, 12 Aug 2011 22:08:37 +0200
parents 0412dc960e3a
children 017925589d4c
files bellaciao.cpp bellaciao.h bridge.cpp contact.cpp contact.h contact_list.cpp contact_list.h dbus_types.cpp dbus_types.h jid.cpp jid.h
diffstat 11 files changed, 80 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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<ContactT>& contacts = m_bridge->getContacts(profile);
 
-    foreach(const ContactT &contact, contacts)
-        m_contactList->addContact(contact.jid);
+    for (int i=0; i<contacts.size(); i++) {
+        ContactT contact = contacts[i];
+        contact.setProfile(profile);
+        m_contactList->addContact(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()
--- 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
 {
--- 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<Jid>();
         qDBusRegisterMetaType<StringDict>();
         qDBusRegisterMetaType<MenuT>();
         qDBusRegisterMetaType< QList<MenuT> >();
--- 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<QString, QString>& 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<QString, QString> ContactT::getAttributes() const {
+    QHash<QString, QString> 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;
+}
+
--- 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 <QtGui>
 #include "jid.h"
-#include <QtGui>
-
-typedef QHash<QString, QString> StringDict;
 
 class ContactT {
     public:
         ContactT();
         ~ContactT();
+        QList<QString> groups;
         Jid jid;
-        StringDict attributes;
-        QList<QString> groups;
+        void setProfile(const QString& profile);
+        const QString& getProfile() const;
+        void setAttributes(const QHash<QString, QString>& attr);
+        QHash<QString, QString> 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;
+
         
 };
 
--- 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()
--- 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 <QtGui>
-#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;
--- 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;
 }
--- 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<QString, StringDict> ActionResultExtDataT;
 
-Q_DECLARE_METATYPE(Jid);
 Q_DECLARE_METATYPE(StringDict);
 Q_DECLARE_METATYPE(ContactT);
 Q_DECLARE_METATYPE(QList<ContactT>);
--- 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;
+}
--- 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;