2014-06-25 04:11:11 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project Contributors
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-06-25 04:11:11 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-25 04:11:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CORE_HPP
|
|
|
|
#define CORE_HPP
|
|
|
|
|
2014-06-26 04:43:28 +08:00
|
|
|
#include <cstdint>
|
2014-06-25 04:11:11 +08:00
|
|
|
#include <QObject>
|
2014-10-29 23:40:09 +08:00
|
|
|
#include <QMutex>
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-11-11 23:05:01 +08:00
|
|
|
#include <tox/tox.h>
|
2015-04-20 05:12:44 +08:00
|
|
|
#include <tox/toxencryptsave.h>
|
2014-11-11 23:05:01 +08:00
|
|
|
|
2014-09-11 21:44:34 +08:00
|
|
|
#include "corestructs.h"
|
|
|
|
#include "coredefines.h"
|
2015-05-18 04:55:50 +08:00
|
|
|
#include "toxid.h"
|
2014-06-26 04:43:28 +08:00
|
|
|
|
2015-06-04 07:30:17 +08:00
|
|
|
class Profile;
|
2014-09-11 21:44:34 +08:00
|
|
|
template <typename T> class QList;
|
|
|
|
class QTimer;
|
|
|
|
class QString;
|
2014-09-21 18:30:10 +08:00
|
|
|
class CString;
|
2015-06-26 19:00:16 +08:00
|
|
|
struct ToxAV;
|
|
|
|
class CoreAV;
|
|
|
|
struct vpx_image;
|
2014-06-27 21:16:39 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
class Core : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-06-04 07:30:17 +08:00
|
|
|
explicit Core(QThread* coreThread, Profile& profile);
|
2016-07-27 06:21:22 +08:00
|
|
|
static Core* getInstance();
|
2016-11-09 14:20:47 +08:00
|
|
|
const CoreAV* getAv() const;
|
2015-09-28 01:59:26 +08:00
|
|
|
CoreAV* getAv();
|
2014-06-25 04:11:11 +08:00
|
|
|
~Core();
|
2015-01-28 04:16:28 +08:00
|
|
|
|
2014-07-17 06:43:30 +08:00
|
|
|
static const QString TOX_EXT;
|
2014-10-09 13:30:33 +08:00
|
|
|
static const QString CONFIG_FILE_NAME;
|
2014-10-09 16:07:26 +08:00
|
|
|
static QString sanitize(QString name);
|
2014-12-29 01:26:35 +08:00
|
|
|
static QList<CString> splitMessage(const QString &message, int maxLen);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-11-04 00:44:01 +08:00
|
|
|
static QByteArray getSaltFromFile(QString filename);
|
|
|
|
|
2015-05-18 04:55:50 +08:00
|
|
|
QString getPeerName(const ToxId& id) const;
|
2014-11-03 01:36:27 +08:00
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
QVector<uint32_t> getFriendList() const;
|
2016-09-25 04:03:26 +08:00
|
|
|
uint32_t getGroupNumberPeers(int groupId) const;
|
2016-07-27 06:21:22 +08:00
|
|
|
QString getGroupPeerName(int groupId, int peerId) const;
|
|
|
|
ToxId getGroupPeerToxId(int groupId, int peerId) const;
|
|
|
|
QList<QString> getGroupPeerNames(int groupId) const;
|
|
|
|
QString getFriendAddress(uint32_t friendNumber) const;
|
|
|
|
QString getFriendPublicKey(uint32_t friendNumber) const;
|
|
|
|
QString getFriendUsername(uint32_t friendNumber) const;
|
|
|
|
|
|
|
|
bool isFriendOnline(uint32_t friendId) const;
|
|
|
|
bool hasFriendWithAddress(const QString &addr) const;
|
|
|
|
bool hasFriendWithPublicKey(const QString &pubkey) const;
|
2016-09-25 04:03:26 +08:00
|
|
|
uint32_t joinGroupchat(int32_t friendId, uint8_t type, const uint8_t* pubkey,uint16_t length) const;
|
2016-07-27 06:21:22 +08:00
|
|
|
void quitGroupChat(int groupId) const;
|
|
|
|
|
|
|
|
QString getUsername() const;
|
|
|
|
Status getStatus() const;
|
|
|
|
QString getStatusMessage() const;
|
|
|
|
ToxId getSelfId() const;
|
|
|
|
QPair<QByteArray, QByteArray> getKeypair() const;
|
2014-07-04 01:38:30 +08:00
|
|
|
|
2016-12-14 07:00:17 +08:00
|
|
|
static std::shared_ptr<Tox_Pass_Key> createPasskey(const QString &password, uint8_t* salt = nullptr);
|
|
|
|
static QByteArray encryptData(const QByteArray& data, const Tox_Pass_Key& encryptionKey);
|
2016-07-27 06:21:22 +08:00
|
|
|
static QByteArray encryptData(const QByteArray& data);
|
2016-12-14 07:00:17 +08:00
|
|
|
static QByteArray decryptData(const QByteArray& data, const Tox_Pass_Key &encryptionKey);
|
2016-07-27 06:21:22 +08:00
|
|
|
static QByteArray decryptData(const QByteArray& data);
|
2015-06-28 03:14:35 +08:00
|
|
|
|
2016-11-09 05:21:08 +08:00
|
|
|
bool isReady() const;
|
2014-10-15 09:04:53 +08:00
|
|
|
|
2016-11-09 14:20:47 +08:00
|
|
|
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
public slots:
|
2016-07-27 06:21:22 +08:00
|
|
|
void start();
|
|
|
|
void reset();
|
|
|
|
void process();
|
|
|
|
void bootstrapDht();
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
QByteArray getToxSaveData();
|
2015-01-24 22:31:11 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
void acceptFriendRequest(const QString& userId);
|
|
|
|
void requestFriendship(const QString& friendAddress, const QString& message);
|
2015-04-20 05:12:44 +08:00
|
|
|
void groupInviteFriend(uint32_t friendId, int groupId);
|
2016-09-22 14:48:01 +08:00
|
|
|
int createGroup(uint8_t type = TOX_CONFERENCE_TYPE_AV);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void removeFriend(uint32_t friendId, bool fake = false);
|
2014-11-12 07:00:24 +08:00
|
|
|
void removeGroup(int groupId, bool fake = false);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-07-01 06:36:48 +08:00
|
|
|
void setStatus(Status status);
|
2014-06-27 08:08:33 +08:00
|
|
|
void setUsername(const QString& username);
|
|
|
|
void setStatusMessage(const QString& message);
|
2015-04-20 05:12:44 +08:00
|
|
|
void setAvatar(const QByteArray& data);
|
2014-06-27 08:08:33 +08:00
|
|
|
|
2016-09-25 04:06:28 +08:00
|
|
|
int sendMessage(uint32_t friendId, const QString& message);
|
2014-06-26 04:43:28 +08:00
|
|
|
void sendGroupMessage(int groupId, const QString& message);
|
2014-11-01 21:00:43 +08:00
|
|
|
void sendGroupAction(int groupId, const QString& message);
|
2014-11-06 08:22:50 +08:00
|
|
|
void changeGroupTitle(int groupId, const QString& title);
|
2016-09-25 04:06:28 +08:00
|
|
|
int sendAction(uint32_t friendId, const QString& action);
|
2015-04-20 05:12:44 +08:00
|
|
|
void sendTyping(uint32_t friendId, bool typing);
|
2014-06-26 04:43:28 +08:00
|
|
|
|
2015-04-25 22:51:58 +08:00
|
|
|
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
2015-04-20 05:12:44 +08:00
|
|
|
void cancelFileSend(uint32_t friendId, uint32_t fileNum);
|
|
|
|
void cancelFileRecv(uint32_t friendId, uint32_t fileNum);
|
|
|
|
void rejectFileRecvRequest(uint32_t friendId, uint32_t fileNum);
|
|
|
|
void acceptFileRecvRequest(uint32_t friendId, uint32_t fileNum, QString path);
|
|
|
|
void pauseResumeFileSend(uint32_t friendId, uint32_t fileNum);
|
|
|
|
void pauseResumeFileRecv(uint32_t friendId, uint32_t fileNum);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-11-16 00:10:04 +08:00
|
|
|
void setNospam(uint32_t nospam);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
signals:
|
|
|
|
void connected();
|
|
|
|
void disconnected();
|
|
|
|
|
|
|
|
void friendRequestReceived(const QString& userId, const QString& message);
|
2015-04-20 05:12:44 +08:00
|
|
|
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void friendAdded(uint32_t friendId, const QString& userId);
|
2015-06-15 21:48:34 +08:00
|
|
|
void friendshipChanged(uint32_t friendId);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void friendStatusChanged(uint32_t friendId, Status status);
|
|
|
|
void friendStatusMessageChanged(uint32_t friendId, const QString& message);
|
|
|
|
void friendUsernameChanged(uint32_t friendId, const QString& username);
|
|
|
|
void friendTypingChanged(uint32_t friendId, bool isTyping);
|
|
|
|
void friendAvatarChanged(uint32_t friendId, const QPixmap& pic);
|
|
|
|
void friendAvatarRemoved(uint32_t friendId);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void friendRemoved(uint32_t friendId);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void friendLastSeenChanged(uint32_t friendId, const QDateTime& dateTime);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-06-30 05:38:48 +08:00
|
|
|
void emptyGroupCreated(int groupnumber);
|
2015-04-25 22:51:58 +08:00
|
|
|
void groupInviteReceived(uint32_t friendId, uint8_t type, QByteArray publicKey);
|
2014-11-23 23:55:49 +08:00
|
|
|
void groupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);
|
2014-06-25 04:11:11 +08:00
|
|
|
void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
2014-11-06 08:22:50 +08:00
|
|
|
void groupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
2015-03-13 14:00:12 +08:00
|
|
|
void groupPeerAudioPlaying(int groupnumber, int peernumber);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
void usernameSet(const QString& username);
|
|
|
|
void statusMessageSet(const QString& message);
|
|
|
|
void statusSet(Status status);
|
2014-10-18 09:15:26 +08:00
|
|
|
void idSet(const QString& id);
|
2014-09-24 22:51:16 +08:00
|
|
|
void selfAvatarChanged(const QPixmap& pic);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void messageSentResult(uint32_t friendId, const QString& message, int messageId);
|
2014-09-24 00:35:06 +08:00
|
|
|
void groupSentResult(int groupId, const QString& message, int result);
|
2015-04-20 05:12:44 +08:00
|
|
|
void actionSentResult(uint32_t friendId, const QString& action, int success);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-11-01 22:19:11 +08:00
|
|
|
void receiptRecieved(int friedId, int receipt);
|
|
|
|
|
2014-11-10 03:23:43 +08:00
|
|
|
void failedToAddFriend(const QString& userId, const QString& errorInfo = QString());
|
2015-04-20 05:12:44 +08:00
|
|
|
void failedToRemoveFriend(uint32_t friendId);
|
2014-06-25 04:11:11 +08:00
|
|
|
void failedToSetUsername(const QString& username);
|
|
|
|
void failedToSetStatusMessage(const QString& message);
|
|
|
|
void failedToSetStatus(Status status);
|
|
|
|
void failedToSetTyping(bool typing);
|
|
|
|
|
|
|
|
void failedToStart();
|
2014-10-06 04:49:44 +08:00
|
|
|
void badProxy();
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-06-27 01:45:47 +08:00
|
|
|
void fileSendStarted(ToxFile file);
|
|
|
|
void fileReceiveRequested(ToxFile file);
|
|
|
|
void fileTransferAccepted(ToxFile file);
|
2014-11-17 23:05:14 +08:00
|
|
|
void fileTransferCancelled(ToxFile file);
|
2014-06-27 01:45:47 +08:00
|
|
|
void fileTransferFinished(ToxFile file);
|
2014-07-12 00:05:18 +08:00
|
|
|
void fileUploadFinished(const QString& path);
|
|
|
|
void fileDownloadFinished(const QString& path);
|
2014-11-17 23:05:14 +08:00
|
|
|
void fileTransferPaused(ToxFile file);
|
|
|
|
void fileTransferInfo(ToxFile file);
|
2014-09-11 21:36:57 +08:00
|
|
|
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
|
2014-09-30 00:14:19 +08:00
|
|
|
void fileTransferBrokenUnbroken(ToxFile file, bool broken);
|
2014-06-27 08:08:33 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void fileSendFailed(uint32_t friendId, const QString& fname);
|
|
|
|
|
2014-06-27 06:42:45 +08:00
|
|
|
private:
|
2016-09-23 03:05:42 +08:00
|
|
|
static void onFriendRequest(Tox* tox, const uint8_t* cUserId,
|
|
|
|
const uint8_t* cMessage, size_t cMessageSize,
|
|
|
|
void* core);
|
|
|
|
static void onFriendMessage(Tox* tox, uint32_t friendId,
|
|
|
|
TOX_MESSAGE_TYPE type, const uint8_t* cMessage,
|
2015-04-24 08:32:09 +08:00
|
|
|
size_t cMessageSize, void* core);
|
2016-09-23 03:05:42 +08:00
|
|
|
static void onFriendNameChange(Tox* tox, uint32_t friendId,
|
|
|
|
const uint8_t* cName, size_t cNameSize,
|
|
|
|
void* core);
|
|
|
|
static void onFriendTypingChange(Tox* tox, uint32_t friendId, bool isTyping,
|
|
|
|
void* core);
|
|
|
|
static void onStatusMessageChanged(Tox* tox, uint32_t friendId,
|
|
|
|
const uint8_t* cMessage,
|
2015-04-24 08:32:09 +08:00
|
|
|
size_t cMessageSize, void* core);
|
2016-09-23 03:05:42 +08:00
|
|
|
static void onUserStatusChanged(Tox* tox, uint32_t friendId,
|
|
|
|
TOX_USER_STATUS userstatus, void* core);
|
|
|
|
static void onConnectionStatusChanged(Tox* tox, uint32_t friendId,
|
|
|
|
TOX_CONNECTION status, void* core);
|
|
|
|
static void onGroupInvite(Tox* tox, uint32_t friendId, TOX_CONFERENCE_TYPE type,
|
|
|
|
const uint8_t* data, size_t length, void* core);
|
|
|
|
static void onGroupMessage(Tox* tox, uint32_t groupId, uint32_t peerId,
|
|
|
|
TOX_MESSAGE_TYPE type, const uint8_t* message,
|
|
|
|
size_t length, void* core);
|
|
|
|
static void onGroupNamelistChange(Tox* tox, uint32_t groupId, uint32_t peerId,
|
|
|
|
TOX_CONFERENCE_STATE_CHANGE change, void* core);
|
|
|
|
static void onGroupTitleChange(Tox* tox, uint32_t groupId, uint32_t peerId,
|
|
|
|
const uint8_t* title, size_t length, void* core);
|
|
|
|
static void onReadReceiptCallback(Tox* tox, uint32_t friendId,
|
|
|
|
uint32_t receipt, void *core);
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2016-09-25 04:06:28 +08:00
|
|
|
void sendGroupMessageWithType(int groupId, const QString& message, TOX_MESSAGE_TYPE type);
|
2016-09-25 04:03:26 +08:00
|
|
|
bool parsePeerQueryError(TOX_ERR_CONFERENCE_PEER_QUERY error) const;
|
|
|
|
bool parseConferenceJoinError(TOX_ERR_CONFERENCE_JOIN error) const;
|
2014-09-29 07:08:07 +08:00
|
|
|
bool checkConnection();
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2014-11-18 14:34:31 +08:00
|
|
|
void checkEncryptedHistory();
|
2015-06-04 08:43:07 +08:00
|
|
|
void makeTox(QByteArray savedata);
|
2014-06-27 06:42:45 +08:00
|
|
|
void loadFriends();
|
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void checkLastOnline(uint32_t friendId);
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2015-10-24 02:05:35 +08:00
|
|
|
void deadifyTox();
|
|
|
|
|
2015-06-04 18:14:17 +08:00
|
|
|
private slots:
|
2016-07-27 06:21:22 +08:00
|
|
|
void killTimers(bool onlyStop);
|
2015-06-04 18:14:17 +08:00
|
|
|
|
2014-06-27 06:42:45 +08:00
|
|
|
private:
|
|
|
|
Tox* tox;
|
2015-06-26 19:00:16 +08:00
|
|
|
CoreAV* av;
|
2015-06-04 18:14:17 +08:00
|
|
|
QTimer *toxTimer;
|
2015-06-04 07:30:17 +08:00
|
|
|
Profile& profile;
|
2015-04-24 21:31:30 +08:00
|
|
|
QMutex messageSendMutex;
|
2014-11-06 22:12:10 +08:00
|
|
|
bool ready;
|
2014-10-22 21:36:36 +08:00
|
|
|
|
2014-11-20 05:26:04 +08:00
|
|
|
static QThread *coreThread;
|
|
|
|
|
|
|
|
friend class Audio; ///< Audio can access our calls directly to reduce latency
|
2015-04-24 21:31:30 +08:00
|
|
|
friend class CoreFile; ///< CoreFile can access tox* and emit our signals
|
2015-06-26 19:00:16 +08:00
|
|
|
friend class CoreAV; ///< CoreAV accesses our toxav* for now
|
2014-06-25 04:11:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CORE_HPP
|
|
|
|
|