all: drnoksnes_plugin.so data
-drnoksnes_plugin.so: plugin.o
+drnoksnes_plugin.so: plugin.o state.o
$(CC) $(LDFLAGS) $^ $(LDLIBS)-o $@
clean:
- rm -f noksnes_plugin.so *.o
+ rm -f drnoksnes_plugin.so *.o
rm -f $(DATA_FILES)
%: %.m4
#include <hildon/hildon-file-chooser-dialog.h>
#include "../platform/hgw.h"
+#include "state.h"
static GtkWidget * load_plugin(void);
static void unload_plugin(void);
// Yes, I'm using the label not only to show but also save the current value.
static GtkLabel * rom_label;
+static GameState cur_state = GAME_STATE_STOP;
+
+static void update_game_state()
+{
+ GameState new_state;
+ GameStateInfo info;
+ const char * rom_file = gtk_label_get_text(rom_label);
+
+ if (rom_file) {
+ game_state_fill(&info, rom_file);
+ }
+
+ if (info.has_state_file) {
+ new_state = GAME_STATE_PAUSED; // We have a freeze file
+ } else {
+ new_state = GAME_STATE_STOP;
+ }
+
+ if (cur_state != new_state) {
+ game_state_set(new_state);
+ cur_state = new_state;
+ }
+}
+
static gchar *
interface_file_chooser
(GtkWindow * parent, GtkFileChooserAction action, const gchar ** extension)
gtk_label_set_text(rom_label, filename);
g_free(filename);
+
+ update_game_state();
}
static GtkWidget * load_plugin(void)
gtk_box_pack_end(GTK_BOX(parent_hbox), GTK_WIDGET(rom_label), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(parent), parent_hbox, FALSE, FALSE, 0);
+ update_game_state();
+
return parent;
}
--- /dev/null
+/*
+* This file is part of DrNokSnes
+*
+* Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
+* http://www.indt.org/maemo
+* Copyright (C) 2009 Javier S. Pedro <maemo@javispedro.com>
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include <string.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#include "state.h"
+
+#define FRZ_FILE_EXT ".frz.gz"
+
+void game_state_fill(GameStateInfo * info, const char * rom_file)
+{
+ char * ext = strrchr(rom_file, '.');
+ char * rom_base;
+ char * frz_file;
+
+ if (!ext) {
+ rom_base = g_strdup(rom_file);
+ } else {
+ rom_base = g_strndup(rom_file, ext - rom_file);
+ }
+
+ info->rom_exists =
+ g_file_test(rom_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
+
+ frz_file = g_strconcat(rom_base, FRZ_FILE_EXT);
+ info->has_state_file =
+ g_file_test(frz_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
+
+ g_free(frz_file);
+ g_free(rom_base);
+}
+
+// More uglyness. If you know a better way to do this please tell.
+void game_state_set(GameState newState)
+{
+ DBusError err;
+ DBusConnection* bus;
+ DBusMessage* m;
+ const char * m_name;
+
+ switch (newState) {
+ case GAME_STATE_PAUSED:
+ m_name = "game_pause";
+ break;
+ case GAME_STATE_STOP:
+ m_name = "game_close";
+ break;
+ default:
+ return;
+ }
+
+
+ dbus_error_init(&err);
+
+ bus = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ dbus_error_free(&err);
+ return;
+ }
+
+ m = dbus_message_new_method_call("com.javispedro.drnoksnes.startup",
+ "/com/javispedro/drnoksnes/startup",
+ "com.javispedro.drnoksnes.startup",
+ m_name);
+
+ dbus_connection_send(bus, m, NULL);
+ dbus_connection_flush(bus);
+
+ dbus_message_unref(m);
+}
+
--- /dev/null
+#ifndef _STATE_H_
+#define _STATE_H_
+
+#include <glib.h>
+
+typedef struct GameStateInfo
+{
+ gboolean rom_exists;
+ gboolean has_state_file;
+} GameStateInfo;
+typedef enum GameState
+{
+ GAME_STATE_NONE = 0,
+ GAME_STATE_PAUSED,
+ GAME_STATE_STOP
+} GameState;
+
+void game_state_fill(GameStateInfo * info, const char * rom_file);
+void game_state_set(GameState newState);
+
+#endif
}
hgwLaunched = true;
- HgwStartCommand cmd = hgw_context_get_start_command(hgw);
-
- switch (cmd) {
- default:
- case HGW_COMM_NONE: // called from libosso
- case HGW_COMM_CONT:
- Config.snapshotLoad = true;
- Config.snapshotSave = true;
- break;
- case HGW_COMM_RESTART:
- Config.snapshotLoad = false;
- Config.snapshotSave = true;
- break;
- case HGW_COMM_QUIT:
- // hum, what?
- Config.snapshotLoad = false;
- Config.snapshotSave = false;
- Config.quitting = true;
- break;
- }
-
printf("Loading in HGW mode\n");
}
if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
S9xSetRomFile(romFile);
} else {
+ hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
DIE("No Rom in Gconf!");
}
+
+ HgwStartCommand cmd = hgw_context_get_start_command(hgw);
+ switch (cmd) {
+ default:
+ case HGW_COMM_NONE: // called from libosso
+ case HGW_COMM_CONT:
+ Config.snapshotLoad = true;
+ Config.snapshotSave = true;
+ break;
+ case HGW_COMM_RESTART:
+ Config.snapshotLoad = false;
+ Config.snapshotSave = true;
+ break;
+ case HGW_COMM_QUIT:
+ // hum, what?
+ Config.snapshotLoad = false;
+ Config.snapshotSave = false;
+ Config.quitting = true;
+ break;
+ }
}
void HgwPollEvents()