File: gtk-sat-popup-common.c

package info (click to toggle)
gpredict 2.3-72-gc596101-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 12,264 kB
  • sloc: ansic: 39,918; makefile: 469; python: 143; sh: 85
file content (248 lines) | stat: -rw-r--r-- 9,313 bytes parent folder | download | duplicates (2)
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
/*
  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 "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);

    /* finally 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);
}

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 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);
    }
}