Mercurial > bellaciao
annotate bellaciao.cpp @ 11:98485ebbdb86 default tip
LayoutView: WidgetViewBox fix
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 27 Aug 2011 00:31:20 +0200 |
parents | 017925589d4c |
children |
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 |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
22 Bellaciao* Bellaciao::_instance=0; |
0 | 23 |
24 Bellaciao::Bellaciao() | |
25 :QMainWindow(0) | |
26 { | |
27 m_bridge = Bridge::getBridge(); | |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
28 m_session = Session::getSession(); |
0 | 29 |
30 //Ui | |
31 setupUi(this); | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
32 const QString & media_dir = m_bridge->getConfig("", "media_dir"); |
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
33 setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png")); |
0 | 34 m_contactList = new ContactList(this); |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
35 |
0 | 36 |
37 //Signals & Slots | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
38 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); |
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
39 connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit())); |
0 | 40 |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
41 //D-Bus Signals |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
42 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
|
43 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
|
44 |
0 | 45 |
46 addDockWidget(Qt::LeftDockWidgetArea, m_contactList); | |
47 | |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
48 |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
49 //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
|
50 |
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 Bellaciao* Bellaciao::getInstance() |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
55 { |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
56 if (_instance==0) |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
57 _instance = new Bellaciao; |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
58 |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
59 return _instance; |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
60 } |
0 | 61 |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
62 void Bellaciao::connectProfiles() |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
63 /* Connect profiles, and fill contact lists*/ |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
64 { |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
65 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
|
66 m_contactList->clear(); |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
67 foreach(const QString& profile, profiles) { |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
68 //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
|
69 if (m_bridge->isConnected(profile)) |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
70 fillContactList(profile); |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
71 m_bridge->connect(profile); |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
72 } |
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 void Bellaciao::fillContactList(const QString& profile) |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
76 { |
7
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
77 //We first get the whole contact list |
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
78 const QList<Contact>& contacts = m_bridge->getContacts(profile); |
0 | 79 |
6 | 80 for (int i=0; i<contacts.size(); i++) { |
7
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
81 Contact contact(contacts[i]); |
6 | 82 contact.setProfile(profile); |
83 m_contactList->addContact(contact); | |
84 } | |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
85 |
7
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
86 //Then add connected contacts |
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
87 |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
88 } |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
89 |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
90 //slots |
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 //D-Bus slots |
0 | 93 |
4
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
94 void Bellaciao::connected(const QString & profile) |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
95 { |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
96 fillContactList(profile); |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
97 } |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
98 |
220e5619bf87
Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
99 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
|
100 { |
7
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
101 Contact contact; |
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
102 contact.getJid().fromString(s_jid); |
6 | 103 contact.setAttributes(attributes); |
7
017925589d4c
Contact (formerly ContactT) now use shared data
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
104 contact.getGroups() = groups; |
6 | 105 contact.setProfile(profile); |
106 m_contactList->addContact(contact); | |
0 | 107 } |
108 | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
109 void Bellaciao::quit() |
0 | 110 { |
111 if ( QMessageBox::question ( | |
112 this, | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
113 tr("Quit?"), |
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
114 tr("Do you really want to quit ?"), |
0 | 115 QMessageBox::Yes | QMessageBox::No, |
116 QMessageBox::No | |
117 ) == QMessageBox::Yes | |
118 ) | |
119 { | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
120 qApp->quit(); |
0 | 121 } |
122 } | |
123 | |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
124 void Bellaciao::showSettings() |
0 | 125 { |
2
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
126 Settings::getDialog()->show(); |
fee291c8d42a
settings: profiles management first draft
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
127 Settings::getDialog()->raise(); |
0 | 128 } |
129 | |
130 void Bellaciao::on_actionToggle_fullscreen_triggered() | |
131 { | |
132 if (isFullScreen()) | |
133 showNormal(); | |
134 else | |
135 showFullScreen(); | |
136 } |