/*
 * 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_macro_editor_interface.h"

enum {
	MODIFIED,
	EMPTY_CHANGED,
	LAST_SIGNAL,
};

static guint signals[LAST_SIGNAL] = { 0 };

gchar const *roccat_macro_editor_interface_name(RoccatMacroEditorInterface *self) {
	return ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->name(self);
}

void roccat_macro_editor_interface_set_keystrokes(RoccatMacroEditorInterface *self, RoccatMacroKeystrokes const *keystrokes) {
	ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->set_keystrokes(self, keystrokes);
}

RoccatMacroKeystrokes *roccat_macro_editor_interface_get_keystrokes(RoccatMacroEditorInterface *self) {
	return ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->get_keystrokes(self);
}

void roccat_macro_editor_interface_clear(RoccatMacroEditorInterface *self) {
	ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->clear(self);
}

gboolean roccat_macro_editor_interface_empty(RoccatMacroEditorInterface *self) {
	return ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->empty(self);
}

void roccat_macro_editor_interface_add_keystroke(RoccatMacroEditorInterface *self, guint key, guint action, glong abs_time, glong rel_time) {
	ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->add_keystroke(self, key, action, abs_time, rel_time);
}

glong roccat_macro_editor_interface_abs_time(RoccatMacroEditorInterface *self) {
	return ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->abs_time(self);
}

gboolean roccat_macro_editor_interface_get_modified(RoccatMacroEditorInterface *self) {
	return ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->get_modified(self);
}

void roccat_macro_editor_interface_set_modified(RoccatMacroEditorInterface *self, gboolean new_state) {
	ROCCAT_MACRO_EDITOR_INTERFACE_GET_INTERFACE(self)->set_modified(self, new_state);
}

void roccat_macro_editor_interface_modified(RoccatMacroEditorInterface *self) {
	g_signal_emit((gpointer)self, signals[MODIFIED], 0);
}

void roccat_macro_editor_interface_empty_changed(RoccatMacroEditorInterface *self) {
	g_signal_emit((gpointer)self, signals[EMPTY_CHANGED], 0);
}

G_DEFINE_INTERFACE(RoccatMacroEditorInterface, roccat_macro_editor_interface, G_TYPE_OBJECT);

static void roccat_macro_editor_interface_default_init(RoccatMacroEditorInterfaceInterface *iface) {
	signals[MODIFIED] = g_signal_new("modified",
			ROCCAT_MACRO_EDITOR_INTERFACE_TYPE,
			G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
			G_STRUCT_OFFSET(RoccatMacroEditorInterfaceInterface, modified),
			NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);

	signals[EMPTY_CHANGED] = g_signal_new("empty-changed",
			ROCCAT_MACRO_EDITOR_INTERFACE_TYPE,
			G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
			G_STRUCT_OFFSET(RoccatMacroEditorInterfaceInterface, empty_changed),
			NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
