home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Divers
/
yagirc-0.51.tar.gz
/
yagirc-0.51.tar
/
yagirc-0.51
/
gui.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-11
|
27KB
|
939 lines
/*
gui.c : User interface
Copyright (C) 1998 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glib.h>
#include "os.h"
#include "gui.h"
#include "txt.h"
#include "irc.h"
#include "commands.h"
/*#include <gdk/gdkx.h>
#include <X11/Xlib.h>*/
/* default colors */
GdkColor colors[] =
{
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0x7fff },
{ 0, 0, 0x7fff, 0 },
{ 0, 0, 0x7fff, 0x7fff },
{ 0, 0x7fff, 0, 0 },
{ 0, 0x7fff, 0, 0x7fff },
{ 0, 0x7fff, 0x7fff, 0 },
{ 0, 0xbfff, 0xbfff, 0xbfff },
{ 0, 0x3fff, 0x3fff, 0x3fff },
{ 0, 0, 0, 0xffff },
{ 0, 0, 0xffff, 0 },
{ 0, 0, 0xffff, 0xffff },
{ 0, 0xffff, 0, 0 },
{ 0, 0xffff, 0, 0xffff },
{ 0, 0xffff, 0xffff, 0 },
{ 0, 0xffff, 0xffff, 0xffff },
};
GdkColor default_color, default_bgcolor;
GdkColor yag_colors[15];
/* command history */
#define MAX_CMDHIST_LINES 100
static GList *cmdhist, *histpos;
static int histlines;
static int setup_open;
#define FLAG_BOLD 1
#define FLAG_REVERSE 2
#define FLAG_UNDERLINE 4
static GdkFont *font_normal, *font_bold, *font_italic, *font_bolditalic;
static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
/* parse ANSI color string */
static char *convert_ansi(char *str, int *fgcolor, int *bgcolor, int *flags)
{
char *start;
int fg, bg, fl, num;
if (*str != '[') return str;
start = str;
fg = *fgcolor-1; bg = *bgcolor; fl = *flags;
if (bg != -1) bg--;
str++; num = 0;
for (;; str++)
{
if (*str == '\0') return start;
if (isdigit(*str))
{
num = num*10 + (*str-'0');
continue;
}
if (*str != ';' && *str != 'm') return start;
switch (num)
{
case 0:
/* reset colors back to default */
fg = 7;
bg = -1;
break;
case 1:
/* hilight */
fg |= 8;
break;
case 5:
/* blink */
bg = bg == -1 ? 8 : bg | 8;
break;
case 7:
/* reverse */
fl |= FLAG_REVERSE;
break;
default:
if (num >= 30 && num <= 37)
fg = (fg & 0xf8) + ansitab[num-30];
if (num >= 40 && num <= 47)
{
if (bg == -1) bg = 0;
bg = (bg & 0xf8) + ansitab[num-40];
}
break;
}
num = 0;
if (*str == 'm')
{
*fgcolor = fg+1;
*bgcolor = bg == -1 ? -1 : bg+1;
*flags = fl;
str++;
break;
}
}
return str;
}
int gui_is_sb_down(WINDOW_REC *win)
{
GtkAdjustment *adj;
g_return_val_if_fail(win != NULL, 1);
g_return_val_if_fail(win->gui != NULL, 1);
adj = win->gui->text->vadj;
return adj->value == adj->upper - adj->lower - adj->page_size;
}
void gui_set_sb_down(WINDOW_REC *win)
{
GtkAdjustment *adj;
g_return_if_fail(win != NULL);
g_return_if_fail(win->gui != NULL);
adj = win->gui->text->vadj;
gtk_adjustment_set_value(adj, adj->upper - adj->lower - adj->page_size);
}
/* Write text to window */
static void printtext(char *str, WINDOW_REC *win)
{
char *ptr, type;
GdkColor *fg, *bg;
int fgcolor, bgcolor;
int flags;
int scroll_down;
g_return_if_fail(str != NULL);
g_return_if_fail(win != NULL);
g_return_if_fail(win->gui != NULL);
scroll_down = gui_is_sb_down(win);
gtk_text_freeze (win->gui->text);
gtk_text_insert (win->gui->text, NULL, NULL, NULL, "\n", 1);
if (win->gui->lines < MAX_TEXTLINES_HISTORY)
{
win->gui->linelen[win->gui->lines++] = strlen(str)+1;
}
else
{
gtk_text_set_point(win->gui->text, 0);
gtk_text_forward_delete(win->gui->text, win->gui->linelen[0]);
gtk_text_set_point(win->gui->text, gtk_text_get_length(win->gui->text));
memmove(win->gui->linelen, &win->gui->linelen[1],
(MAX_TEXTLINES_HISTORY-1)*sizeof(win->gui->linelen[0]));
win->gui->linelen[MAX_TEXTLINES_HISTORY-1] = strlen(str)+1;
}
flags = 0;
fg = &default_color; fgcolor = -2; bgcolor = -1; type = '\0';
while (*str != '\0')
{
for (ptr = str; *ptr != '\0'; ptr++)
if (*ptr == 2 || *ptr == 3 || *ptr == 4 || *ptr == 22 || *ptr == 27 || *ptr == 31)
{
type = *ptr;
*ptr++ = '\0';
break;
}
if (*str != '\0')
{
GdkFont *font;
if (flags & FLAG_BOLD)
font = flags & FLAG_UNDERLINE ? font_bolditalic : font_bold;
else if (flags & FLAG_UNDERLINE)
font = font_italic;
else
font = font_normal;
if (flags & FLAG_REVERSE)
{
if (fgcolor == -2) bg = fg; else bg = &colors[fgcolor];
fg = bgcolor == -1 ? &default_bgcolor : &colors[bgcolor];
}
else
{
if (fgcolor != -2) fg = &colors[fgcolor];
bg = bgcolor == -1 ? NULL : &colors[bgcolor];
}
gtk_text_insert (win->gui->text, font, fg, bg, str, -1);
}
if (*ptr == '\0') break;
if (type == '\0')
{
/* ... */
}
else if (type == 2)
{
/* bold */
flags ^= FLAG_BOLD;
}
else if (type == 22)
{
/* reverse */
flags ^= FLAG_REVERSE;
}
else if (type == 31)
{
/* underline, display as italic.. */
flags ^= FLAG_UNDERLINE;
}
else if (type == 27)
{
/* ansi color code */
ptr = convert_ansi(ptr, &fgcolor, &bgcolor, &flags);
}
else if (type == 4)
{
/* user specific colors */
fg = &yag_colors[((int) *ptr++)-1];
fgcolor = -2;
bgcolor = -1;
}
else if (type == 3)
{
/* color! */
if (*ptr < 16)
{
fgcolor = *ptr++;
bgcolor = -1;
}
else
{
fgcolor = 0; bgcolor = -1;
if (!isdigit(*ptr))
fgcolor = -2;
else
{
/* foreground color */
fgcolor = *ptr++-'0';
if (isdigit(*ptr))
fgcolor = fgcolor*10 + (*ptr++-'0');
fgcolor++;
if (*ptr == ',')
{
/* back color */
bgcolor = 0;
if (!isdigit(*++ptr))
bgcolor = -1;
else
{
bgcolor = *ptr++-'0';
if (isdigit(*ptr))
bgcolor = bgcolor*10 + (*ptr++-'0');
bgcolor++;
}
}
}
}
}
str = ptr;
}
gtk_text_thaw (win->gui->text);
if (scroll_down) gui_set_sb_down(win);
}
void gui_update_statusbar(WINDOW_REC *win)
{
char str[200];
int connected;
GList *tmp;
int windows;
char *act, *ptr;
if (win != NULL && win != win->gui->parent->selected)
{
/* window is hidden - status doesn't need to be displayed */
return;
}
/* find which windows have new text */
windows = g_list_length(winlist);
if (windows == 0)
act = NULL;
else
{
act = (char *) g_malloc0(windows*(sprintf(str, "%d", windows)+1)+10);
ptr = act;
for (tmp = g_list_first(winlist); tmp != NULL; tmp = tmp->next)
{
WINDOW_REC *w;
w = (WINDOW_REC *) tmp->data;
if (w->new_data)
{
if (act == ptr) ptr += sprintf(ptr, "[ act: ");
ptr += sprintf(ptr, "%d ", w->num);
}
}
if (ptr != act) strcpy(ptr, "]");
}
for (tmp = g_list_first(winlist); tmp != NULL || win != NULL; tmp = tmp->next)
{
WINDOW_REC *w;
SERVER_REC *server;
w = win != NULL ? win : (WINDOW_REC *) tmp->data;
server = w->curchan == NULL ? w->defserv : w->curchan->server;
connected = server != NULL && server->connected;
g_snprintf(str, 200, "[ window %d ] [ %s ] [ %s%s ] %s",
w->num,
connected ? server->nick : default_nick,
connected ? _("Connected to ") : _("Not connected"),
connected ? server->name : "",
act == NULL ? "" : act);
gtk_statusbar_pop(GTK_STATUSBAR(w->gui->parent->statusbar), 1);
gtk_statusbar_push(GTK_STATUSBAR(w->gui->parent->statusbar), 1, str);
if (win != NULL) break;
}
if (act != NULL) g_free(act);
}
void gui_set_style(GtkWidget *widget, char *channel)
{
GtkStyle style;
GdkPixmap *pixmap;
GdkBitmap *mask;
memcpy(&style, gtk_widget_get_style(widget), sizeof(GtkStyle));
/* single color */
style.bg[0] = default_bgcolor;
gdk_color_alloc(gtk_widget_get_colormap(widget), &default_bgcolor);
if (default_text_pixmap != NULL)
{
/* pixmap */
pixmap = gdk_pixmap_create_from_xpm(widget->window, &mask, NULL,
default_text_pixmap);
style.bg_pixmap[0] = pixmap;
}
gtk_widget_set_style(widget, &style);
}
/* set window style for all windows */
void gui_refresh_windows(void)
{
GList *tmp;
for (tmp = g_list_first(winlist); tmp != NULL; tmp = tmp->next)
{
WINDOW_REC *w;
w = (WINDOW_REC *) tmp->data;
gui_set_style(GTK_WIDGET(w->gui->text),
w->curchan == NULL ? NULL : w->curchan->name);
}
}
/* allocate colors */
static void init_colors(GtkWidget *window)
{
int n;
g_return_if_fail(window != NULL);
for (n = 0; n < COLORS; n++)
{
colors[n].pixel =
(gulong)((colors[n].red & 0xff00)*256 +
(colors[n].green & 0xff00) +
(colors[n].blue & 0xff00)/256);
gdk_color_alloc(gtk_widget_get_colormap(window), &colors[n]);
}
for (n = 0; n < 15; n++)
{
yag_colors[n].pixel =
(gulong)((yag_colors[n].red & 0xff00)*256 +
(yag_colors[n].green & 0xff00) +
(yag_colors[n].blue & 0xff00)/256);
gdk_color_alloc(gtk_widget_get_colormap(window), &yag_colors[n]);
}
gdk_color_alloc(gtk_widget_get_colormap(window), &default_color);
gdk_color_alloc(gtk_widget_get_colormap(window), &default_bgcolor);
}
/* signal: enter pressed - process entry */
static int enter_text(GtkEntry *entry)
{
if (entry->text == NULL || *entry->text == '\0') return 0;
/* save line for history */
if (histlines >= MAX_CMDHIST_LINES)
{
g_free(g_list_first(cmdhist)->data);
cmdhist = g_list_remove_link(cmdhist, g_list_first(cmdhist));
}
else
histlines++;
cmdhist = g_list_append(cmdhist, g_strdup(entry->text));
irc_parse_outgoing(curwin->curchan, entry->text);
gtk_entry_set_text(entry, "");
histpos = NULL;
return 0;
}
/* signal: key pressed in entry field */
int keyevent(GtkWidget *widget, GdkEventKey *event, GtkEntry *entry)
{
GList *pos;
gtk_widget_grab_focus(GTK_WIDGET(entry));
switch (event->keyval)
{
case GDK_Up:
/* previous line */
pos = histpos;
if (histpos == NULL)
histpos = g_list_last(cmdhist);
else
histpos = histpos->prev;
if (*entry->text != '\0' &&
(pos == NULL || strcmp(pos->data, entry->text) != 0))
{
/* save the old entry to history */
if (histlines >= MAX_CMDHIST_LINES)
{
g_free(g_list_first(cmdhist)->data);
cmdhist = g_list_remove_link(cmdhist, g_list_first(cmdhist));
}
cmdhist = g_list_append(cmdhist, g_strdup(entry->text));
}
gtk_entry_set_text(entry, histpos == NULL ? "" : histpos->data);
break;
case GDK_Down:
/* next line */
pos = histpos;
if (histpos == NULL)
histpos = g_list_first(cmdhist);
else
histpos = histpos->next;
if (*entry->text != '\0' &&
(pos == NULL || strcmp(pos->data, entry->text) != 0))
{
/* save the old entry to history */
if (histlines >= MAX_CMDHIST_LINES)
{
g_free(g_list_first(cmdhist)->data);
cmdhist = g_list_remove_link(cmdhist, g_list_first(cmdhist));
}
cmdhist = g_list_prepend(cmdhist, g_strdup(entry->text));
}
gtk_entry_set_text(entry, histpos == NULL ? "" : histpos->data);
break;
case GDK_Page_Up:
/* scrollback buffer up.. */
{
GtkAdjustment *adj;
int val;
adj = curwin->gui->text->vadj;
val = adj->value - (adj->page_size/2);
gtk_adjustment_set_value(adj, val > 0 ? val : 0);
}
break;
case GDK_Page_Down:
/* scrollback buffer down.. */
{
GtkAdjustment *adj;
int val, max;
adj = curwin->gui->text->vadj;
val = adj->value + (adj->page_size/2);
max = adj->upper - adj->lower - adj->page_size;
gtk_adjustment_set_value(adj, val <= max ? val : max);
}
break;
default:
if (event->keyval >= '0' && event->keyval <= '9' && (event->state & 0x0d) == 8)
{
/* alt-1..0 pressed */
GList *tmp;
tmp = g_list_nth(winlist, event->keyval == '0' ? 9 : event->keyval-'0'-1);
if (tmp != NULL) gui_window_select((WINDOW_REC *) tmp->data);
}
return 0;
}
/* key was used, stop signal */
gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event");
return 1;
}
/* signal: window closed */
static int delete_event(GtkWidget *window, GtkWidget *t, GUI_TOPWIN_REC *win)
{
GList *tmp, *next;
/* close all subwindows in this window */
tmp = g_list_first(win->windows);
while (tmp != NULL)
{
next = tmp->next;
irc_window_close(tmp->data);
tmp = next;
}
return 0;
}
/* signal: got focus for some widget */
static void got_focus(GtkWindow *a, GtkWidget *b, GUI_TOPWIN_REC *top)
{
irc_window_focus(top->selected);
}
static void size_request(GtkWidget *win, GtkRequisition *req)
{
if (win->allocation.width < 50) req->width = gdk_screen_width()*2/3;
if (win->allocation.height <= 1) req->height = gdk_screen_height()/2;
}
/* Create new toplevel window */
static void gui_top_window_new(WINDOW_REC *win)
{
GUI_TOPWIN_REC *top;
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkWidget *entry;
GtkWidget *statusbar;
GtkWidget *nickscroll;
g_return_if_fail(win != NULL);
top = (GUI_TOPWIN_REC *) g_malloc(sizeof(GUI_TOPWIN_REC));
memset(top, 0, sizeof(GUI_TOPWIN_REC));
win->gui->parent = top;
top->windows = g_list_append(NULL, win);
/* main window */
#ifdef USE_GNOME
top->mainwin = window = gnome_app_new("yagIRC", PROGRAM_TITLE);
#else
top->mainwin = window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), PROGRAM_TITLE);
#endif
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC(delete_event), top);
gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
GTK_SIGNAL_FUNC(got_focus), top);
gtk_signal_connect (GTK_OBJECT (window), "size_request",
GTK_SIGNAL_FUNC(size_request), window);
/*
setting size here doesn't work - if window is resized and nicklist changes
it's always resized back to startup size, don't know why.. so size_request
signal works for now.
gtk_widget_set_usize(window, gdk_screen_width()*2/3, gdk_screen_height()/2);
*/
gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
vbox = gtk_vbox_new(FALSE, 0);
#ifdef USE_GNOME
gnome_app_set_contents(GNOME_APP(window), vbox);
#else
gtk_container_add(GTK_CONTAINER(window), vbox);
#endif
gtk_widget_show(vbox);
/* menu */
gui_menu_create(win);
/*gtk_window_add_accelerator_table(GTK_WINDOW(window), top->table);*/
#ifdef USE_GNOME
gnome_app_set_menus(GNOME_APP(window), GTK_MENU_BAR(top->menubar));
#else
gtk_box_pack_start(GTK_BOX(vbox), top->menubar, FALSE, TRUE, 0);
gtk_widget_show(top->menubar);
#endif
/* channel list */
top->chanbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), top->chanbox, FALSE, FALSE, 0);
gtk_widget_show(top->chanbox);
top->hbox = hbox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(vbox), hbox);
gtk_widget_show(hbox);
/* nick list */
nickscroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(nickscroll),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(hbox), nickscroll, FALSE, FALSE, 0);
gtk_widget_show (nickscroll);
gtk_widget_set_usize(nickscroll, 120, -1);
top->nicklist = gtk_list_new();
gtk_list_set_selection_mode (GTK_LIST(top->nicklist), GTK_SELECTION_BROWSE);
gtk_signal_connect (GTK_OBJECT (top->nicklist), "button_press_event",
GTK_SIGNAL_FUNC(signick_button_pressed), win);
gtk_signal_connect (GTK_OBJECT (top->nicklist), "button_release_event",
GTK_SIGNAL_FUNC(signick_button_released), win);
gtk_container_add(GTK_CONTAINER(nickscroll), top->nicklist);
gtk_widget_show(top->nicklist);
top->nicklistlen = 0;
/* entry field */
top->entry = entry = gtk_entry_new_with_max_length(490);
gtk_signal_connect (GTK_OBJECT (entry), "activate",
GTK_SIGNAL_FUNC(enter_text), NULL);
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
gtk_widget_show(entry);
/* redirect all key presses in window to entry field */
gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
GTK_SIGNAL_FUNC(keyevent), entry);
top->statusbar = statusbar = gtk_statusbar_new();
gtk_statusbar_push(GTK_STATUSBAR(top->statusbar), 1, "");
gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
gtk_widget_show(statusbar);
init_colors(window);
gui_update_statusbar(win);
gtk_widget_show(window);
}
void gui_window_init(WINDOW_REC *win, WINDOW_REC *parent)
{
GtkWidget *text;
GtkWidget *textscroll;
win->drawfunc = (DRAW_FUNC) printtext;
win->drawfuncdata = win;
win->gui = (GUI_WINDOW_REC *) g_malloc(sizeof(GUI_WINDOW_REC));
memset(win->gui, 0, sizeof(GUI_WINDOW_REC));
if (parent == NULL)
{
gui_top_window_new(win);
}
else
{
win->gui->parent = parent->gui->parent;
win->gui->parent->windows = g_list_append(win->gui->parent->windows, win);
}
/* irc text field */
text = gtk_text_new(NULL, NULL);
win->gui->text = GTK_TEXT(text);
gtk_signal_connect (GTK_OBJECT (text), "button_release_event",
GTK_SIGNAL_FUNC(sigchantext_button_released), win);
gtk_box_pack_start(GTK_BOX(win->gui->parent->hbox), text, TRUE, TRUE, 0);
gtk_box_reorder_child(GTK_BOX(win->gui->parent->hbox), text, 0);
gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
win->gui->textscroll = textscroll =
gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
gtk_box_pack_start(GTK_BOX(win->gui->parent->hbox), textscroll, FALSE, FALSE, 0);
gtk_box_reorder_child(GTK_BOX(win->gui->parent->hbox), textscroll, 1);
gui_window_select(win);
gui_set_style(text, NULL);
}
/* Deinitialize IRC window */
void gui_window_deinit(WINDOW_REC *window)
{
g_return_if_fail(window != NULL);
if (window->gui->parent->selected == window)
window->gui->parent->selected = NULL;
gtk_widget_destroy(GTK_WIDGET(window->gui->text));
gtk_widget_destroy(window->gui->textscroll);
window->gui->parent->windows =
g_list_remove(window->gui->parent->windows, window);
if (window->gui->parent->windows == NULL)
{
/* Remove main window */
gtk_widget_destroy(window->gui->parent->mainwin);
g_free(window->gui->parent); window->gui->parent = NULL;
}
g_free(window->gui); window->gui = NULL;
if (winlist == NULL)
{
/* This was the last window */
gtk_main_quit();
}
}
/* IRC channel/window changed, update everything you can think of.. */
void gui_window_update(WINDOW_REC *win)
{
g_return_if_fail(win != NULL);
/* Enable/disable (dis)connect menu items */
if (cserver == NULL)
{
menus_set_sensitive(win, "<Main>/IRC/Connect", TRUE);
menus_set_sensitive(win, "<Main>/IRC/Disconnect", FALSE);
}
else
{
menus_set_sensitive(win, "<Main>/IRC/Connect", FALSE);
menus_set_sensitive(win, "<Main>/IRC/Disconnect", TRUE);
}
}
/* Change focus to specified window */
void gui_window_select(WINDOW_REC *win)
{
GUI_WINDOW_REC *gui;
int scroll_down;
g_return_if_fail(win != NULL);
if (curwin != NULL && win->gui->parent != curwin->gui->parent)
{
/* not in same toplevel window .. we should set focus to that window,
but how?? Didn't find any such function from GDK/GTK, XSetInputFocus
changes to that window but WM doesn't notice the change so I think it
should be done with some WM hints.. If there is such... */
gdk_window_raise(win->gui->parent->mainwin->window);
/*XSetInputFocus(GDK_WINDOW_XDISPLAY(win->gui->parent->mainwin->window),
GDK_WINDOW_XWINDOW(win->gui->parent->mainwin->window),
RevertToParent, CurrentTime);*/
/*gtk_widget_grab_focus(win->gui->parent->mainwin);*/
}
scroll_down = gui_is_sb_down(win);
if (win->gui->parent->selected != NULL)
{
/* Hide old window */
gui = win->gui->parent->selected->gui;
gtk_widget_hide(GTK_WIDGET(gui->text));
gtk_widget_hide(gui->textscroll);
}
gtk_widget_show(GTK_WIDGET(win->gui->text));
gtk_widget_show(win->gui->textscroll);
win->gui->parent->selected = win;
irc_window_focus(win);
if (win->curchan != NULL)
gui_select_channel(win, win->curchan);
else
gui_draw_channel(win, NULL);
gui_update_statusbar(curwin);
}
/* Quit program requested */
void gui_exit(void)
{
gtk_main_quit();
}
/* Someone in notify list joined IRC */
void gui_notify_join(char *nick)
{
drawtext(curwin, TXT_TYPE_NOTICE, IRCTXT_IRCJOIN, nick);
}
/* Someone in notify list left IRC */
void gui_notify_part(char *nick)
{
drawtext(curwin, TXT_TYPE_NOTICE, IRCTXT_IRCPART, nick);
}
/* server got connected */
void gui_connected(SERVER_REC *serv, int state)
{
gui_update_statusbar(NULL);
}
#ifdef USE_GNOME
/* drop signal: channel dropped to desktop */
static void rootwin_drop(GtkWidget *widget, GdkEvent *event)
{
WINDOW_REC *win;
CHAN_REC *from;
from = *((CHAN_REC **) event->dropdataavailable.data);
win = irc_window_new(cserver, NULL);
win->curchan = from;
gui_select_channel(win, from);
}
#endif
/* Initialize GUI */
void gui_init(void)
{
#ifdef USE_GNOME
char *channel_drop_types[] = {"yagirc/channel"};
GtkWidget *root;
#endif
histlines = 0;
cmdhist = NULL;
setup_open = 0;
if (!gui_read_config())
{
/* configuration file not created yet - run setup */
setup_open = 1;
gui_write_config();
}
font_normal = gdk_font_load("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*");
font_bold = gdk_font_load("-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*");
font_italic = gdk_font_load("-adobe-helvetica-medium-o-normal--*-120-*-*-*-*-*-*");
font_bolditalic = gdk_font_load("-adobe-helvetica-bold-o-normal--*-120-*-*-*-*-*-*");
#ifdef USE_GNOME
/* dropping channels to desktop creates new window for them */
root = gnome_rootwin_new();
gtk_signal_connect (GTK_OBJECT(root), "drop_data_available_event",
GTK_SIGNAL_FUNC(rootwin_drop), NULL);
gtk_widget_show(root);
gtk_widget_dnd_drop_set (root, TRUE, channel_drop_types, 1, FALSE);
#endif
}
/* deinitialize GUI */
void gui_deinit(void)
{
GList *tmp;
if (cmdhist != NULL)
{
for (tmp = g_list_first(cmdhist); tmp != NULL; tmp = tmp->next)
g_free(tmp->data);
g_list_free(cmdhist);
}
}
int main (int argc, char *argv[])
{
WINDOW_REC *window;
#ifdef USE_GNOME
gnome_init ("yagIRC", NULL, argc, argv, 0, NULL);
#else
gtk_init (&argc, &argv);
#endif
gui_setup_init();
gui_init();
irc_init();
window = irc_window_new(NULL, NULL);
if (setup_open) gui_setup();
gtk_main ();
irc_deinit();
gui_deinit();
gui_setup_deinit();
return 0;
}