Remove the majority of the Gtk related code

- rip all Gtk code from qt-gui.cpp
- don't compile Gtk specific files
- don't link against Gtk libraries
- don't compile modules we don't use at all (yet)
- use #if USE_GTK_UI on the remaining files to disable Gtk related parts
- disable the non-functional Cochran support while I'm at it

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-03 11:04:51 -07:00
parent a6b89b3254
commit 8677721e85
21 changed files with 2684 additions and 2445 deletions

View file

@ -42,33 +42,21 @@ HEADERS = \
SOURCES = \
cochran.c \
deco.c \
device.c \
dive.c \
divelist.c \
divelist-gtk.c \
download-dialog.c \
equipment.c \
file.c \
info.c \
info-gtk.c \
libdivecomputer.c \
main.c \
parse-xml.c \
planner.c \
planner-gtk.c \
prefs.c \
print.c \
profile.c \
save-xml.c \
sha1.c \
statistics.c \
statistics-gtk.c \
time.c \
uemis.c \
uemis-downloader.c \
webservice.c \
qt-gui.cpp \
qt-ui/addcylinderdialog.cpp \
qt-ui/addweightsystemdialog.cpp \
@ -93,10 +81,12 @@ endif
ifneq ($(strip $(LIBXSLT)),)
EXTRA_FLAGS += -DXSLT='"$(XSLTDIR)"' $(XSLCFLAGS)
endif
ifeq ($(USE_GTK_UI),1)
ifneq ($(strip $(LIBOSMGPSMAP)),)
SOURCES += gps.c
EXTRA_FLAGS += -DHAVE_OSM_GPS_MAP $(OSMGPSMAPFLAGS)
endif
endif
ifneq (,$(filter $(UNAME),linux kfreebsd gnu))
SOURCES += linux.c
@ -118,7 +108,7 @@ else
XSLTDIR = .\\xslt
endif
LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) \
LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGCONF2) $(LIBDIVECOMPUTER) \
$(EXTRALIBS) $(LIBZIP) -lpthread -lm $(LIBOSMGPSMAP) $(LIBSOUP) $(LIBWINSOCK)
MSGLANGS=$(notdir $(wildcard po/*.po))

View file

@ -39,15 +39,11 @@ extern void set_divelist_font(const char *);
extern void update_screen(void);
extern void download_dialog(GtkWidget *, gpointer);
extern int is_default_dive_computer_device(const char *);
extern int is_default_dive_computer(const char *, const char *);
extern void add_dive_cb(GtkWidget *, gpointer);
extern void update_progressbar(progressbar_t *progress, double value);
extern void update_progressbar_text(progressbar_t *progress, const char *text);
extern const char *default_dive_computer_vendor;
extern const char *default_dive_computer_product;
extern const char *default_dive_computer_device;
// info.c
enum {

View file

@ -69,6 +69,12 @@ extern char zoomed_plot, dc_number;
extern unsigned int amount_selected;
extern int is_default_dive_computer_device(const char *);
extern int is_default_dive_computer(const char *, const char *);
extern const char *default_dive_computer_vendor;
extern const char *default_dive_computer_product;
extern const char *default_dive_computer_device;
#ifdef __cplusplus
}
#endif

View file

@ -59,7 +59,6 @@ static struct DiveList dive_list;
#define TREESTORE(_dl) GTK_TREE_STORE((_dl).treemodel)
#define LISTSTORE(_dl) GTK_TREE_STORE((_dl).listmodel)
short autogroup = FALSE;
static gboolean in_set_cursor = FALSE;
static gboolean set_selected(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data);

View file

@ -54,6 +54,8 @@
static short dive_list_changed = FALSE;
short autogroup = FALSE;
dive_trip_t *dive_trip_list;
unsigned int amount_selected;
@ -73,6 +75,13 @@ void dump_selection(void)
}
#endif
void set_autogroup(gboolean value)
{
/* if we keep the UI paradigm, this needs to toggle
* the checkbox on the autogroup menu item */
autogroup = value;
}
dive_trip_t *find_trip_by_idx(int idx)
{
dive_trip_t *trip = dive_trip_list;
@ -906,8 +915,9 @@ void merge_dive_index(int i, struct dive *a)
add_single_dive(i, res);
delete_single_dive(i+1);
delete_single_dive(i+1);
#if USE_GTK_UI
dive_list_update_dives();
#endif
mark_divelist_changed(TRUE);
}

View file

@ -3,19 +3,23 @@
#include "dive.h"
#include "divelist.h"
#include "display.h"
#if USE_GTK_UI
#include "display-gtk.h"
#include "callbacks-gtk.h"
#endif
#include "libdivecomputer.h"
const char *default_dive_computer_vendor;
const char *default_dive_computer_product;
const char *default_dive_computer_device;
#if USE_GTK_UI
static gboolean force_download;
static gboolean prefer_downloaded;
OPTIONCALLBACK(force_toggle, force_download)
OPTIONCALLBACK(prefer_dl_toggle, prefer_downloaded)
#endif
struct product {
const char *product;
@ -38,6 +42,7 @@ struct mydescriptor {
struct vendor *dc_list;
#if USE_GTK_UI
static void render_dc_vendor(GtkCellLayout *cell,
GtkCellRenderer *renderer,
GtkTreeModel *model,
@ -63,6 +68,7 @@ static void render_dc_product(GtkCellLayout *cell,
product = dc_descriptor_get_product(descriptor);
g_object_set(renderer, "text", product, NULL);
}
#endif
int is_default_dive_computer(const char *vendor, const char *product)
{
@ -105,6 +111,7 @@ static void set_default_dive_computer_device(const char *name)
subsurface_set_conf("dive_computer_device", name);
}
#if USE_GTK_UI
static void dive_computer_selector_changed(GtkWidget *combo, gpointer data)
{
GtkWidget *import, *button;
@ -149,7 +156,7 @@ static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog)
gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
return info;
}
#endif
/* create a list of lists and keep the elements sorted */
static void add_dc(const char *vendor, const char *product, dc_descriptor_t *descriptor)
@ -195,6 +202,7 @@ static void add_dc(const char *vendor, const char *product, dc_descriptor_t *des
pl->descriptor = descriptor;
}
#if USE_GTK_UI
/* fill the vendors and create and fill the respective product stores; return the longest product name
* and also the indices of the default vendor / product */
static int fill_computer_list(GtkListStore *vendorstore, GtkListStore ***productstore, int *vendor_index, int *product_index)
@ -469,3 +477,4 @@ void update_progressbar_text(progressbar_t *progress, const char *text)
{
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text);
}
#endif

View file

@ -16,10 +16,14 @@
#include "dive.h"
#include "display.h"
#if USE_GTK_UI
#include "display-gtk.h"
#endif
#include "divelist.h"
#include "conversions.h"
#if USE_GTK_UI
#include "display-gtk.h"
static GtkListStore *cylinder_model, *weightsystem_model;
enum {
@ -69,6 +73,7 @@ struct ws_widget {
GtkSpinButton *weight;
int w_idx;
};
#endif /* USE_GTK_UI */
/* we want bar - so let's not use our unit functions */
int convert_pressure(int mbar, double *p)
@ -120,6 +125,7 @@ static int convert_weight(int grams, double *m)
return decimals;
}
#if USE_GTK_UI
static void set_cylinder_description(struct cylinder_widget *cylinder, const char *desc)
{
set_active_text(cylinder->description, desc);
@ -451,6 +457,28 @@ static void show_weightsystem(weightsystem_t *ws, struct ws_widget *weightsystem
set_weight_description(weightsystem_widget, desc);
set_weight_weight_spinbutton(weightsystem_widget, ws->weight.grams);
}
#else
/* placeholders for a few functions that we need to redesign for the Qt UI */
void add_cylinder_description(cylinder_type_t *type)
{
const char *desc;
desc = type->description;
if (!desc)
return;
/* now do something with it... */
}
void add_weightsystem_description(weightsystem_t *weightsystem)
{
const char *desc;
desc = weightsystem->description;
if (!desc)
return;
/* now do something with it... */
}
#endif /* USE_GTK_UI */
gboolean cylinder_nodata(cylinder_t *cyl)
{
@ -515,6 +543,7 @@ gboolean weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2)
return TRUE;
}
#if USE_GTK_UI
static void set_one_cylinder(void *_data, GtkListStore *model, GtkTreeIter *iter)
{
cylinder_t *cyl = _data;
@ -784,7 +813,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
ws->description = desc;
add_weightsystem_type(desc, grams, &iter);
}
#endif /* USE_GTK_UI */
/*
* We hardcode the most common standard cylinders,
* we should pick up any other names from the dive
@ -833,6 +862,7 @@ struct tank_info tank_info[100] = {
{ NULL, }
};
#if USE_GTK_UI
static void fill_tank_list(GtkListStore *store)
{
GtkTreeIter iter;
@ -1679,3 +1709,4 @@ void clear_equipment_widgets()
gtk_list_store_clear(cylinder_list[W_IDX_PRIMARY].model);
gtk_list_store_clear(weightsystem_list[W_IDX_PRIMARY].model);
}
#endif /* USE_GTK_UI */

2
file.c
View file

@ -239,9 +239,11 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
if (!strcasecmp(fmt, "DLD"))
return try_to_open_zip(filename, mem, error);
#if ONCE_COCHRAN_IS_SUPPORTED
/* Truly nasty intentionally obfuscated Cochran Anal software */
if (!strcasecmp(fmt, "CAN"))
return try_to_open_cochran(filename, mem, error);
#endif
/* Cochran export comma-separated-value files */
if (!strcasecmp(fmt, "DPT"))

2550
gtk-gui.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -736,6 +736,14 @@ int edit_multi_dive_info(struct dive *single_dive)
return success;
}
int edit_dive_info(struct dive *dive, gboolean newdive)
{
if (!dive || (!newdive && !amount_selected))
return 0;
return edit_multi_dive_info(dive);
}
static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
{
va_list ap;

15
info.c
View file

@ -448,10 +448,15 @@ void update_time_depth(struct dive *dive, struct dive *edited)
dive->dc.meandepth.mm = edited->dc.meandepth.mm;
}
int edit_dive_info(struct dive *dive, gboolean newdive)
void add_people(const char *string)
{
if (!dive || (!newdive && !amount_selected))
return 0;
return edit_multi_dive_info(dive);
/* add names to the completion list for people */
}
void add_location(const char *string)
{
/* add names to the completion list for locations */
}
void add_suit(const char *string)
{
/* add names to the completion list for suits */
}

View file

@ -26,6 +26,7 @@ static double progress_bar_fraction = 0.0;
static int stoptime, stopdepth, ndl, po2, cns;
static gboolean in_deco, first_temp_is_air;
#if USE_GTK_UI
static GError *error(const char *fmt, ...)
{
va_list args;
@ -38,6 +39,7 @@ static GError *error(const char *fmt, ...)
va_end(args);
return error;
}
#endif
static dc_status_t create_parser(device_data_t *devdata, dc_parser_t **parser)
{
@ -708,6 +710,7 @@ static const char *do_libdivecomputer_import(device_data_t *data)
return err;
}
#if USE_GTK_UI
static void *pthread_wrapper(void *_data)
{
device_data_t *data = _data;
@ -772,3 +775,4 @@ GError *do_import(device_data_t *data)
return error(retval, data->vendor, data->product, data->devname);
return NULL;
}
#endif

View file

@ -17,10 +17,12 @@ typedef struct device_data_t {
unsigned int deviceid, diveid;
dc_device_t *device;
dc_context_t *context;
progressbar_t progress;
int preexisting;
gboolean force_download;
#if USE_GTK_UI
progressbar_t progress;
GtkDialog *dialog;
#endif
} device_data_t;
extern GError *do_import(device_data_t *data);

View file

@ -1,6 +1,7 @@
/* linux.c */
/* implements Linux specific functions */
#include "dive.h"
#include "display.h"
#include "display-gtk.h"
#include <gconf/gconf-client.h>
#include <string.h>

14
main.c
View file

@ -99,7 +99,11 @@ static void parse_argument(const char *arg)
if (strcmp(arg,"--import") == 0) {
/* mark the dives so far as the base,
* everything after is imported */
#if USE_GTK_UI
report_dives(FALSE, FALSE);
#else
process_dives(FALSE, FALSE);
#endif
imported = TRUE;
return;
}
@ -119,6 +123,7 @@ static void parse_argument(const char *arg)
void update_dive(struct dive *new_dive)
{
#if USE_GTK_UI
static struct dive *buffered_dive;
struct dive *old_dive = buffered_dive;
@ -129,6 +134,7 @@ void update_dive(struct dive *new_dive)
show_dive_equipment(new_dive, W_IDX_PRIMARY);
show_dive_stats(new_dive);
buffered_dive = new_dive;
#endif
}
void renumber_dives(int nr)
@ -138,7 +144,9 @@ void renumber_dives(int nr)
for (i = 0; i < dive_table.nr; i++) {
struct dive *dive = dive_table.dives[i];
dive->number = nr + i;
#if USE_GTK_UI
flush_divelist(dive);
#endif
}
mark_divelist_changed(TRUE);
}
@ -229,7 +237,9 @@ int main(int argc, char **argv)
}
if (error != NULL)
{
#if USE_GTK_UI
report_error(error);
#endif
g_error_free(error);
error = NULL;
}
@ -242,9 +252,13 @@ int main(int argc, char **argv)
sure we remember this as the filename in use */
set_filename(filename, FALSE);
}
#if USE_GTK_UI
report_dives(imported, FALSE);
if (dive_table.nr == 0)
show_dive_info(NULL);
#else
process_dives(imported, FALSE);
#endif
parse_xml_exit();
subsurface_command_line_exit(&argc, &argv);

View file

@ -685,9 +685,11 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, c
stopidx--;
}
add_plan_to_notes(diveplan, dive);
#if USE_GTK_UI
/* now make the dive visible in the dive list */
report_dives(FALSE, FALSE);
show_and_select_dive(dive);
#endif
error_exit:
free(stoplevels);
free(gaschanges);

View file

@ -136,6 +136,8 @@ static const color_t profile_color[] = {
};
#if USE_GTK_UI
/* Scale to 0,0 -> maxx,maxy */
#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
@ -189,8 +191,7 @@ static void pattern_add_color_stop_rgba(struct graphics_context *gc, cairo_patte
struct rgba rgb = col->media[gc->printer];
cairo_pattern_add_color_stop_rgba(pat, o, rgb.r, rgb.g, rgb.b, rgb.a);
}
#define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y))
#endif /* USE_GTK_UI */
/* debugging tool - not normally used */
static void dump_pi (struct plot_info *pi)
@ -215,6 +216,8 @@ static void dump_pi (struct plot_info *pi)
printf(" }\n");
}
#define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y))
/*
* When showing dive profiles, we scale things to the
* current dive. However, we don't scale past less than
@ -276,6 +279,7 @@ typedef struct {
#define MIDDLE (0)
#define BOTTOM (-1)
#if USE_GTK_UI
static void plot_text(struct graphics_context *gc, const text_render_options_t *tro,
double x, double y, const char *fmt, ...)
{
@ -308,6 +312,7 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t *
set_source_rgba(gc, tro->color);
cairo_show_text(cr, buffer);
}
#endif /* USE_GTK_UI */
/* collect all event names and whether we display them */
struct ev_select {
@ -357,6 +362,7 @@ void remember_event(const char *eventname)
evn_used++;
}
#if USE_GTK_UI
static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event)
{
int i, depth = 0;
@ -1027,6 +1033,7 @@ static void set_sac_color(struct graphics_context *gc, int sac, int avg_sac)
set_source_rgba(gc, SAC_DEFAULT);
}
}
#endif /* USE_GTK_UI */
/* Get local sac-rate (in ml/min) between entry1 and entry2 */
static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive)
@ -1065,6 +1072,7 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
#define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */
#if USE_GTK_UI
static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info *pi,
struct dive *dive, struct divecomputer *dc)
{
@ -1189,6 +1197,7 @@ static void plot_deco_text(struct graphics_context *gc, struct plot_info *pi)
plot_text(gc, &tro, x, y, "GF %.0f/%.0f", prefs.gflow * 100, prefs.gfhigh * 100);
}
}
#endif /* USE_GTK_UI */
static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
{
@ -1259,6 +1268,7 @@ static velocity_t velocity(int speed)
return v;
}
static struct plot_info *analyze_plot_info(struct plot_info *pi)
{
int i;
@ -1974,6 +1984,7 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
return analyze_plot_info(pi);
}
#if USE_GTK_UI
static void plot_set_scale(scale_mode_t scale)
{
switch (scale) {
@ -1986,6 +1997,7 @@ static void plot_set_scale(scale_mode_t scale)
break;
}
}
#endif
/* make sure you pass this the FIRST dc - it just walks the list */
static int nr_dcs(struct divecomputer *main)
@ -2015,6 +2027,7 @@ struct divecomputer *select_dc(struct divecomputer *main)
return main;
}
#if USE_GTK_UI
void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
{
struct plot_info *pi;
@ -2132,6 +2145,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
pi->nr = 0;
}
}
#endif /* USE_GTK_UI */
static void plot_string(struct plot_data *entry, char *buf, size_t bufsize,
int depth, int pressure, int temp, gboolean has_ndl)

2418
qt-gui.cpp

File diff suppressed because it is too large Load diff

View file

@ -116,6 +116,7 @@ void MainWindow::on_actionClose_triggered()
ui->InfoWidget->clearEquipment();
clear_events();
#if USE_GTK_UI
show_dive_stats(NULL);
/* redraw the screen */
@ -124,6 +125,7 @@ void MainWindow::on_actionClose_triggered()
// WARNING? Port this to Qt.
show_dive_info(NULL);
#endif /* USE_GTK_UI */
}
void MainWindow::on_actionImport_triggered()

View file

@ -922,14 +922,18 @@ GError *uemis_download(const char *mountpath, progressbar_t *progress,
if (!import_thread_cancelled) {
int result;
g_timeout_add(100, timeout_func, dialog);
#if USE_GTK_UI
update_progressbar(args.progress, progress_bar_fraction);
update_progressbar_text(args.progress, progress_bar_text);
#endif
result = gtk_dialog_run(dialog);
if (result == GTK_RESPONSE_CANCEL)
import_thread_cancelled = TRUE;
} else {
#if USE_GTK_UI
update_progressbar(args.progress, progress_bar_fraction);
update_progressbar_text(args.progress, _("Cancelled, exiting cleanly..."));
#endif
usleep(100000);
}
}

View file

@ -164,7 +164,9 @@ static void download_dialog_response_cb(GtkDialog *d, gint response, gpointer da
/* now merge the data in the gps_location table into the dive_table */
if (merge_locations_into_dives()) {
mark_divelist_changed(TRUE);
#if USE_GTK_UI
dive_list_update_dives();
#endif
}
/* store last entered uid in config */
subsurface_set_conf("webservice_uid", gtk_entry_get_text(GTK_ENTRY(state->uid)));