]> git.itanic.dy.fi Git - maemo-mapper/commitdiff
* Fixed bug where Maemo Mapper persists in memory after closing.
authorgnuite <gnuite@gmail.com>
Mon, 21 Jan 2008 07:02:55 +0000 (07:02 +0000)
committergnuite <gnuite@gmail.com>
Mon, 21 Jan 2008 07:02:55 +0000 (07:02 +0000)
  * Added ability to "compact" (aka "reorganize") a map cache database.

git-svn-id: svn+ssh://garage/var/lib/gforge/svnroot/maemo-mapper/trunk@149 6c538b50-5814-0410-93ad-8bdf4c0149d1

src/main.c
src/main.h
src/maps.c

index 59b653f6da39a1283c3be5dd7ca33fe38f20ddc8..da13166c3ff8b5517f924c5fe97e13de2cdef009 100644 (file)
@@ -130,13 +130,13 @@ conic_recommend_connected()
     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
 
     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
 
-void
+gboolean
 conic_ensure_connected()
 {
     printf("%s()\n", __PRETTY_FUNCTION__);
 
 #ifndef DEBUG
 conic_ensure_connected()
 {
     printf("%s()\n", __PRETTY_FUNCTION__);
 
 #ifndef DEBUG
-    while(!_conic_is_connected)
+    while(_window && !_conic_is_connected)
     {   
         g_mutex_lock(_conic_connection_mutex);
         /* If we're not connected, and if we're not connecting, and if we're
     {   
         g_mutex_lock(_conic_connection_mutex);
         /* If we're not connected, and if we're not connecting, and if we're
@@ -152,7 +152,9 @@ conic_ensure_connected()
     }
 #endif
 
     }
 #endif
 
-    vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+    vprintf("%s(): return %d\n", __PRETTY_FUNCTION__,
+            _window && _conic_is_connected);
+    return _window && _conic_is_connected;
 }
 
 /**
 }
 
 /**
@@ -180,6 +182,9 @@ maemo_mapper_destroy()
     g_mutex_unlock(_mut_priority_mutex);
 
     /* Allow remaining downloads to finish. */
     g_mutex_unlock(_mut_priority_mutex);
 
     /* Allow remaining downloads to finish. */
+    g_mutex_lock(_conic_connection_mutex);
+    g_cond_broadcast(_conic_connection_cond);
+    g_mutex_unlock(_conic_connection_mutex);
     g_thread_pool_free(_mut_thread_pool, TRUE, TRUE);
 
     if(_curr_repo->db)
     g_thread_pool_free(_mut_thread_pool, TRUE, TRUE);
 
     if(_curr_repo->db)
index c82e48fe0af0c182edaf031726ccbc9016e8bef8..035b66c0cde79489afda071e78fc189553e13cf8 100644 (file)
@@ -27,6 +27,6 @@
 gint main(gint argc, gchar *argv[]);
 
 void conic_recommend_connected(void);
 gint main(gint argc, gchar *argv[]);
 
 void conic_recommend_connected(void);
-void conic_ensure_connected(void);
+gboolean conic_ensure_connected(void);
 
 #endif /* ifndef MAEMO_MAPPER_MAIN_H */
 
 #endif /* ifndef MAEMO_MAPPER_MAIN_H */
index 9d0457afeb95390ac5092f83faac3eba5b848860..177ff8c1dbd01e956fa1787d6b813cb22eb61870 100644 (file)
@@ -80,6 +80,7 @@ struct _RepoEditInfo {
     GtkWidget *chk_double_size;
     GtkWidget *chk_nextable;
     GtkWidget *btn_browse;
     GtkWidget *chk_double_size;
     GtkWidget *chk_nextable;
     GtkWidget *btn_browse;
+    GtkWidget *btn_compact;
     GtkWidget *num_min_zoom;
     GtkWidget *num_max_zoom;
     BrowseInfo browse_info;
     GtkWidget *num_min_zoom;
     GtkWidget *num_max_zoom;
     BrowseInfo browse_info;
@@ -109,6 +110,15 @@ struct _MapmanInfo {
     GtkWidget *chk_zoom_levels[MAX_ZOOM + 1];
 };
 
     GtkWidget *chk_zoom_levels[MAX_ZOOM + 1];
 };
 
+typedef struct _CompactInfo CompactInfo;
+struct _CompactInfo {
+    GtkWidget *dialog;
+    GtkWidget *txt;
+    GtkWidget *banner;
+    const gchar *db_filename;
+    gchar *status_msg;
+};
+
 typedef struct _MapCacheKey MapCacheKey;
 struct _MapCacheKey {
     RepoData      *repo;
 typedef struct _MapCacheKey MapCacheKey;
 struct _MapCacheKey {
     RepoData      *repo;
@@ -1383,15 +1393,12 @@ thread_proc_mut()
     /* Make sure things are inititalized. */
     gnome_vfs_init();
 
     /* Make sure things are inititalized. */
     gnome_vfs_init();
 
-    while(TRUE)
+    while(conic_ensure_connected())
     {
         gint retries;
         gboolean refresh_sent = FALSE;
         MapUpdateTask *mut = NULL;
 
     {
         gint retries;
         gboolean refresh_sent = FALSE;
         MapUpdateTask *mut = NULL;
 
-        /* Wait until we are connected. */
-        conic_ensure_connected();
-
         /* Get the next MUT from the mut tree. */
         g_mutex_lock(_mut_priority_mutex);
         g_tree_foreach(_mut_priority_tree, (GTraverseFunc)get_next_mut, &mut);
         /* Get the next MUT from the mut tree. */
         g_mutex_lock(_mut_priority_mutex);
         g_tree_foreach(_mut_priority_tree, (GTraverseFunc)get_next_mut, &mut);
@@ -1651,6 +1658,124 @@ repoman_dialog_browse(GtkWidget *widget, BrowseInfo *browse_info)
     return TRUE;
 }
 
     return TRUE;
 }
 
+static gboolean
+repoman_compact_complete_idle(CompactInfo *ci)
+{
+    printf("%s()\n", __PRETTY_FUNCTION__);
+
+    gtk_widget_destroy(GTK_WIDGET(ci->banner));
+    popup_error(ci->dialog, ci->status_msg);
+    gtk_widget_destroy(ci->dialog);
+    g_free(ci);
+
+    vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
+    return FALSE;
+}
+
+static void
+thread_repoman_compact(CompactInfo *ci)
+{
+    GDBM_FILE db;
+    printf("%s()\n", __PRETTY_FUNCTION__);
+
+    if(!(db = gdbm_open((gchar*)ci->db_filename, 0, GDBM_WRITER | GDBM_FAST,
+                    0644, NULL)))
+        ci->status_msg = _("Failed to open map database for compacting.");
+    else
+    {
+        if(gdbm_reorganize(db))
+            ci->status_msg = _("An error occurred while trying to "
+                        "compact the database.");
+        else
+            ci->status_msg = _("Successfully compacted database.");
+        gdbm_close(db);
+    }
+
+    g_idle_add((GSourceFunc)repoman_compact_complete_idle, ci);
+
+    vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+}
+
+static void
+repoman_dialog_compact(GtkWidget *widget, BrowseInfo *browse_info)
+{
+    CompactInfo *ci;
+    GtkWidget *sw;
+    printf("%s()\n", __PRETTY_FUNCTION__);
+
+    ci = g_new0(CompactInfo, 1);
+
+    ci->dialog = gtk_dialog_new_with_buttons(_("Compact Database"),
+            GTK_WINDOW(browse_info->dialog), GTK_DIALOG_MODAL,
+            GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+            GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+            NULL);
+
+    sw = gtk_scrolled_window_new (NULL, NULL);
+    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
+            GTK_SHADOW_ETCHED_IN);
+    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+            GTK_POLICY_NEVER,
+            GTK_POLICY_ALWAYS);
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(ci->dialog)->vbox),
+            sw, TRUE, TRUE, 0);
+
+    gtk_container_add(GTK_CONTAINER(sw), ci->txt = gtk_text_view_new());
+    gtk_text_view_set_editable(GTK_TEXT_VIEW(ci->txt), FALSE);
+    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ci->txt), FALSE);
+    gtk_text_buffer_set_text(
+            gtk_text_view_get_buffer(GTK_TEXT_VIEW(ci->txt)),
+            _("Generally, deleted maps create an empty space in the "
+                "database that is later reused when downloading new maps.  "
+                "Compacting the database reorganizes it such that all "
+                "that blank space is eliminated.  This is the only way "
+                "that the size of the database can decrease.\n"
+                "This reorganization requires creating a new file and "
+                "inserting all the maps in the old database file into the "
+                "new file. The new file is then renamed to the same name "
+                "as the old file and dbf is updated to contain all the "
+                "correct information about the new file.  Note that this "
+                "can require free space on disk of an amount up to the size "
+                "of the map database.\n"
+                "This process may take several minutes, especially if "
+                "your map database is large.  As a rough estimate, you can "
+                "expect to wait approximately 2-5 seconds per megabyte of "
+                "map data (34-85 minutes per gigabyte).  There is no progress "
+                "indicator, although you can watch the new file grow in any "
+                "file manager.  Do not attempt to close Maemo Mapper while "
+                "the compacting operation is in progress."),
+            -1);
+    {
+        GtkTextIter iter;
+        gtk_text_buffer_get_iter_at_offset(
+                gtk_text_view_get_buffer(GTK_TEXT_VIEW(ci->txt)),
+                &iter, 0);
+        gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ci->txt),
+                &iter, 0.0, FALSE, 0, 0);
+    }
+
+    gtk_widget_set_size_request(GTK_WIDGET(sw), 600, 200);
+    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(ci->txt), GTK_WRAP_WORD);
+
+    gtk_widget_show_all(ci->dialog);
+
+    if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(ci->dialog)))
+    {
+        gtk_widget_set_sensitive(GTK_DIALOG(ci->dialog)->action_area, FALSE);
+        ci->db_filename = gtk_entry_get_text(GTK_ENTRY(browse_info->txt));
+        ci->banner = hildon_banner_show_animation(ci->dialog, NULL,
+                _("Compacting database..."));
+
+        g_thread_create((GThreadFunc)thread_repoman_compact, ci, FALSE, NULL);
+    }
+    else
+    {
+        gtk_widget_destroy(ci->dialog);
+    }
+
+    vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+}
+
 static gboolean
 repoman_dialog_rename(GtkWidget *widget, RepoManInfo *rmi)
 {
 static gboolean
 repoman_dialog_rename(GtkWidget *widget, RepoManInfo *rmi)
 {
@@ -1800,6 +1925,9 @@ repoman_dialog_add_repo(RepoManInfo *rmi, gchar *name)
     gtk_box_pack_start(GTK_BOX(hbox),
             rei->btn_browse = gtk_button_new_with_label(_("Browse...")),
             FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(hbox),
             rei->btn_browse = gtk_button_new_with_label(_("Browse...")),
             FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(hbox),
+            rei->btn_compact = gtk_button_new_with_label(_("Compact...")),
+            FALSE, FALSE, 0);
 
     /* Initialize cache dir */
     {
 
     /* Initialize cache dir */
     {
@@ -1908,6 +2036,9 @@ repoman_dialog_add_repo(RepoManInfo *rmi, gchar *name)
     g_signal_connect(G_OBJECT(rei->btn_browse), "clicked",
                       G_CALLBACK(repoman_dialog_browse),
                       &rei->browse_info);
     g_signal_connect(G_OBJECT(rei->btn_browse), "clicked",
                       G_CALLBACK(repoman_dialog_browse),
                       &rei->browse_info);
+    g_signal_connect(G_OBJECT(rei->btn_compact), "clicked",
+                      G_CALLBACK(repoman_dialog_compact),
+                      &rei->browse_info);
 
     gtk_widget_show_all(vbox);
 
 
     gtk_widget_show_all(vbox);