Skip to content

Commit

Permalink
Separate out the UI from the program logic
Browse files Browse the repository at this point in the history
The following are UI toolkit specific:
gtk-gui.c   - overall layout, main window of the UI
divelist.c  - list of dives subsurface maintains
equipment.c - equipment / tank information for each dive
info.c      - detailed dive info
print.c     - printing

The rest is independent of the UI:
main.c i    - program frame
dive.c i    - creates and maintaines the internal dive list structure
libdivecomputer.c
uemis.c
parse-xml.c
save-xml.c  - interface with dive computers and the XML files
profile.c   - creates the data for the profile and draws it using cairo

This commit should contain NO functional changes, just moving code around
and a couple of minor abstractions.

Signed-off-by: Dirk Hohndel <[email protected]>
  • Loading branch information
dirkhh committed Sep 20, 2011
1 parent 6ea5132 commit 6821358
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 648 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib/libdivecomputer.a
LIBS = `pkg-config --libs gtk+-2.0 glib-2.0 gconf-2.0`

OBJS = main.o dive.o profile.o info.o equipment.o divelist.o \
parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o
parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o \
gtk-gui.o

subsurface: $(OBJS)
$(CC) $(LDFLAGS) -o subsurface $(OBJS) \
Expand All @@ -26,13 +27,13 @@ dive.o: dive.c dive.h
$(CC) $(CFLAGS) `pkg-config --cflags glib-2.0` -c dive.c

main.o: main.c dive.h display.h divelist.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0 gconf-2.0` \
$(CC) $(CFLAGS) `pkg-config --cflags glib-2.0 gconf-2.0` \
-c main.c

profile.o: profile.c dive.h display.h divelist.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c profile.c

info.o: info.c dive.h display.h divelist.h
info.o: info.c dive.h display.h display-gtk.h divelist.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c info.c

equipment.o: equipment.c dive.h display.h divelist.h
Expand All @@ -41,13 +42,18 @@ equipment.o: equipment.c dive.h display.h divelist.h
divelist.o: divelist.c dive.h display.h divelist.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c divelist.c

print.o: print.c dive.h display.h
print.o: print.c dive.h display.h display-gtk.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c print.c

libdivecomputer.o: libdivecomputer.c dive.h display.h
libdivecomputer.o: libdivecomputer.c dive.h display.h display-gtk.h libdivecomputer.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` \
-I$(LIBDIVECOMPUTERINCLUDES) \
-c libdivecomputer.c

gtk-gui.o: gtk-gui.c dive.h display.h divelist.h display-gtk.h libdivecomputer.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0 gconf-2.0` \
-I$(LIBDIVECOMPUTERINCLUDES) \
-c gtk-gui.c

uemis.o: uemis.c uemis.h
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c uemis.c
19 changes: 19 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ and subsurface will de-duplicate the ones that are exactly the same
the dives have duplicates that were edited by Dirk in the Suunto Dive
Manager, so they don't trigger the "exact duplicates" match.

Implementation details:

main.c - program frame
dive.c - creates and maintaines the internal dive list structure
libdivecomputer.c
uemis.c
parse-xml.c
save-xml.c - interface with dive computers and the XML files
profile.c - creates the data for the profile and draws it using cairo

A first UI has been implemented in gtk and an attempt has been made to
separate program logic from UI implementation.

gtk-gui.c - overall layout, main window of the UI
divelist.c - list of dives subsurface maintains
equipment.c - equipment / tank information for each dive
info.c - detailed dive info
print.c - printing

WARNING! I wasn't kidding when I said that I've done this by reading
gtk2 tutorials as I've gone along. If somebody is more comfortable with
gtk, feel free to send me (signed-off) patches.
Expand Down
29 changes: 29 additions & 0 deletions display-gtk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef DISPLAY_GTK_H
#define DISPLAY_GTK_H

#include <gtk/gtk.h>
#include <gdk/gdk.h>

extern GtkWidget *main_window;

/* we want a progress bar as part of the device_data_t - let's abstract this out */
typedef struct {
GtkWidget *bar;
} progressbar_t;

extern const char *divelist_font;
extern void set_divelist_font(const char *);

extern void import_dialog(GtkWidget *, gpointer);
extern void report_error(GError* error);
extern int process_ui_events(void);
extern void update_progressbar(progressbar_t *progress, double value);

extern GtkWidget *dive_profile_widget(void);
extern GtkWidget *dive_info_frame(void);
extern GtkWidget *extended_dive_info_widget(void);
extern GtkWidget *equipment_widget(void);

extern GtkWidget *dive_list_create(void);

#endif
16 changes: 1 addition & 15 deletions display.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
#ifndef DISPLAY_H
#define DISPLAY_H

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <cairo.h>

extern GtkWidget *main_window;

extern const char *divelist_font;
extern void set_divelist_font(const char *);

extern void import_dialog(GtkWidget *, gpointer);
extern void report_error(GError* error);

extern GtkWidget *dive_profile_widget(void);
extern GtkWidget *dive_info_frame(void);
extern GtkWidget *extended_dive_info_widget(void);
extern GtkWidget *equipment_widget(void);

extern void repaint_dive(void);
extern void do_print(void);

Expand All @@ -38,5 +23,6 @@ struct graphics_context {
};

extern void plot(struct graphics_context *gc, int w, int h, struct dive *dive);
extern void set_source_rgb(struct graphics_context *gc, double r, double g, double b);

#endif
2 changes: 2 additions & 0 deletions dive.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* dive.c */
/* maintains the internal dive list structure */
#include <string.h>
#include <stdio.h>

Expand Down
15 changes: 14 additions & 1 deletion dive.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,21 @@ extern void report_dives(void);
extern struct dive *fixup_dive(struct dive *dive);
extern struct dive *try_to_merge(struct dive *a, struct dive *b);

extern void update_air_info(char *buffer);
extern void renumber_dives(int nr);

/* UI related protopypes */

extern void init_ui(int argc, char **argv);

extern void run_ui(void);

extern void report_error(GError* error);

extern void dive_list_update_dives(void);
extern void flush_divelist(struct dive *dive);

extern int open_import_file_dialog(char *filterpattern, char *filtertext,
void(* parse_function)(char *));
#define DIVE_ERROR_PARSE 1

const char *weekday(int wday);
Expand Down
30 changes: 13 additions & 17 deletions divelist.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* divelist.c */
/* this creates the UI for the dive list -
* controlled through the following interfaces:
*
* void flush_divelist(struct dive *dive)
* GtkWidget dive_list_create(void)
* void dive_list_update_dives(void)
* void update_dive_list_units(void)
* void set_divelist_font(const char *font)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -6,6 +16,7 @@
#include "divelist.h"
#include "dive.h"
#include "display.h"
#include "display-gtk.h"

struct DiveList {
GtkWidget *tree_view;
Expand Down Expand Up @@ -34,6 +45,8 @@ enum {
DIVELIST_COLUMNS
};

/* the global dive list that we maintain */
static struct DiveList dive_list;

static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
{
Expand All @@ -48,23 +61,6 @@ static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
repaint_dive();
}

const char *weekday(int wday)
{
static const char wday_array[7][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
return wday_array[wday];
}

const char *monthname(int mon)
{
static const char month_array[12][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Oct", "Sep", "Nov", "Dec",
};
return month_array[mon];
}

static void date_data_func(GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
Expand Down
3 changes: 0 additions & 3 deletions divelist.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#ifndef DIVELIST_H
#define DIVELIST_H

#include <gtk/gtk.h>

struct dive;

extern GtkWidget *dive_list_create(void);
extern void dive_list_update_dives(void);
extern void update_dive_list_units(void);
extern void flush_divelist(struct dive *);
Expand Down
11 changes: 11 additions & 0 deletions equipment.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* equipment.c */
/* creates the UI for the equipment page -
* controlled through the following interfaces:
*
* void show_dive_equipment(struct dive *dive)
* void flush_dive_equipment_changes(struct dive *dive)
*
* called from gtk-ui:
* GtkWidget *equipment_widget(void)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -6,6 +16,7 @@

#include "dive.h"
#include "display.h"
#include "display-gtk.h"
#include "divelist.h"

struct cylinder_widget {
Expand Down
Loading

0 comments on commit 6821358

Please sign in to comment.