Commit 63bb1351 authored by Marzanna's avatar Marzanna Committed by Linus Jahn

Add simple login screen (#20)

parent f7906c2f
import QtQuick 2.5
import QtQuick.Controls 1.2
import harbour.kaidan 1.0
Item{
Column{
Row{
TextField{
id: jidField
width: 150
placeholderText: "JID"
}
TextField{
id: passField
width: 150
height: 27
placeholderText: "Password"
echoMode: TextInput.Password
}
}
Button{
id: connectButton
text: "Connect"
onClicked:{
connectButton.enabled = false;
kaidan.mainConnect(jidField.text, passField.text);
}
}
Label{
id: statusLabel
text: "Not connected"
}
}
Component.onCompleted:{
function goToRoster(){
statusLabel.text = "Connected";
//we need to disconnect enableConnectButton to prevent calling it on normal disconnection
kaidan.connectionStateDisconnected.disconnect(enableConnectButton)
mainLoader.source = "RosterPage.qml"
}
function enableConnectButton(){connectButton.enabled = true}
kaidan.connectionStateConnected.connect(goToRoster)
kaidan.connectionStateDisconnected.connect(enableConnectButton)
}
}
import QtQuick 2.1
import harbour.kaidan 1.0
Flickable{
ListView {
anchors.fill: parent
model: kaidan.rosterController.rosterList
delegate: Rectangle {
height: 25
width: parent.width
Text { text: model.modelData.jid}
}
}
}
......@@ -7,20 +7,13 @@ ApplicationWindow{
width: 360
height: 720
Flickable{
Loader{
id: mainLoader
anchors.fill: parent
ListView {
anchors.fill: parent
model: kaidan.rosterController.rosterList
delegate: Rectangle {
height: 25
width: parent.width
Text { text: model.modelData.jid}
}
}
source: "LoginPage.qml"
}
onClosing: kaidan.mainQuit()
onClosing: kaidan.mainDisconnect()
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>RosterPage.qml</file>
<file>LoginPage.qml</file>
</qresource>
</RCC>
......@@ -10,9 +10,29 @@
Kaidan::Kaidan(NetworkFactories* networkFactories, QObject *parent) :
rosterController_(new RosterController()), QObject(parent)
{
client = new Swift::Client("jid@...", "pass", networkFactories);
netFactories = networkFactories;
connected = false;
}
Kaidan::~Kaidan()
{
if(connected){
client->removePayloadSerializer(&echoPayloadSerializer);
client->removePayloadParserFactory(&echoPayloadParserFactory);
softwareVersionResponder->stop();
delete tracer;
}
delete softwareVersionResponder;
delete client;
delete rosterController_;
}
void Kaidan::mainConnect(const QString &jid, const QString &pass){
client = new Swift::Client(jid.toStdString(), pass.toStdString(), netFactories);
client->setAlwaysTrustCertificates();
client->onConnected.connect(boost::bind(&Kaidan::handleConnected, this));
client->onDisconnected.connect(boost::bind(&Kaidan::handleDisconnected, this));
client->onMessageReceived.connect(
boost::bind(&Kaidan::handleMessageReceived, this, _1));
client->onPresenceReceived.connect(
......@@ -29,21 +49,11 @@ Kaidan::Kaidan(NetworkFactories* networkFactories, QObject *parent) :
client->connect();
}
Kaidan::~Kaidan()
{
client->removePayloadSerializer(&echoPayloadSerializer);
client->removePayloadParserFactory(&echoPayloadParserFactory);
softwareVersionResponder->stop();
delete softwareVersionResponder;
delete tracer;
delete client;
delete rosterController_;
}
//we don't want to close client without disconnection
void Kaidan::mainQuit(){
client->disconnect();
void Kaidan::mainDisconnect(){
if(connectionState()){
client->disconnect();
}
}
void Kaidan::handlePresenceReceived(Presence::ref presence)
......@@ -60,12 +70,19 @@ void Kaidan::handlePresenceReceived(Presence::ref presence)
void Kaidan::handleConnected()
{
connected = true;
emit connectionStateConnected();
client->sendPresence(Presence::create("Send me a message"));
// Request the roster
rosterController_->requestRosterFromClient(client);
}
void Kaidan::handleDisconnected(){
connected = false;
emit connectionStateDisconnected();
}
void Kaidan::handleMessageReceived(Message::ref message)
{
// Echo back the incoming message
......@@ -85,3 +102,7 @@ RosterController* Kaidan::getRosterController()
{
return rosterController_;
}
bool Kaidan::connectionState() const{
return connected;
}
......@@ -16,27 +16,35 @@ class Kaidan : public QObject
Q_OBJECT
Q_PROPERTY(RosterController* rosterController READ getRosterController NOTIFY rosterControllerChanged)
Q_PROPERTY(bool connectionState READ connectionState NOTIFY connectionStateConnected NOTIFY connectionStateDisconnected)
public:
Kaidan(Swift::NetworkFactories* networkFactories, QObject *parent = 0);
~Kaidan();
Q_INVOKABLE void mainQuit();
Q_INVOKABLE void mainDisconnect();
Q_INVOKABLE void mainConnect(const QString &jid, const QString &pass);
bool connectionState() const;
RosterController* getRosterController();
signals:
void rosterControllerChanged();
void connectionStateConnected();
void connectionStateDisconnected();
private:
void handlePresenceReceived(Swift::Presence::ref presence);
void handleConnected();
void handleDisconnected();
void handleMessageReceived(Swift::Message::ref message);
bool connected;
Swift::Client* client;
Swift::ClientXMLTracer* tracer;
Swift::SoftwareVersionResponder* softwareVersionResponder;
EchoPayloadParserFactory echoPayloadParserFactory;
EchoPayloadSerializer echoPayloadSerializer;
Swift::NetworkFactories *netFactories;
RosterController* rosterController_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment