correct casts
[rfk] / rfk.c
diff --git a/rfk.c b/rfk.c
index bc516fc..ca9d016 100644 (file)
--- a/rfk.c
+++ b/rfk.c
@@ -3,9 +3,10 @@
  *  ported to maemo by Thomas Thurman, 2009
  *  suggestions welcome
  *  Compile with:
- *  gcc -Wall -g rfk.c -o rfk `pkg-config --cflags --libs gtk+-2.0 hildon-1`
+ *  gcc -Wall -g rfk.c -o rfk `pkg-config --cflags --libs gtk+-2.0 hildon-1 dbus-glib-1 dbus-1`
  */
 
+#include <dbus/dbus-glib.h>
 #include <gtk/gtk.h>
 #include <stdlib.h>
 #include <glib.h>
 
 const int amount_of_random_stuff = 15;
 
-const char *explanation =
-  "In this game, you are robot (#). "
-  "Your job is to find kitten. This task is complicated "
-  "by the existence of various things which are not kitten. "
-  "Robot must touch items to determine if they are kitten or "
-  "not. The game ends when robotfindskitten. You may move "
-  "robot about by tapping on any side of robot, or with the "
-  "cursor keys.";
-
 GSList *nki = NULL;
 guint nki_count = 0;
 
@@ -129,7 +121,8 @@ show_message (const char *message)
 {
   HildonNote* note = HILDON_NOTE
     (hildon_note_new_information (GTK_WINDOW (window),
-                                 message));
+                                 message?message:
+                                 "Some message was supposed to be here."));
   gtk_dialog_run (GTK_DIALOG (note));
   gtk_widget_destroy (GTK_WIDGET (note));
 }
@@ -476,10 +469,41 @@ set_up_game (void)
   gtk_widget_show_all (window);
 }
 
-void
+/****************************************************************/
+/* Online help.                                                 */
+/****************************************************************/
+gboolean
 get_help (gpointer button, gpointer data)
 {
-  show_message ("Not yet implemented.");
+  DBusGConnection *connection;
+  GError *error = NULL;
+  DBusGProxy *proxy;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION,
+                               &error);
+  if (connection == NULL)
+    {
+      show_message (error->message);
+      g_error_free (error);
+      return FALSE;
+    }
+
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     "com.nokia.osso_browser",
+                                     "/com/nokia/osso_browser/request",
+                                     "com.nokia.osso_browser");
+
+  error = NULL;
+  if (!dbus_g_proxy_call (proxy, "load_url", &error,
+                         G_TYPE_STRING, "/usr/share/rfk/help.html",
+                         G_TYPE_INVALID,
+                         G_TYPE_INVALID))
+    {
+      show_message (error->message);
+      g_error_free (error);
+      return FALSE;
+    }
+  return FALSE;
 }
 
 void
@@ -491,10 +515,17 @@ play_game (gpointer button, gpointer data)
 void
 show_intro (void)
 {
-  GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
-  GtkWidget *hbox2 = gtk_hbox_new (TRUE, 0);
+  GtkWidget *middle = gtk_hbox_new (FALSE, 0);
+  GtkWidget *buttons = gtk_hbox_new (TRUE, 0);
   GtkWidget *explain = NULL, *help_button, *play_button;
-
+  const char *explanation =
+    "In this game, you are robot (#). "
+    "Your job is to find kitten. This task is complicated "
+    "by the existence of various things which are not kitten. "
+    "Robot must touch items to determine if they are kitten or "
+    "not. The game ends when robotfindskitten. You may move "
+    "robot about by tapping on any side of robot, or with the "
+    "arrow keys.";
   GKeyFile *desktop = g_key_file_new ();
   gchar *version;
 
@@ -513,32 +544,32 @@ show_intro (void)
       version = g_strdup("");
     }
 
-  help_button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+  help_button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_THUMB_HEIGHT,
                                             HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
                                             "Help", NULL);
   g_signal_connect (help_button, "clicked", G_CALLBACK (get_help), NULL);
 
-  play_button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+  play_button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_THUMB_HEIGHT,
                                             HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
                                             "Play", NULL);
   g_signal_connect (play_button, "clicked", G_CALLBACK (play_game), NULL);
 
-  gtk_box_pack_end (hbox2, play_button, TRUE, TRUE, 0);
-  gtk_box_pack_end (hbox2, help_button, TRUE, TRUE, 0);
+  gtk_box_pack_end (GTK_BOX (buttons), play_button, TRUE, TRUE, 0);
+  gtk_box_pack_end (GTK_BOX (buttons), help_button, TRUE, TRUE, 0);
 
   explain = gtk_label_new (explanation);
-  gtk_label_set_line_wrap (explain, TRUE);
+  gtk_label_set_line_wrap (GTK_LABEL (explain), TRUE);
 
-  gtk_box_pack_end (vbox, hbox2, FALSE, FALSE, 0);
-  gtk_box_pack_end (vbox, explain, TRUE, TRUE, 0);
-  gtk_box_pack_end (vbox, gtk_label_new (version), FALSE, FALSE, 0);
+  gtk_box_pack_end (GTK_BOX (middle), explain, TRUE, TRUE, 0);
+  gtk_box_pack_end (GTK_BOX (middle), gtk_image_new_from_pixbuf (robot_pic), FALSE, FALSE, 0);
 
-  g_free (version);
+  intro = gtk_vbox_new (FALSE, 0);
+  gtk_box_pack_end (GTK_BOX (intro), buttons, FALSE, FALSE, 0);
+  gtk_box_pack_end (GTK_BOX (intro), middle, TRUE, TRUE, 0);
+  gtk_box_pack_end (GTK_BOX (intro), gtk_label_new (version), FALSE, FALSE, 0);
 
-  intro = gtk_hbox_new (FALSE, 0);
+  g_free (version);
 
-  gtk_box_pack_end (intro, vbox, TRUE, TRUE, 0);
-  gtk_box_pack_end (intro, gtk_image_new_from_pixbuf (robot_pic), FALSE, FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (intro));
 
   gtk_widget_show_all (window);