1 /*
2 * mooddlg.cpp
3 * Copyright (C) 2006 Remko Troncon
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "xmpp_pubsubitem.h"
22 #include "xmpp_client.h"
23 #include "xmpp_task.h"
24 #include "mooddlg.h"
25 #include "moodcatalog.h"
26 #include "psiaccount.h"
27 #include "pepmanager.h"
28 #include "psiiconset.h"
29
MoodDlg(QList<PsiAccount * > list)30 MoodDlg::MoodDlg(QList<PsiAccount*> list)
31 : QDialog(0), pa_(list)
32 {
33 setAttribute(Qt::WA_DeleteOnClose);
34 if(pa_.isEmpty())
35 close();
36 ui_.setupUi(this);
37 setModal(false);
38 connect(ui_.pb_cancel, SIGNAL(clicked()), SLOT(close()));
39 connect(ui_.pb_ok, SIGNAL(clicked()), SLOT(setMood()));
40
41 ui_.cb_type->addItem(tr("<unset>"));
42 PsiAccount *pa = pa_.first();
43 Mood::Type mt = pa->mood().type();
44 int i=1;
45 foreach(MoodCatalog::Entry e, MoodCatalog::instance()->entries()) {
46 ui_.cb_type->addItem(IconsetFactory::icon("mood/"+e.value()).icon(), e.text());
47 if (e.type() == mt) {
48 ui_.cb_type->setCurrentIndex(i);
49 }
50 i++;
51 }
52 ui_.le_text->setText(pa->mood().text());
53 }
54
55
setMood()56 void MoodDlg::setMood()
57 {
58 QString moodstr = ui_.cb_type->currentText();
59 foreach(PsiAccount *pa, pa_) {
60 if (moodstr == tr("<unset>")) {
61 pa->pepManager()->disable("mood", PEP_MOOD_NS, "current");
62 }
63 else {
64 Mood::Type type = MoodCatalog::instance()->findEntryByText(moodstr).type();
65 pa->pepManager()->publish(PEP_MOOD_NS, PubSubItem("current",Mood(type,ui_.le_text->text()).toXml(*pa->client()->rootTask()->doc())));
66 }
67 }
68 close();
69 }
70