From accf503afb3c23d40487b0638bc27273eb554413 Mon Sep 17 00:00:00 2001 From: wdlkmpx Date: Sat, 9 Jan 2021 07:09:42 +0800 Subject: [PATCH] about.c: use GtkAboutDialog it creates a nice about dialog with authors window and license window create a new global variable: main_window delete license.c/h --- configure.ac | 2 +- src/Makefile.am | 2 -- src/about.c | 71 ++++++++++++++++++++--------------------- src/gtkballs.h | 2 ++ src/license.c | 84 ------------------------------------------------- src/license.h | 6 ---- src/mainwin.c | 5 ++- 7 files changed, 41 insertions(+), 131 deletions(-) delete mode 100644 src/license.c delete mode 100644 src/license.h diff --git a/configure.ac b/configure.ac index 5deeba7..336425f 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AC_PROG_CC AC_HEADER_STDC AC_CHECK_HEADERS([sys/param.h signal.h]) -PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.0) +PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.8) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index 2fd0aa3..d34b3df 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,10 +2,8 @@ bin_PROGRAMS = gtkballs LIBS = @GTK_LIBS@ @LIBS@ AM_CFLAGS = @CFLAGS@ @GTK_CFLAGS@ -DDATADIR=\"$(datadir)\" -DLOCALSTATEDIR=\"$(localstatedir)\" -DLOCALEDIR=\"$(datadir)/locale\" -AM_CPPFLAGS = -I../intl gtkballs_SOURCES = gtkballs.c gtkballs.h gfx.c gfx.h \ - license.c license.h \ path.c path.h preferences.c preferences.h \ scoreboard.c scoreboard.h themerc.c themerc.h \ gtkutils.c gtkutils.h mainmenu.c mainmenu.h \ diff --git a/src/about.c b/src/about.c index ba200ca..d336f65 100644 --- a/src/about.c +++ b/src/about.c @@ -6,47 +6,44 @@ * version 2 of the License, or (at your option) any later version. */ #include - #include "gtkballs.h" /* _(), VERSION from config.h */ -#include "gtkutils.h" -#include "license.h" /* gnu_license_dialog() */ /* Show about dialog box */ -void about(GtkWidget *widget, gpointer data) { - GtkWidget *window; - GtkWidget *vbox, *hbox, *buttons_box, *ok_button; - GtkWidget *pixmap; - gchar strbuf[1024]; +void about (GtkWidget *widget, gpointer data) +{ + GtkWidget * w; + GdkPixbuf * logo; + const gchar * authors[] = + { + "Eugene Morozov ", + "drF_ckoff ", + NULL + }; + /* TRANSLATORS: Replace this string with your names, one name per line. */ + gchar * translators = _("Translated by"); - window = ut_window_new(_("About"), "GtkBalls_About", "GtkBalls", TRUE, TRUE, FALSE, 5); + logo = gdk_pixbuf_new_from_file (DATADIR "/gtkballs/gtkballs-logo.png", NULL); - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(window), vbox); + w = g_object_new (GTK_TYPE_ABOUT_DIALOG, + "version", VERSION, + "program-name", "GtkBalls", + "copyright", "Copyright (C) 1998-2021", + "comments", "Clone of Lines - logic game about balls", + "license", "This program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.", + "website", "https://github.com/emorozov/gtkballs", + "authors", authors, + "logo", logo, + "translator-credits", translators, + NULL); + if (logo) { + g_object_unref (logo); + } + gtk_container_set_border_width (GTK_CONTAINER (w), 2); + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (main_window)); + gtk_window_set_modal (GTK_WINDOW (w), TRUE); + gtk_window_set_position (GTK_WINDOW (w), GTK_WIN_POS_CENTER_ON_PARENT); - hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - - pixmap = gtk_image_new_from_file(DATADIR "/gtkballs/gtkballs-logo.png"); - gtk_box_pack_start(GTK_BOX(hbox), pixmap, TRUE, TRUE, 4); - - g_snprintf(strbuf, sizeof(strbuf), _("GtkBalls %s\n" \ - "Copyright (C) 2001-2002 drF_ckoff \n" \ - "Copyright (C) 1998-1999 Eugene Morozov\n" \ - ", \n\n" \ - "GtkBalls comes with ABSOLUTELY NO WARRANTY;\n" \ - "for details press \"Show license\" button.\n" \ - "This is free software and you are welcome to\n" \ - "redistribute it under certain conditions;\n" \ - "press \"Show license\" button for details."), VERSION); - gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(strbuf), TRUE, TRUE, 2); - gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 5); - - buttons_box = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(vbox), buttons_box, TRUE, TRUE, 2); - gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_box), GTK_BUTTONBOX_SPREAD); - - ok_button = ut_button_new_stock_swap(GTK_STOCK_CLOSE, gtk_widget_destroy, window, buttons_box); - ut_button_new(_("Show license"), gnu_license_dialog, window, buttons_box); - gtk_widget_grab_default(ok_button); - gtk_widget_show_all(window); + g_signal_connect_swapped (w, "response", + G_CALLBACK (gtk_widget_destroy), w); + gtk_widget_show_all (GTK_WIDGET (w)); } diff --git a/src/gtkballs.h b/src/gtkballs.h index d8913c8..68ada3a 100644 --- a/src/gtkballs.h +++ b/src/gtkballs.h @@ -3,6 +3,8 @@ #include +extern GtkWindow * main_window; + #ifdef ENABLE_NLS # include # include diff --git a/src/license.c b/src/license.c deleted file mode 100644 index 62e2bc2..0000000 --- a/src/license.c +++ /dev/null @@ -1,84 +0,0 @@ -/* license.c - display dialog box with GNU GPL. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - */ -#include -#include /* stat() */ -#include /* stat() */ -#include /* stat() */ -#include /* open() */ - -#include "gtkballs.h" /* _() */ -#include "gtkutils.h" - -void gnu_license_dialog(gpointer data) { - GtkWidget *window; - GtkWidget *swindow; - GtkWidget *vbox,*hbox,*button_box; - GtkWidget *license; - GtkTextBuffer *buffer; - GtkTextIter iter; - GtkWidget *separator; - GtkWidget *ok_button; - struct stat buf; - int fd; - gchar *license_buf; - gchar *license_file=DATADIR "/gtkballs/COPYING"; - - if(stat(license_file, &buf)<0) { - ut_simple_message_box(_("Can't stat license file")); - return; - } - - license_buf=(gchar *)g_malloc(buf.st_size+1); - if((fd=open(license_file, O_RDONLY))<0) { - ut_simple_message_box(_("Can't open license file")); - g_free(license_buf); - return; - } - read(fd, license_buf, buf.st_size); - license_buf[buf.st_size]='\0'; - close(fd); - - window=ut_window_new(_("GNU Public License"), "GtkBalls_License", "GtkBalls", TRUE, TRUE, TRUE, 5); - - vbox=gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); - gtk_container_add(GTK_CONTAINER(window), vbox); - - hbox=gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - - swindow=gtk_scrolled_window_new(NULL, NULL); - gtk_widget_set_size_request(swindow, -1, 250); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swindow), GTK_SHADOW_ETCHED_IN); - gtk_box_pack_start(GTK_BOX(hbox), swindow, TRUE, TRUE, 0); - - license=gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(license), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(license), FALSE); - gtk_container_add(GTK_CONTAINER(swindow), license); - - buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(license)); - gtk_text_buffer_insert_at_cursor(buffer, license_buf, -1); - g_free(license_buf); - - gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0); - gtk_text_buffer_place_cursor(buffer, &iter); - - separator=gtk_hseparator_new(); - gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 5); - - button_box=gtk_hbox_new(TRUE, 0); - gtk_box_pack_start(GTK_BOX(vbox), button_box, FALSE, TRUE, 0); - - ok_button=ut_button_new_stock_swap(GTK_STOCK_CLOSE, gtk_widget_destroy, window, button_box); - - gtk_widget_grab_default(ok_button); - gtk_widget_grab_focus(ok_button); - gtk_widget_show_all(window); -} diff --git a/src/license.h b/src/license.h deleted file mode 100644 index aacd2dd..0000000 --- a/src/license.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __LICENSE_H -#define __LICENSE_H - -void gnu_license_dialog(gpointer data); - -#endif /* __LICENSE_H */ diff --git a/src/mainwin.c b/src/mainwin.c index 4ffe7ae..72dd6f2 100644 --- a/src/mainwin.c +++ b/src/mainwin.c @@ -16,6 +16,8 @@ #include "game.h" #include "child.h" +GtkWindow * main_window; + /* Score labels */ GtkWidget *_hi_score_label = NULL; GtkWidget *_user_score_label = NULL; @@ -136,7 +138,7 @@ gint _user_action_event(GtkWidget *w, GdkEvent *ev) { } void mw_create(gint da_width, gint da_height) { - GtkWidget *mainwin; + GtkWidget *mainwin; GtkWidget *menubar; GtkWidget *vbox, *hbox, *hbox1, *drawing_area_box; GtkWidget *timer_label; @@ -144,6 +146,7 @@ void mw_create(gint da_width, gint da_height) { GError *error=NULL; mainwin = ut_window_new(_("GtkBalls"), "GtkBalls_Main", "GtkBalls", FALSE, FALSE, FALSE, 0); + main_window = GTK_WINDOW (mainwin); g_signal_connect(G_OBJECT(mainwin), "destroy", G_CALLBACK(gtk_main_quit), mainwin); icon = gdk_pixbuf_new_from_file(DATADIR "/gtkballs/gtkballs_16x16.png", &error);