1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/core.h

250 lines
10 KiB
C
Raw Normal View History

2014-06-25 04:11:11 +08:00
/*
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
This file is part of Tox Qt GUI.
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 COPYING file for more details.
*/
#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-09-11 21:44:34 +08:00
#include "corestructs.h"
#include "coreav.h"
#include "coredefines.h"
2014-06-26 04:43:28 +08:00
2014-09-11 21:44:34 +08:00
template <typename T> class QList;
class Camera;
class QTimer;
class QString;
2014-06-25 04:11:11 +08:00
class Core : public QObject
{
Q_OBJECT
public:
explicit Core(Camera* cam, QThread* coreThread);
2014-09-11 21:44:34 +08:00
static Core* getInstance(); ///< Returns the global widget's Core instance
2014-06-25 04:11:11 +08:00
~Core();
static const QString TOX_EXT;
2014-06-25 04:11:11 +08:00
int getGroupNumberPeers(int groupId) const;
QString getGroupPeerName(int groupId, int peerId) const;
QList<QString> getGroupPeerNames(int groupId) const;
2014-09-01 04:26:45 +08:00
QString getFriendAddress(int friendNumber) const;
2014-07-03 15:22:12 +08:00
int joinGroupchat(int32_t friendnumber, const uint8_t* friend_group_public_key) const;
2014-06-25 04:11:11 +08:00
void quitGroupChat(int groupId) const;
2014-06-30 05:38:48 +08:00
void dispatchVideoFrame(vpx_image img) const;
2014-06-25 04:11:11 +08:00
void saveConfiguration();
void saveConfiguration(const QString& path);
void switchConfiguration(QString profile);
QString getIDString();
QString getUsername();
QString getStatusMessage();
2014-09-11 19:40:27 +08:00
QString getSelfId();
2014-07-04 01:38:30 +08:00
void increaseVideoBusyness();
void decreaseVideoBusyness();
2014-06-25 04:11:11 +08:00
public slots:
void start();
void process();
void bootstrapDht(bool reset = false);
2014-06-25 04:11:11 +08:00
void acceptFriendRequest(const QString& userId);
void requestFriendship(const QString& friendAddress, const QString& message);
void groupInviteFriend(int friendId, int groupId);
2014-06-30 05:38:48 +08:00
void createGroup();
2014-06-25 04:11:11 +08:00
void removeFriend(int friendId);
void removeGroup(int groupId);
2014-07-01 06:36:48 +08:00
void setStatus(Status status);
void setUsername(const QString& username);
void setStatusMessage(const QString& message);
2014-06-25 04:11:11 +08:00
void sendMessage(int friendId, const QString& message);
2014-06-26 04:43:28 +08:00
void sendGroupMessage(int groupId, const QString& message);
2014-06-25 04:11:11 +08:00
void sendAction(int friendId, const QString& action);
void sendTyping(int friendId, bool typing);
2014-06-26 04:43:28 +08:00
2014-07-01 19:33:59 +08:00
void sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize);
void cancelFileSend(int friendId, int fileNum);
void cancelFileRecv(int friendId, int fileNum);
void rejectFileRecvRequest(int friendId, int fileNum);
void acceptFileRecvRequest(int friendId, int fileNum, QString path);
void pauseResumeFileSend(int friendId, int fileNum);
void pauseResumeFileRecv(int friendId, int fileNum);
2014-06-25 04:11:11 +08:00
void answerCall(int callId);
void hangupCall(int callId);
2014-06-30 05:38:48 +08:00
void startCall(int friendId, bool video=false);
2014-06-27 09:06:56 +08:00
void cancelCall(int callId, int friendId);
2014-06-25 04:11:11 +08:00
2014-08-19 23:20:20 +08:00
void micMuteToggle(int callId);
2014-06-25 04:11:11 +08:00
signals:
void connected();
void disconnected();
void friendRequestReceived(const QString& userId, const QString& message);
void friendMessageReceived(int friendId, const QString& message);
void friendAdded(int friendId, const QString& userId);
void clearFriends();
2014-06-25 04:11:11 +08:00
void friendStatusChanged(int friendId, Status status);
void friendStatusMessageChanged(int friendId, const QString& message);
void friendUsernameChanged(int friendId, const QString& username);
void friendTypingChanged(int friendId, bool isTyping);
void friendStatusMessageLoaded(int friendId, const QString& message);
void friendUsernameLoaded(int friendId, const QString& username);
void friendAddressGenerated(const QString& friendAddress);
void friendRemoved(int friendId);
void friendLastSeenChanged(int friendId, const QDateTime& dateTime);
2014-06-30 05:38:48 +08:00
void emptyGroupCreated(int groupnumber);
2014-07-03 15:22:12 +08:00
void groupInviteReceived(int friendnumber, const uint8_t *group_public_key);
2014-06-25 04:11:11 +08:00
void groupMessageReceived(int groupnumber, int friendgroupnumber, const QString& message);
void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
void usernameSet(const QString& username);
void statusMessageSet(const QString& message);
void statusSet(Status status);
void messageSentResult(int friendId, const QString& message, int messageId);
void actionSentResult(int friendId, const QString& action, int success);
void failedToAddFriend(const QString& userId);
void failedToRemoveFriend(int friendId);
void failedToSetUsername(const QString& username);
void failedToSetStatusMessage(const QString& message);
void failedToSetStatus(Status status);
void failedToSetTyping(bool typing);
void actionReceived(int friendId, const QString& acionMessage);
void failedToStart();
void fileSendStarted(ToxFile file);
void fileReceiveRequested(ToxFile file);
void fileTransferAccepted(ToxFile file);
void fileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection direction);
void fileTransferFinished(ToxFile file);
void fileUploadFinished(const QString& path);
void fileDownloadFinished(const QString& path);
void fileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection direction);
2014-07-13 00:40:01 +08:00
void fileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction);
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
void avInvite(int friendId, int callIndex, bool video);
void avStart(int friendId, int callIndex, bool video);
void avCancel(int friendId, int callIndex);
void avEnd(int friendId, int callIndex);
void avRinging(int friendId, int callIndex, bool video);
void avStarting(int friendId, int callIndex, bool video);
void avEnding(int friendId, int callIndex);
2014-06-27 09:06:56 +08:00
void avRequestTimeout(int friendId, int callIndex);
2014-06-28 03:59:25 +08:00
void avPeerTimeout(int friendId, int callIndex);
void avMediaChange(int friendId, int callIndex, bool videoEnabled);
void videoFrameReceived(vpx_image* frame);
private:
static void onFriendRequest(Tox* tox, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core);
2014-07-03 15:22:12 +08:00
static void onFriendMessage(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core);
static void onFriendNameChange(Tox* tox, int friendId, const uint8_t* cName, uint16_t cNameSize, void* core);
static void onFriendTypingChange(Tox* tox, int friendId, uint8_t isTyping, void* core);
2014-07-03 15:22:12 +08:00
static void onStatusMessageChanged(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core);
static void onUserStatusChanged(Tox* tox, int friendId, uint8_t userstatus, void* core);
static void onConnectionStatusChanged(Tox* tox, int friendId, uint8_t status, void* core);
2014-07-03 15:22:12 +08:00
static void onAction(Tox* tox, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core);
static void onGroupInvite(Tox *tox, int friendnumber, const uint8_t *group_public_key, void *userdata);
static void onGroupMessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t * message, uint16_t length, void *userdata);
static void onGroupNamelistChange(Tox *tox, int groupnumber, int peernumber, uint8_t change, void *userdata);
static void onFileSendRequestCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
2014-07-03 15:22:12 +08:00
const uint8_t *filename, uint16_t filename_length, void *userdata);
static void onFileControlCallback(Tox *tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
2014-07-03 15:22:12 +08:00
uint8_t control_type, const uint8_t *data, uint16_t length, void *core);
static void onFileDataCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata);
static void onAvInvite(void* toxav, int32_t call_index, void* core);
static void onAvStart(void* toxav, int32_t call_index, void* core);
static void onAvCancel(void* toxav, int32_t call_index, void* core);
static void onAvReject(void* toxav, int32_t call_index, void* core);
static void onAvEnd(void* toxav, int32_t call_index, void* core);
static void onAvRinging(void* toxav, int32_t call_index, void* core);
static void onAvStarting(void* toxav, int32_t call_index, void* core);
static void onAvEnding(void* toxav, int32_t call_index, void* core);
static void onAvRequestTimeout(void* toxav, int32_t call_index, void* core);
static void onAvPeerTimeout(void* toxav, int32_t call_index, void* core);
static void onAvMediaChange(void *toxav, int32_t call_index, void* core);
2014-06-27 07:17:10 +08:00
2014-06-30 05:38:48 +08:00
static void prepareCall(int friendId, int callId, ToxAv *toxav, bool videoEnabled);
static void cleanupCall(int callId);
2014-08-28 21:46:11 +08:00
static void playCallAudio(ToxAv *toxav, int32_t callId, int16_t *data, int samples, void *user_data); // Callback
2014-07-09 15:55:25 +08:00
static void sendCallAudio(int callId, ToxAv* toxav);
2014-08-29 05:06:53 +08:00
static void playAudioBuffer(int callId, int16_t *data, int samples, unsigned channels, int sampleRate);
static void playCallVideo(ToxAv* toxav, int32_t callId, vpx_image_t* img, void *user_data);
2014-06-30 20:49:42 +08:00
void sendCallVideo(int callId);
void checkConnection();
void onBootstrapTimer();
void loadConfiguration(QString path);
static QString sanitize(QString name);
void get_tox();
void loadFriends();
2014-08-28 21:46:11 +08:00
static void sendAllFileData(Core* core, ToxFile* file);
static void removeFileFromQueue(bool sendQueue, int friendId, int fileId);
void checkLastOnline(int friendId);
private slots:
void onFileTransferFinished(ToxFile file);
private:
Tox* tox;
ToxAv* toxav;
2014-07-04 22:41:29 +08:00
QTimer *toxTimer, *fileTimer, *bootstrapTimer; //, *saveTimer;
2014-06-30 20:49:42 +08:00
Camera* camera;
QList<DhtServer> dhtServerList;
int dhtServerId;
static QList<ToxFile> fileSendQueue, fileRecvQueue;
2014-09-11 21:44:34 +08:00
static ToxCall calls[];
static const QString CONFIG_FILE_NAME;
2014-07-12 18:50:40 +08:00
static const int videobufsize;
static uint8_t* videobuf;
static int videoBusyness; // Used to know when to drop frames
2014-08-30 20:40:41 +08:00
static ALCdevice* alOutDev, *alInDev;
static ALCcontext* alContext;
public:
static ALuint alMainSource;
2014-06-25 04:11:11 +08:00
};
#endif // CORE_HPP