cutter/src/CutterApplication.h
Florian Märkl 51c0a3d469
Construct and destruct CutterCore singleton locally (Fix #2704) (#2994)
Using Q_GLOBAL_STATIC meant that the CutterCore was destructed late as
part of a binary destructor. It would then free the RzCore, calling for
example the fini callbacks of all plugins. However global destructors in
shared library plugins may have already been run at this point, leading
to for example rz-ghidra's decompiler_mutex being used after
destruction.
Instead of the Q_GLOBAL_STATIC-managed global object, we are now
handling the lifetime of the CutterCore ourselves and only injecting its
instance to be accessed globally. This can also be a first step towards
making the core instance completely local.
2022-07-09 12:48:48 +02:00

72 lines
1.6 KiB
C++

#ifndef CUTTERAPPLICATION_H
#define CUTTERAPPLICATION_H
#include <QEvent>
#include <QApplication>
#include <QList>
#include <QProxyStyle>
#include "core/MainWindow.h"
enum class AutomaticAnalysisLevel { Ask, None, AAA, AAAA };
struct CutterCommandLineOptions
{
QStringList args;
AutomaticAnalysisLevel analysisLevel = AutomaticAnalysisLevel::Ask;
InitialOptions fileOpenOptions;
QString pythonHome;
bool outputRedirectionEnabled = true;
bool enableCutterPlugins = true;
bool enableRizinPlugins = true;
};
class CutterApplication : public QApplication
{
Q_OBJECT
public:
CutterApplication(int &argc, char **argv);
~CutterApplication();
MainWindow *getMainWindow() { return mainWindow; }
void launchNewInstance(const QStringList &args = {});
protected:
bool event(QEvent *e);
private:
/**
* @brief Load and translations depending on Language settings
* @return true on success
*/
bool loadTranslations();
/**
* @brief Parse commandline options and store them in a structure.
* @return false if options have error
*/
bool parseCommandLineOptions();
private:
bool m_FileAlreadyDropped;
CutterCore core;
MainWindow *mainWindow;
CutterCommandLineOptions clOptions;
};
/**
* @brief CutterProxyStyle is used to force shortcuts displaying in context menu
*/
class CutterProxyStyle : public QProxyStyle
{
Q_OBJECT
public:
/**
* @brief it is enough to get notification about QMenu polishing to force shortcut displaying
*/
void polish(QWidget *widget) override;
};
#endif // CUTTERAPPLICATION_H