Commit d4527fb8 authored by Linus Jahn's avatar Linus Jahn Committed by GitHub

Add VCard back-end support (#85)

The new QML-side variables:
`kaidan.vCardController.currentJid = ""`
`kaidan.vCardController.currentVCard = VCard` (read-only)
`kaidan.vCardController.ownVCard = VCard`

Properties of a VCard:
`version`, `fullName`, `familyName`, `givenName`, `middleName`,
`prefix`, `suffix`, `nickname`, `preferredEMailAddress`

The own VCard is not working correctly yet.
parent 28cf2f19
......@@ -10,7 +10,7 @@ option(I18N "Enable i18n support" FALSE)
option(SAILFISH_OS "Build with Sailfish OS GUI, needs libs/kaidansf submodule" FALSE)
# application name
set(APPLICATION_ID "harbour.kaidan")
set(APPLICATION_ID "io.github.kaidanim")
set(APPLICATION_NAME "kaidan")
set(APPLICATION_DISPLAY_NAME "Kaidan")
set(APPLICATION_DESCRIPTION "Cross platform XMPP client")
......
......@@ -9,4 +9,6 @@ set(KAIDAN_SOURCES
${CURDIR}/MessageController.cpp
${CURDIR}/MessageModel.cpp
${CURDIR}/PresenceController.cpp
${CURDIR}/VCard.cpp
${CURDIR}/VCardController.cpp
)
......@@ -35,6 +35,8 @@
// Kaidan
#include "RosterController.h"
#include "PresenceController.h"
#include "MessageController.h"
#include "VCardController.h"
Kaidan::Kaidan(Swift::NetworkFactories* networkFactories, QObject *parent) : QObject(parent)
{
......@@ -43,6 +45,7 @@ Kaidan::Kaidan(Swift::NetworkFactories* networkFactories, QObject *parent) : QOb
messageController = new MessageController();
rosterController = new RosterController();
presenceController = new PresenceController();
vCardController = new VCardController();
//
// Load settings data
......@@ -83,6 +86,7 @@ Kaidan::~Kaidan()
delete rosterController;
delete presenceController;
delete vCardController;
delete settings;
}
......@@ -110,6 +114,7 @@ void Kaidan::mainConnect()
messageController->setClient(client);
rosterController->setClient(client);
presenceController->setClient(client);
vCardController->setClient(client);
// .. and connect!
client->connect();
......@@ -192,6 +197,7 @@ bool Kaidan::newLoginNeeded() {return (jid == "") || (password == "");}
RosterController* Kaidan::getRosterController() {return rosterController;}
MessageController* Kaidan::getMessageController() {return messageController;}
VCardController* Kaidan::getVCardController() {return vCardController;}
bool Kaidan::getConnectionState() const {return connected;}
QString Kaidan::getVersionString() {return QString(VERSION_STRING);}
......
......@@ -33,6 +33,7 @@
#include "RosterController.h"
#include "MessageController.h"
#include "PresenceController.h"
#include "VCardController.h"
class Kaidan : public QObject
{
......@@ -40,6 +41,7 @@ class Kaidan : public QObject
Q_PROPERTY(RosterController* rosterController READ getRosterController NOTIFY rosterControllerChanged)
Q_PROPERTY(MessageController* messageController READ getMessageController NOTIFY messageControllerChanged)
Q_PROPERTY(VCardController* vCardController READ getVCardController NOTIFY vCardControllerChanged)
Q_PROPERTY(bool connectionState READ getConnectionState NOTIFY connectionStateConnected NOTIFY connectionStateDisconnected)
Q_PROPERTY(QString jid READ getJid WRITE setJid NOTIFY jidChanged)
Q_PROPERTY(QString jidResource READ getJidResource WRITE setJidResource NOTIFY jidResourceChanged)
......@@ -64,6 +66,7 @@ public:
RosterController* getRosterController();
MessageController* getMessageController();
VCardController* getVCardController();
Q_INVOKABLE QString getResourcePath(QString);
Q_INVOKABLE QString getVersionString();
......@@ -71,6 +74,7 @@ public:
signals:
void rosterControllerChanged();
void messageControllerChanged();
void vCardControllerChanged();
void connectionStateConnected();
void connectionStateDisconnected();
void jidChanged();
......@@ -92,6 +96,7 @@ private:
RosterController* rosterController;
MessageController* messageController;
PresenceController* presenceController;
VCardController* vCardController;
QSettings* settings;
......
/*
* Kaidan - Cross platform XMPP client
*
* Copyright (C) 2017 LNJ <git@lnj.li>
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kaidan 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
// VCard
#include "VCard.h"
// Qt 5
#include <QString>
// Boost
#include <boost/shared_ptr.hpp>
// Swiften
#include <Swiften/Swiften.h>
VCard::VCard(QObject *parent) : QObject(parent)
{
vCard = boost::shared_ptr<Swift::VCard>(new Swift::VCard());
emit VCardChanged();
}
VCard::~VCard()
{
}
void VCard::fromSwiftVCard(Swift::VCard::ref vCard_)
{
// only use the new VCard, if it's valid
if (vCard_)
{
vCard = vCard_;
emit VCardChanged();
}
else
{
std::cout << "VCard::fromSwiftVCard - Not Valid / Empty" << '\n';
}
}
void VCard::setVersion(const QString version_)
{
vCard->setVersion(version_.toStdString());
}
const QString VCard::getVersion()
{
return QString::fromStdString(vCard->getVersion());
}
void VCard::setFullName(const QString fullName_)
{
vCard->setFullName(fullName_.toStdString());
}
const QString VCard::getFullName()
{
return QString::fromStdString(vCard->getFullName());
}
void VCard::setFamilyName(const QString familyName_)
{
vCard->setFamilyName(familyName_.toStdString());
}
const QString VCard::getFamilyName()
{
return QString::fromStdString(vCard->getFamilyName());
}
void VCard::setGivenName(const QString givenName_)
{
vCard->setGivenName(givenName_.toStdString());
}
const QString VCard::getGivenName()
{
return QString::fromStdString(vCard->getGivenName());
}
void VCard::setMiddleName(const QString middleName_)
{
vCard->setMiddleName(middleName_.toStdString());
}
const QString VCard::getMiddleName()
{
return QString::fromStdString(vCard->getMiddleName());
}
void VCard::setPrefix(const QString prefix_)
{
vCard->setPrefix(prefix_.toStdString());
}
const QString VCard::getPrefix()
{
return QString::fromStdString(vCard->getPrefix());
}
void VCard::setSuffix(const QString suffix_)
{
vCard->setSuffix(suffix_.toStdString());
}
const QString VCard::getSuffix()
{
return QString::fromStdString(vCard->getSuffix());
}
void VCard::setNickname(const QString nickname_)
{
vCard->setNickname(nickname_.toStdString());
}
const QString VCard::getNickname()
{
return QString::fromStdString(vCard->getNickname());
}
const QString VCard::getPreferredEMailAddress()
{
return QString::fromStdString(vCard->getPreferredEMailAddress().address);
}
/*
* Kaidan - Cross platform XMPP client
*
* Copyright (C) 2017 LNJ <git@lnj.li>
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kaidan 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VCARD_H
#define VCARD_H
// Qt
#include <QObject>
#include <QString>
// Boost
#include <boost/shared_ptr.hpp>
// Swiften
#include <Swiften/Swiften.h>
class VCard : public QObject
{
Q_OBJECT
Q_PROPERTY(const QString version READ getVersion WRITE setVersion NOTIFY VCardChanged)
Q_PROPERTY(const QString fullName READ getFullName WRITE setFullName NOTIFY VCardChanged)
Q_PROPERTY(const QString familyName READ getFamilyName WRITE setFamilyName NOTIFY VCardChanged)
Q_PROPERTY(const QString givenName READ getGivenName WRITE setGivenName NOTIFY VCardChanged)
Q_PROPERTY(const QString middleName READ getGivenName WRITE setGivenName NOTIFY VCardChanged)
Q_PROPERTY(const QString prefix READ getPrefix WRITE setPrefix NOTIFY VCardChanged)
Q_PROPERTY(const QString suffix READ getSuffix WRITE setSuffix NOTIFY VCardChanged)
Q_PROPERTY(const QString nickname READ getNickname WRITE setNickname NOTIFY VCardChanged)
Q_PROPERTY(const QString preferredEMailAddress READ getPreferredEMailAddress NOTIFY VCardChanged)
public:
VCard(QObject *parent = 0);
~VCard();
void fromSwiftVCard(Swift::VCard::ref vCard_);
void setVersion(const QString);
const QString getVersion();
void setFullName(const QString);
const QString getFullName();
void setFamilyName(const QString);
const QString getFamilyName();
void setGivenName(const QString);
const QString getGivenName();
void setMiddleName(const QString);
const QString getMiddleName();
void setPrefix(const QString);
const QString getPrefix();
void setSuffix(const QString);
const QString getSuffix();
void setNickname(const QString);
const QString getNickname();
const QString getPreferredEMailAddress();
signals:
void VCardChanged();
private:
Swift::VCard::ref vCard;
QString version;
QString fullName;
QString familyName;
QString givenName;
QString middleName;
QString prefix;
QString suffix;
QString nickname;
QString preferredEMailAddress;
};
#endif // VCARD_H
/*
* Kaidan - Cross platform XMPP client
*
* Copyright (C) 2017 LNJ <git@lnj.li>
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kaidan 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
// VCardController
#include "VCardController.h"
// C++
#include <string>
// Qt 5
#include <QDebug>
// Swiften
#include <Swiften/Swiften.h>
// Boost
#include <boost/bind.hpp>
// Kaidan
#include "VCard.h"
VCardController::VCardController(QObject *parent) : QObject(parent)
{
currentVCard = new VCard();
ownVCard = new VCard();
}
VCardController::~VCardController()
{
delete currentVCard;
delete ownVCard;
}
void VCardController::setClient(Swift::Client* client_)
{
client = client_;
client->onConnected.connect(boost::bind(&VCardController::requestOwnVCard, this));
client->onConnected.connect(boost::bind(&VCardController::requestCurrentVCard, this));
manager = client->getVCardManager();
manager->onVCardChanged.connect(boost::bind(&VCardController::handleVCardChanged, this, _1, _2));
manager->onOwnVCardChanged.connect(boost::bind(&VCardController::handleOwnVCardChanged, this, _1));
}
void VCardController::setCurrentJid(QString jid_)
{
// set the JID
currentJid = jid_;
// get the new VCard, if client is connected
if (client->isAvailable())
{
currentVCard->fromSwiftVCard(manager->getVCardAndRequestWhenNeeded(
Swift::JID(currentJid.toStdString())
));
emit currentVCardChanged();
}
}
QString VCardController::getCurrentJid()
{
return currentJid;
}
VCard* VCardController::getCurrentVCard()
{
return currentVCard;
}
VCard* VCardController::getOwnVCard()
{
return ownVCard;
}
void VCardController::setOwnVCard(VCard* vCard_)
{
ownVCard = vCard_;
}
void VCardController::requestOwnVCard()
{
manager->requestOwnVCard();
}
void VCardController::requestCurrentVCard()
{
// if a new jid was already set, but the client wasn't connected
if (currentJid != "")
{
currentVCard->fromSwiftVCard(manager->getVCardAndRequestWhenNeeded(
Swift::JID(currentJid.toStdString())
));
emit currentVCardChanged();
}
}
void VCardController::handleVCardChanged(const Swift::JID &jid_, Swift::VCard::ref vCard_)
{
std::cout << "VCardController::handleVCardChanged: Received new VCard from: " << jid_.toString() << '\n';
if (jid_.toString() == currentJid.toStdString())
{
// update the current VCard
currentVCard->fromSwiftVCard(vCard_);
emit currentVCardChanged();
}
}
void VCardController::handleOwnVCardChanged(Swift::VCard::ref vCard_)
{
ownVCard->fromSwiftVCard(vCard_);
emit ownVCardChanged();
}
/*
* Kaidan - Cross platform XMPP client
*
* Copyright (C) 2017 LNJ <git@lnj.li>
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kaidan 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VCARDCONTROLLER_H
#define VCARDCONTROLLER_H
// Qt
#include <QObject>
// Swiften
#include <Swiften/Swiften.h>
// Kaidan
#include "VCard.h"
class VCardController : public QObject
{
Q_OBJECT
Q_PROPERTY(QString currentJid READ getCurrentJid WRITE setCurrentJid)
Q_PROPERTY(VCard* currentVCard READ getCurrentVCard NOTIFY currentVCardChanged)
Q_PROPERTY(VCard* ownVCard READ getOwnVCard WRITE setOwnVCard NOTIFY ownVCardChanged)
public:
VCardController(QObject *parent = 0);
~VCardController();
void setClient(Swift::Client *client_);
QString getCurrentJid();
void setCurrentJid(QString);
VCard* getCurrentVCard();
VCard* getOwnVCard();
void setOwnVCard(VCard*);
signals:
void currentVCardChanged();
void ownVCardChanged();
private:
void handleVCardChanged(const Swift::JID &jid_, Swift::VCard::ref vCard_);
void handleOwnVCardChanged(Swift::VCard::ref vCard_);
void requestCurrentVCard();
void requestOwnVCard();
Swift::Client* client;
Swift::VCardManager* manager;
VCard* currentVCard;
VCard* ownVCard;
QString currentJid;
};
#endif // VCARDCONTROLLER_H
......@@ -37,6 +37,7 @@
#include <Swiften/EventLoop/Qt/QtEventLoop.h>
// Kaidan
#include "Kaidan.h"
#include "VCard.h"
enum CommandLineParseResult
{
......@@ -110,6 +111,9 @@ int main(int argc, char *argv[])
// attributes
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// Kaidan QML types
qmlRegisterType<VCard>(APPLICATION_ID, 1, 0, "VCard");
// Qt-Translator
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
......
......@@ -20,6 +20,7 @@
import QtQuick 2.0
import org.kde.kirigami 2.0 as Kirigami
import io.github.kaidanim 1.0
Kirigami.ScrollablePage {
title: qsTr("Contacts")
......
......@@ -21,6 +21,7 @@
import QtQuick 2.0
import org.kde.kirigami 2.0 as Kirigami
import io.github.kaidanim 1.0
Kirigami.ApplicationWindow {
id: root
......@@ -33,17 +34,17 @@ Kirigami.ApplicationWindow {
globalDrawer: GlobalDrawer {}
// when the window was closed, disconnect from jabber server
onClosing: {
kaidan.mainDisconnect();
}
// load all pages
Component {id: chatPage; ChatPage {}}
Component {id: loginPage; LoginPage {}}
Component {id: rosterPage; RosterPage {}}
Component {id: aboutPage; AboutPage {}}
// when the window was closed, disconnect from jabber server
onClosing: {
kaidan.mainDisconnect();
}
Component.onCompleted: {
function openLoginPage() {
// disconnect this func; the login page will do that now
......
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