sat-pref.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 20 #ifdef HAVE_CONFIG_H 21 #include <build-config.h> 22 #endif 23 #include <glib/gi18n.h> 24 #include <gtk/gtk.h> 25 26 #include "compat.h" 27 #include "gpredict-utils.h" 28 #include "sat-cfg.h" 29 #include "sat-pref.h" 30 #include "sat-pref-general.h" 31 #include "sat-pref-interfaces.h" 32 #include "sat-pref-modules.h" 33 #include "sat-pref-predict.h" 34 35 /** Columns in the icon list */ 36 enum { 37 NBOOK_PAGE_GENERAL = 0, 38 NBOOK_PAGE_MODULES, 39 NBOOK_PAGE_INTERFACE, 40 NBOOK_PAGE_PREDICT 41 }; 42 43 const gchar *WINDOW_TITLE[4] = { 44 N_("GPREDICT Preferences :: General"), 45 N_("GPREDICT Preferences :: Modules"), 46 N_("GPREDICT Preferences :: Interfaces"), 47 N_("GPREDICT Preferences :: Predict") 48 }; 49 50 GtkWidget *window; /* dialog window */ 51 extern GtkWidget *app; 52 53 static void button_press_cb(GtkWidget * widget, gpointer nbook); 54 55 /** 56 * Create and run preferences dialog. 57 * 58 * The preferences dialog contains a GtkNoteBook, which is used to group 59 * the various configuration parts/modules (General, Modules, Interfaces, ...). 60 * Each configuration part can contain several subgroups that are managed 61 * by the module itself. As an example, consider the "Modules" tab which 62 * could have the following sub-groups: General, List View, Map View and so on. 63 * The tabs of the notebook are invisible, instead a vertical icon list 64 * placed on the left of the notebook is used to navigate through the 65 * notebook pages. The icon list is actually implemented using pixmap buttons 66 * in a button box. Using something like the GtkIconView would have been better 67 * but that seems to be rather useless when packed into a box. 68 */ 69 void sat_pref_run() 70 { 71 GtkWidget *nbook; /* notebook widget */ 72 GtkWidget *hbox; /* horizontal box */ 73 GtkWidget *butbox; 74 GtkWidget *genbut, *modbut, *ifbut, *predbut; 75 gchar *iconfile; 76 gint response; 77 78 /* Create notebook and add individual pages. 79 The individual pages will need the GKeyFile 80 */ 81 nbook = gtk_notebook_new(); 82 gtk_notebook_append_page(GTK_NOTEBOOK(nbook), 83 sat_pref_general_create(), 84 gtk_label_new(_("General"))); 85 gtk_notebook_append_page(GTK_NOTEBOOK(nbook), 86 sat_pref_modules_create(NULL), 87 gtk_label_new(_("Modules"))); 88 gtk_notebook_append_page(GTK_NOTEBOOK(nbook), 89 sat_pref_interfaces_create(), 90 gtk_label_new(_("Interfaces"))); 91 gtk_notebook_append_page(GTK_NOTEBOOK(nbook), 92 sat_pref_predict_create(), 93 gtk_label_new(_("Predict"))); 94 95 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(nbook), FALSE); 96 gtk_notebook_set_show_border(GTK_NOTEBOOK(nbook), FALSE); 97 98 /* create a button box and add the buttons one by one */ 99 genbut = gpredict_vpixmap_button("gpredict-sat-pref.png", 100 _("General"), NULL); 101 gtk_button_set_relief(GTK_BUTTON(genbut), GTK_RELIEF_NONE); 102 g_object_set_data(G_OBJECT(genbut), "page", 103 GINT_TO_POINTER(NBOOK_PAGE_GENERAL)); 104 g_signal_connect(G_OBJECT(genbut), "clicked", 105 G_CALLBACK(button_press_cb), nbook); 106 107 modbut = gpredict_vpixmap_button("gpredict-sat-list.png", 108 _("Modules"), NULL); 109 gtk_button_set_relief(GTK_BUTTON(modbut), GTK_RELIEF_NONE); 110 g_object_set_data(G_OBJECT(modbut), "page", 111 GINT_TO_POINTER(NBOOK_PAGE_MODULES)); 112 g_signal_connect(G_OBJECT(modbut), "clicked", 113 G_CALLBACK(button_press_cb), nbook); 114 115 ifbut = gpredict_vpixmap_button("gpredict-oscilloscope.png", 116 _("Interfaces"), NULL); 117 gtk_button_set_relief(GTK_BUTTON(ifbut), GTK_RELIEF_NONE); 118 g_object_set_data(G_OBJECT(ifbut), "page", 119 GINT_TO_POINTER(NBOOK_PAGE_INTERFACE)); 120 g_signal_connect(G_OBJECT(ifbut), "clicked", 121 G_CALLBACK(button_press_cb), nbook); 122 123 predbut = gpredict_vpixmap_button("gpredict-calendar.png", 124 _("Predict"), NULL); 125 gtk_button_set_relief(GTK_BUTTON(predbut), GTK_RELIEF_NONE); 126 g_object_set_data(G_OBJECT(predbut), "page", 127 GINT_TO_POINTER(NBOOK_PAGE_PREDICT)); 128 g_signal_connect(G_OBJECT(predbut), "clicked", 129 G_CALLBACK(button_press_cb), nbook); 130 131 butbox = gtk_button_box_new(GTK_ORIENTATION_VERTICAL); 132 gtk_button_box_set_layout(GTK_BUTTON_BOX(butbox), GTK_BUTTONBOX_START); 133 gtk_container_add(GTK_CONTAINER(butbox), genbut); 134 gtk_container_add(GTK_CONTAINER(butbox), modbut); 135 gtk_container_add(GTK_CONTAINER(butbox), ifbut); 136 gtk_container_add(GTK_CONTAINER(butbox), predbut); 137 138 /* create horizontal box which will contain the icon list on the left side 139 and the notebook on the right side. 140 */ 141 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 142 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE); 143 gtk_box_pack_start(GTK_BOX(hbox), butbox, FALSE, FALSE, 0); 144 gtk_box_pack_start(GTK_BOX(hbox), nbook, TRUE, TRUE, 0); 145 gtk_widget_show_all(hbox); 146 147 /* create and display preferences window */ 148 window = gtk_dialog_new_with_buttons(_("Gpredict Preferences :: General"), 149 GTK_WINDOW(app), 150 GTK_DIALOG_MODAL | 151 GTK_DIALOG_DESTROY_WITH_PARENT, 152 "_Cancel", GTK_RESPONSE_REJECT, 153 "_OK", GTK_RESPONSE_ACCEPT, 154 NULL); 155 iconfile = icon_file_name("gpredict-sat-pref.png"); 156 gtk_window_set_icon_from_file(GTK_WINDOW(window), iconfile, NULL); 157 g_free(iconfile); 158 159 gtk_box_pack_start(GTK_BOX 160 (gtk_dialog_get_content_area(GTK_DIALOG(window))), 161 hbox, TRUE, TRUE, 0); 162 gtk_box_set_spacing(GTK_BOX 163 (gtk_dialog_get_content_area(GTK_DIALOG(window))), 10); 164 165 gtk_button_clicked(GTK_BUTTON(genbut)); 166 167 response = gtk_dialog_run(GTK_DIALOG(window)); 168 switch (response) 169 { 170 case GTK_RESPONSE_ACCEPT: 171 sat_pref_general_ok(); 172 sat_pref_modules_ok(NULL); 173 sat_pref_interfaces_ok(); 174 sat_pref_predict_ok(); 175 sat_cfg_save(); 176 break; 177 178 default: 179 sat_pref_general_cancel(); 180 sat_pref_modules_cancel(NULL); 181 sat_pref_interfaces_cancel(); 182 sat_pref_predict_cancel(); 183 break; 184 } 185 gtk_widget_destroy(window); 186 } 187 188 /** 189 * Handle button press events 190 * 191 * Basically consists of switching pages in the notebook. The page number is 192 * received via the nbook parameter. 193 */ 194 static void button_press_cb(GtkWidget * widget, gpointer nbook) 195 { 196 gint page = 197 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "page")); 198 199 gtk_notebook_set_current_page(GTK_NOTEBOOK(nbook), page); 200 201 gtk_window_set_title(GTK_WINDOW(window), _(WINDOW_TITLE[page])); 202 }