Modified some APIs for more consistence

Correct null check after create_cutter_plugin()

Fix cutter.core()
This commit is contained in:
xarkes 2019-02-11 20:05:53 +01:00 committed by Florian Märkl
parent 18b40a8b90
commit 436842222e
7 changed files with 39 additions and 8 deletions

View File

@ -171,7 +171,7 @@ CutterCore::CutterCore(QObject *parent) :
} }
CutterCore *CutterCore::getInstance() CutterCore *CutterCore::instance()
{ {
return uniqueInstance; return uniqueInstance;
} }

View File

@ -26,7 +26,7 @@
#define APPNAME "Cutter" #define APPNAME "Cutter"
#define Core() (CutterCore::getInstance()) #define Core() (CutterCore::instance())
/*! /*!
* \brief Type to be used for all kinds of addresses/offsets in r2 address space. * \brief Type to be used for all kinds of addresses/offsets in r2 address space.
@ -416,7 +416,7 @@ class CutterCore: public QObject
public: public:
explicit CutterCore(QObject *parent = nullptr); explicit CutterCore(QObject *parent = nullptr);
~CutterCore(); ~CutterCore();
static CutterCore *getInstance(); static CutterCore *instance();
AsyncTaskManager *getAsyncTaskManager() { return asyncTaskManager; } AsyncTaskManager *getAsyncTaskManager() { return asyncTaskManager; }

View File

@ -389,6 +389,11 @@ void MainWindow::addPluginDockWidget(QDockWidget *dockWidget, QAction *action)
updateDockActionChecked(action); updateDockActionChecked(action);
} }
void MainWindow::addMenuFileAction(QAction *action)
{
ui->menuFile->addAction(action);
}
void MainWindow::openNewFile(InitialOptions options, bool skipOptionsDialog) void MainWindow::openNewFile(InitialOptions options, bool skipOptionsDialog)
{ {
setFilename(options.filename); setFilename(options.filename);
@ -1162,3 +1167,18 @@ void MainWindow::addDockWidgetAction(QDockWidget *dockWidget, QAction *action)
{ {
this->dockWidgetActions[action] = dockWidget; this->dockWidgetActions[action] = dockWidget;
} }
/*!
* \brief Show a warning message box.
*
* This API can either be used in Cutter internals, or by Python plugins.
*/
void MainWindow::messageBoxWarning(QString title, QString message)
{
QMessageBox mb(this);
mb.setIcon(QMessageBox::Warning);
mb.setStandardButtons(QMessageBox::Ok);
mb.setWindowTitle(title);
mb.setText(message);
mb.exec();
}

View File

@ -104,6 +104,7 @@ public:
void addExtraWidget(QDockWidget *extraDock); void addExtraWidget(QDockWidget *extraDock);
void addPluginDockWidget(QDockWidget *dockWidget, QAction *action); void addPluginDockWidget(QDockWidget *dockWidget, QAction *action);
void addMenuFileAction(QAction *action);
void updateDockActionChecked(QAction * action); void updateDockActionChecked(QAction * action);
@ -111,6 +112,7 @@ public:
{ {
return filename; return filename;
} }
void messageBoxWarning(QString title, QString message);
public slots: public slots:
void finalizeOpen(); void finalizeOpen();

View File

@ -12,7 +12,7 @@ PyObject *api_version(PyObject *self, PyObject *null)
{ {
Q_UNUSED(self) Q_UNUSED(self)
Q_UNUSED(null) Q_UNUSED(null)
return PyUnicode_FromString("Cutter version " CUTTER_VERSION_FULL); return PyUnicode_FromString(CUTTER_VERSION_FULL);
} }
PyObject *api_cmd(PyObject *self, PyObject *args) PyObject *api_cmd(PyObject *self, PyObject *args)

View File

@ -126,7 +126,7 @@ CutterPlugin *PluginManager::loadPythonPlugin(const char *moduleName)
PyObject *createPluginFunc = PyObject_GetAttrString(pluginModule, "create_cutter_plugin"); PyObject *createPluginFunc = PyObject_GetAttrString(pluginModule, "create_cutter_plugin");
if (!createPluginFunc || !PyCallable_Check(createPluginFunc)) { if (!createPluginFunc || !PyCallable_Check(createPluginFunc)) {
qWarning() << "Plugin module does not contain create_plugin() function:" << QString(moduleName); qWarning() << "Plugin module does not contain create_cutter_plugin() function:" << QString(moduleName);
if (createPluginFunc) { if (createPluginFunc) {
Py_DECREF(createPluginFunc); Py_DECREF(createPluginFunc);
} }
@ -137,14 +137,23 @@ CutterPlugin *PluginManager::loadPythonPlugin(const char *moduleName)
PyObject *pluginObject = PyObject_CallFunction(createPluginFunc, nullptr); PyObject *pluginObject = PyObject_CallFunction(createPluginFunc, nullptr);
Py_DECREF(createPluginFunc); Py_DECREF(createPluginFunc);
Py_DECREF(pluginModule); Py_DECREF(pluginModule);
if (!pluginObject) {
qWarning() << "Plugin's create_cutter_plugin() function failed.";
PyErr_Print();
return nullptr;
}
PythonToCppFunc pythonToCpp = Shiboken::Conversions::isPythonToCppPointerConvertible(reinterpret_cast<SbkObjectType *>(SbkCutterBindingsTypes[SBK_CUTTERPLUGIN_IDX]), pluginObject); PythonToCppFunc pythonToCpp = Shiboken::Conversions::isPythonToCppPointerConvertible(reinterpret_cast<SbkObjectType *>(SbkCutterBindingsTypes[SBK_CUTTERPLUGIN_IDX]), pluginObject);
if (!pythonToCpp) { if (!pythonToCpp) {
qWarning() << "Plugin's create_plugin() function did not return an instance of CutterPlugin:" << QString(moduleName); qWarning() << "Plugin's create_cutter_plugin() function did not return an instance of CutterPlugin:" << QString(moduleName);
return nullptr; return nullptr;
} }
CutterPlugin *plugin; CutterPlugin *plugin;
pythonToCpp(pluginObject, &plugin); pythonToCpp(pluginObject, &plugin);
if (!plugin) {
qWarning() << "Error during the setup of CutterPlugin:" << QString(moduleName);
return nullptr;
}
return plugin; return plugin;
} }
#endif #endif

View File

@ -9,4 +9,4 @@ def cmdj(command):
def core(): def core():
return CutterCore.getInstance() return CutterCore.instance()