📄 example-1.c
字号:
/* This program monitors the /apps/metacity/general/reduced_resources * gconf key, and allows the user to change it as well. */#include <gtk/gtk.h>#include <glade/glade.h>#include <gconf/gconf-client.h>static gboolean old_setting;voidgconf_key_changed_callback (GConfClient* client, guint cnxn_id, GConfEntry* entry, gpointer user_data){ GtkWidget* button; button = GTK_WIDGET (user_data); /* Make sure the preference has a valid value */ if (gconf_entry_get_value (entry) != NULL && gconf_entry_get_value (entry)->type == GCONF_VALUE_BOOL) { /* Get the new value */ gboolean new_setting = gconf_value_get_bool (gconf_entry_get_value (entry)); /* Try to handle asynchronous-ness of GConf and prevent calling * checkbutton_toggled_callback again if this function was * called as a result of the gconf_client_set_bool function call. */ if (new_setting != old_setting) { old_setting = new_setting; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), new_setting); } }}voidcheckbutton_toggled_callback (GtkWidget* check_button, gpointer user_data){ GConfClient* client = GCONF_CLIENT (user_data); /* Determine whether the checkbutton is already set or not */ gboolean is_set = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)); /* Try to handle asynchronous-ness of GConf and prevent calling * gconf_key_changed_callback again if this function was called as a * result of the gtk_toggle_button_set_active function call. */ if (is_set != old_setting) { old_setting = is_set; gconf_client_set_bool (client, "/apps/metacity/general/reduced_resources", is_set, NULL); }}voidhook_up_callbacks_and_set_defaults (GladeXML * the_widgets){ GtkWidget *widget; /* Get the GconfClient, tell it we want to monitor /apps/metacity/general */ GConfClient* client = gconf_client_get_default(); gconf_client_add_dir(client, "/apps/metacity/general", GCONF_CLIENT_PRELOAD_NONE, NULL); /* Get the check_button */ widget = glade_xml_get_widget (the_widgets, "Reduced Resources"); /* Connect the check_button to a callback that can toggle it when the option * is changed by some outside program. */ gconf_client_notify_add(client, "/apps/metacity/general/reduced_resources", gconf_key_changed_callback, widget, NULL, NULL); /* Connect the check_button's clicked callback up so that it can change the * gconf setting. */ g_signal_connect(G_OBJECT (widget), "clicked", G_CALLBACK (checkbutton_toggled_callback), client); /* Determine whether button should start activated or not */ old_setting = gconf_client_get_bool (client, "/apps/metacity/general/reduced_resources", NULL); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), old_setting); /* Get the main_window and connect the close button to gtk_main_quit */ widget = glade_xml_get_widget (the_widgets, "MainWindow"); g_signal_connect (G_OBJECT (widget), "delete_event", G_CALLBACK (gtk_main_quit), NULL); /* Get the quit button and it to gtk_main_quit */ widget = glade_xml_get_widget (the_widgets, "CloseButton"); g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (gtk_main_quit), NULL);}intmain (int argc, char **argv){ GladeXML *all_da_widgets; gtk_init (&argc, &argv); gconf_init(argc, argv, NULL); /* load the interface */ all_da_widgets = glade_xml_new ("example-1.glade", NULL, NULL); /* Connect all the signals to the appropriate callbacks */ hook_up_callbacks_and_set_defaults (all_da_widgets); /* start the event loop */ gtk_main (); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -