00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include <config.h>
00024 #endif
00025
00026 #include "intl.h"
00027 #include <string.h>
00028
00029 #include "status.h"
00030 #include "globals.h"
00031 #include "util.h"
00032 #include "dialog.h"
00033 #include "add_contact_window.h"
00034
00035 #include "pixmaps/tb_preferences.xpm"
00036 #include "pixmaps/cancel.xpm"
00037
00038
00039
00040
00041
00042
00043
00044 static gint window_open = 0;
00045 static GtkWidget *add_contact_window;
00046 static GtkWidget *service_list;
00047 static GtkWidget *account_name;
00048 static GtkWidget *contact_name;
00049 static GtkWidget *group_name;
00050 static int flag;
00051 static int contact_input_handler;
00052
00053 #define COMBO_TEXT(x) gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(x)->entry))
00054
00055 static void destroy(GtkWidget *widget, gpointer data)
00056 {
00057 window_open = 0;
00058 }
00059
00060 static gint strcasecmp_glist(gconstpointer a, gconstpointer b)
00061 {
00062 return strcasecmp((const char *)a, (const char *)b);
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 GList * get_groups()
00072 {
00073 GList * node = NULL;
00074 GList * newlist = NULL;
00075 node = groups;
00076
00077 while(node) {
00078 newlist = g_list_append(newlist, ((grouplist *)node->data)->name);
00079 node = node->next;
00080 }
00081
00082 return newlist;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 static GList * get_contacts(gchar *group)
00092 {
00093 GList *node = NULL, *newlist = NULL;
00094 grouplist *g;
00095
00096 g = find_grouplist_by_name(group);
00097
00098 if(g)
00099 node = g->members;
00100
00101 while(node) {
00102 newlist = g_list_insert_sorted(newlist, ((struct contact *)node->data)->nick, strcasecmp_glist);
00103 node = node->next;
00104 }
00105
00106 return newlist;
00107 }
00108
00109 GList * get_all_contacts()
00110 {
00111 GList *node = get_groups();
00112 GList *newlist = NULL;
00113
00114 while(node) {
00115 GList * g = get_contacts(node->data);
00116 newlist = g_list_concat(newlist, g);
00117 node = node->next;
00118 }
00119
00120 return newlist;
00121 }
00122
00123
00124
00125
00126
00127 GList * get_accounts(gchar *contact)
00128 {
00129 GList *node = NULL, *newlist = NULL;
00130 struct contact * c;
00131
00132 c = find_contact_by_nick(contact);
00133
00134 if(c)
00135 node = c->accounts;
00136
00137 while(node) {
00138 newlist = g_list_append(newlist, ((eb_account *)node->data)->handle);
00139 node = node->next;
00140 }
00141
00142 return newlist;
00143 }
00144
00145 GList * get_eb_accounts(gchar *contact)
00146 {
00147 GList *node = NULL, *newlist = NULL;
00148 struct contact * c;
00149
00150 c = find_contact_by_nick(contact);
00151
00152 if(c)
00153 node = c->accounts;
00154
00155 while(node) {
00156 newlist = g_list_append(newlist, ((eb_account *)node->data));
00157 node = node->next;
00158 }
00159
00160 return newlist;
00161 }
00162
00163 GList * get_all_accounts(int serviceid)
00164 {
00165 GList *node = get_all_contacts();
00166 GList *newlist = NULL;
00167
00168 while(node) {
00169 GList * g = get_eb_accounts(((struct contact*)node->data)->nick);
00170 while (g) {
00171 eb_account *ac = (eb_account *)g->data;
00172 if (ac->service_id == serviceid)
00173 newlist = g_list_append(newlist, ac->handle);
00174 g = g->next;
00175 }
00176 node = node->next;
00177 }
00178
00179 return newlist;
00180 }
00181
00182 void dif_group(GtkEditable *editable, gpointer user_data)
00183 {
00184 GList * list = get_contacts(COMBO_TEXT(group_name));
00185 gtk_signal_handler_block(GTK_OBJECT(GTK_COMBO(contact_name)->entry),
00186 contact_input_handler);
00187 gtk_combo_set_popdown_strings(GTK_COMBO(contact_name), list);
00188 g_list_free(list);
00189 gtk_signal_handler_unblock(GTK_OBJECT(GTK_COMBO(contact_name)->entry),
00190 contact_input_handler);
00191 }
00192
00193
00194
00195 void set_con(GtkEditable *editable, gpointer user_data)
00196 {
00197 if(flag == 0){
00198 gtk_signal_handler_block(GTK_OBJECT(GTK_COMBO(contact_name)->entry),
00199 contact_input_handler);
00200 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(contact_name)->entry),
00201 gtk_entry_get_text(GTK_ENTRY(account_name)));
00202 gtk_signal_handler_unblock(GTK_OBJECT(GTK_COMBO(contact_name)->entry),
00203 contact_input_handler);
00204 }
00205 }
00206
00207
00208
00209 void con_modified(GtkEditable *editable, gpointer user_data)
00210 {
00211 flag = 1;
00212 }
00213
00214 void add_button_callback(GtkButton *button, gpointer userdata)
00215 {
00216 grouplist *gl;
00217 struct contact *con;
00218 gchar *service = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(service_list)->entry));
00219 gchar *account = gtk_entry_get_text(GTK_ENTRY(account_name));
00220
00221 gint service_id = get_service_id( service );
00222
00223 eb_account *ea = eb_services[service_id].sc->new_account(account);
00224 ea->service_id = service_id;
00225
00226 if (eb_services[service_id].sc->check_login) {
00227 char *buf = NULL;
00228 char *err = eb_services[service_id].sc->check_login((char *)account, (char *)"");
00229 if (err != NULL) {
00230 buf = g_strdup_printf(_("The account is not syntaxically correct:\n%s"), err);
00231 g_free(err);
00232 do_error_dialog(buf, _("Error"));
00233 g_free(buf);
00234 return;
00235 }
00236 }
00237 gl = find_grouplist_by_name(COMBO_TEXT(group_name));
00238 con = find_contact_by_nick(COMBO_TEXT(contact_name));
00239
00240 if(!gl) {
00241 add_group(COMBO_TEXT(group_name));
00242 gl = find_grouplist_by_name(COMBO_TEXT(group_name));
00243 }
00244
00245 if(!con) {
00246 con = add_new_contact(COMBO_TEXT(group_name), COMBO_TEXT(contact_name), ea->service_id);
00247 }
00248
00249 add_account(con->nick, ea);
00250 update_contact_list ();
00251 write_contact_list();
00252 gtk_widget_destroy(add_contact_window);
00253 }
00254
00255
00256
00257
00258
00259 void show_add_defined_contact_window(struct contact * cont, grouplist *grp)
00260 {
00261
00262
00263
00264
00265
00266 if(!window_open) {
00267 GtkWidget *hbox;
00268 GtkWidget *hbox2;
00269 GtkWidget *vbox;
00270 GtkWidget *label;
00271 GtkWidget *button;
00272 GtkWidget *iconwid;
00273 GtkWidget *table;
00274 GtkWidget *frame;
00275 GtkWidget *separator;
00276 GList *list;
00277 GdkPixmap *icon;
00278 GdkBitmap *mask;
00279
00280 add_contact_window = gtk_window_new(GTK_WINDOW_DIALOG);
00281 gtk_window_set_position(GTK_WINDOW(add_contact_window), GTK_WIN_POS_MOUSE);
00282 gtk_widget_realize(add_contact_window);
00283 gtk_container_set_border_width(GTK_CONTAINER(add_contact_window), 5);
00284
00285 table = gtk_table_new(2, 4, FALSE);
00286 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
00287 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
00288 gtk_container_set_border_width(GTK_CONTAINER(table), 5);
00289 vbox = gtk_vbox_new(FALSE, 5);
00290 hbox = gtk_hbox_new(FALSE, 0);
00291
00292
00293
00294 label = gtk_label_new(_("Account:"));
00295 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 5);
00296 gtk_widget_show(label);
00297 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00298 gtk_widget_show(hbox);
00299
00300 account_name = gtk_entry_new();
00301 if (cont == NULL)
00302 gtk_signal_connect(GTK_OBJECT(GTK_ENTRY(account_name)), "changed",
00303 GTK_SIGNAL_FUNC(set_con), NULL);
00304 gtk_table_attach(GTK_TABLE(table), account_name, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
00305 gtk_widget_show(account_name);
00306
00307
00308
00309 hbox = gtk_hbox_new(FALSE, 0);
00310
00311 label = gtk_label_new(_("Protocol:"));
00312 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 5);
00313 gtk_widget_show(label);
00314 gtk_table_attach(GTK_TABLE(table), hbox, 2, 3, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00315 gtk_widget_show(hbox);
00316
00317
00318
00319 service_list = gtk_combo_new();
00320 list = get_service_list();
00321 gtk_combo_set_popdown_strings(GTK_COMBO(service_list), list );
00322 g_list_free(list);
00323 gtk_table_attach(GTK_TABLE(table), service_list, 3, 4, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00324 gtk_widget_show(service_list);
00325
00326
00327
00328 hbox = gtk_hbox_new(FALSE, 0);
00329
00330 label = gtk_label_new(_("Group:"));
00331 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00332 gtk_widget_show(label);
00333 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00334 gtk_widget_show(hbox);
00335
00336
00337
00338 group_name = gtk_combo_new();
00339 list = get_groups();
00340 gtk_combo_set_popdown_strings(GTK_COMBO(group_name), list );
00341
00342 if(strlen(COMBO_TEXT(group_name)) == 0) {
00343 if(cont != NULL)
00344 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group_name)->entry), cont->group->name);
00345 else if (grp != NULL)
00346 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group_name)->entry), grp->name);
00347 else
00348 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group_name)->entry), _("Buddies"));
00349 } else if(cont != NULL) {
00350 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group_name)->entry), cont->group->name);
00351 } else if (grp != NULL) {
00352 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group_name)->entry), grp->name);
00353 }
00354 g_list_free(list);
00355 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(group_name)->entry), "changed",
00356 GTK_SIGNAL_FUNC(dif_group), NULL);
00357 gtk_table_attach(GTK_TABLE(table), group_name, 1, 2, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00358 gtk_widget_show(group_name);
00359
00360
00361
00362 hbox = gtk_hbox_new(FALSE, 0);
00363
00364 label = gtk_label_new(_("Contact:"));
00365 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 5);
00366 gtk_widget_show(label);
00367 gtk_table_attach(GTK_TABLE(table), hbox, 2, 3, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00368 gtk_widget_show(hbox);
00369
00370
00371
00372 contact_name = gtk_combo_new();
00373 list = get_all_contacts();
00374 gtk_combo_set_popdown_strings(GTK_COMBO(contact_name), list );
00375 if(cont != NULL)
00376 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(contact_name)->entry), cont->nick);
00377 else
00378 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(contact_name)->entry), "");
00379 g_list_free(list);
00380 contact_input_handler = gtk_signal_connect(GTK_OBJECT(GTK_ENTRY(GTK_COMBO(contact_name)->entry)), "changed",
00381 GTK_SIGNAL_FUNC(con_modified), NULL);
00382 gtk_table_attach(GTK_TABLE(table), contact_name, 3, 4, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00383 gtk_widget_show(contact_name);
00384
00385
00386
00387 frame = gtk_frame_new(NULL);
00388 gtk_frame_set_label(GTK_FRAME(frame), _("Add Contact"));
00389
00390 gtk_container_add(GTK_CONTAINER(frame), table);
00391 gtk_widget_show(table);
00392
00393 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
00394 gtk_widget_show(frame);
00395
00396
00397
00398 separator = gtk_hseparator_new();
00399 gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 5);
00400 gtk_widget_show(separator);
00401
00402 hbox = gtk_hbox_new(FALSE, 5);
00403 hbox2 = gtk_hbox_new(TRUE, 5);
00404
00405
00406
00407 gtk_widget_set_usize(hbox2, 200,25);
00408
00409 icon = gdk_pixmap_create_from_xpm_d(add_contact_window->window, &mask, NULL, tb_preferences_xpm);
00410 iconwid = gtk_pixmap_new(icon, mask);
00411 label = gtk_label_new(_("Add"));
00412
00413 gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00414 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00415
00416 gtk_widget_show(iconwid);
00417 gtk_widget_show(label);
00418
00419 button = gtk_button_new();
00420
00421 gtk_signal_connect(GTK_OBJECT(button), "clicked",
00422 GTK_SIGNAL_FUNC(add_button_callback),
00423 NULL);
00424 gtk_widget_show(hbox);
00425
00426 gtk_container_add(GTK_CONTAINER(button), hbox);
00427
00428 gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 0);
00429 gtk_widget_show(button);
00430
00431
00432
00433 hbox = gtk_hbox_new(FALSE, 5);
00434 icon = gdk_pixmap_create_from_xpm_d(add_contact_window->window, &mask, NULL, cancel_xpm);
00435 iconwid = gtk_pixmap_new(icon, mask);
00436 label = gtk_label_new(_("Cancel"));
00437
00438 gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00439 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00440
00441 gtk_widget_show(iconwid);
00442 gtk_widget_show(label);
00443
00444 button = gtk_button_new();
00445
00446 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
00447 GTK_SIGNAL_FUNC(gtk_widget_destroy),
00448 GTK_OBJECT(add_contact_window));
00449 gtk_widget_show(hbox);
00450
00451 gtk_container_add(GTK_CONTAINER (button), hbox);
00452
00453 gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 0);
00454 gtk_widget_show(button);
00455
00456
00457
00458 hbox = gtk_hbox_new(FALSE, 0);
00459 table = gtk_table_new(1, 1, FALSE);
00460
00461 gtk_box_pack_end(GTK_BOX(hbox),hbox2, FALSE, FALSE, 0);
00462 gtk_widget_show(hbox2);
00463
00464 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00465 gtk_widget_show(hbox);
00466
00467 gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00468 gtk_widget_show(vbox);
00469
00470 gtk_container_add(GTK_CONTAINER(add_contact_window), table);
00471 gtk_widget_show(table);
00472
00473 gtk_window_set_title(GTK_WINDOW(add_contact_window), _("Yattm - Add Contact"));
00474 gtk_window_set_focus(GTK_WINDOW(add_contact_window), account_name);
00475 eb_icon(add_contact_window->window);
00476 gtk_widget_show(add_contact_window);
00477
00478 gtk_signal_connect(GTK_OBJECT(add_contact_window), "destroy",
00479 GTK_SIGNAL_FUNC(destroy), NULL);
00480
00481 window_open = 1;
00482 }
00483 }
00484
00485 void show_add_contact_window()
00486 {
00487 show_add_defined_contact_window(NULL, NULL);
00488 }
00489
00490 void show_add_contact_to_group_window(grouplist *g)
00491 {
00492 show_add_defined_contact_window(NULL, g);
00493 }
00494
00495 void show_add_group_window()
00496 {
00497 edit_group_window_new(NULL);
00498 }
00499
00500 void show_add_account_to_contact_window(struct contact * cont)
00501 {
00502 show_add_defined_contact_window(cont, NULL);
00503 }