Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

edit_account_window.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 "util.h"
00031 #include "globals.h"
00032 #include "dialog.h"
00033 
00034 #include "pixmaps/tb_preferences.xpm"
00035 #include "pixmaps/cancel.xpm"
00036 
00037 static gint window_open = 0;
00038 static eb_account *account;
00039 static GtkWidget *edit_account_window;
00040 static GtkWidget *nick;
00041 static GtkWidget *group;
00042 
00043 #define COMBO_TEXT(x) gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(x)->entry))
00044 
00045 static void destroy(GtkWidget *widget, gpointer data)
00046 {
00047     window_open = 0;
00048 }
00049 
00050 static void ok_callback(GtkWidget *widget, gpointer data)
00051 {
00052     grouplist *gl;
00053     struct contact *con;
00054 
00055     gl = find_grouplist_by_name(COMBO_TEXT(group));
00056 
00057     if(!gl)
00058     {
00059         add_group(COMBO_TEXT(group));
00060         gl = find_grouplist_by_name(COMBO_TEXT(group));
00061     }
00062 
00063     con = find_contact_in_group_by_nick(COMBO_TEXT(nick), gl);
00064 
00065     if(!con)
00066     {
00067         con = add_new_contact(COMBO_TEXT(group), COMBO_TEXT(nick), account->service_id);
00068     }
00069 
00070     if(!account->account_contact)
00071         add_account(con->nick, account);
00072     else
00073         move_account(con, account);
00074 
00075     update_contact_list();
00076     write_contact_list();
00077     gtk_widget_destroy(edit_account_window);
00078 }
00079 
00080 static gint strcasecmp_glist(gconstpointer a, gconstpointer b)
00081 {
00082     return strcasecmp((const char *)a, (const char *)b);
00083 }
00084 
00085 static GList * get_groups()
00086 {
00087     GList * node = NULL;
00088     GList * newlist = NULL;
00089     node = groups;
00090 
00091     while(node)
00092     {
00093     newlist = g_list_append(newlist, ((grouplist *)node->data)->name);
00094     node = node->next;
00095     }
00096 
00097     return newlist;
00098 }
00099 
00100 static GList * get_contacts(gchar * group)
00101 {
00102     GList * node = NULL, *newlist = NULL;
00103     grouplist * g;
00104 
00105     g = find_grouplist_by_name(group);
00106 
00107     if(g)
00108     node = g->members;
00109 
00110     while(node)
00111     {
00112     newlist = g_list_insert_sorted(newlist, ((struct contact *)node->data)->nick, strcasecmp_glist);
00113     node = node->next;
00114     }
00115 
00116     return newlist;
00117 }
00118 
00119 
00120 static void  group_changed(GtkEditable *editable, gpointer user_data)
00121 {
00122     GList * list = get_contacts(COMBO_TEXT(group));
00123     gtk_combo_set_popdown_strings(GTK_COMBO(nick), list );
00124     g_list_free(list);
00125 
00126     if(account->account_contact)
00127         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(nick)->entry), 
00128                 account->account_contact->nick);
00129     else
00130         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(nick)->entry), 
00131                 account->handle);
00132 }
00133 
00134 void draw_edit_account_window(eb_account *ea, char *window_title, char *frame_title, char *add_label)
00135 {
00136     gchar buff[1024];
00137     static GtkWidget *frame;
00138 
00139     account = ea;
00140 
00141     if(!window_open)
00142     {
00143         GtkWidget *vbox;
00144         GtkWidget *hbox;
00145         GtkWidget *hbox2;
00146         GtkWidget *label;
00147         GtkWidget *button;
00148         GtkWidget *iconwid;
00149         GtkWidget *table;
00150         GtkWidget *separator;
00151         GList *list;
00152         GdkPixmap *icon;
00153         GdkBitmap *mask;    
00154 
00155         edit_account_window = gtk_window_new(GTK_WINDOW_DIALOG);
00156         gtk_window_set_position(GTK_WINDOW(edit_account_window), GTK_WIN_POS_MOUSE);
00157         gtk_widget_realize(edit_account_window);
00158         gtk_container_set_border_width(GTK_CONTAINER(edit_account_window), 5);
00159 
00160         table = gtk_table_new(2, 2, FALSE);
00161         gtk_table_set_row_spacings(GTK_TABLE(table), 5);
00162         gtk_table_set_row_spacings(GTK_TABLE(table), 5);
00163         gtk_container_set_border_width(GTK_CONTAINER(table), 5);
00164         hbox = gtk_hbox_new(FALSE, 5);
00165         vbox = gtk_vbox_new(FALSE, 5);
00166 
00167         /*Entry for Group Name*/
00168 
00169         label = gtk_label_new(_("Group Name:"));
00170         gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 5);
00171         gtk_widget_show(label);
00172         gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00173         gtk_widget_show(hbox);
00174 
00175         group = gtk_combo_new();
00176         list = get_groups();
00177         gtk_combo_set_popdown_strings(GTK_COMBO(group), list);
00178 
00179         g_list_free(list);
00180         gtk_signal_connect(GTK_OBJECT(GTK_COMBO(group)->entry), "changed",
00181                 GTK_SIGNAL_FUNC(group_changed), NULL);
00182         gtk_table_attach(GTK_TABLE(table), group, 1, 2, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00183         gtk_widget_show(group);
00184 
00185         /*Entry for Contact Name*/
00186 
00187         hbox = gtk_hbox_new(FALSE, 5);
00188 
00189         label = gtk_label_new(_("Contact Name:"));
00190         gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 5);
00191         gtk_widget_show(label);
00192         gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00193         gtk_widget_show(hbox);
00194 
00195         nick = gtk_combo_new();
00196         list = get_contacts(COMBO_TEXT(group));
00197         gtk_combo_set_popdown_strings(GTK_COMBO(nick), list);
00198         g_list_free(list);
00199         gtk_table_attach(GTK_TABLE(table), nick, 1, 2, 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
00200         gtk_widget_show(nick);
00201 
00202         /*Lets create the frame to put this in*/
00203 
00204         frame = gtk_frame_new(NULL);
00205 
00206         gtk_container_add(GTK_CONTAINER(frame), table);
00207         gtk_widget_show(table);
00208 
00209         gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
00210         gtk_widget_show(frame);
00211 
00212         hbox = gtk_hbox_new(FALSE, 5);
00213         hbox2 = gtk_hbox_new(TRUE, 5);
00214         gtk_widget_set_usize(hbox2, 200,25 );
00215 
00216         /*Lets try adding a seperator*/
00217 
00218         separator = gtk_hseparator_new();
00219         gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 5);
00220         gtk_widget_show(separator);
00221 
00222         /*Add Button*/
00223 
00224         icon = gdk_pixmap_create_from_xpm_d(edit_account_window->window, &mask, NULL, tb_preferences_xpm);
00225         iconwid = gtk_pixmap_new(icon, mask);
00226         label = gtk_label_new(add_label);
00227 
00228         gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00229         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00230 
00231         gtk_widget_show(iconwid);
00232         gtk_widget_show(label);
00233 
00234         button = gtk_button_new();
00235 
00236         gtk_signal_connect(GTK_OBJECT(button), "clicked",
00237                 GTK_SIGNAL_FUNC(ok_callback), NULL);
00238         gtk_widget_show(hbox);
00239 
00240         gtk_container_add(GTK_CONTAINER (button), hbox);
00241 
00242         gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 0);
00243         gtk_widget_show(button);
00244 
00245         /*Cancel Button*/
00246 
00247         hbox = gtk_hbox_new(FALSE, 5);
00248         icon = gdk_pixmap_create_from_xpm_d(edit_account_window->window, &mask, NULL, cancel_xpm);
00249         iconwid = gtk_pixmap_new(icon, mask);
00250         label = gtk_label_new(_("Cancel"));
00251 
00252         gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00253         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00254 
00255         gtk_widget_show(iconwid);
00256         gtk_widget_show(label);
00257 
00258         button = gtk_button_new();
00259 
00260         gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
00261                 GTK_SIGNAL_FUNC(gtk_widget_destroy),
00262                 GTK_OBJECT(edit_account_window));
00263         gtk_widget_show(hbox);
00264 
00265         gtk_container_add(GTK_CONTAINER (button), hbox);
00266 
00267         gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 0);
00268         gtk_widget_show(button);
00269 
00270         /*Buttons End*/
00271 
00272         hbox = gtk_hbox_new(FALSE, 0);
00273         table = gtk_table_new(1, 1, FALSE);
00274 
00275         gtk_box_pack_end(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0);
00276         gtk_widget_show(hbox2);
00277 
00278         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00279         gtk_widget_show(hbox);
00280 
00281         gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
00282         gtk_widget_show(vbox);
00283 
00284         gtk_container_add(GTK_CONTAINER (edit_account_window), table);
00285         gtk_widget_show(table);
00286 
00287         gtk_signal_connect(GTK_OBJECT(edit_account_window), "destroy",
00288                 GTK_SIGNAL_FUNC(destroy), NULL);
00289         gtk_widget_show(edit_account_window);
00290     }
00291 
00292     if(account->account_contact) {
00293         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group)->entry), 
00294                 account->account_contact->group->name);
00295         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(nick)->entry), 
00296                 account->account_contact->nick);
00297     } else {
00298         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(group)->entry), 
00299                 _("Unknown"));
00300         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(nick)->entry), 
00301                 account->handle);
00302     }
00303     
00304     gtk_frame_set_label(GTK_FRAME(frame), frame_title);
00305 
00306     g_snprintf(buff, 1024, window_title, account->handle);
00307     gtk_window_set_title(GTK_WINDOW(edit_account_window), buff);
00308     eb_icon(edit_account_window->window);
00309 
00310     window_open = 1;
00311 }
00312 
00313 void add_unknown_account_window_new(eb_account *ea)
00314 {
00315     draw_edit_account_window(ea, _("Add %s to Contact List"), _("Add Unknown Contact"), _("Add"));
00316 }
00317 
00318 void edit_account_window_new(eb_account *ea)
00319 {
00320     if(!strcmp(ea->account_contact->group->name, _("Unknown")))
00321         add_unknown_account_window_new(ea);
00322     else
00323         draw_edit_account_window(ea, _("Edit %s"), _("Edit Account"), _("Save"));
00324 }
00325 

Contact: Andy Maloney     [Documentation generated by doxygen]