grim/pidgin-credits

c62bdb1984a7
Parents 4a7ea62ed90c
Children 0dca13a8ca1f
kind of almost working, jsonglib is weird...
  • +109 -3
    credits.c
  • +3 -0
    credits.json
  • --- a/credits.c Tue Jun 14 23:28:40 2016 -0500
    +++ b/credits.c Wed Jun 15 00:06:58 2016 -0500
    @@ -1,9 +1,109 @@
    #include <gtk/gtk.h>
    +#include <json-glib/json-glib.h>
    +
    +#include "resources.h"
    +
    +enum {
    + COL_NAME = 0,
    + N_COLS
    +};
    +
    +static void
    +load_store(GtkTreeStore *store) {
    + JsonNode *root_node = NULL, *contributors_node = NULL;
    + JsonObject *root_obj = NULL;
    + JsonObjectIter root_iter;
    + JsonParser *parser = NULL;
    + GError *error = NULL;
    + GResource *res = NULL;
    + GInputStream *istream = NULL;
    + const gchar *section_name = NULL;
    +
    + parser = json_parser_new();
    +
    + res = resources_get_resource();
    + istream = g_resource_open_stream(
    + res,
    + "/com/reaperworld/gtkcredits/credits.json",
    + G_RESOURCE_LOOKUP_FLAGS_NONE,
    + &error
    + );
    + if(error != NULL) {
    + g_error(error->message);
    + }
    +
    + json_parser_load_from_stream(parser, istream, NULL, &error);
    + if(error != NULL) {
    + g_error(error->message);
    + }
    +
    + root_node = json_parser_get_root(parser);
    + root_obj = json_node_get_object(root_node);
    +
    + json_object_iter_init(&root_iter, root_obj);
    + while(json_object_iter_next(&root_iter, &section_name, &contributors_node)) {
    + GtkTreeIter section_iter;
    + JsonNode *contributor_node = NULL;
    + JsonObject *contributors = NULL;
    + JsonObjectIter contributor_iter;
    +
    + gtk_tree_store_append(store, &section_iter, NULL);
    + gtk_tree_store_set(
    + store, &section_iter,
    + COL_NAME, section_name,
    + -1
    + );
    +
    + contributors = json_node_get_object(contributors_node);
    + json_object_iter_init(&contributor_iter, contributors);
    + while(json_object_iter_next(&contributor_iter, NULL, &contributor_node)) {
    + JsonObject *contributor = json_node_get_object(contributor_node);
    + GtkTreeIter person_iter;
    +
    + gtk_tree_store_append(store, &person_iter, &section_iter);
    + gtk_tree_store_set(
    + store, &person_iter,
    + COL_NAME, json_object_get_member(contributor, "name"),
    + -1
    + );
    + }
    + }
    +
    + g_object_unref(parser);
    +}
    +
    +static GtkTreeStore *
    +build_store(void) {
    + GtkTreeStore *store = NULL;
    +
    + store = gtk_tree_store_new(N_COLS, G_TYPE_STRING);
    +
    + load_store(store);
    +
    + return store;
    +}
    +
    +static GtkWidget *
    +build_treeview(void) {
    + GtkWidget *tree = NULL;
    + GtkTreeViewColumn *col = NULL;
    + GtkCellRenderer *rend = NULL;
    +
    + tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(build_store()));
    + col = gtk_tree_view_column_new();
    + gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col);
    +
    + rend = gtk_cell_renderer_text_new();
    + gtk_tree_view_column_pack_start(col, rend, TRUE);
    + gtk_tree_view_column_add_attribute(col, rend, "text", COL_NAME);
    +
    + return tree;
    +}
    +
    static void
    build_window(void) {
    - GtkWidget *win = NULL;
    - GtkWidget *vbox = NULL;
    + GtkWidget *win = NULL, *vbox = NULL, *sw = NULL;
    GtkWidget *logo = NULL;
    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    @@ -13,7 +113,13 @@
    gtk_container_add(GTK_CONTAINER(win), vbox);
    logo = gtk_image_new_from_resource("/com/reaperworld/gtkcredits/logo.png");
    - gtk_box_pack_start(GTK_BOX(vbox), logo, TRUE, TRUE, 0);
    + gtk_box_pack_start(GTK_BOX(vbox), logo, FALSE, TRUE, 0);
    +
    + sw = gtk_scrolled_window_new(NULL, NULL);
    + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    + gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
    +
    + gtk_container_add(GTK_CONTAINER(sw), build_treeview());
    gtk_widget_show_all(win);
    }
    --- a/credits.json Tue Jun 14 23:28:40 2016 -0500
    +++ b/credits.json Wed Jun 15 00:06:58 2016 -0500
    @@ -2,5 +2,8 @@
    "developers": [{
    "name": "Gary 'grim' Kramlich",
    "title": "Maintainer"
    + }],
    + "crazy patch writers": [{
    + "name": "Eion Robb"
    }]
    }