Beispiel #1
0
// load from a file
bool QSgml::load(const QString &sFileName)
{
    QFile fileText( QDir::cleanPath(sFileName) );
    bool qExists = fileText.exists();

    // delete old elements
    delete DocTag;

    //delete EndTag;
    // create new doc-tag
    DocTag = new QSgmlTag("DocTag",QSgmlTag::eVirtualBeginTag,NULL);
    EndTag = new QSgmlTag("EndTag",QSgmlTag::eVirtualEndTag,DocTag);

    // set EndTag as only Child of DocTag
    DocTag->Children.append(EndTag);

    // read the file
    if( qExists==true )
    {
        fileText.open(QIODevice::ReadOnly);
        sSgmlString = fileText.readAll();
        dirPath = QFileInfo(sFileName).absoluteDir();
    }

    // create elements
    String2Sgml(sSgmlString);

    return(qExists);
}
Beispiel #2
0
 virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv)
 {
   //It's really text, not a molecule.
   OBText* pText = dynamic_cast<OBText*>(pOb);
   string fileText(istreambuf_iterator<char>(*pConv->GetInStream()), istreambuf_iterator<char>());
   pText->SetText(fileText);
   return !fileText.empty();
 }
Beispiel #3
0
QString VUtils::readFileFromDisk(const QString &filePath)
{
    QFile file(filePath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qWarning() << "fail to open file" << filePath << "to read";
        return QString();
    }
    QString fileText(file.readAll());
    file.close();
    qDebug() << "read file content:" << filePath;
    return fileText;
}
Beispiel #4
0
// save to a file
bool QSgml::save(const QString &sFileName)
{
    QFile fileText( QDir::cleanPath(sFileName) );
    qint64 s64_Count = 0;

    // write to file
    if( fileText.open(QIODevice::WriteOnly)==true )
    {
        s64_Count = fileText.write( sSgmlString.toLocal8Bit() );
        dirPath = QFileInfo(sFileName).absoluteDir();
    }

    if( s64_Count>=0 )
        return(true);
    else
        return(false);
}
Beispiel #5
0
bool DkUpnpDeviceHost::startDevicehost(QString pathToConfig) {
	qDebug() << "pathToConfig:" << pathToConfig;
	qDebug() << "starting DeviceHost";
	QFile f(pathToConfig);
	if (!f.exists()) {
		qDebug() << "DkUpnpDeviceHost: config file not found";
		return false;
	}

	QUuid uuid = QUuid::createUuid();
	QString uuidString = uuid.toString();
	uuidString.replace("{","");
	uuidString.replace("}","");
	QString newXMLpath = QDir::tempPath() + QDir::separator() + uuidString + ".xml";
	

	QByteArray fileData;
	f.open(QIODevice::ReadOnly);
	//f.seek(0);
	fileData = f.readAll();
	f.close();
	QString fileText(fileData);
	fileText.replace("insert-new-uuid-here", uuidString);
#ifdef WIN32
	fileText.replace("nomacs-service.xml", QDir::temp().dirName()+"/nomacs-service.xml");
#else
	fileText.replace("nomacs-service.xml", "/nomacs-service.xml");
#endif // WIN32
	
	QFile newDescriptorFile(newXMLpath);
	newDescriptorFile.open(QIODevice::WriteOnly);
	newDescriptorFile.write(fileText.toUtf8());
	qDebug() << "writing file:" << newXMLpath;
	newDescriptorFile.close();

	QFileInfo fileInfo = QFileInfo(f);
	QFile serviceXML(fileInfo.absolutePath() + QDir::separator() + "nomacs-service.xml");
	if (!serviceXML.open(QIODevice::ReadOnly))
		qDebug() << "nomacs-service.xml file does not exist";
	
	// copy the resource file to the user tmp folder
	QString newServiceXMLPath = QDir::tempPath()+ QDir::separator() + "nomacs-service.xml";
	QFile tmpServiceXmlFile(newServiceXMLPath);
	tmpServiceXmlFile.open(QIODevice::WriteOnly);
	tmpServiceXmlFile.write(serviceXML.readAll());
	tmpServiceXmlFile.close();
	serviceXML.close();
	
	//if(!QFile::exists(newServiceXMLPath)) {
	//	if (!serviceXML.copy(newServiceXMLPath))
	//		qDebug() << "unable to copy nomacs-service.xml to " << newServiceXMLPath << ", perhaps files already exists";
	//}
	QFile newServiceXMLFile(QDir::tempPath()+ QDir::separator() + "nomacs-service.xml");
	serviceXML.close();
	DkUpnpDeviceModelCreator creator;

	Herqq::Upnp::HDeviceHostConfiguration hostConfig;
	hostConfig.setDeviceModelCreator(creator);
	
	Herqq::Upnp::HDeviceConfiguration config;
	//config.setPathToDeviceDescription(pathToConfig);
	config.setPathToDeviceDescription(newXMLpath);
	
	hostConfig.add(config);
	
	bool retVal = init(hostConfig);
	if (!retVal) {
		qDebug() << "error while initializing device host:\n" << errorDescription();
	}

	if(!newDescriptorFile.remove()) 
		qDebug() << "unable to remove upnp device.xml file";
	// this->serviceXMLPath = newServiceXMLPath;

	if (!tmpServiceXmlFile.remove())
		qDebug() << tmpServiceXmlFile.errorString();

	//qDebug() << "newServiceXMLPath" << newServiceXMLPath;
	//if(!QFile::remove(newServiceXMLPath))
		//qDebug() << "unable to remove upnp service.xml file";
	return retVal;
}