/*
 * digicam.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 *
 * based on image plugin
 *   
 * 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: digicam.c,v 1.13 2005/02/01 09:52:52 peter Exp $
 */

 
/*

File	: digicam.c
Autor	: Peter Juszack

Description
-----------------------------------------------------------------
Main file of the digicam plugin
*/
#include <vdr/plugin.h>
#include <vdr/interface.h>

#include "menu-camera.h"
#include "download-status.h"
#include "digitalcamera.h"
#include "digicam.h"
#include "data.h"
#include "facts-base.h"
#include "i18n.h"
#include "digicam-setup.h"

DigitalCamera digitalCamera;
cFileSources CameraSources;
cFileSources CopyDestinations;

cDirectoryLoader *directoryLoader = NULL;

static const char *VERSION        = "1.0.2";
static const char *DESCRIPTION    = "Plugin to access a digital camera";
static const char *MAINMENUENTRY  = "Digicam";

class cPluginDigicam : public cPlugin {
private:
  
public:
  cPluginDigicam(void);
  virtual ~cPluginDigicam();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return tr(DESCRIPTION); }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Initialize(void);
  virtual bool Start(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);  
  };

cPluginDigicam::cPluginDigicam(void)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!  

  directoryLoader = NULL;
}

cPluginDigicam::~cPluginDigicam()
{
#ifdef DEBUG
  printf("cPluginsDigicam:~cPluginDigicam\n");
#endif
  // Clean up after yourself!
  if (directoryLoader != NULL) {
  	directoryLoader->Stop();
	
	delete directoryLoader;
  	directoryLoader = NULL;
  }	
#ifdef DEBUG
  printf("cPluginsDigicam:~cPluginDigicam OK\n");
#endif
}

const char *cPluginDigicam::CommandLineHelp(void)
{
  // Return a string that describes all known command line options.
  return NULL;
}

bool cPluginDigicam::ProcessArgs(int argc, char *argv[])
{
  // Implement command line argument processing here if applicable.
  return true;
}

bool cPluginDigicam::Initialize(void)
{
  // Initialize any background activities the plugin shall perform.
  return true;
}

bool cPluginDigicam::Start(void)
{  
  // Load camera default directories from digicamsources.conf
  CameraSources.Load( AddDirectory(ConfigDirectory(), "digicamsources.conf" ));
  
  // Load copy destinations
  CopyDestinations.Load( AddDirectory(ConfigDirectory(), "digicamdestinations.conf" ));

  // Check if at least one source was found
  if (CameraSources.Count() < 1) {
    fprintf( stderr, "vdr: you must have defined at least one source in digicamsources.conf\n");
    return false; // cause vdr to exit
  }

  // Check if at least one destination source was found
  if (CopyDestinations.Count() < 1) {
    fprintf( stderr, "vdr: you must have defined at least one copy destination in digicamdestinations.conf\n");
    return false; // cause vdr to exit
  }

  RegisterI18n(Phrases);

  /*
  cSkinDisplayMenu *menu = Skins.Current()->DisplayMenu();
  
  if (menu != NULL) {
      menu->SetTitle("Benutzerauswahl");
      menu->SetItem("Peter", 1, true, true);
      menu->SetItem("Sabrina", 2, false, true);
      menu->SetItem("Gast", 3, false, true);
      menu->Flush();
      
      sleep(5);
      eKeys key = kNone;
      
      while (key != kOk) {
          eKeys key = Interface->GetKey(true);
	  
	  usleep(1000);
      }
      
      menu->Clear();
      delete menu;
  }*/
  
  return true;
}

void cPluginDigicam::Housekeeping(void)
{
  // Perform any cleanup or other regular tasks.

}

cOsdObject *cPluginDigicam::MainMenuAction(void)
{
    digitalCamera.bind();
    
    // Check if a copy thread is running
    if ( directoryLoader == NULL || !directoryLoader->Active() )
    	// no thread running => show browser
    	return new cMenuCamera();
    else // Display menu for download status and cancelling download 
    	return new cDownloadStatusMenu();	
}

cMenuSetupPage *cPluginDigicam::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return new cMenuSetupDigicam();
}

bool cPluginDigicam::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  return DigicamSetup.SetupParse(Name, Value);
}

VDRPLUGINCREATOR(cPluginDigicam); // Don't touch this!
