diff options
Diffstat (limited to 'src/gdu-utils.c')
-rw-r--r-- | src/gdu-utils.c | 120 |
1 files changed, 34 insertions, 86 deletions
diff --git a/src/gdu-utils.c b/src/gdu-utils.c index 0d01aef..8f72144 100644 --- a/src/gdu-utils.c +++ b/src/gdu-utils.c @@ -33,8 +33,8 @@ -GduPresentable * -find_presentable_from_mount_path (char *mount_path) +static GduPresentable * +_find_presentable (char *mount_path, char *device_path) { GduPool *pool; GList *presentables, *presentables_w; @@ -42,35 +42,43 @@ find_presentable_from_mount_path (char *mount_path) GduPresentable *pres_w; GduDevice *device; const char *device_mount; + const char *device_file; GFile *file1, *file2; - g_return_val_if_fail (mount_path != NULL, NULL); - g_return_val_if_fail (strlen (mount_path) > 1, NULL); - pool = gdu_pool_new (); presentables = gdu_pool_get_presentables (pool); presentables_w = presentables; while (presentables_w != NULL) { pres_w = presentables_w->data; +#if 0 if (pres_w) g_print ("presentable '%s', ref count = %d [%p]\n", gdu_presentable_get_name (pres_w), ((GObject*)pres_w)->ref_count, pres_w); +#endif if (! presentable && pres_w) { device = gdu_presentable_get_device (pres_w); if (device) { device_mount = gdu_device_get_mount_path (device); - if (device_mount && strlen (device_mount) > 1) { -// g_print ("find_presentable_from_path: found mount '%s', matching with '%s'\n", device_mount, mount_path); + device_file = gdu_device_get_device_file (device); + + /* match mount_path */ + if (mount_path && device_mount && strlen (device_mount) > 1) { /* compare via GFile routines */ file1 = g_file_new_for_commandline_arg (mount_path); file2 = g_file_new_for_path (device_mount); - if (g_file_equal (file1, file2)) { + if (g_file_equal (file1, file2)) presentable = g_object_ref (pres_w); - g_print (" reffing presentable, count = %d [%p]\n", ((GObject*)presentable)->ref_count, presentable); - break; - } g_object_unref (file1); g_object_unref (file2); + if (presentable) + break; + } + /* match device_path */ + if (device_path && device_file && strlen (device_file) > 1) { + if (strcmp (device_file, device_path) == 0) { + presentable = g_object_ref (pres_w); + break; + } } g_object_unref (device); } @@ -82,68 +90,26 @@ find_presentable_from_mount_path (char *mount_path) g_list_free (presentables); g_object_unref (pool); - if (presentable) - g_print ("find_presentable_from_path: found presentable '%s'\n", gdu_presentable_get_name (presentable)); - else - g_print ("find_presentable_from_path: no presentable found\n"); - return presentable; } +GduPresentable * +find_presentable_from_mount_path (char *mount_path) +{ + g_return_val_if_fail (mount_path != NULL, NULL); + g_return_val_if_fail (strlen (mount_path) > 1, NULL); + return _find_presentable (mount_path, NULL); +} GduPresentable * find_presentable_from_device_path (char *device_path) { - GduPool *pool; - GList *presentables, *presentables_w; - GduPresentable *presentable = NULL; - GduPresentable *pres_w; - GduDevice *device; - const char *device_file; - g_return_val_if_fail (device_path != NULL, NULL); g_return_val_if_fail (strlen (device_path) > 1, NULL); - - pool = gdu_pool_new (); - presentables = gdu_pool_get_presentables (pool); - - presentables_w = presentables; - while (presentables_w != NULL) { - pres_w = presentables_w->data; - if (pres_w) - g_print ("presentable '%s', ref count = %d [%p]\n", gdu_presentable_get_name (pres_w), ((GObject*)pres_w)->ref_count, pres_w); - if (! presentable) { - device = gdu_presentable_get_device (pres_w); - if (device) { - device_file = gdu_device_get_device_file (device); - if (device_file && strlen (device_file) > 1) { - g_print ("find_presentable_from_device_path: found device '%s', matching with '%s'\n", device_file, device_path); - if (strcmp (device_file, device_path) == 0) { - presentable = g_object_ref (pres_w); - g_print (" reffing presentable, count = %d [%p]\n", ((GObject*)presentable)->ref_count, presentable); - break; - } - } - g_object_unref (device); - } - } - presentables_w = g_list_next (presentables_w); - } - - g_list_foreach (presentables, (GFunc) g_object_unref, NULL); - g_list_free (presentables); - g_object_unref (pool); - - if (presentable) - g_print ("find_presentable_from_device_path: found presentable '%s'\n", gdu_presentable_get_name (presentable)); - else - g_print ("find_presentable_from_device_path: no presentable found\n"); - - return presentable; + return _find_presentable (NULL, device_path); } - /* ---------------------------------------------------------------------------------------------------- */ /* Volume selector widget */ @@ -202,8 +168,7 @@ gdu_util_presentable_combo_box_add_item (GtkListStore *store, GduPresentable *pr g_object_unref (toplevel_presentable); if (toplevel_device) g_object_unref (toplevel_device); - if (name) - g_free (name); + g_free (name); if (pixbuf) g_object_unref (pixbuf); } @@ -240,24 +205,15 @@ gdu_util_presentable_combo_box_create_store (GduPool *pool) if (toplevel_presentable) toplevel_device = gdu_presentable_get_device (toplevel_presentable); /* First eliminate all non-toplevel presentables */ - if (/* device != NULL && */ - toplevel_device != NULL && + if (toplevel_device != NULL && toplevel_presentable == presentable && - gdu_device_is_removable (toplevel_device) - /* && ! gdu_device_is_system_internal (device) */) { - + gdu_device_is_removable (toplevel_device)) + { /* determine parent presentables (in case of toplevel drive) */ enclosed_presentables = gdu_pool_get_enclosed_presentables (pool, presentable); g_print ("presentable %s [%s], enclosed_presentables = %d, toplevel_presentable = %p vs. %p, gdu_device_is_partition_table = %d, gdu_device_is_optical_disc = %d, gdu_device_drive_get_media = '%s'\n", gdu_presentable_get_name (presentable), device ? gdu_device_get_device_file (device) : "no device.", g_list_length (enclosed_presentables), toplevel_presentable, presentable, gdu_device_is_partition_table (device), gdu_device_is_optical_disc (device), gdu_device_drive_get_media (device)); -#if 0 - char **media_compat = gdu_device_drive_get_media_compatibility (device); - for (; *media_compat; media_compat++) { - g_print (" compat '%s'\n", *media_compat); - } -#endif - GList *enclosed_presentables_l; for (enclosed_presentables_l = enclosed_presentables; enclosed_presentables_l != NULL; enclosed_presentables_l = enclosed_presentables_l->next) { @@ -270,12 +226,6 @@ gdu_util_presentable_combo_box_create_store (GduPool *pool) g_object_unref (device_e); } -#if 0 - if (/* toplevel_device != NULL && gdu_device_is_removable (toplevel_device) && */ g_list_length (enclosed_presentables) == 0) { - gdu_util_presentable_combo_box_add_item (store, presentable); - } -#endif - g_list_foreach (enclosed_presentables, (GFunc) g_object_unref, NULL); g_list_free (enclosed_presentables); } @@ -337,15 +287,13 @@ gdu_util_presentable_combo_box_text_renderer_func (GtkCellLayout *cell_layout, display_name = g_strdup_printf ("<span font_desc='18'><b> %s</b></span>", name); } - g_object_set (cell, "sensitive", sensitive, /* "visible", visible, */ NULL); + g_object_set (cell, "sensitive", sensitive, NULL); if (GTK_IS_CELL_RENDERER_TEXT (cell)) g_object_set (cell, "markup", display_name, NULL); g_free (display_name); - if (name) - g_free (name); - if (device_path) - g_free (device_path); + g_free (name); + g_free (device_path); gtk_tree_path_free (path); } |