Ejemplo n.º 1
0
void AbookAddressbook::ensureAbookPath()
{
    if (!QDir::home().exists(".abook")) {
        QDir::home().mkdir(".abook");
    }
    QDir abook(QDir::homePath() + "/.abook/");
    QStringList abookrc;
    QFile file(QDir::homePath() + "/.abook/abookrc");
    if (file.exists() && file.open(QIODevice::ReadWrite|QIODevice::Text)) {
        abookrc = QString::fromLocal8Bit(file.readAll()).split('\n');
        bool havePhoto = false;
        for (QStringList::iterator it = abookrc.begin(), end = abookrc.end(); it != end; ++it) {
            if (it->contains("preserve_fields"))
                *it = "set preserve_fields=all";
            else if (it->contains("photo") && it->contains("field"))
                havePhoto = true;
        }
        if (!havePhoto)
            abookrc << "field photo = Photo";
    } else {
        abookrc << "field photo = Photo" << "set preserve_fields=all";
        file.open(QIODevice::WriteOnly|QIODevice::Text);
    }
    if (file.isOpen()) {
        if (file.isWritable()) {
            file.seek(0);
            file.write(abookrc.join("\n").toLocal8Bit());
        }
        file.close();
    }
}
Ejemplo n.º 2
0
void EditorInterface::makeBatch(QString& batchFileName)
{
	FNTRACE("", "EditorInterface", "batchFileName", batchFileName);

	if (batchFileName.endsWith(".bat", Qt::CaseInsensitive))
		fileName = batchFileName.left(batchFileName.length()-4);
	else
		fileName = batchFileName;

	makeRelativePaths();

	batchFileName = fileName+".bat";
	QString debugFileName = fileName + "_debug.txt";

	QStringList args = makeArgs();

	QFile batchFile(batchFileName);
	if (!batchFile.open(QIODevice::WriteOnly | QIODevice::Text))
		ETHROW(Exception(QString("Failed to open %1 for writing").arg(batchFileName)));
	QTextStream batch(&batchFile);

	batch << "@echo off\n";
	if (QDir::drives().size()>1)
		batch << editorDir.absolutePath().left(2) << "\n";
	batch << "cd \"" << editorDir.absolutePath() << "\"\n" << editorName;
	for (QStringList::iterator arg = args.begin(); arg != args.end(); ++arg)
	{
		batch << ' ';
		if (arg->contains(' '))
			batch << '"'+(*arg)+'"';
		else
			batch << (*arg);
	}
	batch << " > \"" << debugFileName << "\"\n"
			"If ERRORLEVEL 0 goto DONE\n"
			"pause\n"
			":DONE\n";
}