]> err.no Git - mapper/blob - src/utils.c
Move some variables and types around
[mapper] / src / utils.c
1 #define _GNU_SOURCE
2
3 #include <config.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stddef.h>
9 #include <locale.h>
10 #include <math.h>
11 #include <errno.h>
12 #include <sys/wait.h>
13 #include <glib/gstdio.h>
14 #include <gtk/gtk.h>
15 #include <fcntl.h>
16 #include <gdk/gdkkeysyms.h>
17 #include <libgnomevfs/gnome-vfs.h>
18 #include <curl/multi.h>
19 #include <gconf/gconf-client.h>
20 #include <libxml/parser.h>
21
22 #include "path.h"
23 #include "utils.h"
24 #include "gps.h"
25 #include "gpsdata.h"
26 #include "mapper-types.h"
27 #include "bt.h"
28
29 void 
30 sound_noise(void)
31 {
32 #ifdef WITH_HILDON
33 hildon_play_system_sound("/usr/share/sounds/ui-information_note.wav");
34 #else
35 gdk_beep();
36 #endif
37 }
38
39 void
40 deg_format(DegFormat degformat, gdouble coor, gchar * scoor, gchar neg_char, gchar pos_char)
41 {
42 gdouble min;
43 gdouble acoor=fabs(coor);
44
45 switch (degformat) {
46         case DDPDDDDD:
47                 sprintf(scoor, "%.5f°", coor);
48                 break;
49         case DDPDDDDD_NSEW:
50                 sprintf(scoor, "%.5f° %c", acoor,
51                         coor < 0.f ? neg_char : pos_char);
52                 break;
53
54         case DD_MMPMMM:
55                 sprintf(scoor, "%d°%06.3f'",
56                         (int)coor, (acoor - (int)acoor) * 60.0);
57                 break;
58         case DD_MMPMMM_NSEW:
59                 sprintf(scoor, "%d°%06.3f' %c",
60                         (int)acoor, (acoor - (int)acoor) * 60.0,
61                         coor < 0.f ? neg_char : pos_char);
62                 break;
63
64         case DD_MM_SSPS:
65                 min = (acoor - (int)acoor) * 60.0;
66                 sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min,
67                         ((min - (int)min) * 60.0));
68                 break;
69         case DD_MM_SSPS_NSEW:
70                 min = (acoor - (int)acoor) * 60.0;
71                 sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min,
72                         ((min - (int)min) * 60.0),
73                         coor < 0.f ? neg_char : pos_char);
74                 break;
75         default:;
76 }
77 }
78
79 /**
80  * Convert the float lat/lon/speed/heading data into integer units.
81  */
82 void 
83 integerize_data(GpsData *gps, Point *pos)
84 {
85 gdouble tmp;
86
87 latlon2unit(gps->lat, gps->lon, pos->unitx, pos->unity);
88
89 tmp=(gps->heading*(1.f/180.f))*G_PI;
90 gps->vel_offsetx=(gint)(floorf(gps->speed*sinf(tmp)+0.5f));
91 gps->vel_offsety=-(gint)(floorf(gps->speed*cosf(tmp)+0.5f));
92 }
93
94 gint
95 download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data)
96 {
97 gint diff = (a->priority - b->priority);
98 if (diff)
99         return diff;
100 diff = (a->tilex - b->tilex);
101 if (diff)
102         return diff;
103 diff = (a->tiley - b->tiley);
104 if (diff)
105         return diff;
106 diff = (a->zoom - b->zoom);
107 if (diff)
108         return diff;
109 diff = (a->repo - b->repo);
110 if (diff)
111         return diff;
112 /* Otherwise, deletes are "greatest" (least priority). */
113 if (!a->retries)
114         return (b->retries ? -1 : 0);
115 else if (!b->retries)
116         return (a->retries ? 1 : 0);
117 /* Do updates after non-updates (because they'll both be done anyway). */
118 return (a->retries - b->retries);
119 }