/***************************************************************************
                          myspldlg.cpp  -  description
                             -------------------
    begin                : Tue Jan 24 2005
    copyright            : (C) 2005 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 <myspldlg.h>

#include <iostream>

#include <qvariant.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qprocess.h>

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

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

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

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

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

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

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

    point->updategl();

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

void MySplEditDlg::slotEditorScript()
{
    QProcess*  proc = new QProcess( this );
    QString   editor = g_prjpath + point->GetValue("path",point ) + "/" + point->GetValue("file",point) ;
    qWarning( editor );   // error handling
#ifdef    Q_OS_LINUX
    
    proc->addArgument( "kwrite" );
    proc->addArgument( editor );

    if ( !proc->start() ) {
      qWarning( "MySplEditDlg::EditorScript(): 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( "MySplEditDlg::EditorScript(): cant start TextEdit" );   // error handling
    }
#endif
#ifdef    Q_OS_WIN32

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

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