void stylesheetParser::parseComment(){ 
  bool stopProcessingComment=false;
  unsigned int k;
  for(k=2;k<m_styleSheet.length()-1;k++){
    QString temp;
    temp.append(m_styleSheet[k]).append(m_styleSheet[k+1]);
    if(temp=="*/")  {
      k+=2;
      stopProcessingComment=true;
      break;
    }    
  }
  
  if(stopProcessingComment){
    int ws=whiteSpaces(k);
    QPair<QString,unsigned int> tmp(m_styleSheet.left(k+ws),++m_orderNumber);
    m_stylesheetStructure["/*"+QString::number(m_orderNumber,10)]=tmp;
    m_styleSheet=m_styleSheet.right(m_styleSheet.length()-k-ws);
    parse(); 
  }
  
   else {
      m_stopProcessing = true;
      emit errorOccurred(i18n("The comment") + " :\n" +m_styleSheet.mid(0,20) + "...\n "+ msg1);      
      return;
    }
}
void stylesheetParser::parseSelector(){
  int closingParenthesisPos = findParanthesis(m_styleSheet, '}');
   if(closingParenthesisPos==-1) {
    m_stopProcessing = true;
    emit errorOccurred(i18n("The selector") + " :\n" +m_styleSheet.mid(0,20) + "...\n "+ msg1);      
    return;
  }
    
   QString temp(m_styleSheet.left(closingParenthesisPos+1));    
  
  if(numberOfParenthesisInAParenthesisBlock(closed,temp) < numberOfParenthesisInAParenthesisBlock(opened,temp)){
    m_stopProcessing = true;
    emit errorOccurred(i18n("The selector") + " :\n" +m_styleSheet.mid(0,20) + "...\n "+ msg1);      
    return;
  }  
  
  if(numberOfParenthesisInAParenthesisBlock(closed,temp) > numberOfParenthesisInAParenthesisBlock(opened,temp)){
    m_stopProcessing = true;
    emit errorOccurred(i18n("The selector") + " :\n" +m_styleSheet.mid(0,20) + "...\n "+ msg2);      
    return;
  }    
 
   int closingParentheses = 1,
        openingParentheses = 0;
  while(true){ 
    openingParentheses = numberOfParenthesisInAParenthesisBlock(closed,m_styleSheet.left(closingParenthesisPos+1)); //m_styleSheet.left(closingParenthesisPos+1).contains("{");
        
    if(openingParentheses==closingParentheses){
      QString selectorName=m_styleSheet.left(findParanthesis(m_styleSheet, '{')/*m_styleSheet.find("{")*/).stripWhiteSpace(),
                   selectorValue=m_styleSheet.mid(findParanthesis(m_styleSheet, '{')/*m_styleSheet.find("{")*/+1, closingParenthesisPos - m_styleSheet.find("{") -1);    
        
      selectorName.remove("\n").remove("\t");
      selectorValue.remove("\n").remove("\t");
      QPair<QString,unsigned int> tmp(selectorValue,++m_orderNumber);
            
      if (m_stylesheetStructure.contains(selectorName))
      {
        uint i = 2;
        QString s = selectorName + QString("-v%1").arg(i);
        while (m_stylesheetStructure.contains(s))
        {          
         i++;
         s = selectorName + QString("-v%1").arg(i);
        }
        selectorName = s;
      }
      m_stylesheetStructure[selectorName]=tmp; 
      break;
    } 
    else {
      closingParenthesisPos = findParanthesis(m_styleSheet, '{',closingParenthesisPos+1)/*m_styleSheet.find("}",closingParenthesisPos+1)*/;
      closingParentheses++;
    } 
  }

  int ws=whiteSpaces(closingParenthesisPos+1);
  m_styleSheet=m_styleSheet.right(m_styleSheet.length()-closingParenthesisPos-1-ws);
  parse(); 
}
void stylesheetParser::parseAtRules2(){
//TODO this needs to be fixed : in case the at rule is not properly closed the parser hangs
  int semicolonPos = m_styleSheet.find(";");
      
  if(semicolonPos==-1) {
    m_stopProcessing = true;
    emit errorOccurred(m_styleSheet.mid(0,20) + "...\n " + msg1);      
    return;
  }
 
  int ws=whiteSpaces(semicolonPos+1);
  QPair<QString,unsigned int> tmp(m_styleSheet.left(semicolonPos+1+ws),++m_orderNumber);
  m_stylesheetStructure["@rule"+QString::number(m_orderNumber,10)]=tmp;
  m_styleSheet=m_styleSheet.right(m_styleSheet.length()-semicolonPos-1-ws);
  parse(); 
}
void MainWindow::alStreaming()
{
    bool aceptar;

    // Recogemos la fuente de streaming
    QString url = QInputDialog::getText(this, tr("Reproducir fuente de streaming"),
                                                  tr("Introduzca la URL:"),
                                                  QLineEdit::Normal,
                                                  maximaFM_,
                                                  &aceptar);
    QRegExp whiteSpaces("^\\s+$");

    // Se comprueba que la página no esté vacía
    if (aceptar && !url.isEmpty() && !whiteSpaces.exactMatch(url)) {
        mediaPlayer_->setMedia(QUrl::fromLocalFile(url));
        mediaPlayer_->play();
    }
}
void stylesheetParser::parseAtRules1(){
//TODO this needs to be fixed : in case the at rule is not properly closed the parser hangs
  if(m_styleSheet.find("{") == -1) {
    m_stopProcessing = true;
    emit errorOccurred(m_styleSheet.mid(0,20) + "...\n " + msg2);      
    return;
  }

  int closingParenthesisPos = m_styleSheet.find("}"),
       closingParentheses = 0;
      
  if(closingParenthesisPos==-1) return;
  else closingParentheses = 1;     

  int openingParentheses=0;
  while(true){
   openingParentheses = m_styleSheet.left(closingParenthesisPos+1).contains("{");

    if(openingParentheses==closingParentheses) 
      break;   
    else {
      closingParenthesisPos = m_styleSheet.find("}",closingParenthesisPos+1);
      if( closingParenthesisPos!= -1 )
        closingParentheses++;
      else {
        m_stopProcessing = true;
        emit errorOccurred(m_styleSheet.mid(0,20) + "...\n " + msg1);      
        return;
      }  
    } 
  }

  int ws=whiteSpaces(closingParenthesisPos+1);
  QPair<QString,unsigned int> tmp(m_styleSheet.left(closingParenthesisPos+1+ws),++m_orderNumber);
  m_stylesheetStructure["@rule"+QString::number(m_orderNumber,10)]=tmp;
  m_styleSheet=m_styleSheet.right(m_styleSheet.length()-closingParenthesisPos-1-ws);
  parse(); 
}
stylesheetParser::stylesheetParser(const QString& s){ 
  m_styleSheet = s;
  m_styleSheet=m_styleSheet.right(m_styleSheet.length()-whiteSpaces(0));
  m_stopProcessing = false;
  m_orderNumber = 0; 
}