diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-01 18:38:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-01 18:38:45 +0000 |
commit | 5778dd84e93598a7837b9ce2c62725c03bb3996a (patch) | |
tree | 778f894f2a6a6fcd7950209cb5d011c874a2c563 | |
parent | d5f408ca11a8572d1902c30316c74b5f99261bc6 (diff) | |
download | gnunet-gtk-5778dd84e93598a7837b9ce2c62725c03bb3996a.tar.gz gnunet-gtk-5778dd84e93598a7837b9ce2c62725c03bb3996a.zip |
-LRN: Use destory signal to enforce ns manager singledness
, NS manager button in namespace dropdown list
-rw-r--r-- | contrib/gnunet_fs_gtk_main_window.glade | 80 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk.c | 2 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk.h | 2 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c | 7 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_namespace_manager.c | 63 |
5 files changed, 102 insertions, 52 deletions
diff --git a/contrib/gnunet_fs_gtk_main_window.glade b/contrib/gnunet_fs_gtk_main_window.glade index fd46bceb..4bd06cc9 100644 --- a/contrib/gnunet_fs_gtk_main_window.glade +++ b/contrib/gnunet_fs_gtk_main_window.glade | |||
@@ -773,41 +773,65 @@ | |||
773 | <signal name="leave_notify_event" handler="GNUNET_FS_GTK_search_namespace_selector_window_leave_notify_event_cb"/> | 773 | <signal name="leave_notify_event" handler="GNUNET_FS_GTK_search_namespace_selector_window_leave_notify_event_cb"/> |
774 | <signal name="enter_notify_event" handler="GNUNET_FS_GTK_search_namespace_dropdown_button_enter_notify_event_cb"/> | 774 | <signal name="enter_notify_event" handler="GNUNET_FS_GTK_search_namespace_dropdown_button_enter_notify_event_cb"/> |
775 | <child> | 775 | <child> |
776 | <object class="GtkTreeView" id="namespace_selector_treeview"> | 776 | <object class="GtkVBox" id="namespace_selector_main_vbox"> |
777 | <property name="visible">True</property> | ||
778 | <property name="can_focus">True</property> | ||
779 | <property name="is_focus">True</property> | ||
780 | <property name="model">main_window_search_namespace_treestore</property> | ||
781 | <property name="headers_clickable">False</property> | ||
782 | <property name="search_column">0</property> | ||
783 | <property name="hover_selection">True</property> | ||
784 | <property name="hover_expand">True</property> | ||
785 | <property name="tooltip_column">3</property> | ||
786 | <signal name="button_press_event" handler="GNUNET_FS_GTK_namespace_selector_treeview_button_press_event_cb"/> | ||
787 | <signal name="button_release_event" handler="GNUNET_FS_GTK_namespace_selector_treeview_button_release_event_cb"/> | ||
788 | <child> | 777 | <child> |
789 | <object class="GtkTreeViewColumn" id="name_column"> | 778 | <object class="GtkTreeView" id="namespace_selector_treeview"> |
790 | <property name="sizing">autosize</property> | 779 | <property name="visible">True</property> |
791 | <property name="title">Name</property> | 780 | <property name="can_focus">True</property> |
781 | <property name="is_focus">True</property> | ||
782 | <property name="model">main_window_search_namespace_treestore</property> | ||
783 | <property name="headers_clickable">False</property> | ||
784 | <property name="search_column">0</property> | ||
785 | <property name="hover_selection">True</property> | ||
786 | <property name="hover_expand">True</property> | ||
787 | <property name="tooltip_column">3</property> | ||
788 | <signal name="button_press_event" handler="GNUNET_FS_GTK_namespace_selector_treeview_button_press_event_cb"/> | ||
789 | <signal name="button_release_event" handler="GNUNET_FS_GTK_namespace_selector_treeview_button_release_event_cb"/> | ||
790 | <child> | ||
791 | <object class="GtkTreeViewColumn" id="name_column"> | ||
792 | <property name="sizing">autosize</property> | ||
793 | <property name="title">Name</property> | ||
794 | <child> | ||
795 | <object class="GtkCellRendererText" id="namespace_selector_name_column_text_cell"/> | ||
796 | <attributes> | ||
797 | <attribute name="text">0</attribute> | ||
798 | </attributes> | ||
799 | </child> | ||
800 | </object> | ||
801 | </child> | ||
792 | <child> | 802 | <child> |
793 | <object class="GtkCellRendererText" id="namespace_selector_name_column_text_cell"/> | 803 | <object class="GtkTreeViewColumn" id="key_column"> |
794 | <attributes> | 804 | <property name="sizing">autosize</property> |
795 | <attribute name="text">0</attribute> | 805 | <property name="title">Root</property> |
796 | </attributes> | 806 | <child> |
807 | <object class="GtkCellRendererText" id="namespace_selector_key_column_text_cell"/> | ||
808 | <attributes> | ||
809 | <attribute name="text">2</attribute> | ||
810 | </attributes> | ||
811 | </child> | ||
812 | </object> | ||
797 | </child> | 813 | </child> |
798 | </object> | 814 | </object> |
815 | <packing> | ||
816 | <property name="expand">True</property> | ||
817 | <property name="fill">True</property> | ||
818 | <property name="position">0</property> | ||
819 | </packing> | ||
799 | </child> | 820 | </child> |
800 | <child> | 821 | <child> |
801 | <object class="GtkTreeViewColumn" id="key_column"> | 822 | <object class="GtkButton" id="namespace_selector_manage_namespaces_button"> |
802 | <property name="sizing">autosize</property> | 823 | <property name="label" translatable="yes">_Manage namespaces</property> |
803 | <property name="title">Root</property> | 824 | <property name="visible">True</property> |
804 | <child> | 825 | <property name="can_focus">True</property> |
805 | <object class="GtkCellRendererText" id="namespace_selector_key_column_text_cell"/> | 826 | <property name="receives_default">False</property> |
806 | <attributes> | 827 | <property name="use_underline">True</property> |
807 | <attribute name="text">2</attribute> | 828 | <signal name="clicked" handler="namespace_selector_manage_namespaces_button_clicked_cb"/> |
808 | </attributes> | ||
809 | </child> | ||
810 | </object> | 829 | </object> |
830 | <packing> | ||
831 | <property name="expand">False</property> | ||
832 | <property name="fill">False</property> | ||
833 | <property name="position">1</property> | ||
834 | </packing> | ||
811 | </child> | 835 | </child> |
812 | </object> | 836 | </object> |
813 | </child> | 837 | </child> |
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c index 7cee7ac3..bbb94b13 100644 --- a/src/fs/gnunet-fs-gtk.c +++ b/src/fs/gnunet-fs-gtk.c | |||
@@ -173,7 +173,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
173 | void | 173 | void |
174 | GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) | 174 | GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) |
175 | { | 175 | { |
176 | struct GNUNET_GTK_MainWindowContext *main_context; | 176 | struct GNUNET_GTK_MainWindowContext *main_context = user_data; |
177 | 177 | ||
178 | main_window_save_position (main_context->main_window); | 178 | main_window_save_position (main_context->main_window); |
179 | 179 | ||
diff --git a/src/fs/gnunet-fs-gtk.h b/src/fs/gnunet-fs-gtk.h index af533fad..32b78d3d 100644 --- a/src/fs/gnunet-fs-gtk.h +++ b/src/fs/gnunet-fs-gtk.h | |||
@@ -56,6 +56,8 @@ struct GNUNET_GTK_MainWindowContext | |||
56 | GtkTreeRowReference *ns_selector_pushed_row; | 56 | GtkTreeRowReference *ns_selector_pushed_row; |
57 | GtkTreeRowReference *selected_ns_row; | 57 | GtkTreeRowReference *selected_ns_row; |
58 | int ns_callback_registered; | 58 | int ns_callback_registered; |
59 | GtkObject *ns_manager; | ||
60 | gulong ns_manager_delete_handler_id; | ||
59 | }; | 61 | }; |
60 | 62 | ||
61 | /** | 63 | /** |
diff --git a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c b/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c index f5697ef1..3f5da1cd 100644 --- a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c +++ b/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "gnunet-fs-gtk_common.h" | 26 | #include "gnunet-fs-gtk_common.h" |
27 | #include "gnunet-fs-gtk.h" | 27 | #include "gnunet-fs-gtk.h" |
28 | #include "gnunet-fs-gtk_event-handler.h" | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * How long until we automatically hide the drop-down if the cursor is outside the bounds? | 31 | * How long until we automatically hide the drop-down if the cursor is outside the bounds? |
@@ -435,4 +436,10 @@ GNUNET_GTK_main_window_refresh_ns_list (struct GNUNET_GTK_MainWindowContext *mai | |||
435 | GNUNET_free_non_null (selected_ns_id); | 436 | GNUNET_free_non_null (selected_ns_id); |
436 | } | 437 | } |
437 | 438 | ||
439 | void | ||
440 | namespace_selector_manage_namespaces_button_clicked_cb (GtkButton *button, gpointer user_data) | ||
441 | { | ||
442 | GNUNET_GTK_open_ns_manager (user_data); | ||
443 | } | ||
444 | |||
438 | /* end of gnunet-fs-gtk_main-window-namespace-dropdown.c */ | 445 | /* end of gnunet-fs-gtk_main-window-namespace-dropdown.c */ |
diff --git a/src/fs/gnunet-fs-gtk_namespace_manager.c b/src/fs/gnunet-fs-gtk_namespace_manager.c index 95763aef..69fe4969 100644 --- a/src/fs/gnunet-fs-gtk_namespace_manager.c +++ b/src/fs/gnunet-fs-gtk_namespace_manager.c | |||
@@ -50,15 +50,6 @@ struct GNUNET_GTK_NamespaceManagerContext | |||
50 | struct GNUNET_GTK_MainWindowContext *main_ctx; | 50 | struct GNUNET_GTK_MainWindowContext *main_ctx; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | /** | ||
54 | * THIS IS EVIL! Used to avoid opening more than one ns manager | ||
55 | * at once. Could be fixed by saving a pointer to the ns manager window | ||
56 | * somewhere in the main gnunet-fs-gtk window, but main window does | ||
57 | * not have a context structure for such things at the moment, hence | ||
58 | * this VERY EVIL GLOBAL VARIABLE! | ||
59 | */ | ||
60 | static struct GNUNET_GTK_NamespaceManagerContext *ns_manager = NULL; | ||
61 | |||
62 | #define GNUNET_GTK_KNOWN_NAMESPACES_IS_MINE_COLUMN 0 | 53 | #define GNUNET_GTK_KNOWN_NAMESPACES_IS_MINE_COLUMN 0 |
63 | #define GNUNET_GTK_KNOWN_NAMESPACES_RANK_COLUMN 1 | 54 | #define GNUNET_GTK_KNOWN_NAMESPACES_RANK_COLUMN 1 |
64 | #define GNUNET_GTK_KNOWN_NAMESPACES_NAME_COLUMN 2 | 55 | #define GNUNET_GTK_KNOWN_NAMESPACES_NAME_COLUMN 2 |
@@ -763,7 +754,6 @@ GNUNET_GTK_namespace_manager_dialog_response_cb (GtkDialog *dialog, | |||
763 | free_lists_contents (ctx); | 754 | free_lists_contents (ctx); |
764 | gtk_widget_destroy (GTK_WIDGET (ctx->namespace_manager)); | 755 | gtk_widget_destroy (GTK_WIDGET (ctx->namespace_manager)); |
765 | GNUNET_free (ctx); | 756 | GNUNET_free (ctx); |
766 | ns_manager = NULL; | ||
767 | } | 757 | } |
768 | } | 758 | } |
769 | 759 | ||
@@ -898,17 +888,10 @@ known_ns_selection_changed (GtkTreeSelection *treeselection, | |||
898 | gtk_widget_set_sensitive (ctx->details_apply_button, FALSE); | 888 | gtk_widget_set_sensitive (ctx->details_apply_button, FALSE); |
899 | } | 889 | } |
900 | 890 | ||
901 | 891 | GtkObject * | |
902 | 892 | GNUNET_GTK_namespace_manager_open (struct GNUNET_GTK_MainWindowContext *main_ctx) | |
903 | void | ||
904 | GNUNET_GTK_main_menu_file_manage_pseudonyms_activate_cb (GtkMenuItem *menuitem, | ||
905 | gpointer user_data) | ||
906 | { | 893 | { |
907 | struct GNUNET_GTK_MainWindowContext *main_ctx = user_data; | 894 | struct GNUNET_GTK_NamespaceManagerContext *ctx; |
908 | struct GNUNET_GTK_NamespaceManagerContext *ctx; | ||
909 | |||
910 | if (ns_manager != NULL) | ||
911 | return; | ||
912 | 895 | ||
913 | ctx = GNUNET_malloc (sizeof (struct GNUNET_GTK_NamespaceManagerContext)); | 896 | ctx = GNUNET_malloc (sizeof (struct GNUNET_GTK_NamespaceManagerContext)); |
914 | ctx->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_namespace_manager.glade", ctx); | 897 | ctx->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_namespace_manager.glade", ctx); |
@@ -916,7 +899,7 @@ GNUNET_GTK_main_menu_file_manage_pseudonyms_activate_cb (GtkMenuItem *menuitem, | |||
916 | { | 899 | { |
917 | GNUNET_break (0); | 900 | GNUNET_break (0); |
918 | GNUNET_free (ctx); | 901 | GNUNET_free (ctx); |
919 | return; | 902 | return NULL; |
920 | } | 903 | } |
921 | 904 | ||
922 | ctx->main_ctx = main_ctx; | 905 | ctx->main_ctx = main_ctx; |
@@ -967,12 +950,46 @@ GNUNET_GTK_main_menu_file_manage_pseudonyms_activate_cb (GtkMenuItem *menuitem, | |||
967 | /* sort namespace order list by rank (initially) */ | 950 | /* sort namespace order list by rank (initially) */ |
968 | sort_order_list (ctx, GNUNET_GTK_NAMESPACE_ORDER_RANK_COLUMN); | 951 | sort_order_list (ctx, GNUNET_GTK_NAMESPACE_ORDER_RANK_COLUMN); |
969 | 952 | ||
970 | ns_manager = ctx; | ||
971 | |||
972 | gtk_widget_set_sensitive (ctx->details_apply_button, FALSE); | 953 | gtk_widget_set_sensitive (ctx->details_apply_button, FALSE); |
973 | 954 | ||
974 | /* show dialog */ | 955 | /* show dialog */ |
975 | gtk_window_present (GTK_WINDOW (ctx->namespace_manager)); | 956 | gtk_window_present (GTK_WINDOW (ctx->namespace_manager)); |
957 | return GTK_OBJECT (ctx->namespace_manager); | ||
958 | } | ||
959 | |||
960 | void | ||
961 | ns_manager_deleted (GtkObject *object, gpointer user_data) | ||
962 | { | ||
963 | struct GNUNET_GTK_MainWindowContext *ctx = user_data; | ||
964 | g_signal_handler_disconnect (object, ctx->ns_manager_delete_handler_id); | ||
965 | g_object_unref (G_OBJECT (ctx->ns_manager)); | ||
966 | ctx->ns_manager = NULL; | ||
967 | ctx->ns_manager_delete_handler_id = 0; | ||
968 | return; | ||
969 | } | ||
970 | |||
971 | void | ||
972 | GNUNET_GTK_open_ns_manager (struct GNUNET_GTK_MainWindowContext *ctx) | ||
973 | { | ||
974 | if (ctx->ns_manager != NULL) | ||
975 | { | ||
976 | gtk_window_present (GTK_WINDOW (ctx->ns_manager)); | ||
977 | return; | ||
978 | } | ||
979 | |||
980 | ctx->ns_manager = GNUNET_GTK_namespace_manager_open (ctx); | ||
981 | if (ctx->ns_manager == NULL) | ||
982 | return; | ||
983 | |||
984 | g_object_ref (G_OBJECT (ctx->ns_manager)); | ||
985 | ctx->ns_manager_delete_handler_id = g_signal_connect (G_OBJECT (ctx->ns_manager), "destroy", G_CALLBACK (ns_manager_deleted), ctx); | ||
986 | } | ||
987 | |||
988 | void | ||
989 | GNUNET_GTK_main_menu_file_manage_pseudonyms_activate_cb (GtkMenuItem *menuitem, | ||
990 | gpointer user_data) | ||
991 | { | ||
992 | GNUNET_GTK_open_ns_manager (user_data); | ||
976 | } | 993 | } |
977 | 994 | ||
978 | /* end of gnunet-fs-gtk_namespace_manager.c */ | 995 | /* end of gnunet-fs-gtk_namespace_manager.c */ |