snes9x/gtk/src/gtk_netplay_dialog.cpp

139 lines
3.7 KiB
C++
Raw Normal View History

/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
2010-09-25 17:46:12 +02:00
#include "gtk_netplay_dialog.h"
#include "gtk_s9x.h"
#include "gtk_file.h"
2010-09-26 11:19:15 +02:00
static void
2010-09-25 17:46:12 +02:00
event_browse_clicked (GtkButton *button, gpointer data)
{
char *filename;
Snes9xNetplayDialog *np_dialog = (Snes9xNetplayDialog *) data;
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
filename = S9xOpenROMDialog ();
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
if (filename)
{
2010-09-26 11:19:15 +02:00
gtk_entry_set_text (GTK_ENTRY (np_dialog->get_widget ("rom_image")),
2010-09-25 17:46:12 +02:00
filename);
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
g_free (filename);
}
}
2010-09-26 11:19:15 +02:00
static void
2010-09-25 17:46:12 +02:00
event_clear_clicked (GtkButton *button, gpointer data)
{
Snes9xNetplayDialog *np_dialog = (Snes9xNetplayDialog *) data;
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
gtk_entry_set_text (GTK_ENTRY (np_dialog->get_widget ("rom_image")), "");
}
2010-09-26 11:19:15 +02:00
static void
2010-09-25 17:46:12 +02:00
event_server_toggled (GtkToggleButton *toggle, gpointer data)
{
Snes9xNetplayDialog *np_dialog = (Snes9xNetplayDialog *) data;
2010-09-26 11:19:15 +02:00
np_dialog->update_state ();
2010-09-25 17:46:12 +02:00
}
Snes9xNetplayDialog::Snes9xNetplayDialog (Snes9xConfig *config) :
2010-09-26 11:19:15 +02:00
GtkBuilderWindow ("netplay_dialog")
2010-09-25 17:46:12 +02:00
{
2010-09-26 11:19:15 +02:00
GtkBuilderWindowCallbacks callbacks[] =
2010-09-25 17:46:12 +02:00
{
{ "server_toggled", G_CALLBACK (event_server_toggled) },
{ "browse_clicked", G_CALLBACK (event_browse_clicked) },
{ "clear_clicked", G_CALLBACK (event_clear_clicked) },
{ NULL, NULL }
};
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
signal_connect (callbacks);
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
this->config = config;
}
void
Snes9xNetplayDialog::update_state ()
2010-09-25 17:46:12 +02:00
{
if (get_check ("host_radio"))
{
enable_widget ("connect_box", false);
enable_widget ("default_port_box", true);
enable_widget ("sync_reset", true);
enable_widget ("send_image", true);
2010-09-25 17:46:12 +02:00
}
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
else
{
enable_widget ("connect_box", true);
enable_widget ("default_port_box", false);
enable_widget ("sync_reset", false);
enable_widget ("send_image", false);
2010-09-25 17:46:12 +02:00
}
}
void
Snes9xNetplayDialog::settings_to_dialog ()
2010-09-25 17:46:12 +02:00
{
set_entry_text ("rom_image", config->netplay_last_rom.c_str ());
set_entry_text ("ip_entry", config->netplay_last_host.c_str ());
2010-09-25 17:46:12 +02:00
set_check ("sync_reset", config->netplay_sync_reset);
set_check ("send_image", config->netplay_send_rom);
set_spin ("port", config->netplay_last_port);
set_spin ("default_port", config->netplay_default_port);
set_spin ("frames_behind", config->netplay_max_frame_loss);
set_check ("connect_radio", !config->netplay_is_server);
set_check ("host_radio", config->netplay_is_server);
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
update_state ();
}
void
Snes9xNetplayDialog::settings_from_dialog ()
2010-09-25 17:46:12 +02:00
{
config->netplay_last_rom = get_entry_text ("rom_image");
config->netplay_last_host = get_entry_text ("ip_entry");
2010-09-25 17:46:12 +02:00
config->netplay_sync_reset = get_check ("sync_reset");
config->netplay_send_rom = get_check ("send_image");
config->netplay_last_port = get_spin ("port");
config->netplay_default_port = get_spin ("default_port");
config->netplay_max_frame_loss = get_spin ("frames_behind");
config->netplay_is_server = get_check ("host_radio");
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
config->save_config_file ();
}
bool Snes9xNetplayDialog::show()
2010-09-25 17:46:12 +02:00
{
int result;
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
settings_to_dialog ();
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
result = gtk_dialog_run (GTK_DIALOG (window));
gtk_widget_hide (window);
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
if (result == GTK_RESPONSE_OK)
{
2010-09-26 11:19:15 +02:00
settings_from_dialog ();
return true;
2010-09-25 17:46:12 +02:00
}
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
else
{
return false;
2010-09-25 17:46:12 +02:00
}
2010-09-26 11:19:15 +02:00
2010-09-25 17:46:12 +02:00
}
Snes9xNetplayDialog::~Snes9xNetplayDialog ()
2010-09-25 17:46:12 +02:00
{
gtk_widget_destroy (window);
}