Mercurial > bellaciao
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:2195295a2058 | 4:220e5619bf87 |
---|---|
15 You should have received a copy of the GNU Affero General Public License | 15 You should have received a copy of the GNU Affero General Public License |
16 along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ | 17 */ |
18 | 18 |
19 #include "settings.h" | 19 #include "settings.h" |
20 #include "bellaciao.h" | |
20 | 21 |
21 using namespace Qt; | 22 using namespace Qt; |
22 | 23 |
23 Settings* Settings::_instance = 0; | 24 Settings* Settings::_instance = 0; |
24 | 25 |
47 | 48 |
48 this->setAttribute(WA_DeleteOnClose); | 49 this->setAttribute(WA_DeleteOnClose); |
49 | 50 |
50 //We fill the profiles list | 51 //We fill the profiles list |
51 m_bridge = Bridge::getBridge(); | 52 m_bridge = Bridge::getBridge(); |
53 m_session = Session::getSession(); | |
54 | |
52 const QList<QString>& profiles = m_bridge->getProfilesList(); | 55 const QList<QString>& profiles = m_bridge->getProfilesList(); |
53 const QString& default_profile = m_bridge->getProfileName("@DEFAULT@"); | 56 const QString& default_profile = m_bridge->getProfileName("@DEFAULT@"); |
57 const QList<QString>& checked_profiles = m_session->getProfiles(); | |
58 | |
54 foreach(const QString& profile, profiles) { | 59 foreach(const QString& profile, profiles) { |
55 ProfileListWidgetItem *item = new ProfileListWidgetItem(profile, profileList, profile==default_profile); | 60 ProfileListWidgetItem *item = new ProfileListWidgetItem(profile, profileList, profile==default_profile); |
56 item->setFlags(item->flags() | ItemIsUserCheckable); | 61 item->setFlags(item->flags() | ItemIsUserCheckable); |
57 item->setCheckState(Checked); | 62 item->setCheckState(checked_profiles.contains(profile)?Checked:Unchecked); |
58 } | 63 } |
59 | 64 |
60 connect(profileList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(profileChanged(QListWidgetItem*))); | 65 connect(profileList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(profileChanged(QListWidgetItem*))); |
61 connect(profileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(profileCurrentChanged(QListWidgetItem*, QListWidgetItem*))); | 66 connect(profileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(profileCurrentChanged(QListWidgetItem*, QListWidgetItem*))); |
62 | |
63 //Profiles manipulation buttons | |
64 connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); | |
65 | 67 |
66 //Confirmation buttons | 68 //Confirmation buttons |
67 connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); | 69 connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); |
68 connect(buttonsGroupConfirm, SIGNAL(rejected()), this, SLOT(cancelSettings())); | 70 connect(buttonsGroupConfirm, SIGNAL(rejected()), this, SLOT(cancelSettings())); |
69 } | 71 } |
82 } | 84 } |
83 | 85 |
84 //Profile settings slots | 86 //Profile settings slots |
85 void Settings::profileChanged(QListWidgetItem* item) | 87 void Settings::profileChanged(QListWidgetItem* item) |
86 { | 88 { |
87 qDebug() << "profileChanged"; | |
88 } | 89 } |
89 | 90 |
90 void Settings::profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous) | 91 void Settings::profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous) |
91 { | 92 { |
92 if (!current) { | 93 if (!current) { |
163 | 164 |
164 } | 165 } |
165 | 166 |
166 | 167 |
167 //Global settings slots | 168 //Global settings slots |
168 void Settings::saveSettings() | 169 void Settings::saveSettings() //Save settings to session |
169 { | 170 { |
171 // We save profiles | |
172 QList<QString> previous_profiles; | |
173 QList<QString>& profiles = m_session->getProfiles(); | |
174 previous_profiles = profiles; | |
175 profiles.clear(); | |
176 for (int i=0; i<profileList->count(); i++) | |
177 { | |
178 ProfileListWidgetItem* item = dynamic_cast<ProfileListWidgetItem*>(profileList->item(i)); | |
179 if (item->checkState() == Checked){ | |
180 profiles.append(item->getProfile()); | |
181 } | |
182 } | |
183 | |
184 if (previous_profiles!=profiles) //The profiles checked are differents, we refill the contactList | |
185 Bellaciao::getInstance()->connectProfiles(); | |
186 | |
187 close(); | |
188 | |
170 } | 189 } |
171 | 190 |
172 void Settings::cancelSettings() | 191 void Settings::cancelSettings() |
173 { | 192 { |
174 this->close(); | 193 close(); |
175 } | 194 } |