/*****************************************************************************/
/*
 *      handlemsg.c -- Messages displaying management
 *
 *      Copyright (C) 2001-2002 Sigma Designs
 *                    written by Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      This program 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.
 *
 *      This program 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 this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include "define.h"
#include "gtk_callbacks.h"

gchar * msg_strings[] =
{
  "Error - UNAUTHORIZED command",
  "Play",
  "Paused",
  "Stopped",
  "Tray is open",
  "Closed !",
  "Rewind @",
  "Forward @",
  "Previous",
  "Next",
  "Step Forward",
  "Step Rewind",
  "Reverse Play",
  "Skip",
  "Loading ..."
};

DWORD displayMsg(int msgdest, int msgstrid, gchar *addon_str)
{
  DWORD msgid = 0;  
  
  
  switch(msgdest)
    {
    case MSG_OSD_ONLY:
      if(addon_str == NULL)
	displayBitmapWithText(pictArr[msgstrid], NULL, 0, 2);
      else
	displayText(addon_str, 2);
      break;
    case MSG_STATUS_ONLY:
      msgid = (DWORD) push_msg_statusbar(addon_str);
      break;
    default:
      {
	gchar *msg = NULL;
	int indent_val = 0;
	
	msg = g_strconcat(msg_strings[msgstrid] , addon_str, NULL);
	msgid = (DWORD) push_msg_statusbar((gchar*)msg);
	
	if(msgstrid == MSG_FR)
	  indent_val = FF_SLOW_RIGHT_INDENT;
	else if(msgstrid == MSG_FF)
	  indent_val = FF_SLOW_LEFT_INDENT;
	
	displayBitmapWithText(pictArr[msgstrid], addon_str, indent_val, 2);
	g_free(msg);
      }
      break;
    }
  
  return msgid;
}

DWORD displayRepeatModeMsg(char *msg)
{
  gtk_statusbar_pop( GTK_STATUSBAR(GUI.repeat_statusbar),GUI.repeat_context_id);
  return (gtk_statusbar_push( GTK_STATUSBAR(GUI.repeat_statusbar), GUI.repeat_context_id, (gchar*)msg));
}

DWORD lockedDisplayMsg(char *msg)
{
 DWORD msgid;
 gdk_threads_enter();
 msgid = (DWORD)push_msg_statusbar((gchar*)msg);
 gdk_threads_leave();
 
 return msgid;
}

guint push_msg_statusbar(gchar *msg)
{
  gtk_statusbar_pop( GTK_STATUSBAR(GUI.statusbar),GUI.context_id);
  return (gtk_statusbar_push( GTK_STATUSBAR(GUI.statusbar), GUI.context_id, msg));  
}

void pop_msg_statusbar(gboolean last_one,guint msg_id)
{
  if(last_one)
    gtk_statusbar_pop( GTK_STATUSBAR(GUI.statusbar),GUI.context_id);
  else
    gtk_statusbar_remove( GTK_STATUSBAR(GUI.statusbar), GUI.context_id, msg_id);
}
