void ManGenerator::startDoxyAnchor(const char *,const char *manName,
                                   const char *, const char *name,
                                   const char *)
{
    // something to be done?
    if( !Config_getBool("MAN_LINKS") ) 
    {
	return; // no
    }

    // the name of the link file is derived from the name of the anchor:
    // - truncate after an (optional) ::
    QCString baseName = name;
    int i=baseName.findRev(':');
    if (i!=-1) baseName=baseName.right(baseName.length()-i-1);
    
    // - remove dangerous characters and append suffix, then add dir prefix
    QCString fileName=dir+"/"+buildFileName( baseName );
    QFile linkfile( fileName );
    // - only create file if it doesn't exist already
    if ( !linkfile.open( IO_ReadOnly ) ) 
    {
	if ( linkfile.open( IO_WriteOnly ) ) 
        {
	      QTextStream linkstream;
	      linkstream.setDevice(&linkfile);
#if QT_VERSION >= 200
	      linkstream.setEncoding(QTextStream::Latin1);
#endif
	      linkstream << ".so man" << getExtension() << "/" << buildFileName( manName ) << endl;
	}
    }
    linkfile.close();
}
Esempio n. 2
0
void UPnpDeviceDesc::GetValidXML(
    const QString &sBaseAddress, int nPort,
    QTextStream &os, const QString &sUserAgent )
{
#if 0
    os.setEncoding( QTextStream::UnicodeUTF8 );
#endif

    QString BaseAddr;
    QHostAddress addr(sBaseAddress);

    BaseAddr = sBaseAddress;

#if !defined(QT_NO_IPV6)
    // Basically if it appears to be an IPv6 IP surround the IP with []
    //  otherwise don't bother
    if (sBaseAddress.contains(":"))
        BaseAddr = "[" + sBaseAddress + "]";
#endif

    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
          "<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
          " xmlns:mythtv=\"mythtv.org\">\n"
            "<specVersion>\n"
              "<major>1</major>\n"
              "<minor>0</minor>\n"
            "</specVersion>\n"
            "<URLBase>http://"
       << BaseAddr << ":" << nPort << "/</URLBase>\n";

    OutputDevice( os, &m_rootDevice, sUserAgent );

    os << "</root>\n";
    os << flush;
}
//
// Write the data configuration element to the XML output stream. Call
// the appropriate configuration type-specific private function to actually
// perform the writing.
//
bool CDCConfig::WriteConfigFile(wchar_t *configFileName)
{
	QFile* pFile = NULL ;
	QTextStream xmlStream ;

	if (m_configType == DCConfigInvalid) {
		// No valid configuration data
		return( false ) ;
	}

	pFile = new QFile( QString::fromUcs2((const short unsigned int*)configFileName) ) ;
	if (! pFile->open( QIODevice::WriteOnly )) {
		// Fill open error
		return( false ) ;
	}
	xmlStream.setDevice( pFile ) ;
	// Set XML file character encoding
	xmlStream.setEncoding(QTextStream::UnicodeUTF8) ;
	//	xmlStream.setEncoding(QTextStream::Unicode) ;

	xmlStream << "<?xml version=\"1.0\"?>\n" ;
	xmlStream << "<!DOCTYPE dc_configuration SYSTEM \"dcconfig.dtd\">\n";
	xmlStream << "<dc_configuration" ;

	if (m_cpuType.isEmpty())
		m_cpuType = getCurrentCpuType();
	WriteStringAttr(xmlStream, "cpu_type", m_cpuType) ;
	xmlStream << ">\n" ;
	switch( m_configType ) {
		case DCConfigTBP: 
			{
				WriteTBP( xmlStream ) ;
				break ;
			}
		case DCConfigEBP:
			{
				WriteEBP( xmlStream ) ;
				break ;
			}
		case DCConfigTBPPerf:
			{
				WriteTBPPerf( xmlStream ) ;
				break ;
			}
		default:
			break;
	}
	xmlStream << "</dc_configuration>\n" ;

	// Close file and deallocate QFile explicitly
	xmlStream.unsetDevice() ;
	pFile->close() ;
	delete pFile ;
	return( true ) ;
}
void HighlightConfig::save()
{

	QString fileName = locateLocal( "appdata", QString::fromLatin1( "highlight.xml" ) );

	KSaveFile file( fileName );
	if( file.status() == 0 )
	{
		QTextStream *stream = file.textStream();
		stream->setEncoding( QTextStream::UnicodeUTF8 );

		QString xml = QString::fromLatin1(
			"<?xml version=\"1.0\"?>\n"
			"<!DOCTYPE kopete-highlight-plugin>\n"
			"<highlight-plugin>\n" );

			// Save metafilter information.
		QPtrListIterator<Filter> filtreIt( m_filters );
		for( ; filtreIt.current(); ++filtreIt )
		{
			Filter *filtre = *filtreIt;
			xml += QString::fromLatin1( "  <filter>\n    <display-name>" )
				+ QStyleSheet::escape(filtre->displayName)
				+ QString::fromLatin1( "</display-name>\n" );

			xml += QString::fromLatin1("    <search caseSensitive=\"") + QString::number( static_cast<int>( filtre->caseSensitive ) ) +
				QString::fromLatin1("\" regExp=\"") + QString::number( static_cast<int>( filtre->isRegExp ) ) +
				QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->search ) + QString::fromLatin1( "</search>\n" );

			xml += QString::fromLatin1("    <BG set=\"") + QString::number( static_cast<int>( filtre->setBG ) ) +
				QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->BG.name() ) + QString::fromLatin1( "</BG>\n" );
			xml += QString::fromLatin1("    <FG set=\"") + QString::number( static_cast<int>( filtre->setFG ) ) +
				QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->FG.name() ) + QString::fromLatin1( "</FG>\n" );

			xml += QString::fromLatin1("    <importance set=\"") + QString::number( static_cast<int>( filtre->setImportance ) ) +
				QString::fromLatin1( "\">" ) + QString::number( filtre->importance ) + QString::fromLatin1( "</importance>\n" );

			xml += QString::fromLatin1("    <sound set=\"") + QString::number( static_cast<int>( filtre->playSound ) ) +
				QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->soundFN ) + QString::fromLatin1( "</sound>\n" );

			xml += QString::fromLatin1("    <raise set=\"") + QString::number( static_cast<int>( filtre->raiseView ) ) +
				QString::fromLatin1( "\"></raise>\n" );

			xml += QString::fromLatin1( "  </filter>\n" );
		}

		xml += QString::fromLatin1( "</highlight-plugin>\n" );

		*stream << xml;
	}
}
Esempio n. 5
0
void Speech::speak(QString command, bool stdIn, const QString &text, const QString &language, int encoding, QTextCodec *codec) {
   if (text.length () > 0) {
      // 1. prepare the text:
      // 1.a) encode the text
      QTextStream ts (encText, IO_WriteOnly);
      if (encoding == Local)
         ts.setEncoding (QTextStream::Locale);
      else if (encoding == Latin1)
         ts.setEncoding (QTextStream::Latin1);
      else if (encoding == Unicode)
         ts.setEncoding (QTextStream::Unicode);
      else
         ts.setCodec (codec);
      ts << text;

      // 1.b) create a temporary file for the text
      tempFile.setAutoDelete(true);
      QTextStream* fs = tempFile.textStream();
      if (encoding == Local)
         fs->setEncoding (QTextStream::Locale);
      else if (encoding == Latin1)
         fs->setEncoding (QTextStream::Latin1);
      else if (encoding == Unicode)
         fs->setEncoding (QTextStream::Unicode);
      else
         fs->setCodec (codec);
      *fs << text;
      *fs << endl;
      QString filename = tempFile.file()->name();
      tempFile.close();

      // 2. prepare the command:
      command = prepareCommand (command, encText, filename, language);


      // 3. create a new process
      process << command;
      connect(&process, SIGNAL(processExited(KProcess *)), this, SLOT(processExited(KProcess *)));
      connect(&process, SIGNAL(wroteStdin(KProcess *)), this, SLOT(wroteStdin(KProcess *)));
      connect(&process, SIGNAL(receivedStdout(KProcess *, char *, int)), this, SLOT(receivedStdout(KProcess *, char *, int)));
      connect(&process, SIGNAL(receivedStderr(KProcess *, char *, int)), this, SLOT(receivedStderr(KProcess *, char *, int)));

      // 4. start the process
      if (stdIn) {
         process.start(KProcess::NotifyOnExit, KProcess::All);
         if (encText.size() > 0)
            process.writeStdin(encText, encText.size());
         else
            process.closeStdin();
      }
      else
         process.start(KProcess::NotifyOnExit, KProcess::AllOutput);
   }
Esempio n. 6
0
void UPnpDeviceDesc::GetValidXML(
    const QString &/*sBaseAddress*/, int /*nPort*/,
    QTextStream &os, const QString &sUserAgent )
{
#if 0
    os.setEncoding( QTextStream::UnicodeUTF8 );
#endif
    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
          "<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
          " xmlns:mythtv=\"mythtv.org\">\n"
            "<specVersion>\n"
              "<major>1</major>\n"
              "<minor>0</minor>\n"
            "</specVersion>\n";

    OutputDevice( os, &m_rootDevice, sUserAgent );

    os << "</root>\n";
    os << flush;
}
Esempio n. 7
0
FLTableMetaData *FLManager::createSystemTable(const QString &n)
{
#ifndef FL_QUICK_CLIENT
  if (!existsTable(n)) {
    QDomDocument doc(n);
    QDomElement docElem;
    QFile fi(AQ_DATA +
             QString::fromLatin1("/tables/") + n +
             QString::fromLatin1(".mtd"));
    if (!fi.open(IO_ReadOnly)) {
#ifdef FL_DEBUG
      qWarning("FLManager : " + QApplication::tr("Los metadatos para %1 no están definidos").arg(n));
#endif
    } else {
      QTextStream t;
      t.setDevice(&fi);
      t.setEncoding(QTextStream::Latin1);
      QString stream = t.read();

      if (!FLUtil::domDocumentSetContent(doc, stream)) {
#ifdef FL_DEBUG
        qWarning("FLManager::createSystemTable : " + QApplication::tr("Error al cargar los metadatos para la tabla %1").arg(n));
#endif

        return 0;
      } else {
        docElem = doc.documentElement();
        FLTableMetaData *mtd = createTable(metadata(&docElem, true));
        return mtd;
      }
    }
    fi.close();
  }

  return 0;
#else

  return metadata(n, true);
#endif //FL_QUICK_CLIENT
}
void VCardFactory::taskFinished()
{
	JT_VCard *task = (JT_VCard *)sender();
	if ( task->success() ) {
		Jid j = task->jid();

		VCard *vcard = new VCard;
		*vcard = task->vcard();
		checkLimit(j.userHost(), vcard);

		// save vCard to disk
		QFile file ( vCardsDir_ + "/" + JIDUtil::encode(j.userHost()).lower() + ".xml" );
		file.open ( QIODevice::WriteOnly );
		QTextStream out ( &file );
		out.setEncoding ( QTextStream::UnicodeUTF8 );
		QDomDocument doc;
		doc.appendChild( vcard->toXml ( &doc ) );
		out << doc.toString(4);

		emit vcardChanged(j);
	}
}
Esempio n. 9
0
/*! This function updates .ini file in two stages. It copies original .ini file
  into temporary one line by line, replacing/deleting/adding lines as necessary.
  Then it copies temporary file into original one and deletes temporary file.
*/
bool TEIniFile::update()
{
  close();
	if (!f.open(IO_ReadWrite)) return false;
  QString tempfn=f.name()+".tmp";
  QFile tempf(tempfn);
  if (!tempf.open(IO_ReadWrite | IO_Truncate)) return false;
  QTextStream tsorg;
  bool skipsec=false;

  tsorg.setEncoding(QTextStream::UnicodeUTF8);
  tsorg.setDevice(&f);
	ts.setDevice(&tempf); // writeXXX function hardwired to write into ts. So we set it appropriatedly.
	// prepare
  QMap<QString,bool> secProcd, valueProcd; // processedp flag's maps
  QMapIterator<QString,type_ValueList> it1;
  for(it1=SectionList.begin();it1!=SectionList.end();++it1)
  {
    secProcd[it1.key()]=false;
  }
	// scan form sections
	QString line, sec;
	type_Processing pr = P_NONE;	// nothing done yet
	type_ValueList ValueList;

	while (!((line = tsorg.readLine()).isNull())) {
		if ((pr == P_NONE) || (pr == P_SECTION)) {
			// trim line
			line = line.stripWhiteSpace();
			// skip if empty
			if (line.isEmpty())
      {
        writeBreak();
        continue;
      }
			// skip if comment
			if (line.startsWith("#"))
      {
        writeComment(line.mid(1));
        continue;
      }
			// check if section
			if (line.startsWith("[") && line.endsWith("]")) {
				if (pr == P_SECTION) {
					// update previous section
          // write new values
          type_ValueList::iterator it;
          type_ValueList & curSec=SectionList[sec];
          type_ValueList & curSecDef=SectionListDef[sec];
          for(it=curSec.begin();it!=curSec.end();++it)
          {
            if (!valueProcd[it.key()])
            { // this value was not processed yet, hence it's new or just default.
              if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data()) // if it equals default value, skip it.
                ts << it.key() << "\t" << it.data() << "\n";
              valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?).
            }
          }
					secProcd[sec]=true;
				}
				// section found!
        valueProcd.clear(); // get ready for next section
				pr = P_SECTION;
				sec = line.mid(1, line.length()-2).stripWhiteSpace();
        writeSection(sec);
        skipsec=SectionList.find(sec)==SectionList.end() || secProcd[sec]==true; // Skip deleted or already processed section
        type_ValueList & curSec=SectionList[sec];
        type_ValueList::iterator it;
        for(it=curSec.begin();it!=curSec.end();++it)
        {
          valueProcd[it.key()]=false;
        }
				ValueList.clear();
				continue;
			}
			if (pr == P_SECTION) {
				// read name
        if (skipsec)
          continue;
				QString nam;
				int j = 0, l = (int)line.length();
				QChar c;
				while ( (j < l) && !((c = line.ref((uint)j)).isSpace()) ) {
					nam += c;
					j++;
				}
				// read value
        bool rawData=false;
        bool doubleQuotes=false;
				QString val;
				val = line.mid((uint)j).stripWhiteSpace();
				if (val == "data{") {
          rawData=true;
					// read raw data...
					val = "";
					while (!((line = ts.readLine()).isNull())) {
						if (line == "}data") {
							ValueList[nam] = val;
							break;
						}
						val += line + "\n";
					}
				} else {
					// test for ""
					if (val.startsWith("\"") && val.endsWith("\""))
          {
            doubleQuotes=true;
						val = val.mid(1, val.length()-2).stripWhiteSpace();
          }
					ValueList[nam] = val;
				}
        if (SectionList[sec].find(nam)!=SectionList[sec].end() && valueProcd[nam]==false)
        { // write modified value
          if (rawData)
            writeData(nam,SectionList[sec][nam]);
          else if (doubleQuotes)
            writeString(nam,SectionList[sec][nam]);
          else
            ts << nam << "\t" << SectionList[sec][nam] << "\n";
          valueProcd[nam]=true;
        }
			}
      else
        writeComment(line);
		}
	}

	if (pr == P_SECTION) {
		// update last section
    // write new values
    type_ValueList::iterator it;
    type_ValueList & curSec=SectionList[sec];
    type_ValueList & curSecDef=SectionListDef[sec];
    for(it=curSec.begin();it!=curSec.end();++it)
    {
      if (!valueProcd[it.key()])
      { // this value was not processed yet, hence it's new.
        if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data())
          ts << it.key() << "\t" << it.data() << "\n";
        valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?).
      }
    }
		secProcd[sec]=true;
	}
  QMapIterator<QString,bool> it;
  for(it=secProcd.begin();it!=secProcd.end();++it)
  {
    QString sec=it.key();
    if (!it.data())
    {
      writeSection(sec);
      type_ValueList & curSec=SectionList[sec];
      type_ValueList & curSecDef=SectionListDef[sec];
      type_ValueList::iterator it1;
      for(it1=curSec.begin();it1!=curSec.end();++it1)
        if (curSecDef.find(it1.key())==curSecDef.end() || curSecDef[it1.key()]!=it1.data())
          ts << it1.key() << "\t" << it1.data() << "\n";
    }
  }
  tempf.flush();
  if (!tempf.reset())
    return false;
  f.close();
  if (!f.open(IO_WriteOnly | IO_Truncate))
    return false;
  const int N=64*1024;
  char * buf=new char[N];
  Q_LONG len;
  while(true)
  {
    len=tempf.readBlock(buf,N);
    if (len<=0)
      break;
    f.writeBlock(buf,(Q_ULONG)len);
  }
  delete [] buf;
  f.close();
  tempf.close();
  tempf.remove();
  ts.setDevice(&f);
	return len>=0;
}
Esempio n. 10
0
bool K3bCddbQuery::parseEntry( QTextStream& stream, K3bCddbResultEntry& entry )
{
  entry.rawData = "";

  stream.setEncoding( QTextStream::UnicodeUTF8 );

  // parse data
  QString line;
  while( !(line = stream.readLine()).isNull() ) {
    entry.rawData.append(line + "\n");

    // !all fields may be splitted into several lines!
  
    if( line.startsWith( "DISCID" ) ) {
      // TODO: this could be several discids separated by comma!
    }

    else if( line.startsWith( "DYEAR" ) ) {
      QString year = line.mid( 6 );
      if( year.length() == 4 )
	entry.year = year.toInt();
    }
    
    else if( line.startsWith( "DGENRE" ) ) {
      entry.genre = line.mid( 7 );
    }

    else if( line.startsWith( "DTITLE" ) ) {
      entry.cdTitle += line.mid( 7 );
    }
    
    else if( line.startsWith( "TTITLE" ) ) {
      int eqSgnPos = line.find( "=" );
      bool ok;
      uint trackNum = (uint)line.mid( 6, eqSgnPos - 6 ).toInt( &ok );
      if( !ok )
	kdDebug() << "(K3bCddbQuery) !!! PARSE ERROR: " << line << endl;
      else {
	//	kdDebug() << "(K3bCddbQuery) Track title for track " << trackNum << endl;
	
	// make sure the list is big enough
	while( entry.titles.count() <= trackNum )
	  entry.titles.append( "" );
	
	entry.titles[trackNum] += line.mid( eqSgnPos+1 );
      }
    }
    
    else if( line.startsWith( "EXTD" ) ) {
      entry.cdExtInfo += line.mid( 5 );
    }
    
    else if( line.startsWith( "EXTT" ) ) {
      int eqSgnPos = line.find( "=" );
      bool ok;
      uint trackNum = (uint)line.mid( 4, eqSgnPos - 4 ).toInt( &ok );
      if( !ok )
	kdDebug() << "(K3bCddbQuery) !!! PARSE ERROR: " << line << endl;
      else {
	//	kdDebug() << "(K3bCddbQuery) Track extr track " << trackNum << endl;

	// make sure the list is big enough
	while( entry.extInfos.count() <= trackNum )
	  entry.extInfos.append( "" );
	
	entry.extInfos[trackNum] += line.mid( eqSgnPos+1 );
      }
    }
    
    else if( line.startsWith( "#" ) ) {
      //      kdDebug() <<  "(K3bCddbQuery) comment: " << line << endl;
    }
    
    else {
      kdDebug() <<  "(K3bCddbQuery) Unknown field: " << line << endl;
    }
  }

  // now split the titles in the last added match 
  // if no " / " delimiter is present title and artist are the same
  // -------------------------------------------------------------------
  QString fullTitle = entry.cdTitle;
  int splitPos = fullTitle.find( " / " );
  if( splitPos < 0 )
    entry.cdArtist = fullTitle;
  else {
    // split
    entry.cdTitle = fullTitle.mid( splitPos + 3 );
    entry.cdArtist = fullTitle.left( splitPos );
  }


  for( QStringList::iterator it = entry.titles.begin();
       it != entry.titles.end(); ++it ) {
    QString fullTitle = *it;
    int splitPos = fullTitle.find( " / " );
    if( splitPos < 0 )
      entry.artists.append( entry.cdArtist );
    else {
      // split
      *it = fullTitle.mid( splitPos + 3 );
      entry.artists.append( fullTitle.left( splitPos ) );
    }
  }


  // replace all "\\n" with "\n"
  for( QStringList::iterator it = entry.titles.begin();
       it != entry.titles.end(); ++it ) {
    (*it).replace( "\\\\\\\\n", "\\n" );
  }

  for( QStringList::iterator it = entry.artists.begin();
       it != entry.artists.end(); ++it ) {
    (*it).replace( "\\\\\\\\n", "\\n" );
  }

  for( QStringList::iterator it = entry.extInfos.begin();
       it != entry.extInfos.end(); ++it ) {
    (*it).replace( "\\\\\\\\n", "\\n" );
  }

  entry.cdTitle.replace( "\\\\\\\\n", "\\n" );
  entry.cdArtist.replace( "\\\\\\\\n", "\\n" );
  entry.cdExtInfo.replace( "\\\\\\\\n", "\\n" );
  entry.genre.replace( "\\\\\\\\n", "\\n" );

  return true;
}
Esempio n. 11
0
void
CollectionScanner::doJob() //SLOT
{
    std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
    std::cout << "<scanner>";


    QStringList entries;

    if( m_restart ) {
        QFile logFile( m_logfile );
        QString lastFile;
        if ( !logFile.open( IO_ReadOnly ) )
            warning() << "Failed to open log file " << logFile.name() << " read-only"
            << endl;
        else {
            QTextStream logStream;
            logStream.setDevice(&logFile);
            logStream.setEncoding(QTextStream::UnicodeUTF8);
            lastFile = logStream.read();
            logFile.close();
        }

        QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files"   );
        if ( !folderFile.open( IO_ReadOnly ) )
            warning() << "Failed to open folder file " << folderFile.name()
            << " read-only" << endl;
        else {
            QTextStream folderStream;
            folderStream.setDevice(&folderFile);
            folderStream.setEncoding(QTextStream::UnicodeUTF8);
            entries = QStringList::split( "\n", folderStream.read() );
        }

        for( int count = entries.findIndex( lastFile ) + 1; count; --count )
            entries.pop_front();

    }
    else {
        foreachType( QStringList, m_folders ) {
            if( (*it).isEmpty() )
                //apparently somewhere empty strings get into the mix
                //which results in a full-system scan! Which we can't allow
                continue;

            QString dir = *it;
            if( !dir.endsWith( "/" ) )
                dir += '/';

            readDir( dir, entries );
        }

        QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files"   );
        if ( !folderFile.open( IO_WriteOnly ) )
            warning() << "Failed to open folder file " << folderFile.name()
            << " read-only" << endl;
        else {
            QTextStream stream( &folderFile );
            stream.setEncoding(QTextStream::UnicodeUTF8);
            stream << entries.join( "\n" );
            folderFile.close();
        }
    }

    if( !entries.isEmpty() ) {
        if( !m_restart ) {
            AttributeMap attributes;
            attributes["count"] = QString::number( entries.count() );
            writeElement( "itemcount", attributes );
        }

        scanFiles( entries );
    }

    std::cout << "</scanner>" << std::endl;

    quit();
}