/******************************************************************************
 * Steve Rider - stever@transmission23.com
 * QuickPics
 *   Image galleries for the web made easy
 *
 * dir.h - directory structures and routines for storing image information
 *
 *****************************************************************************/
/* 17 February 98 */

#ifndef QPDIR_H
#define QPDIR_H

#include "qp.h"

/* Let all files who need QPDir have access to the QPDir object */
extern struct QPDir_object QPDir;



/*****************************************************************************/
/* object QPDir declaration */
typedef struct QPDir_object {
	dirrec	*dirs;			/* -> the list of dirs */
	dirrec	*last;			/* -> the last dir */

	int	num_dirs;		/* how many we have */

	char	title[MAXTEXTLEN];
	char	heading[MAXTEXTLEN];

	int	dir_count;
	int	img_count;

	u_long	flags;			/* flags */

} QPDir_ob;


/* object QPDir low-level function declarations. */
void	QPDir_Init();
void	QPDir_AppendDir(dirrec *dir);
void	QPDir_DeleteDir(dirrec *dir);
void	QPDir_AppendSubDir(dirrec *dir, dirrec *subdir);
void	QPDir_DeleteSubDir(dirrec *dir, dirrec *subdir);
void	QPDir_AppendImage(dirrec *dir, imgrec *img);
void	QPDir_DeleteImage(dirrec *dir, imgrec *img);

/* object QPDir high-level implementation-specific function declarations. */
u_long	QPDir_AvgBytes(dirrec *dir);
dirrec	*QPDir_AddNewDir(const char *name);
imgrec	*QPDir_AddNewImage(dirrec *dir, const char *name);
dirrec	*QPDir_AddNewSubDir(dirrec *dir, const char *name);
void	QPDir_ReadDirectoryTree();
void	QPDir_ExploreDir(dirrec *dir, char *path_home, dirrec *oldest_parent);
void	QPDir_GetFolderName(dirrec *dir);
void	QPDir_GetFolderDescription(dirrec *dir);
void	QPDir_GetFolderMainImage(dirrec *dir);
void	QPDir_GetGalleryName();
void	QPDir_GetGalleryDescription();
void	QPDir_WriteFolderConfig(dirrec *dir);
void	QPDir_WriteGalleryConfig();
void	QPDir_GetImageDescriptions(dirrec *dir, imgrec *img);
void	QPDir_MakeAllThumbnails(int make_thumbnails);
void	QPDir_MakeThumbnails(dirrec *dir, int target_size, int make_thumbnails);



/* ASDF */
/*****************************************************************************/
/* record dirrec declaration */
struct dirrec_node {
	dirrec	*next;			/* -> next */

	char	*name;			/* name of directory */
	char	*alias;			/* name to go on page */
	char	*path;			/* relative pathname to directory */
	char	*path_home;		/* relative pathname to get home */
	char	*description;		/* description */
	char	*mainimage;		/* image used on main page */

	dirrec	*oldest_parent;		/* -> oldest parent dir */
	dirrec	*subdirs;		/* -> list of subdirectories */
	dirrec	*subdirs_last;		/* -> last subdirectory */
	int	num_subdirs;		/* number of subdirectories */

	imgrec	*images;		/* -> list of images in dir */
	imgrec	*images_last;		/* -> last image in list */
	int	num_images;		/* number of images in dir */

	u_long	flags;			/* flags */
	int	order;			/* Used to order lists */
};


/* record dirrec low-level function declarations. */
dirrec	*dirrec_new();
void	dirrec_append(dirrec **list, dirrec **last, dirrec *entry);
void	dirrec_delete(dirrec **list, dirrec **last, dirrec *x);
void	dirrec_movetofront(dirrec **list, dirrec **last, dirrec *lastchecked, dirrec *x);

/* record dirrec low-level data-specific function declarations. */
void	dirrec_init(dirrec *dir);
void	dirrec_free(dirrec *dir);
void	dirrec_setname(dirrec *dir, const char *name);
void	dirrec_setalias(dirrec *dir, const char *alias);
void	dirrec_setpath(dirrec *dir, const char *path);
void	dirrec_setdescription(dirrec *dir, const char *description);
void	dirrec_setmainimage(dirrec *dir, const char *mainimage);
void	dirrec_setpath_home(dirrec *dir, const char *path_home);
dirrec	*dirrec_dir(dirrec **list, dirrec **last, char *name);



/*****************************************************************************/
/* record imgrec declaration */
struct imgrec_node {
	imgrec *next;			/* -> next */

	int	type;			/* image type (JPG, BMP, GIF, ...) */
	char	*name;			/* image name */
	char	*description;		/* description */
	char	*date;			/* date */
	int	width;			/* width */
	int	height;			/* height */
	u_long	bytes;			/* size of image */

	char	*thumbnail_name;	/* thumbnail name */
	int	thumbnail_width;
	int	thumbnail_height;

	int	order;			/* Used to order lists */
};

/* record imgrec low-level function declarations.  Never changes. */
imgrec	*imgrec_new();
void	imgrec_freeall(imgrec **list, imgrec **last);
void	imgrec_append(imgrec **list, imgrec **last, imgrec *entry);
void	imgrec_delete(imgrec **list, imgrec **last, imgrec *x);
void	imgrec_movetofront(imgrec **list, imgrec **last, imgrec *lastchecked, imgrec *x);

/* record imgrec low-level data-specific function declarations. */
void	imgrec_init(imgrec *img);
void	imgrec_free(imgrec *img);
void	imgrec_setname(imgrec *img, const char *name);
void	imgrec_setthumbnailname(imgrec *img, const char *name);
void	imgrec_setdescription(imgrec *img, const char *description);
void	imgrec_setdate(imgrec *img, const char *date);
imgrec	*imgrec_image(imgrec *list, char *name);



#endif /* QPDIR_H */
