Mercurial > pidgin
changeset 6340:7a34722b3164
[gaim-migrate @ 6839]
DIE old vCard/MultiEntryDlg API! We're better off without you!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 30 Jul 2003 08:14:39 +0000 |
parents | cc527f9ba197 |
children | 21378ec5764d |
files | src/dialogs.c src/gaim.h |
diffstat | 2 files changed, 0 insertions(+), 607 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dialogs.c Wed Jul 30 08:09:54 2003 +0000 +++ b/src/dialogs.c Wed Jul 30 08:14:39 2003 +0000 @@ -4144,530 +4144,3 @@ gtk_widget_show_all(bbox); return button; } - -/*------------------------------------------------------------------------*/ -/* The dialog for setting V-Card info */ -/*------------------------------------------------------------------------*/ -/* - * There are actually two "chunks" of code following: generic "multi-entry dialog" - * support and V-Card dialog specific support. - * - * At first blush, this may seem like an unnecessary duplication of effort given - * that a "set dir info" dialog already exists. However, this is not so because: - * - * 1. V-Cards can have a lot more data in them than what the current - * "set dir" dialog supports. - * - * 2. V-Card data, at least with respect to Jabber, is currently in a - * state of flux. As the data and format changes, all that need be - * changed with the V-Card support I've written is the "template" - * data. - * - * 3. The "multi entry dialog" support itself was originally written - * to support Jabber server user registration (TBD). A "dynamically - * configurable" multi-entry dialog is needed for that, as different - * servers may require different registration information. It just - * turned out to be well-suited to adding V-Card setting support, as - * well :-). - * - * TBD: Add check-box support to the generic multi-entry dialog support so that - * it can be used to "replace" the "set dir info" support? - * - * Multiple-language support. Currently Not In There. I think this should - * be easy. Note that when it's added: if anybody saved their data in - * English, it'll be lost when MLS is added and they'll have to re-enter it. - * - * More "TBDs" noted in the code. - */ - - -/*------------------------------------*/ -/* generic multi-entry dialog support */ -/*------------------------------------*/ - -/* - * Print all multi-entry items - * - * Note: Simply a debug helper - */ -void multi_entry_item_print_all(const GSList *list) { - - int cnt = 0; - - /* While there's something to print... */ - while(list != NULL) { - fprintf(stderr, "label %2d: \"%s\"", ++cnt, ((MultiEntryData *) (list->data))->label); - if(((MultiEntryData *) (list->data))->text != NULL) { - fprintf(stderr, ", text: \"%s\"", ((MultiEntryData *) (list->data))->text); - } - fputs("\n", stderr); - list = list->next; - } -} - -/* - * Print all multi-text items - * - * Note: Simply a debug helper - */ -void multi_text_item_print_all(const GSList *list) { - - int cnt = 0; - - /* While there's something to print... */ - while(list != NULL) { - fprintf(stderr, "label %2d: \"%s\"", ++cnt, ((MultiTextData *) (list->data))->label); - if(((MultiTextData *) (list->data))->text != NULL) { - fprintf(stderr, ", text: \"%s\"", ((MultiTextData *) (list->data))->text); - } - fputs("\n", stderr); - list = list->next; - } -} - - -/* - * Free all multi-entry item allocs and NULL the list pointer - */ -void multi_entry_items_free_all(GSList **list) -{ - - GSList *next = *list; - MultiEntryData *data; - - /* While there's something to free() ... */ - while(next != NULL) { - data = (MultiEntryData *) next->data; - g_free(data->label); - g_free(data->text); - g_free(data); - next = next->next; - } - g_slist_free(*list); - *list = NULL; -} - -/* - * Free all multi-text item allocs and NULL the list pointer - */ -void multi_text_items_free_all(GSList **list) -{ - - GSList *next = *list; - MultiTextData *data; - - /* While there's something to free() ... */ - while(next != NULL) { - data = (MultiTextData *) next->data; - g_free(data->label); - g_free(data->text); - g_free(data); - next = next->next; - } - g_slist_free(*list); - *list = NULL; -} - -/* - * See if a MultiEntryData item contains a given label - * - * See: glib docs for g_slist_compare_custom() for details - */ -static gint multi_entry_data_label_compare(gconstpointer data, gconstpointer label) -{ - return(strcmp(((MultiEntryData *) (data))->label, (char *) label)); -} - -/* - * Add a new multi-entry item to list - * - * If adding to existing list: will search the list for existence of - * "label" and change/create "text" entry if necessary. - */ - -MultiEntryData *multi_entry_list_update(GSList **list, const char *label, const char *text, int add_it) -{ - GSList *found; - MultiEntryData *data; - - if((found = g_slist_find_custom(*list, (void *)label, multi_entry_data_label_compare)) == NULL) { - if(add_it) { - data = (MultiEntryData *) g_slist_last(*list = - g_slist_append(*list, g_malloc(sizeof(MultiEntryData))))->data; - data->label = strcpy(g_malloc(strlen(label) +1), label); - data->text = NULL; - /* - * default to setting "visible" and editable to TRUE - they can be - * overridden later, of course. - */ - data->visible = TRUE; - data->editable = TRUE; - } else { - data = NULL; - } - } else { - data = found->data; - } - - if(data != NULL && text != NULL && text[0] != '\0') { - if(data->text == NULL) { - data->text = g_malloc(strlen(text) + 1); - } else { - data->text = g_realloc(data->text, strlen(text) + 1); - } - strcpy(data->text, text); - } - - return(data); -} - -/* - * See if a MultiTextData item contains a given label - * - * See: glib docs for g_slist_compare_custom() for details - */ -static gint multi_text_data_label_compare(gconstpointer data, gconstpointer label) -{ - return(strcmp(((MultiTextData *) (data))->label, (char *) label)); -} - -/* - * Add a new multi-text item to list - * - * If adding to existing list: will search the list for existence of - * "label" and change/create "text" text if necessary. - */ - -MultiTextData *multi_text_list_update(GSList **list, const char *label, const char *text, int add_it) -{ - GSList *found; - MultiTextData *data; - - if((found = g_slist_find_custom(*list, (void *)label, multi_text_data_label_compare)) == NULL) { - if(add_it) { - data = (MultiTextData *) g_slist_last(*list = - g_slist_append(*list, g_malloc(sizeof(MultiTextData))))->data; - data->label = strcpy(g_malloc(strlen(label) +1), label); - data->text = NULL; - } else { - data = NULL; - } - } else { - data = found->data; - } - - if(data != NULL && text != NULL && text[0] != '\0') { - if(data->text == NULL) { - data->text = g_malloc(strlen(text) + 1); - } else { - data->text = g_realloc(data->text, strlen(text) + 1); - } - strcpy(data->text, text); - } - - return(data); -} - -/* - * Free-up the multi-entry item list and the MultiEntryDlg - * struct alloc. - */ -void multi_entry_free(struct multi_entry_dlg *b) -{ - multi_entry_items_free_all(&(b->multi_entry_items)); - multi_text_items_free_all(&(b->multi_text_items)); - g_free(b->instructions->text); - g_free(b->instructions); - g_free(b->entries_title); - g_free(b); -} - -/* - * Multi-Entry dialog "destroyed" catcher - * - * Free-up the multi-entry item list, destroy the dialog widget - * and free the MultiEntryDlg struct alloc. - * - */ -void multi_entry_dialog_destroy(GtkWidget *widget, gpointer data) -{ - MultiEntryDlg *b = data; - - multi_entry_free(b); -} - -/* - * Show/Re-show instructions - */ -void re_show_multi_entry_instr(MultiInstrData *instructions) -{ - if(instructions->label != NULL) { - if(instructions->text == NULL) { - gtk_widget_hide(instructions->label); - } else { - gtk_label_set_text(GTK_LABEL (instructions->label), _(instructions->text)); - gtk_widget_show(instructions->label); - } - } -} - -/* - * Show/Re-show entry boxes - */ -void re_show_multi_entry_entries(GtkWidget **entries_table, - GtkWidget *entries_frame, - GSList *multi_entry_items) -{ - GtkWidget *label; - GSList *multi_entry; - MultiEntryData *med; - int rows, row_num, col_num, col_offset; - int cols = 1; - - /* Figure-out number of rows needed for table */ - if((rows = g_slist_length(multi_entry_items)) > 9) { - rows /= 2; - ++cols; - } - - if(*entries_table != NULL) { - gtk_widget_destroy(GTK_WIDGET (*entries_table)); - } - *entries_table = gtk_table_new(rows, 3 * cols, FALSE); - gtk_container_add(GTK_CONTAINER (entries_frame), *entries_table); - - for(col_num = 0, multi_entry = multi_entry_items; col_num < cols && multi_entry != NULL; - ++col_num) { - col_offset = col_num * 3; - for(row_num = 0; row_num < rows && multi_entry != NULL; - ++row_num, multi_entry = multi_entry->next) { - - med = (MultiEntryData *) multi_entry->data; - - label = gtk_label_new(_(med->label)); - gtk_misc_set_alignment(GTK_MISC(label), (gfloat) 1.0, (gfloat) 0.5); - gtk_table_attach_defaults(GTK_TABLE (*entries_table), label, - col_offset, 1 + col_offset, row_num, row_num +1); - gtk_widget_show(label); - - label = gtk_label_new(": "); - gtk_misc_set_alignment(GTK_MISC(label), (gfloat) 0.0, (gfloat) 0.5); - gtk_table_attach_defaults(GTK_TABLE (*entries_table), label, - 1 + col_offset, 2 + col_offset, row_num, row_num +1); - gtk_widget_show(label); - - med->widget = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(med->widget), 50); - if(med->text != NULL) { - gtk_entry_set_text(GTK_ENTRY (med->widget), med->text); - } - gtk_entry_set_visibility(GTK_ENTRY (med->widget), med->visible); - gtk_editable_set_editable(GTK_EDITABLE(med->widget), med->editable); - gtk_table_attach(GTK_TABLE (*entries_table), med->widget, - 2 + col_offset, 3 + col_offset, row_num, row_num +1, - GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0); - gtk_widget_show(med->widget); - } - } - - gtk_widget_show(*entries_table); -} - -/* - * Show/Re-show textboxes - */ -void re_show_multi_entry_textboxes(GtkWidget **texts_ibox, - GtkWidget *texts_obox, - GSList *multi_text_items) -{ - GSList *multi_text; - MultiTextData *mtd; - GtkWidget *frame; - GtkWidget *sw; - - if(*texts_ibox != NULL) { - gtk_widget_destroy(GTK_WIDGET (*texts_ibox)); - } - *texts_ibox = gtk_vbox_new(FALSE, 5); - gtk_container_add(GTK_CONTAINER (texts_obox), *texts_ibox); - - for(multi_text = multi_text_items; multi_text != NULL; multi_text = multi_text->next) { - mtd = (MultiTextData *) multi_text->data; - frame = gtk_frame_new(_(mtd->label)); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_container_set_border_width(GTK_CONTAINER(sw), 5); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), - GTK_SHADOW_IN); - gtk_widget_set_size_request(sw, 300, 100); - gtk_container_add(GTK_CONTAINER (frame), sw); - gtk_container_add(GTK_CONTAINER (*texts_ibox), frame); - mtd->textbox = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(mtd->textbox), TRUE); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(mtd->textbox), GTK_WRAP_WORD_CHAR); - gtk_text_buffer_set_text( - gtk_text_view_get_buffer(GTK_TEXT_VIEW(mtd->textbox)), - mtd->text?mtd->text:"", -1); - gtk_container_add(GTK_CONTAINER (sw), mtd->textbox); - gtk_widget_show(mtd->textbox); - gtk_widget_show(sw); - gtk_widget_show(frame); - } - - gtk_widget_show(*texts_ibox); -} - -/* - * Create and initialize a new Multi-Entry Dialog struct - */ -MultiEntryDlg *multi_entry_dialog_new() -{ - MultiEntryDlg *b = g_new0(MultiEntryDlg, 1); - b->instructions = g_new0(MultiInstrData, 1); - b->multi_entry_items = NULL; - b->multi_text_items = NULL; - return(b); -} - -/* - * Instantiate a new multi-entry dialog - * - * data == pointer to MultiEntryDlg with the following - * initialized: - * - * role - * title - * user - * multi_entry_items - pointers to MultiEntryData list - * and MultiTextData list - * instructions (optional) - * ok function pointer - * cancel function pointer (actually used to set - * window destroy signal--cancel asserts destroy) - * - * sets the following in the MultiEntryDialog struct: - * - * window - */ -void show_multi_entry_dialog(gpointer data) -{ - GtkWidget *vbox, *hbox; - GtkWidget *button; - MultiEntryDlg *b = data; - - GAIM_DIALOG(b->window); - gtk_container_set_border_width(GTK_CONTAINER(b->window), 5); - gtk_window_set_role(GTK_WINDOW(b->window), b->role); - gtk_window_set_title(GTK_WINDOW (b->window), b->title); - - /* Clean up if user dismisses window via window manager! */ - g_signal_connect(G_OBJECT(b->window), "destroy", G_CALLBACK(b->cancel), (gpointer) b); - gtk_widget_realize(b->window); - - vbox = gtk_vbox_new(FALSE, 5); - gtk_container_add(GTK_CONTAINER (b->window), vbox); - - b->instructions->label = gtk_label_new(NULL); - gtk_label_set_line_wrap(GTK_LABEL (b->instructions->label), TRUE); - gtk_box_pack_start(GTK_BOX (vbox), b->instructions->label, TRUE, TRUE, 5); - re_show_multi_entry_instr(b->instructions); - - b->entries_frame = gtk_frame_new(b->entries_title); - gtk_box_pack_start(GTK_BOX (vbox), b->entries_frame, TRUE, TRUE, 5); - b->entries_table = NULL; - re_show_multi_entry_entries(&(b->entries_table), b->entries_frame, b->multi_entry_items); - - b->texts_obox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX (vbox), b->texts_obox, TRUE, TRUE, 5); - b->texts_ibox = NULL; - re_show_multi_entry_textboxes(&(b->texts_ibox), b->texts_obox, b->multi_text_items); - - hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX (vbox), hbox, FALSE, FALSE, 5); - - button = gaim_pixbuf_button_from_stock(_("Save"), GTK_STOCK_SAVE, GAIM_BUTTON_HORIZONTAL); - g_signal_connect(G_OBJECT (button), "clicked", - G_CALLBACK (b->ok), (gpointer) b); - gtk_box_pack_end(GTK_BOX (hbox), button, FALSE, FALSE, 5); - - button = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); - - /* Let "destroy handling" (set above) handle cleanup */ - g_signal_connect_swapped(G_OBJECT (button), "clicked", - G_CALLBACK (gtk_widget_destroy), G_OBJECT (b->window)); - gtk_box_pack_end(GTK_BOX (hbox), button, FALSE, FALSE, 5); - - gtk_widget_show_all(b->window); -} - - -/*------------------------------------*/ -/* V-Card dialog specific support */ -/*------------------------------------*/ - -/* - * V-Card "set info" dialog "Save" clicked - * - * Copy data from GTK+ dialogs into GSLists, call protocol-specific - * formatter and save the user info data. - */ -void set_vcard_dialog_ok_clicked(GtkWidget *widget, gpointer data) -{ - MultiEntryDlg *b = (MultiEntryDlg *) data; - GaimConnection *gc; - gchar *tmp; - GSList *list; - - for(list = b->multi_entry_items; list != NULL; list = list->next) { - if(((MultiEntryData *) list->data)->text != NULL) { - g_free(((MultiEntryData *) list->data)->text); - } - ((MultiEntryData *) list->data)->text = - g_strdup(gtk_entry_get_text(GTK_ENTRY(((MultiEntryData *) list->data)->widget))); - } - - for(list = b->multi_text_items; list != NULL; list = list->next) { - if(((MultiTextData *) list->data)->text != NULL) { - g_free(((MultiTextData *) list->data)->text); - } - ((MultiTextData *) list->data)->text = - gtk_text_view_get_text(GTK_TEXT_VIEW(((MultiTextData *) list->data)->textbox), FALSE); - } - - - tmp = b->custom(b); - - /* - * Set the user info and (possibly) send to the server - */ - if (b->account) { - gaim_account_set_user_info(b->account, tmp); - gc = b->account->gc; - - if (gc) - serv_set_info(gc, gaim_account_get_user_info(b->account)); - } - - g_free(tmp); - - /* Let multi-edit dialog window "destroy" event catching handle remaining cleanup */ - gtk_widget_destroy(GTK_WIDGET (b->window)); -} - -/* - * Instantiate a v-card dialog - */ -void show_set_vcard(MultiEntryDlg *b) -{ - b->ok = set_vcard_dialog_ok_clicked; - b->cancel = multi_entry_dialog_destroy; - - show_multi_entry_dialog(b); -} - - -/*------------------------------------------------------------------------*/ -/* End dialog for setting v-card info */ -/*------------------------------------------------------------------------*/ -
--- a/src/gaim.h Wed Jul 30 08:09:54 2003 +0000 +++ b/src/gaim.h Wed Jul 30 08:14:39 2003 +0000 @@ -53,84 +53,4 @@ /* Functions in idle.c */ extern gint check_idle(gpointer); - -/*------------------------------------------------------------------------*/ -/* Multi-Entry dialog and vCard dialog support */ -/*------------------------------------------------------------------------*/ - -/* - * Struct for "instructions" dialog data - */ -typedef struct multi_instr_dlg { - GtkWidget *label; /* dialog instructions widget */ - gchar *text; /* dialog instructions */ -} MultiInstrData; - -/* - * Struct for multiple-entry dialog data - */ -typedef struct multi_entry_data { - GtkWidget *widget; /* entry widget object */ - char *label; /* label text pointer */ - char *text; /* entry text pointer */ - int visible; /* should entry field be "visible?" */ - int editable; /* should entry field be editable? */ -} MultiEntryData; - -/* - * Struct for multiple-textbox dialog data - */ -typedef struct multi_text_data { - char *label; /* frame label */ - GtkWidget *textbox; /* text entry widget object */ - char *text; /* textbox text pointer */ -} MultiTextData; - -/* - * Struct to create a multi-entry dialog - */ -typedef struct multi_entry_dlg { - GtkWidget *window; /* dialog main window */ - gchar *role; /* window role */ - char *title; /* window title */ - - GaimAccount *account; /* user info - needed for most everything */ - - MultiInstrData *instructions; /* instructions (what else?) */ - - GtkWidget *entries_table; /* table widget containing m-e lables & entries */ - GtkWidget *entries_frame; /* frame widget containing the table widget */ - gchar *entries_title; /* title of multi-entries list */ - GSList *multi_entry_items; /* entry dialogs parameters */ - - GtkWidget *texts_ibox; /* inner vbox containing multi-text frames */ - GtkWidget *texts_obox; /* outer vbox containing multi-text frames */ - GSList *multi_text_items; /* text dialogs parameters */ - - void * (*custom)(struct multi_entry_dlg *); /* Custom function that may be used by */ - /* multi-entry dialog "wrapper" functions */ - /* (Not used by multi-entry dialog routines) */ - - void (*ok)(GtkWidget *, gpointer); /* "Save/OK" action */ - void (*cancel)(GtkWidget *, gpointer); /* "Cancel" action */ -} MultiEntryDlg; - -extern MultiTextData *multi_text_list_update(GSList **, const char *, const char *, int); -extern void multi_text_items_free_all(GSList **); -extern MultiEntryData *multi_entry_list_update(GSList **, const char *, const char *, int); -extern void multi_entry_items_free_all(GSList **); - -extern void re_show_multi_entry_instr(MultiInstrData *); -extern void re_show_multi_entry_entries(GtkWidget **, GtkWidget *, GSList *); -extern void re_show_multi_entry_textboxes(GtkWidget **, GtkWidget *, GSList *); - -extern MultiEntryDlg *multi_entry_dialog_new(void); -extern void show_multi_entry_dialog(gpointer); - -extern void show_set_vcard(MultiEntryDlg *); - -/*------------------------------------------------------------------------*/ -/* End Multi-Entry dialog and vCard dialog support */ -/*------------------------------------------------------------------------*/ - #endif /* _GAIM_H_ */