Change XMPP connection to use stored credentials.
This commit is contained in:
parent
7717005415
commit
65264b517c
|
@ -331,12 +331,8 @@ int main(int argc, char *argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_REMOTE
|
#ifdef HAVE_REMOTE
|
||||||
Zeroconf* zeroconf = Zeroconf::GetZeroconf();
|
|
||||||
if (zeroconf) {
|
|
||||||
zeroconf->Publish("local", "_clementine._tcp", "Clementine", 12345);
|
|
||||||
}
|
|
||||||
XMPP xmpp;
|
XMPP xmpp;
|
||||||
xmpp.Connect("timetabletest2@googlemail.com", "timetabletestpassword");
|
xmpp.Connect();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
#include <gloox/connectiontcpclient.h>
|
#include <gloox/connectiontcpclient.h>
|
||||||
#include <gloox/message.h>
|
#include <gloox/message.h>
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#include "keychain.h"
|
||||||
|
|
||||||
using gloox::Client;
|
using gloox::Client;
|
||||||
using gloox::ConnectionTCPClient;
|
using gloox::ConnectionTCPClient;
|
||||||
using gloox::JID;
|
using gloox::JID;
|
||||||
|
@ -19,34 +22,52 @@ XMPP::~XMPP() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XMPP::Connect(const QString& jid, const QString& password) {
|
void XMPP::Connect() {
|
||||||
qDebug() << Q_FUNC_INFO;
|
QSettings s;
|
||||||
|
s.beginGroup("remote");
|
||||||
|
QVariant username = s.value("username");
|
||||||
|
if (username.isValid()) {
|
||||||
|
Keychain* keychain = Keychain::getDefault();
|
||||||
|
QString password = keychain->getPassword(username.toString());
|
||||||
|
Connect(username.toString() + "/clementine", password);
|
||||||
|
} else {
|
||||||
|
qWarning() << "No username or password set.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::Connect(const QString& jid, const QString& password) {
|
||||||
// TODO: Generate <256 char resource.
|
// TODO: Generate <256 char resource.
|
||||||
JID j(jid.toUtf8().constData());
|
JID j(jid.toUtf8().constData());
|
||||||
qDebug() << "Resource:" << j.resource().c_str();
|
|
||||||
client_.reset(new Client(j, password.toUtf8().constData()));
|
client_.reset(new Client(j, password.toUtf8().constData()));
|
||||||
|
client_->registerConnectionListener(this);
|
||||||
client_->registerMessageHandler(this);
|
client_->registerMessageHandler(this);
|
||||||
client_->setServer("talk.google.com");
|
client_->setServer("talk.google.com");
|
||||||
client_->connect(false);
|
client_->connect(false);
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
int fd = static_cast<ConnectionTCPClient*>(client_->connectionImpl())->socket();
|
int fd = static_cast<ConnectionTCPClient*>(client_->connectionImpl())->socket();
|
||||||
|
|
||||||
notifier_.reset(new QSocketNotifier(fd, QSocketNotifier::Read));
|
notifier_.reset(new QSocketNotifier(fd, QSocketNotifier::Read));
|
||||||
connect(notifier_.get(), SIGNAL(activated(int)), SLOT(Receive()));
|
connect(notifier_.get(), SIGNAL(activated(int)), SLOT(Receive()));
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMPP::handleMessage(const Message& stanza, MessageSession* session) {
|
void XMPP::handleMessage(const Message& stanza, MessageSession* session) {
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
qDebug() << stanza.tag()->xml().c_str();
|
qDebug() << stanza.tag()->xml().c_str();
|
||||||
qDebug() << "resource:" << client_->resource().c_str();
|
|
||||||
Message reply(Message::Chat, stanza.from(), "Hello World!");
|
Message reply(Message::Chat, stanza.from(), "Hello World!");
|
||||||
client_->send(reply);
|
client_->send(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMPP::onConnect() {
|
||||||
|
qDebug() << "Connected with resource:" << client_->resource().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::onDisconnect(gloox::ConnectionError e) {
|
||||||
|
qDebug() << "Disconnected:" << e;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool XMPP::onTLSConnect(const gloox::CertInfo& info) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void XMPP::Receive() {
|
void XMPP::Receive() {
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
client_->recv();
|
client_->recv();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define XMPP_H
|
#define XMPP_H
|
||||||
|
|
||||||
#include <gloox/client.h>
|
#include <gloox/client.h>
|
||||||
|
#include <gloox/connectionlistener.h>
|
||||||
#include <gloox/messagehandler.h>
|
#include <gloox/messagehandler.h>
|
||||||
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
@ -9,13 +10,14 @@
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class XMPP : public QObject, public gloox::MessageHandler {
|
class XMPP : public QObject, public gloox::ConnectionListener, public gloox::MessageHandler {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
XMPP();
|
XMPP();
|
||||||
virtual ~XMPP();
|
virtual ~XMPP();
|
||||||
|
|
||||||
bool Connect(const QString& jid, const QString& password);
|
void Connect();
|
||||||
|
void Connect(const QString& jid, const QString& password);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void Receive();
|
void Receive();
|
||||||
|
@ -25,6 +27,11 @@ class XMPP : public QObject, public gloox::MessageHandler {
|
||||||
virtual void handleMessage(const gloox::Message& stanza,
|
virtual void handleMessage(const gloox::Message& stanza,
|
||||||
gloox::MessageSession* session = 0);
|
gloox::MessageSession* session = 0);
|
||||||
|
|
||||||
|
// gloox::ConnectionListener
|
||||||
|
virtual void onConnect();
|
||||||
|
virtual void onDisconnect(gloox::ConnectionError e);
|
||||||
|
virtual bool onTLSConnect(const gloox::CertInfo& info);
|
||||||
|
|
||||||
boost::scoped_ptr<gloox::Client> client_;
|
boost::scoped_ptr<gloox::Client> client_;
|
||||||
boost::scoped_ptr<QSocketNotifier> notifier_;
|
boost::scoped_ptr<QSocketNotifier> notifier_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue