Browse Source

refactor: remove unneeded busy waiting code

reviewable/pr5418/r2
sudden6 7 years ago
parent
commit
a3344a127f
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 6
      src/net/toxuri.cpp
  2. 13
      src/nexus.cpp
  3. 2
      src/nexus.h
  4. 16
      src/persistence/toxsave.cpp

6
src/net/toxuri.cpp

@ -56,18 +56,12 @@ bool handleToxURI(const QString& toxURI)
Core* core = nexus.getCore(); Core* core = nexus.getCore();
while (!core) { while (!core) {
if (!nexus.isRunning())
return false;
core = nexus.getCore(); core = nexus.getCore();
qApp->processEvents(); qApp->processEvents();
QThread::msleep(10); QThread::msleep(10);
} }
while (!core->isReady()) { while (!core->isReady()) {
if (!nexus.isRunning())
return false;
qApp->processEvents(); qApp->processEvents();
QThread::msleep(10); QThread::msleep(10);
} }

13
src/nexus.cpp

@ -60,7 +60,6 @@ Nexus::Nexus(QObject* parent)
: QObject(parent) : QObject(parent)
, profile{nullptr} , profile{nullptr}
, widget{nullptr} , widget{nullptr}
, running{true}
{} {}
Nexus::~Nexus() Nexus::~Nexus()
@ -231,21 +230,9 @@ void Nexus::showMainGUI()
*/ */
void Nexus::quit() void Nexus::quit()
{ {
running = false;
qApp->quit(); qApp->quit();
} }
/**
* @brief Returns true until Nexus::quit is called.
*
* Any blocking processEvents() loop should check this as a return condition,
* since the application can not quit until control is returned to the event loop.
*/
bool Nexus::isRunning()
{
return running;
}
/** /**
* @brief Returns the singleton instance. * @brief Returns the singleton instance.
*/ */

2
src/nexus.h

@ -43,7 +43,6 @@ public:
void start(); void start();
void showMainGUI(); void showMainGUI();
void quit(); void quit();
bool isRunning();
static Nexus& getInstance(); static Nexus& getInstance();
static void destroyInstance(); static void destroyInstance();
@ -91,7 +90,6 @@ private:
private: private:
Profile* profile; Profile* profile;
Widget* widget; Widget* widget;
bool running;
}; };
#endif // NEXUS_H #endif // NEXUS_H

16
src/persistence/toxsave.cpp

@ -18,17 +18,15 @@
*/ */
#include "toxsave.h" #include "toxsave.h"
#include "src/core/core.h"
#include "src/persistence/settings.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
#include "src/widget/tool/profileimporter.h" #include "src/widget/tool/profileimporter.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileInfo>
bool toxSaveEventHandler(const QByteArray& eventData) bool toxSaveEventHandler(const QByteArray& eventData)
{ {
if (!eventData.endsWith(".tox")) if (!eventData.endsWith(".tox")) {
return false; return false;
}
handleToxSave(eventData); handleToxSave(eventData);
return true; return true;
@ -42,16 +40,6 @@ bool toxSaveEventHandler(const QByteArray& eventData)
*/ */
bool handleToxSave(const QString& path) bool handleToxSave(const QString& path)
{ {
Core* core = Core::getInstance();
while (!core) {
core = Core::getInstance();
qApp->processEvents();
}
while (!core->isReady())
qApp->processEvents();
ProfileImporter importer(GUI::getMainWidget()); ProfileImporter importer(GUI::getMainWidget());
return importer.importProfile(path); return importer.importProfile(path);
} }

Loading…
Cancel
Save