Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-text / cuix-lib.c
1 #include "module.h"
2 #include "settings.h"
3 #include "cuix-lib.h"
4 #include "signals.h"
5 #include "irc.h"
6 #include "irc-channels.h"
7 #include "mode-lists.h"
8 #include "gui-windows.h"
9
10
11 int do_nothing (char *foo)
12 {
13     (void)foo;
14     return 0;
15 }
16
17
18 void display_message (char *message)
19 {
20     object *list;
21     entry *text, *entries[2];
22
23     text = create_label (message);
24     entries[0] = text;
25     entries[1] = NULL;
26     list = create_list ("Message", entries);
27     display_object (list);
28 }
29
30
31 int change_nick (char *nick)
32 {
33     SERVER_REC *server;
34     WI_ITEM_REC *wiitem;
35     if (active_win == NULL) {
36         server = NULL;
37         wiitem = NULL;
38     } else {
39         server = active_win->active_server != NULL ?
40             active_win->active_server : active_win->connect_server;
41         wiitem = active_win->active;
42     } 
43     signal_emit("command nick", 3, nick, server, wiitem);
44     return 0;
45 }
46
47
48
49 int show_banlist (char *nothing)
50 {
51     GSList *tmp;
52     IRC_CHANNEL_REC *chan = IRC_CHANNEL(active_win->active);
53     BAN_REC *ban;
54     object *list;
55     entry *entry, **entries;
56     unsigned int size, i;
57     GString **baninfo;
58
59     if (!chan) {
60         display_message ("This is not a channel");
61         return 1;
62     }
63     if (!chan->banlist) {
64         display_message ("No bans set");
65         return 0;
66     }
67
68     size = (unsigned int) g_slist_length (chan->banlist);
69     entries = g_new0 (struct entry *, size + 1);
70     baninfo = g_new0 (GString *, size);
71
72     for (tmp = chan->banlist, i = 0; tmp; tmp = tmp->next, i++) {
73         ban = tmp->data;
74         baninfo[i] = g_string_new (NULL);
75         g_string_sprintf (baninfo[i], "%s set by %s %d seconds ago", ban->ban, ban->setby, (int)(time(NULL)-ban->time));
76         entry = create_label (baninfo[i]->str);
77         entries[i] = entry;
78     }
79
80     list = create_list ("Bans", entries);
81     display_object (list);
82     for (i = 0; i < size; i++) {
83         g_string_free (baninfo[i], FALSE);
84     }
85     g_free (entries);
86     g_free (baninfo);
87
88     return 0;
89 }
90
91
92 int change_nick_form (char *nothing) {
93     object *form;
94     entry *question, *answer;
95     (void)nothing;
96
97     form = create_form ("True!");
98     question = create_label ("Enter your new nick");
99     answer = create_field ("", change_nick);
100     attach_entry (form, question);
101     attach_entry (form, answer);
102     display_object (form);
103     return 0;
104 }
105
106
107 int about_list (char *nothing) 
108 {
109     (void)nothing;
110
111     display_message ("(c) irssi; See http://www.irssi.org.");
112     return 0;
113 }
114
115
116
117
118 int home_menu (char *nothing) 
119 {
120     /* Objects declaration */
121     object *root_menu;
122     entry *about, *banlist, *nick;
123     (void)nothing;
124
125     /* Objects initialisation */
126     root_menu = create_menu ("My root menu");
127     banlist = create_menuentry ("Banlist", show_banlist);
128     nick = create_menuentry ("Change nick", change_nick_form);
129     about = create_menuentry ("About", about_list);
130
131     /* Layout */
132     attach_entry (root_menu, (void *)banlist);
133     attach_entry (root_menu, (void *)nick);
134     attach_entry (root_menu, (void *)about);
135
136     /* Declare that the object is ready to be displayed and do it */
137     display_object (root_menu);
138     return 0;
139 }