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

struct _RoccatNotificationSensitivity {
	RoccatNotificator *notificator;
	gpointer audio;
	gpointer osd;
	gchar *device_name;
	RoccatNotificationType type;
};

static void cancel_actual(RoccatNotificationSensitivity *sensitivity) {
	switch(sensitivity->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_sensitivity_osd_cancel(sensitivity->osd);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_sensitivity_audio_cancel(sensitivity->audio);
		break;
	}
}

void roccat_notification_sensitivity_update(RoccatNotificationSensitivity *sensitivity, RoccatNotificationType type, guint x, guint y) {
	sensitivity->type = type;
	switch(sensitivity->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_sensitivity_osd_update(sensitivity->osd, sensitivity->device_name, x, y);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_sensitivity_audio_update(sensitivity->audio, x, y);
		break;
	default:
		g_error("Roccat notification: unknown type %i", sensitivity->type);
	}
}

void roccat_notification_sensitivity_update_up(RoccatNotificationSensitivity *sensitivity, RoccatNotificationType type) {
	sensitivity->type = type;
	switch(sensitivity->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_sensitivity_osd_update_up(sensitivity->osd, sensitivity->device_name);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_sensitivity_audio_update_up(sensitivity->audio);
		break;
	default:
		g_error("Roccat notification: unknown type %i", sensitivity->type);
	}
}

void roccat_notification_sensitivity_update_down(RoccatNotificationSensitivity *sensitivity, RoccatNotificationType type) {
	sensitivity->type = type;
	switch(sensitivity->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_sensitivity_osd_update_down(sensitivity->osd, sensitivity->device_name);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_sensitivity_audio_update_down(sensitivity->audio);
		break;
	default:
		g_error("Roccat notification: unknown type %i", sensitivity->type);
	}
}

RoccatNotificationSensitivity *roccat_notification_sensitivity_new(RoccatNotificator *notificator, gchar const *device_name) {
	RoccatNotificationSensitivity *sensitivity;

	sensitivity = g_malloc0(sizeof(RoccatNotificationSensitivity));
	sensitivity->notificator = notificator;
	sensitivity->osd = roccat_notification_sensitivity_osd_new(notificator);
	sensitivity->audio = roccat_notification_sensitivity_audio_new(notificator);
	sensitivity->device_name = g_strdup(device_name);

	return sensitivity;
}

void roccat_notification_sensitivity_free(RoccatNotificationSensitivity *sensitivity) {
	cancel_actual(sensitivity);
	roccat_notification_sensitivity_osd_free(sensitivity->osd);
	roccat_notification_sensitivity_audio_free(sensitivity->audio);
	g_free(sensitivity->device_name);
	g_free(sensitivity);
}
