Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
minimo_history.cpp File Reference
#include "minimo_history.h"

Go to the source code of this file.

Functions

void add_to_history (const gchar *url)
void view_history (GtkWidget *embed)
void on_history_clist_button_go_cb (GtkWidget *button, HistoryWindow *hwin)
void close_history_win (GtkWidget *button, HistoryWindow *hwin)
void remove_from_history (GtkWidget *button, HistoryWindow *hwin)
void remove_from_list (gchar *text)
void clear_history (GtkWidget *b, HistoryWindow *hwin)
void on_search_button_cb (GtkWidget *button, HistoryWindow *hwin)
void on_history_destroy (GtkWidget *window)
void read_history (void)
void write_history (void)

Variables

gint gHistoryProt = 0
GSList * gHistoryList = NULL

Function Documentation

void add_to_history ( const gchar *  url)

Definition at line 57 of file minimo_history.cpp.

                                      {
  GSList *list;
  gint equals = 0;
  
  read_history();
  
  if (!url || url == NULL) return ;
  if (!g_strncasecmp(url,"about:",6) || !g_strcasecmp(url,"")) return;
  
  while (gHistoryProt == 1) {
  }    
  
  gHistoryProt = 1;
  
  for (list = gHistoryList; list ; list = list->next) {
    if (g_strcasecmp((const gchar*)list->data,url) == 0){
      equals = 1;
      gHistoryProt = 0;
    }
  }
  if (equals == 0) {
    gHistoryList = g_slist_prepend(gHistoryList,g_strdup(url));
    write_history();
  }
  gHistoryProt = 0;
  
  
}

Here is the call graph for this function:

void clear_history ( GtkWidget *  b,
HistoryWindow hwin 
)

Definition at line 235 of file minimo_history.cpp.

{
  gtk_clist_clear(GTK_CLIST(hwin->clist));
  g_slist_free(gHistoryList);
  gHistoryList = NULL;
  gtk_window_set_title(GTK_WINDOW(hwin->window),"Minimo - History (0) items");
}
void close_history_win ( GtkWidget *  button,
HistoryWindow hwin 
)

Definition at line 193 of file minimo_history.cpp.

{
  gtk_widget_destroy(hwin->window);
}
void on_history_clist_button_go_cb ( GtkWidget *  button,
HistoryWindow hwin 
)

Definition at line 177 of file minimo_history.cpp.

                                                                           {
  GList *selection;
  gchar *location;
  gint row;
  
  selection = GTK_CLIST(hwin->clist)->selection;
  
  if (g_list_length(selection) == 0)  return;
  
  row = (gint)g_list_nth_data(selection,0);
  gtk_clist_get_text(GTK_CLIST(hwin->clist),row,0,&location);
  gtk_moz_embed_stop_load(GTK_MOZ_EMBED(hwin->embed));
  gtk_moz_embed_load_url(GTK_MOZ_EMBED(hwin->embed), location);
}

Here is the call graph for this function:

void on_history_destroy ( GtkWidget *  window)

Definition at line 272 of file minimo_history.cpp.

void on_search_button_cb ( GtkWidget *  button,
HistoryWindow hwin 
)

Definition at line 244 of file minimo_history.cpp.

{
  gint rows, i;
  G_CONST_RETURN gchar *search_text;
  gint search_pos = 0;
  
  rows = GTK_CLIST(hwin->clist)->rows;
  if (!rows) return;
  search_text = gtk_entry_get_text(GTK_ENTRY(hwin->search_entry));
  if (!search_text || !strcmp(search_text,"")) return; 
  if (search_pos >= rows) search_pos = 0;
  if (search_pos) search_pos++;
  for (i = search_pos; i < rows ; i++) {
    gchar *tmp, *tmp2 = NULL;
    gtk_clist_get_text(GTK_CLIST(hwin->clist), i, 0, &tmp);
    g_return_if_fail(tmp != NULL);
    tmp2 = strstr(tmp,search_text);
    if (tmp2 != NULL) {
      gtk_clist_moveto(GTK_CLIST(hwin->clist), i, 0, 0.0, 0.0);
      gtk_clist_select_row(GTK_CLIST(hwin->clist), i, 0);
      GTK_CLIST(hwin->clist)->focus_row = i;
      search_pos = i;
    }                              
    
  }
}

Definition at line 278 of file minimo_history.cpp.

                        {
  gchar *line;
  gchar *url;
  gchar *user_home = NULL;
  FILE   *g_history_file = NULL;
  gchar  *g_history_file_name = NULL;
  
  gHistoryList = NULL;
  
  user_home = g_strconcat(g_get_home_dir(),NULL);
  g_history_file_name = g_strconcat(user_home,"/.Minimo/history",NULL);
  
  if ((g_history_file = fopen(g_history_file_name,"r"))!= NULL)
  {
    fclose(g_history_file);
    g_history_file = fopen(g_history_file_name,"r+");
  }
  else
    g_history_file = fopen(g_history_file_name,"w+");
  
  if (g_history_file == NULL) {
    printf("No History file to read!\n");
  }
  line = (gchar *)g_malloc(1024);
  
  while(fgets(line,1024,g_history_file) != NULL) {
    line[strlen(line)-1] = '\0';
    url = g_strdup(line);
    gHistoryList = g_slist_append(gHistoryList,url);
  }
  
  fclose(g_history_file);
  g_free(line);
  
}

Here is the call graph for this function:

void remove_from_history ( GtkWidget *  button,
HistoryWindow hwin 
)

Definition at line 199 of file minimo_history.cpp.

{
  GList *selection = GTK_CLIST(hwin->clist)->selection;
  gchar *text;
  gint row;
  
  
  if (selection == NULL) return;
  
  gtk_clist_freeze(GTK_CLIST(hwin->clist));
  row = (gint) g_list_nth_data(selection,0);
  gtk_clist_get_text(GTK_CLIST(hwin->clist), row, 0, &text);
  remove_from_list(text);
  gtk_clist_remove(GTK_CLIST(hwin->clist), row); 
  gtk_clist_thaw(GTK_CLIST(hwin->clist));
  hwin->title = g_strdup_printf(("Minimo - History (%d) items"), g_slist_length(gHistoryList));
  gtk_window_set_title(GTK_WINDOW(hwin->window),hwin->title);
  
}

Here is the call graph for this function:

void remove_from_list ( gchar *  text)

Definition at line 220 of file minimo_history.cpp.

{
  GSList *l;
  
  for (l = gHistoryList; l ; l = l->next) {
    gchar *data = (gchar *)l->data;
    if (!strcmp(text,data)) {
      gHistoryList = g_slist_remove(gHistoryList,data);
      return;
    }
  }
  
}

Here is the call graph for this function:

void view_history ( GtkWidget *  embed)

Definition at line 87 of file minimo_history.cpp.

                                    {
  
  HistoryWindow *hwin;
  GSList *list;
  GtkWidget *image;
  
  hwin = g_new0(HistoryWindow,1);
  
  read_history();
  
  //hwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  hwin->window = gtk_dialog_new();
  gtk_window_set_position(GTK_WINDOW(hwin->window), GTK_WIN_POS_CENTER_ON_PARENT);
  gtk_window_set_title(GTK_WINDOW(hwin->window),hwin->title);
  gtk_widget_set_usize(hwin->window,230,300);
  gtk_window_set_resizable(GTK_WINDOW(hwin->window),FALSE);
  gtk_window_set_position (GTK_WINDOW(hwin->window),GTK_WIN_POS_CENTER_ON_PARENT);
  gtk_window_set_modal (GTK_WINDOW (hwin->window), TRUE);
  gtk_window_set_keep_above(GTK_WINDOW (hwin->window), TRUE);
  
  g_signal_connect(G_OBJECT(hwin->window),"destroy", G_CALLBACK(on_history_destroy), NULL);
  hwin->title = g_strdup_printf(("Minimo - History (%d) items"), g_slist_length(gHistoryList));
  g_free(hwin->title);
  
  hwin->vbox = gtk_vbox_new(FALSE,5);
  //   gtk_container_add(GTK_CONTAINER(hwin->window),hwin->vbox);
  
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(hwin->window)->vbox),hwin->vbox, TRUE, TRUE, 0);
  
  hwin->scrolled_window = gtk_scrolled_window_new(NULL,NULL);
  gtk_box_pack_start(GTK_BOX(hwin->vbox),hwin->scrolled_window,TRUE,TRUE,0);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(hwin->scrolled_window),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC);
  
  hwin->clist = gtk_clist_new(1);
  
  gtk_container_add(GTK_CONTAINER(hwin->scrolled_window),hwin->clist);
  
  hwin->search_label = gtk_label_new("Search: ");
  hwin->search_entry = gtk_entry_new();
  hwin->search_box = gtk_hbox_new(0,0);
  image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR);
  hwin->search_button = gtk_button_new();
  gtk_container_add(GTK_CONTAINER(hwin->search_button),image);
  gtk_tooltips_set_tip (gtk_tooltips_new (), GTK_WIDGET (hwin->search_button), "Find on history", NULL);
  image = gtk_image_new_from_stock (GTK_STOCK_YES, GTK_ICON_SIZE_SMALL_TOOLBAR);
  hwin->go_button = gtk_button_new ();
  gtk_container_add(GTK_CONTAINER(hwin->go_button),image);
  gtk_tooltips_set_tip (gtk_tooltips_new (), GTK_WIDGET (hwin->go_button), "Go to", NULL);
  
  hwin->embed = embed;
  
  g_signal_connect(G_OBJECT(hwin->search_button), "clicked", G_CALLBACK(on_search_button_cb), hwin);
  g_signal_connect(G_OBJECT(hwin->go_button), "clicked", G_CALLBACK(on_history_clist_button_go_cb), hwin);
  
  gtk_box_pack_start(GTK_BOX(hwin->search_box), hwin->search_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->search_box), hwin->search_entry, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->search_box), hwin->search_button, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->search_box), hwin->go_button, FALSE, FALSE, 0);
  
  hwin->remove = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
  g_signal_connect(G_OBJECT(hwin->remove), "clicked", G_CALLBACK(remove_from_history), hwin);
  
  hwin->clear = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
  g_signal_connect(G_OBJECT(hwin->clear), "clicked", G_CALLBACK(clear_history), hwin);
  
  hwin->close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
  g_signal_connect(G_OBJECT(hwin->close), "clicked", G_CALLBACK(close_history_win), hwin);
  
  hwin->btnbox = gtk_hbox_new(0,0);
  gtk_box_pack_start(GTK_BOX(hwin->vbox), hwin->search_box, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->vbox), hwin->btnbox, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->btnbox), hwin->remove, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->btnbox), hwin->clear, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(hwin->btnbox), hwin->close, TRUE, TRUE, 0);
  
  
  while (gHistoryProt == 1) {
  }    
  
  gHistoryProt = 1;
  for (list = gHistoryList; list ; list = list->next) {
    gchar *clist_entry[1];
    clist_entry[0] = (gchar *)list->data;
    gtk_clist_append(GTK_CLIST(hwin->clist),clist_entry);
  }
  gHistoryProt = 0;
  gtk_widget_show_all(hwin->window);
}

Here is the call graph for this function:

Definition at line 315 of file minimo_history.cpp.

                         {
  GSList *list;
  gchar *user_home= NULL;
  FILE   *g_history_file = NULL;
  gchar  *g_history_file_name = NULL;
  
  user_home = g_strconcat(g_get_home_dir(),NULL);
  g_history_file_name = g_strconcat(user_home,"/.Minimo/history",NULL);
  
  g_history_file = fopen(g_history_file_name,"w");
  if (g_history_file == NULL) {
    printf("Couldn't open history file for writing!\n");
    return;
  }
  
  for (list = gHistoryList; list ; list = list->next) {
    fprintf(g_history_file,"%s\n",(gchar *)(list->data));
  }
  
  fflush(g_history_file);     
  fclose(g_history_file);
  g_free(g_history_file_name);
  
}

Here is the call graph for this function:


Variable Documentation

GSList* gHistoryList = NULL

Definition at line 54 of file minimo_history.cpp.

gint gHistoryProt = 0

Definition at line 52 of file minimo_history.cpp.