]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Open File works. I refactored the code and introduced a new type. I never used it...
authorNathan Samson <nathansamson@gmail.com>
Mon, 5 Sep 2011 19:12:58 +0000 (21:12 +0200)
committerNathan Samson <nathansamson@gmail.com>
Mon, 5 Sep 2011 19:12:58 +0000 (21:12 +0200)
Signed-off-by: Nathan Samson <nathansamson@gmail.com>
Makefile
display.h
divelist.c
divelist.h [new file with mode: 0644]
info.c
main.c
profile.c

index 8b5fd220f57e9729e98941cee4d6ed51f20e6527..00658b6a0ecab340cdec7557d059e16870ec969b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,14 +17,14 @@ save-xml.o: save-xml.c dive.h
 dive.o: dive.c dive.h
        $(CC) $(CFLAGS) -c dive.c
 
-main.o: main.c dive.h display.h
+main.o: main.c dive.h display.h divelist.h
        $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c main.c
 
-profile.o: profile.c dive.h display.h
+profile.o: profile.c dive.h display.h divelist.h
        $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c profile.c
 
-info.o: info.c dive.h display.h
+info.o: info.c dive.h display.h divelist.h
        $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c info.c
 
-divelist.o: divelist.c dive.h display.h
+divelist.o: divelist.c dive.h display.h divelist.h
        $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c divelist.c
index 96fa29a5d574168b8d07b06b4410fff4a874de75..e2e217ff067c8f40ff2047ffcc40d7d8df873c3e 100644 (file)
--- a/display.h
+++ b/display.h
@@ -5,13 +5,9 @@
 #include <gdk/gdk.h>
 #include <cairo.h>
 
-extern int selected_dive;
-#define current_dive (get_dive(selected_dive))
-
 extern GtkWidget *dive_profile_widget(void);
 extern GtkWidget *dive_info_frame(void);
 extern GtkWidget *extended_dive_info_widget(void);
-extern GtkWidget *create_dive_list(void);
 extern void update_dive_info(struct dive *dive);
 extern void repaint_dive(void);
 
index b2ad39d0ee67e85b2ea2a418e8022755a4e5cb19..5dc45657b5ca096099753046277b3516873460b0 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <time.h>
 
+#include "divelist.h"
 #include "dive.h"
 #include "display.h"
 
@@ -62,27 +63,31 @@ static void fill_dive_list(GtkListStore *store)
        }
 }
 
-GtkWidget *create_dive_list(void)
+void dive_list_update_dives(struct DiveList dive_list)
 {
-       GtkListStore      *model;
-       GtkWidget         *tree_view;
+       gtk_list_store_clear(GTK_LIST_STORE(dive_list.model));
+       fill_dive_list(GTK_LIST_STORE(dive_list.model));
+}
+
+struct DiveList dive_list_create(void)
+{
+       struct DiveList    dive_list;
        GtkTreeSelection  *selection;
        GtkCellRenderer   *renderer;
        GtkTreeViewColumn *col;
-       GtkWidget         *scroll_window;
 
-       model = gtk_list_store_new(7,
+       dive_list.model = gtk_list_store_new(7,
                                   G_TYPE_STRING, G_TYPE_INT,
                                   G_TYPE_STRING, G_TYPE_INT, 
                                   G_TYPE_STRING, G_TYPE_INT,
                                   G_TYPE_INT);
-       tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+       dive_list.tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dive_list.model));
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
 
        gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
-       gtk_widget_set_size_request(tree_view, 200, 100);
+       gtk_widget_set_size_request(dive_list.tree_view, 200, 100);
 
-       fill_dive_list(model);
+       fill_dive_list(dive_list.model);
 
        renderer = gtk_cell_renderer_text_new();
        col = gtk_tree_view_column_new();
@@ -91,7 +96,7 @@ GtkWidget *create_dive_list(void)
        gtk_tree_view_column_set_resizable (col, TRUE);
        gtk_tree_view_column_pack_start(col, renderer, TRUE);
        gtk_tree_view_column_add_attribute(col, renderer, "text", 0);
-       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(dive_list.tree_view), col);
        
        renderer = gtk_cell_renderer_text_new();
        col = gtk_tree_view_column_new();
@@ -99,7 +104,7 @@ GtkWidget *create_dive_list(void)
        gtk_tree_view_column_set_sort_column_id(col, 3);
        gtk_tree_view_column_pack_start(col, renderer, FALSE);
        gtk_tree_view_column_add_attribute(col, renderer, "text", 2);
-       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(dive_list.tree_view), col);
        gtk_object_set(GTK_OBJECT(renderer), "alignment", PANGO_ALIGN_RIGHT, NULL);
        gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), 1.0, 0.5);
        
@@ -109,21 +114,21 @@ GtkWidget *create_dive_list(void)
        gtk_tree_view_column_set_sort_column_id(col, 5);
        gtk_tree_view_column_pack_start(col, renderer, FALSE);
        gtk_tree_view_column_add_attribute(col, renderer, "text", 4);
-       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(dive_list.tree_view), col);
        gtk_object_set(GTK_OBJECT(renderer), "alignment", PANGO_ALIGN_RIGHT, NULL);
        gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), 1.0, 0.5);
 
-       g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
+       g_object_set(G_OBJECT(dive_list.tree_view), "headers-visible", TRUE,
                                          "search-column", 0,
                                          "rules-hint", TRUE,
                                          NULL);
 
-       g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), model);
+       g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), dive_list.model);
 
-       scroll_window = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window),
+       dive_list.container_widget = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dive_list.container_widget),
                               GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       gtk_container_add(GTK_CONTAINER(scroll_window), tree_view);
+       gtk_container_add(GTK_CONTAINER(dive_list.container_widget), dive_list.tree_view);
 
-       return scroll_window;
+       return dive_list;
 }
diff --git a/divelist.h b/divelist.h
new file mode 100644 (file)
index 0000000..dc573d7
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef DIVELIST_H
+#define DIVELIST_H
+
+#include <gtk/gtk.h>
+
+struct DiveList {
+       GtkWidget    *tree_view;
+       GtkWidget    *container_widget;
+       GtkListStore *model;
+};
+
+extern int selected_dive;
+#define current_dive (get_dive(selected_dive))
+
+extern struct DiveList dive_list_create(void);
+extern void dive_list_update_dives(struct DiveList);
+
+#endif
diff --git a/info.c b/info.c
index c3b51409155c8d42202be54a9b88d46a1f371376..94dcd34858b11f687d8f8807e888a50254990fc8 100644 (file)
--- a/info.c
+++ b/info.c
@@ -5,6 +5,7 @@
 
 #include "dive.h"
 #include "display.h"
+#include "divelist.h"
 
 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature, *locationnote;
 static GtkEntry *location;
diff --git a/main.c b/main.c
index 2692185180b11e479b55d1dd597d9e432eff871e..83794ca06697269dc65dbb758ce88408e611a9be 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,9 +4,11 @@
 #include <time.h>
 
 #include "dive.h"
+#include "divelist.h"
 #include "display.h"
 
 GtkWidget *main_window;
+struct DiveList   dive_list;
 
 static int sortfn(const void *_a, const void *_b)
 {
@@ -98,8 +100,10 @@ static void file_open(GtkWidget *w, gpointer data)
        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                char *filename;
                filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-               printf("Open: '%s'\n", filename);
+               parse_xml_file(filename);
                g_free(filename);
+               report_dives();
+               dive_list_update_dives(dive_list);
        }
        gtk_widget_destroy(dialog);
 }
@@ -174,7 +178,6 @@ int main(int argc, char **argv)
 {
        int i;
        GtkWidget *win;
-       GtkWidget *divelist;
        GtkWidget *paned;
        GtkWidget *info_box;
        GtkWidget *notebook;
@@ -214,8 +217,8 @@ int main(int argc, char **argv)
        gtk_box_pack_end(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
 
        /* Create the actual divelist */
-       divelist = create_dive_list();
-       gtk_paned_add1(GTK_PANED(paned), divelist);
+       dive_list = dive_list_create();
+       gtk_paned_add1(GTK_PANED(paned), dive_list.container_widget);
 
        /* VBox for dive info, and tabs */
        info_box = gtk_vbox_new(FALSE, 6);
index 5c30fbb5e5768a0c34b38c824b7e497eb64be6ba..032bbd2c5acc86b196799048e46798b741eab99f 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -4,6 +4,7 @@
 
 #include "dive.h"
 #include "display.h"
+#include "divelist.h"
 
 int selected_dive = 0;