<commit_before>/*
WZBlue is a standalone version of aqu4bot's wz.c Warzone 2100 lobby facilities and aqu4bot's networking core.
See http://github.com/Subsentient/aqu4bot for aqu4bot's source code.
Public domain. By Subsentient, 2015.
See the included file UNLICENSE.TXT for more information.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <sys/stat.h>
#include "wzblue.h"
#include "icons.h"

#ifdef WIN
#include <windows.h>
#include <dirent.h>
#include <tchar.h>
#else
#include <sys/wait.h>
#endif //WIN

struct GooeyGuts GuiInfo;

static void GTK_Destroy(GtkWidget *Widget, gpointer Stuff);
static void GTK_NukeContainerChildren(GtkContainer *Container);
static void GUI_LoadIcons(void);
static void GUI_LaunchGame(const char *IP);
static void GUI_DrawLaunchFailure(void);

static gboolean GUI_FindWZExecutable(char *const Out, unsigned OutMaxSize);


static void GTK_Destroy(GtkWidget *Widget, gpointer Stuff)
{
	gtk_main_quit();
	exit(0);
}

gboolean GUI_CheckSlider(void)
{
	const unsigned NewRate = gtk_range_get_value((GtkRange*)GuiInfo.Slider);
	if (RefreshRate != NewRate)
	{
		RefreshRate = NewRate;
		return true; //Value changed.
	}
	
	return false;

}
	

static void GUI_LoadIcons(void)
{
	
	//Our logo
	GdkPixbufLoader *WMIconL = gdk_pixbuf_loader_new();
	
	gdk_pixbuf_loader_write(WMIconL, WMIcon, sizeof WMIcon, NULL);
	gdk_pixbuf_loader_close(WMIconL, NULL);
	
	GuiInfo.WMIcon_Pixbuf = gdk_pixbuf_loader_get_pixbuf(WMIconL);
	 
	//Full icon
	GdkPixbufLoader *FullLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(FullLoader, Icon_Full, sizeof Icon_Full, NULL);
	gdk_pixbuf_loader_close(FullLoader, NULL);

	//Open icon
	GdkPixbufLoader *OpenLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(OpenLoader, Icon_Open, sizeof Icon_Open, NULL);
	gdk_pixbuf_loader_close(OpenLoader, NULL);
	
	//Mod icon
	GdkPixbufLoader *ModLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(ModLoader, Icon_Mod, sizeof Icon_Mod, NULL);
	gdk_pixbuf_loader_close(ModLoader, NULL);
	
	//Locked icon
	GdkPixbufLoader *LockedLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(LockedLoader, Icon_Locked, sizeof Icon_Locked, NULL);
	gdk_pixbuf_loader_close(LockedLoader, NULL);
	

	GuiInfo.Icon_Full_Pixbuf = gdk_pixbuf_loader_get_pixbuf(FullLoader);
	GuiInfo.Icon_Open_Pixbuf = gdk_pixbuf_loader_get_pixbuf(OpenLoader);
	GuiInfo.Icon_Mod_Pixbuf = gdk_pixbuf_loader_get_pixbuf(ModLoader);
	GuiInfo.Icon_Locked_Pixbuf = gdk_pixbuf_loader_get_pixbuf(LockedLoader);
	
	gtk_window_set_icon((GtkWindow*)GuiInfo.Win, GuiInfo.WMIcon_Pixbuf);
}
	
void GTK_NukeWidget(GtkWidget *Widgy)
{
	GTK_NukeContainerChildren((GtkContainer*)Widgy);
	gtk_widget_destroy(Widgy);
}

void GUI_Flush(void)
{ //So if we are doing something that locks us up, we can draw any of our notifications before that happens.
	while (gtk_events_pending()) gtk_main_iteration_do(FALSE);
}

void GUI_SetStatusBar(const char *Text)
{
	gtk_statusbar_remove_all((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID);
	
	
	//Nothing to set it to? We're done.
	if (!Text) return;

	gtk_statusbar_push((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID, Text);
}

void GUI_SetStatusBar_GameCount(const uint32_t GamesAvailable)
{
	gtk_statusbar_remove_all((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID);
	
	char Buf[256];
	
	snprintf(Buf, sizeof Buf, "%u game%s available.", (unsigned)GamesAvailable, GamesAvailable == 1 ? "" : "s");
	
	gtk_statusbar_push((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID, Buf);
}

void GUI_DrawAboutDialog()
{
	GtkWidget *AboutWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	gtk_window_set_type_hint((GtkWindow*)AboutWin, GDK_WINDOW_TYPE_HINT_DIALOG);
	gtk_window_set_skip_taskbar_hint((GtkWindow*)AboutWin, true);
	gtk_window_set_resizable((GtkWindow*)AboutWin, false);
	
	gtk_window_set_title(GTK_WINDOW(AboutWin), "About WZBlue");

	gtk_container_set_border_width(GTK_CONTAINER(AboutWin), 10);
	
	g_signal_connect(G_OBJECT(AboutWin), "destroy", (GCallback)GTK_NukeWidget, NULL);

	GtkWidget *ButtonAlign = gtk_alignment_new(1.0, 1.0, 0.1, 1.0);
	
	GtkWidget *VBox = gtk_vbox_new(FALSE, 5);
	GtkWidget *Image = gtk_image_new_from_pixbuf(GuiInfo.WMIcon_Pixbuf);
	
	gtk_container_add(GTK_CONTAINER(AboutWin), VBox);
	char AboutString[2048];
	
	snprintf(AboutString, sizeof AboutString, "WZBlue Warzone 2100 Lobby Monitor version " WZBLUE_VERSION "\n"
										"Compiled against GTK %d.%d\n\n"
										"By Subsentient. Game status icons by tmp500.", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
	
	GtkWidget *Button = gtk_button_new_from_stock(GTK_STOCK_OK);
	GtkWidget *Label = gtk_label_new(AboutString);
	GtkWidget *LabelAlign = gtk_alignment_new(0.5, 0.5, 0.1, 0.1);
	gtk_container_add((GtkContainer*)LabelAlign, Label);
	
	gtk_container_add(GTK_CONTAINER(ButtonAlign), Button);
	
	gtk_box_pack_start((GtkBox*)VBox, Image, TRUE, TRUE, 5);
	gtk_box_pack_start((GtkBox*)VBox, LabelAlign, TRUE, TRUE, 10);

	gtk_box_pack_start((GtkBox*)VBox, ButtonAlign, TRUE, FALSE, 0);
	
	g_signal_connect_swapped(G_OBJECT(Button), "clicked", (GCallback)GTK_NukeWidget, AboutWin);
	
	gtk_widget_show_all(AboutWin);
}

<commit_msg>Show the ENTIRE gtk version string in our about dialog<commit_after>/*
WZBlue is a standalone version of aqu4bot's wz.c Warzone 2100 lobby facilities and aqu4bot's networking core.
See http://github.com/Subsentient/aqu4bot for aqu4bot's source code.
Public domain. By Subsentient, 2015.
See the included file UNLICENSE.TXT for more information.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <sys/stat.h>
#include "wzblue.h"
#include "icons.h"

#ifdef WIN
#include <windows.h>
#include <dirent.h>
#include <tchar.h>
#else
#include <sys/wait.h>
#endif //WIN

struct GooeyGuts GuiInfo;

static void GTK_Destroy(GtkWidget *Widget, gpointer Stuff);
static void GTK_NukeContainerChildren(GtkContainer *Container);
static void GUI_LoadIcons(void);
static void GUI_LaunchGame(const char *IP);
static void GUI_DrawLaunchFailure(void);

static gboolean GUI_FindWZExecutable(char *const Out, unsigned OutMaxSize);


static void GTK_Destroy(GtkWidget *Widget, gpointer Stuff)
{
	gtk_main_quit();
	exit(0);
}

gboolean GUI_CheckSlider(void)
{
	const unsigned NewRate = gtk_range_get_value((GtkRange*)GuiInfo.Slider);
	if (RefreshRate != NewRate)
	{
		RefreshRate = NewRate;
		return true; //Value changed.
	}
	
	return false;

}
	

static void GUI_LoadIcons(void)
{
	
	//Our logo
	GdkPixbufLoader *WMIconL = gdk_pixbuf_loader_new();
	
	gdk_pixbuf_loader_write(WMIconL, WMIcon, sizeof WMIcon, NULL);
	gdk_pixbuf_loader_close(WMIconL, NULL);
	
	GuiInfo.WMIcon_Pixbuf = gdk_pixbuf_loader_get_pixbuf(WMIconL);
	 
	//Full icon
	GdkPixbufLoader *FullLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(FullLoader, Icon_Full, sizeof Icon_Full, NULL);
	gdk_pixbuf_loader_close(FullLoader, NULL);

	//Open icon
	GdkPixbufLoader *OpenLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(OpenLoader, Icon_Open, sizeof Icon_Open, NULL);
	gdk_pixbuf_loader_close(OpenLoader, NULL);
	
	//Mod icon
	GdkPixbufLoader *ModLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(ModLoader, Icon_Mod, sizeof Icon_Mod, NULL);
	gdk_pixbuf_loader_close(ModLoader, NULL);
	
	//Locked icon
	GdkPixbufLoader *LockedLoader = gdk_pixbuf_loader_new();
	gdk_pixbuf_loader_write(LockedLoader, Icon_Locked, sizeof Icon_Locked, NULL);
	gdk_pixbuf_loader_close(LockedLoader, NULL);
	

	GuiInfo.Icon_Full_Pixbuf = gdk_pixbuf_loader_get_pixbuf(FullLoader);
	GuiInfo.Icon_Open_Pixbuf = gdk_pixbuf_loader_get_pixbuf(OpenLoader);
	GuiInfo.Icon_Mod_Pixbuf = gdk_pixbuf_loader_get_pixbuf(ModLoader);
	GuiInfo.Icon_Locked_Pixbuf = gdk_pixbuf_loader_get_pixbuf(LockedLoader);
	
	gtk_window_set_icon((GtkWindow*)GuiInfo.Win, GuiInfo.WMIcon_Pixbuf);
}
	
void GTK_NukeWidget(GtkWidget *Widgy)
{
	GTK_NukeContainerChildren((GtkContainer*)Widgy);
	gtk_widget_destroy(Widgy);
}

void GUI_Flush(void)
{ //So if we are doing something that locks us up, we can draw any of our notifications before that happens.
	while (gtk_events_pending()) gtk_main_iteration_do(FALSE);
}

void GUI_SetStatusBar(const char *Text)
{
	gtk_statusbar_remove_all((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID);
	
	
	//Nothing to set it to? We're done.
	if (!Text) return;

	gtk_statusbar_push((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID, Text);
}

void GUI_SetStatusBar_GameCount(const uint32_t GamesAvailable)
{
	gtk_statusbar_remove_all((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID);
	
	char Buf[256];
	
	snprintf(Buf, sizeof Buf, "%u game%s available.", (unsigned)GamesAvailable, GamesAvailable == 1 ? "" : "s");
	
	gtk_statusbar_push((GtkStatusbar*)GuiInfo.StatusBar, GuiInfo.StatusBarContextID, Buf);
}

void GUI_DrawAboutDialog()
{
	GtkWidget *AboutWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	gtk_window_set_type_hint((GtkWindow*)AboutWin, GDK_WINDOW_TYPE_HINT_DIALOG);
	gtk_window_set_skip_taskbar_hint((GtkWindow*)AboutWin, true);
	gtk_window_set_resizable((GtkWindow*)AboutWin, false);
	
	gtk_window_set_title(GTK_WINDOW(AboutWin), "About WZBlue");

	gtk_container_set_border_width(GTK_CONTAINER(AboutWin), 10);
	
	g_signal_connect(G_OBJECT(AboutWin), "destroy", (GCallback)GTK_NukeWidget, NULL);

	GtkWidget *ButtonAlign = gtk_alignment_new(1.0, 1.0, 0.1, 1.0);
	
	GtkWidget *VBox = gtk_vbox_new(FALSE, 5);
	GtkWidget *Image = gtk_image_new_from_pixbuf(GuiInfo.WMIcon_Pixbuf);
	
	gtk_container_add(GTK_CONTAINER(AboutWin), VBox);
	char AboutString[2048];
	
	snprintf(AboutString, sizeof AboutString, "WZBlue Warzone 2100 Lobby Monitor version " WZBLUE_VERSION "\n"
										"Compiled against GTK %d.%d.%d\n\n"
										"By Subsentient. Game status icons by tmp500.", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
	
	GtkWidget *Button = gtk_button_new_from_stock(GTK_STOCK_OK);
	GtkWidget *Label = gtk_label_new(AboutString);
	GtkWidget *LabelAlign = gtk_alignment_new(0.5, 0.5, 0.1, 0.1);
	gtk_container_add((GtkContainer*)LabelAlign, Label);
	
	gtk_container_add(GTK_CONTAINER(ButtonAlign), Button);
	
	gtk_box_pack_start((GtkBox*)VBox, Image, TRUE, TRUE, 5);
	gtk_box_pack_start((GtkBox*)VBox, LabelAlign, TRUE, TRUE, 10);

	gtk_box_pack_start((GtkBox*)VBox, ButtonAlign, TRUE, FALSE, 0);
	
	g_signal_connect_swapped(G_OBJECT(Button), "clicked", (GCallback)GTK_NukeWidget, AboutWin);
	
	gtk_widget_show_all(AboutWin);
}


{'fraction_non_alphanumeric': 0.10767763471626132, 'fraction_numerical': 0.01010968049594659, 'mean_word_length': 6.968085106382978, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5905307', 'n_tokens_mistral': 4257, 'n_tokens_neox': 3925, 'n_words': 732}