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

#ifndef TOP_H
#define TOP_H

#include "includes.h"
#include "kfortune_zone.h"

enum { TOGGLE_DISPLAY=-3, USE_DISPLAY=-2,
		CONFIG_DISPLAY=-1, NO_DISPLAY=0, USE_DISPLAY_ONCE } ;
enum { USE_BUTTONS, NO_BUTTONS, CONFIG_BUTTONS } ;
enum { CHOOSING_NORMAL, CHOOSING_SIMPLE } ;
enum { NO_OFFENSIVE, USE_OFFENSIVE } ;
enum { NO_AUTOLAUNCH, USE_AUTOLAUNCH } ;
enum { USE_AUTOEXIT, NO_AUTOEXIT, CONFIG_AUTOEXIT } ;

#define DO_COUNTDOWN USE_AUTOEXIT
#define NO_COUNTDOWN NO_AUTOEXIT
#define CONFIG_COUNTDOWN CONFIG_AUTOEXIT

/**
 * This is the class KFortune. The class is used only for the program 
 * kfortune.
 * 
 * @short Basic class for KFortune
 * @author Pieter Eendebak <pte@ddsw.nl>
 * @version 1.0
 * 
 */
class KFortune : public KTMainWindow
{
	Q_OBJECT

public:
	/**
	 * The constructor method for class KFortune
	 *
	 * @see KFortune
	 * @param argc Argument counter
	 * @param argv Arguments from command line
	 * @param parent Parent widget, used for QWidget
	 * @param name	Name for QWidget
	 *
	 */
	KFortune ( int argc, char **argv,
			 const char *name=0 );
	
	/**
	 * The destrucor method for class KFortune
	 */
	~KFortune();
		
protected slots:
	/**
	 * Used by the popup-menu 
	 */
	void mousePressEvent( QMouseEvent * ) ;

	/**
	 * Only calls the function resizeEvent()
	 *
	 * @see #resizeEvent
	 */
	void resizeEvent ( QResizeEvent * );
	/**
	 * Handels all the resizing of the main window of KFortune
	 *
	 * @param all If this is false the widgets won't be resized, but
	 * only the fortune text will be updated
 	 */
	void resizeEvent ( bool all=true);
	
	/**
	 * Used to automaticly exit the program.
	 */
	void timerEvent( QTimerEvent * ) ;

protected:	 
	/**
	 * Handles the default keybindigs
	 *
	 * @see KKeyConfig
	 */
	void initKeys();
	/**
	 * Creates the menubar and connects the menu-entries to the
	 * appropriate functions
	 */
	void createMenu();
	/**
	 * Get the configuration from the config-file.
	 */
	void initConfig();

	/**
	 * Save the current configuration to the config-file.
	 */
	void saveConfig();
	/**
	 * This function is used enable or disable to menubar 
	 */
	void setDisplay( int );
	/**
	 * This function is used enable or disable
	 * the buttons.
	 */
	void setButtons( int );
	/**
	 * This function is used to automaticaly start the program when 
	 * KDE is started
	 */
	void setLaunch( int );
	/**
	 * Sets whether the program should show offensive fortunes or not
	 */
	void setOffensive( int );
	/**
	 * Reads the data from the different databases.
	 * Which databases are used is determined by the KConfig object.
	 */
	void readData();	
	/**
	 * Updates the cache files of the current used databases.
	 * This is done by calling @ref DataFile#updateCache.
	 *
	 * @see DataFile#updateCache
	 */
	void cacheUpdate();
	/**
	 * Calls @ref #readData after having deleted some objects
	 * to save some memory.
	 */
	void rereadData();

	void setDatabaseEnabled( bool, int db ) ;
	void setDatabaseOffensive( bool, int db ) ;
	bool databaseEnabled( int database ) ;
	bool databaseOffensive( int database ) ;
	QString databaseFile( int database ) ;

	/**
	 * Evaluate the command line options.
	 *
	 * @param argc Number of arguments
	 * @param argv The arguments itself
	 */
	void parseOptions(int argc, char **argv);

	/**
	 * This method was created to solve some portability
	 * problems between Linux and solaris. 
	 *
	 * @return a random number between 0 and 1
	 */
	double getRandom() ;

	KConfig *config;
	QString base;
	KAccel *accel;

	KMenuBar *menu;
	QPopupMenu *file, *options, *help, *mouse_menu;

	QPushButton *quit, *next;
	QGroupBox *box;
	
	KFortuneZone *fortune ;
	QFont fortunefont;

	DataFile **database;
	int databases;	// number of fortune-files
	int enabled;	// number of fortune-files enabled
	int total;	// total number of fortunes
	int *a; 	/* distribution of fortunes over the databases */

	/* used to configure the program */
	int display;	
	int buttons ;
	int offensive;
	int choosing;

	int launch;
	int autoexit; /* used for countdown */
	int autoexit_time ;
	int timer_id ;
	
	int lastdbase;	// we don't want to show a fortune twice
	int lastnumber;


	// for resizing...
	int breed, hoog;

public slots:
	/**
	 * Quit the application
	 *
	 * @param save Saves the current configuration if true
	 */
	void quitapp() ;

	/**
	 * Shows a message telling the user that a function has
	 * not been implemented yet.
	 */
	void notImpl();

	/**
	 * Shows a new fortune. This means randomly choosing a,
	 * checking if it hasn't been displayed the time before,
	 * resizing the window and some other stuff.
	 */
	void newfortune();

	/**
	 * Saves the current fortune to a file
	 */
	void saveFortune();

	/**
	 * Sets a new fortune, this includes checking on html-code
	 *
	 * @param txt The fortune text to be set
	 *
	 */
	void setFortune( QString txt );	

	/**
	 * Shows a window for configuring the keybindings
	 */
	void configkeys();
	/**
	 * Shows a window for choosing a new font.
	 */
	void selectFont();

	/**
	 * Configures the kfortune database.
	 *
	 */
	void configdatabase();

	/**
	 * Allows the user the select some options by creating a
	 * Misc() object.
	 *
	 * @see Misc
	 */
	void configmisc();
	/**
	 * Shows information about the program
	 */
	void about();
	/**
	 * Show the online-help
	 */
	void helpmenu();
};

#endif

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