view bellaciao.cpp @ 5:0412dc960e3a

DBus bridge's xml update
author Goffi <goffi@goffi.org>
date Fri, 12 Aug 2011 22:05:50 +0200
parents 220e5619bf87
children 48045176d1c6
line wrap: on
line source

/*
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 <http://www.gnu.org/licenses/>.
*/

#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);
    const QString & media_dir = m_bridge->getConfig("", "media_dir");
    setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png"));
    m_contactList = new ContactList(this);
    

    //Signals & Slots
    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);
    
   
    //TODO: retrieve saved session's settings from SàT, and fill contactList 
        

}

Bellaciao* Bellaciao::getInstance()
{
    if (_instance==0)
        _instance = new Bellaciao;

    return _instance;
}

void Bellaciao::connectProfiles()
/* Connect profiles, and fill contact lists*/
{
    const QList<QString> & 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<ContactT>& contacts = m_bridge->getContacts(profile);

    foreach(const ContactT &contact, contacts)
        m_contactList->addContact(contact.jid);

}

//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()
{
    if ( QMessageBox::question (
            this,
            tr("Quit?"),
            tr("Do you really want to quit ?"),
            QMessageBox::Yes | QMessageBox::No,
            QMessageBox::No
            ) == QMessageBox::Yes
       )
    {
        qApp->quit();
    }
}

void Bellaciao::showSettings()
{
    Settings::getDialog()->show();
    Settings::getDialog()->raise();
}

void Bellaciao::on_actionToggle_fullscreen_triggered()
{
    if (isFullScreen())
        showNormal();
    else
        showFullScreen();
}