annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 /*
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 Bellaciao: a Salut à Toi frontend
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
4
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 it under the terms of the GNU Affero General Public License as published by
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
7 the Free Software Foundation, either version 3 of the License, or
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 (at your option) any later version.
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
9
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 GNU Affero General Public License for more details.
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
14
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 You should have received a copy of the GNU Affero General Public License
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
17 */
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
18
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19 #include "bellaciao.h"
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
20 #include "settings.h"
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
21 #include "jid.h"
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
22
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
23 Bellaciao* Bellaciao::_instance=0;
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
25 Bellaciao::Bellaciao()
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
26 :QMainWindow(0)
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
27 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 m_bridge = Bridge::getBridge();
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
29 m_session = Session::getSession();
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
30
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
31 //Ui
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
32 setupUi(this);
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
33 const QString & media_dir = m_bridge->getConfig("", "media_dir");
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
34 setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png"));
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
35 m_contactList = new ContactList(this);
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
36
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38 //Signals & Slots
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
39 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
40 connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
42 //D-Bus Signals
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
43 connect(m_bridge, SIGNAL(connected(QString)), this, SLOT(connected(QString)));
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
44 connect(m_bridge, SIGNAL(newContact(const QString&, StringDict, const QStringList&, const QString&)), this, SLOT(addContact(const QString&, StringDict, const QStringList&, const QString&)));
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
45
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 addDockWidget(Qt::LeftDockWidgetArea, m_contactList);
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
49
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
50 //TODO: retrieve saved session's settings from SàT, and fill contactList
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
51
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
52
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
53 }
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
54
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
55 Bellaciao* Bellaciao::getInstance()
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
56 {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
57 if (_instance==0)
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
58 _instance = new Bellaciao;
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
59
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
60 return _instance;
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
61 }
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
62
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
63 void Bellaciao::connectProfiles()
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
64 /* Connect profiles, and fill contact lists*/
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
65 {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
66 const QList<QString> & profiles = m_session->getProfiles();
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
67 m_contactList->clear();
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
68 foreach(const QString& profile, profiles) {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
69 //We autoconnect profile at the moment, behaviour can change in the future
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
70 if (m_bridge->isConnected(profile))
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
71 fillContactList(profile);
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
72 m_bridge->connect(profile);
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
73 }
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
74 }
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
75
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
76 void Bellaciao::fillContactList(const QString& profile)
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
77 {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
78
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
79 const QList<ContactT>& contacts = m_bridge->getContacts(profile);
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
80
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
81 foreach(const ContactT &contact, contacts)
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
82 m_contactList->addContact(contact.jid);
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
83
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
84 }
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
85
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
86 //slots
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
87
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
88 //D-Bus slots
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
89
4
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
90 void Bellaciao::connected(const QString & profile)
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
91 {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
92 fillContactList(profile);
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
93 }
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
94
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
95 void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile)
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
96 {
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
97 Jid jid = Jid(s_jid);
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
98 m_contactList->addContact(jid);
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
99 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
100
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
101 void Bellaciao::quit()
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
102 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
103 if ( QMessageBox::question (
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
104 this,
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
105 tr("Quit?"),
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
106 tr("Do you really want to quit ?"),
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 QMessageBox::Yes | QMessageBox::No,
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
108 QMessageBox::No
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
109 ) == QMessageBox::Yes
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 )
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111 {
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
112 qApp->quit();
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
113 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
114 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
115
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
116 void Bellaciao::showSettings()
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
117 {
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
118 Settings::getDialog()->show();
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
119 Settings::getDialog()->raise();
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
120 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
121
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
122 void Bellaciao::on_actionToggle_fullscreen_triggered()
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
123 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if (isFullScreen())
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
125 showNormal();
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
126 else
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
127 showFullScreen();
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
128 }