-
Notifications
You must be signed in to change notification settings - Fork 18
/
gui.c
1420 lines (1231 loc) · 48.1 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* gui.c
* Written by Daniel Foote.
* Started Feb 2005.
*
* The base of this file was generated with Glade, and then
* hand edited by me for some strange reason.
*
* This file contains the code to create, generate, and look after
* a GTK GUI for the photo correlation program. */
/* This is "basically" the GUI version of it. The only other
* part of the gui program is main-gui.c, but that ended up
* being little more than a "stub" to get the GUI up and running. */
/* Copyright 2005 Daniel Foote.
*
* This file is part of gpscorrelate.
*
* gpscorrelate is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gpscorrelate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gpscorrelate; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "i18n.h"
#include "gpsstructure.h"
#include "gui.h"
#include "exif-gps.h"
#include "gpx-read.h"
#include "correlate.h"
/* Declare all our widgets. Global to this module. */
GtkWidget *MatchWindow;
GtkWidget *WindowHBox;
GtkWidget *ControlsVBox;
GtkWidget *AddPhotosFrame;
GtkWidget *AddPhotosAlignment;
GtkWidget *AddPhotosVBox;
GtkWidget *PhotoAddButton;
GtkWidget *PhotoRemoveButton;
GtkWidget *AddPhotosLabel;
GtkWidget *GPSDataFrame;
GtkWidget *GPSDataAlignment;
GtkWidget *GPSDataVBox;
GtkWidget *GPSSelectedLabel;
GtkWidget *SelectGPSButton;
GtkWidget *GPSDataLabel;
GtkWidget *OptionsFrame;
GtkWidget *OptionsAlignment;
GtkWidget *OptionsVBox;
GtkWidget *InterpolateCheck;
GtkWidget *NoWriteCheck;
GtkWidget *NoMtimeCheck;
GtkWidget *BetweenSegmentsCheck;
GtkWidget *DegMinSecsCheck;
GtkWidget *OptionsTable;
GtkWidget *MaxGapTimeLabel;
GtkWidget *TimeZoneLabel;
GtkWidget *PhotoOffsetLabel;
GtkWidget *GPSDatumLabel;
GtkWidget *GapTimeEntry;
GtkWidget *TimeZoneEntry;
GtkWidget *PhotoOffsetEntry;
GtkWidget *GPSDatumEntry;
GtkWidget *OptionsFrameLable;
GtkWidget *CorrelateFrame;
GtkWidget *CorrelateAlignment;
GtkWidget *CorrelateButton;
GtkWidget *CorrelateLabel;
GtkWidget *OtherOptionsFrame;
GtkWidget *OtherOptionsAlignment;
GtkWidget *OtherOptionsLabel;
GtkWidget *StripGPSButton;
GtkWidget *PhotoListVBox;
GtkWidget *PhotoListScroll;
GtkWidget *PhotoList;
GtkTooltips *tooltips;
/* Enum and other stuff for the Photo list box. */
enum
{
LIST_FILENAME,
LIST_LAT,
LIST_LONG,
LIST_ELEV,
LIST_TIME,
LIST_STATE,
LIST_POINTER,
LIST_NOCOLUMNS
};
GtkListStore *PhotoListStore;
GtkCellRenderer *PhotoListRenderer;
GtkTreeViewColumn *FileColumn;
GtkTreeViewColumn *LatColumn;
GtkTreeViewColumn *LongColumn;
GtkTreeViewColumn *ElevColumn;
GtkTreeViewColumn *TimeColumn;
GtkTreeViewColumn *StateColumn;
/* Structure and variables for holding the list of
* photos in memory. */
struct GUIPhotoList {
char* Filename;
char* Time;
GtkTreeIter ListPointer;
struct GUIPhotoList* Next;
};
struct GUIPhotoList* FirstPhoto = NULL;
struct GUIPhotoList* LastPhoto = NULL;
struct GPSTrack* GPSData; // Array of track entries; empty entry is last
int NumTracks; // Number of entries at GPSData
static const char* const ConfigDefaults[] = {
"interpolate", "true",
"dontwrite", "false",
"nochangemtime", "false",
"betweensegments", "false",
"writeddmmss", "true",
"maxgap", "0",
"timezone", "+0:00",
"photooffset", "0",
"gpsdatum", "WGS-84",
"gpxopendir", "",
"photoopendir", "",
NULL, NULL
};
GKeyFile* GUISettings;
char* SettingsFilename;
gchar* GPXOpenDir = NULL;
gchar* PhotoOpenDir = NULL;
static gboolean DestroyWindow(GtkWidget *Widget, GdkEvent *Event, gpointer Data);
static void AddPhotosButtonPress(GtkWidget *Widget, gpointer Data);
static void AddPhotoToList(const char* Filename);
static void RemovePhotosButtonPress( GtkWidget *Widget, gpointer Data );
static void SetListItem(GtkTreeIter* Iter, const char* Filename,
const char* Time, double Lat, double Long, double Elev,
const char* PassedState, int IncludesGPS);
static void SelectGPSButtonPress( GtkWidget *Widget, gpointer Data );
static void CorrelateButtonPress( GtkWidget *Widget, gpointer Data );
static void StripGPSButtonPress( GtkWidget *Widget, gpointer Data );
static void GtkGUIUpdate(void);
/* Load settings, insert defaults. */
void LoadSettings(void)
{
/* Generate the filename. */
const char* UserHomeDir = g_get_user_config_dir();
const int FilenameLength = strlen(UserHomeDir) + 30;
SettingsFilename = (char*) malloc(sizeof(char) * FilenameLength);
snprintf(SettingsFilename, FilenameLength, "%s%c.gpscorrelaterc", UserHomeDir, G_DIR_SEPARATOR);
/* Create a new key file. */
GUISettings = g_key_file_new();
if (!g_key_file_load_from_file(GUISettings, SettingsFilename, G_KEY_FILE_KEEP_COMMENTS, NULL))
{
/* Unable to load the file. Oh well. */
}
/* Now create all the default settings. */
int i = 0;
while (ConfigDefaults[i])
{
/* If the setting doesn't exist, set the default. */
if (NULL == g_key_file_get_value(GUISettings, "default", ConfigDefaults[i], NULL))
{
g_key_file_set_value(GUISettings, "default", ConfigDefaults[i], ConfigDefaults[i+1]);
}
i += 2;
}
/* Fetch the directory settings from the file. */
PhotoOpenDir = g_key_file_get_value(GUISettings, "default", "photoopendir", NULL);
GPXOpenDir = g_key_file_get_value(GUISettings, "default", "gpxopendir", NULL);
}
void SaveSettings(void)
{
/* Save the settings to file, and deallocate the settings. */
FILE* OutputFile;
OutputFile = fopen(SettingsFilename, "w");
if (OutputFile)
{
gsize SettingsLength = 0;
gchar* SettingsString = g_key_file_to_data(GUISettings, &SettingsLength, NULL);
fwrite((void*)SettingsString, sizeof(gchar), (size_t)SettingsLength, OutputFile);
fclose(OutputFile);
g_free(SettingsString);
}
free(SettingsFilename);
}
GtkWidget* CreateMatchWindow (void)
{
/* Load the settings. */
LoadSettings();
/* Get our tooltips ready. */
tooltips = gtk_tooltips_new ();
/* Start with the window itself. */
MatchWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
char title[40];
snprintf(title, sizeof(title), _("GPS Photo Correlate %s"), PACKAGE_VERSION);
gtk_window_set_title (GTK_WINDOW (MatchWindow), title);
gtk_window_set_default_size (GTK_WINDOW (MatchWindow), 792, -1);
g_signal_connect (G_OBJECT (MatchWindow), "delete_event",
G_CALLBACK (DestroyWindow), NULL);
WindowHBox = gtk_hbox_new (FALSE, 0);
gtk_widget_show (WindowHBox);
gtk_container_add (GTK_CONTAINER (MatchWindow), WindowHBox);
/* The controls side of the window. */
ControlsVBox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (ControlsVBox);
gtk_box_pack_start (GTK_BOX (WindowHBox), ControlsVBox, FALSE, TRUE, 0);
/* Add/remove photos area. */
AddPhotosFrame = gtk_frame_new (NULL);
gtk_widget_show (AddPhotosFrame);
gtk_box_pack_start (GTK_BOX (ControlsVBox), AddPhotosFrame, FALSE, FALSE, 0);
AddPhotosAlignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (AddPhotosAlignment);
gtk_container_add (GTK_CONTAINER (AddPhotosFrame), AddPhotosAlignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (AddPhotosAlignment), 0, 4, 12, 4);
AddPhotosVBox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (AddPhotosVBox);
gtk_container_add (GTK_CONTAINER (AddPhotosAlignment), AddPhotosVBox);
PhotoAddButton = gtk_button_new_with_mnemonic (_("Add..."));
gtk_widget_show (PhotoAddButton);
gtk_box_pack_start (GTK_BOX (AddPhotosVBox), PhotoAddButton, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, PhotoAddButton, _("Add photos to be correlated."), NULL);
g_signal_connect (G_OBJECT (PhotoAddButton), "clicked",
G_CALLBACK (AddPhotosButtonPress), NULL);
PhotoRemoveButton = gtk_button_new_with_mnemonic (_("Remove"));
gtk_widget_show (PhotoRemoveButton);
gtk_box_pack_start (GTK_BOX (AddPhotosVBox), PhotoRemoveButton, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, PhotoRemoveButton, _("Remove selected photos from the list."), NULL);
g_signal_connect (G_OBJECT (PhotoRemoveButton), "clicked",
G_CALLBACK (RemovePhotosButtonPress), NULL);
AddPhotosLabel = gtk_label_new (_("<b>1. Add Photos</b>"));
gtk_widget_show (AddPhotosLabel);
gtk_frame_set_label_widget (GTK_FRAME (AddPhotosFrame), AddPhotosLabel);
gtk_label_set_use_markup (GTK_LABEL (AddPhotosLabel), TRUE);
/* GPS data area */
GPSDataFrame = gtk_frame_new (NULL);
gtk_widget_show (GPSDataFrame);
gtk_box_pack_start (GTK_BOX (ControlsVBox), GPSDataFrame, FALSE, FALSE, 0);
GPSDataAlignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (GPSDataAlignment);
gtk_container_add (GTK_CONTAINER (GPSDataFrame), GPSDataAlignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (GPSDataAlignment), 0, 4, 12, 4);
GPSDataVBox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (GPSDataVBox);
gtk_container_add (GTK_CONTAINER (GPSDataAlignment), GPSDataVBox);
GPSSelectedLabel = gtk_label_new (_("Reading from: No file")); /* FIX ME: Label not appropriately sized/placed for data. */
gtk_widget_show (GPSSelectedLabel);
gtk_box_pack_start (GTK_BOX (GPSDataVBox), GPSSelectedLabel, FALSE, FALSE, 0);
gtk_label_set_ellipsize(GTK_LABEL(GPSSelectedLabel), PANGO_ELLIPSIZE_END);
/*gtk_label_set_width_chars(GTK_LABEL(GPSSelectedLabel), 20);
gtk_label_set_line_wrap(GTK_LABEL(GPSSelectedLabel), TRUE);*/
SelectGPSButton = gtk_button_new_with_mnemonic (_("Choose..."));
gtk_widget_show (SelectGPSButton);
gtk_box_pack_start (GTK_BOX (GPSDataVBox), SelectGPSButton, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, SelectGPSButton,
_("Choose GPX file to read GPS data from. If the GPS data is not in the "
"GPX format, use a converter like GPSBabel to convert it to GPX."), NULL);
g_signal_connect (G_OBJECT (SelectGPSButton), "clicked",
G_CALLBACK (SelectGPSButtonPress), NULL);
GPSDataLabel = gtk_label_new (_("<b>2. GPS Data</b>"));
gtk_widget_show (GPSDataLabel);
gtk_frame_set_label_widget (GTK_FRAME (GPSDataFrame), GPSDataLabel);
gtk_label_set_use_markup (GTK_LABEL (GPSDataLabel), TRUE);
/* Options area. */
OptionsFrame = gtk_frame_new (NULL);
gtk_widget_show (OptionsFrame);
gtk_box_pack_start (GTK_BOX (ControlsVBox), OptionsFrame, FALSE, FALSE, 0);
OptionsAlignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (OptionsAlignment);
gtk_container_add (GTK_CONTAINER (OptionsFrame), OptionsAlignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (OptionsAlignment), 0, 4, 12, 4);
OptionsVBox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (OptionsVBox);
gtk_container_add (GTK_CONTAINER (OptionsAlignment), OptionsVBox);
InterpolateCheck = gtk_check_button_new_with_mnemonic (_("Interpolate"));
gtk_widget_show (InterpolateCheck);
gtk_box_pack_start (GTK_BOX (OptionsVBox), InterpolateCheck, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, InterpolateCheck,
_("Interpolate between points. If disabled, points will be rounded to "
"the nearest recorded point."), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (InterpolateCheck), g_key_file_get_boolean(GUISettings, "default", "interpolate", NULL));
NoWriteCheck = gtk_check_button_new_with_mnemonic (_("Don't write"));
gtk_widget_show (NoWriteCheck);
gtk_box_pack_start (GTK_BOX (OptionsVBox), NoWriteCheck, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, NoWriteCheck, _("Don't write EXIF data back to the photos."), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NoWriteCheck), g_key_file_get_boolean(GUISettings, "default", "dontwrite", NULL));
NoMtimeCheck = gtk_check_button_new_with_mnemonic (_("Don't change mtime"));
gtk_widget_show (NoMtimeCheck);
gtk_box_pack_start (GTK_BOX (OptionsVBox), NoMtimeCheck, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, NoMtimeCheck,
_("Don't change file modification time of the photos."), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NoMtimeCheck), g_key_file_get_boolean(GUISettings, "default", "nochangemtime", NULL));
BetweenSegmentsCheck = gtk_check_button_new_with_mnemonic (_("Between Segments"));
gtk_widget_show (BetweenSegmentsCheck);
gtk_box_pack_start (GTK_BOX (OptionsVBox), BetweenSegmentsCheck, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, BetweenSegmentsCheck,
_("Interpolate between track segments. Generally the data is segmented "
"to show where data was available and not available, but you might "
"still want to interpolate between segments."), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (BetweenSegmentsCheck), g_key_file_get_boolean(GUISettings, "default", "betweensegments", NULL));
DegMinSecsCheck = gtk_check_button_new_with_mnemonic (_("Write DD MM SS.SS"));
gtk_widget_show (DegMinSecsCheck);
gtk_box_pack_start (GTK_BOX (OptionsVBox), DegMinSecsCheck, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, DegMinSecsCheck,
_("Write the latitude and longitude values as DD MM SS.SS; this is "
"the new default. The old behaviour was to write it as "
"DD MM.MM, which will occur if you uncheck this box."), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (DegMinSecsCheck), g_key_file_get_boolean(GUISettings, "default", "writeddmmss", NULL));
OptionsTable = gtk_table_new (4, 2, FALSE);
gtk_widget_show (OptionsTable);
gtk_box_pack_start (GTK_BOX (OptionsVBox), OptionsTable, TRUE, TRUE, 0);
MaxGapTimeLabel = gtk_label_new (_("Max gap time:"));
gtk_widget_show (MaxGapTimeLabel);
gtk_table_attach (GTK_TABLE (OptionsTable), MaxGapTimeLabel, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (MaxGapTimeLabel), 0, 0.5);
TimeZoneLabel = gtk_label_new (_("Time Zone:"));
gtk_widget_show (TimeZoneLabel);
gtk_table_attach (GTK_TABLE (OptionsTable), TimeZoneLabel, 0, 1, 1, 2,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (TimeZoneLabel), 0, 0.5);
PhotoOffsetLabel = gtk_label_new (_("Photo Offset:"));
gtk_widget_show (PhotoOffsetLabel);
gtk_table_attach (GTK_TABLE (OptionsTable), PhotoOffsetLabel, 0, 1, 2, 3,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (PhotoOffsetLabel), 0, 0.5);
GPSDatumLabel = gtk_label_new (_("GPS Datum:"));
gtk_widget_show (GPSDatumLabel);
gtk_table_attach (GTK_TABLE (OptionsTable), GPSDatumLabel, 0, 1, 4, 5,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (GPSDatumLabel), 0, 0.5);
GapTimeEntry = gtk_entry_new ();
gtk_widget_show (GapTimeEntry);
gtk_table_attach (GTK_TABLE (OptionsTable), GapTimeEntry, 1, 2, 0, 1,
(GtkAttachOptions) (0),
(GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, GapTimeEntry,
_("Maximum time \"away\" from a point that the photo will be matched, "
"in seconds. If a photos time is outside this value from any point, "
"it will not be matched."), NULL);
gtk_entry_set_text (GTK_ENTRY (GapTimeEntry), g_key_file_get_value(GUISettings, "default", "maxgap", NULL));
gtk_entry_set_width_chars (GTK_ENTRY (GapTimeEntry), 7);
TimeZoneEntry = gtk_entry_new ();
gtk_widget_show (TimeZoneEntry);
gtk_table_attach (GTK_TABLE (OptionsTable), TimeZoneEntry, 1, 2, 1, 2,
(GtkAttachOptions) (0),
(GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, TimeZoneEntry,
_("The timezone that the cameras time was set to when the photos were "
"taken. For example, if a camera is set to AWST or +8:00 hours. "
"Enter +8:00 here so that the correct adjustment to the photos time "
"can be made. GPS data is always in UTC."), NULL);
gtk_entry_set_text (GTK_ENTRY (TimeZoneEntry), g_key_file_get_value(GUISettings, "default", "timezone", NULL));
gtk_entry_set_width_chars (GTK_ENTRY (TimeZoneEntry), 7);
PhotoOffsetEntry = gtk_entry_new ();
gtk_widget_show (PhotoOffsetEntry);
gtk_table_attach (GTK_TABLE (OptionsTable), PhotoOffsetEntry, 1, 2, 2, 3,
(GtkAttachOptions) (0),
(GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, PhotoOffsetEntry,
_("The number of seconds to add to the photo's time to make it match "
"the GPS data. Calculate this with (GPS - Photo). "
"Can be negative or positive."), NULL);
gtk_entry_set_text (GTK_ENTRY (PhotoOffsetEntry), g_key_file_get_value(GUISettings, "default", "photooffset", NULL));
gtk_entry_set_width_chars (GTK_ENTRY (PhotoOffsetEntry), 7);
GPSDatumEntry = gtk_entry_new ();
gtk_widget_show (GPSDatumEntry);
gtk_table_attach (GTK_TABLE (OptionsTable), GPSDatumEntry, 1, 2, 4, 5,
(GtkAttachOptions) (0),
(GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, GPSDatumEntry,
_("The datum used for the GPS data. This text here is recorded in the "
"EXIF tags as the source datum. WGS-84 is very commonly used."), NULL);
gtk_entry_set_text (GTK_ENTRY (GPSDatumEntry), g_key_file_get_value(GUISettings, "default", "gpsdatum", NULL));
gtk_entry_set_width_chars (GTK_ENTRY (GPSDatumEntry), 7);
OptionsFrameLable = gtk_label_new (_("<b>3. Set options</b>"));
gtk_widget_show (OptionsFrameLable);
gtk_frame_set_label_widget (GTK_FRAME (OptionsFrame), OptionsFrameLable);
gtk_label_set_use_markup (GTK_LABEL (OptionsFrameLable), TRUE);
/* Correlate button area. */
CorrelateFrame = gtk_frame_new (NULL);
gtk_widget_show (CorrelateFrame);
gtk_box_pack_start (GTK_BOX (ControlsVBox), CorrelateFrame, FALSE, FALSE, 0);
CorrelateAlignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (CorrelateAlignment);
gtk_container_add (GTK_CONTAINER (CorrelateFrame), CorrelateAlignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (CorrelateAlignment), 0, 4, 12, 4);
CorrelateButton = gtk_button_new_with_mnemonic (_("Correlate Photos"));
gtk_widget_show (CorrelateButton);
gtk_container_add (GTK_CONTAINER (CorrelateAlignment), CorrelateButton);
gtk_tooltips_set_tip (tooltips, CorrelateButton,
_("Begin the correlation process, writing back into the photos' "
"EXIF tags (unless Don't write is selected)."), NULL);
g_signal_connect (G_OBJECT (CorrelateButton), "clicked",
G_CALLBACK (CorrelateButtonPress), NULL);
CorrelateLabel = gtk_label_new (_("<b>4. Correlate!</b>"));
gtk_widget_show (CorrelateLabel);
gtk_frame_set_label_widget (GTK_FRAME (CorrelateFrame), CorrelateLabel);
gtk_label_set_use_markup (GTK_LABEL (CorrelateLabel), TRUE);
/* Other options area. */
OtherOptionsFrame = gtk_frame_new (NULL);
gtk_widget_show (OtherOptionsFrame);
gtk_box_pack_start (GTK_BOX (ControlsVBox), OtherOptionsFrame, FALSE, FALSE, 0);
OtherOptionsAlignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (OtherOptionsAlignment);
gtk_container_add (GTK_CONTAINER (OtherOptionsFrame), OtherOptionsAlignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (OtherOptionsAlignment), 0, 4, 12, 4);
StripGPSButton = gtk_button_new_with_mnemonic (_("Strip GPS tags"));
gtk_widget_show (StripGPSButton);
gtk_container_add (GTK_CONTAINER (OtherOptionsAlignment), StripGPSButton);
gtk_tooltips_set_tip (tooltips, StripGPSButton,
_("Strip GPS tags from the selected photos."), NULL);
g_signal_connect (G_OBJECT (StripGPSButton), "clicked",
G_CALLBACK (StripGPSButtonPress), NULL);
OtherOptionsLabel = gtk_label_new (_("<b>Other Tools</b>"));
gtk_widget_show (OtherOptionsLabel);
gtk_frame_set_label_widget (GTK_FRAME (OtherOptionsFrame), OtherOptionsLabel);
gtk_label_set_use_markup (GTK_LABEL (OtherOptionsLabel), TRUE);
/* Photo list box area of the window. */
PhotoListVBox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (PhotoListVBox);
gtk_box_pack_start (GTK_BOX (WindowHBox), PhotoListVBox, TRUE, TRUE, 0);
PhotoListScroll = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (PhotoListScroll);
gtk_box_pack_start (GTK_BOX (PhotoListVBox), PhotoListScroll, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (PhotoListScroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (PhotoListScroll), GTK_SHADOW_IN);
/* Get the photo list store ready. */
PhotoListStore = gtk_list_store_new(LIST_NOCOLUMNS,
G_TYPE_STRING, /* The Filename */
G_TYPE_STRING, /* Latitude */
G_TYPE_STRING, /* Longitude */
G_TYPE_STRING, /* Elevation */
G_TYPE_STRING, /* The Time */
G_TYPE_STRING, /* The State */
G_TYPE_POINTER); /* Pointer to the matching list item. */
PhotoList = gtk_tree_view_new_with_model (GTK_TREE_MODEL(PhotoListStore));
gtk_widget_show (PhotoList);
gtk_container_add (GTK_CONTAINER (PhotoListScroll), PhotoList);
gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(PhotoList)), GTK_SELECTION_MULTIPLE);
/* Prepare the columns. We need columns. Columns are good. */
PhotoListRenderer = gtk_cell_renderer_text_new ();
/* File Column. */
FileColumn = gtk_tree_view_column_new_with_attributes (_("File"), PhotoListRenderer,
"text", LIST_FILENAME,
NULL);
gtk_tree_view_column_set_resizable (FileColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), FileColumn);
/* Latitude Column. */
LatColumn = gtk_tree_view_column_new_with_attributes (_("Latitude"), PhotoListRenderer,
"text", LIST_LAT,
NULL);
gtk_tree_view_column_set_resizable (LatColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), LatColumn);
/* Longitude Column. */
LongColumn = gtk_tree_view_column_new_with_attributes (_("Longitude"), PhotoListRenderer,
"text", LIST_LONG,
NULL);
gtk_tree_view_column_set_resizable (LongColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), LongColumn);
/* Elevation Column. */
ElevColumn = gtk_tree_view_column_new_with_attributes (_("Elevation"), PhotoListRenderer,
"text", LIST_ELEV,
NULL);
gtk_tree_view_column_set_resizable (ElevColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), ElevColumn);
/* Time column. */
TimeColumn = gtk_tree_view_column_new_with_attributes (_("Time"), PhotoListRenderer,
"text", LIST_TIME,
NULL);
gtk_tree_view_column_set_resizable (TimeColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), TimeColumn);
/* State column. */
StateColumn = gtk_tree_view_column_new_with_attributes (_("State"), PhotoListRenderer,
"text", LIST_STATE,
NULL);
gtk_tree_view_column_set_resizable (StateColumn, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (PhotoList), StateColumn);
/* Get the track list store ready.
* Create the empty terminating entry. */
GPSData = (struct GPSTrack*) calloc(1, sizeof(*GPSData));
NumTracks = 0;
/* Final thing: show the window. */
gtk_widget_show(MatchWindow);
/* Done! Return a pointer to the window, although we never use it... */
return MatchWindow;
}
gboolean DestroyWindow(GtkWidget *Widget,
GdkEvent *Event,
gpointer Data)
{
/* Record the settings, and then save them. */
g_key_file_set_boolean(GUISettings, "default", "interpolate", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(InterpolateCheck)));
g_key_file_set_boolean(GUISettings, "default", "dontwrite", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(NoWriteCheck)));
g_key_file_set_boolean(GUISettings, "default", "nochangemtime", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(NoMtimeCheck)));
g_key_file_set_boolean(GUISettings, "default", "betweensegments", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(BetweenSegmentsCheck)));
g_key_file_set_boolean(GUISettings, "default", "writeddmmss", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(DegMinSecsCheck)));
g_key_file_set_string(GUISettings, "default", "maxgap", gtk_entry_get_text(GTK_ENTRY(GapTimeEntry)));
g_key_file_set_string(GUISettings, "default", "timezone", gtk_entry_get_text(GTK_ENTRY(TimeZoneEntry)));
g_key_file_set_string(GUISettings, "default", "photooffset", gtk_entry_get_text(GTK_ENTRY(PhotoOffsetEntry)));
g_key_file_set_string(GUISettings, "default", "gpsdatum", gtk_entry_get_text(GTK_ENTRY(GPSDatumEntry)));
g_key_file_set_string(GUISettings, "default", "gpxopendir", GPXOpenDir);
g_key_file_set_string(GUISettings, "default", "photoopendir", PhotoOpenDir);
SaveSettings();
/* Someone closed the window. */
/* Free the memory we allocated for the photo list. */
struct GUIPhotoList* Free = NULL;
struct GUIPhotoList* Free2 = NULL;
if (FirstPhoto)
{
/* Walk through the singly-linked list
* freeing stuff. */
Free = FirstPhoto;
while (1)
{
free(Free->Filename);
free(Free->Time);
Free2 = Free->Next;
free(Free);
if (Free2 == NULL) break;
Free = Free2;
}
}
/* Free the memory for the GPS data, if applicable. */
while (NumTracks > 0)
{
--NumTracks;
FreeTrack(&GPSData[NumTracks]);
}
free(GPSData);
/* Tell GTK that we're done. */
gtk_exit(0);
/* And return FALSE so that GTK knows we have not
* vetoed the close. */
return FALSE;
}
void AddPhotosButtonPress( GtkWidget *Widget, gpointer Data )
{
/* Add some photos to this thing. */
GtkWidget *AddPhotosDialog;
/* Get the dialog ready. */
AddPhotosDialog = gtk_file_chooser_dialog_new (_("Add Photos..."),
GTK_WINDOW(MatchWindow),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(AddPhotosDialog), TRUE);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(AddPhotosDialog), PhotoOpenDir);
GtkFileFilter *JpgFilter = gtk_file_filter_new();
if (JpgFilter) {
gtk_file_filter_add_pattern(JpgFilter, "*.[jJ][pP][gG]");
gtk_file_filter_add_pattern(JpgFilter, "*.[jJ][pP][eE][gG]");
gtk_file_filter_set_name(JpgFilter, _("JPEG images"));
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(AddPhotosDialog), JpgFilter);
}
GtkFileFilter *AllFilter = gtk_file_filter_new();
if (AllFilter) {
gtk_file_filter_add_pattern(AllFilter, "*");
gtk_file_filter_set_name(AllFilter, _("All files"));
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(AddPhotosDialog), AllFilter);
}
/* Run the dialog. */
if (gtk_dialog_run (GTK_DIALOG (AddPhotosDialog)) == GTK_RESPONSE_ACCEPT)
{
/* Hide the dialog. */
gtk_widget_hide(AddPhotosDialog);
/* Haul out the selected files.
* We pass them along to another function that will
* add them to the internal list and onto the screen. */
/* GTK returns a GSList - a singly-linked list of filenames. */
GSList* FileNames = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(AddPhotosDialog));
GSList* Run;
for (Run = FileNames; Run; Run = Run->next)
{
/* Show what's happening on the screen. */
GtkGUIUpdate();
/*printf("Filename: %s.\n", (char*)Run->data);*/
/* Call the other function with the filename - this
* function adds it to the internal list, and adds it
* to the screen display, too. */
AddPhotoToList((char*)Run->data);
/* Free the memory passed to us. */
g_free(Run->data);
}
/* We're done with the list - free it. */
g_slist_free(FileNames);
}
/* Copy out the directory that the user ended up at. */
g_free(PhotoOpenDir);
PhotoOpenDir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(AddPhotosDialog));
/* Now we're done with the dialog. See you! */
gtk_widget_destroy (AddPhotosDialog);
}
void AddPhotoToList(const char* Filename)
{
/* Add the photo to the list. Query out the exif tags
* at the same time, too - so we can add them to the
* current list. */
/* Note that this function does more than update the GUI:
* it also adds it to the internal list, ready to go. */
/* Get ready to read the relevant data. */
GtkTreeIter AddStuff;
double Lat, Long, Elev;
Lat = Long = Elev = 0;
int IncludesGPS = 0;
/* Read the EXIF data. */
char *Time = ReadExifData(Filename, &Lat, &Long, &Elev, &IncludesGPS);
/* Note: we don't check if Time is NULL here. It is done for
* us in SetListItem, and we check again before we attempt
* to allocate memory to store "Time" in. */
/* Add the data to the list. */
gtk_list_store_append(PhotoListStore, &AddStuff);
SetListItem(&AddStuff, Filename, Time, Lat, Long, Elev, NULL, IncludesGPS);
/* Save away the filename and the TreeIter information in the internal
* singly-linked list. */
/* We also make a copy of Filename - it won't exist once we return. */
if (FirstPhoto)
{
/* Already at least one element. Add to it. */
LastPhoto->Next = (struct GUIPhotoList*) malloc(sizeof(struct GUIPhotoList));
LastPhoto = LastPhoto->Next;
LastPhoto->Next = NULL;
} else {
/* No elements. Righto, add one. */
FirstPhoto = (struct GUIPhotoList*) malloc(sizeof(struct GUIPhotoList));
LastPhoto = FirstPhoto;
FirstPhoto->Next = NULL;
}
/* Now that we've allocated memory for the structure, allocate
* memory for the strings and then fill them. */
/* Filename first... */
LastPhoto->Filename = strdup(Filename);
/* And then Time, after checking for NULLness. */
if (Time)
{
LastPhoto->Time = strdup(Time);
} else {
LastPhoto->Time = strdup(_("No EXIF data"));
}
/* Save the TreeIter as the last step. */
LastPhoto->ListPointer = AddStuff;
/* Save the pointer into the data, as well. */
gtk_list_store_set(PhotoListStore, &AddStuff,
LIST_POINTER, LastPhoto,
-1);
/* Free the memory allocated for us.
* (ReadExifData allocates and returns memory) */
free(Time);
}
void RemovePhotosButtonPress( GtkWidget *Widget, gpointer Data )
{
/* Someone clicked the remove photos button. So make it happen!
* First, query out what was selected. */
GtkTreeIter Iter;
GtkTreeSelection* Selection;
Selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PhotoList));
GList* Selected = gtk_tree_selection_get_selected_rows(Selection, NULL);
/* Sanity check: was anything selected? */
if (Selected == NULL)
{
/* Nothing is selected. Do nothing. */
return;
}
/* Count the items on the GList. We need this to be able to
* keep a list of items that have been removed from our internal
* list, and should be removed from the screen. */
int SelectedCount = 0;
GList* Walk;
for (Walk = Selected; Walk; Walk = Walk->next)
{
SelectedCount++;
}
/* Now get ready to keep a list of Iters that we can
* delete. */
GtkTreeIter* RemoveIters = (GtkTreeIter*) malloc(sizeof(GtkTreeIter) * SelectedCount);
/* Walk through and remove the items from our internal list. */
struct GUIPhotoList* PhotoWalk = NULL;
struct GUIPhotoList* LastPhotoWalk = NULL;
struct GUIPhotoList* FreeHold = NULL;
struct GUIPhotoList* FreeMe = NULL;
int IterCount = 0;
for (Walk = Selected; Walk; Walk = Walk->next)
{
/* Acquire a new Iter for this selected row. */
if (gtk_tree_model_get_iter(GTK_TREE_MODEL(PhotoListStore), &Iter,
(GtkTreePath*) Walk->data))
{
/* To remove the row from our internal list.
* Locate it via the pointer stored. */
gtk_tree_model_get(GTK_TREE_MODEL(PhotoListStore), &Iter,
LIST_POINTER, &FreeMe, -1);
/* Save the iter for afterwards: we can then remove the
* data from the screen. */
/* gtk_list_store_remove(PhotoListStore, &Iter); */
RemoveIters[IterCount] = Iter;
IterCount++;
/* Now go back through and take it out from our list. */
PhotoWalk = FirstPhoto;
LastPhotoWalk = NULL;
while (1)
{
if (PhotoWalk == NULL) break;
/*printf("Search: %d / %d.\n", PhotoWalk, FreeMe);*/
/* Check to see if this is the one we want to be rid of. */
if (PhotoWalk == FreeMe)
{
/* Right. Remove. */
/*printf("Removing: %s.\n", PhotoWalk->Filename);*/
PhotoWalk = PhotoWalk->Next;
if (FreeMe == FirstPhoto)
{
/* Remove the top of the list. */
FreeHold = FreeMe;
FirstPhoto = FreeMe->Next;
LastPhotoWalk = FreeMe->Next;
free(FreeHold->Filename);
free(FreeHold->Time);
free(FreeHold);
break;
} else if (FreeMe == LastPhoto) {
/* Remove the bottom of the list. */
FreeHold = FreeMe;
LastPhoto = LastPhotoWalk;
LastPhoto->Next = NULL;
free(FreeHold->Filename);
free(FreeHold->Time);
free(FreeHold);
break;
} else {
/* Remove a middle of the list. */
FreeHold = FreeMe;
LastPhotoWalk->Next = FreeHold->Next;
free(FreeHold->Filename);
free(FreeHold->Time);
free(FreeHold);
break;
}
} else {
/* Nope, this wasn't what we wanted to delete.
* So get ready to look at the next one, keeping
* mind of where we were. */
LastPhotoWalk = PhotoWalk;
PhotoWalk = PhotoWalk->Next;
}
} /* End for Walk the photo list. */
}
} /* End for Walk the GList. */
/* Now remove the rows from the screen.
* By this point, they are no longer in our internal list. */
int i;
for (i = 0; i < SelectedCount; i++)
{
gtk_list_store_remove(PhotoListStore, &RemoveIters[i]);
}
free(RemoveIters);
/* Free the memory used by GList. */
g_list_foreach(Selected, (GFunc)gtk_tree_path_free, NULL);
g_list_free(Selected);
/* Debug: walk the photo list tree. */
/*struct GUIPhotoList* List;
for (List = FirstPhoto; List; List = List->Next)
{
printf("List Filename: %s\n", List->Filename);
}
printf("--------------------------------------------------------------\n");*/
}
void SetListItem(GtkTreeIter* Iter, const char* Filename, const char* Time, double Lat,
double Long, double Elev, const char* PassedState, int IncludesGPS)
{
/* Scratch areas. */
char LatScratch[100] = "";
char LongScratch[100] = "";
char ElevScratch[100] = "";
const char* State = NULL;
/* Format all the data. */
if (!Time)
{
/* Not good. Failure. */
Time = "";
State = _("No EXIF data");
} else {
/* All ok. Get ready. */
if (IncludesGPS)
{
State = _("GPS Data Present");
/* In each case below, consider the values
* that are invalid for each - if that's the case,
* consider the spots as "blank". */
/* Lat can't be greater than 90 degrees. */
if (Lat < 200)
{
snprintf(LatScratch, sizeof(LatScratch), "%f (%c)",
Lat, (Lat < 0) ? 'S' : 'N');
} else {
snprintf(LatScratch, sizeof(LatScratch), " ");
}
/* Long can't be greater than 180 degrees. */
if (Long < 200)
{
snprintf(LongScratch, sizeof(LongScratch), "%f (%c)",
Long, (Long < 0) ? 'W' : 'E');
} else {
snprintf(LongScratch, sizeof(LongScratch), " ");
}
/* Radius of earth ~6000km */
if (Elev > -7000000)
{
snprintf(ElevScratch, sizeof(ElevScratch), "%.2fm", Elev);
} else {
snprintf(ElevScratch, sizeof(ElevScratch), " ");
}
} else {
/* Placeholders for the lack of data. */
State = _("Ready");
}
}
/* Overwrite state with what we want, if needed. */
if (PassedState) State = PassedState;
/* And set all the appropriate data. */
gtk_list_store_set(PhotoListStore, Iter,
LIST_FILENAME, strrchr(Filename, G_DIR_SEPARATOR)+1,
LIST_LAT, LatScratch,
LIST_LONG, LongScratch,
LIST_ELEV, ElevScratch,
LIST_TIME, Time,
LIST_STATE, State,
-1);
}
void SetState(GtkTreeIter* Iter, const char* State)
{
/* Set the state on the item... just the state. */
gtk_list_store_set(PhotoListStore, Iter,
LIST_STATE, State,
-1);
}
void SelectGPSButtonPress( GtkWidget *Widget, gpointer Data )
{
/* Select and load some GPS data! */
GtkWidget *GPSDataDialog;
GtkWidget *ErrorDialog;
/* Get the dialog ready... */
GPSDataDialog = gtk_file_chooser_dialog_new (_("Select GPS Data..."),
GTK_WINDOW(MatchWindow),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);