summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--display.h4
-rw-r--r--divelist.c41
-rw-r--r--divelist.h18
-rw-r--r--info.c1
-rw-r--r--main.c11
-rw-r--r--profile.c1
7 files changed, 54 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 8b5fd220f..00658b6a0 100644
--- 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
diff --git a/display.h b/display.h
index 96fa29a5d..e2e217ff0 100644
--- 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);
diff --git a/divelist.c b/divelist.c
index b2ad39d0e..5dc45657b 100644
--- a/divelist.c
+++ b/divelist.c
@@ -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
index 000000000..dc573d770
--- /dev/null
+++ b/divelist.h
@@ -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 c3b514091..94dcd3485 100644
--- 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 269218518..83794ca06 100644
--- 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);
diff --git a/profile.c b/profile.c
index 5c30fbb5e..032bbd2c5 100644
--- a/profile.c
+++ b/profile.c
@@ -4,6 +4,7 @@
#include "dive.h"
#include "display.h"
+#include "divelist.h"
int selected_dive = 0;