From 713c845e5a04a5ea5a41d1d8de3dc5c16b0e8df5 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 22 Jan 2013 19:52:07 -0800 Subject: 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 --- Makefile | 5 +- display-gtk.h | 3 ++ divelist.c | 79 ++++++++++++++++++++++++-------- gtk-gui.c | 14 +++++- satellite.h | 29 ++++++++++++ satellite.png | Bin 0 -> 379 bytes satellite.svg | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 252 insertions(+), 21 deletions(-) create mode 100644 satellite.h create mode 100644 satellite.png create mode 100644 satellite.svg diff --git a/Makefile b/Makefile index 2e264c90d..1610443b4 100644 --- a/Makefile +++ b/Makefile @@ -250,7 +250,10 @@ statistics.o: statistics.c dive.h display.h divelist.h gps.o: gps.c dive.h display.h divelist.h $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(OSMGPSMAPFLAGS) -c gps.c -divelist.o: divelist.c dive.h display.h divelist.h +#satellite.h: satellite.png +# gdk-pixbuf-csource --struct satellite.png > satellite.h + +divelist.o: divelist.c dive.h display.h divelist.h satellite.h $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c print.o: print.c dive.h display.h display-gtk.h diff --git a/display-gtk.h b/display-gtk.h index b889ff1a2..df29ff1d8 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -72,6 +72,8 @@ extern GtkWidget *weightsystem_list_widget(int w_idx); extern GtkWidget *dive_list_create(void); extern void dive_list_destroy(void); +extern gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data); + unsigned int amount_selected; extern void process_selected_dives(void); @@ -95,6 +97,7 @@ typedef gint (*sort_func_t)(GtkTreeModel *model, extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, data_func_t data_func, unsigned int flags); +extern GtkTreeViewColumn *tree_view_column_add_pixbuf(GtkWidget *tree_view, data_func_t data_func, GtkTreeViewColumn *col); GError *uemis_download(const char *path, progressbar_t *progress, GtkDialog *dialog, gboolean force_download); 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 +#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 ? "" : "", location, hasgps ? "" : ""); - 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(); diff --git a/gtk-gui.c b/gtk-gui.c index 7a8f10c68..01615976c 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -343,6 +343,15 @@ void quit(GtkWidget *w, gpointer data) } } +GtkTreeViewColumn *tree_view_column_add_pixbuf(GtkWidget *tree_view, data_func_t data_func, GtkTreeViewColumn *col) +{ + GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(col, renderer, FALSE); + gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, NULL, NULL); + g_signal_connect(tree_view, "button-press-event", G_CALLBACK(icon_click_cb), col); + return col; +} + GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, data_func_t data_func, unsigned int flags) { @@ -370,7 +379,10 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char if (!(flags & UNSORTABLE)) gtk_tree_view_column_set_sort_column_id(col, index); gtk_tree_view_column_set_resizable(col, TRUE); - gtk_tree_view_column_pack_start(col, renderer, TRUE); + /* all but one column have only one renderer - so packing from the end + * makes no difference; for the location column we want to be able to + * prepend the icon in front of the text - so this works perfectly */ + gtk_tree_view_column_pack_end(col, renderer, TRUE); if (data_func) gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL); else diff --git a/satellite.h b/satellite.h new file mode 100644 index 000000000..c13bb0cf4 --- /dev/null +++ b/satellite.h @@ -0,0 +1,29 @@ +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +static const GdkPixdata my_pixbuf = { + 0x47646b50, /* Pixbuf magic: 'GdkP' */ + 24 + 458, /* header length + pixel_data length */ + 0x2010002, /* pixdata_type */ + 44, /* rowstride */ + 11, /* width */ + 16, /* height */ + /* pixel_data: */ + "\12\0\0\0\0\0\0\0""4\0\0\0\216\0\0\0\1\0\0\0\34\0\0\0\254\0\0\0\261\0" + "\0\0\274\0\0\0\207\0\0\0\17\202\0\0\0\0\5\0\0\0\301\0\0\0\377\0\0\0\235" + "\0\0\0\6\0\0\0\14\202\0\0\0\20\4\0\0\0=\0\0\0\260\0\0\0\5\0\0\0.\203" + "\0\0\0\377\10\0\0\0\263\0\0\0\27\0\0\0\234\0\0\0\260\0\0\0M\0\0\0Z\0" + "\0\0e\0\0\0w\204\0\0\0\377\7\0\0\0\265\0\0\0\11\0\0\0\3\0\0\0\257\0\0" + "\0\7\0\0\0\242\0\0\0\245\205\0\0\0\377\6\0\0\0\277\0\0\0\15\0\0\0\222" + "\0\0\0\6\0\0\0\243\0\0\0\261\206\0\0\0\377\5\0\0\0\311\0\0\0\22\0\0\0" + "\15\0\0\0C\0\0\0\232\207\0\0\0\377\4\0\0\0\330\0\0\0\35\0\0\0\0\0\0\0" + "^\210\0\0\0\377\4\0\0\0\332\0\0\0\37\0\0\0\13\0\0\0\345\210\0\0\0\377" + "\4\0\0\0\306\0\0\0\0\0\0\0H\0\0\0\371\206\0\0\0\377\6\0\0\0\341\0\0\0" + "&\0\0\0\0\0\0\0e\0\0\0z\0\0\0\320\203\0\0\0\377\3\0\0\0\371\0\0\0\236" + "\0\0\0\22\202\0\0\0\0\7\0\0\0\272\0\0\0\377\0\0\0\300\0\0\0""0\0\0\0" + "U\0\0\0G\0\0\0\20\203\0\0\0\0\2\0\0\0\14\0\0\0\371\202\0\0\0\377\1\0" + "\0\0R\206\0\0\0\0\1\0\0\0M\203\0\0\0\377\1\0\0\0\256\206\0\0\0\0\1\0" + "\0\0\224\203\0\0\0\377\2\0\0\0\371\0\0\0\23\205\0\0\0\0\1\0\0\0\334\204" + "\0\0\0\377\1\0\0\0h\205\0\0\0\0", +}; + + diff --git a/satellite.png b/satellite.png new file mode 100644 index 000000000..b85b396dc Binary files /dev/null and b/satellite.png differ diff --git a/satellite.svg b/satellite.svg new file mode 100644 index 000000000..3e4c2c578 --- /dev/null +++ b/satellite.svg @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2