<commit_before>/*******************************************************************************

Licensed to the OpenCOR team under one or more contributor license agreements.
See the NOTICE.txt file distributed with this work for additional information
regarding copyright ownership. The OpenCOR team licenses this file to you under
the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

*******************************************************************************/

//==============================================================================
// Main window
//==============================================================================

#include "centralwidget.h"
#include "common.h"
#include "dockwidget.h"
#include "fileinterface.h"
#include "i18ninterface.h"
#include "mainwindow.h"
#include "pluginmanager.h"
#include "pluginswindow.h"
#include "preferenceswindow.h"
#include "solverinterface.h"
#include "utils.h"

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

#include "ui_mainwindow.h"

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

#ifdef Q_OS_WIN
    #include <windows.h>
#endif

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

#include <QAction>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#ifdef Q_OS_MAC
    #include <QShortcut>
#endif
#include <QUrl>

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

#include <QtSingleApplication>

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

namespace OpenCOR {

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

static const QString SystemLocale  = "";
static const QString EnglishLocale = "en";
static const QString FrenchLocale  = "fr";

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

static const QString CorePlugin = "Core";
static const QString HelpPlugin = "Help";

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

MainWindow::MainWindow(SharedTools::QtSingleApplication *pApp) :
    QMainWindow(),
    mGui(new Ui::MainWindow),
    mLocale(QString()),
    mFileNewMenu(0),
    mViewOrganisationMenu(0),
    mViewSeparator(0),
    mViewMenus(QMap<Plugin *, QMenu *>()),
    mViewActions(QMap<Plugin *, QAction *>()),
    mViewPlugin(0),
    mDockedWidgetsVisible(true),
    mDockedWidgetsState(QByteArray())
{
    // Make sure that OpenCOR can handle a file opening request (from the
    // operating system), as well as a message sent by another instance of
    // itself

    QObject::connect(pApp, SIGNAL(fileOpenRequest(const QString &)),
                     this, SLOT(fileOpenRequest(const QString &)));
    QObject::connect(pApp, SIGNAL(messageReceived(const QString &, QObject *)),
                     this, SLOT(messageReceived(const QString &, QObject *)));

    // Create our settings object

    mSettings = new QSettings(SettingsOrganization, SettingsApplication);

    // Create our plugin manager (which will automatically load our various
    // plugins)

    mPluginManager = new PluginManager(qApp);

    // Set up the GUI
    // Note: the application icon (which needs to be set for Linux, but not for
    //       Windows or OS X, since it's set through CMake in those cases (see
    //       CMakeLists.txt)) is set within the GUI file. This being said, it's
    //       good to have it set for all three platforms, since it can then be
    //       used in, for example, the about box...

    mGui->setupUi(this);
//---GRY--- BEGIN
// THIS IS TEMPORARY, I.E. WHILE WE DON'T FULLY SUPPORT USER PREFERENCES...
mGui->actionPreferences->setEnabled(false);
mGui->actionPreferences->setVisible(false);
//---GRY--- END

    // Set the role of some of our menu items, so that OS X can move them into
    // the application menu

    mGui->actionQuit->setMenuRole(QAction::QuitRole);
    mGui->actionPreferences->setMenuRole(QAction::PreferencesRole);
    mGui->actionAbout->setMenuRole(QAction::AboutRole);

    // Title of our main window
    // Note: we don't set it in our .ui file since this will require
    //       'translating' it in other languages...

    setWindowTitle(qApp->applicationName());

    // Customise our docked widgets action and handle it through a connection
    // Note: Ctrl+Space doesn't work on OS X, so ideally we would add the Alt
    //       key (since it's next to it, but it doesn't work either), so in the
    //       we add the Meta key...

#ifdef Q_OS_MAC
    mGui->actionDockedWidgets->setShortcut(QKeySequence(Qt::CTRL|Qt::META|Qt::Key_Space));
#else
    mGui->actionDockedWidgets->setShortcut(QKeySequence(Qt::CTRL|Qt::Key_Space));
#endif

    connect(mGui->actionDockedWidgets, SIGNAL(triggered(bool)),
            this, SLOT(showDockedWidgets(const bool &)));

    // A connection to handle the status bar

    connect(mGui->actionStatusBar, SIGNAL(triggered(bool)),
            statusBar(), SLOT(setVisible(bool)));

    // Some connections to handle our various menu items

    connect(mGui->actionQuit, SIGNAL(triggered()),
            this, SLOT(close()));
    connect(mGui->actionResetAll, SIGNAL(triggered()),
            this, SLOT(resetAll()));

    // Set the shortcuts of some actions
    // Note: we do it here, so that we can use standard shortcuts (whenever
    //       possible)...

#if defined(Q_OS_WIN)
    // Note: QKeySequence::Quit corresponds to Alt+F4 on Windows, but it doesn't<commit_msg>Some minor cleaning up [ci skip].<commit_after>/*******************************************************************************

Licensed to the OpenCOR team under one or more contributor license agreements.
See the NOTICE.txt file distributed with this work for additional information
regarding copyright ownership. The OpenCOR team licenses this file to you under
the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

*******************************************************************************/

//==============================================================================
// Main window
//==============================================================================

#include "centralwidget.h"
#include "common.h"
#include "dockwidget.h"
#include "fileinterface.h"
#include "i18ninterface.h"
#include "mainwindow.h"
#include "pluginmanager.h"
#include "pluginswindow.h"
#include "preferenceswindow.h"
#include "solverinterface.h"
#include "utils.h"

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

#include "ui_mainwindow.h"

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

#ifdef Q_OS_WIN
    #include <windows.h>
#endif

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

#include <QAction>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#ifdef Q_OS_MAC
    #include <QShortcut>
#endif
#include <QUrl>

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

#include <QtSingleApplication>

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

namespace OpenCOR {

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

static const QString SystemLocale  = "";
static const QString EnglishLocale = "en";
static const QString FrenchLocale  = "fr";

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

static const QString CorePlugin = "Core";
static const QString HelpPlugin = "Help";

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

MainWindow::MainWindow(SharedTools::QtSingleApplication *pApp) :
    QMainWindow(),
    mGui(new Ui::MainWindow),
    mLocale(QString()),
    mFileNewMenu(0),
    mViewOrganisationMenu(0),
    mViewSeparator(0),
    mViewMenus(QMap<Plugin *, QMenu *>()),
    mViewActions(QMap<Plugin *, QAction *>()),
    mViewPlugin(0),
    mDockedWidgetsVisible(true),
    mDockedWidgetsState(QByteArray())
{
    // Make sure that OpenCOR can handle a file opening request (from the
    // operating system), as well as a message sent by another instance of
    // itself

    QObject::connect(pApp, SIGNAL(fileOpenRequest(const QString &)),
                     this, SLOT(fileOpenRequest(const QString &)));
    QObject::connect(pApp, SIGNAL(messageReceived(const QString &, QObject *)),
                     this, SLOT(messageReceived(const QString &, QObject *)));

    // Create our settings object

    mSettings = new QSettings(SettingsOrganization, SettingsApplication);

    // Create our plugin manager (which will automatically load our various
    // plugins)

    mPluginManager = new PluginManager(qApp);

    // Set up the GUI
    // Note: the application icon (which needs to be set for Linux, but not for
    //       Windows or OS X, since it's set through CMake in those cases (see
    //       CMakeLists.txt)) is set within the GUI file. This being said, it's
    //       good to have it set for all three platforms, since it can then be
    //       used in, for example, the about box...

    mGui->setupUi(this);
//---GRY--- BEGIN
// THIS IS TEMPORARY, I.E. WHILE WE DON'T FULLY SUPPORT USER PREFERENCES...
mGui->actionPreferences->setEnabled(false);
mGui->actionPreferences->setVisible(false);
//---GRY--- END

    // Set the role of some of our menu items, so that OS X can move them into
    // the application menu

    mGui->actionQuit->setMenuRole(QAction::QuitRole);
    mGui->actionPreferences->setMenuRole(QAction::PreferencesRole);
    mGui->actionAbout->setMenuRole(QAction::AboutRole);

    // Title of our main window
    // Note: we don't set it in our .ui file since this will require
    //       'translating' it in other languages...

    setWindowTitle(qApp->applicationName());

    // Customise our docked widgets action and handle it through a connection
    // Note: Ctrl+Space doesn't work on OS X, so ideally we would add the Alt
    //       key (since it's next to it, but it doesn't work either), so in the
    //       we add the Meta key...

#if defined(Q_OS_MAC)
    mGui->actionDockedWidgets->setShortcut(QKeySequence(Qt::CTRL|Qt::META|Qt::Key_Space));
#else
    mGui->actionDockedWidgets->setShortcut(QKeySequence(Qt::CTRL|Qt::Key_Space));
#endif

    connect(mGui->actionDockedWidgets, SIGNAL(triggered(bool)),
            this, SLOT(showDockedWidgets(const bool &)));

    // A connection to handle the status bar

    connect(mGui->actionStatusBar, SIGNAL(triggered(bool)),
            statusBar(), SLOT(setVisible(bool)));

    // Some connections to handle our various menu items

    connect(mGui->actionQuit, SIGNAL(triggered()),
            this, SLOT(close()));
    connect(mGui->actionResetAll, SIGNAL(triggered()),
            this, SLOT(resetAll()));

    // Set the shortcuts of some actions
    // Note: we do it here, so that we can use standard shortcuts (whenever
    //       possible)...

#if defined(Q_OS_WIN)
    // Note: QKeySequence::Quit corresponds to Alt+F4 on Windows, but it doesn't
{'fraction_non_alphanumeric': 0.24733037621159848, 'fraction_numerical': 0.0018071299490717923, 'mean_word_length': 4.314273243125273, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1503580', 'n_tokens_mistral': 3239, 'n_tokens_neox': 3046, 'n_words': 1026}