void QXmppRosterManager::presenceReceived(const QXmppPresence& presence) { QString jid = presence.from(); QString bareJid = jidToBareJid(jid); QString resource = jidToResource(jid); if (bareJid.isEmpty()) return; switch(presence.type()) { case QXmppPresence::Available: m_presences[bareJid][resource] = presence; emit presenceChanged(bareJid, resource); break; case QXmppPresence::Unavailable: m_presences[bareJid].remove(resource); emit presenceChanged(bareJid, resource); break; case QXmppPresence::Subscribe: if (m_stream->configuration().autoAcceptSubscriptions()) { QXmppPresence presence; presence.setTo(jid); presence.setType(QXmppPresence::Subscribed); m_stream->sendPacket(presence); } break; default: break; } }
void QXmppRosterManager::_q_presenceReceived(const QXmppPresence& presence) { const QString jid = presence.from(); const QString bareJid = QXmppUtils::jidToBareJid(jid); const QString resource = QXmppUtils::jidToResource(jid); if (bareJid.isEmpty()) return; switch(presence.type()) { case QXmppPresence::Available: d->presences[bareJid][resource] = presence; emit presenceChanged(bareJid, resource); break; case QXmppPresence::Unavailable: d->presences[bareJid].remove(resource); emit presenceChanged(bareJid, resource); break; case QXmppPresence::Subscribe: if (client()->configuration().autoAcceptSubscriptions()) { // accept subscription request acceptSubscription(bareJid); // ask for reciprocal subscription subscribe(bareJid); } else { emit subscriptionReceived(bareJid); } break; default: break; } }
void TelepathyClient::join(GameInfo *game) { TelepathyGameInfo *gameInfo = qobject_cast<TelepathyGameInfo *>(game); if (gameInfo == NULL) { qDebug() << "Unsupported game parameter."; return; } if (!gameInfo->contact || !gameInfo->account) return; setState(Connecting); // Subscribe to presence changes of the remote contact - we need to disconnect if its state changes to offline remoteContact = gameInfo->contact; connect(remoteContact.data(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onContactPresenceChanged(Tp::Presence))); Tp::PendingChannelRequest *request = gameInfo->account->createStreamTube(gameInfo->contact, "x-sudoku-united"); connect(request, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onCreateTubeFinished(Tp::PendingOperation*))); qDebug() << "Connecting..."; }
void ChannelContactModel::addContacts(const Tp::Contacts &contacts) { QList<Tp::ContactPtr> newContacts = contacts.toList(); Q_FOREACH(Tp::ContactPtr contact, newContacts) { connect(contact.data(), SIGNAL(aliasChanged(QString)), SLOT(onContactAliasChanged(QString))); connect(contact.data(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onContactPresenceChanged(Tp::Presence))); connect(contact.data(), SIGNAL(blockStatusChanged(bool)), SLOT(onContactBlockStatusChanged(bool))); }
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 ); }
void tlen::event(const QDomNode &n) { kdebugf(); QString nodeName=n.nodeName(); QDomElement element = n.toElement(); if(nodeName=="s" && element.hasAttribute("i")) { ping->start( 50000 ); sid = element.attribute("i"); if(tlenLogin()) state = tlen::Connected; else socket->close(); // TODO: Dont close connection and repeat login, after n times disconnect, signal } else if(nodeName=="iq") { if(element.hasAttribute( "type" ) && element.attribute("type") == "result") { // tcfg if(element.hasAttribute("id") && element.attribute("id")==sid) { tcfgRequest(); rosterRequest(); } if(element.hasAttribute("from") && element.attribute("from")=="tuba" && element.hasAttribute("id")){ // <iq from="tuba" type="result" to="jid" id="tr"> // <query xmlns="jabber:iq:register"> // <item></item></query></iq> if(element.attribute("id")=="tr") { QDomElement query = element.elementsByTagName("query").item(0).toElement(); //if (query.hasAttribute("xmlns") && element.attribute("xmlns")=="jabber:iq:register") emit pubdirReceived(query.childNodes()); return; } if(element.attribute("id")=="tw") { //if (query.hasAttribute("xmlns") && element.attribute("xmlns")=="jabber:iq:register") // TODO implement unsuccess if timeout emit pubdirUpdated(true); return; } } if(element.hasAttribute("id") && element.attribute("id")=="GetRoster") { emit clearRosterView(); } if(element.hasAttribute("from") && element.attribute("from") == "tcfg") { tcfgReceived(element); return; } if(n.hasChildNodes()) { QDomNodeList el=n.childNodes(); for(int i=0;i<el.count();++i) emit eventReceived(el.item(i)); } if(0) { emit tlenLoggedIn(); } } else if(element.hasAttribute("type") && element.attribute("type") == "set") { if(n.hasChildNodes()) { QDomNodeList el=n.childNodes(); for(int i=0;i<el.count();++i) emit eventReceived(el.item(i)); } } } else if(nodeName=="query") { QDomElement e=n.toElement(); QDomNodeList nl=n.childNodes(); for(int i=0;i<nl.count();++i) event(nl.item(i)); } else if(nodeName=="item") { QDomElement e=n.toElement(); QString jid=decode(e.attribute("jid")); QString subscription=e.attribute("subscription"); QString name=NULL, group=NULL; if(subscription=="remove") { emit removeItem(jid); return; } if(e.hasAttribute("ask")) subscription=e.attribute("ask"); if(e.hasAttribute("name")) name=e.attribute("name"); else name=jid; if( n.hasChildNodes() ) { QDomNodeList nl=n.childNodes(); for(int i=0;i<nl.count();++i) { group=nl.item(i).firstChild().toText().data(); } } if(group.isEmpty()) group=tr("Contacts"); group=decode(group.toUtf8()); name=decode(name.toUtf8()); emit itemReceived(jid, name, subscription, group); } else if(nodeName=="presence") { QDomElement e=n.toElement(); QString from=decode(e.attribute("from")); if(e.hasAttribute("type") && e.attribute("type")=="subscribe") { emit authorizationAsk(from); } else if( e.hasAttribute("type") && e.attribute("type")=="subscribed" ) return; else if(e.hasAttribute("type") && (e.attribute("type")=="unsubscribe" || e.attribute("type")=="unsubscribed")) return; else { QString status="none"; QString descr=""; if(e.hasAttribute("type")) status=e.attribute("type"); QDomNodeList l=n.childNodes(); for(int i=0; i<l.count(); ++i) { if(l.item(i).nodeName()=="show" && status=="none") status=l.item(i).firstChild().toText().data(); if(l.item(i).nodeName()=="status") descr=l.item(i).firstChild().toText().data(); if(l.item(i).nodeName()=="avatar") { // TODO store jid,type,md5 on list/qmultimap, check md5 - avatar changed QDomElement avatar = l.item(i).toElement().elementsByTagName("a").item(0).toElement(); if (avatar.hasAttribute("type") && avatar.hasAttribute("md5")) { emit avatarReceived(decode(from), avatar.attribute("type"), avatar.attribute("md5")); qDebug() << "Avatar " << from << "type:" <<avatar.attribute("type") << "md5:" << avatar.attribute("md5"); } } } descr=decode(descr.toUtf8()); emit presenceChanged(from,status,descr); } } else if(nodeName=="message") { QDomElement e=n.toElement(); if(e.hasAttribute("type") && e.attribute("type")=="chat") emit chatMsgReceived(n); } else if(nodeName=="m") { QDomElement e=n.toElement(); if(e.hasAttribute("tp")) { emit chatNotify(decode(e.attribute("f")), e.attribute("tp")); } } else if(nodeName=="n") { //<n f='Rainer+Wiesenfarth+%[email protected]%3E' s='Re%3A+qt+and+mysql,+odbc'/> - new mail } else if(nodeName=="avatar") { // search for token QDomElement e=n.toElement(); QDomNodeList l=n.childNodes(); for(int i=0; i<l.count(); ++i) if(l.item(i).nodeName()=="token") token=l.item(i).firstChild().toText().data(); } else if(nodeName=="f") { QDomElement e=n.toElement(); if(e.attribute("e")=="1") { //fileIncomingDialog *dlg=new fileIncomingDialog(n); //connect(dlg, SIGNAL(receive(QString,QString,bool)), this, SLOT(receiveFile(QString,QString,bool))); //dlg->show(); } else if(e.attribute("e")=="5") { //if( fileTransferDialog *dlg = fTransferMap.value( QString("%1-%2").arg( e.attribute("f") ).arg( e.attribute("i") ) ) ) // dlg->fileThread()->transferingAccepted(); } else if(e.attribute("e")=="6") { //fileTransferDialog *dlg=new fileTransferDialog( e.attribute("i").toInt(), e.attribute("f"), e.attribute("a"), (quint16)e.attribute("p").toInt(), TRUE); //fTransferMap.insert(QString("%1-%2").arg( e.attribute("f") ).arg( e.attribute("i") ), dlg); //dlg->show(); } else if(e.attribute("e")=="7") { //if( fileTransferDialog *dlg = fTransferMap.value( QString("%1-%2").arg( e.attribute("f") ).arg( e.attribute("i") ) ) ) // dlg->fileThread()->switchToSocketMode( e.attribute("a"), (quint16)e.attribute("p").toInt() ); } } }
void Contact::ut_emitPresenceChanged() { emit presenceChanged(mPriv->m_presence); }
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 {
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()); }
void ContactWrapper::setupContactConnects() { connect(m_contact.data(), SIGNAL(avatarDataChanged(Tp::AvatarData)), this, SIGNAL(avatarChanged())); connect(m_contact.data(), SIGNAL(presenceChanged(Tp::Presence)), this, SIGNAL(presenceChanged())); }