From ca3a45e3fcf84fbbfe60df424810cf6ea02f630f Mon Sep 17 00:00:00 2001 From: Alexandru Csete Date: Tue, 26 Dec 2017 20:55:51 +0100 Subject: [PATCH] Migrate sat-pref-qth-editor to Gtk+ 3 Issue #80. --- src/sat-pref-qth-editor.c | 604 ++++++++++++++++++-------------------- src/sat-pref-qth-editor.h | 26 -- 2 files changed, 282 insertions(+), 348 deletions(-) diff --git a/src/sat-pref-qth-editor.c b/src/sat-pref-qth-editor.c index e542317..19c1684 100644 --- a/src/sat-pref-qth-editor.c +++ b/src/sat-pref-qth-editor.c @@ -1,16 +1,8 @@ /* Gpredict: Real-time satellite tracking and orbit prediction program - Copyright (C) 2001-2013 Alexandru Csete, OZ9AEC. - - Authors: Alexandru Csete - Charles Suprin - - Comments, questions and bugreports should be submitted via - http://sourceforge.net/projects/gpredict/ - More details can be found at the project home page: - - http://gpredict.oz9aec.net/ + Copyright (C) 2001-2017 Alexandru Csete, OZ9AEC + 2011 Charles Suprin, AA1VS This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,8 +18,7 @@ along with this program; if not, visit http://www.fsf.org/ */ -/** - * @file +/* * Edit ground station details. * * The functions in this unit are used to edit the details of a given @@ -57,7 +48,7 @@ #include "sat-pref-qth-data.h" #include "sat-pref-qth-editor.h" -/** +/* * Symbolic refs to be used when calling select_location in order * to determine which mode the selection should run in, ie. * select location or select weather station. @@ -69,330 +60,24 @@ enum { extern GtkWidget *window; /* dialog window defined in sat-pref.c */ -/* private widgets */ static GtkWidget *dialog; /* dialog window */ static GtkWidget *name; /* QTH name */ static GtkWidget *location; /* QTH location */ static GtkWidget *desc; /* QTH description */ static GtkWidget *lat, *lon, *alt; /* LAT, LON and ALT */ static GtkWidget *ns, *ew; - static GtkWidget *qra; /* QRA locator */ +static gulong latsigid, lonsigid, nssigid, ewsigid, qrasigid; +static GtkWidget *wx; /* weather station */ #ifdef HAS_LIBGPS static GtkWidget *type; /* GPSD type */ static GtkWidget *server; /* GPSD Server */ static GtkWidget *port; /* GPSD Port */ #endif -static gulong latsigid, lonsigid, nssigid, ewsigid, qrasigid; - -static GtkWidget *wx; /* weather station */ - -static GtkWidget *create_editor_widgets(GtkTreeView * treeview, gboolean new); -static void update_widgets(GtkTreeView * treeview); -static void clear_widgets(void); -static void name_changed(GtkWidget * widget, gpointer data); -static void select_location(GtkWidget * widget, gpointer data); -static gboolean apply_changes(GtkTreeView * treeview, gboolean new); - -static void latlon_changed(GtkWidget * widget, gpointer data); -static void qra_changed(GtkEntry * entry, gpointer data); - -/** - * Add or edit a QTH entry. - * - * The parameter new is used to indicate whether a new entry should be - * created or just edit the one selected in the treeview. - */ -void sat_pref_qth_editor_run(GtkTreeView * treeview, gboolean new) -{ - gint response; - gboolean finished = FALSE; - - /* crate dialog and add contents */ - dialog = gtk_dialog_new_with_buttons(_("Edit ground station data"), - GTK_WINDOW(window), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLEAR, - GTK_RESPONSE_REJECT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - - /* disable OK button to begin with */ - gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), - GTK_RESPONSE_OK, FALSE); - - gtk_container_add(GTK_CONTAINER - (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), - create_editor_widgets(treeview, new)); - - /* this hacky-thing is to keep the dialog running in case the - CLEAR button is plressed. OK and CANCEL will exit the loop - */ - while (!finished) - { - response = gtk_dialog_run(GTK_DIALOG(dialog)); - - switch (response) - { - case GTK_RESPONSE_OK: - /* OK */ - if (apply_changes(treeview, new)) - finished = TRUE; - else - finished = FALSE; - - break; - - case GTK_RESPONSE_REJECT: - /* CLEAR */ - clear_widgets(); - break; - - default: - /* Everything else is considered CANCEL */ - finished = TRUE; - break; - } - } - - gtk_widget_destroy(dialog); -} - -/** Create and initialise widgets */ -static GtkWidget *create_editor_widgets(GtkTreeView * treeview, gboolean new) -{ - GtkWidget *table; - GtkWidget *label; - GtkWidget *locbut; - GtkWidget *wxbut; - - table = gtk_table_new(9, 4, FALSE); - gtk_container_set_border_width(GTK_CONTAINER(table), 5); - gtk_table_set_col_spacings(GTK_TABLE(table), 5); - gtk_table_set_row_spacings(GTK_TABLE(table), 5); - - /* QTH name */ - label = gtk_label_new(_("Name")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); - - name = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(name), 25); - gtk_widget_set_tooltip_text(name, - _ - ("Enter a short name for this ground station, " - "e.g. callsign.\n" - "Allowed characters: 0..9, a..z, A..Z, - and _")); - /* new api does not allow private tip - _("The name will be used to identify the ground station when "\ - "it is presented to the user. Maximum allowed length "\ - "is 25 characters.")); - */ - gtk_table_attach_defaults(GTK_TABLE(table), name, 1, 4, 0, 1); - - /* attach changed signal so that we can enable OK button when - a proper name has been entered - */ - g_signal_connect(name, "changed", G_CALLBACK(name_changed), NULL); - - /* QTH description */ - label = gtk_label_new(_("Description")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); - - desc = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(desc), 256); - gtk_widget_set_tooltip_text(desc, - _("Enter an optional description for this" - " ground station.")); - /* new api does not have private tip - _("The description can be used as additional "\ - "information. It may be included when generating reports. "\ - "The maximum length for the description is 256 characters.")); - */ - gtk_table_attach_defaults(GTK_TABLE(table), desc, 1, 4, 1, 2); - - /* location */ - label = gtk_label_new(_("Location")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); - - location = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(location), 50); - gtk_widget_set_tooltip_text(location, - _("Optional location of the ground station, " - "e.g. Copenhagen, Denmark.")); - gtk_table_attach_defaults(GTK_TABLE(table), location, 1, 3, 2, 3); - - locbut = gpredict_hstock_button(GTK_STOCK_INDEX, _("Select"), - _ - ("Select a predefined location from a list.")); - g_signal_connect(locbut, "clicked", G_CALLBACK(select_location), - GUINT_TO_POINTER(SELECTION_MODE_LOC)); - gtk_table_attach_defaults(GTK_TABLE(table), locbut, 3, 4, 2, 3); - /* latitude */ - label = gtk_label_new(_("Latitude (\302\260)")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); - - lat = gtk_spin_button_new_with_range(0.00, 90.00, 0.0001); - gtk_spin_button_set_increments(GTK_SPIN_BUTTON(lat), 0.0001, 1.0); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(lat), TRUE); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(lat), 4); - gtk_widget_set_tooltip_text(lat, - _("Select the latitude of the ground station " - "in decimal degrees.")); - gtk_table_attach_defaults(GTK_TABLE(table), lat, 1, 2, 3, 4); - - ns = gtk_combo_box_text_new(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ns), _("North")); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ns), _("South")); - gtk_combo_box_set_active(GTK_COMBO_BOX(ns), 0); - /*** FIXME tooltips */ - gtk_table_attach_defaults(GTK_TABLE(table), ns, 2, 3, 3, 4); - - /* longitude */ - label = gtk_label_new(_("Longitude (\302\260)")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5); - - lon = gtk_spin_button_new_with_range(0.00, 180.00, 0.0001); - gtk_spin_button_set_increments(GTK_SPIN_BUTTON(lon), 0.0001, 1.0); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(lon), TRUE); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(lon), 4); - gtk_widget_set_tooltip_text(lon, - _("Select the longitude of the ground station " - "in decimal degrees.")); - gtk_table_attach_defaults(GTK_TABLE(table), lon, 1, 2, 4, 5); - - ew = gtk_combo_box_text_new(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ew), _("East")); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ew), _("West")); - gtk_combo_box_set_active(GTK_COMBO_BOX(ew), 0); - /*** FIXME tooltips */ - gtk_table_attach_defaults(GTK_TABLE(table), ew, 2, 3, 4, 5); - - - /* connect lat/lon spinners and combos to callback - remember signal id so that we can block signals - while doing automatic cross-updates - */ - latsigid = g_signal_connect(lat, "value-changed", - G_CALLBACK(latlon_changed), NULL); - lonsigid = g_signal_connect(lon, "value-changed", - G_CALLBACK(latlon_changed), NULL); - nssigid = g_signal_connect(ns, "changed", - G_CALLBACK(latlon_changed), NULL); - ewsigid = g_signal_connect(ew, "changed", - G_CALLBACK(latlon_changed), NULL); - - /* QRA locator */ - label = gtk_label_new(_("Locator")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 5, 6); - - qra = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(qra), 6); - gtk_widget_set_tooltip_text(qra, _("Maidenhead locator grid.")); - gtk_table_attach_defaults(GTK_TABLE(table), qra, 1, 2, 5, 6); - qrasigid = g_signal_connect(qra, "changed", G_CALLBACK(qra_changed), NULL); - - /* altitude */ - label = gtk_label_new(_("Altitude")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 6, 7); - - alt = gtk_spin_button_new_with_range(0, 5000, 1); - gtk_spin_button_set_increments(GTK_SPIN_BUTTON(alt), 1, 100); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(alt), TRUE); - gtk_widget_set_tooltip_text(alt, - _("Select the altitude of the ground station " - "in meters or feet " - "depending on your settings")); - gtk_table_attach_defaults(GTK_TABLE(table), alt, 1, 2, 6, 7); - - if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_IMPERIAL)) - { - label = gtk_label_new(_("ft above sea level")); - } - else - { - label = gtk_label_new(_("m above sea level")); - } - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 6, 7); - - /* weather station */ - label = gtk_label_new(_("Weather St")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 7, 8); - - wx = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(wx), 4); - gtk_widget_set_tooltip_text(wx, _("Four letter code for weather station")); - gtk_table_attach_defaults(GTK_TABLE(table), wx, 1, 3, 7, 8); - - wxbut = gpredict_hstock_button(GTK_STOCK_INDEX, _("Select"), - _ - ("Select a predefined weather station from " - "a list.")); - g_signal_connect(wxbut, "clicked", G_CALLBACK(select_location), - GUINT_TO_POINTER(SELECTION_MODE_WX)); - gtk_table_attach_defaults(GTK_TABLE(table), wxbut, 3, 4, 7, 8); - -#ifdef HAS_LIBGPS - /* GPSD enabled */ - label = gtk_label_new(_("QTH Type")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 8, 9); - - type = gtk_combo_box_text_new(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(type), _("Static")); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(type), _("GPSD")); - gtk_combo_box_set_active(GTK_COMBO_BOX(type), 0); - gtk_widget_set_tooltip_text(type, - _("A qth can be static, ie. it does not " - "change, or gpsd based for computers with " - "gps attached.")); - gtk_table_attach_defaults(GTK_TABLE(table), type, 1, 2, 8, 9); - /* GPSD Server */ - label = gtk_label_new(_("GPSD Server")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 9, 10); - - server = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(server), 6000); - gtk_widget_set_tooltip_text(server, _("GPSD Server.")); - gtk_table_attach_defaults(GTK_TABLE(table), server, 1, 2, 9, 10); - - /* GPSD Port */ - label = gtk_label_new(_("GPSD Port")); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 10, 11); - - port = gtk_spin_button_new_with_range(0, 32768, 1); - gtk_spin_button_set_increments(GTK_SPIN_BUTTON(port), 1, 100); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE); - gtk_widget_set_tooltip_text(port, - _("Set the port for GPSD to use. Default for " - "gpsd is 2947.")); - gtk_table_attach_defaults(GTK_TABLE(table), port, 1, 2, 10, 11); -#endif - - if (!new) - update_widgets(treeview); - - gtk_widget_show_all(table); - - return table; -} - -/** Update widgets from the currently selected row in the treeview */ +/* Update widgets from the currently selected row in the treeview */ static void update_widgets(GtkTreeView * treeview) { GtkTreeSelection *selection; /* the selection in the tree view */ @@ -886,3 +571,278 @@ static void qra_changed(GtkEntry * entry, gpointer data) } } + +static GtkWidget *create_editor_widgets(GtkTreeView * treeview, gboolean new) +{ + GtkWidget *table; + GtkWidget *label; + GtkWidget *locbut; + GtkWidget *wxbut; + + table = gtk_grid_new(); + gtk_grid_set_column_homogeneous(GTK_GRID(table), FALSE); + gtk_grid_set_row_homogeneous(GTK_GRID(table), FALSE); + gtk_grid_set_column_spacing(GTK_GRID(table), 5); + gtk_grid_set_row_spacing(GTK_GRID(table), 5); + gtk_container_set_border_width(GTK_CONTAINER(table), 5); + + /* QTH name */ + label = gtk_label_new(_("Name")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); + + name = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(name), 25); + gtk_widget_set_tooltip_text(name, + _ + ("Enter a short name for this ground station, " + "e.g. callsign.\n" + "Allowed characters: 0..9, a..z, A..Z, - and _")); + gtk_grid_attach(GTK_GRID(table), name, 1, 0, 3, 1); + + /* attach changed signal so that we can enable OK button when + a proper name has been entered + */ + g_signal_connect(name, "changed", G_CALLBACK(name_changed), NULL); + + /* QTH description */ + label = gtk_label_new(_("Description")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); + + desc = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(desc), 256); + gtk_widget_set_tooltip_text(desc, + _("Enter an optional description for this" + " ground station.")); + gtk_grid_attach(GTK_GRID(table), desc, 1, 1, 3, 1); + + /* location */ + label = gtk_label_new(_("Location")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1); + + location = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(location), 50); + gtk_widget_set_tooltip_text(location, + _("Optional location of the ground station, " + "e.g. Copenhagen, Denmark.")); + gtk_grid_attach(GTK_GRID(table), location, 1, 2, 2, 1); + + locbut = gtk_button_new_with_label(_("Select")); + gtk_widget_set_tooltip_text(locbut, _("Select a location from a list")); + g_signal_connect(locbut, "clicked", G_CALLBACK(select_location), + GUINT_TO_POINTER(SELECTION_MODE_LOC)); + gtk_grid_attach(GTK_GRID(table), locbut, 3, 2, 1, 1); + + + /* latitude */ + label = gtk_label_new(_("Latitude (\302\260)")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 3, 1, 1); + + lat = gtk_spin_button_new_with_range(0.00, 90.00, 0.0001); + gtk_spin_button_set_increments(GTK_SPIN_BUTTON(lat), 0.0001, 1.0); + gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(lat), TRUE); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(lat), 4); + gtk_widget_set_tooltip_text(lat, + _("Select the latitude of the ground station " + "in decimal degrees.")); + gtk_grid_attach(GTK_GRID(table), lat, 1, 3, 1, 1); + + ns = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ns), _("North")); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ns), _("South")); + gtk_combo_box_set_active(GTK_COMBO_BOX(ns), 0); + gtk_grid_attach(GTK_GRID(table), ns, 2, 3, 1, 1); + + /* longitude */ + label = gtk_label_new(_("Longitude (\302\260)")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 4, 1, 1); + + lon = gtk_spin_button_new_with_range(0.00, 180.00, 0.0001); + gtk_spin_button_set_increments(GTK_SPIN_BUTTON(lon), 0.0001, 1.0); + gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(lon), TRUE); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(lon), 4); + gtk_widget_set_tooltip_text(lon, + _("Select the longitude of the ground station " + "in decimal degrees.")); + gtk_grid_attach(GTK_GRID(table), lon, 1, 4, 1, 1); + + ew = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ew), _("East")); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ew), _("West")); + gtk_combo_box_set_active(GTK_COMBO_BOX(ew), 0); + gtk_grid_attach(GTK_GRID(table), ew, 2, 4, 1, 1); + + /* connect lat/lon spinners and combos to callback + remember signal id so that we can block signals + while doing automatic cross-updates + */ + latsigid = g_signal_connect(lat, "value-changed", + G_CALLBACK(latlon_changed), NULL); + lonsigid = g_signal_connect(lon, "value-changed", + G_CALLBACK(latlon_changed), NULL); + nssigid = g_signal_connect(ns, "changed", + G_CALLBACK(latlon_changed), NULL); + ewsigid = g_signal_connect(ew, "changed", + G_CALLBACK(latlon_changed), NULL); + + /* QRA locator */ + label = gtk_label_new(_("Locator")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 5, 1, 1); + + qra = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(qra), 6); + gtk_widget_set_tooltip_text(qra, _("Maidenhead locator grid.")); + qrasigid = g_signal_connect(qra, "changed", G_CALLBACK(qra_changed), NULL); + gtk_grid_attach(GTK_GRID(table), qra, 1, 5, 1, 1); + + /* altitude */ + label = gtk_label_new(_("Altitude")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 6, 1, 1); + + alt = gtk_spin_button_new_with_range(0, 5000, 1); + gtk_spin_button_set_increments(GTK_SPIN_BUTTON(alt), 1, 100); + gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(alt), TRUE); + gtk_widget_set_tooltip_text(alt, + _("Select the altitude of the ground station " + "in meters or feet " + "depending on your settings")); + gtk_grid_attach(GTK_GRID(table), alt, 1, 6, 1, 1); + + if (sat_cfg_get_bool(SAT_CFG_BOOL_USE_IMPERIAL)) + label = gtk_label_new(_("ft ASL")); + else + label = gtk_label_new(_("m ASL")); + + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 2, 6, 1, 1); + + /* weather station */ + label = gtk_label_new(_("Weather St")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 7, 1, 1); + + wx = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(wx), 4); + gtk_widget_set_tooltip_text(wx, _("Four letter code for weather station")); + gtk_grid_attach(GTK_GRID(table), wx, 1, 7, 2, 1); + + wxbut = gtk_button_new_with_label(_("Select")); + gtk_widget_set_tooltip_text(wxbut, _("Select a weather station")); + g_signal_connect(wxbut, "clicked", G_CALLBACK(select_location), + GUINT_TO_POINTER(SELECTION_MODE_WX)); + gtk_grid_attach(GTK_GRID(table), wxbut, 3, 7, 1, 1); + +#ifdef HAS_LIBGPS + /* GPSD enabled */ + label = gtk_label_new(_("QTH Type")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 8, 1, 1); + + type = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(type), _("Static")); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(type), _("GPSD")); + gtk_combo_box_set_active(GTK_COMBO_BOX(type), 0); + gtk_widget_set_tooltip_text(type, + _("A qth can be static, ie. it does not " + "change, or gpsd based for computers with " + "gps attached.")); + gtk_grid_attach(GTK_GRID(table), type, 1, 8, 1, 1); + + /* GPSD Server */ + label = gtk_label_new(_("GPSD Server")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 9, 1, 1); + + server = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(server), 6000); + gtk_widget_set_tooltip_text(server, _("GPSD Server.")); + gtk_grid_attach(GTK_GRID(table), server, 1, 9, 1, 1); + + /* GPSD Port */ + label = gtk_label_new(_("GPSD Port")); + g_object_set(label, "xalign", 0.0f, "yalign", 0.5f, NULL); + gtk_grid_attach(GTK_GRID(table), label, 0, 10, 1, 1); + + port = gtk_spin_button_new_with_range(0, 32768, 1); + gtk_spin_button_set_increments(GTK_SPIN_BUTTON(port), 1, 100); + gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE); + gtk_widget_set_tooltip_text(port, + _("Set the port for GPSD to use. Default for " + "gpsd is 2947.")); + gtk_grid_attach(GTK_GRID(table), port, 1, 10, 1, 1); +#endif + + if (!new) + update_widgets(treeview); + + gtk_widget_show_all(table); + + return table; +} + +/* + * Add or edit a QTH entry. + * + * The parameter new is used to indicate whether a new entry should be + * created or just edit the one selected in the treeview. + */ +void sat_pref_qth_editor_run(GtkTreeView * treeview, gboolean new) +{ + gint response; + gboolean finished = FALSE; + + /* crate dialog and add contents */ + dialog = gtk_dialog_new_with_buttons(_("Edit ground station data"), + GTK_WINDOW(window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + "_Clear", GTK_RESPONSE_REJECT, + "_Cancel", GTK_RESPONSE_CANCEL, + "_OK", GTK_RESPONSE_OK, NULL); + + /* disable OK button to begin with */ + gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), + GTK_RESPONSE_OK, FALSE); + + gtk_container_add(GTK_CONTAINER + (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), + create_editor_widgets(treeview, new)); + + /* this hacky-thing is to keep the dialog running in case the + CLEAR button is plressed. OK and CANCEL will exit the loop + */ + while (!finished) + { + response = gtk_dialog_run(GTK_DIALOG(dialog)); + + switch (response) + { + case GTK_RESPONSE_OK: + /* OK */ + if (apply_changes(treeview, new)) + finished = TRUE; + else + finished = FALSE; + + break; + + case GTK_RESPONSE_REJECT: + /* CLEAR */ + clear_widgets(); + break; + + default: + /* Everything else is considered CANCEL */ + finished = TRUE; + break; + } + } + + gtk_widget_destroy(dialog); +} diff --git a/src/sat-pref-qth-editor.h b/src/sat-pref-qth-editor.h index 6f2667d..44812e3 100644 --- a/src/sat-pref-qth-editor.h +++ b/src/sat-pref-qth-editor.h @@ -1,29 +1,3 @@ -/* - Gpredict: Real-time satellite tracking and orbit prediction program - - Copyright (C) 2001-2009 Alexandru Csete, OZ9AEC. - - Authors: Alexandru Csete - - Comments, questions and bugreports should be submitted via - http://sourceforge.net/projects/gpredict/ - More details can be found at the project home page: - - http://gpredict.oz9aec.net/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, visit http://www.fsf.org/ -*/ #ifndef SAT_PREF_QTH_EDITOR_H #define SAT_PREF_QTH_EDITOR_H 1