+/**
+ * Removes the oldest entry from the [Recent] group in the config
+ * file until there are only five entries left. Does not save
+ * the file; you have to do that.
+ */
+static void
+remove_old_recent_entries (void)
+{
+ gint count;
+
+ do
+ {
+ gchar **towers;
+ gint oldest_date = 0;
+ gchar *oldest_tower = NULL;
+ gint i;
+
+ /* It is a bit inefficient to do this every
+ * time we go around the loop. However, it
+ * makes the code far simpler, and we almost
+ * never go around more than once.
+ */
+ towers = g_key_file_get_keys (config,
+ CONFIG_RECENT_GROUP,
+ &count,
+ NULL);
+
+ if (count <= MAX_RECENT)
+ /* everything's fine */
+ return;
+
+ for (i=0; i<count; i++)
+ {
+ gint date = g_key_file_get_integer (config,
+ CONFIG_RECENT_GROUP,
+ towers[i],
+ NULL);
+
+ if (date==0)
+ continue;
+
+ if (oldest_date==0 ||
+ date < oldest_date)
+ {
+ oldest_tower = towers[i];
+ oldest_date = date;
+ }
+ }
+
+ if (oldest_tower)
+ {
+ g_key_file_remove_key (config,
+ CONFIG_RECENT_GROUP,
+ oldest_tower,
+ NULL);
+ count --;
+ }
+ g_strfreev (towers);
+ }
+ while (count > MAX_RECENT);
+}
+