2 * Copyright (C) 2009 Reto Zingg
4 * Some of the code is based on the examples on:
5 * http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details, a copy of which may be found in
16 * the file COPYING provided in the main directory of this release.
24 #include <hildon/hildon.h>
31 #define OSSO_SERVICE "com.nokia.mancala"
33 osso_context_t *ossoContext = NULL;
36 dbus_callback (const gchar *interface, const gchar *method,
37 GArray *arguments, gpointer data,
40 printf ("Msg dbus: %s, %s\n", interface, method);
42 if (!strcmp (method, "top_application"))
43 gtk_window_present (GTK_WINDOW (data));
45 retval->type = DBUS_TYPE_INVALID;
50 void play_wrapper (GtkWidget *win)
53 fprintf(stderr, "Button start-play pressed\n");
55 fprintf(stderr, "start play failed\n");
58 fprintf(stderr, "successfull played...\n");
61 osso_application_top(ossoContext, OSSO_SERVICE, NULL);
65 static HildonAppMenu* create_menu (GtkWidget *win)
70 HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
71 for (i = 1; i <= 2; i++) {
72 /* Create menu entries */
73 button = hildon_gtk_button_new (HILDON_SIZE_AUTO);
74 command_id = g_strdup_printf ("Menu command %d", i);
75 gtk_button_set_label (GTK_BUTTON (button), command_id);
77 /* Attach callback to clicked signal */
81 command_id = g_strdup_printf ("Play");
82 gtk_button_set_label (GTK_BUTTON (button), command_id);
83 g_signal_connect_after (button, "clicked",
84 G_CALLBACK (play_wrapper),win);
88 command_id = g_strdup_printf ("Quit");
89 gtk_button_set_label (GTK_BUTTON (button), command_id);
90 g_signal_connect_after (button, "clicked",
91 G_CALLBACK (gtk_main_quit), NULL);
94 /* Add entry to the view menu */
95 hildon_app_menu_append (menu, GTK_BUTTON (button));
98 gtk_widget_show_all (GTK_WIDGET (menu));
103 int main (int argc, char **argv) {
107 g_print("Initializing LibOSSO\n");
108 ossoContext = osso_initialize(OSSO_SERVICE, "0.1", FALSE, NULL);
109 if (ossoContext == NULL) {
110 g_error("Failed to initialize LibOSSO\n");
115 GtkTextBuffer *textbox_buffer;
119 PangoFontDescription *font_desc;
121 gchar *button_lable_text;
122 GtkWidget *pannable_text;
124 hildon_gtk_init (&argc, &argv);
125 win = hildon_window_new ();
127 /* Create and pack labels */
128 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.");
130 textbox = hildon_text_view_new();
131 // gtk_text_view_set_editable(GTK_TEXT_VIEW(textbox), FALSE);
132 // gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textbox), FALSE);
133 gtk_text_view_set_indent(GTK_TEXT_VIEW(textbox), 10);
134 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textbox), 10);
135 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textbox), 10);
136 gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textbox), 3);
137 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textbox), 2);
138 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD);
139 // gtk_widget_set_sensitive(textbox, FALSE);
140 font_desc = pango_font_description_from_string ("vera 18");
141 gtk_widget_modify_font(textbox, font_desc);
142 pango_font_description_free (font_desc);
144 textbox_buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (textbox));
146 gtk_text_buffer_set_text(textbox_buffer, textbox_text, -1);
149 pannable_text = hildon_pannable_area_new();
150 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(pannable_text), textbox);
153 vbox = GTK_BOX (gtk_vbox_new (FALSE, 2));
155 button = hildon_button_new (HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT,
156 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
157 button_lable_text = g_strdup_printf ("Play");
158 gtk_button_set_label (GTK_BUTTON (button), button_lable_text);
159 g_signal_connect_after (button, "clicked",
160 G_CALLBACK (play_wrapper),win);
162 gtk_box_pack_start (vbox, button, FALSE, TRUE, 1);
163 gtk_box_pack_start (vbox, pannable_text, TRUE, TRUE, 1);
166 menu = create_menu (win);
168 /* Attach menu to the window */
169 hildon_window_set_app_menu (HILDON_WINDOW (win), menu);
171 /* Add label's box to window */
172 gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
174 g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
176 gtk_widget_show_all (win);
178 ret = osso_rpc_set_default_cb_f (ossoContext, dbus_callback, GTK_WINDOW(win));
181 fprintf (stderr, "osso_rpc_set_default_cb_f failed: %d.\n", ret);
187 osso_deinitialize(ossoContext);