trying to use osso-games-startup as gui
[drnoksnes] / gui / plugin.c
1 /*
2 * This file is part of DrNokSnes
3 *
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>
7 *
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.
12 *
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.
17 *
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
21 * 02110-1301 USA
22 *
23 */
24
25 #include <stdio.h>
26 #include <gtk/gtk.h>
27 #include <startup_plugin.h>
28 #include <gconf/gconf.h>
29 #include <gconf/gconf-client.h>
30 #include <hildon/hildon-file-chooser-dialog.h>
31
32 #include "../platform/hgw.h"
33
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);
40
41 GConfClient *gcc = NULL;
42 static GameStartupInfo gs;
43 GtkWidget *menu_items[2];
44
45 static StartupPluginInfo plugin_info = {
46   load_plugin,
47   unload_plugin,
48   write_config,
49   load_menu,
50   update_menu,
51   plugin_callback
52 };
53
54 STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, TRUE)
55
56 // Yes, I'm using the label not only to show but also save the current value.
57 static GtkLabel * rom_label;
58
59 static gchar *
60 interface_file_chooser
61 (GtkWindow * parent, GtkFileChooserAction action, const gchar * extension)
62 {
63         GtkWidget * dialog;
64         GtkFileFilter * filter;
65         gchar * filename = NULL;
66
67         filter = gtk_file_filter_new();
68         gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), extension);
69
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));
73
74         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
75                 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
76         }
77         
78         gtk_widget_destroy(dialog);
79         
80         return filename;
81 }
82
83 static void select_rom_callback(GtkWidget * button, gpointer data)
84 {
85         gchar * filename = interface_file_chooser(
86                 GTK_WINDOW(gtk_widget_get_parent_window(button)),
87                 GTK_FILE_CHOOSER_ACTION_OPEN,
88                 "*.smc");
89                 
90         if (!filename) return;
91         
92         gtk_label_set_text(rom_label, filename);
93         
94         g_free(filename);
95 }
96
97 static GtkWidget * load_plugin(void)
98 {
99         g_type_init();
100         gcc = gconf_client_get_default();
101
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));
106         
107         gtk_widget_set_size_request(GTK_WIDGET(selectRomBtn),
108                                                                 180, 50);
109                                                                 
110         gtk_label_set_text(rom_label,
111                                                 gconf_client_get_string(gcc, kGConfRomFile, NULL));
112                                                                 
113
114         g_signal_connect(G_OBJECT(selectRomBtn), "clicked",
115                                         G_CALLBACK (select_rom_callback), NULL);
116
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);
120
121         return parent;
122 }
123
124 static void unload_plugin(void)
125 {
126         g_object_unref(gcc);
127 }
128
129 static void write_config(void)
130 {
131         gconf_client_set_string(gcc, kGConfRomFile,
132         gtk_label_get_text(GTK_LABEL(rom_label)), NULL);
133 }
134
135 static GtkWidget **load_menu(guint *nitems)
136 {
137         *nitems = 0;
138         
139         return NULL;
140 }
141
142 static void update_menu(void)
143 {
144
145 }
146
147 static void plugin_callback(GtkWidget * menu_item, gpointer data)
148 {
149
150 }
151