about.c 9.79 KB
Newer Older
1 2 3
/**
 * about.c - about dialog for SciteProj
 *
4
 *	 Copyright 2008-2018 Andreas Rönnquist
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of SciteProj.
 *
 * SciteProj 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 3 of the License, or
 * (at your option) any later version.
 *
 * SciteProj 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 SciteProj.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <glib.h>
#include <gtk/gtk.h>
25 26 27
#include <glib/gi18n.h>

#include <locale.h>
28 29 30 31 32 33 34

#include "about.h"

#include "graphics.h"

#include "prefs.h"

35
gchar *homepage_string=(gchar*)"https://www.nongnu.org/sciteproj";
36

37
gchar *sVersion = (gchar*)SCITEPROJ_VERSION;
38 39 40 41 42 43 44 45

static GtkWidget *window;

void create_about_dialog();

gboolean handle_about_close_event(GtkWidget *widget,GdkEvent *event,gpointer user_data);
void link_button_cb(GtkButton *button,gpointer user_data);

46
gchar *version_string = NULL;
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

/**
 * show_about_dialog
 * Shows the about dialog, and if it isnt already made, creates it
 */
void show_about_dialog()
{
	if (!window)
		create_about_dialog();
	else
		gtk_window_present(GTK_WINDOW(window));
}


/**
 *	creates a new dialog box, and fills it will all necessary information
 */
void create_about_dialog()
{
66
	GtkWidget *grid;
67 68 69 70 71 72 73
	GtkWidget *textview_info;
	GtkWidget *logo_image;
	GtkWidget *linkbutton;
	GtkWidget *ok_button;
	GtkWidget *notebook;
	GtkWidget *notebook_label1;
	GtkWidget *notebook_label2;
74

75 76 77 78
	GtkWidget *sciteproj_label;
	GtkWidget *version_string_label;
	GtkWidget *copyright_label;
	GtkWidget *gtk_version_label;
79

80 81 82 83 84 85 86 87 88
	GtkTextBuffer *textbuffer_info;
	GtkTextBuffer *textbuffer_license;
	GtkWidget *textview_license;
	GtkTextIter iter;

	gchar *copyrightstring;


	// Make the dialog
89
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
90 91
	gtk_container_set_border_width(GTK_CONTAINER(window), 8);

92
	gtk_widget_set_size_request(window, 500, 400);
93 94

	// Make a container
95
	grid = gtk_grid_new();
96

97
	gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
98

99
	gtk_container_add(GTK_CONTAINER(window), grid);
100

101
	logo_image = gtk_image_new_from_pixbuf(program_icon_pixbuf);
102

103
	gtk_grid_attach(GTK_GRID(grid), logo_image, 0, 0, 5, 1);
104

105 106 107
	sciteproj_label = gtk_label_new(NULL);
	gtk_label_set_selectable(GTK_LABEL(sciteproj_label), FALSE);
	gtk_label_set_markup(GTK_LABEL(sciteproj_label), "<big><b>SciteProj</b></big>");
108

109

110
	gtk_grid_attach_next_to(GTK_GRID(grid), sciteproj_label, logo_image, GTK_POS_BOTTOM, 5, 1);
111 112 113

	// Show version of SciteProj

114
	gchar *about_dialog_version_string;
115

116
 #ifdef _DEBUG
117
	about_dialog_version_string = g_strdup_printf("%s DEBUG",version_string);
118
#else
119
	about_dialog_version_string = g_strdup_printf("%s", version_string);
120 121
#endif

122 123
	version_string_label = gtk_label_new(about_dialog_version_string);
	gtk_label_set_selectable(GTK_LABEL(version_string_label), FALSE);
124

125
	gtk_grid_attach_next_to(GTK_GRID(grid), version_string_label, sciteproj_label, GTK_POS_BOTTOM, 5, 1);
126

127
	// Show SciteProj copyrights
128
	copyrightstring = g_strdup_printf("Copyright (C) 2008-2017 Andreas Rönnquist <andreas@ronnquist.net>");
129

130 131
	copyright_label = gtk_label_new(copyrightstring);
	gtk_label_set_selectable(GTK_LABEL(copyright_label), FALSE);
132

133
	gtk_grid_attach_next_to(GTK_GRID(grid), copyright_label, version_string_label, GTK_POS_BOTTOM, 5, 1);
134 135

	// show GTK versions
136
	gchar *gtk_string = g_strdup_printf("GTK+ %d.%d.%d / GLib %d.%d.%d",
137 138 139 140
		   //"Operating System: unknown",
		   gtk_major_version, gtk_minor_version, gtk_micro_version,
		   glib_major_version, glib_minor_version, glib_micro_version);

141
	gtk_version_label = gtk_label_new(gtk_string);
142

143
	gtk_label_set_selectable(GTK_LABEL(gtk_version_label), FALSE);
144

145
	gtk_grid_attach_next_to(GTK_GRID(grid), gtk_version_label, copyright_label, GTK_POS_BOTTOM, 5, 1);
146

147 148

	// Show a link to the SciteProj homepage
149
	linkbutton = gtk_link_button_new_with_label(homepage_string, homepage_string);
150

151
	gtk_grid_attach_next_to(GTK_GRID(grid), linkbutton, gtk_version_label, GTK_POS_BOTTOM, 5, 1);
152

153 154
	// New notebook - we want tabs for different sets of text

155
	notebook = gtk_notebook_new();
156

157 158
	notebook_label1 = gtk_label_new(_("Information"));
	notebook_label2 = gtk_label_new(_("License"));
159 160

	// create a scrolled_window and a textview for the license
161 162
	textbuffer_license = gtk_text_buffer_new(NULL);
	gtk_text_buffer_get_start_iter(textbuffer_license, &iter);
163 164


165 166

	gchar *sLicense =	_("SciteProj is free software: you can redistribute it and/or modify "
167 168 169 170 171 172 173 174 175 176 177
	                      "it under the terms of the GNU General Public License as published by "
	                      "the Free Software Foundation, either version 3 of the License, or "
	                      "(at your option) any later version.\n"
	                      "\n"
	                      "SciteProj 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.\n"
	                      "\n"
	                      "You should have received a copy of the GNU General Public License "
	                      "along with SciteProj.  If not, see <http://www.gnu.org/licenses/>.\n");
178 179


180

181
	gtk_text_buffer_insert(textbuffer_license, &iter, sLicense, -1);
182

183
	textview_license = gtk_text_view_new_with_buffer(textbuffer_license);
184

185
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview_license), GTK_WRAP_WORD);
186

187 188
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview_license), TRUE);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(textview_license), FALSE);
189 190 191

	GtkWidget *scrolled_window_license;

192
	scrolled_window_license = gtk_scrolled_window_new(NULL, NULL);
193 194

	// Never show horisontal scrollbar, always show vertical
195
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window_license), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
196

197
	gtk_container_add(GTK_CONTAINER(scrolled_window_license), textview_license);
198 199 200 201



	// New textbuffer - and we get the beginning of the textbuffer
202 203
	textbuffer_info = gtk_text_buffer_new(NULL);
	gtk_text_buffer_get_start_iter(textbuffer_info, &iter);
204

205
	gchar *about_text2 = g_strdup_printf(""
206
		"%s\n"
207 208
		"Roy Wood <roy.wood@gmail.com> and\n"
		"Martin Andrews <ScitePM@PLATFORMedia.com>\n\n"
209
		"%s\n"
210 211
		"Mattias Wecksten <wecksten@gmail.com>\n"
		"Frank Wunderlich\n\n"
212 213 214 215 216
		"%s",
		_("SciteProj is based on ScitePM by"),
		_("Many thanks to"),
		_("For more information about SciteProj, see the README file that\n"
											"is provided with this package."));
217 218 219 220 221

	gchar *text_to_add;

#ifdef _DEBUG

222
	gchar *prefs_dir_string = g_strdup_printf("Preferences loaded from %s",prefs_filename);
223

224 225
	text_to_add = g_strdup_printf("%s\n\n%s", about_text2,
	                            prefs_dir_string);
226 227

#else
228
	text_to_add = about_text2;
229 230 231

#endif

232
	gtk_text_buffer_insert(textbuffer_info, &iter, text_to_add, -1);
233

234
	gtk_text_buffer_get_end_iter(textbuffer_info, &iter);
235 236

	// Setup the textview and windows
237
	textview_info = gtk_text_view_new_with_buffer(textbuffer_info);
238

239 240
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview_info), TRUE);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(textview_info), FALSE);
241 242 243

	GtkWidget *scrolled_window_info;

244
	scrolled_window_info = gtk_scrolled_window_new(NULL, NULL);
245 246

	// Never show horisontal scrollbar, always show vertical
247
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window_info), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
248

249
	gtk_container_add(GTK_CONTAINER(scrolled_window_info), textview_info);
250

251 252
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window_info, notebook_label1);
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window_license, notebook_label2);
253

254
	gtk_widget_set_vexpand(notebook, TRUE);
255

256
	gtk_widget_set_hexpand(notebook, TRUE);
257

258
	gtk_grid_attach_next_to(GTK_GRID(grid), notebook, linkbutton/*gtk_version_label*/, GTK_POS_BOTTOM, 5, 1);
259

260 261
	gtk_text_buffer_place_cursor(textbuffer_info, &iter);
	gtk_text_buffer_select_range(textbuffer_info, &iter, &iter);
262 263

	// Create an ok button
264 265 266
	ok_button = gtk_button_new();
	gtk_button_set_use_underline(GTK_BUTTON(ok_button), TRUE);
	gtk_button_set_label(GTK_BUTTON(ok_button), "_OK");
267

268 269
	gtk_widget_set_halign(ok_button, GTK_ALIGN_END);
	gtk_widget_set_hexpand(ok_button, FALSE);
270

271
	gtk_grid_attach_next_to(GTK_GRID(grid), ok_button, notebook, GTK_POS_BOTTOM, 5, 1);
272 273 274 275 276 277 278

	gtk_widget_grab_focus(ok_button);

	gtk_text_buffer_get_start_iter(textbuffer_info, &iter);
	gtk_text_buffer_place_cursor(textbuffer_info, &iter);

	g_signal_connect_closure
279 280 281
	(G_OBJECT(ok_button), "clicked",
	 g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
	                     window, NULL), FALSE);
282 283


284 285
	g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(handle_about_close_event), window);
	g_signal_connect(G_OBJECT(linkbutton), "released", G_CALLBACK(link_button_cb), linkbutton);
286 287 288 289 290 291 292 293 294 295 296

	gtk_widget_show_all(window);

}


/**
 * Show version
 */
void show_version()
{
297
	g_print("SciteProj %s\n", version_string);
298 299 300 301 302 303
}


/**
 *
 */
304
gboolean handle_about_close_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
305 306 307 308 309 310 311 312 313 314 315
{
	gtk_widget_hide(window);

	return TRUE;
}


/**
 *	Callback for the link button, Without this, it would color the text purple when the
 *	link is followed, which I found really ugly.
 */
316
void link_button_cb(GtkButton *button, gpointer user_data)
317
{
318
	GtkWidget *linkbutton = (GtkWidget*)(user_data);
319

320
	gtk_link_button_set_visited(GTK_LINK_BUTTON(linkbutton), FALSE);
321
}
322 323 324 325 326 327 328


/**
 *
 */
void init_version_string()
{
329
	version_string = g_strdup_printf(_("version %s"), SCITEPROJ_VERSION);
330 331 332 333 334 335 336 337 338 339
}


/**
 *
 */
void done_version_string()
{
	g_free(version_string);
}