Added usermode printing on statusbar.
[crypto.git] / apps / irssi / src / silc / core / silc-expandos.c
1 /*
2
3   silc-expandos.c 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #include "module.h"
21 #include "misc.h"
22 #include "expandos.h"
23 #include "settings.h"
24
25 #include "chatnets.h"
26 #include "servers-setup.h"
27 #include "channels-setup.h"
28 #include "silc-servers.h"
29 #include "silc-channels.h"
30 #include "silc-queries.h"
31 #include "silc-nicklist.h"
32
33 /* User mode in active server */
34
35 static char *expando_usermode(SERVER_REC *server, void *item, int *free_ret)
36 {
37   SILC_SERVER_REC *s = SILC_SERVER(server);
38
39   if (!s)
40     return "";
41
42   return (s->umode & SILC_UMODE_SERVER_OPERATOR) ? "Server Operator" :
43     (s->umode & SILC_UMODE_ROUTER_OPERATOR) ? "Router Operator" : "";
44 }
45
46 /* Expands to your usermode on channel */
47
48 static char *expando_cumode(SERVER_REC *server, void *item, int *free_ret)
49 {
50   if (IS_CHANNEL(item) && CHANNEL(item)->ownnick) {
51     SILC_NICK_REC *nick = (SILC_NICK_REC *)CHANNEL(item)->ownnick;
52     return (nick->op && nick->founder) ? "*@" :
53       nick->op ? "@" : nick->founder ? "*" : "";
54   }
55
56   return "";
57 }
58
59 static char *expando_cumode_space(SERVER_REC *server, void *item, 
60                                   int *free_ret)
61 {
62   char *ret = expando_cumode(server, item, free_ret);
63   return *ret == '\0' ? " " : ret;
64 }
65
66 void silc_expandos_init(void)
67 {
68   expando_create("usermode", expando_usermode,
69                  "window changed", EXPANDO_ARG_NONE,
70                  "window server changed", EXPANDO_ARG_WINDOW,
71                  "user mode changed", EXPANDO_ARG_SERVER, NULL);
72   expando_create("cumode", expando_cumode,
73                  "window changed", EXPANDO_ARG_NONE,
74                  "window item changed", EXPANDO_ARG_WINDOW,
75                  "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
76   expando_create("cumode_space", expando_cumode_space,
77                  "window changed", EXPANDO_ARG_NONE,
78                  "window item changed", EXPANDO_ARG_WINDOW,
79                  "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
80 }
81
82 void silc_expandos_deinit(void)
83 {
84   expando_destroy("usermode", expando_usermode);
85   expando_destroy("cumode", expando_cumode);
86   expando_destroy("cumode_space", expando_cumode_space);
87 }