3 * This file is part of Mancala
5 * Copyright (C) 2009 Reto Zingg
7 * Some of the code is based on the examples on:
8 * http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details, a copy of which may be found in
19 * the file COPYING provided in the main directory of this release.
23 /*********************************************************************
25 ** NOT used at the moment...
27 *********************************************************************/
33 #include <hildon/hildon.h>
40 #define OSSO_SERVICE "com.nokia.mancala"
42 osso_context_t *ossoContext = NULL;
45 dbus_callback (const gchar *interface, const gchar *method,
46 GArray *arguments, gpointer data,
49 printf ("Msg dbus: %s, %s\n", interface, method);
51 if (!strcmp (method, "top_application"))
52 gtk_window_present (GTK_WINDOW (data));
54 retval->type = DBUS_TYPE_INVALID;
59 void play_wrapper (GtkWidget *win)
62 fprintf(stderr, "Button start-play pressed\n");
64 fprintf(stderr, "start play failed\n");
67 fprintf(stderr, "successfull played...\n");
70 osso_application_top(ossoContext, OSSO_SERVICE, NULL);
74 static HildonAppMenu* create_menu (GtkWidget *win)
79 HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
80 for (i = 1; i <= 2; i++) {
81 /* Create menu entries */
82 button = hildon_gtk_button_new (HILDON_SIZE_AUTO);
83 command_id = g_strdup_printf ("Menu command %d", i);
84 gtk_button_set_label (GTK_BUTTON (button), command_id);
86 /* Attach callback to clicked signal */
90 command_id = g_strdup_printf ("Play");
91 gtk_button_set_label (GTK_BUTTON (button), command_id);
92 g_signal_connect_after (button, "clicked",
93 G_CALLBACK (play_wrapper),win);
97 command_id = g_strdup_printf ("Quit");
98 gtk_button_set_label (GTK_BUTTON (button), command_id);
99 g_signal_connect_after (button, "clicked",
100 G_CALLBACK (gtk_main_quit), NULL);
103 /* Add entry to the view menu */
104 hildon_app_menu_append (menu, GTK_BUTTON (button));
107 gtk_widget_show_all (GTK_WIDGET (menu));
112 int main (int argc, char **argv) {
116 g_print("Initializing LibOSSO\n");
117 ossoContext = osso_initialize(OSSO_SERVICE, "0.1", FALSE, NULL);
118 if (ossoContext == NULL) {
119 g_error("Failed to initialize LibOSSO\n");
124 GtkTextBuffer *textbox_buffer;
128 PangoFontDescription *font_desc;
130 gchar *button_lable_text;
131 GtkWidget *pannable_text;
133 hildon_gtk_init (&argc, &argv);
134 win = hildon_window_new ();
136 /* Create and pack labels */
137 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.");
139 textbox = hildon_text_view_new();
140 // gtk_text_view_set_editable(GTK_TEXT_VIEW(textbox), FALSE);
141 // gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textbox), FALSE);
142 gtk_text_view_set_indent(GTK_TEXT_VIEW(textbox), 10);
143 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textbox), 10);
144 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textbox), 10);
145 gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textbox), 3);
146 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textbox), 2);
147 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD);
148 // gtk_widget_set_sensitive(textbox, FALSE);
149 font_desc = pango_font_description_from_string ("vera 18");
150 gtk_widget_modify_font(textbox, font_desc);
151 pango_font_description_free (font_desc);
153 textbox_buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (textbox));
155 gtk_text_buffer_set_text(textbox_buffer, textbox_text, -1);
158 pannable_text = hildon_pannable_area_new();
159 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(pannable_text), textbox);
162 vbox = GTK_BOX (gtk_vbox_new (FALSE, 2));
164 button = hildon_button_new (HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT,
165 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
166 button_lable_text = g_strdup_printf ("Play");
167 gtk_button_set_label (GTK_BUTTON (button), button_lable_text);
168 g_signal_connect_after (button, "clicked",
169 G_CALLBACK (play_wrapper),win);
171 gtk_box_pack_start (vbox, button, FALSE, TRUE, 1);
172 gtk_box_pack_start (vbox, pannable_text, TRUE, TRUE, 1);
175 menu = create_menu (win);
177 /* Attach menu to the window */
178 hildon_window_set_app_menu (HILDON_WINDOW (win), menu);
180 /* Add label's box to window */
181 gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
183 g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
185 gtk_widget_show_all (win);
187 ret = osso_rpc_set_default_cb_f (ossoContext, dbus_callback, GTK_WINDOW(win));
190 fprintf (stderr, "osso_rpc_set_default_cb_f failed: %d.\n", ret);
196 osso_deinitialize(ossoContext);