/*
 * facts-base.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: facts-base.c,v 1.6 2004/11/26 21:18:53 peter Exp $
 */

 
/*

File	: facts-base.c
Autor	: Peter Juszack

Description
-----------------------------------------------------------------
base class for file/ directory menu

- Defines Actions ( copy, delete, choose copy destination, back )
- does the key processing and calls abstract member functions
- defines functions to create descriptive tab seperated menu items for image data ( e.g. "Filename:\tDSC0001.JPG" )
- static member and setter for the copy destination path ( is set from cMenuDestinationBrowse )

*/

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

#include <gphoto2/gphoto2.h>

#include "facts-base.h"
#include "digicam.h"
#include "menu-destbrowse.h"

char cFactsheetBase::copyDestination[FACTSHEET_BUFLEN] = { 0 };

cFactsheetBase::cFactsheetBase(const char* title, cDirItem *file):cOsdMenu(title, 15) {
    fileItem = file;
}

void cFactsheetBase::addAttribute( const char* name, const char* value ) {
	// fill output string with file info result
	snprintf( buf, FACTSHEET_BUFLEN, "%s:\t%s", name, value ); 

	cOsdItem *item = new cOsdItem(buf);
#if VDRVERSNUM > 10306
	item->SetSelectable(false);
#endif
	Add(item);
}

void cFactsheetBase::addAttribute( const char* name, double value, const char* suffix) {
	// fill output string with file info result
	snprintf( buf, FACTSHEET_BUFLEN, "%s:\t%.2lf %s", name, value, suffix ); 

	cOsdItem *item = new cOsdItem(buf);
#if VDRVERSNUM > 10306
	item->SetSelectable(false);
#endif		
	Add(item);
}

void cFactsheetBase::addAttribute( const char* name, int value, const char* suffix) {
	// fill output string with file info result
	snprintf( buf, FACTSHEET_BUFLEN, "%s:\t%d %s", name, value, suffix ); 

	cOsdItem *item = new cOsdItem(buf);
#if VDRVERSNUM > 10306
	item->SetSelectable(false);
#endif		
	Add(item);
}


void cFactsheetBase::SetButtons(void) {
    /* 4 actions for the menu
    
    - copy image(s) to disc
    - Delete image(s) on camera
    - go back to browsing menu
    */
    
    SetHelp( tr("Copy"), 0, tr("Delete"), tr("Cancel") );
    Display();
}


// Process key or "button" event
eOSState cFactsheetBase::ProcessKey(eKeys Key) {
    // pass event to base class
    eOSState state = cOsdMenu::ProcessKey(Key);
    
    if (state == osUnknown && digitalCamera.getErrNo() == DIGICAM_NO_ERROR) {
	switch(Key) {	// validate key
	    case kRed:	// Copy file to disc
		state = SaveToDisc();
	    break;
	    case kBlue:	// Go back to browsing
		state = osBack;
	    break;
	    case kYellow: // call delete method
	    	state = DeleteFromCamera();
	    break;	    
	    // Ignore all other keys
	    default: state = osContinue;
	}
    }
    
    return state;
}

void cFactsheetBase::setCopyDestination( const char* dest ) {
    snprintf( (char*) copyDestination, FACTSHEET_BUFLEN, "%s", dest );    
}

const char* cFactsheetBase::getCopyDestination(void) {
#ifdef DEBUG
    printf("getCopyDestination() |%s|\n", copyDestination);
#endif

    if (copyDestination[0] == 0)
	setCopyDestination( CopyDestinations.GetSource()->BaseDir() );

    return (const char*) copyDestination;
}

