- Timestamp:
- 01/17/07 17:23:55 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ohand/branches/private/omoko/src/contacts-omoko-groups-editor.c
r838 r839 26 26 #include "contacts-utils.h" 27 27 28 static GtkWidget *groups_create_dialog (ContactsData *data); 28 static void groups_checkbutton_cb (GtkWidget *checkbutton, ContactsData *data); 29 void contacts_groups_pane_update_selection (GtkTreeSelection *selection, ContactsData *data); 29 30 30 31 /* TODO: put these in a struct and stop using global variables */ 31 32 static GHashTable *groups_widgets_hash; 32 static GtkWidget *contact_label;33 static GtkWidget *treeview, *groups_vbox;34 33 35 34 void 36 moko_open_groups_editor (GtkWidget *widget, ContactsData *data)35 contacts_groups_pane_show (GtkWidget *button, ContactsData *data) 37 36 { 38 groups_widgets_hash = g_hash_table_new (NULL, NULL); 39 if (!MOKO_IS_DIALOG_WINDOW (data->ui->chooser_dialog)) 40 data->ui->chooser_dialog = groups_create_dialog (data); 37 GtkWidget *widget; 38 GList *cur; 39 if (!groups_widgets_hash) 40 { 41 groups_widgets_hash = g_hash_table_new (NULL, NULL); 42 for (cur = data->contacts_groups; cur; cur = g_list_next (cur)) 43 { 44 widget = gtk_check_button_new_with_label (cur->data); 45 gtk_box_pack_start (GTK_BOX (data->ui->groups_vbox), widget, FALSE, FALSE, 6); 46 g_hash_table_insert (groups_widgets_hash, cur->data, widget); 47 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (groups_checkbutton_cb), data); 48 gtk_widget_show (widget); 49 } 50 } 51 gtk_notebook_set_current_page (GTK_NOTEBOOK (data->ui->main_notebook), CONTACTS_GROUPS_PANE); 41 52 42 moko_dialog_window_run (MOKO_DIALOG_WINDOW (data->ui->chooser_dialog)); 43 gtk_widget_hide (data->ui->chooser_dialog); 44 g_hash_table_destroy (groups_widgets_hash); 53 contacts_groups_pane_update_selection (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->ui->contacts_treeview)), data); 45 54 } 46 55 47 static void 48 groups_checkbutton_cb (GtkWidget *checkbutton, ContactsData *data) 49 { 50 EContact *contact; 51 GtkTreeSelection *selection; 52 GList *current_groups, *g = NULL; 53 gchar *new_group; 54 55 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (checkbutton), "UPDATING"))) 56 { 57 g_object_set_data (G_OBJECT(checkbutton), "updating", GINT_TO_POINTER (FALSE)); 58 return; 59 } 60 61 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); 62 63 contact = contacts_contact_from_selection (selection, 64 data->contacts_table); 65 current_groups = e_contact_get (contact, E_CONTACT_CATEGORY_LIST); 66 67 /* TODO: probably ought to do something better here */ 68 new_group = g_strdup(gtk_button_get_label (GTK_BUTTON (checkbutton))); 69 70 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton))) 71 { 72 /* add this to the contact */ 73 current_groups = g_list_append (current_groups, new_group); 74 } 75 else 76 { 77 /* make sure this isn't in the list */ 78 g = g_list_find_custom (current_groups, new_group, (GCompareFunc) strcmp); 79 if (g) 80 current_groups = g_list_remove (current_groups, g->data); 81 } 82 83 e_contact_set (contact, E_CONTACT_CATEGORY_LIST, current_groups); 84 e_book_async_commit_contact (data->book, contact, NULL, NULL); 85 } 86 87 static void 88 groups_contact_selection_cb (GtkTreeSelection * selection, ContactsData *data) 56 void 57 contacts_groups_pane_update_selection (GtkTreeSelection *selection, ContactsData *data) 89 58 { 90 59 GtkWidget *widget; 91 60 EContact *contact; 92 61 GList *groups, *g; 93 gchar *fullname, *markup; 62 63 64 if (!selection) 65 return; 94 66 95 67 /* Get the currently selected contact and update the contact summary */ … … 98 70 if (!contact) 99 71 return; 100 101 fullname = e_contact_get (contact, E_CONTACT_FULL_NAME);102 markup = g_markup_printf_escaped ("<span size=\"large\"><b>%s</b></span>", fullname);103 g_free (fullname);104 gtk_label_set_markup (GTK_LABEL (contact_label), markup);105 g_free (markup);106 72 107 73 groups = e_contact_get (contact, E_CONTACT_CATEGORY_LIST); … … 131 97 } 132 98 99 133 100 } 134 101 135 static void 136 groups_new_group_cb (GtkWidget *button, ContactsData *data) 102 void 103 contacts_groups_pane_hide () 104 { 105 g_hash_table_destroy (groups_widgets_hash); 106 } 107 108 109 void 110 contacts_groups_new_group_cb (GtkWidget *button, ContactsData *data) 137 111 { 138 112 GtkWidget *widget; … … 160 134 161 135 widget = gtk_check_button_new_with_label (text); 162 gtk_box_pack_start (GTK_BOX ( groups_vbox), widget, FALSE, FALSE, 0);136 gtk_box_pack_start (GTK_BOX (data->ui->groups_vbox), widget, FALSE, FALSE, 0); 163 137 g_hash_table_insert (groups_widgets_hash, text, widget); 164 138 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (groups_checkbutton_cb), data); 165 139 166 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW ( treeview));140 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->ui->contacts_treeview)); 167 141 if (gtk_tree_selection_count_selected_rows (selection) == 0) 168 142 { … … 180 154 } 181 155 182 static GtkWidget *183 groups_c reate_dialog (ContactsData *data)156 static void 157 groups_checkbutton_cb (GtkWidget *checkbutton, ContactsData *data) 184 158 { 185 GtkWidget *dialog;186 Gtk Widget *vbox;187 G tkWidget *widget;188 GtkWidget *details_vbox;159 EContact *contact; 160 GtkTreeSelection *selection; 161 GList *current_groups, *g = NULL; 162 gchar *new_group; 189 163 190 dialog = GTK_WIDGET (moko_dialog_window_new ()); 191 moko_dialog_window_set_title (MOKO_DIALOG_WINDOW (dialog), _("Group Membership") ); 192 193 vbox = gtk_vbox_new (FALSE, 0); 194 moko_dialog_window_set_contents (MOKO_DIALOG_WINDOW (dialog), vbox); 195 196 details_vbox = gtk_vbox_new (FALSE, 0); 197 gtk_container_set_border_width (GTK_CONTAINER (details_vbox), 24); 198 gtk_container_add (GTK_CONTAINER (vbox), details_vbox); 199 200 201 contact_label = gtk_label_new ("<span size=\"large\"><b>Contact Name</b></span>"); 202 gtk_box_pack_start (GTK_BOX (details_vbox), contact_label, FALSE, FALSE, 0); 203 gtk_label_set_use_markup (GTK_LABEL (contact_label), TRUE); 204 gtk_misc_set_alignment (GTK_MISC (contact_label), 0, 0); 205 206 widget = gtk_hseparator_new (); 207 gtk_box_pack_start (GTK_BOX (details_vbox), widget, FALSE, FALSE, 0); 208 209 groups_vbox = gtk_vbox_new (FALSE, 0); 210 gtk_container_set_border_width (GTK_CONTAINER (groups_vbox), 12); 211 212 widget = gtk_scrolled_window_new (NULL, NULL); 213 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, 214 GTK_POLICY_AUTOMATIC); 215 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (widget), groups_vbox); 216 gtk_box_pack_start (GTK_BOX (details_vbox), widget, TRUE, TRUE, 0); 217 218 /* FIXME: don't do this */ 219 gtk_viewport_set_shadow_type (GTK_VIEWPORT (groups_vbox->parent), GTK_SHADOW_NONE); 220 gtk_container_set_border_width (GTK_CONTAINER (groups_vbox->parent), 12); 221 222 widget = gtk_alignment_new (1, 0, 0, 0); 223 gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 0, 0, 0, 24); 224 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); 225 226 GtkWidget *new_group_button = gtk_button_new_with_label ("New Group"); 227 g_signal_connect (G_OBJECT(new_group_button), "clicked", G_CALLBACK (groups_new_group_cb), data); 228 gtk_container_add (GTK_CONTAINER (widget), new_group_button); 229 230 GList *cur; 231 for (cur = data->contacts_groups; cur; cur = g_list_next (cur)) 164 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (checkbutton), "updating"))) 232 165 { 233 widget = gtk_check_button_new_with_label (cur->data); 234 gtk_box_pack_start (GTK_BOX (groups_vbox), widget, FALSE, FALSE, 6); 235 g_hash_table_insert (groups_widgets_hash, cur->data, widget); 236 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (groups_checkbutton_cb), data); 237 gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE); 166 g_object_set_data (G_OBJECT(checkbutton), "updating", GINT_TO_POINTER (FALSE)); 167 return; 238 168 } 239 169 240 /* contacts list */ 241 widget = gtk_alignment_new (0, 0, 1, 1); 242 gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 12, 12, 12, 12); 243 gtk_box_pack_start (GTK_BOX(vbox), widget, FALSE, FALSE, 0); 170 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->ui->contacts_treeview)); 244 171 245 GtkWidget *list = create_contacts_list (data); 246 gtk_container_add (GTK_CONTAINER (widget), list); 247 248 /* Connect signal for selection changed event */ 249 treeview = GTK_WIDGET (moko_navigation_list_get_tree_view (list)); 250 GtkTreeSelection *selection; 251 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); 252 g_signal_connect (G_OBJECT (selection), "changed", 253 G_CALLBACK (groups_contact_selection_cb), data); 172 contact = contacts_contact_from_selection (selection, 173 data->contacts_table); 174 current_groups = e_contact_get (contact, E_CONTACT_CATEGORY_LIST); 254 175 255 gtk_widget_show_all (vbox); 176 /* TODO: probably ought to do something better here */ 177 new_group = g_strdup(gtk_button_get_label (GTK_BUTTON (checkbutton))); 256 178 257 return dialog; 179 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton))) 180 { 181 /* add this to the contact */ 182 current_groups = g_list_append (current_groups, new_group); 183 } 184 else 185 { 186 /* make sure this isn't in the list */ 187 g = g_list_find_custom (current_groups, new_group, (GCompareFunc) strcmp); 188 if (g) 189 current_groups = g_list_remove (current_groups, g->data); 190 } 258 191 192 e_contact_set (contact, E_CONTACT_CATEGORY_LIST, current_groups); 193 e_book_async_commit_contact (data->book, contact, NULL, NULL); 259 194 } 260 261
Note: See TracChangeset
for help on using the changeset viewer.
