mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Add cylinder data to cylinder model as we record each dive
This way the cylinder model list will contain all the different cylinders that we have ever seen, rather than only containing the models that we have *edited*. That makes it much more practical to add new dives with the same cylinders that we've used before, because now those cylinders will show up as cylinder models even if we haven't looked and edited the old dives first. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
567c945714
commit
f9cb526c96
3 changed files with 53 additions and 15 deletions
5
dive.c
5
dive.c
|
@ -240,6 +240,11 @@ struct dive *fixup_dive(struct dive *dive)
|
||||||
update_temperature(&dive->watertemp, mintemp);
|
update_temperature(&dive->watertemp, mintemp);
|
||||||
update_depth(&dive->maxdepth, maxdepth);
|
update_depth(&dive->maxdepth, maxdepth);
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
|
cylinder_type_t *type = &dive->cylinder[i].type;
|
||||||
|
add_cylinder_description(type);
|
||||||
|
}
|
||||||
|
|
||||||
return dive;
|
return dive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
dive.h
1
dive.h
|
@ -259,6 +259,7 @@ extern void run_ui(void);
|
||||||
|
|
||||||
extern void report_error(GError* error);
|
extern void report_error(GError* error);
|
||||||
|
|
||||||
|
extern void add_cylinder_description(cylinder_type_t *);
|
||||||
extern void dive_list_update_dives(void);
|
extern void dive_list_update_dives(void);
|
||||||
extern void flush_divelist(struct dive *dive);
|
extern void flush_divelist(struct dive *dive);
|
||||||
|
|
||||||
|
|
62
equipment.c
62
equipment.c
|
@ -19,7 +19,7 @@
|
||||||
#include "display-gtk.h"
|
#include "display-gtk.h"
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
|
|
||||||
GtkListStore *cylinder_model;
|
static GtkListStore *cylinder_model;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CYL_DESC,
|
CYL_DESC,
|
||||||
|
@ -148,7 +148,8 @@ static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
|
||||||
* The gtk_tree_model_foreach() interface is bad. It could have
|
* The gtk_tree_model_foreach() interface is bad. It could have
|
||||||
* returned whether the callback ever returned true
|
* returned whether the callback ever returned true
|
||||||
*/
|
*/
|
||||||
static int found_match = 0;
|
static GtkTreeIter *found_match = NULL;
|
||||||
|
static GtkTreeIter match_iter;
|
||||||
|
|
||||||
static gboolean match_cylinder(GtkTreeModel *model,
|
static gboolean match_cylinder(GtkTreeModel *model,
|
||||||
GtkTreePath *path,
|
GtkTreePath *path,
|
||||||
|
@ -156,39 +157,70 @@ static gboolean match_cylinder(GtkTreeModel *model,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
struct cylinder_widget *cylinder = data;
|
const char *desc = data;
|
||||||
GValue value = {0, };
|
GValue value = {0, };
|
||||||
|
|
||||||
gtk_tree_model_get_value(model, iter, 0, &value);
|
gtk_tree_model_get_value(model, iter, 0, &value);
|
||||||
name = g_value_get_string(&value);
|
name = g_value_get_string(&value);
|
||||||
if (strcmp(cylinder->name, name))
|
if (strcmp(desc, name))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
gtk_combo_box_set_active_iter(cylinder->description, iter);
|
match_iter = *iter;
|
||||||
found_match = 1;
|
found_match = &match_iter;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
|
static GtkTreeIter *add_cylinder_type(const char *desc, int ml, int mbar, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
|
|
||||||
found_match = 0;
|
/* Don't even bother adding stuff without a size */
|
||||||
model = gtk_combo_box_get_model(cylinder->description);
|
if (!ml)
|
||||||
cylinder->name = desc;
|
return NULL;
|
||||||
gtk_tree_model_foreach(model, match_cylinder, cylinder);
|
|
||||||
|
found_match = NULL;
|
||||||
|
model = GTK_TREE_MODEL(cylinder_model);
|
||||||
|
gtk_tree_model_foreach(model, match_cylinder, (void *)desc);
|
||||||
|
|
||||||
if (!found_match) {
|
if (!found_match) {
|
||||||
GtkListStore *store = GTK_LIST_STORE(model);
|
GtkListStore *store = GTK_LIST_STORE(model);
|
||||||
GtkTreeIter iter;
|
|
||||||
|
|
||||||
gtk_list_store_append(store, &iter);
|
gtk_list_store_append(store, iter);
|
||||||
gtk_list_store_set(store, &iter,
|
gtk_list_store_set(store, iter,
|
||||||
0, desc,
|
0, desc,
|
||||||
1, ml,
|
1, ml,
|
||||||
2, mbar,
|
2, mbar,
|
||||||
-1);
|
-1);
|
||||||
gtk_combo_box_set_active_iter(cylinder->description, &iter);
|
return iter;
|
||||||
}
|
}
|
||||||
|
return found_match;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When adding a dive, we'll add all the pre-existing cylinder
|
||||||
|
* information from that dive to our cylinder model.
|
||||||
|
*/
|
||||||
|
void add_cylinder_description(cylinder_type_t *type)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
const char *desc;
|
||||||
|
unsigned int size, workp;
|
||||||
|
|
||||||
|
desc = type->description;
|
||||||
|
if (!desc)
|
||||||
|
return;
|
||||||
|
size = type->size.mliter;
|
||||||
|
workp = type->workingpressure.mbar;
|
||||||
|
add_cylinder_type(desc, size, workp, &iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter, *match;
|
||||||
|
|
||||||
|
cylinder->name = desc;
|
||||||
|
match = add_cylinder_type(desc, ml, mbar, &iter);
|
||||||
|
if (match)
|
||||||
|
gtk_combo_box_set_active_iter(cylinder->description, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
|
static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
|
||||||
|
|
Loading…
Add table
Reference in a new issue