From 76ff1a2a499ebb7b6ec4a2474eb21d8a1b22a646 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 4 Jun 2020 10:19:44 -0400 Subject: [PATCH] gtk-demo: Drop the awards This was a neat idea, but maintaining it at a sufficient level is too much work. --- demos/gtk-demo/award.c | 247 ------------------------------ demos/gtk-demo/award.h | 18 --- demos/gtk-demo/awardlistitem.ui | 18 --- demos/gtk-demo/awards.ui | 89 ----------- demos/gtk-demo/awardview.c | 48 ------ demos/gtk-demo/demo.gresource.xml | 5 - demos/gtk-demo/listbox.c | 4 - demos/gtk-demo/main.c | 4 - demos/gtk-demo/meson.build | 2 - demos/gtk-demo/password_entry.c | 6 - demos/gtk-demo/sliding_puzzle.c | 13 -- 11 files changed, 454 deletions(-) delete mode 100644 demos/gtk-demo/award.c delete mode 100644 demos/gtk-demo/award.h delete mode 100644 demos/gtk-demo/awardlistitem.ui delete mode 100644 demos/gtk-demo/awards.ui delete mode 100644 demos/gtk-demo/awardview.c diff --git a/demos/gtk-demo/award.c b/demos/gtk-demo/award.c deleted file mode 100644 index 389bfc6790..0000000000 --- a/demos/gtk-demo/award.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright © 2018 Benjamin Otte - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Authors: Benjamin Otte - */ - -#include "award.h" - -struct _GtkAward -{ - GObject parent; - - char *explanation; - char *name; - char *title; - GDateTime *granted; /* or NULL if not granted */ -}; - -enum { - PROP_0, - PROP_EXPLANATION, - PROP_NAME, - PROP_TITLE, - PROP_GRANTED, - - N_PROPS, -}; - -static GParamSpec *properties[N_PROPS] = { NULL, }; - -G_DEFINE_TYPE (GtkAward, gtk_award, G_TYPE_OBJECT) - -static void -gtk_award_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) - -{ - GtkAward *self = GTK_AWARD (object); - - switch (prop_id) - { - case PROP_EXPLANATION: - self->explanation = g_value_dup_string (value); - break; - - case PROP_NAME: - self->name = g_value_dup_string (value); - break; - - case PROP_TITLE: - self->title = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gtk_award_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GtkAward *self = GTK_AWARD (object); - - switch (prop_id) - { - case PROP_EXPLANATION: - g_value_set_string (value, self->explanation); - break; - - case PROP_NAME: - g_value_set_string (value, self->name); - break; - - case PROP_TITLE: - g_value_set_string (value, self->title); - break; - - case PROP_GRANTED: - g_value_set_boxed (value, self->granted); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gtk_award_dispose (GObject *object) -{ - GtkAward *self = GTK_AWARD (object); - - g_clear_pointer (&self->name, g_free); - g_clear_pointer (&self->title, g_free); - g_clear_pointer (&self->granted, g_date_time_unref); - - G_OBJECT_CLASS (gtk_award_parent_class)->dispose (object); -} - -static void -gtk_award_class_init (GtkAwardClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - - gobject_class->set_property = gtk_award_set_property; - gobject_class->get_property = gtk_award_get_property; - gobject_class->dispose = gtk_award_dispose; - - properties[PROP_EXPLANATION] = - g_param_spec_string ("explanation", - "Explanation", - "How to get the title", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - properties[PROP_NAME] = - g_param_spec_string ("name", - "Name", - "internal name of the award", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - properties[PROP_TITLE] = - g_param_spec_string ("title", - "Title", - "user-visible title", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - properties[PROP_GRANTED] = - g_param_spec_boxed ("granted", - "Granted", - "Timestamp the award was granted or NULL if not granted yet", - G_TYPE_DATE_TIME, - G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (gobject_class, N_PROPS, properties); -} - -static void -gtk_award_init (GtkAward *self) -{ -} - -GListModel * -gtk_award_get_list (void) -{ - static GListModel *list = NULL; - - if (list == NULL) - { - GtkBuilder *builder; - - g_type_ensure (GTK_TYPE_AWARD); - builder = gtk_builder_new_from_resource ("/awards.ui"); - list = G_LIST_MODEL (gtk_builder_get_object (builder, "list")); - g_object_ref (list); - g_object_unref (builder); - } - - return g_object_ref (list); -} - -const char * -gtk_award_get_name (GtkAward *award) -{ - return award->name; -} - -const char * -gtk_award_get_title (GtkAward *award) -{ - return award->title; -} - -GDateTime * -gtk_award_get_granted (GtkAward *award) -{ - return award->granted; -} - -GtkAward * -award_find (const char *name) -{ - GListModel *list; - GtkAward *self; - guint i; - - list = gtk_award_get_list (); - g_object_unref (list); - - for (i = 0; i < g_list_model_get_n_items (list); i++) - { - self = g_list_model_get_item (list, i); - g_object_unref (self); - - if (g_ascii_strcasecmp (name, self->name) == 0) - return self; - } - - return NULL; -} - -void -award (const char *name) -{ - GtkAward *self; - GNotification *notification; - - self = award_find (name); - if (self == NULL) - { - g_warning ("Did not find award \"%s\"", name); - return; - } - - if (self->granted) - return; - - self->granted = g_date_time_new_now_utc (); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_GRANTED]); - - notification = g_notification_new ("You won an award!"); - g_notification_set_body (notification, self->title); - g_application_send_notification (g_application_get_default (), NULL, notification); - g_object_unref (notification); -} - diff --git a/demos/gtk-demo/award.h b/demos/gtk-demo/award.h deleted file mode 100644 index 0c4cca01f2..0000000000 --- a/demos/gtk-demo/award.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __AWARD_H__ -#define __AWARD_H__ - -#include - -#define GTK_TYPE_AWARD (gtk_award_get_type ()) - -G_DECLARE_FINAL_TYPE (GtkAward, gtk_award, GTK, AWARD, GObject) - -GListModel * gtk_award_get_list (void); - -const char * gtk_award_get_name (GtkAward *award); -const char * gtk_award_get_title (GtkAward *award); -GDateTime * gtk_award_get_granted (GtkAward *award); - -void award (const char *name); - -#endif /* __AWARD_H__ */ diff --git a/demos/gtk-demo/awardlistitem.ui b/demos/gtk-demo/awardlistitem.ui deleted file mode 100644 index 3627877cdd..0000000000 --- a/demos/gtk-demo/awardlistitem.ui +++ /dev/null @@ -1,18 +0,0 @@ - - - - diff --git a/demos/gtk-demo/awards.ui b/demos/gtk-demo/awards.ui deleted file mode 100644 index 5979c9253a..0000000000 --- a/demos/gtk-demo/awards.ui +++ /dev/null @@ -1,89 +0,0 @@ - - - - GtkAward - - - demo-inspector - - You got a high-rise double-pump carburetor. - Launch the inspector - - - - - demo-start - - After this, there is no turning back. - Start gtk-demo - - - - - - listbox-reshare - - Trying to make fetch happen - Reshare a tweet - - - - - listbox-100th-row - - The ever impressive, long contained, often imitated, but never duplicated Genie of the lamp. - Select a 100th row in a list - - - - - - password-best - - I've got the same combination on my luggage! - Use "12345" as the password - - - - - password-correct - - Night Shark 1-1-5 - Correctly enter a password - - - - - - puzzle-give-up - - Big Mistake. Big. Huge! - Close the puzzle without finishing it - - - - - puzzle-solve - - That was totally wicked! - Solve a puzzle - - - - - puzzle-solve-animated - - A surprise to be sure but a welcome one. - Solve an animated puzzle - - - - - puzzle-solve-large - - Science isn't about WHY. It's about WHY NOT?! - Solve a puzzle with at least 20 pieces - - - - diff --git a/demos/gtk-demo/awardview.c b/demos/gtk-demo/awardview.c deleted file mode 100644 index 30831c9d56..0000000000 --- a/demos/gtk-demo/awardview.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Awards - * - * This demo demonstrates how to use lists to show the awards you have collected - * while exploring this demo. - * - */ - -#include - -/* Include the header for accessing the awards */ -#include "award.h" - -static GtkWidget *window = NULL; - -GtkWidget * -do_awardview (GtkWidget *do_widget) -{ - if (!window) - { - GtkWidget *sw, *listview; - GListModel *list; - - window = gtk_window_new (); - gtk_window_set_display (GTK_WINDOW (window), - gtk_widget_get_display (do_widget)); - gtk_window_set_title (GTK_WINDOW (window), "Awards"); - gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); - g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_window_set_child (GTK_WINDOW (window), sw); - - listview = gtk_list_view_new_with_factory ( - gtk_builder_list_item_factory_new_from_resource (NULL, "/awardview/awardlistitem.ui")); - list = gtk_award_get_list (); - gtk_list_view_set_model (GTK_LIST_VIEW (listview), list); - g_object_unref (list); - gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE); - gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview); - } - - if (!gtk_widget_get_visible (window)) - gtk_widget_show (window); - else - gtk_window_destroy (GTK_WINDOW (window)); - - return window; -} diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml index e1c2998b46..fc0c1465a4 100644 --- a/demos/gtk-demo/demo.gresource.xml +++ b/demos/gtk-demo/demo.gresource.xml @@ -1,7 +1,6 @@ - awards.ui main.ui @@ -12,9 +11,6 @@ application.ui menus.ui - - awardlistitem.ui - demo.ui @@ -178,7 +174,6 @@ application_demo.c - awardview.c assistant.c builder.c clipboard.c diff --git a/demos/gtk-demo/listbox.c b/demos/gtk-demo/listbox.c index 1f56ff9faa..b390218dfe 100644 --- a/demos/gtk-demo/listbox.c +++ b/demos/gtk-demo/listbox.c @@ -8,7 +8,6 @@ #include #include #include -#include "award.h" static GdkPixbuf *avatar_pixbuf_other; static GtkWidget *window = NULL; @@ -235,7 +234,6 @@ reshare_clicked (GtkMessageRow *row, { GtkMessageRowPrivate *priv = row->priv; - award ("listbox-reshare"); priv->message->n_reshares++; gtk_message_row_update (row); } @@ -262,8 +260,6 @@ gtk_message_row_state_flags_changed (GtkWidget *widget, visible = flags & (GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED) ? TRUE : FALSE; gtk_widget_set_visible (priv->extra_buttons_box, visible); - if (visible && gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (widget)) % 100 == 99) - award ("listbox-100th-row"); GTK_WIDGET_CLASS (gtk_message_row_parent_class)->state_flags_changed (widget, previous_state_flags); } diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c index 28a05167d5..f9ea82c9cd 100644 --- a/demos/gtk-demo/main.c +++ b/demos/gtk-demo/main.c @@ -8,7 +8,6 @@ #include #include -#include "award.h" #include "demos.h" static GtkWidget *info_view; @@ -213,7 +212,6 @@ activate_inspector (GSimpleAction *action, gpointer user_data) { gtk_window_set_interactive_debugging (TRUE); - award ("demo-inspector"); } static void @@ -1051,8 +1049,6 @@ activate (GApplication *app) gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection)); - award ("demo-start"); - g_object_unref (builder); } diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build index 011bbf8787..1a9ee4aee0 100644 --- a/demos/gtk-demo/meson.build +++ b/demos/gtk-demo/meson.build @@ -3,7 +3,6 @@ demos = files([ 'application_demo.c', 'assistant.c', - 'awardview.c', 'builder.c', 'clipboard.c', 'combobox.c', @@ -92,7 +91,6 @@ demos = files([ gtkdemo_deps = [ libgtk_dep, ] extra_demo_sources = files(['main.c', - 'award.c', 'gtkfishbowl.c', 'fontplane.c', 'gtkgears.c', diff --git a/demos/gtk-demo/password_entry.c b/demos/gtk-demo/password_entry.c index 3f5b28539a..62ffb7897f 100644 --- a/demos/gtk-demo/password_entry.c +++ b/demos/gtk-demo/password_entry.c @@ -11,7 +11,6 @@ #include #include -#include "award.h" static GtkWidget *entry; static GtkWidget *entry2; @@ -27,17 +26,12 @@ update_button (GObject *object, gtk_widget_set_sensitive (button, text[0] != '\0' && g_str_equal (text, text2)); - - if (g_str_equal (text, text2) && - g_ascii_strcasecmp (text, "12345") == 0) - award ("password-best"); } static void button_pressed (GtkButton *widget, GtkWidget *window) { - award ("password-correct"); gtk_window_destroy (GTK_WINDOW (window)); } diff --git a/demos/gtk-demo/sliding_puzzle.c b/demos/gtk-demo/sliding_puzzle.c index c7897f2dfd..28f98eaea2 100644 --- a/demos/gtk-demo/sliding_puzzle.c +++ b/demos/gtk-demo/sliding_puzzle.c @@ -11,8 +11,6 @@ #include "puzzlepiece.h" #include "paintable.h" -/* Give out awards */ -#include "award.h" static GtkWidget *window = NULL; static GtkWidget *frame = NULL; @@ -159,14 +157,6 @@ check_solved (GtkWidget *grid) picture = gtk_grid_get_child_at (GTK_GRID (grid), pos_x, pos_y); gtk_picture_set_paintable (GTK_PICTURE (picture), piece); - /* Hand out a bunch of awards - */ - award ("puzzle-solve"); - if ((gdk_paintable_get_flags (piece) & GDK_PAINTABLE_STATIC_CONTENTS) == 0) - award ("puzzle-solve-animated"); - if (height * width > 20) - award ("puzzle-solve-large"); - return TRUE; } @@ -416,9 +406,6 @@ widget_destroyed (gpointer data, { if (data) *(gpointer *) data = NULL; - - if (!solved) - award ("puzzle-give-up"); }