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
This commit is contained in:
wdlkmpx 2021-01-09 07:09:42 +08:00
parent fd260a5be5
commit accf503afb
7 changed files with 41 additions and 131 deletions

2
configure.ac vendored
View File

@ -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)

View File

@ -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 \

View File

@ -6,47 +6,44 @@
* version 2 of the License, or (at your option) any later version.
*/
#include <gtk/gtk.h>
#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 <jmv@online.ru>",
"drF_ckoff <dfo@antex.ru>",
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 <dfo@antex.ru>\n" \
"Copyright (C) 1998-1999 Eugene Morozov\n" \
"<jmv@online.ru>, <roshiajin@yahoo.com>\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));
}

View File

@ -3,6 +3,8 @@
#include <config.h>
extern GtkWindow * main_window;
#ifdef ENABLE_NLS
# include <locale.h>
# include <libintl.h>

View File

@ -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 <gtk/gtk.h>
#include <sys/types.h> /* stat() */
#include <sys/stat.h> /* stat() */
#include <unistd.h> /* stat() */
#include <fcntl.h> /* 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);
}

View File

@ -1,6 +0,0 @@
#ifndef __LICENSE_H
#define __LICENSE_H
void gnu_license_dialog(gpointer data);
#endif /* __LICENSE_H */

View File

@ -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);