Logo Search packages:      
Sourcecode: qsstv version File versions  Download package

bool configurationFile::readFile ( const char *  name,
const char *  path = NULL,
bool  create = FALSE 
)

Parameters:
name Filename
path Optional pathname
create If TRUE create the configurationfile if it does not exist
Returns:
return TRUE if succesfull

Definition at line 84 of file configfile.cpp.

References configOption::IsStored(), and registerOption().

{

  QFileInfo t;
  QDir ConfigDir;
  QString home;
  QString OptN;
  QString OptV;
  QString s;
  configOption *co;
  configFileName.setFile(name);

  if(path==NULL)
    {
      // try to find it in the local directory
      ConfigDir.setPath(getenv("PWD"));
      configFileName.setFile(ConfigDir,name);
      if (!configFileName.exists())
                        {
                         //try to find it in the HOME directory
                          ConfigDir.setPath(getenv("HOME"));
                              configFileName.setFile(ConfigDir,name);
                        }
    }
  else
    {
      ConfigDir.setPath(path);
      configFileName.setFile(ConfigDir,name); 
    }
  if (!configFileName.exists())
    {
      //      debug("fn=%s",(const char *)configFileName.filePath());
      changed=TRUE;
      QFile inf(configFileName.filePath());
      if(inf.open(IO_WriteOnly))
            {
                  inf.close(); //make one
            return TRUE;
        }
       else
            {
                  return FALSE;
            }
    }
  QFile inf(configFileName.filePath());
  if(!inf.open(IO_ReadOnly))
            {
      return FALSE;
            } 
  QTextStream stream( &inf);
      while (!stream.eof())
            {
                  s=stream.readLine(); //line excluding \n
                  if(processLine(s,OptN,OptV)==1) // 1 if valid option layout
                        {
                          if(optionCheck (OptN,OptV,TRUE)==NULL)
                                    {
                                          if(create)
                                                {
                                                      registerOption(OptN, OptV);   //register the option
                                                }
                                    }
                        }           
    }
  for ( co=optionList.first(); co!= 0; co=optionList.next() )
    {
      if (co->IsStored()==FALSE)
                        {
                        changed=TRUE; // we have registered options that are not in the configfile
                        }
    }
  inf.close();
  return TRUE;  
}


Generated by  Doxygen 1.6.0   Back to index