Use macros instead of raw numbers for login type
[rofl0r-ixchat.git] / src / fe-gtk / servlistgui.c
blob282afaa650782b83c270c7f6a3ab855f789d52bf
1 /* X-Chat
2 * Copyright (C) 2004-2008 Peter Zelezny.
3 */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <ctype.h>
10 #include <gtk/gtkversion.h>
11 #include <gtk/gtkcheckbutton.h>
12 #include <gtk/gtkcellrenderertext.h>
13 #include <gtk/gtkcomboboxentry.h>
14 #include <gtk/gtkentry.h>
15 #include <gtk/gtkhbox.h>
16 #include <gtk/gtkhbbox.h>
17 #include <gtk/gtkhseparator.h>
18 #include <gtk/gtkimage.h>
19 #include <gtk/gtklabel.h>
20 #include <gtk/gtkliststore.h>
21 #include <gtk/gtkmenuitem.h>
22 #include <gtk/gtkmessagedialog.h>
23 #include <gtk/gtkscrolledwindow.h>
24 #include <gtk/gtkstock.h>
25 #include <gtk/gtktable.h>
26 #include <gtk/gtktogglebutton.h>
27 #include <gtk/gtktree.h>
28 #include <gtk/gtktreeselection.h>
29 #include <gtk/gtktreeview.h>
30 #include <gtk/gtkvbbox.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkwindow.h>
33 #include <gdk/gdkkeysyms.h>
35 #include "../common/xchat.h"
36 #include "../common/xchatc.h"
37 #include "../common/servlist.h"
38 #include "../common/cfgfiles.h"
39 #include "../common/fe.h"
41 #include "fe-gtk.h"
42 #include "gtkutil.h"
43 #include "menu.h"
44 #include "pixmaps.h"
47 /* servlistgui.c globals */
48 static GtkWidget *serverlist_win = NULL;
49 static GtkWidget *networks_tree; /* network TreeView */
50 static int ignore_changed = FALSE;
51 static int win_width = 364;
52 static int win_height = 478;
54 /* global user info */
55 static GtkWidget *entry_nick1;
56 static GtkWidget *entry_nick2;
57 static GtkWidget *entry_nick3;
58 static GtkWidget *entry_guser;
59 static GtkWidget *entry_greal;
61 /* edit area */
62 static GtkWidget *edit_win;
63 static GtkWidget *edit_entry_nick;
64 static GtkWidget *edit_entry_nick2;
65 static GtkWidget *edit_entry_user;
66 static GtkWidget *edit_entry_real;
67 static GtkWidget *edit_entry_join;
68 static GtkWidget *edit_entry_pass;
69 static GtkWidget *edit_entry_cmd;
70 static GtkWidget *edit_label_nick;
71 static GtkWidget *edit_label_nick2;
72 static GtkWidget *edit_label_real;
73 static GtkWidget *edit_label_user;
74 static GtkWidget *edit_tree;
76 static ircnet *selected_net = NULL;
77 static ircserver *selected_serv = NULL;
78 static ircnet *fav_add_net = NULL; /* used in Add/Remove fav context menus */
79 static session *servlist_sess;
81 static void servlist_network_row_cb (GtkTreeSelection *sel, gpointer user_data);
82 static GtkWidget *servlist_open_edit (GtkWidget *parent, ircnet *net);
85 static const char *pages[]=
87 "UTF-8 (Unicode)",
88 "IRC (Latin/Unicode Hybrid)",
89 "ISO-8859-15 (Western Europe)",
90 "ISO-8859-2 (Central Europe)",
91 "ISO-8859-7 (Greek)",
92 "ISO-8859-8 (Hebrew)",
93 "ISO-8859-9 (Turkish)",
94 "ISO-2022-JP (Japanese)",
95 "SJIS (Japanese)",
96 "CP949 (Korean)",
97 "KOI8-R (Cyrillic)",
98 "CP1251 (Cyrillic)",
99 "CP1256 (Arabic)",
100 "CP1257 (Baltic)",
101 "GB18030 (Chinese)",
102 "TIS-620 (Thai)",
103 NULL
106 /* This is our dictionary for authentication types. Keep these in sync with
107 * login_types[]! This allows us to re-order the login type dropdown in the
108 * network list without breaking config compatibility.
110 * Also make sure inbound_nickserv_login() won't break, i.e. if you add a new
111 * type that is NickServ-based, add it there as well so that HexChat knows to
112 * treat it as such.
114 static int login_types_conf[] =
116 LOGIN_DEFAULT, /* default entry - we don't use this but it makes indexing consistent with login_types[] so it's nice */
117 LOGIN_SASL,
118 LOGIN_PASS,
119 LOGIN_MSG_NICKSERV,
120 LOGIN_NICKSERV,
121 #if 0
122 LOGIN_NS,
123 #endif
124 LOGIN_MSG_NS,
125 LOGIN_AUTH,
128 static const char *login_types[]=
130 "Default",
131 "SASL (username + password)",
132 "Server Password (/PASS password)",
133 "NickServ (/MSG NickServ + password)",
134 "NickServ (/NICKSERV + password)",
135 #if 0
136 "NickServ (/NS + password)",
137 #endif
138 "NickServ (/MSG NS + password)",
139 "AUTH (/AUTH nickname password)",
140 NULL
143 /* poor man's IndexOf() - find the dropdown string index that belongs to the given config value */
144 static int
145 servlist_get_login_desc_index (int conf_value)
147 int i;
148 int length = sizeof (login_types_conf) / sizeof (login_types_conf[0]); /* the number of elements in the conf array */
150 for (i = 0; i < length; i++)
152 if (login_types_conf[i] == conf_value)
154 return i;
158 return 0; /* make the compiler happy */
161 static void
162 servlist_select_and_show (GtkTreeView *treeview, GtkTreeIter *iter,
163 GtkListStore *store)
165 GtkTreePath *path;
166 GtkTreeSelection *sel;
168 sel = gtk_tree_view_get_selection (treeview);
170 /* select this network */
171 gtk_tree_selection_select_iter (sel, iter);
172 /* and make sure it's visible */
173 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
174 if (path)
176 gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5);
177 gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
178 gtk_tree_path_free (path);
182 static void
183 servlist_servers_populate (ircnet *net, GtkWidget *treeview)
185 GtkListStore *store;
186 GtkTreeIter iter;
187 int i;
188 ircserver *serv;
189 GSList *list = net->servlist;
191 store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
192 gtk_list_store_clear (store);
194 i = 0;
195 while (list)
197 serv = list->data;
198 gtk_list_store_append (store, &iter);
199 gtk_list_store_set (store, &iter, 0, serv->hostname, 1, 1, -1);
201 if (net->selected == i)
202 /* select this server */
203 servlist_select_and_show (GTK_TREE_VIEW (treeview), &iter, store);
205 i++;
206 list = list->next;
210 static void
211 servlist_networks_populate_ (GtkWidget *treeview, GSList *netlist, gboolean favorites)
213 GtkListStore *store;
214 GtkTreeIter iter;
215 int i;
216 ircnet *net;
218 if (!netlist)
220 net = servlist_net_add (_("New Network"), "", FALSE);
221 servlist_server_add (net, "newserver/6667");
222 netlist = network_list;
224 store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
225 gtk_list_store_clear (store);
227 i = 0;
228 while (netlist)
230 net = netlist->data;
231 if (!favorites || (net->flags & FLAG_FAVORITE))
233 if (favorites)
234 gtk_list_store_insert_with_values (store, &iter, 0x7fffffff, 0, net->name, 1, 1, 2, 400, -1);
235 else
236 gtk_list_store_insert_with_values (store, &iter, 0x7fffffff, 0, net->name, 1, 1, 2, (net->flags & FLAG_FAVORITE) ? 800 : 400, -1);
237 if (i == prefs.slist_select)
239 /* select this network */
240 servlist_select_and_show (GTK_TREE_VIEW (treeview), &iter, store);
241 selected_net = net;
244 i++;
245 netlist = netlist->next;
249 static void
250 servlist_networks_populate (GtkWidget *treeview, GSList *netlist)
252 servlist_networks_populate_ (treeview, netlist, prefs.slist_fav);
255 static void
256 servlist_server_row_cb (GtkTreeSelection *sel, gpointer user_data)
258 GtkTreeModel *model;
259 GtkTreeIter iter;
260 ircserver *serv;
261 char *servname;
262 int pos;
264 if (!selected_net)
265 return;
267 if (gtk_tree_selection_get_selected (sel, &model, &iter))
269 gtk_tree_model_get (model, &iter, 0, &servname, -1);
270 serv = servlist_server_find (selected_net, servname, &pos);
271 g_free (servname);
272 if (serv)
273 selected_net->selected = pos;
274 selected_serv = serv;
278 static void
279 servlist_start_editing (GtkTreeView *tree)
281 GtkTreeSelection *sel;
282 GtkTreeModel *model;
283 GtkTreeIter iter;
284 GtkTreePath *path;
286 sel = gtk_tree_view_get_selection (tree);
288 if (gtk_tree_selection_get_selected (sel, &model, &iter))
290 path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
291 if (path)
293 gtk_tree_view_set_cursor (tree, path,
294 gtk_tree_view_get_column (tree, 0), TRUE);
295 gtk_tree_path_free (path);
300 static void
301 servlist_addserver_cb (GtkWidget *item, GtkWidget *treeview)
303 GtkTreeIter iter;
304 GtkListStore *store;
306 if (!selected_net)
307 return;
309 store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
310 servlist_server_add (selected_net, "newserver/6667");
312 gtk_list_store_append (store, &iter);
313 gtk_list_store_set (store, &iter, 0, "newserver/6667", 1, 1, -1);
315 /* select this server */
316 servlist_select_and_show (GTK_TREE_VIEW (treeview), &iter, store);
317 /*servlist_start_editing (GTK_TREE_VIEW (treeview));*/
319 servlist_server_row_cb (gtk_tree_view_get_selection (GTK_TREE_VIEW (networks_tree)), NULL);
322 static void
323 servlist_addnet_cb (GtkWidget *item, GtkTreeView *treeview)
325 GtkTreeIter iter;
326 GtkListStore *store;
327 ircnet *net;
329 net = servlist_net_add (_("New Network"), "", TRUE);
330 net->encoding = strdup ("IRC (Latin/Unicode Hybrid)");
331 servlist_server_add (net, "newserver/6667");
333 store = (GtkListStore *)gtk_tree_view_get_model (treeview);
334 gtk_list_store_prepend (store, &iter);
335 gtk_list_store_set (store, &iter, 0, net->name, 1, 1, -1);
337 /* select this network */
338 servlist_select_and_show (GTK_TREE_VIEW (networks_tree), &iter, store);
339 servlist_start_editing (GTK_TREE_VIEW (networks_tree));
341 servlist_network_row_cb (gtk_tree_view_get_selection (GTK_TREE_VIEW (networks_tree)), NULL);
344 static void
345 servlist_deletenetwork (ircnet *net)
347 GtkTreeSelection *sel;
348 GtkTreeModel *model;
349 GtkTreeIter iter;
351 /* remove from GUI */
352 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (networks_tree));
353 if (gtk_tree_selection_get_selected (sel, &model, &iter))
354 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
356 /* remove from list */
357 servlist_net_remove (net);
359 /* force something to be selected */
360 gtk_tree_model_get_iter_first (model, &iter);
361 servlist_select_and_show (GTK_TREE_VIEW (networks_tree), &iter,
362 GTK_LIST_STORE (model));
363 servlist_network_row_cb (sel, NULL);
366 static void
367 servlist_deletenetdialog_cb (GtkDialog *dialog, gint arg1, ircnet *net)
369 gtk_widget_destroy (GTK_WIDGET (dialog));
370 if (arg1 == GTK_RESPONSE_OK)
371 servlist_deletenetwork (net);
374 static void
375 servlist_move_server (ircserver *serv, int delta)
377 int pos;
379 pos = g_slist_index (selected_net->servlist, serv);
380 if (pos >= 0)
382 pos += delta;
383 if (pos >= 0)
385 selected_net->servlist = g_slist_remove (selected_net->servlist, serv);
386 selected_net->servlist = g_slist_insert (selected_net->servlist, serv, pos);
387 servlist_servers_populate (selected_net, edit_tree);
392 static void
393 servlist_move_network (ircnet *net, int delta)
395 int pos;
397 pos = g_slist_index (network_list, net);
398 if (pos >= 0)
400 pos += delta;
401 if (pos >= 0)
403 /*prefs.slist_select += delta;*/
404 network_list = g_slist_remove (network_list, net);
405 network_list = g_slist_insert (network_list, net, pos);
406 servlist_networks_populate (networks_tree, network_list);
411 static gboolean
412 servlist_net_keypress_cb (GtkWidget *wid, GdkEventKey *evt, gpointer tree)
414 if (!selected_net)
415 return FALSE;
417 if (evt->state & GDK_SHIFT_MASK)
419 if (evt->keyval == GDK_Up)
421 servlist_move_network (selected_net, -1);
423 else if (evt->keyval == GDK_Down)
425 servlist_move_network (selected_net, +1);
429 return FALSE;
432 static gboolean
433 servlist_serv_keypress_cb (GtkWidget *wid, GdkEventKey *evt, gpointer userdata)
435 if (!selected_net || !selected_serv)
436 return FALSE;
438 if (evt->state & GDK_SHIFT_MASK)
440 if (evt->keyval == GDK_Up)
442 servlist_move_server (selected_serv, -1);
444 else if (evt->keyval == GDK_Down)
446 servlist_move_server (selected_serv, +1);
450 return FALSE;
453 static gint
454 servlist_compare (ircnet *net1, ircnet *net2)
456 gchar *net1_casefolded, *net2_casefolded;
457 int result=0;
459 net1_casefolded=g_utf8_casefold(net1->name,-1),
460 net2_casefolded=g_utf8_casefold(net2->name,-1),
462 result=g_utf8_collate(net1_casefolded,net2_casefolded);
464 g_free(net1_casefolded);
465 g_free(net2_casefolded);
467 return result;
471 static void
472 servlist_sort (GtkWidget *button, gpointer none)
474 network_list=g_slist_sort(network_list,(GCompareFunc)servlist_compare);
475 servlist_networks_populate (networks_tree, network_list);
478 static gboolean
479 servlist_has_selection (GtkTreeView *tree)
481 GtkTreeSelection *sel;
482 GtkTreeModel *model;
483 GtkTreeIter iter;
485 /* make sure something is selected */
486 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
487 return gtk_tree_selection_get_selected (sel, &model, &iter);
490 static void
491 servlist_favor (GtkWidget *button, gpointer none)
493 GtkTreeSelection *sel;
494 GtkTreeModel *model;
495 GtkTreeIter iter;
497 if (!selected_net)
498 return;
500 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (networks_tree));
501 if (gtk_tree_selection_get_selected (sel, &model, &iter))
503 if (selected_net->flags & FLAG_FAVORITE)
505 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 2, 400, -1);
506 selected_net->flags &= ~FLAG_FAVORITE;
508 else
510 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 2, 800, -1);
511 selected_net->flags |= FLAG_FAVORITE;
516 static void
517 servlist_update_from_entry (char **str, GtkWidget *entry)
519 if (*str)
520 free (*str);
522 if (GTK_ENTRY (entry)->text[0] == 0)
523 *str = NULL;
524 else
525 *str = strdup (GTK_ENTRY (entry)->text);
528 static void
529 servlist_edit_update (ircnet *net)
531 servlist_update_from_entry (&net->nick, edit_entry_nick);
532 servlist_update_from_entry (&net->nick2, edit_entry_nick2);
533 servlist_update_from_entry (&net->user, edit_entry_user);
534 servlist_update_from_entry (&net->real, edit_entry_real);
536 servlist_update_from_entry (&net->autojoin, edit_entry_join);
537 servlist_update_from_entry (&net->command, edit_entry_cmd);
538 servlist_update_from_entry (&net->pass, edit_entry_pass);
541 static void
542 servlist_edit_close_cb (GtkWidget *button, gpointer userdata)
544 if (selected_net)
545 servlist_edit_update (selected_net);
547 gtk_widget_destroy (edit_win);
548 edit_win = NULL;
551 static gint
552 servlist_editwin_delete_cb (GtkWidget *win, GdkEventAny *event, gpointer none)
554 servlist_edit_close_cb (NULL, NULL);
555 return FALSE;
558 static gboolean
559 servlist_configure_cb (GtkWindow *win, GdkEventConfigure *event, gpointer none)
561 /* remember the window size */
562 gtk_window_get_size (win, &win_width, &win_height);
563 return FALSE;
566 static void
567 servlist_edit_cb (GtkWidget *but, gpointer none)
569 if (!servlist_has_selection (GTK_TREE_VIEW (networks_tree)))
570 return;
572 edit_win = servlist_open_edit (serverlist_win, selected_net);
573 gtkutil_set_icon (edit_win);
574 servlist_servers_populate (selected_net, edit_tree);
575 g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (edit_tree))),
576 "changed", G_CALLBACK (servlist_server_row_cb), NULL);
577 g_signal_connect (G_OBJECT (edit_win), "delete_event",
578 G_CALLBACK (servlist_editwin_delete_cb), 0);
579 g_signal_connect (G_OBJECT (edit_tree), "key_press_event",
580 G_CALLBACK (servlist_serv_keypress_cb), 0);
581 gtk_widget_show (edit_win);
584 static void
585 servlist_deletenet_cb (GtkWidget *item, ircnet *net)
587 GtkWidget *dialog;
589 if (!servlist_has_selection (GTK_TREE_VIEW (networks_tree)))
590 return;
592 net = selected_net;
593 if (!net)
594 return;
595 dialog = gtk_message_dialog_new (GTK_WINDOW (serverlist_win),
596 GTK_DIALOG_DESTROY_WITH_PARENT |
597 GTK_DIALOG_MODAL,
598 GTK_MESSAGE_QUESTION,
599 GTK_BUTTONS_OK_CANCEL,
600 _("Really remove network \"%s\" and all its servers?"),
601 net->name);
602 g_signal_connect (dialog, "response",
603 G_CALLBACK (servlist_deletenetdialog_cb), net);
604 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
605 gtk_widget_show (dialog);
608 static void
609 servlist_deleteserver (ircserver *serv, GtkTreeModel *model)
611 GtkTreeSelection *sel;
612 GtkTreeIter iter;
614 /* don't remove the last server */
615 if (selected_net && g_slist_length (selected_net->servlist) < 2)
616 return;
618 /* remove from GUI */
619 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (edit_tree));
620 if (gtk_tree_selection_get_selected (sel, &model, &iter))
621 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
623 /* remove from list */
624 if (selected_net)
625 servlist_server_remove (selected_net, serv);
628 static void
629 servlist_editserverbutton_cb (GtkWidget *item, gpointer none)
631 servlist_start_editing (GTK_TREE_VIEW (edit_tree));
634 static void
635 servlist_deleteserver_cb (GtkWidget *item, gpointer none)
637 GtkTreeSelection *sel;
638 GtkTreeModel *model;
639 GtkTreeIter iter;
640 char *servname;
641 ircserver *serv;
642 int pos;
644 /* find the selected item in the GUI */
645 model = gtk_tree_view_get_model (GTK_TREE_VIEW (edit_tree));
646 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (edit_tree));
648 if (gtk_tree_selection_get_selected (sel, &model, &iter))
650 gtk_tree_model_get (model, &iter, 0, &servname, -1);
651 serv = servlist_server_find (selected_net, servname, &pos);
652 g_free (servname);
653 if (serv)
654 servlist_deleteserver (serv, model);
658 static ircnet *
659 servlist_find_selected_net (GtkTreeSelection *sel)
661 GtkTreeModel *model;
662 GtkTreeIter iter;
663 char *netname;
664 int pos;
665 ircnet *net = NULL;
667 if (gtk_tree_selection_get_selected (sel, &model, &iter))
669 gtk_tree_model_get (model, &iter, 0, &netname, -1);
670 net = servlist_net_find (netname, &pos, strcmp);
671 g_free (netname);
672 if (net)
673 prefs.slist_select = pos;
676 return net;
679 static void
680 servlist_network_row_cb (GtkTreeSelection *sel, gpointer user_data)
682 ircnet *net;
684 selected_net = NULL;
686 net = servlist_find_selected_net (sel);
687 if (net)
688 selected_net = net;
691 static int
692 servlist_savegui (void)
694 char *sp;
696 /* check for blank username, ircd will not allow this */
697 if (GTK_ENTRY (entry_guser)->text[0] == 0)
698 return 1;
700 if (GTK_ENTRY (entry_greal)->text[0] == 0)
701 return 1;
703 strcpy (prefs.nick1, GTK_ENTRY (entry_nick1)->text);
704 strcpy (prefs.nick2, GTK_ENTRY (entry_nick2)->text);
705 strcpy (prefs.nick3, GTK_ENTRY (entry_nick3)->text);
706 strcpy (prefs.username, GTK_ENTRY (entry_guser)->text);
707 sp = strchr (prefs.username, ' ');
708 if (sp)
709 sp[0] = 0; /* spaces will break the login */
710 strcpy (prefs.realname, GTK_ENTRY (entry_greal)->text);
711 servlist_save ();
713 return 0;
716 static gboolean
717 servlist_get_iter_from_name (GtkTreeModel *model, gchar *name, GtkTreeIter *iter)
719 GtkTreePath *path = gtk_tree_path_new_from_string (name);
721 if (!gtk_tree_model_get_iter (model, iter, path))
723 gtk_tree_path_free (path);
724 return FALSE;
727 gtk_tree_path_free (path);
728 return TRUE;
731 static void
732 servlist_editchannel_cb (GtkCellRendererText *cell, gchar *name, gchar *newval, GtkTreeModel *model)
734 GtkTreeIter iter;
735 static int loop_guard = FALSE;
737 if (loop_guard)
738 return;
740 if (!servlist_get_iter_from_name (model, name, &iter))
741 return;
743 loop_guard = TRUE;
744 /* delete empty item */
745 if (newval[0] == 0)
746 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
747 else
748 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, newval, -1);
749 loop_guard = FALSE;
752 static void
753 servlist_editkey_cb (GtkCellRendererText *cell, gchar *name, gchar *newval, GtkTreeModel *model)
755 GtkTreeIter iter;
757 if (!servlist_get_iter_from_name (model, name, &iter))
758 return;
760 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 1, newval, -1);
763 static void
764 servlist_addchannel (GtkWidget *tree, char *channel)
766 GtkTreeIter iter;
767 GtkListStore *store;
769 store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
771 gtk_list_store_append (store, &iter);
772 gtk_list_store_set (store, &iter, 0, channel, 1, "", 2, TRUE, -1);
774 /* select this server */
775 servlist_select_and_show (GTK_TREE_VIEW (tree), &iter, store);
776 servlist_start_editing (GTK_TREE_VIEW (tree));
779 static void
780 servlist_addchannel_cb (GtkWidget *item, GtkWidget *tree)
782 servlist_addchannel (tree, _("#channel"));
785 static void
786 servlist_deletechannel_cb (GtkWidget *item, GtkWidget *tree)
788 GtkTreeSelection *sel;
789 GtkTreeModel *model;
790 GtkTreeIter iter;
792 /* find the selected item in the GUI */
793 model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
794 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
796 if (gtk_tree_selection_get_selected (sel, &model, &iter))
797 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
800 static void
801 servlist_editchannelbutton_cb (GtkWidget *item, GtkWidget *tree)
803 servlist_start_editing (GTK_TREE_VIEW (tree));
806 /* save everything from the GUI to the GtkEntry */
808 static void
809 servlist_autojoineditok_cb (GtkWidget *button, GtkWidget *tree)
811 GtkTreeModel *model;
812 GtkTreeIter iter;
813 char *channel, *key;
814 char *autojoin;
815 GSList *channels = NULL, *keys = NULL;
817 model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
819 if (gtk_tree_model_get_iter_first (model, &iter))
823 gtk_tree_model_get (model, &iter, 0, &channel, 1, &key, -1);
824 channels = g_slist_append (channels, channel);
825 if (key && key[0] == 0)
827 /* NULL out empty keys */
828 g_free (key);
829 keys = g_slist_append (keys, NULL);
831 else
832 keys = g_slist_append (keys, key);
834 while (gtk_tree_model_iter_next (model, &iter));
837 gtk_widget_destroy (gtk_widget_get_toplevel (button));
839 autojoin = joinlist_merge (channels, keys);
840 if (autojoin)
842 if (edit_win && selected_net)
843 gtk_entry_set_text (GTK_ENTRY (edit_entry_join), autojoin);
844 else
846 if (fav_add_net->autojoin)
847 free (fav_add_net->autojoin);
848 fav_add_net->autojoin = strdup (autojoin);
850 g_free (autojoin);
853 /* this does g_free too */
854 joinlist_free (channels, keys);
856 if (fav_add_net)
857 servlist_save ();
860 void
861 servlist_autojoinedit (ircnet *net, char *channel, gboolean add)
863 GtkWidget *win;
864 GtkWidget *scrolledwindow;
865 GtkTreeModel *model;
866 GtkListStore *store;
867 GtkCellRenderer *renderer;
868 GtkWidget *tree;
869 GtkWidget *table;
870 GtkWidget *label;
871 GtkWidget *label2;
872 GtkWidget *bbox;
873 GtkWidget *wid;
875 GtkWidget *vbuttonbox1;
876 GtkWidget *buttonadd;
877 GtkWidget *buttonremove;
878 GtkWidget *buttonedit;
880 char buf[128];
881 char lab[128];
882 GSList *channels, *keys;
883 GSList *clist, *klist;
884 GtkTreeIter iter;
886 if (edit_win && selected_net)
887 /* update net->autojoin */
888 servlist_edit_update (selected_net);
890 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
891 gtk_container_set_border_width (GTK_CONTAINER (win), 4);
892 gtk_window_set_title (GTK_WINDOW (win), _("XChat: Favorite Channels (Auto-Join List)"));
893 gtk_window_set_default_size (GTK_WINDOW (win), 354, 256);
894 gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_MOUSE);
895 if (edit_win)
896 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (edit_win));
897 gtk_window_set_modal (GTK_WINDOW (win), TRUE);
898 gtk_window_set_type_hint (GTK_WINDOW (win), GDK_WINDOW_TYPE_HINT_DIALOG);
899 gtk_window_set_role (GTK_WINDOW (win), "editserv");
901 table = gtk_table_new (1, 1, FALSE);
902 gtk_container_add (GTK_CONTAINER (win), table);
903 gtk_widget_show (table);
905 snprintf (buf, sizeof (buf), _("These channels will be joined whenever you connect to %s."), net->name);
906 label = gtk_label_new (buf);
907 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
908 gtk_table_attach (GTK_TABLE (table), label, 0, 2, 0, 1, GTK_FILL|GTK_EXPAND, GTK_FILL, 3, 3);
909 gtk_widget_show (label);
911 label2 = gtk_label_new ("");
912 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_CENTER);
913 gtk_table_attach (GTK_TABLE (table), label2, 0, 2, 1, 2, GTK_FILL, 0, 3, 3);
914 gtk_widget_show (label2);
916 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
917 gtk_table_attach (GTK_TABLE (table), scrolledwindow, 0, 1, 2, 3, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
918 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
919 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
920 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
921 GTK_SHADOW_IN);
922 gtk_widget_show (scrolledwindow);
924 store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
925 model = GTK_TREE_MODEL (store);
927 tree = gtk_tree_view_new_with_model (model);
928 g_object_unref (model);
929 gtk_container_add (GTK_CONTAINER (scrolledwindow), tree);
930 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree), TRUE);
931 gtk_widget_show (tree);
933 renderer = gtk_cell_renderer_text_new ();
934 g_signal_connect (G_OBJECT (renderer), "edited",
935 G_CALLBACK (servlist_editchannel_cb), model);
936 gtk_tree_view_insert_column_with_attributes (
937 GTK_TREE_VIEW (tree), -1,
938 _("Channel"), renderer,
939 "text", 0,
940 "editable", 2,
941 NULL);
943 renderer = gtk_cell_renderer_text_new ();
944 g_signal_connect (G_OBJECT (renderer), "edited",
945 G_CALLBACK (servlist_editkey_cb), model);
946 gtk_tree_view_insert_column_with_attributes (
947 GTK_TREE_VIEW (tree), -1,
948 _("Key (Password)"), renderer,
949 "text", 1,
950 "editable", 2,
951 NULL);
953 gtk_tree_view_column_set_expand (gtk_tree_view_get_column (GTK_TREE_VIEW (tree), 0), TRUE);
954 gtk_tree_view_column_set_expand (gtk_tree_view_get_column (GTK_TREE_VIEW (tree), 1), TRUE);
956 gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable *)model, 0, GTK_SORT_ASCENDING);
958 /* ===BUTTONS=== */
959 vbuttonbox1 = gtk_vbutton_box_new ();
960 gtk_box_set_spacing (GTK_BOX (vbuttonbox1), 3);
961 gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox1), GTK_BUTTONBOX_START);
962 gtk_widget_show (vbuttonbox1);
963 gtk_table_attach (GTK_TABLE (table), vbuttonbox1, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 3, 0);
965 buttonadd = gtk_button_new_from_stock ("gtk-add");
966 g_signal_connect (G_OBJECT (buttonadd), "clicked",
967 G_CALLBACK (servlist_addchannel_cb), tree);
968 gtk_widget_show (buttonadd);
969 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonadd);
970 GTK_WIDGET_SET_FLAGS (buttonadd, GTK_CAN_DEFAULT);
972 buttonremove = gtk_button_new_from_stock ("gtk-remove");
973 g_signal_connect (G_OBJECT (buttonremove), "clicked",
974 G_CALLBACK (servlist_deletechannel_cb), tree);
975 gtk_widget_show (buttonremove);
976 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonremove);
977 GTK_WIDGET_SET_FLAGS (buttonremove, GTK_CAN_DEFAULT);
979 buttonedit = gtk_button_new_with_mnemonic (_("_Edit"));
980 g_signal_connect (G_OBJECT (buttonedit), "clicked",
981 G_CALLBACK (servlist_editchannelbutton_cb), tree);
982 gtk_widget_show (buttonedit);
983 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonedit);
984 GTK_WIDGET_SET_FLAGS (buttonedit, GTK_CAN_DEFAULT);
986 bbox = gtk_hbutton_box_new ();
987 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
988 gtk_box_set_spacing (GTK_BOX (bbox), 4);
989 gtk_table_attach (GTK_TABLE (table), bbox, 0, 1, 3, 4, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 4);
990 gtk_widget_show (bbox);
992 wid = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
993 g_signal_connect (G_OBJECT (wid), "clicked", G_CALLBACK (gtkutil_destroy), win);
994 gtk_container_add (GTK_CONTAINER (bbox), wid);
995 gtk_widget_show (wid);
997 wid = gtk_button_new_from_stock (GTK_STOCK_OK);
998 g_signal_connect (G_OBJECT (wid), "clicked", G_CALLBACK (servlist_autojoineditok_cb), tree);
999 gtk_container_add (GTK_CONTAINER (bbox), wid);
1000 gtk_widget_show (wid);
1001 gtk_widget_grab_focus (wid);
1002 /* =========== */
1004 if (net->autojoin)
1006 joinlist_split (net->autojoin, &channels, &keys);
1008 clist = channels;
1009 klist = keys;
1011 while (clist)
1013 if (channel && !add && !rfc_casecmp (channel, clist->data))
1015 snprintf (buf, sizeof (buf), _("%s has been removed."), channel);
1016 snprintf (lab, sizeof (lab), "<span foreground=\"#2222DD\">%s</span>", buf);
1017 gtk_label_set_markup (GTK_LABEL (label2), lab);
1019 else
1021 gtk_list_store_append (store, &iter);
1022 gtk_list_store_set (store, &iter, 0, clist->data, 1, klist->data, 2, TRUE, -1);
1025 klist = klist->next;
1026 clist = clist->next;
1029 joinlist_free (channels, keys);
1032 if (channel && add)
1034 servlist_addchannel (tree, channel);
1035 snprintf (buf, sizeof (buf), _("%s has been added."), channel);
1036 snprintf (lab, sizeof (lab), "<span foreground=\"#2222DD\">%s</span>", buf);
1037 gtk_label_set_markup (GTK_LABEL (label2), lab);
1040 fav_add_net = net;
1042 gtk_widget_show (win);
1045 static void
1046 servlist_autojoinedit_cb (GtkWidget *button, ircnet *net)
1048 servlist_autojoinedit (net, NULL, FALSE);
1051 static void
1052 servlist_connect_cb (GtkWidget *button, gpointer userdata)
1054 if (!selected_net)
1055 return;
1057 if (servlist_savegui () != 0)
1059 fe_message (_("User name and Real name cannot be left blank."), FE_MSG_ERROR);
1060 return;
1063 if (!is_session (servlist_sess))
1064 servlist_sess = NULL; /* open a new one */
1067 GSList *list;
1068 session *sess;
1069 session *chosen = servlist_sess;
1071 servlist_sess = NULL; /* open a new one */
1073 for (list = sess_list; list; list = list->next)
1075 sess = list->data;
1076 if (sess->server->network == selected_net)
1078 servlist_sess = sess;
1079 if (sess->server->connected)
1080 servlist_sess = NULL; /* open a new one */
1081 break;
1085 /* use the chosen one, if it's empty */
1086 if (!servlist_sess &&
1087 chosen &&
1088 !chosen->server->connected &&
1089 chosen->server->server_session->channel[0] == 0)
1091 servlist_sess = chosen;
1095 servlist_connect (servlist_sess, selected_net, TRUE);
1097 gtk_widget_destroy (serverlist_win);
1098 serverlist_win = NULL;
1099 selected_net = NULL;
1102 static void
1103 servlist_celledit_cb (GtkCellRendererText *cell, gchar *arg1, gchar *arg2,
1104 gpointer user_data)
1106 GtkTreeModel *model = (GtkTreeModel *)user_data;
1107 GtkTreeIter iter;
1108 GtkTreePath *path;
1109 char *netname;
1110 ircnet *net;
1112 if (!arg1 || !arg2)
1113 return;
1115 path = gtk_tree_path_new_from_string (arg1);
1116 if (!path)
1117 return;
1119 if (!gtk_tree_model_get_iter (model, &iter, path))
1121 gtk_tree_path_free (path);
1122 return;
1124 gtk_tree_model_get (model, &iter, 0, &netname, -1);
1126 net = servlist_net_find (netname, NULL, strcmp);
1127 g_free (netname);
1128 if (net)
1130 /* delete empty item */
1131 if (arg2[0] == 0)
1133 servlist_deletenetwork (net);
1134 gtk_tree_path_free (path);
1135 return;
1138 netname = net->name;
1139 net->name = strdup (arg2);
1140 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, net->name, -1);
1141 free (netname);
1144 gtk_tree_path_free (path);
1147 static void
1148 servlist_check_cb (GtkWidget *but, gpointer num_p)
1150 int num = GPOINTER_TO_INT (num_p);
1152 if (!selected_net)
1153 return;
1155 if ((1 << num) == FLAG_CYCLE || (1 << num) == FLAG_USE_PROXY)
1157 /* these ones are reversed, so it's compat with 2.0.x */
1158 if (GTK_TOGGLE_BUTTON (but)->active)
1159 selected_net->flags &= ~(1 << num);
1160 else
1161 selected_net->flags |= (1 << num);
1162 } else
1164 if (GTK_TOGGLE_BUTTON (but)->active)
1165 selected_net->flags |= (1 << num);
1166 else
1167 selected_net->flags &= ~(1 << num);
1170 if ((1 << num) == FLAG_USE_GLOBAL)
1172 if (GTK_TOGGLE_BUTTON (but)->active)
1174 gtk_widget_hide (edit_label_nick);
1175 gtk_widget_hide (edit_entry_nick);
1177 gtk_widget_hide (edit_label_nick2);
1178 gtk_widget_hide (edit_entry_nick2);
1180 gtk_widget_hide (edit_label_user);
1181 gtk_widget_hide (edit_entry_user);
1183 gtk_widget_hide (edit_label_real);
1184 gtk_widget_hide (edit_entry_real);
1185 } else
1187 gtk_widget_show (edit_label_nick);
1188 gtk_widget_show (edit_entry_nick);
1190 gtk_widget_show (edit_label_nick2);
1191 gtk_widget_show (edit_entry_nick2);
1193 gtk_widget_show (edit_label_user);
1194 gtk_widget_show (edit_entry_user);
1196 gtk_widget_show (edit_label_real);
1197 gtk_widget_show (edit_entry_real);
1202 static GtkWidget *
1203 servlist_create_check (int num, int state, GtkWidget *table, int row, int col, char *labeltext)
1205 GtkWidget *but;
1207 but = gtk_check_button_new_with_label (labeltext);
1208 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (but), state);
1209 g_signal_connect (G_OBJECT (but), "toggled",
1210 G_CALLBACK (servlist_check_cb), GINT_TO_POINTER (num));
1211 gtk_table_attach (GTK_TABLE (table), but, col, col+2, row, row+1,
1212 GTK_FILL|GTK_EXPAND, 0, 0, 0);
1213 gtk_widget_show (but);
1215 return but;
1218 static GtkWidget *
1219 servlist_create_entry (GtkWidget *table, char *labeltext, int row,
1220 char *def, GtkWidget **label_ret, char *tip)
1222 GtkWidget *label, *entry;
1224 label = gtk_label_new_with_mnemonic (labeltext);
1225 if (label_ret)
1226 *label_ret = label;
1227 gtk_widget_show (label);
1228 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
1229 GTK_FILL, 0, 0, 0);
1230 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1232 entry = gtk_entry_new ();
1233 add_tip (entry, tip);
1234 gtk_widget_show (entry);
1235 gtk_entry_set_text (GTK_ENTRY (entry), def ? def : "");
1236 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
1238 if (row == 15) /* for "Channels to Join:" */
1240 GtkWidget *button, *box;
1242 box = gtk_hbox_new (0, 0);
1243 button = gtk_button_new_with_label ("...");
1244 g_signal_connect (G_OBJECT (button), "clicked",
1245 G_CALLBACK (servlist_autojoinedit_cb), selected_net);
1247 gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
1248 gtk_box_pack_end (GTK_BOX (box), button, 0, 0, 0);
1249 gtk_widget_show_all (box);
1251 gtk_table_attach (GTK_TABLE (table), box, 2, 3, row, row+1,
1252 GTK_FILL|GTK_EXPAND, 0, 0, 0);
1254 else
1256 gtk_table_attach (GTK_TABLE (table), entry, 2, 3, row, row+1,
1257 GTK_FILL|GTK_EXPAND, 0, 0, 0);
1260 return entry;
1263 static gint
1264 servlist_delete_cb (GtkWidget *win, GdkEventAny *event, gpointer userdata)
1266 servlist_savegui ();
1267 serverlist_win = NULL;
1268 selected_net = NULL;
1270 if (sess_list == NULL)
1271 xchat_exit ();
1273 return FALSE;
1276 static void
1277 servlist_close_cb (GtkWidget *button, gpointer userdata)
1279 servlist_savegui ();
1280 gtk_widget_destroy (serverlist_win);
1281 serverlist_win = NULL;
1282 selected_net = NULL;
1284 if (sess_list == NULL)
1285 xchat_exit ();
1288 /* convert "host:port" format to "host/port" */
1290 static char *
1291 servlist_sanitize_hostname (char *host)
1293 char *ret, *c, *e;
1295 ret = strdup (host);
1297 c = strchr (ret, ':');
1298 e = strrchr (ret, ':');
1300 /* if only one colon exists it's probably not IPv6 */
1301 if (c && c == e)
1302 *c = '/';
1304 return ret;
1307 static void
1308 servlist_editserver_cb (GtkCellRendererText *cell, gchar *arg1, gchar *arg2,
1309 gpointer user_data)
1311 GtkTreeModel *model = (GtkTreeModel *)user_data;
1312 GtkTreeIter iter;
1313 GtkTreePath *path;
1314 char *servname;
1315 ircserver *serv;
1317 if (!selected_net)
1318 return;
1320 path = gtk_tree_path_new_from_string (arg1);
1322 if (!gtk_tree_model_get_iter (model, &iter, path))
1324 gtk_tree_path_free (path);
1325 return;
1328 gtk_tree_model_get (model, &iter, 0, &servname, -1);
1329 serv = servlist_server_find (selected_net, servname, NULL);
1330 g_free (servname);
1332 if (serv)
1334 /* delete empty item */
1335 if (arg2[0] == 0)
1337 servlist_deleteserver (serv, model);
1338 gtk_tree_path_free (path);
1339 return;
1342 servname = serv->hostname;
1343 serv->hostname = servlist_sanitize_hostname (arg2);
1344 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, serv->hostname, -1);
1345 free (servname);
1348 gtk_tree_path_free (path);
1351 static void
1352 servlist_combo_cb (GtkEntry *entry, gpointer userdata)
1354 if (!selected_net)
1355 return;
1357 if (!ignore_changed)
1359 if (selected_net->encoding)
1360 free (selected_net->encoding);
1361 selected_net->encoding = strdup (entry->text);
1365 /* Fills up the network's authentication type so that it's guaranteed to be either NULL or a valid value. */
1366 static void
1367 servlist_logintypecombo_cb (GtkEntry *entry, gpointer userdata)
1369 int index;
1371 if (!selected_net)
1373 return;
1376 if (!ignore_changed)
1378 index = gtk_combo_box_get_active (GTK_COMBO_BOX (entry)); /* starts at 0, returns -1 for invalid selections */
1380 if (index != -1)
1382 /* The selection is valid. It can be 0, which is the default type, but we need to allow
1383 * that so that you can revert from other types. servlist_save() will dump 0 anyway.
1385 selected_net->logintype = login_types_conf[index];
1391 static GtkWidget *
1392 servlist_create_charsetcombo (void)
1394 GtkWidget *cb;
1395 int i;
1397 cb = gtk_combo_box_entry_new_text ();
1398 gtk_combo_box_append_text (GTK_COMBO_BOX (cb), "System default");
1399 i = 0;
1400 while (pages[i])
1402 gtk_combo_box_append_text (GTK_COMBO_BOX (cb), (char *)pages[i]);
1403 i++;
1405 g_signal_connect (G_OBJECT (GTK_BIN (cb)->child), "changed",
1406 G_CALLBACK (servlist_combo_cb), NULL);
1408 return cb;
1411 static GtkWidget *
1412 servlist_create_logintypecombo (void)
1414 GtkWidget *cb;
1415 int i;
1417 cb = gtk_combo_box_entry_new_text ();
1419 i = 0;
1421 while (login_types[i])
1423 gtk_combo_box_append_text (GTK_COMBO_BOX (cb), (char *)login_types[i]);
1424 i++;
1427 g_signal_connect (G_OBJECT (GTK_BIN (cb)), "changed", G_CALLBACK (servlist_logintypecombo_cb), NULL);
1429 return cb;
1432 static void
1433 no_servlist (GtkWidget * igad, gpointer serv)
1435 if (GTK_TOGGLE_BUTTON (igad)->active)
1436 prefs.slist_skip = TRUE;
1437 else
1438 prefs.slist_skip = FALSE;
1441 static void
1442 fav_servlist (GtkWidget * igad, gpointer serv)
1444 if (GTK_TOGGLE_BUTTON (igad)->active)
1445 prefs.slist_fav = TRUE;
1446 else
1447 prefs.slist_fav = FALSE;
1449 servlist_networks_populate (networks_tree, network_list);
1452 static GtkWidget *
1453 bold_label (char *text)
1455 char buf[128];
1456 GtkWidget *label;
1458 snprintf (buf, sizeof (buf), "<b>%s</b>", text);
1459 label = gtk_label_new (buf);
1460 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1461 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1462 gtk_widget_show (label);
1464 return label;
1467 static GtkWidget *
1468 servlist_open_edit (GtkWidget *parent, ircnet *net)
1470 GtkWidget *editwindow;
1471 GtkWidget *vbox5;
1472 GtkWidget *table3;
1473 GtkWidget *label17;
1474 GtkWidget *label16;
1475 GtkWidget *label21;
1476 GtkWidget *label34;
1477 GtkWidget *label_logintype;
1478 GtkWidget *comboboxentry_charset;
1479 GtkWidget *comboboxentry_logintypes;
1480 GtkWidget *hbox1;
1481 GtkWidget *scrolledwindow2;
1482 GtkWidget *treeview_servers;
1483 GtkWidget *vbuttonbox1;
1484 GtkWidget *buttonadd;
1485 GtkWidget *buttonremove;
1486 GtkWidget *buttonedit;
1487 GtkWidget *hseparator2;
1488 GtkWidget *hbuttonbox4;
1489 GtkWidget *button10;
1490 GtkWidget *check;
1491 GtkTreeModel *model;
1492 GtkListStore *store;
1493 GtkCellRenderer *renderer;
1494 char buf[128];
1495 char buf2[128 + 8];
1497 editwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1498 gtk_container_set_border_width (GTK_CONTAINER (editwindow), 4);
1499 snprintf (buf, sizeof (buf), _("XChat: Edit %s"), net->name);
1500 gtk_window_set_title (GTK_WINDOW (editwindow), buf);
1501 gtk_window_set_default_size (GTK_WINDOW (editwindow), 354, 0);
1502 gtk_window_set_position (GTK_WINDOW (editwindow), GTK_WIN_POS_MOUSE);
1503 gtk_window_set_transient_for (GTK_WINDOW (editwindow), GTK_WINDOW (parent));
1504 gtk_window_set_modal (GTK_WINDOW (editwindow), TRUE);
1505 gtk_window_set_type_hint (GTK_WINDOW (editwindow), GDK_WINDOW_TYPE_HINT_DIALOG);
1506 gtk_window_set_role (GTK_WINDOW (editwindow), "editserv");
1508 vbox5 = gtk_vbox_new (FALSE, 0);
1509 gtk_widget_show (vbox5);
1510 gtk_container_add (GTK_CONTAINER (editwindow), vbox5);
1512 table3 = gtk_table_new (17, 3, FALSE);
1513 gtk_widget_show (table3);
1514 gtk_box_pack_start (GTK_BOX (vbox5), table3, TRUE, TRUE, 0);
1515 gtk_table_set_row_spacings (GTK_TABLE (table3), 2);
1516 gtk_table_set_col_spacings (GTK_TABLE (table3), 8);
1518 snprintf (buf, sizeof (buf), _("Servers for %s"), net->name);
1519 snprintf (buf2, sizeof (buf2), "<b>%s</b>", buf);
1520 label16 = gtk_label_new (buf2);
1521 gtk_widget_show (label16);
1522 gtk_table_attach (GTK_TABLE (table3), label16, 0, 3, 0, 1,
1523 (GtkAttachOptions) (GTK_FILL),
1524 (GtkAttachOptions) (0), 0, 3);
1525 gtk_label_set_use_markup (GTK_LABEL (label16), TRUE);
1526 gtk_misc_set_alignment (GTK_MISC (label16), 0, 0.5);
1528 check = servlist_create_check (0, !(net->flags & FLAG_CYCLE), table3,
1529 2, 1, _("Connect to selected server only"));
1530 add_tip (check, _("Don't cycle through all the servers when the connection fails."));
1532 label17 = bold_label (_("Your Details"));
1533 gtk_table_attach (GTK_TABLE (table3), label17, 0, 3, 3, 4,
1534 (GtkAttachOptions) (GTK_FILL),
1535 (GtkAttachOptions) (0), 0, 3);
1537 servlist_create_check (1, net->flags & FLAG_USE_GLOBAL, table3,
1538 4, 1, _("Use global user information"));
1540 edit_entry_nick =
1541 servlist_create_entry (table3, _("_Nick name:"), 5, net->nick,
1542 &edit_label_nick, 0);
1544 edit_entry_nick2 =
1545 servlist_create_entry (table3, _("Second choice:"), 6, net->nick2,
1546 &edit_label_nick2, 0);
1548 edit_entry_user =
1549 servlist_create_entry (table3, _("_User name:"), 7, net->user,
1550 &edit_label_user, 0);
1552 edit_entry_real =
1553 servlist_create_entry (table3, _("Rea_l name:"), 8, net->real,
1554 &edit_label_real, 0);
1556 label21 = bold_label (_("Connecting"));
1557 gtk_table_attach (GTK_TABLE (table3), label21, 0, 3, 9, 10,
1558 (GtkAttachOptions) (GTK_FILL),
1559 (GtkAttachOptions) (0), 0, 3);
1561 servlist_create_check (3, net->flags & FLAG_AUTO_CONNECT, table3,
1562 11, 1, _("Auto connect to this network at startup"));
1563 servlist_create_check (4, !(net->flags & FLAG_USE_PROXY), table3,
1564 12, 1, _("Bypass proxy server"));
1565 check = servlist_create_check (2, net->flags & FLAG_USE_SSL, table3,
1566 13, 1, _("Use SSL for all the servers on this network"));
1567 #ifndef USE_OPENSSL
1568 gtk_widget_set_sensitive (check, FALSE);
1569 #endif
1570 check = servlist_create_check (5, net->flags & FLAG_ALLOW_INVALID, table3,
1571 14, 1, _("Accept invalid SSL certificate"));
1572 #ifndef USE_OPENSSL
1573 gtk_widget_set_sensitive (check, FALSE);
1574 #endif
1576 edit_entry_join =
1577 servlist_create_entry (table3, _("_Favorite channels:"), 15,
1578 net->autojoin, 0,
1579 _("Channels to join, separated by commas, but not spaces!"));
1581 edit_entry_cmd =
1582 servlist_create_entry (table3, _("Connect command:"), 16,
1583 net->command, 0,
1584 _("Extra command to execute after connecting. If you need more than one, set this to LOAD -e <filename>, where <filename> is a text-file full of commands to execute."));
1586 label_logintype = gtk_label_new (_("Login method:"));
1587 gtk_widget_show (label_logintype);
1588 gtk_table_attach (GTK_TABLE (table3), label_logintype, 1, 2, 18, 19,
1589 (GtkAttachOptions) (GTK_FILL),
1590 (GtkAttachOptions) (0), 0, 0);
1591 gtk_misc_set_alignment (GTK_MISC (label_logintype), 0, 0.5);
1593 comboboxentry_logintypes = servlist_create_logintypecombo ();
1594 ignore_changed = TRUE;
1595 gtk_entry_set_text (GTK_ENTRY (GTK_BIN (comboboxentry_logintypes)->child), net->logintype ? login_types[servlist_get_login_desc_index (net->logintype)] : login_types[0]);
1596 ignore_changed = FALSE;
1597 gtk_widget_show (comboboxentry_logintypes);
1598 gtk_table_attach (GTK_TABLE (table3), comboboxentry_logintypes, 2, 3, 18, 19,
1599 (GtkAttachOptions) (GTK_FILL),
1600 (GtkAttachOptions) (GTK_FILL), 0, 0);
1602 edit_entry_pass =
1603 servlist_create_entry (table3, _("Password:"), 20,
1604 net->pass, 0,
1605 _("Password used for login. If in doubt, leave blank."));
1606 gtk_entry_set_visibility (GTK_ENTRY (edit_entry_pass), FALSE);
1609 label34 = gtk_label_new (_("Character set:"));
1610 gtk_widget_show (label34);
1611 gtk_table_attach (GTK_TABLE (table3), label34, 1, 2, 21, 22,
1612 (GtkAttachOptions) (GTK_FILL),
1613 (GtkAttachOptions) (0), 0, 0);
1614 gtk_misc_set_alignment (GTK_MISC (label34), 0, 0.5);
1616 comboboxentry_charset = servlist_create_charsetcombo ();
1617 ignore_changed = TRUE;
1618 gtk_entry_set_text (GTK_ENTRY (GTK_BIN (comboboxentry_charset)->child), net->encoding ? net->encoding : "System default");
1619 ignore_changed = FALSE;
1620 gtk_widget_show (comboboxentry_charset);
1621 gtk_table_attach (GTK_TABLE (table3), comboboxentry_charset, 2, 3, 21, 22,
1622 (GtkAttachOptions) (GTK_FILL),
1623 (GtkAttachOptions) (GTK_FILL), 0, 0);
1625 hbox1 = gtk_hbox_new (FALSE, 0);
1626 gtk_widget_show (hbox1);
1627 gtk_table_attach (GTK_TABLE (table3), hbox1, 1, 3, 1, 2,
1628 (GtkAttachOptions) (GTK_FILL),
1629 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
1631 scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
1632 gtk_widget_show (scrolledwindow2);
1633 gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
1634 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2),
1635 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1636 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow2),
1637 GTK_SHADOW_IN);
1639 store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
1640 model = GTK_TREE_MODEL (store);
1642 edit_tree = treeview_servers = gtk_tree_view_new_with_model (model);
1643 g_object_unref (model);
1644 gtk_widget_show (treeview_servers);
1645 gtk_container_add (GTK_CONTAINER (scrolledwindow2), treeview_servers);
1646 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview_servers),
1647 FALSE);
1649 renderer = gtk_cell_renderer_text_new ();
1650 g_signal_connect (G_OBJECT (renderer), "edited",
1651 G_CALLBACK (servlist_editserver_cb), model);
1652 gtk_tree_view_insert_column_with_attributes (
1653 GTK_TREE_VIEW (treeview_servers), -1,
1654 0, renderer,
1655 "text", 0,
1656 "editable", 1,
1657 NULL);
1659 vbuttonbox1 = gtk_vbutton_box_new ();
1660 gtk_box_set_spacing (GTK_BOX (vbuttonbox1), 3);
1661 gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox1), GTK_BUTTONBOX_START);
1662 gtk_widget_show (vbuttonbox1);
1663 gtk_box_pack_start (GTK_BOX (hbox1), vbuttonbox1, FALSE, FALSE, 3);
1665 buttonadd = gtk_button_new_from_stock ("gtk-add");
1666 g_signal_connect (G_OBJECT (buttonadd), "clicked",
1667 G_CALLBACK (servlist_addserver_cb), edit_tree);
1668 gtk_widget_show (buttonadd);
1669 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonadd);
1670 GTK_WIDGET_SET_FLAGS (buttonadd, GTK_CAN_DEFAULT);
1672 buttonremove = gtk_button_new_from_stock ("gtk-remove");
1673 g_signal_connect (G_OBJECT (buttonremove), "clicked",
1674 G_CALLBACK (servlist_deleteserver_cb), NULL);
1675 gtk_widget_show (buttonremove);
1676 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonremove);
1677 GTK_WIDGET_SET_FLAGS (buttonremove, GTK_CAN_DEFAULT);
1679 buttonedit = gtk_button_new_with_mnemonic (_("_Edit"));
1680 g_signal_connect (G_OBJECT (buttonedit), "clicked",
1681 G_CALLBACK (servlist_editserverbutton_cb), NULL);
1682 gtk_widget_show (buttonedit);
1683 gtk_container_add (GTK_CONTAINER (vbuttonbox1), buttonedit);
1684 GTK_WIDGET_SET_FLAGS (buttonedit, GTK_CAN_DEFAULT);
1686 hseparator2 = gtk_hseparator_new ();
1687 gtk_widget_show (hseparator2);
1688 gtk_box_pack_start (GTK_BOX (vbox5), hseparator2, FALSE, FALSE, 8);
1690 hbuttonbox4 = gtk_hbutton_box_new ();
1691 gtk_widget_show (hbuttonbox4);
1692 gtk_box_pack_start (GTK_BOX (vbox5), hbuttonbox4, FALSE, FALSE, 0);
1693 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox4),
1694 GTK_BUTTONBOX_END);
1696 button10 = gtk_button_new_from_stock ("gtk-close");
1697 g_signal_connect (G_OBJECT (button10), "clicked",
1698 G_CALLBACK (servlist_edit_close_cb), 0);
1699 gtk_widget_show (button10);
1700 gtk_container_add (GTK_CONTAINER (hbuttonbox4), button10);
1701 GTK_WIDGET_SET_FLAGS (button10, GTK_CAN_DEFAULT);
1703 if (net->flags & FLAG_USE_GLOBAL)
1705 gtk_widget_hide (edit_label_nick);
1706 gtk_widget_hide (edit_entry_nick);
1708 gtk_widget_hide (edit_label_nick2);
1709 gtk_widget_hide (edit_entry_nick2);
1711 gtk_widget_hide (edit_label_user);
1712 gtk_widget_hide (edit_entry_user);
1714 gtk_widget_hide (edit_label_real);
1715 gtk_widget_hide (edit_entry_real);
1718 gtk_widget_grab_focus (button10);
1719 gtk_widget_grab_default (button10);
1721 return editwindow;
1724 static GtkWidget *
1725 servlist_open_networks (void)
1727 GtkWidget *servlist;
1728 GtkWidget *vbox1;
1729 GtkWidget *label2;
1730 GtkWidget *table1;
1731 GtkWidget *label3;
1732 GtkWidget *label4;
1733 GtkWidget *label5;
1734 GtkWidget *label6;
1735 GtkWidget *label7;
1736 GtkWidget *entry1;
1737 GtkWidget *entry2;
1738 GtkWidget *entry3;
1739 GtkWidget *entry4;
1740 GtkWidget *entry5;
1741 GtkWidget *vbox2;
1742 GtkWidget *label1;
1743 GtkWidget *table4;
1744 GtkWidget *scrolledwindow3;
1745 GtkWidget *treeview_networks;
1746 GtkWidget *checkbutton_skip;
1747 GtkWidget *checkbutton_fav;
1748 GtkWidget *hbox;
1749 GtkWidget *vbuttonbox2;
1750 GtkWidget *button_add;
1751 GtkWidget *button_remove;
1752 GtkWidget *button_edit;
1753 GtkWidget *button_sort;
1754 GtkWidget *hseparator1;
1755 GtkWidget *hbuttonbox1;
1756 GtkWidget *button_connect;
1757 GtkWidget *button_close;
1758 GtkTreeModel *model;
1759 GtkListStore *store;
1760 GtkCellRenderer *renderer;
1762 servlist = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1763 gtk_container_set_border_width (GTK_CONTAINER (servlist), 4);
1764 gtk_window_set_title (GTK_WINDOW (servlist), _("XChat: Network List"));
1765 gtk_window_set_default_size (GTK_WINDOW (servlist), win_width, win_height);
1766 gtk_window_set_position (GTK_WINDOW (servlist), GTK_WIN_POS_MOUSE);
1767 gtk_window_set_role (GTK_WINDOW (servlist), "servlist");
1768 gtk_window_set_type_hint (GTK_WINDOW (servlist), GDK_WINDOW_TYPE_HINT_DIALOG);
1769 if (current_sess)
1770 gtk_window_set_transient_for (GTK_WINDOW (servlist), GTK_WINDOW (current_sess->gui->window));
1772 vbox1 = gtk_vbox_new (FALSE, 0);
1773 gtk_widget_show (vbox1);
1774 gtk_container_add (GTK_CONTAINER (servlist), vbox1);
1776 label2 = bold_label (_("User Information"));
1777 gtk_box_pack_start (GTK_BOX (vbox1), label2, FALSE, FALSE, 0);
1779 table1 = gtk_table_new (5, 2, FALSE);
1780 gtk_widget_show (table1);
1781 gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, FALSE, 0);
1782 gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
1783 gtk_table_set_row_spacings (GTK_TABLE (table1), 2);
1784 gtk_table_set_col_spacings (GTK_TABLE (table1), 4);
1786 label3 = gtk_label_new_with_mnemonic (_("_Nick name:"));
1787 gtk_widget_show (label3);
1788 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 0, 1,
1789 (GtkAttachOptions) (GTK_FILL),
1790 (GtkAttachOptions) (0), 0, 0);
1791 gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
1793 label4 = gtk_label_new (_("Second choice:"));
1794 gtk_widget_show (label4);
1795 gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 1, 2,
1796 (GtkAttachOptions) (GTK_FILL),
1797 (GtkAttachOptions) (0), 0, 0);
1798 gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
1800 label5 = gtk_label_new (_("Third choice:"));
1801 gtk_widget_show (label5);
1802 gtk_table_attach (GTK_TABLE (table1), label5, 0, 1, 2, 3,
1803 (GtkAttachOptions) (GTK_FILL),
1804 (GtkAttachOptions) (0), 0, 0);
1805 gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);
1807 label6 = gtk_label_new_with_mnemonic (_("_User name:"));
1808 gtk_widget_show (label6);
1809 gtk_table_attach (GTK_TABLE (table1), label6, 0, 1, 3, 4,
1810 (GtkAttachOptions) (GTK_FILL),
1811 (GtkAttachOptions) (0), 0, 0);
1812 gtk_misc_set_alignment (GTK_MISC (label6), 0, 0.5);
1814 label7 = gtk_label_new_with_mnemonic (_("Rea_l name:"));
1815 gtk_widget_show (label7);
1816 gtk_table_attach (GTK_TABLE (table1), label7, 0, 1, 4, 5,
1817 (GtkAttachOptions) (GTK_FILL),
1818 (GtkAttachOptions) (0), 0, 0);
1819 gtk_misc_set_alignment (GTK_MISC (label7), 0, 0.5);
1821 entry_nick1 = entry1 = gtk_entry_new ();
1822 gtk_entry_set_text (GTK_ENTRY (entry1), prefs.nick1);
1823 gtk_widget_show (entry1);
1824 gtk_table_attach (GTK_TABLE (table1), entry1, 1, 2, 0, 1,
1825 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1826 (GtkAttachOptions) (0), 0, 0);
1828 entry_nick2 = entry2 = gtk_entry_new ();
1829 gtk_entry_set_text (GTK_ENTRY (entry2), prefs.nick2);
1830 gtk_widget_show (entry2);
1831 gtk_table_attach (GTK_TABLE (table1), entry2, 1, 2, 1, 2,
1832 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1833 (GtkAttachOptions) (0), 0, 0);
1835 entry_nick3 = entry3 = gtk_entry_new ();
1836 gtk_entry_set_text (GTK_ENTRY (entry3), prefs.nick3);
1837 gtk_widget_show (entry3);
1838 gtk_table_attach (GTK_TABLE (table1), entry3, 1, 2, 2, 3,
1839 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1840 (GtkAttachOptions) (0), 0, 0);
1842 entry_guser = entry4 = gtk_entry_new ();
1843 gtk_entry_set_text (GTK_ENTRY (entry4), prefs.username);
1844 gtk_widget_show (entry4);
1845 gtk_table_attach (GTK_TABLE (table1), entry4, 1, 2, 3, 4,
1846 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1847 (GtkAttachOptions) (0), 0, 0);
1849 entry_greal = entry5 = gtk_entry_new ();
1850 gtk_entry_set_text (GTK_ENTRY (entry5), prefs.realname);
1851 gtk_widget_show (entry5);
1852 gtk_table_attach (GTK_TABLE (table1), entry5, 1, 2, 4, 5,
1853 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1854 (GtkAttachOptions) (0), 0, 0);
1856 vbox2 = gtk_vbox_new (FALSE, 0);
1857 gtk_widget_show (vbox2);
1858 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0);
1860 label1 = bold_label (_("Networks"));
1861 gtk_box_pack_start (GTK_BOX (vbox2), label1, FALSE, FALSE, 0);
1863 table4 = gtk_table_new (2, 2, FALSE);
1864 gtk_widget_show (table4);
1865 gtk_box_pack_start (GTK_BOX (vbox2), table4, TRUE, TRUE, 0);
1866 gtk_container_set_border_width (GTK_CONTAINER (table4), 8);
1867 gtk_table_set_row_spacings (GTK_TABLE (table4), 2);
1868 gtk_table_set_col_spacings (GTK_TABLE (table4), 3);
1870 scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
1871 gtk_widget_show (scrolledwindow3);
1872 gtk_table_attach (GTK_TABLE (table4), scrolledwindow3, 0, 1, 0, 1,
1873 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1874 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
1875 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3),
1876 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1877 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow3),
1878 GTK_SHADOW_IN);
1880 store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT);
1881 model = GTK_TREE_MODEL (store);
1883 networks_tree = treeview_networks = gtk_tree_view_new_with_model (model);
1884 g_object_unref (model);
1885 gtk_widget_show (treeview_networks);
1886 gtk_container_add (GTK_CONTAINER (scrolledwindow3), treeview_networks);
1887 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview_networks),
1888 FALSE);
1890 renderer = gtk_cell_renderer_text_new ();
1891 g_signal_connect (G_OBJECT (renderer), "edited",
1892 G_CALLBACK (servlist_celledit_cb), model);
1893 gtk_tree_view_insert_column_with_attributes (
1894 GTK_TREE_VIEW (treeview_networks), -1,
1895 0, renderer,
1896 "text", 0,
1897 "editable", 1,
1898 "weight", 2,
1899 NULL);
1901 hbox = gtk_hbox_new (0, FALSE);
1902 gtk_table_attach (GTK_TABLE (table4), hbox, 0, 2, 1, 2,
1903 (GtkAttachOptions) (GTK_FILL),
1904 (GtkAttachOptions) (0), 0, 0);
1905 gtk_widget_show (hbox);
1907 checkbutton_skip =
1908 gtk_check_button_new_with_mnemonic (_("Skip network list on startup"));
1909 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton_skip),
1910 prefs.slist_skip);
1911 gtk_container_add (GTK_CONTAINER (hbox), checkbutton_skip);
1912 g_signal_connect (G_OBJECT (checkbutton_skip), "toggled",
1913 G_CALLBACK (no_servlist), 0);
1914 gtk_widget_show (checkbutton_skip);
1916 checkbutton_fav =
1917 gtk_check_button_new_with_mnemonic (_("Show favorites only"));
1918 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton_fav),
1919 prefs.slist_fav);
1920 gtk_container_add (GTK_CONTAINER (hbox), checkbutton_fav);
1921 g_signal_connect (G_OBJECT (checkbutton_fav), "toggled",
1922 G_CALLBACK (fav_servlist), 0);
1923 gtk_widget_show (checkbutton_fav);
1925 vbuttonbox2 = gtk_vbutton_box_new ();
1926 gtk_box_set_spacing (GTK_BOX (vbuttonbox2), 3);
1927 gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox2), GTK_BUTTONBOX_START);
1928 gtk_widget_show (vbuttonbox2);
1929 gtk_table_attach (GTK_TABLE (table4), vbuttonbox2, 1, 2, 0, 1,
1930 (GtkAttachOptions) (GTK_FILL),
1931 (GtkAttachOptions) (GTK_FILL), 0, 0);
1933 button_add = gtk_button_new_from_stock ("gtk-add");
1934 g_signal_connect (G_OBJECT (button_add), "clicked",
1935 G_CALLBACK (servlist_addnet_cb), networks_tree);
1936 gtk_widget_show (button_add);
1937 gtk_container_add (GTK_CONTAINER (vbuttonbox2), button_add);
1938 GTK_WIDGET_SET_FLAGS (button_add, GTK_CAN_DEFAULT);
1940 button_remove = gtk_button_new_from_stock ("gtk-remove");
1941 g_signal_connect (G_OBJECT (button_remove), "clicked",
1942 G_CALLBACK (servlist_deletenet_cb), 0);
1943 gtk_widget_show (button_remove);
1944 gtk_container_add (GTK_CONTAINER (vbuttonbox2), button_remove);
1945 GTK_WIDGET_SET_FLAGS (button_remove, GTK_CAN_DEFAULT);
1947 button_edit = gtk_button_new_with_mnemonic (_("_Edit..."));
1948 g_signal_connect (G_OBJECT (button_edit), "clicked",
1949 G_CALLBACK (servlist_edit_cb), 0);
1950 gtk_widget_show (button_edit);
1951 gtk_container_add (GTK_CONTAINER (vbuttonbox2), button_edit);
1952 GTK_WIDGET_SET_FLAGS (button_edit, GTK_CAN_DEFAULT);
1954 button_sort = gtk_button_new_with_mnemonic (_("_Sort"));
1955 add_tip (button_sort, _("Sorts the network list in alphabetical order. "
1956 "Use SHIFT-UP and SHIFT-DOWN keys to move a row."));
1957 g_signal_connect (G_OBJECT (button_sort), "clicked",
1958 G_CALLBACK (servlist_sort), 0);
1959 gtk_widget_show (button_sort);
1960 gtk_container_add (GTK_CONTAINER (vbuttonbox2), button_sort);
1961 GTK_WIDGET_SET_FLAGS (button_sort, GTK_CAN_DEFAULT);
1963 button_sort = gtk_button_new_with_mnemonic (_("_Favor"));
1964 add_tip (button_sort, _("Mark or unmark this network as a favorite."));
1965 g_signal_connect (G_OBJECT (button_sort), "clicked",
1966 G_CALLBACK (servlist_favor), 0);
1967 gtk_widget_show (button_sort);
1968 gtk_container_add (GTK_CONTAINER (vbuttonbox2), button_sort);
1969 GTK_WIDGET_SET_FLAGS (button_sort, GTK_CAN_DEFAULT);
1971 hseparator1 = gtk_hseparator_new ();
1972 gtk_widget_show (hseparator1);
1973 gtk_box_pack_start (GTK_BOX (vbox1), hseparator1, FALSE, TRUE, 4);
1975 hbuttonbox1 = gtk_hbutton_box_new ();
1976 gtk_widget_show (hbuttonbox1);
1977 gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
1978 gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 8);
1980 button_close = gtk_button_new_from_stock ("gtk-close");
1981 gtk_widget_show (button_close);
1982 g_signal_connect (G_OBJECT (button_close), "clicked",
1983 G_CALLBACK (servlist_close_cb), 0);
1984 gtk_container_add (GTK_CONTAINER (hbuttonbox1), button_close);
1985 GTK_WIDGET_SET_FLAGS (button_close, GTK_CAN_DEFAULT);
1987 button_connect = gtkutil_button (hbuttonbox1, GTK_STOCK_CONNECT, NULL,
1988 servlist_connect_cb, NULL, _("C_onnect"));
1989 GTK_WIDGET_SET_FLAGS (button_connect, GTK_CAN_DEFAULT);
1991 gtk_label_set_mnemonic_widget (GTK_LABEL (label3), entry1);
1992 gtk_label_set_mnemonic_widget (GTK_LABEL (label6), entry4);
1993 gtk_label_set_mnemonic_widget (GTK_LABEL (label7), entry5);
1995 gtk_widget_grab_focus (networks_tree);
1996 gtk_widget_grab_default (button_close);
1997 return servlist;
2000 void
2001 fe_serverlist_open (session *sess)
2003 if (serverlist_win)
2005 gtk_window_present (GTK_WINDOW (serverlist_win));
2006 return;
2009 servlist_sess = sess;
2011 serverlist_win = servlist_open_networks ();
2012 gtkutil_set_icon (serverlist_win);
2014 servlist_networks_populate (networks_tree, network_list);
2016 g_signal_connect (G_OBJECT (serverlist_win), "delete_event",
2017 G_CALLBACK (servlist_delete_cb), 0);
2018 g_signal_connect (G_OBJECT (serverlist_win), "configure_event",
2019 G_CALLBACK (servlist_configure_cb), 0);
2020 g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (networks_tree))),
2021 "changed", G_CALLBACK (servlist_network_row_cb), NULL);
2022 g_signal_connect (G_OBJECT (networks_tree), "key_press_event",
2023 G_CALLBACK (servlist_net_keypress_cb), networks_tree);
2025 gtk_widget_show (serverlist_win);