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
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
220e5619bf87 Profiles selection now fill contact list + new Jid class
Goffi <goffi@goffi.org>
parents: 2
diff changeset
22 Bellaciao* Bellaciao::_instance=0;
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
23
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24 Bellaciao::Bellaciao()
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
25 :QMainWindow(0)
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
26 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
29
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
30 //Ui
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
34 m_contactList = new ContactList(this);
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
35
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
36
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 addDockWidget(Qt::LeftDockWidgetArea, m_contactList);
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
79
6
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
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
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
82 contact.setProfile(profile);
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
83 m_contactList->addContact(contact);
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
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
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
105 contact.setProfile(profile);
48045176d1c6 ContactT and Ji improvments
Goffi <goffi@goffi.org>
parents: 4
diff changeset
106 m_contactList->addContact(contact);
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
108
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
109 void Bellaciao::quit()
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111 if ( QMessageBox::question (
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
115 QMessageBox::Yes | QMessageBox::No,
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
116 QMessageBox::No
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
117 ) == QMessageBox::Yes
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
118 )
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
119 {
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
120 qApp->quit();
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
121 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
122 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
123
2
fee291c8d42a settings: profiles management first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
124 void Bellaciao::showSettings()
0
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
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
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
128 }
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
129
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
130 void Bellaciao::on_actionToggle_fullscreen_triggered()
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
131 {
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if (isFullScreen())
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
133 showNormal();
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
134 else
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
135 showFullScreen();
22b44846b04b Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
136 }