19 |
|
|
20 |
#include <stdio.h> |
#include <stdio.h> |
21 |
#include <string.h> |
#include <string.h> |
22 |
|
#include <errno.h> |
23 |
|
|
24 |
#include <glib/gunicode.h> |
#include <glib/gunicode.h> |
25 |
|
|
49 |
|
|
50 |
#define TAG_STATE GTK_STATE_PRELIGHT |
#define TAG_STATE GTK_STATE_PRELIGHT |
51 |
|
|
|
static GtkWidget *check_button_new_with_label(char *label) { |
|
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
|
|
return gtk_check_button_new_with_label(label); |
|
|
#else |
|
|
GtkWidget *cbut = |
|
|
hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); |
|
|
gtk_button_set_label(GTK_BUTTON(cbut), label); |
|
|
return cbut; |
|
|
#endif |
|
|
} |
|
|
|
|
|
static void check_button_set_active(GtkWidget *button, gboolean active) { |
|
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
|
|
#else |
|
|
hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active); |
|
|
#endif |
|
|
} |
|
|
|
|
|
static gboolean check_button_get_active(GtkWidget *button) { |
|
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
|
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
|
|
#else |
|
|
return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button)); |
|
|
#endif |
|
|
} |
|
|
|
|
52 |
static notes_t *notes_load(appdata_t *appdata, cache_t *cache) { |
static notes_t *notes_load(appdata_t *appdata, cache_t *cache) { |
53 |
notes_t *notes = NULL; |
notes_t *notes = NULL; |
54 |
xmlDoc *doc = NULL; |
xmlDoc *doc = NULL; |
172 |
char *text, pos_t pos, |
char *text, pos_t pos, |
173 |
gboolean override, gboolean found, |
gboolean override, gboolean found, |
174 |
time_t ftime, gboolean logged) { |
time_t ftime, gboolean logged) { |
175 |
|
|
176 |
|
g_assert(context); |
177 |
|
g_assert(context->cache); |
178 |
|
|
179 |
/* build local path */ |
/* build local path */ |
180 |
int path_len = strlen(context->appdata->image_path) + |
int path_len = strlen(context->appdata->image_path) + |
181 |
2 * strlen(context->cache->id) + 6; |
2 * strlen(context->cache->id) + 6; |
182 |
|
|
183 |
char *path = malloc(path_len); |
char *path = malloc(path_len); |
184 |
snprintf(path, path_len, "%s%s/%s.gpx", |
snprintf(path, path_len, "%s%s/%s.gpx", |
185 |
context->appdata->image_path, |
context->appdata->image_path, |
252 |
/* or has been changed */ |
/* or has been changed */ |
253 |
|
|
254 |
if(context->notes.modified) { |
if(context->notes.modified) { |
255 |
|
#ifdef USE_STACKABLE_WINDOW |
256 |
|
context->notes_have_been_changed = TRUE; |
257 |
|
#endif |
258 |
|
|
259 |
printf("something has been modified, saving notes\n"); |
printf("something has been modified, saving notes\n"); |
260 |
|
|
261 |
GtkTextIter start; |
GtkTextIter start; |
266 |
&start, &end, FALSE); |
&start, &end, FALSE); |
267 |
|
|
268 |
pos_t pos; |
pos_t pos; |
269 |
pos.lat = lat_get(context->notes.latw); |
pos.lat = lat_entry_get(context->notes.latw); |
270 |
pos.lon = lon_get(context->notes.lonw); |
pos.lon = lon_entry_get(context->notes.lonw); |
271 |
|
|
272 |
gboolean override = |
gboolean override = |
273 |
check_button_get_active(context->notes.overridew); |
check_button_get_active(context->notes.overridew); |
276 |
gboolean logged = |
gboolean logged = |
277 |
check_button_get_active(context->notes.loggedw); |
check_button_get_active(context->notes.loggedw); |
278 |
|
|
279 |
/* required accuracy is 1/60000 degree */ |
if(pos_differ(&pos, &context->cache->pos)) |
280 |
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); |
|
281 |
if(override || found) |
if(override || found) |
282 |
printf("flags are set\n"); |
printf("flags are set\n"); |
283 |
if(strlen(text)) |
if(strlen(text)) |
284 |
printf("text is present\n"); |
printf("text is present\n"); |
285 |
|
|
286 |
/* check if the notes are empty */ |
/* check if the notes are empty */ |
287 |
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)) && |
|
288 |
!override && !found && !logged && (strlen(text) == 0)) { |
!override && !found && !logged && (strlen(text) == 0)) { |
289 |
printf("notes are in default state, removing them if present\n"); |
printf("notes are in default state, removing them if present\n"); |
290 |
|
|
337 |
/* we have to do two things here: */ |
/* we have to do two things here: */ |
338 |
/* - update the notes.xml file on disk */ |
/* - update the notes.xml file on disk */ |
339 |
/* - update the notes entry in the loaded gpx tree */ |
/* - update the notes entry in the loaded gpx tree */ |
340 |
|
|
341 |
/* update file on disk */ |
/* update file on disk */ |
342 |
notes_write_file(context, text, pos, override, found, |
notes_write_file(context, text, pos, override, found, |
343 |
context->notes.ftime, logged); |
context->notes.ftime, logged); |
344 |
|
|
345 |
/* search for matching caches and replace note there */ |
/* search for matching caches and replace note there */ |
346 |
notes_t *note = NULL; |
notes_t *note = NULL; |
347 |
gpx_t *gpx = context->appdata->gpx; |
gpx_t *gpx = context->appdata->gpx; |
563 |
} |
} |
564 |
#endif |
#endif |
565 |
|
|
566 |
|
#ifndef FREMANTLE |
567 |
static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event, |
static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event, |
568 |
gpointer data) { |
gpointer data) { |
569 |
cache_context_t *context = (cache_context_t*)data; |
cache_context_t *context = (cache_context_t*)data; |
575 |
|
|
576 |
return FALSE; |
return FALSE; |
577 |
} |
} |
578 |
|
#else |
579 |
|
static void coo_changed(GtkWidget *widget, gpointer data) { |
580 |
|
notes_save((cache_context_t*)data); |
581 |
|
} |
582 |
|
#endif |
583 |
|
|
584 |
GtkWidget *cache_notes(cache_context_t *context) { |
GtkWidget *cache_notes(cache_context_t *context) { |
585 |
cache_t *cache = context->cache; |
cache_t *cache = context->cache; |
598 |
GtkWidget *table = gtk_table_new(2, 4, FALSE); |
GtkWidget *table = gtk_table_new(2, 4, FALSE); |
599 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
600 |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
|
gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16); |
|
601 |
#endif |
#endif |
602 |
|
|
603 |
|
gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16); |
604 |
|
|
605 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
606 |
gtk_label_new(_("New coordinate:")), 0, 1, 0, 1); |
gtk_label_new(_("New coordinate:")), 0, 1, 0, 1); |
607 |
context->notes.overridew = check_button_new_with_label(_("Override")); |
context->notes.overridew = check_button_new_with_label(_("Override")); |
608 |
check_button_set_active(context->notes.overridew, |
check_button_set_active(context->notes.overridew, |
609 |
cache->notes && cache->notes->override); |
cache->notes && cache->notes->override); |
610 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
611 |
context->notes.overridew, 0, 1, 1, 2); |
context->notes.overridew, 2, 3, 0, 1); |
612 |
|
|
613 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 2); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 2); |
614 |
|
|
639 |
pos_t pos = gpx_cache_pos(cache); |
pos_t pos = gpx_cache_pos(cache); |
640 |
if(cache->notes) pos = cache->notes->pos; |
if(cache->notes) pos = cache->notes->pos; |
641 |
|
|
642 |
gtk_table_attach_defaults(GTK_TABLE(table), |
context->notes.latw = lat_entry_new(pos.lat); |
643 |
context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1); |
context->notes.lonw = lon_entry_new(pos.lon); |
644 |
|
GtkWidget *picker = |
645 |
|
preset_coordinate_picker(context->appdata, |
646 |
|
context->notes.latw, context->notes.lonw); |
647 |
|
|
648 |
|
/* on fremantle we react on "changed" event instead since this */ |
649 |
|
/* means that editing is done */ |
650 |
|
#ifdef FREMANTLE |
651 |
|
g_signal_connect(G_OBJECT(context->notes.latw), "changed", |
652 |
|
G_CALLBACK(coo_changed), context); |
653 |
|
g_signal_connect(G_OBJECT(context->notes.lonw), "changed", |
654 |
|
G_CALLBACK(coo_changed), context); |
655 |
|
#else |
656 |
g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event", |
g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event", |
657 |
G_CALLBACK(focus_out), context); |
G_CALLBACK(focus_out), context); |
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2); |
|
658 |
g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event", |
g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event", |
659 |
G_CALLBACK(focus_out), context); |
G_CALLBACK(focus_out), context); |
660 |
|
#endif |
661 |
|
|
662 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
663 |
|
|
664 |
|
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->notes.latw); |
665 |
|
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->notes.lonw); |
666 |
|
gtk_box_pack_start_defaults(GTK_BOX(ihbox), picker); |
667 |
|
|
668 |
|
gtk_table_attach_defaults(GTK_TABLE(table), |
669 |
|
ihbox, 0, 3, 1, 2); |
670 |
|
|
671 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
672 |
hbox = gtk_hbox_new(FALSE, 0); |
hbox = gtk_hbox_new(FALSE, 0); |
696 |
hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer); |
hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer); |
697 |
#endif |
#endif |
698 |
|
|
699 |
|
/* if the cache has been marked found in the logs already, there's */ |
700 |
|
/* no need/use to be able to change all this */ |
701 |
|
if(cache->found) { |
702 |
|
check_button_set_active(context->notes.loggedw, TRUE); |
703 |
|
check_button_set_active(context->notes.foundw, TRUE); |
704 |
|
gtk_widget_set_sensitive(table, FALSE); |
705 |
|
|
706 |
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); |
707 |
|
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE); |
708 |
|
} else |
709 |
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE); |
710 |
|
|
711 |
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); |
|
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 ); |
713 |
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 2 ); |
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 2 ); |
714 |
|
|
756 |
return vbox; |
return vbox; |
757 |
} |
} |
758 |
|
|
759 |
|
void notes_logged(cache_context_t *context) { |
760 |
|
|
761 |
|
/* if you log it, you sure also found it */ |
762 |
|
check_button_set_active(context->notes.foundw, TRUE); |
763 |
|
check_button_set_active(context->notes.loggedw, TRUE); |
764 |
|
|
765 |
|
gtk_widget_set_sensitive(context->notes.foundw, FALSE); |
766 |
|
gtk_widget_set_sensitive(context->notes.loggedw, TRUE); |
767 |
|
|
768 |
|
ftime_update(context->notes.foundw, context, TRUE); |
769 |
|
} |
770 |
|
|
771 |
void notes_free(notes_t *notes) { |
void notes_free(notes_t *notes) { |
772 |
if(notes) { |
if(notes) { |
773 |
if(notes->text) xmlFree(notes->text); |
if(notes->text) xmlFree(notes->text); |
778 |
pos_t notes_get_pos(cache_context_t *context) { |
pos_t notes_get_pos(cache_context_t *context) { |
779 |
pos_t pos = context->cache->pos; |
pos_t pos = context->cache->pos; |
780 |
if(check_button_get_active(context->notes.overridew)) { |
if(check_button_get_active(context->notes.overridew)) { |
781 |
pos.lat = lat_get(context->notes.latw); |
pos.lat = lat_entry_get(context->notes.latw); |
782 |
pos.lon = lon_get(context->notes.lonw); |
pos.lon = lon_entry_get(context->notes.lonw); |
783 |
} |
} |
784 |
return pos; |
return pos; |
785 |
} |
} |
793 |
GtkWidget *info_label; |
GtkWidget *info_label; |
794 |
GtkWidget *dialog; |
GtkWidget *dialog; |
795 |
appdata_t *appdata; |
appdata_t *appdata; |
|
GtkWidget *path_label; |
|
796 |
} export_context_t; |
} export_context_t; |
797 |
|
|
|
static void on_browse(GtkWidget *widget, gpointer data) { |
|
|
GtkWidget *dialog; |
|
|
|
|
|
export_context_t *context = (export_context_t*)data; |
|
|
|
|
|
#ifdef USE_MAEMO |
|
|
dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(context->dialog), |
|
|
GTK_FILE_CHOOSER_ACTION_SAVE); |
|
|
#else |
|
|
dialog = gtk_file_chooser_dialog_new(_("Save POI database"), |
|
|
GTK_WINDOW(context->dialog), |
|
|
GTK_FILE_CHOOSER_ACTION_SAVE, |
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
|
NULL); |
|
|
#endif |
|
|
|
|
|
printf("set filename <%s>\n", context->appdata->fieldnotes_path); |
|
|
|
|
|
if(!g_file_test(context->appdata->fieldnotes_path, G_FILE_TEST_EXISTS)) { |
|
|
char *last_sep = strrchr(context->appdata->fieldnotes_path, '/'); |
|
|
if(last_sep) { |
|
|
*last_sep = 0; // seperate path from file |
|
|
|
|
|
/* the user just created a new document */ |
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
|
|
context->appdata->fieldnotes_path); |
|
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), last_sep+1); |
|
|
|
|
|
/* restore full filename */ |
|
|
*last_sep = '/'; |
|
|
} |
|
|
} else |
|
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), |
|
|
context->appdata->fieldnotes_path); |
|
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) { |
|
|
gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
|
|
if(name) { |
|
|
free(context->appdata->fieldnotes_path); |
|
|
context->appdata->fieldnotes_path = strdup(name); |
|
|
gtk_label_set_text(GTK_LABEL(context->path_label), |
|
|
context->appdata->fieldnotes_path); |
|
|
} |
|
|
} |
|
|
|
|
|
gtk_widget_destroy (dialog); |
|
|
} |
|
|
|
|
798 |
typedef struct log_chain_s { |
typedef struct log_chain_s { |
799 |
cache_t *cache; |
cache_t *cache; |
800 |
struct log_chain_s *next; |
struct log_chain_s *next; |
884 |
/* ------------------ path/file ------------------ */ |
/* ------------------ path/file ------------------ */ |
885 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new()); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new()); |
886 |
|
|
887 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), |
888 |
GtkWidget *label = gtk_label_new(_("Export to:")); |
export_file(_("Save POI database"), &appdata->fieldnotes_path)); |
|
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
|
|
GtkWidget *button = gtk_button_new_with_label(_("Browse")); |
|
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
|
|
hildon_gtk_widget_set_theme_size(button, |
|
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
|
|
#endif |
|
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_browse), (gpointer)&context); |
|
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
|
|
|
|
|
context.path_label = gtk_label_new(appdata->fieldnotes_path); |
|
|
gtk_misc_set_alignment(GTK_MISC(context.path_label), 0.f, 0.5f); |
|
|
gtk_label_set_ellipsize(GTK_LABEL(context.path_label), |
|
|
PANGO_ELLIPSIZE_MIDDLE); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), context.path_label); |
|
889 |
|
|
890 |
label = gtk_label_new(_("(a %s in the filename will be replaced by the " |
GtkWidget *label = |
891 |
"current date and time)")); |
gtk_label_new(_("(a %s in the filename will be replaced by the " |
892 |
|
"current date and time)")); |
893 |
gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD); |
gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD); |
894 |
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
895 |
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
908 |
time_t now = time(NULL); |
time_t now = time(NULL); |
909 |
struct tm *tm_now = localtime(&now); |
struct tm *tm_now = localtime(&now); |
910 |
char now_str[32]; |
char now_str[32]; |
911 |
strftime(now_str, sizeof(now_str)-1, "%F_%H:%M", tm_now); |
strftime(now_str, sizeof(now_str)-1, "%F_%H-%M", tm_now); |
912 |
char *fname = g_strdup_printf(appdata->fieldnotes_path, now_str); |
char *fname = g_strdup_printf(appdata->fieldnotes_path, now_str); |
913 |
|
|
914 |
printf("--- about to export logs to %s ---\n", fname); |
printf("--- about to export logs to %s ---\n", fname); |
915 |
FILE *file = fopen(fname, "w"); |
FILE *file = fopen(fname, "w"); |
916 |
g_free(fname); |
g_free(fname); |
917 |
|
|
918 |
if(file) { |
if(file) { |
|
|
|
919 |
llog = log; |
llog = log; |
920 |
while(llog) { |
while(llog) { |
921 |
printf("Exporting %s\n", llog->cache->id); |
printf("Exporting %s\n", llog->cache->id); |
1005 |
} |
} |
1006 |
|
|
1007 |
fclose(file); |
fclose(file); |
1008 |
} |
} else |
1009 |
|
errorf(_("Can't open file:\n\n%s"), strerror(errno)); |
1010 |
|
|
1011 |
} else { |
} else { |
1012 |
/* restore old path, in case it has been altered but not been used */ |
/* restore old path, in case it has been altered but not been used */ |
1013 |
free(appdata->fieldnotes_path); |
free(appdata->fieldnotes_path); |