2019-08-14 14:54:46 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2019-10-16 19:38:35 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QDir>
|
|
|
|
|
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>
|
|
|
|
#include <QXmppMamManager.h>
|
2019-07-11 08:51:52 +00:00
|
|
|
#include <QXmppMucManager.h>
|
2019-06-28 15:15:30 +00:00
|
|
|
#include <QXmppClient.h>
|
2019-07-11 08:51:52 +00:00
|
|
|
#include <QXmppBookmarkManager.h>
|
|
|
|
#include <QXmppBookmarkSet.h>
|
2019-10-15 19:25:40 +00:00
|
|
|
#include <QXmppVCardIq.h>
|
|
|
|
#include <QXmppVCardManager.h>
|
2019-03-31 21:05:09 +00:00
|
|
|
#include "../global.h"
|
2019-04-17 20:08:56 +00:00
|
|
|
#include "contact.h"
|
2019-08-21 09:35:07 +00:00
|
|
|
#include "conference.h"
|
2019-03-29 14:54:34 +00:00
|
|
|
|
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
|
|
|
|
class Account : public QObject
|
|
|
|
{
|
2019-03-31 21:05:09 +00:00
|
|
|
Q_OBJECT
|
2019-03-29 14:54:34 +00:00
|
|
|
public:
|
2019-03-30 20:13:13 +00:00
|
|
|
Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, QObject* parent = 0);
|
2019-03-29 14:54:34 +00:00
|
|
|
~Account();
|
|
|
|
|
2019-03-31 21:05:09 +00:00
|
|
|
void connect();
|
|
|
|
void disconnect();
|
2019-05-24 14:46:34 +00:00
|
|
|
void reconnect();
|
2019-03-31 21:05:09 +00:00
|
|
|
|
|
|
|
Shared::ConnectionState getState() const;
|
|
|
|
QString getName() const;
|
2019-04-02 21:58:43 +00:00
|
|
|
QString getLogin() const;
|
|
|
|
QString getServer() const;
|
|
|
|
QString getPassword() const;
|
2019-04-07 20:14:15 +00:00
|
|
|
QString getResource() const;
|
2019-10-16 19:38:35 +00:00
|
|
|
QString getAvatarPath() const;
|
2019-04-07 20:14:15 +00:00
|
|
|
Shared::Availability getAvailability() 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);
|
2019-04-09 22:01:25 +00:00
|
|
|
QString getFullJid() const;
|
2019-04-11 14:58:59 +00:00
|
|
|
void sendMessage(const Shared::Message& data);
|
2019-04-21 19:17:04 +00:00
|
|
|
void requestArchive(const QString& jid, int count, const QString& before);
|
2019-05-24 14:46:34 +00:00
|
|
|
void setReconnectTimes(unsigned int times);
|
2019-06-12 17:18:18 +00:00
|
|
|
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);
|
2019-09-28 14:30:16 +00:00
|
|
|
void addContactToGroupRequest(const QString& jid, const QString& groupName);
|
|
|
|
void removeContactFromGroupRequest(const QString& jid, const QString& groupName);
|
2019-10-01 08:47:40 +00:00
|
|
|
void renameContactRequest(const QString& jid, const QString& newName);
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2019-08-29 14:19:35 +00:00
|
|
|
void setRoomJoined(const QString& jid, bool joined);
|
|
|
|
void setRoomAutoJoin(const QString& jid, bool joined);
|
2019-09-03 20:28:58 +00:00
|
|
|
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);
|
2019-10-19 19:34:25 +00:00
|
|
|
void requestVCard(const QString& jid);
|
2019-08-29 14:19:35 +00:00
|
|
|
|
2019-03-31 21:05:09 +00:00
|
|
|
signals:
|
2019-10-16 19:38:35 +00:00
|
|
|
void changed(const QMap<QString, QVariant>& data);
|
2019-03-31 21:05:09 +00:00
|
|
|
void connectionStateChanged(int);
|
2019-04-07 20:14:15 +00:00
|
|
|
void availabilityChanged(int);
|
2019-04-03 21:23:51 +00:00
|
|
|
void addGroup(const QString& name);
|
|
|
|
void removeGroup(const QString& name);
|
2019-07-11 08:51:52 +00:00
|
|
|
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);
|
2019-04-07 20:14:15 +00:00
|
|
|
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);
|
2019-04-07 20:14:15 +00:00
|
|
|
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);
|
2019-04-11 14:58:59 +00:00
|
|
|
void message(const Shared::Message& data);
|
2019-05-15 17:36:37 +00:00
|
|
|
void responseArchive(const QString& jid, const std::list<Shared::Message>& list);
|
2019-05-24 14:46:34 +00:00
|
|
|
void error(const QString& text);
|
2019-09-01 19:46:12 +00:00
|
|
|
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);
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
private:
|
2019-03-30 20:13:13 +00:00
|
|
|
QString name;
|
2019-04-13 20:38:20 +00:00
|
|
|
std::map<QString, QString> achiveQueries;
|
2019-03-29 14:54:34 +00:00
|
|
|
QXmppClient client;
|
2019-04-07 20:14:15 +00:00
|
|
|
QXmppConfiguration config;
|
|
|
|
QXmppPresence presence;
|
2019-03-31 21:05:09 +00:00
|
|
|
Shared::ConnectionState state;
|
2019-04-06 10:14:32 +00:00
|
|
|
std::map<QString, std::set<QString>> groups;
|
2019-04-12 15:22:10 +00:00
|
|
|
QXmppCarbonManager* cm;
|
2019-04-13 20:38:20 +00:00
|
|
|
QXmppMamManager* am;
|
2019-07-11 08:51:52 +00:00
|
|
|
QXmppMucManager* mm;
|
|
|
|
QXmppBookmarkManager* bm;
|
2019-05-24 14:46:34 +00:00
|
|
|
std::map<QString, Contact*> contacts;
|
2019-08-21 09:35:07 +00:00
|
|
|
std::map<QString, Conference*> conferences;
|
2019-05-24 14:46:34 +00:00
|
|
|
unsigned int maxReconnectTimes;
|
|
|
|
unsigned int reconnectTimes;
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2019-06-18 15:08:03 +00:00
|
|
|
std::map<QString, QString> queuedContacts;
|
|
|
|
std::set<QString> outOfRosterContacts;
|
2019-10-15 19:25:40 +00:00
|
|
|
std::set<QString> pendingVCardRequests;
|
2019-06-18 15:08:03 +00:00
|
|
|
|
2019-10-16 19:38:35 +00:00
|
|
|
QString avatarHash;
|
|
|
|
QString avatarType;
|
|
|
|
bool ownVCardRequestInProgress;
|
|
|
|
|
2019-03-31 21:05:09 +00:00
|
|
|
private slots:
|
|
|
|
void onClientConnected();
|
2019-04-02 15:46:18 +00:00
|
|
|
void onClientDisconnected();
|
2019-05-15 17:36:37 +00:00
|
|
|
void onClientError(QXmppClient::Error err);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2019-04-03 21:23:51 +00:00
|
|
|
void onRosterReceived();
|
2019-04-07 14:02:41 +00:00
|
|
|
void onRosterItemAdded(const QString& bareJid);
|
|
|
|
void onRosterItemChanged(const QString& bareJid);
|
|
|
|
void onRosterItemRemoved(const QString& bareJid);
|
|
|
|
void onRosterPresenceChanged(const QString& bareJid, const QString& resource);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2019-04-07 14:02:41 +00:00
|
|
|
void onPresenceReceived(const QXmppPresence& presence);
|
2019-04-09 15:04:08 +00:00
|
|
|
void onMessageReceived(const QXmppMessage& message);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2019-04-12 15:22:10 +00:00
|
|
|
void onCarbonMessageReceived(const QXmppMessage& message);
|
|
|
|
void onCarbonMessageSent(const QXmppMessage& message);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
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);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2019-07-11 08:51:52 +00:00
|
|
|
void onMucRoomAdded(QXmppMucRoom* room);
|
2019-08-21 09:35:07 +00:00
|
|
|
void onMucJoinedChanged(bool joined);
|
|
|
|
void onMucAutoJoinChanged(bool autoJoin);
|
2019-07-11 08:51:52 +00:00
|
|
|
void onMucNickNameChanged(const QString& nickName);
|
2019-09-03 20:28:58 +00:00
|
|
|
void onMucSubjectChanged(const QString& subject);
|
2019-09-01 19:46:12 +00:00
|
|
|
void onMucAddParticipant(const QString& nickName, const QMap<QString, QVariant>& data);
|
|
|
|
void onMucChangeParticipant(const QString& nickName, const QMap<QString, QVariant>& data);
|
|
|
|
void onMucRemoveParticipant(const QString& nickName);
|
2019-07-11 08:51:52 +00:00
|
|
|
|
|
|
|
void bookmarksReceived(const QXmppBookmarkSet& bookmarks);
|
|
|
|
|
2019-04-19 09:12:12 +00:00
|
|
|
void onContactGroupAdded(const QString& group);
|
|
|
|
void onContactGroupRemoved(const QString& group);
|
|
|
|
void onContactNameChanged(const QString& name);
|
|
|
|
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
2019-05-15 17:36:37 +00:00
|
|
|
void onContactHistoryResponse(const std::list<Shared::Message>& list);
|
2019-07-01 06:31:38 +00:00
|
|
|
void onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at);
|
2019-10-15 19:25:40 +00:00
|
|
|
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
2019-06-28 15:15:30 +00:00
|
|
|
|
|
|
|
void onMamLog(QXmppLogger::MessageType type, const QString &msg);
|
2019-10-15 19:25:40 +00:00
|
|
|
|
|
|
|
void onVCardReceived(const QXmppVCardIq& card);
|
2019-10-16 19:38:35 +00:00
|
|
|
void onOwnVCardReceived(const QXmppVCardIq& card);
|
2019-04-06 10:14:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void addedAccount(const QString &bareJid);
|
2019-06-15 15:29:15 +00:00
|
|
|
void handleNewContact(Contact* contact);
|
2019-08-21 09:35:07 +00:00
|
|
|
void handleNewRosterItem(RosterItem* contact);
|
|
|
|
void handleNewConference(Conference* contact);
|
2019-04-13 20:38:20 +00:00
|
|
|
bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
|
2019-08-28 11:40:55 +00:00
|
|
|
bool handleGroupMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
|
2019-09-04 16:38:52 +00:00
|
|
|
void addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin);
|
2019-04-19 09:12:12 +00:00
|
|
|
void addToGroup(const QString& jid, const QString& group);
|
|
|
|
void removeFromGroup(const QString& jid, const QString& group);
|
2019-05-15 17:36:37 +00:00
|
|
|
void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const;
|
2019-04-19 09:12:12 +00:00
|
|
|
Shared::SubscriptionState castSubscriptionState(QXmppRosterIq::Item::SubscriptionType qs) const;
|
2019-06-28 15:15:30 +00:00
|
|
|
void logMessage(const QXmppMessage& msg, const QString& reason = "Message wasn't handled: ");
|
2019-09-03 20:28:58 +00:00
|
|
|
void storeConferences();
|
|
|
|
void clearConferences();
|
2019-07-11 08:51:52 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-11 08:51:52 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
#endif // CORE_ACCOUNT_H
|