/*
 * cameralist.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *   
 * based on the 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: cameralist.c,v 1.3 2004/11/13 06:05:40 peter Exp $
 */

 
/*

File	: cameralist.c
Autor	: Peter Juszack

Description
-----------------------------------------------------------------
Fetches file lists from a camera
*/

#include <gphoto2/gphoto2.h>

#include "data.h"
#include "cameralist.h"
#include "digitalcamera.h"
#include "digicam.h"

// Overwrite base class function to scan for files and directories on the camera
bool cCameraList::ScanDir( cFileSource *src, const char *subdir, eScanType type,
    const char *spec, const char *excl, bool recursiv ) {

    // check pre processor option to disable real scan and produce sample entries 
#ifndef SAMPLE_DIRS
    // libgphoto2 struct for folder/file list
    CameraList result;
    
    if (!digitalCamera.isAvailable())
	return true;

    // set working directory for camera
    digitalCamera.setDirectory( src->BaseDir(), subdir );
    
    // what scan type ?
    switch (type) {
	case stDir: // Scan for directories
	    digitalCamera.getFolderList( &result );
	break;	
	case stFile: // Scan for files
	    digitalCamera.getFileList( &result );
	break;	
	
    }

    // Display item for each result entry    
    for (int i=0; i<result.count; i++) {
	DoItem(src, subdir, result.entry[i].name );
    }

#else
    // Produce test entries

    // what scan type ?
    switch (type) {
	case stDir: // Scan for directories
	    DoItem(src, subdir, "DCIM" );
	    DoItem(src, subdir, "OTHERS" );
	break;	
	case stFile: // Scan for files
	    DoItem(src, subdir, "file1.jpg" );
	    DoItem(src, subdir, "file2.jpg" );
	break;		
    }
#endif
    
    return true;
}
