Back to index

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