/******************************************************************** Copyright (C) 2000 Bassoukos Tassos 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. *********************************************************************/ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "bookmarks.h" #include "protocol.h" #include "connection.h" #include "guiprefs.h" #include "login.h" #include "main.h" #include "smalltrans.h" #include "agreement.h" #include "news.h" #include "news15.h" #include "userlist.h" #include "files.h" #include "pixmap.h" #include "guiutils.h" #include "users.h" #include "hldat.h" static void gui_show_agreement(GtkWidget *w,gpointer data){ Connection *c=(Connection *)data; show_agreement(c); } static void gui_show_files(GtkWidget *w,gpointer data){ Connection *c=(Connection *)data; show_files(c); } static void gui_show_userlist(GtkWidget *w,gpointer data){ Connection *c=(Connection *)data; show_users(c); } static void gui_show_news(GtkWidget *w,gpointer data){ Connection *c=(Connection *)data; if(c->version<150) want_news(c); else want_news_15(c); } static gboolean delete_gui(GtkWidget *widget, GdkEvent *event, gpointer user_data){ Connection *c=(Connection *)user_data; connection_cancel(c); return TRUE; } static void initialize_notebook(Connection *c){ check_userlist(c); check_users(c); check_messages(c); if(c->version<150 || client_version<150) check_news(c); else check_news_15(c); check_files(c); } static void make_bookmark(GtkWidget *w,gpointer data){ Connection *c=(Connection *)data; Bookmark *b=dup_bookmark(c->bookmark); Bookmark *bm=bookmark_dialog(b,_("Add bookmark"),c->gui->main_window); if(bm==NULL){ free(b); } else { add_bookmark(b); } } static GnomeUIInfo server_toolbar[]={ GNOMEUIINFO_ITEM_STOCK(N_("Agreement"),N_("Show Agreement"), gui_show_agreement, HL_STOCK_PIXMAP_AGREEMENT), GNOMEUIINFO_ITEM_STOCK(N_("News"),N_("Show the news"), gui_show_news, HL_STOCK_PIXMAP_NEWS), GNOMEUIINFO_ITEM_STOCK(N_("Files"),N_("Show the files"), gui_show_files, HL_STOCK_PIXMAP_FILES), GNOMEUIINFO_ITEM_STOCK(N_("Users"),N_("Show the Userlist"), gui_show_userlist, HL_STOCK_PIXMAP_USERS), GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_ITEM_STOCK(N_("Bookmark"),N_("Bookmark this site"), make_bookmark, HL_STOCK_PIXMAP_BOOKMARKS), GNOMEUIINFO_END }; void gui_destroy(Connection *c){ if(c->gui==NULL) return; if(c->gui->main_window!=NULL) gtk_widget_destroy(c->gui->main_window); free(c->gui); c->gui=NULL; } static void login_gui_create(Connection *c){ GtkWidget *w; ConnectionGui *cg=(ConnectionGui *)malloc(sizeof(ConnectionGui)); play_sound(HL_SOUND_LOGGED_IN); // cg->toolbar_info=(GnomeUIInfo *)malloc(sizeof(server_toolbar)); // memcpy(cg->toolbar_info,server_toolbar,sizeof(server_toolbar)); cg->toolbar_info = server_toolbar; w=gnome_app_new(PACKAGE "/Server",C_NAME(c)); cg->main_window=w; gnome_app_create_toolbar_with_data(GNOME_APP(w),cg->toolbar_info, (gpointer)c); cg->hbox=gtk_hbox_new(FALSE,0); cg->notebook=gtk_notebook_new(); gtk_notebook_popup_enable(GTK_NOTEBOOK(cg->notebook)); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(cg->notebook),notebook_tab_side); gtk_box_pack_end(GTK_BOX(cg->hbox),cg->notebook,TRUE,TRUE,0); gnome_app_set_contents(GNOME_APP(w),cg->hbox); c->gui=cg; guiprefs_add_window(GTK_WINDOW(w),"Server/Window/Size"); gtk_signal_connect(GTK_OBJECT(w), "delete_event", GTK_SIGNAL_FUNC(delete_gui),(gpointer)c); gtk_widget_set_sensitive(cg->toolbar_info[0].widget,FALSE); gtk_widget_show_all(w); initialize_notebook(c); gtk_signal_connect(GTK_OBJECT(cg->notebook), "switch-page", guiutils_nbpage_change_hook,(gpointer)c); register_window(w,C_NAME(c)); } static void login_done(Connection *c){ if(c->version==0){ login_gui_create(c); if(client_version>=150) users_update_self(c); } return; } gboolean login_done_after_agreement(gpointer c){ if(client_version>=150) users_register_self(c); login_gui_create(c); show_agreement(c); return FALSE; } static void login_handle_reply(Transaction *t,Message *m,gpointer dummy){ HLObject *o; Connection *c=dummy; if(c->task!=NULL) c->task=NULL; if(message_is_error(m)){ o=message_find_object(m,HLO_ERRORMSG); show_error(NULL,NULL,_("Login failed: %s"),o?o->data.string:_("(no reason given)")); connection_cancel(t->c); return; } if((o=message_find_object(m,HLO_SERVERNAME))!=NULL){ free(c->bookmark->name); c->bookmark->name=strdup(o->data.string); } if((o=message_find_object(m,HLO_VERSION))!=NULL){ c->version=o->data.number; } if (c->version == 0) users_update_self(c); if((o=message_find_object(m,HLO_SOCKET))!=NULL){ c->server_socket_no=o->data.number; } login_done(t->c); } void start_login(Connection *c){ Transaction *t; t=transaction_new(c,HLCT_LOGIN); if(c->bookmark->login!=NULL && strlen(c->bookmark->login)>0) message_add_object(t->request,create_string(HLO_LOGIN,c->bookmark->login)); if(c->bookmark->passwd!=NULL && strlen(c->bookmark->passwd)>0) message_add_object(t->request,create_string(HLO_PASSWD,c->bookmark->passwd)); if(client_version>=150) { message_add_object(t->request,create_number(HLO_VERSION,client_version)); } else { message_add_object(t->request,create_string(HLO_NICK,nickname)); message_add_object(t->request,create_number(HLO_ICON,user_icon_number)); } transaction_set_task(t,c->task,0.85); message_set_task(t->request,c->task,0.75,0.85); gtk_signal_connect(GTK_OBJECT(t),"response-received", GTK_SIGNAL_FUNC(login_handle_reply),c); transaction_start(t); }