Mercurial > bellaciao
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 |
rev | line source |
---|---|
0 | 1 /* |
2 Bellaciao: a Salut à Toi frontend | |
3 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
4 | |
5 This program is free software: you can redistribute it and/or modify | |
6 it under the terms of the GNU Affero General Public License as published by | |
7 the Free Software Foundation, either version 3 of the License, or | |
8 (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 Affero General Public License for more details. | |
14 | |
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/>. | |
17 */ | |
18 | |
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 | 24 |
25 Bellaciao::Bellaciao() | |
26 :QMainWindow(0) | |
27 { | |
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 | 30 |
31 //Ui | |
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 | 35 m_contactList = new ContactList(this); |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
36 |
0 | 37 |
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 | 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 | 46 |
47 addDockWidget(Qt::LeftDockWidgetArea, m_contactList); | |
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 | 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 | 80 |
81 foreach(const ContactT &contact, contacts) | |
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 | 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 | 99 } |
100 | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
101 void Bellaciao::quit() |
0 | 102 { |
103 if ( QMessageBox::question ( | |
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 | 107 QMessageBox::Yes | QMessageBox::No, |
108 QMessageBox::No | |
109 ) == QMessageBox::Yes | |
110 ) | |
111 { | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
112 qApp->quit(); |
0 | 113 } |
114 } | |
115 | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
116 void Bellaciao::showSettings() |
0 | 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 | 120 } |
121 | |
122 void Bellaciao::on_actionToggle_fullscreen_triggered() | |
123 { | |
124 if (isFullScreen()) | |
125 showNormal(); | |
126 else | |
127 showFullScreen(); | |
128 } |