1 /*
2  * main.h: application initialization, misc funcs
3  * Copyright (C) 2002,2004 Saulius Menkevicius
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * $Id: main.h,v 1.36 2005/01/03 01:20:22 bobas Exp $
20  */
21 
22 #ifndef MAIN_H__
23 #define MAIN_H__
24 
25 #ifdef HAVE_CONFIG_H
26  #include <config.h>
27 #endif
28 
29 #ifdef ENABLE_NLS
30  #include <libintl.h>
31 
32  #define _(text) gettext(text)
33  #define N_(text) (text)
34 #else
35  #define _(text) (text)
36  #define N_(text) (text)
37 #endif
38 
39 #define MAX_TOPIC_LENGTH	1023
40 #define MAX_TEXT_LENGTH		1023
41 #define MAX_NICK_LENGTH		64
42 #define MAX_CHAN_LENGTH		64
43 
44 #define DEFAULT_SESSION_SIZE	256
45 
46 /* preferences registered in main module
47  */
48 #define PREFS_MAIN_NICKNAME	"main/nickname"
49 #define PREFS_MAIN_MODE		"main/mode"
50 #define PREFS_MAIN_LOG_GLOBAL	"main/log_global"
51 #define PREFS_MAIN_PERSISTENT_CHANNELS "main/persistent_channels"
52 #define PREFS_MAIN_POPUP_TIMEOUT "main/popup_timeout"
53 
54 enum app_status_enum {
55 	APP_INIT,
56 	APP_START,
57 	APP_RUNNING,
58 	APP_PRECLOSE,
59 	APP_CLOSE
60 };
61 enum app_status_enum app_status();
62 
63 #define EVENT_V(p, i) (((gpointer*)p)[i])
64 #define APP_EVENT_V(p, i) EVENT_V(p, i)	/* XXX: deprecated */
65 
66 enum app_event_enum {
67 	EVENT_NULL,
68 	EVENT_MAIN	= 0x00100,
69 	EVENT_MAIN_INIT,
70 	EVENT_MAIN_REGISTER_PREFS,
71 	EVENT_MAIN_PRESET_PREFS,
72 	EVENT_MAIN_LOAD_PREFS,
73 	EVENT_MAIN_START,
74 	EVENT_MAIN_PRECLOSE,
75 	EVENT_MAIN_CLOSE,
76 
77 	EVENT_IFACE	= 0x00200,
78 	EVENT_IFACE_EXIT,
79 	EVENT_IFACE_SHOW_CONFIGURE_DLG,
80 	EVENT_IFACE_SHOW_IGNORE_DLG,
81 	EVENT_IFACE_SHOW_TOPIC_DLG,	/* p = sess_id of session to set topic of */
82 	EVENT_IFACE_SHOW_NETDETECT_DLG,
83 	EVENT_IFACE_SHOW_CHANNEL_DLG,
84 	EVENT_IFACE_SHOW_ABOUT_DLG,
85 	EVENT_IFACE_TOPIC_ENTER,	/* p = {sess_id, text} */
86 	EVENT_IFACE_TEXT_ENTER,
87 	EVENT_IFACE_HISTORY,
88 	EVENT_IFACE_NICKNAME_ENTERED,
89 	EVENT_IFACE_PAGE_SWITCH,
90 	EVENT_IFACE_PAGE_CLOSE,		/* p = page_id(eq sess_id); (or NULL, if active page) */
91 	EVENT_IFACE_PAGE_SCROLL,
92 	EVENT_IFACE_USER_INFO_REQ,	/* p = user_id */
93 	EVENT_IFACE_USER_MESSAGE_REQ,
94 	EVENT_IFACE_USER_BEEP_REQ,
95 	EVENT_IFACE_USER_OPEN_REQ,
96 	EVENT_IFACE_USER_CLOSE_REQ,
97 	EVENT_IFACE_USER_IGNORE_REQ,
98 	EVENT_IFACE_USER_UNIGNORE_REQ,
99 	EVENT_IFACE_USER_REMOVE_REQ,
100 	EVENT_IFACE_USER_LIST_REFRESH_REQ,
101 	EVENT_IFACE_IGNORE_ADD,		/* p=(const char *)nickname */
102 	EVENT_IFACE_IGNORE_REMOVE,	/* p=(const char *)nickname */
103 	EVENT_IFACE_JOIN_CHANNEL,	/* p=(const char *)channel */
104 	EVENT_IFACE_REQUEST_NET_CHANNELS,
105 	EVENT_IFACE_RELOAD_CONFIG,
106 	EVENT_IFACE_STORE_CONFIG,
107 	EVENT_IFACE_MAINWND_SHOWN,
108 	EVENT_IFACE_MAINWND_HIDDEN,
109 	EVENT_IFACE_ACTIVE_CHANGE,	/* i="is_active" */
110 	EVENT_IFACE_PAGE_RELEASE_FOCUS,	/* invoked when page widget wants to release focus */
111 	EVENT_IFACE_TRAY_CLICK,
112 	EVENT_IFACE_TRAY_UMODE,		/* p=(enum user_mode_enum) */
113 	EVENT_IFACE_TRAY_EMBEDDED,
114 	EVENT_IFACE_TRAY_REMOVED,
115 	/* requests to the i-iface */
116 	EVENT_IFACE_REQ_PRESENT,	/* present the main window */
117 
118 	EVENT_NET	= 0x00400,
119 	EVENT_NET_PRECONNECT,
120 	EVENT_NET_CONNECTED,
121 	EVENT_NET_PREDISCONNECT,
122 	EVENT_NET_DISCONNECTED,
123 	EVENT_NET_ERROR,		/* i(errno) */
124 	EVENT_NET_NEW_USER,		/* p[]={(char*)username, usermode, found_via_pong} */
125 	EVENT_NET_MSG_REFRESH_REQ,	/* (uid)p */
126 	EVENT_NET_MSG_REFRESH_ACK,	/* p[]={uid,(int)is_active}, (usermode)i */
127 	EVENT_NET_MSG_TOPIC_CHANGE,	/* p (topic): topic of all channels */
128 	EVENT_NET_MSG_TOPIC_CHANGE_4,	/* p[]={channel, topic} */
129 	EVENT_NET_MSG_MESSAGE,		/* p[]={uid, msg, is_mass_message} */
130 	EVENT_NET_MSG_MESSAGE_ACK,	/* p[]={uid, ack_msg}, i(mode)*/
131 	EVENT_NET_MSG_RENAME,		/* p[]={uid, new_name} */
132 	EVENT_NET_MSG_MODE_CHANGE,	/* (uid)p; (mode)i */
133 	EVENT_NET_MSG_ACTIVE_CHANGE,	/* (uid)p; i="is_active" */
134 	EVENT_NET_MSG_CHANNEL_JOIN,	/* p[]={uid, chan} */
135 	EVENT_NET_MSG_CHANNEL_LEAVE,	/* p[]={uid, chan} */
136 	EVENT_NET_MSG_CHANNEL_TEXT,	/* p[]={uid, chan, text}, i(is /me) */
137 	EVENT_NET_MSG_PRIVATE_OPEN,	/* (uid)p */
138 	EVENT_NET_MSG_PRIVATE_CLOSE,	/* (uid)p */
139 	EVENT_NET_MSG_PRIVATE_TEXT,	/* p[]={uid, text}, i(is /me) */
140 	EVENT_NET_MSG_INFO_REPLY,	/* p[]={uid; login; (GList*)channels; motd; src_ip} */
141 	EVENT_NET_MSG_BEEP_SEND,	/* (uid)p */
142 	EVENT_NET_MSG_BEEP_ACK,		/* (uid)p */
143 	EVENT_NET_MSG_CHANNEL_LIST,	/* p = (GList*)channels */
144 
145 	EVENT_USER	= 0x00800,
146 	EVENT_USER_NEW,			/* (enum user_mode)i,
147 					   p[]={"user_id", nickname, (int)is_active} */
148 	EVENT_USER_REMOVED,		/* p="user_id" */
149 	EVENT_USER_MODE_CHANGE,		/* (enum user_mode)i="prev_mode", (user_id)p */
150 	EVENT_USER_ACTIVE_CHANGE,	/* i="is_active", (user_id)p */
151 	EVENT_USER_RENAME,		/* p[]={uid, previous_nick} */
152 	EVENT_USER_NET_UPDATE_REQ,
153 
154 	EVENT_SESSION	= 0x01000,
155 	EVENT_SESSION_OPENED,		/* (enum session_type)i, (sess_id)p */
156 	EVENT_SESSION_CLOSED,		/* (enum session_type)i, (sess_id)p */
157 	EVENT_SESSION_RENAMED,		/* p[]={sess_id, new_name} */
158 	EVENT_SESSION_TOPIC_CHANGED,	/* p[]={sess_id, new_topic}; i = (gboolean): TRUE if readonly */
159 	EVENT_SESSION_TOPIC_ENTER,	/* p[]={sess_id, new_topic}; */
160 	EVENT_SESSION_TEXT,		/* p[]=(sess_id, text); i = (session_text_type) */
161 
162 	EVENT_PREFS = 0x02000,
163 	EVENT_PREFS_CHANGED,		/* (const gchar * prefs_name)p */
164 	EVENT_PREFS_SAVED,
165 
166 	EVENT_CMDPROC	= 0x04000,
167 	EVENT_CMDPROC_SET_TEXT,
168 	EVENT_CMDPROC_SESSION_TEXT,	/* (boolean)int = me-text	*/
169 
170 	EVENT_MESSAGE	= 0x08000,
171 	EVENT_MESSAGE_SEND,		/* p={uid, text}		*/
172 
173 	EVENT_IDLE	= 0x10000,
174 	EVENT_IDLE_AUTO_AWAY,
175 	EVENT_IDLE_AUTO_OFFLINE,
176 	EVENT_IDLE_NOT
177 };
178 
179 typedef void (*app_event_cb)(enum app_event_enum, void *, int);
180 
181 void register_event_cb(app_event_cb, enum app_event_enum mask);
182 void unregister_event_cb(app_event_cb);
183 void raise_event(enum app_event_enum, void *, int);
184 
185 void log_event_withfree(const gchar *, gchar *, int is_error);
186 void log_event_nofree(const gchar *, const gchar *, int is_error);
187 
188 /* !!!! log_f* funcs free the char * suplied !!!! */
189 #define log_ferror(d,s)	log_event_withfree(d,s,1)
190 #define log_fevent(d,s)	log_event_withfree(d,s,0)
191 #define log_error(d,s)	log_event_nofree(d,s,1)
192 #define log_event(d,s)	log_event_nofree(d,s,0)
193 
194 #define my_nickname()	prefs_str(PREFS_MAIN_NICKNAME)
195 #define set_nickname(s)	prefs_set(PREFS_MAIN_NICKNAME, s)
196 #define my_mode()	(enum user_mode_enum)prefs_int(PREFS_MAIN_MODE)
197 #define set_mode(m)	prefs_set(PREFS_MODE, (int)m)
198 #define IS_MESSAGEABLE_MODE(m) (m==UMODE_NORMAL || m==UMODE_AWAY || m==UMODE_DND)
199 GList * my_channels();
200 
201 /**
202  * channel and nickname compare/validation routines (utf8)
203  */
204 #define nickname_cmp(n1, n2) g_utf8_collate((n1), (n2))
205 int nickname_valid(const char *);
206 
207 int channel_cmp(const char *, const char *);
208 int channel_valid(const char *);
209 
210 /* you have to g_free this string after use */
211 gchar * generate_timestamp();
212 
213 #endif /* #ifndef MAIN_H__ */
214 
215