sat-pref-multi-pass.c
1 /* 2 Gpredict: Real-time satellite tracking and orbit prediction program 3 4 Copyright (C) 2001-2017 Alexandru Csete, OZ9AEC. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, visit http://www.fsf.org/ 18 */ 19 #ifdef HAVE_CONFIG_H 20 #include <build-config.h> 21 #endif 22 #include <glib/gi18n.h> 23 #include <gtk/gtk.h> 24 25 #include "sat-cfg.h" 26 #include "sat-pass-dialogs.h" 27 #include "sat-pref-multi-pass.h" 28 29 30 #define Y0 1 /* First row where checkboxes are placed */ 31 #define COLUMNS 2 /* Number of columns in the table */ 32 33 static GtkWidget *check[MULTI_PASS_COL_NUMBER]; 34 static guint startflags; 35 static guint flags; 36 static gboolean dirty = FALSE; 37 static gboolean reset = FALSE; 38 39 extern const gchar *MULTI_PASS_COL_HINT[]; 40 41 42 /* User pressed cancel. Any changes to config must be cancelled. */ 43 void sat_pref_multi_pass_cancel() 44 { 45 dirty = FALSE; 46 reset = FALSE; 47 } 48 49 /* User pressed OK. Any changes should be stored in config. */ 50 void sat_pref_multi_pass_ok() 51 { 52 if (dirty) 53 { 54 sat_cfg_set_int(SAT_CFG_INT_PRED_MULTI_COL, flags); 55 dirty = FALSE; 56 } 57 else if (reset) 58 { 59 sat_cfg_reset_int(SAT_CFG_INT_PRED_MULTI_COL); 60 reset = FALSE; 61 } 62 } 63 64 static void toggle_cb(GtkToggleButton * toggle, gpointer data) 65 { 66 if (gtk_toggle_button_get_active(toggle)) 67 flags |= (1 << GPOINTER_TO_UINT(data)); 68 else 69 flags &= ~(1 << GPOINTER_TO_UINT(data)); 70 71 /* clear dirty flag if we are back where we started */ 72 dirty = (flags != startflags); 73 } 74 75 /* Reset settings */ 76 static void reset_cb(GtkWidget * button, gpointer data) 77 { 78 guint i; 79 80 (void)button; 81 (void)data; 82 83 /* get defaults */ 84 flags = sat_cfg_get_int_def(SAT_CFG_INT_PRED_MULTI_COL); 85 86 for (i = 0; i < MULTI_PASS_COL_NUMBER; i++) 87 { 88 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check[i]), 89 flags & (1 << i)); 90 } 91 92 /* reset flags */ 93 reset = TRUE; 94 dirty = FALSE; 95 } 96 97 static void create_reset_button(GtkBox * vbox) 98 { 99 GtkWidget *button; 100 GtkWidget *butbox; 101 102 button = gtk_button_new_with_label(_("Reset")); 103 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(reset_cb), NULL); 104 105 gtk_widget_set_tooltip_text(button, 106 _("Reset settings to the default values.")); 107 108 butbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); 109 gtk_button_box_set_layout(GTK_BUTTON_BOX(butbox), GTK_BUTTONBOX_END); 110 gtk_box_pack_end(GTK_BOX(butbox), button, FALSE, TRUE, 10); 111 112 gtk_box_pack_end(vbox, butbox, FALSE, TRUE, 0); 113 } 114 115 GtkWidget *sat_pref_multi_pass_create() 116 { 117 GtkWidget *table; 118 GtkWidget *label; 119 GtkWidget *vbox; 120 guint i; 121 122 /* create the table */ 123 table = gtk_grid_new(); 124 gtk_grid_set_row_spacing(GTK_GRID(table), 10); 125 gtk_grid_set_column_spacing(GTK_GRID(table), 5); 126 127 /* create header */ 128 label = gtk_label_new(NULL); 129 g_object_set(label, "xalign", 0.0, "yalign", 0.5, NULL); 130 gtk_label_set_markup(GTK_LABEL(label), _("<b>Visible Columns:</b>")); 131 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 2, 1); 132 133 /* get visible column flags */ 134 flags = sat_cfg_get_int(SAT_CFG_INT_PRED_MULTI_COL); 135 136 for (i = 0; i < MULTI_PASS_COL_NUMBER; i++) 137 { 138 check[i] = gtk_check_button_new_with_label(MULTI_PASS_COL_HINT[i]); 139 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check[i]), 140 flags & (1 << i)); 141 g_signal_connect(check[i], "toggled", G_CALLBACK(toggle_cb), 142 GUINT_TO_POINTER(i)); 143 144 gtk_grid_attach(GTK_GRID(table), check[i], 145 i % COLUMNS, Y0 + i / COLUMNS, 1, 1); 146 } 147 148 /* create vertical box */ 149 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); 150 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); 151 gtk_container_set_border_width(GTK_CONTAINER(vbox), 20); 152 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); 153 154 /* create RESET button */ 155 create_reset_button(GTK_BOX(vbox)); 156 157 startflags = flags; 158 dirty = FALSE; 159 reset = FALSE; 160 161 return vbox; 162 }