/** \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); }
/** 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; }
/** User pressed OK. Any changes should be stored in config. */ void sat_pref_layout_ok(GKeyFile * cfg) { if (dirty) { /* we have new settings */ if (cfg != NULL) { g_key_file_set_string(cfg, MOD_CFG_GLOBAL_SECTION, MOD_CFG_GRID, gtk_entry_get_text(GTK_ENTRY(gridstr))); } else { sat_cfg_set_str(SAT_CFG_STR_MODULE_GRID, gtk_entry_get_text(GTK_ENTRY(gridstr))); sat_cfg_set_bool(SAT_CFG_BOOL_MAIN_WIN_POS, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (mwin))); sat_cfg_set_bool(SAT_CFG_BOOL_MOD_WIN_POS, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (mod))); sat_cfg_set_bool(SAT_CFG_BOOL_MOD_STATE, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (state))); } } else if (reset) { /* we have to reset the values to global or default settings */ if (cfg == NULL) { /* layout */ sat_cfg_reset_str(SAT_CFG_STR_MODULE_GRID); /* window placement */ sat_cfg_reset_bool(SAT_CFG_BOOL_MAIN_WIN_POS); sat_cfg_reset_bool(SAT_CFG_BOOL_MOD_WIN_POS); sat_cfg_reset_bool(SAT_CFG_BOOL_MOD_STATE); } else { g_key_file_remove_key((GKeyFile *) (cfg), MOD_CFG_GLOBAL_SECTION, MOD_CFG_GRID, NULL); } } dirty = FALSE; reset = FALSE; }
/** \brief User pressed OK. Any changes should be stored in config. */ void sat_pref_help_ok () { gint idx; if (dirty) { /* get and store browser type */ idx = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); sat_cfg_set_int (SAT_CFG_INT_WEB_BROWSER_TYPE, idx); /* if type is OTHER, store command, otherwise clear command */ if (idx == BROWSER_TYPE_OTHER) { sat_cfg_set_str (SAT_CFG_STR_WEB_BROWSER, gtk_entry_get_text (GTK_ENTRY (entry))); } else { sat_cfg_reset_str (SAT_CFG_STR_WEB_BROWSER); } } dirty = FALSE; }
/* Update TLE from local files */ static void menubar_tle_local_cb(GtkWidget * widget, gpointer data) { gchar *dir; /* selected directory */ GtkWidget *dir_chooser; /* directory chooser button */ GtkWidget *dialog; /* dialog window */ GtkWidget *label; /* misc labels */ GtkWidget *progress; /* progress indicator */ GtkWidget *label1, *label2; /* activitity and stats labels */ GtkWidget *box; gint response; /* dialog response */ gboolean doupdate = FALSE; (void)widget; (void)data; /* get last used directory */ dir = sat_cfg_get_str(SAT_CFG_STR_TLE_FILE_DIR); /* if there is no last used dir fall back to $HOME */ if (dir == NULL) { dir = g_strdup(g_get_home_dir()); } /* create file chooser */ dir_chooser = gtk_file_chooser_button_new(_("Select directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dir_chooser), dir); g_free(dir); /* create label */ label = gtk_label_new(_("Select TLE directory:")); /* pack label and chooser into a hbox */ box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(box), FALSE); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), dir_chooser, TRUE, TRUE, 5); gtk_widget_show_all(box); /* create the dalog */ dialog = gtk_dialog_new_with_buttons(_("Update TLE from files"), GTK_WINDOW(app), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "_Cancel", GTK_RESPONSE_REJECT, "_OK", GTK_RESPONSE_ACCEPT, NULL); gtk_box_pack_start(GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), box, TRUE, TRUE, 30); response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_ACCEPT) doupdate = TRUE; else doupdate = FALSE; /* get directory before we destroy the dialog */ dir = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dir_chooser)); /* nuke the dialog */ gtk_widget_destroy(dialog); if (doupdate) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Running TLE update from %s"), __func__, dir); /* store last used TLE dir */ sat_cfg_set_str(SAT_CFG_STR_TLE_FILE_DIR, dir); /* create new dialog with progress indicator */ dialog = gtk_dialog_new_with_buttons(_("TLE Update"), GTK_WINDOW(app), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "_Close", GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE); /* create a vbox */ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_set_homogeneous(GTK_BOX(box), FALSE); gtk_container_set_border_width(GTK_CONTAINER(box), 20); /* add static label */ label = gtk_label_new(NULL); g_object_set(label, "xalign", 0.5, "yalign", 0.5, NULL); gtk_label_set_markup(GTK_LABEL(label), _("<b>Updating TLE files from files</b>")); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); /* activity label */ label1 = gtk_label_new("..."); g_object_set(label1, "xalign", 0.5, "yalign", 0.5, NULL); gtk_box_pack_start(GTK_BOX(box), label1, FALSE, FALSE, 0); /* add progress bar */ progress = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(box), progress, FALSE, FALSE, 10); /* statistics */ label2 = gtk_label_new(_("Satellites updated:\t 0\n" "Satellites skipped:\t 0\n" "Missing Satellites:\t 0\n")); gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 0); /* finalise dialog */ gtk_container_add(GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), box); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); gtk_widget_show_all(dialog); /* Force the drawing queue to be processed otherwise the dialog may not appear before we enter the TLE updating func - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602 */ while (g_main_context_iteration(NULL, FALSE)); /* update TLE */ tle_update_from_files(dir, NULL, FALSE, progress, label1, label2); /* set progress bar to 100% */ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 1.0); gtk_label_set_text(GTK_LABEL(label1), _("Finished")); /* enable close button */ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, TRUE); } if (dir) g_free(dir); /* reload satellites */ mod_mgr_reload_sats(); }