/* datafile.h
 *
 * Pieter Eendebak ( pte@ddsw.nl )
 *
 */

#ifndef DATAFILE_H
#define DATAFILE_H

#include <qobject.h>
#include <qstring.h>
#include <qfile.h>
#include <qdstream.h>

/**
 * A DataFile is a structure which manages a file containing fortunes
 * It is used by the KFortune program. The class creates a cache
 * file in ~/.kde/share/apps/kfortune/ to speed up the program.
 *
 * @short A structure used by KFortune
 */
class DataFile : public QObject
{
	Q_OBJECT

public:
	/*
	 * Constructor for class Datafile.
	 *
	 * @param dir The directory which contains the fortune file
	 * @param file The file which contains the fortunes to be used
	 * @param parent The parent QObject
	 * @param n The name of the parent QObject
	 * @author Pieter Eendebak <pte@ddsw.nl>
	 *
	 */
	DataFile ( const char *dir=0, const char *file=0,
			QObject *parent=0, const char *n=0 );
	~DataFile();

	/**
	 * Give the database a new file to hanlde
	 *
	 * @param dir The directory which contains the fortune file
	 * @param file The new fortune file
	 */
	void setName ( const char *dir=0, const char *file=0);
	/**
	 * @return returns the number of fortunes in this database
	 */
	int getNumber();
	/**
	 * This function is used to get a fortune.
	 *
	 * @param n Number of the fortune which has to be fetched
	 * @return Returns the requested fortune or an empty string if the
	 * requested fortune doesn't exist.
	 */
	QString getFortune(int n);
	
	/**
	 * This function adds a fortune the the database. Note : this
	 * function hasn't been implemented yet and will probably never be
	 * implemented.
	 *
	 * @param fort The fortune to be added to the database
	 *
	 */
	void addFortune(QString fort);
	
	/**
	 * Rebuilds the cache-file from scratch
	 *
	 * The format of the cache-file :
	 * <pre>
	 * # "Comment line"
	 * Number of fortunes in database
	 * # "Comment line"
	 * Streamposition of fortune number x
	 * Streamposition of fortune number 2*x
 	 * Streamposition of fortune number 3*x
	 * etc.
	 *
	 * where x is a constant defined in defines.h
	 * </pre>
	 *
	 */
	void updateCache();

protected:

	/**
	 * Get the number of fortunes from the fortune-file, not from
	 * the cache file.
	 *
	 */
	int getNumberCache();
	/**
	 * This function is used to get data from the cache file
	 *
	 * @param x Number of fortune * CACHENUMBER which streamposition
	 * has to be returned
	 * @return returns the streamposition of a fortune 
	 *
	 */
	int getCache(int x);

	QString name;
	QFile *file, *cache;
	int number;

public slots:
	
};

#endif

Documentation generated by root@ziep on Tue Dec 29 15:38:56 CET 1998