logic: Ask user before reparsing the project

While the message box with the question is visible the ui is blocked. A message appears when:
* when project was edited
* when preferences were edited
* when project file has more recent changes than db
* when db has a different version than Coati
This commit is contained in:
Eberhard Graether
2016-04-24 22:47:39 +02:00
parent a6e57a6564
commit 6be207a68a
16 changed files with 342 additions and 70 deletions
+57
View File
@@ -1,5 +1,10 @@
#include "qt/view/QtMainView.h"
#include <chrono>
#include <thread>
#include <QMessageBox>
#include "utility/logging/logging.h"
#include "qt/window/QtMainWindow.h"
@@ -12,6 +17,7 @@ QtMainView::QtMainView()
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
, m_forceLicenseScreenFunctor(std::bind(&QtMainView::doForceLicenseScreen, this, std::placeholders::_1))
, m_confirmFunctor(std::bind(&QtMainView::doConfirm, this, std::placeholders::_1, std::placeholders::_2))
{
m_window = std::make_shared<QtMainWindow>();
m_window->show();
@@ -89,6 +95,30 @@ void QtMainView::updateRecentProjectMenu()
m_updateRecentProjectMenuFunctor();
}
int QtMainView::confirm(const std::string& message, const std::vector<std::string>& options)
{
m_confirmDone = false;
m_confirmFunctor(message, options);
while (true)
{
{
std::lock_guard<std::mutex> lock(m_confirmMutex);
if (m_confirmDone)
{
break;
}
}
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
}
return m_confirmResult;
}
void QtMainView::handleMessage(MessageForceEnterLicense* message)
{
m_forceLicenseScreenFunctor(message->licenseExpired);
@@ -144,3 +174,30 @@ void QtMainView::doForceLicenseScreen(bool expired)
{
m_window->forceEnterLicense(expired);
}
void QtMainView::doConfirm(const std::string& message, const std::vector<std::string>& options)
{
QMessageBox msgBox;
msgBox.setText(message.c_str());
for (const std::string& option : options)
{
msgBox.addButton(option.c_str(), QMessageBox::AcceptRole);
}
msgBox.exec();
m_confirmResult = -1;
for (int i = 0; i < msgBox.buttons().size(); i++)
{
if (msgBox.clickedButton() == msgBox.buttons().at(i))
{
m_confirmResult = i;
break;
}
}
std::lock_guard<std::mutex> lock(m_confirmMutex);
m_confirmDone = true;
}