27 |
|
|
28 |
#include <math.h> |
#include <math.h> |
29 |
|
|
30 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
31 |
|
#include <hildon/hildon-note.h> |
32 |
|
#include <hildon/hildon-entry.h> |
33 |
|
#include <hildon/hildon-check-button.h> |
34 |
|
#endif |
35 |
|
|
36 |
#if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED) |
#if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED) |
37 |
#error "libxml doesn't support required tree or output" |
#error "libxml doesn't support required tree or output" |
38 |
#endif |
#endif |
39 |
|
|
40 |
#include "gpxview.h" |
#include "gpxview.h" |
41 |
|
|
42 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
43 |
|
#include <hildon/hildon-note.h> |
44 |
|
#endif |
45 |
|
|
46 |
void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean); |
void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean); |
47 |
void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *); |
void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *); |
48 |
|
|
49 |
#define TAG_STATE GTK_STATE_PRELIGHT |
#define TAG_STATE GTK_STATE_PRELIGHT |
50 |
|
|
51 |
|
static GtkWidget *check_button_new_with_label(char *label) { |
52 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
53 |
|
return gtk_check_button_new_with_label(label); |
54 |
|
#else |
55 |
|
GtkWidget *cbut = |
56 |
|
hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); |
57 |
|
gtk_button_set_label(GTK_BUTTON(cbut), label); |
58 |
|
return cbut; |
59 |
|
#endif |
60 |
|
} |
61 |
|
|
62 |
|
static void check_button_set_active(GtkWidget *button, gboolean active) { |
63 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
64 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
65 |
|
#else |
66 |
|
hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active); |
67 |
|
#endif |
68 |
|
} |
69 |
|
|
70 |
|
static gboolean check_button_get_active(GtkWidget *button) { |
71 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
72 |
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
73 |
|
#else |
74 |
|
return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button)); |
75 |
|
#endif |
76 |
|
} |
77 |
|
|
78 |
static notes_t *notes_load(appdata_t *appdata, cache_t *cache) { |
static notes_t *notes_load(appdata_t *appdata, cache_t *cache) { |
79 |
notes_t *notes = NULL; |
notes_t *notes = NULL; |
80 |
xmlDoc *doc = NULL; |
xmlDoc *doc = NULL; |
198 |
char *text, pos_t pos, |
char *text, pos_t pos, |
199 |
gboolean override, gboolean found, |
gboolean override, gboolean found, |
200 |
time_t ftime, gboolean logged) { |
time_t ftime, gboolean logged) { |
201 |
|
|
202 |
|
g_assert(context); |
203 |
|
g_assert(context->cache); |
204 |
|
|
205 |
|
printf("write\n"); |
206 |
|
|
207 |
/* build local path */ |
/* build local path */ |
208 |
int path_len = strlen(context->appdata->image_path) + |
int path_len = strlen(context->appdata->image_path) + |
209 |
2 * strlen(context->cache->id) + 6; |
2 * strlen(context->cache->id) + 6; |
210 |
|
printf("plen = %d\n", path_len); |
211 |
|
|
212 |
char *path = malloc(path_len); |
char *path = malloc(path_len); |
213 |
snprintf(path, path_len, "%s%s/%s.gpx", |
snprintf(path, path_len, "%s%s/%s.gpx", |
214 |
context->appdata->image_path, |
context->appdata->image_path, |
220 |
return -1; |
return -1; |
221 |
} |
} |
222 |
|
|
223 |
|
printf("still al\n"); |
224 |
|
|
225 |
LIBXML_TEST_VERSION; |
LIBXML_TEST_VERSION; |
226 |
|
|
227 |
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
282 |
/* there is a position which differs from the original one */ |
/* there is a position which differs from the original one */ |
283 |
/* or has been changed */ |
/* or has been changed */ |
284 |
|
|
285 |
|
printf("saving notes\n"); |
286 |
|
|
287 |
if(context->notes.modified) { |
if(context->notes.modified) { |
288 |
printf("something has been modified, saving notes\n"); |
printf("something has been modified, saving notes\n"); |
289 |
|
|
295 |
&start, &end, FALSE); |
&start, &end, FALSE); |
296 |
|
|
297 |
pos_t pos; |
pos_t pos; |
298 |
pos.lat = lat_get(context->notes.latw); |
pos.lat = lat_entry_get(context->notes.latw); |
299 |
pos.lon = lon_get(context->notes.lonw); |
pos.lon = lon_entry_get(context->notes.lonw); |
300 |
|
|
301 |
gboolean override = |
gboolean override = |
302 |
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.overridew)); |
check_button_get_active(context->notes.overridew); |
303 |
gboolean found = |
gboolean found = |
304 |
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.foundw)); |
check_button_get_active(context->notes.foundw); |
305 |
gboolean logged = |
gboolean logged = |
306 |
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.loggedw)); |
check_button_get_active(context->notes.loggedw); |
307 |
|
|
308 |
/* required accuracy is 1/60000 degree */ |
if(pos_differ(&pos, &context->cache->pos)) |
309 |
if(((int)(pos.lat * 60000 + .5) != |
printf("position is modified\n"); |
|
(int)(context->cache->pos.lat * 60000 + .5)) || |
|
|
((int)(pos.lon * 60000 + .5) != |
|
|
(int)(context->cache->pos.lon * 60000 + .5))) |
|
|
printf("position is modified %f != %f / %f != %f\n", |
|
|
pos.lat * 60000 + .5, context->cache->pos.lat * 60000 + .5, |
|
|
pos.lon * 60000 + .5, context->cache->pos.lon * 60000 + .5); |
|
310 |
if(override || found) |
if(override || found) |
311 |
printf("flags are set\n"); |
printf("flags are set\n"); |
312 |
if(strlen(text)) |
if(strlen(text)) |
313 |
printf("text is present\n"); |
printf("text is present\n"); |
314 |
|
|
315 |
/* check if the notes are empty */ |
/* check if the notes are empty */ |
316 |
if(((int)(pos.lat * 60000 + .5) == |
if(!pos_differ(&pos, &context->cache->pos) && |
|
(int)(context->cache->pos.lat * 60000 + .5)) && |
|
|
((int)(pos.lon * 60000 + .5) == |
|
|
(int)(context->cache->pos.lon * 60000 + .5)) && |
|
317 |
!override && !found && !logged && (strlen(text) == 0)) { |
!override && !found && !logged && (strlen(text) == 0)) { |
318 |
printf("notes are in default state, removing them if present\n"); |
printf("notes are in default state, removing them if present\n"); |
319 |
|
|
366 |
/* we have to do two things here: */ |
/* we have to do two things here: */ |
367 |
/* - update the notes.xml file on disk */ |
/* - update the notes.xml file on disk */ |
368 |
/* - update the notes entry in the loaded gpx tree */ |
/* - update the notes entry in the loaded gpx tree */ |
369 |
|
|
370 |
/* update file on disk */ |
/* update file on disk */ |
371 |
notes_write_file(context, text, pos, override, found, |
notes_write_file(context, text, pos, override, found, |
372 |
context->notes.ftime, logged); |
context->notes.ftime, logged); |
373 |
|
|
374 |
/* search for matching caches and replace note there */ |
/* search for matching caches and replace note there */ |
375 |
notes_t *note = NULL; |
notes_t *note = NULL; |
376 |
gpx_t *gpx = context->appdata->gpx; |
gpx_t *gpx = context->appdata->gpx; |
461 |
static void ftime_update(GtkWidget *widget, cache_context_t *context, |
static void ftime_update(GtkWidget *widget, cache_context_t *context, |
462 |
gboolean update) { |
gboolean update) { |
463 |
/* check if it has been selected */ |
/* check if it has been selected */ |
464 |
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { |
if(check_button_get_active(widget)) { |
465 |
printf("set active\n"); |
printf("set active\n"); |
466 |
|
|
467 |
if(update) |
if(update) |
493 |
printf("was foundw\n"); |
printf("was foundw\n"); |
494 |
|
|
495 |
/* about to remove "found" flag -> ask for confirmation */ |
/* about to remove "found" flag -> ask for confirmation */ |
496 |
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { |
if(!check_button_get_active(widget)) { |
497 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
498 |
GtkWidget *dialog = gtk_message_dialog_new( |
GtkWidget *dialog = gtk_message_dialog_new( |
499 |
GTK_WINDOW(context->appdata->window), |
GTK_WINDOW(context->appdata->window), |
500 |
GTK_DIALOG_DESTROY_WITH_PARENT, |
GTK_DIALOG_DESTROY_WITH_PARENT, |
508 |
if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog))) |
if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog))) |
509 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); |
510 |
|
|
511 |
|
#else |
512 |
|
GtkWidget *dialog = |
513 |
|
hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window), |
514 |
|
_("Do you really want to remove the \"found\" flag? " |
515 |
|
"This will void the recorded date of your find!")); |
516 |
|
|
517 |
|
/* set the active flag again if the user answered "no" */ |
518 |
|
if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog))) |
519 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); |
520 |
|
#endif |
521 |
|
|
522 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
523 |
} |
} |
524 |
|
|
529 |
printf("was loggedw\n"); |
printf("was loggedw\n"); |
530 |
|
|
531 |
/* about to remove "found" flag -> ask for confirmation */ |
/* about to remove "found" flag -> ask for confirmation */ |
532 |
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { |
if(!check_button_get_active(widget)) { |
533 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
534 |
GtkWidget *dialog = gtk_message_dialog_new( |
GtkWidget *dialog = gtk_message_dialog_new( |
535 |
GTK_WINDOW(context->appdata->window), |
GTK_WINDOW(context->appdata->window), |
536 |
GTK_DIALOG_DESTROY_WITH_PARENT, |
GTK_DIALOG_DESTROY_WITH_PARENT, |
549 |
gtk_widget_set_sensitive(context->notes.foundw, TRUE); |
gtk_widget_set_sensitive(context->notes.foundw, TRUE); |
550 |
} |
} |
551 |
|
|
552 |
|
#else |
553 |
|
GtkWidget *dialog = |
554 |
|
hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window), |
555 |
|
_("Do you really want to remove the \"logged\" flag? " |
556 |
|
"This may cause problems on your next Garmin Field " |
557 |
|
"Notes upload!")); |
558 |
|
|
559 |
|
/* set the active flag again if the user answered "no" */ |
560 |
|
if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog))) |
561 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); |
562 |
|
else { |
563 |
|
gtk_widget_set_sensitive(widget, FALSE); |
564 |
|
gtk_widget_set_sensitive(context->notes.foundw, TRUE); |
565 |
|
} |
566 |
|
|
567 |
|
#endif |
568 |
|
|
569 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
570 |
} |
} |
571 |
} |
} |
619 |
/* -------------- custom coordinate ---------------- */ |
/* -------------- custom coordinate ---------------- */ |
620 |
|
|
621 |
GtkWidget *table = gtk_table_new(2, 4, FALSE); |
GtkWidget *table = gtk_table_new(2, 4, FALSE); |
622 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
623 |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
624 |
|
#endif |
625 |
|
|
626 |
gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16); |
gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16); |
627 |
|
|
628 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
629 |
gtk_label_new(_("New coordinate:")), 0, 1, 0, 1); |
gtk_label_new(_("New coordinate:")), 0, 1, 0, 1); |
630 |
context->notes.overridew = gtk_check_button_new_with_label(_("Override")); |
context->notes.overridew = check_button_new_with_label(_("Override")); |
631 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.overridew), |
check_button_set_active(context->notes.overridew, |
632 |
cache->notes && cache->notes->override); |
cache->notes && cache->notes->override); |
633 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
634 |
context->notes.overridew, 0, 1, 1, 2); |
context->notes.overridew, 2, 3, 0, 1); |
635 |
|
|
636 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 2); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 2); |
637 |
|
|
638 |
context->notes.foundw = gtk_check_button_new_with_label(_("Found")); |
context->notes.foundw = check_button_new_with_label(_("Found")); |
639 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.foundw), |
check_button_set_active(context->notes.foundw, |
640 |
cache->notes && cache->notes->found); |
cache->notes && cache->notes->found); |
641 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw); |
642 |
|
|
643 |
context->notes.loggedw = gtk_check_button_new_with_label(_("Logged")); |
context->notes.loggedw = check_button_new_with_label(_("Logged")); |
644 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.loggedw), |
check_button_set_active(context->notes.loggedw, |
645 |
cache->notes && cache->notes->logged); |
cache->notes && cache->notes->logged); |
646 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw); |
647 |
|
|
648 |
gtk_table_attach_defaults(GTK_TABLE(table), hbox, 3, 4, 0, 1); |
gtk_table_attach_defaults(GTK_TABLE(table), hbox, 3, 4, 0, 1); |
654 |
gtk_widget_set_sensitive(context->notes.foundw, FALSE); |
gtk_widget_set_sensitive(context->notes.foundw, FALSE); |
655 |
|
|
656 |
context->notes.datew = gtk_label_new(""); |
context->notes.datew = gtk_label_new(""); |
657 |
gtk_misc_set_alignment(GTK_MISC(context->notes.datew), 0.0f, 0.5f); |
gtk_misc_set_alignment(GTK_MISC(context->notes.datew), 0.5f, 0.5f); |
658 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
659 |
context->notes.datew, 3, 4, 1, 2); |
context->notes.datew, 3, 4, 1, 2); |
660 |
ftime_update(context->notes.foundw, context, FALSE); |
ftime_update(context->notes.foundw, context, FALSE); |
663 |
if(cache->notes) pos = cache->notes->pos; |
if(cache->notes) pos = cache->notes->pos; |
664 |
|
|
665 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
666 |
context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1); |
context->notes.latw = lat_entry_new(pos.lat), 0, 1, 1, 2); |
667 |
g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event", |
g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event", |
668 |
G_CALLBACK(focus_out), context); |
G_CALLBACK(focus_out), context); |
669 |
|
|
670 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
671 |
context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2); |
context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2); |
672 |
g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event", |
g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event", |
673 |
G_CALLBACK(focus_out), context); |
G_CALLBACK(focus_out), context); |
674 |
|
|
675 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
676 |
hbox = gtk_hbox_new(FALSE, 0); |
hbox = gtk_hbox_new(FALSE, 0); |
677 |
gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0); |
678 |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
679 |
|
#else |
680 |
|
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
681 |
|
#endif |
682 |
|
|
683 |
#ifndef USE_PANNABLE_AREA |
#ifndef USE_PANNABLE_AREA |
684 |
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
700 |
hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer); |
hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer); |
701 |
#endif |
#endif |
702 |
|
|
703 |
|
/* if the cache has been marked found in the logs already, there's */ |
704 |
|
/* no need/use to be able to change all this */ |
705 |
|
if(cache->found) { |
706 |
|
gtk_widget_set_sensitive(table, FALSE); |
707 |
|
gtk_widget_set_sensitive(view, FALSE); |
708 |
|
} |
709 |
|
|
710 |
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD); |
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD); |
711 |
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE); |
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE); |
712 |
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 ); |
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 ); |
765 |
|
|
766 |
pos_t notes_get_pos(cache_context_t *context) { |
pos_t notes_get_pos(cache_context_t *context) { |
767 |
pos_t pos = context->cache->pos; |
pos_t pos = context->cache->pos; |
768 |
if(gtk_toggle_button_get_active( |
if(check_button_get_active(context->notes.overridew)) { |
769 |
GTK_TOGGLE_BUTTON(context->notes.overridew))) { |
pos.lat = lat_entry_get(context->notes.latw); |
770 |
pos.lat = lat_get(context->notes.latw); |
pos.lon = lon_entry_get(context->notes.lonw); |
|
pos.lon = lon_get(context->notes.lonw); |
|
771 |
} |
} |
772 |
return pos; |
return pos; |
773 |
} |
} |
774 |
|
|
775 |
gboolean notes_get_override(cache_context_t *context) { |
gboolean notes_get_override(cache_context_t *context) { |
776 |
/* get override value */ |
/* get override value */ |
777 |
return gtk_toggle_button_get_active( |
return check_button_get_active(context->notes.overridew); |
|
GTK_TOGGLE_BUTTON(context->notes.overridew)); |
|
|
|
|
778 |
} |
} |
779 |
|
|
780 |
typedef struct { |
typedef struct { |
927 |
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0); |
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0); |
928 |
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
929 |
GtkWidget *button = gtk_button_new_with_label(_("Browse")); |
GtkWidget *button = gtk_button_new_with_label(_("Browse")); |
930 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
931 |
|
hildon_gtk_widget_set_theme_size(button, |
932 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
933 |
|
#endif |
934 |
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
935 |
GTK_SIGNAL_FUNC(on_browse), (gpointer)&context); |
GTK_SIGNAL_FUNC(on_browse), (gpointer)&context); |
936 |
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0); |
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0); |