/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Glade / Gtk Programming
#+
#+     Copyright (C) 2019 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     http://threadsafebooks.com/
#+
#+ This program 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 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program 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 this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

// May 14, 2019

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <gtk/gtk.h>
#include <sys/ipc.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <gtk/gtkx.h>
#include <time.h>
#include <ctype.h>

GtkWidget	*window;
GtkWidget	*fixed1;
GtkWidget	*draw2;
GtkBuilder	*builder; 

char		bg_color[256] = "blue";

#include "meter.h"

int main(int argc, char *argv[]) {

	gtk_init(&argc, &argv); // init Gtk

//-----------------------
//	GTK interface
//-----------------------

	builder = gtk_builder_new_from_resource ("/part1/part1.glade");
 
	window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));

	g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), NULL);

        gtk_builder_connect_signals(builder, NULL);

	fixed1		= GTK_WIDGET(gtk_builder_get_object(builder, "fixed1"));
	draw2		= GTK_WIDGET(gtk_builder_get_object(builder, "draw2"));

	g_object_unref(builder);

	gtk_widget_show(window);

        GdkColor color; // default background color

	if (!gdk_color_parse (bg_color, &color)) { // does color parse?
        	color.blue = 0x0000; color.red = 0x0000; color.green = 0x0000;
		}

        gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &color); // set background color

	gtk_window_set_title(GTK_WINDOW(window), "Meter 1.00");

	gtk_window_set_resizable (GTK_WINDOW(window), TRUE);

	gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);

//----------------------------------------------------------------
//	Timer will trigger once per second (1000 milliseconds).
//	Timer function will collect data on system load and
//	queue an update draw to the meter.
//----------------------------------------------------------------

        g_timeout_add(1000, (GSourceFunc) timer_handler, NULL); 

	gtk_main();

	return EXIT_SUCCESS;
	}
