//
//  Copyright (c) 2001-2002 by Miroslav Jezbera, jezberam@phoenix.inf.upol.cz
//
//  This program 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 program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// (See the included file COPYING / GPL-2.0)
//

#ifndef BBSMOUNT_HH
#define BBSMOUNT_HH

#ifdef HAVE_CONFIG_H
#   include "config.h"
#endif /* HAVE_CONFIG_H */

#include <map>
#include <set>

using namespace std;

#include "bbsmount_base.hh"
#include "Basewindow.hh"
#include "resource.hh"
#include "main.hh"
#include "tooltip.hh"

// Constants:
const int max_mount_device_point_size = 128, max_mtab_line_length = 256;

// Types:
enum debug_levels {
    dbg_no_debug_needed,	// Default, only errors are printed
    dbg_warning,		// Warnings are printed
    dbg_summary,		// Only summary messages are printed
    dbg_all_work		// Say what are you doing
};

typedef struct command_data {
    char *command;
    MountPoint *mp;
} command_data_type;

// Functions:
int run_command_in_foreground(const char *command, MountPoint &mp);
int run_command_in_background(const char *command, MountPoint &mp);
set<int> what_is_mounted(const map<string, int> &mount_points);
bool update_mount_points(const map<string, int> &mount_points);
void create_notify_event(void);
void check_mounts(void);
RETSIGTYPE shutdown(int signal);

// Another data types
struct PIXMAP {
	Pixmap 	frame;
	Pixmap	draw;
	Pixmap	draw_pressed;
};

struct GEOM {
	int height;
	int width;
	int x;
	int y;
};

// Forward definitions
class Resource;
class BaseResource;
class Basewindow;

// Main class
class ToolWindow :public Basewindow {
    public:
	ToolWindow(int argc,char **argv,struct CMDOPTIONS *);
	~ToolWindow(void); 

	const MyImage &GetImage(const int imageidx) const;
	const MountPoint &GetMountPoint(const int mntidx) const;
	const PIXMAP &GetPixmaps(void) const;
	size_t GetMountPointsCount(void) const;
	string getTooltip(const string &format, const MountPoint &mp, bool actual_statfs = false) const;

	void configure();
	void FreeAll(void);
	void rereadResources(void);
	MountPoint &GetMountPoint(const int mntidx);
//	Display *GetDisplay(void);
	Resource *GetResources(void);
	Window GetRootWindow(void);
	void CreateWindow(const bool reconfigure);
	void CreateSubWindows(const bool reconfigure);
	void EventLoop(void);
	void Draw(void);
	void Draw(const int x, const int y, const unsigned int width, const unsigned int height);
	void SetCommand(const int cmdidx, const string command);
	void SetImage(const int imgidx, MyImage *image);
	void SetMountPoint(const int mntidx, const MountPoint &mntpoint);
	void Stop(void);
	void ShowTooltip(const Window w, const int x, const int y, const int screen_x, const int screen_y);
	void updateTooltip(void);

	void reconfigure(void);

    private:
	Window rootwin;
	Resource *resource;
	GEOM rootgeometry, drawarea;
	PIXMAP pixmap;
	bool stop;
	MountPoint *tooltip_for_mp;

	vector<MountPoint> mount_points;
	vector<string> commands;
	vector<string> infotexts;
	vector<MyImage *> images;
	vector<MountWindow *> mount_windows;
};

// Global variables
extern ToolWindow *AppWindow;
extern bool finish_checking, reconfigure;
extern int debug_level;

#endif /* BBSMOUNT_HH */


syntax highlighted by Code2HTML, v. 0.9.1