[five-or-more] Use libgnome-games-support
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more] Use libgnome-games-support
- Date: Wed, 21 Mar 2018 01:55:17 +0000 (UTC)
commit 231da2d15f92ba638307291bf55e2331ffd75770
Author: Ruxandra Simion <ruxandra simion93 gmail com>
Date: Tue Mar 20 14:26:55 2018 +0200
Use libgnome-games-support
configure.ac | 1 +
meson.build | 3 +-
po/POTFILES.in | 1 -
src/Makefile.am | 8 -
src/five-or-more-app.c | 110 +++++++---
src/five-or-more-app.h | 5 +-
src/five-or-more.c | 1 -
src/game-area.c | 11 +-
src/games-gridframe.c | 276 ------------------------
src/games-gridframe.h | 61 ------
src/games-score.c | 164 --------------
src/games-score.h | 66 ------
src/games-scores-backend.c | 339 -----------------------------
src/games-scores-backend.h | 61 ------
src/games-scores-dialog.c | 507 --------------------------------------------
src/games-scores-dialog.h | 80 -------
src/games-scores.c | 445 --------------------------------------
src/games-scores.h | 89 --------
src/meson.build | 19 +--
19 files changed, 90 insertions(+), 2157 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 37ce8d7..f33c9fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,7 @@ PKG_CHECK_MODULES(FIVE_OR_MORE, [
glib-2.0 >= $GLIB_REQUIRED
gio-2.0 >= $GLIB_REQUIRED
gtk+-3.0 >= $GTK_REQUIRED
+ libgnome-games-support-1
librsvg-2.0 >= $RSVG_REQUIRED
])
diff --git a/meson.build b/meson.build
index e704fb9..14d9d3c 100644
--- a/meson.build
+++ b/meson.build
@@ -15,11 +15,12 @@ pkgdata_dir = join_paths (data_dir, 'five-or-more')
# Dependencies
glib_min_version = '2.32'
-librsvg = dependency('librsvg-2.0', version: '>= 2.32.0')
gio = dependency('gio-2.0', version: '>= ' + glib_min_version)
glib = dependency('glib-2.0', version: '>= ' + glib_min_version)
gmodule_export = dependency('gmodule-export-2.0')
gtk = dependency('gtk+-3.0', version: '>= 3.20.0')
+libgnome_games_support = dependency('libgnome-games-support-1')
+librsvg = dependency('librsvg-2.0', version: '>= 2.32.0')
# Libraries
cc = meson.get_compiler('c')
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 980c576..8f10122 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,7 +8,6 @@ data/menu.ui
data/org.gnome.five-or-more.gschema.xml
data/translatable_themes.h
src/five-or-more.c
-src/games-scores-dialog.c
src/five-or-more-app.c
src/game-area.c
src/balls-preview.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 79d7d95..8bd07fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,14 +8,6 @@ five_or_more_SOURCES = \
games-gridframe.h \
games-preimage.c \
games-preimage.h \
- games-score.h \
- games-score.c \
- games-scores.c \
- games-scores.h \
- games-scores-dialog.c \
- games-scores-dialog.h \
- games-scores-backend.c \
- games-scores-backend.h \
five-or-more-app.h \
five-or-more-app.c \
balls-preview.c \
diff --git a/src/five-or-more-app.c b/src/five-or-more-app.c
index 8c94ddc..839c95f 100644
--- a/src/five-or-more-app.c
+++ b/src/five-or-more-app.c
@@ -33,12 +33,10 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
+#include <libgnome-games-support.h>
#include "games-file-list.h"
#include "games-preimage.h"
-#include "games-gridframe.h"
-#include "games-scores.h"
-#include "games-scores-dialog.h"
#include "game-area.h"
#include "five-or-more-app.h"
#include "balls-preview.h"
@@ -50,7 +48,12 @@
#define KEY_BACKGROUND_COLOR "background-color"
#define KEY_BALL_THEME "ball-theme"
-static const GamesScoresCategory scorecats[] = {
+typedef struct {
+ gchar *key;
+ gchar *name;
+} key_value;
+
+static const key_value scorecats[] = {
{ "Small", NC_("board size", "Small") },
{ "Medium", NC_("board size", "Medium") },
{ "Large", NC_("board size", "Large") }
@@ -77,7 +80,11 @@ static GtkWidget *size_radio_s, *size_radio_m, *size_radio_l;
static int move_timeout = 100;
static gboolean window_is_fullscreen = FALSE, window_is_maximized = FALSE;
static gint window_width = 0, window_height = 0;
-static GamesScores *highscores;
+
+static gint no_categories = 3;
+static gchar *score_current_category = NULL;
+static GamesScoresContext *highscores;
+
static GSettings *settings;
static GtkBuilder *builder;
static GtkBuilder *builder_preferences;
@@ -93,12 +100,6 @@ get_settings ()
return &settings;
}
-const GamesScoresCategory *
-get_scorecats ()
-{
- return scorecats;
-}
-
gint *
get_game_size ()
{
@@ -129,12 +130,6 @@ get_move_timeout ()
return move_timeout;
}
-GamesScores *
-get_highscores()
-{
- return highscores;
-}
-
void
update_score (guint value)
{
@@ -170,9 +165,11 @@ set_backgnd_color (const gchar * str)
}
static void
-show_scores (gint pos)
+show_scores ()
{
- static GtkWidget *dialog;
+ games_scores_context_run_dialog (highscores);
+
+/* static GtkWidget *dialog;
if (dialog == NULL) {
dialog = games_scores_dialog_new (GTK_WINDOW (app), highscores, _("Five or More Scores"));
@@ -186,7 +183,7 @@ show_scores (gint pos)
gtk_window_present (GTK_WINDOW (dialog));
gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_hide (dialog);
+ gtk_widget_hide (dialog);*/
}
static void
@@ -205,15 +202,46 @@ load_properties (void)
load_theme ();
}
+static void
+add_score_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ GamesScoresContext *context = GAMES_SCORES_CONTEXT (source_object);
+ GError *error = NULL;
+
+ games_scores_context_add_score_finish (context, res, &error);
+ if (error != NULL) {
+ g_warning ("Failed to add score: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+const gchar *
+category_name_from_key (const gchar *key)
+{
+ int i;
+ for (i = 0; i < no_categories; i++) {
+ if (g_strcmp0 (scorecats[i].key, key) == 0)
+ return scorecats[i].name;
+ }
+ return NULL;
+}
+
void
game_over (void)
{
- int pos;
set_status_message (_("Game Over!"));
- if (score > 0)
- pos = games_scores_add_plain_score (highscores, score);
- show_scores (pos);
+ if (score > 0) {
+ const gchar *name = category_name_from_key (score_current_category);
+ GamesScoresCategory *current_category = games_scores_category_new (score_current_category, name);
+ games_scores_context_add_score (highscores,
+ score,
+ current_category,
+ NULL,
+ add_score_cb,
+ NULL);
+ }
+ show_scores ();
}
static void
@@ -263,6 +291,8 @@ conf_value_changed_cb (GSettings *settings, gchar *key)
if (size_tmp != game_size) {
set_sizes (size_tmp);
+ score_current_category = scorecats[size_tmp - 1].key;
+
reset_game ();
start_game ();
}
@@ -282,6 +312,7 @@ init_config (void)
game_size = CLAMP (game_size, SMALL, MAX_SIZE - 1);
set_sizes (game_size);
+ score_current_category = scorecats[game_size - 1].key;
}
static gboolean
@@ -318,7 +349,7 @@ game_top_ten_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- show_scores (0);
+ show_scores ();
}
@@ -561,6 +592,16 @@ game_quit_callback (GSimpleAction *action,
g_application_quit (G_APPLICATION (user_data));
}
+static GamesScoresCategory *
+create_category_from_key (const char *key, gpointer user_data)
+{
+ const gchar *name = category_name_from_key (key);
+ if (name == NULL)
+ return NULL;
+
+ return games_scores_category_new (key, name);
+}
+
void
startup_cb (GApplication *application)
{
@@ -570,6 +611,7 @@ startup_cb (GApplication *application)
GtkWidget *new_game_button;
guint i;
GError *error = NULL;
+ GamesScoresDirectoryImporter *importer;
GActionEntry app_actions[] = {
{ "new-game", game_new_callback },
@@ -588,11 +630,6 @@ startup_cb (GApplication *application)
settings = g_settings_new ("org.gnome.five-or-more");
- highscores = games_scores_new ("five-or-more",
- scorecats, G_N_ELEMENTS (scorecats),
- "board size", NULL,
- 0 /* default category */,
- GAMES_SCORES_STYLE_PLAIN_DESCENDING);
init_config ();
builder = gtk_builder_new ();
ui_path = g_build_filename (DATA_DIRECTORY, "menu.ui", NULL);
@@ -644,13 +681,22 @@ startup_cb (GApplication *application)
GtkWidget *draw_area = game_area_init ();
- gridframe = games_grid_frame_new (get_hfieldsize(), get_vfieldsize());
+ gridframe = GTK_WIDGET (games_grid_frame_new (get_hfieldsize(), get_vfieldsize()));
games_grid_frame_set_padding (GAMES_GRID_FRAME (gridframe), 1, 1);
gtk_container_add (GTK_CONTAINER (gridframe), draw_area);
gtk_box_pack_start (GTK_BOX (hbox), gridframe, TRUE, TRUE, 0);
new_game_button = GTK_WIDGET (gtk_builder_get_object (builder, "new_game_button"));
+ importer = games_scores_directory_importer_new ();
+ highscores = games_scores_context_new_with_importer ("five-or-more",
+ _("Board Size: "),
+ GTK_WINDOW (app),
+ create_category_from_key,
+ NULL,
+ GAMES_SCORES_STYLE_POINTS_GREATER_IS_BETTER,
+ GAMES_SCORES_IMPORTER (importer));
+
load_properties ();
gtk_builder_connect_signals (builder, NULL);
@@ -692,4 +738,4 @@ set_application_callbacks(GtkApplication *application)
g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
g_signal_connect (application, "shutdown", G_CALLBACK (shutdown_cb), NULL);
-}
\ No newline at end of file
+}
diff --git a/src/five-or-more-app.h b/src/five-or-more-app.h
index 6e9a6b6..6f853f7 100644
--- a/src/five-or-more-app.h
+++ b/src/five-or-more-app.h
@@ -24,7 +24,6 @@
#define FIVE_OR_MORE_APP_H
#include <gtk/gtk.h>
-#include "games-scores.h"
typedef struct _background background;
struct _background{
@@ -33,7 +32,6 @@ struct _background{
gint set;
} ;
-GamesScores *get_highscores ();
GtkWidget *get_gridframe ();
char *get_ball_filename ();
background get_backgnd ();
@@ -41,11 +39,10 @@ void set_status_message (gchar * message);
void game_over (void);
void set_application_callbacks (GtkApplication *application);
gint *get_game_size ();
-const GamesScoresCategory *get_scorecats ();
GSettings **get_settings ();
int get_move_timeout ();
void game_props_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void update_score (guint value);
-#endif
\ No newline at end of file
+#endif
diff --git a/src/five-or-more.c b/src/five-or-more.c
index cc9e1fe..4a68b11 100644
--- a/src/five-or-more.c
+++ b/src/five-or-more.c
@@ -51,7 +51,6 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- games_scores_startup ();
GRand **rgen = get_rgen();
*rgen = g_rand_new ();
diff --git a/src/game-area.c b/src/game-area.c
index 7a3043b..d4c70f4 100644
--- a/src/game-area.c
+++ b/src/game-area.c
@@ -33,8 +33,8 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
+#include <libgnome-games-support.h>
-#include "games-gridframe.h"
#include "game-area.h"
#include "five-or-more-app.h"
#include "balls-preview.h"
@@ -82,8 +82,7 @@ static const gint field_sizes[MAX_SIZE][4] = {
};
static scoretable sctab[] =
- { {5, 10}, {6, 12}, {7, 18}, {8, 28}, {9, 42}, {10, 82}, {11, 108}, {12,
- 138},
+ { {5, 10}, {6, 12}, {7, 18}, {8, 28}, {9, 42}, {10, 82}, {11, 108}, {12, 138},
{13, 172}, {14, 210}, {0, 0} };
static gchar *warning_message = NULL;
@@ -98,8 +97,6 @@ set_sizes (gint size)
npieces = field_sizes[size][3];
gint *game_size = get_game_size();
*game_size = size;
- GamesScoresCategory *scorecats = get_scorecats();
- games_scores_set_category (get_highscores(), scorecats[size - 1].key);
g_settings_set_int (*(get_settings()), KEY_SIZE, size);
GtkWidget *gridframe = get_gridframe();
@@ -321,7 +318,6 @@ check_gameover (void)
static int
addscore (int num)
{
- gchar string[20];
int i = 0;
int retval;
@@ -670,7 +666,6 @@ cell_clicked (GtkWidget * widget, int fx, int fy)
static gint
button_press_event (GtkWidget * widget, GdkEvent * event)
{
- int x, y;
int fx, fy;
if (inmove)
@@ -1054,4 +1049,4 @@ game_area_init (void)
gtk_widget_set_can_focus (draw_area, TRUE);
gtk_widget_grab_focus (draw_area);
return draw_area;
-}
\ No newline at end of file
+}
diff --git a/src/meson.build b/src/meson.build
index 190d20a..441eb86 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -10,18 +10,8 @@ five_or_more_c_sources = [
'balls-preview.h',
'games-file-list.c',
'games-file-list.h',
- 'games-gridframe.c',
- 'games-gridframe.h',
'games-preimage.c',
- 'games-preimage.h',
- 'games-score.c',
- 'games-score.h',
- 'games-scores-backend.c',
- 'games-scores-backend.h',
- 'games-scores-dialog.c',
- 'games-scores-dialog.h',
- 'games-scores.c',
- 'games-scores.h'
+ 'games-preimage.h'
]
five_or_more_sources = [
@@ -29,11 +19,12 @@ five_or_more_sources = [
]
five_or_more_deps = [
- libmath,
- librsvg,
glib,
gio,
- gtk
+ gtk,
+ libgnome_games_support,
+ libmath,
+ librsvg
]
five_or_more_includes = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]