]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Split up divelist scroll window generation into its own file
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 17:27:58 +0000 (10:27 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 17:27:58 +0000 (10:27 -0700)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Makefile
display.h
divelist.c [new file with mode: 0644]
main.c

index b073223812d8260cbd8026e8d8dab9476fa21678..244bf397935035033ddaec31ada5387991387e13 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
 CFLAGS=-Wall -Wno-pointer-sign -g
 
-OBJS=main.o profile.o parse.o
+OBJS=main.o profile.o divelist.o parse.o
 
 parse: $(OBJS)
        $(CC) $(LDLAGS) -o parse $(OBJS) `xml2-config --libs` \
@@ -15,3 +15,6 @@ main.o: main.c dive.h
 
 profile.o: profile.c dive.h
        $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c profile.c
+
+divelist.o: divelist.c dive.h
+       $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c divelist.c
index c239fbd3c3bc516ae8341a4b8c0536cec2fc6507..cde0708e3392484c4d995cf4a3b39989344d5a5a 100644 (file)
--- a/display.h
+++ b/display.h
@@ -6,5 +6,6 @@
 #include <cairo.h>
 
 extern GtkWidget *dive_profile_frame(void);
+extern GtkWidget *create_dive_list(void);
 
 #endif
diff --git a/divelist.c b/divelist.c
new file mode 100644 (file)
index 0000000..a1aa21a
--- /dev/null
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "dive.h"
+#include "display.h"
+
+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);
+}
+
+GtkWidget *create_dive_list(void)
+{
+       GtkWidget *list;
+       GtkCellRenderer *renderer;
+       GtkTreeModel *model;
+       GtkWidget *scrolled_window;
+
+       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);
+
+       /* Scrolled window for the list goes into the vbox.. */
+       scrolled_window=gtk_scrolled_window_new(NULL, NULL);
+       gtk_widget_set_usize(scrolled_window, 150, 350);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       gtk_widget_show(scrolled_window);
+
+       /* .. and connect it to the scrolled window */
+       gtk_container_add(GTK_CONTAINER(scrolled_window), list);
+
+       return scrolled_window;
+}
diff --git a/main.c b/main.c
index b7df3bfaa38df9c35c19e5bbfa1bba54cc423a0b..e567ee118fe7ae43281329bc6216dc5cfaed3337 100644 (file)
--- a/main.c
+++ b/main.c
@@ -47,51 +47,12 @@ static void on_destroy(GtkWidget* w, gpointer data)
        gtk_main_quit();
 }
 
-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 *divelist;
        GtkWidget *vbox;
-       GtkWidget *scrolled_window;
        GtkWidget *frame;
 
        parse_xml_init();
@@ -119,24 +80,14 @@ int main(int argc, char **argv)
        gtk_container_add(GTK_CONTAINER(win), vbox);
        gtk_widget_show(vbox);
 
-       /* Scrolled window for the list goes into the vbox.. */
-       scrolled_window=gtk_scrolled_window_new(NULL, NULL);
-       gtk_widget_set_usize(scrolled_window, 150, 350);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-       gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
-       gtk_widget_show(scrolled_window);
+       /* Create the atual divelist */
+       divelist = create_dive_list();
+       gtk_container_add(GTK_CONTAINER(vbox), divelist);
 
        /* Frame for dive profile */
        frame = dive_profile_frame();
-
        gtk_container_add(GTK_CONTAINER(vbox), frame);
 
-       /* Create the atual divelist */
-       divelist = create_dive_list();
-
-       /* .. and connect it to the scrolled window */
-       gtk_container_add(GTK_CONTAINER(scrolled_window), divelist);
-
        gtk_widget_set_app_paintable(win, TRUE);
        gtk_widget_show_all(win);