2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
26 #include <sys/types.h>
29 #include "../common/xchat.h"
30 #include "../common/xchatc.h"
31 #include "../common/outbound.h"
32 #include "../common/util.h"
33 #include "../common/fe.h"
37 static GSList
*tmr_list
; /* timer list */
38 static int tmr_list_count
;
39 static GSList
*se_list
; /* socket event list */
40 static int se_list_count
;
41 static int done
= FALSE
; /* finished ? */
45 send_command (char *cmd
)
47 handle_multiline (sess_list
->data
, cmd
, TRUE
, FALSE
);
55 static char inbuf
[1024];
58 len
= read (STDIN_FILENO
, tmpbuf
, sizeof tmpbuf
- 1);
74 inbuf
[pos
] = tmpbuf
[i
];
75 if (pos
< (sizeof inbuf
- 2))
82 static int done_intro
= 0;
85 fe_new_window (struct session
*sess
, int focus
)
89 sess
->gui
= malloc (4);
91 if (!sess
->server
->front_session
)
92 sess
->server
->front_session
= sess
;
93 if (!sess
->server
->server_session
)
94 sess
->server
->server_session
= sess
;
102 snprintf (buf
, sizeof (buf
),
104 " \017xchat \00310"PACKAGE_VERSION
"\n"
105 " \017Running on \00310%s \017glib \00310%d.%d.%d\n"
107 glib_major_version
, glib_minor_version
, glib_micro_version
);
108 fe_print_text (sess
, buf
, 0);
110 fe_print_text (sess
, "\n\nCompiled in Features\0032:\017 "
129 get_stamp_str (time_t tim
, char *dest
, int size
)
131 return strftime (dest
, size
, prefs
.stamp_format
, localtime (&tim
));
139 get_stamp_str (time (0), stampbuf
, sizeof (stampbuf
));
140 strcat (buf
, stampbuf
);
141 return strlen (stampbuf
);
144 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
145 static const short colconv
[] = { 0, 7, 4, 2, 1, 3, 5, 11, 13, 12, 6, 16, 14, 15, 10, 7 };
148 fe_print_text (struct session
*sess
, char *text
, time_t stamp
)
152 int reverse
= 0, under
= 0, bold
= 0,
153 comma
, k
, i
= 0, j
= 0, len
= strlen (text
);
154 unsigned char *newtext
= malloc (len
+ 1024);
159 j
+= timecat (newtext
);
163 if (dotime
&& text
[i
] != 0)
167 j
+= timecat (newtext
);
173 if (!isdigit (text
[i
]))
188 if (text
[i
] >= '0' && text
[i
] <= '9' && k
< 2)
211 mirc
= colconv
[mirc
];
215 sprintf ((char *) &newtext
[j
], "%dm", mirc
+ col
);
218 sprintf ((char *) &newtext
[j
], "%dm", mirc
+ col
);
220 j
= strlen (newtext
);
235 case '\026': /* REVERSE */
239 strcpy (&newtext
[j
], "\033[27m");
243 strcpy (&newtext
[j
], "\033[7m");
245 j
= strlen (newtext
);
247 case '\037': /* underline */
251 strcpy (&newtext
[j
], "\033[24m");
255 strcpy (&newtext
[j
], "\033[4m");
257 j
= strlen (newtext
);
259 case '\002': /* bold */
263 strcpy (&newtext
[j
], "\033[22m");
267 strcpy (&newtext
[j
], "\033[1m");
269 j
= strlen (newtext
);
272 if (!prefs
.filterbeep
)
274 newtext
[j
] = text
[i
];
278 case '\017': /* reset all */
279 strcpy (&newtext
[j
], "\033[m");
295 newtext
[j
] = text
[i
];
304 write (STDOUT_FILENO
, newtext
, j
);
309 fe_timeout_remove (int tag
)
317 te
= (timerevent
*) list
->data
;
320 tmr_list
= g_slist_remove (tmr_list
, te
);
329 fe_timeout_add (int interval
, void *callback
, void *userdata
)
332 timerevent
*te
= malloc (sizeof (timerevent
));
334 tmr_list_count
++; /* this overflows at 2.2Billion, who cares!! */
336 te
->tag
= tmr_list_count
;
337 te
->interval
= interval
;
338 te
->callback
= callback
;
339 te
->userdata
= userdata
;
341 gettimeofday (&now
, NULL
);
342 te
->next_call
= now
.tv_sec
* 1000 + (now
.tv_usec
/ 1000) + te
->interval
;
344 tmr_list
= g_slist_prepend (tmr_list
, te
);
350 fe_input_remove (int tag
)
358 se
= (socketevent
*) list
->data
;
361 se_list
= g_slist_remove (se_list
, se
);
370 fe_input_add (int sok
, int flags
, void *func
, void *data
)
372 socketevent
*se
= malloc (sizeof (socketevent
));
374 se_list_count
++; /* this overflows at 2.2Billion, who cares!! */
376 se
->tag
= se_list_count
;
378 se
->rread
= flags
& FIA_READ
;
379 se
->wwrite
= flags
& FIA_WRITE
;
380 se
->eexcept
= flags
& FIA_EX
;
383 se_list
= g_slist_prepend (se_list
, se
);
389 fe_args (int argc
, char *argv
[])
393 if (!strcasecmp (argv
[1], "--version") || !strcasecmp (argv
[1], "-v"))
395 puts (PACKAGE_VERSION
);
410 prefs
.use_server_tab
= 0;
411 prefs
.autodialog
= 0;
413 prefs
.slist_skip
= 1;
419 struct timeval timeout
, now
;
424 guint64 shortest
, delay
;
427 new_ircwindow (NULL
, NULL
, SESS_SERVER
, 0);
438 se
= (socketevent
*) list
->data
;
440 FD_SET (se
->sok
, &rd
);
442 FD_SET (se
->sok
, &wd
);
444 FD_SET (se
->sok
, &ex
);
448 FD_SET (STDIN_FILENO
, &rd
); /* for reading keyboard */
450 /* find the shortest timeout event */
455 te
= (timerevent
*) list
->data
;
456 if (te
->next_call
< shortest
|| shortest
== 0)
457 shortest
= te
->next_call
;
460 gettimeofday (&now
, NULL
);
461 delay
= shortest
- ((now
.tv_sec
* 1000) + (now
.tv_usec
/ 1000));
462 timeout
.tv_sec
= delay
/ 1000;
463 timeout
.tv_usec
= (delay
% 1000) * 1000;
465 select (FD_SETSIZE
, &rd
, &wd
, &ex
, &timeout
);
467 if (FD_ISSET (STDIN_FILENO
, &rd
))
470 /* set all checked flags to false */
474 se
= (socketevent
*) list
->data
;
479 /* check all the socket callbacks */
483 se
= (socketevent
*) list
->data
;
485 if (se
->rread
&& FD_ISSET (se
->sok
, &rd
))
487 se
->callback (NULL
, 1, se
->userdata
);
488 } else if (se
->wwrite
&& FD_ISSET (se
->sok
, &wd
))
490 se
->callback (NULL
, 2, se
->userdata
);
491 } else if (se
->eexcept
&& FD_ISSET (se
->sok
, &ex
))
493 se
->callback (NULL
, 4, se
->userdata
);
498 se
= (socketevent
*) list
->data
;
504 se
= (socketevent
*) list
->data
;
509 /* now check our list of timeout events, some might need to be called! */
510 gettimeofday (&now
, NULL
);
514 te
= (timerevent
*) list
->data
;
516 if (now
.tv_sec
* 1000 + (now
.tv_usec
/ 1000) >= te
->next_call
)
518 /* if the callback returns 0, it must be removed */
519 if (te
->callback (te
->userdata
) == 0)
521 fe_timeout_remove (te
->tag
);
524 te
->next_call
= now
.tv_sec
* 1000 + (now
.tv_usec
/ 1000) + te
->interval
;
539 fe_new_server (struct server
*serv
)
541 serv
->gui
= malloc (4);
545 fe_message (char *msg
, int flags
)
551 fe_close_window (struct session
*sess
)
564 fe_add_rawlog (struct server
*serv
, char *text
, int len
, int outbound
)
568 fe_set_topic (struct session
*sess
, char *topic
, char *stripped_topic
)
576 fe_set_hilight (struct session
*sess
)
580 fe_set_tab_color (struct session
*sess
, int col
)
584 fe_update_mode_buttons (struct session
*sess
, char mode
, char sign
)
588 fe_update_channel_key (struct session
*sess
)
592 fe_update_channel_limit (struct session
*sess
)
596 fe_is_chanwindow (struct server
*serv
)
602 fe_add_chan_list (struct server
*serv
, char *chan
, char *users
, char *topic
)
606 fe_chan_list_end (struct server
*serv
)
610 fe_is_banwindow (struct session
*sess
)
615 fe_add_ban_list (struct session
*sess
, char *mask
, char *who
, char *when
, int is_exemption
)
619 fe_ban_list_end (struct session
*sess
, int is_exemption
)
623 fe_notify_update (char *name
)
627 fe_notify_ask (char *name
, char *networks
)
631 fe_text_clear (struct session
*sess
, int lines
)
635 fe_progressbar_start (struct session
*sess
)
639 fe_progressbar_end (struct server
*serv
)
643 fe_userlist_insert (struct session
*sess
, struct User
*newuser
, int row
, int sel
)
647 fe_userlist_remove (struct session
*sess
, struct User
*user
)
652 fe_userlist_rehash (struct session
*sess
, struct User
*user
)
656 fe_userlist_move (struct session
*sess
, struct User
*user
, int new_row
)
660 fe_userlist_numbers (struct session
*sess
)
664 fe_userlist_clear (struct session
*sess
)
668 fe_userlist_set_selected (struct session
*sess
)
672 fe_dcc_add (struct DCC
*dcc
)
676 fe_dcc_update (struct DCC
*dcc
)
680 fe_dcc_remove (struct DCC
*dcc
)
684 fe_clear_channel (struct session
*sess
)
688 fe_session_callback (struct session
*sess
)
692 fe_server_callback (struct server
*serv
)
696 fe_url_add (const char *text
)
700 fe_pluginlist_update (void)
704 fe_buttons_update (struct session
*sess
)
708 fe_dlgbuttons_update (struct session
*sess
)
712 fe_dcc_send_filereq (struct session
*sess
, char *nick
, int maxcps
, int passive
)
716 fe_set_channel (struct session
*sess
)
720 fe_set_title (struct session
*sess
)
724 fe_set_nonchannel (struct session
*sess
, int state
)
728 fe_set_nick (struct server
*serv
, char *newnick
)
732 fe_change_nick (struct server
*serv
, char *nick
, char *newnick
)
736 fe_ignore_update (int level
)
740 fe_dcc_open_recv_win (int passive
)
745 fe_dcc_open_send_win (int passive
)
750 fe_dcc_open_chat_win (int passive
)
755 fe_userlist_hide (session
* sess
)
759 fe_lastlog (session
* sess
, session
* lastlog_sess
, char *sstr
, gboolean regexp
)
763 fe_set_lag (server
* serv
, int lag
)
767 fe_set_throttle (server
* serv
)
771 fe_set_away (server
*serv
)
775 fe_serverlist_open (session
*sess
)
779 fe_get_str (char *prompt
, char *def
, void *callback
, void *ud
)
783 fe_get_int (char *prompt
, int def
, void *callback
, void *ud
)
787 fe_idle_add (void *func
, void *data
)
791 fe_ctrl_gui (session
*sess
, fe_gui_action action
, int arg
)
795 fe_gui_info (session
*sess
, int info_type
)
800 fe_gui_info_ptr (session
*sess
, int info_type
)
804 void fe_confirm (const char *message
, void (*yesproc
)(void *), void (*noproc
)(void *), void *ud
)
807 char *fe_get_inputbox_contents (struct session
*sess
)
811 void fe_set_inputbox_contents (struct session
*sess
, char *text
)
814 int fe_get_inputbox_cursor (struct session
*sess
)
818 void fe_set_inputbox_cursor (struct session
*sess
, int delta
, int pos
)
821 void fe_open_url (const char *url
)
824 void fe_menu_del (menu_entry
*me
)
827 char *fe_menu_add (menu_entry
*me
)
831 void fe_menu_update (menu_entry
*me
)
834 void fe_uselect (struct session
*sess
, char *word
[], int do_clear
, int scroll_to
)
838 fe_server_event (server
*serv
, int type
, int arg
)
842 fe_flash_window (struct session
*sess
)
845 void fe_get_file (const char *title
, char *initial
,
846 void (*callback
) (void *userdata
, char *file
), void *userdata
,
850 void fe_tray_set_flash (const char *filename1
, const char *filename2
, int timeout
){}
851 void fe_tray_set_file (const char *filename
){}
852 void fe_tray_set_icon (feicon icon
){}
853 void fe_tray_set_tooltip (const char *text
){}
854 void fe_tray_set_balloon (const char *title
, const char *text
){}
855 void fe_userlist_update (session
*sess
, struct User
*user
){}