gpredict-help.c
1 /* 2 Gpredict: Real-time satellite tracking and orbit prediction program 3 4 Copyright (C) 2001-2017 Alexandru Csete, OZ9AEC. 5 6 Comments, questions and bugreports should be submitted via 7 http://sourceforge.net/projects/gpredict/ 8 More details can be found at the project home page: 9 10 http://gpredict.oz9aec.net/ 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, visit http://www.fsf.org/ 24 */ 25 #include <gtk/gtk.h> 26 #include <glib/gi18n.h> 27 #ifdef HAVE_CONFIG_H 28 #include <build-config.h> 29 #endif 30 #include "compat.h" 31 #include "gpredict-help.h" 32 #include "sat-cfg.h" 33 #include "sat-log.h" 34 35 36 extern GtkWidget *app; 37 38 /** 39 * Show a text file in the gpredict system directory 40 * @param filename The basic file name 41 * 42 * This function is intended to display files like NEWS, COPYING, etc. 43 * Note that on windows these files have .txt suffix, while on Unix they 44 * do not. 45 */ 46 void gpredict_help_show_txt(const gchar * filename) 47 { 48 GtkWidget *dialog; 49 GtkWidget *swin; 50 GtkWidget *view; 51 GtkTextBuffer *txtbuf; 52 GIOChannel *chan; 53 GError *error = NULL; 54 gchar *fname; 55 gchar *buff; 56 gsize length; 57 58 /* get system data directory */ 59 #ifdef G_OS_UNIX 60 fname = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S, filename, NULL); 61 #endif 62 #ifdef G_OS_WIN32 63 buff = g_win32_get_package_installation_directory_of_module(NULL); 64 fname = g_strconcat(buff, G_DIR_SEPARATOR_S, "doc", 65 G_DIR_SEPARATOR_S, filename, ".txt", NULL); 66 g_free(buff); 67 #endif 68 69 /* load file into buffer */ 70 chan = g_io_channel_new_file(fname, "r", &error); 71 if (error != NULL) 72 { 73 sat_log_log(SAT_LOG_LEVEL_ERROR, 74 _("%s: Failed to load %s (%s)"), 75 __func__, fname, error->message); 76 g_free(fname); 77 g_clear_error(&error); 78 79 return; 80 } 81 82 g_io_channel_read_to_end(chan, &buff, &length, &error); 83 if (error != NULL) 84 { 85 sat_log_log(SAT_LOG_LEVEL_ERROR, 86 _("%s: Error reading %s (%s)"), 87 __func__, fname, error->message); 88 89 g_free(buff); 90 g_clear_error(&error); 91 g_io_channel_shutdown(chan, TRUE, NULL); 92 g_io_channel_unref(chan); 93 94 return; 95 } 96 97 g_free(fname); 98 99 /* create text view and text buffer widgets */ 100 view = gtk_text_view_new(); 101 gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); 102 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE); 103 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 15); 104 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 15); 105 if (GTK_MINOR_VERSION >= 16) 106 gtk_text_view_set_monospace(GTK_TEXT_VIEW(view), FALSE); 107 108 txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); 109 110 gtk_text_buffer_set_text(txtbuf, buff, -1); 111 g_free(buff); 112 113 /* scrolled window */ 114 swin = gtk_scrolled_window_new(NULL, NULL); 115 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), 116 GTK_SHADOW_ETCHED_IN); 117 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), 118 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); 119 gtk_container_add(GTK_CONTAINER(swin), view); 120 121 /* create and show dialogue with textbuffer */ 122 dialog = gtk_dialog_new_with_buttons(_("Gpredict Info"), 123 GTK_WINDOW(app), 0, 124 "_Close", GTK_RESPONSE_ACCEPT, NULL); 125 gtk_widget_set_size_request(dialog, -1, 450); 126 buff = icon_file_name("gpredict-icon.png"); 127 gtk_window_set_icon_from_file(GTK_WINDOW(dialog), buff, NULL); 128 g_free(buff); 129 130 g_signal_connect_swapped(dialog, "response", 131 G_CALLBACK(gtk_widget_destroy), dialog); 132 133 gtk_box_pack_start(GTK_BOX 134 (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), swin, 135 TRUE, TRUE, 0); 136 gtk_widget_show_all(dialog); 137 }