GTK: Replace GtkFileChooserDialog with GtkFileChooserNative

This one uses the native file chooser the user is used to, which can be
GTK’s on Linux but a more familiar one on other OSes.  If
xdg-desktop-portal is installed, it can even use the DE’s native one on
Linux.
This commit is contained in:
Emmanuel Gil Peyrot 2020-08-29 12:26:35 +02:00
parent c1efe4f475
commit cc9d7a1450
1 changed files with 80 additions and 162 deletions

View File

@ -977,15 +977,11 @@ void Pause()
static void LoadStateDialog() static void LoadStateDialog()
{ {
GtkFileFilter *pFilter_ds, *pFilter_any; GtkFileFilter *pFilter_ds, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_ds = gtk_file_filter_new(); pFilter_ds = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_ds, "*.ds*"); gtk_file_filter_add_pattern(pFilter_ds, "*.ds*");
gtk_file_filter_set_name(pFilter_ds, "DeSmuME binary (.ds*)"); gtk_file_filter_set_name(pFilter_ds, "DeSmuME binary (.ds*)");
@ -995,26 +991,22 @@ static void LoadStateDialog()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Load State From ...", pFileSelection = gtk_file_chooser_native_new("Load State From ...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Open", "_Cancel");
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_ds); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_ds);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
if(savestate_load(sPath) == false ) { if(savestate_load(sPath) == false ) {
GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
@ -1026,25 +1018,18 @@ static void LoadStateDialog()
} }
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void RecordMovieDialog() static void RecordMovieDialog()
{ {
GtkFileFilter *pFilter_dsm, *pFilter_any; GtkFileFilter *pFilter_dsm, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_dsm = gtk_file_filter_new(); pFilter_dsm = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_dsm, "*.dsm*"); gtk_file_filter_add_pattern(pFilter_dsm, "*.dsm*");
gtk_file_filter_set_name(pFilter_dsm, "DeSmuME movie file (.dsm*)"); gtk_file_filter_set_name(pFilter_dsm, "DeSmuME movie file (.dsm*)");
@ -1054,31 +1039,25 @@ static void RecordMovieDialog()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Save Movie To ...", pFileSelection = gtk_file_chooser_native_new("Save Movie To ...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Save", "_Cancel");
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsm); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsm);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
FCEUI_SaveMovie(sPath,L"",START_BLANK,"", FCEUI_MovieGetRTCDefault()); FCEUI_SaveMovie(sPath,L"",START_BLANK,"", FCEUI_MovieGetRTCDefault());
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void StopMovie() static void StopMovie()
@ -1089,15 +1068,11 @@ static void StopMovie()
static void PlayMovieDialog() static void PlayMovieDialog()
{ {
GtkFileFilter *pFilter_dsm, *pFilter_any; GtkFileFilter *pFilter_dsm, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_dsm = gtk_file_filter_new(); pFilter_dsm = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_dsm, "*.dsm*"); gtk_file_filter_add_pattern(pFilter_dsm, "*.dsm*");
gtk_file_filter_set_name(pFilter_dsm, "DeSmuME movie file (.dsm*)"); gtk_file_filter_set_name(pFilter_dsm, "DeSmuME movie file (.dsm*)");
@ -1107,47 +1082,36 @@ static void PlayMovieDialog()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Play movie from...", pFileSelection = gtk_file_chooser_native_new("Play movie from...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Open", "_Cancel");
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsm); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsm);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
FCEUI_LoadMovie(sPath,true,false,-1); FCEUI_LoadMovie(sPath,true,false,-1);
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void SaveStateDialog() static void SaveStateDialog()
{ {
GtkFileFilter *pFilter_ds, *pFilter_any; GtkFileFilter *pFilter_ds, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_ds = gtk_file_filter_new(); pFilter_ds = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_ds, "*.ds*"); gtk_file_filter_add_pattern(pFilter_ds, "*.ds*");
gtk_file_filter_set_name(pFilter_ds, "DeSmuME binary (.ds*)"); gtk_file_filter_set_name(pFilter_ds, "DeSmuME binary (.ds*)");
@ -1157,27 +1121,23 @@ static void SaveStateDialog()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Save State To ...", pFileSelection = gtk_file_chooser_native_new("Save State To ...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Save", "_Cancel");
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_ds); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_ds);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
if(savestate_save(sPath) == false ) { if(savestate_save(sPath) == false ) {
GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
@ -1189,25 +1149,18 @@ static void SaveStateDialog()
} }
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void RecordAV_x264() static void RecordAV_x264()
{ {
GtkFileFilter *pFilter_mkv, *pFilter_mp4, *pFilter_any; GtkFileFilter *pFilter_mkv, *pFilter_mp4, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_mkv = gtk_file_filter_new(); pFilter_mkv = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_mkv, "*.mkv"); gtk_file_filter_add_pattern(pFilter_mkv, "*.mkv");
gtk_file_filter_set_name(pFilter_mkv, "Matroska (.mkv)"); gtk_file_filter_set_name(pFilter_mkv, "Matroska (.mkv)");
@ -1221,30 +1174,26 @@ static void RecordAV_x264()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Save video...", pFileSelection = gtk_file_chooser_native_new("Save video...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Save", "_Cancel");
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_mkv); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_mkv);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_mp4); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_mp4);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
if(avout_x264.begin(sPath)) { if(avout_x264.begin(sPath)) {
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "record_x264"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "record_x264"), FALSE);
} else { } else {
GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
@ -1254,25 +1203,18 @@ static void RecordAV_x264()
} }
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void RecordAV_flac() static void RecordAV_flac()
{ {
GtkFileFilter *pFilter_flac, *pFilter_any; GtkFileFilter *pFilter_flac, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_flac = gtk_file_filter_new(); pFilter_flac = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_flac, "*.flac"); gtk_file_filter_add_pattern(pFilter_flac, "*.flac");
gtk_file_filter_set_name(pFilter_flac, "FLAC file (.flac)"); gtk_file_filter_set_name(pFilter_flac, "FLAC file (.flac)");
@ -1282,29 +1224,25 @@ static void RecordAV_flac()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Save audio...", pFileSelection = gtk_file_chooser_native_new("Save audio...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Save", "_Cancel");
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (pFileSelection), TRUE);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_flac); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_flac);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
if(avout_flac.begin(sPath)) { if(avout_flac.begin(sPath)) {
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "record_flac"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "record_flac"), FALSE);
} else { } else {
GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
@ -1314,11 +1252,8 @@ static void RecordAV_flac()
} }
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void RecordAV_stop() { static void RecordAV_stop() {
@ -1331,15 +1266,11 @@ static void RecordAV_stop() {
static void OpenNdsDialog() static void OpenNdsDialog()
{ {
GtkFileFilter *pFilter_nds, *pFilter_dsgba, *pFilter_any; GtkFileFilter *pFilter_nds, *pFilter_dsgba, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
if (desmume_running()) if (desmume_running())
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_nds = gtk_file_filter_new(); pFilter_nds = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_nds, "*.[nN][dD][sS]"); gtk_file_filter_add_pattern(pFilter_nds, "*.[nN][dD][sS]");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
@ -1359,14 +1290,10 @@ static void OpenNdsDialog()
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
/* Creating the selection window */ /* Creating the selection window */
pFileSelection = gtk_file_chooser_dialog_new("Open...", pFileSelection = gtk_file_chooser_native_new("Open...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Open", "_Cancel");
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
/* Only the dialog window is accepting events: */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsgba); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsgba);
@ -1375,11 +1302,13 @@ static void OpenNdsDialog()
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(pFileSelection), g_get_home_dir()); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(pFileSelection), g_get_home_dir());
/* Showing the window */ /* Showing the window */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
if(Open((const char*)sPath) < 0) { if(Open((const char*)sPath) < 0) {
GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
@ -1406,11 +1335,8 @@ static void OpenNdsDialog()
} }
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
} }
static void OpenRecent(GtkRecentChooser *chooser, gpointer user_data) static void OpenRecent(GtkRecentChooser *chooser, gpointer user_data)
@ -2525,15 +2451,11 @@ static void Printscreen()
static void SelectFirmwareFile() static void SelectFirmwareFile()
{ {
GtkFileFilter *pFilter_nds, *pFilter_bin, *pFilter_any; GtkFileFilter *pFilter_nds, *pFilter_bin, *pFilter_any;
GtkWidget *pFileSelection; GtkFileChooserNative *pFileSelection;
GtkWidget *pParent;
gchar *sPath;
BOOL oldState = desmume_running(); BOOL oldState = desmume_running();
Pause(); Pause();
pParent = GTK_WIDGET(pWindow);
pFilter_nds = gtk_file_filter_new(); pFilter_nds = gtk_file_filter_new();
gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); gtk_file_filter_add_pattern(pFilter_nds, "*.nds");
gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)");
@ -2546,29 +2468,25 @@ static void SelectFirmwareFile()
gtk_file_filter_add_pattern(pFilter_any, "*"); gtk_file_filter_add_pattern(pFilter_any, "*");
gtk_file_filter_set_name(pFilter_any, "All files"); gtk_file_filter_set_name(pFilter_any, "All files");
pFileSelection = gtk_file_chooser_dialog_new("Load firmware...", pFileSelection = gtk_file_chooser_native_new("Load firmware...",
GTK_WINDOW(pParent), GTK_WINDOW(pWindow),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, "_Open", "_Cancel");
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_bin); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_bin);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any);
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { int response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(pFileSelection));
case GTK_RESPONSE_OK: if (response == GTK_RESPONSE_ACCEPT) {
sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pFileSelection));
gchar *sPath = g_file_get_path(file);
CommonSettings.UseExtFirmware = true; CommonSettings.UseExtFirmware = true;
strncpy(CommonSettings.ExtFirmwarePath, (const char*)sPath, g_utf8_strlen(sPath, -1)); strncpy(CommonSettings.ExtFirmwarePath, (const char*)sPath, g_utf8_strlen(sPath, -1));
g_free(sPath); g_free(sPath);
break;
default:
break;
} }
gtk_widget_destroy(pFileSelection); g_object_unref(pFileSelection);
if(oldState) Launch(); if(oldState) Launch();
} }