Exemple #1
0
void
sat_cfg_reset_bool (sat_cfg_bool_e param)
{

    if (param < SAT_CFG_BOOL_NUM) {

        if (config == NULL) {
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s: Module not initialised\n"),
                         __FUNCTION__);
        }
        else {
            g_key_file_remove_key (config,
                                   sat_cfg_bool[param].group,
                                   sat_cfg_bool[param].key,
                                   NULL);
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Unknown BOOL param index (%d)\n"),
                     __FUNCTION__, param);
    }
}
Exemple #2
0
/**
 * Store a boolean configuration value.
 * @param param The parameter to store.
 * @param value The value of the parameter.
 *
 * This function stores a boolean configuration value in the configuration
 * table.
 */
void sat_cfg_set_bool(sat_cfg_bool_e param, gboolean value)
{
    if (param < SAT_CFG_BOOL_NUM)
    {
        if (config == NULL)
        {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Module not initialised\n"),
                         __func__);
        }
        else
        {
            g_key_file_set_boolean (config,
                                    sat_cfg_bool[param].group,
                                    sat_cfg_bool[param].key,
                                    value);
        }
    }
    else
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Unknown BOOL param index (%d)\n"),
                     __func__, param);
    }
}
Exemple #3
0
/** \brief Store a str configuration value.
 */
void sat_cfg_set_str (sat_cfg_str_e param, const gchar *value)
{

    if (param < SAT_CFG_STR_NUM) {

        if (config == NULL) {
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s: Module not initialised\n"),
                         __FUNCTION__);
        }
        else {
            if (value) {
                g_key_file_set_string (config,
                                       sat_cfg_str[param].group,
                                       sat_cfg_str[param].key,
                                       value);
            }
            else {
                /* remove key from config */
                g_key_file_remove_key (config,
                                       sat_cfg_str[param].group,
                                       sat_cfg_str[param].key,
                                       NULL);
            }
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Unknown STR param index (%d)\n"),
                     __FUNCTION__, param);
    }
}
Exemple #4
0
/** brief Reload satellites in all modules. */
void
mod_mgr_reload_sats    ()
{
    guint      num;
    guint      i;
    GtkSatModule *mod;

    
    if (!nbook) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Attempt to reload sats but mod-mgr is NULL?"),
                     __FUNCTION__);
        return;
    }

    num = g_slist_length (modules);

    if (num == 0) {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: No modules need to reload sats."),
                     __FUNCTION__);

        return;
    }

    /* for each module in the GSList execute sat_module_reload_sats() */
    for (i = 0; i < num; i++) {

        mod = GTK_SAT_MODULE (g_slist_nth_data (modules, i));
        
        gtk_sat_module_reload_sats (mod);

    }

}
Exemple #5
0
void sat_cfg_reset_int(sat_cfg_int_e param)
{
    if (param < SAT_CFG_INT_NUM)
    {
        if (config == NULL)
        {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Module not initialised\n"),
                         __func__);
        }
        else
        {
            g_key_file_remove_key (config,
                                   sat_cfg_int[param].group,
                                   sat_cfg_int[param].key,
                                   NULL);
        }

    }
    else
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Unknown INT param index (%d)\n"),
                     __func__, param);
    }
}
Exemple #6
0
/* Create new module */
static void menubar_new_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: Starting new module configurator..."), __func__);

    modnam = mod_cfg_new();

    if (modnam)
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: New module name is %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)
        {
            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
        {
            mod_mgr_add_module(module, TRUE);
        }

        g_free(modnam);
        g_free(modfile);
    }
    else
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: New module config cancelled."),
                    __func__);
    }
}
Exemple #7
0
/** \brief Save state of module manager.
 *
 * This function saves the state of the module manager. Currently, this consists
 * of saving the list of open modules. If no modules are open, the function saves
 * a NULL-list, indication that the corresponding configuration key should be
 * removed.
 */
void
mod_mgr_save_state ()
{
    guint      num;
    guint      i;
    GtkWidget *module;
    gchar     *mods = NULL;
    gchar     *buff;

    
    if (!nbook) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Attempt to save state but mod-mgr is NULL?"),
                     __FUNCTION__);
        return;
    }

    num = g_slist_length (modules);

    if (num == 0) {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: No modules need to save state."),
                     __FUNCTION__);

        sat_cfg_set_str (SAT_CFG_STR_OPEN_MODULES, NULL);

        return;
    }

    for (i = 0; i < num; i++) {
        module = GTK_WIDGET (g_slist_nth_data (modules, i));
        
        /* save state of the module */
        mod_cfg_save (GTK_SAT_MODULE (module)->name, GTK_SAT_MODULE (module)->cfgdata);
        
        if (i == 0) {
            buff = g_strdup (GTK_SAT_MODULE (module)->name);
        }
        else {
            buff = g_strconcat (mods, ";", GTK_SAT_MODULE (module)->name, NULL);
            g_free (mods);
        }

        mods = g_strdup (buff);
        g_free (buff);

        sat_log_log (SAT_LOG_LEVEL_DEBUG, _("%s: Stored %s"),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);

    }

    sat_log_log (SAT_LOG_LEVEL_MSG, _("%s: Saved states for %d modules."),
                 __FUNCTION__, num);

    sat_cfg_set_str (SAT_CFG_STR_OPEN_MODULES, mods);

    g_free (mods);
}
/** \brief Delete the ground track for a satellite.
 *  \param satmap The satellite map widget.
 *  \param sat Pointer to the satellite object.
 *  \param qth Pointer to the QTH data.
 *  \param obj the satellite object.
 *  \param clear_ssp Flag indicating whether SSP data should be cleared as well (TRUE=yes);
 *
 */
void
ground_track_delete (GtkSatMap *satmap, sat_t *sat, qth_t *qth, sat_map_obj_t *obj, gboolean clear_ssp)
{
     guint              i,n;
     gint               j;
     GooCanvasItemModel *line;
     GooCanvasItemModel *root;

    (void) qth; /* avoid unusued parameter compiler warning */

    sat_log_log (SAT_LOG_LEVEL_DEBUG,
                     _("%s: Deleting ground track for %s"),
                 __FUNCTION__, sat->nickname);

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

     /* remove plylines */
     if (obj->track_data.lines != NULL) {
          n = g_slist_length (obj->track_data.lines);

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

               /* get line */
               line = GOO_CANVAS_ITEM_MODEL (g_slist_nth_data (obj->track_data.lines, i));

               /* find its ID and remove it */
               j = goo_canvas_item_model_find_child (root, line);
               if (j == -1) {
                    sat_log_log (SAT_LOG_LEVEL_ERROR,
                                    _("%s: Could not find part %d of ground track"),
                                    __FUNCTION__, j);
               }
               else {
                    goo_canvas_item_model_remove_child (root, j);
               }
          }

          g_slist_free (obj->track_data.lines);
          obj->track_data.lines = NULL;
               
     }

     /* clear SSP too? */
     if (clear_ssp == TRUE) {
          if (obj->track_data.latlon != NULL) {

               /* free allocated ssp_t */
               g_slist_foreach (obj->track_data.latlon, free_ssp, NULL);

               /* free the SList itself */
               g_slist_free (obj->track_data.latlon);
               obj->track_data.latlon = NULL;

          }

          obj->track_orbit = 0;
     }
}
Exemple #9
0
/** \brief Add a new module to mod-mgr.
 *  \param module The GtkSatModule widget to add
 *  \param dock Flag indicating whether module should be docked or not.
 *
 * This function registers a new module in the mod-mgr. If the dock flag is true
 * the module is added to the mod-mgr notebook, otherwise it will be up to the
 * caller to create a proper container.
 *
 */
gint
mod_mgr_add_module     (GtkWidget *module, gboolean dock)
{
    gint       retcode = 0;
    gint       page;


    if (module) {

        /* add module to internal list */
        modules = g_slist_append (modules, module);

        if (dock) {
            /* add module to notebook if state = DOCKED */
            page = gtk_notebook_append_page (GTK_NOTEBOOK (nbook),
                                             module,
                                             gtk_label_new (GTK_SAT_MODULE (module)->name));

            /* allow nmodule to be dragged to different position */
            gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK(nbook), module, TRUE);

            gtk_notebook_set_current_page (GTK_NOTEBOOK (nbook), page);

            /* send message to logger */
            sat_log_log (SAT_LOG_LEVEL_MSG,
                         _("%s: Added %s to module manger (page %d)."),
                         __FUNCTION__, GTK_SAT_MODULE (module)->name, page);
        }
        else {
            /* send message to logger */
            sat_log_log (SAT_LOG_LEVEL_MSG,
                         _("%s: Added %s to module manger (NOT DOCKED)."),
                         __FUNCTION__, GTK_SAT_MODULE (module)->name);
        }
        retcode = 0;
    }
    else {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Module %s seems to be NULL"),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);
        retcode = 1;
    }

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

    update_window_title    ();

    return retcode;

}
Exemple #10
0
/** \brief Remove a module from the notebook.
 *  \param module The module that should be removed.
 *  \return 0 if the module has been removed or 1 if the requested module
 *          could not be found in the notebook.
 */
gint
mod_mgr_remove_module (GtkWidget *module)
{
    gint page;
    gint retcode = 0;


    /* remove from notebook */
    if (GTK_SAT_MODULE (module)->state == GTK_SAT_MOD_STATE_DOCKED) {
        /* get page number for this module */
        page = gtk_notebook_page_num (GTK_NOTEBOOK (nbook), module);

        if (page == -1) {
            /* this is some kind of bug (inconsistency between internal states) */
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s: Could not find child in notebook. This may hurt..."),
                         __FUNCTION__);

            retcode = 1;
        }
        else {
            gtk_notebook_remove_page (GTK_NOTEBOOK (nbook), page);

            sat_log_log (SAT_LOG_LEVEL_MSG,
                         _("%s: Removed child from notebook page %d."),
                         __FUNCTION__, page);

            retcode = 0;
        }
    }

    /* remove from list */
    modules = g_slist_remove (modules, module);

    /* undocked modules will have to destroy themselves
       because of their parent window
    */


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

    /* update window title */
    update_window_title ();

    return retcode;
}
Exemple #11
0
/**
 * Remove .qth files.
 *
 * This function is used to remove any existing .qth file
 * before storing the data from the QTH list.
 */
static void delete_location_files()
{
    GDir           *dir = NULL; /* directory handle */
    GError         *error = NULL;       /* error flag and info */
    gchar          *dirname;    /* directory name */
    const gchar    *filename;   /* file name */
    gchar          *buff;

    /* scan for .qth files in the user config directory and
       add the contents of each .qth file to the list store
     */
    dirname = get_user_conf_dir();
    dir = g_dir_open(dirname, 0, &error);

    if (dir)
    {
        while ((filename = g_dir_read_name(dir)))
        {
            if (g_str_has_suffix(filename, ".qth"))
            {
                buff = g_strconcat(dirname, G_DIR_SEPARATOR_S, filename, NULL);

                /* remove file */
                if (g_remove(buff))
                {
                    sat_log_log(SAT_LOG_LEVEL_ERROR,
                                _("%s:%d: Failed to remove %s"),
                                __FILE__, __LINE__, filename);
                }
                else
                {
                    sat_log_log(SAT_LOG_LEVEL_DEBUG,
                                _("%s:%d: Removed %s"),
                                __FILE__, __LINE__, filename);
                }

                g_free(buff);
            }
        }
    }
    else
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s:%d: Failed to open user cfg dir (%s)"),
                    __FILE__, __LINE__, error->message);
        g_clear_error(&error);

    }

    g_free(dirname);
    g_dir_close(dir);
}
Exemple #12
0
/**
 * Handle toggle events on "Default" check box
 * @param cell The item that received the signal.
 * @param path_str Path string.
 * @param data Pointer to user data (list store).
 *
 * This function is called when the user clicks on "Default" check box
 * indicating that a new default location has been selected. If the
 * clicked check box has been un-checked the action is ignored, because
 * we need a default location. If the clicked check box has been checked,
 * the default flag of the checked QTH is set to TRUE, while the flag is
 * cleared for all the other QTH's.
 */
static void default_toggled(GtkCellRendererToggle * cell, gchar * path_str,
                            gpointer data)
{
    GtkTreeModel   *model = (GtkTreeModel *) data;
    GtkTreeIter     iter;
    GtkTreePath    *path = gtk_tree_path_new_from_string(path_str);
    gboolean        fixed;
    gchar          *defqth;

    /* block toggle signals while we mess with the check boxes */
    g_signal_handler_block(cell, handler_id);

    /* get toggled iter */
    gtk_tree_model_get_iter(model, &iter, path);
    gtk_tree_model_get(model, &iter, QTH_LIST_COL_DEF, &fixed, -1);

    if (fixed)
    {
        /* do nothing except sending a message */
        sat_log_log(SAT_LOG_LEVEL_INFO,
                    _("%s:%d: Default QTH can not be cleared! "
                      "Select another QTH to change default."),
                    __FILE__, __LINE__);
    }
    else
    {
        /* make this qth new default */
        gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                           QTH_LIST_COL_DEF, TRUE, -1);

        /* copy file name of new default QTH to a string buffer */
        gtk_tree_model_get(model, &iter, QTH_LIST_COL_NAME, &defqth, -1);

        sat_log_log(SAT_LOG_LEVEL_INFO,
                    _("%s:%d: New default QTH is %s.qth."),
                    __FILE__, __LINE__, defqth);

        /* clear the default flag for the other qth */
        gtk_tree_model_foreach(model, clear_default_flags, defqth);

        g_free(defqth);

    }

    /* clean up */
    gtk_tree_path_free(path);

    /* unblock toggle signals */
    g_signal_handler_unblock(cell, handler_id);
}
Exemple #13
0
/** \brief Load configuration data.
 *  \return 0 if everything OK, 1 otherwise.
 *
 * This function reads the configuration data from gpredict.cfg into
 * memory. This function must be called very early at program start.
 *
 * The the configuration data in memory is already "loaded" the data will
 * be ereased first.
 */
guint sat_cfg_load        ()
{
    gchar  *keyfile,*confdir;
    GError *error = NULL;

    if (config != NULL)
        sat_cfg_close ();

    /* load the configuration file */
    config = g_key_file_new ();
    confdir = get_user_conf_dir ();
    keyfile = g_strconcat (confdir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
    g_free (confdir);

    g_key_file_load_from_file (config, keyfile, G_KEY_FILE_KEEP_COMMENTS, &error);

    g_free (keyfile);

    if (error != NULL) {

        sat_log_log (SAT_LOG_LEVEL_WARN,
                     _("%s: Error reading config file (%s)"),
                     __FUNCTION__, error->message);

        sat_log_log (SAT_LOG_LEVEL_WARN,
                     _("%s: Using built-in defaults"),
                     __FUNCTION__);

        g_clear_error (&error);

        return 1;
    }
    else {
        sat_log_log (SAT_LOG_LEVEL_DEBUG,
                     _("%s: Everything OK."), __FUNCTION__);
    }

    /* if config version is < 1.1; reset SAT_CFG_STR_TLE_FILES */
    guint ver;
    ver = 10*sat_cfg_get_int (SAT_CFG_INT_VERSION_MAJOR) + sat_cfg_get_int (SAT_CFG_INT_VERSION_MINOR);
    if (ver < 11) {
        sat_cfg_reset_str (SAT_CFG_STR_TLE_FILES);
        sat_cfg_set_int (SAT_CFG_INT_VERSION_MAJOR, 1);
        sat_cfg_set_int (SAT_CFG_INT_VERSION_MINOR, 1);
    }


    return 0;
}
/** \brief Close and permanently delete module.
 *
 * This function is called when the user selects the delete menu
 * item in the GtkSatModule popup menu. First it will close the module
 * with gtk_sat_module_close_cb, which will close the current module,
 * whereafter the module file will be deleted from the disk.
 */
static void delete_cb (GtkWidget *menuitem, gpointer data)
{
    gchar *file;
    GtkWidget *dialog;
    gchar *moddir;

    moddir = get_modules_dir ();
    file = g_strconcat (moddir, G_DIR_SEPARATOR_S,
                        GTK_SAT_MODULE (data)->name, ".mod", NULL);
    g_free (moddir);

    gtk_sat_module_close_cb (menuitem, data);


    /* ask user to confirm removal */
    dialog = gtk_message_dialog_new_with_markup
             (NULL, //GTK_WINDOW (parent),
              GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
              GTK_MESSAGE_QUESTION,
              GTK_BUTTONS_YES_NO,
              _("This operation will permanently delete\n<b>%s</b>\n"\
                "from the disk.\nDo you you want to proceed?"),
              file);

    switch (gtk_dialog_run (GTK_DIALOG (dialog))) {

    case GTK_RESPONSE_YES:

        if (g_remove (file)) {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s:%d: Failed to delete %s."),
                         __FILE__, __LINE__, file);
        }
        else {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s:%d: %s deleted permanently."),
                         __FILE__, __LINE__, file);
        }
        break;

     default:
        break;
    }

    gtk_widget_destroy (dialog);

    g_free (file);
}
gint
mod_cfg_get_int  (GKeyFile *f, const gchar *sec, const gchar *key, sat_cfg_int_e p)
{
     GError  *error = NULL;
     gint     param;

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

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

          if (error != NULL) {

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

               g_clear_error (&error);

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

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

     return param;
}
gboolean gtk_sat_selector_search_equal_func (GtkTreeModel *model, 
                                             gint column,
                                             const gchar *key,
                                             GtkTreeIter *iter,
                                             gpointer search_data)
{
    gchar *name = NULL;
    gchar *match;

    (void) column; /* avoid unused parameter compiler warning */
    (void) search_data; /* avoid unused parameter compiler warning */

    gtk_tree_model_get(model, iter, GTK_SAT_SELECTOR_COL_NAME, &name, -1);
    /* sat_log_log(SAT_LOG_LEVEL_INFO, "%s: key %s, name %s", */
    /*             __FUNCTION__,  */
    /*             key,  */
    /*             (name==NULL) ? NULLSTR : name);  */ 
    if (name == NULL){
        sat_log_log(SAT_LOG_LEVEL_INFO, "%s:%s: name is NULL", __FILE__, __FUNCTION__); 
        return TRUE;
    }
    match = strstr(name, key);

    if (match == NULL) {
        //sat_log_log(SAT_LOG_LEVEL_ERROR, "%s: no match", __FUNCTION__);
        return TRUE;
    } 
    else {
        //sat_log_log(SAT_LOG_LEVEL_ERROR, "%s: MATCH at %s", __FUNCTION__, match);
        return FALSE;
    }
}
/** \brief Manage button responses for single-pass dialogues.
 *  \param dialog The dialog widget.
 *  \param response The ID of the response signal, i.e. the pressed button.
 *  \param data User data (currently NULL).
 *
 * Use sat, qth, and passes labels to obtain the relevant data
 *
 */
static void single_pass_response (GtkWidget *dialog, gint response, gpointer data)
{
    (void) data; /* avoid unused parameter compiler warning */

    switch (response) {

    case RESPONSE_PRINT:
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: PRINT not implemented"),
                     __FUNCTION__);

        pass_t    *pass = (pass_t *) g_object_get_data (G_OBJECT (dialog), "pass");
        qth_t     *qth = (qth_t *) g_object_get_data (G_OBJECT (dialog), "qth");

        print_pass (pass, qth, GTK_WINDOW (dialog));
        break;

    case RESPONSE_SAVE:
        save_pass (dialog);
        break;

        /* Close button or delete events */
    default:
        gtk_widget_destroy (dialog);
        break;
    }
}
Exemple #18
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;
}
Exemple #19
0
/** \brief Dock a module into the notebook.
 *  \param module The module to insert into the notebook.
 *  \return 0 if the operation was successful, 1 otherwise.
 *
 * This function inserts the module into the notebook but does not add it
 * to the list of modules, since it should already be there.
 *
 * The function does some sanity checks to ensure the the module actually
 * is in the internal list of modules and also that the module is not
 * already present in the notebook. If any of these checks fail, the function
 * will send an error message and try to recover.
 *
 * The function does not modify the internal state of the module, module->state,
 * that is up to the module itself.
 */
gint
mod_mgr_dock_module    (GtkWidget *module)
{
    gint retcode = 0;
    gint page;

    
    if (!g_slist_find (modules, module)) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Module %s not found in list. Trying to recover."),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);
        modules = g_slist_append (modules, module);
    }

    page = gtk_notebook_page_num (GTK_NOTEBOOK (nbook), module);
    if (page != -1) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Module %s already in notebook!"),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);
        retcode = 1;
    }
    else {
        /* add module to notebook */
        page = gtk_notebook_append_page (GTK_NOTEBOOK (nbook),
                                         module,
                                         gtk_label_new (GTK_SAT_MODULE (module)->name));

        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: Docked %s into notebook (page %d)"),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name, page);
        
        retcode = 0;
    }

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

    /* update window title */
    update_window_title ();

    return retcode;
}
/** \brief Launch help system.
 *
 */
void
gpredict_help_launch (gpredict_help_type_t type)
{
     browser_type_t idx;
     gint           resp;

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


     idx = sat_cfg_get_int (SAT_CFG_INT_WEB_BROWSER_TYPE);

     /* some sanity check before accessing the arrays ;-) */
     if ((idx <= BROWSER_TYPE_NONE) || (idx >= BROWSER_TYPE_NUM)) {
          idx = BROWSER_TYPE_NONE;
     }

     if (idx == BROWSER_TYPE_NONE) {
          sat_log_log (SAT_LOG_LEVEL_INFO,
                    _("%s: Help browser is not set up yet."),
                    __FUNCTION__);

          resp = config_help ();

          if (resp == GTK_RESPONSE_CANCEL) {
               sat_log_log (SAT_LOG_LEVEL_INFO,
                         _("%s: Configure help browser cancelled."),
                         __FUNCTION__);

               return;
          }

          /* else try again */
          idx = sat_cfg_get_int (SAT_CFG_INT_WEB_BROWSER_TYPE);          
     }

     if ((idx <= BROWSER_TYPE_NONE) || (idx >= BROWSER_TYPE_NUM)) {
          return;
     }

     /* launch help browser */
     sat_log_log (SAT_LOG_LEVEL_DEBUG,
               _("%s: Launching help browser %s."),
               __FUNCTION__, sat_help[idx].type);

     g_print ("FIXME: FINSH IMPELMTATION\n");
}
Exemple #21
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 #22
0
/** \brief Undock module from notebook
 *  \param module The module that should be undocked.
 *
 * This function removes module from the notebook without removing it from
 * the internal list of modules.
 *
 * The function does some sanity checks to ensure that the module actually
 * exists in the mod-mgr, if not it will add module to the internal list
 * and raise a warning.
 *
 * The function does not modify the internal state of the module, module->state,
 * that is up to the module itself.
 *
 * \note The module itself is responsible for temporarily incrementing the
 *       reference count of the widget in order to avoid destruction when
 *       removing from the notebook.
 */
gint
mod_mgr_undock_module  (GtkWidget *module)
{
    gint retcode = 0;
    gint page;


    if (!g_slist_find (modules, module)) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Module %s not found in list. Trying to recover."),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);
        modules = g_slist_append (modules, module);
    }

    page = gtk_notebook_page_num (GTK_NOTEBOOK (nbook), module);
    if (page == -1) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Module %s does not seem to be docked!"),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name);
        retcode = 1;
    }
    else {

        gtk_notebook_remove_page (GTK_NOTEBOOK (nbook), page);

        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: Removed %s from notebook page %d."),
                     __FUNCTION__, GTK_SAT_MODULE (module)->name, page);

        retcode = 0;
    }

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

    /* update window title */
    update_window_title ();

    return retcode;
}
Exemple #23
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);
}
Exemple #24
0
/**
 * Get string value
 *
 * Return a newly allocated gchar * which must be freed when no longer needed.
 */
gchar *sat_cfg_get_str(sat_cfg_str_e param)
{
    gchar    *value;
    GError   *error = NULL;

    if (param < SAT_CFG_STR_NUM)
    {
        if (config == NULL)
        {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Module not initialised\n"),
                         __func__);

            /* return default value */
            value = g_strdup (sat_cfg_str[param].defval);
        }
        else
        {
            /* fetch value */
            value = g_key_file_get_string (config,
                                           sat_cfg_str[param].group,
                                           sat_cfg_str[param].key,
                                           &error);
            if (error != NULL)
            {
                g_clear_error (&error);

                value = g_strdup (sat_cfg_str[param].defval);
            }
        }
    }
    else
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Unknown STR param index (%d)\n"),
                     __func__, param);

        value = g_strdup ("ERROR");
    }

    return value;
}
Exemple #25
0
/** Get boolean value */
gboolean sat_cfg_get_bool(sat_cfg_bool_e param)
{
    gboolean  value = FALSE;
    GError   *error = NULL;

    if (param < SAT_CFG_BOOL_NUM)
    {
        if (config == NULL)
        {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Module not initialised\n"),
                         __func__);

            /* return default value */
            value = sat_cfg_bool[param].defval;
        }
        else
        {
            /* fetch value */
            value = g_key_file_get_boolean (config,
                                            sat_cfg_bool[param].group,
                                            sat_cfg_bool[param].key,
                                            &error);

            if (error != NULL) {
                g_clear_error (&error);

                value = sat_cfg_bool[param].defval;
            }
        }

    }
    else
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Unknown BOOL param index (%d)\n"),
                     __func__, param);
    }

    return value;
}
Exemple #26
0
gint sat_cfg_get_int(sat_cfg_int_e param)
{
    gint      value = 0;
    GError   *error = NULL;

    if (param < SAT_CFG_INT_NUM)
    {
        if (config == NULL)
        {
            sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Module not initialised\n"),
                         __func__);

            /* return default value */
            value = sat_cfg_int[param].defval;
        }
        else
        {
            /* fetch value */
            value = g_key_file_get_integer (config,
                                            sat_cfg_int[param].group,
                                            sat_cfg_int[param].key,
                                            &error);

            if (error != NULL) {
                g_clear_error (&error);

                value = sat_cfg_int[param].defval;
            }
        }

    }
    else
    {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Unknown INT param index (%d)\n"),
                     __func__, param);
    }

    return value;
}
/**
 * \brief Manage STOP signals.
 * \param widget The GtkButton that received the signal.
 * \param data Pointer to the GtkSatModule widget.
 *
 * This function is called when the user clicks on the STOP button.
 * If the button state is active (pressed in) the function sets the
 * throttle parameter of the module to 0.
 */
static void tmg_stop(GtkWidget * widget, gpointer data)
{
    GtkSatModule   *mod = GTK_SAT_MODULE(data);

    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, __func__);

        /* set throttle to 0 */
        mod->throttle = 0;
    }
}
/** \brief Manage toggling of Ground Track.
 *  \param item The menu item that was toggled.
 *  \param data Pointer to the GtkPolarView structure.
 *
 */
static void track_toggled(GtkCheckMenuItem * item, gpointer data)
{
    GtkPolarView   *pv = GTK_POLAR_VIEW(data);
    sat_obj_t      *obj = NULL;
    sat_t          *sat;

    /* qth_t              *qth; Unused */
    gint           *catnum;


    /* get satellite object */
    obj = SAT_OBJ(g_object_get_data(G_OBJECT(item), "obj"));
    sat = SAT(g_object_get_data(G_OBJECT(item), "sat"));
    /*qth = (qth_t *)(g_object_get_data (G_OBJECT (item), "qth")); */

    if (obj == NULL)
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s:%d: Failed to get satellite object."),
                    __FILE__, __LINE__);
        return;
    }

    /* toggle flag */
    obj->showtrack = !obj->showtrack;
    gtk_check_menu_item_set_active(item, obj->showtrack);

    catnum = g_new0(gint, 1);
    *catnum = sat->tle.catnr;

    if (obj->showtrack)
    {
        /* add sky track */

        /* add it to the storage structure */
        g_hash_table_insert(pv->showtracks_on, catnum, NULL);
        /* remove it from the don't show */
        g_hash_table_remove(pv->showtracks_off, catnum);

        gtk_polar_view_create_track(pv, obj, sat);
    }
    else
    {
        /* add it to the hide */
        g_hash_table_insert(pv->showtracks_off, catnum, NULL);
        /* remove it from the show */
        g_hash_table_remove(pv->showtracks_on, catnum);

        /* delete sky track */
        gtk_polar_view_delete_track(pv, obj, sat);
    }

}
/** \brief Manage BWD signals.
 *  \param widget The GtkButton that received the signal.
 *  \param data Pointer to the GtkSatModule widget.
 *
 * This function is called when the user clicks on the BWD button.
 * If the button state is active (pressed in) the function sets the
 *  throttle parameter of the module to -1.
 */
static void tmg_bwd      (GtkWidget *widget, gpointer data)
{
    GtkSatModule *mod = GTK_SAT_MODULE (data);

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {

        sat_log_log (SAT_LOG_LEVEL_DEBUG, __FUNCTION__);

        /* set throttle to -1 */
        mod->throttle = -gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (mod->tmgFactor));;

    }
}
Exemple #30
0
void sat_cfg_set_int      (sat_cfg_int_e param, gint value)
{
    if (param < SAT_CFG_INT_NUM) {

        if (config == NULL) {
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s: Module not initialised\n"),
                         __FUNCTION__);
        }
        else {
            g_key_file_set_integer (config,
                                    sat_cfg_int[param].group,
                                    sat_cfg_int[param].key,
                                    value);
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s: Unknown INT param index (%d)\n"),
                     __FUNCTION__, param);
    }
}