summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-30 20:56:01 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-30 20:56:01 -0700
commitd1ae1c48309cd0ac5af96114040407dd51e92c37 (patch)
tree75a7e2ce1dafc57d62bf8b6ac5224f93a7069332 /main.c
parent3aa02ccba93648f2decab899a5b9c42b6bcea9bf (diff)
downloadsubsurface-d1ae1c48309cd0ac5af96114040407dd51e92c37.tar.gz
Show the dives as a gtk list/tree widget
Ok, so I'm not very good at this. I'll need to enclose the dang thing in a scrollable window, and then make that scrollable thing just part of the whole window. But hey, it's pixels on the screen. Pixels that show the names of the dives we've parsed. At least as many as will fit on screen at one time ;) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'main.c')
-rw-r--r--main.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/main.c b/main.c
index adceca9e6..1b97930e5 100644
--- a/main.c
+++ b/main.c
@@ -84,10 +84,49 @@ static gboolean on_expose(GtkWidget* w, GdkEventExpose* e, gpointer data)
return FALSE;
}
+static GtkTreeModel *fill_dive_list(void)
+{
+ int i;
+ GtkListStore *store;
+ GtkTreeIter iter;
+
+ store = gtk_list_store_new(1, G_TYPE_STRING);
+
+ for (i = 0; i < dive_table.nr; i++) {
+ struct dive *dive = dive_table.dives[i];
+
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ 0, dive->name,
+ -1);
+ }
+
+ return GTK_TREE_MODEL(store);
+}
+
+static GtkWidget *create_dive_list(void)
+{
+ GtkWidget *list;
+ GtkCellRenderer *renderer;
+ GtkTreeModel *model;
+
+ list = gtk_tree_view_new();
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(list),
+ -1, "Dive", renderer, "text", 0, NULL);
+
+ model = fill_dive_list();
+ gtk_tree_view_set_model(GTK_TREE_VIEW(list), model);
+ g_object_unref(model);
+ return list;
+}
+
int main(int argc, char **argv)
{
int i;
- GtkWidget* win;
+ GtkWidget *win;
+ GtkWidget *divelist;
parse_xml_init();
@@ -108,10 +147,13 @@ int main(int argc, char **argv)
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect(G_OBJECT(win), "expose-event", G_CALLBACK(on_expose), NULL);
+
+ divelist = create_dive_list();
+ gtk_container_add(GTK_CONTAINER(win), divelist);
+
gtk_widget_set_app_paintable(win, TRUE);
gtk_widget_show_all(win);
gtk_main();
return 0;
}
-