comparison 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
comparison
equal deleted inserted replaced
3:2195295a2058 4:220e5619bf87
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include "bellaciao.h" 19 #include "bellaciao.h"
20 #include "settings.h" 20 #include "settings.h"
21 #include "jid.h"
22
23 Bellaciao* Bellaciao::_instance=0;
21 24
22 Bellaciao::Bellaciao() 25 Bellaciao::Bellaciao()
23 :QMainWindow(0) 26 :QMainWindow(0)
24 { 27 {
25 m_bridge = Bridge::getBridge(); 28 m_bridge = Bridge::getBridge();
29 m_session = Session::getSession();
26 30
27 //Ui 31 //Ui
28 setupUi(this); 32 setupUi(this);
29 const QString & media_dir = m_bridge->getConfig("", "media_dir"); 33 const QString & media_dir = m_bridge->getConfig("", "media_dir");
30 setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png")); 34 setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png"));
33 37
34 //Signals & Slots 38 //Signals & Slots
35 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); 39 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
36 connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit())); 40 connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
37 41
42 //D-Bus Signals
43 connect(m_bridge, SIGNAL(connected(QString)), this, SLOT(connected(QString)));
44 connect(m_bridge, SIGNAL(newContact(const QString&, StringDict, const QStringList&, const QString&)), this, SLOT(addContact(const QString&, StringDict, const QStringList&, const QString&)));
45
38 46
39 addDockWidget(Qt::LeftDockWidgetArea, m_contactList); 47 addDockWidget(Qt::LeftDockWidgetArea, m_contactList);
40 48
41 49
42 setWindowTitle("Bellaciao"); 50 //TODO: retrieve saved session's settings from SàT, and fill contactList
43 QList<MenuT> menus = m_bridge->getMenus(); 51
44 foreach(const MenuT &menu, menus)
45 qDebug() << menu.name;
46 52
47 QList<ContactT> contacts = m_bridge->getContacts("jabberfr"); 53 }
54
55 Bellaciao* Bellaciao::getInstance()
56 {
57 if (_instance==0)
58 _instance = new Bellaciao;
59
60 return _instance;
61 }
62
63 void Bellaciao::connectProfiles()
64 /* Connect profiles, and fill contact lists*/
65 {
66 const QList<QString> & profiles = m_session->getProfiles();
67 m_contactList->clear();
68 foreach(const QString& profile, profiles) {
69 //We autoconnect profile at the moment, behaviour can change in the future
70 if (m_bridge->isConnected(profile))
71 fillContactList(profile);
72 m_bridge->connect(profile);
73 }
74 }
75
76 void Bellaciao::fillContactList(const QString& profile)
77 {
78
79 const QList<ContactT>& contacts = m_bridge->getContacts(profile);
48 80
49 foreach(const ContactT &contact, contacts) 81 foreach(const ContactT &contact, contacts)
50 m_contactList->addContact(contact.jid); 82 m_contactList->addContact(contact.jid);
51 //qDebug() << contact.jid << contact.attributes << contact.groups;
52
53 83
84 }
85
86 //slots
87
88 //D-Bus slots
89
90 void Bellaciao::connected(const QString & profile)
91 {
92 fillContactList(profile);
93 }
94
95 void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile)
96 {
97 Jid jid = Jid(s_jid);
98 m_contactList->addContact(jid);
54 } 99 }
55 100
56 void Bellaciao::quit() 101 void Bellaciao::quit()
57 { 102 {
58 if ( QMessageBox::question ( 103 if ( QMessageBox::question (
68 } 113 }
69 } 114 }
70 115
71 void Bellaciao::showSettings() 116 void Bellaciao::showSettings()
72 { 117 {
73 qDebug("Show settings");
74 Settings::getDialog()->show(); 118 Settings::getDialog()->show();
75 Settings::getDialog()->raise(); 119 Settings::getDialog()->raise();
76 } 120 }
77 121
78 void Bellaciao::on_actionToggle_fullscreen_triggered() 122 void Bellaciao::on_actionToggle_fullscreen_triggered()
79 { 123 {
80 if (isFullScreen()) 124 if (isFullScreen())
81 showNormal(); 125 showNormal();
82 else 126 else
83 showFullScreen(); 127 showFullScreen();
84 qDebug("on_actionToggle_fullscreen_triggered");
85 } 128 }