2015-02-06 19:28:49 +08:00
|
|
|
#include "nexus.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2015-02-06 19:28:49 +08:00
|
|
|
#include "misc/settings.h"
|
|
|
|
#include "video/camera.h"
|
2015-02-07 02:01:31 +08:00
|
|
|
#include "widget/gui.h"
|
2015-02-06 19:28:49 +08:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDebug>
|
2015-02-16 07:35:27 +08:00
|
|
|
#include <QImageReader>
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
#include <src/widget/androidgui.h>
|
|
|
|
#else
|
|
|
|
#include <src/widget/widget.h>
|
|
|
|
#endif
|
|
|
|
|
2015-02-07 02:38:08 +08:00
|
|
|
static Nexus* nexus{nullptr};
|
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
Nexus::Nexus(QObject *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
core{nullptr},
|
|
|
|
coreThread{nullptr},
|
|
|
|
widget{nullptr},
|
|
|
|
androidgui{nullptr},
|
|
|
|
started{false}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Nexus::~Nexus()
|
|
|
|
{
|
|
|
|
delete core;
|
|
|
|
delete coreThread;
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
delete androidgui;
|
|
|
|
#else
|
|
|
|
delete widget;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::start()
|
|
|
|
{
|
|
|
|
if (started)
|
|
|
|
return;
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
qDebug() << "Nexus: Starting up";
|
|
|
|
|
|
|
|
// Setup the environment
|
|
|
|
qRegisterMetaType<Status>("Status");
|
|
|
|
qRegisterMetaType<vpx_image>("vpx_image");
|
|
|
|
qRegisterMetaType<uint8_t>("uint8_t");
|
|
|
|
qRegisterMetaType<uint16_t>("uint16_t");
|
2015-04-20 05:12:44 +08:00
|
|
|
qRegisterMetaType<uint32_t>("uint32_t");
|
2015-02-06 19:28:49 +08:00
|
|
|
qRegisterMetaType<const int16_t*>("const int16_t*");
|
|
|
|
qRegisterMetaType<int32_t>("int32_t");
|
|
|
|
qRegisterMetaType<int64_t>("int64_t");
|
|
|
|
qRegisterMetaType<QPixmap>("QPixmap");
|
|
|
|
qRegisterMetaType<ToxFile>("ToxFile");
|
|
|
|
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
|
|
|
|
qRegisterMetaType<Core::PasswordType>("Core::PasswordType");
|
|
|
|
|
2015-02-19 04:22:03 +08:00
|
|
|
// Create GUI
|
|
|
|
#ifndef Q_OS_ANDROID
|
|
|
|
widget = Widget::getInstance();
|
|
|
|
#endif
|
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
// Create Core
|
|
|
|
QString profilePath = Settings::getInstance().detectProfile();
|
|
|
|
coreThread = new QThread(this);
|
|
|
|
coreThread->setObjectName("qTox Core");
|
|
|
|
core = new Core(Camera::getInstance(), coreThread, profilePath);
|
|
|
|
core->moveToThread(coreThread);
|
|
|
|
connect(coreThread, &QThread::started, core, &Core::start);
|
|
|
|
|
|
|
|
// Start GUI
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
androidgui = new AndroidGUI;
|
|
|
|
androidgui->show();
|
|
|
|
#else
|
2015-02-19 04:22:03 +08:00
|
|
|
widget->init();
|
2015-02-06 19:28:49 +08:00
|
|
|
#endif
|
2015-02-07 02:01:31 +08:00
|
|
|
GUI::getInstance();
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
// Connections
|
2015-02-07 19:46:55 +08:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
connect(core, &Core::connected, androidgui, &AndroidGUI::onConnected);
|
|
|
|
connect(core, &Core::disconnected, androidgui, &AndroidGUI::onDisconnected);
|
|
|
|
//connect(core, &Core::failedToStart, androidgui, &AndroidGUI::onFailedToStartCore);
|
|
|
|
//connect(core, &Core::badProxy, androidgui, &AndroidGUI::onBadProxyCore);
|
|
|
|
connect(core, &Core::statusSet, androidgui, &AndroidGUI::onStatusSet);
|
|
|
|
connect(core, &Core::usernameSet, androidgui, &AndroidGUI::setUsername);
|
|
|
|
connect(core, &Core::statusMessageSet, androidgui, &AndroidGUI::setStatusMessage);
|
|
|
|
connect(core, &Core::selfAvatarChanged, androidgui, &AndroidGUI::onSelfAvatarLoaded);
|
|
|
|
|
|
|
|
connect(androidgui, &AndroidGUI::statusSet, core, &Core::setStatus);
|
|
|
|
//connect(androidgui, &AndroidGUI::friendRequested, core, &Core::requestFriendship);
|
|
|
|
//connect(androidgui, &AndroidGUI::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
|
|
|
//connect(androidgui, &AndroidGUI::changeProfile, core, &Core::switchConfiguration);
|
|
|
|
#else
|
2015-03-13 14:00:12 +08:00
|
|
|
connect(core, &Core::connected, widget, &Widget::onConnected);
|
|
|
|
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
|
|
|
connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore);
|
|
|
|
connect(core, &Core::badProxy, widget, &Widget::onBadProxyCore);
|
|
|
|
connect(core, &Core::statusSet, widget, &Widget::onStatusSet);
|
|
|
|
connect(core, &Core::usernameSet, widget, &Widget::setUsername);
|
|
|
|
connect(core, &Core::statusMessageSet, widget, &Widget::setStatusMessage);
|
|
|
|
connect(core, &Core::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
|
|
|
connect(core, &Core::friendAdded, widget, &Widget::addFriend);
|
|
|
|
connect(core, &Core::failedToAddFriend, widget, &Widget::addFriendFailed);
|
|
|
|
connect(core, &Core::friendUsernameChanged, widget, &Widget::onFriendUsernameChanged);
|
|
|
|
connect(core, &Core::friendStatusChanged, widget, &Widget::onFriendStatusChanged);
|
2015-02-06 19:28:49 +08:00
|
|
|
connect(core, &Core::friendStatusMessageChanged, widget, &Widget::onFriendStatusMessageChanged);
|
2015-03-13 14:00:12 +08:00
|
|
|
connect(core, &Core::friendRequestReceived, widget, &Widget::onFriendRequestReceived);
|
|
|
|
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
|
|
|
connect(core, &Core::receiptRecieved, widget, &Widget::onReceiptRecieved);
|
|
|
|
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
|
|
|
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
|
|
|
connect(core, &Core::groupNamelistChanged, widget, &Widget::onGroupNamelistChanged);
|
|
|
|
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
|
|
|
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
2015-02-06 19:28:49 +08:00
|
|
|
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
|
|
|
connect(core, &Core::avInvite, widget, &Widget::playRingtone);
|
|
|
|
connect(core, &Core::blockingClearContacts, widget, &Widget::clearContactsList, Qt::BlockingQueuedConnection);
|
|
|
|
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
|
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);
|
|
|
|
connect(core, &Core::groupSentResult, widget, &Widget::onGroupSendResult);
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
connect(widget, &Widget::statusSet, core, &Core::setStatus);
|
|
|
|
connect(widget, &Widget::friendRequested, core, &Core::requestFriendship);
|
|
|
|
connect(widget, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
|
|
|
connect(widget, &Widget::changeProfile, core, &Core::switchConfiguration);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Start Core
|
|
|
|
coreThread->start();
|
|
|
|
|
|
|
|
started = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Nexus& Nexus::getInstance()
|
|
|
|
{
|
2015-02-07 02:38:08 +08:00
|
|
|
if (!nexus)
|
|
|
|
nexus = new Nexus;
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-02-07 02:38:08 +08:00
|
|
|
return *nexus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::destroyInstance()
|
|
|
|
{
|
|
|
|
delete nexus;
|
|
|
|
nexus = nullptr;
|
2015-02-06 19:28:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Core* Nexus::getCore()
|
|
|
|
{
|
|
|
|
return getInstance().core;
|
|
|
|
}
|
2015-02-07 02:01:31 +08:00
|
|
|
|
|
|
|
AndroidGUI* Nexus::getAndroidGUI()
|
|
|
|
{
|
|
|
|
return getInstance().androidgui;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* Nexus::getDesktopGUI()
|
|
|
|
{
|
|
|
|
return getInstance().widget;
|
|
|
|
}
|
2015-02-16 07:35:27 +08:00
|
|
|
|
|
|
|
QString Nexus::getSupportedImageFilter()
|
|
|
|
{
|
|
|
|
QString res;
|
|
|
|
for (auto type : QImageReader::supportedImageFormats())
|
|
|
|
res += QString("*.%1 ").arg(QString(type));
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-02-16 07:35:27 +08:00
|
|
|
return tr("Images (%1)", "filetype filter").arg(res.left(res.size()-1));
|
|
|
|
}
|
2015-03-17 05:41:59 +08:00
|
|
|
|
|
|
|
bool Nexus::isFilePathWritable(const QString& filepath)
|
|
|
|
{
|
|
|
|
QFile tmp(filepath);
|
|
|
|
bool writable = tmp.open(QIODevice::WriteOnly);
|
|
|
|
tmp.remove();
|
|
|
|
return writable;
|
|
|
|
}
|