/***************************************************************************
 *   Copyright (C) 2006 by Jens Koehler                                    *
 *   irimi_at_gmx_de                                                       *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <string>
#include "menuAmarokSetup.h"



AmarokConfig::AmarokConfig() :
        p_HostID("AmarokGWHost"),
        p_PortID("AmarokGWPort"),
        p_UserID("AmarokGWUser"),
        p_PwID("AmarokGWPasswd"),
        p_ConfigDir(0),
        m_AmarokPort(8173)
{
    strncpy(m_AmarokHost, "localhost", MY_MAX_CHAR_LEN);
    strncpy(m_AmarokUser, "amarok", MY_MAX_CHAR_LEN);
    strncpy(m_AmarokPw, "secret", MY_MAX_CHAR_LEN);
}

AmarokConfig::~AmarokConfig()
{
  delete [] p_ConfigDir;
  p_ConfigDir=0;
}

bool AmarokConfig::SetupParse( const char * Name, const char * Value )
{

    if(strcmp(Name, p_HostID ) == 0)
        snprintf(m_AmarokHost, sizeof(m_AmarokHost), Value);
    else if (strcmp(Name, p_PortID )    == 0)
        m_AmarokPort=strtol(Value,NULL,10);
    else if(strcmp(Name, p_UserID ) == 0)
        snprintf(m_AmarokUser, sizeof(m_AmarokUser), Value);
    else if(strcmp(Name, p_PwID ) == 0)
        snprintf(m_AmarokPw, sizeof(m_AmarokPw), Value);
    else
        return false;


    return true;
}

//////////////////////////////////////////////////////////////////
////// cMenuAmarokSetup
//////////////////////////////////////////////////////////////////

cMenuAmarokSetup::cMenuAmarokSetup():cMenuSetupPage(),
        p_allowedChar(" .,:;+-*~?!\"$%&/\()=?`')_abcdefghijklmnopqrstuvwxyz0123456789")
{

    Add(new cMenuEditStrItem(tr(g_amarokConfig.p_HostID),
                             g_amarokConfig.m_AmarokHost,
                             sizeof(g_amarokConfig.m_AmarokHost),
                             p_allowedChar));

    Add(new cMenuEditIntItem( tr(g_amarokConfig.p_PortID),&g_amarokConfig.m_AmarokPort));

    Add(new cMenuEditStrItem(tr(g_amarokConfig.p_UserID),
                             g_amarokConfig.m_AmarokUser,
                             sizeof(g_amarokConfig.m_AmarokUser),
                             p_allowedChar));

    Add(new cMenuEditStrItem(tr(g_amarokConfig.p_PwID),
                             g_amarokConfig.m_AmarokPw,
                             sizeof(g_amarokConfig.m_AmarokPw),
                             p_allowedChar));

}


cMenuAmarokSetup::~cMenuAmarokSetup()
{}

void cMenuAmarokSetup::Store(void)
{

    SetupStore(g_amarokConfig.p_HostID,  g_amarokConfig.m_AmarokHost);
    SetupStore(g_amarokConfig.p_PortID,   g_amarokConfig.m_AmarokPort);
    SetupStore(g_amarokConfig.p_UserID,   g_amarokConfig.m_AmarokUser);
    SetupStore(g_amarokConfig.p_PwID, g_amarokConfig.m_AmarokPw);

}

#undef MY_MAX_CHAR_LEN

