You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(106) |
Oct
(334) |
Nov
(246) |
Dec
(145) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(42) |
Feb
(53) |
Mar
(232) |
Apr
(109) |
May
(137) |
Jun
(63) |
Jul
(26) |
Aug
(263) |
Sep
(193) |
Oct
(507) |
Nov
(440) |
Dec
(241) |
2003 |
Jan
(567) |
Feb
(195) |
Mar
(504) |
Apr
(481) |
May
(524) |
Jun
(522) |
Jul
(594) |
Aug
(502) |
Sep
(643) |
Oct
(508) |
Nov
(430) |
Dec
(377) |
2004 |
Jan
(361) |
Feb
(251) |
Mar
(219) |
Apr
(499) |
May
(461) |
Jun
(419) |
Jul
(314) |
Aug
(519) |
Sep
(416) |
Oct
(247) |
Nov
(305) |
Dec
(382) |
2005 |
Jan
(267) |
Feb
(282) |
Mar
(327) |
Apr
(338) |
May
(189) |
Jun
(400) |
Jul
(462) |
Aug
(530) |
Sep
(316) |
Oct
(523) |
Nov
(481) |
Dec
(650) |
2006 |
Jan
(536) |
Feb
(361) |
Mar
(287) |
Apr
(146) |
May
(101) |
Jun
(169) |
Jul
(221) |
Aug
(498) |
Sep
(300) |
Oct
(236) |
Nov
(209) |
Dec
(205) |
2007 |
Jan
(30) |
Feb
(23) |
Mar
(26) |
Apr
(15) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sa...@us...> - 2006-07-19 07:13:14
|
Revision: 16520 Author: sadrul Date: 2006-07-19 00:12:59 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16520&view=rev Log Message: ----------- Add multi-column support for GntTree. Use it for email-notifications. Restore colors before exiting. Modified Paths: -------------- trunk/console/gntaccount.c trunk/console/gntblist.c trunk/console/gntnotify.c trunk/console/libgnt/gntcolors.c trunk/console/libgnt/gntcolors.h trunk/console/libgnt/gntcombobox.c trunk/console/libgnt/gntlabel.c trunk/console/libgnt/gntlabel.h trunk/console/libgnt/gntline.h trunk/console/libgnt/gntmain.c trunk/console/libgnt/gnttextview.h trunk/console/libgnt/gnttree.c trunk/console/libgnt/gnttree.h trunk/console/libgnt/test/focus.c trunk/console/libgnt/test/multiwin.c trunk/console/libgnt/test/wm.c Modified: trunk/console/gntaccount.c =================================================================== --- trunk/console/gntaccount.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/gntaccount.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -210,25 +210,26 @@ gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); - accounts.tree = gnt_tree_new(); + accounts.tree = gnt_tree_new_with_columns(2); GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); for (iter = gaim_accounts_get_all(); iter; iter = iter->next) { GaimAccount *account = iter->data; - char *str = g_strdup_printf("%s (%s)", - gaim_account_get_username(account), gaim_account_get_protocol_id(account)); gnt_tree_add_choice(GNT_TREE(accounts.tree), account, - str, NULL, NULL); + gnt_tree_create_row(GNT_TREE(accounts.tree), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)), + NULL, NULL); gnt_tree_set_choice(GNT_TREE(accounts.tree), account, gaim_account_get_enabled(account, GAIM_GNT_UI)); - g_free(str); } g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); - gnt_widget_set_size(accounts.tree, 40, 10); + gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40); + gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10); gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); Modified: trunk/console/gntblist.c =================================================================== --- trunk/console/gntblist.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/gntblist.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -129,8 +129,9 @@ GaimBlistNode *node = (GaimBlistNode *)group; if (node->ui_data) return; + gnt_tree_remove(GNT_TREE(ggblist->tree), group); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group, - group->name, NULL, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), group->name), NULL, NULL); } static const char * @@ -191,8 +192,10 @@ group = gaim_chat_get_group(chat); add_node((GaimBlistNode*)group, ggblist); + gnt_tree_remove(GNT_TREE(ggblist->tree), chat); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat, - get_display_name(node), group, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), + group, NULL); } static void @@ -206,8 +209,10 @@ group = gaim_buddy_get_group(buddy); add_node((GaimBlistNode*)group, ggblist); + gnt_tree_remove(GNT_TREE(ggblist->tree), buddy); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, - get_display_name(node), group, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), + group, NULL); if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy))) gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM); else @@ -270,7 +275,8 @@ { GList *list; - gnt_tree_add_row_after(tree, action, action->label, parent, NULL); + gnt_tree_add_row_after(tree, action, + gnt_tree_create_row(tree, action->label), parent, NULL); for (list = action->children; list; list = list->next) gnt_append_menu_action(tree, list->data, action); } @@ -640,7 +646,7 @@ static void update_buddy_display(GaimBuddy *buddy, GGBlist *ggblist) { - gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, get_display_name((GaimBlistNode*)buddy)); + gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((GaimBlistNode*)buddy)); if (ggblist->tnode == (GaimBlistNode*)buddy) draw_tooltip(ggblist); @@ -685,7 +691,8 @@ ggblist->tree = gnt_tree_new(); GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); - gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr) - 4); + gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, 25); + gnt_widget_set_size(ggblist->tree, 0, getmaxy(stdscr) - 4); gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); gnt_widget_show(ggblist->window); Modified: trunk/console/gntnotify.c =================================================================== --- trunk/console/gntnotify.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/gntnotify.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -2,12 +2,19 @@ #include <gntbox.h> #include <gntbutton.h> #include <gntlabel.h> +#include <gnttree.h> #include <util.h> #include "gntnotify.h" #include "gntgaim.h" +static struct +{ + GntWidget *window; + GntWidget *tree; +} emaildialog; + static void * gg_notify_message(GaimNotifyMsgType type, const char *title, const char *primary, const char *secondary) @@ -72,6 +79,44 @@ return ret; } +static void +reset_email_dialog() +{ + emaildialog.window = NULL; + emaildialog.tree = NULL; +} + +static void +setup_email_dialog() +{ + GntWidget *box, *tree, *button; + if (emaildialog.window) + return; + + emaildialog.window = box = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(box), TRUE); + gnt_box_set_title(GNT_BOX(box), _("Emails")); + gnt_box_set_fill(GNT_BOX(box), FALSE); + gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); + gnt_box_set_pad(GNT_BOX(box), 0); + + gnt_box_add_widget(GNT_BOX(box), + gnt_label_new_with_format(_("You have mail!"), GNT_TEXT_FLAG_BOLD)); + + emaildialog.tree = tree = gnt_tree_new_with_columns(3); + gnt_tree_set_col_width(GNT_TREE(tree), 0, 15); + gnt_tree_set_col_width(GNT_TREE(tree), 1, 25); + gnt_tree_set_col_width(GNT_TREE(tree), 2, 25); + + gnt_box_add_widget(GNT_BOX(box), tree); + + button = gnt_button_new(_("Close")); + gnt_box_add_widget(GNT_BOX(box), button); + + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box); + g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL); +} + static void * gg_notify_emails(GaimConnection *gc, size_t count, gboolean detailed, const char **subjects, const char **froms, const char **tos, @@ -92,14 +137,16 @@ } else { - /* XXX: Yes, yes. I know, the combined dialog thing. Maybe later. */ - g_string_append_printf(message, - _("You have received a mail \"%s\""), *subjects); - if (froms && *froms && **froms) - g_string_append_printf(message, _("\nfrom %s"), *froms); - g_string_append_printf(message, _(" to %s (%s)"), - tos ? *tos : gaim_account_get_username(account), - gaim_account_get_protocol_name(account)); + setup_email_dialog(); + + gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), + gnt_tree_create_row(GNT_TREE(emaildialog.tree), + tos ? *tos : gaim_account_get_username(account), + froms ? *froms : "[Unknown sender]", + *subjects), + NULL, NULL); + gnt_widget_show(emaildialog.window); + return NULL; } ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, _("New Mail"), _("You have mail!"), message->str); Modified: trunk/console/libgnt/gntcolors.c =================================================================== --- trunk/console/libgnt/gntcolors.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntcolors.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -1,10 +1,40 @@ #include <ncursesw/ncurses.h> #include "gntcolors.h" +static struct +{ + short r, g, b; +} colors[GNT_TOTAL_COLORS]; + +static void +backup_colors() +{ + short i; + for (i = 0; i < GNT_TOTAL_COLORS; i++) + { + color_content(i, &colors[i].r, + &colors[i].g, &colors[i].b); + } +} + +static void +restore_colors() +{ + short i; + for (i = 0; i < GNT_TOTAL_COLORS; i++) + { + init_color(i, colors[i].r, + colors[i].g, colors[i].b); + } +} + void gnt_init_colors() { + start_color(); if (can_change_color()) { + backup_colors(); + /* XXX: Do some init_color()s */ init_color(GNT_COLOR_BLACK, 0, 0, 0); init_color(GNT_COLOR_RED, 1000, 0, 0); @@ -39,3 +69,9 @@ } } +void +gnt_uninit_colors() +{ + restore_colors(); +} + Modified: trunk/console/libgnt/gntcolors.h =================================================================== --- trunk/console/libgnt/gntcolors.h 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntcolors.h 2006-07-19 07:12:59 UTC (rev 16520) @@ -32,4 +32,6 @@ /* populate some default colors */ void gnt_init_colors(); +void gnt_uninit_colors(); + #endif Modified: trunk/console/libgnt/gntcombobox.c =================================================================== --- trunk/console/libgnt/gntcombobox.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntcombobox.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -235,7 +235,8 @@ void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) { - gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, text, NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, + gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL, NULL); if (box->selected == NULL) set_selection(box, key); } Modified: trunk/console/libgnt/gntlabel.c =================================================================== --- trunk/console/libgnt/gntlabel.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntlabel.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -126,3 +126,16 @@ return widget; } +void gnt_label_set_text(GntLabel *label, const char *text) +{ + g_free(label->text); + label->text = g_strdup(text); + + if (GNT_WIDGET(label)->window) + { + gnt_widget_hide(GNT_WIDGET(label)); + gnt_label_size_request(GNT_WIDGET(label)); + gnt_widget_draw(GNT_WIDGET(label)); + } +} + Modified: trunk/console/libgnt/gntlabel.h =================================================================== --- trunk/console/libgnt/gntlabel.h 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntlabel.h 2006-07-19 07:12:59 UTC (rev 16520) @@ -46,6 +46,8 @@ GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags); +void gnt_label_set_text(GntLabel *label, const char *text); + G_END_DECLS #endif /* GNT_LABEL_H */ Modified: trunk/console/libgnt/gntline.h =================================================================== --- trunk/console/libgnt/gntline.h 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntline.h 2006-07-19 07:12:59 UTC (rev 16520) @@ -42,6 +42,9 @@ GType gnt_line_get_gtype(void); +#define gnt_hline_new() gnt_line_new(FALSE) +#define gnt_vline_new() gnt_line_new(TRUE) + GntWidget *gnt_line_new(gboolean vertical); G_END_DECLS Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gntmain.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -258,14 +258,16 @@ { GntBox *box = GNT_BOX(iter->data); - gnt_tree_add_row_after(GNT_TREE(tree), box, box->title, NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), box, + gnt_tree_create_row(GNT_TREE(tree), box->title), NULL, NULL); update_window_in_list(GNT_WIDGET(box)); } gnt_tree_set_selected(GNT_TREE(tree), focus_list->data); gnt_box_add_widget(GNT_BOX(win), tree); - gnt_widget_set_size(tree, getmaxx(stdscr) / 3, getmaxy(stdscr) / 2); + gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); + gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); lock_focus_list = 1; @@ -539,7 +541,6 @@ ascii_only = TRUE; initscr(); - start_color(); gnt_init_colors(); X_MIN = 0; @@ -602,7 +603,8 @@ && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { gnt_tree_add_row_after(GNT_TREE(window_list.tree), widget, - GNT_BOX(widget)->title, NULL, NULL); + gnt_tree_create_row(GNT_TREE(window_list.tree), GNT_BOX(widget)->title), + NULL, NULL); update_window_in_list(widget); } } @@ -692,6 +694,7 @@ void gnt_quit() { + gnt_uninit_colors(); endwin(); } Modified: trunk/console/libgnt/gnttextview.h =================================================================== --- trunk/console/libgnt/gnttextview.h 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gnttextview.h 2006-07-19 07:12:59 UTC (rev 16520) @@ -30,6 +30,7 @@ typedef enum { + GNT_TEXT_FLAG_NORMAL = 0, GNT_TEXT_FLAG_BOLD = 1 << 0, GNT_TEXT_FLAG_UNDERLINE = 1 << 1, GNT_TEXT_FLAG_BLINK = 1 << 2, Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gnttree.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -18,7 +18,6 @@ struct _GnTreeRow { void *key; - char *text; void *data; /* XXX: unused */ gboolean collapsed; @@ -31,8 +30,16 @@ GntTreeRow *child; GntTreeRow *next; GntTreeRow *prev; + + GList *columns; }; +struct _GnTreeCol +{ + char *text; + int span; /* How many columns does it span? */ +}; + static GntWidgetClass *parent_class = NULL; static guint signals[SIGS] = { 0 }; @@ -151,6 +158,83 @@ return (hb - ha); } +static int +find_depth(GntTreeRow *row) +{ + int dep = -1; + + while (row) + { + dep++; + row = row->parent; + } + + return dep; +} + +static char * +update_row_text(GntTree *tree, GntTreeRow *row) +{ + GString *string = g_string_new(NULL); + GList *iter; + int i; + + for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) + { + GntTreeCol *col = iter->data; + char *text; + int len = g_utf8_strlen(col->text, -1); + int fl = 0; + gboolean ell = FALSE; + + if (i == 0) + { + if (row->choice) + { + g_string_append_printf(string, "[%c] ", + row->isselected ? 'X' : ' '); + fl = 4; + } + else if (row->parent == NULL && row->child) + { + if (row->collapsed) + { + string = g_string_append(string, "+ "); + } + else + { + string = g_string_append(string, "- "); + } + fl = 2; + } + else + { + fl = TAB_SIZE * find_depth(row); + g_string_append_printf(string, "%*s", fl, ""); + } + len += fl; + } + else + g_string_append_c(string, '|'); + + if (len > tree->columns[i].width) + { + len = tree->columns[i].width; + ell = TRUE; + } + + text = g_utf8_offset_to_pointer(col->text, len - fl - ell); + string = g_string_append_len(string, col->text, text - col->text); + if (len < tree->columns[i].width) + g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); + else if (ell) + { + g_string_append_unichar(string, (gunichar)2026); + } + } + return g_string_free(string, FALSE); +} + static void redraw_tree(GntTree *tree) { @@ -158,7 +242,6 @@ GntWidget *widget = GNT_WIDGET(tree); GntTreeRow *row; int pos; - gboolean deep; if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) pos = 0; @@ -172,37 +255,18 @@ wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); - deep = TRUE; row = tree->top; for (start = pos; row && start < widget->priv.height - pos; start++, row = get_next(row)) { - char str[2048]; + char *str; int wr; - char format[16] = ""; GntTextFormatFlags flags = row->flags; int attr = 0; - deep = TRUE; + str = update_row_text(tree, row); - if (row->parent == NULL && row->child) - { - if (row->collapsed) - { - strcpy(format, "+ "); - deep = FALSE; - } - else - strcpy(format, "- "); - } - else if (row->choice) - { - g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' '); - } - - g_snprintf(str, sizeof(str) - 1, "%s%s", format, row->text); - if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) { /* XXX: ellipsize */ @@ -238,6 +302,7 @@ mvwprintw(widget->window, start, pos, str); whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1)); tree->bottom = row; + g_free(str); } wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); @@ -267,7 +332,13 @@ if (widget->priv.height == 0) widget->priv.height = 10; /* XXX: Why?! */ if (widget->priv.width == 0) - widget->priv.width = 20; /* YYY: 'cuz ... */ + { + GntTree *tree = GNT_TREE(widget); + int i, width = 0; + for (i = 0; i < tree->ncol; i++) + width += tree->columns[i].width; + widget->priv.width = width + i; + } } static void @@ -437,6 +508,15 @@ } static void +free_tree_col(gpointer data) +{ + GntTreeCol *col = data; + + g_free(col->text); + g_free(col); +} + +static void free_tree_row(gpointer data) { GntTreeRow *row = data; @@ -444,20 +524,14 @@ if (!row) return; - g_free(row->text); + g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); + g_list_free(row->columns); g_free(row); } GntWidget *gnt_tree_new() { - GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); - GntTree *tree = GNT_TREE(widget); - - tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); - GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); - gnt_widget_set_take_focus(widget, TRUE); - - return widget; + return gnt_tree_new_with_columns(1); } void gnt_tree_set_visible_rows(GntTree *tree, int rows) @@ -500,24 +574,10 @@ g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); } -static int -find_depth(GntTreeRow *row) +GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) { - int dep = -1; + GntTreeRow *pr = NULL; - while (row) - { - dep++; - row = row->parent; - } - - return dep; -} - -GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) -{ - GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; - g_hash_table_replace(tree->hash, key, row); if (tree->root == NULL) @@ -575,7 +635,6 @@ } row->key = key; - row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); row->data = NULL; if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) @@ -591,10 +650,10 @@ return NULL; } -const char *gnt_tree_get_selection_text(GntTree *tree) +char *gnt_tree_get_selection_text(GntTree *tree) { if (tree->current) - return tree->current->text; + update_row_text(tree, tree->current); return NULL; } @@ -657,27 +716,32 @@ !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); } -void gnt_tree_change_text(GntTree *tree, gpointer key, const char *text) +void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) { - GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + GntTreeRow *row; + GntTreeCol *col; + + g_return_if_fail(colno < tree->ncol); + + row = g_hash_table_lookup(tree->hash, key); if (row) { - g_free(row->text); - row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); + col = g_list_nth_data(row->columns, colno); + g_free(col->text); + col->text = g_strdup(text); if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) > 0) redraw_tree(tree); } } -GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) +GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) { - GntTreeRow *row; - - row = g_hash_table_lookup(tree->hash, key); - g_return_val_if_fail(!row || !row->choice, NULL); + GntTreeRow *r; + r = g_hash_table_lookup(tree->hash, key); + g_return_val_if_fail(!r || !r->choice, NULL); - row = gnt_tree_add_row_after(tree, key, text, parent, bigbro); + row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); row->choice = TRUE; return row; @@ -737,3 +801,49 @@ redraw_tree(tree); } +GntWidget *gnt_tree_new_with_columns(int col) +{ + GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); + GntTree *tree = GNT_TREE(widget); + + tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); + tree->ncol = col; + tree->columns = g_new0(struct _GntTreeColInfo, col); + while (col--) + { + tree->columns[col].width = 15; + } + + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); + gnt_widget_set_take_focus(widget, TRUE); + + return widget; +} + +GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) +{ + GntTreeRow *row = g_new0(GntTreeRow, 1); + int i; + va_list args; + + va_start(args, tree); + + for (i = 0; i < tree->ncol; i++) + { + GntTreeCol *col = g_new0(GntTreeCol, 1); + col->span = 1; + col->text = g_strdup(va_arg(args, const char *)); + + row->columns = g_list_append(row->columns, col); + } + + return row; +} + +void gnt_tree_set_col_width(GntTree *tree, int col, int width) +{ + g_return_if_fail(col < tree->ncol); + + tree->columns[col].width = width; +} + Modified: trunk/console/libgnt/gnttree.h =================================================================== --- trunk/console/libgnt/gnttree.h 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/gnttree.h 2006-07-19 07:12:59 UTC (rev 16520) @@ -23,20 +23,28 @@ typedef struct _GnTreeClass GntTreeClass; typedef struct _GnTreeRow GntTreeRow; +typedef struct _GnTreeCol GntTreeCol; struct _GnTree { GntWidget parent; - GntTreeRow *current; /* current selection */ + GntTreeRow *current; /* current selection */ - GntTreeRow *top; /* The topmost visible item */ - GntTreeRow *bottom; /* The bottommost visible item */ + GntTreeRow *top; /* The topmost visible item */ + GntTreeRow *bottom; /* The bottommost visible item */ - GntTreeRow *root; /* The root of all evil */ + GntTreeRow *root; /* The root of all evil */ - GList *list; /* List of GntTreeRow s */ - GHashTable *hash; /* XXX: We may need this for quickly referencing the rows */ + GList *list; /* List of GntTreeRow s */ + GHashTable *hash; /* XXX: We may need this for quickly referencing the rows */ + + int ncol; /* No. of columns */ + struct _GntTreeColInfo + { + int width; + int *name; + } *columns; /* Would a GList be better? */ }; struct _GnTreeClass @@ -55,28 +63,30 @@ GType gnt_tree_get_gtype(void); -GntWidget *gnt_tree_new(); +GntWidget *gnt_tree_new(); /* A tree with just one column */ +GntWidget *gnt_tree_new_with_columns(int columns); + void gnt_tree_set_visible_rows(GntTree *tree, int rows); int gnt_tree_get_visible_rows(GntTree *tree); void gnt_tree_scroll(GntTree *tree, int count); -GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro); +GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro); gpointer gnt_tree_get_selection_data(GntTree *tree); -const char *gnt_tree_get_selection_text(GntTree *tree); +char *gnt_tree_get_selection_text(GntTree *tree); void gnt_tree_remove(GntTree *tree, gpointer key); /* Returns the visible line number of the selected row */ int gnt_tree_get_selection_visible_line(GntTree *tree); -void gnt_tree_change_text(GntTree *tree, gpointer key, const char *text); +void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text); -GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro); +GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro); void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set); @@ -86,6 +96,10 @@ void gnt_tree_set_selected(GntTree *tree , void *key); +GntTreeRow *gnt_tree_create_row(GntTree *tree, ...); + +void gnt_tree_set_col_width(GntTree *tree, int col, int width); + G_END_DECLS #endif /* GNT_TREE_H */ Modified: trunk/console/libgnt/test/focus.c =================================================================== --- trunk/console/libgnt/test/focus.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/test/focus.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -48,11 +48,11 @@ gnt_box_add_widget(GNT_BOX(box), tree); gnt_box_add_widget(GNT_BOX(hbox), box); - gnt_tree_add_row_after(GNT_TREE(tree), "a", "a", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "c", "c", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "d", "d", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "e", "e", "a", NULL); - gnt_tree_add_choice(GNT_TREE(tree), "b", "b", "d", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "a", gnt_tree_create_row(GNT_TREE(tree), "a"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "c", gnt_tree_create_row(GNT_TREE(tree), "c"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "d", gnt_tree_create_row(GNT_TREE(tree), "d"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "e", gnt_tree_create_row(GNT_TREE(tree), "e"), "a", NULL); + gnt_tree_add_choice(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL); GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); gnt_box_set_title(GNT_BOX(hbox), "This is the title …"); Modified: trunk/console/libgnt/test/multiwin.c =================================================================== --- trunk/console/libgnt/test/multiwin.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/test/multiwin.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -43,19 +43,19 @@ gnt_widget_set_position(box2, 35, 15); gnt_widget_show(box2); - gnt_tree_add_row_after(GNT_TREE(tree), "a", "a", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "c", "c", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "d", "d", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "e", "e", "a", NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "b", "b", "d", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "a", gnt_tree_create_row(GNT_TREE(tree), "a"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "c", gnt_tree_create_row(GNT_TREE(tree), "c"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "d", gnt_tree_create_row(GNT_TREE(tree), "d"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "e", gnt_tree_create_row(GNT_TREE(tree), "e"), "a", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL); - gnt_tree_add_choice(GNT_TREE(tree), "1", "1", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "2", "2", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "3", "3", NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "4", "4", "a", NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "5", "5", "d", NULL); + gnt_tree_add_choice(GNT_TREE(tree), "1", gnt_tree_create_row(GNT_TREE(tree), "1"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "2", gnt_tree_create_row(GNT_TREE(tree), "2"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "3", gnt_tree_create_row(GNT_TREE(tree), "3"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "4", gnt_tree_create_row(GNT_TREE(tree), "4"), "a", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "5", gnt_tree_create_row(GNT_TREE(tree), "5"), "d", NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "6", "6", "4", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "6", gnt_tree_create_row(GNT_TREE(tree), "6"), "4", NULL); gnt_tree_set_row_flags(GNT_TREE(tree), "e", GNT_TEXT_FLAG_DIM); Modified: trunk/console/libgnt/test/wm.c =================================================================== --- trunk/console/libgnt/test/wm.c 2006-07-19 06:47:26 UTC (rev 16519) +++ trunk/console/libgnt/test/wm.c 2006-07-19 07:12:59 UTC (rev 16520) @@ -20,8 +20,9 @@ handle = g_module_open(cmd, G_MODULE_BIND_LOCAL); if (handle && g_module_symbol(handle, "main", (gpointer)&func)) { + char *argv[] = {cmd, NULL}; gnt_entry_clear(entry); - func(); + func(1, argv); } else { @@ -29,6 +30,7 @@ gnt_box_set_toplevel(GNT_BOX(widget), TRUE); gnt_box_set_title(GNT_BOX(widget), "Error"); gnt_box_add_widget(GNT_BOX(widget), gnt_label_new("Could not execute.")); + gnt_box_add_widget(GNT_BOX(widget), gnt_label_new(g_module_error())); gnt_widget_show(widget); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aar...@us...> - 2006-07-19 06:47:32
|
Revision: 16519 Author: aaronsheldon Date: 2006-07-18 23:47:26 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16519&view=rev Log Message: ----------- Fixes potential segfaults, especially with completely empty buddy lists. Modified Paths: -------------- branches/soc-2006-blist-efficiency/src/gtkblist.c Modified: branches/soc-2006-blist-efficiency/src/gtkblist.c =================================================================== --- branches/soc-2006-blist-efficiency/src/gtkblist.c 2006-07-18 07:18:23 UTC (rev 16518) +++ branches/soc-2006-blist-efficiency/src/gtkblist.c 2006-07-19 06:47:26 UTC (rev 16519) @@ -4008,8 +4008,11 @@ node = gaim_blist_node_next(node, FALSE); } - g_hash_table_destroy(status_icon_hash_table); - status_icon_hash_table = NULL; + /* There is no hash table if there is nothing in the buddy list to update */ + if (status_icon_hash_table) { + g_hash_table_destroy(status_icon_hash_table); + status_icon_hash_table = NULL; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-18 07:18:26
|
Revision: 16518 Author: thekingant Date: 2006-07-18 00:18:23 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16518&view=rev Log Message: ----------- Backport SVN revision #16517 from HEAD to v2_0_0 Original commit message: Whitespace McFixen. Also, I think I'm listening to a duet of the song "One" performed by Bono and Mary J. Blige? ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16517&view=rev Modified Paths: -------------- branches/v2_0_0/src/dbus-server.c Modified: branches/v2_0_0/src/dbus-server.c =================================================================== --- branches/v2_0_0/src/dbus-server.c 2006-07-18 07:18:05 UTC (rev 16517) +++ branches/v2_0_0/src/dbus-server.c 2006-07-18 07:18:23 UTC (rev 16518) @@ -45,105 +45,119 @@ /** @name Gaim DBUS pointer registration mechanism */ /**************************************************************************/ -/* - Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for - all structs defined in gaim. This file has been generated by the - #dbus-analize-types.py script. -*/ +/* + * Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for + * all structs defined in gaim. This file has been generated by the + * #dbus-analize-types.py script. + */ #include "dbus-types.c" -/* The following three hashtables map are used to translate between - pointers (nodes) and the corresponding handles (ids). */ +/* + * The following three hashtables map are used to translate between + * pointers (nodes) and the corresponding handles (ids). + */ -static GHashTable *map_node_id; -static GHashTable *map_id_node; -static GHashTable *map_id_type; +static GHashTable *map_node_id; +static GHashTable *map_id_node; +static GHashTable *map_id_type; static gchar *init_error; - -/* This function initializes the pointer-id traslation system. It - creates the three above hashtables and defines parents of some types. +/** + * This function initializes the pointer-id traslation system. It + * creates the three above hashtables and defines parents of some types. */ -void gaim_dbus_init_ids(void) { - map_id_node = g_hash_table_new (g_direct_hash, g_direct_equal); - map_id_type = g_hash_table_new (g_direct_hash, g_direct_equal); - map_node_id = g_hash_table_new (g_direct_hash, g_direct_equal); +void +gaim_dbus_init_ids(void) +{ + map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal); + map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal); + map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal); - GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode); } -void gaim_dbus_register_pointer(gpointer node, GaimDBusType *type) +void +gaim_dbus_register_pointer(gpointer node, GaimDBusType *type) { - static gint last_id = 0; + static gint last_id = 0; - g_return_if_fail(map_node_id); - g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL); - - last_id++; - g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id)); - g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node); - g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type); + g_return_if_fail(map_node_id); + g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL); + + last_id++; + g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id)); + g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node); + g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type); } -void gaim_dbus_unregister_pointer(gpointer node) { - gpointer id = g_hash_table_lookup(map_node_id, node); - - g_hash_table_remove(map_node_id, node); - g_hash_table_remove(map_id_node, GINT_TO_POINTER(id)); - g_hash_table_remove(map_id_type, GINT_TO_POINTER(id)); +void +gaim_dbus_unregister_pointer(gpointer node) +{ + gpointer id = g_hash_table_lookup(map_node_id, node); + + g_hash_table_remove(map_node_id, node); + g_hash_table_remove(map_id_node, GINT_TO_POINTER(id)); + g_hash_table_remove(map_id_type, GINT_TO_POINTER(id)); } -gint gaim_dbus_pointer_to_id(gpointer node) { - gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node)); +gint +gaim_dbus_pointer_to_id(gpointer node) +{ + gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node)); if ((id == 0) && (node != NULL)) { gaim_debug_warning("dbus", "Need to register an object with the dbus subsystem.\n"); g_return_val_if_reached(0); } - return id; + return id; } - -gpointer gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) { - GaimDBusType *objtype = - (GaimDBusType*) g_hash_table_lookup(map_id_type, - GINT_TO_POINTER(id)); - - while (objtype != type && objtype != NULL) - objtype = objtype->parent; - if (objtype == type) - return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id)); - else - return NULL; +gpointer +gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) +{ + GaimDBusType *objtype; + + objtype = (GaimDBusType*)g_hash_table_lookup(map_id_type, + GINT_TO_POINTER(id)); + + while (objtype != type && objtype != NULL) + objtype = objtype->parent; + + if (objtype == type) + return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id)); + else + return NULL; } -gint gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error) +gint +gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error) { - gint id = gaim_dbus_pointer_to_id(ptr); + gint id = gaim_dbus_pointer_to_id(ptr); - if (ptr != NULL && id == 0) - dbus_set_error(error, "net.sf.gaim.ObjectNotFound", - "The return object is not mapped (this is a Gaim error)"); + if (ptr != NULL && id == 0) + dbus_set_error(error, "net.sf.gaim.ObjectNotFound", + "The return object is not mapped (this is a Gaim error)"); - return id; + return id; } -gpointer gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type, - const char *typename, DBusError *error) +gpointer +gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type, + const char *typename, DBusError *error) { - gpointer ptr = gaim_dbus_id_to_pointer(id, type); + gpointer ptr = gaim_dbus_id_to_pointer(id, type); - if (ptr == NULL && id != 0) - dbus_set_error(error, "net.sf.gaim.InvalidHandle", - "%s object with ID = %i not found", typename, id); - - return ptr; + if (ptr == NULL && id != 0) + dbus_set_error(error, "net.sf.gaim.InvalidHandle", + "%s object with ID = %i not found", typename, id); + + return ptr; } @@ -152,98 +166,96 @@ /**************************************************************************/ dbus_bool_t -gaim_dbus_message_get_args (DBusMessage *message, - DBusError *error, - int first_arg_type, - ...) +gaim_dbus_message_get_args(DBusMessage *message, + DBusError *error, int first_arg_type, ...) { - dbus_bool_t retval; - va_list var_args; + dbus_bool_t retval; + va_list var_args; - va_start (var_args, first_arg_type); - retval = gaim_dbus_message_get_args_valist (message, error, first_arg_type, var_args); - va_end (var_args); + va_start(var_args, first_arg_type); + retval = gaim_dbus_message_get_args_valist(message, error, first_arg_type, var_args); + va_end(var_args); - return retval; + return retval; } dbus_bool_t -gaim_dbus_message_get_args_valist (DBusMessage *message, - DBusError *error, - int first_arg_type, - va_list var_args) +gaim_dbus_message_get_args_valist(DBusMessage *message, + DBusError *error, int first_arg_type, va_list var_args) { - DBusMessageIter iter; + DBusMessageIter iter; - dbus_message_iter_init (message, &iter); - return gaim_dbus_message_iter_get_args_valist (&iter, error, first_arg_type, var_args); + dbus_message_iter_init(message, &iter); + return gaim_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args); } dbus_bool_t gaim_dbus_message_iter_get_args(DBusMessageIter *iter, - DBusError *error, - int first_arg_type, - ...) + DBusError *error, int first_arg_type, ...) { - dbus_bool_t retval; - va_list var_args; + dbus_bool_t retval; + va_list var_args; - va_start (var_args, first_arg_type); - retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args); - va_end (var_args); + va_start(var_args, first_arg_type); + retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args); + va_end(var_args); - return retval; + return retval; } -#define TYPE_IS_CONTAINER(typecode) \ - ((typecode) == DBUS_TYPE_STRUCT || \ - (typecode) == DBUS_TYPE_DICT_ENTRY || \ - (typecode) == DBUS_TYPE_VARIANT || \ - (typecode) == DBUS_TYPE_ARRAY) +#define TYPE_IS_CONTAINER(typecode) \ + ((typecode) == DBUS_TYPE_STRUCT || \ + (typecode) == DBUS_TYPE_DICT_ENTRY || \ + (typecode) == DBUS_TYPE_VARIANT || \ + (typecode) == DBUS_TYPE_ARRAY) dbus_bool_t -gaim_dbus_message_iter_get_args_valist (DBusMessageIter *iter, - DBusError *error, - int first_arg_type, - va_list var_args) +gaim_dbus_message_iter_get_args_valist(DBusMessageIter *iter, + DBusError *error, int first_arg_type, va_list var_args) { - int spec_type, msg_type, i; + int spec_type, msg_type, i; - spec_type = first_arg_type; - - for(i=0; spec_type != DBUS_TYPE_INVALID; i++) { - msg_type = dbus_message_iter_get_arg_type (iter); + spec_type = first_arg_type; - if (msg_type != spec_type) { - dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, - "Argument %d is specified to be of type \"%i\", but " - "is actually of type \"%i\"\n", i, - spec_type, msg_type); - return FALSE; + for (i = 0; spec_type != DBUS_TYPE_INVALID; i++) + { + msg_type = dbus_message_iter_get_arg_type(iter); + + if (msg_type != spec_type) + { + dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, + "Argument %d is specified to be of type \"%i\", but " + "is actually of type \"%i\"\n", i, + spec_type, msg_type); + return FALSE; + } + + if (!TYPE_IS_CONTAINER(spec_type)) + { + gpointer ptr; + ptr = va_arg (var_args, gpointer); + dbus_message_iter_get_basic(iter, ptr); + } + else + { + DBusMessageIter *sub; + sub = va_arg (var_args, DBusMessageIter*); + dbus_message_iter_recurse(iter, sub); + gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); + break; /* for testing only! */ + } + + spec_type = va_arg(var_args, int); + if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Message has only %d arguments, but more were expected", i); + return FALSE; + } } - if (!TYPE_IS_CONTAINER(spec_type)) { - gpointer ptr; - ptr = va_arg (var_args, gpointer); - dbus_message_iter_get_basic(iter, ptr); - } - else { - DBusMessageIter *sub; - sub = va_arg (var_args, DBusMessageIter*); - dbus_message_iter_recurse(iter, sub); - gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); - break; /* for testing only! */ - } - - spec_type = va_arg (var_args, int); - if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) { - dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, - "Message has only %d arguments, but more were expected", i); - return FALSE; - } - } - return TRUE; + return TRUE; } @@ -252,30 +264,33 @@ /** @name Useful functions */ /**************************************************************************/ -const char* empty_to_null(const char *str) { - if (str == NULL || str[0] == 0) - return NULL; - else - return str; +const char *empty_to_null(const char *str) +{ + if (str == NULL || str[0] == 0) + return NULL; + else + return str; } -const char* null_to_empty(const char *s) { +const char * +null_to_empty(const char *s) +{ if (s) return s; else return ""; } -dbus_int32_t* gaim_dbusify_GList(GList *list, gboolean free_memory, - dbus_int32_t *len) - { +dbus_int32_t * +gaim_dbusify_GList(GList *list, gboolean free_memory, dbus_int32_t *len) +{ dbus_int32_t *array; int i; GList *elem; *len = g_list_length(list); array = g_new0(dbus_int32_t, g_list_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = gaim_dbus_pointer_to_id(elem->data); if (free_memory) @@ -284,8 +299,8 @@ return array; } -dbus_int32_t* gaim_dbusify_GSList(GSList *list, gboolean free_memory, - dbus_int32_t *len) +dbus_int32_t * +gaim_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len) { dbus_int32_t *array; int i; @@ -293,7 +308,7 @@ *len = g_slist_length(list); array = g_new0(dbus_int32_t, g_slist_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = gaim_dbus_pointer_to_id(elem->data); if (free_memory) @@ -302,8 +317,8 @@ return array; } -gpointer* gaim_GList_to_array(GList *list, gboolean free_memory, - dbus_int32_t *len) +gpointer * +gaim_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len) { gpointer *array; int i; @@ -311,7 +326,7 @@ *len = g_list_length(list); array = g_new0(gpointer, g_list_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = elem->data; if (free_memory) @@ -320,8 +335,8 @@ return array; } -gpointer* gaim_GSList_to_array(GSList *list, gboolean free_memory, - dbus_int32_t *len) +gpointer * +gaim_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len) { gpointer *array; int i; @@ -329,7 +344,7 @@ *len = g_slist_length(list); array = g_new0(gpointer, g_slist_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = elem->data; if (free_memory) @@ -338,40 +353,44 @@ return array; } -GHashTable *gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) { - GHashTable *hash; +GHashTable * +gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) +{ + GHashTable *hash; - /* we do not need to destroy strings because they are part of the message */ - hash = g_hash_table_new(g_str_hash, g_str_equal); + /* we do not need to destroy strings because they are part of the message */ + hash = g_hash_table_new(g_str_hash, g_str_equal); - do { - char *key, *value; - DBusMessageIter subiter; + do { + char *key, *value; + DBusMessageIter subiter; - if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) - goto error; /* With all due respect to Dijkstra, - this goto is for exception - handling, and it is ok because it - avoids duplication of the code - responsible for destroying the hash - table. Exceptional instructions - for exceptional situations. */ + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) + goto error; + /* With all due respect to Dijkstra, + * this goto is for exception + * handling, and it is ok because it + * avoids duplication of the code + * responsible for destroying the hash + * table. Exceptional instructions + * for exceptional situations. + */ - dbus_message_iter_recurse(iter, &subiter); - if (!gaim_dbus_message_iter_get_args(&subiter, error, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &value, - DBUS_TYPE_INVALID)) - goto error; /* same here */ + dbus_message_iter_recurse(iter, &subiter); + if (!gaim_dbus_message_iter_get_args(&subiter, error, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &value, + DBUS_TYPE_INVALID)) + goto error; /* same here */ - g_hash_table_insert(hash, key, value); - } while (dbus_message_iter_next(iter)); - - return hash; + g_hash_table_insert(hash, key, value); + } while (dbus_message_iter_next(iter)); - error: - g_hash_table_destroy(hash); - return NULL; + return hash; + +error: + g_hash_table_destroy(hash); + return NULL; } /**************************************************************/ @@ -380,213 +399,220 @@ static DBusConnection *gaim_dbus_connection; -DBusConnection *gaim_dbus_get_connection(void) { - return gaim_dbus_connection; +DBusConnection * +gaim_dbus_get_connection(void) +{ + return gaim_dbus_connection; } #include "dbus-bindings.c" static gboolean gaim_dbus_dispatch_cb(DBusConnection *connection, - DBusMessage *message, - void *user_data) + DBusMessage *message, void *user_data) { - const char *name; - GaimDBusBinding *bindings; - int i; + const char *name; + GaimDBusBinding *bindings; + int i; - bindings = (GaimDBusBinding*) user_data; + bindings = (GaimDBusBinding*) user_data; - if (!dbus_message_has_path(message, DBUS_PATH_GAIM)) - return FALSE; + if (!dbus_message_has_path(message, DBUS_PATH_GAIM)) + return FALSE; - name = dbus_message_get_member(message); + name = dbus_message_get_member(message); - if (name == NULL) - return FALSE; + if (name == NULL) + return FALSE; - if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL) - return FALSE; + if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL) + return FALSE; - for(i=0; bindings[i].name; i++) - if (!strcmp(name, bindings[i].name)) { - DBusMessage *reply; - DBusError error; + for (i = 0; bindings[i].name; i++) + if (!strcmp(name, bindings[i].name)) + { + DBusMessage *reply; + DBusError error; - dbus_error_init(&error); - - reply = bindings[i].handler(message, &error); - - if (reply == NULL && dbus_error_is_set(&error)) - reply = dbus_message_new_error (message, - error.name, - error.message); - - if (reply != NULL) { - dbus_connection_send (connection, reply, NULL); - dbus_message_unref(reply); - } - - return TRUE; /* return reply! */ - } + dbus_error_init(&error); - return FALSE; + reply = bindings[i].handler(message, &error); + + if (reply == NULL && dbus_error_is_set(&error)) + reply = dbus_message_new_error (message, + error.name, error.message); + + if (reply != NULL) + { + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + } + + return TRUE; /* return reply! */ + } + + return FALSE; } -static const char *dbus_gettext(const char **ptr) { - const char *text = *ptr; - *ptr += strlen(text) + 1; - return text; +static const char * +dbus_gettext(const char **ptr) +{ + const char *text = *ptr; + *ptr += strlen(text) + 1; + return text; } static void -gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) { - *bindings_list = g_list_prepend(*bindings_list, bindings); +gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) +{ + *bindings_list = g_list_prepend(*bindings_list, bindings); } -static DBusMessage *gaim_dbus_introspect(DBusMessage *message) +static DBusMessage *gaim_dbus_introspect(DBusMessage *message) { - DBusMessage *reply; - GString *str; - GList *bindings_list, *node; + DBusMessage *reply; + GString *str; + GList *bindings_list, *node; - str = g_string_sized_new(0x1000); /* fixme: why this size? */ + str = g_string_sized_new(0x1000); /* TODO: why this size? */ - g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n"); - g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM); - g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM); + g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n"); + g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM); + g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM); - bindings_list = NULL; - gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list); + bindings_list = NULL; + gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list); - for(node = bindings_list; node; node = node->next) { - GaimDBusBinding *bindings; - int i; + for (node = bindings_list; node; node = node->next) + { + GaimDBusBinding *bindings; + int i; - bindings = (GaimDBusBinding*) node->data; - - for(i=0; bindings[i].name; i++) { - const char *text; + bindings = (GaimDBusBinding*)node->data; - g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name); - - text = bindings[i].parameters; - while (*text) { - const char *name, *direction, *type; - - direction = dbus_gettext(&text); - type = dbus_gettext(&text); - name = dbus_gettext(&text); - - g_string_append_printf(str, - "<arg name='%s' type='%s' direction='%s'/>\n", - name, type, direction); - } - g_string_append(str, "</method>\n"); + for (i = 0; bindings[i].name; i++) + { + const char *text; + + g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name); + + text = bindings[i].parameters; + while (*text) + { + const char *name, *direction, *type; + + direction = dbus_gettext(&text); + type = dbus_gettext(&text); + name = dbus_gettext(&text); + + g_string_append_printf(str, + "<arg name='%s' type='%s' direction='%s'/>\n", + name, type, direction); + } + g_string_append(str, "</method>\n"); + } } - } - g_string_append(str, "</interface>\n</node>\n"); + g_string_append(str, "</interface>\n</node>\n"); - reply = dbus_message_new_method_return (message); - dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str), - DBUS_TYPE_INVALID); - g_string_free(str, TRUE); - g_list_free(bindings_list); + reply = dbus_message_new_method_return(message); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str), + DBUS_TYPE_INVALID); + g_string_free(str, TRUE); + g_list_free(bindings_list); - return reply; - + return reply; } -static DBusHandlerResult gaim_dbus_dispatch(DBusConnection *connection, - DBusMessage *message, - void *user_data) +static DBusHandlerResult +gaim_dbus_dispatch(DBusConnection *connection, + DBusMessage *message, void *user_data) { - if (gaim_signal_emit_return_1(gaim_dbus_get_handle(), - "dbus-method-called", - connection, message)) - return DBUS_HANDLER_RESULT_HANDLED; + if (gaim_signal_emit_return_1(gaim_dbus_get_handle(), + "dbus-method-called", connection, message)) + return DBUS_HANDLER_RESULT_HANDLED; - if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL && - dbus_message_has_path(message, DBUS_PATH_GAIM) && - dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) && - dbus_message_has_member(message, "Introspect")) - { - DBusMessage *reply; - reply = gaim_dbus_introspect(message); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref(reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL && + dbus_message_has_path(message, DBUS_PATH_GAIM) && + dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) && + dbus_message_has_member(message, "Introspect")) + { + DBusMessage *reply; + reply = gaim_dbus_introspect(message); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref(reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -void gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) { - gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called", - handle, +void +gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) +{ + gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called", + handle, GAIM_CALLBACK(gaim_dbus_dispatch_cb), bindings); - gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect", - handle, + gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect", + handle, GAIM_CALLBACK(gaim_dbus_introspect_cb), bindings); } +static void +gaim_dbus_dispatch_init(void) +{ + static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; + DBusError error; + int result; + dbus_error_init(&error); + gaim_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error); -static void gaim_dbus_dispatch_init(void) -{ - static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; + if (gaim_dbus_connection == NULL) + { + init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); + dbus_error_free(&error); + return; + } - DBusError error; - int result; - - dbus_error_init (&error); - gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); + if (!dbus_connection_register_object_path(gaim_dbus_connection, + DBUS_PATH_GAIM, &vtable, NULL)) + { + init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); + dbus_error_free(&error); + return; + } - if (gaim_dbus_connection == NULL) { - init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); - dbus_error_free(&error); - return; - } + result = dbus_bus_request_name(gaim_dbus_connection, + DBUS_SERVICE_GAIM, 0, &error); - if (!dbus_connection_register_object_path (gaim_dbus_connection, - DBUS_PATH_GAIM, &vtable, NULL)) - { - init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); - dbus_error_free(&error); - return; - } - + if (dbus_error_is_set(&error)) + { + dbus_connection_unref(gaim_dbus_connection); + dbus_error_free(&error); + gaim_dbus_connection = NULL; + init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); + return; + } - result = dbus_bus_request_name (gaim_dbus_connection, DBUS_SERVICE_GAIM, - 0, &error); - - if (dbus_error_is_set (&error)) { - dbus_connection_unref(gaim_dbus_connection); - dbus_error_free(&error); - gaim_dbus_connection = NULL; - init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); - return; - } - - dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); + dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); - gaim_debug_misc ("dbus", "okkk\n"); + gaim_debug_misc("dbus", "okkk\n"); - gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called", + gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called", gaim_marshal_BOOLEAN__POINTER_POINTER, gaim_value_new(GAIM_TYPE_BOOLEAN), 2, gaim_value_new(GAIM_TYPE_POINTER), gaim_value_new(GAIM_TYPE_POINTER)); - gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", + gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", gaim_marshal_VOID__POINTER, NULL, 1, gaim_value_new_outgoing(GAIM_TYPE_POINTER)); - GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); + GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); } @@ -597,14 +623,16 @@ -static char *gaim_dbus_convert_signal_name(const char *gaim_name) +static char * +gaim_dbus_convert_signal_name(const char *gaim_name) { int gaim_index, g_index; - char *g_name = g_new(char, strlen(gaim_name)+1); + char *g_name = g_new(char, strlen(gaim_name) + 1); gboolean capitalize_next = TRUE; - for(gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++) - if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') { + for (gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++) + if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') + { if (capitalize_next) g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]); else @@ -612,96 +640,104 @@ capitalize_next = FALSE; } else capitalize_next = TRUE; + g_name[g_index] = 0; - + return g_name; } #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type)) -static void gaim_dbus_message_append_gaim_values(DBusMessageIter *iter, - int number, - GaimValue **gaim_values, - va_list data) +static void +gaim_dbus_message_append_gaim_values(DBusMessageIter *iter, + int number, GaimValue **gaim_values, va_list data) { - int i; + int i; - for(i=0; i<number; i++) { - const char *str; - int id; - gint xint; - guint xuint; - gboolean xboolean; - gpointer ptr = NULL; - if (gaim_value_is_outgoing(gaim_values[i])) { - ptr = my_arg(gpointer); - g_return_if_fail(ptr); + for (i = 0; i < number; i++) + { + const char *str; + int id; + gint xint; + guint xuint; + gboolean xboolean; + gpointer ptr = NULL; + + if (gaim_value_is_outgoing(gaim_values[i])) + { + ptr = my_arg(gpointer); + g_return_if_fail(ptr); + } + + switch (gaim_values[i]->type) + { + case GAIM_TYPE_INT: + xint = my_arg(gint); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint); + break; + case GAIM_TYPE_UINT: + xuint = my_arg(guint); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint); + break; + case GAIM_TYPE_BOOLEAN: + xboolean = my_arg(gboolean); + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean); + break; + case GAIM_TYPE_STRING: + str = null_to_empty(my_arg(char*)); + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); + break; + case GAIM_TYPE_SUBTYPE: /* registered pointers only! */ + case GAIM_TYPE_POINTER: + case GAIM_TYPE_OBJECT: + case GAIM_TYPE_BOXED: + id = gaim_dbus_pointer_to_id(my_arg(gpointer)); + dbus_message_iter_append_basic(iter, + (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id); + break; + default: /* no conversion implemented */ + g_return_if_reached(); + } } - - switch(gaim_values[i]->type) { - case GAIM_TYPE_INT: - xint = my_arg(gint); - dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint); - break; - case GAIM_TYPE_UINT: - xuint = my_arg(guint); - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint); - break; - case GAIM_TYPE_BOOLEAN: - xboolean = my_arg(gboolean); - dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean); - break; - case GAIM_TYPE_STRING: - str = null_to_empty(my_arg(char*)); - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); - break; - case GAIM_TYPE_SUBTYPE: /* registered pointers only! */ - case GAIM_TYPE_POINTER: - case GAIM_TYPE_OBJECT: - case GAIM_TYPE_BOXED: - id = gaim_dbus_pointer_to_id(my_arg(gpointer)); - dbus_message_iter_append_basic(iter, (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id); - break; - default: /* no conversion implemented */ - g_return_if_reached(); - } - } } #undef my_arg -void gaim_dbus_signal_emit_gaim(const char *name, int num_values, - GaimValue **values, va_list vargs) +void +gaim_dbus_signal_emit_gaim(const char *name, int num_values, + GaimValue **values, va_list vargs) { - DBusMessage *signal; - DBusMessageIter iter; - char *newname; + DBusMessage *signal; + DBusMessageIter iter; + char *newname; #if 0 /* this is noisy with no dbus connection */ - g_return_if_fail(gaim_dbus_connection); + g_return_if_fail(gaim_dbus_connection); #else if (gaim_dbus_connection == NULL) return; #endif - - /* The test below is a hack that prevents our "dbus-method-called" - signal from being propagated to dbus. What we really need is a - flag for each signal that states whether this signal is to be - dbus-propagated or not. */ - if (!strcmp(name, "dbus-method-called")) - return; - newname = gaim_dbus_convert_signal_name(name); - signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname); - dbus_message_iter_init_append(signal, &iter); + /* + * The test below is a hack that prevents our "dbus-method-called" + * signal from being propagated to dbus. What we really need is a + * flag for each signal that states whether this signal is to be + * dbus-propagated or not. + */ + if (!strcmp(name, "dbus-method-called")) + return; - gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs); + newname = gaim_dbus_convert_signal_name(name); + signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname); + dbus_message_iter_init_append(signal, &iter); - dbus_connection_send(gaim_dbus_connection, signal, NULL); + gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs); - g_free(newname); - dbus_message_unref(signal); + dbus_connection_send(gaim_dbus_connection, signal, NULL); + + g_free(newname); + dbus_message_unref(signal); } const char * @@ -713,15 +749,15 @@ void * gaim_dbus_get_handle(void) { - static int handle; + static int handle; - return &handle; + return &handle; } void gaim_dbus_init(void) { - gaim_dbus_init_ids(); + gaim_dbus_init_ids(); g_free(init_error); init_error = NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-18 07:18:11
|
Revision: 16517 Author: thekingant Date: 2006-07-18 00:18:05 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16517&view=rev Log Message: ----------- Whitespace McFixen. Also, I think I'm listening to a duet of the song "One" performed by Bono and Mary J. Blige? Modified Paths: -------------- trunk/src/dbus-server.c Modified: trunk/src/dbus-server.c =================================================================== --- trunk/src/dbus-server.c 2006-07-18 06:34:06 UTC (rev 16516) +++ trunk/src/dbus-server.c 2006-07-18 07:18:05 UTC (rev 16517) @@ -45,105 +45,119 @@ /** @name Gaim DBUS pointer registration mechanism */ /**************************************************************************/ -/* - Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for - all structs defined in gaim. This file has been generated by the - #dbus-analize-types.py script. -*/ +/* + * Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for + * all structs defined in gaim. This file has been generated by the + * #dbus-analize-types.py script. + */ #include "dbus-types.c" -/* The following three hashtables map are used to translate between - pointers (nodes) and the corresponding handles (ids). */ +/* + * The following three hashtables map are used to translate between + * pointers (nodes) and the corresponding handles (ids). + */ -static GHashTable *map_node_id; -static GHashTable *map_id_node; -static GHashTable *map_id_type; +static GHashTable *map_node_id; +static GHashTable *map_id_node; +static GHashTable *map_id_type; static gchar *init_error; - -/* This function initializes the pointer-id traslation system. It - creates the three above hashtables and defines parents of some types. +/** + * This function initializes the pointer-id traslation system. It + * creates the three above hashtables and defines parents of some types. */ -void gaim_dbus_init_ids(void) { - map_id_node = g_hash_table_new (g_direct_hash, g_direct_equal); - map_id_type = g_hash_table_new (g_direct_hash, g_direct_equal); - map_node_id = g_hash_table_new (g_direct_hash, g_direct_equal); +void +gaim_dbus_init_ids(void) +{ + map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal); + map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal); + map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal); - GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode); - GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode); + GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode); } -void gaim_dbus_register_pointer(gpointer node, GaimDBusType *type) +void +gaim_dbus_register_pointer(gpointer node, GaimDBusType *type) { - static gint last_id = 0; + static gint last_id = 0; - g_return_if_fail(map_node_id); - g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL); - - last_id++; - g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id)); - g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node); - g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type); + g_return_if_fail(map_node_id); + g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL); + + last_id++; + g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id)); + g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node); + g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type); } -void gaim_dbus_unregister_pointer(gpointer node) { - gpointer id = g_hash_table_lookup(map_node_id, node); - - g_hash_table_remove(map_node_id, node); - g_hash_table_remove(map_id_node, GINT_TO_POINTER(id)); - g_hash_table_remove(map_id_type, GINT_TO_POINTER(id)); +void +gaim_dbus_unregister_pointer(gpointer node) +{ + gpointer id = g_hash_table_lookup(map_node_id, node); + + g_hash_table_remove(map_node_id, node); + g_hash_table_remove(map_id_node, GINT_TO_POINTER(id)); + g_hash_table_remove(map_id_type, GINT_TO_POINTER(id)); } -gint gaim_dbus_pointer_to_id(gpointer node) { - gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node)); +gint +gaim_dbus_pointer_to_id(gpointer node) +{ + gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node)); if ((id == 0) && (node != NULL)) { gaim_debug_warning("dbus", "Need to register an object with the dbus subsystem.\n"); g_return_val_if_reached(0); } - return id; + return id; } - -gpointer gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) { - GaimDBusType *objtype = - (GaimDBusType*) g_hash_table_lookup(map_id_type, - GINT_TO_POINTER(id)); - - while (objtype != type && objtype != NULL) - objtype = objtype->parent; - if (objtype == type) - return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id)); - else - return NULL; +gpointer +gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) +{ + GaimDBusType *objtype; + + objtype = (GaimDBusType*)g_hash_table_lookup(map_id_type, + GINT_TO_POINTER(id)); + + while (objtype != type && objtype != NULL) + objtype = objtype->parent; + + if (objtype == type) + return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id)); + else + return NULL; } -gint gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error) +gint +gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error) { - gint id = gaim_dbus_pointer_to_id(ptr); + gint id = gaim_dbus_pointer_to_id(ptr); - if (ptr != NULL && id == 0) - dbus_set_error(error, "net.sf.gaim.ObjectNotFound", - "The return object is not mapped (this is a Gaim error)"); + if (ptr != NULL && id == 0) + dbus_set_error(error, "net.sf.gaim.ObjectNotFound", + "The return object is not mapped (this is a Gaim error)"); - return id; + return id; } -gpointer gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type, - const char *typename, DBusError *error) +gpointer +gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type, + const char *typename, DBusError *error) { - gpointer ptr = gaim_dbus_id_to_pointer(id, type); + gpointer ptr = gaim_dbus_id_to_pointer(id, type); - if (ptr == NULL && id != 0) - dbus_set_error(error, "net.sf.gaim.InvalidHandle", - "%s object with ID = %i not found", typename, id); - - return ptr; + if (ptr == NULL && id != 0) + dbus_set_error(error, "net.sf.gaim.InvalidHandle", + "%s object with ID = %i not found", typename, id); + + return ptr; } @@ -152,98 +166,96 @@ /**************************************************************************/ dbus_bool_t -gaim_dbus_message_get_args (DBusMessage *message, - DBusError *error, - int first_arg_type, - ...) +gaim_dbus_message_get_args(DBusMessage *message, + DBusError *error, int first_arg_type, ...) { - dbus_bool_t retval; - va_list var_args; + dbus_bool_t retval; + va_list var_args; - va_start (var_args, first_arg_type); - retval = gaim_dbus_message_get_args_valist (message, error, first_arg_type, var_args); - va_end (var_args); + va_start(var_args, first_arg_type); + retval = gaim_dbus_message_get_args_valist(message, error, first_arg_type, var_args); + va_end(var_args); - return retval; + return retval; } dbus_bool_t -gaim_dbus_message_get_args_valist (DBusMessage *message, - DBusError *error, - int first_arg_type, - va_list var_args) +gaim_dbus_message_get_args_valist(DBusMessage *message, + DBusError *error, int first_arg_type, va_list var_args) { - DBusMessageIter iter; + DBusMessageIter iter; - dbus_message_iter_init (message, &iter); - return gaim_dbus_message_iter_get_args_valist (&iter, error, first_arg_type, var_args); + dbus_message_iter_init(message, &iter); + return gaim_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args); } dbus_bool_t gaim_dbus_message_iter_get_args(DBusMessageIter *iter, - DBusError *error, - int first_arg_type, - ...) + DBusError *error, int first_arg_type, ...) { - dbus_bool_t retval; - va_list var_args; + dbus_bool_t retval; + va_list var_args; - va_start (var_args, first_arg_type); - retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args); - va_end (var_args); + va_start(var_args, first_arg_type); + retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args); + va_end(var_args); - return retval; + return retval; } -#define TYPE_IS_CONTAINER(typecode) \ - ((typecode) == DBUS_TYPE_STRUCT || \ - (typecode) == DBUS_TYPE_DICT_ENTRY || \ - (typecode) == DBUS_TYPE_VARIANT || \ - (typecode) == DBUS_TYPE_ARRAY) +#define TYPE_IS_CONTAINER(typecode) \ + ((typecode) == DBUS_TYPE_STRUCT || \ + (typecode) == DBUS_TYPE_DICT_ENTRY || \ + (typecode) == DBUS_TYPE_VARIANT || \ + (typecode) == DBUS_TYPE_ARRAY) dbus_bool_t -gaim_dbus_message_iter_get_args_valist (DBusMessageIter *iter, - DBusError *error, - int first_arg_type, - va_list var_args) +gaim_dbus_message_iter_get_args_valist(DBusMessageIter *iter, + DBusError *error, int first_arg_type, va_list var_args) { - int spec_type, msg_type, i; + int spec_type, msg_type, i; - spec_type = first_arg_type; - - for(i=0; spec_type != DBUS_TYPE_INVALID; i++) { - msg_type = dbus_message_iter_get_arg_type (iter); + spec_type = first_arg_type; - if (msg_type != spec_type) { - dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, - "Argument %d is specified to be of type \"%i\", but " - "is actually of type \"%i\"\n", i, - spec_type, msg_type); - return FALSE; + for (i = 0; spec_type != DBUS_TYPE_INVALID; i++) + { + msg_type = dbus_message_iter_get_arg_type(iter); + + if (msg_type != spec_type) + { + dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, + "Argument %d is specified to be of type \"%i\", but " + "is actually of type \"%i\"\n", i, + spec_type, msg_type); + return FALSE; + } + + if (!TYPE_IS_CONTAINER(spec_type)) + { + gpointer ptr; + ptr = va_arg (var_args, gpointer); + dbus_message_iter_get_basic(iter, ptr); + } + else + { + DBusMessageIter *sub; + sub = va_arg (var_args, DBusMessageIter*); + dbus_message_iter_recurse(iter, sub); + gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); + break; /* for testing only! */ + } + + spec_type = va_arg(var_args, int); + if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Message has only %d arguments, but more were expected", i); + return FALSE; + } } - if (!TYPE_IS_CONTAINER(spec_type)) { - gpointer ptr; - ptr = va_arg (var_args, gpointer); - dbus_message_iter_get_basic(iter, ptr); - } - else { - DBusMessageIter *sub; - sub = va_arg (var_args, DBusMessageIter*); - dbus_message_iter_recurse(iter, sub); - gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); - break; /* for testing only! */ - } - - spec_type = va_arg (var_args, int); - if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) { - dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, - "Message has only %d arguments, but more were expected", i); - return FALSE; - } - } - return TRUE; + return TRUE; } @@ -252,30 +264,33 @@ /** @name Useful functions */ /**************************************************************************/ -const char* empty_to_null(const char *str) { - if (str == NULL || str[0] == 0) - return NULL; - else - return str; +const char *empty_to_null(const char *str) +{ + if (str == NULL || str[0] == 0) + return NULL; + else + return str; } -const char* null_to_empty(const char *s) { +const char * +null_to_empty(const char *s) +{ if (s) return s; else return ""; } -dbus_int32_t* gaim_dbusify_GList(GList *list, gboolean free_memory, - dbus_int32_t *len) - { +dbus_int32_t * +gaim_dbusify_GList(GList *list, gboolean free_memory, dbus_int32_t *len) +{ dbus_int32_t *array; int i; GList *elem; *len = g_list_length(list); array = g_new0(dbus_int32_t, g_list_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = gaim_dbus_pointer_to_id(elem->data); if (free_memory) @@ -284,8 +299,8 @@ return array; } -dbus_int32_t* gaim_dbusify_GSList(GSList *list, gboolean free_memory, - dbus_int32_t *len) +dbus_int32_t * +gaim_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len) { dbus_int32_t *array; int i; @@ -293,7 +308,7 @@ *len = g_slist_length(list); array = g_new0(dbus_int32_t, g_slist_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = gaim_dbus_pointer_to_id(elem->data); if (free_memory) @@ -302,8 +317,8 @@ return array; } -gpointer* gaim_GList_to_array(GList *list, gboolean free_memory, - dbus_int32_t *len) +gpointer * +gaim_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len) { gpointer *array; int i; @@ -311,7 +326,7 @@ *len = g_list_length(list); array = g_new0(gpointer, g_list_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = elem->data; if (free_memory) @@ -320,8 +335,8 @@ return array; } -gpointer* gaim_GSList_to_array(GSList *list, gboolean free_memory, - dbus_int32_t *len) +gpointer * +gaim_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len) { gpointer *array; int i; @@ -329,7 +344,7 @@ *len = g_slist_length(list); array = g_new0(gpointer, g_slist_length(list)); - for(i = 0, elem = list; elem != NULL; elem = elem->next, i++) + for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) array[i] = elem->data; if (free_memory) @@ -338,40 +353,44 @@ return array; } -GHashTable *gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) { - GHashTable *hash; +GHashTable * +gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) +{ + GHashTable *hash; - /* we do not need to destroy strings because they are part of the message */ - hash = g_hash_table_new(g_str_hash, g_str_equal); + /* we do not need to destroy strings because they are part of the message */ + hash = g_hash_table_new(g_str_hash, g_str_equal); - do { - char *key, *value; - DBusMessageIter subiter; + do { + char *key, *value; + DBusMessageIter subiter; - if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) - goto error; /* With all due respect to Dijkstra, - this goto is for exception - handling, and it is ok because it - avoids duplication of the code - responsible for destroying the hash - table. Exceptional instructions - for exceptional situations. */ + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) + goto error; + /* With all due respect to Dijkstra, + * this goto is for exception + * handling, and it is ok because it + * avoids duplication of the code + * responsible for destroying the hash + * table. Exceptional instructions + * for exceptional situations. + */ - dbus_message_iter_recurse(iter, &subiter); - if (!gaim_dbus_message_iter_get_args(&subiter, error, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &value, - DBUS_TYPE_INVALID)) - goto error; /* same here */ + dbus_message_iter_recurse(iter, &subiter); + if (!gaim_dbus_message_iter_get_args(&subiter, error, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &value, + DBUS_TYPE_INVALID)) + goto error; /* same here */ - g_hash_table_insert(hash, key, value); - } while (dbus_message_iter_next(iter)); - - return hash; + g_hash_table_insert(hash, key, value); + } while (dbus_message_iter_next(iter)); - error: - g_hash_table_destroy(hash); - return NULL; + return hash; + +error: + g_hash_table_destroy(hash); + return NULL; } /**************************************************************/ @@ -380,213 +399,220 @@ static DBusConnection *gaim_dbus_connection; -DBusConnection *gaim_dbus_get_connection(void) { - return gaim_dbus_connection; +DBusConnection * +gaim_dbus_get_connection(void) +{ + return gaim_dbus_connection; } #include "dbus-bindings.c" static gboolean gaim_dbus_dispatch_cb(DBusConnection *connection, - DBusMessage *message, - void *user_data) + DBusMessage *message, void *user_data) { - const char *name; - GaimDBusBinding *bindings; - int i; + const char *name; + GaimDBusBinding *bindings; + int i; - bindings = (GaimDBusBinding*) user_data; + bindings = (GaimDBusBinding*) user_data; - if (!dbus_message_has_path(message, DBUS_PATH_GAIM)) - return FALSE; + if (!dbus_message_has_path(message, DBUS_PATH_GAIM)) + return FALSE; - name = dbus_message_get_member(message); + name = dbus_message_get_member(message); - if (name == NULL) - return FALSE; + if (name == NULL) + return FALSE; - if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL) - return FALSE; + if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL) + return FALSE; - for(i=0; bindings[i].name; i++) - if (!strcmp(name, bindings[i].name)) { - DBusMessage *reply; - DBusError error; + for (i = 0; bindings[i].name; i++) + if (!strcmp(name, bindings[i].name)) + { + DBusMessage *reply; + DBusError error; - dbus_error_init(&error); - - reply = bindings[i].handler(message, &error); - - if (reply == NULL && dbus_error_is_set(&error)) - reply = dbus_message_new_error (message, - error.name, - error.message); - - if (reply != NULL) { - dbus_connection_send (connection, reply, NULL); - dbus_message_unref(reply); - } - - return TRUE; /* return reply! */ - } + dbus_error_init(&error); - return FALSE; + reply = bindings[i].handler(message, &error); + + if (reply == NULL && dbus_error_is_set(&error)) + reply = dbus_message_new_error (message, + error.name, error.message); + + if (reply != NULL) + { + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + } + + return TRUE; /* return reply! */ + } + + return FALSE; } -static const char *dbus_gettext(const char **ptr) { - const char *text = *ptr; - *ptr += strlen(text) + 1; - return text; +static const char * +dbus_gettext(const char **ptr) +{ + const char *text = *ptr; + *ptr += strlen(text) + 1; + return text; } static void -gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) { - *bindings_list = g_list_prepend(*bindings_list, bindings); +gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) +{ + *bindings_list = g_list_prepend(*bindings_list, bindings); } -static DBusMessage *gaim_dbus_introspect(DBusMessage *message) +static DBusMessage *gaim_dbus_introspect(DBusMessage *message) { - DBusMessage *reply; - GString *str; - GList *bindings_list, *node; + DBusMessage *reply; + GString *str; + GList *bindings_list, *node; - str = g_string_sized_new(0x1000); /* fixme: why this size? */ + str = g_string_sized_new(0x1000); /* TODO: why this size? */ - g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n"); - g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM); - g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM); + g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n"); + g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM); + g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM); - bindings_list = NULL; - gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list); + bindings_list = NULL; + gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list); - for(node = bindings_list; node; node = node->next) { - GaimDBusBinding *bindings; - int i; + for (node = bindings_list; node; node = node->next) + { + GaimDBusBinding *bindings; + int i; - bindings = (GaimDBusBinding*) node->data; - - for(i=0; bindings[i].name; i++) { - const char *text; + bindings = (GaimDBusBinding*)node->data; - g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name); - - text = bindings[i].parameters; - while (*text) { - const char *name, *direction, *type; - - direction = dbus_gettext(&text); - type = dbus_gettext(&text); - name = dbus_gettext(&text); - - g_string_append_printf(str, - "<arg name='%s' type='%s' direction='%s'/>\n", - name, type, direction); - } - g_string_append(str, "</method>\n"); + for (i = 0; bindings[i].name; i++) + { + const char *text; + + g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name); + + text = bindings[i].parameters; + while (*text) + { + const char *name, *direction, *type; + + direction = dbus_gettext(&text); + type = dbus_gettext(&text); + name = dbus_gettext(&text); + + g_string_append_printf(str, + "<arg name='%s' type='%s' direction='%s'/>\n", + name, type, direction); + } + g_string_append(str, "</method>\n"); + } } - } - g_string_append(str, "</interface>\n</node>\n"); + g_string_append(str, "</interface>\n</node>\n"); - reply = dbus_message_new_method_return (message); - dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str), - DBUS_TYPE_INVALID); - g_string_free(str, TRUE); - g_list_free(bindings_list); + reply = dbus_message_new_method_return(message); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str), + DBUS_TYPE_INVALID); + g_string_free(str, TRUE); + g_list_free(bindings_list); - return reply; - + return reply; } -static DBusHandlerResult gaim_dbus_dispatch(DBusConnection *connection, - DBusMessage *message, - void *user_data) +static DBusHandlerResult +gaim_dbus_dispatch(DBusConnection *connection, + DBusMessage *message, void *user_data) { - if (gaim_signal_emit_return_1(gaim_dbus_get_handle(), - "dbus-method-called", - connection, message)) - return DBUS_HANDLER_RESULT_HANDLED; + if (gaim_signal_emit_return_1(gaim_dbus_get_handle(), + "dbus-method-called", connection, message)) + return DBUS_HANDLER_RESULT_HANDLED; - if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL && - dbus_message_has_path(message, DBUS_PATH_GAIM) && - dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) && - dbus_message_has_member(message, "Introspect")) - { - DBusMessage *reply; - reply = gaim_dbus_introspect(message); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref(reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL && + dbus_message_has_path(message, DBUS_PATH_GAIM) && + dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) && + dbus_message_has_member(message, "Introspect")) + { + DBusMessage *reply; + reply = gaim_dbus_introspect(message); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref(reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -void gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) { - gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called", - handle, +void +gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) +{ + gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called", + handle, GAIM_CALLBACK(gaim_dbus_dispatch_cb), bindings); - gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect", - handle, + gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect", + handle, GAIM_CALLBACK(gaim_dbus_introspect_cb), bindings); } +static void +gaim_dbus_dispatch_init(void) +{ + static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; + DBusError error; + int result; + dbus_error_init(&error); + gaim_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error); -static void gaim_dbus_dispatch_init(void) -{ - static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; + if (gaim_dbus_connection == NULL) + { + init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); + dbus_error_free(&error); + return; + } - DBusError error; - int result; - - dbus_error_init (&error); - gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); + if (!dbus_connection_register_object_path(gaim_dbus_connection, + DBUS_PATH_GAIM, &vtable, NULL)) + { + init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); + dbus_error_free(&error); + return; + } - if (gaim_dbus_connection == NULL) { - init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); - dbus_error_free(&error); - return; - } + result = dbus_bus_request_name(gaim_dbus_connection, + DBUS_SERVICE_GAIM, 0, &error); - if (!dbus_connection_register_object_path (gaim_dbus_connection, - DBUS_PATH_GAIM, &vtable, NULL)) - { - init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); - dbus_error_free(&error); - return; - } - + if (dbus_error_is_set(&error)) + { + dbus_connection_unref(gaim_dbus_connection); + dbus_error_free(&error); + gaim_dbus_connection = NULL; + init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); + return; + } - result = dbus_bus_request_name (gaim_dbus_connection, DBUS_SERVICE_GAIM, - 0, &error); - - if (dbus_error_is_set (&error)) { - dbus_connection_unref(gaim_dbus_connection); - dbus_error_free(&error); - gaim_dbus_connection = NULL; - init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); - return; - } - - dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); + dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); - gaim_debug_misc ("dbus", "okkk\n"); + gaim_debug_misc("dbus", "okkk\n"); - gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called", + gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called", gaim_marshal_BOOLEAN__POINTER_POINTER, gaim_value_new(GAIM_TYPE_BOOLEAN), 2, gaim_value_new(GAIM_TYPE_POINTER), gaim_value_new(GAIM_TYPE_POINTER)); - gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", + gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", gaim_marshal_VOID__POINTER, NULL, 1, gaim_value_new_outgoing(GAIM_TYPE_POINTER)); - GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); + GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); } @@ -597,14 +623,16 @@ -static char *gaim_dbus_convert_signal_name(const char *gaim_name) +static char * +gaim_dbus_convert_signal_name(const char *gaim_name) { int gaim_index, g_index; - char *g_name = g_new(char, strlen(gaim_name)+1); + char *g_name = g_new(char, strlen(gaim_name) + 1); gboolean capitalize_next = TRUE; - for(gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++) - if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') { + for (gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++) + if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') + { if (capitalize_next) g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]); else @@ -612,96 +640,104 @@ capitalize_next = FALSE; } else capitalize_next = TRUE; + g_name[g_index] = 0; - + return g_name; } #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type)) -static void gaim_dbus_message_append_gaim_values(DBusMessageIter *iter, - int number, - GaimValue **gaim_values, - va_list data) +static void +gaim_dbus_message_append_gaim_values(DBusMessageIter *iter, + int number, GaimValue **gaim_values, va_list data) { - int i; + int i; - for(i=0; i<number; i++) { - const char *str; - int id; - gint xint; - guint xuint; - gboolean xboolean; - gpointer ptr = NULL; - if (gaim_value_is_outgoing(gaim_values[i])) { - ptr = my_arg(gpointer); - g_return_if_fail(ptr); + for (i = 0; i < number; i++) + { + const char *str; + int id; + gint xint; + guint xuint; + gboolean xboolean; + gpointer ptr = NULL; + + if (gaim_value_is_outgoing(gaim_values[i])) + { + ptr = my_arg(gpointer); + g_return_if_fail(ptr); + } + + switch (gaim_values[i]->type) + { + case GAIM_TYPE_INT: + xint = my_arg(gint); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint); + break; + case GAIM_TYPE_UINT: + xuint = my_arg(guint); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint); + break; + case GAIM_TYPE_BOOLEAN: + xboolean = my_arg(gboolean); + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean); + break; + case GAIM_TYPE_STRING: + str = null_to_empty(my_arg(char*)); + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); + break; + case GAIM_TYPE_SUBTYPE: /* registered pointers only! */ + case GAIM_TYPE_POINTER: + case GAIM_TYPE_OBJECT: + case GAIM_TYPE_BOXED: + id = gaim_dbus_pointer_to_id(my_arg(gpointer)); + dbus_message_iter_append_basic(iter, + (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id); + break; + default: /* no conversion implemented */ + g_return_if_reached(); + } } - - switch(gaim_values[i]->type) { - case GAIM_TYPE_INT: - xint = my_arg(gint); - dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint); - break; - case GAIM_TYPE_UINT: - xuint = my_arg(guint); - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint); - break; - case GAIM_TYPE_BOOLEAN: - xboolean = my_arg(gboolean); - dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean); - break; - case GAIM_TYPE_STRING: - str = null_to_empty(my_arg(char*)); - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); - break; - case GAIM_TYPE_SUBTYPE: /* registered pointers only! */ - case GAIM_TYPE_POINTER: - case GAIM_TYPE_OBJECT: - case GAIM_TYPE_BOXED: - id = gaim_dbus_pointer_to_id(my_arg(gpointer)); - dbus_message_iter_append_basic(iter, (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id); - break; - default: /* no conversion implemented */ - g_return_if_reached(); - } - } } #undef my_arg -void gaim_dbus_signal_emit_gaim(const char *name, int num_values, - GaimValue **values, va_list vargs) +void +gaim_dbus_signal_emit_gaim(const char *name, int num_values, + GaimValue **values, va_list vargs) { - DBusMessage *signal; - DBusMessageIter iter; - char *newname; + DBusMessage *signal; + DBusMessageIter iter; + char *newname; #if 0 /* this is noisy with no dbus connection */ - g_return_if_fail(gaim_dbus_connection); + g_return_if_fail(gaim_dbus_connection); #else if (gaim_dbus_connection == NULL) return; #endif - - /* The test below is a hack that prevents our "dbus-method-called" - signal from being propagated to dbus. What we really need is a - flag for each signal that states whether this signal is to be - dbus-propagated or not. */ - if (!strcmp(name, "dbus-method-called")) - return; - newname = gaim_dbus_convert_signal_name(name); - signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname); - dbus_message_iter_init_append(signal, &iter); + /* + * The test below is a hack that prevents our "dbus-method-called" + * signal from being propagated to dbus. What we really need is a + * flag for each signal that states whether this signal is to be + * dbus-propagated or not. + */ + if (!strcmp(name, "dbus-method-called")) + return; - gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs); + newname = gaim_dbus_convert_signal_name(name); + signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname); + dbus_message_iter_init_append(signal, &iter); - dbus_connection_send(gaim_dbus_connection, signal, NULL); + gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs); - g_free(newname); - dbus_message_unref(signal); + dbus_connection_send(gaim_dbus_connection, signal, NULL); + + g_free(newname); + dbus_message_unref(signal); } const char * @@ -713,15 +749,15 @@ void * gaim_dbus_get_handle(void) { - static int handle; + static int handle; - return &handle; + return &handle; } void gaim_dbus_init(void) { - gaim_dbus_init_ids(); + gaim_dbus_init_ids(); g_free(init_error); init_error = NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-18 06:34:10
|
Revision: 16516 Author: thekingant Date: 2006-07-17 23:34:06 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16516&view=rev Log Message: ----------- Backport SVN revision #16515 from HEAD to v2_0_0 Original commit message: Fix a tiny and rare memleak when unloading a plugin that was designed for an older version of Gaim. ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16515&view=rev Modified Paths: -------------- branches/v2_0_0/plugins/dbus-example.c branches/v2_0_0/src/plugin.c branches/v2_0_0/src/protocols/msn/user.c Modified: branches/v2_0_0/plugins/dbus-example.c =================================================================== --- branches/v2_0_0/plugins/dbus-example.c 2006-07-18 06:33:36 UTC (rev 16515) +++ branches/v2_0_0/plugins/dbus-example.c 2006-07-18 06:34:06 UTC (rev 16516) @@ -152,7 +152,7 @@ GAIM_PRIORITY_DEFAULT, /**< priority */ "dbus-example", /**< id */ - N_("DBus"), /**< name */ + N_("DBus Example"), /**< name */ VERSION, /**< version */ /** summary */ N_("DBus Plugin Example"), Modified: branches/v2_0_0/src/plugin.c =================================================================== --- branches/v2_0_0/src/plugin.c 2006-07-18 06:33:36 UTC (rev 16515) +++ branches/v2_0_0/src/plugin.c 2006-07-18 06:34:06 UTC (rev 16516) @@ -772,12 +772,16 @@ * mismatch, but it's a lot better than trying to free something * we shouldn't, and crashing while trying to load an old plugin */ if(plugin->info == NULL || plugin->info->magic != GAIM_PLUGIN_MAGIC || - plugin->info->major_version != GAIM_MAJOR_VERSION) { + plugin->info->major_version != GAIM_MAJOR_VERSION) + { if(plugin->handle) g_module_close(plugin->handle); + g_free(plugin->path); + g_free(plugin->error); + GAIM_DBUS_UNREGISTER_POINTER(plugin); - + g_free(plugin); return; } Modified: branches/v2_0_0/src/protocols/msn/user.c =================================================================== --- branches/v2_0_0/src/protocols/msn/user.c 2006-07-18 06:33:36 UTC (rev 16515) +++ branches/v2_0_0/src/protocols/msn/user.c 2006-07-18 06:34:06 UTC (rev 16516) @@ -55,6 +55,12 @@ { g_return_if_fail(user != NULL); + /* + * TODO: If any GaimBuddy->proto_data pointers point to this + * MsnUser then set them to NULL. Or possibly even better, + * don't set GaimBuddy->proto_data in the first place. + */ + if (user->clientcaps != NULL) g_hash_table_destroy(user->clientcaps); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-18 06:33:40
|
Revision: 16515 Author: thekingant Date: 2006-07-17 23:33:36 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16515&view=rev Log Message: ----------- Fix a tiny and rare memleak when unloading a plugin that was designed for an older version of Gaim. Modified Paths: -------------- trunk/plugins/dbus-example.c trunk/src/plugin.c trunk/src/protocols/msn/user.c Modified: trunk/plugins/dbus-example.c =================================================================== --- trunk/plugins/dbus-example.c 2006-07-17 23:57:12 UTC (rev 16514) +++ trunk/plugins/dbus-example.c 2006-07-18 06:33:36 UTC (rev 16515) @@ -152,7 +152,7 @@ GAIM_PRIORITY_DEFAULT, /**< priority */ "dbus-example", /**< id */ - N_("DBus"), /**< name */ + N_("DBus Example"), /**< name */ VERSION, /**< version */ /** summary */ N_("DBus Plugin Example"), Modified: trunk/src/plugin.c =================================================================== --- trunk/src/plugin.c 2006-07-17 23:57:12 UTC (rev 16514) +++ trunk/src/plugin.c 2006-07-18 06:33:36 UTC (rev 16515) @@ -772,12 +772,16 @@ * mismatch, but it's a lot better than trying to free something * we shouldn't, and crashing while trying to load an old plugin */ if(plugin->info == NULL || plugin->info->magic != GAIM_PLUGIN_MAGIC || - plugin->info->major_version != GAIM_MAJOR_VERSION) { + plugin->info->major_version != GAIM_MAJOR_VERSION) + { if(plugin->handle) g_module_close(plugin->handle); + g_free(plugin->path); + g_free(plugin->error); + GAIM_DBUS_UNREGISTER_POINTER(plugin); - + g_free(plugin); return; } Modified: trunk/src/protocols/msn/user.c =================================================================== --- trunk/src/protocols/msn/user.c 2006-07-17 23:57:12 UTC (rev 16514) +++ trunk/src/protocols/msn/user.c 2006-07-18 06:33:36 UTC (rev 16515) @@ -55,6 +55,12 @@ { g_return_if_fail(user != NULL); + /* + * TODO: If any GaimBuddy->proto_data pointers point to this + * MsnUser then set them to NULL. Or possibly even better, + * don't set GaimBuddy->proto_data in the first place. + */ + if (user->clientcaps != NULL) g_hash_table_destroy(user->clientcaps); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 23:57:18
|
Revision: 16514 Author: sadrul Date: 2006-07-17 16:57:12 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16514&view=rev Log Message: ----------- Fix the makefile. Modified Paths: -------------- trunk/console/libgnt/test/Makefile Modified: trunk/console/libgnt/test/Makefile =================================================================== --- trunk/console/libgnt/test/Makefile 2006-07-17 22:27:26 UTC (rev 16513) +++ trunk/console/libgnt/test/Makefile 2006-07-17 23:57:12 UTC (rev 16514) @@ -1,6 +1,6 @@ CC=gcc CFLAGS=`pkg-config --cflags gobject-2.0 gmodule-2.0` -g -I../ -DSTANDALONE -LDFLAGS=`pkg-config --libs gobject-2.0 gmodule-2.0` -pg -lgnt -L../ +LDFLAGS=`pkg-config --libs gobject-2.0 gmodule-2.0 gnt` -pg EXAMPLES=combo focus tv multiwin This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 22:27:35
|
Revision: 16513 Author: sadrul Date: 2006-07-17 15:27:26 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16513&view=rev Log Message: ----------- It is possible to have multiple gnt-applications sharing the same screen. To try this, 'make WM' in console/libgnt/test. It will have a small 'Command' entry. You can give a command like './focus.so' (or one of the other examples). The applications can also be executed standalone. This required some tinkering to the Makefile. I am not sure whether there is an easier way of doing it. Modified Paths: -------------- trunk/console/libgnt/test/Makefile trunk/console/libgnt/test/combo.c trunk/console/libgnt/test/focus.c trunk/console/libgnt/test/multiwin.c trunk/console/libgnt/test/tv.c Added Paths: ----------- trunk/console/libgnt/test/wm.c Modified: trunk/console/libgnt/test/Makefile =================================================================== --- trunk/console/libgnt/test/Makefile 2006-07-17 21:53:28 UTC (rev 16512) +++ trunk/console/libgnt/test/Makefile 2006-07-17 22:27:26 UTC (rev 16513) @@ -1,6 +1,6 @@ CC=gcc -CFLAGS=`pkg-config --cflags gobject-2.0` -g -I../ -LDFLAGS=`pkg-config --libs gobject-2.0` -pg -lgnt -L../ +CFLAGS=`pkg-config --cflags gobject-2.0 gmodule-2.0` -g -I../ -DSTANDALONE +LDFLAGS=`pkg-config --libs gobject-2.0 gmodule-2.0` -pg -lgnt -L../ EXAMPLES=combo focus tv multiwin @@ -8,6 +8,9 @@ make examples clean: - rm -f $(EXAMPLES) + rm -f $(EXAMPLES) *.so wm +WM: wm + for i in $(EXAMPLES); do gcc -shared $(CFLAGS) -USTANDALONE $(LDFLAGS) $${i}.c -o $${i}.so ; done + examples: $(EXAMPLES) Modified: trunk/console/libgnt/test/combo.c =================================================================== --- trunk/console/libgnt/test/combo.c 2006-07-17 21:53:28 UTC (rev 16512) +++ trunk/console/libgnt/test/combo.c 2006-07-17 22:27:26 UTC (rev 16513) @@ -20,8 +20,10 @@ GntWidget *box, *combo, *button; GntWidget *hbox; +#ifdef STANDALONE freopen(".error", "w", stderr); gnt_init(); +#endif box = gnt_box_new(FALSE, TRUE); gnt_widget_set_name(box, "box"); @@ -61,9 +63,11 @@ gnt_widget_show(box); +#ifdef STANDALONE gnt_main(); gnt_quit(); +#endif return 0; } Modified: trunk/console/libgnt/test/focus.c =================================================================== --- trunk/console/libgnt/test/focus.c 2006-07-17 21:53:28 UTC (rev 16512) +++ trunk/console/libgnt/test/focus.c 2006-07-17 22:27:26 UTC (rev 16513) @@ -20,16 +20,15 @@ int main() { +#ifdef STANDALONE freopen(".error", "w", stderr); gnt_init(); - +#endif + GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\nSo this is, like,\nthe third line!! \\o/"); GntWidget *vbox, *hbox, *tree, *box, *button; WINDOW *test; - box(stdscr, 0, 0); - wrefresh(stdscr); - vbox = gnt_box_new(FALSE, FALSE); hbox = gnt_box_new(FALSE, TRUE); gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); @@ -58,7 +57,6 @@ GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); gnt_box_set_title(GNT_BOX(hbox), "This is the title …"); - g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(toggled), NULL); button = gnt_button_new("one"); @@ -77,9 +75,11 @@ gnt_widget_show(hbox); +#ifdef STANDALONE gnt_main(); gnt_quit(); +#endif return 0; } Modified: trunk/console/libgnt/test/multiwin.c =================================================================== --- trunk/console/libgnt/test/multiwin.c 2006-07-17 21:53:28 UTC (rev 16512) +++ trunk/console/libgnt/test/multiwin.c 2006-07-17 22:27:26 UTC (rev 16513) @@ -13,14 +13,13 @@ int main() { +#ifdef STANDALONE freopen(".error", "w", stderr); gnt_init(); +#endif GntWidget *hbox, *tree, *box2; - box(stdscr, 0, 0); - wrefresh(stdscr); - hbox = gnt_box_new(FALSE, TRUE); box2 = gnt_box_new(FALSE, TRUE); @@ -64,9 +63,11 @@ g_timeout_add(5000, (GSourceFunc)show, box2); +#ifdef STANDALONE gnt_main(); gnt_quit(); +#endif return 0; } Modified: trunk/console/libgnt/test/tv.c =================================================================== --- trunk/console/libgnt/test/tv.c 2006-07-17 21:53:28 UTC (rev 16512) +++ trunk/console/libgnt/test/tv.c 2006-07-17 22:27:26 UTC (rev 16513) @@ -35,13 +35,12 @@ { GntWidget *hbox, *entry, *view; +#ifdef STANDALONE freopen(".error", "w", stderr); gnt_init(); +#endif - box(stdscr, 0, 0); - wrefresh(stdscr); - hbox = gnt_box_new(FALSE, TRUE); gnt_widget_set_name(hbox, "hbox"); gnt_box_set_toplevel(GNT_BOX(hbox), TRUE); @@ -67,9 +66,11 @@ g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), view); +#ifdef STANDALONE gnt_main(); gnt_quit(); +#endif return 0; } Added: trunk/console/libgnt/test/wm.c =================================================================== --- trunk/console/libgnt/test/wm.c (rev 0) +++ trunk/console/libgnt/test/wm.c 2006-07-17 22:27:26 UTC (rev 16513) @@ -0,0 +1,65 @@ +#include <gmodule.h> + +#include <gnt.h> +#include <gntbox.h> +#include <gntentry.h> +#include <gntlabel.h> + +static gboolean +key_pressed(GntEntry *entry, const char *text, gpointer null) +{ + if (*text != '\r') + return FALSE; + + { + const char *cmd; + void *handle; + void (*func)(); + + cmd = gnt_entry_get_text(entry); + handle = g_module_open(cmd, G_MODULE_BIND_LOCAL); + if (handle && g_module_symbol(handle, "main", (gpointer)&func)) + { + gnt_entry_clear(entry); + func(); + } + else + { + GntWidget *widget = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(widget), TRUE); + gnt_box_set_title(GNT_BOX(widget), "Error"); + gnt_box_add_widget(GNT_BOX(widget), gnt_label_new("Could not execute.")); + + gnt_widget_show(widget); + } + } + + return TRUE; +} + +int main() +{ + GntWidget *window, *entry; + + freopen(".error", "w", stderr); + + gnt_init(); + + window = gnt_hbox_new(FALSE); + + gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Command")); + + entry = gnt_entry_new(NULL); + g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), NULL); + gnt_box_add_widget(GNT_BOX(window), entry); + + gnt_widget_set_position(window, 0, getmaxy(stdscr) - 2); + gnt_widget_show(window); + + gnt_main(); + + gnt_quit(); + + return 0; +} + Property changes on: trunk/console/libgnt/test/wm.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bi...@us...> - 2006-07-17 21:53:33
|
Revision: 16512 Author: billatq Date: 2006-07-17 14:53:28 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16512&view=rev Log Message: ----------- Partially plumbed async logging. Still needs to hook up a g_idle callback for each, incremental reading and something that understands being called multiple times from the event loop. Log sizing for the moment is out. Modified Paths: -------------- branches/soc-2006-db-logger/src/gtklog.c branches/soc-2006-db-logger/src/log.c branches/soc-2006-db-logger/src/log.h Modified: branches/soc-2006-db-logger/src/gtklog.c =================================================================== --- branches/soc-2006-db-logger/src/gtklog.c 2006-07-17 21:33:50 UTC (rev 16511) +++ branches/soc-2006-db-logger/src/gtklog.c 2006-07-17 21:53:28 UTC (rev 16512) @@ -281,7 +281,59 @@ } } -static GaimGtkLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, GList *logs, +static void update_log_viewer_cb(GList *logs, gpointer data) +{ + const char *month; + char prev_top_month[30] = ""; + GtkTreeIter toplevel, child; + GaimGtkLogViewer *lv; + gboolean first_run = FALSE; + + lv = (GaimGtkLogViewer *) data; + if(NULL == lv->logs) { first_run = TRUE; } + + // Concat the new batch of logs to the logviewer, but also keep them around to add to the tree view + lv->logs = g_list_concat(lv->logs, logs); + + while (logs != NULL) { + GaimLog *log = logs->data; + + month = gaim_utf8_strftime(_("%B %Y"), + log->tm ? log->tm : localtime(&log->time)); + + if (strcmp(month, prev_top_month) != 0) + { + /* top level */ + gtk_tree_store_append(lv->treestore, &toplevel, NULL); + gtk_tree_store_set(lv->treestore, &toplevel, 0, month, 1, NULL, -1); + + strncpy(prev_top_month, month, sizeof(prev_top_month)); + } + + /* sub */ + gtk_tree_store_append(lv->treestore, &child, &toplevel); + gtk_tree_store_set(lv->treestore, &child, + 0, log->tm ? gaim_date_format_full(log->tm) : gaim_date_format_full(localtime(&log->time)), + 1, log, + -1); + + logs = logs->next; + } + + if(first_run) + { + select_first_log(lv); + } + +} + +static void finish_update_log_viewer_cb(GList *logs, gpointer data) +{ + // TODO: Do something specific to being finished here + update_log_viewer_cb(logs, data); +} + +static GaimGtkLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, const char *title, GdkPixbuf *pixbuf, int log_size) { GaimGtkLogViewer *lv; @@ -298,30 +350,26 @@ GtkWidget *button; GtkWidget *size_label; - if (logs == NULL) - { - /* No logs were found. */ - const char *log_preferences = NULL; + /* Does logging seem to be disabled? */ + const char *log_preferences = NULL; - if (ht == NULL) { - if (!gaim_prefs_get_bool("/core/logging/log_system")) - log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled."); - } else { - if (ht->type == GAIM_LOG_IM) { - if (!gaim_prefs_get_bool("/core/logging/log_ims")) - log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled."); - } else if (ht->type == GAIM_LOG_CHAT) { - if (!gaim_prefs_get_bool("/core/logging/log_chats")) - log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled."); - } + if (ht == NULL) { + if (!gaim_prefs_get_bool("/core/logging/log_system")) + log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled."); + } else { + if (ht->type == GAIM_LOG_IM) { + if (!gaim_prefs_get_bool("/core/logging/log_ims")) + log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled."); + } else if (ht->type == GAIM_LOG_CHAT) { + if (!gaim_prefs_get_bool("/core/logging/log_chats")) + log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled."); } - + gaim_notify_info(NULL, title, _("No logs were found"), log_preferences); - return NULL; } lv = g_new0(GaimGtkLogViewer, 1); - lv->logs = logs; + lv->logs = NULL; if (ht != NULL) g_hash_table_insert(log_viewers, ht, lv); @@ -426,7 +474,7 @@ g_signal_connect(GTK_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv); g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(search_cb), lv); - select_first_log(lv); +/* select_first_log(lv); */ gtk_widget_show_all(lv->window); @@ -471,9 +519,12 @@ title = g_strdup_printf(_("Conversations with %s"), name); } - - display_log_viewer(ht, gaim_log_get_logs(type, screenname, account), - title, gaim_gtk_create_prpl_icon(account, 0.5), gaim_log_get_total_size(type, screenname, account)); + + // Set up log lister + gaim_log_get_logs(type, screenname, account, update_log_viewer_cb, lv, finish_update_log_viewer_cb, lv, NULL); + // XXX: Fix log sizing + display_log_viewer(ht, title, gaim_gtk_create_prpl_icon(account, 0.5), 0); + g_free(title); } @@ -505,9 +556,10 @@ if (!GAIM_BLIST_NODE_IS_BUDDY(child)) continue; - logs = g_list_concat(gaim_log_get_logs(GAIM_LOG_IM, ((GaimBuddy *)child)->name, - ((GaimBuddy *)child)->account), logs); - total_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy *)child)->name, ((GaimBuddy *)child)->account); + gaim_log_get_logs(GAIM_LOG_IM, ((GaimBuddy *)child)->name, ((GaimBuddy *)child)->account, update_log_viewer_cb, lv, finish_update_log_viewer_cb, lv, NULL); + // XXX: For simplicity's sake, pretend the log size is zero for now +// total_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy *)child)->name, ((GaimBuddy *)child)->account); + total_log_size = 0; } logs = g_list_sort(logs, gaim_log_compare); @@ -521,7 +573,7 @@ name = gaim_buddy_get_contact_alias(contact->priority); title = g_strdup_printf(_("Conversations with %s"), name); - display_log_viewer(ht, logs, title, pixbuf, total_log_size); + display_log_viewer(ht, title, pixbuf, total_log_size); g_free(title); } @@ -534,7 +586,8 @@ gtk_window_present(GTK_WINDOW(syslog_viewer->window)); return; } - + /* TODO: Finish this after the other bits */ +#if 0 for(accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { GaimAccount *account = (GaimAccount *)accounts->data; @@ -544,8 +597,9 @@ logs = g_list_concat(gaim_log_get_system_logs(account), logs); } logs = g_list_sort(logs, gaim_log_compare); - - syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), NULL, 0); +#endif + // XXX: Implement this thing +// syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), NULL, 0); } /**************************************************************************** Modified: branches/soc-2006-db-logger/src/log.c =================================================================== --- branches/soc-2006-db-logger/src/log.c 2006-07-17 21:33:50 UTC (rev 16511) +++ branches/soc-2006-db-logger/src/log.c 2006-07-17 21:53:28 UTC (rev 16512) @@ -49,12 +49,12 @@ static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, const char *from, time_t time, const char *message); static void html_logger_finalize(GaimLog *log); -static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer data); static GList *html_logger_list_syslog(GaimAccount *account); static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); static int html_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); -static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer data); static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags); static int old_logger_size (GaimLog *log); @@ -65,7 +65,7 @@ GaimMessageFlags type, const char *from, time_t time, const char *message); static void txt_logger_finalize(GaimLog *log); -static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer data); static GList *txt_logger_list_syslog(GaimAccount *account); static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags); static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); @@ -209,6 +209,7 @@ int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account) { gpointer ptrsize; + gpointer data; int size = 0; GSList *n; struct _gaim_logsize_user *lu; @@ -226,9 +227,13 @@ GaimLogLogger *logger = n->data; if(logger->total_size){ - size += (logger->total_size)(type, name, account); + // TODO: Fix this + //size += (logger->total_size)(type, name, account, gaim_log_get_logs_cb, data); + size = 0; } else if(logger->list) { - GList *logs = (logger->list)(type, name, account); + // TODO: Fix this + //GList *logs = (logger->list)(type, name, account, gaim_log_get_logs_cb, data); + /* int this_size = 0; while (logs) { @@ -239,6 +244,7 @@ } size += this_size; + */ } } @@ -417,18 +423,34 @@ return b->time - a->time; } -GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account) +// Target of the callback from the logger list +void gaim_log_get_logs_cb(GList *logs, gpointer data) { - GList *logs = NULL; + // ... +} + +void gaim_log_get_logs(GaimLogType type, + const char *name, + GaimAccount *account, + GaimLogListCallback *cb, + gpointer cb_data, + GaimLogListCallback *done_cb, + gpointer done_cb_data, + GList *logs) +{ + +//GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account) +//{ GSList *n; + gpointer data; for (n = loggers; n; n = n->next) { GaimLogLogger *logger = n->data; if (!logger->list) continue; - logs = g_list_concat(logger->list(type, name, account), logs); + logger->list(type, name, account, gaim_log_get_logs_cb, data); } - return g_list_sort(logs, gaim_log_compare); + //return g_list_sort(logs, gaim_log_compare); } gint gaim_log_set_compare(gconstpointer y, gconstpointer z) @@ -1143,7 +1165,7 @@ } } -static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) +static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer data) { return gaim_log_common_lister(type, sn, account, ".html", html_logger); } @@ -1275,7 +1297,7 @@ } } -static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) +static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer data) { return gaim_log_common_lister(type, sn, account, ".txt", txt_logger); } @@ -1328,7 +1350,7 @@ int length; }; -static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account) +static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account, GaimLogListCallback *cb, gpointer cb_data) { char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); Modified: branches/soc-2006-db-logger/src/log.h =================================================================== --- branches/soc-2006-db-logger/src/log.h 2006-07-17 21:33:50 UTC (rev 16511) +++ branches/soc-2006-db-logger/src/log.h 2006-07-17 21:53:28 UTC (rev 16512) @@ -50,6 +50,7 @@ #include "account.h" #include "conversation.h" +typedef void (*GaimLogListCallback) (GList *logs, gpointer data); typedef void (*GaimLogSetCallback) (GHashTable *sets, GaimLogSet *set); /** @@ -77,7 +78,7 @@ void (*finalize)(GaimLog *log); /** This function returns a sorted GList of available GaimLogs */ - GList *(*list)(GaimLogType type, const char *name, GaimAccount *account); + GList *(*list)(GaimLogType type, const char *name, GaimAccount *account, GaimLogListCallback *cb, gpointer cb_data); /** Given one of the logs returned by the logger's list function, * this returns the contents of the log in GtkIMHtml markup */ @@ -177,6 +178,8 @@ /***************************************/ /*@{*/ +void gaim_log_get_logs_cb(GList *logs, gpointer data); + /** * Creates a new log * @@ -226,6 +229,8 @@ */ char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags); +// TODO: Update Documentation + /** * Returns a list of all available logs * @@ -234,7 +239,14 @@ * @param account The account * @return A sorted list of GaimLogs */ -GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account); +void gaim_log_get_logs(GaimLogType type, + const char *name, + GaimAccount *account, + GaimLogListCallback *cb, + gpointer cb_data, + GaimLogListCallback *done_cb, + gpointer done_cb_data, + GList *logs); /** * Returns a GHashTable of GaimLogSets. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 21:33:55
|
Revision: 16511 Author: sadrul Date: 2006-07-17 14:33:50 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16511&view=rev Log Message: ----------- Fix a leak from last commit. Modified Paths: -------------- trunk/console/gntblist.c Modified: trunk/console/gntblist.c =================================================================== --- trunk/console/gntblist.c 2006-07-17 21:23:38 UTC (rev 16510) +++ trunk/console/gntblist.c 2006-07-17 21:33:50 UTC (rev 16511) @@ -479,6 +479,7 @@ gnt_widget_set_position(window, x, y); gnt_widget_draw(window); + g_free(title); } static void This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 21:23:45
|
Revision: 16510 Author: sadrul Date: 2006-07-17 14:23:38 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16510&view=rev Log Message: ----------- Add a context menu for the buddy-list. Most of the menus don't do anything yet, because the request-ui is not done. But the others, eg. 'Get Info', 'Join In Chat' etc.) work. Modified Paths: -------------- trunk/console/gntblist.c Modified: trunk/console/gntblist.c =================================================================== --- trunk/console/gntblist.c 2006-07-17 17:12:07 UTC (rev 16509) +++ trunk/console/gntblist.c 2006-07-17 21:23:38 UTC (rev 16510) @@ -1,5 +1,6 @@ #include <account.h> #include <blist.h> +#include <request.h> #include <server.h> #include <signal.h> #include <util.h> @@ -19,6 +20,9 @@ GntWidget *tooltip; GaimBlistNode *tnode; /* Who is the tooltip being displayed for? */ + + GntWidget *context; + GaimBlistNode *cnode; } GGBlist; GGBlist *ggblist; @@ -28,6 +32,7 @@ static void add_chat(GaimChat *chat, GGBlist *ggblist); static void add_node(GaimBlistNode *node, GGBlist *ggblist); static void draw_tooltip(GGBlist *ggblist); +static void remove_peripherals(GGBlist *ggblist); static void new_node(GaimBlistNode *node) @@ -252,6 +257,231 @@ } static void +remove_context_menu(GGBlist *ggblist) +{ + if (ggblist->context) + gnt_widget_destroy(ggblist->context->parent); + ggblist->context = NULL; + ggblist->cnode = NULL; +} + +static void +gnt_append_menu_action(GntTree *tree, GaimMenuAction *action, gpointer parent) +{ + GList *list; + + gnt_tree_add_row_after(tree, action, action->label, parent, NULL); + for (list = action->children; list; list = list->next) + gnt_append_menu_action(tree, list->data, action); +} + +static void +append_proto_menu(GntTree *tree, GaimConnection *gc, GaimBlistNode *node) +{ + GList *list; + GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); + + if(!prpl_info || !prpl_info->blist_node_menu) + return; + + for(list = prpl_info->blist_node_menu(node); list; + list = g_list_delete_link(list, list)) + { + GaimMenuAction *act = (GaimMenuAction *) list->data; + gnt_append_menu_action(tree, act, NULL); + } +} + +static void +add_custom_action(GntTree *tree, const char *label, GaimCallback callback, + gpointer data) +{ + GaimMenuAction *action = gaim_menu_action_new(label, callback, data, NULL); + gnt_append_menu_action(tree, action, NULL); + g_signal_connect_swapped(G_OBJECT(tree), "destroy", + G_CALLBACK(gaim_menu_action_free), action); +} + +static void +create_chat_menu(GntTree *tree, GaimChat *chat) +{ +} + +static void +create_group_menu(GntTree *tree, GaimGroup *group) +{ +} + +static void +gg_blist_get_buddy_info_cb(GaimBuddy *buddy, GaimBlistNode *null) +{ + serv_get_info(buddy->account->gc, gaim_buddy_get_name(buddy)); +} + +static void +create_buddy_menu(GntTree *tree, GaimBuddy *buddy) +{ + GaimPluginProtocolInfo *prpl_info; + + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); + if (prpl_info && prpl_info->get_info) + { + add_custom_action(tree, _("Get Info"), + GAIM_CALLBACK(gg_blist_get_buddy_info_cb), buddy); + } + +#if 0 + add_custom_action(tree, _("Add Buddy Pounce"), + GAIM_CALLBACK(gg_blist_add_buddy_pounce_cb)), buddy); + + if (prpl_info && prpl_info->send_file) + { + if (!prpl_info->can_receive_file || + prpl_info->can_receive_file(buddy->account->gc, buddy->name)) + add_custom_action(tree, _("Send File"), + GAIM_CALLBACK(gg_blist_show_file_cb)), buddy); + } + + add_custom_action(tree, _("View Log"), + GAIM_CALLBACK(gg_blist_view_log_cb)), buddy); +#endif + + /* Protocol actions */ + append_proto_menu(tree, + gaim_account_get_connection(gaim_buddy_get_account(buddy)), + (GaimBlistNode*)buddy); +} + +static void +append_extended_menu(GntTree *tree, GaimBlistNode *node) +{ + GList *iter; + + for (iter = gaim_blist_node_get_extended_menu(node); + iter; iter = g_list_delete_link(iter, iter)) + { + gnt_append_menu_action(tree, iter->data, NULL); + } +} + +static void +context_menu_callback(GntTree *tree, GGBlist *ggblist) +{ + GaimMenuAction *action = gnt_tree_get_selection_data(tree); + GaimBlistNode *node = ggblist->cnode; + + if (action) + { + void (*callback)(GaimBlistNode *, gpointer); + callback = (void (*)(GaimBlistNode *, gpointer))action->callback; + callback(node, action->data); + } + + remove_context_menu(ggblist); +} + +static void +gg_blist_rename_node_cb(GaimBlistNode *node, GaimBlistNode *null) +{ +} + +/* XXX: This still doesn't do anything, because request doesn't have a ui yet */ +static void +gg_blist_remove_node_cb(GaimBlistNode *node, GaimBlistNode *null) +{ + void (*callback)(gpointer); + + if (GAIM_BLIST_NODE_IS_BUDDY(node)) + callback = (void(*)(gpointer))gaim_blist_remove_buddy; + else if (GAIM_BLIST_NODE_IS_CHAT(node)) + callback = (void(*)(gpointer))gaim_blist_remove_chat; + else if (GAIM_BLIST_NODE_IS_GROUP(node)) + callback = (void(*)(gpointer))gaim_blist_remove_group; + + /* XXX: anything to do with the returned ui-handle? */ + gaim_request_action(node, _("Confirm Remove"), + _("Are you sure you want to remove ..."), NULL, /* XXX: tidy up */ + 1, node, 2, + _("Remove"), callback, + _("No"), NULL); + +} + +static void +draw_context_menu(GGBlist *ggblist) +{ + GaimBlistNode *node = NULL; + GntWidget *context = NULL, *window = NULL; + GntTree *tree = NULL; + int x, y, top, width; + char *title = NULL; + + tree = GNT_TREE(ggblist->tree); + + if (ggblist->context) + { + remove_context_menu(ggblist); + } + + node = gnt_tree_get_selection_data(tree); + + if (node == NULL) + return; + if (ggblist->tooltip) + remove_tooltip(ggblist); + + ggblist->cnode = node; + ggblist->context = context = gnt_tree_new(); + GNT_WIDGET_SET_FLAGS(context, GNT_WIDGET_NO_BORDER); + gnt_widget_set_name(context, "context menu"); + g_signal_connect(G_OBJECT(context), "activate", G_CALLBACK(context_menu_callback), ggblist); + + if (GAIM_BLIST_NODE_IS_BUDDY(node)) + { + GaimBuddy *buddy = (GaimBuddy *)node; + create_buddy_menu(GNT_TREE(context), buddy); + title = g_strdup(gaim_buddy_get_name(buddy)); + } + else if (GAIM_BLIST_NODE_IS_CHAT(node)) + { + GaimChat *chat = (GaimChat*)node; + create_chat_menu(GNT_TREE(context), chat); + title = g_strdup(gaim_chat_get_name(chat)); + } + else if (GAIM_BLIST_NODE_IS_GROUP(node)) + { + GaimGroup *group = (GaimGroup *)node; + create_group_menu(GNT_TREE(context), group); + title = g_strdup(group->name); + } + + append_extended_menu(GNT_TREE(context), node); + + /* These are common for everything */ + add_custom_action(GNT_TREE(context), _("Rename"), + GAIM_CALLBACK(gg_blist_rename_node_cb), node); + add_custom_action(GNT_TREE(context), _("Remove"), + GAIM_CALLBACK(gg_blist_remove_node_cb), node); + + window = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), title); + + gnt_box_add_widget(GNT_BOX(window), context); + + /* Set the position for the popup */ + gnt_widget_get_position(GNT_WIDGET(tree), &x, &y); + gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL); + top = gnt_tree_get_selection_visible_line(tree); + + x += width; + y += top - 1; + + gnt_widget_set_position(window, x, y); + gnt_widget_draw(window); +} + +static void draw_tooltip(GGBlist *ggblist) { GaimBlistNode *node; @@ -270,6 +500,9 @@ if (!gnt_widget_has_focus(ggblist->tree)) return; + if (ggblist->context) + return; + if (ggblist->tooltip) { /* XXX: Once we can properly redraw on expose events, this can be removed at the end @@ -372,18 +605,35 @@ static gboolean key_pressed(GntWidget *widget, const char *text, GGBlist *ggblist) { + gboolean stop = FALSE, ret = FALSE; if (text[0] == 27 && text[1] == 0) { /* Escape was pressed */ - if (ggblist->tooltip) + remove_peripherals(ggblist); + stop = TRUE; + ret = TRUE; + } + + if (ggblist->context) + { + ret = gnt_widget_key_pressed(ggblist->context, text); + stop = TRUE; + } + + if (text[0] == 27) + { + if (strcmp(text + 1, GNT_KEY_POPUP) == 0) { - gnt_widget_destroy(ggblist->tooltip); - ggblist->tooltip = NULL; - return TRUE; + draw_context_menu(ggblist); + stop = TRUE; + ret = TRUE; } } - return FALSE; + if (stop) + g_signal_stop_emission_by_name(G_OBJECT(widget), "key_pressed"); + + return ret; } static void @@ -411,6 +661,15 @@ update_buddy_display(buddy, ggblist); } +static void +remove_peripherals(GGBlist *ggblist) +{ + if (ggblist->tooltip) + remove_tooltip(ggblist); + else if (ggblist->context) + remove_context_menu(ggblist); +} + void gg_blist_init() { ggblist = g_new0(GGBlist, 1); @@ -456,7 +715,7 @@ g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist); g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip), ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); - g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_tooltip), + g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_peripherals), ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-07-17 17:12:15
|
Revision: 16509 Author: seanegan Date: 2006-07-17 10:12:07 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16509&view=rev Log Message: ----------- (01:48:55 PM) Zilding: Hey Sean... I tried to get Rob to do this for years, but he never f'n got around to it -- please remove my s/n from the contact page? :) Modified Paths: -------------- web/htdocs/contactinfo.php Modified: web/htdocs/contactinfo.php =================================================================== --- web/htdocs/contactinfo.php 2006-07-17 13:37:08 UTC (rev 16508) +++ web/htdocs/contactinfo.php 2006-07-17 17:12:07 UTC (rev 16509) @@ -184,10 +184,9 @@ <dl> <dt> - Jim Duchek - <<a href="mailto:ji...@li...">ji...@li...</a>> + Jim Duchek </dt> <dd> - <b>AIM:</b> Zilding<br /> <i>Ex-Maintainer, resident bum, alcohol consumer, and Tiger tamer.</i> </dd> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 13:37:19
|
Revision: 16508 Author: sadrul Date: 2006-07-17 06:37:08 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16508&view=rev Log Message: ----------- Use alt+, and alt+. to change the order of the window. Modified Paths: -------------- trunk/console/libgnt/gntmain.c Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-07-17 12:22:37 UTC (rev 16507) +++ trunk/console/libgnt/gntmain.c 2006-07-17 13:37:08 UTC (rev 16508) @@ -275,6 +275,34 @@ g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL); } +static void +shift_window(GntWidget *widget, int dir) +{ + GList *all = g_list_first(focus_list); + GList *list = g_list_find(all, widget); + int length, pos; + if (!list) + return; + + length = g_list_length(all); + pos = g_list_position(all, list); + + pos += dir; + if (dir > 0) + pos++; + + if (pos < 0) + pos = length; + else if (pos > length) + pos = 0; + + all = g_list_insert(all, widget, pos); + all = g_list_delete_link(all, list); + if (focus_list == list) + focus_list = g_list_find(all, widget); + draw_taskbar(); +} + static gboolean io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) { @@ -351,6 +379,15 @@ /* Resize window */ mode = GNT_KP_MODE_RESIZE; } + else if (strcmp(buffer + 1, ",") == 0 && focus_list) + { + /* Re-order the list of windows */ + shift_window(focus_list->data, -1); + } + else if (strcmp(buffer + 1, ".") == 0 && focus_list) + { + shift_window(focus_list->data, 1); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <may...@us...> - 2006-07-17 12:23:09
|
Revision: 16507 Author: mayuan2006 Date: 2006-07-17 05:22:37 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16507&view=rev Log Message: ----------- add the contact list retrieve and dump contact list to server currently can do chanllenge successfully But can't get the buddy list done by MaYuan<may...@gm...> Modified Paths: -------------- branches/soc-2006-msnp13/src/protocols/msn/Makefile.am branches/soc-2006-msnp13/src/protocols/msn/cmdproc.c branches/soc-2006-msnp13/src/protocols/msn/command.c branches/soc-2006-msnp13/src/protocols/msn/contact.c branches/soc-2006-msnp13/src/protocols/msn/contact.h branches/soc-2006-msnp13/src/protocols/msn/dialog.c branches/soc-2006-msnp13/src/protocols/msn/group.c branches/soc-2006-msnp13/src/protocols/msn/group.h branches/soc-2006-msnp13/src/protocols/msn/msn-utils.c branches/soc-2006-msnp13/src/protocols/msn/msn-utils.h branches/soc-2006-msnp13/src/protocols/msn/msn.h branches/soc-2006-msnp13/src/protocols/msn/nexus.c branches/soc-2006-msnp13/src/protocols/msn/notification.c branches/soc-2006-msnp13/src/protocols/msn/notification.h branches/soc-2006-msnp13/src/protocols/msn/object.c branches/soc-2006-msnp13/src/protocols/msn/session.c branches/soc-2006-msnp13/src/protocols/msn/soap.c branches/soc-2006-msnp13/src/protocols/msn/soap.h branches/soc-2006-msnp13/src/protocols/msn/user.c branches/soc-2006-msnp13/src/protocols/msn/user.h branches/soc-2006-msnp13/src/protocols/msn/userlist.c branches/soc-2006-msnp13/src/protocols/msn/userlist.h Added Paths: ----------- branches/soc-2006-msnp13/src/protocols/msn/oim.c branches/soc-2006-msnp13/src/protocols/msn/oim.h Modified: branches/soc-2006-msnp13/src/protocols/msn/Makefile.am =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/Makefile.am 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/Makefile.am 2006-07-17 12:22:37 UTC (rev 16507) @@ -32,6 +32,8 @@ notification.h \ object.c \ object.h \ + oim.c\ + oim.h\ page.c \ page.h \ servconn.c \ Modified: branches/soc-2006-msnp13/src/protocols/msn/cmdproc.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/cmdproc.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/cmdproc.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -134,6 +134,7 @@ } msn_servconn_write(servconn, data, len); + gaim_debug_info("<<","%s",data); g_free(data); } Modified: branches/soc-2006-msnp13/src/protocols/msn/command.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/command.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/command.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -47,7 +47,6 @@ if( (!strcmp(str,"ADL")) || (!strcmp(str,"GCF")) || (!strcmp(str,"MSG")) || - (!strcmp(str,"QRY")) || (!strcmp(str,"RML")) || (!strcmp(str,"UBX")) || (!strcmp(str,"UBN")) || Modified: branches/soc-2006-msnp13/src/protocols/msn/contact.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/contact.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/contact.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -37,9 +37,7 @@ contact = g_new0(MsnContact, 1); contact->session = session; - contact->soapconn = msn_soap_new(session); - contact->soapconn->parent = contact; - contact->soapconn->ssl_conn = 1; + contact->soapconn = msn_soap_new(session,contact,1); return contact; } @@ -84,13 +82,44 @@ msn_get_contact_list(contact); } +/*get MSN member role utility*/ +static int +msn_get_memberrole(char * role) +{ + if(!strcmp(role,"Allow")){ + return MSN_LIST_AL_OP; + }else if(!strcmp(role,"Block")){ + return MSN_LIST_BL_OP; + }else if(!strcmp(role,"Reverse")){ + return MSN_LIST_RL_OP; + }else if(!strcmp(role,"Forward")){ + return MSN_LIST_FL_OP; + } + return 0; +} + +/*get User Type*/ +static int +msn_get_user_type(char * type) +{ + if(!strcmp(type,"Regular")){ + return 1; + } + return 0; +} + +/*parse contact list*/ static void msn_parse_contact_list(MsnContact * contact) { - xmlnode * node,*envelop,*body,*response,*result,*services,*service,*memberships; - xmlnode *membershipnode,*members,*member,*passport,*role; - int len; + MsnSession * session; + MsnUser *user; + int list_op =0; + char * passport; + xmlnode * node,*body,*response,*result,*services,*service,*memberships; + xmlnode *membershipnode,*members,*member,*passportNode,*role; + session = contact->session; gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); // node = xmlnode_from_str(contact->soapconn->body, -1); @@ -115,16 +144,28 @@ for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; membershipnode = xmlnode_get_next_twin(membershipnode)){ role = xmlnode_get_child(membershipnode,"MemberRole"); - gaim_debug_misc("memberrole","role:%s\n",xmlnode_get_data(role)); + // gaim_debug_misc("memberrole","role:%s\n",xmlnode_get_data(role)); + list_op = msn_get_memberrole(xmlnode_get_data(role)); + gaim_debug_misc("memberrole","role:%s,list_op:%d\n",xmlnode_get_data(role),list_op); members = xmlnode_get_child(membershipnode,"Members"); - for(member = xmlnode_get_child(members, "Member"); member; - member = xmlnode_get_next_twin(member)){ - passport = xmlnode_get_child(member,"PassportName"); - gaim_debug_misc("Passport","name:%s\n",xmlnode_get_data(passport)); + for(member = xmlnode_get_child(members, "Member"); member; + member = xmlnode_get_next_twin(member)){ + passportNode = xmlnode_get_child(member,"PassportName"); + passport = xmlnode_get_data(passportNode); + gaim_debug_misc("Passport","name:%s\n",passport); + user = msn_userlist_find_user(session->userlist, passport); + if (user == NULL){ + user = msn_user_new(session->userlist, passport, ""); + msn_userlist_add_user(session->userlist, user); } +// user->list_op |= list_op; + msn_got_lst_user(session, user, list_op, NULL); + } } xmlnode_free(node); + + msn_get_address_book(contact); } static void @@ -156,55 +197,182 @@ void msn_get_contact_list(MsnContact * contact) { - char * soap_head = NULL; - char * soap_body = NULL; - char * request_str = NULL; - gaim_debug_info("MaYuan","msn_get_contact_list()...\n"); contact->soapconn->login_path = g_strdup(MSN_GET_CONTACT_POST_URL); - soap_body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE); - soap_head = g_strdup_printf( - "POST %s HTTP/1.1\r\n" - "SOAPAction: http://www.msn.com/webservices/AddressBook/FindMembership\r\n" - "Content-Type:text/xml; charset=utf-8\r\n" - "Cookie: MSPAuth=%s\r\n" - "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" - "Accept: text/*\r\n" - "Host: %s\r\n" - "Content-Length: %d\r\n" - "Connection: Keep-Alive\r\n" - "Cache-Control: no-cache\r\n\r\n", - contact->soapconn->login_path, - contact->session->passport_info.mspauth, - contact->soapconn->login_host, - strlen(soap_body) - ); - request_str = g_strdup_printf("%s%s", soap_head,soap_body); - g_free(soap_head); - g_free(soap_body); + contact->soapconn->soap_action = g_strdup(MSN_GET_CONTACT_SOAP_ACTION); + msn_soap_post(contact->soapconn,MSN_GET_CONTACT_TEMPLATE,msn_contact_written_cb); +} -// gaim_debug_info("MaYuan","send to contact server{%s}\n",request_str); - msn_soap_write(contact->soapconn,request_str,msn_contact_written_cb); +static void +msn_parse_addressbook(MsnContact * contact) +{ + MsnSession * session; + xmlnode * node,*body,*response,*result; + xmlnode *groups,*group,*groupname,*groupId,*groupInfo; + xmlnode *contacts,*contactNode,*contactId,*contactInfo,*contactType,*passportName,*displayName,*groupIds,*guid; + xmlnode *ab; + + session = contact->session; + gaim_debug_misc("xml","parse addressbook:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); + node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); + + if(node == NULL){ + gaim_debug_misc("xml","parse from str err!\n"); + return; + } + gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); + body = xmlnode_get_child(node,"Body"); + gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); + response = xmlnode_get_child(body,"ABFindAllResponse"); + gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); + result =xmlnode_get_child(response,"ABFindAllResult"); + gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); + groups =xmlnode_get_child(result,"groups"); + for(group = xmlnode_get_child(groups, "Group"); group; + group = xmlnode_get_next_twin(group)){ + char * name,*group_id; + groupId = xmlnode_get_child(group,"groupId"); + group_id = xmlnode_get_data(groupId); + groupInfo = xmlnode_get_child(group,"groupInfo"); + groupname = xmlnode_get_child(groupInfo,"name"); + name = xmlnode_get_data(groupname); + + msn_group_new(session->userlist, group_id, name); + + if (group_id == NULL) + /* Group of ungroupped buddies */ + continue; + + if ((gaim_find_group(name)) == NULL){ + GaimGroup *g = gaim_group_new(name); + gaim_blist_add_group(g, NULL); + } + + gaim_debug_misc("group","name:%s,Id:{%s}\n",name,group_id); + } + + contacts =xmlnode_get_child(result,"contacts"); + for(contactNode = xmlnode_get_child(contacts, "Contact"); contactNode; + contactNode = xmlnode_get_next_twin(contactNode)){ + MsnUser *user; + char *passport,*Name,*uid,*type; + + contactId= xmlnode_get_child(contactNode,"contactId"); + uid = xmlnode_get_data(contactId); + + contactInfo = xmlnode_get_child(contactNode,"contactInfo"); + contactType = xmlnode_get_child(contactInfo,"contactType"); + type = xmlnode_get_data(contactType); + + passportName = xmlnode_get_child(contactInfo,"passportName"); + passport = xmlnode_get_data(passportName); + + displayName = xmlnode_get_child(contactInfo,"displayName"); + Name =xmlnode_get_data(displayName); + + gaim_debug_misc("contact","name:%s,Id:{%s},display:{%s}\n", + passport, + xmlnode_get_data(contactId), + Name); + + user = msn_userlist_find_user(session->userlist, passport); + if (user == NULL){ + user = msn_user_new(session->userlist, passport, Name); + msn_userlist_add_user(session->userlist, user); + } + msn_user_set_uid(user,uid); + msn_user_set_type(user,msn_get_user_type(type)); + + groupIds = xmlnode_get_child(contactInfo,"groupIds"); + if(groupIds){ + for(guid = xmlnode_get_child(groupIds, "guid");guid; + guid = xmlnode_get_next_twin(guid)){ + char * group_id; + + group_id = xmlnode_get_data(guid); + msn_user_add_group_id(user,group_id); + gaim_debug_misc("contact","guid:%s\n",group_id); + } + }else{ + gaim_debug_misc("contact","guid is NULL\n"); + } + } + + ab =xmlnode_get_child(result,"ab"); + + xmlnode_free(node); + msn_soap_free_read_buf(contact->soapconn); + + dump_adl_cmd(session); + msn_session_finish_login(session); } -msn_add_contact() +static void +msn_get_address_cb(gpointer data, gint source, GaimInputCondition cond) { + MsnSoapConn * soapconn = data; + MsnContact *contact; + MsnSession *session; + + contact = soapconn->parent; + g_return_if_fail(contact != NULL); + session = soapconn->session; + g_return_if_fail(session != NULL); + +// gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); + msn_parse_addressbook(contact); } -msn_delete_contact() +/**/ +static void +msn_address_written_cb(gpointer data, gint source, GaimInputCondition cond) { + MsnSoapConn * soapconn = data; + + gaim_debug_info("MaYuan","finish contact written\n"); + soapconn->read_cb = msn_get_address_cb; + msn_soap_read_cb(data,source,cond); } -msn_block_contact() +/*get the address book*/ +void +msn_get_address_book(MsnContact *contact) { + gaim_debug_info("MaYuan","msn_get_address_book()...\n"); + /*build SOAP and POST it*/ + contact->soapconn->login_path = g_strdup(MSN_GET_ADDRESS_POST_URL); + contact->soapconn->soap_action = g_strdup(MSN_GET_ADDRESS_SOAP_ACTION); + msn_soap_post(contact->soapconn,MSN_GET_ADDRESS_TEMPLATE,msn_address_written_cb); } -msn_unblock_contact() +void +msn_add_contact(MsnContact *contact) { + } -msn_get_gleams() +void +msn_delete_contact(MsnContact *contact) +{ + +} + +void +msn_block_contact(MsnContact *contact) +{ + +} + +void +msn_unblock_contact(MsnContact *contact) +{ + +} + +void +msn_get_gleams(MsnContact *contact) { + } void Modified: branches/soc-2006-msnp13/src/protocols/msn/contact.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/contact.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/contact.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -28,6 +28,7 @@ #define MSN_CONTACT_SERVER "contacts.msn.com" #define MSN_GET_CONTACT_POST_URL "/abservice/SharingService.asmx" +#define MSN_GET_CONTACT_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/FindMembership" #define MSN_GET_CONTACT_TEMPLATE "<?xml version='1.0' encoding='utf-8'?>"\ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\ "<soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\ @@ -55,7 +56,9 @@ "</soap:Body>"\ "</soap:Envelope>" -#define MSN_ADDRESS_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\ +#define MSN_GET_ADDRESS_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/ABFindAll" +#define MSN_GET_ADDRESS_POST_URL "/abservice/abservice.asmx" +#define MSN_GET_ADDRESS_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"\ "<soap:Header>"\ "<ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">"\ @@ -97,6 +100,25 @@ "</soap:Body>"\ "</soap:Envelope>" +#define MSN_CONTACT_ADD_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/ABContactAdd" +#define MSN_CONTACT_XML "<Contact xmlns=\"http://www.msn.com/webservices/AddressBook\"><contactInfo><contactType>LivePending</contactType><passportName>%s</passportName><isMessengerUser>true</isMessengerUser></contactInfo></Contact>" + +#define MSN_ADD_CONTACT_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>ContactSave</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABContactAdd xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><contacts>%s</contacts><options><EnableAllowListManagement>true</EnableAllowListManagement></options></ABContactAdd></soap:Body></soap:Envelope>" + +#define MSN_CONTACT_DEL_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/ABContactDelete" +#define MSN_CONTACTS_DEL "<Contact><contactId>5e8a2e64-c271-443f-ac86-2429f3ffd18a</contactId></Contact>" +#define MSN_DEL_CONTACT_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>Timer</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABContactDelete xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><contacts>%s</contacts></ABContactDelete></soap:Body></soap:Envelope>" + +#define MSN_MEMBER_TEMPLATE "<Member xsi:type=\"PassportMember\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Type>Passport</Type><State>Accepted</State><PassportName>%s</PassportName></Member>" + +/*block means add contact to block list*/ +#define MSN_CONTACT_BLOCK_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/AddMember" +#define MSN_BLOCK_CONTACT_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>BlockUnblock</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><AddMember xmlns=\"http://www.msn.com/webservices/AddressBook\"><serviceHandle><Id>0</Id><Type>Messenger</Type><ForeignId></ForeignId></serviceHandle><memberships><Membership><MemberRole>Block</MemberRole><Members>%s</Members></Membership></memberships></AddMember></soap:Body></soap:Envelope>" + +/*unblock means delete contact to block list*/ +#define MSN_CONTACT_UNBLOCK_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/DeleteMember" +#define MSN_UNBLOCK_CONTACT_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>BlockUnblock</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><DeleteMember xmlns=\"http://www.msn.com/webservices/AddressBook\"><serviceHandle><Id>0</Id><Type>Messenger</Type><ForeignId></ForeignId></serviceHandle><memberships><Membership><MemberRole>Block</MemberRole><Members>%s</Members></Membership></memberships></DeleteMember></soap:Body></soap:Envelope>" + typedef struct _MsnContact MsnContact; struct _MsnContact @@ -108,11 +130,11 @@ /*function prototype*/ MsnContact * msn_contact_new(MsnSession *session); -void msn_get_contact_list(MsnContact * contact); +void msn_contact_destroy(MsnContact *contact); + void msn_contact_connect(MsnContact *contact); - -void msn_contact_destroy(MsnContact *contact); void msn_get_contact_list(MsnContact * contact); +void msn_get_address_book(MsnContact *contact); #endif/* _MSN_CMDPROC_H_*/ Modified: branches/soc-2006-msnp13/src/protocols/msn/dialog.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/dialog.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/dialog.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -93,16 +93,13 @@ gaim_account_get_username(account), gaim_account_get_protocol_name(account)); - if (group_name != NULL) - { + if (group_name != NULL){ reason = g_strdup_printf(_("%s on the local list is " "inside the group \"%s\" but not on " "the server list. " "Do you want this buddy to be added?"), passport, group_name); - } - else - { + }else{ reason = g_strdup_printf(_("%s is on the local list but " "not on the server list. " "Do you want this buddy to be added?"), Modified: branches/soc-2006-msnp13/src/protocols/msn/group.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/group.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/group.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -25,18 +25,18 @@ #include "group.h" MsnGroup * -msn_group_new(MsnUserList *userlist, int id, const char *name) +msn_group_new(MsnUserList *userlist, const char *id, const char *name) { MsnGroup *group; - g_return_val_if_fail(id >= 0, NULL); + g_return_val_if_fail(id != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); group = g_new0(MsnGroup, 1); msn_userlist_add_group(userlist, group); - group->id = id; + group->id = g_strdup(id); group->name = g_strdup(name); return group; @@ -47,17 +47,18 @@ { g_return_if_fail(group != NULL); + g_free(group->id); g_free(group->name); g_free(group); } void -msn_group_set_id(MsnGroup *group, int id) +msn_group_set_id(MsnGroup *group, const char *id) { g_return_if_fail(group != NULL); - g_return_if_fail(id >= 0); + g_return_if_fail(id != NULL); - group->id = id; + group->id = g_strdup(id); } void @@ -72,7 +73,7 @@ group->name = g_strdup(name); } -int +char* msn_group_get_id(const MsnGroup *group) { g_return_val_if_fail(group != NULL, -1); @@ -87,3 +88,4 @@ return group->name; } + Modified: branches/soc-2006-msnp13/src/protocols/msn/group.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/group.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/group.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -30,17 +30,25 @@ #include "session.h" #include "user.h" - +#include "soap.h" #include "userlist.h" +#define MSN_ADD_GROUPS "<GroupInfo><name>test111</name><groupType>C8529CE2-6EAD-434d-881F-341E17DB3FF8</groupType><fMessenger>false</fMessenger><annotations><Annotation><Name>MSN.IM.Display</Name><Value>1</Value></Annotation></annotations></GroupInfo>" + +#define MSN_ADD_GROUP_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>GroupSave</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABGroupAdd xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><groupAddOptions><fRenameOnMsgrConflict>false</fRenameOnMsgrConflict></groupAddOptions><groupInfo>%s</groupInfo></ABGroupAdd></soap:Body></soap:Envelope>" + +#define MSN_GROUP_IDS "<guid>9e57e654-59f0-44d1-aedc-0a7500b7e51f</guid>" +#define MSN_DELETE_GROUP_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>Timer</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABGroupDelete xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><groupFilter><groupIds>%s</groupIds></groupFilter></ABGroupDelete></soap:Body></soap:Envelope>" + /** * A group. */ struct _MsnGroup { MsnSession *session; /**< The MSN session. */ + MsnSoapConn *soapconn; - int id; /**< The group ID. */ + char *id; /**< The group ID. */ char *name; /**< The name of the group. */ }; @@ -58,7 +66,7 @@ * * @return A new group structure. */ -MsnGroup *msn_group_new(MsnUserList *userlist, int id, const char *name); +MsnGroup *msn_group_new(MsnUserList *userlist, const char *id, const char *name); /** * Destroys a group structure. @@ -73,7 +81,7 @@ * @param group The group. * @param id The ID. */ -void msn_group_set_id(MsnGroup *group, int id); +void msn_group_set_id(MsnGroup *group, const char *id); /** * Sets the name for a group. @@ -90,7 +98,7 @@ * * @return The ID. */ -int msn_group_get_id(const MsnGroup *group); +char* msn_group_get_id(const MsnGroup *group); /** * Returns the name for a group. Modified: branches/soc-2006-msnp13/src/protocols/msn/msn-utils.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/msn-utils.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/msn-utils.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -23,6 +23,7 @@ */ #include "msn.h" #include "msn-utils.h" +//#include <openssl/md5.h> void msn_parse_format(const char *mime, char **pre_ret, char **post_ret) @@ -362,3 +363,122 @@ *ret_port = port; } +/*check the edian of system*/ +int +isBigEndian(void) +{ + short int word = 0x0100; + char *byte = (char *)&word; + + return(byte[0]); +} + +/*swap utility*/ +unsigned int +swapInt(unsigned int dw) +{ + unsigned int tmp; + tmp = (dw & 0x000000FF); + tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08); + tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08); + tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08); + return(tmp); +} + +/* + * handle MSN Chanllege computation + *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges + */ +#define BUFSIZE 256 +void +msn_handle_chl(char *input, char *output) +{ + GaimCipher *cipher; + GaimCipherContext *context; + char *productKey = MSNP13_WLM_PRODUCT_KEY, + *productID = MSNP13_WLM_PRODUCT_ID, + *hexChars = "0123456789abcdef", + buf[BUFSIZE]; + unsigned char md5Hash[16], *newHash; + unsigned int *md5Parts, *chlStringParts, newHashParts[5]; + + long long nHigh=0, nLow=0; + + int i, bigEndian; + + /* Determine our endianess */ + bigEndian = isBigEndian(); + + /* Create the MD5 hash by using Gaim MD5 algorithm*/ + cipher = gaim_ciphers_find_cipher("md5"); + context = gaim_cipher_context_new(cipher, NULL); + + gaim_cipher_context_append(context, (const guchar *)input, + strlen(input)); + gaim_cipher_context_append(context, (const guchar *)productKey, + strlen(productKey)); + gaim_cipher_context_digest(context, sizeof(md5Hash), md5Hash, NULL); + gaim_cipher_context_destroy(context); + + /* Split it into four integers */ + md5Parts = (unsigned int *)md5Hash; + for(i=0; i<4; i++){ + /* check for endianess */ + if(bigEndian) + md5Parts[i] = swapInt(md5Parts[i]); + + /* & each integer with 0x7FFFFFFF */ + /* and save one unmodified array for later */ + newHashParts[i] = md5Parts[i]; + md5Parts[i] &= 0x7FFFFFFF; + } + + /* make a new string and pad with '0' */ + snprintf(buf, BUFSIZE-5, "%s%s", input, productID); + i = strlen(buf); + memset(&buf[i], '0', 8 - (i % 8)); + buf[i + (8 - (i % 8))]='\0'; + + /* split into integers */ + chlStringParts = (unsigned int *)buf; + + /* this is magic */ + for (i=0; i<(strlen(buf)/4)-1; i+=2){ + long long temp; + + if(bigEndian){ + chlStringParts[i] = swapInt(chlStringParts[i]); + chlStringParts[i+1] = swapInt(chlStringParts[i+1]); + } + + temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; + nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; + nLow=nLow + nHigh + temp; + } + nHigh=(nHigh+md5Parts[1]) % 0x7FFFFFFF; + nLow=(nLow+md5Parts[3]) % 0x7FFFFFFF; + + newHashParts[0]^=nHigh; + newHashParts[1]^=nLow; + newHashParts[2]^=nHigh; + newHashParts[3]^=nLow; + + /* swap more bytes if big endian */ + for(i=0; i<4 && bigEndian; i++) + newHashParts[i] = swapInt(newHashParts[i]); + + /* make a string of the parts */ + newHash = (unsigned char *)newHashParts; + + /* convert to hexadecimal */ + for (i=0; i<16; i++) + { + output[i*2]=hexChars[(newHash[i]>>4)&0xF]; + output[(i*2)+1]=hexChars[newHash[i]&0xF]; + } + + output[32]='\0'; + +// gaim_debug_info("MaYuan","chl output{%s}\n",output); +} + Modified: branches/soc-2006-msnp13/src/protocols/msn/msn-utils.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/msn-utils.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/msn-utils.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -47,5 +47,9 @@ void msn_import_html(const char *html, char **attributes, char **message); void msn_parse_socket(const char *str, char **ret_host, int *ret_port); +void msn_handle_chl(char *input, char *output); +int isBigEndian(void); +unsigned int swapInt(unsigned int dw); + #endif /* _MSN_UTILS_H_ */ Modified: branches/soc-2006-msnp13/src/protocols/msn/msn.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/msn.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/msn.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -66,6 +66,7 @@ #define WLM_SERVER "muser.messenger.hotmail.com" #define WLM_PORT 1863 #define WLM_PROT_VER 13 +#define WLM_MAX_PROTOCOL 14 #define WLM_MIN_PROTOCOL 13 #define MSN_TYPING_RECV_TIMEOUT 6 Modified: branches/soc-2006-msnp13/src/protocols/msn/nexus.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/nexus.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/nexus.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -37,10 +37,9 @@ nexus = g_new0(MsnNexus, 1); nexus->session = session; - nexus->soapconn = msn_soap_new(session); - nexus->soapconn->parent = nexus; /*we must use SSL connection to do Windows Live ID authentication*/ - nexus->soapconn->ssl_conn = 1; + nexus->soapconn = msn_soap_new(session,nexus,1); + nexus->challenge_data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); Modified: branches/soc-2006-msnp13/src/protocols/msn/notification.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/notification.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/notification.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -102,9 +102,11 @@ account = session->account; /* Allocate an array for CVR0, NULL, and all the versions */ - a = c = g_new0(char *, session->protocol_ver - WLM_MIN_PROTOCOL + 3); +// a = c = g_new0(char *, session->protocol_ver - WLM_MIN_PROTOCOL + 3); + a = c = g_new0(char *, WLM_MAX_PROTOCOL - WLM_MIN_PROTOCOL + 3); - for (i = session->protocol_ver; i >= WLM_MIN_PROTOCOL; i--) +// for (i = session->protocol_ver; i >= WLM_MIN_PROTOCOL; i--) + for (i = WLM_MAX_PROTOCOL; i >= WLM_MIN_PROTOCOL; i--) *c++ = g_strdup_printf("MSNP%d", i); *c++ = g_strdup("CVR0"); @@ -163,24 +165,16 @@ account = session->account; gc = gaim_account_get_connection(account); - if (error == 224) - { - if (group_id == 0) - { + if (error == 224){ + if (group_id == 0){ return; - } - else - { + }else{ const char *group_name; - group_name = - msn_userlist_find_group_name(session->userlist, - group_id); + group_name = msn_userlist_find_group_name(session->userlist,group_id); reason = g_strdup_printf(_("%s is not a valid group."), group_name); } - } - else - { + }else{ reason = g_strdup(_("Unknown error.")); } @@ -214,7 +208,6 @@ GaimAccount *account; account = cmdproc->session->account; - msn_cmdproc_send(cmdproc, "USR", "TWN I %s", gaim_account_get_username(account)); } @@ -303,17 +296,15 @@ g_snprintf(proto_str, sizeof(proto_str), "MSNP%d", session->protocol_ver); - for (i = 1; i < cmd->param_count; i++) - { - if (!strcmp(cmd->params[i], proto_str)) - { + for (i = 1; i < cmd->param_count; i++){ +// gaim_debug_info("MaYuan","%s\,proto_str:%s\n",cmd->params[i],proto_str); + if (!strcmp(cmd->params[i], proto_str)) { protocol_supported = TRUE; break; } } - if (!protocol_supported) - { + if (!protocol_supported){ msn_session_set_error(session, MSN_ERROR_UNSUPPORTED_PROTOCOL, NULL); return; @@ -324,7 +315,8 @@ * Notice :CVR String discriminate! */ msn_cmdproc_send(cmdproc, "CVR", - "0x0409 winnt 5.1 i386 MSG80BETA 8.0.0689 msmsgs %s", +// "0x0409 winnt 5.1 i386 MSG80BETA 8.0.0689 msmsgs %s", + "0x0804 winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs %s", gaim_account_get_username(account)); } @@ -405,18 +397,12 @@ { MsnTransaction *trans; char buf[33]; - const char *challenge_resp; - GaimCipher *cipher; - GaimCipherContext *context; - guchar digest[16]; - int i; +#if 0 cipher = gaim_ciphers_find_cipher("md5"); context = gaim_cipher_context_new(cipher, NULL); - gaim_cipher_context_append(context, (const guchar *)cmd->params[1], strlen(cmd->params[1])); - challenge_resp = MSNP13_WLM_PRODUCT_KEY; gaim_cipher_context_append(context, (const guchar *)challenge_resp, @@ -424,9 +410,13 @@ gaim_cipher_context_digest(context, sizeof(digest), digest, NULL); gaim_cipher_context_destroy(context); - for (i = 0; i < 16; i++) + for (i = 0; i < 16; i++){ g_snprintf(buf + (i*2), 3, "%02x", digest[i]); - + } +#else + msn_handle_chl(cmd->params[1], buf); +#endif + gaim_debug_info("MaYuan","<<challenge:{%s}:{%s}\n",cmd->params[1],buf); trans = msn_transaction_new(cmdproc, "QRY", "%s 32", MSNP13_WLM_PRODUCT_ID); msn_transaction_set_payload(trans, buf, 32); @@ -437,7 +427,103 @@ /************************************************************************** * Buddy Lists **************************************************************************/ +void +dump_adl_cmd(MsnSession *session) +{ + MsnCmdProc *cmdproc; + MsnTransaction *trans; + MsnUserList *userlist; + MsnUser *user; + GList *l; + xmlnode *adl_node,*d_node,*c_node; + char **tokens; + char *email,*domain; + char * payload,*attr; + char *list_op,*type; + int payload_len; + + cmdproc = session->notification->cmdproc; + userlist = session->userlist; + adl_node = xmlnode_new("ml"); + adl_node->child = NULL; + xmlnode_set_attrib(adl_node, "l", "1"); + + /*get the userlist*/ + for (l = userlist->users; l != NULL; l = l->next){ + user = l->data; + + gaim_debug_info("MaYuan","passport:%s\n",user->passport); + tokens = g_strsplit(user->passport, "@", 2); + email = tokens[0]; + domain = tokens[1]; + + /*find a domain node*/ + for(d_node = xmlnode_get_child(adl_node,"d"); d_node; d_node = xmlnode_get_next_twin(d_node)){ + gaim_debug_info("MaYuan","d_node:%s\n",d_node->name); + attr = xmlnode_get_attrib(d_node,"n"); + if(attr == NULL){ + continue; + } + if(!strcmp(attr,domain)){ + break; + } + } + if(d_node == NULL){ + gaim_debug_info("MaYuan","get No d_node\n"); + d_node = xmlnode_new("d"); + xmlnode_set_attrib(d_node,"n",domain); + xmlnode_insert_child(adl_node,d_node); + } + + /*create contact node*/ + c_node = xmlnode_new("c"); + xmlnode_set_attrib(c_node,"n",email); + + list_op = g_strdup_printf("%d",user->list_op); + gaim_debug_info("MaYuan","list_op:%d\n",user->list_op); + xmlnode_set_attrib(c_node,"l",list_op); +#if 1 + type = g_strdup_printf("%d",user->type); + xmlnode_set_attrib(c_node,"t",type); +#else + xmlnode_set_attrib(c_node,"t","1"); +#endif + xmlnode_insert_child(d_node, c_node); + + g_free(list_op); + g_free(type); + } + + payload = xmlnode_to_str(adl_node,payload_len); + + gaim_debug_info("MaYuan","ADL{%s}\n",payload); + trans = msn_transaction_new(cmdproc, "ADL","%d",strlen(payload)); + + msn_transaction_set_payload(trans, payload, strlen(payload)); + + msn_cmdproc_send_trans(cmdproc, trans); +} + static void +adl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) +{ + +} + +static void +rml_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) +{ + MsnTransaction *trans; + char * payload; + + trans = msn_transaction_new(cmdproc, "RML",""); + + msn_transaction_set_payload(trans, payload, strlen(payload)); + + msn_cmdproc_send_trans(cmdproc, trans); +} + +static void add_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) { MsnSession *session; @@ -456,13 +542,12 @@ user = msn_userlist_find_user(session->userlist, passport); - if (user == NULL) - { + if (user == NULL){ user = msn_user_new(session->userlist, passport, friendly); msn_userlist_add_user(session->userlist, user); + }else{ + msn_user_set_friendly_name(user, friendly); } - else - msn_user_set_friendly_name(user, friendly); list_id = msn_get_list_id(list); @@ -554,10 +639,6 @@ g_strfreev(params); } -static void adl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) -{ -} - static void adg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) { @@ -634,8 +715,7 @@ msn_user_set_friendly_name(user, friendly); - if (session->protocol_ver >= 9 && cmd->param_count == 6) - { + if (session->protocol_ver >= 9 && cmd->param_count == 6){ msnobj = msn_object_new_from_string(gaim_url_decode(cmd->params[5])); msn_user_set_object(user, msnobj); } @@ -684,16 +764,12 @@ msn_user_set_friendly_name(user, friendly); - if (session->protocol_ver >= 9) - { - if (cmd->param_count == 5) - { + if (session->protocol_ver >= 9){ + if (cmd->param_count == 5){ msnobj = msn_object_new_from_string(gaim_url_decode(cmd->params[4])); msn_user_set_object(user, msnobj); - } - else - { + }else{ msn_user_set_object(user, NULL); } } @@ -1195,7 +1271,6 @@ /*starting retrieve the contact list*/ session->contact = msn_contact_new(session); msn_contact_connect(session->contact); - } static void @@ -1252,6 +1327,12 @@ } static void +initial_mdata_msg(MsnCmdProc *cmdproc, MsnMessage *msg) +{ + gaim_debug_info("MaYuan","mdata...{%s} \n",msg->body); +} + +static void email_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; @@ -1458,6 +1539,9 @@ "text/x-msmsgsprofile", profile_msg); msn_table_add_msg_type(cbs_table, + "text/x-msmsgsinitialmdatanotification", + initial_mdata_msg); + msn_table_add_msg_type(cbs_table, "text/x-msmsgsinitialemailnotification", initial_email_msg); msn_table_add_msg_type(cbs_table, Modified: branches/soc-2006-msnp13/src/protocols/msn/notification.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/notification.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/notification.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -63,6 +63,7 @@ gboolean msn_notification_connect(MsnNotification *notification, const char *host, int port); void msn_notification_disconnect(MsnNotification *notification); +void dump_adl_cmd(MsnSession *session); /** * Closes a notification. Modified: branches/soc-2006-msnp13/src/protocols/msn/object.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/object.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/object.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -283,8 +283,7 @@ g_return_val_if_fail(sha1c != NULL, NULL); - for (l = local_objs; l != NULL; l = l->next) - { + for (l = local_objs; l != NULL; l = l->next){ MsnObject *local_obj = l->data; if (!strcmp(msn_object_get_sha1c(local_obj), sha1c)) @@ -333,3 +332,4 @@ return NULL; } + Added: branches/soc-2006-msnp13/src/protocols/msn/oim.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/oim.c (rev 0) +++ branches/soc-2006-msnp13/src/protocols/msn/oim.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -0,0 +1,103 @@ +/** + * @file oim.c + * get and send MSN offline Instant Message via SOAP request + * Author + * MaYuan<may...@gm...> + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "msn.h" +#include "soap.h" +#include "oim.h" + +/*new a OIM object*/ +MsnOim * +msn_oim_new(MsnSession *session) +{ + MsnOim *oim; + + oim = g_new0(MsnOim, 1); + oim->session = session; + oim->retrieveconn = msn_soap_new(session,oim,1); + oim->sendconn = msn_soap_new(session,oim,1); + + return oim; +} + +/*destroy the oim object*/ +void +msn_oim_destroy(MsnOim *oim) +{ + msn_soap_destroy(oim->retrieveconn); + msn_soap_destroy(oim->sendconn); + g_free(oim); +} + +/*oim SOAP server login error*/ +static void +msn_oim_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) +{ + MsnSoapConn *soapconn = data; + MsnSession *session; + + session = soapconn->session; + g_return_if_fail(session != NULL); + + msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server")); +} + +/*msn oim SOAP server connect process*/ +static void +msn_oim_login_connect_cb(gpointer data, GaimSslConnection *gsc, + GaimInputCondition cond) +{ + MsnSoapConn *soapconn = data; + MsnSession * session; + MsnOim *oim; + + oim = soapconn->parent; + g_return_if_fail(oim != NULL); + + session = oim->session; + g_return_if_fail(session != NULL); +} + +void msn_oim_send_msg(MsnOim *oim,char * msg) +{ + if(msn_soap_connected(oim->sendconn) == -1){ + msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1, + msn_oim_login_connect_cb, + msn_oim_login_error_cb); + } + +} + +/*msn oim server connect*/ +void +msn_oim_connect(MsnOim *oim) +{ + gaim_debug_info("MaYuan","msn_oim_connect...\n"); + + msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1, + msn_oim_login_connect_cb, + msn_oim_login_error_cb); +} + +/*endof oim.c*/ Property changes on: branches/soc-2006-msnp13/src/protocols/msn/oim.c ___________________________________________________________________ Name: svn:eol-type:native + Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: branches/soc-2006-msnp13/src/protocols/msn/oim.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/oim.h (rev 0) +++ branches/soc-2006-msnp13/src/protocols/msn/oim.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -0,0 +1,103 @@ +/** + * @file oim.h Header file for oim.c + * Author + * MaYuan<may...@gm...> + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _MSN_OIM_H_ +#define _MSN_OIM_H_ + +#define MSN_OIM_RETRIEVE_HOST "rsi.hotmail.com" +#define MSN_OIM_RETRIEVE__URL "/rsi/rsi.asmx" +#define MSN_OIM_GET_SOAP_ACTION "http://www.hotmail.msn.com/ws/2004/09/oim/rsi/GetMessage" +#define MSN_OIM_DEL_SOAP_ACTION "http://www.hotmail.msn.com/ws/2004/09/oim/rsi/DeleteMessages" + +#define MSN_OIM_GET_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\ +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\ + "<soap:Header>"\ + "<PassportCookie xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\ + "<t>%s</t>"\ + "<p>%s</p>"\ + "</PassportCookie>"\ + "</soap:Header>"\ + "<soap:Body>"\ + "<GetMessage xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\ + "<messageId>%s</messageId>"\ + "<alsoMarkAsRead>false</alsoMarkAsRead>"\ + "</GetMessage>"\ + "</soap:Body>"\ +"</soap:Envelope>" + +#define MSN_OIM_DEL_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\ +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\ + "<soap:Header>"\ + "<PassportCookie xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\ + "<t>%s</t>"\ + " <p>%s</p>"\ + "</PassportCookie>"\ + "</soap:Header>"\ + "<soap:Body>"\ + "<DeleteMessages xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\ + "<messageIds>"\ + "<messageId>%s</messageId>"\ + "</messageIds>"\ + "</DeleteMessages>"\ + "</soap:Body>"\ +"</soap:Envelope>" + +#define MSN_OIM_SEND_HOST "ows.messenger.msn.com" +#define MSN_OIM_SEND_URL "/OimWS/oim.asmx" +#define MSN_OIM_SEND_SOAP_ACTION "http://messenger.msn.com/ws/2004/09/oim/Store" +#define MSN_OIM_SEND_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\ +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\ + "<soap:Header>"\ + "<From memberName=\"%s\" friendlyName=\"%s\" xml:lang=\"en-US\" proxy=\"MSNMSGR\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\" msnpVer=\"MSNP13\" buildVer=\"8.0.0689\"/>"\ + "<To memberName=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>"\ + "<Ticket passport=\"%s\" appid=\"%s\" lockkey=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>"\ + "<Sequence xmlns=\"http://schemas.xmlsoap.org/ws/2003/03/rm\">"\ + "<Identifier xmlns=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">http://messenger.msn.com</Identifier>"\ + "<MessageNumber>%s</MessageNumber>"\ + "</Sequence>"\ + "</soap:Header>"\ + "<soap:Body>"\ + "<MessageType xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\">text</MessageType>"\ + "<Content xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\">%s</Content>"\ + "</soap:Body>"\ +"</soap:Envelope>" + +typedef struct _MsnOim MsnOim; + +struct _MsnOim +{ + MsnSession *session; + + MsnSoapConn *retrieveconn; + + MsnSoapConn *sendconn; + gint LockKeyChallenge; +}; + +/*function prototype*/ +MsnOim * msn_oim_new(MsnSession *session); +void msn_oim_destroy(MsnOim *oim); + +#endif/* _MSN_OIM_H_*/ +/*endof oim.h*/ Property changes on: branches/soc-2006-msnp13/src/protocols/msn/oim.h ___________________________________________________________________ Name: svn:eol-type:native + Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: branches/soc-2006-msnp13/src/protocols/msn/session.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/session.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/session.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -252,18 +252,15 @@ remote_user = msn_userlist_find_user(session->userlist, b->name); - if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP)) - { + if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP)){ int group_id; GList *l; group_id = msn_userlist_find_group_id(remote_user->userlist, group_name); - for (l = remote_user->group_ids; l != NULL; l = l->next) - { - if (group_id == GPOINTER_TO_INT(l->data)) - { + for (l = remote_user->group_ids; l != NULL; l = l->next){ + if (group_id == GPOINTER_TO_INT(l->data)){ found = TRUE; break; } @@ -271,8 +268,7 @@ } - if (!found) - { + if (!found){ /* The user was not on the server list or not in that group * on the server list */ msn_show_sync_issue(session, b->name, group_name); @@ -407,3 +403,4 @@ /* Sync users */ msn_session_sync_users(session); } + Modified: branches/soc-2006-msnp13/src/protocols/msn/soap.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/soap.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/soap.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -26,14 +26,19 @@ #include "msn.h" #include "soap.h" +//msn_soap_new(MsnSession *session,gpointer data,int sslconn) /*new a soap connection*/ MsnSoapConn * -msn_soap_new(MsnSession *session) +msn_soap_new(MsnSession *session,gpointer data,int sslconn) { MsnSoapConn *soapconn; soapconn = g_new0(MsnSoapConn, 1); soapconn->session = session; + soapconn->parent = data; + soapconn->ssl_conn = sslconn; + + soapconn->gsc = NULL; soapconn->input_handler = -1; soapconn->output_handler = -1; return soapconn; @@ -118,6 +123,18 @@ g_free(soapconn); } +/*check the soap is connected? + * if connected return 0 + */ +int +msn_soap_connected(MsnSoapConn *soapconn) +{ + if(soapconn->ssl_conn){ + return (soapconn->gsc == NULL? -1 : 0); + } + return(soapconn->fd>0? 0 : -1); +} + /*read and append the content to the buffer*/ static gssize msn_soap_read(MsnSoapConn *soapconn) @@ -154,7 +171,7 @@ char * body_start,*body_len; char *length_start,*length_end; - gaim_debug_misc("MaYuan", "soap read cb\n"); +// gaim_debug_misc("MaYuan", "soap read cb\n"); session = soapconn->session; g_return_if_fail(session != NULL); @@ -207,6 +224,12 @@ g_free(body_len); +#if 1 + /*remove the read handler*/ + gaim_input_remove(soapconn->input_handler); + soapconn->input_handler = -1; +#endif + /*call the read callback*/ if(soapconn->read_cb != NULL){ soapconn->read_cb(soapconn,source,0); @@ -218,8 +241,8 @@ /*remove the read handler*/ gaim_input_remove(soapconn->input_handler); soapconn->input_handler = -1; - gaim_ssl_close(soapconn->gsc); - soapconn->gsc = NULL; +// gaim_ssl_close(soapconn->gsc); +// soapconn->gsc = NULL; #endif } @@ -294,9 +317,50 @@ soapconn->write_buf = write_buf; soapconn->written_len = 0; soapconn->written_cb = written_cb; + + /*clear the read buffer first*/ /*start the write*/ soapconn->output_handler = gaim_input_add(soapconn->gsc->fd, GAIM_INPUT_WRITE, msn_soap_write_cb, soapconn); msn_soap_write_cb(soapconn, soapconn->gsc->fd, GAIM_INPUT_WRITE); } +/*Post the soap action*/ +void +msn_soap_post(MsnSoapConn *soapconn,const char * body,GaimInputFunction written_cb) +{ + char * soap_head = NULL; + char * soap_body = NULL; + char * request_str = NULL; + + gaim_debug_info("MaYuan","msn_get_address_book()...\n"); + soap_body = g_strdup_printf(body); + soap_head = g_strdup_printf( + "POST %s HTTP/1.1\r\n" + "SOAPAction: %s\r\n" + "Content-Type:text/xml; charset=utf-8\r\n" + "Cookie: MSPAuth=%s\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" + "Accept: text/*\r\n" + "Host: %s\r\n" + "Content-Length: %d\r\n" + "Connection: Keep-Alive\r\n" + "Cache-Control: no-cache\r\n\r\n", + soapconn->login_path, + soapconn->soap_action, + soapconn->session->passport_info.mspauth, + soapconn->login_host, + strlen(soap_body) + ); + request_str = g_strdup_printf("%s%s", soap_head,soap_body); + g_free(soapconn->login_path); + g_free(soapconn->soap_action); + g_free(soap_head); + g_free(soap_body); + + /*free read buffer*/ + msn_soap_free_read_buf(soapconn); +// gaim_debug_info("MaYuan","send to contact server{%s}\n",request_str); + msn_soap_write(soapconn,request_str,written_cb); +} + Modified: branches/soc-2006-msnp13/src/protocols/msn/soap.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/soap.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/soap.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -35,6 +35,7 @@ char *login_host; char *login_path; + char *soap_action; /*ssl connection?*/ guint ssl_conn; @@ -69,7 +70,8 @@ /*Function Prototype*/ /*new a soap conneciton */ -MsnSoapConn *msn_soap_new(MsnSession *session); +MsnSoapConn *msn_soap_new(MsnSession *session,gpointer data,int sslconn); + /*destroy */ void msn_soap_destroy(MsnSoapConn *soapconn); @@ -78,10 +80,15 @@ /*write to soap*/ void msn_soap_write(MsnSoapConn * soapconn, char *write_buf, GaimInputFunction written_cb); +void msn_soap_post(MsnSoapConn *soapconn,const char * body,GaimInputFunction written_cb); + void msn_soap_free_read_buf(MsnSoapConn *soapconn); void msn_soap_free_write_buf(MsnSoapConn *soapconn); void msn_soap_connect_cb(gpointer data, GaimSslConnection *gsc, GaimInputCondition cond); void msn_soap_read_cb(gpointer data, gint source, GaimInputCondition cond); +/*check if the soap connection is connected*/ +int msn_soap_connected(MsnSoapConn *soapconn); + #endif/*_MSN_SOAP_H_*/ Modified: branches/soc-2006-msnp13/src/protocols/msn/user.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/user.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/user.c 2006-07-17 12:22:37 UTC (rev 16507) @@ -25,6 +25,7 @@ #include "user.h" #include "slp.h" +/*new a user object*/ MsnUser * msn_user_new(MsnUserList *userlist, const char *passport, const char *store_name) @@ -50,6 +51,7 @@ return user; } +/*destroy a user object*/ void msn_user_destroy(MsnUser *user) { @@ -67,6 +69,7 @@ g_free(user->passport); g_free(user->friendly_name); g_free(user->store_name); + g_free(user->uid); g_free(user->phone.home); g_free(user->phone.work); g_free(user->phone.mobile); @@ -144,6 +147,23 @@ } void +msn_user_set_uid(MsnUser *user, const char *uid) +{ + g_return_if_fail(user != NULL); + + g_free(user->uid); + user->uid = g_strdup(uid); +} + +void +msn_user_set_type(MsnUser *user,int type) +{ + g_return_if_fail(user != NULL); + + user->type = type; +} + +void msn_user_set_buddy_icon(MsnUser *user, const char *filename) { struct stat st; @@ -152,20 +172,16 @@ g_return_if_fail(user != NULL); - if (filename == NULL || g_stat(filename, &st) == -1) - { + if (filename == NULL || g_stat(filename, &st) == -1){ msn_user_set_object(user, NULL); - } - else if ((fp = g_fopen(filename, "rb")) != NULL) - { + }else if ((fp = g_fopen(filename, "rb")) != NULL){ GaimCipherContext *ctx; char *buf; gsize len; char *base64; unsigned char digest[20]; - if (msnobj == NULL) - { + if (msnobj == NULL) { msnobj = msn_object_new(); msn_object_set_local(msnobj); msn_object_set_type(msnobj, MSN_OBJECT_USERTILE); @@ -217,16 +233,15 @@ base64 = gaim_base64_encode(digest, sizeof(digest)); msn_object_set_sha1c(msnobj, base64); g_free(base64); - } - else - { + }else{ gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename); msn_user_set_object(user, NULL); } } +/*add group id to User object*/ void -msn_user_add_group_id(MsnUser *user, int id) +msn_user_add_group_id(MsnUser *user, const char* id) { MsnUserList *userlist; GaimAccount *account; @@ -236,9 +251,9 @@ const char *group_name; g_return_if_fail(user != NULL); - g_return_if_fail(id >= 0); + g_return_if_fail(id != NULL); - user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id)); + user->group_ids = g_list_append(user->group_ids,id); userlist = user->userlist; account = userlist->session->account; @@ -248,16 +263,14 @@ g = gaim_find_group(group_name); - if ((id == 0) && (g == NULL)) - { + if ((id == 0) && (g == NULL)){ g = gaim_group_new(group_name); gaim_blist_add_group(g, NULL); } b = gaim_find_buddy_in_group(account, passport, g); - if (b == NULL) - { + if (b == NULL){ b = gaim_buddy_new(account, passport, NULL); gaim_blist_add_buddy(b, NULL, g, NULL); @@ -267,12 +280,12 @@ } void -msn_user_remove_group_id(MsnUser *user, int id) +msn_user_remove_group_id(MsnUser *user, const char * id) { g_return_if_fail(user != NULL); - g_return_if_fail(id >= 0); + g_return_if_fail(id != NULL); - user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id)); + user->group_ids = g_list_remove(user->group_ids, id); } void Modified: branches/soc-2006-msnp13/src/protocols/msn/user.h =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/user.h 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/user.h 2006-07-17 12:22:37 UTC (rev 16507) @@ -45,6 +45,8 @@ char *store_name; /**< The name stored in the server. */ char *friendly_name; /**< The friendly name. */ + char * uid; /*< User Id */ + const char *status; /**< The state of the user. */ gboolean idle; /**< The idle state of the user. */ @@ -65,6 +67,7 @@ GHashTable *clientcaps; /**< The client's capabilities. */ + int type; int list_op; }; @@ -156,7 +159,7 @@ * @param user The user. * @param id The group ID. */ -void msn_user_add_group_id(MsnUser *user, int id); +void msn_user_add_group_id(MsnUser *user, const char * id); /** * Removes the group ID from a user. @@ -164,7 +167,7 @@ * @param user The user. * @param id The group ID. */ -void msn_user_remove_group_id(MsnUser *user, int id); +void msn_user_remove_group_id(MsnUser *user, const char * id); /** * Sets the home phone number for a user. @@ -182,6 +185,9 @@ */ void msn_user_set_work_phone(MsnUser *user, const char *number); +void msn_user_set_uid(MsnUser *user, const char *uid); +void msn_user_set_type(MsnUser *user,int type); + /** * Sets the mobile phone number for a user. * Modified: branches/soc-2006-msnp13/src/protocols/msn/userlist.c =================================================================== --- branches/soc-2006-msnp13/src/protocols/msn/userlist.c 2006-07-17 06:22:09 UTC (rev 16506) +++ branches/soc-2006-msnp13/src/protocols/msn/userlist.c ... [truncated message content] |
From: <the...@us...> - 2006-07-17 06:22:12
|
Revision: 16506 Author: thekingant Date: 2006-07-16 23:22:09 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16506&view=rev Log Message: ----------- Backport SVN revision #16505 from HEAD to v2_0_0 Original commit message: Change the music messaging plugin to not try to load if our D-BUS stuff is not initialized. Also extracted the gaim_notify_error() message code to a #define in src/dbus-server.c And print a debug warning if something tries to register a callback for a signal using a handle that we don't have any registered signals for ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16505&view=rev Modified Paths: -------------- branches/v2_0_0/plugins/dbus-example.c branches/v2_0_0/plugins/musicmessaging/musicmessaging.c branches/v2_0_0/src/dbus-server.h branches/v2_0_0/src/signals.c Modified: branches/v2_0_0/plugins/dbus-example.c =================================================================== --- branches/v2_0_0/plugins/dbus-example.c 2006-07-17 06:21:53 UTC (rev 16505) +++ branches/v2_0_0/plugins/dbus-example.c 2006-07-17 06:22:09 UTC (rev 16506) @@ -109,17 +109,8 @@ static gboolean plugin_load(GaimPlugin *plugin) { - const char *dbus_init_error; + GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); - dbus_init_error = gaim_dbus_get_init_error(); - if (dbus_init_error != NULL) - { - gaim_notify_error(NULL, _("Unable to Load Plugin"), - _("Gaim's D-BUS server is not running for the reason listed below"), - _(dbus_init_error)); - return FALSE; - } - /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: branches/v2_0_0/plugins/musicmessaging/musicmessaging.c =================================================================== --- branches/v2_0_0/plugins/musicmessaging/musicmessaging.c 2006-07-17 06:21:53 UTC (rev 16505) +++ branches/v2_0_0/plugins/musicmessaging/musicmessaging.c 2006-07-17 06:22:09 UTC (rev 16506) @@ -259,6 +259,8 @@ plugin_load(GaimPlugin *plugin) { void *conv_list_handle; + GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); + /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: branches/v2_0_0/src/dbus-server.h =================================================================== --- branches/v2_0_0/src/dbus-server.h 2006-07-17 06:21:53 UTC (rev 16505) +++ branches/v2_0_0/src/dbus-server.h 2006-07-17 06:22:09 UTC (rev 16506) @@ -74,6 +74,17 @@ #define GAIM_DBUS_DEFINE_INHERITING_TYPE(type, parent) \ GaimDBusType GAIM_DBUS_TYPE_##type = { GAIM_DBUS_TYPE(parent) }; +#define GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin) \ + if (gaim_dbus_get_init_error() != NULL) \ + { \ + gchar *title; \ + title = g_strdup_printf("Unable to Load %s Plugin", plugin->info->name); \ + gaim_notify_error(NULL, title, \ + _("Gaim's D-BUS server is not running for the reason listed below"), \ + _(gaim_dbus_get_init_error())); \ + g_free(title); \ + return FALSE; \ + } /** Initializes gaim dbus pointer registration engine. @@ -139,8 +150,9 @@ * NOT running then gaim_dbus_dispatch_init() failed for some reason, * and a message should have been gaim_debug_error()'ed. * - * This function should be called by any DBUS plugin before trying - * to use the DBUS API. See plugins/dbus-example.c for usage. + * Gaim plugins that use D-BUS should use the + * GAIM_DBUS_RETURN_FALSE_IF_DISABLED macro to short-circuit + * initialization if Gaim's D-BUS subsystem is not running. * * @return If the D-BUS subsystem started with no problems then this * will return NULL and everything will be hunky dory. If Modified: branches/v2_0_0/src/signals.c =================================================================== --- branches/v2_0_0/src/signals.c 2006-07-17 06:21:53 UTC (rev 16505) +++ branches/v2_0_0/src/signals.c 2006-07-17 06:22:09 UTC (rev 16506) @@ -267,7 +267,13 @@ instance_data = (GaimInstanceData *)g_hash_table_lookup(instance_table, instance); - g_return_val_if_fail(instance_data != NULL, 0); + if (instance_data == NULL) + { + gaim_debug_warning("signals", "Something tried to register a callback " + "for the '%s' signal, but we do not have any signals " + "registered with the given handle\n", signal); + g_return_val_if_reached(0); + } /* Get the signal data */ signal_data = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-17 06:21:55
|
Revision: 16505 Author: thekingant Date: 2006-07-16 23:21:53 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16505&view=rev Log Message: ----------- Change the music messaging plugin to not try to load if our D-BUS stuff is not initialized. Also extracted the gaim_notify_error() message code to a #define in src/dbus-server.c And print a debug warning if something tries to register a callback for a signal using a handle that we don't have any registered signals for Modified Paths: -------------- trunk/plugins/dbus-example.c trunk/plugins/musicmessaging/musicmessaging.c trunk/src/dbus-server.h trunk/src/signals.c Modified: trunk/plugins/dbus-example.c =================================================================== --- trunk/plugins/dbus-example.c 2006-07-17 05:50:49 UTC (rev 16504) +++ trunk/plugins/dbus-example.c 2006-07-17 06:21:53 UTC (rev 16505) @@ -109,17 +109,8 @@ static gboolean plugin_load(GaimPlugin *plugin) { - const char *dbus_init_error; + GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); - dbus_init_error = gaim_dbus_get_init_error(); - if (dbus_init_error != NULL) - { - gaim_notify_error(NULL, _("Unable to Load Plugin"), - _("Gaim's D-BUS server is not running for the reason listed below"), - _(dbus_init_error)); - return FALSE; - } - /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: trunk/plugins/musicmessaging/musicmessaging.c =================================================================== --- trunk/plugins/musicmessaging/musicmessaging.c 2006-07-17 05:50:49 UTC (rev 16504) +++ trunk/plugins/musicmessaging/musicmessaging.c 2006-07-17 06:21:53 UTC (rev 16505) @@ -259,6 +259,8 @@ plugin_load(GaimPlugin *plugin) { void *conv_list_handle; + GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); + /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: trunk/src/dbus-server.h =================================================================== --- trunk/src/dbus-server.h 2006-07-17 05:50:49 UTC (rev 16504) +++ trunk/src/dbus-server.h 2006-07-17 06:21:53 UTC (rev 16505) @@ -74,6 +74,17 @@ #define GAIM_DBUS_DEFINE_INHERITING_TYPE(type, parent) \ GaimDBusType GAIM_DBUS_TYPE_##type = { GAIM_DBUS_TYPE(parent) }; +#define GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin) \ + if (gaim_dbus_get_init_error() != NULL) \ + { \ + gchar *title; \ + title = g_strdup_printf("Unable to Load %s Plugin", plugin->info->name); \ + gaim_notify_error(NULL, title, \ + _("Gaim's D-BUS server is not running for the reason listed below"), \ + _(gaim_dbus_get_init_error())); \ + g_free(title); \ + return FALSE; \ + } /** Initializes gaim dbus pointer registration engine. @@ -139,8 +150,9 @@ * NOT running then gaim_dbus_dispatch_init() failed for some reason, * and a message should have been gaim_debug_error()'ed. * - * This function should be called by any DBUS plugin before trying - * to use the DBUS API. See plugins/dbus-example.c for usage. + * Gaim plugins that use D-BUS should use the + * GAIM_DBUS_RETURN_FALSE_IF_DISABLED macro to short-circuit + * initialization if Gaim's D-BUS subsystem is not running. * * @return If the D-BUS subsystem started with no problems then this * will return NULL and everything will be hunky dory. If Modified: trunk/src/signals.c =================================================================== --- trunk/src/signals.c 2006-07-17 05:50:49 UTC (rev 16504) +++ trunk/src/signals.c 2006-07-17 06:21:53 UTC (rev 16505) @@ -267,7 +267,13 @@ instance_data = (GaimInstanceData *)g_hash_table_lookup(instance_table, instance); - g_return_val_if_fail(instance_data != NULL, 0); + if (instance_data == NULL) + { + gaim_debug_warning("signals", "Something tried to register a callback " + "for the '%s' signal, but we do not have any signals " + "registered with the given handle\n", signal); + g_return_val_if_reached(0); + } /* Get the signal data */ signal_data = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-17 05:50:54
|
Revision: 16504 Author: thekingant Date: 2006-07-16 22:50:49 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16504&view=rev Log Message: ----------- Backport SVN revision #16503 from HEAD to v2_0_0 Original commit message: Get rid of an assertion failure when trying to load our D-BUS example plugin if the D-BUS subsystem is not initialized for whatever reason. Not only that, the plugin gracefully fails to load and prints an error message. These error messages could be improved. If you're familiar with how D-BUS works then go for it. Also, do we need to be uninitializing any of the D-BUS stuff? ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16503&view=rev Modified Paths: -------------- branches/v2_0_0/plugins/dbus-example.c branches/v2_0_0/src/core.c branches/v2_0_0/src/dbus-server.c branches/v2_0_0/src/dbus-server.h branches/v2_0_0/src/plugin.c Modified: branches/v2_0_0/plugins/dbus-example.c =================================================================== --- branches/v2_0_0/plugins/dbus-example.c 2006-07-17 05:50:28 UTC (rev 16503) +++ branches/v2_0_0/plugins/dbus-example.c 2006-07-17 05:50:49 UTC (rev 16504) @@ -37,8 +37,9 @@ #include "internal.h" +#include "blist.h" +#include "notify.h" #include "plugin.h" -#include "blist.h" #include "version.h" #include <stdio.h> @@ -108,6 +109,17 @@ static gboolean plugin_load(GaimPlugin *plugin) { + const char *dbus_init_error; + + dbus_init_error = gaim_dbus_get_init_error(); + if (dbus_init_error != NULL) + { + gaim_notify_error(NULL, _("Unable to Load Plugin"), + _("Gaim's D-BUS server is not running for the reason listed below"), + _(dbus_init_error)); + return FALSE; + } + /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: branches/v2_0_0/src/core.c =================================================================== --- branches/v2_0_0/src/core.c 2006-07-17 05:50:28 UTC (rev 16503) +++ branches/v2_0_0/src/core.c 2006-07-17 05:50:49 UTC (rev 16504) @@ -99,7 +99,6 @@ gaim_dbus_init(); #endif - /* Initialize all static protocols. */ static_proto_init(); @@ -193,6 +192,10 @@ gaim_plugins_uninit(); gaim_signals_uninit(); +#ifdef HAVE_DBUS + gaim_dbus_uninit(); +#endif + if (core->ui != NULL) { g_free(core->ui); core->ui = NULL; Modified: branches/v2_0_0/src/dbus-server.c =================================================================== --- branches/v2_0_0/src/dbus-server.c 2006-07-17 05:50:28 UTC (rev 16503) +++ branches/v2_0_0/src/dbus-server.c 2006-07-17 05:50:49 UTC (rev 16504) @@ -36,6 +36,7 @@ #include "dbus-bindings.h" #include "debug.h" #include "core.h" +#include "internal.h" #include "savedstatuses.h" #include "value.h" @@ -59,7 +60,9 @@ static GHashTable *map_id_node; static GHashTable *map_id_type; +static gchar *init_error; + /* This function initializes the pointer-id traslation system. It creates the three above hashtables and defines parents of some types. */ @@ -229,7 +232,7 @@ DBusMessageIter *sub; sub = va_arg (var_args, DBusMessageIter*); dbus_message_iter_recurse(iter, sub); - g_print("subiter %i:%i\n", (int) sub, * (int*) sub); + gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); break; /* for testing only! */ } @@ -383,12 +386,6 @@ #include "dbus-bindings.c" -void *gaim_dbus_get_handle(void) { - static int handle; - - return &handle; -} - static gboolean gaim_dbus_dispatch_cb(DBusConnection *connection, DBusMessage *message, @@ -437,7 +434,7 @@ } -static const char *gettext(const char **ptr) { +static const char *dbus_gettext(const char **ptr) { const char *text = *ptr; *ptr += strlen(text) + 1; return text; @@ -478,9 +475,9 @@ while (*text) { const char *name, *direction, *type; - direction = gettext(&text); - type = gettext(&text); - name = gettext(&text); + direction = dbus_gettext(&text); + type = dbus_gettext(&text); + name = dbus_gettext(&text); g_string_append_printf(str, "<arg name='%s' type='%s' direction='%s'/>\n", @@ -539,7 +536,7 @@ -static gboolean gaim_dbus_dispatch_init(void) +static void gaim_dbus_dispatch_init(void) { static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; @@ -550,17 +547,17 @@ gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (gaim_dbus_connection == NULL) { - gaim_debug_error("dbus", "Failed to get connection\n"); + init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); dbus_error_free(&error); - return FALSE; + return; } if (!dbus_connection_register_object_path (gaim_dbus_connection, DBUS_PATH_GAIM, &vtable, NULL)) { - gaim_debug_error("dbus", "Failed to get name: %s\n", error.name); + init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); dbus_error_free(&error); - return FALSE; + return; } @@ -571,8 +568,8 @@ dbus_connection_unref(gaim_dbus_connection); dbus_error_free(&error); gaim_dbus_connection = NULL; - gaim_debug_error("dbus", "Failed to get serv name: %s\n", error.name); - return FALSE; + init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); + return; } dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); @@ -590,8 +587,6 @@ gaim_value_new_outgoing(GAIM_TYPE_POINTER)); GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); - - return TRUE; } @@ -709,15 +704,37 @@ dbus_message_unref(signal); } +const char * +gaim_dbus_get_init_error(void) +{ + return init_error; +} +void * +gaim_dbus_get_handle(void) +{ + static int handle; + return &handle; +} - - -gboolean gaim_dbus_init(void) +void +gaim_dbus_init(void) { gaim_dbus_init_ids(); - return gaim_dbus_dispatch_init() ; + + g_free(init_error); + init_error = NULL; + gaim_dbus_dispatch_init(); + if (init_error != NULL) + gaim_debug_error("dbus", "%s\n", init_error); } +void +gaim_dbus_uninit(void) +{ + /* Surely we must do SOME kind of uninitialization? */ + g_free(init_error); + init_error = NULL; +} Modified: branches/v2_0_0/src/dbus-server.h =================================================================== --- branches/v2_0_0/src/dbus-server.h 2006-07-17 05:50:28 UTC (rev 16503) +++ branches/v2_0_0/src/dbus-server.h 2006-07-17 05:50:49 UTC (rev 16504) @@ -135,14 +135,20 @@ GaimValue **values, va_list vargs); /** - * Starts the gaim DBUS server. It is responsible for handling DBUS - * requests from other applications. + * Returns whether Gaim's D-BUS subsystem is up and running. If it's + * NOT running then gaim_dbus_dispatch_init() failed for some reason, + * and a message should have been gaim_debug_error()'ed. * - * @return TRUE if successful, FALSE otherwise. + * This function should be called by any DBUS plugin before trying + * to use the DBUS API. See plugins/dbus-example.c for usage. + * + * @return If the D-BUS subsystem started with no problems then this + * will return NULL and everything will be hunky dory. If + * there was an error initializing the D-BUS subsystem then + * this will return an error message explaining why. */ -gboolean gaim_dbus_init(void); +const char *gaim_dbus_get_init_error(void); - /** * Returns the dbus subsystem handle. * @@ -151,7 +157,18 @@ void *gaim_dbus_get_handle(void); /** + * Starts Gaim's D-BUS server. It is responsible for handling DBUS + * requests from other applications. + */ +void gaim_dbus_init(void); +/** + * Uninitializes Gaim's D-BUS server. + */ +void gaim_dbus_uninit(void); + +/** + Macro #DBUS_EXPORT expands to nothing. It is used to indicate to the dbus-analize-functions.py script that the given function should be available to other applications through DBUS. If Modified: branches/v2_0_0/src/plugin.c =================================================================== --- branches/v2_0_0/src/plugin.c 2006-07-17 05:50:28 UTC (rev 16503) +++ branches/v2_0_0/src/plugin.c 2006-07-17 05:50:49 UTC (rev 16504) @@ -843,8 +843,8 @@ } } - if (plugin->path != NULL) g_free(plugin->path); - if (plugin->error != NULL) g_free(plugin->error); + g_free(plugin->path); + g_free(plugin->error); GAIM_DBUS_UNREGISTER_POINTER(plugin); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-17 05:50:31
|
Revision: 16503 Author: thekingant Date: 2006-07-16 22:50:28 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16503&view=rev Log Message: ----------- Get rid of an assertion failure when trying to load our D-BUS example plugin if the D-BUS subsystem is not initialized for whatever reason. Not only that, the plugin gracefully fails to load and prints an error message. These error messages could be improved. If you're familiar with how D-BUS works then go for it. Also, do we need to be uninitializing any of the D-BUS stuff? Modified Paths: -------------- trunk/plugins/dbus-example.c trunk/src/core.c trunk/src/dbus-server.c trunk/src/dbus-server.h Modified: trunk/plugins/dbus-example.c =================================================================== --- trunk/plugins/dbus-example.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/plugins/dbus-example.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -37,8 +37,9 @@ #include "internal.h" +#include "blist.h" +#include "notify.h" #include "plugin.h" -#include "blist.h" #include "version.h" #include <stdio.h> @@ -108,6 +109,17 @@ static gboolean plugin_load(GaimPlugin *plugin) { + const char *dbus_init_error; + + dbus_init_error = gaim_dbus_get_init_error(); + if (dbus_init_error != NULL) + { + gaim_notify_error(NULL, _("Unable to Load Plugin"), + _("Gaim's D-BUS server is not running for the reason listed below"), + _(dbus_init_error)); + return FALSE; + } + /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ Modified: trunk/src/core.c =================================================================== --- trunk/src/core.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/core.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -99,7 +99,6 @@ gaim_dbus_init(); #endif - /* Initialize all static protocols. */ static_proto_init(); @@ -193,6 +192,10 @@ gaim_plugins_uninit(); gaim_signals_uninit(); +#ifdef HAVE_DBUS + gaim_dbus_uninit(); +#endif + if (core->ui != NULL) { g_free(core->ui); core->ui = NULL; Modified: trunk/src/dbus-server.c =================================================================== --- trunk/src/dbus-server.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/dbus-server.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -36,6 +36,7 @@ #include "dbus-bindings.h" #include "debug.h" #include "core.h" +#include "internal.h" #include "savedstatuses.h" #include "value.h" @@ -59,7 +60,9 @@ static GHashTable *map_id_node; static GHashTable *map_id_type; +static gchar *init_error; + /* This function initializes the pointer-id traslation system. It creates the three above hashtables and defines parents of some types. */ @@ -229,7 +232,7 @@ DBusMessageIter *sub; sub = va_arg (var_args, DBusMessageIter*); dbus_message_iter_recurse(iter, sub); - g_print("subiter %i:%i\n", (int) sub, * (int*) sub); + gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); break; /* for testing only! */ } @@ -383,12 +386,6 @@ #include "dbus-bindings.c" -void *gaim_dbus_get_handle(void) { - static int handle; - - return &handle; -} - static gboolean gaim_dbus_dispatch_cb(DBusConnection *connection, DBusMessage *message, @@ -437,7 +434,7 @@ } -static const char *gettext(const char **ptr) { +static const char *dbus_gettext(const char **ptr) { const char *text = *ptr; *ptr += strlen(text) + 1; return text; @@ -478,9 +475,9 @@ while (*text) { const char *name, *direction, *type; - direction = gettext(&text); - type = gettext(&text); - name = gettext(&text); + direction = dbus_gettext(&text); + type = dbus_gettext(&text); + name = dbus_gettext(&text); g_string_append_printf(str, "<arg name='%s' type='%s' direction='%s'/>\n", @@ -539,7 +536,7 @@ -static gboolean gaim_dbus_dispatch_init(void) +static void gaim_dbus_dispatch_init(void) { static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; @@ -550,17 +547,17 @@ gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (gaim_dbus_connection == NULL) { - gaim_debug_error("dbus", "Failed to get connection\n"); + init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); dbus_error_free(&error); - return FALSE; + return; } if (!dbus_connection_register_object_path (gaim_dbus_connection, DBUS_PATH_GAIM, &vtable, NULL)) { - gaim_debug_error("dbus", "Failed to get name: %s\n", error.name); + init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); dbus_error_free(&error); - return FALSE; + return; } @@ -571,8 +568,8 @@ dbus_connection_unref(gaim_dbus_connection); dbus_error_free(&error); gaim_dbus_connection = NULL; - gaim_debug_error("dbus", "Failed to get serv name: %s\n", error.name); - return FALSE; + init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); + return; } dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); @@ -590,8 +587,6 @@ gaim_value_new_outgoing(GAIM_TYPE_POINTER)); GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); - - return TRUE; } @@ -709,15 +704,37 @@ dbus_message_unref(signal); } +const char * +gaim_dbus_get_init_error(void) +{ + return init_error; +} +void * +gaim_dbus_get_handle(void) +{ + static int handle; + return &handle; +} - - -gboolean gaim_dbus_init(void) +void +gaim_dbus_init(void) { gaim_dbus_init_ids(); - return gaim_dbus_dispatch_init() ; + + g_free(init_error); + init_error = NULL; + gaim_dbus_dispatch_init(); + if (init_error != NULL) + gaim_debug_error("dbus", "%s\n", init_error); } +void +gaim_dbus_uninit(void) +{ + /* Surely we must do SOME kind of uninitialization? */ + g_free(init_error); + init_error = NULL; +} Modified: trunk/src/dbus-server.h =================================================================== --- trunk/src/dbus-server.h 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/dbus-server.h 2006-07-17 05:50:28 UTC (rev 16503) @@ -135,14 +135,20 @@ GaimValue **values, va_list vargs); /** - * Starts the gaim DBUS server. It is responsible for handling DBUS - * requests from other applications. + * Returns whether Gaim's D-BUS subsystem is up and running. If it's + * NOT running then gaim_dbus_dispatch_init() failed for some reason, + * and a message should have been gaim_debug_error()'ed. * - * @return TRUE if successful, FALSE otherwise. + * This function should be called by any DBUS plugin before trying + * to use the DBUS API. See plugins/dbus-example.c for usage. + * + * @return If the D-BUS subsystem started with no problems then this + * will return NULL and everything will be hunky dory. If + * there was an error initializing the D-BUS subsystem then + * this will return an error message explaining why. */ -gboolean gaim_dbus_init(void); +const char *gaim_dbus_get_init_error(void); - /** * Returns the dbus subsystem handle. * @@ -151,7 +157,18 @@ void *gaim_dbus_get_handle(void); /** + * Starts Gaim's D-BUS server. It is responsible for handling DBUS + * requests from other applications. + */ +void gaim_dbus_init(void); +/** + * Uninitializes Gaim's D-BUS server. + */ +void gaim_dbus_uninit(void); + +/** + Macro #DBUS_EXPORT expands to nothing. It is used to indicate to the dbus-analize-functions.py script that the given function should be available to other applications through DBUS. If This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-17 04:33:36
|
Revision: 16502 Author: thekingant Date: 2006-07-16 21:33:32 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16502&view=rev Log Message: ----------- Extremely minor memleak fix in the tcl loader plugin Modified Paths: -------------- trunk/plugins/tcl/tcl.c trunk/src/plugin.c Modified: trunk/plugins/tcl/tcl.c =================================================================== --- trunk/plugins/tcl/tcl.c 2006-07-17 04:30:50 UTC (rev 16501) +++ trunk/plugins/tcl/tcl.c 2006-07-17 04:33:32 UTC (rev 16502) @@ -380,10 +380,12 @@ gaim_stringref_unref(GaimTclRefConnection); gaim_stringref_unref(GaimTclRefConversation); gaim_stringref_unref(GaimTclRefPointer); + gaim_stringref_unref(GaimTclRefPlugin); gaim_stringref_unref(GaimTclRefPresence); gaim_stringref_unref(GaimTclRefStatus); gaim_stringref_unref(GaimTclRefStatusAttr); gaim_stringref_unref(GaimTclRefStatusType); + gaim_stringref_unref(GaimTclRefXfer); return TRUE; } Modified: trunk/src/plugin.c =================================================================== --- trunk/src/plugin.c 2006-07-17 04:30:50 UTC (rev 16501) +++ trunk/src/plugin.c 2006-07-17 04:33:32 UTC (rev 16502) @@ -843,8 +843,8 @@ } } - if (plugin->path != NULL) g_free(plugin->path); - if (plugin->error != NULL) g_free(plugin->error); + g_free(plugin->path); + g_free(plugin->error); GAIM_DBUS_UNREGISTER_POINTER(plugin); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 04:30:58
|
Revision: 16501 Author: sadrul Date: 2006-07-16 21:30:50 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16501&view=rev Log Message: ----------- Minor adjustments to the packing of child widgets in a box. Modified Paths: -------------- trunk/console/gntnotify.c trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntbox.h trunk/console/libgnt/test/focus.c trunk/console/libgnt/test/tv.c Modified: trunk/console/gntnotify.c =================================================================== --- trunk/console/gntnotify.c 2006-07-17 03:45:24 UTC (rev 16500) +++ trunk/console/gntnotify.c 2006-07-17 04:30:50 UTC (rev 16501) @@ -29,6 +29,8 @@ window = gnt_box_new(FALSE, TRUE); gnt_box_set_toplevel(GNT_BOX(window), TRUE); gnt_box_set_title(GNT_BOX(window), title); + gnt_box_set_fill(GNT_BOX(window), FALSE); + gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); if (primary) gnt_box_add_widget(GNT_BOX(window), Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-07-17 03:45:24 UTC (rev 16500) +++ trunk/console/libgnt/gntbox.c 2006-07-17 04:30:50 UTC (rev 16501) @@ -173,31 +173,30 @@ if (maxw < w) maxw = w; } - - if (box->homogeneous) + + for (iter = box->list; iter; iter = iter->next) { - for (iter = box->list; iter; iter = iter->next) + int w, h; + GntWidget *wid = GNT_WIDGET(iter->data); + + gnt_widget_get_size(wid, &w, &h); + + if (box->homogeneous) { - gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, maxh); + if (box->vertical) + h = maxh; + else + w = maxw; } - } - else - { - for (iter = box->list; iter; iter = iter->next) + if (box->fill) { if (box->vertical) - { - int h; - gnt_widget_get_size(GNT_WIDGET(iter->data), NULL, &h); - gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, h); - } + w = maxw; else - { - int w; - gnt_widget_get_size(GNT_WIDGET(iter->data), &w, NULL); - gnt_widget_set_size(GNT_WIDGET(iter->data), w, maxh); - } + h = maxh; } + + gnt_widget_set_size(wid, w, h); } reposition_children(widget); @@ -495,6 +494,7 @@ box->homogeneous = homo; box->vertical = vert; box->pad = 1; + box->fill = TRUE; gnt_widget_set_take_focus(widget, TRUE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); if (vert) @@ -669,3 +669,8 @@ } } +void gnt_box_set_fill(GntBox *box, gboolean fill) +{ + box->fill = fill; +} + Modified: trunk/console/libgnt/gntbox.h =================================================================== --- trunk/console/libgnt/gntbox.h 2006-07-17 03:45:24 UTC (rev 16500) +++ trunk/console/libgnt/gntbox.h 2006-07-17 04:30:50 UTC (rev 16501) @@ -33,6 +33,7 @@ gboolean vertical; gboolean homogeneous; + gboolean fill; GList *list; /* List of widgets */ GntWidget *active; @@ -85,6 +86,8 @@ void gnt_box_readjust(GntBox *box); +void gnt_box_set_fill(GntBox *box, gboolean fill); + G_END_DECLS #endif /* GNT_BOX_H */ Modified: trunk/console/libgnt/test/focus.c =================================================================== --- trunk/console/libgnt/test/focus.c 2006-07-17 03:45:24 UTC (rev 16500) +++ trunk/console/libgnt/test/focus.c 2006-07-17 04:30:50 UTC (rev 16501) @@ -32,6 +32,7 @@ vbox = gnt_box_new(FALSE, FALSE); hbox = gnt_box_new(FALSE, TRUE); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); gnt_widget_set_name(vbox, "vbox"); gnt_widget_set_name(hbox, "hbox"); Modified: trunk/console/libgnt/test/tv.c =================================================================== --- trunk/console/libgnt/test/tv.c 2006-07-17 03:45:24 UTC (rev 16500) +++ trunk/console/libgnt/test/tv.c 2006-07-17 04:30:50 UTC (rev 16501) @@ -45,7 +45,9 @@ hbox = gnt_box_new(FALSE, TRUE); gnt_widget_set_name(hbox, "hbox"); gnt_box_set_toplevel(GNT_BOX(hbox), TRUE); + gnt_box_set_fill(GNT_BOX(hbox), FALSE); gnt_box_set_title(GNT_BOX(hbox), "Textview test"); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); entry = gnt_entry_new(NULL); gnt_widget_set_name(entry, "entry"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-07-17 03:45:41
|
Revision: 16500 Author: sadrul Date: 2006-07-16 20:45:24 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16500&view=rev Log Message: ----------- uiops for GaimConnections. This only shows an error message for a disconnect. uiops for GaimNotify. I have not done the notifications for searchresults yet. That will require multi-column GntTree's, which will also allow for improved email-notifications. I hope to complete it by next week. Modified Paths: -------------- trunk/console/Makefile trunk/console/gntblist.c trunk/console/gntgaim.h trunk/console/gntui.c trunk/console/libgnt/gntlabel.c trunk/console/libgnt/gntlabel.h trunk/console/libgnt/gntmain.c trunk/console/libgnt/gnttextview.c trunk/console/libgnt/gnttextview.h trunk/console/libgnt/gnttree.c trunk/console/libgnt/gnttree.h trunk/console/libgnt/test/multiwin.c trunk/console/libgnt/test/tv.c Added Paths: ----------- trunk/console/gntconn.c trunk/console/gntconn.h trunk/console/gntnotify.c trunk/console/gntnotify.h Modified: trunk/console/Makefile =================================================================== --- trunk/console/Makefile 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/Makefile 2006-07-17 03:45:24 UTC (rev 16500) @@ -6,19 +6,25 @@ GG_SOURCES = \ gntaccount.c \ gntblist.c \ + gntconn.c \ gntconv.c \ + gntnotify.c \ gntui.c GG_HEADERS = \ gntaccount.h \ gntblist.h \ + gntconn.h \ gntconv.h \ + gntnotify.h \ gntui.h GG_OBJECTS = \ gntaccount.o \ gntblist.o \ + gntconn.o \ gntconv.o \ + gntnotify.o \ gntui.o all: gntgaim @@ -29,6 +35,7 @@ gntblist.o: gntblist.c $(GG_HEADERS) gntconv.o: gntconv.c $(GG_HEADERS) gntgaim.o: gntgaim.c gntgaim.h $(GG_HEADERS) +gntnotify.o: gntnotify.c $(GG_HEADERS) gntui.o: gntui.c $(GG_HEADERS) clean: Modified: trunk/console/gntblist.c =================================================================== --- trunk/console/gntblist.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/gntblist.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -288,7 +288,9 @@ GaimBuddy *buddy = (GaimBuddy *)node; account = gaim_buddy_get_account(buddy); - g_string_append_printf(str, _("Account: %s"), gaim_account_get_username(account)); + g_string_append_printf(str, _("Account: %s (%s)"), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); @@ -323,7 +325,9 @@ GaimChat *chat = (GaimChat *)node; GaimAccount *account = chat->account; - g_string_append_printf(str, _("Account: %s"), gaim_account_get_username(account)); + g_string_append_printf(str, _("Account: %s (%s)"), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); title = g_strdup(gaim_chat_get_name(chat)); } Added: trunk/console/gntconn.c =================================================================== --- trunk/console/gntconn.c (rev 0) +++ trunk/console/gntconn.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -0,0 +1,45 @@ +#include "notify.h" + +#include "gntconn.h" +#include "gntgaim.h" + +static void +gg_connection_report_disconnect(GaimConnection *gc, const char *text) +{ + char *act, *primary, *secondary; + GaimAccount *account = gaim_connection_get_account(gc); + + act = g_strdup_printf(_("%s (%s)"), gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); + + primary = g_strdup_printf(_("%s disconnected."), act); + secondary = g_strdup_printf(_("%s was disconnected due to the following error:\n%s"), + act, text); + + gaim_notify_error(account, _("Connection Error"), primary, secondary); + + g_free(act); + g_free(primary); + g_free(secondary); +} + +static GaimConnectionUiOps ops = +{ + .connect_progress = NULL, + .connected = NULL, + .disconnected = NULL, + .notice = NULL, + .report_disconnect = gg_connection_report_disconnect +}; + +GaimConnectionUiOps *gg_connections_get_ui_ops() +{ + return &ops; +} + +void gg_connections_init() +{} + +void gg_connections_uninit() +{} + Property changes on: trunk/console/gntconn.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/gntconn.h =================================================================== --- trunk/console/gntconn.h (rev 0) +++ trunk/console/gntconn.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -0,0 +1,8 @@ +#include "connection.h" + +GaimConnectionUiOps *gg_connections_get_ui_ops(); + +void gg_connections_init(); + +void gg_connections_uninit(); + Property changes on: trunk/console/gntconn.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/console/gntgaim.h =================================================================== --- trunk/console/gntgaim.h 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/gntgaim.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -1,4 +1,5 @@ #include <glib.h> +#include <libintl.h> #define GAIM_GNT_UI "gnt-gaim" Added: trunk/console/gntnotify.c =================================================================== --- trunk/console/gntnotify.c (rev 0) +++ trunk/console/gntnotify.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -0,0 +1,160 @@ +#include <gnt.h> +#include <gntbox.h> +#include <gntbutton.h> +#include <gntlabel.h> + +#include <util.h> + +#include "gntnotify.h" +#include "gntgaim.h" + +static void * +gg_notify_message(GaimNotifyMsgType type, const char *title, + const char *primary, const char *secondary) +{ + GntWidget *window, *button; + GntTextFormatFlags pf = 0, sf = 0; + + switch (type) + { + case GAIM_NOTIFY_MSG_ERROR: + sf |= GNT_TEXT_FLAG_BOLD; + case GAIM_NOTIFY_MSG_WARNING: + pf |= GNT_TEXT_FLAG_UNDERLINE; + case GAIM_NOTIFY_MSG_INFO: + pf |= GNT_TEXT_FLAG_BOLD; + break; + } + + window = gnt_box_new(FALSE, TRUE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), title); + + if (primary) + gnt_box_add_widget(GNT_BOX(window), + gnt_label_new_with_format(primary, pf)); + if (secondary) + gnt_box_add_widget(GNT_BOX(window), + gnt_label_new_with_format(secondary, sf)); + + button = gnt_button_new(_("OK")); + gnt_box_add_widget(GNT_BOX(window), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); + + gnt_widget_show(window); + return window; +} + +/* handle is, in all/most occasions, a GntWidget * */ +static void gg_close_notify(GaimNotifyType type, void *handle) +{ + gnt_widget_destroy(GNT_WIDGET(handle)); +} + +static void *gg_notify_formatted(const char *title, const char *primary, + const char *secondary, const char *text) +{ + /* XXX: For now, simply strip the html and use _notify_message. For future use, + * there should be some way of parsing the makrups from GntTextView */ + char *unformat = gaim_markup_strip_html(text); + char *t = g_strdup_printf("%s%s%s", + secondary ? secondary : "", + secondary ? "\n" : "", + unformat ? unformat : ""); + + void *ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, title, primary, t); + + g_free(t); + g_free(unformat); + + return ret; +} + +static void * +gg_notify_emails(GaimConnection *gc, size_t count, gboolean detailed, + const char **subjects, const char **froms, const char **tos, + const char **urls) +{ + GaimAccount *account = gaim_connection_get_account(gc); + GString *message = g_string_new(NULL); + void *ret; + + if (!detailed) + { + g_string_append_printf(message, + ngettext("%s (%s) has %d new message.", + "%s (%s) has %d new messages.", + (int)count), + tos ? *tos : gaim_account_get_username(account), + gaim_account_get_protocol_name(account), (int)count); + } + else + { + /* XXX: Yes, yes. I know, the combined dialog thing. Maybe later. */ + g_string_append_printf(message, + _("You have received a mail \"%s\""), *subjects); + if (froms && *froms && **froms) + g_string_append_printf(message, _("\nfrom %s"), *froms); + g_string_append_printf(message, _(" to %s (%s)"), + tos ? *tos : gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); + } + + ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, _("New Mail"), _("You have mail!"), message->str); + g_string_free(message, TRUE); + return ret; +} + +static void * +gg_notify_email(GaimConnection *gc, const char *subject, const char *from, + const char *to, const char *url) +{ + return gg_notify_emails(gc, 1, subject != NULL, + subject ? &subject : NULL, + from ? &from : NULL, + to ? &to : NULL, + url ? &url : NULL); +} + +static void * +gg_notify_userinfo(GaimConnection *gc, const char *who, const char *text) +{ + /* Xeroxed from gtknotify.c */ + char *primary; + void *ui_handle; + + primary = g_strdup_printf(_("Info for %s"), who); + ui_handle = gg_notify_formatted(_("Buddy Information"), primary, NULL, text); + g_free(primary); + return ui_handle; +} + +static GaimNotifyUiOps ops = +{ + .notify_message = gg_notify_message, + .close_notify = gg_close_notify, /* The rest of the notify-uiops return a GntWidget. + These widgets should be destroyed from here. */ + .notify_formatted = gg_notify_formatted, + .notify_email = gg_notify_email, + .notify_emails = gg_notify_emails, + .notify_userinfo = gg_notify_userinfo, + + .notify_searchresults = NULL, /* We are going to need multi-column GntTree's for this */ + .notify_searchresults_new_rows = NULL, + .notify_uri = NULL /* This is of low-priority to me */ +}; + +GaimNotifyUiOps *gg_notify_get_ui_ops() +{ + return &ops; +} + +void gg_notify_init() +{ +} + +void gg_notify_uninit() +{ +} + + Property changes on: trunk/console/gntnotify.c ___________________________________________________________________ Name: svn:mime-type + text/plan Name: svn:eol-style + native Added: trunk/console/gntnotify.h =================================================================== --- trunk/console/gntnotify.h (rev 0) +++ trunk/console/gntnotify.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -0,0 +1,8 @@ +#include "notify.h" + +GaimNotifyUiOps *gg_notify_get_ui_ops(); + +void gg_notify_init(); + +void gg_notify_uninit(); + Property changes on: trunk/console/gntnotify.h ___________________________________________________________________ Name: svn:mime-type + text/plan Name: svn:eol-style + native Modified: trunk/console/gntui.c =================================================================== --- trunk/console/gntui.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/gntui.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -2,7 +2,9 @@ #include "gntaccount.h" #include "gntblist.h" +#include "gntconn.h" #include "gntconv.h" +#include "gntnotify.h" void init_gnt_ui() { @@ -12,6 +14,10 @@ gg_accounts_init(); gaim_accounts_set_ui_ops(gg_accounts_get_ui_ops()); + /* Connections */ + gg_connections_init(); + gaim_connections_set_ui_ops(gg_connections_get_ui_ops()); + /* Initialize the buddy list */ gg_blist_init(); gaim_blist_set_ui_ops(gg_blist_get_ui_ops()); @@ -20,17 +26,27 @@ gg_conversation_init(); gaim_conversations_set_ui_ops(gg_conv_get_ui_ops()); + /* Notify */ + gg_notify_init(); + gaim_notify_set_ui_ops(gg_notify_get_ui_ops()); + gnt_main(); gaim_accounts_set_ui_ops(NULL); gg_accounts_uninit(); + gaim_connections_set_ui_ops(NULL); + gg_connections_uninit(); + gaim_blist_set_ui_ops(NULL); gg_blist_uninit(); gaim_conversations_set_ui_ops(NULL); gg_conversation_uninit(); + gaim_notify_set_ui_ops(NULL); + gg_notify_uninit(); + gnt_quit(); } Modified: trunk/console/libgnt/gntlabel.c =================================================================== --- trunk/console/libgnt/gntlabel.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gntlabel.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -21,8 +21,9 @@ gnt_label_draw(GntWidget *widget) { GntLabel *label = GNT_LABEL(widget); + chtype flag = gnt_text_format_flag_to_chtype(label->flags); - wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); + wbkgdset(widget->window, '\0' | flag); mvwprintw(widget->window, 0, 0, label->text); DEBUG; @@ -109,10 +110,16 @@ GntWidget *gnt_label_new(const char *text) { + return gnt_label_new_with_format(text, 0); +} + +GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags) +{ GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); GntLabel *label = GNT_LABEL(widget); label->text = g_strdup(text); + label->flags = flags; gnt_widget_set_take_focus(widget, FALSE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); Modified: trunk/console/libgnt/gntlabel.h =================================================================== --- trunk/console/libgnt/gntlabel.h 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gntlabel.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -3,6 +3,7 @@ #include "gnt.h" #include "gntwidget.h" +#include "gnttextview.h" #define GNT_TYPE_LABEL (gnt_label_get_gtype()) #define GNT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_LABEL, GntLabel)) @@ -19,6 +20,7 @@ GntWidget parent; char *text; + GntTextFormatFlags flags; void (*gnt_reserved1)(void); void (*gnt_reserved2)(void); @@ -42,6 +44,8 @@ GntWidget *gnt_label_new(const char *text); +GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags); + G_END_DECLS #endif /* GNT_LABEL_H */ Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gntmain.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -262,6 +262,7 @@ update_window_in_list(GNT_WIDGET(box)); } + gnt_tree_set_selected(GNT_TREE(tree), focus_list->data); gnt_box_add_widget(GNT_BOX(win), tree); gnt_widget_set_size(tree, getmaxx(stdscr) / 3, getmaxy(stdscr) / 2); Modified: trunk/console/libgnt/gnttextview.c =================================================================== --- trunk/console/libgnt/gnttextview.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gnttextview.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -178,20 +178,8 @@ if (text == NULL || *text == '\0') return; - if (flags & GNT_TEXT_FLAG_BOLD) - fl |= A_BOLD; - if (flags & GNT_TEXT_FLAG_UNDERLINE) - fl |= A_UNDERLINE; - if (flags & GNT_TEXT_FLAG_BLINK) - fl |= A_BLINK; + fl = gnt_text_format_flag_to_chtype(flags); - if (flags & GNT_TEXT_FLAG_DIM) - fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); - else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) - fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); - else - fl |= COLOR_PAIR(GNT_COLOR_NORMAL); - view->list = g_list_first(view->list); split = g_strsplit(text, "\n", 0); @@ -262,3 +250,24 @@ gnt_widget_draw(GNT_WIDGET(view)); } +chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) +{ + chtype fl = 0; + + if (flags & GNT_TEXT_FLAG_BOLD) + fl |= A_BOLD; + if (flags & GNT_TEXT_FLAG_UNDERLINE) + fl |= A_UNDERLINE; + if (flags & GNT_TEXT_FLAG_BLINK) + fl |= A_BLINK; + + if (flags & GNT_TEXT_FLAG_DIM) + fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); + else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) + fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); + else + fl |= COLOR_PAIR(GNT_COLOR_NORMAL); + + return fl; +} + Modified: trunk/console/libgnt/gnttextview.h =================================================================== --- trunk/console/libgnt/gnttextview.h 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gnttextview.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -64,6 +64,8 @@ * It first completes the current line with the current text-attributes. */ void gnt_text_view_next_line(GntTextView *view); +chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags); + G_END_DECLS #endif /* GNT_TEXT_VIEW_H */ Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gnttree.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -716,3 +716,24 @@ redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ } +void gnt_tree_set_selected(GntTree *tree , void *key) +{ + int dist; + GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + if (!row) + return; + + if (tree->top == NULL) + tree->top = row; + if (tree->bottom == NULL) + tree->bottom = row; + + tree->current = row; + if ((dist = get_distance(tree->current, tree->bottom)) < 0) + gnt_tree_scroll(tree, -dist); + else if ((dist = get_distance(tree->current, tree->top)) > 0) + gnt_tree_scroll(tree, -dist); + else + redraw_tree(tree); +} + Modified: trunk/console/libgnt/gnttree.h =================================================================== --- trunk/console/libgnt/gnttree.h 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/gnttree.h 2006-07-17 03:45:24 UTC (rev 16500) @@ -84,6 +84,8 @@ void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags); +void gnt_tree_set_selected(GntTree *tree , void *key); + G_END_DECLS #endif /* GNT_TREE_H */ Modified: trunk/console/libgnt/test/multiwin.c =================================================================== --- trunk/console/libgnt/test/multiwin.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/test/multiwin.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -60,6 +60,8 @@ gnt_tree_set_row_flags(GNT_TREE(tree), "e", GNT_TEXT_FLAG_DIM); + gnt_tree_set_selected(GNT_TREE(tree), "2"); + g_timeout_add(5000, (GSourceFunc)show, box2); gnt_main(); Modified: trunk/console/libgnt/test/tv.c =================================================================== --- trunk/console/libgnt/test/tv.c 2006-07-17 03:12:41 UTC (rev 16499) +++ trunk/console/libgnt/test/tv.c 2006-07-17 03:45:24 UTC (rev 16500) @@ -59,6 +59,7 @@ gnt_box_add_widget(GNT_BOX(hbox), view); gnt_box_add_widget(GNT_BOX(hbox), entry); + gnt_box_add_widget(GNT_BOX(hbox), gnt_button_new("OK")); gnt_widget_show(hbox); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2006-07-17 03:13:19
|
Revision: 16499 Author: roast Date: 2006-07-16 20:12:41 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16499&view=rev Log Message: ----------- merged with svn trunk. 16464:16498. Modified Paths: -------------- branches/soc-2006-file-loggers/console/gntaccount.c branches/soc-2006-file-loggers/console/gntblist.c branches/soc-2006-file-loggers/console/gntconv.c branches/soc-2006-file-loggers/console/libgnt/Makefile.am branches/soc-2006-file-loggers/console/libgnt/gnt.h branches/soc-2006-file-loggers/console/libgnt/gntbox.c branches/soc-2006-file-loggers/console/libgnt/gntbox.h branches/soc-2006-file-loggers/console/libgnt/gntbutton.c branches/soc-2006-file-loggers/console/libgnt/gntentry.c branches/soc-2006-file-loggers/console/libgnt/gntlabel.c branches/soc-2006-file-loggers/console/libgnt/gntmain.c branches/soc-2006-file-loggers/console/libgnt/gnttextview.c branches/soc-2006-file-loggers/console/libgnt/gnttree.c branches/soc-2006-file-loggers/console/libgnt/gnttree.h branches/soc-2006-file-loggers/console/libgnt/gntwidget.c branches/soc-2006-file-loggers/console/libgnt/gntwidget.h branches/soc-2006-file-loggers/console/libgnt/test/Makefile branches/soc-2006-file-loggers/console/libgnt/test/focus.c branches/soc-2006-file-loggers/console/libgnt/test/multiwin.c branches/soc-2006-file-loggers/pixmaps/status/default/Makefile.am branches/soc-2006-file-loggers/plugins/spellchk.c branches/soc-2006-file-loggers/plugins/tcl/tcl.c branches/soc-2006-file-loggers/plugins/tcl/tcl_gaim.h branches/soc-2006-file-loggers/plugins/tcl/tcl_glib.c branches/soc-2006-file-loggers/plugins/tcl/tcl_signals.c branches/soc-2006-file-loggers/src/Makefile.am branches/soc-2006-file-loggers/src/Makefile.mingw branches/soc-2006-file-loggers/src/gtkimhtml.c branches/soc-2006-file-loggers/src/log.h branches/soc-2006-file-loggers/src/protocols/irc/irc.h branches/soc-2006-file-loggers/src/protocols/jabber/jabber.c branches/soc-2006-file-loggers/src/protocols/jabber/jabber.h branches/soc-2006-file-loggers/src/protocols/msn/httpconn.h branches/soc-2006-file-loggers/src/protocols/msn/msn.c branches/soc-2006-file-loggers/src/protocols/oscar/oscar.c branches/soc-2006-file-loggers/src/protocols/oscar/oscar.h branches/soc-2006-file-loggers/src/protocols/sametime/sametime.c branches/soc-2006-file-loggers/src/protocols/simple/simple.h branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.h branches/soc-2006-file-loggers/src/util.c Added Paths: ----------- branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c branches/soc-2006-file-loggers/console/libgnt/gntcombobox.h branches/soc-2006-file-loggers/console/libgnt/gntline.c branches/soc-2006-file-loggers/console/libgnt/gntline.h branches/soc-2006-file-loggers/console/libgnt/gntmarshal.c branches/soc-2006-file-loggers/console/libgnt/gntmarshal.h branches/soc-2006-file-loggers/console/libgnt/test/combo.c branches/soc-2006-file-loggers/src/circbuffer.c branches/soc-2006-file-loggers/src/circbuffer.h Removed Paths: ------------- branches/soc-2006-file-loggers/console/libgnt/gntutils.c branches/soc-2006-file-loggers/console/libgnt/gntutils.h branches/soc-2006-file-loggers/pixmaps/status/default/nr.png branches/soc-2006-file-loggers/src/gaim_buffer.c branches/soc-2006-file-loggers/src/gaim_buffer.h Modified: branches/soc-2006-file-loggers/console/gntaccount.c =================================================================== --- branches/soc-2006-file-loggers/console/gntaccount.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/gntaccount.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -1,11 +1,17 @@ #include <gnt.h> #include <gntbox.h> #include <gntbutton.h> +#include <gntcombobox.h> +#include <gntentry.h> #include <gntlabel.h> +#include <gntline.h> #include <gnttree.h> +#include <account.h> +#include <accountopt.h> #include <connection.h> #include <notify.h> +#include <plugin.h> #include <request.h> #include "gntaccount.h" @@ -19,7 +25,167 @@ static GGAccountList accounts; +typedef struct +{ + GaimAccount *account; /* NULL for a new account */ + + GntWidget *window; + + GntWidget *protocol; + GntWidget *screenname; + GntWidget *password; + GntWidget *alias; + + GntWidget *splits; + GList *split_entries; +} AccountEditDialog; + static void +edit_dialog_destroy(AccountEditDialog *dialog) +{ + g_free(dialog); +} + +static void +save_account_cb(AccountEditDialog *dialog) +{ +} + +static void +update_user_splits(AccountEditDialog *dialog) +{ + GntWidget *hbox; + GaimPlugin *plugin; + GaimPluginProtocolInfo *prplinfo; + GList *iter; + char *username = NULL; + + if (dialog->splits) + { + gnt_box_remove_all(GNT_BOX(dialog->splits)); + g_list_free(dialog->split_entries); + } + else + { + dialog->splits = gnt_box_new(FALSE, TRUE); + gnt_box_set_pad(GNT_BOX(dialog->splits), 0); + } + + dialog->split_entries = NULL; + + plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); + if (!plugin) + return; + prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plugin); + + username = g_strdup(gaim_account_get_username(dialog->account)); + + for (iter = prplinfo->user_splits; iter; iter = iter->next) + { + GaimAccountUserSplit *split = iter->data; + GntWidget *entry; + char *buf; + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_add_widget(GNT_BOX(dialog->splits), hbox); + + buf = g_strdup_printf("%s:", gaim_account_user_split_get_text(split)); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(buf)); + + entry = gnt_entry_new(NULL); + gnt_box_add_widget(GNT_BOX(hbox), entry); + + dialog->split_entries = g_list_append(dialog->split_entries, entry); + g_free(buf); + } + + /* XXX: Add default/custom values to the splits */ + g_free(username); +} + +static void +prpl_changed_cb(GntWidget *combo, GaimPlugin *old, GaimPlugin *new, AccountEditDialog *dialog) +{ + update_user_splits(dialog); + gnt_box_readjust(GNT_BOX(dialog->window)); + gnt_widget_draw(dialog->window); +} + +static void +add_account(GntWidget *b, gpointer null) +{ + GntWidget *window, *hbox; + GntWidget *combo, *button, *entry; + GList *list, *iter; + AccountEditDialog *dialog; + + dialog = g_new0(AccountEditDialog, 1); + + dialog->window = window = gnt_box_new(FALSE, TRUE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), _("New Account")); + gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); + gnt_box_set_pad(GNT_BOX(window), 0); + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_add_widget(GNT_BOX(window), hbox); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); + + dialog->protocol = combo = gnt_combo_box_new(); + list = gaim_plugins_get_protocols(); + for (iter = list; iter; iter = iter->next) + { + gnt_combo_box_add_data(GNT_COMBO_BOX(combo), iter->data, + ((GaimPlugin*)iter->data)->info->name); + } + g_signal_connect(G_OBJECT(combo), "selection-changed", G_CALLBACK(prpl_changed_cb), dialog); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Protocol:"))); + gnt_box_add_widget(GNT_BOX(hbox), combo); + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_add_widget(GNT_BOX(window), hbox); + + dialog->screenname = entry = gnt_entry_new(NULL); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Screen name:"))); + gnt_box_add_widget(GNT_BOX(hbox), entry); + + /* User splits */ + update_user_splits(dialog); + gnt_box_add_widget(GNT_BOX(window), dialog->splits); + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_add_widget(GNT_BOX(window), hbox); + + dialog->password = entry = gnt_entry_new(NULL); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Password:"))); + gnt_box_add_widget(GNT_BOX(hbox), entry); + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_add_widget(GNT_BOX(window), hbox); + + dialog->alias = entry = gnt_entry_new(NULL); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Alias:"))); + gnt_box_add_widget(GNT_BOX(hbox), entry); + + gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); + + hbox = gnt_box_new(FALSE, FALSE); + gnt_box_add_widget(GNT_BOX(window), hbox); + + button = gnt_button_new(_("Cancel")); + gnt_box_add_widget(GNT_BOX(hbox), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); + + button = gnt_button_new(_("Save")); + gnt_box_add_widget(GNT_BOX(hbox), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(save_account_cb), dialog); + + g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(edit_dialog_destroy), dialog); + + gnt_widget_show(window); +} + +static void account_toggled(GntWidget *widget, void *key, gpointer null) { GaimAccount *account = key; @@ -32,15 +198,18 @@ GList *iter; GntWidget *box, *button; - accounts.window = gnt_box_new(TRUE, TRUE); + accounts.window = gnt_box_new(FALSE, TRUE); gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE); gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts")); gnt_box_set_pad(GNT_BOX(accounts.window), 0); + gnt_box_set_alignment(GNT_BOX(accounts.window), GNT_ALIGN_MID); gnt_widget_set_name(accounts.window, "accounts"); gnt_box_add_widget(GNT_BOX(accounts.window), gnt_label_new(_("You can enable/disable accounts from the following list."))); + gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); + accounts.tree = gnt_tree_new(); GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); @@ -62,10 +231,13 @@ gnt_widget_set_size(accounts.tree, 40, 10); gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); + gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); + box = gnt_box_new(FALSE, FALSE); button = gnt_button_new(_("Add")); gnt_box_add_widget(GNT_BOX(box), button); + g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account), NULL); button = gnt_button_new(_("Modify")); gnt_box_add_widget(GNT_BOX(box), button); Modified: branches/soc-2006-file-loggers/console/gntblist.c =================================================================== --- branches/soc-2006-file-loggers/console/gntblist.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/gntblist.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -234,6 +234,9 @@ GntTree *tree = GNT_TREE(ggblist->tree); GaimBlistNode *node = gnt_tree_get_selection_data(tree); + if (!node) + return; + if (GAIM_BLIST_NODE_IS_BUDDY(node)) { GaimBuddy *buddy = (GaimBuddy *)node; Modified: branches/soc-2006-file-loggers/console/gntconv.c =================================================================== --- branches/soc-2006-file-loggers/console/gntconv.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/gntconv.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -47,17 +47,29 @@ if (key[0] == '\r' && key[1] == 0) { const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); - switch (gaim_conversation_get_type(ggconv->conv)) + if (*text == '/') { - case GAIM_CONV_TYPE_IM: - gaim_conv_im_send_with_flags(GAIM_CONV_IM(ggconv->conv), text, GAIM_MESSAGE_SEND); - break; - case GAIM_CONV_TYPE_CHAT: - gaim_conv_chat_send(GAIM_CONV_CHAT(ggconv->conv), text); - break; - default: - g_return_val_if_reached(FALSE); + /* XXX: Need to check for /-commands here */ + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), + _("Commands are not supported yet. Message was NOT sent."), + GNT_TEXT_FLAG_DIM | GNT_TEXT_FLAG_UNDERLINE); + gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); + gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); } + else + { + switch (gaim_conversation_get_type(ggconv->conv)) + { + case GAIM_CONV_TYPE_IM: + gaim_conv_im_send_with_flags(GAIM_CONV_IM(ggconv->conv), text, GAIM_MESSAGE_SEND); + break; + case GAIM_CONV_TYPE_CHAT: + gaim_conv_chat_send(GAIM_CONV_CHAT(ggconv->conv), text); + break; + default: + g_return_val_if_reached(FALSE); + } + } gnt_entry_clear(GNT_ENTRY(ggconv->entry)); return TRUE; } @@ -107,7 +119,7 @@ type = gaim_conversation_get_type(conv); title = g_strdup_printf(_("%s"), gaim_conversation_get_name(conv)); - ggc->window = gnt_box_new(TRUE, TRUE); + ggc->window = gnt_box_new(FALSE, TRUE); gnt_box_set_title(GNT_BOX(ggc->window), title); gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); gnt_box_set_pad(GNT_BOX(ggc->window), 0); Modified: branches/soc-2006-file-loggers/console/libgnt/Makefile.am =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/Makefile.am 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/Makefile.am 2006-07-17 03:12:41 UTC (rev 16499) @@ -8,11 +8,13 @@ gntbox.c \ gntbutton.c \ gntcolors.c \ + gntcombobox.c \ gntentry.c \ gntlabel.c \ + gntline.c \ + gntmarshal.c \ gnttextview.c \ gnttree.c \ - gntutils.c \ gntmain.c libgnt_la_headers = \ @@ -20,12 +22,14 @@ gntbox.h \ gntbutton.h \ gntcolors.h \ + gntcombobox.h \ gntentry.h \ gntkeys.h \ gntlabel.h \ + gntline.h \ + gntmarshal.h \ gnttextview.h \ gnttree.h \ - gntutils.h \ gnt.h libgnt_laincludedir=$(includedir)/gnt Modified: branches/soc-2006-file-loggers/console/libgnt/gnt.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnt.h 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gnt.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -17,6 +17,8 @@ void gnt_screen_take_focus(GntWidget *widget); +void gnt_screen_resize_widget(GntWidget *widget, int width, int height); + gboolean gnt_widget_has_focus(GntWidget *widget); void gnt_widget_set_urgent(GntWidget *widget); Modified: branches/soc-2006-file-loggers/console/libgnt/gntbox.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntbox.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntbox.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -77,7 +77,7 @@ gboolean has_border = FALSE; w = h = 0; - max = -1; + max = 0; curx = widget->priv.x; cury = widget->priv.y; if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) @@ -93,15 +93,21 @@ gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); if (box->vertical) { - cury += h + box->pad; - if (max < w) - max = w; + if (h) + { + cury += h + box->pad; + if (max < w) + max = w; + } } else { - curx += w + box->pad; - if (max < h) - max = h; + if (w) + { + curx += w + box->pad; + if (max < h) + max = h; + } } } @@ -112,6 +118,14 @@ max += 2; } + if (box->list) + { + if (box->vertical) + cury -= box->pad; + else + curx -= box->pad; + } + if (box->vertical) { widget->priv.width = max; @@ -127,8 +141,18 @@ static void gnt_box_set_position(GntWidget *widget, int x, int y) { - gnt_widget_size_request(widget); - reposition_children(widget); + GList *iter; + int changex, changey; + + changex = widget->priv.x - x; + changey = widget->priv.y - y; + + for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) + { + GntWidget *w = GNT_WIDGET(iter->data); + gnt_widget_set_position(w, w->priv.x - changex, + w->priv.y - changey); + } } static void @@ -136,25 +160,43 @@ { GntBox *box = GNT_BOX(widget); GList *iter; + int maxw = 0, maxh = 0; g_list_foreach(box->list, (GFunc)gnt_widget_size_request, NULL); + for (iter = box->list; iter; iter = iter->next) + { + int w, h; + gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); + if (maxh < h) + maxh = h; + if (maxw < w) + maxw = w; + } + if (box->homogeneous) { - int max = -1, w, h; - - /* XXX: should probably be changed based on vertical-ness */ for (iter = box->list; iter; iter = iter->next) { - gnt_widget_get_size(GNT_WIDGET(iter->data), &w, NULL); - if (max < w) - max = w; + gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, maxh); } - + } + else + { for (iter = box->list; iter; iter = iter->next) { - gnt_widget_get_size(GNT_WIDGET(iter->data), NULL, &h); - gnt_widget_set_size(GNT_WIDGET(iter->data), max, h); + if (box->vertical) + { + int h; + gnt_widget_get_size(GNT_WIDGET(iter->data), NULL, &h); + gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, h); + } + else + { + int w; + gnt_widget_get_size(GNT_WIDGET(iter->data), &w, NULL); + gnt_widget_set_size(GNT_WIDGET(iter->data), w, maxh); + } } } @@ -185,10 +227,21 @@ return box->active; } +static void +find_next_focus(GntBox *box) +{ + GList *iter = g_list_find(box->focus, box->active); + if (iter && iter->next) + box->active = iter->next->data; + else if (box->focus) + box->active = box->focus->data; +} + static gboolean gnt_box_key_pressed(GntWidget *widget, const char *text) { GntBox *box = GNT_BOX(widget); + GntWidget *now; if (box->active == NULL && !find_focusable_widget(box)) return FALSE; @@ -196,9 +249,10 @@ if (gnt_widget_key_pressed(box->active, text)) return TRUE; + now = box->active; + if (text[0] == 27) { - GntWidget *now = box->active; if (strcmp(text+1, GNT_KEY_LEFT) == 0) { GList *iter = g_list_find(box->focus, box->active); @@ -213,23 +267,19 @@ } else if (strcmp(text+1, GNT_KEY_RIGHT) == 0) { - GList *iter = g_list_find(box->focus, box->active); - if (iter && iter->next) - { - box->active = iter->next->data; - } - else if (box->focus) - { - box->active = box->focus->data; - } + find_next_focus(box); } + } + else if (text[0] == '\t') + { + find_next_focus(box); + } - if (now && now != box->active) - { - gnt_widget_set_focus(now, FALSE); - gnt_widget_set_focus(box->active, TRUE); - return TRUE; - } + if (now && now != box->active) + { + gnt_widget_set_focus(now, FALSE); + gnt_widget_set_focus(box->active, TRUE); + return TRUE; } return FALSE; @@ -257,16 +307,9 @@ gnt_box_destroy(GntWidget *w) { GntBox *box = GNT_BOX(w); - GList *iter; - for (iter = box->list; iter; iter = iter->next) - { - gnt_widget_destroy(iter->data); - } - + gnt_box_remove_all(box); gnt_screen_release(w); - - g_list_free(box->list); } static void @@ -285,9 +328,20 @@ GntBox *box = GNT_BOX(widget); int wchange, hchange; + if (widget->priv.width != width && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_X)) + return FALSE; + if (widget->priv.height != height && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_Y)) + return FALSE; + + if (!box->list) + return TRUE; + wchange = widget->priv.width - width; hchange = widget->priv.height - height; + if (wchange == 0 && hchange == 0) + return TRUE; /* Quit playing games */ + /* XXX: Right now, I am trying to just apply all the changes to * just one widget. It should be possible to distribute the * changes to all the widgets in the box. */ @@ -298,14 +352,84 @@ gnt_widget_get_size(wid, &w, &h); - if (gnt_widget_set_size(wid, w - wchange, h - hchange)) + if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) + { + GList *i; + + for (i = box->list; i; i = i->next) + { + int tw, th; + if (i == iter) continue; + gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); + if (box->vertical) + { + if (!gnt_widget_confirm_size(i->data, tw - wchange, th)) + return FALSE; + } + else + { + if (!gnt_widget_confirm_size(i->data, tw, th - hchange)) + return FALSE; + } + } +#if 0 + gnt_widget_set_size(wid, w - wchange, h - hchange); + if (box->vertical) + hchange = 0; + else + wchange = 0; + + for (i = box->list; i; i = i->next) + { + int tw, th; + if (i == iter) continue; + gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); + gnt_widget_set_size(i->data, tw - wchange, th - hchange); + } +#endif + g_object_set_data(G_OBJECT(box), "size-queued", wid); return TRUE; + } } return FALSE; } static void +gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) +{ + int wchange, hchange; + GList *i; + GntBox *box = GNT_BOX(widget); + GntWidget *wid; + int tw, th; + + wchange = widget->priv.width - oldw; + hchange = widget->priv.height - oldh; + + wid = g_object_get_data(G_OBJECT(box), "size-queued"); + if (wid) + { + gnt_widget_get_size(wid, &tw, &th); + gnt_widget_set_size(wid, tw + wchange, th + hchange); + g_object_set_data(G_OBJECT(box), "size-queued", NULL); + } + + if (box->vertical) + hchange = 0; + else + wchange = 0; + + for (i = box->list; i; i = i->next) + { + gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); + gnt_widget_set_size(i->data, tw + wchange, th + hchange); + } + + reposition_children(widget); +} + +static void gnt_box_class_init(GntBoxClass *klass) { parent_class = GNT_WIDGET_CLASS(klass); @@ -319,6 +443,7 @@ parent_class->lost_focus = gnt_box_lost_focus; parent_class->gained_focus = gnt_box_gained_focus; parent_class->confirm_size = gnt_box_confirm_size; + parent_class->size_changed = gnt_box_size_changed; DEBUG; } @@ -372,6 +497,10 @@ box->pad = 1; gnt_widget_set_take_focus(widget, TRUE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); + if (vert) + box->alignment = GNT_ALIGN_LEFT; + else + box->alignment = GNT_ALIGN_MID; return widget; } @@ -424,25 +553,119 @@ { GList *iter; GntWidget *widget = GNT_WIDGET(box); + int pos = 1; - /* XXX: werase first? */ + if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) + pos = 0; for (iter = box->list; iter; iter = iter->next) { GntWidget *w = GNT_WIDGET(iter->data); int height, width; + int x, y; if (GNT_IS_BOX(w)) gnt_box_sync_children(GNT_BOX(w)); gnt_widget_get_size(w, &width, &height); + x = w->priv.x - widget->priv.x; + y = w->priv.y - widget->priv.y; + + if (box->vertical) + { + if (box->alignment == GNT_ALIGN_RIGHT) + x += widget->priv.width - width; + else if (box->alignment == GNT_ALIGN_MID) + x += (widget->priv.width - width)/2; + if (x + width > widget->priv.width - pos) + x -= x + width - (widget->priv.width - pos); + } + else + { + if (box->alignment == GNT_ALIGN_BOTTOM) + y += widget->priv.height - height; + else if (box->alignment == GNT_ALIGN_MID) + y += (widget->priv.height - height)/2; + if (y + height >= widget->priv.height - pos) + y = widget->priv.height - height - pos; + } + copywin(w->window, widget->window, 0, 0, - w->priv.y - widget->priv.y, - w->priv.x - widget->priv.x, - w->priv.y - widget->priv.y + height - 1, - w->priv.x - widget->priv.x + width - 1, - FALSE); + y, x, y + height - 1, x + width - 1, FALSE); } } +void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) +{ + box->alignment = alignment; +} + +void gnt_box_remove(GntBox *box, GntWidget *widget) +{ + box->list = g_list_remove(box->list, widget); + if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) + && GNT_WIDGET(box)->parent == NULL && box->focus) + { + if (widget == box->active) + { + find_next_focus(box); + if (box->active == widget) /* There's only one widget */ + box->active = NULL; + } + box->focus = g_list_remove(box->focus, widget); + } + + if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) + gnt_widget_draw(GNT_WIDGET(box)); +} + +void gnt_box_remove_all(GntBox *box) +{ + g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); + g_list_free(box->list); + g_list_free(box->focus); + box->list = NULL; + box->focus = NULL; + GNT_WIDGET(box)->priv.width = 0; + GNT_WIDGET(box)->priv.height = 0; +} + +void gnt_box_readjust(GntBox *box) +{ + GList *iter; + GntWidget *wid; + int width, height; + + g_return_if_fail(GNT_WIDGET(box)->parent == NULL); + + for (iter = box->list; iter; iter = iter->next) + { + GntWidget *w = iter->data; + if (GNT_IS_BOX(w)) + gnt_box_readjust(GNT_BOX(w)); + else + { + GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); + w->priv.width = 0; + w->priv.height = 0; + } + } + + wid = GNT_WIDGET(box); + GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); + wid->priv.width = 0; + wid->priv.height = 0; + + if (wid->parent == NULL) + { + g_list_free(box->focus); + box->focus = NULL; + box->active = NULL; + gnt_widget_size_request(wid); + gnt_widget_get_size(wid, &width, &height); + gnt_screen_resize_widget(wid, width, height); + find_focusable_widget(box); + } +} + Modified: branches/soc-2006-file-loggers/console/libgnt/gntbox.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntbox.h 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntbox.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -14,6 +14,19 @@ typedef struct _GnBox GntBox; typedef struct _GnBoxClass GntBoxClass; +typedef enum +{ + /* These for vertical boxes */ + GNT_ALIGN_LEFT, + GNT_ALIGN_RIGHT, + + GNT_ALIGN_MID, + + /* These for horizontal boxes */ + GNT_ALIGN_TOP, + GNT_ALIGN_BOTTOM +} GntAlignment; + struct _GnBox { GntWidget parent; @@ -24,6 +37,7 @@ GntWidget *active; int pad; /* Number of spaces to use between widgets */ + GntAlignment alignment; /* How are the widgets going to be aligned? */ char *title; GList *focus; /* List of widgets to cycle focus (only valid for parent boxes) */ @@ -48,6 +62,9 @@ GType gnt_box_get_gtype(void); +#define gnt_vbox_new(homo) gnt_box_new(homo, TRUE) +#define gnt_hbox_new(homo) gnt_box_new(homo, FALSE) + GntWidget *gnt_box_new(gboolean homo, gboolean vert); void gnt_box_add_widget(GntBox *box, GntWidget *widget); @@ -60,6 +77,14 @@ void gnt_box_sync_children(GntBox *box); +void gnt_box_set_alignment(GntBox *box, GntAlignment alignment); + +void gnt_box_remove(GntBox *box, GntWidget *widget); /* XXX: does NOT destroy widget */ + +void gnt_box_remove_all(GntBox *box); /* Removes AND destroys all the widgets in it */ + +void gnt_box_readjust(GntBox *box); + G_END_DECLS #endif /* GNT_BOX_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gntbutton.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntbutton.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntbutton.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -69,10 +69,14 @@ static void gnt_button_init(GTypeInstance *instance, gpointer class) { + GntWidget *widget = GNT_WIDGET(instance); GntButton *button = GNT_BUTTON(instance); button->priv = g_new0(GntButtonPriv, 1); - GNT_WIDGET_SET_FLAGS(GNT_WIDGET(button), GNT_WIDGET_GROW_X); /* Can be resized sideways */ + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); + + widget->priv.minw = 4; + widget->priv.minh = 3; DEBUG; } Copied: branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c (from rev 16498, trunk/console/libgnt/gntcombobox.c) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,247 @@ +#include "gntbox.h" +#include "gntcombobox.h" +#include "gnttree.h" +#include "gntmarshal.h" + +#include <string.h> + +enum +{ + SIG_SELECTION_CHANGED, + SIGS, +}; + +static GntWidgetClass *parent_class = NULL; +static guint signals[SIGS] = { 0 }; +static void (*widget_lost_focus)(GntWidget *widget); + +static void +set_selection(GntComboBox *box, gpointer key) +{ + if (box->selected != key) + { + gpointer old = box->selected; + box->selected = key; + g_signal_emit(box, signals[SIG_SELECTION_CHANGED], 0, old, key); + gnt_widget_draw(GNT_WIDGET(box)); + } +} + +static void +gnt_combo_box_draw(GntWidget *widget) +{ + GntComboBox *box = GNT_COMBO_BOX(widget); + char *text = NULL; + GntColorType type; + int len; + + if (box->dropdown) + { + text = (char *)gnt_tree_get_selection_text(GNT_TREE(box->dropdown)); + box->selected = gnt_tree_get_selection_data(GNT_TREE(box->dropdown)); + } + + if (text == NULL) + text = ""; + + text = g_strdup(text); + + if (gnt_widget_has_focus(widget)) + type = GNT_COLOR_HIGHLIGHT; + else + type = GNT_COLOR_NORMAL; + + wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); + + if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4) + { + char *s = g_utf8_offset_to_pointer(text, widget->priv.width - 4); + *s = '\0'; + len = widget->priv.width - 4; + } + + mvwprintw(widget->window, 1, 1, text); + whline(widget->window, '\0' | COLOR_PAIR(type), widget->priv.width - 4 - len); + mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL)); + mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | COLOR_PAIR(GNT_COLOR_NORMAL)); + + g_free(text); + DEBUG; +} + +static void +gnt_combo_box_size_request(GntWidget *widget) +{ + widget->priv.height = 3; /* For now, a combobox will have border */ + widget->priv.width = 15; +} + +static void +gnt_combo_box_map(GntWidget *widget) +{ + if (widget->priv.width == 0 || widget->priv.height == 0) + gnt_widget_size_request(widget); + DEBUG; +} + +static gboolean +gnt_combo_box_key_pressed(GntWidget *widget, const char *text) +{ + GntComboBox *box = GNT_COMBO_BOX(widget); + if (GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED)) + { + if (text[1] == 0) + { + switch (text[0]) + { + case '\r': + case '\t': + set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); + case 27: + gnt_widget_hide(box->dropdown->parent); + return TRUE; + break; + } + } + if (gnt_widget_key_pressed(box->dropdown, text)) + return TRUE; + } + else + { + if (text[0] == 27) + { + if (strcmp(text + 1, GNT_KEY_UP) == 0 || + strcmp(text + 1, GNT_KEY_DOWN) == 0) + { + GntWidget *parent = box->dropdown->parent; + gnt_widget_set_size(box->dropdown, widget->priv.width, 9); + gnt_widget_set_position(parent, + widget->priv.x, widget->priv.y + widget->priv.height - 1); + if (parent->window) + { + if (mvwin(parent->window, widget->priv.y + widget->priv.height - 1, + widget->priv.x) == ERR) + mvwin(parent->window, + widget->priv.y - 9 + 1, widget->priv.x); + } + + gnt_widget_draw(parent); + return TRUE; + } + } + } + + return FALSE; +} + +static void +gnt_combo_box_destroy(GntWidget *widget) +{ + gnt_widget_destroy(GNT_COMBO_BOX(widget)->dropdown->parent); +} + +static void +gnt_combo_box_lost_focus(GntWidget *widget) +{ + GntComboBox *combo = GNT_COMBO_BOX(widget); + if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED)) + gnt_widget_hide(GNT_COMBO_BOX(widget)->dropdown->parent); + widget_lost_focus(widget); +} + +static void +gnt_combo_box_class_init(GntComboBoxClass *klass) +{ + parent_class = GNT_WIDGET_CLASS(klass); + + parent_class->destroy = gnt_combo_box_destroy; + parent_class->draw = gnt_combo_box_draw; + parent_class->map = gnt_combo_box_map; + parent_class->size_request = gnt_combo_box_size_request; + parent_class->key_pressed = gnt_combo_box_key_pressed; + + widget_lost_focus = parent_class->lost_focus; + parent_class->lost_focus = gnt_combo_box_lost_focus; + + signals[SIG_SELECTION_CHANGED] = + g_signal_new("selection-changed", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + gnt_closure_marshal_VOID__POINTER_POINTER, + G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); + + DEBUG; +} + +static void +gnt_combo_box_init(GTypeInstance *instance, gpointer class) +{ + GntWidget *box; + GntWidget *widget = GNT_WIDGET(instance); + GntComboBox *combo = GNT_COMBO_BOX(instance); + + GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), + GNT_WIDGET_GROW_X | GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW); + combo->dropdown = gnt_tree_new(); + + box = gnt_box_new(FALSE, FALSE); + GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER); + gnt_box_set_pad(GNT_BOX(box), 0); + gnt_box_add_widget(GNT_BOX(box), combo->dropdown); + + widget->priv.minw = 4; + widget->priv.minh = 3; + DEBUG; +} + +/****************************************************************************** + * GntComboBox API + *****************************************************************************/ +GType +gnt_combo_box_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) + { + static const GTypeInfo info = { + sizeof(GntComboBoxClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_combo_box_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GntComboBox), + 0, /* n_preallocs */ + gnt_combo_box_init, /* instance_init */ + }; + + type = g_type_register_static(GNT_TYPE_WIDGET, + "GntComboBox", + &info, 0); + } + + return type; +} + +GntWidget *gnt_combo_box_new() +{ + GntWidget *widget = g_object_new(GNT_TYPE_COMBO_BOX, NULL); + + return widget; +} + +void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) +{ + gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, text, NULL, NULL); + if (box->selected == NULL) + set_selection(box, key); +} + +gpointer gnt_combo_box_get_selected_data(GntComboBox *box) +{ + return box->selected; +} + Copied: branches/soc-2006-file-loggers/console/libgnt/gntcombobox.h (from rev 16498, trunk/console/libgnt/gntcombobox.h) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntcombobox.h (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntcombobox.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,55 @@ +#ifndef GNT_COMBO_BOX_H +#define GNT_COMBO_BOX_H + +#include "gnt.h" +#include "gntcolors.h" +#include "gntkeys.h" +#include "gntwidget.h" + +#define GNT_TYPE_COMBO_BOX (gnt_combo_box_get_gtype()) +#define GNT_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_COMBO_BOX, GntComboBox)) +#define GNT_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_COMBO_BOX, GntComboBoxClass)) +#define GNT_IS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_COMBO_BOX)) +#define GNT_IS_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_COMBO_BOX)) +#define GNT_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_COMBO_BOX, GntComboBoxClass)) + +#define GNT_COMBO_BOX_FLAGS(obj) (GNT_COMBO_BOX(obj)->priv.flags) +#define GNT_COMBO_BOX_SET_FLAGS(obj, flags) (GNT_COMBO_BOX_FLAGS(obj) |= flags) +#define GNT_COMBO_BOX_UNSET_FLAGS(obj, flags) (GNT_COMBO_BOX_FLAGS(obj) &= ~(flags)) + +typedef struct _GnComboBox GntComboBox; +typedef struct _GnComboBoxPriv GntComboBoxPriv; +typedef struct _GnComboBoxClass GntComboBoxClass; + +struct _GnComboBox +{ + GntWidget parent; + + GntWidget *dropdown; /* This is a GntTree */ + + void *selected; /* Currently selected key */ +}; + +struct _GnComboBoxClass +{ + GntWidgetClass parent; + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_combo_box_get_gtype(void); + +GntWidget *gnt_combo_box_new(); + +void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text); + +gpointer gnt_combo_box_get_selected_data(GntComboBox *box); + +G_END_DECLS + +#endif /* GNT_COMBO_BOX_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gntentry.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntentry.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntentry.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -83,6 +83,10 @@ entry_redraw(widget); } /* XXX: handle other keys, like home/end, and ctrl+ goodness */ + else + return FALSE; + + return TRUE; } else { @@ -136,6 +140,7 @@ entry->scroll--; entry_redraw(widget); + return TRUE; } } } @@ -166,6 +171,7 @@ static void gnt_entry_init(GTypeInstance *instance, gpointer class) { + GntWidget *widget = GNT_WIDGET(instance); GntEntry *entry = GNT_ENTRY(instance); entry->flag = GNT_ENTRY_FLAG_ALL; @@ -174,6 +180,9 @@ GNT_WIDGET_SET_FLAGS(GNT_WIDGET(entry), GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW | GNT_WIDGET_CAN_TAKE_FOCUS); GNT_WIDGET_SET_FLAGS(GNT_WIDGET(entry), GNT_WIDGET_GROW_X); + + widget->priv.minw = 3; + widget->priv.minh = 1; DEBUG; } Modified: branches/soc-2006-file-loggers/console/libgnt/gntlabel.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntlabel.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntlabel.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -70,7 +70,10 @@ static void gnt_label_init(GTypeInstance *instance, gpointer class) { - GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); + GntWidget *widget = GNT_WIDGET(instance); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); + widget->priv.minw = 3; + widget->priv.minh = 1; DEBUG; } Copied: branches/soc-2006-file-loggers/console/libgnt/gntline.c (from rev 16498, trunk/console/libgnt/gntline.c) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntline.c (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntline.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,115 @@ +#include "gntline.h" + +enum +{ + SIGS = 1, +}; + +static GntWidgetClass *parent_class = NULL; +static guint signals[SIGS] = { 0 }; + +static void +gnt_line_draw(GntWidget *widget) +{ + GntLine *line = GNT_LINE(widget); + if (line->vertical) + mvwvline(widget->window, 1, 0, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), + widget->priv.height - 3); + else + mvwhline(widget->window, 0, 1, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), + widget->priv.width - 3); +} + +static void +gnt_line_size_request(GntWidget *widget) +{ + if (GNT_LINE(widget)->vertical) + { + widget->priv.width = 1; + widget->priv.height = 5; + } + else + { + widget->priv.width = 5; + widget->priv.height = 1; + } +} + +static void +gnt_line_map(GntWidget *widget) +{ + if (widget->priv.width == 0 || widget->priv.height == 0) + gnt_widget_size_request(widget); + DEBUG; +} + +static void +gnt_line_class_init(GntLineClass *klass) +{ + parent_class = GNT_WIDGET_CLASS(klass); + parent_class->draw = gnt_line_draw; + parent_class->map = gnt_line_map; + parent_class->size_request = gnt_line_size_request; + + DEBUG; +} + +static void +gnt_line_init(GTypeInstance *instance, gpointer class) +{ + GntWidget *widget = GNT_WIDGET(instance); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER); + widget->priv.minw = 1; + widget->priv.minh = 1; + DEBUG; +} + +/****************************************************************************** + * GntLine API + *****************************************************************************/ +GType +gnt_line_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) + { + static const GTypeInfo info = { + sizeof(GntLineClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_line_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GntLine), + 0, /* n_preallocs */ + gnt_line_init, /* instance_init */ + }; + + type = g_type_register_static(GNT_TYPE_WIDGET, + "GntLine", + &info, 0); + } + + return type; +} + +GntWidget *gnt_line_new(gboolean vertical) +{ + GntWidget *widget = g_object_new(GNT_TYPE_LINE, NULL); + GntLine *line = GNT_LINE(widget); + + line->vertical = vertical; + + if (vertical) + { + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_Y); + } + else + { + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); + } + + return widget; +} + Copied: branches/soc-2006-file-loggers/console/libgnt/gntline.h (from rev 16498, trunk/console/libgnt/gntline.h) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntline.h (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntline.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,49 @@ +#ifndef GNT_LINE_H +#define GNT_LINE_H + +#include "gntwidget.h" +#include "gnt.h" +#include "gntcolors.h" +#include "gntkeys.h" + +#define GNT_TYPE_LINE (gnt_line_get_gtype()) +#define GNT_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_LINE, GntLine)) +#define GNT_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_LINE, GntLineClass)) +#define GNT_IS_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_LINE)) +#define GNT_IS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_LINE)) +#define GNT_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_LINE, GntLineClass)) + +#define GNT_LINE_FLAGS(obj) (GNT_LINE(obj)->priv.flags) +#define GNT_LINE_SET_FLAGS(obj, flags) (GNT_LINE_FLAGS(obj) |= flags) +#define GNT_LINE_UNSET_FLAGS(obj, flags) (GNT_LINE_FLAGS(obj) &= ~(flags)) + +typedef struct _GnLine GntLine; +typedef struct _GnLinePriv GntLinePriv; +typedef struct _GnLineClass GntLineClass; + +struct _GnLine +{ + GntWidget parent; + + gboolean vertical; +}; + +struct _GnLineClass +{ + GntWidgetClass parent; + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_line_get_gtype(void); + +GntWidget *gnt_line_new(gboolean vertical); + +G_END_DECLS + +#endif /* GNT_LINE_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gntmain.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntmain.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntmain.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -400,6 +400,7 @@ { mode = GNT_KP_MODE_NORMAL; changed = TRUE; + gnt_widget_draw(widget); } if (changed) @@ -471,19 +472,7 @@ if (changed) { - GntNode *node = g_hash_table_lookup(nodes, widget); - int x, y; - - gnt_widget_get_position(widget, &x, &y); - - hide_panel(node->panel); - gnt_widget_set_size(widget, width, height); - gnt_widget_set_position(widget, x, y); - gnt_widget_draw(widget); - replace_panel(node->panel, widget->window); - show_panel(node->panel); - update_panels(); - doupdate(); + gnt_screen_resize_widget(widget, width, height); } } } @@ -673,3 +662,21 @@ return ascii_only; } +void gnt_screen_resize_widget(GntWidget *widget, int width, int height) +{ + if (widget->parent == NULL) + { + GntNode *node = g_hash_table_lookup(nodes, widget); + if (!node) + return; + + hide_panel(node->panel); + gnt_widget_set_size(widget, width, height); + gnt_widget_draw(widget); + replace_panel(node->panel, widget->window); + show_panel(node->panel); + update_panels(); + doupdate(); + } +} + Copied: branches/soc-2006-file-loggers/console/libgnt/gntmarshal.c (from rev 16498, trunk/console/libgnt/gntmarshal.c) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntmarshal.c (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntmarshal.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,168 @@ +#include "gntmarshal.h" + +void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef gboolean (*func) (gpointer data1, const char *arg1, gpointer data2); + register func callback; + register GCClosure *cc = (GCClosure*)closure; + register gpointer data1, data2; + gboolean ret; + + g_return_if_fail(ret_value != NULL); + g_return_if_fail(n_param_values == 2); + + if (G_CCLOSURE_SWAP_DATA(closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer(param_values + 0); + } + else + { + data1 = g_value_peek_pointer(param_values + 0); + data2 = closure->data; + } + + callback = (func) (marshal_data ? marshal_data : cc->callback); + ret = callback(data1, g_value_get_string(param_values + 1) , data2); + g_value_set_boolean(ret_value, ret); +} + +void gnt_closure_marshal_VOID__INT_INT_INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*func) (gpointer data1, int, int, int, int, gpointer data2); + register func callback; + register GCClosure *cc = (GCClosure*)closure; + register gpointer data1, data2; + + g_return_if_fail(n_param_values == 5); + + if (G_CCLOSURE_SWAP_DATA(closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer(param_values + 0); + } + else + { + data1 = g_value_peek_pointer(param_values + 0); + data2 = closure->data; + } + + callback = (func) (marshal_data ? marshal_data : cc->callback); + callback(data1, + g_value_get_int(param_values + 1) , + g_value_get_int(param_values + 2) , + g_value_get_int(param_values + 3) , + g_value_get_int(param_values + 4) , + data2); +} + +void gnt_closure_marshal_VOID__INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*func) (gpointer data1, int, int, gpointer data2); + register func callback; + register GCClosure *cc = (GCClosure*)closure; + register gpointer data1, data2; + + g_return_if_fail(n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA(closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer(param_values + 0); + } + else + { + data1 = g_value_peek_pointer(param_values + 0); + data2 = closure->data; + } + + callback = (func) (marshal_data ? marshal_data : cc->callback); + callback(data1, + g_value_get_int(param_values + 1) , + g_value_get_int(param_values + 2) , + data2); +} + +void gnt_closure_marshal_VOID__POINTER_POINTER(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*func) (gpointer data1, gpointer, gpointer, gpointer data2); + register func callback; + register GCClosure *cc = (GCClosure*)closure; + register gpointer data1, data2; + + g_return_if_fail(n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA(closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer(param_values + 0); + } + else + { + data1 = g_value_peek_pointer(param_values + 0); + data2 = closure->data; + } + + callback = (func) (marshal_data ? marshal_data : cc->callback); + callback(data1, + g_value_get_pointer(param_values + 1) , + g_value_get_pointer(param_values + 2) , + data2); +} + +void gnt_closure_marshal_BOOLEAN__INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef gboolean (*func) (gpointer data1, int, int, gpointer data2); + register func callback; + register GCClosure *cc = (GCClosure*)closure; + register gpointer data1, data2; + gboolean ret; + + g_return_if_fail(ret_value != NULL); + g_return_if_fail(n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA(closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer(param_values + 0); + } + else + { + data1 = g_value_peek_pointer(param_values + 0); + data2 = closure->data; + } + + callback = (func) (marshal_data ? marshal_data : cc->callback); + ret = callback(data1, + g_value_get_int(param_values + 1) , + g_value_get_int(param_values + 2) , + data2); + g_value_set_boolean(ret_value, ret); +} + + Copied: branches/soc-2006-file-loggers/console/libgnt/gntmarshal.h (from rev 16498, trunk/console/libgnt/gntmarshal.h) =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntmarshal.h (rev 0) +++ branches/soc-2006-file-loggers/console/libgnt/gntmarshal.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -0,0 +1,37 @@ +#include "gntwidget.h" + +void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +void gnt_closure_marshal_VOID__INT_INT_INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +void gnt_closure_marshal_VOID__INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +void gnt_closure_marshal_VOID__POINTER_POINTER(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +void gnt_closure_marshal_BOOLEAN__INT_INT(GClosure *closure, + GValue *ret_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + Modified: branches/soc-2006-file-loggers/console/libgnt/gnttextview.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttextview.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gnttextview.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -113,9 +113,14 @@ static void gnt_text_view_init(GTypeInstance *instance, gpointer class) { + GntWidget *widget = GNT_WIDGET(instance); + /* XXX: For now, resizing the width is not permitted. This is because * of the way I am handling wrapped lines. */ GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y); + + widget->priv.minw = 5; + widget->priv.minh = 1; DEBUG; } Modified: branches/soc-2006-file-loggers/console/libgnt/gnttree.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttree.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gnttree.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -1,5 +1,5 @@ #include "gnttree.h" -#include "gntutils.h" +#include "gntmarshal.h" #include <string.h> @@ -201,18 +201,14 @@ g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' '); } - /* XXX: Need a utf8 version of snprintf */ - if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width) + g_snprintf(str, sizeof(str) - 1, "%s%s", format, row->text); + + if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) { /* XXX: ellipsize */ - str[widget->priv.width - 1 - pos] = 0; + char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos); + *s = '\0'; } - else - { - while (wr < widget->priv.width - 1 - pos) - str[wr++] = ' '; - str[wr] = 0; - } if (flags & GNT_TEXT_FLAG_BOLD) attr |= A_BOLD; @@ -403,7 +399,10 @@ static void gnt_tree_init(GTypeInstance *instance, gpointer class) { - GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); + GntWidget *widget = GNT_WIDGET(instance); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); + widget->priv.minw = 4; + widget->priv.minh = 3; DEBUG; } @@ -592,6 +591,13 @@ return NULL; } +const char *gnt_tree_get_selection_text(GntTree *tree) +{ + if (tree->current) + return tree->current->text; + return NULL; +} + /* XXX: Should this also remove all the children of the row being removed? */ void gnt_tree_remove(GntTree *tree, gpointer key) { @@ -707,6 +713,6 @@ return; row->flags = flags; - redraw_tree(tree); /* XXX: Is shouldn't be necessary to redraw the whole darned tree */ + redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ } Modified: branches/soc-2006-file-loggers/console/libgnt/gnttree.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttree.h 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gnttree.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -67,6 +67,8 @@ gpointer gnt_tree_get_selection_data(GntTree *tree); +const char *gnt_tree_get_selection_text(GntTree *tree); + void gnt_tree_remove(GntTree *tree, gpointer key); /* Returns the visible line number of the selected row */ Deleted: branches/soc-2006-file-loggers/console/libgnt/gntutils.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntutils.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntutils.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -1,168 +0,0 @@ -#include "gntutils.h" - -void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*func) (gpointer data1, const char *arg1, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - gboolean ret; - - g_return_if_fail(ret_value != NULL); - g_return_if_fail(n_param_values == 2); - - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } - - callback = (func) (marshal_data ? marshal_data : cc->callback); - ret = callback(data1, g_value_get_string(param_values + 1) , data2); - g_value_set_boolean(ret_value, ret); -} - -void gnt_closure_marshal_VOID__INT_INT_INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*func) (gpointer data1, int, int, int, int, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - - g_return_if_fail(n_param_values == 5); - - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } - - callback = (func) (marshal_data ? marshal_data : cc->callback); - callback(data1, - g_value_get_int(param_values + 1) , - g_value_get_int(param_values + 2) , - g_value_get_int(param_values + 3) , - g_value_get_int(param_values + 4) , - data2); -} - -void gnt_closure_marshal_VOID__INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*func) (gpointer data1, int, int, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - - g_return_if_fail(n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } - - callback = (func) (marshal_data ? marshal_data : cc->callback); - callback(data1, - g_value_get_int(param_values + 1) , - g_value_get_int(param_values + 2) , - data2); -} - -void gnt_closure_marshal_VOID__POINTER_POINTER(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*func) (gpointer data1, gpointer, gpointer, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - - g_return_if_fail(n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } - - callback = (func) (marshal_data ? marshal_data : cc->callback); - callback(data1, - g_value_get_pointer(param_values + 1) , - g_value_get_pointer(param_values + 2) , - data2); -} - -void gnt_closure_marshal_BOOLEAN__INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*func) (gpointer data1, int, int, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - gboolean ret; - - g_return_if_fail(ret_value != NULL); - g_return_if_fail(n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } - - callback = (func) (marshal_data ? marshal_data : cc->callback); - ret = callback(data1, - g_value_get_int(param_values + 1) , - g_value_get_int(param_values + 2) , - data2); - g_value_set_boolean(ret_value, ret); -} - - Deleted: branches/soc-2006-file-loggers/console/libgnt/gntutils.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntutils.h 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntutils.h 2006-07-17 03:12:41 UTC (rev 16499) @@ -1,37 +0,0 @@ -#include "gntwidget.h" - -void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -void gnt_closure_marshal_VOID__INT_INT_INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -void gnt_closure_marshal_VOID__INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -void gnt_closure_marshal_VOID__POINTER_POINTER(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -void gnt_closure_marshal_BOOLEAN__INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - Modified: branches/soc-2006-file-loggers/console/libgnt/gntwidget.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntwidget.c 2006-07-17 02:58:46 UTC (rev 16498) +++ branches/soc-2006-file-loggers/console/libgnt/gntwidget.c 2006-07-17 03:12:41 UTC (rev 16499) @@ -1,11 +1,9 @@ /* Stuff brutally ripped from Gflib */ #include "gntwidget.h" -#include "gntutils.h" +#include "gntmarshal.h" #include "gnt.h" -#define MIN_SIZE 5 - enum { SIG_DESTROY, @@ -18,6 +16,7 @@ SIG_EXPOSE, SIG_SIZE_REQUEST, SIG_CONFIRM_SIZE, + SIG_SIZE_CHANGED, SIG_POSITION, SIGS }; @@ -71,7 +70,7 @@ static gboolean gnt_widget_dummy_confirm_size(GntWidget *widget, int width, int height) { - if (width < MIN_SIZE || he... [truncated message content] |
From: <ro...@us...> - 2006-07-17 02:58:56
|
Revision: 16498 Author: roast Date: 2006-07-16 19:58:46 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16498&view=rev Log Message: ----------- added buzz message-type logging support into Yahoo and MSN Modified Paths: -------------- branches/soc-2006-file-loggers/plugins/ChangeLog.API branches/soc-2006-file-loggers/src/conversation.h branches/soc-2006-file-loggers/src/log.c branches/soc-2006-file-loggers/src/protocols/msn/msn.c branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.c Modified: branches/soc-2006-file-loggers/plugins/ChangeLog.API =================================================================== --- branches/soc-2006-file-loggers/plugins/ChangeLog.API 2006-07-16 19:09:06 UTC (rev 16497) +++ branches/soc-2006-file-loggers/plugins/ChangeLog.API 2006-07-17 02:58:46 UTC (rev 16498) @@ -291,6 +291,7 @@ * gaim_proxy_get_setup() * GaimNotifySearchResultsCallback: Added user_data. * gaim_notify_searchresults: Added user_data. + * GAIM_MESSAGE_BELL, for pokes, nudges, and buzzes (and bells) Signals - Changed: (See the Doxygen docs for details on all signals.) * Signal propagation now stops after a handler returns a non-NULL value. Modified: branches/soc-2006-file-loggers/src/conversation.h =================================================================== --- branches/soc-2006-file-loggers/src/conversation.h 2006-07-16 19:09:06 UTC (rev 16497) +++ branches/soc-2006-file-loggers/src/conversation.h 2006-07-17 02:58:46 UTC (rev 16498) @@ -115,7 +115,8 @@ GAIM_MESSAGE_DELAYED = 0x0400, /**< Delayed message. */ GAIM_MESSAGE_RAW = 0x0800, /**< "Raw" message - don't apply formatting */ - GAIM_MESSAGE_IMAGES = 0x1000 /**< Message contains images */ + GAIM_MESSAGE_IMAGES = 0x1000, /**< Message contains images */ + GAIM_MESSAGE_BELL = 0x2000 /**< Bell/Poke/Nudge message */ } GaimMessageFlags; Modified: branches/soc-2006-file-loggers/src/log.c =================================================================== --- branches/soc-2006-file-loggers/src/log.c 2006-07-16 19:09:06 UTC (rev 16497) +++ branches/soc-2006-file-loggers/src/log.c 2006-07-17 02:58:46 UTC (rev 16498) @@ -1068,6 +1068,9 @@ else if (type & GAIM_MESSAGE_WHISPER) { g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"whisper\">%s</message>\n", date, from, msg_fixed); } + else if (type & GAIM_MESSAGE_BELL) { + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"bell\">%s</message>\n", date, from, msg_fixed); + } else if (type & GAIM_MESSAGE_AUTO_RESP && (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV)) { gboolean recv_from_self = FALSE; if (type & GAIM_MESSAGE_RECV) { Modified: branches/soc-2006-file-loggers/src/protocols/msn/msn.c =================================================================== --- branches/soc-2006-file-loggers/src/protocols/msn/msn.c 2006-07-16 19:09:06 UTC (rev 16497) +++ branches/soc-2006-file-loggers/src/protocols/msn/msn.c 2006-07-17 02:58:46 UTC (rev 16498) @@ -110,7 +110,7 @@ msn_switchboard_send_msg(swboard, msg, TRUE); - gaim_conversation_write(conv, NULL, _("You have just sent a Nudge!"), GAIM_MESSAGE_SYSTEM, time(NULL)); + gaim_conversation_write(conv, NULL, _("You have just sent a Nudge!"), GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_BELL, time(NULL)); return GAIM_CMD_RET_OK; } Modified: branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.c =================================================================== --- branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.c 2006-07-16 19:09:06 UTC (rev 16497) +++ branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.c 2006-07-17 02:58:46 UTC (rev 16498) @@ -767,7 +767,7 @@ if (!strcmp(m, "<ding>")) { GaimConversation *c = gaim_conversation_new(GAIM_CONV_TYPE_IM, gaim_connection_get_account(gc), im->from); - gaim_conv_im_write(GAIM_CONV_IM(c), "", _("Buzz!!"), GAIM_MESSAGE_NICK|GAIM_MESSAGE_RECV, + gaim_conv_im_write(GAIM_CONV_IM(c), "", _("Buzz!!"), GAIM_MESSAGE_NICK|GAIM_MESSAGE_RECV|GAIM_MESSAGE_BELL, im->time); g_free(m); g_free(im); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-16 19:09:14
|
Revision: 16497 Author: thekingant Date: 2006-07-16 12:09:06 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16497&view=rev Log Message: ----------- Backport SVN revision #16496 from HEAD to v2_0_0 Original commit message: Rename gaim_buffer.c and .h to circbuffer.c and .h ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16496&view=rev Modified Paths: -------------- branches/v2_0_0/src/Makefile.am branches/v2_0_0/src/Makefile.mingw branches/v2_0_0/src/protocols/irc/irc.h branches/v2_0_0/src/protocols/jabber/jabber.h branches/v2_0_0/src/protocols/msn/httpconn.h branches/v2_0_0/src/protocols/oscar/oscar.h branches/v2_0_0/src/protocols/sametime/sametime.c branches/v2_0_0/src/protocols/simple/simple.h branches/v2_0_0/src/protocols/yahoo/yahoo.h Added Paths: ----------- branches/v2_0_0/src/circbuffer.c branches/v2_0_0/src/circbuffer.h Removed Paths: ------------- branches/v2_0_0/src/gaim_buffer.c branches/v2_0_0/src/gaim_buffer.h Modified: branches/v2_0_0/src/Makefile.am =================================================================== --- branches/v2_0_0/src/Makefile.am 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/Makefile.am 2006-07-16 19:09:06 UTC (rev 16497) @@ -70,6 +70,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -78,7 +79,6 @@ desktopitem.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ idle.c \ imgstore.c \ log.c \ @@ -117,6 +117,7 @@ blist.h \ buddyicon.h \ cipher.h \ + circbuffer.h \ cmds.h \ connection.h \ conversation.h \ @@ -126,7 +127,6 @@ desktopitem.h \ eventloop.h \ ft.h \ - gaim_buffer.h \ idle.h \ imgstore.h \ log.h \ Modified: branches/v2_0_0/src/Makefile.mingw =================================================================== --- branches/v2_0_0/src/Makefile.mingw 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/Makefile.mingw 2006-07-16 19:09:06 UTC (rev 16497) @@ -89,6 +89,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -97,7 +98,6 @@ dnssrv.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ gtkaccount.c \ gtkblist.c \ gtkconn.c \ Copied: branches/v2_0_0/src/circbuffer.c (from rev 16491, branches/v2_0_0/src/gaim_buffer.c) =================================================================== --- branches/v2_0_0/src/circbuffer.c (rev 0) +++ branches/v2_0_0/src/circbuffer.c 2006-07-16 19:09:06 UTC (rev 16497) @@ -0,0 +1,141 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "internal.h" + +#include "circbuffer.h" + +#define DEFAULT_BUF_SIZE 256 + +GaimCircBuffer * +gaim_circ_buffer_new(gsize growsize) { + GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); + buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; + return buf; +} + +void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { + g_free(buf->buffer); + g_free(buf); +} + +static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { + int in_offset = 0, out_offset = 0; + int start_buflen = buf->buflen; + + while ((buf->buflen - buf->bufused) < len) + buf->buflen += buf->growsize; + + if (buf->inptr != NULL) { + in_offset = buf->inptr - buf->buffer; + out_offset = buf->outptr - buf->buffer; + } + buf->buffer = g_realloc(buf->buffer, buf->buflen); + + /* adjust the fill and remove pointer locations */ + if (buf->inptr == NULL) { + buf->inptr = buf->outptr = buf->buffer; + } else { + buf->inptr = buf->buffer + in_offset; + buf->outptr = buf->buffer + out_offset; + } + + /* If the fill pointer is wrapped to before the remove + * pointer, we need to shift the data */ + if (in_offset < out_offset) { + int shift_n = MIN(buf->buflen - start_buflen, + in_offset); + memcpy(buf->buffer + start_buflen, buf->buffer, + shift_n); + + /* If we couldn't fit the wrapped read buffer + * at the end */ + if (shift_n < in_offset) { + memmove(buf->buffer, + buf->buffer + shift_n, + in_offset - shift_n); + buf->inptr = buf->buffer + + (in_offset - shift_n); + } else { + buf->inptr = buf->buffer + + start_buflen + in_offset; + } + } +} + +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { + + int len_stored; + + /* Grow the buffer, if necessary */ + if ((buf->buflen - buf->bufused) < len) + grow_circ_buffer(buf, len); + + /* If there is not enough room to copy all of src before hitting + * the end of the buffer then we will need to do two copies. + * One copy from inptr to the end of the buffer, and the + * second copy from the start of the buffer to the end of src. */ + if (buf->inptr >= buf->outptr) + len_stored = MIN(len, buf->buflen + - (buf->inptr - buf->buffer)); + else + len_stored = len; + + memcpy(buf->inptr, src, len_stored); + + if (len_stored < len) { + memcpy(buf->buffer, src + len_stored, len - len_stored); + buf->inptr = buf->buffer + (len - len_stored); + } else if ((buf->buffer - buf->inptr) == len_stored) { + buf->inptr = buf->buffer; + } else { + buf->inptr += len_stored; + } + + buf->bufused += len; +} + +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { + int max_read; + + if (buf->bufused == 0) + max_read = 0; + else if ((buf->outptr - buf->inptr) >= 0) + max_read = buf->buflen - (buf->outptr - buf->buffer); + else + max_read = buf->inptr - buf->outptr; + + return max_read; +} + +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { + g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); + + buf->outptr += len; + buf->bufused -= len; + /* wrap to the start if we're at the end */ + if ((buf->outptr - buf->buffer) == buf->buflen) + buf->outptr = buf->buffer; + + return TRUE; +} + Property changes on: branches/v2_0_0/src/circbuffer.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/v2_0_0/src/circbuffer.h (from rev 16491, branches/v2_0_0/src/gaim_buffer.h) =================================================================== --- branches/v2_0_0/src/circbuffer.h (rev 0) +++ branches/v2_0_0/src/circbuffer.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -0,0 +1,117 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _CIRCBUFFER_H +#define _CIRCBUFFER_H + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _GaimCircBuffer { + + /** A pointer to the starting address of our chunk of memory. */ + gchar *buffer; + + /** The incremental amount to increase this buffer by when + * the buffer is not big enough to hold incoming data, in bytes. */ + gsize growsize; + + /** The length of this buffer, in bytes. */ + gsize buflen; + + /** The number of bytes of this buffer that contain unread data. */ + gsize bufused; + + /** A pointer to the next byte where new incoming data is + * buffered to. */ + gchar *inptr; + + /** A pointer to the next byte of buffered data that should be + * read by the consumer. */ + gchar *outptr; + +} GaimCircBuffer; + +/** + * Creates a new circular buffer. This will not allocate any memory for the + * actual buffer until data is appended to it. + * + * @param growsize The amount that the buffer should grow the first time data + * is appended and every time more space is needed. Pass in + * "0" to use the default of 256 bytes. + * + * @return The new GaimCircBuffer. This should be freed with + * gaim_circ_buffer_destroy when you are done with it + */ +GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); + +/** + * Dispose of the GaimCircBuffer and free any memory used by it (including any + * memory used by the internal buffer). + * + * @param buf The GaimCircBuffer to free + */ +void gaim_circ_buffer_destroy(GaimCircBuffer *buf); + +/** + * Append data to the GaimCircBuffer. This will grow the internal + * buffer to fit the added data, if needed. + * + * @param buf The GaimCircBuffer to which to append the data + * @param src pointer to the data to copy into the buffer + * @param len number of bytes to copy into the buffer + */ +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); + +/** + * Determine the maximum number of contiguous bytes that can be read from the + * GaimCircBuffer. + * Note: This may not be the total number of bytes that are buffered - a + * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more + * data is available to read. + * + * @param buf the GaimCircBuffer for which to determine the maximum contiguous + * bytes that can be read. + * + * @return the number of bytes that can be read from the GaimCircBuffer + */ +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); + +/** + * Mark the number of bytes that have been read from the buffer. + * + * @param buf The GaimCircBuffer to mark bytes read from + * @param len The number of bytes to mark as read + * + * @return TRUE if we successfully marked the bytes as having been read, FALSE + * otherwise. + */ +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); + +#ifdef __cplusplus +} +#endif + +#endif /* _CIRCBUFFER_H */ Property changes on: branches/v2_0_0/src/circbuffer.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Deleted: branches/v2_0_0/src/gaim_buffer.c =================================================================== --- branches/v2_0_0/src/gaim_buffer.c 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/gaim_buffer.c 2006-07-16 19:09:06 UTC (rev 16497) @@ -1,141 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "internal.h" - -#include "gaim_buffer.h" - -#define DEFAULT_BUF_SIZE 256 - -GaimCircBuffer * -gaim_circ_buffer_new(gsize growsize) { - GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); - buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; - return buf; -} - -void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { - g_free(buf->buffer); - g_free(buf); -} - -static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { - int in_offset = 0, out_offset = 0; - int start_buflen = buf->buflen; - - while ((buf->buflen - buf->bufused) < len) - buf->buflen += buf->growsize; - - if (buf->inptr != NULL) { - in_offset = buf->inptr - buf->buffer; - out_offset = buf->outptr - buf->buffer; - } - buf->buffer = g_realloc(buf->buffer, buf->buflen); - - /* adjust the fill and remove pointer locations */ - if (buf->inptr == NULL) { - buf->inptr = buf->outptr = buf->buffer; - } else { - buf->inptr = buf->buffer + in_offset; - buf->outptr = buf->buffer + out_offset; - } - - /* If the fill pointer is wrapped to before the remove - * pointer, we need to shift the data */ - if (in_offset < out_offset) { - int shift_n = MIN(buf->buflen - start_buflen, - in_offset); - memcpy(buf->buffer + start_buflen, buf->buffer, - shift_n); - - /* If we couldn't fit the wrapped read buffer - * at the end */ - if (shift_n < in_offset) { - memmove(buf->buffer, - buf->buffer + shift_n, - in_offset - shift_n); - buf->inptr = buf->buffer + - (in_offset - shift_n); - } else { - buf->inptr = buf->buffer + - start_buflen + in_offset; - } - } -} - -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { - - int len_stored; - - /* Grow the buffer, if necessary */ - if ((buf->buflen - buf->bufused) < len) - grow_circ_buffer(buf, len); - - /* If there is not enough room to copy all of src before hitting - * the end of the buffer then we will need to do two copies. - * One copy from inptr to the end of the buffer, and the - * second copy from the start of the buffer to the end of src. */ - if (buf->inptr >= buf->outptr) - len_stored = MIN(len, buf->buflen - - (buf->inptr - buf->buffer)); - else - len_stored = len; - - memcpy(buf->inptr, src, len_stored); - - if (len_stored < len) { - memcpy(buf->buffer, src + len_stored, len - len_stored); - buf->inptr = buf->buffer + (len - len_stored); - } else if ((buf->buffer - buf->inptr) == len_stored) { - buf->inptr = buf->buffer; - } else { - buf->inptr += len_stored; - } - - buf->bufused += len; -} - -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { - int max_read; - - if (buf->bufused == 0) - max_read = 0; - else if ((buf->outptr - buf->inptr) >= 0) - max_read = buf->buflen - (buf->outptr - buf->buffer); - else - max_read = buf->inptr - buf->outptr; - - return max_read; -} - -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { - g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); - - buf->outptr += len; - buf->bufused -= len; - /* wrap to the start if we're at the end */ - if ((buf->outptr - buf->buffer) == buf->buflen) - buf->outptr = buf->buffer; - - return TRUE; -} - Deleted: branches/v2_0_0/src/gaim_buffer.h =================================================================== --- branches/v2_0_0/src/gaim_buffer.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/gaim_buffer.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -1,115 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _GAIM_BUFFER_H -#define _GAIM_BUFFER_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _GaimCircBuffer { - - /** A pointer to the starting address of our chunk of memory. */ - gchar *buffer; - - /** The incremental amount to increase this buffer by when - * the buffer is not big enough to hold incoming data, in bytes. */ - gsize growsize; - - /** The length of this buffer, in bytes. */ - gsize buflen; - - /** The number of bytes of this buffer that contain unread data. */ - gsize bufused; - - /** A pointer to the next byte where new incoming data is - * buffered to. */ - gchar *inptr; - - /** A pointer to the next byte of buffered data that should be - * read by the consumer. */ - gchar *outptr; - -} GaimCircBuffer; - -/** - * Creates a new circular buffer. This will not allocate any memory for the - * actual buffer until data is appended to it. - * - * @param growsize The amount that the buffer should grow the first time data - * is appended and every time more space is needed. Pass in - * "0" to use the default of 256 bytes. - * - * @return The new GaimCircBuffer. This should be freed with - * gaim_circ_buffer_destroy when you are done with it - */ -GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); - -/** - * Dispose of the GaimCircBuffer and free any memory used by it (including any - * memory used by the internal buffer). - * - * @param buf The GaimCircBuffer to free - */ -void gaim_circ_buffer_destroy(GaimCircBuffer *buf); - -/** - * Append data to the GaimCircBuffer. This will grow the internal - * buffer to fit the added data, if needed. - * - * @param buf The GaimCircBuffer to which to append the data - * @param src pointer to the data to copy into the buffer - * @param len number of bytes to copy into the buffer - */ -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); - -/** - * Determine the maximum number of contiguous bytes that can be read from the - * GaimCircBuffer. - * Note: This may not be the total number of bytes that are buffered - a - * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more - * data is available to read. - * - * @param buf the GaimCircBuffer for which to determine the maximum contiguous - * bytes that can be read. - * - * @return the number of bytes that can be read from the GaimCircBuffer - */ -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); - -/** - * Mark the number of bytes that have been read from the buffer. - * - * @param buf The GaimCircBuffer to mark bytes read from - * @param len The number of bytes to mark as read - * - * @return TRUE if we successfully marked the bytes as having been read, FALSE - * otherwise. - */ -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); - -#ifdef __cplusplus -} -#endif - -#endif /* _GAIM_BUFFER_H */ Modified: branches/v2_0_0/src/protocols/irc/irc.h =================================================================== --- branches/v2_0_0/src/protocols/irc/irc.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/irc/irc.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -25,8 +25,8 @@ #include <glib.h> +#include "circbuffer.h" #include "ft.h" -#include "gaim_buffer.h" #include "roomlist.h" #include "sslconn.h" Modified: branches/v2_0_0/src/protocols/jabber/jabber.h =================================================================== --- branches/v2_0_0/src/protocols/jabber/jabber.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/jabber/jabber.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -26,10 +26,10 @@ #include <libxml/parser.h> #endif #include <glib.h> +#include "circbuffer.h" #include "connection.h" #include "roomlist.h" #include "sslconn.h" -#include "gaim_buffer.h" #include "jutil.h" #include "xmlnode.h" Modified: branches/v2_0_0/src/protocols/msn/httpconn.h =================================================================== --- branches/v2_0_0/src/protocols/msn/httpconn.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/msn/httpconn.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -26,8 +26,8 @@ typedef struct _MsnHttpConn MsnHttpConn; +#include "circbuffer.h" #include "servconn.h" -#include "gaim_buffer.h" /** * An HTTP Connection. Modified: branches/v2_0_0/src/protocols/oscar/oscar.h =================================================================== --- branches/v2_0_0/src/protocols/oscar/oscar.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/oscar/oscar.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -29,9 +29,9 @@ #ifndef _OSCAR_H_ #define _OSCAR_H_ +#include "circbuffer.h" #include "debug.h" #include "eventloop.h" -#include "gaim_buffer.h" #include "internal.h" #include <stdio.h> Modified: branches/v2_0_0/src/protocols/sametime/sametime.c =================================================================== --- branches/v2_0_0/src/protocols/sametime/sametime.c 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/sametime/sametime.c 2006-07-16 19:09:06 UTC (rev 16497) @@ -32,25 +32,25 @@ #include <glib/glist.h> /* gaim includes */ -#include <internal.h> -#include <gaim.h> -#include <config.h> +#include "internal.h" +#include "gaim.h" +#include "config.h" -#include <account.h> -#include <accountopt.h> -#include <conversation.h> -#include <debug.h> -#include <ft.h> -#include <gaim_buffer.h> -#include <imgstore.h> -#include <mime.h> -#include <notify.h> -#include <plugin.h> -#include <privacy.h> -#include <prpl.h> -#include <request.h> -#include <util.h> -#include <version.h> +#include "account.h" +#include "accountopt.h" +#include "circbuffer.h" +#include "conversation.h" +#include "debug.h" +#include "ft.h" +#include "imgstore.h" +#include "mime.h" +#include "notify.h" +#include "plugin.h" +#include "privacy.h" +#include "prpl.h" +#include "request.h" +#include "util.h" +#include "version.h" /* meanwhile includes */ #include <mw_cipher.h> Modified: branches/v2_0_0/src/protocols/simple/simple.h =================================================================== --- branches/v2_0_0/src/protocols/simple/simple.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/simple/simple.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -26,9 +26,9 @@ #include <glib.h> #include <time.h> -#include <cipher.h> -#include <gaim_buffer.h> -#include <prpl.h> +#include "cipher.h" +#include "circbuffer.h" +#include "prpl.h" #include "sipmsg.h" Modified: branches/v2_0_0/src/protocols/yahoo/yahoo.h =================================================================== --- branches/v2_0_0/src/protocols/yahoo/yahoo.h 2006-07-16 19:08:31 UTC (rev 16496) +++ branches/v2_0_0/src/protocols/yahoo/yahoo.h 2006-07-16 19:09:06 UTC (rev 16497) @@ -25,8 +25,8 @@ #ifndef _YAHOO_H_ #define _YAHOO_H_ +#include "circbuffer.h" #include "prpl.h" -#include "gaim_buffer.h" #define YAHOO_PAGER_HOST "scs.msg.yahoo.com" #define YAHOO_PAGER_PORT 5050 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-07-16 19:08:39
|
Revision: 16496 Author: thekingant Date: 2006-07-16 12:08:31 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16496&view=rev Log Message: ----------- Rename gaim_buffer.c and .h to circbuffer.c and .h Modified Paths: -------------- trunk/src/Makefile.am trunk/src/Makefile.mingw trunk/src/protocols/irc/irc.h trunk/src/protocols/jabber/jabber.h trunk/src/protocols/msn/httpconn.h trunk/src/protocols/oscar/oscar.h trunk/src/protocols/sametime/sametime.c trunk/src/protocols/simple/simple.h trunk/src/protocols/yahoo/yahoo.h Added Paths: ----------- trunk/src/circbuffer.c trunk/src/circbuffer.h Removed Paths: ------------- trunk/src/gaim_buffer.c trunk/src/gaim_buffer.h Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/Makefile.am 2006-07-16 19:08:31 UTC (rev 16496) @@ -70,6 +70,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -78,7 +79,6 @@ desktopitem.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ idle.c \ imgstore.c \ log.c \ @@ -117,6 +117,7 @@ blist.h \ buddyicon.h \ cipher.h \ + circbuffer.h \ cmds.h \ connection.h \ conversation.h \ @@ -126,7 +127,6 @@ desktopitem.h \ eventloop.h \ ft.h \ - gaim_buffer.h \ idle.h \ imgstore.h \ log.h \ Modified: trunk/src/Makefile.mingw =================================================================== --- trunk/src/Makefile.mingw 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/Makefile.mingw 2006-07-16 19:08:31 UTC (rev 16496) @@ -89,6 +89,7 @@ blist.c \ buddyicon.c \ cipher.c \ + circbuffer.c \ cmds.c \ connection.c \ conversation.c \ @@ -97,7 +98,6 @@ dnssrv.c \ eventloop.c \ ft.c \ - gaim_buffer.c \ gtkaccount.c \ gtkblist.c \ gtkconn.c \ Copied: trunk/src/circbuffer.c (from rev 16491, trunk/src/gaim_buffer.c) =================================================================== --- trunk/src/circbuffer.c (rev 0) +++ trunk/src/circbuffer.c 2006-07-16 19:08:31 UTC (rev 16496) @@ -0,0 +1,142 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "internal.h" + +#include "circbuffer.h" + +#define DEFAULT_BUF_SIZE 256 + +GaimCircBuffer * +gaim_circ_buffer_new(gsize growsize) { + GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); + buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; + return buf; +} + +void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { + g_return_if_fail(buf); + g_free(buf->buffer); + g_free(buf); +} + +static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { + int in_offset = 0, out_offset = 0; + int start_buflen = buf->buflen; + + while ((buf->buflen - buf->bufused) < len) + buf->buflen += buf->growsize; + + if (buf->inptr != NULL) { + in_offset = buf->inptr - buf->buffer; + out_offset = buf->outptr - buf->buffer; + } + buf->buffer = g_realloc(buf->buffer, buf->buflen); + + /* adjust the fill and remove pointer locations */ + if (buf->inptr == NULL) { + buf->inptr = buf->outptr = buf->buffer; + } else { + buf->inptr = buf->buffer + in_offset; + buf->outptr = buf->buffer + out_offset; + } + + /* If the fill pointer is wrapped to before the remove + * pointer, we need to shift the data */ + if (in_offset < out_offset) { + int shift_n = MIN(buf->buflen - start_buflen, + in_offset); + memcpy(buf->buffer + start_buflen, buf->buffer, + shift_n); + + /* If we couldn't fit the wrapped read buffer + * at the end */ + if (shift_n < in_offset) { + memmove(buf->buffer, + buf->buffer + shift_n, + in_offset - shift_n); + buf->inptr = buf->buffer + + (in_offset - shift_n); + } else { + buf->inptr = buf->buffer + + start_buflen + in_offset; + } + } +} + +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { + + int len_stored; + + /* Grow the buffer, if necessary */ + if ((buf->buflen - buf->bufused) < len) + grow_circ_buffer(buf, len); + + /* If there is not enough room to copy all of src before hitting + * the end of the buffer then we will need to do two copies. + * One copy from inptr to the end of the buffer, and the + * second copy from the start of the buffer to the end of src. */ + if (buf->inptr >= buf->outptr) + len_stored = MIN(len, buf->buflen + - (buf->inptr - buf->buffer)); + else + len_stored = len; + + memcpy(buf->inptr, src, len_stored); + + if (len_stored < len) { + memcpy(buf->buffer, src + len_stored, len - len_stored); + buf->inptr = buf->buffer + (len - len_stored); + } else if ((buf->buffer - buf->inptr) == len_stored) { + buf->inptr = buf->buffer; + } else { + buf->inptr += len_stored; + } + + buf->bufused += len; +} + +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { + int max_read; + + if (buf->bufused == 0) + max_read = 0; + else if ((buf->outptr - buf->inptr) >= 0) + max_read = buf->buflen - (buf->outptr - buf->buffer); + else + max_read = buf->inptr - buf->outptr; + + return max_read; +} + +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { + g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); + + buf->outptr += len; + buf->bufused -= len; + /* wrap to the start if we're at the end */ + if ((buf->outptr - buf->buffer) == buf->buflen) + buf->outptr = buf->buffer; + + return TRUE; +} + Property changes on: trunk/src/circbuffer.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/src/circbuffer.h (from rev 16491, trunk/src/gaim_buffer.h) =================================================================== --- trunk/src/circbuffer.h (rev 0) +++ trunk/src/circbuffer.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -0,0 +1,117 @@ +/* + * @file circbuffer.h Buffer Utility Functions + * @ingroup core + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _CIRCBUFFER_H +#define _CIRCBUFFER_H + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _GaimCircBuffer { + + /** A pointer to the starting address of our chunk of memory. */ + gchar *buffer; + + /** The incremental amount to increase this buffer by when + * the buffer is not big enough to hold incoming data, in bytes. */ + gsize growsize; + + /** The length of this buffer, in bytes. */ + gsize buflen; + + /** The number of bytes of this buffer that contain unread data. */ + gsize bufused; + + /** A pointer to the next byte where new incoming data is + * buffered to. */ + gchar *inptr; + + /** A pointer to the next byte of buffered data that should be + * read by the consumer. */ + gchar *outptr; + +} GaimCircBuffer; + +/** + * Creates a new circular buffer. This will not allocate any memory for the + * actual buffer until data is appended to it. + * + * @param growsize The amount that the buffer should grow the first time data + * is appended and every time more space is needed. Pass in + * "0" to use the default of 256 bytes. + * + * @return The new GaimCircBuffer. This should be freed with + * gaim_circ_buffer_destroy when you are done with it + */ +GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); + +/** + * Dispose of the GaimCircBuffer and free any memory used by it (including any + * memory used by the internal buffer). + * + * @param buf The GaimCircBuffer to free + */ +void gaim_circ_buffer_destroy(GaimCircBuffer *buf); + +/** + * Append data to the GaimCircBuffer. This will grow the internal + * buffer to fit the added data, if needed. + * + * @param buf The GaimCircBuffer to which to append the data + * @param src pointer to the data to copy into the buffer + * @param len number of bytes to copy into the buffer + */ +void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); + +/** + * Determine the maximum number of contiguous bytes that can be read from the + * GaimCircBuffer. + * Note: This may not be the total number of bytes that are buffered - a + * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more + * data is available to read. + * + * @param buf the GaimCircBuffer for which to determine the maximum contiguous + * bytes that can be read. + * + * @return the number of bytes that can be read from the GaimCircBuffer + */ +gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); + +/** + * Mark the number of bytes that have been read from the buffer. + * + * @param buf The GaimCircBuffer to mark bytes read from + * @param len The number of bytes to mark as read + * + * @return TRUE if we successfully marked the bytes as having been read, FALSE + * otherwise. + */ +gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); + +#ifdef __cplusplus +} +#endif + +#endif /* _CIRCBUFFER_H */ Property changes on: trunk/src/circbuffer.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Deleted: trunk/src/gaim_buffer.c =================================================================== --- trunk/src/gaim_buffer.c 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/gaim_buffer.c 2006-07-16 19:08:31 UTC (rev 16496) @@ -1,142 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "internal.h" - -#include "gaim_buffer.h" - -#define DEFAULT_BUF_SIZE 256 - -GaimCircBuffer * -gaim_circ_buffer_new(gsize growsize) { - GaimCircBuffer *buf = g_new0(GaimCircBuffer, 1); - buf->growsize = growsize ? growsize : DEFAULT_BUF_SIZE; - return buf; -} - -void gaim_circ_buffer_destroy(GaimCircBuffer *buf) { - g_return_if_fail(buf); - g_free(buf->buffer); - g_free(buf); -} - -static void grow_circ_buffer(GaimCircBuffer *buf, gsize len) { - int in_offset = 0, out_offset = 0; - int start_buflen = buf->buflen; - - while ((buf->buflen - buf->bufused) < len) - buf->buflen += buf->growsize; - - if (buf->inptr != NULL) { - in_offset = buf->inptr - buf->buffer; - out_offset = buf->outptr - buf->buffer; - } - buf->buffer = g_realloc(buf->buffer, buf->buflen); - - /* adjust the fill and remove pointer locations */ - if (buf->inptr == NULL) { - buf->inptr = buf->outptr = buf->buffer; - } else { - buf->inptr = buf->buffer + in_offset; - buf->outptr = buf->buffer + out_offset; - } - - /* If the fill pointer is wrapped to before the remove - * pointer, we need to shift the data */ - if (in_offset < out_offset) { - int shift_n = MIN(buf->buflen - start_buflen, - in_offset); - memcpy(buf->buffer + start_buflen, buf->buffer, - shift_n); - - /* If we couldn't fit the wrapped read buffer - * at the end */ - if (shift_n < in_offset) { - memmove(buf->buffer, - buf->buffer + shift_n, - in_offset - shift_n); - buf->inptr = buf->buffer + - (in_offset - shift_n); - } else { - buf->inptr = buf->buffer + - start_buflen + in_offset; - } - } -} - -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len) { - - int len_stored; - - /* Grow the buffer, if necessary */ - if ((buf->buflen - buf->bufused) < len) - grow_circ_buffer(buf, len); - - /* If there is not enough room to copy all of src before hitting - * the end of the buffer then we will need to do two copies. - * One copy from inptr to the end of the buffer, and the - * second copy from the start of the buffer to the end of src. */ - if (buf->inptr >= buf->outptr) - len_stored = MIN(len, buf->buflen - - (buf->inptr - buf->buffer)); - else - len_stored = len; - - memcpy(buf->inptr, src, len_stored); - - if (len_stored < len) { - memcpy(buf->buffer, src + len_stored, len - len_stored); - buf->inptr = buf->buffer + (len - len_stored); - } else if ((buf->buffer - buf->inptr) == len_stored) { - buf->inptr = buf->buffer; - } else { - buf->inptr += len_stored; - } - - buf->bufused += len; -} - -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf) { - int max_read; - - if (buf->bufused == 0) - max_read = 0; - else if ((buf->outptr - buf->inptr) >= 0) - max_read = buf->buflen - (buf->outptr - buf->buffer); - else - max_read = buf->inptr - buf->outptr; - - return max_read; -} - -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len) { - g_return_val_if_fail(gaim_circ_buffer_get_max_read(buf) >= len, FALSE); - - buf->outptr += len; - buf->bufused -= len; - /* wrap to the start if we're at the end */ - if ((buf->outptr - buf->buffer) == buf->buflen) - buf->outptr = buf->buffer; - - return TRUE; -} - Deleted: trunk/src/gaim_buffer.h =================================================================== --- trunk/src/gaim_buffer.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/gaim_buffer.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -1,115 +0,0 @@ -/* - * @file gaim_buffer.h Buffer Utility Functions - * @ingroup core - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _GAIM_BUFFER_H -#define _GAIM_BUFFER_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _GaimCircBuffer { - - /** A pointer to the starting address of our chunk of memory. */ - gchar *buffer; - - /** The incremental amount to increase this buffer by when - * the buffer is not big enough to hold incoming data, in bytes. */ - gsize growsize; - - /** The length of this buffer, in bytes. */ - gsize buflen; - - /** The number of bytes of this buffer that contain unread data. */ - gsize bufused; - - /** A pointer to the next byte where new incoming data is - * buffered to. */ - gchar *inptr; - - /** A pointer to the next byte of buffered data that should be - * read by the consumer. */ - gchar *outptr; - -} GaimCircBuffer; - -/** - * Creates a new circular buffer. This will not allocate any memory for the - * actual buffer until data is appended to it. - * - * @param growsize The amount that the buffer should grow the first time data - * is appended and every time more space is needed. Pass in - * "0" to use the default of 256 bytes. - * - * @return The new GaimCircBuffer. This should be freed with - * gaim_circ_buffer_destroy when you are done with it - */ -GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); - -/** - * Dispose of the GaimCircBuffer and free any memory used by it (including any - * memory used by the internal buffer). - * - * @param buf The GaimCircBuffer to free - */ -void gaim_circ_buffer_destroy(GaimCircBuffer *buf); - -/** - * Append data to the GaimCircBuffer. This will grow the internal - * buffer to fit the added data, if needed. - * - * @param buf The GaimCircBuffer to which to append the data - * @param src pointer to the data to copy into the buffer - * @param len number of bytes to copy into the buffer - */ -void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); - -/** - * Determine the maximum number of contiguous bytes that can be read from the - * GaimCircBuffer. - * Note: This may not be the total number of bytes that are buffered - a - * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more - * data is available to read. - * - * @param buf the GaimCircBuffer for which to determine the maximum contiguous - * bytes that can be read. - * - * @return the number of bytes that can be read from the GaimCircBuffer - */ -gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); - -/** - * Mark the number of bytes that have been read from the buffer. - * - * @param buf The GaimCircBuffer to mark bytes read from - * @param len The number of bytes to mark as read - * - * @return TRUE if we successfully marked the bytes as having been read, FALSE - * otherwise. - */ -gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); - -#ifdef __cplusplus -} -#endif - -#endif /* _GAIM_BUFFER_H */ Modified: trunk/src/protocols/irc/irc.h =================================================================== --- trunk/src/protocols/irc/irc.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/irc/irc.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -25,8 +25,8 @@ #include <glib.h> +#include "circbuffer.h" #include "ft.h" -#include "gaim_buffer.h" #include "roomlist.h" #include "sslconn.h" Modified: trunk/src/protocols/jabber/jabber.h =================================================================== --- trunk/src/protocols/jabber/jabber.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/jabber/jabber.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -26,10 +26,10 @@ #include <libxml/parser.h> #endif #include <glib.h> +#include "circbuffer.h" #include "connection.h" #include "roomlist.h" #include "sslconn.h" -#include "gaim_buffer.h" #include "jutil.h" #include "xmlnode.h" Modified: trunk/src/protocols/msn/httpconn.h =================================================================== --- trunk/src/protocols/msn/httpconn.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/msn/httpconn.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -26,8 +26,8 @@ typedef struct _MsnHttpConn MsnHttpConn; +#include "circbuffer.h" #include "servconn.h" -#include "gaim_buffer.h" /** * An HTTP Connection. Modified: trunk/src/protocols/oscar/oscar.h =================================================================== --- trunk/src/protocols/oscar/oscar.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/oscar/oscar.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -29,9 +29,9 @@ #ifndef _OSCAR_H_ #define _OSCAR_H_ +#include "circbuffer.h" #include "debug.h" #include "eventloop.h" -#include "gaim_buffer.h" #include "internal.h" #include <stdio.h> Modified: trunk/src/protocols/sametime/sametime.c =================================================================== --- trunk/src/protocols/sametime/sametime.c 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/sametime/sametime.c 2006-07-16 19:08:31 UTC (rev 16496) @@ -32,25 +32,25 @@ #include <glib/glist.h> /* gaim includes */ -#include <internal.h> -#include <gaim.h> -#include <config.h> +#include "internal.h" +#include "gaim.h" +#include "config.h" -#include <account.h> -#include <accountopt.h> -#include <conversation.h> -#include <debug.h> -#include <ft.h> -#include <gaim_buffer.h> -#include <imgstore.h> -#include <mime.h> -#include <notify.h> -#include <plugin.h> -#include <privacy.h> -#include <prpl.h> -#include <request.h> -#include <util.h> -#include <version.h> +#include "account.h" +#include "accountopt.h" +#include "circbuffer.h" +#include "conversation.h" +#include "debug.h" +#include "ft.h" +#include "imgstore.h" +#include "mime.h" +#include "notify.h" +#include "plugin.h" +#include "privacy.h" +#include "prpl.h" +#include "request.h" +#include "util.h" +#include "version.h" /* meanwhile includes */ #include <mw_cipher.h> Modified: trunk/src/protocols/simple/simple.h =================================================================== --- trunk/src/protocols/simple/simple.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/simple/simple.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -26,9 +26,9 @@ #include <glib.h> #include <time.h> -#include <cipher.h> -#include <gaim_buffer.h> -#include <prpl.h> +#include "cipher.h" +#include "circbuffer.h" +#include "prpl.h" #include "sipmsg.h" Modified: trunk/src/protocols/yahoo/yahoo.h =================================================================== --- trunk/src/protocols/yahoo/yahoo.h 2006-07-16 16:59:27 UTC (rev 16495) +++ trunk/src/protocols/yahoo/yahoo.h 2006-07-16 19:08:31 UTC (rev 16496) @@ -25,8 +25,8 @@ #ifndef _YAHOO_H_ #define _YAHOO_H_ +#include "circbuffer.h" #include "prpl.h" -#include "gaim_buffer.h" #define YAHOO_PAGER_HOST "scs.msg.yahoo.com" #define YAHOO_PAGER_PORT 5050 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |