diff settings.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 c63d67895cbe
line wrap: on
line diff
--- a/settings.cpp	Mon Aug 08 10:59:34 2011 +0200
+++ b/settings.cpp	Thu Aug 11 00:02:25 2011 +0200
@@ -17,6 +17,7 @@
 */
 
 #include "settings.h"
+#include "bellaciao.h"
 
 using namespace Qt;
 
@@ -49,20 +50,21 @@
 
     //We fill the profiles list
     m_bridge = Bridge::getBridge();
+    m_session = Session::getSession();
+
     const QList<QString>& profiles = m_bridge->getProfilesList();
     const QString& default_profile = m_bridge->getProfileName("@DEFAULT@");
+    const QList<QString>& checked_profiles = m_session->getProfiles(); 
+    
     foreach(const QString& profile, profiles) {
         ProfileListWidgetItem *item = new ProfileListWidgetItem(profile, profileList, profile==default_profile);
         item->setFlags(item->flags() | ItemIsUserCheckable);
-        item->setCheckState(Checked);
+        item->setCheckState(checked_profiles.contains(profile)?Checked:Unchecked);
     }
     
     connect(profileList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(profileChanged(QListWidgetItem*)));
     connect(profileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(profileCurrentChanged(QListWidgetItem*, QListWidgetItem*)));
 
-    //Profiles manipulation buttons
-    connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings()));
-
     //Confirmation buttons
     connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings()));
     connect(buttonsGroupConfirm, SIGNAL(rejected()), this, SLOT(cancelSettings()));
@@ -84,7 +86,6 @@
 //Profile settings slots
 void Settings::profileChanged(QListWidgetItem* item)
 {
-    qDebug() << "profileChanged";
 }
 
 void Settings::profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous)
@@ -165,11 +166,29 @@
 
 
 //Global settings slots
-void Settings::saveSettings()
+void Settings::saveSettings() //Save settings to session
 {
+    // We save profiles
+    QList<QString> previous_profiles;
+    QList<QString>& profiles = m_session->getProfiles();
+    previous_profiles = profiles;
+    profiles.clear();
+    for (int i=0; i<profileList->count(); i++)
+    {
+        ProfileListWidgetItem* item = dynamic_cast<ProfileListWidgetItem*>(profileList->item(i));
+        if (item->checkState() == Checked){
+            profiles.append(item->getProfile());
+        }
+    }
+
+    if (previous_profiles!=profiles) //The profiles checked are differents, we refill the contactList
+        Bellaciao::getInstance()->connectProfiles();
+
+    close();
+        
 }
 
 void Settings::cancelSettings()
 {
-    this->close();
+    close();
 }