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

#define KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_TYPE, KovaplusconfigPollingRateSelectorClass))
#define IS_KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_TYPE))
#define KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_TYPE, KovaplusconfigPollingRateSelectorPrivate))

typedef struct _KovaplusconfigPollingRateSelectorClass KovaplusconfigPollingRateSelectorClass;

struct _KovaplusconfigPollingRateSelector {
	RoccatPollingRateSelector parent;
};

struct _KovaplusconfigPollingRateSelectorClass {
	RoccatPollingRateSelectorClass parent_class;
};

G_DEFINE_TYPE(KovaplusconfigPollingRateSelector, kovaplusconfig_polling_rate_selector, ROCCAT_POLLING_RATE_SELECTOR_TYPE);

GtkWidget *kovaplusconfig_polling_rate_selector_new(void) {
	KovaplusconfigPollingRateSelector *polling_rate_selector;

	polling_rate_selector = KOVAPLUSCONFIG_POLLING_RATE_SELECTOR(g_object_new(KOVAPLUSCONFIG_POLLING_RATE_SELECTOR_TYPE,
			"mask", ROCCAT_POLLING_RATE_SELECTOR_ALL,
			NULL));

	return GTK_WIDGET(polling_rate_selector);
}

static void kovaplusconfig_polling_rate_selector_init(KovaplusconfigPollingRateSelector *polling_rate_selector) {}

static void kovaplusconfig_polling_rate_selector_class_init(KovaplusconfigPollingRateSelectorClass *klass) {}

void kovaplusconfig_polling_rate_selector_set_value(KovaplusconfigPollingRateSelector *polling_rate_selector, guint rmp_value) {
	guint roccat_value;

	switch (rmp_value) {
	case KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_125:
		roccat_value = ROCCAT_POLLING_RATE_SELECTOR_125;
		break;
	case KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_250:
		roccat_value = ROCCAT_POLLING_RATE_SELECTOR_250;
		break;
	case KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_500:
		roccat_value = ROCCAT_POLLING_RATE_SELECTOR_500;
		break;
	case KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_1000:
		roccat_value = ROCCAT_POLLING_RATE_SELECTOR_1000;
		break;
	default:
		roccat_value = ROCCAT_POLLING_RATE_SELECTOR_NONE;
		// TODO warning
		break;
	}

	roccat_polling_rate_selector_set_value(ROCCAT_POLLING_RATE_SELECTOR(polling_rate_selector), roccat_value);
}

guint kovaplusconfig_polling_rate_selector_get_value(KovaplusconfigPollingRateSelector *polling_rate_selector) {
	guint roccat_value;
	guint rmp_value;

	roccat_value = roccat_polling_rate_selector_get_value(ROCCAT_POLLING_RATE_SELECTOR(polling_rate_selector));

	switch (roccat_value) {
	case ROCCAT_POLLING_RATE_SELECTOR_125:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_125;
		break;
	case ROCCAT_POLLING_RATE_SELECTOR_250:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_250;
		break;
	case ROCCAT_POLLING_RATE_SELECTOR_500:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_500;
		break;
	case ROCCAT_POLLING_RATE_SELECTOR_1000:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_1000;
		break;
	case ROCCAT_POLLING_RATE_SELECTOR_NONE:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_1000;
		// TODO warning
		break;
	default:
		rmp_value = KOVAPLUS_PROFILE_SETTINGS_POLLING_RATE_1000;
		// TODO error
		break;
	}

	return rmp_value;
}
