Back to index

lightning-sunbird  0.9+nobinonly
minimo_callbacks.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. 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 "nsMemory.h"
00051 #include "minimo_callbacks.h"
00052 #include "minimo_context.h"
00053 #include "minimo_history.h"
00054 #include "mozilla_api.h"
00055 
00056 /* Number of browsers */
00057 extern int gMinimoNumBrowsers;
00058 
00059 extern gchar *gMinimoLinkMessageURL ;
00060 
00061 /* Emulating right button clicks */
00062 RightButtonClick *rButtonClick;
00063 
00064 void
00065 set_browser_visibility(MinimoBrowser *browser, gboolean visibility) {
00066   
00067   if (!visibility) {
00068     gtk_widget_hide(browser->topLevelWindow);
00069     return;
00070   }
00071   
00072   gtk_widget_show(browser->mozEmbed);
00073   gtk_widget_show(browser->topLevelVBox);
00074   gtk_widget_show(browser->topLevelWindow);
00075 }
00076 
00077 /* callbacks handlers */
00078 void browse_in_window_from_popup(GtkWidget *menuitem, MinimoBrowser *browser)
00079 {
00080   gchar *href;
00081   
00082   href = (gchar *) g_object_get_data(G_OBJECT(menuitem), "link");
00083   
00084   minimo_load_url(href, browser);
00085   
00086   return;
00087 }
00088 
00089 void download_link_from_popup(GtkWidget *menuitem, MinimoBrowser *browser)
00090 {
00091   
00092   gchar *href;
00093   
00094   href = (gchar *) g_object_get_data(G_OBJECT(menuitem), "link");
00095   if (!href) {
00096     return;
00097   }
00098   
00099   create_save_document(NULL, browser, href);
00100   
00101   return;
00102 }
00103 
00104 void minimo_load_url(gchar *url, MinimoBrowser *browser)
00105 {
00106   g_return_if_fail(browser->mozEmbed != NULL);
00107   g_return_if_fail(url != NULL);
00108   
00109   gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser->mozEmbed), url);
00110   
00111   return;
00112 }
00113 
00114 void make_tab_from_popup(GtkWidget *menuitem, MinimoBrowser *browser)
00115 {
00116   gchar *href;
00117   
00118   href = (gchar *) g_object_get_data(G_OBJECT(menuitem), "link");
00119   open_new_tab_cb(NULL, browser);
00120   
00121   minimo_load_url(href, browser);
00122   
00123   return;
00124 }
00125 
00126 void open_new_tab_cb (GtkMenuItem *button, MinimoBrowser *browser)
00127 {
00128   GtkWidget *page_label;
00129   gint num_pages;
00130   gchar *page_title;
00131   gint current_page;
00132   
00133   g_return_if_fail(browser->notebook != NULL);
00134   
00135   /* right button click emulation initialization */
00136   rButtonClick = (RightButtonClick*) malloc(sizeof(RightButtonClick));
00137   rButtonClick->sig_handler= 0;
00138   rButtonClick->is_connected= FALSE;
00139   
00140   num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
00141   page_title = g_strdup_printf("%d",num_pages+1);
00142   page_label = gtk_label_new (page_title);
00143   
00144   browser->mozEmbed = gtk_moz_embed_new();
00145   
00146   gtk_notebook_append_page (GTK_NOTEBOOK (browser->notebook), browser->mozEmbed, page_label);
00147   gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (browser->notebook), browser->mozEmbed, FALSE, FALSE, GTK_PACK_START);
00148   gtk_widget_show (browser->mozEmbed);
00149   
00150   current_page = gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), browser->mozEmbed);
00151   gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), current_page);
00152   browser->active_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), current_page);
00153   
00154   num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
00155   
00156   browser->progressPopup = create_minimo_progress(browser);
00157   
00158   gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), 
00159                      browser->progressPopup,
00160                      FALSE, // expand
00161                      FALSE, // fill
00162                      0);   // padding
00163   
00164   /* applying the Signal into the new Render Engine - MozEmbed */
00165   // hook up the title change to update the window title
00166   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "title",       G_CALLBACK (title_changed_cb), browser);
00167   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "location",    G_CALLBACK(location_changed_cb), page_label);
00168   
00169   // hook up the start and stop signals
00170   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "net_start",   G_CALLBACK(load_started_cb), browser);
00171   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "net_stop",    G_CALLBACK(load_finished_cb), browser);
00172   
00173   // hookup to see whenever a new window is requested
00174   //g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "new_window",  G_CALLBACK(new_window_cb), browser);
00175   
00176   // hookup to any requested visibility changes
00177   g_signal_connect(GTK_OBJECT(browser->mozEmbed), "visibility",     G_CALLBACK(visibility_cb), browser);
00178   
00179   // hookup to the signal that is called when someone clicks on a link to load a new uri
00180   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "open_uri",    G_CALLBACK(open_uri_cb), browser);
00181   
00182   // this signal is emitted when there's a request to change the containing browser window to a certain height, like with width
00183   // and height args for a window.open in javascript
00184   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "size_to",     G_CALLBACK(size_to_cb), browser);
00185   g_signal_connect (GTK_OBJECT  (browser->mozEmbed), "link_message",G_CALLBACK (link_message_cb), browser);
00186   
00187   // this signals are emitted when the mouse is clicked, then we can measure the time between pressed and released for left click or right click
00188   g_signal_connect (GTK_OBJECT (browser->mozEmbed), "dom_mouse_down", G_CALLBACK(on_button_pressed_cb), browser);
00189   g_signal_connect (GTK_OBJECT (browser->mozEmbed), "dom_mouse_up", G_CALLBACK(on_button_released_cb), browser);
00190   
00191   gMinimoNumBrowsers= num_pages;
00192 }
00193 
00194 GtkWidget* create_minimo_progress (MinimoBrowser* browser)
00195 {
00196   GtkWidget *Minimo_Progress;
00197   GtkWidget *dialog_vbox4;
00198   GtkWidget *vbox3;
00199   GtkWidget *hbox2;
00200   GtkWidget *LoadingLabel;
00201   GtkWidget *URLLable;
00202   GtkWidget *progressbar1;
00203   GtkWidget *Minimo_Progress_Status;
00204   
00205   Minimo_Progress = gtk_vbox_new(FALSE, 0);
00206   
00207   dialog_vbox4 = Minimo_Progress;
00208   
00209   vbox3 = gtk_vbox_new(FALSE, 0);
00210   gtk_widget_show(vbox3);
00211   gtk_box_pack_start(GTK_BOX (dialog_vbox4), vbox3, FALSE, FALSE, 0);
00212   
00213   hbox2 = gtk_hbox_new(FALSE, 0);
00214   gtk_widget_show(hbox2);
00215   gtk_box_pack_start(GTK_BOX (vbox3), hbox2, FALSE, TRUE, 0);
00216   
00217   LoadingLabel = gtk_label_new("Loading:");
00218   gtk_widget_modify_font(LoadingLabel, getOrCreateDefaultMinimoFont());
00219   gtk_widget_show(LoadingLabel);
00220   gtk_box_pack_start(GTK_BOX (hbox2), LoadingLabel, FALSE, FALSE, 0);
00221   
00222   URLLable = gtk_label_new("...");
00223   gtk_widget_modify_font(URLLable, getOrCreateDefaultMinimoFont());
00224   gtk_widget_show(URLLable);
00225   gtk_box_pack_start(GTK_BOX (hbox2), URLLable, FALSE, FALSE, 0);
00226   gtk_label_set_justify(GTK_LABEL (URLLable), GTK_JUSTIFY_CENTER);
00227   
00228   progressbar1 = gtk_progress_bar_new ();
00229   gtk_widget_show(progressbar1);
00230   gtk_box_pack_start(GTK_BOX (vbox3), progressbar1, FALSE, FALSE, 0);
00231   gtk_widget_set_usize(progressbar1, 240, 20);
00232   
00233   Minimo_Progress_Status = gtk_label_new ("");
00234   gtk_widget_modify_font(Minimo_Progress_Status, getOrCreateDefaultMinimoFont());
00235   gtk_widget_show(Minimo_Progress_Status);
00236   gtk_box_pack_start(GTK_BOX (vbox3), Minimo_Progress_Status, TRUE, FALSE, 0);
00237   
00238   browser->progressBar = progressbar1;
00239   
00240   g_signal_connect(GTK_OBJECT(browser->mozEmbed), "net_state", G_CALLBACK(net_state_change_cb), Minimo_Progress_Status);
00241   g_signal_connect(GTK_OBJECT(browser->mozEmbed), "progress",  G_CALLBACK(progress_change_cb), browser);
00242   g_signal_connect(GTK_OBJECT(browser->mozEmbed), "location",  G_CALLBACK(location_changed_cb), URLLable);
00243   
00244   return Minimo_Progress;
00245 }
00246 
00247 void quick_message(gchar* message)
00248 {
00249   GtkWidget *dialog, *label, *okbutton;
00250   
00251   dialog = gtk_dialog_new();
00252   label  = gtk_label_new(message);
00253   okbutton = gtk_button_new_with_label("Ok");
00254   
00255   gtk_widget_modify_font(label, getOrCreateDefaultMinimoFont());
00256   gtk_widget_modify_font(okbutton, getOrCreateDefaultMinimoFont());
00257   
00258   g_signal_connect_swapped(GTK_OBJECT(okbutton), "clicked", G_CALLBACK(gtk_widget_destroy), dialog);
00259   
00260   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), okbutton);
00261   
00262   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
00263   gtk_widget_show_all(dialog);
00264 }
00265 
00266 void net_state_change_cb(GtkMozEmbed *embed, gint flags, guint status, GtkLabel* label)
00267 {
00268   char * message = "Waiting...";
00269   
00270   if(flags & GTK_MOZ_EMBED_FLAG_IS_REQUEST) 
00271   {
00272     if (flags & GTK_MOZ_EMBED_FLAG_REDIRECTING)
00273       message = "Redirecting to site...";
00274     else if (flags & GTK_MOZ_EMBED_FLAG_TRANSFERRING)
00275       message = "Transferring data from site...";
00276     else if (flags & GTK_MOZ_EMBED_FLAG_NEGOTIATING)
00277       message = "Waiting for authorization...";
00278   }
00279   
00280   if (status == GTK_MOZ_EMBED_STATUS_FAILED_DNS)
00281     message = "Site not found.";
00282   else if (status == GTK_MOZ_EMBED_STATUS_FAILED_CONNECT)
00283     message = "Failed to connect to site.";
00284   else if (status == GTK_MOZ_EMBED_STATUS_FAILED_TIMEOUT)
00285     message = "Failed due to connection timeout.";
00286   else if (status == GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED)
00287     message = "User canceled connecting to site.";
00288   
00289   if (flags & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT) {
00290     if (flags & GTK_MOZ_EMBED_FLAG_START)
00291       message = "Loading site...";
00292     else if (flags & GTK_MOZ_EMBED_FLAG_STOP)
00293       message = "Done.";
00294   }
00295   
00296   gtk_label_set_text(label, message);
00297 }
00298 
00299 void progress_change_cb(GtkMozEmbed *embed, gint cur, gint max, MinimoBrowser* browser)
00300 {
00301   browser->totalBytes += cur;
00302   
00303   if (max < 1)
00304     gtk_progress_bar_pulse(GTK_PROGRESS_BAR(browser->progressBar));
00305   
00306   else { 
00307     float tmp = (cur/max);
00308     
00309     if ( tmp <= 1 && tmp >=0)
00310       gtk_progress_bar_update(GTK_PROGRESS_BAR(browser->progressBar), cur/max);
00311   }
00312 }
00313 
00314 
00315 void close_current_tab_cb (GtkMenuItem *button, MinimoBrowser *browser)
00316 {
00317   gint current_page, num_pages;
00318   
00319   num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
00320   
00321   if (num_pages >1) {
00322        
00323     current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
00324        
00325     gtk_notebook_remove_page (GTK_NOTEBOOK (browser->notebook), current_page);
00326     num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
00327     gMinimoNumBrowsers= num_pages;
00328        
00329     if (num_pages == 1) {
00330       gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), FALSE);
00331     }
00332   }
00333   
00334   g_free(rButtonClick);
00335 }
00336 
00337 /* bookmark button clicked */ 
00338 void open_bookmark_window_cb (GtkMenuItem *button,MinimoBrowser *browser)
00339 {
00340   open_bookmark();
00341 }
00342 
00343 void back_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00344 {
00345   gtk_moz_embed_go_back(GTK_MOZ_EMBED(browser->mozEmbed));
00346 }
00347 
00348 void reload_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00349 {
00350   GdkModifierType state = (GdkModifierType)0;
00351   gint x, y;
00352   gdk_window_get_pointer(NULL, &x, &y, &state);
00353   
00354   gtk_moz_embed_reload(GTK_MOZ_EMBED(browser->mozEmbed),
00355                        (state & GDK_SHIFT_MASK) ?
00356                        GTK_MOZ_EMBED_FLAG_RELOADBYPASSCACHE : 
00357                        GTK_MOZ_EMBED_FLAG_RELOADNORMAL);
00358 }
00359 
00360 void forward_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00361 {
00362   gtk_moz_embed_go_forward(GTK_MOZ_EMBED(browser->mozEmbed));
00363 }
00364 
00365 void stop_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00366 {
00367   gtk_moz_embed_stop_load(GTK_MOZ_EMBED(browser->mozEmbed));
00368 }
00369 
00370 gboolean delete_cb(GtkWidget *widget, GdkEventAny *event, MinimoBrowser *browser)
00371 {
00372   gtk_widget_destroy(widget);
00373   return TRUE;
00374 }
00375 
00376 /* Creates a GUI for proxy and 'block popup' settings */
00377 void pref_clicked_cb(GtkButton *button, MinimoBrowser *browser) {
00378   
00379   build_pref_window (browser->topLevelWindow);
00380 }
00381 
00382 void title_changed_cb(GtkMozEmbed *embed, MinimoBrowser *browser)
00383 {
00384   char *newTitle;
00385   
00386   newTitle = gtk_moz_embed_get_title(embed);
00387   if(newTitle) {
00388     gtk_window_set_title(GTK_WINDOW(browser->topLevelWindow), newTitle);
00389     g_free(newTitle);
00390   }
00391 }
00392 
00393 void load_started_cb(GtkMozEmbed *embed, MinimoBrowser *browser)
00394 {
00395   browser->totalBytes = 0;
00396   gtk_widget_show_all(browser->progressPopup);
00397 }
00398 
00399 void load_finished_cb(GtkMozEmbed *embed, MinimoBrowser *browser)
00400 {
00401   gtk_widget_hide_all(browser->progressPopup);
00402   nsMemory::HeapMinimize(PR_TRUE);
00403 }
00404 /*
00405   void new_window_cb(GtkMozEmbed *embed, GtkMozEmbed **newEmbed, guint chromemask, MinimoBrowser *browser)
00406   {
00407   //   open_new_tab_cb (NULL, browser);
00408   //   gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser->mozEmbed), gMinimoLinkMessageURL );
00409   //   show_hide_tabs_cb (NULL, browser);
00410   MinimoBrowser *newBrowser = new_gtk_browser(chromemask);
00411   gtk_widget_set_usize(newBrowser->mozEmbed, 240, 320);
00412   *newEmbed = GTK_MOZ_EMBED(newBrowser->mozEmbed);
00413   }
00414 */
00415 void location_changed_cb(GtkMozEmbed *embed, GtkLabel* label)
00416 {
00417   char *newLocation;
00418   
00419   newLocation = gtk_moz_embed_get_location(embed);
00420   if (newLocation) {
00421     
00422     gtk_label_set_text(label, newLocation);
00423     add_to_history(newLocation);
00424     g_free(newLocation);
00425   }
00426 }
00427 
00428 /* Method that create the "save dialog" */
00429 void create_save_document(GtkMenuItem *button, MinimoBrowser *browser, gchar *location) 
00430 {
00431   GtkWidget *fs, *ok_button, *cancel_button, *hbox;
00432   GtkWidget *SaveDialog, *scrolled_window;
00433   OpenDialogParams *dialogParams;
00434   
00435   G_CONST_RETURN gchar *file_name = NULL;
00436   
00437   g_return_if_fail(browser->mozEmbed != NULL);
00438   
00439   if (location)
00440     location = gtk_moz_embed_get_location(GTK_MOZ_EMBED (browser->mozEmbed));
00441   
00442   if (location) file_name = g_basename(location);
00443   
00444   dialogParams = (OpenDialogParams*) malloc(sizeof(OpenDialogParams));
00445   
00446   fs = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_SAVE);
00447   SaveDialog = gtk_dialog_new ();
00448   gtk_widget_set_size_request (SaveDialog, 240, 320);
00449   gtk_window_set_title (GTK_WINDOW (SaveDialog), ("Save as"));
00450   gtk_window_set_position (GTK_WINDOW (SaveDialog), GTK_WIN_POS_CENTER_ON_PARENT);
00451   gtk_window_set_modal (GTK_WINDOW (SaveDialog), TRUE);
00452   gtk_window_set_default_size (GTK_WINDOW (SaveDialog), 240, 320);
00453   gtk_window_set_resizable (GTK_WINDOW (SaveDialog), FALSE);
00454   gtk_window_set_decorated (GTK_WINDOW (SaveDialog), TRUE);
00455   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (SaveDialog), TRUE);
00456   gtk_window_set_skip_pager_hint (GTK_WINDOW (SaveDialog), TRUE);
00457   gtk_window_set_type_hint (GTK_WINDOW (SaveDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00458   gtk_window_set_gravity (GTK_WINDOW (SaveDialog), GDK_GRAVITY_NORTH_EAST);
00459   gtk_window_set_transient_for(GTK_WINDOW(SaveDialog), GTK_WINDOW(browser->topLevelWindow));
00460   
00461   scrolled_window = gtk_scrolled_window_new(NULL,NULL);
00462   gtk_widget_show(scrolled_window);
00463   gtk_box_pack_start(GTK_BOX(GTK_DIALOG (SaveDialog)->vbox),scrolled_window,TRUE,TRUE,0);
00464   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
00465   
00466   gtk_scrolled_window_add_with_viewport ( GTK_SCROLLED_WINDOW (scrolled_window) ,fs);
00467   
00468   g_object_set_data(G_OBJECT(fs), "minimo", browser);
00469   
00470   /* adding extra button into the widget -> 'Ok and Cancel' Button */
00471   ok_button = gtk_button_new_with_label ("Ok");
00472   gtk_widget_modify_font(GTK_BIN(ok_button)->child, getOrCreateDefaultMinimoFont());
00473   
00474   cancel_button = gtk_button_new_with_label ("Cancel");
00475   gtk_widget_modify_font(GTK_BIN(cancel_button)->child, getOrCreateDefaultMinimoFont());
00476   
00477   hbox = gtk_hbox_new(FALSE, 10);
00478   gtk_box_pack_start(GTK_BOX (hbox), ok_button, FALSE, TRUE, 10);
00479   gtk_box_pack_start(GTK_BOX (hbox), cancel_button, FALSE, TRUE, 10);
00480   gtk_widget_show_all (hbox);
00481   
00482   gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER (fs), GTK_WIDGET (hbox));
00483   
00484   dialogParams->main_combo= fs;    
00485   dialogParams->dialog_combo= SaveDialog;
00486   
00487   /* connecting callbacks into the extra buttons */
00488   g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(on_save_ok_cb), dialogParams);
00489   
00490   gtk_widget_show(fs);
00491   gtk_widget_show_all(SaveDialog);
00492   
00493   return;
00494 }
00495 
00496 void on_save_ok_cb(GtkWidget *button, OpenDialogParams *dialogParams) {
00497   
00498   MinimoBrowser *browser = NULL;
00499   G_CONST_RETURN gchar *filename;
00500   
00501   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialogParams->main_combo));
00502   
00503   if (!filename || !strcmp(filename,"")) {
00504        
00505     return ;
00506        
00507   } else {
00508     browser = (MinimoBrowser *) g_object_get_data(G_OBJECT(dialogParams->main_combo), "minimo");
00509     
00510     if (!mozilla_save( GTK_MOZ_EMBED (browser->mozEmbed), (gchar *) filename, TRUE )) {
00511       //create_dialog("Error","Save failed, did you enter a name?",0,0);
00512     }
00513     
00514     gtk_widget_destroy(dialogParams->main_combo);
00515     gtk_widget_destroy(dialogParams->dialog_combo);
00516     
00517     g_free(dialogParams);
00518   }
00519   return ;
00520 }
00521 
00522 void save_image_from_popup(GtkWidget *menuitem, MinimoBrowser *browser)
00523 {
00524   
00525   gchar *href, *name, *FullPath;
00526   
00527   FullPath= PR_GetEnv("HOME");
00528   
00529   href = (gchar *) g_object_get_data(G_OBJECT(menuitem), "link");
00530   if (!href) {
00531     g_print("Could not find href to save image\n");
00532     return;
00533   }
00534   name = (gchar *) g_object_get_data(G_OBJECT(menuitem), "name");
00535   
00536   FullPath= g_strconcat(FullPath,"/downloaded_files/",NULL);
00537   mkdir(FullPath,0755);
00538   
00539   FullPath= g_strconcat(FullPath,name,NULL);
00540   mozilla_save_image(GTK_MOZ_EMBED(browser->mozEmbed),href,FullPath);
00541   
00542   g_free(FullPath);
00543   g_free(name);
00544   g_free(href);
00545   return;
00546 }
00547 
00548 void visibility_cb(GtkMozEmbed *embed, gboolean visibility, MinimoBrowser *browser)
00549 {
00550   set_browser_visibility(browser, visibility);
00551 }
00552 
00553 gint open_uri_cb(GtkMozEmbed *embed, const char *uri, MinimoBrowser *browser)
00554 {
00555   // don't interrupt anything
00556   return FALSE;
00557 }
00558 
00559 void size_to_cb(GtkMozEmbed *embed, gint width, gint height,
00560                 MinimoBrowser *browser)
00561 {
00562   gtk_widget_set_usize(browser->mozEmbed, width, height);
00563 }
00564 
00565 void link_message_cb (GtkWidget *embed, MinimoBrowser *browser)
00566 {
00567   gMinimoLinkMessageURL  = mozilla_get_link_message (browser->active_page);
00568 }
00569 
00570 /* (mouse or stylus) clicks interaction */
00571 void on_button_clicked_cb(GtkWidget *button, MinimoBrowser *browser)
00572 {
00573   return;
00574 }
00575 
00576 /* button pressed */
00577 gint on_button_pressed_cb(GtkWidget *button, MinimoBrowser *browser)
00578 {
00579   rButtonClick->pressing_timer= g_timer_new();
00580   
00581   return NS_OK;
00582 }
00583 
00584 /* button released */
00585 gint on_button_released_cb(GtkWidget *button, gpointer *dom_event, MinimoBrowser *browser)
00586 {
00587   gint button_number;
00588   glong type;
00589   gdouble timeElapsed;
00590   gchar *img=NULL, *href=NULL, *linktext=NULL;
00591   
00592   type = mozilla_get_context_menu_type(GTK_MOZ_EMBED(browser->mozEmbed), dom_event, &img, &href, &linktext);
00593   
00594   button_number = 1;
00595   timeElapsed = g_timer_elapsed(rButtonClick->pressing_timer,0);
00596   g_timer_destroy(rButtonClick->pressing_timer);
00597   
00598   if (timeElapsed>= 2)
00599     button_number = 2;
00600   
00601   switch (button_number)
00602   {
00603   case 1: /* left button - disconect signal click for normal using */
00604     if (rButtonClick->is_connected) {
00605       g_signal_handler_disconnect(GTK_OBJECT (browser->mozEmbed), rButtonClick->sig_handler);
00606       rButtonClick->is_connected= FALSE;;
00607     }
00608     break;
00609   case 2: /* right button - connect signal click for do nothing with left button */
00610     if (!rButtonClick->is_connected) {
00611       rButtonClick->sig_handler= g_signal_connect(GTK_OBJECT(browser->mozEmbed),"dom_mouse_click", G_CALLBACK(on_button_clicked_cb), browser);
00612       rButtonClick->is_connected= TRUE;
00613     }
00614     
00615     if ((type & CONTEXT_IMAGE) && (type & CONTEXT_LINK)) {
00616       GtkWidget *menu = get_link_image_popup_menu(browser,img,href);
00617       gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, GDK_BUTTON3_MASK, gtk_get_current_event_time());
00618     } else if (type & CONTEXT_IMAGE) {
00619       gtk_menu_popup(GTK_MENU(get_image_popup_menu(browser,img)), NULL, NULL, NULL, NULL, GDK_BUTTON3_MASK, gtk_get_current_event_time());
00620     } else if (type & CONTEXT_LINK) {
00621       gtk_menu_popup(GTK_MENU(get_link_popup_menu(browser,href,linktext)), NULL, NULL, NULL, NULL, GDK_BUTTON3_MASK, gtk_get_current_event_time());
00622     } else if (type & CONTEXT_DOCUMENT) {
00623       gtk_menu_popup(GTK_MENU(get_doc_popup_menu(browser,href)), NULL, NULL, NULL, NULL, GDK_BUTTON3_MASK, gtk_get_current_event_time());
00624     } else if (type & CONTEXT_OTHER) {
00625       g_print("clicked on some other components\n");
00626     }
00627     break;
00628   default:
00629     break;
00630   }
00631   return NS_OK;
00632 }