mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Implement restarting toxcore
This commit is contained in:
parent
a03eea9b5f
commit
2dbf2e54b1
|
@ -105,9 +105,10 @@ Core::~Core()
|
|||
if (coreThread->isRunning())
|
||||
{
|
||||
if (QThread::currentThread() == coreThread)
|
||||
killTimers();
|
||||
killTimers(false);
|
||||
else
|
||||
QMetaObject::invokeMethod(this, "killTimers", Qt::BlockingQueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "killTimers", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(bool, false));
|
||||
}
|
||||
coreThread->exit(0);
|
||||
while (coreThread->isRunning())
|
||||
|
@ -1245,9 +1246,27 @@ void Core::resetCallSources()
|
|||
}
|
||||
}
|
||||
|
||||
void Core::killTimers()
|
||||
void Core::killTimers(bool onlyStop)
|
||||
{
|
||||
assert(QThread::currentThread() == coreThread);
|
||||
toxTimer->stop();
|
||||
delete toxTimer;
|
||||
if (!onlyStop)
|
||||
{
|
||||
delete toxTimer;
|
||||
toxTimer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Core::reset()
|
||||
{
|
||||
assert(QThread::currentThread() == coreThread);
|
||||
|
||||
ready = false;
|
||||
killTimers(true);
|
||||
deadifyTox();
|
||||
|
||||
emit selfAvatarChanged(QPixmap(":/img/contact_dark.svg"));
|
||||
GUI::clearContacts();
|
||||
|
||||
start();
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void start(); ///< Initializes the core, must be called before anything else
|
||||
void reset(); ///< Reinitialized the core. Must be called from the Core thread, with the GUI thread ready to process events.
|
||||
void process(); ///< Processes toxcore events and ensure we stay connected, called by its own timer
|
||||
void bootstrapDht(); ///< Connects us to the Tox network
|
||||
|
||||
|
@ -151,7 +152,6 @@ public slots:
|
|||
signals:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void blockingClearContacts();
|
||||
|
||||
void friendRequestReceived(const QString& userId, const QString& message);
|
||||
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
|
||||
|
@ -283,7 +283,7 @@ private:
|
|||
void deadifyTox();
|
||||
|
||||
private slots:
|
||||
void killTimers(); ///< Must only be called from the Core thread
|
||||
void killTimers(bool onlyStop); ///< Must only be called from the Core thread
|
||||
|
||||
private:
|
||||
Tox* tox;
|
||||
|
|
|
@ -157,7 +157,6 @@ void Nexus::showMainGUI()
|
|||
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
||||
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);
|
||||
|
||||
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "src/misc/settings.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/historykeeper.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include <cassert>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
@ -17,6 +18,7 @@ Profile::Profile(QString name, QString password, bool isNewProfile)
|
|||
newProfile{isNewProfile}, isRemoved{false}
|
||||
{
|
||||
Settings::getInstance().setCurrentProfile(name);
|
||||
HistoryKeeper::resetInstance();
|
||||
|
||||
coreThread = new QThread();
|
||||
coreThread->setObjectName("qTox Core");
|
||||
|
@ -313,3 +315,11 @@ QString Profile::getPassword()
|
|||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
void Profile::restartCore()
|
||||
{
|
||||
GUI::setEnabled(false); // Core::reset re-enables it
|
||||
if (!isRemoved && core->isReady())
|
||||
saveToxSave();
|
||||
QMetaObject::invokeMethod(core, "reset");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
QString getName();
|
||||
|
||||
void startCore(); ///< Starts the Core thread
|
||||
void restartCore(); ///< Delete core and restart a new one
|
||||
bool isNewProfile();
|
||||
bool isEncrypted(); ///< Returns true if we have a password set (doesn't check the actual file on disk)
|
||||
bool checkPassword(); ///< Checks whether the password is valid
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "src/misc/smileypack.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/misc/style.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/profile.h"
|
||||
#include <QMessageBox>
|
||||
#include <QStyleFactory>
|
||||
#include <QTime>
|
||||
|
@ -351,7 +353,7 @@ void GeneralForm::onReconnectClicked()
|
|||
QMessageBox::warning(this, tr("Call active", "popup title"),
|
||||
tr("You can't disconnect while a call is active!", "popup text"));
|
||||
else
|
||||
; /// TODO: Add a reset function in Profile to save then restart toxcore
|
||||
Nexus::getProfile()->restartCore();
|
||||
}
|
||||
|
||||
void GeneralForm::reloadSmiles()
|
||||
|
|
|
@ -35,6 +35,14 @@ GUI& GUI::getInstance()
|
|||
|
||||
// Implementation of the public clean interface
|
||||
|
||||
void GUI::clearContacts()
|
||||
{
|
||||
if (QThread::currentThread() == qApp->thread())
|
||||
getInstance()._clearContacts();
|
||||
else
|
||||
QMetaObject::invokeMethod(&getInstance(), "_clearContacts", Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
void GUI::setEnabled(bool state)
|
||||
{
|
||||
if (QThread::currentThread() == qApp->thread())
|
||||
|
@ -192,6 +200,14 @@ QString GUI::passwordDialog(const QString& cancel, const QString& body)
|
|||
|
||||
// Private implementations
|
||||
|
||||
void GUI::_clearContacts()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
#else
|
||||
Nexus::getDesktopGUI()->clearContactsList();
|
||||
#endif
|
||||
}
|
||||
|
||||
void GUI::_setEnabled(bool state)
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
|
|
@ -15,6 +15,8 @@ public:
|
|||
static GUI& getInstance();
|
||||
/// Returns the main QWidget* of the application
|
||||
static QWidget* getMainWidget();
|
||||
/// Clear the GUI's contact list
|
||||
static void clearContacts();
|
||||
/// Will enable or disable the GUI.
|
||||
/// A disabled GUI can't be interacted with by the user
|
||||
static void setEnabled(bool state);
|
||||
|
@ -64,6 +66,7 @@ private:
|
|||
|
||||
// Private implementation, those must be called from the GUI thread
|
||||
private slots:
|
||||
void _clearContacts();
|
||||
void _setEnabled(bool state);
|
||||
void _setWindowTitle(const QString& title);
|
||||
void _reloadTheme();
|
||||
|
|
|
@ -898,6 +898,8 @@ void Widget::removeFriend(int friendId)
|
|||
|
||||
void Widget::clearContactsList()
|
||||
{
|
||||
assert(QThread::currentThread() == qApp->thread());
|
||||
|
||||
QList<Friend*> friends = FriendList::getAllFriends();
|
||||
for (Friend* f : friends)
|
||||
removeFriend(f, true);
|
||||
|
|
|
@ -70,9 +70,9 @@ public:
|
|||
void newMessageAlert(GenericChatroomWidget* chat);
|
||||
bool isFriendWidgetCurActiveWidget(Friend* f);
|
||||
bool getIsWindowMinimized();
|
||||
void clearContactsList();
|
||||
void setTranslation();
|
||||
void updateIcons();
|
||||
void clearContactsList();
|
||||
~Widget();
|
||||
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
|
|
Loading…
Reference in New Issue
Block a user