2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <modules/Maps.h>
|
|
|
|
#include <modules/Gui.h>
|
|
|
|
#include <extra/MapExtras.h>
|
2011-07-16 04:26:31 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <stack>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include "blankslade.h"
|
2011-09-26 16:11:13 -06:00
|
|
|
#include "tinythread.h"
|
2011-07-16 04:26:31 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::stack;
|
|
|
|
using namespace DFHack;
|
2011-09-26 16:11:13 -06:00
|
|
|
static void runnable(void *);
|
|
|
|
static tthread::mutex * instance_mutex = 0;
|
2011-07-16 04:26:31 -06:00
|
|
|
static bool running = false;
|
2011-09-26 16:11:13 -06:00
|
|
|
static tthread::thread * QTThread;
|
2011-07-16 04:26:31 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result runqt (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "Qt Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
2011-09-26 16:11:13 -06:00
|
|
|
instance_mutex = new tthread::mutex();
|
2011-07-16 04:26:31 -06:00
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("runqt","Open an interactive Qt gui.",runqt));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
2011-07-18 08:22:49 -06:00
|
|
|
return CR_FAILURE;
|
2011-07-16 04:26:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result runqt (Core * c, vector <string> & parameters)
|
|
|
|
{
|
2011-09-26 16:11:13 -06:00
|
|
|
instance_mutex->lock();
|
2011-07-16 04:26:31 -06:00
|
|
|
if(!running)
|
|
|
|
{
|
|
|
|
running = true;
|
2011-09-26 16:11:13 -06:00
|
|
|
QTThread = new tthread::thread(runnable, 0);
|
2011-07-16 04:26:31 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c->con.printerr("The Qt test plugin is already running!\n");
|
|
|
|
}
|
2011-09-26 16:11:13 -06:00
|
|
|
instance_mutex->unlock();
|
2011-07-16 04:26:31 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-26 16:11:13 -06:00
|
|
|
static void runnable(void *)
|
2011-07-16 04:26:31 -06:00
|
|
|
{
|
2011-09-26 16:11:13 -06:00
|
|
|
int zero = 0;
|
2011-07-16 10:10:08 -06:00
|
|
|
QApplication app(zero, 0);
|
2011-07-16 04:26:31 -06:00
|
|
|
blankslade appGui;
|
|
|
|
appGui.show();
|
2011-09-26 16:11:13 -06:00
|
|
|
app.exec();
|
|
|
|
instance_mutex->lock();
|
2011-07-16 04:26:31 -06:00
|
|
|
running = false;
|
2011-09-26 16:11:13 -06:00
|
|
|
instance_mutex->unlock();
|
2011-07-16 04:26:31 -06:00
|
|
|
}
|