textual
[RRG-proxmark3.git] / client / src / proxgui.cpp
blobf8dd10fa430568e774d6e5e27fbe9385820baa5f
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // GUI functions
9 //-----------------------------------------------------------------------------
11 #include "proxgui.h"
13 #include <string.h>
14 #include "proxguiqt.h"
15 #include "proxmark3.h"
16 #include "ui.h" // for prints
18 static ProxGuiQT *gui = NULL;
19 static WorkerThread *main_loop_thread = NULL;
21 WorkerThread::WorkerThread(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) : script_cmds_file(script_cmds_file), script_cmd(script_cmd), stayInCommandLoop(stayInCommandLoop) {
24 WorkerThread::~WorkerThread() {
27 void WorkerThread::run() {
28 main_loop(script_cmds_file, script_cmd, stayInCommandLoop);
31 extern "C" void ShowGraphWindow(void) {
32 if (!gui) {
33 // Show a notice if X11/XQuartz isn't available
34 #if defined(__MACH__) && defined(__APPLE__)
35 PrintAndLogEx(WARNING, "You appear to be on a MacOS device without XQuartz.\nYou may need to install XQuartz (https://www.xquartz.org/) to make the plot work.");
36 #else
37 PrintAndLogEx(WARNING, "You appear to be on an environment without an X11 server or without DISPLAY environment variable set.\nPlot may not work until you resolve these issues.");
38 #endif
39 return;
42 gui->ShowGraphWindow();
45 extern "C" void HideGraphWindow(void) {
46 if (!gui)
47 return;
49 gui->HideGraphWindow();
52 extern "C" void RepaintGraphWindow(void) {
53 if (!gui)
54 return;
56 gui->RepaintGraphWindow();
59 extern "C" void MainGraphics(void) {
60 if (!gui)
61 return;
63 gui->MainLoop();
66 extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
67 #ifdef Q_WS_X11
68 if (getenv("DISPLAY") == NULL)
69 return;
70 #endif
71 #if QT_VERSION >= 0x050100
72 qunsetenv("SESSION_MANAGER");
73 #endif
74 main_loop_thread = new WorkerThread(script_cmds_file, script_cmd, stayInCommandLoop);
75 gui = new ProxGuiQT(argc, argv, main_loop_thread);
78 extern "C" void ExitGraphics(void) {
79 if (!gui)
80 return;
82 gui->Exit();
83 gui = NULL;