summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-22 19:52:07 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-22 20:11:13 -0800
commit713c845e5a04a5ea5a41d1d8de3dc5c16b0e8df5 (patch)
tree72dc14770d34098a444d1ac3940ec8a2c5cb5d25 /divelist.c
parentc02f1b88ab5a0a9d6fadf56468910d76ce0b1c5d (diff)
downloadsubsurface-713c845e5a04a5ea5a41d1d8de3dc5c16b0e8df5.tar.gz
Add GPS icon to the location column for dive sites where we have GPS data
This replaces the really lame "italics text" from commit abe810ca1a29 ("Mark locations that have GPS location data attached") with a marginally less lame GPS icon.There's a reason why I am not making a living as graphics artist. But I think this is a huge step forward from what we had before... The satellite.svg file is very loosely based on a different icon that I found as public domain here http://www.clker.com/clipart-30400.html. From that I created the PNG and then that was converted into the GdkPixdata via gdk-pixbuf-csource; a rule for that was added to the Makefile but commented out as I don't know if this tool will always be available in the path. Having this icon included in the sources avoids locating yet another icon file. Better icons are certainly welcome! Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c79
1 files changed, 60 insertions, 19 deletions
diff --git a/divelist.c b/divelist.c
index e46e8ea20..b3c5417b8 100644
--- a/divelist.c
+++ b/divelist.c
@@ -23,6 +23,9 @@
#include "display.h"
#include "display-gtk.h"
+#include <gdk-pixbuf/gdk-pixdata.h>
+#include "satellite.h"
+
struct DiveList {
GtkWidget *tree_view;
GtkWidget *container_widget;
@@ -63,6 +66,7 @@ enum {
DIVE_OTU, /* int: in OTUs */
DIVE_MAXCNS, /* int: in % */
DIVE_LOCATION, /* "2nd Cathedral, Lanai" */
+ DIVE_LOC_ICON, /* pixbuf for gps icon */
DIVELIST_COLUMNS
};
@@ -480,28 +484,17 @@ static void temperature_data_func(GtkTreeViewColumn *col,
g_object_set(renderer, "text", buffer, NULL);
}
-static void location_data_func(GtkTreeViewColumn *col,
+static void gpsicon_data_func(GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
int idx;
- char *location;
- char buffer[512];
- struct dive *dive;
- gboolean hasgps = FALSE;
+ GdkPixbuf *icon;
- gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_LOCATION, &location, -1);
- if (idx >0 ) {
- /* make locations with GPS data stand out */
- dive = get_dive(idx);
- if (dive && (dive->latitude.udeg || dive->longitude.udeg)) {
- hasgps = TRUE;
- }
- }
- snprintf(buffer, sizeof(buffer), "%s%s%s", hasgps ? "<i>" : "", location, hasgps ? "</i>" : "");
- g_object_set(renderer, "markup", buffer, NULL);
+ gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_LOC_ICON, &icon, -1);
+ g_object_set(renderer, "pixbuf", icon, NULL);
}
static void nr_data_func(GtkTreeViewColumn *col,
@@ -987,6 +980,14 @@ static void get_suit(struct dive *dive, char **str)
get_string(str, dive->suit);
}
+static GdkPixbuf *get_gps_icon(struct dive *dive)
+{
+ if (dive->latitude.udeg || dive->longitude.udeg)
+ return gdk_pixbuf_from_pixdata(&my_pixbuf, TRUE, NULL);
+ else
+ return NULL;
+}
+
/*
* Set up anything that could have changed due to editing
* of dive information; we need to do this for both models,
@@ -1004,14 +1005,16 @@ static void fill_one_dive(struct dive *dive,
{
char *location, *cylinder, *suit;
GtkTreeModel *othermodel;
+ GdkPixbuf *icon;
get_cylinder(dive, &cylinder);
get_location(dive, &location);
get_suit(dive, &suit);
-
+ icon = get_gps_icon(dive);
gtk_tree_store_set(GTK_TREE_STORE(model), iter,
DIVE_NR, dive->number,
DIVE_LOCATION, location,
+ DIVE_LOC_ICON, icon,
DIVE_CYLINDER, cylinder,
DIVE_RATING, dive->rating,
DIVE_SAC, dive->sac,
@@ -1359,6 +1362,7 @@ static void fill_dive_list(void)
int i, trip_index = 0;
GtkTreeIter iter, parent_iter, lookup, *parent_ptr = NULL;
GtkTreeStore *liststore, *treestore;
+ GdkPixbuf *icon;
/* Do we need to create any dive groups automatically? */
if (autogroup)
@@ -1409,6 +1413,7 @@ static void fill_dive_list(void)
/* store dive */
update_cylinder_related_info(dive);
gtk_tree_store_append(treestore, &iter, parent_ptr);
+ icon = get_gps_icon(dive);
gtk_tree_store_set(treestore, &iter,
DIVE_INDEX, i,
DIVE_NR, dive->number,
@@ -1416,6 +1421,7 @@ static void fill_dive_list(void)
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATION, dive->duration.seconds,
DIVE_LOCATION, dive->location,
+ DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
DIVE_TEMPERATURE, dive->watertemp.mkelvin,
DIVE_SAC, 0,
@@ -1428,6 +1434,7 @@ static void fill_dive_list(void)
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATION, dive->duration.seconds,
DIVE_LOCATION, dive->location,
+ DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
DIVE_TEMPERATURE, dive->watertemp.mkelvin,
DIVE_TOTALWEIGHT, 0,
@@ -1522,7 +1529,7 @@ static struct divelist_column {
[DIVE_SAC] = { N_("SAC"), sac_data_func, NULL, 0, &prefs.visible_cols.sac },
[DIVE_OTU] = { N_("OTU"), otu_data_func, NULL, 0, &prefs.visible_cols.otu },
[DIVE_MAXCNS] = { N_("maxCNS"), cns_data_func, NULL, 0, &prefs.visible_cols.maxcns },
- [DIVE_LOCATION] = { N_("Location"), location_data_func, NULL, ALIGN_LEFT },
+ [DIVE_LOCATION] = { N_("Location"), NULL, NULL, ALIGN_LEFT },
};
@@ -1690,6 +1697,33 @@ static void show_gps_location_cb(GtkWidget *menuitem, struct dive *dive)
}
#endif
+gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data)
+{
+#if HAVE_OSM_GPS_MAP
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeViewColumn *col;
+ int idx;
+ struct dive *dive;
+
+ /* left click ? */
+ if (event->button == 1) {
+ gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(dive_list.tree_view), event->x, event->y, &path, &col, NULL, NULL);
+ /* is it the icon column ? (we passed the correct column in when registering the callback) */
+ if (col == data) {
+ gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
+ gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
+ dive = get_dive(idx);
+ if (dive->latitude.udeg || dive->longitude.udeg)
+ show_gps_location(dive);
+ }
+ gtk_tree_path_free(path);
+ }
+#endif
+ /* keep processing the click */
+ return FALSE;
+}
+
static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
{
gtk_tree_view_expand_all(tree_view);
@@ -1706,6 +1740,7 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
struct dive store_dive;
int totalweight, idx;
char *cylinder_text;
+ GdkPixbuf *icon;
gtk_tree_model_get(MODEL(dive_list), a,
DIVE_INDEX, &idx,
@@ -1722,6 +1757,7 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_OTU, &store_dive.otu,
DIVE_MAXCNS, &store_dive.maxcns,
DIVE_LOCATION, &store_dive.location,
+ DIVE_LOC_ICON, &icon,
-1);
gtk_tree_store_set(STORE(dive_list), b,
DIVE_INDEX, idx,
@@ -1738,6 +1774,7 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_OTU, store_dive.otu,
DIVE_MAXCNS, store_dive.maxcns,
DIVE_LOCATION, store_dive.location,
+ DIVE_LOC_ICON, &icon,
-1);
free(cylinder_text);
free(store_dive.location);
@@ -2682,7 +2719,8 @@ GtkWidget *dive_list_create(void)
G_TYPE_INT, /* SAC */
G_TYPE_INT, /* OTU */
G_TYPE_INT, /* MAXCNS */
- G_TYPE_STRING /* Location */
+ G_TYPE_STRING, /* Location */
+ GDK_TYPE_PIXBUF /* GPS icon */
);
dive_list.treemodel = gtk_tree_store_new(DIVELIST_COLUMNS,
G_TYPE_INT, /* index */
@@ -2699,7 +2737,8 @@ GtkWidget *dive_list_create(void)
G_TYPE_INT, /* SAC */
G_TYPE_INT, /* OTU */
G_TYPE_INT, /* MAXCNS */
- G_TYPE_STRING /* Location */
+ G_TYPE_STRING, /* Location */
+ GDK_TYPE_PIXBUF /* GPS icon */
);
dive_list.model = dive_list.treemodel;
dive_list.tree_view = gtk_tree_view_new_with_model(TREEMODEL(dive_list));
@@ -2728,6 +2767,8 @@ GtkWidget *dive_list_create(void)
dive_list.otu = divelist_column(&dive_list, dl_column + DIVE_OTU);
dive_list.maxcns = divelist_column(&dive_list, dl_column + DIVE_MAXCNS);
dive_list.location = divelist_column(&dive_list, dl_column + DIVE_LOCATION);
+ /* now add the GPS icon to the location column */
+ tree_view_column_add_pixbuf(dive_list.tree_view, gpsicon_data_func, dive_list.location);
fill_dive_list();