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

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

static void cancel_actual(RoccatNotificationCpi *cpi) {
	switch(cpi->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_cpi_osd_cancel(cpi->osd);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_cpi_audio_cancel(cpi->audio);
		break;
	}
}

void roccat_notification_cpi_update(RoccatNotificationCpi *cpi, RoccatNotificationType type, guint number) {
	cpi->type = type;
	switch(cpi->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_cpi_osd_update(cpi->osd, cpi->device_name, number);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_cpi_audio_update(cpi->audio, number);
		break;
	default:
		g_error("Roccat notification: unknown type %i", cpi->type);
	}
}

void roccat_notification_cpi_update_up(RoccatNotificationCpi *cpi, RoccatNotificationType type) {
	cpi->type = type;
	switch(cpi->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_cpi_osd_update_up(cpi->osd, cpi->device_name);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_cpi_audio_update_up(cpi->audio);
		break;
	default:
		g_error("Roccat notification: unknown type %i", cpi->type);
	}
}

void roccat_notification_cpi_update_down(RoccatNotificationCpi *cpi, RoccatNotificationType type) {
	cpi->type = type;
	switch(cpi->type) {
	case ROCCAT_NOTIFICATION_TYPE_OFF:
		break;
	case ROCCAT_NOTIFICATION_TYPE_OSD:
		roccat_notification_cpi_osd_update_down(cpi->osd, cpi->device_name);
		break;
	case ROCCAT_NOTIFICATION_TYPE_AUDIO:
		roccat_notification_cpi_audio_update_down(cpi->audio);
		break;
	default:
		g_error("Roccat notification: unknown type %i", cpi->type);
	}
}

RoccatNotificationCpi *roccat_notification_cpi_new(RoccatNotificator *notificator, gchar const *device_name) {
	RoccatNotificationCpi *cpi;

	cpi = g_malloc0(sizeof(RoccatNotificationCpi));
	cpi->notificator = notificator;
	cpi->osd = roccat_notification_cpi_osd_new(notificator);
	cpi->audio = roccat_notification_cpi_audio_new(notificator);
	cpi->device_name = g_strdup(device_name);

	return cpi;
}

void roccat_notification_cpi_free(RoccatNotificationCpi *cpi) {
	cancel_actual(cpi);
	roccat_notification_cpi_osd_free(cpi->osd);
	roccat_notification_cpi_audio_free(cpi->audio);
	g_free(cpi->device_name);
	g_free(cpi);
}
