Convert gtk-glade frontend to gtk config machinery

This commit is contained in:
riccardom 2010-01-29 10:45:38 +00:00
parent 7fefaca661
commit 9b1d5c4ef2
2 changed files with 9 additions and 70 deletions

View File

@ -26,7 +26,8 @@ desmume_glade_SOURCES = \
dTools/callbacks_dtools.h \
dTools/dTools_display.h \
gdk_3Demu.cpp gdk_3Demu.h \
../sndsdl.h ../sndsdl.cpp ../ctrlssdl.h ../ctrlssdl.cpp
../sndsdl.h ../sndsdl.cpp ../ctrlssdl.h ../ctrlssdl.cpp \
../gtk/desmume_config.h ../gtk/desmume_config.cpp
desmume_glade_LDADD = ../libdesmume.a \
$(SDL_LIBS) $(GTKGLEXT_LIBS) $(LIBGLADE_LIBS) \

View File

@ -29,6 +29,8 @@
#include "desmume.h"
#include "firmware.h"
#include "gtk/desmume_config.h"
#ifdef GDB_STUB
#include "../gdbstub.h"
#endif
@ -335,72 +337,6 @@ gchar * get_ui_file (const char *filename)
}
/* ***** ***** CONFIG FILE ***** ***** */
char * CONFIG_FILE;
static int Read_ConfigFile()
{
int i, tmp;
GKeyFile * keyfile = g_key_file_new();
GError * error = NULL;
load_default_config(gtk_kb_cfg);
g_key_file_load_from_file(keyfile, CONFIG_FILE, G_KEY_FILE_NONE, 0);
/* Load keypad keys */
for(i = 0; i < NB_KEYS; i++)
{
tmp = g_key_file_get_integer(keyfile, "KEYS", key_names[i], &error);
if (error != NULL) {
g_error_free(error);
error = NULL;
} else {
keyboard_cfg[i] = tmp;
}
}
/* Load joypad keys */
for(i = 0; i < NB_KEYS; i++)
{
tmp = g_key_file_get_integer(keyfile, "JOYKEYS", key_names[i], &error);
if (error != NULL) {
g_error_free(error);
error = NULL;
} else {
joypad_cfg[i] = tmp;
}
}
g_key_file_free(keyfile);
return 0;
}
static int Write_ConfigFile()
{
int i;
GKeyFile * keyfile;
gchar *contents;
keyfile = g_key_file_new();
for(i = 0; i < NB_KEYS; i++)
{
g_key_file_set_integer(keyfile, "KEYS", key_names[i], keyboard_cfg[i]);
g_key_file_set_integer(keyfile, "JOYKEYS", key_names[i], joypad_cfg[i]);
}
contents = g_key_file_to_data(keyfile, 0, 0);
g_file_set_contents(CONFIG_FILE, contents, -1, 0);
g_free(contents);
g_key_file_free(keyfile);
return 0;
}
/*
* The thread handling functions needed by the GDB stub code.
*/
@ -439,6 +375,7 @@ common_gtk_glade_main( struct configured_features *my_config) {
/* the firmware settings */
struct NDS_fw_config_data fw_config;
gchar *uifile;
GKeyFile *keyfile;
/* default the firmware settings, they may get changed later */
NDS_FillDefaultFirmwareConfigData( &fw_config);
@ -512,8 +449,7 @@ common_gtk_glade_main( struct configured_features *my_config) {
/* Initialize joysticks */
if(!init_joy()) return 1;
CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
Read_ConfigFile();
keyfile = desmume_config_read_file(gtk_kb_cfg);
/* load the interface */
uifile = get_ui_file("DeSmuMe.glade");
@ -589,7 +525,9 @@ common_gtk_glade_main( struct configured_features *my_config) {
uninit_joy();
SDL_Quit();
Write_ConfigFile();
desmume_config_update_keys(keyfile);
desmume_config_update_joykeys(keyfile);
desmume_config_dispose(keyfile);
return EXIT_SUCCESS;
}