Skip to content

Commit

Permalink
Merge c129f19 into fb9da46
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Sep 12, 2018
2 parents fb9da46 + c129f19 commit bf7c178
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
1 change: 1 addition & 0 deletions doc/downloads/index.js
Expand Up @@ -37,6 +37,7 @@ var jsonData = { "versions": [
}
],
"changes": [
{ "change": "<strong>General:</strong> only handle a URL when OpenCOR is visible and no modal dialog is active (see issue <a href=\"https://github.com/opencor/opencor/issues/1802\">#1802</a>)." },
{ "change": "<strong>Third-party libraries:</strong> upgraded <a href=\"https://libgit2.github.com/\">libgit2</a> to version 0.27.4 (see issue <a href=\"https://github.com/opencor/opencor/issues/1799\">#1799</a>)." }
]
},
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Expand Up @@ -27,12 +27,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "guiapplication.h"
#include "guiutils.h"
#include "mainwindow.h"
#include "splashscreenwindow.h"

#ifdef Q_OS_MAC
#include "macos.h"
#endif

#ifndef QT_DEBUG
#include "splashscreenwindow.h"
#endif

//==============================================================================

#include <QDir>
Expand Down
28 changes: 27 additions & 1 deletion src/mainwindow.cpp
Expand Up @@ -55,6 +55,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QRect>
#include <QSettings>
#include <QShortcut>
#include <QTimer>
#include <QUrl>
#include <QWindow>

Expand Down Expand Up @@ -1038,8 +1039,13 @@ void MainWindow::openFileOrHandleUrl(const QString &pFileNameOrOpencorUrl)

//==============================================================================

void MainWindow::handleUrl(const QUrl &pUrl)
void MainWindow::doHandleUrl(const QUrl &pUrl)
{
// Make sure that no modal dialog is active

if (qApp->activeModalWidget())
return;

// Handle the action that was passed to OpenCOR

QString actionName = pUrl.authority();
Expand Down Expand Up @@ -1096,6 +1102,26 @@ void MainWindow::handleUrl(const QUrl &pUrl)

//==============================================================================

void MainWindow::handleUrl(const QUrl &pUrl)
{
// Handle the action that was passed to OpenCOR
// Note: we want to make sure that we are visible before handling a URL,
// hence we do this through a single shot. Indeed, otherwise to start
// OpenCOR through our URL scheme (e.g. opencor://openAboutDialog)
// will result in the dialog appearing before we become visible, which
// doesn't look neat. Not only that, but it might in some cases (e.g.
// opencor://openPreferencesDialog) result in some GUI problems (see
// issue #1802). When it comes to opening a file / files through our
// URL scheme, it's kind of the same in the sense that without a
// single shot, the file/s will get opened in the "background", which
// is not neat either...

QTimer::singleShot(0, this, std::bind(&MainWindow::doHandleUrl,
this, pUrl));
}

//==============================================================================

void MainWindow::handleMessage(const QString &pMessage)
{
// We have just received a message, which means that the user tried to run
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Expand Up @@ -157,6 +157,7 @@ private slots:

void resetAll();

void doHandleUrl(const QUrl &pUrl);
void handleUrl(const QUrl &pUrl);
};

Expand Down
37 changes: 16 additions & 21 deletions src/splashscreenwindow.cpp
Expand Up @@ -129,38 +129,33 @@ void SplashScreenWindow::closeAndDeleteAfter(QWidget *pWindow)
{
// Wait for our window to expose itself

if (pWindow) {
QWindow *window = pWindow->windowHandle();
enum {
TimeOut = 1000,
ShortDelay = 10
};

if (window) {
enum {
TimeOut = 1000,
ShortDelay = 10
};

QElapsedTimer timer;
QWindow *window = pWindow->windowHandle();
QElapsedTimer timer;
#ifndef Q_OS_WIN
struct timespec shortDelaySpec = { ShortDelay/1000, 1000000*(ShortDelay%1000) };
struct timespec shortDelaySpec = { ShortDelay/1000, 1000000*(ShortDelay%1000) };
#endif

timer.start();
timer.start();

while (!window->isExposed()) {
int remaining = int(TimeOut-timer.elapsed());
while (!window->isExposed()) {
int remaining = int(TimeOut-timer.elapsed());

if (remaining <= 0)
break;
if (remaining <= 0)
break;

QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);

#ifdef Q_OS_WIN
Sleep(ShortDelay);
Sleep(ShortDelay);
#else
nanosleep(&shortDelaySpec, nullptr);
nanosleep(&shortDelaySpec, nullptr);
#endif
}
}
}

// Close ourselves with a bit of a delay
Expand Down

0 comments on commit bf7c178

Please sign in to comment.