/***************************************************************************
                          myshadereditdlg.cpp  -  description
                             -------------------
    begin                : Mon Mai 15 2006
    copyright            : (C) 2006 by Krippel Harald
    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 <qlineedit.h>
#include <qcheckbox.h>
#include <qprocess.h>

#include "myshaderdlg.h"


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

MyShaderEditDlg::~MyShaderEditDlg(){

}

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

void MyShaderEditDlg::slotGetData(FolderListItem *i)
{
    point=i;

    text->setText(i->text(0));
    on->setChecked(i->GetValue("on",i).toInt());

    vfile->setText(i->GetValue("vfile",i));
    ffile->setText(i->GetValue("ffile",i));


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

void MyShaderEditDlg::slotEditData()
{
    point->setText(0,text->text());
    point->SetValue("on", on->isChecked() ? "1" : "0");

//  implement later
//    point->SetValue("vfile",vfile->text());
//    point->SetValue("ffile",ffile->text());

    point->updategl();

qWarning( "MyShaderEditDlg::slotEditData(): Geht !" );

}

void MyShaderEditDlg::slotEditVertexData()
{
    QProcess*  proc = new QProcess( this );
    QString   editor = g_prjpath + point->GetValue("path",point ) + "/" + point->GetValue("vfile",point) ;
    qWarning( editor );   // error handling
#ifdef    Q_OS_LINUX

    proc->addArgument( "kwrite" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditVertexData(): cant start kwrite" );   // error handling
    }
#endif
#ifdef    Q_OS_MACX

    proc->addArgument( "/Applications/TextEdit.app/Contents/MacOS/TextEdit" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditVertexData(): cant start TextEdit" );   // error handling
    }
#endif
#ifdef    Q_OS_WIN32

    proc->addArgument( "edit" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditVertexData(): cant start edit" );   // error handling
    }
#endif

    qWarning( "MyShaderEditDlg::slotEditVertexData(): Geht !" );
}
void MyShaderEditDlg::slotEditFragmentData()
{
    QProcess*  proc = new QProcess( this );
    QString   editor = g_prjpath + point->GetValue("path",point ) + "/" + point->GetValue("ffile",point) ;
    qWarning( editor );   // error handling
#ifdef    Q_OS_LINUX

    proc->addArgument( "kwrite" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditFragmentData(): cant start kwrite" );   // error handling
    }
#endif
#ifdef    Q_OS_MACX

    proc->addArgument( "/Applications/TextEdit.app/Contents/MacOS/TextEdit" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditFragmentData(): cant start TextEdit" );   // error handling
    }
#endif
#ifdef    Q_OS_WIN32

    proc->addArgument( "edit" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MyShaderEditDlg::slotEditFragmentData(): cant start edit" );   // error handling
    }
#endif

    qWarning( "MyShaderEditDlg::slotEditFragmentData(): Geht !" );
}
