/***************************************************************************
                          qcakerun.cpp  -  description
                             -------------------
    begin                : Mon Sep  18 16:54:22 CET 2006
    copyright            : (C) 2004 by Harald Krippel
    email                : harald@the-develop.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

// Qt includes
#include <qsettings.h>

// application specific includes
#include "globdefines.h"
#include "qcakerun.h"
#include "main.h"
#include "glcontrol.h"
#include "playerview.h"

QcakeRunApp::QcakeRunApp(QObject *parent):QObject(parent)
{
  view = NULL;
  initView();
}

QcakeRunApp::~QcakeRunApp()
{

}


void QcakeRunApp::initView()
{ 
  view = new PlayerView();
}

void QcakeRunApp::openDocumentFile(const char* filename)
{

  QDomDocument domdoc("mydocument");
  QFile f( filename );
  
  if ( !f.open( IO_ReadOnly ) )
  {
    qWarning( "can not open File !!" );
		return ;
  }
  if ( !domdoc.setContent( &f ) ) {
    qWarning( "can not open DomDoc !!" );
    f.close();
    return ;
  }
  f.close();
  	
  g_prjpath =  QFileInfo(f).filePath();
  g_prjpath = g_prjpath.left(g_prjpath.findRev(QFileInfo(f).fileName()));
  qWarning( "%s",g_prjpath.latin1() );
  view->initListView(&domdoc,g_prjpath);
  view->newWirebox(view->getStart());
//  setCentralWidget(g_gl);
}

/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////

void QcakeRunApp::slotToolsPlay()
{
  int a;

  // compile the spl program
  for(a=0;a<MAX_SPL;a++)
  {
    if(gl_spl_obj[a] != NULL)
    {
      gl_spl_obj[a]->compile();
    }
  }

  g_playmode = 1;

}

void QcakeRunApp::slotToolsStop()
{

  g_playmode = 0;
  toolsPlay->setEnabled(true);
  toolsStop->setEnabled(false);
  if(g_gl != NULL)
  {
    g_gl->StopSound();
  }
}

void QcakeRunApp::slotToolsReset()
{

  g_playmode_reset=1;

      if (g_tmpItem != NULL && g_gl != NULL)    // only it exist !!
      {
         g_gl->switchScene(g_tmpItem);
      }

}
