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

Clean code, improve compilation speed

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-09-11 15:44:34 +02:00
parent e91846e821
commit a7c75e63a5
56 changed files with 323 additions and 288 deletions

View File

@ -15,6 +15,8 @@
*/
#include "cdata.h"
#include <QString>
#include <tox/tox.h>
// CData
@ -54,6 +56,8 @@ uint16_t CData::fromString(const QString& data, uint8_t* cData)
// CUserId
const uint16_t CUserId::SIZE{TOX_CLIENT_ID_SIZE};
CUserId::CUserId(const QString &userId) :
CData(userId, SIZE)
{
@ -68,6 +72,8 @@ QString CUserId::toString(const uint8_t* cUserId)
// CFriendAddress
const uint16_t CFriendAddress::SIZE{TOX_FRIEND_ADDRESS_SIZE};
CFriendAddress::CFriendAddress(const QString &friendAddress) :
CData(friendAddress, SIZE)
{

View File

@ -18,9 +18,8 @@
#define CDATA_H
#include <cstdint>
#include <QString>
#include "tox/tox.h"
class QString;
class CData
{
public:
@ -48,7 +47,7 @@ public:
static QString toString(const uint8_t *cUserId);
private:
static const uint16_t SIZE = TOX_CLIENT_ID_SIZE;
static const uint16_t SIZE;
};
@ -60,7 +59,7 @@ public:
static QString toString(const uint8_t* cFriendAddress);
private:
static const uint16_t SIZE = TOX_FRIEND_ADDRESS_SIZE;
static const uint16_t SIZE;
};

View File

@ -20,6 +20,8 @@
#include "settings.h"
#include "widget/widget.h"
#include <tox/tox.h>
#include <ctime>
#include <functional>
@ -29,7 +31,9 @@
#include <QSaveFile>
#include <QStandardPaths>
#include <QThread>
#include <QtConcurrent/QtConcurrent>
#include <QTimer>
#include <QCoreApplication>
#include <QDateTime>
const QString Core::CONFIG_FILE_NAME = "data";
QList<ToxFile> Core::fileSendQueue;
@ -111,6 +115,11 @@ Core::~Core()
alcCaptureCloseDevice(alInDev);
}
Core* Core::getInstance()
{
return Widget::getInstance()->getCore();
}
void Core::start()
{
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options.

94
core.h
View File

@ -17,102 +17,24 @@
#ifndef CORE_HPP
#define CORE_HPP
#include <tox/tox.h>
#include <tox/toxav.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
#include <cstdint>
#include <QDateTime>
#include <QObject>
#include <QTimer>
#include <QString>
#include <QFile>
#include <QList>
#include <QByteArray>
#define TOXAV_MAX_CALLS 16
#define GROUPCHAT_MAX_SIZE 32
#define TOX_SAVE_INTERVAL 30*1000
#define TOX_FILE_INTERVAL 0
#define TOX_BOOTSTRAP_INTERVAL 5*1000
#define TOXAV_RINGING_TIME 15
// TODO: Put that in the settings
#define TOXAV_MAX_VIDEO_WIDTH 1600
#define TOXAV_MAX_VIDEO_HEIGHT 1200
#include "corestructs.h"
#include "coreav.h"
#include "coredefines.h"
template <typename T> class QList;
class Camera;
enum class Status : int {Online = 0, Away, Busy, Offline};
struct DhtServer
{
QString name;
QString userId;
QString address;
int port;
};
struct ToxFile
{
enum FileStatus
{
STOPPED,
PAUSED,
TRANSMITTING
};
enum FileDirection : bool
{
SENDING,
RECEIVING
};
ToxFile()=default;
ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction)
: fileNum(FileNum), friendId(FriendId), fileName{FileName}, filePath{FilePath}, file{new QFile(filePath)},
bytesSent{0}, filesize{0}, status{STOPPED}, direction{Direction}, sendTimer{nullptr} {}
~ToxFile(){}
void setFilePath(QString path) {filePath=path; file->setFileName(path);}
bool open(bool write) {return write?file->open(QIODevice::ReadWrite):file->open(QIODevice::ReadOnly);}
int fileNum;
int friendId;
QByteArray fileName;
QString filePath;
QFile* file;
long long bytesSent;
long long filesize;
FileStatus status;
FileDirection direction;
QTimer* sendTimer;
};
struct ToxCall
{
public:
ToxAvCSettings codecSettings;
QTimer *sendAudioTimer, *sendVideoTimer;
int callId;
int friendId;
bool videoEnabled;
bool active;
bool muteMic;
ALuint alSource;
};
class QTimer;
class QString;
class Core : public QObject
{
Q_OBJECT
public:
explicit Core(Camera* cam, QThread* coreThread);
static Core* getInstance(); ///< Returns the global widget's Core instance
~Core();
int getGroupNumberPeers(int groupId) const;
@ -298,7 +220,7 @@ private:
QList<DhtServer> dhtServerList;
int dhtServerId;
static QList<ToxFile> fileSendQueue, fileRecvQueue;
static ToxCall calls[TOXAV_MAX_CALLS];
static ToxCall calls[];
static const QString CONFIG_FILE_NAME;
static const int videobufsize;

View File

@ -15,7 +15,9 @@
*/
#include "core.h"
#include "widget/widget.h"
#include "widget/camera.h"
#include <QDebug>
#include <QTimer>
ToxCall Core::calls[TOXAV_MAX_CALLS];
const int Core::videobufsize{TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4};
@ -55,7 +57,7 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
if (calls[callId].videoEnabled)
{
calls[callId].sendVideoTimer->start();
Widget::getInstance()->getCamera()->suscribe();
Camera::getInstance()->suscribe();
}
}
@ -71,12 +73,12 @@ void Core::onAvMediaChange(void* toxav, int32_t callId, void* core)
{
calls[callId].videoEnabled = false;
calls[callId].sendVideoTimer->stop();
Widget::getInstance()->getCamera()->unsuscribe();
Camera::getInstance()->unsuscribe();
emit ((Core*)core)->avMediaChange(friendId, callId, false);
}
else
{
Widget::getInstance()->getCamera()->suscribe();
Camera::getInstance()->suscribe();
calls[callId].videoEnabled = true;
calls[callId].sendVideoTimer->start();
emit ((Core*)core)->avMediaChange(friendId, callId, true);
@ -159,7 +161,7 @@ void Core::cleanupCall(int callId)
calls[callId].sendAudioTimer->stop();
calls[callId].sendVideoTimer->stop();
if (calls[callId].videoEnabled)
Widget::getInstance()->getCamera()->unsuscribe();
Camera::getInstance()->unsuscribe();
alcCaptureStop(alInDev);
}
@ -224,7 +226,7 @@ void Core::playCallVideo(ToxAv*, int32_t callId, vpx_image_t* img, void *user_da
if (videoBusyness >= 1)
qWarning() << "Core: playCallVideo: Busy, dropping current frame";
else
emit Widget::getInstance()->getCore()->videoFrameReceived(img);
emit Core::getInstance()->videoFrameReceived(img);
vpx_img_free(img);
}

29
coreav.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef COREAV_H
#define COREAV_H
#include <tox/toxav.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
class QTimer;
struct ToxCall
{
public:
ToxAvCSettings codecSettings;
QTimer *sendAudioTimer, *sendVideoTimer;
int callId;
int friendId;
bool videoEnabled;
bool active;
bool muteMic;
ALuint alSource;
};
#endif // COREAV_H

15
coredefines.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef COREDEFINES_H
#define COREDEFINES_H
#define TOXAV_MAX_CALLS 16
#define GROUPCHAT_MAX_SIZE 32
#define TOX_SAVE_INTERVAL 30*1000
#define TOX_FILE_INTERVAL 0
#define TOX_BOOTSTRAP_INTERVAL 5*1000
#define TOXAV_RINGING_TIME 15
// TODO: Put that in the settings
#define TOXAV_MAX_VIDEO_WIDTH 1600
#define TOXAV_MAX_VIDEO_HEIGHT 1200
#endif // COREDEFINES_H

19
corestructs.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "corestructs.h"
#include <QFile>
ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction)
: fileNum(FileNum), friendId(FriendId), fileName{FileName}, filePath{FilePath}, file{new QFile(filePath)},
bytesSent{0}, filesize{0}, status{STOPPED}, direction{Direction}, sendTimer{nullptr}
{
}
void ToxFile::setFilePath(QString path)
{
filePath=path;
file->setFileName(path);
}
bool ToxFile::open(bool write)
{
return write ? file->open(QIODevice::ReadWrite) : file->open(QIODevice::ReadOnly);
}

54
corestructs.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef CORESTRUCTS_H
#define CORESTRUCTS_H
// Some headers use Core structs but don't need to include all of core.h
// They should include this file directly instead to reduce compilation times
#include <QString>
class QFile;
class QTimer;
enum class Status : int {Online = 0, Away, Busy, Offline};
struct DhtServer
{
QString name;
QString userId;
QString address;
int port;
};
struct ToxFile
{
enum FileStatus
{
STOPPED,
PAUSED,
TRANSMITTING
};
enum FileDirection : bool
{
SENDING,
RECEIVING
};
ToxFile()=default;
ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction);
~ToxFile(){}
void setFilePath(QString path);
bool open(bool write);
int fileNum;
int friendId;
QByteArray fileName;
QString filePath;
QFile* file;
long long bytesSent;
long long filesize;
FileStatus status;
FileDirection direction;
QTimer* sendTimer;
};
#endif // CORESTRUCTS_H

View File

@ -15,6 +15,7 @@
*/
#include "cstring.h"
#include <QString>
CString::CString(const QString& string)
{

View File

@ -18,7 +18,8 @@
#define CSTRING_H
#include <cstdint>
#include <QString>
class QString;
class CString
{

View File

@ -15,15 +15,12 @@
*/
#include "filetransferinstance.h"
#include "widget/widget.h"
#include "core.h"
#include "math.h"
#include "style.h"
#include <math.h>
#include <QFileDialog>
#include <QPixmap>
#include <QPainter>
#include <QMessageBox>
#include <QBuffer>
#include <QDebug>
uint FileTransferInstance::Idconter = 0;
@ -93,7 +90,7 @@ void FileTransferInstance::onFileTransferCancelled(int FriendId, int FileNum, To
{
if (FileNum != fileNum || FriendId != friendId || Direction != direction)
return;
disconnect(Widget::getInstance()->getCore(),0,this,0);
disconnect(Core::getInstance(),0,this,0);
state = tsCanceled;
emit stateUpdated();
@ -103,7 +100,7 @@ void FileTransferInstance::onFileTransferFinished(ToxFile File)
{
if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction)
return;
disconnect(Widget::getInstance()->getCore(),0,this,0);
disconnect(Core::getInstance(),0,this,0);
if (File.direction == ToxFile::RECEIVING)
{
@ -126,14 +123,14 @@ void FileTransferInstance::onFileTransferFinished(ToxFile File)
void FileTransferInstance::cancelTransfer()
{
Widget::getInstance()->getCore()->cancelFileSend(friendId, fileNum);
Core::getInstance()->cancelFileSend(friendId, fileNum);
state = tsCanceled;
emit stateUpdated();
}
void FileTransferInstance::rejectRecvRequest()
{
Widget::getInstance()->getCore()->rejectFileRecvRequest(friendId, fileNum);
Core::getInstance()->rejectFileRecvRequest(friendId, fileNum);
onFileTransferCancelled(friendId, fileNum, direction);
state = tsCanceled;
emit stateUpdated();
@ -159,7 +156,7 @@ void FileTransferInstance::acceptRecvRequest()
QString path;
while (true)
{
path = QFileDialog::getSaveFileName(Widget::getInstance(), tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename));
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename));
if (path.isEmpty())
return;
else
@ -170,13 +167,13 @@ void FileTransferInstance::acceptRecvRequest()
if (isFileWritable(path))
break;
else
QMessageBox::warning(Widget::getInstance(), tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
QMessageBox::warning(0, tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
}
}
savePath = path;
Widget::getInstance()->getCore()->acceptFileRecvRequest(friendId, fileNum, path);
Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path);
state = tsProcessing;
emit stateUpdated();
@ -184,7 +181,7 @@ void FileTransferInstance::acceptRecvRequest()
void FileTransferInstance::pauseResumeRecv()
{
Widget::getInstance()->getCore()->pauseResumeFileRecv(friendId, fileNum);
Core::getInstance()->pauseResumeFileRecv(friendId, fileNum);
if (state == tsProcessing)
state = tsPaused;
else state = tsProcessing;
@ -193,7 +190,7 @@ void FileTransferInstance::pauseResumeRecv()
void FileTransferInstance::pauseResumeSend()
{
Widget::getInstance()->getCore()->pauseResumeFileSend(friendId, fileNum);
Core::getInstance()->pauseResumeFileSend(friendId, fileNum);
if (state == tsProcessing)
state = tsPaused;
else state = tsProcessing;

View File

@ -17,15 +17,10 @@
#define FILETRANSFERINSTANCE_H
#include <QObject>
#include <QLabel>
#include <QPushButton>
#include <QProgressBar>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDateTime>
#include <QTextCursor>
#include <QImage>
#include "core.h"
#include "corestructs.h"
struct ToxFile;
@ -39,7 +34,6 @@ public:
explicit FileTransferInstance(ToxFile File);
QString getHtmlImage();
uint getId(){return id;}
void setTextCursor(QTextCursor cursor);
TransfState getState() {return state;}
public slots:

View File

@ -17,6 +17,7 @@
#include "friend.h"
#include "friendlist.h"
#include "widget/friendwidget.h"
#include "widget/form/chatform.h"
Friend::Friend(int FriendId, QString UserId)
: friendId(FriendId), userId(UserId)

View File

@ -18,9 +18,10 @@
#define FRIEND_H
#include <QString>
#include "widget/form/chatform.h"
#include "corestructs.h"
struct FriendWidget;
class ChatForm;
struct Friend
{
@ -38,7 +39,6 @@ public:
ChatForm* chatForm;
int hasNewEvents;
Status friendStatus;
QPixmap avatar;
};
#endif // FRIEND_H

View File

@ -21,7 +21,7 @@
QList<Friend*> FriendList::friendList;
Friend* FriendList::addFriend(int friendId, QString userId)
Friend* FriendList::addFriend(int friendId, const QString& userId)
{
for (Friend* f : friendList)
if (f->friendId == friendId)

View File

@ -17,16 +17,15 @@
#ifndef FRIENDLIST_H
#define FRIENDLIST_H
#include <QString>
#include <QList>
template <class T> class QList;
struct Friend;
class QString;
class FriendList
{
public:
FriendList();
static Friend* addFriend(int friendId, QString userId);
static Friend* addFriend(int friendId, const QString& userId);
static Friend* findFriend(int friendId);
static void removeFriend(int friendId);

View File

@ -19,18 +19,18 @@
#include "widget/form/groupchatform.h"
#include "friendlist.h"
#include "friend.h"
#include "widget/widget.h"
#include "core.h"
#include <QDebug>
#include <QTimer>
Group::Group(int GroupId, QString Name)
: groupId(GroupId), nPeers{0}, hasPeerInfo{false}
: groupId(GroupId), nPeers{0}, hasPeerInfo{false}, peerInfoTimer{new QTimer}
{
widget = new GroupWidget(groupId, Name);
chatForm = new GroupChatForm(this);
connect(&peerInfoTimer, SIGNAL(timeout()), this, SLOT(queryPeerInfo()));
peerInfoTimer.setInterval(500);
peerInfoTimer.setSingleShot(false);
connect(peerInfoTimer, SIGNAL(timeout()), this, SLOT(queryPeerInfo()));
peerInfoTimer->setInterval(500);
peerInfoTimer->setSingleShot(false);
//peerInfoTimer.start();
//in groupchats, we only notify on messages containing your name
@ -42,11 +42,12 @@ Group::~Group()
{
delete chatForm;
delete widget;
delete peerInfoTimer;
}
void Group::queryPeerInfo()
{
const Core* core = Widget::getInstance()->getCore();
const Core* core = Core::getInstance();
int nPeersResult = core->getGroupNumberPeers(groupId);
if (nPeersResult == -1)
{
@ -86,7 +87,7 @@ void Group::queryPeerInfo()
{
qDebug() << "Group::queryPeerInfo: Successfully loaded names";
hasPeerInfo = true;
peerInfoTimer.stop();
peerInfoTimer->stop();
}
}

View File

@ -17,15 +17,15 @@
#ifndef GROUP_H
#define GROUP_H
#include <QList>
#include <QMap>
#include <QTimer>
#include <QObject>
#define RETRY_PEER_INFO_INTERVAL 500
struct Friend;
class GroupWidget;
class GroupChatForm;
class QTimer;
class Group : public QObject
{
@ -47,7 +47,7 @@ public:
GroupWidget* widget;
GroupChatForm* chatForm;
bool hasPeerInfo;
QTimer peerInfoTimer;
QTimer* peerInfoTimer;
int hasNewMessages, userWasMentioned;
};

View File

@ -19,7 +19,7 @@
QList<Group*> GroupList::groupList;
Group* GroupList::addGroup(int groupId, QString name)
Group* GroupList::addGroup(int groupId, const QString& name)
{
Group* newGroup = new Group(groupId, name);
groupList.append(newGroup);

View File

@ -17,17 +17,16 @@
#ifndef GROUPLIST_H
#define GROUPLIST_H
#include <QString>
#include <QList>
#include <QMap>
template <typename T>
class QList;
class Group;
class QString;
class GroupList
{
public:
GroupList();
static Group* addGroup(int groupId, QString name);
static Group* addGroup(int groupId, const QString& name);
static Group* findGroup(int groupId);
static void removeGroup(int groupId);

View File

@ -19,6 +19,7 @@
#include <QApplication>
#include <QFontDatabase>
#include <QTranslator>
#include <QDebug>
int main(int argc, char *argv[])
{
@ -31,7 +32,7 @@ int main(int argc, char *argv[])
if (Settings::getInstance().getUseTranslations())
{
QString locale = QLocale::system().name().section('_', 0, 0);
if (translator.load(locale,":translations/"))
if (locale=="en" || translator.load(locale,":translations/"))
qDebug() << "Loaded translation "+locale;
else
qDebug() << "Error loading translation "+locale;
@ -50,45 +51,3 @@ int main(int argc, char *argv[])
return errorcode;
}
/** TODO
* ">using a dedicated tool to maintain a TODO list" edition
*
* QRC FILES DO YOU EVEN INTO THEM ? Fix it soon for packaging and Urras.
* Most cameras use YUYV, implement YUYV -> YUV240
* Sending large files (~380MB) "restarts" after ~10MB. Goes back to 0%, consumes twice as much ram (reloads the file?)
* => Don't load the whole file at once, load small chunks (25MB?) when needed, then free them and load the next
* Don't do anything if a friend is disconnected, don't print to the chat
* Changing online/away/busy/offline by clicking the bubble
* /me action messages
* Popup windows for adding friends and changing settings
* And logging of the chat
* Show the picture's size between name and size after transfer completion if it's a pic
* Adjust all status icons to match the mockup, including scooting the friendslist ones to the left and making the user one the same size
* Sidepanel (friendlist) should be resizeable
* An extra side panel for groupchats, like Venom does (?)
*
* In the file transfer widget:
* >There is more padding on the left side compared to the right.
* >Maybe put the file size should be in the same row as the name.
* >Right-align the ETA.
*
*/
/** NAMES :
Botox
Ricin
Anthrax
Sarin
Cyanide
Polonium
Mercury
Arsenic
qTox
plague
Britney
Nightshade
Belladonna
toxer
GoyIM
*/

View File

@ -107,7 +107,10 @@ HEADERS += widget/form/addfriendform.h \
widget/form/genericchatform.h \
widget/tool/chataction.h \
widget/chatareawidget.h \
filetransferinstance.h
filetransferinstance.h \
corestructs.h \
coredefines.h \
coreav.h
SOURCES += \
widget/form/addfriendform.cpp \
@ -143,4 +146,5 @@ SOURCES += \
widget/form/genericchatform.cpp \
widget/tool/chataction.cpp \
widget/chatareawidget.cpp \
filetransferinstance.cpp
filetransferinstance.cpp \
corestructs.cpp

View File

@ -16,8 +16,8 @@
#include "settings.h"
#include "smileypack.h"
#include "widget/widget.h"
#include <QFont>
#include <QApplication>
#include <QDir>
#include <QFile>

View File

@ -18,8 +18,7 @@
#define SETTINGS_HPP
#include <QHash>
#include <QMainWindow>
#include <QSplitter>
#include <QObject>
class Settings : public QObject
{

View File

@ -19,8 +19,14 @@
#include <QFileInfo>
#include <QFile>
#include <QtXml>
#include <QDebug>
#include <QIcon>
#include <QPixmap>
#include <QDir>
#include <QCoreApplication>
#include <QDomDocument>
#include <QDomElement>
#include <QBuffer>
#include <QStringBuilder>
SmileyPack::SmileyPack()
{

View File

@ -17,7 +17,7 @@
#ifndef STYLE_H
#define STYLE_H
#include <QString>
class QString;
class Style
{

View File

@ -15,7 +15,7 @@
*/
#include "camera.h"
#include <QMessageBox>
#include "widget.h"
using namespace cv;
@ -114,3 +114,8 @@ vpx_image Camera::getLastVPXImage()
}
return img;
}
Camera* Camera::getInstance()
{
return Widget::getInstance()->getCamera();
}

View File

@ -31,6 +31,7 @@ class Camera
{
public:
Camera();
static Camera* getInstance(); ///< Returns the global widget's Camera instance
void suscribe(); ///< Call this once before trying to get frames
void unsuscribe(); ///< Call this once when you don't need frames anymore
cv::Mat getLastFrame(); ///< Get the last captured frame

View File

@ -16,10 +16,10 @@
#include "chatareawidget.h"
#include "widget/tool/chataction.h"
#include <QAbstractTextDocumentLayout>
#include <QMessageBox>
#include <QScrollBar>
#include <QDesktopServices>
#include <QTextTable>
#include <QAbstractTextDocumentLayout>
ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
QTextBrowser(parent)

View File

@ -19,9 +19,9 @@
#include <QTextBrowser>
#include <QList>
#include <QTextTable>
class ChatAction;
class QTextTable;
class ChatAreaWidget : public QTextBrowser
{

View File

@ -16,6 +16,7 @@
#include "croppinglabel.h"
#include <QResizeEvent>
#include <QLineEdit>
CroppingLabel::CroppingLabel(QWidget* parent)
: QLabel(parent)

View File

@ -18,7 +18,8 @@
#define CROPPINGLABEL_H
#include <QLabel>
#include <QLineEdit>
class QLineEdit;
class CroppingLabel : public QLabel
{

View File

@ -19,7 +19,7 @@
#include <QFont>
#include <QMessageBox>
#include <tox/tox.h>
#include "widget/widget.h"
#include "ui_mainwindow.h"
#include "core.h"
#define TOX_ID_LENGTH 2*TOX_FRIEND_ADDRESS_SIZE
@ -95,7 +95,7 @@ void AddFriendForm::onSendTriggered()
if (id.isEmpty()) {
showWarning(tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to"));
} else if (isToxId(id)) {
if (id.toUpper() == Widget::getInstance()->getCore()->getSelfId().toUpper())
if (id.toUpper() == Core::getInstance()->getSelfId().toUpper())
showWarning(tr("You can't add yourself as a friend !","When trying to add your own Tox ID as friend"));
else
emit friendRequested(id, getMessage());

View File

@ -17,8 +17,6 @@
#ifndef ADDFRIENDFORM_H
#define ADDFRIENDFORM_H
#include "ui_mainwindow.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
@ -26,6 +24,8 @@
#include <QPushButton>
#include <QDnsLookup>
namespace Ui {class MainWindow;}
class AddFriendForm : public QObject
{
Q_OBJECT
@ -42,8 +42,8 @@ signals:
void friendRequested(const QString& friendAddress, const QString& message);
private slots:
void onSendTriggered();
void handleDnsLookup();
void onSendTriggered();
void handleDnsLookup();
private:
QLabel headLabel, toxIdLabel, messageLabel;

View File

@ -14,15 +14,21 @@
See the COPYING file for more details.
*/
#include <QDebug>
#include <QScrollBar>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include "chatform.h"
#include "friend.h"
#include "widget/friendwidget.h"
#include "filetransferinstance.h"
#include "widget/widget.h"
#include "widget/tool/chataction.h"
#include <QScrollBar>
#include <QFileDialog>
#include <QMessageBox>
#include "widget/netcamview.h"
#include "widget/chatareawidget.h"
#include "widget/tool/chattextedit.h"
#include "core.h"
#include "widget/widget.h"
ChatForm::ChatForm(Friend* chatFriend)
: f(chatFriend)
@ -36,15 +42,15 @@ ChatForm::ChatForm(Friend* chatFriend)
headTextLayout->addWidget(statusMessageLabel);
headTextLayout->addStretch();
connect(Widget::getInstance()->getCore(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
connect(Widget::getInstance()->getCore(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
connect(Core::getInstance(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
connect(Core::getInstance(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered);
connect(fileButton, &QPushButton::clicked, this, &ChatForm::onAttachClicked);
connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered);
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered);
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
connect(chatWidget, SIGNAL(onFileTranfertInterract(QString,QString)), this, SLOT(onFileTansBtnClicked(QString,QString)));
connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked);
}
ChatForm::~ChatForm()
@ -99,9 +105,9 @@ void ChatForm::startFileSend(ToxFile file)
FileTransferInstance* fileTrans = new FileTransferInstance(file);
ftransWidgets.insert(fileTrans->getId(), fileTrans);
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
QString name = Widget::getInstance()->getUsername();
if (name == previousName)
@ -119,9 +125,9 @@ void ChatForm::onFileRecvRequest(ToxFile file)
FileTransferInstance* fileTrans = new FileTransferInstance(file);
ftransWidgets.insert(fileTrans->getId(), fileTrans);
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->getIsWindowMinimized() || !w->isActiveWindow())

View File

@ -18,11 +18,11 @@
#define CHATFORM_H
#include "genericchatform.h"
#include "core.h"
#include "widget/netcamview.h"
#include "corestructs.h"
struct Friend;
class FileTransferInstance;
class NetCamView;
class ChatForm : public GenericChatForm
{

View File

@ -15,6 +15,11 @@
*/
#include "filesform.h"
#include "ui_mainwindow.h"
#include <QFileInfo>
#include <QUrl>
#include <QDebug>
#include <QDesktopServices>
FilesForm::FilesForm()
: QObject()

View File

@ -17,17 +17,14 @@
#ifndef FILESFORM_H
#define FILESFORM_H
#include "ui_mainwindow.h"
#include <QListWidget>
#include <QListWidgetItem>
#include <QTabWidget>
#include <QString>
#include <QDesktopServices>
#include <QLabel>
#include <QVBoxLayout>
#include <QUrl>
#include <QDebug>
#include <QFileInfo>
namespace Ui {class MainWindow;}
class QListWidget;
class FilesForm : public QObject
{

View File

@ -23,6 +23,8 @@
#include "widget/widget.h"
#include "settings.h"
#include "widget/tool/chataction.h"
#include "widget/chatareawidget.h"
#include "widget/tool/chattextedit.h"
GenericChatForm::GenericChatForm(QObject *parent) :
QObject(parent)

View File

@ -19,19 +19,18 @@
#include <QObject>
#include <QPoint>
#include <QTime>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include "widget/croppinglabel.h"
#include "widget/chatareawidget.h"
#include "widget/tool/chattextedit.h"
#include <QDateTime>
// Spacing in px inserted when the author of the last message changes
#define AUTHOR_CHANGE_SPACING 5
class QLabel;
class QVBoxLayout;
class QPushButton;
class CroppingLabel;
class ChatTextEdit;
class ChatAreaWidget;
namespace Ui {
class MainWindow;
}

View File

@ -17,7 +17,9 @@
#include "groupchatform.h"
#include "group.h"
#include "widget/groupwidget.h"
#include "widget/widget.h"
#include "widget/tool/chattextedit.h"
#include "widget/croppinglabel.h"
#include <QPushButton>
GroupChatForm::GroupChatForm(Group* chatGroup)
: group(chatGroup)

View File

@ -18,9 +18,8 @@
#define GROUPCHATFORM_H
#include "genericchatform.h"
#include "widget/tool/chattextedit.h"
#include "ui_mainwindow.h"
namespace Ui {class MainWindow;}
class Group;
class GroupChatForm : public GenericChatForm

View File

@ -18,6 +18,7 @@
#include "widget/widget.h"
#include "settings.h"
#include "smileypack.h"
#include "ui_mainwindow.h"
#include <QFont>
#include <QClipboard>
#include <QApplication>

View File

@ -20,17 +20,17 @@
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QString>
#include <QObject>
#include <QSpacerItem>
#include <QCheckBox>
#include <QPushButton>
#include <QTextEdit>
#include <QComboBox>
#include "ui_mainwindow.h"
#include "widget/selfcamview.h"
#include "widget/croppinglabel.h"
namespace Ui {class MainWindow;}
class QString;
class SettingsForm : public QObject
{
Q_OBJECT

View File

@ -15,6 +15,7 @@
*/
#include "friendlistwidget.h"
#include <QDebug>
#include <QGridLayout>
FriendListWidget::FriendListWidget(QWidget *parent) :
QWidget(parent)

View File

@ -18,8 +18,11 @@
#define FRIENDLISTWIDGET_H
#include <QWidget>
#include <QGridLayout>
#include "core.h"
#include <QHash>
#include "corestructs.h"
class QLayout;
class QGridLayout;
class FriendListWidget : public QWidget
{

View File

@ -18,9 +18,10 @@
#include "group.h"
#include "grouplist.h"
#include "groupwidget.h"
#include "widget.h"
#include "friendlist.h"
#include "friend.h"
#include "core.h"
#include "widget/form/chatform.h"
#include <QContextMenuEvent>
#include <QMenu>
@ -112,7 +113,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
else if (groupActions.contains(selectedItem))
{
Group* group = groupActions[selectedItem];
Widget::getInstance()->getCore()->groupInviteFriend(friendId, group->groupId);
Core::getInstance()->groupInviteFriend(friendId, group->groupId);
}
}
}

View File

@ -17,10 +17,7 @@
#ifndef FRIENDWIDGET_H
#define FRIENDWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "genericchatroomwidget.h"
#include "croppinglabel.h"

View File

@ -17,7 +17,6 @@
#ifndef GROUPWIDGET_H
#define GROUPWIDGET_H
#include <QWidget>
#include <QLabel>
#include "genericchatroomwidget.h"

View File

@ -16,9 +16,8 @@
#include "netcamview.h"
#include "core.h"
#include "widget.h"
#include <QApplication>
#include <QtConcurrent/QtConcurrent>
#include <QLabel>
#include <QHBoxLayout>
static inline void fromYCbCrToRGB(
uint8_t Y, uint8_t Cb, uint8_t Cr,
@ -70,7 +69,7 @@ void NetCamView::updateDisplay(vpx_image* frame)
if (!frame->w || !frame->h)
return;
Core* core = Widget::getInstance()->getCore();
Core* core = Core::getInstance();
core->increaseVideoBusyness();

View File

@ -18,14 +18,13 @@
#define NETCAMVIEW_H
#include <QWidget>
#include <QHBoxLayout>
#include <QTimer>
#include <QLabel>
#include <vpx/vpx_image.h>
class QCloseEvent;
class QShowEvent;
class QPainter;
class QLabel;
class QHBoxLayout;
class vpx_image;
class NetCamView : public QWidget
{

View File

@ -15,46 +15,45 @@
*/
#include "selfcamview.h"
#include "camera.h"
#include <QCloseEvent>
#include <QShowEvent>
#include "widget.h"
#include <QTimer>
#include <QLabel>
#include <QHBoxLayout>
#include <opencv2/opencv.hpp>
using namespace cv;
SelfCamView::SelfCamView(Camera* Cam, QWidget* parent)
: QWidget(parent), displayLabel{new QLabel},
mainLayout{new QHBoxLayout()}, cam(Cam)
mainLayout{new QHBoxLayout()}, cam(Cam), updateDisplayTimer{new QTimer}
{
setLayout(mainLayout);
setWindowTitle(SelfCamView::tr("Tox video test","Title of the window to test the video/webcam"));
setMinimumSize(320,240);
updateDisplayTimer.setInterval(5);
updateDisplayTimer.setSingleShot(false);
updateDisplayTimer->setInterval(5);
updateDisplayTimer->setSingleShot(false);
displayLabel->setScaledContents(true);
mainLayout->addWidget(displayLabel);
connect(&updateDisplayTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
}
SelfCamView::~SelfCamView()
{
connect(updateDisplayTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
}
void SelfCamView::closeEvent(QCloseEvent* event)
{
cam->unsuscribe();
updateDisplayTimer.stop();
updateDisplayTimer->stop();
event->accept();
}
void SelfCamView::showEvent(QShowEvent* event)
{
cam->suscribe();
updateDisplayTimer.start();
updateDisplayTimer->start();
event->accept();
}

View File

@ -18,14 +18,14 @@
#define SELFCAMVIEW_H
#include <QWidget>
#include <QHBoxLayout>
#include <QTimer>
#include <QLabel>
#include "camera.h"
class QCloseEvent;
class QShowEvent;
class QPainter;
class Camera;
class QLabel;
class QHBoxLayout;
class QTimer;
class SelfCamView : public QWidget
{
@ -33,7 +33,6 @@ class SelfCamView : public QWidget
public:
SelfCamView(Camera* Cam, QWidget *parent=0);
~SelfCamView();
private slots:
void updateDisplay();
@ -47,7 +46,7 @@ private:
QLabel *displayLabel;
QHBoxLayout* mainLayout;
Camera* cam;
QTimer updateDisplayTimer;
QTimer* updateDisplayTimer;
};
#endif // SELFCAMVIEW_H

View File

@ -16,6 +16,7 @@
#include "widget.h"
#include "ui_mainwindow.h"
#include "core.h"
#include "settings.h"
#include "friend.h"
#include "friendlist.h"
@ -26,17 +27,19 @@
#include "widget/groupwidget.h"
#include "widget/form/groupchatform.h"
#include "style.h"
#include "selfcamview.h"
#include "widget/friendlistwidget.h"
#include "camera.h"
#include "widget/form/chatform.h"
#include <QMessageBox>
#include <QDebug>
#include <QTextStream>
#include <QFile>
#include <QString>
#include <QPainter>
#include <QMouseEvent>
#include <QDesktopWidget>
#include <QCursor>
#include <QSettings>
#include <QClipboard>
#include <QThread>
#include <tox/tox.h>
Widget *Widget::instance{nullptr};

View File

@ -17,17 +17,11 @@
#ifndef WIDGET_H
#define WIDGET_H
#include <QThread>
#include <QMainWindow>
#include <QString>
#include <QHBoxLayout>
#include <QMenu>
#include "core.h"
#include "widget/form/addfriendform.h"
#include "widget/form/settingsform.h"
#include "widget/form/filesform.h"
#include "camera.h"
#include "friendlistwidget.h"
#include "corestructs.h"
#define PIXELS_TO_ACT 7
@ -38,6 +32,12 @@ class MainWindow;
class GenericChatroomWidget;
class Group;
struct Friend;
class QSplitter;
class SelfCamView;
class QMenu;
class Core;
class Camera;
class FriendListWidget;
class Widget : public QMainWindow
{