2 * This file is part of DrNokSnes
4 * Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
5 * http://www.indt.org/maemo
6 * Copyright (C) 2009 Javier S. Pedro <maemo@javispedro.com>
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this software; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 #include <startup_plugin.h>
29 #include <gconf/gconf.h>
30 #include <gconf/gconf-client.h>
31 #include <hildon/hildon-file-chooser-dialog.h>
33 #include "../platform/hgw.h"
35 static GtkWidget * load_plugin(void);
36 static void unload_plugin(void);
37 static void write_config(void);
38 static GtkWidget ** load_menu(guint *);
39 static void update_menu(void);
40 static void plugin_callback(GtkWidget * menu_item, gpointer data);
42 GConfClient *gcc = NULL;
43 static GameStartupInfo gs;
44 GtkWidget *menu_items[2];
46 static StartupPluginInfo plugin_info = {
55 static const gchar * rom_globs[] = {
62 STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, TRUE)
64 // Yes, I'm using the label not only to show but also save the current value.
65 static GtkLabel * rom_label;
68 interface_file_chooser
69 (GtkWindow * parent, GtkFileChooserAction action, const gchar ** extension)
72 GtkFileFilter * filter;
73 const gchar * current_filename;
74 gchar * filename = NULL;
77 filter = gtk_file_filter_new();
78 for (i = 0; extension[i]; i++) {
79 gtk_file_filter_add_pattern(filter, extension[i]);
82 dialog = hildon_file_chooser_dialog_new_with_properties(parent,
83 "action", action, "local_only", TRUE, "filter", filter, NULL);
85 current_filename = gtk_label_get_text(rom_label);
86 if (current_filename && strlen(current_filename) > 1) {
87 // By default open showing the last selected file
88 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
92 gtk_widget_show_all(GTK_WIDGET(dialog));
93 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
94 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
97 gtk_widget_destroy(dialog);
102 static void select_rom_callback(GtkWidget * button, gpointer data)
104 gchar * filename = interface_file_chooser(
105 GTK_WINDOW(gtk_widget_get_parent_window(button)),
106 GTK_FILE_CHOOSER_ACTION_OPEN,
109 if (!filename) return;
111 gtk_label_set_text(rom_label, filename);
116 static GtkWidget * load_plugin(void)
119 gcc = gconf_client_get_default();
121 GtkWidget* parent = gtk_vbox_new(FALSE, HILDON_MARGIN_DEFAULT);
122 GtkWidget* parent_hbox = gtk_hbox_new(FALSE, HILDON_MARGIN_DEFAULT);
123 GtkWidget* selectRomBtn = gtk_button_new_with_label("Select ROM...");
124 rom_label = GTK_LABEL(gtk_label_new(NULL));
126 gtk_widget_set_size_request(GTK_WIDGET(selectRomBtn),
129 gtk_label_set_text(rom_label,
130 gconf_client_get_string(gcc, kGConfRomFile, NULL));
133 g_signal_connect(G_OBJECT(selectRomBtn), "clicked",
134 G_CALLBACK (select_rom_callback), NULL);
136 gtk_box_pack_start(GTK_BOX(parent_hbox), selectRomBtn, FALSE, FALSE, 0);
137 gtk_box_pack_end(GTK_BOX(parent_hbox), GTK_WIDGET(rom_label), TRUE, TRUE, 0);
138 gtk_box_pack_start(GTK_BOX(parent), parent_hbox, FALSE, FALSE, 0);
143 static void unload_plugin(void)
148 static void write_config(void)
150 gconf_client_set_string(gcc, kGConfRomFile,
151 gtk_label_get_text(GTK_LABEL(rom_label)), NULL);
154 static GtkWidget **load_menu(guint *nitems)
161 static void update_menu(void)
166 static void plugin_callback(GtkWidget * menu_item, gpointer data)