#include <string.h>
#include <time.h>
+#include "divelist.h"
#include "dive.h"
#include "display.h"
}
}
-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();
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();
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);
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;
}
#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)
{
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);
}
{
int i;
GtkWidget *win;
- GtkWidget *divelist;
GtkWidget *paned;
GtkWidget *info_box;
GtkWidget *notebook;
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);