diff bellaciao.cpp @ 4:220e5619bf87

Profiles selection now fill contact list + new Jid class
author Goffi <goffi@goffi.org>
date Thu, 11 Aug 2011 00:02:25 +0200
parents fee291c8d42a
children 48045176d1c6
line wrap: on
line diff
--- a/bellaciao.cpp	Mon Aug 08 10:59:34 2011 +0200
+++ b/bellaciao.cpp	Thu Aug 11 00:02:25 2011 +0200
@@ -18,11 +18,15 @@
 
 #include "bellaciao.h"
 #include "settings.h"
+#include "jid.h"
+
+Bellaciao* Bellaciao::_instance=0;
 
 Bellaciao::Bellaciao()
     :QMainWindow(0)
 {
     m_bridge = Bridge::getBridge();
+    m_session = Session::getSession();
 
     //Ui
     setupUi(this);
@@ -35,22 +39,63 @@
     connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
     connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
 
+    //D-Bus Signals
+    connect(m_bridge, SIGNAL(connected(QString)), this, SLOT(connected(QString)));
+    connect(m_bridge, SIGNAL(newContact(const QString&, StringDict, const QStringList&, const QString&)), this, SLOT(addContact(const QString&, StringDict, const QStringList&, const QString&)));
+
 
     addDockWidget(Qt::LeftDockWidgetArea, m_contactList);
     
-    
-    setWindowTitle("Bellaciao");
-    QList<MenuT> menus = m_bridge->getMenus();
-    foreach(const MenuT &menu, menus)
-        qDebug() << menu.name;
+   
+    //TODO: retrieve saved session's settings from SàT, and fill contactList 
+        
+
+}
+
+Bellaciao* Bellaciao::getInstance()
+{
+    if (_instance==0)
+        _instance = new Bellaciao;
+
+    return _instance;
+}
 
-    QList<ContactT> contacts = m_bridge->getContacts("jabberfr");
+void Bellaciao::connectProfiles()
+/* Connect profiles, and fill contact lists*/
+{
+    const QList<QString> & profiles = m_session->getProfiles();
+    m_contactList->clear();
+    foreach(const QString& profile, profiles) {
+        //We autoconnect profile at the moment, behaviour can change in the future
+        if (m_bridge->isConnected(profile))
+            fillContactList(profile);
+        m_bridge->connect(profile);
+    }
+}
+
+void Bellaciao::fillContactList(const QString& profile)
+{
+   
+    const QList<ContactT>& contacts = m_bridge->getContacts(profile);
 
     foreach(const ContactT &contact, contacts)
         m_contactList->addContact(contact.jid);
-        //qDebug() << contact.jid << contact.attributes << contact.groups;
-        
+
+}
+
+//slots
+
+//D-Bus slots
 
+void Bellaciao::connected(const QString & profile)
+{
+    fillContactList(profile);
+}
+
+void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile)
+{
+    Jid jid = Jid(s_jid);
+    m_contactList->addContact(jid);
 }
 
 void Bellaciao::quit()
@@ -70,7 +115,6 @@
 
 void Bellaciao::showSettings()
 {
-    qDebug("Show settings");
     Settings::getDialog()->show();
     Settings::getDialog()->raise();
 }
@@ -81,5 +125,4 @@
         showNormal();
     else
         showFullScreen();
-    qDebug("on_actionToggle_fullscreen_triggered");
 }