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
27 #include <startup_plugin.h>
28 #include <gconf/gconf.h>
29 #include <gconf/gconf-client.h>
30 #include <hildon/hildon-file-chooser-dialog.h>
32 #include "../platform/hgw.h"
34 static GtkWidget * load_plugin(void);
35 static void unload_plugin(void);
36 static void write_config(void);
37 static GtkWidget ** load_menu(guint *);
38 static void update_menu(void);
39 static void plugin_callback(GtkWidget * menu_item, gpointer data);
41 GConfClient *gcc = NULL;
42 static GameStartupInfo gs;
43 GtkWidget *menu_items[2];
45 static StartupPluginInfo plugin_info = {
54 STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, TRUE)
56 // Yes, I'm using the label not only to show but also save the current value.
57 static GtkLabel * rom_label;
60 interface_file_chooser
61 (GtkWindow * parent, GtkFileChooserAction action, const gchar * extension)
64 GtkFileFilter * filter;
65 gchar * filename = NULL;
67 filter = gtk_file_filter_new();
68 gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), extension);
70 dialog = hildon_file_chooser_dialog_new_with_properties(parent,
71 "action", action, "local_only", TRUE, "filter", filter, NULL);
72 gtk_widget_show_all(GTK_WIDGET(dialog));
74 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
75 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
78 gtk_widget_destroy(dialog);
83 static void select_rom_callback(GtkWidget * button, gpointer data)
85 gchar * filename = interface_file_chooser(
86 GTK_WINDOW(gtk_widget_get_parent_window(button)),
87 GTK_FILE_CHOOSER_ACTION_OPEN,
90 if (!filename) return;
92 gtk_label_set_text(rom_label, filename);
97 static GtkWidget * load_plugin(void)
100 gcc = gconf_client_get_default();
102 GtkWidget* parent = gtk_vbox_new(FALSE, HILDON_MARGIN_DEFAULT);
103 GtkWidget* parent_hbox = gtk_hbox_new(FALSE, HILDON_MARGIN_DEFAULT);
104 GtkWidget* selectRomBtn = gtk_button_new_with_label("Select ROM...");
105 rom_label = GTK_LABEL(gtk_label_new(NULL));
107 gtk_widget_set_size_request(GTK_WIDGET(selectRomBtn),
110 gtk_label_set_text(rom_label,
111 gconf_client_get_string(gcc, kGConfRomFile, NULL));
114 g_signal_connect(G_OBJECT(selectRomBtn), "clicked",
115 G_CALLBACK (select_rom_callback), NULL);
117 gtk_box_pack_start(GTK_BOX(parent_hbox), selectRomBtn, FALSE, FALSE, 0);
118 gtk_box_pack_end(GTK_BOX(parent_hbox), GTK_WIDGET(rom_label), TRUE, TRUE, 0);
119 gtk_box_pack_start(GTK_BOX(parent), parent_hbox, FALSE, FALSE, 0);
124 static void unload_plugin(void)
129 static void write_config(void)
131 gconf_client_set_string(gcc, kGConfRomFile,
132 gtk_label_get_text(GTK_LABEL(rom_label)), NULL);
135 static GtkWidget **load_menu(guint *nitems)
142 static void update_menu(void)
147 static void plugin_callback(GtkWidget * menu_item, gpointer data)