Yasumichi Akahoshi
yasum****@users*****
2005年 5月 19日 (木) 11:00:06 JST
Index: cxplorer/src/cxplorer-window.c diff -u cxplorer/src/cxplorer-window.c:1.57 cxplorer/src/cxplorer-window.c:1.58 --- cxplorer/src/cxplorer-window.c:1.57 Thu May 19 09:24:11 2005 +++ cxplorer/src/cxplorer-window.c Thu May 19 11:00:06 2005 @@ -34,6 +34,7 @@ #include <sys/stat.h> #include <unistd.h> #include <errno.h> +#include <string.h> #include "cxp-dir-view.h" #include "cxp-right-pane.h" #include "cxp-property-dialog.h" @@ -63,6 +64,7 @@ GtkUIManager *ui_manager; GtkWidget *menubar; GtkWidget *toolbar; + GHashTable *dynamic_widgets; GtkWidget *entry; GtkWidget *dirview; GtkWidget *right_pane; @@ -83,9 +85,9 @@ static void cxplorer_window_instance_init (GTypeInstance * instance, gpointer g_class); static void cxplorer_window_sendto_menu_init (CxplorerWindow *self); -static void cxplorer_window_menu_item_new_from_sendto (const gchar *caption, const gchar *command, gpointer user_data); +static GtkWidget* cxplorer_window_menu_item_new_from_sendto (const gchar *caption, const gchar *command, gpointer user_data); static void cxplorer_window_bookmark_menu_init (CxplorerWindow *self); -static void cxplorer_window_menu_item_new_from_bookmark (const gchar *key, const gchar *value, gpointer user_data); +static GtkWidget* cxplorer_window_menu_item_new_from_bookmark (const gchar *key, const gchar *value, gpointer user_data); static void cxplorer_window_dispose (GObject * obj); static void cxplorer_window_finalize (GObject * obj); static void cxplorer_window_entry_activate (GtkWidget *widget, gpointer user_data); @@ -115,6 +117,8 @@ static void cxplorer_window_sendto_activate (GtkWidget *widget, gpointer user_data); static void cxplorer_window_user_bookmark_activate (GtkWidget *widget, gpointer user_data); +static void cxplorer_window_gconf_value_changed (GConfClient* client, const gchar* key, GConfValue* value, gpointer user_data); + /** * Actions */ @@ -199,7 +203,8 @@ gchar *filter; private->client = gconf_client_get_default (); - gconf_client_add_dir (private->client, CXPLORER_GCONF_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL); + gconf_client_add_dir (private->client, BOOKMARK_GCONF_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL); + gconf_client_add_dir (private->client, SENDTO_GCONF_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL); show_dot_file = gconf_client_get_bool (private->client, CXPLORER_GCONF_DIR"/ShowDotFile", NULL); filter = gconf_client_get_string (private->client, CXPLORER_GCONF_DIR"/FilenameFilter", NULL); if(filter != NULL) @@ -208,6 +213,7 @@ g_free (filter); } + private->dynamic_widgets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (self), vbox); @@ -303,6 +309,7 @@ g_signal_connect (right_pane, "up_dir_request", G_CALLBACK (cxplorer_window_go_up_action), self); + g_signal_connect (private->client, "value_changed", G_CALLBACK(cxplorer_window_gconf_value_changed), self); } /** @@ -313,23 +320,30 @@ static void cxplorer_window_sendto_menu_init (CxplorerWindow *self) { CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (self); + GtkWidget *menu_item; GSList *sendto_list; GSList *node; GConfEntry *entry; GConfValue *value; + gchar *key; sendto_list = gconf_client_all_entries (private->client, SENDTO_GCONF_DIR, NULL); node = sendto_list; while (node != NULL) { entry = node->data; + key = g_strdup (gconf_entry_get_key(entry)); value = gconf_entry_get_value (entry); if (value && value->type == GCONF_VALUE_PAIR) { - cxplorer_window_menu_item_new_from_sendto ( + menu_item = cxplorer_window_menu_item_new_from_sendto ( gconf_value_get_string(gconf_value_get_car(value)), gconf_value_get_string(gconf_value_get_cdr(value)), self); + if (menu_item) + { + g_hash_table_insert (private->dynamic_widgets, key, menu_item); + } } gconf_entry_free (entry); node = g_slist_next(node); @@ -346,32 +360,36 @@ * @param [in] user_data CxplorerWindow * \endif */ -static void cxplorer_window_menu_item_new_from_sendto (const gchar *caption, const gchar *command, gpointer user_data) +static GtkWidget* cxplorer_window_menu_item_new_from_sendto (const gchar *caption, const gchar *command, gpointer user_data) { CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (user_data); GtkWidget *menu; - GtkWidget *menuitem; + GtkWidget *menuitem = NULL; + GtkWidget *senditem = NULL; const gchar *path[] = { "/menubar/FileMenu/SendMenu", "/popup/SendMenu", }; guint idx; - g_return_if_fail (caption != NULL); - g_return_if_fail (command != NULL); + g_return_val_if_fail (caption != NULL, NULL); + g_return_val_if_fail (command != NULL, NULL); + for (idx=0; idx<G_N_ELEMENTS(path); idx++) { if((menuitem = gtk_ui_manager_get_widget (private->ui_manager, path[idx])) != NULL) { + senditem = gtk_menu_item_new_with_label (caption); + g_object_set_data (G_OBJECT (senditem), "config_value", g_strdup(command)); + g_signal_connect (senditem, "activate", G_CALLBACK(cxplorer_window_sendto_activate), user_data); + gtk_widget_show (senditem); menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuitem)); - menuitem = gtk_menu_item_new_with_label (caption); - g_object_set_data (G_OBJECT (menuitem), "command", g_strdup(command)); - gtk_container_add (GTK_CONTAINER(menu), menuitem); - g_signal_connect (menuitem, "activate", G_CALLBACK(cxplorer_window_sendto_activate), user_data); - gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER(menu), senditem); } } + + return senditem; } /** @@ -382,23 +400,30 @@ static void cxplorer_window_bookmark_menu_init (CxplorerWindow *self) { CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (self); + GtkWidget *menu_item; GSList *bookmark_list; GSList *node; GConfEntry *entry; GConfValue *value; + gchar *key; bookmark_list = gconf_client_all_entries (private->client, BOOKMARK_GCONF_DIR, NULL); node = bookmark_list; while (node != NULL) { entry = node->data; + key = g_strdup(gconf_entry_get_key(entry)); value = gconf_entry_get_value (entry); if (value && value->type == GCONF_VALUE_PAIR) { - cxplorer_window_menu_item_new_from_bookmark ( + menu_item = cxplorer_window_menu_item_new_from_bookmark ( gconf_value_get_string(gconf_value_get_car(value)), gconf_value_get_string(gconf_value_get_cdr(value)), self); + if (menu_item) + { + g_hash_table_insert (private->dynamic_widgets, key, menu_item); + } } gconf_entry_free (entry); node = g_slist_next(node); @@ -415,24 +440,26 @@ * @param [in] user_data CxplorerWindow * \endif */ -static void cxplorer_window_menu_item_new_from_bookmark (const gchar *key, const gchar *value, gpointer user_data) +static GtkWidget *cxplorer_window_menu_item_new_from_bookmark (const gchar *key, const gchar *value, gpointer user_data) { CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (user_data); GtkWidget *menu; - GtkWidget *menuitem; + GtkWidget *menuitem = NULL; - g_return_if_fail (key != NULL); - g_return_if_fail (value != NULL); + g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (value != NULL, NULL); if((menuitem = gtk_ui_manager_get_widget (private->ui_manager, "/menubar/BookmarkMenu")) != NULL) { menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuitem)); menuitem = gtk_menu_item_new_with_label (key); - g_object_set_data (G_OBJECT (menuitem), "dirname", g_strdup(value)); + g_object_set_data (G_OBJECT (menuitem), "config_value", g_strdup(value)); gtk_container_add (GTK_CONTAINER(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK(cxplorer_window_user_bookmark_activate), user_data); gtk_widget_show (menuitem); } + + return menuitem; } static void cxplorer_window_dispose (GObject * obj) @@ -456,6 +483,7 @@ g_object_unref (private->client); g_object_unref (private->action_group); g_object_unref (private->ui_manager); + g_hash_table_destroy (private->dynamic_widgets); cxp_utils_free_filename_filter (); /* Chain up to the parent class */ @@ -855,6 +883,7 @@ { CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (user_data); GtkWidget *dialog; + GtkWidget *menu_item; gchar *cur_dir; gchar *dir_utf8; gchar *message; @@ -876,10 +905,10 @@ /* ブックマーク名とディレクトリ名のペアを登録する */ gconf_client_set_pair (private->client, bookmark_key, GCONF_VALUE_STRING, GCONF_VALUE_STRING, &alias, &dir_utf8, NULL); - cxplorer_window_menu_item_new_from_bookmark (alias, cur_dir, user_data); + menu_item = cxplorer_window_menu_item_new_from_bookmark (alias, cur_dir, user_data); + g_hash_table_insert (private->dynamic_widgets, bookmark_key, menu_item); g_free (alias); g_free (bookmark_name); - g_free (bookmark_key); } gtk_widget_destroy (dialog); @@ -927,7 +956,7 @@ CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (user_data); gchar *cmd; - if((cmd = g_object_get_data (G_OBJECT (widget), "command")) != NULL) + if((cmd = g_object_get_data (G_OBJECT (widget), "config_value")) != NULL) { cxp_right_pane_send_file_to_command (CXP_RIGHT_PANE(private->right_pane), cmd); } @@ -949,7 +978,68 @@ label = gtk_bin_get_child (GTK_BIN(widget)); if (GTK_IS_LABEL(label)) { - dirname = g_object_get_data (G_OBJECT(widget), "dirname"); + dirname = g_object_get_data (G_OBJECT(widget), "config_value"); cxp_dir_view_change_directory (CXP_DIR_VIEW(private->dirview), dirname); } } + +/** + * \if japanese + * GConfが監視中のディレクトリで値の変化を検出した時のコールバック + * \endif + */ +static void cxplorer_window_gconf_value_changed (GConfClient* client, const gchar* key, GConfValue* value, gpointer user_data) +{ + CxplorerWindow *self = CXPLORER_WINDOW (user_data); + CxplorerWindowPrivate *private = CXPLORER_WINDOW_GET_PRIVATE (user_data); + GtkWidget *menu_item; + GtkWidget *label; + gchar *dir; + + if (private) + { + g_print ("private valid.\n"); + } + g_print ("%s was changed.\n", key); + if (value == NULL) + { + menu_item = g_hash_table_lookup (private->dynamic_widgets, key); + gtk_widget_destroy (menu_item); + g_hash_table_remove (private->dynamic_widgets, key); + } + else if (value->type == GCONF_VALUE_PAIR) + { + menu_item = g_hash_table_lookup (private->dynamic_widgets, key); + if (menu_item) + { + label = gtk_bin_get_child (GTK_BIN(menu_item)); + gtk_label_set_text (GTK_LABEL(label), gconf_value_get_string(gconf_value_get_car(value))); + g_object_set_data (G_OBJECT(menu_item), "config_value", g_strdup(gconf_value_get_string(gconf_value_get_cdr(value)))); + } + else + { + dir = g_path_get_dirname (key); + if (strcmp(dir, BOOKMARK_GCONF_DIR) == 0) + { + menu_item = cxplorer_window_menu_item_new_from_bookmark ( + gconf_value_get_string(gconf_value_get_car(value)), + gconf_value_get_string(gconf_value_get_cdr(value)), + self); + } + else if (strcmp(dir, SENDTO_GCONF_DIR) == 0) + { + menu_item = cxplorer_window_menu_item_new_from_sendto ( + gconf_value_get_string(gconf_value_get_car(value)), + gconf_value_get_string(gconf_value_get_cdr(value)), + self); + } + + if (menu_item) + { + g_hash_table_insert (private->dynamic_widgets, g_strdup(key), menu_item); + } + + g_free (dir); + } + } +}