Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

log_window.c File Reference

#include "intl.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <assert.h>
#include "globals.h"
#include "gtk_eb_html.h"
#include "log_window.h"
#include "util.h"
#include "pixmaps/cancel.xpm"

Include dependency graph for log_window.c:

Include dependency graph

Go to the source code of this file.

Functions

void free_string_list (gpointer data, gpointer user_data)
void free_gs_list (gpointer data, gpointer user_data)
void create_html_widget (log_window *lw)
void set_html_text (GSList *gl, log_window *lw)
void load_log_information (log_window *lw)
void destroy_event (GtkWidget *widget, gpointer data)
void close_log_window_callback (GtkWidget *button, gpointer data)
gboolean search_callback (GtkWidget *widget, GdkEventKey *event, gpointer data)
void select_date_callback (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer user_data)
log_windoweb_log_window_new (struct contact *rc)

Variables

int current_row = -1
int last_pos = -1


Function Documentation

void close_log_window_callback GtkWidget *    button,
gpointer    data
[static]
 

Definition at line 196 of file log_window.c.

References _log_window::window.

Referenced by eb_log_window_new().

00197 {
00198   log_window* lw = (log_window*)data;
00199   gtk_widget_destroy(lw->window);
00200 }

void create_html_widget log_window   lw [static]
 

Definition at line 58 of file log_window.c.

References _log_window::date_html_hbox, EXT_GTK_TEXT, ext_gtk_text_new(), gtk_eb_html_init(), _log_window::html_display, and _log_window::html_scroller.

Referenced by set_html_text().

00059 {  
00060   /* add in the html display */
00061   lw->html_display = ext_gtk_text_new(NULL, NULL);
00062   gtk_eb_html_init(EXT_GTK_TEXT(lw->html_display));
00063 
00064   /* need to add scrollbar to the html text box*/
00065   lw->html_scroller = gtk_scrolled_window_new(NULL, NULL);
00066   gtk_widget_set_usize(lw->html_scroller, 375, 150);
00067   gtk_container_add(GTK_CONTAINER(lw->html_scroller), lw->html_display);
00068   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(lw->html_scroller), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
00069 
00070   gtk_box_pack_end(GTK_BOX(lw->date_html_hbox), lw->html_scroller, TRUE, TRUE, 5);  
00071 
00072   gtk_widget_show(GTK_WIDGET(lw->html_scroller));
00073   gtk_widget_show(GTK_WIDGET(lw->html_display));  
00074 }

void destroy_event GtkWidget *    widget,
gpointer    data
[static]
 

Definition at line 185 of file log_window.c.

References _log_window::entries, free_gs_list(), contact::logwindow, _log_window::remote, and _log_window::window.

Referenced by eb_log_window_new().

00186 {
00187   log_window* lw = (log_window*)data;
00188   
00189   g_slist_foreach(lw->entries, (GFunc)free_gs_list, NULL);
00190 
00191   lw->remote->logwindow = NULL;
00192   lw->window = NULL;
00193   g_free(lw);
00194 }

log_window* eb_log_window_new struct contact   rc
 

Definition at line 304 of file log_window.c.

References _, close_log_window_callback(), _log_window::date_html_hbox, _log_window::date_list, _log_window::date_scroller, destroy_event(), _log_window::html_display, load_log_information(), contact::logwindow, contact::nick, _log_window::remote, search_callback(), select_date_callback(), and _log_window::window.

Referenced by eb_view_log().

00305 {
00306   GtkWidget *iconwid0;
00307   GdkPixmap *icon0;
00308   GdkBitmap *mask;
00309 
00310   log_window* lw = g_new0(log_window, 1);
00311   char buffer[512];
00312   GtkWidget* vbox;
00313   GtkWidget* hbox;
00314   GtkWidget* button;
00315   GtkWidget* toolbar;
00316   GtkWidget* search_label;
00317   GtkWidget* search_entry;
00318   lw->remote = rc;
00319   rc->logwindow = lw;
00320   lw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00321   gtk_window_set_position(GTK_WINDOW(lw->window), GTK_WIN_POS_MOUSE);
00322   /* show who the conversation is with */
00323   sprintf(buffer, _("Past conversations with %s"), rc->nick);
00324   gtk_window_set_title(GTK_WINDOW(lw->window), buffer);
00325   gtk_container_set_border_width(GTK_CONTAINER(lw->window), 5);
00326   
00327 
00328   /* for the html and list box */
00329   lw->date_html_hbox = gtk_hbox_new(FALSE, 0);
00330 
00331   lw->date_list = gtk_clist_new(1);
00332   gtk_clist_set_column_width(GTK_CLIST(lw->date_list), 0, 100);
00333   gtk_clist_set_selection_mode(GTK_CLIST(lw->date_list), GTK_SELECTION_BROWSE);
00334 
00335   /* scroll window for the date list */
00336   lw->date_scroller = gtk_scrolled_window_new(NULL, NULL);
00337   gtk_widget_set_usize(lw->date_scroller, 180, 150);
00338   gtk_container_add(GTK_CONTAINER(lw->date_scroller), lw->date_list);
00339   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(lw->date_scroller), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
00340   
00341   /* let the packing begin (god that sounds wrong) */
00342   gtk_box_pack_start(GTK_BOX(lw->date_html_hbox), lw->date_scroller, TRUE, TRUE, 5);
00343   vbox = gtk_vbox_new(FALSE, 0);  
00344   gtk_box_pack_start(GTK_BOX(vbox), lw->date_html_hbox, TRUE, TRUE, 5);
00345   gtk_container_add(GTK_CONTAINER(lw->window), vbox);
00346 
00347   gtk_signal_connect(GTK_OBJECT(lw->window), "destroy",
00348              GTK_SIGNAL_FUNC(destroy_event), lw);
00349 
00350   /* buttons toolbar */
00351   hbox = gtk_hbox_new(FALSE, 0);
00352   toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
00353   gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
00354   gtk_container_set_border_width(GTK_CONTAINER(toolbar), 0);
00355 
00356   /* need to realize the window for the pixmaps */
00357   gtk_widget_realize(GTK_WIDGET(lw->window));
00358 
00359 
00360   /* search field */
00361   search_label = gtk_label_new(_("Search: "));
00362   search_entry = gtk_entry_new();
00363   gtk_box_pack_start(GTK_BOX(hbox), search_label, FALSE, FALSE, 0);
00364   gtk_box_pack_start(GTK_BOX(hbox), search_entry, TRUE, TRUE, 0);
00365   gtk_widget_show (search_label);
00366   gtk_widget_show (search_entry);
00367   gtk_signal_connect(GTK_OBJECT(search_entry), "key_press_event",
00368              GTK_SIGNAL_FUNC(search_callback), lw);
00369 
00370   
00371   /* close button*/
00372   icon0 = gdk_pixmap_create_from_xpm_d(lw->window->window, &mask, NULL, cancel_xpm);
00373   iconwid0 = gtk_pixmap_new(icon0, mask);
00374   gtk_widget_show(iconwid0);
00375   button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
00376                    GTK_TOOLBAR_CHILD_BUTTON,
00377                    NULL,
00378                    "close",
00379                    "Close",
00380                    "close",
00381                    iconwid0,
00382                    GTK_SIGNAL_FUNC(close_log_window_callback),
00383                    lw);
00384   gtk_widget_show(GTK_WIDGET(button));
00385   gtk_widget_show(GTK_WIDGET(toolbar));
00386 
00387   gtk_box_pack_end(GTK_BOX(hbox), toolbar, FALSE, FALSE, 0);
00388   gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00389 
00390   /* connect signals to the date list */
00391   gtk_signal_connect(GTK_OBJECT(lw->date_list), "select-row", 
00392              GTK_SIGNAL_FUNC(select_date_callback), lw);
00393 
00394   load_log_information(lw);  
00395 
00396   /* show everything... can you get arrested for baring it all? */
00397   gtk_widget_show(GTK_WIDGET(lw->date_list));
00398   gtk_widget_show(GTK_WIDGET(lw->html_display));
00399   gtk_widget_show(GTK_WIDGET(lw->date_scroller));
00400   gtk_widget_show(GTK_WIDGET(lw->date_html_hbox));
00401   gtk_widget_show(GTK_WIDGET(hbox));  
00402   gtk_widget_show(GTK_WIDGET(vbox));
00403 
00404   gtk_widget_show(GTK_WIDGET(lw->window));
00405 
00406   gtk_clist_select_row(GTK_CLIST(lw->date_list), 0, 0);
00407 
00408   return lw;
00409 }

void free_gs_list gpointer    data,
gpointer    user_data
[static]
 

Definition at line 52 of file log_window.c.

References free_string_list().

Referenced by destroy_event().

00053 {
00054   g_slist_foreach((GSList*)data, (GFunc)free_string_list, NULL);
00055   g_slist_free((GSList*)data);
00056 }

void free_string_list gpointer    data,
gpointer    user_data
[static]
 

Definition at line 47 of file log_window.c.

Referenced by free_gs_list().

00048 {
00049   g_free(data);
00050 }

void load_log_information log_window   lw [static]
 

Definition at line 106 of file log_window.c.

References _, _log_window::date_list, _log_window::entries, make_safe_filename(), NAME_MAX, contact::nick, and _log_window::remote.

Referenced by eb_log_window_new().

00107 {
00108   gchar name_buffer[NAME_MAX];
00109   gchar read_buffer[4096];
00110   FILE* fp;
00111   gchar* p1, *p2;
00112   gchar date_buffer[128];
00113   gchar* p3[1];
00114   GSList* gl = NULL, *gl1 = NULL;
00115   gint idx;
00116 
00117   gtk_clist_freeze(GTK_CLIST(lw->date_list)); /* freeze, thaw?  So corny. */
00118 
00119   make_safe_filename(name_buffer, lw->remote->nick);
00120     
00121   if ( (fp = fopen(name_buffer, "r")) != NULL) {
00122     gl = g_slist_alloc();
00123 
00124     while (fgets(read_buffer, 4096, fp) != NULL) {
00125       if ((p1 = strstr(read_buffer, _("Conversation started on "))) != NULL) 
00126       {
00127 
00128     /* extract the date, I am not sure if this is portable (but it
00129        works on my machine, so if someone wants to hack it, go ahead */
00130     p1 += strlen(_("Conversation started on "));
00131 
00132     /* if html tags are in the buffer, gotta strip the last two tags */
00133     if ((p2 = strstr(read_buffer, "</B></P>")) != NULL) {
00134       strncpy(date_buffer, p1, p2 - p1);
00135       date_buffer[p2-p1] = '\0';
00136     } else {
00137       /* eww, c's string handling sucks */
00138       strncpy(date_buffer, p1, (read_buffer + strlen(read_buffer)) - p1);
00139       date_buffer[(read_buffer + strlen(read_buffer)) - p1 - 1] = '\0';
00140     }
00141     
00142     p3[0] = date_buffer;
00143     idx = gtk_clist_append(GTK_CLIST(lw->date_list), p3);
00144 
00145     /* add new gslist entry */
00146     gl1 = g_slist_alloc();
00147     gl = g_slist_append(gl, gl1);   
00148 
00149     /* set the datapointer for the clist */
00150     gtk_clist_set_row_data(GTK_CLIST(lw->date_list), idx, gl1);
00151       } else if ((p1 = strstr(read_buffer, _("Conversation ended on "))) == NULL) {
00152     if (gl1 != NULL) {
00153       gl1 = g_slist_append(gl1, strdup(read_buffer));
00154     }
00155     else
00156     {
00157               char buff1[4096];
00158               p3[0] = _("Undated Log");
00159 
00160                 strcpy(buff1, read_buffer);
00161                 idx = gtk_clist_append(GTK_CLIST(lw->date_list), p3);
00162 
00163                 /* add new gslist entry */
00164                 gl1 = g_slist_alloc();
00165                 gl = g_slist_append(gl, gl1);   
00166 
00167                 /* set the datapointer for the clist */
00168                 gtk_clist_set_row_data(GTK_CLIST(lw->date_list), idx, gl1);
00169                 gl1 = g_slist_append(gl1, strdup(buff1));
00170     }
00171       }
00172     }
00173     fclose(fp);
00174   } else {
00175     perror(name_buffer);
00176   }
00177 
00178   lw->entries = gl;
00179 
00180   gtk_clist_thaw(GTK_CLIST(lw->date_list));
00181 }

gboolean search_callback GtkWidget *    widget,
GdkEventKey *    event,
gpointer    data
[static]
 

Definition at line 202 of file log_window.c.

References current_row, _log_window::date_list, DBG_CORE, eb_debug, _log_window::html_display, last_pos, set_html_text(), and strip_html().

Referenced by eb_log_window_new().

00203 {
00204   int cur_pos=0,cur_log=current_row;
00205   log_window * lw = (log_window *)data;
00206   gboolean looped=FALSE;
00207   /* if user wants to search */
00208   if (event->keyval == GDK_Return) {
00209     gchar * text = gtk_entry_get_text(GTK_ENTRY(widget));
00210     strip_html(text);
00211     if(strlen(text) == 0)
00212        return TRUE;
00213     
00214     while(!looped) {
00215       int total_length=0;
00216       GSList *c_slist, *s_list;
00217       /* get the selected conversation's log */
00218       s_list = (GSList*)gtk_clist_get_row_data(GTK_CLIST(lw->date_list), cur_log);
00219       if (!s_list) {
00220           /* end of the conversation's list, back to the beginning */
00221           s_list = (GSList*)gtk_clist_get_row_data(GTK_CLIST(lw->date_list), 0);
00222       /*reset */
00223       cur_log=cur_pos=current_row=last_pos=total_length=0;
00224       looped=TRUE;
00225       }
00226       if(!s_list) {
00227           eb_debug(DBG_CORE, "search: breaking\n");
00228           /* empty !*/
00229       break;
00230       }
00231       
00232       /* keep a pointer to the beginning of the conversation 
00233        * as we'll move s_list pointer */
00234       c_slist = s_list;
00235       while(s_list && cur_pos <= last_pos) {
00236       s_list=s_list->next;
00237       if(s_list && s_list->data && cur_pos<last_pos) {
00238         total_length+=strlen((char*)s_list->data);
00239       }
00240           if(s_list) cur_pos++;
00241       }
00242       while(s_list) {
00243              gchar *list_text = (gchar *)s_list->data;
00244          gchar *no_html_text = NULL;
00245          if (list_text) 
00246              no_html_text = strdup(list_text);
00247          if (no_html_text) 
00248              strip_html(no_html_text);
00249          /* found string ? */
00250          if(no_html_text && strstr(no_html_text,text) != NULL) {
00251            GtkEditable *editable;
00252            /* go to the the found conversation */
00253                    gtk_clist_select_row(GTK_CLIST(lw->date_list),cur_log,0);
00254                    gtk_clist_moveto (GTK_CLIST(lw->date_list),
00255                              cur_log,0,0,0);
00256                    /* update the conversation log */                 
00257                set_html_text(c_slist,lw);
00258                    editable = GTK_EDITABLE (lw->html_display);
00259 
00260                    last_pos=cur_pos+1;
00261                    current_row=cur_log;
00262            /* select the matching substring */
00263            eb_debug(DBG_CORE, "search: total2=%d\n",total_length);
00264            gtk_editable_set_position ( editable,
00265                            total_length+(int)(strstr(no_html_text,text)-no_html_text));
00266            gtk_editable_select_region( editable,
00267                            total_length+(int)(strstr(no_html_text,text)-no_html_text),
00268                            total_length+(int)(strstr(no_html_text,text)-no_html_text)+strlen(text));
00269            total_length+=strlen(no_html_text);
00270            return TRUE;
00271          } else if (no_html_text) 
00272              total_length+=strlen(no_html_text);
00273          
00274          if (no_html_text)
00275              free(no_html_text);
00276          /* next line */
00277          s_list=s_list->next;
00278          cur_pos++; 
00279          last_pos=cur_pos;     
00280       }
00281       /* next conversation */
00282       cur_log++;
00283       cur_pos=0;last_pos=0;
00284       current_row=cur_log;
00285     }
00286     
00287   }
00288   return TRUE;
00289 }

void select_date_callback GtkCList *    clist,
gint    row,
gint    column,
GdkEventButton *    event,
gpointer    user_data
[static]
 

Definition at line 292 of file log_window.c.

References current_row, last_pos, and set_html_text().

Referenced by eb_log_window_new().

00294 {
00295   GSList* string_list;
00296   log_window* lw = (log_window*)user_data;
00297 
00298   string_list = (GSList*)gtk_clist_get_row_data(GTK_CLIST(clist), row);
00299   set_html_text(string_list, lw);
00300   current_row = row; last_pos=0;
00301 }

void set_html_text GSList *    gl,
log_window   lw
[static]
 

Definition at line 77 of file log_window.c.

References create_html_widget(), EXT_GTK_TEXT, ext_gtk_text_freeze(), ext_gtk_text_thaw(), gtk_eb_html_add(), _log_window::html_display, and _log_window::html_scroller.

Referenced by search_callback(), and select_date_callback().

00078 {
00079   GSList *h;
00080 
00081   /* need to destroy the html widget, and add it again */
00082   if (lw->html_display != NULL)
00083      gtk_widget_destroy(GTK_WIDGET(lw->html_display));
00084   if (lw->html_scroller != NULL)
00085      gtk_widget_destroy(GTK_WIDGET(lw->html_scroller));
00086 
00087 
00088   /* create the html stuff */
00089   create_html_widget(lw);
00090   
00091   ext_gtk_text_freeze(EXT_GTK_TEXT(lw->html_display)); /* cold snap */
00092 
00093   /* walk down the list and add the test */
00094   h = gl;  
00095   while (h != NULL) {
00096     if (h->data != NULL) {
00097       gtk_eb_html_add(EXT_GTK_TEXT(lw->html_display), (gchar*)h->data,0,0,0);
00098     }
00099     h = g_slist_next(h);
00100   }
00101 
00102   ext_gtk_text_thaw(EXT_GTK_TEXT(lw->html_display)); /* and now, a warm front */
00103 
00104 }


Variable Documentation

int current_row = -1
 

Definition at line 45 of file log_window.c.

Referenced by search_callback(), and select_date_callback().

int last_pos = -1
 

Definition at line 45 of file log_window.c.

Referenced by search_callback(), and select_date_callback().


Contact: Andy Maloney     [Documentation generated by doxygen]