Thread: [gq-commit] gq/src mainwin.c,1.47,1.48 mainwin.h,1.21,1.22
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-20 09:50:36
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv14130 Modified Files: mainwin.c mainwin.h Log Message: * Added message log history. Might be removed again if it turns out to be of no use Index: mainwin.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/mainwin.c,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** mainwin.c 19 Oct 2003 12:01:31 -0000 1.47 --- mainwin.c 20 Oct 2003 08:08:24 -0000 1.48 *************** *** 238,241 **** --- 238,450 ---- } + + static GList *log_list = NULL; + static int log_list_len = 0; + + void clear_message_history() + { + if (log_list) { + g_list_foreach(log_list, (GFunc) g_free, NULL); + g_list_free(log_list); + log_list = NULL; + } + + if (mainwin.ml_text) { + #if GTK_MAJOR >= 2 + GtkTextIter start; + GtkTextIter end; + + gtk_text_buffer_get_start_iter(mainwin.ml_buffer, &start); + gtk_text_buffer_get_end_iter(mainwin.ml_buffer, &end); + + gtk_text_buffer_delete(mainwin.ml_buffer, &start, &end); + #else + gtk_editable_delete_text(GTK_EDITABLE(mainwin.ml_text), 0, -1); + #endif + } + } + + + void message_log_append(const char *buf) + { + log_list = g_list_append(log_list, g_strdup(buf)); + log_list_len++; + + if (mainwin.ml_text) { + #if GTK_MAJOR >= 2 + GtkTextIter iter; + gtk_text_buffer_get_end_iter(mainwin.ml_buffer, &iter); + gtk_text_buffer_insert(mainwin.ml_buffer, &iter, + buf, strlen(buf)); + gtk_text_buffer_insert(mainwin.ml_buffer, &iter, "\n", 1); + + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(mainwin.ml_text), + gtk_text_buffer_create_mark(mainwin.ml_buffer, + NULL, + &iter, + FALSE), + 0.0, + FALSE, + 0.0, 0.0); + #else + int pos = gtk_text_get_length(GTK_TEXT(mainwin.ml_text)); + gtk_editable_insert_text(GTK_EDITABLE(mainwin.ml_text), buf, + strlen(buf), &pos); + gtk_editable_insert_text(GTK_EDITABLE(mainwin.ml_text), "\n", 1, &pos) + #endif + } + while (log_list_len > MESSAGE_LOG_MAX) { + g_free(log_list->data); + log_list = g_list_remove(log_list, log_list->data); + log_list_len--; + } + } + + static void message_log_destroyed(GtkWidget *window, + struct mainwin_data *win) + { + win->ml_window = NULL; + win->ml_text = NULL; + win->ml_buffer = NULL; + } + + static void clear_clicked(void) + { + clear_message_history(); + } + + static void message_log(struct mainwin_data *win) + { + GtkWidget *window, *vbox0, *scrwin, *text, *bbox, *button; + #if GTK_MAJOR >= 2 + GtkTextBuffer *buffer; + GtkTextIter iter; + #else + int pos = 0; + #endif + GList *I; + + assert(win); + + if (win->ml_window) { + gdk_beep(); /* Is this OK, philosophically? */ + #if GTK_MAJOR >= 2 + gtk_window_present(GTK_WINDOW(win->ml_window)); + #else + gtk_window_activate_focus(GTK_WINDOW(win->ml_window)); + #endif + return; + } + + #if GTK_MAJOR < 2 + window = stateful_gtk_window_new(GTK_WINDOW_DIALOG, + "statusbar-log", 500, 350); + #else + window = stateful_gtk_window_new(GTK_WINDOW_TOPLEVEL, + "statusbar-log", 500, 350); + #endif + win->ml_window = window; + + gtk_widget_realize(window); + + gtk_signal_connect(GTK_OBJECT(window), "destroy", + GTK_SIGNAL_FUNC(message_log_destroyed), win); + + gtk_signal_connect(GTK_OBJECT(window), "key_press_event", + GTK_SIGNAL_FUNC(close_on_esc), + (gpointer) window); + + /* current_search_options_window = window; */ + gtk_window_set_title(GTK_WINDOW(window), _("Message Log")); + gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE); + + vbox0 = gtk_vbox_new(FALSE, 0); + gtk_container_border_width(GTK_CONTAINER(vbox0), + CONTAINER_BORDER_WIDTH); + gtk_widget_show(vbox0); + gtk_container_add(GTK_CONTAINER(window), vbox0); + + /* scrolled window to hold the log */ + scrwin = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_show(scrwin); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwin), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrwin), + GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(vbox0), scrwin, TRUE, TRUE, 0); + + #if GTK_MAJOR >= 2 + text = gtk_text_view_new(); + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); + win->ml_buffer = buffer; + + gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); + gtk_text_buffer_get_end_iter(buffer, &iter); + #else + text = gtk_text_new(NULL, NULL); + gtk_text_set_editable(GTK_TEXT(inputbox), FALSE); + #endif + + win->ml_text = text; + + gtk_widget_show(text); + gtk_container_add(GTK_CONTAINER(scrwin), text); + + for (I = log_list ; I ; I = g_list_next(I) ) { + #if GTK_MAJOR >= 2 + gtk_text_buffer_insert(buffer, &iter, + I->data, strlen(I->data)); + gtk_text_buffer_insert(buffer, &iter, "\n", 1); + #else + gtk_editable_insert_text(GTK_EDITABLE(text), I->data, + strlen(I->data), &pos); + gtk_editable_insert_text(GTK_EDITABLE(text), "\n", 1, &pos) + #endif + } + + #if GTK_MAJOR >= 2 + gtk_text_buffer_get_end_iter(buffer, &iter); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text), + gtk_text_buffer_create_mark(buffer, NULL, + &iter, FALSE), + 0.0, + FALSE, + 0.0, 0.0); + #endif + + bbox = gtk_hbutton_box_new(); + gtk_widget_show(bbox); + + gtk_box_pack_end(GTK_BOX(vbox0), bbox, FALSE, FALSE, 3); + + #if GTK_MAJOR >= 2 + button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); + #else + button = gq_button_new_with_label(_("_Clear")); + #endif + gtk_widget_show(button); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(clear_clicked), + (gpointer) win); + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, TRUE, 10); + + #if GTK_MAJOR >= 2 + button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); + #else + button = gq_button_new_with_label(_("_Close")); + #endif + gtk_widget_show(button); + gtk_signal_connect_object(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + (gpointer) window); + gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, TRUE, 10); + + GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); + gtk_widget_grab_default(button); + + gtk_widget_show(window); + } + /* Callback function called when a tab gets removed from the notebook. */ *************** *** 272,276 **** { GtkWidget *outer_vbox, *main_vbox, *menubar, *menuitem, *submenu; ! GtkWidget *File, *menuFile, *New, *Close, *Quit; GtkWidget *Search, *Browse, *Schema; GtkWidget *menuHelp, *Help, *License, *About; --- 481,485 ---- { GtkWidget *outer_vbox, *main_vbox, *menubar, *menuitem, *submenu; ! GtkWidget *File, *menuFile, *New, *Close, *ShowM, *Quit; GtkWidget *Search, *Browse, *Schema; GtkWidget *menuHelp, *Help, *License, *About; *************** *** 401,404 **** --- 610,622 ---- GTK_SIGNAL_FUNC(ctrl_w_hack), (gpointer) Close); + + /* File | Show Message */ + + ShowM = gq_menu_item_new_with_label(_("Show _Message Log")); + gtk_widget_show(ShowM); + gtk_container_add(GTK_CONTAINER(menuFile), ShowM); + gtk_signal_connect_object(GTK_OBJECT(ShowM), "activate", + GTK_SIGNAL_FUNC(message_log), + (gpointer) win); /* File | Quit */ Index: mainwin.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/mainwin.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** mainwin.h 17 Oct 2003 05:47:49 -0000 1.21 --- mainwin.h 20 Oct 2003 08:08:24 -0000 1.22 *************** *** 46,49 **** --- 46,56 ---- GtkWidget *filtermenu; GHashTable *lastofmode; + + /* the message log window */ + GtkWidget *ml_window; + GtkWidget *ml_text; + #if GTK_MAJOR >= 2 + GtkTextBuffer *ml_buffer; + #endif }; *************** *** 95,98 **** --- 102,109 ---- struct tab *mainwin_get_current_tab(GtkWidget *notebook); + void message_log_append(const char *buf); + void clear_message_history(); + + #define MESSAGE_LOG_MAX 1000 #endif |