fixes to debian/*
[belltower] / belltower.c
index b5ef2a3..f995a6c 100644 (file)
@@ -100,6 +100,9 @@ typedef struct {
   int n_fields;
 } tower;
 
+static void show_towers_from_list (GSList *list, gchar *list_name);
+static void free_tower_list (GSList *list);
+
 static void
 show_message (char *message)
 {
@@ -583,31 +586,9 @@ single_tower_cb (tower *details,
 
   tower_window = hildon_stackable_window_new ();
 
-  if (g_str_has_prefix (details->fields[FieldDedication],
-                       "S "))
-    {
-      /* FIXME: This needs to be cleverer, because we can have
-       * e.g. "S Peter and S Paul".
-       * May have to use regexps.
-       * Reallocation in general even when unchanged is okay,
-       * because it's the common case (most towers are S Something)
-       */
-      
-      /* FIXME: Since we're passing this in as markup,
-       * we need to escape the strings.
-       */
-
-      str = g_strdup_printf("S<sup>t</sup> %s, %s",
-                             details->fields[FieldDedication]+2,
-                             details->fields[FieldPlace]);
-
-    }
-  else
-    {
-      str = g_strdup_printf("%s, %s",
-                             details->fields[FieldDedication],
-                             details->fields[FieldPlace]);
-    }
+  str = g_strdup_printf("%s, %s",
+                       details->fields[FieldDedication],
+                       details->fields[FieldPlace]);
 
   hildon_window_set_markup (HILDON_WINDOW (tower_window),
                            str);
@@ -741,16 +722,28 @@ found_tower_free (FoundTower *tower)
   g_free (tower);
 }
 
+/**
+ * Calls a given function once for each tower in the world.
+ * (The first call, however, is a header row.)
+ *
+ * \param callback       The function to call.
+ * \param data           Arbitrary data to pass to the callback.
+ * \param dialogue_title If non-NULL, a list will be displayed
+ *                       with the results.  This is the title
+ *                       used for that dialogue.  (The dialogue
+ *                       will automatically free filter_results.)
+ */
 static void
 parse_dove (ParseDoveCallback callback,
-           GSList **filter_results,
-           gpointer data)
+           gpointer data,
+           gchar *dialogue_title)
 {
   FILE *dove = fopen("/usr/share/belltower/dove.txt", "r");
   char tower_rec[4096];
   tower result;
   char *i;
   gboolean seen_newline;
+  GSList *filter_results = NULL;
 
   if (!dove)
     {
@@ -801,23 +794,30 @@ parse_dove (ParseDoveCallback callback,
          return;
 
        case FILTER_ACCEPT:
-         if (filter_results)
-           {
-             *filter_results = g_slist_append (*filter_results,
-                                               found_tower_new (&result));
-           }
+         filter_results = g_slist_append (filter_results,
+                                          found_tower_new (&result));
        }
 
       result.serial++;
     }
 
   fclose (dove);
+
+  if (dialogue_title)
+    {
+      show_towers_from_list (filter_results,
+                            dialogue_title);
+    }
+  else
+    {
+      free_tower_list (filter_results);
+    }
 }
 
 static void
 show_tower (char *primary_key)
 {
-  parse_dove (single_tower_cb, NULL, primary_key);
+  parse_dove (single_tower_cb, primary_key, NULL);
 }
 
 static void
@@ -851,7 +851,6 @@ show_towers_from_list (GSList *list,
   GtkWidget *selector;
   gint result = -1;
   GSList *cursor;
-  gchar foo[2048];
 
   if (!list)
     {
@@ -932,8 +931,6 @@ put_areas_into_list (gpointer key,
 static void
 nearby_towers (void)
 {
-  GSList *matches = NULL;
-
   if (!(device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET))
     {
       show_message ("I don't know where you are!");
@@ -941,10 +938,8 @@ nearby_towers (void)
     }
 
   parse_dove (get_nearby_towers_cb,
-             &matches,
-             NULL);
-
-  show_towers_from_list (matches);
+             NULL,
+             "Towers within fifty miles of you");
 }
 
 static void
@@ -964,7 +959,7 @@ towers_by_subarea (gchar *area)
   gtk_window_set_title (GTK_WINDOW (dialog), title);
   g_free (title);
 
-  parse_dove (get_counties_cb, NULL, &d);
+  parse_dove (get_counties_cb, &d, NULL);
 
   g_hash_table_foreach (hash,
                        put_areas_into_list,
@@ -983,15 +978,16 @@ towers_by_subarea (gchar *area)
 
   if (gtk_dialog_run (GTK_DIALOG (dialog))==GTK_RESPONSE_OK)
     {
-      GSList *matches = NULL;
+      gchar *title;
       cac.county = g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
+      title = g_strdup_printf ("Towers in %s",
+                              cac.county);
 
       parse_dove (get_towers_by_county_cb,
-                 &matches,
-                 &cac);
+                 &cac,
+                 title);
       g_free (cac.county);
-
-      show_towers_from_list (matches);
+      g_free (title);
     }
   g_hash_table_unref (hash);
   gtk_widget_destroy (GTK_WIDGET (dialog));
@@ -1066,7 +1062,7 @@ towers_by_area_with_many (gboolean countries_with_many)
                        countries_with_many?
                        COUNTRIES_WITH_MANY : COUNTRIES_WITH_FEW);
 
-  parse_dove (get_countries_cb, NULL, countries_to_counts);
+  parse_dove (get_countries_cb, countries_to_counts, NULL);
 
   country_names = get_countries_with_many (countries_to_counts,
                                           countries_with_many);
@@ -1116,13 +1112,14 @@ towers_by_area_with_many (gboolean countries_with_many)
       else
        {
          country_and_county cac = { result, NULL };
-         GSList *matches = NULL;
+         gchar *title = g_strdup_printf ("Belltowers in %s",
+                                         result);
 
          parse_dove (get_towers_by_county_cb,
-                     &matches,
-                     &cac);
+                     &cac,
+                     title);
 
-         show_towers_from_list (matches);
+         g_free (title);
        }
 
       g_free (result);
@@ -1141,13 +1138,9 @@ towers_by_area (void)
 static void
 show_bookmarks (void)
 {
-  GSList *matches = NULL;
-
   parse_dove (get_group_of_towers_cb,
-             &matches,
-             CONFIG_BOOKMARK_GROUP);
-
-  show_towers_from_list (matches);
+             CONFIG_BOOKMARK_GROUP,
+             "Bookmarks");
 }
 
 static void
@@ -1160,7 +1153,6 @@ tower_search (void)
                                                  GTK_RESPONSE_OK,
                                                  NULL);
   GtkWidget *entry = gtk_entry_new ();
-  GSList *matches = NULL;
 
   gtk_box_pack_end (GTK_BOX (GTK_DIALOG (terms)->vbox),
                    entry, TRUE, TRUE, 0);
@@ -1169,13 +1161,9 @@ tower_search (void)
 
   if (gtk_dialog_run (GTK_DIALOG (terms))==GTK_RESPONSE_OK)
     {
-      GSList *matches = NULL;
-
       parse_dove (get_towers_by_search_cb,
-                 &matches,
-                 (char*) gtk_entry_get_text (GTK_ENTRY (entry)));
-
-      show_towers_from_list (matches);
+                 (char*) gtk_entry_get_text (GTK_ENTRY (entry)),
+                 "Search results");
     }
 
   gtk_widget_destroy (GTK_WIDGET (terms));
@@ -1184,13 +1172,9 @@ tower_search (void)
 static void
 recent_towers (void)
 {
-  GSList *matches = NULL;
-
   parse_dove (get_group_of_towers_cb,
-             &matches,
-             CONFIG_RECENT_GROUP);
-
-  show_towers_from_list (matches);
+             CONFIG_RECENT_GROUP,
+             "Towers you have recently viewed");
 }
 
 /**
@@ -1239,18 +1223,28 @@ show_credits (GtkButton *source,
 
   button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL,
-                                       "View the GNU General Public Licence",
-                                       "This program is provided under the GPL, with no warranty.");
+                                       "Welcome to Belltower.  The program is \xc2\xa9 2009 Thomas Thurman.",
+                                       "View the program's home page.");
+  g_signal_connect (button, "clicked", G_CALLBACK (show_web_page),
+                   "http://belltower.garage.maemo.org");
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                   button,
+                   TRUE, TRUE, 0);
+
+  button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+                                       HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                       "This program is provided under the GNU GPL, with no warranty.",
+                                       "View the GNU General Public Licence.");
   g_signal_connect (button, "clicked", G_CALLBACK (show_web_page),
-                   "www.gnu.org/copyleft/gpl.html");
+                   "http://www.gnu.org/copyleft/gpl.html");
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                    button,
                    TRUE, TRUE, 0);
 
   button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL,
-                                       "View Dove's Guide for Church Bell Ringers",
-                                       "The source of this program's data.");
+                                       "The data comes from Dove's Guide for Church Bell Ringers.",
+                                       "View Dove's Guide.");
   g_signal_connect (button, "clicked", G_CALLBACK (show_web_page),
                    "http://dove.cccbr.org.uk");
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
@@ -1259,8 +1253,8 @@ show_credits (GtkButton *source,
 
   button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL,
-                                       "View belfry photograph",
-                                       "Image \xc2\xa9 Amanda Slater, cc-by-sa.");
+                                       "The belfry image is \xc2\xa9 Amanda Slater, cc-by-sa.",
+                                       "View the original photograph.");
   g_signal_connect (button, "clicked", G_CALLBACK (show_web_page),
                    "http://www.flickr.com/photos/pikerslanefarm/3398769335/");
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),