/***************************************************************************
                          mynetworkdlg.cpp  -  description
                             -------------------
    begin                : Tue September 1 2004
    copyright            : (C) 2004 by Harald Krippel
    email                : neuro.harald@surfeu.at
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include <mynetworkdlg.h>

#include <iostream>

#include <qvariant.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>

MyNetworkEditDlg::MyNetworkEditDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
    : NetworkEditDlg( parent, name, modal, fl )
{
    point = NULL;
}

/*
 *  Destroys the object and frees any allocated resources
 */
MyNetworkEditDlg::~MyNetworkEditDlg()
{
    // no need to delete child widgets, Qt does it all for us
}

void MyNetworkEditDlg::slotGetData()
{
    if(point != NULL)
    {
      slotGetData(point);
    }
}

void MyNetworkEditDlg::slotGetData(FolderListItem *i)
{
    local->setChecked(i->GetValue("local",i).toInt());
    client->setChecked(i->GetValue("client",i).toInt());
    server->setChecked(i->GetValue("server",i).toInt());

    surl->setText(i->GetValue("surl",i));
    sport->setText(i->GetValue("sport",i));
    rport->setText(i->GetValue("rport",i));
    nickname->setText(i->GetValue("nickname",i));

    point=i;

    qWarning( "MyNetworkEditDlg::slotGetData(): Geht !" );
}

void MyNetworkEditDlg::slotEditData()
{
    point->SetValue("local", local->isChecked() ? "1" : "0");
    point->SetValue("client", client->isChecked() ? "1" : "0");
    point->SetValue("server", server->isChecked() ? "1" : "0");
    
    point->SetValue("surl",surl->text());
    point->SetValue("sport",sport->text());
    point->SetValue("rport",rport->text());
    point->SetValue("nickname",nickname->text());

    point->updategl();

    qWarning( "MyNetworkEditDlg::slotEditData(): Geht !" );
}

void MyNetworkEditDlg::slotLogon()
{
  char sendmsg[256];

    if(point->client == NULL)
    {
       point->client = new  netclient();
       g_client = point->client;
    }
    if(point->client != NULL)
    {
      if(point->client->status[0] == 0) // not connected
      {
        point->client->logon(surl->text().latin1(),rport->text().toInt());
        sprintf(sendmsg,"1 0 %s %s 0.7",rport->text().latin1(),nickname->text().latin1());
        point->client->send(sendmsg);
        qWarning( "point->client->logon() Geht !" );
      }
      else
      {
        qWarning( "Error ! -> You are connected !" );
      }
    }
    qWarning( "MyNetworkEditDlg::slotLogon(): Geht !" );
}

void MyNetworkEditDlg::slotLogoff()
{
  char sendmsg[256];
  
    if(point->client != NULL)
    {
      if(point->client->status[0] == 0) // not connected
      {
        qWarning( "Error ! -> You are disconnected !" );
      }
      else
      {
        sprintf(sendmsg,"2 %d",point->client->userid[0]);
        point->client->send(sendmsg);
        if(point->client->status[0] == 0) // not connected
        {
          point->client->logoff();
          qWarning( "Disconnected Geht !" );
        }
      }
    }
    qWarning( "MyNetworkEditDlg::slotLogoff(): Geht !" );
}
