/*
 * setup.c: Plugin-Einstellunen
 *
 * $Id: vdricqsetup.c,v 1.7 2005/04/10 21:56:52 jurij Exp $
 */

#include <vdr/menuitems.h>
#include "vdricqsetup.h"
#include "i18n.h"
#include "icqhook.h"


// --- cVdrIcqSetup -----------------------------------------------------------

cVdrIcqSetup VdrIcqSetup;

cVdrIcqSetup::cVdrIcqSetup() 
{
  OriginX  = 50;
  OriginY  = 50;
  IcqUIN   = 0;
  memset(IcqPassword, 0, MAX_ICQPASSWORDLEN + 1);
  StatusOnVDRStartup  = 6;
  StatusOnCloseVdrICQ = 6;
  TextInputmode       = 0;
}

bool cVdrIcqSetup::SetupParse(const char *Name, const char *Value) 
{
  if      (strcmp(Name, "Origin_X")                == 0)  OriginX  = atoi(Value);
  else if (strcmp(Name, "Origin_Y")                == 0)  OriginY  = atoi(Value);
  else if (strcmp(Name, "Status_on_VDR_Startup")   == 0)  StatusOnVDRStartup  = atoi(Value);
  else if (strcmp(Name, "Status_if_VDRICQ_closed") == 0)  StatusOnCloseVdrICQ = atoi(Value);
  else if (strcmp(Name, "Status_if_VDRICQ_opened") == 0)  StatusOnOpenVdrICQ  = atoi(Value);
  else if (strcmp(Name, "TextInputmode")           == 0)  TextInputmode  = atoi(Value);
  else if (strcmp(Name, "ICQ_UIN")                 == 0)  IcqUIN   = atoi(Value);
  else if (strcmp(Name, "ICQ_Password")            == 0)  strn0cpy(IcqPassword, Value, MAX_ICQPASSWORDLEN + 1);
  else return false;
  return true;
}



// --- cMenuSetupVdrIcq -------------------------------------------------------

cMenuSetupVdrIcq::cMenuSetupVdrIcq(SimpleClient *pIcqClient)
{
  m_pIcqClient = pIcqClient;

  static const char allowed[] = { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" };
 
  statuslist[0] = "Online";
  statuslist[1] = "Away";
  statuslist[2] = "NA";
  statuslist[3] = "Occupied";
  statuslist[4] = "DND";
  statuslist[5] = "Free For Chat";
  statuslist[6] = "Offline";
  statuslist[7] = "Invisible";
  statuslist[8] = "no change"; 

  textinputmodelist[0] = "beginner";
  textinputmodelist[1] = "advanced one";

  newOriginX  = VdrIcqSetup.OriginX;
  newOriginY  = VdrIcqSetup.OriginY;
  newIcqUIN   = VdrIcqSetup.IcqUIN;
  strn0cpy(newIcqPassword, VdrIcqSetup.IcqPassword, MAX_ICQPASSWORDLEN + 1);
  newStatusOnVDRStartup   = VdrIcqSetup.StatusOnVDRStartup;
  newStatusOnOpenVdrICQ   = VdrIcqSetup.StatusOnOpenVdrICQ;
  newStatusOnCloseVdrICQ  = VdrIcqSetup.StatusOnCloseVdrICQ;
  newTextInputmode        = VdrIcqSetup.TextInputmode;
  Add(new cMenuEditIntItem(  tr("Origin X"),                  &newOriginX, 0,   300));
  Add(new cMenuEditIntItem(  tr("Origin Y"),                  &newOriginY, 0,   300));
  Add(new cMenuEditStraItem( tr("Status on VDR Startup"),     &newStatusOnVDRStartup,  8, statuslist));
  Add(new cMenuEditStraItem( tr("Status if VDRICQ opened"),   &newStatusOnOpenVdrICQ,  9, statuslist));
  Add(new cMenuEditStraItem( tr("Status if VDRICQ closed"),   &newStatusOnCloseVdrICQ, 9, statuslist));
  Add(new cMenuEditStraItem( tr("Input mode for the text"),   &newTextInputmode,       2, textinputmodelist));
  Add(new cMenuEditIntItem(  tr("ICQ UIN"),                   &newIcqUIN, 10000, 2147483646));
  Add(new cMenuEditStrItem(  tr("ICQ Password"),              newIcqPassword, MAX_ICQPASSWORDLEN + 1, allowed));
}

void cMenuSetupVdrIcq::Store(void)
{
  SetupStore("Origin_X",                  VdrIcqSetup.OriginX             = newOriginX);
  SetupStore("Origin_Y",                  VdrIcqSetup.OriginY             = newOriginY);
  SetupStore("Status_on_VDR_Startup",     VdrIcqSetup.StatusOnVDRStartup  = newStatusOnVDRStartup);
  SetupStore("Status_if_VDRICQ_opened",   VdrIcqSetup.StatusOnOpenVdrICQ  = newStatusOnOpenVdrICQ);
  SetupStore("Status_if_VDRICQ_closed",   VdrIcqSetup.StatusOnCloseVdrICQ = newStatusOnCloseVdrICQ);
  SetupStore("TextInputmode",             VdrIcqSetup.TextInputmode       = newTextInputmode);
  SetupStore("ICQ_UIN",                   VdrIcqSetup.IcqUIN              = newIcqUIN);
  strn0cpy(VdrIcqSetup.IcqPassword, newIcqPassword, MAX_ICQPASSWORDLEN + 1);
  SetupStore("ICQ_Password",              VdrIcqSetup.IcqPassword);

  m_pIcqClient->SetConnectParameters(VdrIcqSetup.IcqUIN, VdrIcqSetup.IcqPassword);
}

