Back to index

lightning-sunbird  0.9+nobinonly
bookmark.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *   Doug Turner <dougt@meer.net>  Branched from TestGtkEmbed.cpp
00024  *
00025  *   The 10LE Team (in alphabetical order)
00026  *   -------------------------------------
00027  *
00028  *    Ilias Biris       <ext-ilias.biris@indt.org.br> - Coordinator
00029  *    Afonso Costa      <afonso.costa@indt.org.br>
00030  *    Antonio Gomes     <antonio.gomes@indt.org.br>
00031  *    Diego Gonzalez    <diego.gonzalez@indt.org.br>
00032  *    Raoni Novellino   <raoni.novellino@indt.org.br>
00033  *    Andre Pedralho    <andre.pedralho@indt.org.br>
00034  *
00035  *
00036  * Alternatively, the contents of this file may be used under the terms of
00037  * either the GNU General Public License Version 2 or later (the "GPL"), or
00038  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00039  * in which case the provisions of the GPL or the LGPL are applicable instead
00040  * of those above. If you wish to allow use of your version of this file only
00041  * under the terms of either the GPL or the LGPL, and not to allow others to
00042  * use your version of this file under the terms of the MPL, indicate your
00043  * decision by deleting the provisions above and replace them with the notice
00044  * and other provisions required by the GPL or the LGPL. If you do not delete
00045  * the provisions above, a recipient may use your version of this file under
00046  * the terms of any one of the MPL, the GPL or the LGPL.
00047  *
00048  * ***** END LICENSE BLOCK ***** */
00049 
00050 #include "history.h"
00051 
00052 /* Callbacks from the UI */
00053 void initialize_bookmark(GtkWidget *embed);
00054 void open_bookmark(void);
00055 void show_bookmark(void);
00056 void read_bookmark(void);
00057 void generate_bookmark_ctree(GNode *node, BookmarkCTreeData *ctree_data);
00058 void add_bookmark_cb(GtkWidget *menu_item,GtkWidget *min);
00059 void on_bookmark_add_button_clicked(GtkWidget *button,BookmarkWindow *bwin);
00060 void on_bookmark_edit_button_clicked(GtkWidget *button,BookmarkWindow *bwin);
00061 void on_bookmark_ok_button_clicked(GtkWidget *button,BookmarkWindow *bwin);
00062 void on_bookmark_cancel_button_clicked(GtkWidget *button,BookmarkWindow *bwin);
00063 void on_bookmark_go_button_clicked(GtkButton *button,BookmarkWindow *bwin);
00064 void on_bookmark_remove_button_clicked(GtkWidget *button,BookmarkWindow *bwin);
00065 void export_bookmarks(GtkButton *button,BookmarkWindow *bwin);
00066 
00067 /* Callbacks from widgets*/
00068 void on_bookmark_ctree_select_row(GtkWidget *ctree,GtkCTreeNode *node,gint col,BookmarkWindow *bwin);
00069 void on_bookmark_ctree_unselect_row(GtkWidget *ctree,GtkCTreeNode *node,gint col,BookmarkWindow *bwin);
00070 void on_bookmark_ctree_move(GtkWidget *ctree,GtkCTreeNode *node,GtkCTreeNode *parent,GtkCTreeNode *sibling,BookmarkWindow *bwin);
00071 void move_folder(GNode *old_node, GNode *new_parent_node);
00072 void print_bookmarks ();
00073 void print_node_data (GNode *node,FILE *file);
00074 void clear_entries(BookmarkWindow *bwin);
00075 void close_bookmark_window(BookmarkWindow *bwin);
00076 gboolean url_exists(BookmarkData *data);
00077 
00078 /* Bookmarks Functions*/
00079 void initialize_bookmark(GtkWidget *embed)
00080 {
00081   minEmbed= GTK_MOZ_EMBED(embed);
00082 }
00083 
00084 /* verify if there is a bookmark file */
00085 void open_bookmark()
00086 {
00087   gchar* file = g_strconcat(g_get_home_dir(),"/.Minimo/bookmarks",NULL);
00088   
00089   if (!(g_file_test(file,G_FILE_TEST_EXISTS)))
00090   {
00091     bookmark_file = fopen(file,"w+");
00092     fprintf(bookmark_file, "Bookmarks\n");
00093     fclose(bookmark_file);
00094     open_bookmark();
00095   }
00096   else
00097   {
00098     bookmark_file = fopen(file,"r");
00099     show_bookmark();
00100   }
00101 }
00102 
00103 /* Create bookmarks manager window */
00104 void show_bookmark()
00105 {
00106   BookmarkWindow *bwin;
00107   
00108   bwin = g_new0(BookmarkWindow,1);
00109   
00110   //   minEmbed= GTK_MOZ_EMBED(embed);
00111   
00112   bwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00113   g_object_set_data(G_OBJECT(bwin->window),"window",bwin->window);
00114   gtk_window_set_title(GTK_WINDOW(bwin->window),"Bookmarks");
00115   gtk_widget_set_usize(bwin->window,230,350);
00116   gtk_window_set_resizable(GTK_WINDOW(bwin->window),FALSE);
00117   gtk_window_set_position (GTK_WINDOW(bwin->window),GTK_WIN_POS_CENTER_ON_PARENT);
00118   gtk_window_set_modal (GTK_WINDOW (bwin->window), TRUE);
00119   gtk_window_set_keep_above(GTK_WINDOW (bwin->window), TRUE);
00120   
00121   bwin->vbox1 = gtk_vbox_new(FALSE,0);
00122   gtk_widget_show(bwin->vbox1);
00123   gtk_container_add(GTK_CONTAINER(bwin->window),bwin->vbox1);
00124   
00125   bwin->scrolled_window = gtk_scrolled_window_new(NULL,NULL);
00126   gtk_widget_show(bwin->scrolled_window);
00127   gtk_box_pack_start(GTK_BOX(bwin->vbox1),bwin->scrolled_window,TRUE,TRUE,0);
00128   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bwin->scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
00129   
00130   gchar *titles[] = {("Name"),("URL")};
00131   gchar *menur[] = {"Bookmarks",""};
00132   
00133   bwin->menu_node_data = g_new0(BookmarkData,1);
00134   bwin->menu_node_data->label = g_strdup("Bookmarks");
00135   bwin->menu_node_data->url = NULL;
00136   
00137   bookmarks= g_node_new(bwin->menu_node_data);
00138   bwin->parent_node= bookmarks;
00139   
00140   read_bookmark();
00141   
00142   /* mount the bookmark ctree */
00143   bwin->ctree = gtk_ctree_new_with_titles(2,0,titles);
00144   gtk_container_add(GTK_CONTAINER(bwin->scrolled_window),bwin->ctree);
00145   gtk_clist_set_column_width(GTK_CLIST(bwin->ctree),0,150);
00146   gtk_clist_set_column_width(GTK_CLIST(bwin->ctree),1,150);
00147   gtk_clist_column_titles_show(GTK_CLIST(bwin->ctree));
00148   gtk_clist_set_reorderable(GTK_CLIST(bwin->ctree),TRUE);
00149   gtk_clist_set_auto_sort(GTK_CLIST(bwin->ctree),TRUE);
00150   
00151   bwin->menu_node = gtk_ctree_insert_node(GTK_CTREE(bwin->ctree),NULL,NULL,menur,0,NULL,NULL,NULL,NULL,FALSE,TRUE);
00152   gtk_ctree_node_set_row_data(GTK_CTREE(bwin->ctree),bwin->menu_node,bwin->menu_node_data);
00153   gtk_ctree_node_set_selectable(GTK_CTREE(bwin->ctree),bwin->menu_node,FALSE);
00154   bwin->ctree_data.ctree = bwin->ctree;
00155   
00156   /* show bookmark ctree */
00157   if (bookmarks != NULL)
00158   {
00159     bwin->ctree_data.parent = bwin->menu_node;
00160     g_node_children_foreach(bookmarks,G_TRAVERSE_ALL,(GNodeForeachFunc)generate_bookmark_ctree,&bwin->ctree_data);
00161   }
00162   
00163   gtk_widget_show(bwin->ctree);
00164   
00165   g_signal_connect(G_OBJECT(bwin->ctree),"tree_select_row",G_CALLBACK(on_bookmark_ctree_select_row),bwin);
00166   g_signal_connect(G_OBJECT(bwin->ctree),"tree_unselect_row",G_CALLBACK(on_bookmark_ctree_unselect_row),bwin);
00167   g_signal_connect(G_OBJECT(bwin->ctree),"tree_move",G_CALLBACK(on_bookmark_ctree_move),bwin);
00168   
00169   /* hbox1: name label, name entry, url label, url entry and add button */
00170   bwin->hbox1 = gtk_hbox_new(FALSE,0);
00171   gtk_widget_show(bwin->hbox1);
00172   gtk_box_pack_start(GTK_BOX(bwin->vbox1),bwin->hbox1,FALSE,FALSE,0);
00173   
00174   /* name label */
00175   bwin->text_label = gtk_label_new("Name ");
00176   gtk_widget_show(bwin->text_label);
00177   gtk_box_pack_start(GTK_BOX(bwin->hbox1),bwin->text_label,FALSE,FALSE,0);
00178   
00179   /* name entry */
00180   bwin->text_entry = gtk_entry_new();
00181   gtk_widget_show(bwin->text_entry);
00182   gtk_box_pack_start(GTK_BOX(bwin->hbox1),bwin->text_entry,TRUE,TRUE,0);
00183   
00184   /* url label */
00185   bwin->url_label = gtk_label_new(" URL ");
00186   gtk_widget_show(bwin->url_label);
00187   gtk_box_pack_start(GTK_BOX(bwin->hbox1),bwin->url_label,FALSE,FALSE,2);
00188   
00189   /* url entry */
00190   bwin->url_entry = gtk_entry_new();
00191   gtk_widget_show(bwin->url_entry);
00192   gtk_box_pack_start(GTK_BOX(bwin->hbox1),bwin->url_entry,TRUE,TRUE,0);
00193   gtk_entry_set_text(GTK_ENTRY(bwin->url_entry)," ");
00194   
00195   /* hbox 2: add folder button and folder name entry */
00196   bwin->hbox2 = gtk_hbox_new(FALSE,0);
00197   gtk_widget_show(bwin->hbox2);
00198   gtk_box_pack_start(GTK_BOX(bwin->vbox1),bwin->hbox2,FALSE,FALSE,0);
00199   
00200   /* folder name label */
00201   bwin->text_label = gtk_label_new("Folder ");
00202   gtk_widget_show(bwin->text_label);
00203   gtk_box_pack_start(GTK_BOX(bwin->hbox2),bwin->text_label,FALSE,FALSE,0);
00204   
00205   /* folder name entry */
00206   bwin->folder_entry = gtk_entry_new();
00207   gtk_widget_show(bwin->folder_entry);
00208   gtk_box_pack_start(GTK_BOX(bwin->hbox2),bwin->folder_entry,TRUE,TRUE,0);
00209   
00210   /* add button */
00211   bwin->add_button = gtk_button_new_with_label("Add");
00212   gtk_widget_show(bwin->add_button);
00213   gtk_box_pack_start(GTK_BOX(bwin->hbox2),bwin->add_button,FALSE,FALSE,0);
00214   g_signal_connect(G_OBJECT(bwin->add_button),"clicked",G_CALLBACK(on_bookmark_add_button_clicked),bwin);
00215   
00216   /* edit button */
00217   bwin->edit_button = gtk_button_new_with_label("Edit");
00218   gtk_widget_show(bwin->edit_button);
00219   gtk_box_pack_start(GTK_BOX(bwin->hbox2),bwin->edit_button,FALSE,FALSE,0);
00220   g_signal_connect(G_OBJECT(bwin->edit_button),"clicked",G_CALLBACK(on_bookmark_edit_button_clicked),bwin);
00221   
00222   /* hbox 3: go, ok, remove buttons */
00223   bwin->hbox3 = gtk_hbox_new(FALSE,0);
00224   gtk_widget_show(bwin->hbox3);
00225   gtk_box_pack_start(GTK_BOX(bwin->vbox1),bwin->hbox3,FALSE,FALSE,0);
00226   
00227   /* go button */
00228   bwin->go_button = gtk_button_new_with_label("Go");
00229   gtk_widget_show(bwin->go_button);
00230   gtk_box_pack_start(GTK_BOX(bwin->hbox3),bwin->go_button,FALSE,FALSE,0);
00231   g_signal_connect(G_OBJECT(bwin->go_button),"clicked",G_CALLBACK(on_bookmark_go_button_clicked),bwin);
00232   
00233   /* ok button */
00234   bwin->ok_button = gtk_button_new_with_label("Ok");
00235   gtk_widget_show(bwin->ok_button);
00236   gtk_box_pack_start(GTK_BOX(bwin->hbox3),bwin->ok_button,FALSE,FALSE,0);
00237   g_signal_connect(G_OBJECT(bwin->ok_button),"clicked",G_CALLBACK(on_bookmark_ok_button_clicked),bwin);
00238   
00239   /* remove button */
00240   bwin->remove_button = gtk_button_new_with_label("Remove");
00241   gtk_widget_show(bwin->remove_button);
00242   gtk_box_pack_start(GTK_BOX(bwin->hbox3),bwin->remove_button,FALSE,FALSE,0);
00243   g_signal_connect(G_OBJECT(bwin->remove_button),"clicked",G_CALLBACK(on_bookmark_remove_button_clicked),bwin);
00244   
00245   /* cancel button*/
00246   bwin->cancel_button = gtk_button_new_with_label("Cancel");
00247   gtk_widget_show(bwin->cancel_button);
00248   gtk_box_pack_start(GTK_BOX(bwin->hbox3),bwin->cancel_button,FALSE,FALSE,0);
00249   g_signal_connect(G_OBJECT(bwin->cancel_button),"clicked",G_CALLBACK(on_bookmark_cancel_button_clicked),bwin);
00250   
00251   gtk_widget_show(bwin->window);
00252   
00253 }
00254 
00255 /* read bookmarks */
00256 void read_bookmark()
00257 {
00258   gchar *line;
00259   BookmarkData *data;
00260   GNode *parent;
00261   
00262   line = (gchar *)g_malloc(1024);
00263   
00264   parent= bookmarks;
00265   
00266   while(fgets(line,1023,bookmark_file)!= NULL)
00267   {    
00268     line = g_strstrip(line);
00269     
00270     if (g_strncasecmp(line,"folder",6) == 0)
00271     {
00272       data = g_new0(BookmarkData,1);
00273       data->label = g_strdup(line+7);
00274       data->url = " ";
00275       
00276       parent= g_node_append_data(parent, data);
00277       
00278       continue;
00279     }
00280     
00281     if (g_strncasecmp(line,"url",3) == 0)
00282     {
00283       gchar **temp;
00284       
00285       data = g_new0(BookmarkData,1);
00286       temp = g_strsplit(line+4," ",2);
00287       data->url = g_strdup(temp[0]);
00288       
00289       if (temp[1] != NULL)
00290         data->label = g_strdup(temp[1]);
00291       else
00292         data->label = g_strdup(temp[0]);
00293       g_strfreev(temp);
00294       
00295       g_node_append_data(parent,data);
00296       
00297       continue;
00298     }
00299     
00300     if (g_strncasecmp(line,"/folder",7) == 0)
00301     {
00302       parent= parent->parent;
00303       continue;
00304     }
00305   }
00306   g_free(line);
00307 }
00308 
00309 /* generate bookmark ctree */
00310 void generate_bookmark_ctree(GNode *node, BookmarkCTreeData *ctree_data)
00311 {
00312   BookmarkData *data;
00313   gchar *ctree_entry[2];
00314   GtkCTreeNode *ctree_node;
00315   
00316   data= (BookmarkData*) node->data;
00317   
00318   ctree_entry[0] = data->label;
00319   ctree_entry[1] = data->url;
00320   
00321   /* it's a folder */
00322   if (g_ascii_strcasecmp(data->url," ") == 0)
00323   {
00324     BookmarkCTreeData new_ctree_data;
00325     ctree_node = gtk_ctree_insert_node(GTK_CTREE(ctree_data->ctree),ctree_data->parent,NULL,ctree_entry,0,NULL,NULL,NULL,NULL,FALSE,TRUE);
00326     new_ctree_data.ctree = ctree_data->ctree;
00327     new_ctree_data.parent = ctree_node;
00328     g_node_children_foreach(node,G_TRAVERSE_ALL,(GNodeForeachFunc)generate_bookmark_ctree,&new_ctree_data);
00329   }/* it's a url */
00330   else
00331     ctree_node = gtk_ctree_insert_node(GTK_CTREE(ctree_data->ctree),ctree_data->parent,NULL,ctree_entry,0,NULL,NULL,NULL,NULL,TRUE,TRUE);
00332   
00333   gtk_ctree_node_set_row_data(GTK_CTREE(ctree_data->ctree),ctree_node,data);
00334 }
00335 
00336 /* get selected data */
00337 void on_bookmark_ctree_select_row(GtkWidget *ctree,GtkCTreeNode *node,gint col,BookmarkWindow *bwin)
00338 {
00339   BookmarkData *bmark;
00340   
00341   bmark = (BookmarkData*) gtk_ctree_node_get_row_data(GTK_CTREE(bwin->ctree), node);
00342   
00343   if (g_ascii_strcasecmp(bmark->url," ") == 0)
00344     gtk_entry_set_text(GTK_ENTRY(bwin->folder_entry), bmark->label);
00345   else
00346   {
00347     gtk_entry_set_text(GTK_ENTRY(bwin->text_entry), bmark->label);
00348     gtk_entry_set_text(GTK_ENTRY(bwin->url_entry), bmark->url);
00349   } 
00350   
00351   bwin->temp_node= g_node_find(bookmarks,G_IN_ORDER,G_TRAVERSE_ALL,bmark);
00352   if (G_NODE_IS_LEAF(bwin->temp_node))
00353   {
00354     bwin->parent_node= bwin->temp_node->parent;
00355     bwin->menu_node= node;
00356   }
00357   else
00358   {
00359     bwin->parent_node= bwin->temp_node;
00360     bwin->menu_node= node;
00361   }
00362 }
00363 
00364 /* there isn't a selected raw on ctree */
00365 void on_bookmark_ctree_unselect_row(GtkWidget *ctree,GtkCTreeNode *node,gint col,BookmarkWindow *bwin)
00366 {      
00367   bwin->menu_node= gtk_ctree_node_nth(GTK_CTREE(bwin->ctree),0);
00368   gtk_ctree_unselect_recursive(GTK_CTREE(bwin->ctree),gtk_ctree_node_nth (GTK_CTREE(bwin->ctree),0));
00369   gtk_entry_set_text(GTK_ENTRY(bwin->text_entry),"");
00370   gtk_entry_set_text(GTK_ENTRY(bwin->url_entry)," ");
00371   gtk_entry_set_text(GTK_ENTRY(bwin->folder_entry),"");
00372 }
00373 
00374 /* move a node */
00375 void on_bookmark_ctree_move(GtkWidget *ctree,GtkCTreeNode *node,GtkCTreeNode *parent,GtkCTreeNode *sibling,BookmarkWindow *bwin)
00376 {
00377   BookmarkData *data, *parent_data;
00378   GNode *menu_node, *old_node;
00379   
00380   data= (BookmarkData *) gtk_ctree_node_get_row_data(GTK_CTREE(ctree),node);
00381   
00382   if (parent== NULL) return;
00383   
00384   old_node= g_node_find(bookmarks,G_IN_ORDER,G_TRAVERSE_ALL,data);
00385   
00386   parent_data= (BookmarkData *) gtk_ctree_node_get_row_data(GTK_CTREE(ctree),parent);
00387   menu_node= g_node_find(bookmarks, G_IN_ORDER, G_TRAVERSE_ALL, parent_data);
00388   
00389   if (old_node->children!= NULL)
00390     move_folder(old_node,menu_node);
00391   else
00392     g_node_append_data(menu_node,old_node->data);
00393   
00394   g_node_destroy(old_node);
00395   
00396 }
00397 
00398 /* move a folder and its contents */
00399 void move_folder(GNode *old_node, GNode *new_parent_node)
00400 {
00401   
00402   if (old_node== NULL) return;
00403   else if  (old_node->children!= NULL) 
00404   {
00405     new_parent_node= g_node_append_data(new_parent_node,old_node->data);
00406     move_folder(old_node->children,new_parent_node);
00407   }
00408   else if (old_node->children== NULL)
00409   {
00410     g_node_append_data(new_parent_node,old_node->data);
00411     move_folder(old_node->next,new_parent_node);
00412   }    
00413 }
00414 
00415 /* add a bookmark */
00416 void on_bookmark_add_button_clicked(GtkWidget *button,BookmarkWindow *bwin)
00417 {
00418   BookmarkData *data;
00419   gchar *ctree_entry[2];
00420   GtkCTreeNode *node;
00421   
00422   data = g_new0(BookmarkData,1);
00423   node= NULL;
00424   
00425   data->url = ctree_entry[1] = g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->url_entry)));
00426   
00427   if (((GtkCTreeRow *)(((GList *)(bwin->menu_node))->data))->is_leaf)
00428     bwin->menu_node= ((GtkCTreeRow *)(((GList *)(bwin->menu_node))->data))->parent;
00429   
00430   /* it's a url */
00431   if (g_ascii_strcasecmp(data->url," ")!=0)
00432   {
00433     data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->text_entry))));
00434     node = gtk_ctree_insert_node(GTK_CTREE(bwin->ctree),bwin->menu_node,NULL,ctree_entry,0,NULL,NULL,NULL,NULL,TRUE,FALSE);
00435   }
00436   else /* it's a folder */
00437   {
00438     data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->folder_entry))));
00439     if (g_ascii_strcasecmp(data->label,"")==0)
00440       data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->text_entry))));
00441     node = gtk_ctree_insert_node(GTK_CTREE(bwin->ctree),bwin->menu_node,NULL,ctree_entry,0,NULL,NULL,NULL,NULL,FALSE,TRUE);
00442   }
00443   
00444   gtk_ctree_node_set_row_data(GTK_CTREE(bwin->ctree),node,data);
00445   g_node_append_data(bwin->parent_node,data);
00446   
00447   clear_entries(bwin);
00448 }
00449 
00450 /* add a folder */
00451 void on_bookmark_edit_button_clicked(GtkWidget *button,BookmarkWindow *bwin)
00452 {
00453   BookmarkData *data;
00454   gchar *ctree_entry[2];
00455   GNode *parent;
00456   data = g_new0(BookmarkData,1);
00457   
00458   data->label = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->text_entry))));
00459   data->url = ctree_entry[1]= g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->url_entry)));
00460   
00461   /* it's a folder */
00462   if (g_ascii_strcasecmp(data->url," ")==0)
00463   {
00464     data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->folder_entry))));
00465     if (g_ascii_strcasecmp(data->label,"")==0)
00466       data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->text_entry))));
00467     gtk_ctree_set_node_info(GTK_CTREE(bwin->ctree),bwin->menu_node,ctree_entry[0],0,NULL,NULL,NULL,NULL,FALSE,TRUE);
00468   }
00469   else /* it's a url */
00470   {
00471     data->label = ctree_entry[0] = g_strstrip(g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->text_entry))));
00472     gtk_ctree_set_node_info(GTK_CTREE(bwin->ctree),bwin->menu_node,ctree_entry[0],0,NULL,NULL,NULL,NULL,TRUE,FALSE);
00473   }
00474   
00475   gtk_ctree_node_set_row_data(GTK_CTREE(bwin->ctree),bwin->menu_node,data);
00476   
00477   parent= g_node_append_data(bwin->temp_node->parent,data);
00478   
00479   if (bwin->temp_node->children!= NULL)
00480     move_folder(bwin->temp_node->children,parent);
00481   
00482   g_node_destroy(bwin->temp_node);
00483   
00484   clear_entries(bwin);
00485 }
00486 
00487 /* a button to go to a selected url */
00488 void on_bookmark_go_button_clicked(GtkButton *button,BookmarkWindow *bwin)
00489 {
00490   GList *selection;
00491   gchar *url;
00492   
00493   /* case there isn't a selected url */
00494   if (!(selection = GTK_CLIST(bwin->ctree)->selection)) return;
00495   
00496   url= g_strdup(gtk_entry_get_text(GTK_ENTRY(bwin->url_entry)));
00497   
00498   /* it isn't a folder */
00499   if (g_ascii_strcasecmp(url," ") != 0)
00500   {
00501     gtk_moz_embed_stop_load(GTK_MOZ_EMBED(minEmbed));
00502     gtk_moz_embed_load_url(GTK_MOZ_EMBED(minEmbed), url);
00503   }
00504   clear_entries(bwin);
00505 }
00506 
00507 /* accept new edit configurations and update bookmark menu */
00508 void on_bookmark_ok_button_clicked(GtkWidget *button,BookmarkWindow *bwin)
00509 {
00510   print_bookmarks();
00511   close_bookmark_window(bwin);
00512 }
00513 
00514 /* cancel user's operations */
00515 void on_bookmark_cancel_button_clicked(GtkWidget *button,BookmarkWindow *bwin)
00516 {      
00517   close_bookmark_window(bwin);
00518 }
00519 
00520 /* remove a selected bookmark */
00521 void on_bookmark_remove_button_clicked(GtkWidget *button,BookmarkWindow *bwin)
00522 {
00523   GList *selection;
00524   GtkCTreeNode *node;
00525   BookmarkData *data;
00526   GNode *menu_node;
00527   
00528   /* case there isn't a selected folder, url or separator to be removed */
00529   if (!(selection = GTK_CLIST(bwin->ctree)->selection)) {
00530     return;
00531   }
00532   
00533   node = (GtkCTreeNode*) g_list_nth_data(selection,0);
00534   
00535   data = g_new0(BookmarkData,1);
00536   data= (BookmarkData*) gtk_ctree_node_get_row_data(GTK_CTREE(bwin->ctree),node);
00537   
00538   gtk_ctree_remove_node(GTK_CTREE(bwin->ctree),node);
00539   
00540   menu_node= g_node_find(bookmarks, G_IN_ORDER, G_TRAVERSE_ALL, data);
00541   
00542   g_node_destroy(menu_node);
00543   
00544   clear_entries(bwin);
00545 }
00546 
00547 /* write bookmarks on file */
00548 void print_bookmarks ()
00549 {
00550   char* file = g_strconcat(g_get_home_dir(),"/.Minimo/bookmarks",NULL);
00551   
00552   fclose(bookmark_file);
00553   bookmark_file = fopen(file,"w");
00554   
00555   if (bookmarks != NULL)
00556     g_node_children_foreach(bookmarks,G_TRAVERSE_ALL,(GNodeForeachFunc)print_node_data,bookmark_file);
00557 }
00558 
00559 /* print node data on file */
00560 void print_node_data (GNode *node,FILE *bookmark_file)
00561 {
00562   BookmarkData *data;
00563   
00564   data = (BookmarkData*) node->data;
00565   
00566   /* it's a url */
00567   if (g_ascii_strcasecmp(data->url," ") != 0)
00568     fprintf(bookmark_file,"url %s %s\n",data->url,data->label);
00569   else /* it's a folder */
00570   {
00571     fprintf(bookmark_file,"folder %s\n",data->label);
00572     g_node_children_foreach(node,G_TRAVERSE_ALL,(GNodeForeachFunc)print_node_data,bookmark_file);
00573     fprintf(bookmark_file,"/folder\n");
00574   }
00575 }
00576 
00577 /* clear all the bookmarks entries */
00578 void clear_entries(BookmarkWindow *bwin)
00579 {
00580   bwin->menu_node= gtk_ctree_node_nth(GTK_CTREE(bwin->ctree),0);
00581   bwin->parent_node= g_node_get_root(bookmarks);
00582   gtk_ctree_unselect_recursive(GTK_CTREE(bwin->ctree),gtk_ctree_node_nth (GTK_CTREE(bwin->ctree),0));
00583   gtk_entry_set_text(GTK_ENTRY(bwin->url_entry)," ");
00584   gtk_editable_delete_text(GTK_EDITABLE(bwin->text_entry),0 ,-1);
00585   gtk_editable_delete_text(GTK_EDITABLE(bwin->folder_entry),0 ,-1);
00586 }
00587 
00588 /* close the bookmark window */
00589 void close_bookmark_window(BookmarkWindow *bwin)
00590 {      
00591   /* close bookmark file*/
00592   fclose(bookmark_file);
00593   
00594   gtk_widget_destroy(bwin->window);
00595   g_free(bwin);
00596 }
00597 
00598 /* export bookmarks callback */
00599 void export_bookmarks(GtkButton *button,BookmarkWindow *bwin)
00600 {
00601   
00602 }
00603 
00604 /* the menu button to add a bookmark */
00605 void add_bookmark_cb(GtkWidget *menu_item,GtkWidget *embed)
00606 {
00607   gchar *url;
00608   gchar *title;
00609   
00610   char* file_path = g_strconcat(g_get_home_dir(),"/.Minimo/bookmarks",NULL);
00611   if (!file_path)
00612     return;
00613 
00614   if (!(bookmark_file = fopen(file_path,"a+"))) return;
00615 
00616   g_free(file_path);
00617   
00618   if (!(url= gtk_moz_embed_get_location(minEmbed))) return;
00619   
00620   /* doesn't add an empty url or about:blank */
00621   if ((g_ascii_strcasecmp(url," ") != 0) && (g_ascii_strcasecmp(url,"about:blank") != 0))
00622   {
00623     title= gtk_moz_embed_get_title (minEmbed);
00624     fprintf(bookmark_file, "url %s %s\n", url, title);
00625   }
00626   
00627   fclose(bookmark_file);    
00628 }