// generated 2002/9/29 23:16:46 CEST by triendl.kj@triendl.kj.(none)
// using glademm V1.1.0c
//
// newer (non customized) versions of this file go to CFireFlierClient.hh_new

// you might replace
//    class foo : public foo_glade { ... };
// by
//    typedef foo_glade foo;
// if you didn't make any modifications to the widget

#ifndef _CFIREFLIERCLIENT_HH
#define _CFIREFLIERCLIENT_HH

#include <gtkmm.h>
#include "CFireFlierClientApp.hh"
#include "CDlgAuthentication.hh"
#include "CDlgSrc.hh"
#include "CDlgIPTablesRules.hh"
#include "CDlgUSpaceRules.hh"
#include "CPacket.h"
#include "CResolverThread.h"
#include "dispatcher.h"
#include "fireflier.h"
#include "fireflierIO.h"
#include <map>
#include <list>

#ifdef WITHGCONF
#include "CGConf.h"
#endif


class CFireFlierClient: public Gtk::Window
{  
	Gtk::Tooltips m_tooltips;

protected:
	Gtk::MenuItem *m_menuItemViewSrc;
	Gtk::MenuItem *m_menuItemViewIPTablesRules;
	Gtk::MenuItem *m_menuItemViewUSpaceRules;
	Gtk::Toolbar *toolbarFireFlier;
	Gtk::Image *m_butViewSrc;
	Gtk::Image* m_butViewIPTablesRules;
	Gtk::Image* m_butViewUSpaceRules;
	Gtk::RadioButton *m_radioThisPacket;
	Gtk::RadioButton *m_radioQueuedPackets;
	Gtk::RadioButton *m_radioCreateRule;
	Gtk::Label *m_labelChain;
	Gtk::CheckButton *m_chkIPSrc;
	Gtk::Label *m_labelHostSrc;
	Gtk::CheckButton *m_chkPortSrc;
	Gtk::CheckButton *m_chkIFaceIn;
	Gtk::Label *m_labelMAC;
	Gtk::Label *m_labelLen;
	Gtk::Frame *m_frameSrc;
	Gtk::Combo *m_cbTimeout;
	Gtk::CheckButton *m_chkIPDst;
	Gtk::Label *m_labelHostDst;
	Gtk::CheckButton *m_chkPortDst;
	Gtk::CheckButton *m_chkIFaceOut;
	Gtk::CheckButton *m_chkProtocol;
	Gtk::Label *m_labelTCPFlags;
	Gtk::Frame *m_frameDst;
	Gtk::Frame* m_frameGeneral;
	Gtk::Frame* m_frameOptions;
	Gtk::Label *m_labelICMPType;
	Gtk::Label *m_labelTimestamp;
	Gtk::CheckButton *m_chkProgram;
	Gtk::CheckButton *m_chkTracking;
	Gtk::Button *m_butAccept;
	Gtk::Button *m_butDrop;
	Gtk::CheckMenuItem* m_menuItemDropInAuto;
	Gtk::CheckMenuItem* m_menuItemDropFwdAuto;
	Gtk::CheckMenuItem* m_menuItemDropOutAuto;
	Gtk::MenuItem* m_menuItemLogin;
	Gtk::Statusbar* m_pStatusbar;
	Gtk::Label* m_labelTimeout;
	
	Gtk::Label* m_labelChainValue;
	Gtk::Label* m_labelLenValue;
	Gtk::Label* m_labelMACValue;
	Gtk::Label* m_labelProgramValue;
	Gtk::Label* m_labelTimestampValue;
	Gtk::Label* m_labelTCPFlagsValue;
	Gtk::Label* m_labelICMPTypeValue;
	Gtk::Label* m_labelProtocolValue;
	Gtk::Label* m_labelIPSrcValue;
	Gtk::Label* m_labelIPDstValue;
	Gtk::Label* m_labelHostSrcValue;
	Gtk::Label* m_labelHostDstValue;
	Gtk::Label* m_labelPortSrcValue;
	Gtk::Label* m_labelPortDstValue;
	Gtk::Label* m_labelIFaceInValue;
	Gtk::Label* m_labelIFaceOutValue;
	Gtk::Label* m_labelTrackingValue;

private:	
	bool m_bAuthOpen;
	bool m_bProcessing;
	std::list <SigC::Connection> m_signalList;	// used to disconnect all
												// handler in dtor

	CResolverThread m_resSrcThread;
	CResolverThread m_resDstThread;

	Dispatcher1 <bool> m_signalConnection;
	Dispatcher1 <int> m_signalAuthentication;
	Dispatcher1 <CRefPtr <const CPacket> > m_signalPacketAvail;
	Dispatcher0 m_signalNetworkThreadFinished;
	Dispatcher2 <CffIO::pCffIOError, bool> m_signalNetworkThreadError;
	
	Dispatcher1 <const char*> m_signalResolvedSrc;
	Dispatcher1 <const char*> m_signalResolvedDst;

	CRefPtr <const CPacket> m_pCurPacket;
	std::map <Glib::ustring, guint32> m_mapTimeout;	// since the gtk-combo isnt able to provide the current selected element
									// (as i know by now), lets do it on our own..

	CDlgSrc m_dlgSrc;
	CDlgIPTablesRules m_dlgIPTablesRules;
	CDlgUSpaceRules m_dlgUSpaceRules;
#ifdef WITHGCONF
	CGConfUI m_gconfUI;
#endif


public:
	CFireFlierClient();
	virtual ~CFireFlierClient();
	
	
protected:
#ifdef WITHGCONF
	void on_value_changed(const ustring& strKey, const Gnome::Conf::Value& value);
	bool on_delete(GdkEventAny*);
	void save_pos_and_size();
	void on_quit();
#endif
	void initGUI();
	void setLabels();
	void activateInterface();
	void clearInterface();
	void on_sendCmd(ff::Commands enCmd);
#ifdef ALREADY_12
	void on_dropAuto_toggled(ff::Chains enChain);
#endif // ALREADY_12
	void on_menuItemAbout_activate();
	// handler for any checkbox and the time combo
	void on_Rule_compile(Gtk::CheckButton* EventSrc = NULL);
	void on_timeout_changed();
	void on_radioRuleCmds_toggled(ff::Rulecommands enCmd);
	void on_dropAuto_activate(ff::Chains);
	// handler for view src, iptablesrules and uspacerules
	void on_Request(ff::Commands enCmd);
	bool on_idle();
	void on_about();
	void on_login();

// signal handlers for the network thread
	void on_Packet_avail(CRefPtr <const CPacket>);
	void on_Src_avail(const char* szSource, int nLen);
	void on_IPTablesRules_avail(char* szMsg, int nLen);
	void on_Connection(bool bConnected);
	void on_Authentication(int nAuthenticated);
	void on_NetworkThread_finished();
	void on_networkthread_error(CffIO::pCffIOError pErr, bool bDisconnected);

// signal handlers for the resolver threads
	// must be a Label* because SigC::bind calls the desctructor of the bound element_type
	// and this does not work for a Label&
	void on_resolved(const char* szHostName, Gtk::Label* label);

public:
};
#endif
