9fb5cf7802eb3105c45011c0f7beef2ac6670a55
[mancala] / src / plugin / mancala-ui-plugin.c
1 /*
2 * This file is part of Mancala
3 *
4 * Originally from Crazyparking:
5 * Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
6 * http://www.indt.org/maemo
7 *
8 * adapted:
9 * Copyright (c) 2009 Reto Zingg
10 *
11 * Some of the code is based on the examples on:
12 * http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide
13 *
14 * This software is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public License
16 * as published by the Free Software Foundation; either version 2.1 of
17 * the License, or (at your option) any later version.
18 *
19 * This software is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this software; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */ 
30
31
32 #include <stdio.h>
33 #include <hildon/hildon.h>
34 #include <gtk/gtk.h>
35 #include <startup_plugin.h>
36 #include <startup_app.h>
37 #include <dbus/dbus-glib.h>
38
39
40 static GtkWidget *load_plugin               (void);
41 static void       unload_plugin             (void);
42 static void       write_config              (void);
43
44 static GameStartupInfo gs;
45
46 static StartupPluginInfo plugin_info = {
47   load_plugin,
48   unload_plugin,
49   write_config,
50   NULL
51 };
52
53
54
55
56 STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, FALSE)
57
58 // the following does not work proper until osso_game_startup is
59 // implemented as stackable window...
60
61 // static void destroy_help_subwindow (void)
62 // {
63 //     StartupApp *app = gs.ui->app;
64 //     osso_application_top(app->osso, app->path, NULL);
65 // }
66 // 
67 // static void show_help_subwindow (void)
68 // {
69 //     GtkWidget *win;
70 //     GtkWidget *textbox;
71 //     GtkTextBuffer *textbox_buffer;
72 //     gchar *textbox_text;
73 //     PangoFontDescription *font_desc;
74 //     GtkWidget *pannable_text;
75 //     
76 //     /* Create the subwindow (a stackable window) */
77 //     win = hildon_stackable_window_new();
78 //     gtk_window_set_title ( GTK_WINDOW (win), "Help");
79 // 
80 //     /* Create and pack labels */     
81 //     textbox_text = g_strdup_printf("Welcome to Mancala, the ancient African game of skill!\n\nMancala is a very simple, easy-to-learn game. Each player begins with a horizontal row of holes or pits filled with a certain number of stones. At either end of the board are the players' home pits, which are used to keep score. In this case, the human player has the left home pit and the upper row holes. A move is made by clicking into the hole you wish to move from. The stones are then picked up and distributed, one to each hole, moving toward your home pit is reached, and then moving through your opponent's row, bypassing his/her home, and moving back towards in a circle (counterclockwise), until all the stones have been distributed.\n\nIf the last stone is placed in your home, you receive an extra turn. If the last stone lands in an empty hole on your side, you 'capture' the stones in the opposite hole on your opponent's side, moving them to your home.\n\nThe game ends when one player cannot play (ie. there are no stones on his/her side of the board.  The player who has the most stones on his/her *side* wins.");
82 //     
83 //     textbox = hildon_text_view_new();
84 //     gtk_text_view_set_editable(GTK_TEXT_VIEW(textbox), FALSE);
85 //     // gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textbox), FALSE);
86 //     gtk_text_view_set_indent(GTK_TEXT_VIEW(textbox), 10);
87 //     gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textbox), 10);
88 //     gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textbox), 10);
89 //     gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textbox), 3);
90 //     gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textbox), 2);
91 //     gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD);
92 //     // gtk_widget_set_sensitive(textbox, FALSE);
93 //     font_desc = pango_font_description_from_string ("vera 18");
94 //     gtk_widget_modify_font(textbox, font_desc);
95 //     pango_font_description_free (font_desc);
96 //     
97 //     textbox_buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (textbox));
98 //     
99 //     gtk_text_buffer_set_text(textbox_buffer, textbox_text, -1);
100 //     
101 //     
102 //     pannable_text = hildon_pannable_area_new();
103 //     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(pannable_text), textbox);
104 //     
105 //     gtk_container_add (GTK_CONTAINER (win), pannable_text);
106 //     
107 //     g_signal_connect (win, "destroy",    destroy_help_subwindow, NULL);
108 //     
109 // 
110 //     /* This call show the window and also add the window to the stack */
111 //     gtk_widget_show_all (win);
112 // }
113
114
115 static void show_help_browser (void)
116 {
117     char *uri = "file:///home/opt/mancala/data/mancala.html";
118     DBusGConnection *connection;
119     GError *error = NULL;
120     DBusGProxy *proxy;
121     
122     connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
123     
124     if (connection == NULL){
125         printf("Dbus connection failed: %s\n",error->message);
126         g_error_free (error);
127         return;
128     }
129     
130     proxy = dbus_g_proxy_new_for_name (connection,
131                                        "com.nokia.osso_browser",
132                                        "/com/nokia/osso_browser/request",
133                                        "com.nokia.osso_browser");
134
135     error = NULL;
136
137     if (!dbus_g_proxy_call (proxy, "load_url", &error, G_TYPE_STRING, uri, G_TYPE_INVALID, G_TYPE_INVALID)){
138         printf("Load_URL failed: %s\n",error->message);
139         g_error_free (error);
140     }
141
142 }
143
144
145 static GtkWidget *load_plugin (void)
146 {
147     GtkWidget *button;
148     button =  gtk_button_new_with_label ("Instuctions");
149     
150     g_signal_connect (button, "clicked", G_CALLBACK (show_help_browser), NULL);
151     
152     return GTK_WIDGET(button);
153     
154 }
155
156 static void
157 unload_plugin (void)
158 {
159
160 }
161
162 static void
163 write_config (void)
164 {
165   
166 }
167
168