Exemplo n.º 1
0
void Xmpp::login (const QString& jid, const QString& passwd)
{
    Q_ASSERT (!jid.isEmpty());
    Q_ASSERT (!passwd.isEmpty());

    m_jid = jid;

    //
    // Avoid common issues realted to Facebook accounts...
    // XMPP connections to Facebook only work when we connect to "chat.facebook.com"
    //
    if (m_jid.contains ("@facebook.com") || jid.contains ("@fb.com") || jid.contains ("@chat.fb.com"))
    {
        m_jid.replace ("fb.com", "facebook.com");
        m_jid.replace ("@facebook.com", "@chat.facebook.com");
    }

    //
    // Connect with the specified JID and password
    //
    m_client->connectToServer (m_jid, passwd);

    //
    // Communicate the XMPP client with the rest of the class
    //
    connect (m_client, SIGNAL (connected()), this, SIGNAL (connected()));
    connect (m_client, SIGNAL (disconnected()), this, SIGNAL (disconnected()));
    connect (m_client, SIGNAL (error (QXmppClient::Error)), this, SIGNAL (disconnected()));
    connect (m_client, SIGNAL (messageReceived (QXmppMessage)), this,
             SLOT (messageReceived (QXmppMessage)));
    connect (&m_client->rosterManager(), SIGNAL (rosterReceived()),
             this, SLOT (rosterReceived()));
}
Exemplo n.º 2
0
void QXmppRosterManager::rosterIqReceived(const QXmppRosterIq& rosterIq)
{
    bool isInitial = (m_rosterReqId == rosterIq.id());

    switch(rosterIq.type())
    {
    case QXmppIq::Set:
        {
            // send result iq
            QXmppIq returnIq(QXmppIq::Result);
            returnIq.setId(rosterIq.id());
            m_stream->sendPacket(returnIq);

            // store updated entries and notify changes
            const QList<QXmppRosterIq::Item> items = rosterIq.items();
            for (int i = 0; i < items.count(); i++)
            {
                QString bareJid = items.at(i).bareJid();
                m_entries[bareJid] = items.at(i);
                emit rosterChanged(bareJid);
            }

            // when contact subscribes user...user sends 'subscribed' presence 
            // then after recieving following iq user requests contact for subscription
            
            // check the "from" is newly added in the roster...and remove this ask thing...and do this for all items
            QXmppRosterIq::Item item = items.at(0);
            if (!item.bareJid().isEmpty() &&
                item.subscriptionType() == QXmppRosterIq::Item::From &&
                item.subscriptionStatus().isEmpty())
            {
                QXmppPresence presence;
                presence.setTo(item.bareJid());
                presence.setType(QXmppPresence::Subscribe);
                m_stream->sendPacket(presence);
            }
        }
        break;
    case QXmppIq::Result:
        {
            QList<QXmppRosterIq::Item> items = rosterIq.items();
            for(int i = 0; i < items.count(); ++i)
            {
                QString bareJid = items.at(i).bareJid();
                m_entries[bareJid] = items.at(i);
                if (!isInitial)
                    emit rosterChanged(bareJid);
            }
            if (isInitial)
            {
                m_isRosterReceived = true;
                emit rosterReceived();
            }
            break;
        }
    default:
        break;
    }
}
Exemplo n.º 3
0
void Client::clientConnected()
{
    qDebug() << "Client has connected server.";
     QXmppRosterManager *roster = &m_client->rosterManager();
     qDebug() << roster->getRosterBareJids();
     connect(roster, SIGNAL(rosterReceived()),
             this, SLOT(parseRoster()) );

    QTimer::singleShot(1000, this, SIGNAL( loginSuccessed() ));
}
Exemplo n.º 4
0
void MyXmppClient::initRosterManager() {
  rosterManager = &xmppClient->rosterManager();

  qDebug() << "MyXmppClient::clientStateChanged(): initializing roster manager";

  QObject::connect( rosterManager, SIGNAL(presenceChanged(QString,QString)), this, SLOT(initPresence(const QString, const QString)), Qt::UniqueConnection );
  QObject::connect( rosterManager, SIGNAL(rosterReceived()), this, SLOT(initRoster()), Qt::UniqueConnection );
  QObject::connect( rosterManager, SIGNAL(subscriptionReceived(QString)), this, SLOT(notifyNewSubscription(QString)), Qt::UniqueConnection );
  QObject::connect( rosterManager, SIGNAL(itemAdded(QString)), this, SLOT(itemAdded(QString)), Qt::UniqueConnection );
  QObject::connect( rosterManager, SIGNAL(itemRemoved(QString)), this, SLOT(itemRemoved(QString)), Qt::UniqueConnection );
  QObject::connect( rosterManager, SIGNAL(itemChanged(QString)), this, SLOT(itemChanged(QString)), Qt::UniqueConnection );
}
Exemplo n.º 5
0
void Lvk::CA::XmppChatbot::connectSignals()
{
    connect(m_xmppClient, SIGNAL(messageReceived(const QXmppMessage&)),
            this, SLOT(onMessageReceived(const QXmppMessage&)));

    connect(m_xmppClient, SIGNAL(connected()),    SLOT(onConnected()));

    connect(&m_xmppClient->rosterManager(), SIGNAL(rosterReceived()), SLOT(onRosterReceived()));
    connect(&m_xmppClient->rosterManager(), SIGNAL(rosterChanged(QString)),
            SLOT(onRosterChanged(QString)));

    connect(&m_xmppClient->vCardManager(), SIGNAL(vCardReceived(const QXmppVCardIq&)),
            this, SLOT(onVCardReceived(const QXmppVCardIq&)));

    connect(m_xmppClient, SIGNAL(disconnected()), SLOT(onDisconnected()));

    connect(m_xmppClient, SIGNAL(error(QXmppClient::Error)),
            SLOT(emitLocalError(QXmppClient::Error)));

    connect(&m_netMgr, SIGNAL(onlineStateChanged(bool)), SLOT(onOnlineStateChanged(bool)));
}
Exemplo n.º 6
0
XMPP::XMPP(QObject *parent) : QXmppClient(parent),
        m_Hub(NULL),
        m_App(NULL),
        m_Connected(false),
        m_LastError(0),
        m_SendContactWhenAvailable(false),
        m_ConnectionType(OTHER),

        m_Port(27015),
        m_NotificationEnabled(true),
        m_Restarting(false),
        m_VcardManagerConnected(false) {


    m_PauseService = false;

    bool check = connect(this, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
    Q_ASSERT(check);

    check = connect(&this->rosterManager(), SIGNAL(rosterReceived()), this, SLOT(rosterReceived()));
    Q_ASSERT(check);
    Q_UNUSED(check);


    check = connect(this, SIGNAL(connected()), this, SLOT(logConnection()));
    Q_ASSERT(check);
    Q_UNUSED(check);

    check = connect(this, SIGNAL(error(QXmppClient::Error)), this, SLOT(logConnectionError(QXmppClient::Error)));
    Q_ASSERT(check);


    check = connect(&this->rosterManager(), SIGNAL(presenceChanged(QString,QString)), SLOT(presenceChanged(QString,QString)));
    Q_ASSERT(check);


    // ---------------------------------------------------------------------
    // communication controls
    m_Server = boost::shared_ptr<QTcpServer>(new QTcpServer(this));

    bool ok = connect(m_Server.get(), SIGNAL(newConnection()), this, SLOT(newConnection()));
    Q_ASSERT(ok);
    Q_UNUSED(ok);

    // put the handling of the server into a thread --> avoid blocking the XMPP client while listening a new UI client...
    m_TcpThreadBind = boost::shared_ptr<TcpThreadBind>(new TcpThreadBind());
    m_TcpThreadBind->m_Server = m_Server;
    m_TcpThreadBind->m_Port   = m_Port;



    initOTR();


    // ---------------------------------------------------------------------
    // connection using oauth (PREFERED)

    QSettings settings("Amonchakai", "Hg10");
    if(!settings.value("access_token").value<QString>().isEmpty()) {

        m_GoogleConnect = boost::shared_ptr<GoogleConnectController>(new GoogleConnectController());
        bool check = connect(m_GoogleConnect.get(), SIGNAL(tokenObtained(const QString&)), this, SLOT(readyRestart(const QString &)));
        Q_ASSERT(check);
        Q_UNUSED(check);

        check = connect(m_GoogleConnect.get(), SIGNAL(failedRenew()), this, SLOT(oauth2Restart()));
        Q_ASSERT(check);

        //check = connect(m_GoogleConnect.get(), SIGNAL(failedConnection()), this, SLOT(waitForInternet()));
        //Q_ASSERT(check);

        check = connect(this, SIGNAL(disconnected()), this, SLOT(oauthDisconnected()));
        Q_ASSERT(check);

        oauth2Restart();

    } else {
Exemplo n.º 7
0
/// \cond
bool QXmppRosterManager::handleStanza(const QDomElement &element)
{
    if (element.tagName() != "iq" || !QXmppRosterIq::isRosterIq(element))
        return false;

    // Security check: only server should send this iq
    // from() should be either empty or bareJid of the user
    const QString fromJid = element.attribute("from");
    if (!fromJid.isEmpty() && QXmppUtils::jidToBareJid(fromJid) != client()->configuration().jidBare())
        return false;

    QXmppRosterIq rosterIq;
    rosterIq.parse(element);

    bool isInitial = (d->rosterReqId == rosterIq.id());
    switch(rosterIq.type())
    {
    case QXmppIq::Set:
        {
            // send result iq
            QXmppIq returnIq(QXmppIq::Result);
            returnIq.setId(rosterIq.id());
            client()->sendPacket(returnIq);

            // store updated entries and notify changes
            const QList<QXmppRosterIq::Item> items = rosterIq.items();
            foreach (const QXmppRosterIq::Item &item, items) {
                const QString bareJid = item.bareJid();
                if (item.subscriptionType() == QXmppRosterIq::Item::Remove) {
                    if (d->entries.remove(bareJid)) {
                        // notify the user that the item was removed
                        emit itemRemoved(bareJid);
                    }
                } else {
                    const bool added = !d->entries.contains(bareJid);
                    d->entries.insert(bareJid, item);
                    if (added) {
                        // notify the user that the item was added
                        emit itemAdded(bareJid);
                    } else {
                        // notify the user that the item changed
                        emit itemChanged(bareJid);
                    }

                    // FIXME: remove legacy signal
                    emit rosterChanged(bareJid);
                }
            }
        }
        break;
    case QXmppIq::Result:
        {
            const QList<QXmppRosterIq::Item> items = rosterIq.items();
            foreach (const QXmppRosterIq::Item &item, items) {
                const QString bareJid = item.bareJid();
                d->entries.insert(bareJid, item);
                if (!isInitial)
                    emit rosterChanged(bareJid);
            }
            if (isInitial)
            {
                d->isRosterReceived = true;
                emit rosterReceived();
            }
            break;
        }
    default:
        break;
    }

    return true;
}
Exemplo n.º 8
0
CFrmUserList::CFrmUserList(QWidget *parent) :
    QFrame(parent),
    m_UserList(this),
    ui(new Ui::CFrmUserList)
{
    ui->setupUi(this);

    InitMenu();

    m_pModel = new QStandardItemModel(this);
    if(m_pModel)
    {
        //增加头,只有增加了这个后,下面才会显示内容  
        m_pModel->setHorizontalHeaderLabels(QStringList() << tr("User name or group")<< tr("Information"));
    }

    m_UserList.setModel(m_pModel);
    m_UserList.show();

    InsertGroup(tr("My friends"));

    bool check = connect(&m_UserList, SIGNAL(clicked(QModelIndex)),
                         SLOT(clicked(QModelIndex)));
    Q_ASSERT(check);

    check = connect(&m_UserList, SIGNAL(doubleClicked(QModelIndex)),
                         SLOT(doubleClicked(QModelIndex)));
    Q_ASSERT(check);

    check = connect(&m_UserList, SIGNAL(customContextMenuRequested(QPoint)),
                    SLOT(slotCustomContextMenuRequested(QPoint)));
    Q_ASSERT(check);

    check = connect(CGlobal::Instance()->GetMainWindow(), SIGNAL(sigMenuInitOperator(QMenu*)),
                    SLOT(slotAddToMainMenu(QMenu*)));
    Q_ASSERT(check);

    check = connect(CGlobal::Instance()->GetMainWindow(), SIGNAL(sigRefresh()),
                    SLOT(slotRefresh()));
    Q_ASSERT(check);

    check = connect(CGlobal::Instance()->GetMainWindow(), SIGNAL(sigMenuRemoveOperator(QMenu*)),
                    SLOT(slotDeleteFromMainMenu(QMenu*)));
    Q_ASSERT(check);

    check = connect(CGlobal::Instance()->GetXmppClient(),
                         SIGNAL(presenceReceived(const QXmppPresence)),
                         SLOT(slotChangedPresence(QXmppPresence)));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->rosterManager(), SIGNAL(rosterReceived()),
                    SLOT(slotRosterReceived()));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->rosterManager(), SIGNAL(subscriptionReceived(QString)),
                    SLOT(slotSubscriptionReceived(QString)));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->rosterManager(), SIGNAL(itemAdded(QString)),
                    SLOT(slotItemAdded(QString)));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->rosterManager(), SIGNAL(itemChanged(QString)),
                    SLOT(slotItemChanged(QString)));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->rosterManager(), SIGNAL(itemRemoved(QString)),
                    SLOT(slotItemRemoved(QString)));
    Q_ASSERT(check);

    check = connect(&CGlobal::Instance()->GetXmppClient()->vCardManager(), SIGNAL(vCardReceived(QXmppVCardIq)),
                    SLOT(slotvCardReceived(QXmppVCardIq)));
    Q_ASSERT(check);

    check = connect(CGlobal::Instance()->GetXmppClient(), SIGNAL(messageReceived(QXmppMessage)),
                    SLOT(slotClientMessageReceived(QXmppMessage)));
    Q_ASSERT(check);
}
Exemplo n.º 9
0
Xmpp_client::Xmpp_client(QString a_login, QString a_password, int a_xmpp_client_port, QObject *parent) : m_login(a_login), m_password(a_password), m_xmpp_client_port(a_xmpp_client_port), QXmppClient(parent)
{
    bool check;
    Q_UNUSED(check);

    m_capabilitiesCache = new capabilitiesCache(this);
    m_vCardCache = new vCardCache(this);

    qDebug() << "Xmpp_client::Xmpp_client !!!";

    QXmppLogger::getLogger()->setLoggingType(QXmppLogger::SignalLogging);


    transfer_manager = new QXmppTransferManager;
    this->addExtension (transfer_manager);


    // uncomment one of the following if you only want to use a specific transfer method:
    //
     //transfer_manager->setSupportedMethods(QXmppTransferJob::InBandMethod);
    // manager->setSupportedMethods(QXmppTransferJob::SocksMethod);
     transfer_manager->setProxy("proxy.nodecast.net");
     transfer_manager->setSupportedMethods(QXmppTransferJob::InBandMethod);

     muc_manager = new QXmppMucManager;
     this->addExtension(muc_manager);



     check = connect(&this->rosterManager(),
                          SIGNAL(rosterReceived()),
                          this, SLOT(rosterReceived()));
     Q_ASSERT(check);


     check = connect(&this->rosterManager(),
                          SIGNAL(itemChanged(QString)),
                          this, SLOT(rosterChanged(QString)));
     Q_ASSERT(check);


     check = connect(&this->rosterManager(), SIGNAL(presenceChanged(QString,QString)),
                     this, SLOT(presenceChanged(QString,QString)));                
     Q_ASSERT(check);


     check = connect(this, SIGNAL(messageReceived(const QXmppMessage&)),
           SLOT(messageReceived(const QXmppMessage&)));
       Q_ASSERT(check);
       Q_UNUSED(check);

    check = connect(this, SIGNAL(presenceReceived(const QXmppPresence&)),
                    SLOT(presenceReceived(const QXmppPresence&)));



    check = connect(this, SIGNAL(connected()), SLOT(updateStatusWidget()));
    Q_ASSERT(check);


   // check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(addAccountToCache()));
  //  Q_ASSERT(check);


    check = connect(this, SIGNAL(connected()),
                    SLOT(connectedToServer()));
    Q_ASSERT(check);


    check = connect(this, SIGNAL(disconnected()),
                    SLOT(disconnectedToServer()));
    Q_ASSERT(check);


    check = connect(this, SIGNAL(error(QXmppClient::Error)),
                    SLOT(connectedError()));
    Q_ASSERT(check);



    check = connect(transfer_manager, SIGNAL(fileReceived(QXmppTransferJob*)),
                             SLOT(file_received(QXmppTransferJob*)));
    Q_ASSERT(check);


    check = connect(transfer_manager, SIGNAL(jobFinished(QXmppTransferJob*)),
                             SLOT(job_finished(QXmppTransferJob*)));
    Q_ASSERT(check);


    check = connect(&this->vCardManager(),
                    SIGNAL(vCardReceived(QXmppVCardIq)), m_vCardCache,
                    SLOT(vCardReceived(QXmppVCardIq)));
    Q_ASSERT(check);

    check = connect(m_vCardCache,
                    SIGNAL(vCardReadyToUse(QString)),
                    SLOT(updateVCard(QString)));
    Q_ASSERT(check);




    check = connect(QXmppLogger::getLogger(),
            SIGNAL(message(QXmppLogger::MessageType,QString)),
            &m_consoleDlg,
            SLOT(message(QXmppLogger::MessageType,QString)));
    Q_ASSERT(check);




    //this->logger()->setLoggingType(QXmppLogger::StdoutLogging);

    //this->logger()->setLoggingType(QXmppLogger::FileLogging);


    m_rosterItemSortFilterModel = new rosterItemSortFilterProxyModel(this);
    m_rosterItemModel = new rosterItemModel(this);
    roster = new Ui::Roster;
    roster_widget= new QWidget;
    roster->setupUi(roster_widget);
    layoutRoster = new QVBoxLayout;
    layoutRoster->addWidget(&m_statusWidget);
    layoutRoster->addWidget(roster_widget);

    m_stacked_tab_chat = new QStackedWidget;

    vRosterSplitter = new QSplitter(Qt::Horizontal);
    groupBoxContact = new QGroupBox;
    groupBoxContact->setLayout(layoutRoster);

    vRosterSplitter->addWidget(groupBoxContact);
    vRosterSplitter->addWidget(m_stacked_tab_chat);

    check = connect(roster->lineEdit_filter, SIGNAL(textChanged(QString)),
                    this, SLOT(filterChanged(QString)));
    Q_ASSERT(check);


    m_rosterItemSortFilterModel->setSourceModel(m_rosterItemModel);
    roster->listView->setModel(m_rosterItemSortFilterModel);
    m_rosterItemSortFilterModel->sort(0);


    connect(roster->listView->selectionModel(),
            SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(rosterItemSelectionChanged(QItemSelection)));




    rosterItemDelegate *delegate = new rosterItemDelegate();
    roster->listView->setItemDelegate(delegate);
    roster->verticalLayout->insertWidget(0, &m_statusWidget);


    check = connect(&m_statusWidget, SIGNAL(statusTextChanged(QString)),
                    SLOT(statusTextChanged(QString)));
    Q_ASSERT(check);
    check = connect(&m_statusWidget, SIGNAL(presenceTypeChanged(QXmppPresence::Type)),
                    SLOT(presenceTypeChanged(QXmppPresence::Type)));
    Q_ASSERT(check);
    check = connect(&m_statusWidget,
                    SIGNAL(presenceStatusTypeChanged(QXmppPresence::AvailableStatusType)),
                    SLOT(presenceStatusTypeChanged(QXmppPresence::AvailableStatusType)));
    Q_ASSERT(check);
    check = connect(&m_statusWidget,
                    SIGNAL(avatarChanged(QImage)),
                    SLOT(avatarChanged(QImage)));
    Q_ASSERT(check);


    check = connect(roster->listView, SIGNAL(showProfile(QString)),
                    this, SLOT(showProfile(QString)));
    Q_ASSERT(check);

    check = connect(roster->listView, SIGNAL(removeContact(QString)),
                    this, SLOT(action_removeContact(QString)));
    Q_ASSERT(check);

    check = connect(roster->pushButton_addContact, SIGNAL(clicked()), SLOT(action_addContact()));
    Q_ASSERT(check);


    this->configuration().setPort(m_xmpp_client_port);
    this->configuration().setJid(m_login);
    this->configuration().setPassword(m_password);
    this->configuration().setResource("nodecast");
    this->configuration().setStreamSecurityMode(QXmppConfiguration::StreamSecurityMode::TLSRequired);

    this->connectToServer(this->configuration());
}