/*
 * BOUCLE D'AFFICHAGE
 */
bool SceneManager::execute(SDL_Window* window, unsigned int w, unsigned int h)
{
  init3D(w,h);
  init2D();
  initSounds();
  unsigned int debut ,fin;							  	/* VARIABLES DE GESTION DU TEMPS */
  float period = 1.0 / FPS_LIMIT,fps,time;
  while(!m_input.terminer())								/* BOUCLE D'EXECUTION */
  {
    debut = SDL_GetTicks();								/* ON RELEVE LE TEMPS DE DEBUT DE BOUCLE */
    onPreRender();									/* ON MET À JOUR LES MODELES DYNAMIQUES */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);					/* NETTOYAGE DE LA FENETRE */
    m_input.update();									/* MISE A JOUR DES EVENEMENTS */
    updateCameras();									/* MISE À JOUR DES CAMERAS */
    if(m_input.getKey(SDL_SCANCODE_ESCAPE))  break;					/* QUITTER EN APPUYANT SUR ESPACE */
    if(m_input.getKeyRelease(SDL_SCANCODE_V)) changeCamera();					/* CHANGER DE CAMERA EN APPUYANT SUR ESPACE */
    if(m_input.getKeyRelease(SDL_SCANCODE_SPACE)) m_soundMgr.playEffect("laser",127/2);
    drawAll();										/* AFFICHAGE DE TOUS LES MODELES DU MONDE 3D */
    SDL_GL_SwapWindow(window);								/* RAFRAICHISSEMENT DE LA FENETRE */    
    fin = SDL_GetTicks();								/* ON RELEVE LE TEMPS DE FIN DE BOUCLE */
    time = (float)(fin - debut);							/* ON CALCULE LE TEMPS D'EXECUTION DE LA BOUCLE */
    fps = 1000.0/time;									/* ON CALCULE LA FREQUENCE MAXIMALE */
    std::ostringstream streamTitle;
    streamTitle << "fps: " << fps;							
    SDL_SetWindowTitle(window,streamTitle.str().c_str());				/* ON AFFICHE LA FREQUENCE COMME TITRE DE LA FENETRE */
    if(time < period)
      SDL_Delay((unsigned int)(period - time));  					/* ON LIMITE LA FREQUENCE A 60 FPS */
  }
  printf("toto\n");
  return true;
}
DVRServer::DVRServer(int id, QObject *parent)
    : QObject(parent), m_configuration(id), m_devicesLoaded(false)
{
    m_api = new ServerRequestManager(this);

    connect(&m_configuration, SIGNAL(changed()), this, SIGNAL(changed()));
    connect(m_api, SIGNAL(loginSuccessful()), SLOT(updateCameras()));
    connect(m_api, SIGNAL(disconnected()), SLOT(disconnectedSlot()));

    connect(m_api, SIGNAL(loginRequestStarted()), this, SIGNAL(loginRequestStarted()));
    connect(m_api, SIGNAL(loginSuccessful()), this, SIGNAL(loginSuccessful()));
    connect(m_api, SIGNAL(serverError(QString)), this, SIGNAL(serverError(QString)));
    connect(m_api, SIGNAL(loginError(QString)), this, SIGNAL(loginError(QString)));
    connect(m_api, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
    connect(m_api, SIGNAL(statusChanged(int)), this, SIGNAL(statusChanged(int)));
    connect(m_api, SIGNAL(onlineChanged(bool)), this, SIGNAL(onlineChanged(bool)));

    connect(&m_refreshTimer, SIGNAL(timeout()), SLOT(updateCameras()));
}
void ServerMenu::createActions()
{
	m_connectAction = addAction(tr("Connect"), m_server, SLOT(toggleOnline()));

	addSeparator();

	m_browseEventsAction = addAction(tr("Browse &events"), this, SIGNAL(showEventsWindow()));
	m_browseEventsAction->setEnabled(m_server->isOnline());
	connect(m_server, SIGNAL(onlineChanged(bool)), m_browseEventsAction, SLOT(setEnabled(bool)));

	m_configureServerAction = addAction(tr("&Configure server"), this, SIGNAL(openServerConfig()));
	m_configureServerAction->setEnabled(m_server->isOnline());
	connect(m_server, SIGNAL(onlineChanged(bool)), m_configureServerAction, SLOT(setEnabled(bool)));

	addSeparator();

	m_configureServerAction = addAction(tr("Refresh devices"), m_server, SLOT(updateCameras()));
	m_configureServerAction->setEnabled(m_server->isOnline());
	connect(m_server, SIGNAL(onlineChanged(bool)), m_configureServerAction, SLOT(setEnabled(bool)));

	m_configureServerAction = addAction(tr("Settings"), this, SIGNAL(openServerSettings()));

	updateMenuForServer();
}