~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/init.c

  • Committer: Joshua Judson Rosen
  • Date: 2009-09-26 02:35:15 UTC
  • Revision ID: rozzin@geekspace.com-20090926023515-yxl5sg1a45gupuc8
Imported from tangogps-0.9.7 tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#ifdef HAVE_CONFIG_H
 
4
#  include <config.h>
 
5
#endif
 
6
 
 
7
#include <glib.h>
 
8
#include <glib/gstdio.h>
 
9
#include <glib/gprintf.h>
 
10
#include <gtk/gtk.h>
 
11
#include <string.h>
 
12
#include <stdlib.h>
 
13
#include <stdio.h>
 
14
#include <gdk/gdk.h>
 
15
#include <gconf/gconf.h>
 
16
#include <math.h>
 
17
#include <time.h>
 
18
#include <errno.h>
 
19
 
 
20
#include "globals.h"
 
21
#include "map_management.h"
 
22
#include "converter.h"
 
23
#include "gps_functions.h"
 
24
#include "support.h"
 
25
#include "callbacks.h"
 
26
#include "wp.h"
 
27
 
 
28
FILE *fp = NULL;
 
29
 
 
30
 
 
31
 
 
32
void
 
33
track_log()
 
34
{
 
35
        gchar buffer[256];
 
36
        gchar data[256];
 
37
        time_t time_sec;
 
38
        struct tm *ts;
 
39
        
 
40
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
41
        
 
42
        if(gpsdata->valid)
 
43
        {
 
44
                
 
45
                time_sec = (time_t)gpsdata->fix.time;
 
46
                ts = localtime(&time_sec);
 
47
                
 
48
                
 
49
                strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", ts);
 
50
                
 
51
                
 
52
                sprintf(data, "%f,%f,%.1f,%.1f,%.1f,%.1f,%s\n",
 
53
                                gpsdata->fix.latitude,
 
54
                                gpsdata->fix.longitude,
 
55
                                gpsdata->fix.altitude,
 
56
                                gpsdata->fix.speed,
 
57
                                gpsdata->fix.track,
 
58
                                gpsdata->hdop,
 
59
                                buffer);
 
60
                
 
61
                if (fp) fprintf(fp,data);
 
62
        }
 
63
}
 
64
 
 
65
void
 
66
track_log_open()
 
67
{
 
68
        time_t time_epoch_sec;
 
69
        struct tm  *tm_struct;
 
70
        gchar buffer[256];
 
71
        gchar *filename = NULL;
 
72
        GtkLabel *label76;
 
73
        gchar *labeltext;
 
74
        
 
75
        label76 = GTK_LABEL(lookup_widget(window1, "label76"));
 
76
        
 
77
        
 
78
        time_epoch_sec = time(NULL);
 
79
        tm_struct = localtime(&time_epoch_sec);
 
80
        
 
81
        
 
82
        
 
83
 
 
84
        strftime(buffer, sizeof(buffer), "%Y%m%d_%H%M%S.log", tm_struct);
 
85
        
 
86
 
 
87
        
 
88
        filename = g_strconcat(global_track_dir, buffer,NULL);
 
89
        
 
90
        printf("*** %s(): %s\n",__PRETTY_FUNCTION__,filename);
 
91
        
 
92
        if(fp==NULL && trip_logger_on)
 
93
        {
 
94
                fp = fopen(filename,"w");
 
95
                if(!fp)
 
96
                {
 
97
                        printf("oops: %s \n",strerror(errno));
 
98
                        perror("Triplog open failed: ");
 
99
                        gtk_label_set_label(label76,"<span foreground='#ff0000'>Error opening logfile</span>");
 
100
                }
 
101
                else 
 
102
                {
 
103
                        labeltext = g_strconcat("<b><span foreground='#0000ff'>Log: ",buffer,"</span></b>",NULL);
 
104
                        gtk_label_set_label(label76,labeltext);
 
105
                        g_free(labeltext);      
 
106
                }
 
107
        }
 
108
        
 
109
        g_free(filename);
 
110
}
 
111
 
 
112
 
 
113
void
 
114
track_log_close()
 
115
{
 
116
        int ret;
 
117
        GtkLabel *label76;
 
118
        label76 = GTK_LABEL(lookup_widget(window1, "label76"));
 
119
        gtk_label_set_label(label76,"");
 
120
        
 
121
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
122
        
 
123
        if(fp) {
 
124
                printf("closing FP\n");
 
125
                ret = fclose(fp);
 
126
                fp = NULL;
 
127
        
 
128
                if(ret) printf("ERROR closing file\n");
 
129
        }
 
130
}
 
131
 
 
132
 
 
133
gboolean
 
134
cb_gps_timer()
 
135
{
 
136
        int pixel_x, pixel_y, x, y, last_x, last_y;
 
137
        static float lat, lon;
 
138
        static float lat_tmp=0, lon_tmp=0;
 
139
        float trip_delta=0;
 
140
        
 
141
        static double trip_time_accumulated = 0;
 
142
 
 
143
 
 
144
        static gboolean trip_counter_got_stopped = FALSE;
 
145
 
 
146
 
 
147
        GdkColor color;
 
148
        static GdkGC *gc=NULL, *gc_2=NULL, *gc_3=NULL, *gc_4=NULL, *gc_5=NULL;
 
149
        
 
150
        if(gc == NULL)
 
151
        {
 
152
                gc   = gdk_gc_new(pixmap);
 
153
                gc_2 = gdk_gc_new(pixmap);
 
154
                gc_3 = gdk_gc_new(pixmap);
 
155
                gc_4 = gdk_gc_new(pixmap);
 
156
                gc_5 = gdk_gc_new(pixmap);
 
157
        }
 
158
        
 
159
        color.red = 60000;
 
160
        color.green = 0;
 
161
        color.blue = 0;
 
162
        gdk_gc_set_rgb_fg_color(gc, &color);
 
163
        gdk_gc_set_line_attributes(gc,
 
164
                        5, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
 
165
                        
 
166
        color.red = 5000;
 
167
        color.green = 5000;
 
168
        color.blue = 55000;
 
169
        gdk_gc_set_rgb_fg_color(gc_2, &color);
 
170
                
 
171
        gdk_gc_set_line_attributes(gc_2,
 
172
                        6, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
 
173
 
 
174
        color.red = 25500; 
 
175
        color.green = 35000;
 
176
        color.blue = 65500;
 
177
        gdk_gc_set_rgb_fg_color(gc_3, &color);
 
178
        gdk_gc_set_line_attributes(gc_3,
 
179
                        7, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
 
180
        
 
181
        
 
182
        color.red = 35500; 
 
183
        color.green = 5000;
 
184
        color.blue = 500;
 
185
        gdk_gc_set_rgb_fg_color(gc_4, &color);
 
186
        gdk_gc_set_line_attributes(gc_4,
 
187
                        7, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
 
188
                        
 
189
                        
 
190
        color.red = 65500; 
 
191
        color.green = 65500;
 
192
        color.blue = 65500;
 
193
        gdk_gc_set_rgb_fg_color(gc_5, &color);
 
194
        gdk_gc_set_line_attributes(gc_5,
 
195
                        11, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
 
196
                        
 
197
                        
 
198
 
 
199
        get_gps();
 
200
        
 
201
 
 
202
        if(gpsdata) 
 
203
        {
 
204
                trackpoint_t *tp = g_new0(trackpoint_t,1);
 
205
                static int counter = 0;
 
206
                
 
207
 
 
208
                lat = deg2rad(gpsdata->fix.latitude);
 
209
                lon = deg2rad(gpsdata->fix.longitude);
 
210
                
 
211
                printf("** %s() \n", __PRETTY_FUNCTION__);
 
212
                
 
213
                
 
214
                
 
215
                pixel_x = lon2pixel(global_zoom, lon);
 
216
                pixel_y = lat2pixel(global_zoom, lat);
 
217
                
 
218
                x = pixel_x - global_x;
 
219
                y = pixel_y - global_y;
 
220
                
 
221
                
 
222
                pixel_x = lon2pixel(global_zoom, lon_tmp);
 
223
                pixel_y = lat2pixel(global_zoom, lat_tmp);
 
224
                
 
225
                last_x = pixel_x - global_x;
 
226
                last_y = pixel_y - global_y;
 
227
 
 
228
 
 
229
                
 
230
                if(gpsdata->seen_vaild)
 
231
                {
 
232
                        int hand_x, hand_y, hand_wp_x, hand_wp_y;
 
233
                        double heading_rad, bearing;
 
234
                        
 
235
                        heading_rad = (gpsdata->fix.track * (1.0 / 180.0)) * M_PI;
 
236
 
 
237
                        if(gpsdata->fix.speed>0.3) 
 
238
                        {
 
239
                                hand_x =  25 * sinf(heading_rad);
 
240
                                hand_y = -25 * cosf(heading_rad);
 
241
                        }
 
242
                        else
 
243
                        {
 
244
                                hand_x = 0;
 
245
                                hand_y = 0;
 
246
                        }
 
247
 
 
248
                        
 
249
                        
 
250
                        
 
251
                        
 
252
 
 
253
                        
 
254
                        gdk_draw_drawable (
 
255
                                map_drawable->window,
 
256
                                map_drawable->style->fg_gc[GTK_WIDGET_STATE (map_drawable)],
 
257
                                pixmap,
 
258
                                last_x-29, last_y-29,
 
259
                                last_x-29 + mouse_dx, last_y-29 + mouse_dy,
 
260
                                58,58);
 
261
 
 
262
                        
 
263
                        
 
264
                        if (lat_tmp && lon_tmp)
 
265
                                gdk_draw_line(pixmap, gc, last_x, last_y, x, y);
 
266
                        
 
267
 
 
268
 
 
269
                        gdk_window_process_all_updates();
 
270
 
 
271
                        
 
272
                        if(mouse_dx == 0 && mouse_dy == 0)
 
273
                        {
 
274
                                
 
275
                                gdk_draw_arc (
 
276
                                        map_drawable->window,
 
277
                                        
 
278
                                        gc_2,
 
279
                                        FALSE,                  
 
280
                                        x-15 + mouse_dx, y-15 + mouse_dy,               
 
281
                                        30,30,                  
 
282
                                        0, 360*64);             
 
283
                                
 
284
                                
 
285
                                if(global_wp_on && gpsdata->valid)
 
286
                                {
 
287
                                        
 
288
                                        bearing = get_bearing(lat, lon, global_wp.lat, global_wp.lon);
 
289
                                        gpsdata->fix.bearing = bearing;
 
290
                                        printf("BEARING: %f\n", bearing);
 
291
                                        hand_wp_x =  25 * sinf(bearing);
 
292
                                        hand_wp_y = -25 * cosf(bearing);
 
293
                                        
 
294
                                        gdk_draw_line(map_drawable->window,
 
295
                                                        gc_5,
 
296
                                                        x + mouse_dx,
 
297
                                                        y + mouse_dy,
 
298
                                                        x + mouse_dx + hand_wp_x,
 
299
                                                        y + mouse_dy + hand_wp_y);
 
300
 
 
301
                                        gdk_draw_line(map_drawable->window,
 
302
                                                        gc_4,
 
303
                                                        x + mouse_dx,
 
304
                                                        y + mouse_dy,
 
305
                                                        x + mouse_dx + hand_wp_x,
 
306
                                                        y + mouse_dy + hand_wp_y);
 
307
                                        
 
308
                                        osd_wp();
 
309
                                        
 
310
                                }
 
311
                                
 
312
                                gdk_draw_line(map_drawable->window,
 
313
                                                gc_5,
 
314
                                                x + mouse_dx,
 
315
                                                y + mouse_dy,
 
316
                                                x + mouse_dx + hand_x,
 
317
                                                y + mouse_dy + hand_y);
 
318
                                
 
319
                                gdk_draw_line(map_drawable->window,
 
320
                                                gc_3,
 
321
                                                x + mouse_dx,
 
322
                                                y + mouse_dy,
 
323
                                                x + mouse_dx + hand_x,
 
324
                                                y + mouse_dy + hand_y);
 
325
                        }
 
326
                        
 
327
                }
 
328
                
 
329
                if(global_autocenter)
 
330
                {
 
331
                        if(    (x < (global_drawingarea_width /2 - global_drawingarea_width /8) ||
 
332
                                x > (global_drawingarea_width /2 + global_drawingarea_width /8) ||
 
333
                                y < (global_drawingarea_height /2 - global_drawingarea_height /8) ||
 
334
                                y > (global_drawingarea_height /2 + global_drawingarea_height /8) ) &&
 
335
                        
 
336
                                
 
337
                                isnan(gpsdata->fix.latitude) ==0 &&
 
338
                                isnan(gpsdata->fix.longitude)==0 &&
 
339
                                gpsdata->fix.latitude  !=0 &&
 
340
                                gpsdata->fix.longitude !=0
 
341
                                )
 
342
                        {
 
343
                                set_mapcenter(gpsdata->fix.latitude, gpsdata->fix.longitude, global_zoom);
 
344
                        }
 
345
                }
 
346
                
 
347
 
 
348
                
 
349
                if(trip_counter_on)
 
350
                {
 
351
                        
 
352
                        
 
353
                        
 
354
                        if( gpsdata->valid && lat_tmp!=0 && lon_tmp!=0) 
 
355
                        {
 
356
                                trip_delta = 6371.0 *  acos(sin(lat) * sin(lat_tmp) + 
 
357
                                                                cos(lat) * cos(lat_tmp) * cos(lon_tmp-lon) );
 
358
                                if(isnan(trip_delta))
 
359
                                {
 
360
                                        
 
361
                                        
 
362
                                        printf("WTF??? %f %f %f %f %f \n",lat,lon,lat_tmp,lon_tmp,trip_delta);
 
363
                                }
 
364
                                else
 
365
                                {
 
366
                                        trip_distance += trip_delta;
 
367
                                        
 
368
                                        
 
369
                                        if(trip_distance > 0.005)
 
370
                                        {
 
371
                                                
 
372
                                                counter++;
 
373
                                                if(counter % 5 == 0)
 
374
                                                {
 
375
                                                        tp->lat = lat;
 
376
                                                        tp->lon = lon;
 
377
                                                        trackpoint_list = g_slist_append(trackpoint_list, tp);
 
378
                                                }       
 
379
                                        }
 
380
                                }
 
381
                        }
 
382
                        
 
383
                        
 
384
                        
 
385
                        
 
386
                        
 
387
                        
 
388
                        
 
389
                        
 
390
                        if(gpsdata->valid && gpsdata->fix.speed > trip_maxspeed)
 
391
                                trip_maxspeed = gpsdata->fix.speed;
 
392
                        
 
393
                        
 
394
                        
 
395
                        
 
396
                        if(trip_time == 0) 
 
397
                                trip_time_accumulated = 0;
 
398
                        
 
399
                        if(trip_counter_got_stopped)
 
400
                        {
 
401
                                printf("counter had been stopped \n");
 
402
                                trip_counter_got_stopped = FALSE;
 
403
                                trip_time_accumulated = trip_time;
 
404
                                trip_starttime = 0;
 
405
                        }
 
406
                        
 
407
                        
 
408
                        if(trip_starttime == 0 && gpsdata->seen_vaild)
 
409
                        {
 
410
                                trip_starttime = gpsdata->fix.time;
 
411
                                
 
412
                        }
 
413
                        
 
414
                        
 
415
                        if(trip_starttime > 0 && gpsdata->seen_vaild)
 
416
                        {
 
417
                                trip_time = gpsdata->fix.time - trip_starttime + trip_time_accumulated;
 
418
                                
 
419
                                
 
420
                        }
 
421
                        
 
422
                        if(trip_time < 0)
 
423
                        {
 
424
                                trip_time = 0;
 
425
                                trip_starttime = 0;
 
426
                                trip_distance = 0;
 
427
                                trip_maxspeed = 0;
 
428
                        }
 
429
 
 
430
                }
 
431
                else
 
432
                {
 
433
                        printf("trip counter halted\n");
 
434
                        trip_counter_got_stopped = TRUE;
 
435
                        lat_tmp = lon_tmp = 0;
 
436
                }
 
437
                
 
438
                
 
439
                
 
440
                set_label();
 
441
                
 
442
                if(trip_logger_on && gpsdata->valid)
 
443
                        track_log();
 
444
                
 
445
                if(gpsdata->valid)
 
446
                {       
 
447
                        lat_tmp = lat;
 
448
                        lon_tmp = lon;
 
449
                }
 
450
                
 
451
 
 
452
        }
 
453
        else 
 
454
        {
 
455
                printf("no gpsdata for timer\n");
 
456
                set_label_nogps();
 
457
        }
 
458
        return TRUE; 
 
459
}
 
460
 
 
461
GSList *
 
462
gconf_get_repolist()
 
463
{
 
464
        GSList  *repo_list;
 
465
        
 
466
        GSList  *list;
 
467
        GError **error = NULL;
 
468
        
 
469
        
 
470
        repo_list = gconf_client_get_list(      global_gconfclient, 
 
471
                                                GCONF"/repos",
 
472
                                                GCONF_VALUE_STRING,
 
473
                                                error);
 
474
        
 
475
        if (repo_list == NULL)
 
476
        {
 
477
                repo_t *repo1 = g_new0(repo_t, 1);
 
478
                repo_t *repo2 = g_new0(repo_t, 1);
 
479
                repo_t *repo3 = g_new0(repo_t, 1);
 
480
                repo_t *repo4 = g_new0(repo_t, 1);
 
481
                repo_t *repo5 = g_new0(repo_t, 1);
 
482
 
 
483
                
 
484
                printf("REPOLIST == NULL\n");
 
485
                repo1->name = g_strdup("OSM");
 
486
                repo1->uri  = g_strdup("http://tile.openstreetmap.org/%d/%d/%d.png");
 
487
                repo1->dir  = g_strdup_printf("%s/Maps/OSM",global_home_dir);
 
488
                repo1->inverted_zoom = 0;
 
489
                global_repo_list = g_slist_append(global_repo_list, repo1);
 
490
 
 
491
                repo2->name = g_strdup("Topo");
 
492
                repo2->uri  = g_strdup("maps-for-free");
 
493
                repo2->dir  = g_strdup_printf("%s/Maps/maps4free",global_home_dir);
 
494
                repo2->inverted_zoom = 0;
 
495
                global_repo_list = g_slist_append(global_repo_list, repo2);
 
496
                
 
497
                repo3->name = g_strdup("Aerial");
 
498
                repo3->uri  = g_strdup("openaerial");
 
499
                repo3->dir  = g_strdup_printf("%s/Maps/openaerial",global_home_dir);
 
500
                repo3->inverted_zoom = 0;
 
501
                global_repo_list = g_slist_append(global_repo_list, repo3);
 
502
                
 
503
                repo4->name = g_strdup("Opencyclemap");
 
504
                repo4->uri  = g_strdup("http://a.andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png");
 
505
                repo4->dir  = g_strdup_printf("%s/Maps/opencyclemap",global_home_dir);
 
506
                repo4->inverted_zoom = 0;
 
507
                global_repo_list = g_slist_append(global_repo_list, repo4);
 
508
                
 
509
                repo5->name = g_strdup("Google Sat (testing only)");
 
510
                repo5->uri  = g_strdup("http://khm.google.com/kh/v=45&x=%d&y=%d&z=%d");
 
511
                repo5->dir  = g_strdup_printf("%s/Maps/googlesat",global_home_dir);
 
512
                repo5->inverted_zoom = 1;
 
513
                global_repo_list = g_slist_append(global_repo_list, repo5);
 
514
                
 
515
        }
 
516
        
 
517
        
 
518
        for(list = repo_list; list != NULL; list = list->next)
 
519
        {
 
520
                gchar **array;
 
521
                gchar *str = list->data;
 
522
                repo_t *repo = g_new0(repo_t, 1);
 
523
                
 
524
                array = g_strsplit(str,"|",4);  
 
525
                
 
526
                repo->name = g_strdup(array[0]);
 
527
                repo->uri  = g_strdup(array[1]);
 
528
                repo->dir  = g_strdup(array[2]);
 
529
                repo->inverted_zoom = (atoi(g_strdup(array[3])) == 1) ? TRUE : FALSE;
 
530
                
 
531
                global_repo_list = g_slist_append(global_repo_list, repo);
 
532
 
 
533
                printf("GCONF: \n -- name: %s \n -- uri: %s \n -- dir: %s \n",
 
534
                        repo->name, repo->uri, repo->dir);
 
535
        }
 
536
        
 
537
        
 
538
        return global_repo_list;        
 
539
                                        
 
540
}
 
541
 
 
542
void
 
543
gconf_set_repolist()
 
544
{
 
545
        
 
546
        GSList  *list;
 
547
        GSList  *gconf_list = NULL;
 
548
        GError **error = NULL;
 
549
        gboolean success = FALSE;
 
550
        
 
551
        
 
552
        
 
553
        for(list = global_repo_list; list != NULL; list = list->next)
 
554
        {
 
555
                repo_t *repo;
 
556
                gchar gconf_str[1024];
 
557
                
 
558
                repo = list->data;
 
559
                
 
560
                
 
561
                g_sprintf(      gconf_str, 
 
562
                                "%s|%s|%s|%i",
 
563
                                repo->name, repo->uri, repo->dir, repo->inverted_zoom);
 
564
                
 
565
                gconf_list = g_slist_append(gconf_list, g_strdup(gconf_str));
 
566
 
 
567
                printf("GCONFSAVE: \n -- name: %s \n -- uri: %s \n -- dir: %s \n -- zoom: %i \n\n %s \n",
 
568
                        repo->name, repo->uri, repo->dir, repo->inverted_zoom, gconf_str);
 
569
        }
 
570
        
 
571
        success = gconf_client_set_list(        global_gconfclient, 
 
572
                                                GCONF"/repos",
 
573
                                                GCONF_VALUE_STRING,
 
574
                                                gconf_list,
 
575
                                                error);
 
576
        
 
577
        printf("*** %s(): %i \n",__PRETTY_FUNCTION__, success);
 
578
 
 
579
}
 
580
 
 
581
 
 
582
 
 
583
 
 
584
void
 
585
repoconfig__populate_dialog()
 
586
{
 
587
 
 
588
}
 
589
 
 
590
void
 
591
repoconfig__set_current_list_pointer()
 
592
{
 
593
        
 
594
        
 
595
        GSList          *list;
 
596
        const gchar     *reponame;
 
597
        
 
598
        for(list = global_repo_list; list != NULL; list = list->next)
 
599
        {
 
600
                repo_t *repo;
 
601
                repo    = list->data;
 
602
                
 
603
                reponame = g_strdup(repo->name);
 
604
                
 
605
                if(     g_strrstr(reponame,global_curr_reponame) != NULL &&
 
606
                        strlen(reponame) == strlen(global_curr_reponame)        
 
607
                )
 
608
                        global_curr_repo = list;
 
609
        }
 
610
        if(!global_curr_repo)
 
611
        {
 
612
                printf("\n#\n#\n#  ERROR: repository %s is broken \n#\n#\n", global_curr_reponame);
 
613
                
 
614
                printf("Resetting repo_name and exiting now.\n\n");
 
615
                printf("If problem persists after restart, \n");
 
616
                printf("execute in a terminal: gconftool-2 -u /apps/tangogps/repos");
 
617
                system("gconftool-2 -u /apps/tangogps/repo_name");
 
618
                exit(EXIT_FAILURE);             
 
619
        }
 
620
}
 
621
 
 
622
 
 
623
void
 
624
repoconfig__create_dropdown()
 
625
{
 
626
        GtkWidget       *combobox;
 
627
        GSList          *list;
 
628
        int             i = 0;
 
629
        int             j = 0;
 
630
        const gchar     *reponame;
 
631
        
 
632
        combobox = lookup_widget(window1, "combobox1");
 
633
 
 
634
        for(list = global_repo_list; list != NULL; list = list->next)
 
635
        {
 
636
                repo_t  *repo;
 
637
                
 
638
                repo = list->data;
 
639
                reponame = g_strdup(repo->name);
 
640
                gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), g_strdup(repo->name));
 
641
                
 
642
                if(     g_strrstr(reponame,global_curr_reponame) != NULL &&
 
643
                        strlen(reponame) == strlen(global_curr_reponame)        
 
644
                )
 
645
                {
 
646
                        j = i;
 
647
                        global_curr_repo = list;
 
648
                }
 
649
                i++;
 
650
        }
 
651
        global_repo_cnt = i;
 
652
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), j);
 
653
}
 
654
 
 
655
 
 
656
void
 
657
pre_init()
 
658
{
 
659
        GError  **err = NULL;
 
660
 
 
661
        g_type_init();
 
662
 
 
663
        global_home_dir = getenv("HOME");
 
664
 
 
665
        global_gconfclient      = gconf_client_get_default();
 
666
        global_curr_reponame    = gconf_client_get_string(global_gconfclient, GCONF"/repo_name",err);
 
667
 
 
668
 
 
669
        if(global_curr_reponame == NULL)
 
670
        {
 
671
                printf("gconf repo_name not set\n");
 
672
                global_curr_reponame = g_strdup("OSM");
 
673
        }
 
674
        gconf_get_repolist();   
 
675
        repoconfig__set_current_list_pointer();
 
676
        
 
677
        global_x = gconf_client_get_int(
 
678
                                global_gconfclient, 
 
679
                                GCONF"/global_x",
 
680
                                err);
 
681
        global_y = gconf_client_get_int(
 
682
                                global_gconfclient, 
 
683
                                GCONF"/global_y",
 
684
                                err);
 
685
        global_zoom = gconf_client_get_int(
 
686
                                global_gconfclient, 
 
687
                                GCONF"/global_zoom",
 
688
                                err);
 
689
        
 
690
 
 
691
 
 
692
 
 
693
        if(global_zoom <= 2) 
 
694
        {
 
695
                global_x = 890;
 
696
                global_y = 515;
 
697
                global_zoom = 3;
 
698
        }
 
699
        
 
700
        if(gconf_client_get_bool(global_gconfclient, GCONF"/started_before", err))      
 
701
                global_auto_download = gconf_client_get_bool(
 
702
                                        global_gconfclient, 
 
703
                                        GCONF"/auto_download",
 
704
                                        err);
 
705
        else
 
706
        {
 
707
                gconf_client_set_bool(global_gconfclient, GCONF"/started_before", TRUE, err);
 
708
                gconf_client_set_bool(global_gconfclient, GCONF"/auto_download", TRUE, err);
 
709
                global_auto_download = TRUE;
 
710
        }
 
711
}
 
712
 
 
713
void
 
714
init()
 
715
{
 
716
        gint timer;
 
717
        gpointer data = NULL;   
 
718
        
 
719
        GError  *err = NULL;
 
720
        const gchar *nick, *pass;
 
721
        GtkWidget *nick_entry, *pass_entry, *widget;
 
722
        gchar buffer[128];
 
723
        gboolean gconf_fftimer_running;
 
724
        char *str = NULL;
 
725
        int screen_height;
 
726
        
 
727
        screen_height = gdk_screen_get_height(gdk_screen_get_default());
 
728
        
 
729
        if(screen_height < 640)
 
730
        {
 
731
                printf("height: %d \n",screen_height);
 
732
                gtk_window_resize(GTK_WINDOW(window1), 480, screen_height-10);
 
733
        }
 
734
        
 
735
        tangogps_dir = g_strconcat(global_home_dir, "/.tangogps", NULL);
 
736
        g_mkdir(tangogps_dir, 0700);
 
737
 
 
738
        repoconfig__create_dropdown();
 
739
 
 
740
        
 
741
        nick_entry  = lookup_widget(window1, "entry7");
 
742
        pass_entry  = lookup_widget(window1, "entry8");
 
743
 
 
744
        global_gconfclient      = gconf_client_get_default(); 
 
745
        nick                    = gconf_client_get_string(global_gconfclient, GCONF"/nick",&err);
 
746
        pass                    = gconf_client_get_string(global_gconfclient, GCONF"/pass",&err);
 
747
        
 
748
        global_speed_unit       = gconf_client_get_int(global_gconfclient, GCONF"/speed_unit",&err);
 
749
        global_alt_unit         = gconf_client_get_int(global_gconfclient, GCONF"/alt_unit",&err);
 
750
        global_latlon_unit      = gconf_client_get_int(global_gconfclient, GCONF"/latlon_unit",&err);
 
751
        
 
752
        switch (global_speed_unit)
 
753
        {
 
754
                case 1:
 
755
                        widget = lookup_widget(window1, "radiobutton15");
 
756
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
757
                        break;
 
758
                case 2:
 
759
                        widget = lookup_widget(window1, "radiobutton16");
 
760
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
761
                        break;
 
762
        }
 
763
        
 
764
        switch (global_alt_unit)
 
765
        {
 
766
                case 1:
 
767
                        widget = lookup_widget(window1, "radiobutton18");
 
768
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
769
                        break;
 
770
        }
 
771
        
 
772
        switch (global_latlon_unit)
 
773
        {
 
774
                case 1:
 
775
                        widget = lookup_widget(window1, "radiobutton20");
 
776
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
777
                        break;
 
778
                case 2:
 
779
                        widget = lookup_widget(window1, "radiobutton21");
 
780
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
781
                        break;
 
782
        }
 
783
        
 
784
        gtk_entry_set_text( GTK_ENTRY(nick_entry), nick );
 
785
        gtk_entry_set_text( GTK_ENTRY(pass_entry), pass );
 
786
        
 
787
        widget = lookup_widget(window1, "vscale1");
 
788
        gtk_range_set_value(GTK_RANGE(widget), (double) global_zoom);
 
789
        
 
790
        global_track_dir        = gconf_client_get_string(global_gconfclient, GCONF"/track_dir",&err);
 
791
        if(!global_track_dir)
 
792
                global_track_dir = g_strdup_printf("%s/Maps/",global_home_dir);
 
793
        
 
794
        global_myposition.lat = 0;
 
795
        global_myposition.lon = 0;
 
796
 
 
797
        widget = lookup_widget(window1, "checkbutton2");
 
798
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), global_auto_download);
 
799
 
 
800
        
 
801
        
 
802
        
 
803
        
 
804
        
 
805
        gconf_fftimer_running = gconf_client_get_bool(global_gconfclient, GCONF"/fftimer_running",&err);
 
806
        
 
807
        
 
808
        global_ffupdate_interval_minutes = gconf_client_get_float(global_gconfclient, GCONF"/ffupdate_interval_minutes",&err);
 
809
        global_ffupdate_interval = (int)floor(global_ffupdate_interval_minutes) * 60000;
 
810
        widget = lookup_widget(window1, "entry16");
 
811
        if (global_ffupdate_interval_minutes<10)
 
812
                g_sprintf(buffer, "%.1f", global_ffupdate_interval_minutes);
 
813
        else
 
814
                g_sprintf(buffer, "%.0f", global_ffupdate_interval_minutes);
 
815
        gtk_entry_set_text( GTK_ENTRY(widget), buffer );
 
816
        
 
817
        
 
818
        global_ffupdate_auto    = gconf_client_get_bool(global_gconfclient, GCONF"/ffupdate_auto",&err);
 
819
        if(global_ffupdate_auto)
 
820
        {
 
821
                widget = lookup_widget(window1, "radiobutton13");
 
822
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
 
823
        }
 
824
 
 
825
        
 
826
        if(gconf_fftimer_running)
 
827
        {
 
828
                widget = lookup_widget(menu1, "item19");
 
829
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
 
830
        }
 
831
                
 
832
        
 
833
        global_ffcm_public      = gconf_client_get_bool(global_gconfclient, GCONF"/ffcm_public",&err);
 
834
        global_ffcm_registered  = gconf_client_get_bool(global_gconfclient, GCONF"/ffcm_registered",&err);
 
835
        global_ffcm_friends     = gconf_client_get_bool(global_gconfclient, GCONF"/ffcm_friends",&err);
 
836
        
 
837
        widget = lookup_widget(window1, "checkbutton3");
 
838
        if(global_ffcm_public)
 
839
        {
 
840
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
841
        }
 
842
        else
 
843
        {
 
844
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
845
        }
 
846
 
 
847
 
 
848
        widget = lookup_widget(window1, "checkbutton4");
 
849
        if(global_ffcm_registered)
 
850
        {
 
851
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
852
        }
 
853
        else
 
854
        {
 
855
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
856
        }
 
857
 
 
858
        
 
859
        widget = lookup_widget(window1, "checkbutton5");
 
860
        if(global_ffcm_friends)
 
861
        {
 
862
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
863
        }
 
864
        else
 
865
        {
 
866
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
867
        }       
 
868
        
 
869
        
 
870
        
 
871
        
 
872
        global_ffcu_public      = gconf_client_get_bool(global_gconfclient, GCONF"/ffcu_public",&err);
 
873
        global_ffcu_registered  = gconf_client_get_bool(global_gconfclient, GCONF"/ffcu_registered",&err);
 
874
        global_ffcu_friends     = gconf_client_get_bool(global_gconfclient, GCONF"/ffcu_friends",&err);
 
875
        
 
876
        widget = lookup_widget(window1, "checkbutton6");
 
877
        if(global_ffcu_public)
 
878
        {
 
879
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
880
        }
 
881
        else
 
882
        {
 
883
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
884
        }
 
885
        
 
886
        
 
887
        widget = lookup_widget(window1, "checkbutton7");
 
888
        if(global_ffcu_registered)
 
889
        {
 
890
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
891
        }
 
892
        else
 
893
        {
 
894
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
895
        }
 
896
 
 
897
        
 
898
        widget = lookup_widget(window1, "checkbutton8");
 
899
        if(global_ffcu_friends)
 
900
        {
 
901
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
 
902
        }
 
903
        else
 
904
        {
 
905
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
 
906
        }       
 
907
        
 
908
        widget = lookup_widget(window1, "label117");
 
909
#ifdef VERSION
 
910
        gtk_label_set_label(GTK_LABEL(widget), "<i>tangoGPS version: " VERSION "\nDeveloper: Marcus Bauer</i>");
 
911
#endif
 
912
 
 
913
        str = gconf_client_get_string(global_gconfclient, GCONF"/gpsd_host",&err);
 
914
        widget = lookup_widget(window1, "entry3");
 
915
        gtk_entry_set_text(GTK_ENTRY(widget), g_strdup(str));
 
916
        g_free(str);
 
917
        
 
918
        str = gconf_client_get_string(global_gconfclient, GCONF"/gpsd_port",&err);
 
919
        widget = lookup_widget(window1, "entry4");
 
920
        gtk_entry_set_text(GTK_ENTRY(widget), g_strdup(str));
 
921
        g_free(str);
 
922
        
 
923
        if (gconf_client_get_bool(global_gconfclient, GCONF"/tracklog_on", NULL))
 
924
                gtk_button_clicked(GTK_BUTTON(lookup_widget(window1,"button18")));
 
925
        
 
926
        timer = g_timeout_add (1000,cb_gps_timer,data);
 
927
        
 
928
        gtk_window_set_icon_from_file(GTK_WINDOW(window1), PACKAGE_PIXMAPS_DIR "/" PNAME ".png" ,&err);
 
929
        if (err)
 
930
        {
 
931
                fprintf (stderr, "Failed to load pixbuf file:  %s\n", err->message);
 
932
                g_error_free (err);
 
933
        }
 
934
}