/*
 * This file is part of roccat-tools.
 *
 * roccat-tools 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.
 *
 * roccat-tools 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 roccat-tools. If not, see <http://www.gnu.org/licenses/>.
 */

#include "roccat_device_reset_frame.h"

#define ROCCAT_DEVICE_RESET_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), ROCCAT_DEVICE_RESET_FRAME_TYPE, RoccatDeviceResetFrameClass))
#define IS_ROCCAT_DEVICE_RESET_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ROCCAT_DEVICE_RESET_FRAME_TYPE))
#define ROCCAT_DEVICE_RESET_FRAME_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ROCCAT_DEVICE_RESET_FRAME_TYPE, RoccatDeviceResetFramePrivate))

struct _RoccatDeviceResetFramePrivate {
	GtkButton *button;
};

G_DEFINE_TYPE(RoccatDeviceResetFrame, roccat_device_reset_frame, GTK_TYPE_FRAME);

enum {
	CLICKED,
	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

GtkWidget *roccat_device_reset_frame_new(void) {
	RoccatDeviceResetFrame *frame;

	frame = g_object_new(ROCCAT_DEVICE_RESET_FRAME_TYPE, NULL);

	return GTK_WIDGET(frame);
}

static void button_clicked_cb(GtkButton *button, gpointer user_data) {
	RoccatDeviceResetFrame *frame = ROCCAT_DEVICE_RESET_FRAME(user_data);
	g_signal_emit((gpointer)frame, signals[CLICKED], 0);
}

static void roccat_device_reset_frame_init(RoccatDeviceResetFrame *frame) {
	RoccatDeviceResetFramePrivate *priv = ROCCAT_DEVICE_RESET_FRAME_GET_PRIVATE(frame);
	GtkWidget *content;

	frame->priv = priv;

	content = gtk_hbox_new(FALSE, 0);
	priv->button = GTK_BUTTON(gtk_button_new_with_label("Reset"));

	g_signal_connect(G_OBJECT(priv->button), "clicked", G_CALLBACK(button_clicked_cb), frame);

	gtk_container_add(GTK_CONTAINER(frame), content);
	gtk_box_pack_start(GTK_BOX(content), GTK_WIDGET(priv->button), TRUE, TRUE, 0);

	gtk_frame_set_label(GTK_FRAME(frame), "Device reset");

	gtk_widget_show_all(content);
}

static void roccat_device_reset_frame_class_init(RoccatDeviceResetFrameClass *klass) {
	g_type_class_add_private(klass, sizeof(RoccatDeviceResetFramePrivate));

	signals[CLICKED] = g_signal_new("clicked",
			G_TYPE_FROM_CLASS(klass),
			G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
			G_STRUCT_OFFSET(RoccatDeviceResetFrameClass, clicked),
			NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
