/*
 * 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/roccat.h"
#include "roccat_macro_keystrokes.h"

void roccat_macro_set_macro_set_name(RoccatMacro *macro, gchar const *new_name) {
	g_free(macro->macro_set);
	macro->macro_set = g_strdup(new_name);
}

void roccat_macro_set_macro_name(RoccatMacro *macro, gchar const *new_name) {
	g_free(macro->macro);
	macro->macro = g_strdup(new_name);
}

gchar *roccat_macro_get_name_joined(RoccatMacro const *macro) {
	return g_strjoin("/", macro->macro_set, macro->macro, NULL);
}

RoccatMacroKeystrokes *roccat_macro_get_keystrokes(RoccatMacro *macro) {
	return &macro->keystrokes;
}

gboolean roccat_macro_add_keystroke(RoccatMacro *macro, RoccatMacroKeystroke const *keystroke) {
	return roccat_macro_keystrokes_add(&macro->keystrokes, keystroke);
}

RoccatMacro *roccat_macro_dup(RoccatMacro const *roccat_macro) {
	return roccat_macro_new(roccat_macro->macro_set, roccat_macro->macro, &roccat_macro->keystrokes);
}

RoccatMacro *roccat_macro_new(gchar const *macro_set_name, gchar const *macro_name, RoccatMacroKeystrokes const *keystrokes) {
	RoccatMacro *macro;
	macro = g_malloc0(sizeof(RoccatMacro));
	roccat_macro_set_macro_set_name(macro, macro_set_name);
	roccat_macro_set_macro_name(macro, macro_name);

	if (keystrokes)
		roccat_macro_keystrokes_copy(keystrokes, &macro->keystrokes);
	else
		roccat_macro_keystrokes_init(&macro->keystrokes);

	return macro;
}

void roccat_macro_free(RoccatMacro *macro) {
	if (macro == NULL)
		return;
	g_free(macro->macro_set);
	g_free(macro->macro);
	g_free(macro);
}

gboolean roccat_macro_has_mouse_keystroke(RoccatMacro const *roccat_macro) {
	return roccat_macro_keystrokes_have_mouse_keystroke(&roccat_macro->keystrokes);
}
