squawk/core/account.h

198 lines
7.2 KiB
C
Raw Normal View History

/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-03-29 14:54:34 +00:00
#ifndef CORE_ACCOUNT_H
#define CORE_ACCOUNT_H
#include <QObject>
#include <QCryptographicHash>
#include <QFile>
#include <QMimeDatabase>
#include <QStandardPaths>
#include <QDir>
#include <QTimer>
2019-04-03 21:23:51 +00:00
#include <map>
2019-04-06 10:14:32 +00:00
#include <set>
2019-03-29 14:54:34 +00:00
2019-06-28 15:15:30 +00:00
#include <QXmppRosterManager.h>
#include <QXmppCarbonManager.h>
2019-11-12 13:38:01 +00:00
#include <QXmppDiscoveryManager.h>
2019-06-28 15:15:30 +00:00
#include <QXmppMamManager.h>
#include <QXmppMucManager.h>
2019-06-28 15:15:30 +00:00
#include <QXmppClient.h>
#include <QXmppBookmarkManager.h>
#include <QXmppBookmarkSet.h>
#include <QXmppUploadRequestManager.h>
#include <QXmppVCardIq.h>
#include <QXmppVCardManager.h>
#include <QXmppMessageReceiptManager.h>
#include "shared.h"
#include "contact.h"
2019-08-21 09:35:07 +00:00
#include "conference.h"
#include "networkaccess.h"
2019-03-29 14:54:34 +00:00
2020-04-28 20:35:52 +00:00
#include "handlers/messagehandler.h"
2020-06-14 21:23:43 +00:00
#include "handlers/rosterhandler.h"
2020-04-28 20:35:52 +00:00
2019-03-29 14:54:34 +00:00
namespace Core
{
class Account : public QObject
{
Q_OBJECT
2020-04-28 20:35:52 +00:00
friend class MessageHandler;
2020-06-14 21:23:43 +00:00
friend class RosterHandler;
2019-03-29 14:54:34 +00:00
public:
Account(
const QString& p_login,
const QString& p_server,
const QString& p_password,
const QString& p_name,
NetworkAccess* p_net,
QObject* parent = 0);
2019-03-29 14:54:34 +00:00
~Account();
Shared::ConnectionState getState() const;
QString getName() const;
QString getLogin() const;
QString getServer() const;
QString getPassword() const;
QString getResource() const;
QString getAvatarPath() const;
Shared::Availability getAvailability() const;
Shared::AccountPassword getPasswordType() const;
void setName(const QString& p_name);
void setLogin(const QString& p_login);
void setServer(const QString& p_server);
void setPassword(const QString& p_password);
void setResource(const QString& p_resource);
void setAvailability(Shared::Availability avail);
void setPasswordType(Shared::AccountPassword pt);
2019-04-09 22:01:25 +00:00
QString getFullJid() const;
2020-04-28 20:35:52 +00:00
void sendMessage(const Shared::Message& data);
void sendMessage(const Shared::Message& data, const QString& path);
2019-04-21 19:17:04 +00:00
void requestArchive(const QString& jid, int count, const QString& before);
void subscribeToContact(const QString& jid, const QString& reason);
void unsubscribeFromContact(const QString& jid, const QString& reason);
2019-06-14 16:36:04 +00:00
void removeContactRequest(const QString& jid);
void addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups);
void addContactToGroupRequest(const QString& jid, const QString& groupName);
void removeContactFromGroupRequest(const QString& jid, const QString& groupName);
void renameContactRequest(const QString& jid, const QString& newName);
void setRoomJoined(const QString& jid, bool joined);
void setRoomAutoJoin(const QString& jid, bool joined);
void removeRoomRequest(const QString& jid);
2019-09-04 16:38:52 +00:00
void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin);
void uploadVCard(const Shared::VCard& card);
2019-12-30 20:22:04 +00:00
public slots:
void connect();
void disconnect();
void reconnect();
2019-12-30 20:22:04 +00:00
void requestVCard(const QString& jid);
signals:
void changed(const QMap<QString, QVariant>& data);
void connectionStateChanged(Shared::ConnectionState);
void availabilityChanged(Shared::Availability);
2019-04-03 21:23:51 +00:00
void addGroup(const QString& name);
void removeGroup(const QString& name);
void addRoom(const QString& jid, const QMap<QString, QVariant>& data);
void changeRoom(const QString& jid, const QMap<QString, QVariant>& data);
void removeRoom(const QString& jid);
void addContact(const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
2019-04-06 10:14:32 +00:00
void removeContact(const QString& jid);
void removeContact(const QString& jid, const QString& group);
void changeContact(const QString& jid, const QMap<QString, QVariant>& data);
2019-04-07 14:02:41 +00:00
void addPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
void removePresence(const QString& jid, const QString& name);
void message(const Shared::Message& data);
void changeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
void responseArchive(const QString& jid, const std::list<Shared::Message>& list);
void error(const QString& text);
void addRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
void removeRoomParticipant(const QString& jid, const QString& nickName);
2019-10-19 19:34:25 +00:00
void receivedVCard(const QString& jid, const Shared::VCard& card);
void uploadFile(const QFileInfo& file, const QUrl& set, const QUrl& get, QMap<QString, QString> headers);
void uploadFileError(const QString& messageId, const QString& error);
2019-03-29 14:54:34 +00:00
private:
2019-03-30 20:13:13 +00:00
QString name;
std::map<QString, QString> archiveQueries;
2019-03-29 14:54:34 +00:00
QXmppClient client;
QXmppConfiguration config;
QXmppPresence presence;
Shared::ConnectionState state;
2019-04-12 15:22:10 +00:00
QXmppCarbonManager* cm;
2019-04-13 20:38:20 +00:00
QXmppMamManager* am;
QXmppMucManager* mm;
QXmppBookmarkManager* bm;
QXmppRosterManager* rm;
QXmppVCardManager* vm;
QXmppUploadRequestManager* um;
2019-11-12 13:38:01 +00:00
QXmppDiscoveryManager* dm;
QXmppMessageReceiptManager* rcpm;
bool reconnectScheduled;
QTimer* reconnectTimer;
std::set<QString> pendingVCardRequests;
QString avatarHash;
QString avatarType;
bool ownVCardRequestInProgress;
NetworkAccess* network;
Shared::AccountPassword passwordType;
2020-04-28 20:35:52 +00:00
MessageHandler* mh;
2020-06-14 21:23:43 +00:00
RosterHandler* rh;
2020-04-28 20:35:52 +00:00
private slots:
void onClientStateChange(QXmppClient::State state);
void onClientError(QXmppClient::Error err);
2019-04-19 09:12:12 +00:00
2019-04-07 14:02:41 +00:00
void onPresenceReceived(const QXmppPresence& presence);
2020-06-14 21:23:43 +00:00
void onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at);
2019-04-13 20:38:20 +00:00
void onMamMessageReceived(const QString& bareJid, const QXmppMessage& message);
void onMamResultsReceived(const QString &queryId, const QXmppResultSetReply &resultSetReply, bool complete);
2020-06-14 21:23:43 +00:00
2019-06-28 15:15:30 +00:00
void onMamLog(QXmppLogger::MessageType type, const QString &msg);
void onVCardReceived(const QXmppVCardIq& card);
void onOwnVCardReceived(const QXmppVCardIq& card);
2020-04-28 20:35:52 +00:00
2019-11-12 13:38:01 +00:00
void onDiscoveryItemsReceived (const QXmppDiscoveryIq& items);
void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info);
2019-04-06 10:14:32 +00:00
private:
2020-08-07 23:33:03 +00:00
void handleDisconnection();
void onReconnectTimer();
2019-03-29 14:54:34 +00:00
};
2019-11-05 18:55:21 +00:00
void initializeVCard(Shared::VCard& vCard, const QXmppVCardIq& card);
void initializeQXmppVCard(QXmppVCardIq& card, const Shared::VCard& vCard);
2019-03-29 14:54:34 +00:00
}
2019-03-29 14:54:34 +00:00
#endif // CORE_ACCOUNT_H