grim/pidgin-credits

Fix a typo

2016-06-28, Gary Kramlich
7f5ee84932c1
Fix a typo
#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, *vbox = NULL, *sw = NULL;
GtkWidget *logo = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(win), 12);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
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, 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);
}
gint
main(gint argc, gchar **argv) {
gtk_init(&argc, &argv);
build_window();
gtk_main();
return 0;
}