configure: fix bug when one of libsexy/gtkspell is either found or desired
[rofl0r-ixchat.git] / src / fe-gtk / joind.c
blobee5c56d1723c589f870794c2ca1e088476a3224a
1 /* Copyright (c) 2005 Peter Zelezny
2 All Rights Reserved.
4 joind.c - The Join Dialog.
6 Popups up when you connect without any autojoin channels and helps you
7 to find or join a channel.
8 */
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <stdio.h>
16 #include <gtk/gtkbbox.h>
17 #include <gtk/gtkbutton.h>
18 #include <gtk/gtkdialog.h>
19 #include <gtk/gtkentry.h>
20 #include <gtk/gtkhbox.h>
21 #include <gtk/gtkimage.h>
22 #include <gtk/gtklabel.h>
23 #include <gtk/gtkradiobutton.h>
24 #include <gtk/gtkvbox.h>
25 #include <gtk/gtkwindow.h>
27 #include "../common/xchat.h"
28 #include "../common/xchatc.h"
29 #include "../common/server.h"
30 #include "../common/fe.h"
31 #include "fe-gtk.h"
32 #include "chanlist.h"
35 static void
36 joind_radio2_cb (GtkWidget *radio, server *serv)
38 if (GTK_TOGGLE_BUTTON (radio)->active)
40 gtk_widget_grab_focus (serv->gui->joind_entry);
41 gtk_editable_set_position (GTK_EDITABLE (serv->gui->joind_entry), 999);
45 static void
46 joind_entryenter_cb (GtkWidget *entry, GtkWidget *ok)
48 gtk_widget_grab_focus (ok);
51 static void
52 joind_entryfocus_cb (GtkWidget *entry, GdkEventFocus *event, server *serv)
54 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (serv->gui->joind_radio2), TRUE);
57 static void
58 joind_destroy_cb (GtkWidget *win, server *serv)
60 if (is_server (serv))
61 serv->gui->joind_win = NULL;
64 static void
65 joind_ok_cb (GtkWidget *ok, server *serv)
67 if (!is_server (serv))
69 gtk_widget_destroy (gtk_widget_get_toplevel (ok));
70 return;
73 /* do nothing */
74 if (GTK_TOGGLE_BUTTON (serv->gui->joind_radio1)->active)
75 goto xit;
77 /* join specific channel */
78 if (GTK_TOGGLE_BUTTON (serv->gui->joind_radio2)->active)
80 char *text = GTK_ENTRY (serv->gui->joind_entry)->text;
81 if (strlen (text) < 2)
83 fe_message (_("Channel name too short, try again."), FE_MSG_ERROR);
84 return;
86 serv->p_join (serv, text, "");
87 goto xit;
90 /* channel list */
91 chanlist_opengui (serv, TRUE);
93 xit:
94 prefs.gui_join_dialog = 0;
95 if (GTK_TOGGLE_BUTTON (serv->gui->joind_check)->active)
96 prefs.gui_join_dialog = 1;
98 gtk_widget_destroy (serv->gui->joind_win);
99 serv->gui->joind_win = NULL;
102 static void
103 joind_show_dialog (server *serv)
105 GtkWidget *dialog1;
106 GtkWidget *dialog_vbox1;
107 GtkWidget *vbox1;
108 GtkWidget *hbox1;
109 GtkWidget *image1;
110 GtkWidget *vbox2;
111 GtkWidget *label;
112 GtkWidget *radiobutton1;
113 GtkWidget *radiobutton2;
114 GtkWidget *radiobutton3;
115 GSList *radiobutton1_group;
116 GtkWidget *hbox2;
117 GtkWidget *entry1;
118 GtkWidget *checkbutton1;
119 GtkWidget *dialog_action_area1;
120 GtkWidget *okbutton1;
121 char buf[256];
122 char buf2[256];
124 serv->gui->joind_win = dialog1 = gtk_dialog_new ();
125 gtk_window_set_title (GTK_WINDOW (dialog1), _("XChat: Connection Complete"));
126 gtk_window_set_type_hint (GTK_WINDOW (dialog1), GDK_WINDOW_TYPE_HINT_DIALOG);
127 gtk_window_set_position (GTK_WINDOW (dialog1), GTK_WIN_POS_MOUSE);
129 dialog_vbox1 = GTK_DIALOG (dialog1)->vbox;
130 gtk_widget_show (dialog_vbox1);
132 vbox1 = gtk_vbox_new (FALSE, 0);
133 gtk_widget_show (vbox1);
134 gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, TRUE, TRUE, 0);
136 hbox1 = gtk_hbox_new (FALSE, 0);
137 gtk_widget_show (hbox1);
138 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
140 image1 = gtk_image_new_from_stock ("gtk-yes", GTK_ICON_SIZE_DIALOG);
141 gtk_widget_show (image1);
142 gtk_box_pack_start (GTK_BOX (hbox1), image1, FALSE, TRUE, 24);
143 gtk_misc_set_alignment (GTK_MISC (image1), 0.5, 0.06);
145 vbox2 = gtk_vbox_new (FALSE, 10);
146 gtk_container_set_border_width (GTK_CONTAINER (vbox2), 6);
147 gtk_widget_show (vbox2);
148 gtk_box_pack_start (GTK_BOX (hbox1), vbox2, TRUE, TRUE, 0);
150 snprintf (buf2, sizeof (buf2), _("Connection to %s complete."),
151 server_get_network (serv, TRUE));
152 snprintf (buf, sizeof (buf), "\n<b>%s</b>", buf2);
153 label = gtk_label_new (buf);
154 gtk_widget_show (label);
155 gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
156 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
157 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
159 label = gtk_label_new (_("In the Server-List window, no channel (chat room) has been entered to be automatically joined for this network."));
160 gtk_widget_show (label);
161 gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
162 GTK_LABEL (label)->wrap = TRUE;
163 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
165 label = gtk_label_new (_("What would you like to do next?"));
166 gtk_widget_show (label);
167 gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
168 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
170 serv->gui->joind_radio1 = radiobutton1 = gtk_radio_button_new_with_mnemonic (NULL, _("_Nothing, I'll join a channel later."));
171 gtk_widget_show (radiobutton1);
172 gtk_box_pack_start (GTK_BOX (vbox2), radiobutton1, FALSE, FALSE, 0);
173 radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton1));
175 hbox2 = gtk_hbox_new (FALSE, 0);
176 gtk_widget_show (hbox2);
177 gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
179 serv->gui->joind_radio2 = radiobutton2 = gtk_radio_button_new_with_mnemonic (NULL, _("_Join this channel:"));
180 gtk_widget_show (radiobutton2);
181 gtk_box_pack_start (GTK_BOX (hbox2), radiobutton2, FALSE, FALSE, 0);
182 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton2), radiobutton1_group);
183 radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton2));
185 serv->gui->joind_entry = entry1 = gtk_entry_new ();
186 gtk_entry_set_text (GTK_ENTRY (entry1), "#");
187 gtk_widget_show (entry1);
188 gtk_box_pack_start (GTK_BOX (hbox2), entry1, TRUE, TRUE, 8);
190 snprintf (buf, sizeof (buf), "<small> %s</small>",
191 _("If you know the name of the channel you want to join, enter it here."));
192 label = gtk_label_new (buf);
193 gtk_widget_show (label);
194 gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
195 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
196 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
198 radiobutton3 = gtk_radio_button_new_with_mnemonic (NULL, _("O_pen the Channel-List window."));
199 gtk_widget_show (radiobutton3);
200 gtk_box_pack_start (GTK_BOX (vbox2), radiobutton3, FALSE, FALSE, 0);
201 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton3), radiobutton1_group);
202 radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton3));
204 snprintf (buf, sizeof (buf), "<small> %s</small>",
205 _("Retrieving the Channel-List may take a minute or two."));
206 label = gtk_label_new (buf);
207 gtk_widget_show (label);
208 gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
209 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
210 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
212 serv->gui->joind_check = checkbutton1 = gtk_check_button_new_with_mnemonic (_("_Always show this dialog after connecting."));
213 if (prefs.gui_join_dialog)
214 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton1), TRUE);
215 gtk_widget_show (checkbutton1);
216 gtk_box_pack_start (GTK_BOX (vbox1), checkbutton1, FALSE, FALSE, 0);
218 dialog_action_area1 = GTK_DIALOG (dialog1)->action_area;
219 gtk_widget_show (dialog_action_area1);
220 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
222 okbutton1 = gtk_button_new_from_stock ("gtk-ok");
223 gtk_widget_show (okbutton1);
224 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog1)->action_area), okbutton1, FALSE, TRUE, 0);
225 GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
227 g_signal_connect (G_OBJECT (dialog1), "destroy",
228 G_CALLBACK (joind_destroy_cb), serv);
229 g_signal_connect (G_OBJECT (entry1), "focus_in_event",
230 G_CALLBACK (joind_entryfocus_cb), serv);
231 g_signal_connect (G_OBJECT (entry1), "activate",
232 G_CALLBACK (joind_entryenter_cb), okbutton1);
233 g_signal_connect (G_OBJECT (radiobutton2), "toggled",
234 G_CALLBACK (joind_radio2_cb), serv);
235 g_signal_connect (G_OBJECT (okbutton1), "clicked",
236 G_CALLBACK (joind_ok_cb), serv);
238 gtk_widget_grab_focus (okbutton1);
239 gtk_widget_show_all (dialog1);
242 void
243 joind_open (server *serv)
245 if (prefs.gui_join_dialog)
246 joind_show_dialog (serv);
249 void
250 joind_close (server *serv)
252 if (serv->gui->joind_win)
254 gtk_widget_destroy (serv->gui->joind_win);
255 serv->gui->joind_win = NULL;