/*
 * download-status.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *   
 * This code 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 code 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.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 * $Id: download-status.c,v 1.6 2005/02/01 09:24:52 peter Exp $
 */

 
/*

File	: download-status.c
Autor	: Peter Juszack

Description
-----------------------------------------------------------------
OSD menu to view download status
*/


#include <vdr/status.h>
#include <vdr/menuitems.h>

// wrapper for libgphoto2
#include "digitalcamera.h"
#include "download-status.h"
// globals
#include "digicam.h"
#include "i18n.h"

#if VDRVERSNUM < 10307
cDownloadStatusMenu::cDownloadStatusMenu():cOsdMenu( tr("Download status") ) {
#else
cDownloadStatusMenu::cDownloadStatusMenu():cMenuText( tr("Download status"), "") {
#endif

    const char* message = tr("Digicam is loading data from your camera.");
// display camera info in scrollable box			
#if VDRVERSNUM < 10307
	Add( new cMenuTextItem( message, 1, 1, Setup.OSDwidth ));
#else	
	SetText( message );
#endif    
    SetButtons();
    Display();
    
    // display status message        
    DisplayStatus();
}

void cDownloadStatusMenu::DisplayStatus() {
    if (directoryLoader!=NULL) {
	const char* msg = directoryLoader->GetMessage();
	
	if ( msg[0] > 0) {
	    OSD_StatusMsg( msg );
	}
    }
}

void cDownloadStatusMenu::SetButtons() {
    SetHelp( tr("Cancel"),0,0, tr("Close") );
}

eOSState cDownloadStatusMenu::ProcessKey(eKeys Key) {

#if VDRVERSNUM < 10307
    eOSState state = cOsdMenu::ProcessKey(Key);
#else
    eOSState state = cMenuText::ProcessKey(Key);
#endif

    // display status message        
    DisplayStatus();
    
    if (state != osUnknown && state != osContinue) {
	return state;
    }

    switch(Key) {
	case kBlue: 
	    state = osBack;
	    break;
	case kRed:
	    OSD_StatusMsg( tr("Canceling download...") );
	    if (directoryLoader != NULL)
	    	directoryLoader->Stop();
	    
	    state = osContinue;
	    break;
	default:
	    state = osContinue;
	    break;
    }
    
    return state;
}
