Skip to content

Commit

Permalink
Main window: slight improvement to the way we use the Core plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Apr 30, 2018
1 parent 6a2ff90 commit 3d2728f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/mainwindow.cpp
Expand Up @@ -96,6 +96,7 @@ MainWindow::MainWindow(const QString &pApplicationDate) :
mLoadedGuiPlugins(Plugins()),
mLoadedPreferencesPlugins(Plugins()),
mLoadedWindowPlugins(Plugins()),
mCoreInterface(0),
mRawLocale(QString()),
mMenus(QMap<QString, QMenu *>()),
mFileNewMenu(0),
Expand Down Expand Up @@ -158,6 +159,11 @@ MainWindow::MainWindow(const QString &pApplicationDate) :
mLoadedWindowPlugins << plugin;
}

// Retrieve our Core plugin's interface, should the Core plugin be loaded

if (mPluginManager->corePlugin())
mCoreInterface = qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance());

// Set up the GUI

mGui->setupUi(this);
Expand Down Expand Up @@ -383,11 +389,8 @@ void MainWindow::closeEvent(QCloseEvent *pEvent)

bool canClose = true;

if (mPluginManager->corePlugin()) {
canClose = qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->canClose();
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...
}
if (mCoreInterface)
canClose = mCoreInterface->canClose();

// Close ourselves, if possible

Expand Down Expand Up @@ -691,11 +694,8 @@ void MainWindow::loadSettings()
// settings
// Note: this is similar to initializePlugin() vs. pluginsInitialized()...

if (mPluginManager->corePlugin()) {
qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->settingsLoaded(mPluginManager->loadedPlugins());
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...
}
if (mCoreInterface)
mCoreInterface->settingsLoaded(mPluginManager->loadedPlugins());

// Remove the File menu when on macOS, should no plugins be loaded
// Note: our File menu should only contain the Exit menu item, but on macOS
Expand Down Expand Up @@ -986,11 +986,8 @@ void MainWindow::handleArguments(const QStringList &pArguments)
arguments << stringFromPercentEncoding(argument);
}

if (!arguments.isEmpty() && mPluginManager->corePlugin()) {
qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->handleArguments(arguments);
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...
}
if (!arguments.isEmpty() && mCoreInterface)
mCoreInterface->handleArguments(arguments);

// Make sure that our status bar is shown/hidden, depending on its action's
// status
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.h
Expand Up @@ -50,6 +50,7 @@ namespace OpenCOR {

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

class CoreInterface;
class PluginManager;

//==============================================================================
Expand Down Expand Up @@ -92,6 +93,8 @@ class MainWindow : public QMainWindow
Plugins mLoadedPreferencesPlugins;
Plugins mLoadedWindowPlugins;

CoreInterface *mCoreInterface;

QString mRawLocale;

QTranslator mQtBaseTranslator;
Expand Down

0 comments on commit 3d2728f

Please sign in to comment.