/*
 * mousemate plugin for VDR
 *
 * MouseMate.c - MouseMate context monitor class
 *
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 */

#include "MouseMateMonitor.h"
#include "MouseMate.h"

cMouseMateMonitor:: cMouseMateMonitor(void)
:menu(false),
replay(false),
DVD(false),
MP3(false),
CDDA(false),
IMAGE(false)
{
}


cMouseMateMonitor:: ~cMouseMateMonitor()
{
}


int cMouseMateMonitor::GetContext(const bool toggle)
{
    if (!toggle)
    {
        if (menu)
        {
            #ifdef DEBUG
            fprintf(stderr,"mousemate: Context=Menu DVD=%i MP3=%i CDDA=%i IMAGE=%i\n",DVD,MP3,CDDA,IMAGE);
            #endif
            return kContextMenu;
        }
        if (replay)
        {
            #ifdef DEBUG
            fprintf(stderr,"mousemate: Context=Replay DVD=%i MP3=%i CDDA=%i IMAGE=%i\n", DVD,MP3,CDDA,IMAGE);
            #endif
            if (DVD)
                return kContextReplayDVD;
            if (MP3)
                return kContextReplayMP3;
            if (CDDA)
                return kContextReplayCDDA;
            if (IMAGE)
                return kContextReplayIMAGE;

            return kContextReplay;
        }
        #ifdef DEBUG
        fprintf(stderr,"mousemate: Context=Normal DVD=%i MP3=%i CDDA=%i IMAGE=%i\n",DVD, MP3,CDDA, IMAGE);
        #endif
        return kContextNormal;
    }
    else
    {
        if (menu)
        {
            #ifdef DEBUG
            fprintf(stderr,"mousemate: Context=MenuAlt DVD=%i MP3=%i CDDA=%i IMAGE=%i\n",DVD,MP3,CDDA,IMAGE);
            #endif
            return kContextMenuAlt;
        }
        if (replay)
        {
            #ifdef DEBUG
            fprintf(stderr,"mousemate: Context=ReplayAlt DVD=%i MP3=%i CDDA=%i IMAGE=%i\n", DVD,MP3,CDDA,IMAGE);
            #endif
            if (DVD)
                return kContextReplayDVDAlt;
            if (MP3)
                return kContextReplayMP3Alt;
            if (CDDA)
                return kContextReplayCDDAAlt;
            if (IMAGE)
                return kContextReplayIMAGEAlt;
            return kContextReplayAlt;
        }
        #ifdef DEBUG
        fprintf(stderr,"mousemate: Context=NormalAlt DVD=%i MP3=%i CDDA=%i IMAGE=%i\n",DVD, MP3,CDDA, IMAGE);
        #endif
        return kContextNormalAlt;
    }

}


void cMouseMateMonitor::Replaying(const cControl *Control, const char *Name, const char *FileName, bool On)
{
    if (On)
    {
        replay=true;
        if (!strcmp(Name,"DVD"))
            DVD=true;
        if (!strcmp(Name,"MP3"))
            MP3=true;
        if (!strcmp(Name,"cdda"))
            CDDA=true;
        if (!strcmp(Name,"image"))
            IMAGE=true;
    }
    else
    {
        DVD=false;
        MP3=false;
        CDDA=false;
        IMAGE=false;
        replay=false;
    }
    #ifdef DEBUG
    fprintf(stderr,"mousemate: %s is %i\n", Name, On);
    fprintf(stderr,"mousemate: Replaying DVD %i MP3: %i CDDA: %i IMAGE: %i\n",DVD, MP3,CDDA, IMAGE);
    #endif
}


void cMouseMateMonitor::OsdClear(void)
{
    menu =false;
}


void cMouseMateMonitor::OsdTitle(const char *Title)
{
    menu = true;
}


void cMouseMateMonitor::OsdHelpKeys(const char *Red, const char *Green, const char *Yellow, const char *Blue)
{
    menu = true;
}


void cMouseMateMonitor::OsdItem(const char *Text, int Index)
{
    menu = true;
}


void cMouseMateMonitor::OsdCurrentItem(const char *Text)
{
    menu = true;
}


void cMouseMateMonitor::OsdTextItem(const char *Text, bool Scroll)
{
    menu = true;
}
