/** \brief Get boolean parameter.
 *  \param f The configuration data for the module.
 *  \param sec Configuration section in the cfg data (see config-keys.h).
 *  \param key Configuration key in the cfg data (see config-keys.h).
 *  \param p SatCfg index to use as fallback.
 */
gboolean
mod_cfg_get_bool (GKeyFile *f, const gchar *sec, const gchar *key, sat_cfg_bool_e p)
{
     GError  *error = NULL;
     gboolean param;

     /* check whether parameter is present in GKeyFile */
     if (g_key_file_has_key (f, sec, key, NULL)) {

          param = g_key_file_get_boolean (f, sec, key, &error);

          if (error != NULL) {

               sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Failed to read boolean (%s)"),
                         __FUNCTION__, error->message);

               g_clear_error (&error);

               /* get a timeout from global config */
               param = sat_cfg_get_bool (p);
          }
     }
     /* get value from sat-cfg */
     else {
          param = sat_cfg_get_bool (p);

/*           sat_log_log (SAT_LOG_LEVEL_DEBUG, */
/*                     _("%s: Boolean value not found, using default (%d)"), */
/*                     __FUNCTION__, param); */
     }

     return param;
}
/** \brief Create window placement widgets.
 *  \param vbox The GtkVBox into which the widgets should be packed.
 *
 */
static void create_window_placement (GtkBox *vbox)
{
    GtkWidget *label;
    GtkTooltips *tips;


    /* create header */
    label = gtk_label_new (NULL);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_label_set_markup (GTK_LABEL (label),
                          _("<b>Window Placements:</b>"));
    gtk_box_pack_start (vbox, label, FALSE, FALSE, 0);

    /* main window setting */
    mwin = gtk_check_button_new_with_label (_("Restore position of main window"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mwin),
                                  sat_cfg_get_bool (SAT_CFG_BOOL_MAIN_WIN_POS));
    tips = gtk_tooltips_new ();
    gtk_tooltips_set_tip (tips, mwin,
                          _("If you check this button, gpredict will try to "\
                            "place the main window at the position it was "\
                            "during the last session.\n"\
                            "Note that window managers can ignore this request."),
                          NULL);
    g_signal_connect (G_OBJECT (mwin), "toggled",
                      G_CALLBACK (window_pos_toggle_cb), NULL);
    gtk_box_pack_start (vbox, mwin, FALSE, FALSE, 0);

    /* module window setting */
    mod = gtk_check_button_new_with_label (_("Restore position of module windows"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mod),
                                  sat_cfg_get_bool (SAT_CFG_BOOL_MOD_WIN_POS));
    tips = gtk_tooltips_new ();
    gtk_tooltips_set_tip (tips, mod,
                          _("If you check this button, gpredict will try to "\
                            "place the module windows at the position they were "\
                            "the last time.\n"\
                            "Note that window managers can ignore this request."),
                          NULL);
    g_signal_connect (G_OBJECT (mod), "toggled",
                      G_CALLBACK (window_pos_toggle_cb), NULL);
    gtk_box_pack_start (vbox, mod, FALSE, FALSE, 0);

    /* module state */
    state = gtk_check_button_new_with_label (_("Restore the state of modules when reopened (docked or window)"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state),
                                  sat_cfg_get_bool (SAT_CFG_BOOL_MOD_STATE));
    tips = gtk_tooltips_new ();
    gtk_tooltips_set_tip (tips, state,
                          _("If you check this button, gpredict will restore "\
                            "the states of the modules from the last time they were used."),
                          NULL);
    g_signal_connect (G_OBJECT (state), "toggled",
                      G_CALLBACK (window_pos_toggle_cb), NULL);
    gtk_box_pack_start (vbox, state, FALSE, FALSE, 0);
}
/* range rate is special, because we may need to convert to miles
   and want 2-3 decimal digits.
*/
static void range_rate_cell_data_function (GtkTreeViewColumn *col,
                                           GtkCellRenderer   *renderer,
                                           GtkTreeModel      *model,
                                           GtkTreeIter       *iter,
                                           gpointer           column)
{
    gdouble    number;
    gchar     *buff;
    guint      coli = GPOINTER_TO_UINT (column);
    
    (void) col; /* avoid unused parameter compiler warning */

    gtk_tree_model_get (model, iter, coli, &number, -1);

    /* convert distance to miles? */
    if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_IMPERIAL)) {
        number = KM_TO_MI(number);
    }

    /* format the number */
    buff = g_strdup_printf ("%.3f", number);
    g_object_set (renderer,
                  "text", buff,
                  NULL);
    g_free (buff);
}
Exemple #4
0
/** Save a row from the QTH list (called by the save function) */
static gboolean save_qth(GtkTreeModel * model, GtkTreePath * path,
                         GtkTreeIter * iter, gpointer data)
{
    qth_t           qth;
    gboolean        def = FALSE;
    gchar          *filename, *confdir;
    gchar          *buff;

    (void)path;
    (void)data;

    gtk_tree_model_get(model, iter,
                       QTH_LIST_COL_DEF, &def,
                       QTH_LIST_COL_NAME, &qth.name,
                       QTH_LIST_COL_LOC, &qth.loc,
                       QTH_LIST_COL_DESC, &qth.desc,
                       QTH_LIST_COL_LAT, &qth.lat,
                       QTH_LIST_COL_LON, &qth.lon,
                       QTH_LIST_COL_ALT, &qth.alt,
                       QTH_LIST_COL_WX, &qth.wx,
                       QTH_LIST_COL_TYPE, &qth.type,
                       QTH_LIST_COL_GPSD_SERVER, &qth.gpsd_server,
                       QTH_LIST_COL_GPSD_PORT, &qth.gpsd_port, -1);

    confdir = get_user_conf_dir();
    filename = g_strconcat(confdir, G_DIR_SEPARATOR_S, qth.name, ".qth", NULL);
    g_free(confdir);

    /* check wehter we are using imperial or metric system;
       in case of imperial we have to convert altitude from
       feet to meters before saving.
     */
    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_IMPERIAL))
    {
        qth.alt = (guint) FT_TO_M(qth.alt);
    }

    if (qth_data_save(filename, &qth))
    {
        /* saved ok, go on check whether qth is default */
        if (def)
        {
            sat_log_log(SAT_LOG_LEVEL_INFO,
                        _("%s:%d: %s appears to be default QTH"),
                        __FILE__, __LINE__, qth.name);

            buff = g_path_get_basename(filename);
            sat_cfg_set_str(SAT_CFG_STR_DEF_QTH, buff);
            g_free(buff);
        }
    }

    g_free(filename);
    g_free(qth.name);
    g_free(qth.loc);
    g_free(qth.desc);
    g_free(qth.wx);

    return FALSE;
}
/**
 * \brief Update Time controller widgets
 * \param mod Pointer to the GtkSatModule widget
 */
void tmg_update_widgets(GtkSatModule * mod)
{
    struct tm       tim;
    time_t          t;

    /* update time widgets */
    t = (mod->tmgCdnum - 2440587.5) * 86400.;

    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_LOCAL_TIME))
        tim = *localtime(&t);
    else
        tim = *gmtime(&t);

    /* hour, min, sec, msec */
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(mod->tmgHour), tim.tm_hour);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(mod->tmgMin), tim.tm_min);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(mod->tmgSec), tim.tm_sec);

    /* msec: alway 0 in RT and SRT modes */
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(mod->tmgMsec), 0);

    /* calendar */
    gtk_calendar_select_month(GTK_CALENDAR(mod->tmgCal),
                              tim.tm_mon, tim.tm_year + 1900);
    gtk_calendar_select_day(GTK_CALENDAR(mod->tmgCal), tim.tm_mday);
}
Exemple #6
0
/* render column containg float
   by using this instead of the default data function, we can
   disable lat,lon and alt for the continent and country rows.

   Please note that this function only affects how the numbers are
   displayed (rendered), the tree_store will still contain the
   original flaoting point numbers. Very cool!
*/
static void
loc_tree_float_cell_data_function (GtkTreeViewColumn *col,
                                           GtkCellRenderer   *renderer,
                                           GtkTreeModel      *model,
                                           GtkTreeIter       *iter,
                                           gpointer           column)
{
     gfloat   number;
     gchar   *buff;
     guint    coli = GPOINTER_TO_UINT (column);
     gchar    hmf = ' ';

     (void) col; /* avoid unused parameter compiler warning */

     gtk_tree_model_get (model, iter, coli, &number, -1);


     /* check whether configuration requests the use
        of N, S, E and W instead of signs
     */
     if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_NSEW)) {

          if (coli == TREE_COL_LAT) {
               if (number < 0.0) {
                    number *= -1.0;
                    hmf = 'S';
               }
               else {
                    hmf = 'N';
               }
          }
          else if (coli == TREE_COL_LON) {
               if (number < 0.0) {
                    number *= -1.0;
                    hmf = 'W';
               }
               else {
                    hmf = 'E';
               }
          }
          else {
               sat_log_log (SAT_LOG_LEVEL_ERROR,
                               _("%s: Invalid column: %d"),
                               __FUNCTION__, coli);
               hmf = '?';
          }
     }

     if (fabs (LTMN-number) > LTEPS) {
          buff = g_strdup_printf ("%.4f\302\260%c", number, hmf);
     }
     else {
          buff = g_strdup ("");
     }

     g_object_set (renderer, "text", buff, NULL);
     g_free (buff);
}
Exemple #7
0
/* render column containg float
   by using this instead of the default data function, we can
   control the number of decimals and display the coordinates in a
   fancy way, including degree sign and NWSE suffixes.

   Please note that this function only affects how the numbers are
   displayed (rendered), the tree_store will still contain the
   original flaoting point numbers. Very cool!
*/
static void float_cell_data_function(GtkTreeViewColumn * col,
                                     GtkCellRenderer * renderer,
                                     GtkTreeModel * model,
                                     GtkTreeIter * iter, gpointer column)
{
    gdouble         number;
    gchar          *buff;
    guint           coli = GPOINTER_TO_UINT(column);
    gchar           hmf = ' ';

    (void)col;

    gtk_tree_model_get(model, iter, coli, &number, -1);

    /* check whether configuration requests the use
       of N, S, E and W instead of signs
     */
    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_NSEW))
    {
        if (coli == QTH_LIST_COL_LAT)
        {
            if (number < 0.0)
            {
                number *= -1.0;
                hmf = 'S';
            }
            else
            {
                hmf = 'N';
            }
        }
        else if (coli == QTH_LIST_COL_LON)
        {
            if (number < 0.0)
            {
                number *= -1.0;
                hmf = 'W';
            }
            else
            {
                hmf = 'E';
            }
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_ERROR,
                        _("%s:%d: Invalid column: %d"),
                        __FILE__, __LINE__, coli);
            hmf = '?';
        }
    }

    /* format the number */
    buff = g_strdup_printf("%.4f\302\260%c", number, hmf);
    g_object_set(renderer, "text", buff, NULL);
    g_free(buff);
}
/** \brief Invoke Sky-at-glance.
 *
 * This function is a shortcut to the sky at glance function
 * in that it will make the predictions with the satellites
 * tracked in the current module.
 */
static void sky_at_glance_cb (GtkWidget *menuitem, gpointer data)
{
    GtkSatModule *module = GTK_SAT_MODULE (data);
    //GtkWidget    *skg;
    //GtkWidget    *window;
    gchar        *buff;

    (void) menuitem; /* avoid unused parameter compiler warning */

    /* if module is busy wait until done then go on */
    g_mutex_lock(&module->busy);


    if (module->skgwin != NULL) {
        /* there is already a sky at glance for this module */
        gtk_window_present (GTK_WINDOW (module->skgwin));
        g_mutex_unlock(&module->busy);

        return;
    }


    /* create window */
    module->skgwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    buff = g_strdup_printf (_("The sky at a glance (%s)"), module->name);
    gtk_window_set_title (GTK_WINDOW (module->skgwin), buff);
    g_free (buff);
    g_signal_connect (G_OBJECT (module->skgwin), "delete_event", G_CALLBACK (window_delete), NULL);
    g_signal_connect (G_OBJECT (module->skgwin), "destroy", G_CALLBACK (destroy_skg), module);

    /* window icon */
    buff = icon_file_name ("gpredict-planner.png");
    gtk_window_set_icon_from_file (GTK_WINDOW (module->skgwin), buff, NULL);
    g_free (buff);


    /* create sky at a glance widget */  
    if (sat_cfg_get_bool (SAT_CFG_BOOL_PRED_USE_REAL_T0)) {
        module->skg = gtk_sky_glance_new (module->satellites, module->qth, 0.0);
    }
    else {
        module->skg = gtk_sky_glance_new (module->satellites, module->qth, module->tmgCdnum);
    }

    /* store time at which GtkSkyGlance has been created */
    module->lastSkgUpd = module->tmgCdnum;

    gtk_container_set_border_width (GTK_CONTAINER (module->skgwin), 10);
    gtk_container_add (GTK_CONTAINER (module->skgwin), module->skg);

    gtk_widget_show_all (module->skgwin);

    g_mutex_unlock(&module->busy);

}
static GooCanvasItemModel *
        create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y)
{
    GooCanvasItemModel *item;
    time_t             t;
    gchar              buff[7];
    GtkAnchorType      anchor;
    GooCanvasItemModel *root;
    guint32            col;

    root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));

    col = mod_cfg_get_int (pv->cfgdata,
                           MOD_CFG_POLAR_SECTION,
                           MOD_CFG_POLAR_TRACK_COL,
                           SAT_CFG_INT_POLAR_TRACK_COL);

    /* convert julian date to struct tm */
    t = (time - 2440587.5)*86400.;

    /* format either local time or UTC depending on check box */
    if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_LOCAL_TIME))
        strftime (buff, 8, "%H:%M", localtime (&t));
    else
        strftime (buff, 8, "%H:%M", gmtime (&t));

    buff[6]='\0';

    if (x > pv->cx) {
        anchor = GTK_ANCHOR_EAST;
        x -= 5;
    }
    else {
        anchor = GTK_ANCHOR_WEST;
        x += 5;
    }

    item = goo_canvas_text_model_new (root, buff,
                                      (gdouble) x, (gdouble) y,
                                      -1, anchor,
                                      "font", "Sans 7",
                                      "fill-color-rgba", col,
                                      NULL);

    goo_canvas_item_model_lower (item, NULL);

    return item;
}
/*! \brief Calculate the time as Julian day (and fraction) from the TMG widgets.
 *  \param mod Pointer to the GtkSatModule this time manager belongs to.
 *  \returns The current date and time in Julian days and fraction of days.
 */
static gdouble calculate_time(GtkSatModule *mod)
{
    guint year, month, day;
    gint  hr, min, sec, msec;
    struct tm tim,utim;
    gdouble jd = 0.0;

    /* get date and time from widgets */
    gtk_calendar_get_date (GTK_CALENDAR (mod->tmgCal), &year, &month, &day);
    hr = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (mod->tmgHour));
    min = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (mod->tmgMin));
    sec = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (mod->tmgSec));
    msec = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (mod->tmgMsec));

    /* build struct_tm */
    tim.tm_year = (int) (year);
    tim.tm_mon = (int) (month+1);
    tim.tm_mday = (int) day;
    tim.tm_hour = (int) hr;
    tim.tm_min = (int) min;
    tim.tm_sec = (int) sec;

    sat_log_log (SAT_LOG_LEVEL_DEBUG,
                 _("%s: %d/%d/%d %d:%d:%d.%d"),
                 __FUNCTION__,
                 tim.tm_year, tim.tm_mon, tim.tm_mday,
                 tim.tm_hour, tim.tm_min, tim.tm_sec, msec);

    /* convert UTC time to Julian Date  */
    if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_LOCAL_TIME))
    {
        /* convert local time to UTC */
        Time_to_UTC (&tim, &utim);

        /* Convert to JD */
        jd = Julian_Date (&utim);
    }
    else
    {
        /* Already UTC, just convert to JD */
        jd = Julian_Date (&tim);
    }

    jd = jd + (gdouble)msec/8.64e+7;

    return jd;
}
Exemple #11
0
/*
 * Create a module window.
 *
 * This function is used to create a module window when opening modules
 * that should not be packed into the notebook.
 */
static void create_module_window(GtkWidget * module)
{
    gint            w, h;
    gchar          *icon;       /* icon file name */
    gchar          *title;      /* window title */
    GtkAllocation   aloc;

    gtk_widget_get_allocation(module, &aloc);
    /* get stored size; use size from main window if size not explicitly stoed */
    if (g_key_file_has_key(GTK_SAT_MODULE(module)->cfgdata,
                           MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_WIDTH, NULL))
    {
        w = g_key_file_get_integer(GTK_SAT_MODULE(module)->cfgdata,
                                   MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_WIDTH,
                                   NULL);
    }
    else
    {
        w = aloc.width;
    }
    if (g_key_file_has_key(GTK_SAT_MODULE(module)->cfgdata,
                           MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_HEIGHT, NULL))
    {
        h = g_key_file_get_integer(GTK_SAT_MODULE(module)->cfgdata,
                                   MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_HEIGHT,
                                   NULL);
    }
    else
    {
        h = aloc.height;
    }

    /* create window */
    GTK_SAT_MODULE(module)->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    title = g_strconcat(_("GPREDICT: "),
                        GTK_SAT_MODULE(module)->name,
                        " (", GTK_SAT_MODULE(module)->qth->name, ")", NULL);
    gtk_window_set_title(GTK_WINDOW(GTK_SAT_MODULE(module)->win), title);
    g_free(title);
    gtk_window_set_default_size(GTK_WINDOW(GTK_SAT_MODULE(module)->win), w, h);
    g_signal_connect(G_OBJECT(GTK_SAT_MODULE(module)->win), "configure_event",
                     G_CALLBACK(module_window_config_cb), module);

    /* window icon */
    icon = icon_file_name("gpredict-icon.png");
    if (g_file_test(icon, G_FILE_TEST_EXISTS))
    {
        gtk_window_set_icon_from_file(GTK_WINDOW(GTK_SAT_MODULE(module)->win),
                                      icon, NULL);
    }
    g_free(icon);

    /* move window to stored position if requested by configuration */
    if (sat_cfg_get_bool(SAT_CFG_BOOL_MOD_WIN_POS) &&
        g_key_file_has_key(GTK_SAT_MODULE(module)->cfgdata,
                           MOD_CFG_GLOBAL_SECTION,
                           MOD_CFG_WIN_POS_X,
                           NULL) &&
        g_key_file_has_key(GTK_SAT_MODULE(module)->cfgdata,
                           MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_POS_Y, NULL))
    {

        gtk_window_move(GTK_WINDOW(GTK_SAT_MODULE(module)->win),
                        g_key_file_get_integer(GTK_SAT_MODULE(module)->cfgdata,
                                               MOD_CFG_GLOBAL_SECTION,
                                               MOD_CFG_WIN_POS_X, NULL),
                        g_key_file_get_integer(GTK_SAT_MODULE(module)->cfgdata,
                                               MOD_CFG_GLOBAL_SECTION,
                                               MOD_CFG_WIN_POS_Y, NULL));

    }

    /* add module to window */
    gtk_container_add(GTK_CONTAINER(GTK_SAT_MODULE(module)->win), module);

    /* show window */
    gtk_widget_show_all(GTK_SAT_MODULE(module)->win);

    /* reparent time manager window if visible */
    if (GTK_SAT_MODULE(module)->tmgActive)
    {
        gtk_window_set_transient_for(GTK_WINDOW
                                     (GTK_SAT_MODULE(module)->tmgWin),
                                     GTK_WINDOW(GTK_SAT_MODULE(module)->win));
    }
}
/** \brief Toggle dockig state.
 *
 * This function is called when the user selects the (Un)Dock menu
 * item in the GtkSatModule popup menu. If the current module state
 * is DOCKED, the module will be undocked and moved into it's own,
 * GtkWindow. If the current module state is WINDOW or FULLSCREEN,
 * the module will be docked.
 *
 * The text of the menu item will be changed corresponding to the
 * action that has been performed.
 */
static void docking_state_cb (GtkWidget *menuitem, gpointer data)
{
    GtkWidget *module = GTK_WIDGET (data);
    GtkAllocation aloc;
    gint       w,h;
    gchar     *icon;      /* icon file name */
    gchar     *title;     /* window title */

    (void) menuitem; /* avoid unused parameter compiler warning */

    gtk_widget_get_allocation ( module, &aloc);
    
    switch (GTK_SAT_MODULE (module)->state) {

    case GTK_SAT_MOD_STATE_DOCKED:

        /* get stored size; use size from main window if size not explicitly stoed */
        if (g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_WIN_WIDTH,
                                NULL)) {
            w = g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata,
                                        MOD_CFG_GLOBAL_SECTION,
                                        MOD_CFG_WIN_WIDTH,
                                        NULL);
        }
        else {
            w = aloc.width;
        }
        if (g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_WIN_HEIGHT,
                                NULL)) {
            h = g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata,
                                        MOD_CFG_GLOBAL_SECTION,
                                        MOD_CFG_WIN_HEIGHT,
                                        NULL);
        }
        else {
            h = aloc.height;
        }
        
        /* increase reference count of module */
        g_object_ref (module);

        /* we don't need the positions */
        //GTK_SAT_MODULE (module)->vpanedpos = -1;
        //GTK_SAT_MODULE (module)->hpanedpos = -1;

        /* undock from mod-mgr */
        mod_mgr_undock_module (module);

        /* create window */
        GTK_SAT_MODULE (module)->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        title = g_strconcat (_("GPREDICT: "),
                             GTK_SAT_MODULE (module)->name,
                             " (", GTK_SAT_MODULE (module)->qth->name, ")",
                             NULL);
        gtk_window_set_title (GTK_WINDOW (GTK_SAT_MODULE (module)->win), title);
        g_free (title);
        gtk_window_set_default_size (GTK_WINDOW (GTK_SAT_MODULE (module)->win), w, h);
        g_signal_connect (G_OBJECT (GTK_SAT_MODULE (module)->win), "configure_event",
                          G_CALLBACK (module_window_config_cb), module);

        /* window icon */
        icon = icon_file_name ("gpredict-icon.png");
        if (g_file_test (icon, G_FILE_TEST_EXISTS)) {
            gtk_window_set_icon_from_file (GTK_WINDOW (GTK_SAT_MODULE (module)->win), icon, NULL);
        }
        g_free (icon);

        /* move window to stored position if requested by configuration */
        if (sat_cfg_get_bool (SAT_CFG_BOOL_MOD_WIN_POS) &&
            g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_WIN_POS_X,
                                NULL) &&
            g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_WIN_POS_Y,
                                NULL)) {

            gtk_window_move (GTK_WINDOW (GTK_SAT_MODULE (module)->win),
                             g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata,
                                                     MOD_CFG_GLOBAL_SECTION,
                                                     MOD_CFG_WIN_POS_X, NULL),
                             g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata,
                                                     MOD_CFG_GLOBAL_SECTION,
                                                     MOD_CFG_WIN_POS_Y,
                                                     NULL));

        }

        /* add module to window */
        gtk_container_add (GTK_CONTAINER (GTK_SAT_MODULE (module)->win), module);

        /* change internal state */
        GTK_SAT_MODULE (module)->state = GTK_SAT_MOD_STATE_WINDOW;

        /* store new state in configuration */
        g_key_file_set_integer (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_STATE,
                                GTK_SAT_MOD_STATE_WINDOW);

        /* decrease reference count of module */
        g_object_unref (module);

        /* show window */
        gtk_widget_show_all (GTK_SAT_MODULE (module)->win);
        
        /* reparent time manager window if visible */
        if (GTK_SAT_MODULE (module)->tmgActive) {
            gtk_window_set_transient_for (GTK_WINDOW (GTK_SAT_MODULE (module)->tmgWin),
                                          GTK_WINDOW (GTK_SAT_MODULE (module)->win));
        }

        break;

     case GTK_SAT_MOD_STATE_WINDOW:
     case GTK_SAT_MOD_STATE_FULLSCREEN:

        /* increase referene count */
        g_object_ref (module);

        /* reparent time manager window if visible */
        if (GTK_SAT_MODULE (module)->tmgActive) {
            gtk_window_set_transient_for (GTK_WINDOW (GTK_SAT_MODULE (module)->tmgWin),
                                          GTK_WINDOW (app));
        }

        /* remove module from window, destroy window */
        gtk_container_remove (GTK_CONTAINER (GTK_SAT_MODULE (module)->win), module);
        gtk_widget_destroy (GTK_SAT_MODULE (module)->win);
        GTK_SAT_MODULE (module)->win = NULL;

        /* dock into mod-mgr */
        mod_mgr_dock_module (module);

        /* change internal state */
        GTK_SAT_MODULE (module)->state = GTK_SAT_MOD_STATE_DOCKED;
        
        /* store new state in configuration */
        g_key_file_set_integer (GTK_SAT_MODULE (module)->cfgdata,
                                MOD_CFG_GLOBAL_SECTION,
                                MOD_CFG_STATE,
                                GTK_SAT_MOD_STATE_DOCKED);

        /* decrease reference count of module */
        g_object_unref (module);


        break;

     default:

        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s:%d: Unknown module state: %d"),
                     __FILE__, __LINE__, GTK_SAT_MODULE (module)->state);
        break;

    }


}
static void show_future_passes_cb (GtkWidget *menuitem, gpointer data)
{
    GtkWidget *dialog;
    GtkWindow *toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data)));
    GtkEventList *list = GTK_EVENT_LIST (data);
    GSList    *passes = NULL;
    sat_t     *sat;
    qth_t     *qth;



    sat = SAT(g_object_get_data (G_OBJECT (menuitem), "sat"));
    qth = (qth_t *) (g_object_get_data (G_OBJECT (menuitem), "qth"));

    /* check wheather sat actially has AOS */
    if ((sat->otype != ORBIT_TYPE_GEO) && (sat->otype != ORBIT_TYPE_DECAYED) &&
        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, list->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);
    }
}
Exemple #14
0
/**
 * Read QTH file and add data to list store.
 * @param liststore The GtkListStore where the data should be stored.
 * @param filename The full name of the qth file.
 * @return 1 if read is successful, 0 if an error occurs.
 *
 * The function uses the gtk-sat-data infrastructure to read the qth
 * data from the specified file.
 *
 * There is a little challenge here. First, we want to read the data from
 * the .qth files and store them in the list store. To do this we use a
 * qth_t structure, which can be populated using gtk_sat_data_read_qth.
 * Then, when the configuration is finished and the user presses "OK", we
 * want to write all the data back to the .qth files. To do that, we create
 * an up-to-date qth_t data structure and pass it to the gtk_sat_data_write_qth
 * function, which will take care of updating the GKeyFile data structure and
 * writing the contents to the .qth file.
 */
static guint read_qth_file(GtkListStore * liststore, gchar * filename)
{
    GtkTreeIter     item;       /* new item added to the list store */
    qth_t          *qth;        /* qth data structure */
    gchar          *defqth;
    gboolean        is_default = FALSE;
    gchar          *fname;
    gint            dispalt;    /* displayed altitude */

    if ((qth = g_try_new0(qth_t, 1)) == NULL)
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s:%d: Failed to allocate memory!\n"),
                    __FILE__, __LINE__);

        return FALSE;
    }

    /* read data from file */
    if (!qth_data_read(filename, qth))
    {
        g_free(qth);
        return FALSE;
    }

    /* calculate QRA locator */
    gint            retcode;

    qth->qra = g_malloc(7);
    retcode = longlat2locator(qth->lon, qth->lat, qth->qra, 3);

    if (retcode != RIG_OK)
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s:%d: Could not convert (%.2f,%.2f) to QRA."),
                    __FILE__, __LINE__, qth->lat, qth->lon);
        qth->qra[0] = '\0';
    }
    else
    {
        qth->qra[6] = '\0';
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s:%d: QRA locator is %s"),
                    __FILE__, __LINE__, qth->qra);
    }

    /* is this the default qth? */
    defqth = sat_cfg_get_str(SAT_CFG_STR_DEF_QTH);

    if (g_str_has_suffix(filename, defqth))
    {
        is_default = TRUE;

        sat_log_log(SAT_LOG_LEVEL_INFO,
                    _("%s:%d: This appears to be the default QTH."),
                    __FILE__, __LINE__);
    }

    g_free(defqth);

    /* check wehter we are using imperial or metric system;
       in case of imperial we have to convert altitude from
       meters to feet.
       note: the internat data are always kept in metric and
       only the displayed numbers are converted. Therefore,
       we use a dedicated var 'dispalt'
     */
    /* NO, ONLY DISPLAY WIDGETS WILL BE AFFECTED BY THIS SETTING */
    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_IMPERIAL))
    {
        dispalt = (gint) M_TO_FT(qth->alt);
    }
    else
    {
        dispalt = (gint) qth->alt;
    }

    /* strip file name; we don't need the whole path */
    fname = g_path_get_basename(filename);

    /* we now have all necessary data in the qth_t structure;
       add the data to the list store */
    gtk_list_store_append(liststore, &item);
    gtk_list_store_set(liststore, &item,
                       QTH_LIST_COL_NAME, qth->name,
                       QTH_LIST_COL_LOC, qth->loc,
                       QTH_LIST_COL_DESC, qth->desc,
                       QTH_LIST_COL_LAT, qth->lat,
                       QTH_LIST_COL_LON, qth->lon,
                       QTH_LIST_COL_ALT, dispalt,
                       QTH_LIST_COL_QRA, qth->qra,
                       QTH_LIST_COL_WX, qth->wx,
                       QTH_LIST_COL_DEF, is_default,
                       QTH_LIST_COL_TYPE, qth->type,
                       QTH_LIST_COL_GPSD_SERVER, qth->gpsd_server,
                       QTH_LIST_COL_GPSD_PORT, qth->gpsd_port, -1);

    g_free(fname);

    /* we are finished with this qth, free it */
    qth_data_free(qth);

    return TRUE;
}
/** \brief Toggle screen state.
 *
 * This function is intended to toggle between FULLSCREEN
 * and WINDOW state.
 */
static void screen_state_cb  (GtkWidget *menuitem, gpointer data)
{
    GtkWidget *module = GTK_WIDGET (data);
    gint       w,h;
    gchar     *icon;      /* icon file name */
    gchar     *title;     /* window title */

    (void) menuitem; /* avoid unused parameter compiler warning */

    switch (GTK_SAT_MODULE (module)->state) {

    case GTK_SAT_MOD_STATE_DOCKED:

        /* increase reference count of module */
        g_object_ref (module);

        /* undock from mod-mgr */
        mod_mgr_undock_module (module);

        /* create window */
        GTK_SAT_MODULE (module)->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        title = g_strconcat (_("GPREDICT: "),
                             GTK_SAT_MODULE (module)->name,
                             " (", GTK_SAT_MODULE (module)->qth->name, ")",
                             NULL);
        gtk_window_set_title (GTK_WINDOW (GTK_SAT_MODULE (module)->win), title);
        g_free (title);

        /* window icon */
        icon = icon_file_name ("gpredict-icon.png");
        if (g_file_test (icon, G_FILE_TEST_EXISTS)) {
            gtk_window_set_icon_from_file (GTK_WINDOW (GTK_SAT_MODULE (module)->win), icon, NULL);
        }
        g_free (icon);

        /* add module to window */
        gtk_container_add (GTK_CONTAINER (GTK_SAT_MODULE (module)->win), module);

        /* change internal state */
        GTK_SAT_MODULE (module)->state = GTK_SAT_MOD_STATE_FULLSCREEN;

        /* decrease reference count of module */
        g_object_unref (module);

        gtk_window_fullscreen (GTK_WINDOW (GTK_SAT_MODULE (module)->win));

        /* show window */
        gtk_widget_show_all (GTK_SAT_MODULE (module)->win);
        
        /* reparent time manager window if visible */
        if (GTK_SAT_MODULE (module)->tmgActive) {
            gtk_window_set_transient_for (GTK_WINDOW (GTK_SAT_MODULE (module)->tmgWin),
                                          GTK_WINDOW (GTK_SAT_MODULE (module)->win));
        }

        break;


     case GTK_SAT_MOD_STATE_WINDOW:
        /* change internal state */
        GTK_SAT_MODULE (module)->state = GTK_SAT_MOD_STATE_FULLSCREEN;
        gtk_window_fullscreen (GTK_WINDOW (GTK_SAT_MODULE (module)->win));
        gtk_window_set_default_size (GTK_WINDOW (GTK_SAT_MODULE (module)->win), 800, 600);

        break;


     case GTK_SAT_MOD_STATE_FULLSCREEN:
        /* change internal state */
        GTK_SAT_MODULE (module)->state = GTK_SAT_MOD_STATE_WINDOW;
        gtk_window_unfullscreen (GTK_WINDOW (GTK_SAT_MODULE (module)->win));

        /* get stored size; use some standard size if not explicitly specified */
        if (g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_WIDTH, NULL)) {
            w = g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_WIDTH, NULL);
        }
        else {
            w = 800;
        }
        if (g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_HEIGHT, NULL)) {
            h = g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_HEIGHT, NULL);
        }
        else {
            h = 600;
        }
        gtk_window_set_default_size (GTK_WINDOW (GTK_SAT_MODULE (module)->win), w, h);

        /* move window to stored position if requested by configuration */
        if (sat_cfg_get_bool (SAT_CFG_BOOL_MOD_WIN_POS) &&
            g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_POS_X, NULL) &&
            g_key_file_has_key (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_POS_Y, NULL)) {

            gtk_window_move (GTK_WINDOW (GTK_SAT_MODULE (module)->win),
                             g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_POS_X, NULL),
                             g_key_file_get_integer (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_WIN_POS_Y, NULL));

        }

        /* store new state in configuration */
        g_key_file_set_integer (GTK_SAT_MODULE (module)->cfgdata, MOD_CFG_GLOBAL_SECTION, MOD_CFG_STATE, GTK_SAT_MOD_STATE_WINDOW);

        break;

     default:

        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s:%d: Unknown module state: %d"),
                     __FILE__, __LINE__, GTK_SAT_MODULE (module)->state);
        break;

    }

}
Exemple #16
0
/** Create QTH list widgets. */
static GtkWidget *create_qth_list()
{
    GtkTreeModel   *model;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    qthlist = gtk_tree_view_new();

    model = create_and_fill_model();
    gtk_tree_view_set_model(GTK_TREE_VIEW(qthlist), model);
    g_object_unref(model);

    /* name column */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer,
                                                      "text",
                                                      QTH_LIST_COL_NAME, NULL);
    gtk_tree_view_column_set_expand(column, TRUE);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);

    /* location column */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("Location"), renderer,
                                                      "text", QTH_LIST_COL_LOC,
                                                      NULL);
    gtk_tree_view_column_set_expand(column, TRUE);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);

    /* lat column */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("Lat"), renderer,
                                                      "text", QTH_LIST_COL_LAT,
                                                      NULL);
    gtk_tree_view_column_set_alignment(column, 0.5);
    gtk_tree_view_column_set_cell_data_func(column,
                                            renderer,
                                            float_cell_data_function,
                                            GUINT_TO_POINTER(QTH_LIST_COL_LAT),
                                            NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);

    /* lon column */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("Lon"), renderer,
                                                      "text", QTH_LIST_COL_LON,
                                                      NULL);
    gtk_tree_view_column_set_alignment(column, 0.5);
    gtk_tree_view_column_set_cell_data_func(column,
                                            renderer,
                                            float_cell_data_function,
                                            GUINT_TO_POINTER(QTH_LIST_COL_LON),
                                            NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);

    /* alt column */
    renderer = gtk_cell_renderer_text_new();
    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_IMPERIAL))
    {
        column = gtk_tree_view_column_new_with_attributes(_("Alt\n(ft)"),
                                                          renderer,
                                                          "text",
                                                          QTH_LIST_COL_ALT,
                                                          NULL);
    }
    else
    {
        column =
            gtk_tree_view_column_new_with_attributes(_("Alt\n(m)"), renderer,
                                                     "text", QTH_LIST_COL_ALT,
                                                     NULL);
    }
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);
    gtk_tree_view_column_set_alignment(column, 0.5);

    /* locator */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("QRA"), renderer,
                                                      "text", QTH_LIST_COL_QRA,
                                                      NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);
    gtk_tree_view_column_set_alignment(column, 0.5);

    /* weather station */
    /*      renderer = gtk_cell_renderer_text_new (); */
    /*      column = gtk_tree_view_column_new_with_attributes (_("WX"), renderer, */
    /*                                       "text", QTH_LIST_COL_WX, */
    /*                                       NULL); */
    /*      gtk_tree_view_insert_column (GTK_TREE_VIEW (qthlist), column, -1); */
    /*      gtk_tree_view_column_set_alignment (column, 0.5); */

    /* default */
    renderer = gtk_cell_renderer_toggle_new();
    handler_id = g_signal_connect(renderer, "toggled",
                                  G_CALLBACK(default_toggled), model);

    column = gtk_tree_view_column_new_with_attributes(_("Default"), renderer,
                                                      "active",
                                                      QTH_LIST_COL_DEF, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(qthlist), column);
    gtk_tree_view_column_set_alignment(column, 0.5);

    g_signal_connect(qthlist, "row-activated", G_CALLBACK(row_activated_cb),
                     NULL);

#ifdef HAS_LIBGPS
    /* GPSD enabled */
    /*server */
    renderer = gtk_cell_renderer_text_new();
    column =
        gtk_tree_view_column_new_with_attributes(_("GPSD\nServer"), renderer,
                                                 "text",
                                                 QTH_LIST_COL_GPSD_SERVER,
                                                 NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);
    gtk_tree_view_column_set_alignment(column, 0.5);
    /*port */
    renderer = gtk_cell_renderer_text_new();
    column =
        gtk_tree_view_column_new_with_attributes(_("GPSD\nPort"), renderer,
                                                 "text",
                                                 QTH_LIST_COL_GPSD_PORT, NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);
    gtk_tree_view_column_set_alignment(column, 0.5);

    /*type */
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("QTH\nType"), renderer,
                                                      "text",
                                                      QTH_LIST_COL_TYPE, NULL);
    gtk_tree_view_insert_column(GTK_TREE_VIEW(qthlist), column, -1);
    gtk_tree_view_column_set_alignment(column, 0.5);
#endif

    return qthlist;
}
/** \brief Create and initialise widgets for the radios tab.
 *
 * The widgets must be preloaded with values from config. If a config value
 * is NULL, sensible default values, eg. those from defaults.h should
 * be laoded.
 */
GtkWidget *sat_pref_conditions_create ()
{
     GtkWidget   *table;
     GtkWidget   *label;
     GtkWidget   *vbox;


     dirty = FALSE;
     reset = FALSE;

     table = gtk_table_new (14, 3, FALSE);
     gtk_table_set_row_spacings (GTK_TABLE (table), 10);
     gtk_table_set_col_spacings (GTK_TABLE (table), 5);

     /* minimum elevation */
     label = gtk_label_new (_("Minimum elevation"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 0, 1,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     minel = gtk_spin_button_new_with_range (1, 90, 1);
     gtk_widget_set_tooltip_text (minel,
                                _("Elevation threshold for passes.\n"\
                                   "Passes with maximum elevation below this limit "\
                                  "will be omitted"));
     gtk_spin_button_set_digits (GTK_SPIN_BUTTON (minel), 0);
     gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (minel), TRUE);
     gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (minel), FALSE);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (minel),
                                      sat_cfg_get_int (SAT_CFG_INT_PRED_MIN_EL));
     g_signal_connect (G_OBJECT (minel), "value-changed",
                           G_CALLBACK (spin_changed_cb), NULL);
     gtk_table_attach (GTK_TABLE (table), minel,
                           1, 2, 0, 1,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     label = gtk_label_new (_("[deg]"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           2, 3, 0, 1,
                           GTK_FILL | GTK_EXPAND,
                           GTK_SHRINK,
                           0, 0);
     
     /* separator */
     gtk_table_attach (GTK_TABLE (table),
                           gtk_hseparator_new (),
                           0, 3, 1, 2,
                           GTK_FILL | GTK_EXPAND,
                           GTK_SHRINK,
                           0, 0);

     label = gtk_label_new (NULL);
     gtk_label_set_markup (GTK_LABEL (label), _("<b>Multiple Passes:</b>"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 2, 3,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);

     /* number of passes */
     label = gtk_label_new (_("Number of passes to predict"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 3, 4,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     numpass = gtk_spin_button_new_with_range (5, 50, 1);
     gtk_widget_set_tooltip_text (numpass,
                                  _("The maximum number of passes to predict."));
     gtk_spin_button_set_digits (GTK_SPIN_BUTTON (numpass), 0);
     gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (numpass), TRUE);
     gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (numpass), FALSE);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (numpass),
                                      sat_cfg_get_int (SAT_CFG_INT_PRED_NUM_PASS));
     g_signal_connect (G_OBJECT (numpass), "value-changed",
                           G_CALLBACK (spin_changed_cb), NULL);
     gtk_table_attach (GTK_TABLE (table), numpass,
                           1, 2, 3, 4,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);

     /* lookahead */
     label = gtk_label_new (_("Passes should occur within"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 4, 5,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     lookahead = gtk_spin_button_new_with_range (1, 14, 1);
     gtk_widget_set_tooltip_text (lookahead,
                                _("Only passes that occur within the specified "\
                                  "number of days will be shown."));
     gtk_spin_button_set_digits (GTK_SPIN_BUTTON (lookahead), 0);
     gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (lookahead), TRUE);
     gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (lookahead), FALSE);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (lookahead),
                                      sat_cfg_get_int (SAT_CFG_INT_PRED_LOOK_AHEAD));
     g_signal_connect (G_OBJECT (lookahead), "value-changed",
                           G_CALLBACK (spin_changed_cb), NULL);
     gtk_table_attach (GTK_TABLE (table), lookahead,
                           1, 2, 4, 5,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     label = gtk_label_new (_("[days]"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           2, 3, 4, 5,
                           GTK_FILL | GTK_EXPAND,
                           GTK_SHRINK,
                           0, 0);
     
     /* separator */
     gtk_table_attach (GTK_TABLE (table),
                           gtk_hseparator_new (),
                           0, 3, 5, 6,
                           GTK_FILL | GTK_EXPAND,
                           GTK_SHRINK,
                           0, 0);


     label = gtk_label_new (NULL);
     gtk_label_set_markup (GTK_LABEL (label), _("<b>Pass Details:</b>"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 6, 7,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);

     /* time resolution */
     label = gtk_label_new (_("Time resolution"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 7, 8,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     res = gtk_spin_button_new_with_range (1, 600, 1);
     gtk_widget_set_tooltip_text (res,
                                _("Gpredict will try to show the pass details "\
                                  "with the specified time resolution."));
     gtk_spin_button_set_digits (GTK_SPIN_BUTTON (res), 0);
     gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (res), TRUE);
     gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (res), FALSE);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (res),
                                      sat_cfg_get_int (SAT_CFG_INT_PRED_RESOLUTION));
     g_signal_connect (G_OBJECT (res), "value-changed",
                           G_CALLBACK (spin_changed_cb), NULL);
     gtk_table_attach (GTK_TABLE (table), res,
                           1, 2, 7, 8,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     label = gtk_label_new (_("[sec]"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           2, 3, 7, 8,
                           GTK_FILL | GTK_EXPAND,
                           GTK_SHRINK,
                           0, 0);

     /* number of entries */
     label = gtk_label_new (_("Number of entries"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
     gtk_table_attach (GTK_TABLE (table), label,
                           0, 1, 8, 9,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);
     nument = gtk_spin_button_new_with_range (10, 200, 1);
     gtk_widget_set_tooltip_text (nument,
                                  _("Gpredict will try to keep the number of rows " \
                                    "in the detailed prediction within this limit."));
     gtk_spin_button_set_digits (GTK_SPIN_BUTTON (nument), 0);
     gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (nument), TRUE);
     gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (nument), FALSE);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (nument),
                                      sat_cfg_get_int (SAT_CFG_INT_PRED_NUM_ENTRIES));
     g_signal_connect (G_OBJECT (nument), "value-changed",
                           G_CALLBACK (spin_changed_cb), NULL);
     gtk_table_attach (GTK_TABLE (table), nument,
                           1, 2, 8, 9,
                           GTK_FILL,
                           GTK_SHRINK,
                           0, 0);

    /* separator */
    gtk_table_attach (GTK_TABLE (table),
                      gtk_hseparator_new (),
                      0, 3, 9, 10,
                      GTK_FILL | GTK_EXPAND,
                      GTK_SHRINK,
                      0, 0);

    /* satellite visibility */
    label = gtk_label_new (NULL);
    gtk_label_set_markup (GTK_LABEL (label), _("<b>Satellite Visibility:</b>"));
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_table_attach (GTK_TABLE (table), label,
                      0, 1, 10, 11,
                      GTK_FILL,
                      GTK_SHRINK,
                      0, 0);

    /* twilight threshold */
    label = gtk_label_new (_("Twilight threshold"));
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_table_attach (GTK_TABLE (table), label,
                      0, 1, 11, 12,
                      GTK_FILL,
                      GTK_SHRINK,
                      0, 0);
    twspin = gtk_spin_button_new_with_range (-18, 0, 1);
    gtk_widget_set_tooltip_text (twspin,
                          _("Satellites are only considered visible if the elevation "\
                            "of the Sun is below the specified threshold.\n"\
                            "  \342\200\242 Astronomical: -18\302\260 to -12\302\260\n"\
                            "  \342\200\242 Nautical: -12\302\260 to -6\302\260\n"\
                            "  \342\200\242 Civil: -6\302\260 to 0\302\260"));
    gtk_spin_button_set_digits (GTK_SPIN_BUTTON (twspin), 0);
    gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (twspin), TRUE);
    gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (twspin), FALSE);
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (twspin),
                               sat_cfg_get_int (SAT_CFG_INT_PRED_TWILIGHT_THLD));
    g_signal_connect (G_OBJECT (twspin), "value-changed",
                      G_CALLBACK (spin_changed_cb), NULL);
    gtk_table_attach (GTK_TABLE (table), twspin,
                      1, 2, 11, 12,
                      GTK_FILL,
                      GTK_SHRINK,
                      0, 0);
    label = gtk_label_new (_("[deg]"));
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_table_attach (GTK_TABLE (table), label,
                      2, 3, 11, 12,
                      GTK_FILL | GTK_EXPAND,
                      GTK_SHRINK,
                      0, 0);
    
    /* separator */
    gtk_table_attach (GTK_TABLE (table),
                      gtk_hseparator_new (),
                      0, 3, 12, 13,
                      GTK_FILL | GTK_EXPAND,
                      GTK_SHRINK,
                      0, 0);

    /* T0 for predictions */
    tzero = gtk_check_button_new_with_label (_("Always use real time for pass predictions"));
    gtk_widget_set_tooltip_text (tzero,
                                 _("Check this box if you want Gpredict to always use "\
                                   "the current (real) time as starting time when predicting "\
                                   "future satellite passes.\n\n"\
                                   "If you leave the box unchecked and the time controller is "\
                                   "active, Gpredict will use the time from the time controller "\
                                   "as starting time for predicting satellite passes."));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tzero),
                                  sat_cfg_get_bool (SAT_CFG_BOOL_PRED_USE_REAL_T0));
    g_signal_connect (G_OBJECT (tzero), "toggled",
                      G_CALLBACK (spin_changed_cb), NULL);
     
    gtk_table_attach (GTK_TABLE (table), tzero, 0, 3, 13, 14,
                      GTK_FILL | GTK_EXPAND, GTK_SHRINK,
                      0, 0);
    
     /* create vertical box */
     vbox = gtk_vbox_new (FALSE, 0);
     gtk_container_set_border_width (GTK_CONTAINER (vbox), 20);
     gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

     /* create RESET button */
     create_reset_button (GTK_BOX (vbox));


     return vbox;
}
Exemple #18
0
/** \brief Update TLE files from local files.
 *  \param dir Directory where files are located.
 *  \param filter File filter, e.g. *.txt (not used at the moment!)
 *  \param silent TRUE if function should execute without graphical status indicator.
 *  \param label1 Activity label (can be NULL)
 *  \param label2 Statistics label (can be NULL)
 *  \param progress Pointer to progress indicator.
 *  \param init_prgs Initial value of progress indicator, e.g 0.5 if we are updating
 *                   from network.
 *
 * This function is used to update the TLE data from local files.
 *
 * Functional description: TBD
 *
 */
void tle_update_from_files (const gchar *dir, const gchar *filter,
                            gboolean silent, GtkWidget *progress,
                            GtkWidget *label1, GtkWidget *label2)
{
    static GMutex tle_file_in_progress;

    GHashTable  *data;        /* hash table with fresh TLE data */
    GDir        *cache_dir;   /* directory to scan fresh TLE */
    GDir        *loc_dir;     /* directory for gpredict TLE files */
    GError      *err = NULL;
    gchar       *text;
    gchar       *ldname;
    gchar       *userconfdir;
    const gchar *fnam;
    guint        num = 0;
    guint        updated,updated_tmp;
    guint        skipped,skipped_tmp;
    guint        nodata,nodata_tmp;
    guint        newsats = 0;
    guint        total,total_tmp;
    gdouble      fraction = 0.0;
    gdouble      start = 0.0;

    (void) filter; /* avoid unused parameter compiler warning */

    if (g_mutex_trylock(&tle_file_in_progress) == FALSE)
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: A TLE update process is already running. Aborting."),
                     __FUNCTION__);

        return;
    }

    /* create hash table */
    data = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, free_new_tle);

    /* open directory and read files one by one */
    cache_dir = g_dir_open (dir, 0, &err);

    if (err != NULL) {

        /* send an error message */
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Error opening directory %s (%s)"),
                     __FUNCTION__, dir, err->message);

        /* insert error message into the status string, too */
        if (!silent && (label1 != NULL)) {
            text = g_strdup_printf (_("<b>ERROR</b> opening directory %s\n%s"),
                                    dir, err->message);

            gtk_label_set_markup (GTK_LABEL (label1), text);
            g_free (text);

        }

        g_clear_error (&err);
        err = NULL;
    }
    else {

        /* scan directory for tle files */
        while ((fnam = g_dir_read_name (cache_dir)) != NULL) {
            /* check that we got a TLE file */
            if (is_tle_file(dir, fnam)) {
                
                /* status message */
                if (!silent && (label1 != NULL)) {
                    text = g_strdup_printf (_("Reading data from %s"), fnam);
                    gtk_label_set_text (GTK_LABEL (label1), text);
                    g_free (text);

                    /* Force the drawing queue to be processed otherwise there will
                        not be any visual feedback, ie. frozen GUI
                        - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602
                    */
                    while (g_main_context_iteration (NULL, FALSE));

                    /* give user a chance to follow progress */
                    g_usleep (G_USEC_PER_SEC / 100);
                }

                /* now, do read the fresh data */
                num = read_fresh_tle (dir, fnam, data);
            } else {
                num = 0;
            }

            if (num < 1) {
                sat_log_log (SAT_LOG_LEVEL_ERROR,
                             _("%s: No valid TLE data found in %s"),
                             __FUNCTION__, fnam);
            }
            else {
                sat_log_log (SAT_LOG_LEVEL_INFO,
                             _("%s: Read %d sats from %s into memory"),
                             __FUNCTION__, num, fnam);
            }
        }

        /* close directory since we don't need it anymore */
        g_dir_close (cache_dir);

        /* now we load each .sat file and update if we have new data */
        userconfdir = get_user_conf_dir ();
        ldname = g_strconcat (userconfdir, G_DIR_SEPARATOR_S, "satdata", NULL);
        g_free (userconfdir);

        /* open directory and read files one by one */
        loc_dir = g_dir_open (ldname, 0, &err);

        if (err != NULL) {

            /* send an error message */
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Error opening directory %s (%s)"),
                         __FUNCTION__, dir, err->message);

            /* insert error message into the status string, too */
            if (!silent && (label1 != NULL)) {
                text = g_strdup_printf (_("<b>ERROR</b> opening directory %s\n%s"),
                                        dir, err->message);

                gtk_label_set_markup (GTK_LABEL (label1), text);
                g_free (text);
            }

            g_clear_error (&err);
            err = NULL;
        }
        else {
            /* clear statistics */
            updated = 0;
            skipped = 0;
            nodata = 0;
            total = 0;

            /* get initial value of progress indicator */
            if (progress != NULL)
                start = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress));

            /* This is insane but I don't know how else to count the number of sats */
            num = 0;
            while ((fnam = g_dir_read_name (loc_dir)) != NULL) {
                /* only consider .sat files */
                if (g_str_has_suffix (fnam, ".sat")) {
                    num++;
                }
            }

            g_dir_rewind (loc_dir);

            /* update TLE files one by one */
            while ((fnam = g_dir_read_name (loc_dir)) != NULL) {
                /* only consider .sat files */
                if (g_str_has_suffix (fnam, ".sat")) {

                    /* clear stat bufs */
                    updated_tmp = 0;
                    skipped_tmp = 0;
                    nodata_tmp = 0;
                    total_tmp = 0;

                    /* update TLE data in this file */
                    update_tle_in_file (ldname, fnam, data, 
                                        &updated_tmp,
                                        &skipped_tmp,
                                        &nodata_tmp,
                                        &total_tmp);

                    /* update statistics */
                    updated += updated_tmp;
                    skipped += skipped_tmp;
                    nodata  += nodata_tmp;
                    total   = updated+skipped+nodata;

                    if (!silent) {

                        if (label1 != NULL) {
                            gtk_label_set_text (GTK_LABEL (label1),
                                                _("Updating data..."));
                        }

                        if (label2 != NULL) {
                            text = g_strdup_printf (_("Satellites updated:\t %d\n"\
                                                      "Satellites skipped:\t %d\n"\
                                                      "Missing Satellites:\t %d\n"),
                                                    updated, skipped, nodata);
                            gtk_label_set_text (GTK_LABEL (label2), text);
                            g_free (text);
                        }

                        if (progress != NULL) {
                            /* two different calculations for completeness depending on whether 
                               we are adding new satellites or not. */
                            if (sat_cfg_get_bool (SAT_CFG_BOOL_TLE_ADD_NEW)) {
                                /* In this case we are possibly processing more than num satellites
                                   How many more? We do not know yet.  Worst case is g_hash_table_size more.
                                   
                                   As we update skipped and updated we can reduce the denominator count
                                   as those are in both pools (files and hash table). When we have processed 
                                   all the files, updated and skipped are completely correct and the progress 
                                   is correct. It may be correct sooner if the missed satellites are the 
                                   last files to process.
                                   
                                   Until then, if we eliminate the ones that are updated and skipped from being 
                                   double counted, our progress will shown will always be less or equal to our 
                                   true progress since the denominator will be larger than is correct.
                                   
                                   Advantages to this are that the progress bar does not stall close to 
                                   finished when there are a large number of new satellites.
                                */
                                fraction = start + (1.0-start) * ((gdouble) total) / 
                                    ((gdouble) num + g_hash_table_size(data) - updated - skipped);
                            } else {
                                /* here we only process satellites we have have files for so divide by num */
                                fraction = start + (1.0-start) * ((gdouble) total) / ((gdouble) num);
                            }
                            gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress),
                                                           fraction);

                        }

                        /* update the gui only every so often to speed up the process */
                        /* 47 was selected empirically to balance the update looking smooth but not take too much time. */
                        /* it also tumbles all digits in the numbers so that there is no obvious pattern. */
                        /* on a developer machine this improved an update from 5 minutes to under 20 seconds. */
                        if (total%47 == 0) {
                            /* Force the drawing queue to be processed otherwise there will
                               not be any visual feedback, ie. frozen GUI
                               - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602
                            */
                            while (g_main_context_iteration (NULL, FALSE));
                        
                            /* give user a chance to follow progress */
                            g_usleep (G_USEC_PER_SEC / 1000);
                        }
                    }
                }
            }
            
            /* force gui update */
            while (g_main_context_iteration (NULL, FALSE));


            /* close directory handle */
            g_dir_close (loc_dir);
            
            /* see if we have any new sats that need to be added */
            if (sat_cfg_get_bool (SAT_CFG_BOOL_TLE_ADD_NEW)) {
                
                newsats = add_new_sats (data);
                
                if (!silent && (label2 != NULL)) {
                    text = g_strdup_printf (_("Satellites updated:\t %d\n"\
                                              "Satellites skipped:\t %d\n"\
                                              "Missing Satellites:\t %d\n"\
                                              "New Satellites:\t\t %d"),
                                            updated, skipped, nodata, newsats);
                    gtk_label_set_text (GTK_LABEL (label2), text);
                    g_free (text);

                }
                
                sat_log_log (SAT_LOG_LEVEL_INFO,
                             _("%s: Added %d new satellites to local database"),
                             __FUNCTION__, newsats);
            }

            /* store time of update if we have updated something */
            if ((updated > 0) || (newsats > 0)) {
                GTimeVal tval;
                
                g_get_current_time (&tval);
                sat_cfg_set_int (SAT_CFG_INT_TLE_LAST_UPDATE, tval.tv_sec);
            }

        }

        g_free (ldname);

        sat_log_log (SAT_LOG_LEVEL_INFO,
                     _("%s: TLE elements updated."),
                     __FUNCTION__);
    }

    /* destroy hash tables */
    g_hash_table_destroy (data);

    g_mutex_unlock(&tle_file_in_progress);
}
Exemple #19
0
static void menubar_open_mod_cb(GtkWidget * widget, gpointer data)
{
    gchar          *modnam = NULL;
    gchar          *modfile;
    gchar          *confdir;
    GtkWidget      *module = NULL;

    (void)widget;
    (void)data;

    sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open existing module..."),
                __func__);

    modnam = select_module();

    if (modnam)
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open module %s."), __func__,
                    modnam);

        confdir = get_modules_dir();
        modfile =
            g_strconcat(confdir, G_DIR_SEPARATOR_S, modnam, ".mod", NULL);
        g_free(confdir);

        /* create new module */
        module = gtk_sat_module_new(modfile);

        if (module == NULL)
        {
            /* mod manager could not create the module */
            GtkWidget      *dialog;

            dialog = gtk_message_dialog_new(GTK_WINDOW(app),
                                            GTK_DIALOG_MODAL |
                                            GTK_DIALOG_DESTROY_WITH_PARENT,
                                            GTK_MESSAGE_ERROR,
                                            GTK_BUTTONS_OK,
                                            _("Could not open %s. "
                                              "Please examine the log "
                                              "messages for details."),
                                            modnam);

            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
        }
        else
        {
            /* if module state was window or user does not want to restore the
               state of the modules, pack the module into the notebook */
            if ((GTK_SAT_MODULE(module)->state == GTK_SAT_MOD_STATE_DOCKED) ||
                !sat_cfg_get_bool(SAT_CFG_BOOL_MOD_STATE))
            {
                mod_mgr_add_module(module, TRUE);
            }
            else
            {
                mod_mgr_add_module(module, FALSE);
                create_module_window(module);
            }
        }

        g_free(modnam);
        g_free(modfile);
    }
    else
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open module cancelled."),
                    __func__);
    }
}
Exemple #20
0
/** \brief Create and initialise module manger.
 *  \return The main module container widget (GtkNotebook).
 *
 * This function creates and initialises the module manager widget, which
 * consist of a GtkNotebook container. Before returning the container to the
 * caller, the function checks whether any modules should be restored (ie.
 * openend), if yes, it creates them and adds them to the notebook.
 *
 */
GtkWidget *
mod_mgr_create (void)
{
    gchar  *openmods = NULL;
    gchar **mods;
    gint    count,i;
    GtkWidget *module;
    gchar     *modfile;
    gchar     *confdir;

    /* create notebook */
    nbook = gtk_notebook_new ();
    gtk_notebook_set_scrollable (GTK_NOTEBOOK (nbook), TRUE);
    gtk_notebook_popup_enable (GTK_NOTEBOOK (nbook));
    g_object_set (G_OBJECT (nbook), "homogeneous", TRUE, NULL);
    g_signal_connect (G_OBJECT (nbook), "switch-page",
                      G_CALLBACK (switch_page_cb), NULL);

    /* get list of modules which should be open */
    openmods = sat_cfg_get_str (SAT_CFG_STR_OPEN_MODULES);

    if (openmods) {
        mods = g_strsplit (openmods, ";", 0);
        count = g_strv_length (mods);

        for (i = 0; i < count; i++) {

            /* get data file name */
            confdir = get_modules_dir ();
            modfile = g_strconcat (confdir, G_DIR_SEPARATOR_S,
                                   mods[i], ".mod", NULL);
            g_free (confdir);
            
            /* create module */
            module = gtk_sat_module_new (modfile);

            if (IS_GTK_SAT_MODULE (module)) {

                /* if module state was window or user does not want to restore the
                   state of the modules, pack the module into the notebook */
                if ((GTK_SAT_MODULE (module)->state == GTK_SAT_MOD_STATE_DOCKED) ||
                    !sat_cfg_get_bool (SAT_CFG_BOOL_MOD_STATE)) {

                    mod_mgr_add_module (module, TRUE);

                }
                else {
                    mod_mgr_add_module (module, FALSE);
                    create_module_window (module);
                }
            }
            else {
                sat_log_log (SAT_LOG_LEVEL_ERROR,
                             _("%s: Failed to restore %s"),
                             __FUNCTION__, mods[i]);
            }

            g_free (modfile);

        }

        g_strfreev (mods);
        g_free (openmods);

        /* disable tabs if only one page in notebook */
        if ((gtk_notebook_get_n_pages (GTK_NOTEBOOK(nbook))) == 1) {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), FALSE);
        }
        else {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), TRUE);
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: No modules have to be restored."),
                     __FUNCTION__);
    }

    return nbook;
}
Exemple #21
0
/*  BBBBB.BBBBBBBB] - Epoch Time -- 2-digit year, followed by 3-digit sequential
                      day of the year, followed by the time represented as the
                      fractional portion of one day, but...

    we now have the converted fields, tle->epoch_year, tle->epoch_day and tle->epoch_fod
                
*/
static gchar   *epoch_to_str(sat_t * sat)
{
    GDate          *epd;
    guint           h, m, s, sec;
    gchar          *buff;
    gchar          *fmt;
    struct tm       tms;
    time_t          t;
    guint           size;

    /* http://celestrak.com/columns/v04n03/#FAQ02
       ... While talking about the epoch, this is perhaps a good place to answer
       the other time-related questions. First, how is the epoch time format
       interpreted? This question is best answered by using an example. An epoch
       of 98001.00000000 corresponds to 0000 UT on 1998 January 01st in other
       words, midnight between 1997 December 31 and 1998 January 01. An epoch of
       98000.00000000 would actually correspond to the beginning of 1997 December
       31st strange as that might seem. Note that the epoch day starts at UT
       midnight (not noon) and that all times are measured mean solar rather than
       sidereal time units (the answer to our third question).
     */
    epd = g_date_new_dmy(1, 1, sat->tle.epoch_year);
    g_date_add_days(epd, sat->tle.epoch_day - 1);

    /* convert date to struct tm */
    g_date_to_struct_tm(epd, &tms);

    /* add HMS */
    sec = (guint) floor(sat->tle.epoch_fod * 86400);    /* fraction of day in seconds */

    /* hour */
    h = (guint) floor(sec / 3600);
    tms.tm_hour = h;

    /* minutes */
    m = (guint) floor((sec - (h * 3600)) / 60);
    tms.tm_min = m;

    s = (guint) floor(sec - (h * 3600) - (m * 60));
    tms.tm_sec = s;

    /* get format string */
    fmt = sat_cfg_get_str(SAT_CFG_STR_TIME_FORMAT);

    /* format either local time or UTC depending on check box */
    t = mktime(&tms);
    buff = g_try_malloc(51);

    if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_LOCAL_TIME))
        size = strftime(buff, 50, fmt, localtime(&t));
    else
        size = strftime(buff, 50, fmt, gmtime(&t));

    if (size < 50)
        buff[size] = '\0';
    else
        buff[50] = '\0';

    g_date_free(epd);
    g_free(fmt);

    return buff;
}
static void
        show_next_pass_cb       (GtkWidget *menuitem, gpointer data)
{
    GtkPolarView *pv = GTK_POLAR_VIEW (data);
    sat_t        *sat;
    qth_t        *qth;
    pass_t       *pass;
    GtkWidget    *dialog;
    GtkWindow    *toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data)));


    /* get next pass */
    sat = SAT(g_object_get_data (G_OBJECT (menuitem), "sat"));
    qth = (qth_t *) (g_object_get_data (G_OBJECT (menuitem), "qth"));

    /* check wheather sat actially has AOS */
    if ((sat->otype != ORBIT_TYPE_GEO) && (sat->otype != ORBIT_TYPE_DECAYED) &&
        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, pv->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);
    }

}