tidy comments
[rfk] / rfk.c
diff --git a/rfk.c b/rfk.c
index 13abae7..926d273 100644 (file)
--- a/rfk.c
+++ b/rfk.c
@@ -18,7 +18,7 @@
 #define ARENA_WIDTH 25
 #define ARENA_HEIGHT 12
 
-const int amount_of_random_stuff = 1;
+const int amount_of_random_stuff = 15;
 
 typedef enum {
   STATE_PROLOGUE,
@@ -56,8 +56,8 @@ description (void)
       r = random() % nki_count;
     }
   while (used[r]);
-
   used[r] = TRUE;
+
   return g_slist_nth_data (nki, r);
 }
 
@@ -184,8 +184,6 @@ ensure_messages_loaded (void)
     }
 
   fclose (nki_file);
-
-  used = g_malloc0 (nki_count);
 }
 
 void
@@ -216,6 +214,67 @@ switch_state (StateOfPlay new_state)
 }
 
 /****************************************************************/
+/* Things we need DBus for: online help, and vibration.         */
+/****************************************************************/
+static void
+call_dbus (DBusBusType type,
+          char *name,
+          char *path,
+          char *interface,
+          char *method,
+          char *parameter)
+{
+  DBusGConnection *connection;
+  GError *error = NULL;
+
+  DBusGProxy *proxy;
+
+  connection = dbus_g_bus_get (type,
+                               &error);
+  if (connection == NULL)
+    {
+      show_message (error->message);
+      g_error_free (error);
+      return;
+    }
+
+  proxy = dbus_g_proxy_new_for_name (connection, name, path, interface);
+
+  error = NULL;
+  if (!dbus_g_proxy_call (proxy, method, &error,
+                         G_TYPE_STRING, parameter,
+                         G_TYPE_INVALID,
+                         G_TYPE_INVALID))
+    {
+      show_message (error->message);
+      g_error_free (error);
+    }
+}
+
+static gboolean
+get_help (gpointer button, gpointer data)
+{
+  call_dbus (DBUS_BUS_SESSION,
+            "com.nokia.osso_browser",
+            "/com/nokia/osso_browser/request",
+            "com.nokia.osso_browser",
+            "load_url",
+            "/usr/share/rfk/help.html");
+  return FALSE;
+}
+
+static void
+vibrate (void)
+{
+  call_dbus (DBUS_BUS_SYSTEM,
+            "com.nokia.mce",
+            "/com/nokia/mce/request",
+            "com.nokia.mce.request",
+            "req_vibrator_pattern_activate",
+            "PatternIncomingMessage");
+}
+
+/****************************************************************/
 /* The ending animation.                                        */
 /****************************************************************/
 
@@ -240,6 +299,7 @@ ending_animation_draw (GtkWidget *widget, GdkEventExpose *event, gpointer data)
   static GdkGC *gc = NULL;
 
   const int stepsize = 3;
+  static int love_size = 40;
 
   if (!kitten_x)
     {
@@ -272,30 +332,48 @@ ending_animation_draw (GtkWidget *widget, GdkEventExpose *event, gpointer data)
                   -1, -1,
                   GDK_RGB_DITHER_NONE, 0, 0);
 
-  cycle_count++;
-  robot_x += stepsize;
-  kitten_x -= stepsize;
-
-  if (robot_x+robot_stop >= kitten_x)
+  if (robot_x+robot_stop < kitten_x)
+    {
+      cycle_count++;
+      robot_x += stepsize;
+      kitten_x -= stepsize;
+    }
+  else
     {
+      GdkPixbuf *scaled_love_pic =
+       gdk_pixbuf_scale_simple (love_pic,
+                                love_size,
+                                love_size,
+                                GDK_INTERP_BILINEAR);
+
       gdk_draw_pixbuf (GDK_DRAWABLE(widget->window),
                       gc,
-                      love_pic, 0, 0,
+                      scaled_love_pic, 0, 0,
                       robot_x + gdk_pixbuf_get_width (robot_pic), all_y,
                       -1, -1,
                       GDK_RGB_DITHER_NONE, 0, 0);
 
-      animation_running = FALSE;
-
-      g_timeout_add (2000, ending_animation_quit, NULL);
+      love_size ++;
 
-      gdk_gc_unref (gc);
-      cycle_count = 0;
-      robot_x = 0;
-      robot_stop = 0;
-      kitten_x = 0;
-      all_y = 0;
-      gc = NULL;
+      if (love_size >= gdk_pixbuf_get_width (love_pic))
+       {
+         /* all done! */
+         
+         vibrate ();
+         
+         animation_running = FALSE;
+
+         g_timeout_add (2000, ending_animation_quit, NULL);
+
+         gdk_gc_unref (gc);
+         love_size = 40;
+         cycle_count = 0;
+         robot_x = 0;
+         robot_stop = 0;
+         kitten_x = 0;
+         all_y = 0;
+         gc = NULL;
+       }
     }
 
   return TRUE;
@@ -462,44 +540,12 @@ on_key_pressed (GtkWidget      *widget,
        }
     }
 
-  return FALSE;
-}
-
-/****************************************************************/
-/* Online help.                                                 */
-/****************************************************************/
-gboolean
-get_help (gpointer button, gpointer data)
-{
-  DBusGConnection *connection;
-  GError *error = NULL;
-
-  DBusGProxy *proxy;
-
-  connection = dbus_g_bus_get (DBUS_BUS_SESSION,
-                               &error);
-  if (connection == NULL)
+  if (keyval=='d' && event->state & GDK_CONTROL_MASK)
     {
-      show_message (error->message);
-      g_error_free (error);
-      return FALSE;
+      /* secret debugging key */
+      show_message (gtk_label_get_text (GTK_LABEL (kitten)));
     }
 
-  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;
 }
 
@@ -534,6 +580,9 @@ set_up_board (void)
     {
       /* make everything new */
   
+      g_free (used);
+      used = g_malloc0 (nki_count * sizeof(gboolean));
+
       robot = gtk_label_new ("#");
       g_object_ref (robot);
       kitten = random_character ("You found kitten!  Way to go, robot!");
@@ -588,6 +637,9 @@ set_up_widgets (void)
 
   /* The prologue */
 
+  /* Get the rather odd version string.  The RFK spec says that
+   * it should read v<major>.<minor>.<number-of-NKIs>.
+   */
   if (g_key_file_load_from_file (desktop,
                                 "/usr/share/applications/hildon/rfk.desktop",
                                 G_KEY_FILE_NONE,