1 /*****************************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2, or (at your option)
6    any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 *****************************************************************************/
13 #ifdef HAVE_CONFIG_H
14 #include <fc_config.h>
15 #endif
16 
17 // Qt
18 #include <QFileDialog>
19 #include <QString>
20 
21 // utility
22 #include "shared.h"
23 
24 // common
25 #include "featured_text.h"
26 
27 /* client/luascript */
28 #include "script_client.h"
29 
30 // gui-qt
31 #include "fc_client.h"
32 #include "luaconsole.h"
33 #include "qtg_cxxside.h"
34 
35 QString qlua_filename;
36 
37 /*****************************************************************************
38   Popup the lua console inside the main-window, and optionally raise it.
39 *****************************************************************************/
luaconsole_dialog_popup(bool raise)40 void luaconsole_dialog_popup(bool raise)
41 {
42   /* lua output is in chat */
43 }
44 
45 /*****************************************************************************
46   Return true if the lua console is open.
47 *****************************************************************************/
luaconsole_dialog_is_open(void)48 bool luaconsole_dialog_is_open(void)
49 {
50   return true;
51 }
52 
53 /*****************************************************************************
54   Update the lua console.
55 *****************************************************************************/
real_luaconsole_dialog_update(void)56 void real_luaconsole_dialog_update(void)
57 {
58 }
59 
60 /*****************************************************************************
61   Appends the string to the chat output window.  The string should be
62   inserted on its own line, although it will have no newline.
63 *****************************************************************************/
real_luaconsole_append(const char * astring,const struct text_tag_list * tags)64 void real_luaconsole_append(const char *astring,
65                             const struct text_tag_list *tags)
66 {
67   qtg_real_output_window_append(astring, tags, 0);
68 }
69 
70 
71 /***************************************************************************
72   Load and execute lua script
73 ***************************************************************************/
qload_lua_script()74 void qload_lua_script()
75 {
76   QString str;
77 
78   str = QString(_("Lua scripts")) + QString(" (*.lua)");
79   qlua_filename = QFileDialog::getOpenFileName(gui()->central_wdg,
80                                               _("Load lua script"),
81                                               QDir::homePath(), str);
82   if (!qlua_filename.isEmpty()) {
83     script_client_do_file(qlua_filename.toLocal8Bit().constData());
84   }
85 }
86 
87 /***************************************************************************
88   Reload last lua script
89 ***************************************************************************/
qreload_lua_script()90 void qreload_lua_script()
91 {
92   if (!qlua_filename.isEmpty()) {
93     script_client_do_file(qlua_filename.toLocal8Bit().constData());
94   }
95 }
96