// generated 2002/9/29 3:48:54 CEST by triendl.kj@triendl.kj.(none)
// using glademm V1.1.0c
//
// newer (non customized) versions of this file go to CFireFlierClientApp.cc_new

// This file is for your program, I won't touch it again!

#include "CFireFlierClientApp.hh"
#include "CDlgAuthentication.hh"
#include "CFireFlierClient.hh"
#include "fireflierIO.h"
#ifdef WITHGCONF
#include "CkjConfSystem.h"
#endif
#include <netinet/in.h>
#include <iostream>
#include <string>

using namespace std;


bool connected = false;
int authenticated = 0; // not authenticated

#ifdef WITHGCONF
CkjConfSystem gconfInit;
Glib::RefPtr <Gnome::Conf::Client> gb_pGConfClient = Gnome::Conf::Client::get_default_client();
#endif


void usage(char** argv)
{
	cout << endl << "usage:" << endl << endl;
	cout << "  " << *argv << " [server_ip [server_port]]" << endl;
	cout << "  default: " << *argv << " 127.0.0.1 1133" << endl << endl;
}


int main(int argc, char** argv)
{  
#ifdef WITHGNOME
	Gnome::Main theApp(strAppName, strAppVersion, Gnome::UI::module_info_get(), argc, argv);
#else
	Gtk::Main theApp(argc, argv);
#endif

	{	// parsing command line arguments
		std::string strIP = "127.0.0.1";
		guint16 nPort = 1133;
		
		if ((argc > 3) ||
		    ((argc > 1) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))))
		{
		    usage(argv);
                    return 1;
		}

		if (argc >= 2)
			strIP = argv[1];
	
		if (argc == 3)
		{
		    nPort = atoi(argv[2]);
		    if (nPort == 0)
                        usage(argv);
		}
		
		ffIO.setSocket(strIP.c_str(), nPort);
		if (FF_DEBUG)
			cout << "connecting to fireflier-server on " << strIP << ":" << nPort << endl;
	}
	
	CFireFlierClient* theClient = new CFireFlierClient;

	try
	{
		theApp.run(*theClient);
	}
	catch (...)
	{
		theClient->hide();
		cerr << "some error occurred" << endl;
	}

	if (theClient)
		delete theClient;
	
	if (FF_DEBUG)
		cout << "ending program" << endl;
	
	return 0;
}
