//  bbsmount_base.hh for bbsmount - an tool for simple mounting in X11
//
//  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_BASE_HH
#define BBSMOUNT_BASE_HH

#include <vector>
#include <set>
#include <string>

#include <X11/Xlib.h>
#include <X11/xpm.h>

using namespace std;

// Classes:
class File {
    public:
	File(const char * file_name, const char * images_prefix);
	~File();
	
	bool Exist(void) const;
	char *GetPath(void) const;
    private:
	void FindFile(const char *file_name);

	char *path;
	const char *images_path;
};

class Action {
    public:
	Action();
	Action(const Action &copy);
	~Action();

	unsigned int GetCommand(const bool mounted) const;
	unsigned int GetButton() const;
	unsigned int GetModifiers() const;
	unsigned int GetNegativeModifiers() const;
	bool IsActive(const unsigned int _button, const unsigned int state) const;

	void SetCommand(const unsigned int command, const bool mounted);
	void SetButton(const unsigned int _button);
	void AddModifier(const unsigned int _modifier);
	void AddNegativeModifier(const unsigned int _modifier);

	bool operator == (const Action &cmp) const {
	    return (cmp.GetButton() == button && cmp.GetModifiers() == modifiers && cmp.GetNegativeModifiers() == nmodifiers);
	}
	bool operator != (const Action &cmp) const {
	    return (cmp.GetButton() != button || cmp.GetModifiers() != modifiers || cmp.GetNegativeModifiers() != nmodifiers);
	}
	bool operator > (const Action &cmp) const {
	    if (cmp.GetButton() < button)
		return true;
	    if (cmp.GetButton() == button && cmp.GetModifiers() < modifiers)
		return true;
	    if (cmp.GetButton() == button && cmp.GetModifiers() == modifiers && cmp.GetNegativeModifiers() < nmodifiers)
		return true;
	    return false;
	}
	bool operator < (const Action &cmp) const {
	    if (cmp.GetButton() > button)
		return true;
	    if (cmp.GetButton() == button && cmp.GetModifiers() > modifiers)
		return true;
	    if (cmp.GetButton() == button && cmp.GetModifiers() == modifiers && cmp.GetNegativeModifiers() > nmodifiers)
		return true;
	    return false;
	}

    private:
	unsigned int command_if_mouted, command_if_not_mounted, button, modifiers, nmodifiers;
};

class MountPoint {
    public:
	MountPoint(const string &_mountpoint);
	MountPoint(const MountPoint &copy);
	~MountPoint();

	bool IsMounted() const;
	unsigned int GetMountedImage() const;
	unsigned int GetNotMountedImage() const;
	unsigned int GetCurrentImage(bool &ismounted) const;
	unsigned int getMountedInfo(void) const;
	unsigned int getNotMountedInfo(void) const;
	unsigned int getErrorInfo(void) const;
	unsigned int getCurrentInfo(void) const;
	const string &GetMountPoint() const;
	const string &getDescription(void) const;
	const string &getLastError(void) const;
	const set<Action> &GetActions() const;
	unsigned int GetCommand(const unsigned int button, const unsigned int state) const;
	bool IsLocked() const;
	
	void AddAction(const Action &action);
	void SetMountedImage(const unsigned int image);
	void SetNotMountedImage(const unsigned int image);
	void setMountedInfo(const unsigned int infotext);
	void setNotMountedInfo(const unsigned int infotext);
	void setErrorInfo(const unsigned int infotext);
	void setDescription(const string &desc);
	void setLastError(const string &error);
	void clearError(void);
	void SetMounted(const bool is_mounted);

	void Lock();
	void Unlock();

	bool operator == (const MountPoint &other) const { return (this == &other); };
    private:
	set<Action> actions;
	string mountpoint, description, last_error;
	unsigned int mounted_image, not_mounted_image, mounted_info, not_mounted_info, error_info;
	bool mounted, commandlock, was_error;
};

class MyImage {
    public:
	MyImage(Display *_dpy, const Pixmap image, const Pixmap shape);
	MyImage(Display *_dpy, const Window &rootwin, XpmImage *image);
	MyImage(const MyImage &copy);
	~MyImage();
	
	Display *GetDisplay();
	Pixmap GetImage(void) const;
	Pixmap GetImageShape(void) const;
    private:
	Pixmap normal_pixmap, shape_pixmap;
	Display *dpy;
};

class MountWindow {
    public:
	MountWindow(MountPoint *_mountpoint, Display *_display, const Window _parent, const int _x, const int _y, const unsigned int _width, const unsigned int _height);
	~MountWindow();

	const Window GetWindow() const;
	
	MountPoint &GetMountPoint(void);
	void Update(void);
	void SetPressed(const bool is_pressed);
	void Draw(const bool _raised = true);
	void Draw(const int _x, const int _y, const unsigned int _width, const unsigned int _height);
	void Resize(const unsigned int _width, const unsigned int _height);
	void Move(const int _x, const int _y);
	void MoveResize(const int _x, const int _y, const unsigned int _width, const unsigned int _height);
	
    private:
	Display *display;
	Window parent, mywindow;
	GC mywindowgc;
	int x, y;
	unsigned int width, height;
	MountPoint *mountpoint;
	bool drawmounted, raised;
};

#endif /* BBSMOUNT_BASE_HH */


syntax highlighted by Code2HTML, v. 0.9.1