-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcallbacks.c
176 lines (157 loc) · 5.01 KB
/
callbacks.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
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <fap.h>
#include <osm-gps-map.h>
#include <sqlite3.h>
#include "callbacks.h"
#include "aprsis.h"
G_MODULE_EXPORT int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
G_MODULE_EXPORT int call_callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
G_MODULE_EXPORT int user_callback(aprs_details *properties, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
if (strcmp (azColName[i],"lat") == 0) {
properties->lat = g_ascii_strtod (argv[i],NULL);
//printf("%f\n", properties->lat); //debug
printf("Lat Data Loaded\n");
} else if (strcmp (azColName[i],"lon") == 0) {
properties->lon = g_ascii_strtod (argv[i],NULL);
//printf("%f\n", properties->lon); //debug
printf("Lon Data Loaded\n");
}
//osm_gps_map_set_center_and_zoom(map,properties->lat,properties->lon,5);
}
printf("\n");
return 0;
}
G_MODULE_EXPORT gboolean
on_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
if(event->type == GDK_2BUTTON_PRESS) {
int zoom;
g_object_get(map, "zoom", &zoom, NULL);
osm_gps_map_set_zoom(map, zoom+1);
}
return FALSE;
}
/*
Unconnected callbacks that will likely become useful in time.
G_MODULE_EXPORT gboolean
on_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
float lat,lon;
OsmGpsMap *map = OSM_GPS_MAP(widget);
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
gchar *msg = g_strdup_printf("%f,%f",lat,lon);
g_free(msg);
return FALSE;
} */
G_MODULE_EXPORT gboolean
on_set_home_activate_event (GtkWidget *widget, aprs_details *properties)
{
float lat,lon;
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
properties->lat = lat;
properties->lon = lon;
//set filter around home area
aprsis_set_filter(properties->ctx, properties->lat, properties->lon, properties->range);
//update text boxes in properties
gtk_entry_set_text(latent, g_strdup_printf("%f",properties->lat));
gtk_entry_set_text(lonent, g_strdup_printf("%f",properties->lon));
gtk_entry_set_text(rangeent, g_strdup_printf("%d",properties->range));
return FALSE;
}
G_MODULE_EXPORT gboolean
on_zoom_in_clicked_event (GtkWidget *widget, gpointer user_data)
{
int zoom;
g_object_get(map, "zoom", &zoom, NULL);
osm_gps_map_set_zoom(map, zoom+1);
return FALSE;
}
G_MODULE_EXPORT gboolean
on_zoom_out_clicked_event (GtkWidget *widget, gpointer user_data)
{
int zoom;
g_object_get(map, "zoom", &zoom, NULL);
osm_gps_map_set_zoom(map, zoom-1);
return FALSE;
}
G_MODULE_EXPORT gboolean
on_home_clicked_event (GtkWidget *widget, aprs_details *properties)
{
//change this bitch up
osm_gps_map_set_center_and_zoom(map,properties->lat,properties->lon,5);
return FALSE;
}
G_MODULE_EXPORT void
on_about_clicked_event (GtkWidget *widget, gpointer user_data)
{
gtk_dialog_run (GTK_DIALOG(about) );
gtk_widget_hide (GTK_WIDGET(about));
}
G_MODULE_EXPORT gpointer
on_properties_clicked_event (GtkWidget *widget, aprs_details *properties)
{
gtk_window_present( GTK_WINDOW( popup ) );
return FALSE;
}
G_MODULE_EXPORT gboolean
on_properties_ok_clicked (GtkWidget *widget, aprs_details *properties)
{
double oldlat = properties->lat;
double oldlon = properties->lon;
printf("We were: %f%f\n",oldlat,oldlon);
properties->lat=g_ascii_strtod (gtk_entry_get_text(GTK_ENTRY(latent)),NULL);
properties->lon=g_ascii_strtod (gtk_entry_get_text(GTK_ENTRY(lonent)), NULL);
properties->range=g_ascii_strtod (gtk_entry_get_text(GTK_ENTRY(rangeent)), NULL);
printf("We are: %f%f\n",properties->lat,properties->lon);
//Check Latitude/Longitude entries are correct
if(properties->lat > 89.9 || properties->lat < -89.9) {
//printf("Invalid Lat\n");
//double homelat = oldlat;
//printf("New Lat:%f\n", homelat);
gtk_entry_set_text(latent, g_strdup_printf("%f",properties->lat));
}
if(properties->lon > 180 || properties->lon < -180) {
//printf("Invalid Lon\n");
//double homelon = oldlon;
//printf("New Lon:%f\n", homelon);
gtk_entry_set_text(lonent, g_strdup_printf("%f",properties->lon));
}
//centre map on new coordinates after widget closed
osm_gps_map_set_center_and_zoom(map,properties->lat, properties->lon, 5);
aprsis_set_filter(properties->ctx, properties->lat,properties->lon,properties->range);
gtk_widget_hide( GTK_WIDGET( popup ) );
return FALSE;
}
G_MODULE_EXPORT gboolean
on_properties_hide_event (GtkWidget *widget, gpointer user_data)
{
gtk_widget_hide( GTK_WIDGET( popup ) );
return FALSE;
}
G_MODULE_EXPORT void
on_close (GtkWidget *widget, gpointer user_data)
{
gtk_widget_destroy(widget);
gtk_main_quit();
}