Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
popular_user_funcs.c
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  ~/xemu/gui/popular_user_funcs.c: popular/common functions for Xemu's UI abstraction
3  Copyright (C)2016-2022 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18 
19 
20 
21 #define UI_CB_QUIT() exit(0)
22 #define UI_CB_QUIT_() do { \
23  SDL_Event ev; \
24  ev.type = SDL_QUIT; \
25  SDL_PushEvent(&ev); \
26 } while(0)
27 
28 
29 void xemugui_cb_call_user_data ( const struct menu_st *m, int *query )
30 {
31  if (!query)
32  ((void(*)(void))(m->user_data))();
33 }
34 
35 void xemugui_cb_call_user_data_if_sure ( const struct menu_st *m, int *query )
36 {
37  if (!query && ARE_YOU_SURE(NULL, 0))
38  ((void(*)(void))(m->user_data))();
39 }
40 
41 void xemugui_cb_quit ( const struct menu_st *m, int *query )
42 {
43  if (!query)
44  UI_CB_QUIT();
45 }
46 
47 void xemugui_cb_show_info_window_text ( const struct menu_st *m, int *query )
48 {
49  if (!query)
50  INFO_WINDOW("%s", (const char*)m->user_data);
51 }
52 
53 void xemugui_cb_about_window ( const struct menu_st *m, int *query )
54 {
55  if (!query) {
57  "Xemu/%s %s\n"
58  "%s (%s)\n"
59  "Compiled by: %s at %s\n"
60  "Built with: %s for %s\n"
61  "\n"
62  "Copyright (C)" COPYRIGHT_YEARS " Gábor Lénárt (aka LGB) lgb@lgb.hu\nhttp://lgb.hu/\n"
63  "This software is part of the Xemu project:\nhttps://github.com/lgblgblgb/xemu\n"
64  "\n"
65  "This software is a GNU/GPL version 2 (or later) software.\n"
66  "<http://gnu.org/licenses/gpl.html>\n"
67  "This is free software; you are free to change and redistribute it.\n"
68  "There is NO WARRANTY, to the extent permitted by law."
69  ,
72  xemu_is_official_build() ? "official-build" : "custom-build",
74  XEMU_BUILDINFO_CC, XEMU_ARCH_NAME
75  );
76  }
77 }
78 
79 void xemugui_cb_call_quit_if_sure ( const struct menu_st *m, int *query )
80 {
82  UI_CB_QUIT();
83 }
84 
85 
86 #ifdef XEMU_ARCH_WIN
87 void xemugui_cb_sysconsole ( const struct menu_st *m, int *query )
88 {
89  if (query)
91  else
93 }
94 #endif
95 
96 
97 void xemugui_cb_windowsize ( const struct menu_st *m, int *query )
98 {
99  int mode_spec = (int)(uintptr_t)m->user_data;
100 #if 0
101  static int last_mode = 0;
102  if (query) {
103  if (mode_spec == last_mode)
105  return;
106  }
107  last_mode = mode_spec;
108 #endif
109  xemu_set_screen_mode(mode_spec);
110 }
111 
112 #ifdef HAVE_XEMU_EXEC_API
113 #include "xemu/emutools_files.h"
114 void xemugui_cb_native_os_prefdir_browser ( const struct menu_st *m, int *query )
115 {
116  if (!query)
118 }
119 static void _open_url ( const char *url_in, const char *par_list[] )
120 {
121  if (ARE_YOU_SURE("Can I open a web browser instance/window/tab to be able to serve your request?", i_am_sure_override | ARE_YOU_SURE_DEFAULT_YES)) {
122  char buffer[2048];
123  char *b = buffer + sprintf(buffer, "%s", url_in);
124  for (int i = 0; par_list && par_list[i]; i++)
125  if (!(i & 1))
126  b += sprintf(b, "%c%s", !i ? '?' : '&', par_list[i]);
127  else {
128  *b++ = '=';
129  const char *u = par_list[i];
130  while (*u)
131  if ((*u >= 'a' && *u <= 'z') || (*u >= '0' && *u <= '9') || (*u >= 'A' && *u <= 'Z'))
132  *b++ = *u++;
133  else
134  b += sprintf(b, "%%%02X", (unsigned char)(*u++));
135  }
136  *b = '\0';
137  DEBUGPRINT("BROWSER: requesting web resource to open: %s" NL, buffer);
139  }
140 }
141 void xemugui_cb_web_url ( const struct menu_st *m, int *query )
142 {
143  if (!query)
144  _open_url((char*)m->user_data, NULL);
145 }
146 #include <time.h>
147 #include "xemu/online_resources.h"
148 void xemugui_cb_web_help_main ( const struct menu_st *m, int *query )
149 {
150  if (query)
151  return;
152  char par[512];
153  sprintf(par, "o=%d\001v=%s\001b=%s\001t=%s\001T=%s\001p=%s\001u=" PRINTF_LLD "\001x=%s\002chk", // normal param list MUST end with \002 for future extension!
154  xemu_is_official_build(), // o=%d (official build?)
155  XEMU_BUILDINFO_CDATE, // v=%s (version data - formed from commit date actually)
156  XEMU_BUILDINFO_GIT, // b=%s (build info)
157  TARGET_NAME, // t=%s (target name)
158  TARGET_DESC, // T=%s (target description)
159  XEMU_ARCH_NAME, // p=%s (platform name)
160  (long long int)time(NULL), // u=%d (uts of the current time)
161  m->user_data != NULL ? (const char*)(m->user_data) : "null" // x=%s (user defined command)
162  );
163  const char *par_list[] = { XEMU_ONLINE_HELP_GET_VAR, par, NULL };
164  _open_url(XEMU_ONLINE_HELP_HANDLER_URL, par_list);
165 }
166 #endif
167 
168 #include "xemu/emutools_hid.h"
169 void xemugui_cb_osd_key_debugger ( const struct menu_st *m, int *query )
170 {
173  OSD(-1, -1, "OSD key debugger has been %sABLED", hid_show_osd_keys ? "EN" : "DIS");
174 }
175 
176 void xemugui_cb_set_mouse_grab ( const struct menu_st *m, int *query )
177 {
180  static int first_warning = 1;
181  if (allow_mouse_grab && first_warning) {
182  first_warning = 0;
183  INFO_WINDOW("Mouse grab mode has been enabled.\nLeft click into the emulator window to initiate.\nPress both SHIFTs together to cancel.");
184  }
185 }
186 
187 void xemugui_cb_set_integer_to_one ( const struct menu_st *m, int *query )
188 {
189  if (!query)
190  *(int*)(m->user_data) = 1;
191 }
192 
193 void xemugui_cb_toggle_int_inverted ( const struct menu_st *m, int *query )
194 {
195  XEMUGUI_RETURN_CHECKED_ON_QUERY(query, !*(int*)m->user_data);
196  *(int*)m->user_data = !*(int*)m->user_data;
197 }
198 
199 void xemugui_cb_toggle_int ( const struct menu_st *m, int *query )
200 {
201  XEMUGUI_RETURN_CHECKED_ON_QUERY(query, *(int*)m->user_data);
202  *(int*)m->user_data = !*(int*)m->user_data;
203 }
204 
205 #ifdef XEMU_CONFIGDB_SUPPORT
206 #include "xemu/emutools_config.h"
207 
208 /* Note: currently, this is not recommended to use functions to LOAD any config file.
209  This is because the configuration is loaded on Xemu start-up and many options are
210  parsed in a strict order bound to machine and emulation initialization, thus it's
211  kinda impossible to have valid state when loading a config file run-time "randomly". */
212 
213 void xemugui_cb_cfgfile ( const struct menu_st *m, int *query )
214 {
215  if (XEMU_UNLIKELY(query))
216  return;
217  const enum xemuguicfgfileop_type mode = (const enum xemuguicfgfileop_type)VOIDPTR_TO_INT(m->user_data);
218  char fnbuf[PATH_MAX + 1];
219  static char dir[PATH_MAX + 1] = "";
220  if (!*dir)
221  strcpy(dir, sdl_pref_dir);
222  switch (mode) {
223  case XEMUGUICFGFILEOP_SAVE_DEFAULT:
224  case XEMUGUICFGFILEOP_LOAD_DEFAULT:
225  strcpy(fnbuf, xemucfg_get_default_config_file_name());
226  break;
227  case XEMUGUICFGFILEOP_LOAD_CUSTOM:
228  case XEMUGUICFGFILEOP_SAVE_CUSTOM:
230  (mode == XEMUGUICFGFILEOP_LOAD_CUSTOM ? XEMUGUI_FSEL_OPEN : XEMUGUI_FSEL_SAVE) | XEMUGUI_FSEL_FLAG_STORE_DIR,
231  "Select config file",
232  dir,
233  fnbuf,
234  sizeof fnbuf
235  ))
236  return;
237  break;
238  }
239  switch (mode) {
240  case XEMUGUICFGFILEOP_LOAD_DEFAULT:
241  case XEMUGUICFGFILEOP_LOAD_CUSTOM:
242  xemucfg_parse_config_file(fnbuf, "Cannot load/parse config file");
243  break;
244  case XEMUGUICFGFILEOP_SAVE_DEFAULT:
245  case XEMUGUICFGFILEOP_SAVE_CUSTOM:
246  xemucfg_save_config_file(fnbuf, "# Saved from Xemu GUI by the user" NL NL, "Cannot save/store config file");
247  break;
248  }
249 }
250 #endif
xemugui_cb_show_info_window_text
void xemugui_cb_show_info_window_text(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:47
XEMU_ONLINE_HELP_GET_VAR
#define XEMU_ONLINE_HELP_GET_VAR
Definition: online_resources.h:7
TARGET_DESC
#define TARGET_DESC
Definition: xemu-target.h:2
sysconsole_is_open
int sysconsole_is_open
Definition: emutools.c:109
menu_st
Definition: emutools_gui.h:65
XEMUGUI_MENUFLAG_UNCHECKED
#define XEMUGUI_MENUFLAG_UNCHECKED
Definition: emutools_gui.h:41
UI_CB_QUIT
#define UI_CB_QUIT()
Definition: popular_user_funcs.c:21
xemuexec_open_native_file_browser
void xemuexec_open_native_file_browser(char *dir)
Definition: emutools_files.c:431
XEMU_ONLINE_HELP_HANDLER_URL
#define XEMU_ONLINE_HELP_HANDLER_URL
Definition: online_resources.h:6
XEMUGUI_MENUFLAG_ACTIVE_RADIO
#define XEMUGUI_MENUFLAG_ACTIVE_RADIO
Definition: emutools_gui.h:37
menu_st::user_data
const void * user_data
Definition: emutools_gui.h:69
xemugui_file_selector
int xemugui_file_selector(int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size)
Definition: emutools_gui.c:126
xemugui_cb_call_quit_if_sure
void xemugui_cb_call_quit_if_sure(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:79
i_am_sure_override
int i_am_sure_override
Definition: emutools.c:74
xemugui_cb_set_integer_to_one
void xemugui_cb_set_integer_to_one(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:187
hid_show_osd_keys
int hid_show_osd_keys
Definition: emutools_hid.c:34
INFO_WINDOW
#define INFO_WINDOW(...)
Definition: xep128.h:114
COPYRIGHT_YEARS
#define COPYRIGHT_YEARS
Definition: emutools_basicdefs.h:24
XEMU_BUILDINFO_GIT
const char XEMU_BUILDINFO_GIT[]
Definition: emutools_basicdefs.h:251
xemucfg_save_config_file
int xemucfg_save_config_file(const char *filename, const char *initial_part, const char *cry)
XEMUGUI_FSEL_FLAG_STORE_DIR
#define XEMUGUI_FSEL_FLAG_STORE_DIR
Definition: emutools_gui.h:28
xemugui_cb_osd_key_debugger
void xemugui_cb_osd_key_debugger(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:169
online_resources.h
XEMUGUI_FSEL_SAVE
#define XEMUGUI_FSEL_SAVE
Definition: emutools_gui.h:27
TARGET_NAME
#define TARGET_NAME
Definition: xemu-target.h:1
emutools_files.h
XEMU_BUILDINFO_CC
const char XEMU_BUILDINFO_CC[]
Definition: emutools_basicdefs.h:251
DEBUGPRINT
#define DEBUGPRINT(...)
Definition: emutools_basicdefs.h:171
xemu_is_official_build
int xemu_is_official_build(void)
Definition: emutools_buildinfo.c:33
VOIDPTR_TO_INT
#define VOIDPTR_TO_INT(x)
Definition: emutools_basicdefs.h:270
allow_mouse_grab
int allow_mouse_grab
Definition: emutools.c:118
xemucfg_parse_config_file
int xemucfg_parse_config_file(const char *filename_in, const char *open_fail_msg)
sysconsole_toggle
int sysconsole_toggle(int set)
Definition: emutools.c:1455
xemugui_cb_call_user_data_if_sure
void xemugui_cb_call_user_data_if_sure(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:35
dir
DIR * dir
Definition: cpmfs.c:46
xemucfg_get_default_config_file_name
const char * xemucfg_get_default_config_file_name(void)
xemugui_cb_call_user_data
void xemugui_cb_call_user_data(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:29
mode
int mode
Definition: vera.c:61
NL
#define NL
Definition: fat32.c:37
emutools_config.h
xemugui_cb_toggle_int
void xemugui_cb_toggle_int(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:199
XEMUGUI_FSEL_OPEN
#define XEMUGUI_FSEL_OPEN
Definition: emutools_gui.h:26
PRINTF_LLD
#define PRINTF_LLD
Definition: emutools_basicdefs.h:145
xemugui_cb_quit
void xemugui_cb_quit(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:41
xemugui_cb_toggle_int_inverted
void xemugui_cb_toggle_int_inverted(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:193
ARE_YOU_SURE_DEFAULT_YES
#define ARE_YOU_SURE_DEFAULT_YES
Definition: emutools.h:125
XEMU_BUILDINFO_CDATE
const char XEMU_BUILDINFO_CDATE[]
Definition: emutools_basicdefs.h:251
ARE_YOU_SURE
int ARE_YOU_SURE(const char *s, int flags)
Definition: emutools.c:1202
OSD
#define OSD(...)
Definition: xep128.h:100
XEMU_BUILDINFO_ON
const char XEMU_BUILDINFO_ON[]
str_are_you_sure_to_exit
const char * str_are_you_sure_to_exit
Definition: emutools.c:75
xemugui_cb_about_window
void xemugui_cb_about_window(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:53
XEMUGUI_RETURN_CHECKED_ON_QUERY
#define XEMUGUI_RETURN_CHECKED_ON_QUERY(query, status)
Definition: emutools_gui.h:55
xemugui_cb_set_mouse_grab
void xemugui_cb_set_mouse_grab(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:176
emutools_hid.h
xemugui_cb_windowsize
void xemugui_cb_windowsize(const struct menu_st *m, int *query)
Definition: popular_user_funcs.c:97
xemu_set_screen_mode
void xemu_set_screen_mode(int setting)
Definition: emutools.c:343
XEMU_BUILDINFO_AT
const char XEMU_BUILDINFO_AT[]
Definition: emutools_basicdefs.h:251
sdl_pref_dir
char * sdl_pref_dir
Definition: emutools.c:97
XEMUGUI_MENUFLAG_CHECKED
#define XEMUGUI_MENUFLAG_CHECKED
Definition: emutools_gui.h:39
XEMU_UNLIKELY
#define XEMU_UNLIKELY(__x__)
Definition: emutools_basicdefs.h:125