e7fdae6c402c2d59aeb6d37de05d2ed215199e9a
[proxmark3-svn] / client / proxgui.cpp
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 //-----------------------------------------------------------------------------
10
11 #include "proxgui.h"
12 #include "proxguiqt.h"
13 #include "proxmark3.h"
14
15 static ProxGuiQT *gui = NULL;
16 static WorkerThread *main_loop_thread = NULL;
17
18 WorkerThread::WorkerThread(char *script_cmds_file, bool usb_present) : script_cmds_file(script_cmds_file), usb_present(usb_present)
19 {
20 }
21
22 WorkerThread::~WorkerThread()
23 {
24 }
25
26 void WorkerThread::run() {
27 main_loop(script_cmds_file, usb_present);
28 }
29
30 extern "C" void ShowGraphWindow(void)
31 {
32 if (!gui)
33 return;
34
35 gui->ShowGraphWindow();
36 }
37
38 extern "C" void HideGraphWindow(void)
39 {
40 if (!gui)
41 return;
42
43 gui->HideGraphWindow();
44 }
45
46 extern "C" void RepaintGraphWindow(void)
47 {
48 if (!gui)
49 return;
50
51 gui->RepaintGraphWindow();
52 }
53
54 extern "C" void MainGraphics(void)
55 {
56 if (!gui)
57 return;
58
59 main_loop_thread->start();
60 gui->MainLoop();
61 }
62
63 extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present)
64 {
65 #ifdef Q_WS_X11
66 bool useGUI = getenv("DISPLAY") != 0;
67 #else
68 bool useGUI = true;
69 #endif
70 if (!useGUI)
71 return;
72
73 gui = new ProxGuiQT(argc, argv);
74 main_loop_thread = new WorkerThread(script_cmds_file, usb_present);
75 QObject::connect(main_loop_thread, SIGNAL(finished()), main_loop_thread, SLOT(deleteLater()));
76 QObject::connect(main_loop_thread, SIGNAL(finished()), gui, SLOT(_Exit()));
77 }
78
79
80 extern "C" void ExitGraphics(void)
81 {
82 if (!gui)
83 return;
84
85 gui->Exit();
86 gui = NULL;
87 }
Impressum, Datenschutz