# HG changeset patch # User Goffi # Date 1313013745 -7200 # Node ID 220e5619bf87a36b7bf59e3ccea9f6c4a4de5ca8 # Parent 2195295a2058c6e5b7002881449b5c768ed8f82f Profiles selection now fill contact list + new Jid class diff -r 2195295a2058 -r 220e5619bf87 bellaciao.cpp --- a/bellaciao.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/bellaciao.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -18,11 +18,15 @@ #include "bellaciao.h" #include "settings.h" +#include "jid.h" + +Bellaciao* Bellaciao::_instance=0; Bellaciao::Bellaciao() :QMainWindow(0) { m_bridge = Bridge::getBridge(); + m_session = Session::getSession(); //Ui setupUi(this); @@ -35,22 +39,63 @@ connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit())); + //D-Bus Signals + connect(m_bridge, SIGNAL(connected(QString)), this, SLOT(connected(QString))); + connect(m_bridge, SIGNAL(newContact(const QString&, StringDict, const QStringList&, const QString&)), this, SLOT(addContact(const QString&, StringDict, const QStringList&, const QString&))); + addDockWidget(Qt::LeftDockWidgetArea, m_contactList); - - setWindowTitle("Bellaciao"); - QList menus = m_bridge->getMenus(); - foreach(const MenuT &menu, menus) - qDebug() << menu.name; + + //TODO: retrieve saved session's settings from SàT, and fill contactList + + +} + +Bellaciao* Bellaciao::getInstance() +{ + if (_instance==0) + _instance = new Bellaciao; + + return _instance; +} - QList contacts = m_bridge->getContacts("jabberfr"); +void Bellaciao::connectProfiles() +/* Connect profiles, and fill contact lists*/ +{ + const QList & profiles = m_session->getProfiles(); + m_contactList->clear(); + foreach(const QString& profile, profiles) { + //We autoconnect profile at the moment, behaviour can change in the future + if (m_bridge->isConnected(profile)) + fillContactList(profile); + m_bridge->connect(profile); + } +} + +void Bellaciao::fillContactList(const QString& profile) +{ + + const QList& contacts = m_bridge->getContacts(profile); foreach(const ContactT &contact, contacts) m_contactList->addContact(contact.jid); - //qDebug() << contact.jid << contact.attributes << contact.groups; - + +} + +//slots + +//D-Bus slots +void Bellaciao::connected(const QString & profile) +{ + fillContactList(profile); +} + +void Bellaciao::addContact(const QString &s_jid, StringDict attributes, const QStringList &groups, const QString &profile) +{ + Jid jid = Jid(s_jid); + m_contactList->addContact(jid); } void Bellaciao::quit() @@ -70,7 +115,6 @@ void Bellaciao::showSettings() { - qDebug("Show settings"); Settings::getDialog()->show(); Settings::getDialog()->raise(); } @@ -81,5 +125,4 @@ showNormal(); else showFullScreen(); - qDebug("on_actionToggle_fullscreen_triggered"); } diff -r 2195295a2058 -r 220e5619bf87 bellaciao.h --- a/bellaciao.h Mon Aug 08 10:59:34 2011 +0200 +++ b/bellaciao.h Thu Aug 11 00:02:25 2011 +0200 @@ -24,12 +24,17 @@ #include "ui_main_win.h" #include "contact_list.h" #include "bridge.h" +#include "session.h" class Bellaciao : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: + static Bellaciao* getInstance(); + void connectProfiles(); + + protected: Bellaciao(); @@ -37,10 +42,16 @@ void quit(); void showSettings(); void on_actionToggle_fullscreen_triggered(); + //D-Bus slots + void connected(const QString& profile); + void addContact(const QString& jid, StringDict attributes, const QStringList& groups, const QString& profile); private: + void fillContactList(const QString& profile); + static Bellaciao* _instance; + Bridge* m_bridge; + Session* m_session; ContactList* m_contactList; - Bridge* m_bridge; }; #endif diff -r 2195295a2058 -r 220e5619bf87 bellaciao.pro --- a/bellaciao.pro Mon Aug 08 10:59:34 2011 +0200 +++ b/bellaciao.pro Thu Aug 11 00:02:25 2011 +0200 @@ -10,6 +10,6 @@ CONFIG += debug # Input -HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h settings.h session.h -SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp settings.cpp session.cpp +HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h settings.h session.h contact.h jid.h +SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp settings.cpp session.cpp contact.cpp jid.cpp FORMS += main_win.ui settings.ui diff -r 2195295a2058 -r 220e5619bf87 bridge.cpp --- a/bridge.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/bridge.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -29,6 +29,7 @@ Bridge* Bridge::getBridge() { if (_bridge_instance == 0) { + qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType< QList >(); diff -r 2195295a2058 -r 220e5619bf87 contact.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contact.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -0,0 +1,35 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "contact.h" + +ContactT::ContactT() +{ + connected = false; +} + +ContactT::~ContactT() +{ +} + + +bool ContactT::isConnected() { + return connected; +} + + diff -r 2195295a2058 -r 220e5619bf87 contact.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contact.h Thu Aug 11 00:02:25 2011 +0200 @@ -0,0 +1,44 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef CONTACT_H +#define CONTACT_H + +#include "jid.h" +#include + +typedef QHash StringDict; + +class ContactT { + public: + ContactT(); + ~ContactT(); + Jid jid; + StringDict attributes; + QList groups; + + bool isConnected(); + + + private: + bool connected; + +}; + + +#endif diff -r 2195295a2058 -r 220e5619bf87 contact_list.cpp --- a/contact_list.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/contact_list.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -1,5 +1,5 @@ /* -Mignonne: a Salut à Toi frontend +Bellaciao: a Salut à Toi frontend Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) This program is free software: you can redistribute it and/or modify @@ -18,7 +18,6 @@ #include "contact_list.h" - ContactList::ContactList(QWidget * parent): QDockWidget(tr("Contacts"), parent) @@ -32,7 +31,12 @@ } -void ContactList::addContact(const QString& jid) +void ContactList::addContact(const Jid& jid) { - new QListWidgetItem(jid, listWidget); + new QListWidgetItem(jid.getString(), listWidget); } + +void ContactList::clear() +{ + listWidget->clear(); +} diff -r 2195295a2058 -r 220e5619bf87 contact_list.h --- a/contact_list.h Mon Aug 08 10:59:34 2011 +0200 +++ b/contact_list.h Thu Aug 11 00:02:25 2011 +0200 @@ -1,5 +1,5 @@ /* -Mignonne: a Salut à Toi frontend +Bellaciao: a Salut à Toi frontend Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) This program is free software: you can redistribute it and/or modify @@ -20,13 +20,15 @@ #define CONTACTLIST_H #include +#include "jid.h" class ContactList : public QDockWidget { Q_OBJECT public: ContactList(QWidget* parent = 0); - void addContact(const QString& jid); + void addContact(const Jid& jid); + void clear(); private: QWidget* mainWidget; QListWidget* listWidget; diff -r 2195295a2058 -r 220e5619bf87 dbus_types.cpp --- a/dbus_types.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/dbus_types.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -1,5 +1,5 @@ /* -Mignonne: a Salut à Toi frontend +Bellaciao: a Salut à Toi frontend Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) This program is free software: you can redistribute it and/or modify @@ -17,6 +17,20 @@ */ #include "dbus_types.h" +#include + +QDBusArgument &operator<<(QDBusArgument &argument, const Jid &jid) +{ + return argument << jid.getString(); +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, Jid &jid) +{ + QString _str = QString(); + argument >> _str; + jid.fromString(_str); + return argument; +} QDBusArgument &operator<<(QDBusArgument &argument, const ContactT &contact) { diff -r 2195295a2058 -r 220e5619bf87 dbus_types.h --- a/dbus_types.h Mon Aug 08 10:59:34 2011 +0200 +++ b/dbus_types.h Thu Aug 11 00:02:25 2011 +0200 @@ -1,5 +1,5 @@ /* -Mignonne: a Salut à Toi frontend +Bellaciao: a Salut à Toi frontend Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) This program is free software: you can redistribute it and/or modify @@ -24,15 +24,10 @@ #include #include #include +#include "contact.h" typedef QHash StringDict; -struct ContactT { - QString jid; - StringDict attributes; - QList groups; -}; - struct MessageT { QString from_jid; QString text; @@ -58,6 +53,7 @@ typedef QHash ActionResultExtDataT; +Q_DECLARE_METATYPE(Jid); Q_DECLARE_METATYPE(StringDict); Q_DECLARE_METATYPE(ContactT); Q_DECLARE_METATYPE(QList); @@ -67,6 +63,8 @@ Q_DECLARE_METATYPE(QList); Q_DECLARE_METATYPE(ActionResultExtDataT); +QDBusArgument &operator<<(QDBusArgument &argument, const Jid &jid); +const QDBusArgument &operator>>(const QDBusArgument &argument, Jid &jid); QDBusArgument &operator<<(QDBusArgument &argument, const ContactT &contact); const QDBusArgument &operator>>(const QDBusArgument &argument, ContactT &contact); QDBusArgument &operator<<(QDBusArgument &argument, const MenuT &menu); diff -r 2195295a2058 -r 220e5619bf87 jid.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jid.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -0,0 +1,130 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "jid.h" +#include + +Jid::Jid() + :m_valid(false) +{ +} + +Jid::~Jid() +{ +} + +Jid::Jid(const QString& str) +{ + fromString(str); +} + +void Jid::fromString(const QString& str) +//Replace jid with the one parsed in str +//m_valid set to false is jid is not valid +{ + //We do a basic parsing of the string + //TODO: better parsing/validity check + m_valid = false; + m_user.clear(); + m_domain.clear(); + m_resource.clear(); + + QChar delimiter = '@'; + QString* curr_dest = &m_user; + + for (int i=0; iappend(str[i]); + } + } + + if (!m_user.isEmpty() && !m_domain.isEmpty()) + m_valid = true; +} + +QString Jid::getString() const +{ + if (!m_valid) { + return m_user; //We return the user anyway if the jid is invalid + } + return m_resource.isEmpty() ? getBareString() : getFullString(); +} + +QString Jid::getBareString() const +{ + return QString("%1@%2").arg(m_user).arg(m_domain); +} + +QString Jid::getFullString() const +{ + return QString("%1@%2/%3").arg(m_user).arg(m_domain).arg(m_resource); +} + +const QString& Jid::getUser() const +{ + return m_user; +} + +const QString& Jid::getDomain() const +{ + return m_domain; +} + +const QString& Jid::getResource() const +{ + return m_resource; +} + +void Jid::setUser(const QString& user) +{ + m_user = user; +} + +void Jid::setDomain(const QString& domain) +{ + m_domain = domain; +} + +void Jid::setResource(const QString& resource) +{ + m_resource = resource; +} + +bool Jid::isValid() +{ + return m_valid; +} diff -r 2195295a2058 -r 220e5619bf87 jid.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jid.h Thu Aug 11 00:02:25 2011 +0200 @@ -0,0 +1,48 @@ + +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef JID_H +#define JID_H + +#include + +class Jid { + public: + Jid(); + ~Jid(); + Jid(const QString& str); + void fromString(const QString& str); + QString getString() const; + QString getBareString() const; + QString getFullString() const; + const QString& getUser() const; + const QString& getDomain() const; + const QString& getResource() const; + void setUser(const QString& user); + void setDomain(const QString& domain); + void setResource(const QString& resource); + bool isValid(); + + private: + bool m_valid; + QString m_user, m_domain, m_resource; +}; + +#endif + diff -r 2195295a2058 -r 220e5619bf87 main.cpp --- a/main.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/main.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -24,8 +24,7 @@ { QApplication app(argv, args); - Bellaciao window; - window.show(); + Bellaciao::getInstance()->show(); return app.exec(); } diff -r 2195295a2058 -r 220e5619bf87 session.cpp --- a/session.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/session.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -31,6 +31,11 @@ _instance = new Session; return _instance; - } +QList& Session::getProfiles() { + return m_profiles; +} + + + diff -r 2195295a2058 -r 220e5619bf87 session.h --- a/session.h Mon Aug 08 10:59:34 2011 +0200 +++ b/session.h Thu Aug 11 00:02:25 2011 +0200 @@ -19,16 +19,20 @@ #ifndef SESSION_H #define SESSION_H +#include + class Session { public: static Session* getSession(); + QList& getProfiles(); protected: Session(); private: static Session* _instance; + QList m_profiles; }; diff -r 2195295a2058 -r 220e5619bf87 settings.cpp --- a/settings.cpp Mon Aug 08 10:59:34 2011 +0200 +++ b/settings.cpp Thu Aug 11 00:02:25 2011 +0200 @@ -17,6 +17,7 @@ */ #include "settings.h" +#include "bellaciao.h" using namespace Qt; @@ -49,20 +50,21 @@ //We fill the profiles list m_bridge = Bridge::getBridge(); + m_session = Session::getSession(); + const QList& profiles = m_bridge->getProfilesList(); const QString& default_profile = m_bridge->getProfileName("@DEFAULT@"); + const QList& checked_profiles = m_session->getProfiles(); + foreach(const QString& profile, profiles) { ProfileListWidgetItem *item = new ProfileListWidgetItem(profile, profileList, profile==default_profile); item->setFlags(item->flags() | ItemIsUserCheckable); - item->setCheckState(Checked); + item->setCheckState(checked_profiles.contains(profile)?Checked:Unchecked); } connect(profileList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(profileChanged(QListWidgetItem*))); connect(profileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(profileCurrentChanged(QListWidgetItem*, QListWidgetItem*))); - //Profiles manipulation buttons - connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); - //Confirmation buttons connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); connect(buttonsGroupConfirm, SIGNAL(rejected()), this, SLOT(cancelSettings())); @@ -84,7 +86,6 @@ //Profile settings slots void Settings::profileChanged(QListWidgetItem* item) { - qDebug() << "profileChanged"; } void Settings::profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous) @@ -165,11 +166,29 @@ //Global settings slots -void Settings::saveSettings() +void Settings::saveSettings() //Save settings to session { + // We save profiles + QList previous_profiles; + QList& profiles = m_session->getProfiles(); + previous_profiles = profiles; + profiles.clear(); + for (int i=0; icount(); i++) + { + ProfileListWidgetItem* item = dynamic_cast(profileList->item(i)); + if (item->checkState() == Checked){ + profiles.append(item->getProfile()); + } + } + + if (previous_profiles!=profiles) //The profiles checked are differents, we refill the contactList + Bellaciao::getInstance()->connectProfiles(); + + close(); + } void Settings::cancelSettings() { - this->close(); + close(); } diff -r 2195295a2058 -r 220e5619bf87 settings.h --- a/settings.h Mon Aug 08 10:59:34 2011 +0200 +++ b/settings.h Thu Aug 11 00:02:25 2011 +0200 @@ -23,6 +23,7 @@ #include #include "ui_settings.h" #include "bridge.h" +#include "session.h" class ProfileListWidgetItem : public QListWidgetItem { @@ -57,6 +58,7 @@ private: static Settings* _instance; Bridge* m_bridge; + Session* m_session; };