-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathgtk-sat-popup-common.c
More file actions
304 lines (257 loc) · 10.4 KB
/
Copy pathgtk-sat-popup-common.c
File metadata and controls
304 lines (257 loc) · 10.4 KB
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
/*
Gpredict: Real-time satellite tracking and orbit prediction program
Copyright (C) 2001-2017 Alexandru Csete, OZ9AEC.
2011 Charles Suprin, AA1VS
This program 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.
This program 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 this program; if not, visit http://www.fsf.org/
*/
#include <gtk/gtk.h>
#include "gtk-sat-popup-common.h"
#include "gtk-sat-module.h"
#include "gtk-event-list.h"
#include "gtk-polar-view.h"
#include "gtk-sat-map.h"
#include "gtk-single-sat.h"
#include "gtk-sat-list.h"
#include "sat-log.h"
#include "orbit-tools.h"
#include "predict-tools.h"
#include "sat-cfg.h"
#include "sat-pass-dialogs.h"
void add_pass_menu_items(GtkWidget * menu, sat_t * sat, qth_t * qth,
gdouble * tstamp, GtkWidget * widget)
{
GtkWidget *menuitem;
/* next pass and predict passes */
if (sat->el > 0.0)
{
menuitem = gtk_menu_item_new_with_label(_("Show current pass"));
g_object_set_data(G_OBJECT(menuitem), "sat", sat);
g_object_set_data(G_OBJECT(menuitem), "qth", qth);
g_object_set_data(G_OBJECT(menuitem), "tstamp", tstamp);
g_signal_connect(menuitem, "activate",
G_CALLBACK(show_current_pass_cb), widget);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
/* the next pass menu item */
menuitem = gtk_menu_item_new_with_label(_("Show next pass"));
g_object_set_data(G_OBJECT(menuitem), "sat", sat);
g_object_set_data(G_OBJECT(menuitem), "qth", qth);
g_object_set_data(G_OBJECT(menuitem), "tstamp", tstamp);
g_signal_connect(menuitem, "activate", G_CALLBACK(show_next_pass_cb),
widget);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
/* the future pass menu item */
menuitem = gtk_menu_item_new_with_label(_("Future passes"));
g_object_set_data(G_OBJECT(menuitem), "sat", sat);
g_object_set_data(G_OBJECT(menuitem), "qth", qth);
g_object_set_data(G_OBJECT(menuitem), "tstamp", tstamp);
g_signal_connect(menuitem, "activate", G_CALLBACK(show_future_passes_cb),
widget);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
/* finally the select menu item */
menuitem = gtk_menu_item_new_with_label(_("Select"));
g_object_set_data(G_OBJECT(menuitem), "sat", sat);
g_signal_connect(menuitem, "activate", G_CALLBACK(sat_select_cb),
widget);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
void show_current_pass_cb(GtkWidget * menuitem, gpointer data)
{
sat_t *sat;
qth_t *qth;
gdouble *tstamp;
GtkWindow *toplevel =
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(data)));
sat = SAT(g_object_get_data(G_OBJECT(menuitem), "sat"));
qth = (qth_t *) (g_object_get_data(G_OBJECT(menuitem), "qth"));
tstamp = (gdouble *) (g_object_get_data(G_OBJECT(menuitem), "tstamp"));
if (sat->el > 0.0)
show_next_pass_dialog(sat, qth, *tstamp, toplevel);
}
void show_next_pass_cb(GtkWidget * menuitem, gpointer data)
{
sat_t *sat;
qth_t *qth;
gdouble *tstamp;
GtkWindow *toplevel =
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(data)));
sat = SAT(g_object_get_data(G_OBJECT(menuitem), "sat"));
qth = (qth_t *) (g_object_get_data(G_OBJECT(menuitem), "qth"));
tstamp = (gdouble *) (g_object_get_data(G_OBJECT(menuitem), "tstamp"));
if (sat->el < 0)
show_next_pass_dialog(sat, qth, *tstamp, toplevel);
else
/*if the satellite is currently visible
go to end of pass and then add 10 minutes */
show_next_pass_dialog(sat, qth, sat->los + 0.007, toplevel);
}
void show_future_passes_cb(GtkWidget * menuitem, gpointer data)
{
sat_t *sat;
qth_t *qth;
gdouble *tstamp;
GtkWindow *toplevel =
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(data)));
sat = SAT(g_object_get_data(G_OBJECT(menuitem), "sat"));
qth = (qth_t *) (g_object_get_data(G_OBJECT(menuitem), "qth"));
tstamp = (gdouble *) (g_object_get_data(G_OBJECT(menuitem), "tstamp"));
show_future_passes_dialog(sat, qth, *tstamp, toplevel);
}
void sat_select_cb(GtkWidget * menuitem, gpointer data)
{
sat_t *sat;
GtkWidget *satmod;
if (IS_GTK_SAT_LIST(data))
{
satmod = GTK_SAT_LIST(data)->satmod;
}
else if (IS_GTK_SAT_MAP(data))
{
satmod = GTK_SAT_MAP(data)->satmod;
}
else if (IS_GTK_POLAR_VIEW(data))
{
satmod = GTK_POLAR_VIEW(data)->satmod;
}
else if (IS_GTK_SINGLE_SAT(data))
{
satmod = GTK_SINGLE_SAT(data)->satmod;
}
else if (IS_GTK_EVENT_LIST(data))
{
satmod = GTK_EVENT_LIST(data)->satmod;
}
else
{
sat_log_log(SAT_LOG_LEVEL_ERROR,
_("%s:%d: Unknown data type"), __FILE__, __LINE__);
return;
}
sat = SAT(g_object_get_data(G_OBJECT(menuitem), "sat"));
gtk_sat_module_select_sat(GTK_SAT_MODULE(satmod), sat->tle.catnr);
}
void show_next_pass_dialog(sat_t * sat, qth_t * qth, gdouble tstamp,
GtkWindow * toplevel)
{
GtkWidget *dialog;
pass_t *pass;
/* check whether sat actually has AOS */
if (has_aos(sat, qth))
{
if (sat_cfg_get_bool(SAT_CFG_BOOL_PRED_USE_REAL_T0))
{
pass = get_next_pass(sat, qth,
sat_cfg_get_int(SAT_CFG_INT_PRED_LOOK_AHEAD));
}
else
{
pass = get_pass(sat, qth, tstamp,
sat_cfg_get_int(SAT_CFG_INT_PRED_LOOK_AHEAD));
}
if (pass != NULL)
{
show_pass(sat->nickname, qth, pass, GTK_WIDGET(toplevel));
}
else
{
/* show dialog that there are no passes within time frame */
dialog = gtk_message_dialog_new(toplevel,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
_("Satellite %s has no passes\n"
"within the next %d days"),
sat->nickname,
sat_cfg_get_int
(SAT_CFG_INT_PRED_LOOK_AHEAD));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}
else
{
/* show dialog telling that this sat never reaches AOS */
dialog = gtk_message_dialog_new(toplevel,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("Satellite %s has no passes for\n"
"the current ground station!\n\n"
"This can be because the satellite\n"
"is geostationary, decayed or simply\n"
"never comes above the horizon"),
sat->nickname);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}
void show_future_passes_dialog(sat_t * sat, qth_t * qth, gdouble tstamp,
GtkWindow * toplevel)
{
GSList *passes = NULL;
GtkWidget *dialog;
/* check wheather sat actially has AOS */
if (has_aos(sat, qth))
{
if (sat_cfg_get_bool(SAT_CFG_BOOL_PRED_USE_REAL_T0))
{
passes = get_next_passes(sat, qth,
sat_cfg_get_int
(SAT_CFG_INT_PRED_LOOK_AHEAD),
sat_cfg_get_int
(SAT_CFG_INT_PRED_NUM_PASS));
}
else
{
passes = get_passes(sat, qth, tstamp,
sat_cfg_get_int(SAT_CFG_INT_PRED_LOOK_AHEAD),
sat_cfg_get_int(SAT_CFG_INT_PRED_NUM_PASS));
}
if (passes != NULL)
{
show_passes(sat->nickname, qth, passes, GTK_WIDGET(toplevel));
}
else
{
/* show dialog that there are no passes within time frame */
dialog = gtk_message_dialog_new(toplevel,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
_("Satellite %s has no passes\n"
"within the next %d days"),
sat->nickname,
sat_cfg_get_int
(SAT_CFG_INT_PRED_LOOK_AHEAD));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}
else
{
/* show dialog */
GtkWidget *dialog;
dialog = gtk_message_dialog_new(toplevel,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("Satellite %s has no passes for\n"
"the current ground station!"),
sat->nickname);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}