Browse Source

Implement restarting toxcore

pull/1793/head
tux3 10 years ago
parent
commit
2dbf2e54b1
  1. 27
      src/core/core.cpp
  2. 4
      src/core/core.h
  3. 1
      src/nexus.cpp
  4. 10
      src/profile.cpp
  5. 1
      src/profile.h
  6. 4
      src/widget/form/settings/generalform.cpp
  7. 16
      src/widget/gui.cpp
  8. 3
      src/widget/gui.h
  9. 2
      src/widget/widget.cpp
  10. 2
      src/widget/widget.h

27
src/core/core.cpp

@ -105,9 +105,10 @@ Core::~Core()
if (coreThread->isRunning()) if (coreThread->isRunning())
{ {
if (QThread::currentThread() == coreThread) if (QThread::currentThread() == coreThread)
killTimers(); killTimers(false);
else else
QMetaObject::invokeMethod(this, "killTimers", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, "killTimers", Qt::BlockingQueuedConnection,
Q_ARG(bool, false));
} }
coreThread->exit(0); coreThread->exit(0);
while (coreThread->isRunning()) while (coreThread->isRunning())
@ -1245,9 +1246,27 @@ void Core::resetCallSources()
} }
} }
void Core::killTimers() void Core::killTimers(bool onlyStop)
{ {
assert(QThread::currentThread() == coreThread); assert(QThread::currentThread() == coreThread);
toxTimer->stop(); 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();
} }

4
src/core/core.h

@ -87,6 +87,7 @@ public:
public slots: public slots:
void start(); ///< Initializes the core, must be called before anything else 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 process(); ///< Processes toxcore events and ensure we stay connected, called by its own timer
void bootstrapDht(); ///< Connects us to the Tox network void bootstrapDht(); ///< Connects us to the Tox network
@ -151,7 +152,6 @@ public slots:
signals: signals:
void connected(); void connected();
void disconnected(); void disconnected();
void blockingClearContacts();
void friendRequestReceived(const QString& userId, const QString& message); void friendRequestReceived(const QString& userId, const QString& message);
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction); void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
@ -283,7 +283,7 @@ private:
void deadifyTox(); void deadifyTox();
private slots: 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: private:
Tox* tox; Tox* tox;

1
src/nexus.cpp

@ -157,7 +157,6 @@ void Nexus::showMainGUI()
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying); connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated); connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
connect(core, &Core::avInvite, widget, &Widget::playRingtone); 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::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult); connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);

10
src/profile.cpp

@ -3,6 +3,7 @@
#include "src/misc/settings.h" #include "src/misc/settings.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/historykeeper.h" #include "src/historykeeper.h"
#include "src/widget/gui.h"
#include <cassert> #include <cassert>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -17,6 +18,7 @@ Profile::Profile(QString name, QString password, bool isNewProfile)
newProfile{isNewProfile}, isRemoved{false} newProfile{isNewProfile}, isRemoved{false}
{ {
Settings::getInstance().setCurrentProfile(name); Settings::getInstance().setCurrentProfile(name);
HistoryKeeper::resetInstance();
coreThread = new QThread(); coreThread = new QThread();
coreThread->setObjectName("qTox Core"); coreThread->setObjectName("qTox Core");
@ -313,3 +315,11 @@ QString Profile::getPassword()
{ {
return password; return password;
} }
void Profile::restartCore()
{
GUI::setEnabled(false); // Core::reset re-enables it
if (!isRemoved && core->isReady())
saveToxSave();
QMetaObject::invokeMethod(core, "reset");
}

1
src/profile.h

@ -25,6 +25,7 @@ public:
QString getName(); QString getName();
void startCore(); ///< Starts the Core thread void startCore(); ///< Starts the Core thread
void restartCore(); ///< Delete core and restart a new one
bool isNewProfile(); bool isNewProfile();
bool isEncrypted(); ///< Returns true if we have a password set (doesn't check the actual file on disk) 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 bool checkPassword(); ///< Checks whether the password is valid

4
src/widget/form/settings/generalform.cpp

@ -20,6 +20,8 @@
#include "src/misc/smileypack.h" #include "src/misc/smileypack.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/misc/style.h" #include "src/misc/style.h"
#include "src/nexus.h"
#include "src/profile.h"
#include <QMessageBox> #include <QMessageBox>
#include <QStyleFactory> #include <QStyleFactory>
#include <QTime> #include <QTime>
@ -351,7 +353,7 @@ void GeneralForm::onReconnectClicked()
QMessageBox::warning(this, tr("Call active", "popup title"), QMessageBox::warning(this, tr("Call active", "popup title"),
tr("You can't disconnect while a call is active!", "popup text")); tr("You can't disconnect while a call is active!", "popup text"));
else else
; /// TODO: Add a reset function in Profile to save then restart toxcore Nexus::getProfile()->restartCore();
} }
void GeneralForm::reloadSmiles() void GeneralForm::reloadSmiles()

16
src/widget/gui.cpp

@ -35,6 +35,14 @@ GUI& GUI::getInstance()
// Implementation of the public clean interface // 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) void GUI::setEnabled(bool state)
{ {
if (QThread::currentThread() == qApp->thread()) if (QThread::currentThread() == qApp->thread())
@ -192,6 +200,14 @@ QString GUI::passwordDialog(const QString& cancel, const QString& body)
// Private implementations // Private implementations
void GUI::_clearContacts()
{
#ifdef Q_OS_ANDROID
#else
Nexus::getDesktopGUI()->clearContactsList();
#endif
}
void GUI::_setEnabled(bool state) void GUI::_setEnabled(bool state)
{ {
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID

3
src/widget/gui.h

@ -15,6 +15,8 @@ public:
static GUI& getInstance(); static GUI& getInstance();
/// Returns the main QWidget* of the application /// Returns the main QWidget* of the application
static QWidget* getMainWidget(); static QWidget* getMainWidget();
/// Clear the GUI's contact list
static void clearContacts();
/// Will enable or disable the GUI. /// Will enable or disable the GUI.
/// A disabled GUI can't be interacted with by the user /// A disabled GUI can't be interacted with by the user
static void setEnabled(bool state); static void setEnabled(bool state);
@ -64,6 +66,7 @@ private:
// Private implementation, those must be called from the GUI thread // Private implementation, those must be called from the GUI thread
private slots: private slots:
void _clearContacts();
void _setEnabled(bool state); void _setEnabled(bool state);
void _setWindowTitle(const QString& title); void _setWindowTitle(const QString& title);
void _reloadTheme(); void _reloadTheme();

2
src/widget/widget.cpp

@ -898,6 +898,8 @@ void Widget::removeFriend(int friendId)
void Widget::clearContactsList() void Widget::clearContactsList()
{ {
assert(QThread::currentThread() == qApp->thread());
QList<Friend*> friends = FriendList::getAllFriends(); QList<Friend*> friends = FriendList::getAllFriends();
for (Friend* f : friends) for (Friend* f : friends)
removeFriend(f, true); removeFriend(f, true);

2
src/widget/widget.h

@ -70,9 +70,9 @@ public:
void newMessageAlert(GenericChatroomWidget* chat); void newMessageAlert(GenericChatroomWidget* chat);
bool isFriendWidgetCurActiveWidget(Friend* f); bool isFriendWidgetCurActiveWidget(Friend* f);
bool getIsWindowMinimized(); bool getIsWindowMinimized();
void clearContactsList();
void setTranslation(); void setTranslation();
void updateIcons(); void updateIcons();
void clearContactsList();
~Widget(); ~Widget();
virtual void closeEvent(QCloseEvent *event); virtual void closeEvent(QCloseEvent *event);

Loading…
Cancel
Save