Пример #1
0
/*
 *  Saves the selected messages into a file, all if none selected
 */
void Superconductor_Messages::saveOutput()
{
	QString s = QFileDialog::getSaveFileName(
                    "/home",
                    "Log files (*.log)",
                    this,
                    "save file dialog"
                    "Choose a filename to save under" );
	if ( s ) {
		QFile aFile( s );
		QTextStream stream;
		QString output;
		if ( strings ) {
			output = strings->join( "\n" );
			output += "\n";
		}
		else {
			output = " ";
		}
		if ( aFile.exists() ) {
			switch( QMessageBox::warning( this, "Log Save",
	        "This file already exists. Overwrite?\n",
			"Yes",
	        "No", 0, 0, 1 ) ) {
 			case 0:  // user clicked ok... overwrite file
				aFile.open( IO_WriteOnly | IO_Truncate | IO_Raw );
				aFile.at( 0 );
				stream.setDevice( &aFile );
				stream << output;
				stream.unsetDevice();
				aFile.close();
				this->close();
				break;
			case 1: // The user clicked the Quit or pressed Escape
				break;
			default:
				break;
			}
		}
		else {  // file doesn't exist, just write it
			if ( !s.endsWith( (QString)".log" )) {
				s.append( ".log" );
				aFile.setName( s );
			}
			aFile.open( IO_WriteOnly | IO_Truncate | IO_Raw );
			aFile.at( 0 );
			stream.setDevice( &aFile );
			stream << output;
			stream.unsetDevice();
			aFile.close();
			this->close();
		}
	}
}
Пример #2
0
bool ClassGenerator::finishStreams(const QString& baseName,
                                   QTextStream& headerStream,
                                   QTextStream& sourceStream)
{
    closeIncludeGuard(baseName, headerStream);
    writeFileFooter(headerStream);
    writeFileFooter(sourceStream);

    QIODevice* device = headerStream.device();
    headerStream.unsetDevice();
    delete device;

    device = sourceStream.device();
    sourceStream.unsetDevice();
    delete device;

    return true;
}
//
// 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 ) ;
}