diff --git a/src/callbacks.c b/src/callbacks.c index cc57404..5a6a8c3 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1,20 +1,17 @@ /* $Id$ */ -static char const _copyright[] = -"Copyright (c) 2010 Pierre Pronchery "; +/* Copyright (c) 2010 Pierre Pronchery */ /* This file is part of DeforaOS Desktop Surfer */ -static char const _license[] = -"Surfer is free software; you can redistribute it and/or modify it\n" -"under the terms of the GNU General Public License version 2 as\n" -"published by the Free Software Foundation.\n" -"\n" -"Surfer is distributed in the hope that it will be useful, but WITHOUT ANY\n" -"WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n" -"FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n" -"details.\n" -"\n" -"You should have received a copy of the GNU General Public License along\n" -"with Surfer; if not, write to the Free Software Foundation, Inc., 59 Temple\n" -"Place, Suite 330, Boston, MA 02111-1307 USA\n"; +/* Surfer is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * Surfer is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * Surfer; if not, write to the Free Software Foundation, Inc., 59 Temple Place, + * Suite 330, Boston, MA 02111-1307 USA */ @@ -27,18 +24,9 @@ static char const _license[] = #include "ghtml.h" #include "callbacks.h" #include "common.h" -#include "../config.h" #define _(string) gettext(string) -/* constants */ -static char const * _authors[] = -{ - "Pierre Pronchery ", - NULL -}; - - /* window */ gboolean on_closex(gpointer data) { @@ -230,208 +218,12 @@ void on_view_zoom_out(gpointer data) /* help menu */ /* on_help_about */ -static gboolean _about_on_closex(gpointer data); -# if !GTK_CHECK_VERSION(2, 6, 0) -static void _about_on_close(GtkWidget * widget, gpointer data); -static void _about_on_credits(GtkWidget * widget, gpointer data); -static void _about_on_license(GtkWidget * widget, gpointer data); -# endif - void on_help_about(gpointer data) { Surfer * surfer = data; - static GtkWidget * window = NULL; -# if GTK_CHECK_VERSION(2, 6, 0) - gsize cnt = 65536; - gchar * buf; - if(window != NULL) - { - gtk_widget_show(window); - return; - } - if((buf = malloc(sizeof(*buf) * cnt)) == NULL) - { - surfer_error(surfer, "Memory allocation failed", 0); - return; - } - window = gtk_about_dialog_new(); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW( - surfer->window)); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(window), PACKAGE); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window), VERSION); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(window), _authors); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window), _copyright); - gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(window), - "stock_internet"); - if(g_file_get_contents("/usr/share/common-licenses/GPL-2", &buf, &cnt, - NULL) == TRUE) - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window), buf); - else - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window), - _license); - free(buf); - g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK( - _about_on_closex), window); - g_signal_connect(G_OBJECT(window), "response", G_CALLBACK( - gtk_widget_hide), NULL); - gtk_widget_show(window); + surfer_about(surfer); } -# else - GtkWidget * vbox; - GtkWidget * hbox; - GtkWidget * button; - - if(window != NULL) - { - gtk_widget_show(window); - return; - } - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK( - _about_on_closex), window); - gtk_container_set_border_width(GTK_CONTAINER(window), 4); - gtk_window_set_title(GTK_WINDOW(window), _("About " PACKAGE)); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW( - surfer->window)); - vbox = gtk_vbox_new(FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(PACKAGE " " VERSION), - FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(_copyright), FALSE, - FALSE, 2); - hbox = gtk_hbox_new(TRUE, 4); - button = gtk_button_new_with_mnemonic(_("C_redits")); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK( - _about_on_credits), window); - gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 4); - button = gtk_button_new_with_mnemonic(_("_License")); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK( - _about_on_license), window); - gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 4); - button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK( - _about_on_close), window); - gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, TRUE, 4); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 4); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_widget_show_all(window); -} -# endif - -static gboolean _about_on_closex(gpointer data) -{ - GtkWidget * widget = data; - - gtk_widget_hide(widget); - return TRUE; -} - -# if !GTK_CHECK_VERSION(2, 6, 0) -static void _about_on_close(GtkWidget * widget, gpointer data) -{ - GtkWidget * window = data; - - gtk_widget_hide(window); -} - -static void _about_on_credits(GtkWidget * widget, gpointer data) -{ - static GtkWidget * window = NULL; - GtkWidget * about = data; - GtkWidget * vbox; - GtkWidget * notebook; - GtkWidget * textview; - GtkTextBuffer * tbuf; - GtkTextIter iter; - GtkWidget * hbox; - size_t i; - - if(window != NULL) - { - gtk_widget_show(window); - return; - } - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); - gtk_container_set_border_width(GTK_CONTAINER(window), 4); - gtk_window_set_title(GTK_WINDOW(window), _("Credits")); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(about)); - g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK( - _about_on_closex), window); - vbox = gtk_vbox_new(FALSE, 0); - textview = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE); - tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); - gtk_text_buffer_set_text(tbuf, "", 0); - for(i = 0; _authors[i] != NULL; i++) - { - gtk_text_buffer_get_end_iter(tbuf, &iter); - gtk_text_buffer_insert(tbuf, &iter, _authors[i], strlen( - _authors[i])); - } - widget = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(widget), textview); - notebook = gtk_notebook_new(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), widget, - gtk_label_new(_("Written by"))); - gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 4); - hbox = gtk_hbox_new(FALSE, 0); - widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect(G_OBJECT(widget), "clicked", - G_CALLBACK(_about_on_close), window); - gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 4); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 4); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_widget_show_all(window); -} - -static void _about_on_license(GtkWidget * widget, gpointer data) -{ - static GtkWidget * window = NULL; - GtkWidget * about = data; - GtkWidget * vbox; - GtkWidget * textview; - GtkTextBuffer * tbuf; - GtkWidget * hbox; - - if(window != NULL) - { - gtk_widget_show(window); - return; - } - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); - gtk_container_set_border_width(GTK_CONTAINER(window), 4); - gtk_window_set_title(GTK_WINDOW(window), _("License")); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(about)); - g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK( - _about_on_closex), window); - vbox = gtk_vbox_new(FALSE, 0); - textview = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE); - tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); - gtk_text_buffer_set_text(tbuf, _license, strlen(_license)); - widget = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(widget), textview); - gtk_box_pack_start(GTK_BOX(vbox), widget, TRUE, TRUE, 4); - hbox = gtk_hbox_new(FALSE, 0); - widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect(G_OBJECT(widget), "clicked", - G_CALLBACK(_about_on_close), window); - gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 4); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 4); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_widget_show_all(window); -} -# endif /* !GTK_CHECK_VERSION(2, 6, 0) */ #endif /* !EMBEDDED */ diff --git a/src/common.h b/src/common.h index f59ce0a..c2c3745 100644 --- a/src/common.h +++ b/src/common.h @@ -65,6 +65,9 @@ struct _Surfer GtkWidget * co_window; GtkWidget * co_entry; GtkListStore * co_store; + + /* about */ + GtkWidget * ab_dialog; }; #endif /* !SURFER_COMMON_H */ diff --git a/src/surfer.c b/src/surfer.c index b50b5cc..24bf790 100644 --- a/src/surfer.c +++ b/src/surfer.c @@ -1,17 +1,20 @@ /* $Id$ */ -/* Copyright (c) 2010 Pierre Pronchery */ +static char const _copyright[] = +"Copyright (c) 2010 Pierre Pronchery "; /* This file is part of DeforaOS Desktop Surfer */ -/* Surfer is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License version 2 as published by the Free - * Software Foundation. - * - * Surfer is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Surfer; if not, write to the Free Software Foundation, Inc., 59 Temple Place, - * Suite 330, Boston, MA 02111-1307 USA */ +static char const _license[] = +"Surfer is free software; you can redistribute it and/or modify it\n" +"under the terms of the GNU General Public License version 2 as\n" +"published by the Free Software Foundation.\n" +"\n" +"Surfer is distributed in the hope that it will be useful, but WITHOUT ANY\n" +"WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n" +"FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n" +"details.\n" +"\n" +"You should have received a copy of the GNU General Public License along\n" +"with Surfer; if not, write to the Free Software Foundation, Inc., 59 Temple\n" +"Place, Suite 330, Boston, MA 02111-1307 USA\n"; @@ -25,6 +28,7 @@ #include "ghtml.h" #include "surfer.h" #include "common.h" +#include "../config.h" #define _(string) gettext(string) #define N_(string) (string) @@ -46,6 +50,14 @@ typedef enum _SurferConsoleMessage #define SCM_COUNT (SCM_LAST + 1) +/* constants */ +static char const * _authors[] = +{ + "Pierre Pronchery ", + NULL +}; + + /* variables */ static DesktopAccel _surfer_accel[] = { @@ -318,6 +330,8 @@ Surfer * _new_do(char const * url) surfer->co_window = NULL; surfer->co_store = gtk_list_store_new(SCM_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); + /* about */ + surfer->ab_dialog = NULL; /* hack to display the statusbar only if necessary */ gtk_box_pack_start(GTK_BOX(vbox), surfer->statusbox, FALSE, FALSE, 0); surfer_set_status(surfer, NULL); @@ -496,6 +510,28 @@ void surfer_set_title(Surfer * surfer, char const * title) /* useful */ +/* surfer_about */ +void surfer_about(Surfer * surfer) +{ + if(surfer->ab_dialog != NULL) + { + gtk_widget_show(surfer->ab_dialog); + return; + } + surfer->ab_dialog = desktop_about_dialog_new(); + gtk_window_set_transient_for(GTK_WINDOW(surfer->ab_dialog), + GTK_WINDOW(surfer->window)); + desktop_about_dialog_set_authors(surfer->ab_dialog, _authors); + desktop_about_dialog_set_copyright(surfer->ab_dialog, _copyright); + desktop_about_dialog_set_logo_icon_name(surfer->ab_dialog, + "stock_internet"); + desktop_about_dialog_set_license(surfer->ab_dialog, _license); + desktop_about_dialog_set_name(surfer->ab_dialog, PACKAGE); + desktop_about_dialog_set_version(surfer->ab_dialog, VERSION); + gtk_widget_show(surfer->ab_dialog); +} + + /* surfer_close_tab */ void surfer_close_tab(Surfer * surfer, GtkWidget * view) { diff --git a/src/surfer.h b/src/surfer.h index 67e1b41..817b222 100644 --- a/src/surfer.h +++ b/src/surfer.h @@ -90,6 +90,7 @@ void surfer_find(Surfer * surfer, char const * text); void surfer_download(Surfer * surfer, char const * url, char const * suggested); /* interface */ +void surfer_about(Surfer * surfer); void surfer_resize(Surfer * surfer, gint width, gint height); void surfer_show_console(Surfer * surfer, gboolean show); void surfer_show_menubar(Surfer * surfer, gboolean show);