Example #1
0
/*!
    \internal

    Generates header of the web service file, based on template located in
    ./qtwsdlconverter/templates/service_header
  */
bool CodeGenerator::createServiceHeader()
{
    QString wsName;
    QMap<QString, QWebMethod *> *tempMap = wsdl->methods();

    if (baseClassName != QString())
        wsName = baseClassName;
    else
        wsName = wsdl->webServiceName();

    QFile file(QString(workingDir.path() + QLatin1String("/")
                       + wsName + QLatin1String(".h")));
    if (!file.open(QFile::WriteOnly | QFile::Text)) // Means \r\n on Windows. Might be a bad idea.
        return enterErrorState(QLatin1String("Error: could not open Web Service"
                                             "header file for writing."));

    QString serviceHeader = logic.readFile("../qtWsdlConverter/templates/service_header");
    int beginIndex = 0;

    serviceHeader.replace("%headerIfndef%", wsName.toUpper() + "_H");
    serviceHeader.replace("%service%", wsName);

    // Includes.
    if (!(flags->flags() & Flags::NoMessagesStructure)) {
        // Include all methods.
        QStringList tempMp = wsdl->methodNames();
        beginIndex = logic.removeTag(serviceHeader, "%include%");

        foreach (QString s, tempMp) {
            QString toInsert = "#include \"" + s + ".h\"" + flags->endLine();
            serviceHeader.insert(beginIndex, toInsert);
            beginIndex += toInsert.length();
        }
/*!
  Converts a directory recursively.
  */
void ConverterCore::convertDirectory(const QDir &input, const QDir &output)
{
    QDir tempInput = input;
    tempInput.makeAbsolute();
    if (!tempInput.exists()) {
        qFatal("Error! Input: %s does not exist!", tempInput.path().toLocal8Bit().data());
    }

    QStringList dirs(tempInput.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
    QStringList files(tempInput.entryList(QDir::Files));

    QDir tempOutput = output;
    tempOutput.makeAbsolute();
    if (!tempOutput.exists()) {
        if (!tempOutput.mkpath(output.path()))
            qFatal("Creating directory failed! %s", tempOutput.path().toLocal8Bit().data());
    }

    foreach (const QString &file, files) {
        ConverterFile converter(tempInput.path() + "/" + file, output.path() + "/" + file, flags);
        converter.convertToQrc();

        if (converter.isErrorState()) {
            enterErrorState(converter.errorMessage());
            return;
        }
    }
void CursorHandler::readHeaderIfNecessary() const
{
    if (state != BeforeHeader)
        return;

    quint16 reserved;
    quint16 type;
    quint16 count;

    QDataStream in(device());
    in.setByteOrder(QDataStream::LittleEndian);

    in >> reserved >> type >> count;
    in.skipRawData(16 * count);

    if (in.status() != QDataStream::Ok || reserved != 0
            || type != 2 || count == 0) {
        enterErrorState();
        return;
    }

    state = BeforeImage;
    currentImageNo = 0;
    numImages = int(count);
}
Example #4
0
/*!
    \internal

    Displays help messages.

    Current implementation is not very nice.
    It simply throws out all the info into successive lines.
    No formatting is used.
*/
void WsdlConverter::displayHelp()
{
    QString helpMessage = QLatin1String(
    "qtwsdlconvert [options] <WSDL file or URL> [output directory] "
    "[base output class name, defaults to web service name]\n\n"
    "Possible options:\n"
    + flags->tab().toLatin1() + "--help (-h),\n"
    + flags->tab().toLatin1() + "--soap10, --soap12, --http, --json, --xml, "
    "--rest={POST, GET, PUT, DELETE, post, get, put, delete}\n"
    + flags->tab().toLatin1() + "--synchronous, --asynchronous (-a),\n"
    + flags->tab().toLatin1() + "--subclass (-s), --full-mode, *--debug-mode, *(partial)--compact-mode, "
    "('mode' can be omitted)\n"
    + flags->tab().toLatin1() + "--standard-structure, --no-messages-structure, --all-in-one-dir-structure, "
    "('structure' can be omitted)\n"
    + flags->tab().toLatin1() + "--qmake, --cmake, --scons, --no-build-system (-n),\n"
    + flags->tab().toLatin1() + "--objSuffix=, --msgSuffix=,\n"
    + flags->tab().toLatin1() + "--endLine={unix, windows},\n"
    + flags->tab().toLatin1() + "--tabulation=, (number of spaces),\n"
    + flags->tab().toLatin1() + "--force (-f).\n\n"
    "Default switches are: \n"
    "--synchronous, --soap12, --standard-structure, --full-mode, --qmake, "
    "--endLine=windows, --tabulation=4.\n"
    "Example use: qtwsdlconverter -af --cmake --scons --json ../webService.asmx\n\n"
    "For detailed description, see README file or \n"
    "https://gitorious.org/qwebservice/qwebservice/blobs/master/doc/README.txt\n\n"
    "qtWsdlConverter Copyright (C) 2011  Tomasz 'sierdzio' Siekierda\n"
    "This program comes with ABSOLUTELY NO WARRANTY.\n"
    "This is free software, and you are welcome to redistribute it\n"
    "under certain conditions, listed in LICENCE.txt.");
    enterErrorState(helpMessage);
}
Example #5
0
/*!
    Performs the WSDL => Qt/C++ code conversion.
  */
void WsdlConverter::convert()
{
    if (errorState) {
        enterErrorState(QLatin1String("Converter is in error state and cannot continue."));
        return;
    }

    displayIntro();
    QString mainPath = qApp->applicationDirPath()
            + QLatin1String("/") + webServiceName();
    QDir mainDir;
    if (outputDir != QString()) {
        if (outputDir.at(0) != QChar('/'))
            mainPath = qApp->applicationDirPath() + QLatin1String("/") + outputDir;
        else
            mainPath = outputDir;
    }
    mainDir.setPath(mainPath);

    if (mainDir.exists() && (flags->isForced() == false)) {
        // Might be good to add an interactive menu here
        enterErrorState(QLatin1String("Error - directory already exists! "
                                      "Use -f or --force to force deleting "
                                      "existing directories."));
        return;
    } else {
        if (flags->isForced() == true) {
            if(removeDir(mainPath)) {
                enterErrorState(QLatin1String("When using '--force': Removing "
                                "preexisting directory failed."));
                return;
            }
        }

        mainDir.mkdir(mainPath);
        mainDir.cd(mainPath);

        if (!CodeGenerator::create(wsdl, mainDir, flags, baseClassName, this)) {
            enterErrorState(QLatin1String("Error - code creation failed."));
            return;
        }
    }
    displayOutro();
    return;
}
Example #6
0
/*!
    \internal

    Manages creation of web service main files - they keep info
    about all web methods, host addresses etc.
  */
bool CodeGenerator::createService()
{
    if (!(flags->flags() & Flags::AllInOneDirStructure))
        workingDir.cd(QLatin1String("headers"));
    if (!createServiceHeader())
        return enterErrorState("Creating header for Web Service \""
                               + wsdl->webServiceName() + "\" failed!");

    if (!(flags->flags() & Flags::AllInOneDirStructure)) {
        workingDir.cdUp();
        workingDir.cd("sources");
    }

    if (!createServiceSource())
        return enterErrorState("Creating source for Web Service \""
                               + wsdl->webServiceName() + "\" failed!");

    if (!(flags->flags() & Flags::AllInOneDirStructure))
        workingDir.cdUp();
    return true;
}
/*!
  Main conversion routine.
  */
void ConverterCore::convert()
{
    if (helpMode)
        return;

    if ((flags->inputDirectory() == flags->outputDirectory())
            && !(flags->flags() & ConverterFlags::Force)
            && !(flags->flags() & ConverterFlags::Suffix)) {
        enterErrorState("Will not overwrite without --force or a given --suffix.");
        return;
    }

    QString input;
    QString output;

    if (flags->inputDirectory() == "") {
        input = ".";
    } else {
        input = flags->inputDirectory();
    }

    if (flags->outputDirectory() == "") {
        output = ".";
    } else {
        output = flags->outputDirectory();
    }

    QDir inputDir(input);
    QDir outputDir(output);

    convertDirectory(inputDir, outputDir);

    ConverterQrcGenerator qrcGenerator(flags, this);
    qrcGenerator.createQrcFiles();
    if (qrcGenerator.isErrorState()) {
        enterErrorState(qrcGenerator.errorMessage());
    }
}
Example #8
0
/*!
    Uses application's arguments (\a appArguments) to initialise
    QWsdl Flags and itself, and \a parent to construct the object.
  */
WsdlConverter::WsdlConverter(const QStringList &appArguments, QObject *parent) :
    QObject(parent)
{
    flags = new Flags();
    argList = new QMap<int, QVariant>();
    // Dummy wsdl to prevent segfaulting when parsing arguments fails.
    wsdl = new QWsdl(this);
    errorState = false;
//    errorMessage = "";

    QString applicationName = qApp->applicationFilePath().mid(
                qApp->applicationDirPath().length() + 1);

    if ((appArguments.length() == 0)
            || (appArguments.contains(QLatin1String("--help")))
            || (appArguments.contains(QLatin1String("-h")))
            || (appArguments.length() == 1
                && (appArguments.at(0) == qApp->applicationFilePath()
                    || appArguments.at(0) == (QLatin1String("./") + applicationName)
                    || appArguments.at(0) == applicationName)
                )) {
        displayHelp();
        return;
    }

    if (!parseArguments(appArguments)) {
        enterErrorState(QLatin1String("Encountered an error when parsing arguments."));
        return;
    }

    baseClassName = argList->value(ClassName).toString();
    outputDir = argList->value(Dir).toString();
    wsdl->setWsdlFile(argList->value(Path).toString());
    if (wsdl->isErrorState())
        enterErrorState(QLatin1String("WSDL error!"));
}
Example #9
0
/*!
  Initialises the config and important variables, used later in QML.

  Currently uses global object in UI mode changing. This is wrong, should and will
  be fixed.
  */
CcfConfig::CcfConfig(const QString &configFilePath, CcfLogger *logger, QObject *parent) :
    QObject(parent), CcfError(), mFilePath(configFilePath), mLogger(logger)
{
    mConfiguration = new CcfConfigData();
    mParser = new CcfConfigParser(mFilePath, this);
    mTerrainInfoMode = "OFF";

    if (!mParser->isErrorState()) {
        mConfiguration = mParser->configuration();
        mRuntimeWidth = mConfiguration->value("width").toInt();
        mRuntimeHeight = mConfiguration->value("height").toInt();
        parseValidKeyboardShortcuts();
    } else {
        enterErrorState(mParser->errorMessage());
    }
}
/*!
  Sets internal flags (ConverterFlags).
  */
void ConverterCore::setFlags(const QStringList &args)
{
    bool result = false;

    // If first arg is not a flag - it's probably the app name.
    // In such a case, that arg will be discarded.
    if (!args.at(0).startsWith(QChar('-')) && !args.at(0).startsWith(QLatin1String("--"))) {
        result = flags->setFlags(args.mid(1));
    } else {
        result = flags->setFlags(args);
    }

    if (!result) {
        enterErrorState(flags->errorMessage());
    }
}
/*!
  Saves game state to a file.

  For now, it always uses file with name "saves/save1.qml".
  */
void CcfGameManager::saveGame(const QObjectList &unitList,
                              const QString &mapFile,
                              const QString &saveFileName)
{
    // As a first attempt, I will generate the whole file myself.
    // A better approach for the future might be to copy and modify
    // a real scenario file, OR create a QML element like ScenarioLoader
    // which would have "map", "units" properties.

    // Init. Read template.
    QFile templateFile("src/config/saveFileTemplate.txt");
    if (!templateFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qFatal("Template file could not be read! Cannot continue, bailing out.");
        return;
    }

    // File numbers incrementation should go here, or at least overwrite warnings!
    QFile saveFile(saveFileName);
    if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        enterErrorState("Could not save the file: " + saveFileName);
        return;
    }

    QString fileContent = templateFile.readAll();

    // Fill template with given data.
    fileContent.replace("%customImports%", "");
    fileContent.replace("%mapFile%", mapFile);

    // Save units. Hope this will work.
    QString units;
    foreach (QObject *obj, unitList) {
        // In release code, this needs to include order queue,
        // soldier states, damages etc.
        CcfQmlBaseUnit *unit = CcfQmlBaseUnit::ccfUnit(obj);
        units += mTab + unit->getUnitFileName() + " {\n"
                + mTab + mTab + "objectName: \"" + unit->objectName() + "\"\n"
                + mTab + mTab + "x: " + unit->getString("x") + "\n"
                + mTab + mTab + "y: " + unit->getString("y") + "\n"
                + mTab + mTab + "rotation: " + unit->getString("rotation") + "\n"
                + mTab + mTab + "unitSide: \"" + unit->getUnitSide() + "\"\n"
                + mTab + mTab + "state: \"" + unit->getString("state") + "\"\n";
        units += addSavePropertyIfExists(unit, "turretRotation");
        units += addSavePropertyIfExists(unit, "hullColor", true);
        units += mTab + "}\n";
    }
Example #12
0
/*!
  Triggers configuration save (to "config" and "config_old" files).
  */
bool CcfConfig::saveConfig()
{
    // Put screen size checks here!
    if (mConfiguration->value("remember dimensions on exit") == "true") {
        if (mConfiguration->value("height").toInt() != mRuntimeHeight) {
            mConfiguration->replace("height", QString::number(mRuntimeHeight));
        }
        if (mConfiguration->value("width").toInt() != mRuntimeWidth) {
            mConfiguration->replace("width", QString::number(mRuntimeWidth));
        }
    }


    mSaver = new CcfConfigSaver(mConfiguration, mParser->configIndexes(),
                               mFilePath, this);
    mSaver->updateConfigFile();

    if (mSaver->isErrorState()) {
        enterErrorState("Saving config file failed. Error: " + mSaver->errorMessage());
        return false;
    }

    return true;
}
bool CursorHandler::read(QImage *image)
{
    readHeaderIfNecessary();

    if (state != BeforeImage)
        return false;

    quint32 size;
    quint32 width;
    quint32 height;
    quint16 numPlanes;
    quint16 bitsPerPixel;
    quint32 compression;

    QDataStream in(device());
    in.setByteOrder(QDataStream::LittleEndian);
    in >> size;
    if (size != 40) {
        enterErrorState();
        return false;
    }
    in >> width >> height >> numPlanes >> bitsPerPixel >> compression;
    height /= 2;

    if (numPlanes != 1 || bitsPerPixel != 1 || compression != 0) {
        enterErrorState();
        return false;
    }

    in.skipRawData((size - 20) + 8);

    QBitArray xorBitmap = readBitmap(width, height, in);
    QBitArray andBitmap = readBitmap(width, height, in);

    if (in.status() != QDataStream::Ok) {
        enterErrorState();
        return false;
    }

    *image = QImage(width, height, QImage::Format_ARGB32);

    for (int i = 0; i < int(height); ++i) {
        for (int j = 0; j < int(width); ++j) {
            QRgb color;
            int bit = (i * width) + j;

            if (andBitmap.testBit(bit)) {
                if (xorBitmap.testBit(bit)) {
                    color = 0x7F7F7F7F;
                } else {
                    color = 0x00FFFFFF;
                }
            } else {
                if (xorBitmap.testBit(bit)) {
                    color = 0xFFFFFFFF;
                } else {
                    color = 0xFF000000;
                }
            }
            image->setPixel(j, i, color);
        }
    }

    ++currentImageNo;
    if (currentImageNo == numImages)
        state = AfterLastImage;
    return true;
}
Example #14
0
/*!
    \internal

    Reads application's command line, sets Flags, paths etc.
  */
bool WsdlConverter::parseArguments(const QStringList &arguments)
{
    bool wasFile = false;
    bool wasOutDir = false;
    bool wasClassName = false;
    bool endOfOptions = false;
    QString appFilePath = qApp->applicationFilePath();

    foreach (QString s, arguments) {
        // Handles '--' arguments
        if (s.startsWith(QLatin1String("--")) && (endOfOptions == false)) {
            // End of options:
            if (s == QLatin1String("--")) {
                endOfOptions = true;
                continue;
            } else if (s == QLatin1String("--soap12")) { // Protocol flags:
                flags->resetFlags(Flags::Soap10 | Flags::Http
                                  | Flags::Json | Flags::Xml);
                flags->setFlags(Flags::Soap12);
            } else if (s == QLatin1String("--soap10")) {
                flags->resetFlags(Flags::Soap12 | Flags::Http
                                  | Flags::Json | Flags::Xml);
                flags->setFlags(Flags::Soap10);
            } else if (s == QLatin1String("--soap")) {
                flags->resetFlags(Flags::Http | Flags::Json | Flags::Xml);
                flags->setFlags(Flags::Soap);
            } else if (s == QLatin1String("--http")) {
                flags->resetFlags(Flags::Soap | Flags::Json | Flags::Xml);
                flags->setFlags(Flags::Http);
            } else if (s == QLatin1String("--json")) {
                flags->resetFlags(Flags::Soap | Flags::Http | Flags::Xml);
                flags->setFlags(Flags::Json);
            } else if (s == QLatin1String("--xml")) {
                flags->resetFlags(Flags::Soap | Flags::Http | Flags::Json);
                flags->setFlags(Flags::Xml);
            } else if (s.startsWith(QLatin1String("--rest"))) {
                flags->setFlags(Flags::Rest);
                // Set HTTP method:
                if (s == QLatin1String("--rest")) {
                    flags->setHttpMethod(Flags::Post);
                } else if (s.startsWith(QLatin1String("--rest="))) {
                    if (!flags->setHttpMethod(s.mid(7)))
                        return false;
                }
            } else if (s == QLatin1String("--synchronous")) { // Synchronousness:
                flags->resetFlags(Flags::Asynchronous);
                flags->setFlags(Flags::Synchronous);
            } else if (s == QLatin1String("--asynchronous")) {
                flags->resetFlags(Flags::Synchronous);
                flags->setFlags(Flags::Asynchronous);
            } else if (s == QLatin1String("--subclass")) { // Modes:
                flags->resetFlags(Flags::DebugMode
                                  | Flags::CompactMode
                                  | Flags::FullMode);
                flags->setFlags(Flags::Subclass);
            } else if ((s == QLatin1String("--full-mode"))
                        || (s == QLatin1String("--full"))) {
                flags->resetFlags(Flags::DebugMode
                                  | Flags::CompactMode
                                  | Flags::Subclass);
                flags->setFlags(Flags::FullMode);
            } else if ((s == QLatin1String("--debug-mode"))
                        || (s == QLatin1String("--debug"))) {
                flags->resetFlags(Flags::FullMode
                                  | Flags::CompactMode
                                  | Flags::Subclass);
                flags->setFlags(Flags::DebugMode);
            } else if ((s == QLatin1String("--compact-mode"))
                        || (s == QLatin1String("--compact"))) {
                flags->resetFlags(Flags::FullMode
                                  | Flags::CompactMode
                                  | Flags::Subclass);
                flags->setFlags(Flags::CompactMode);
            } else if ((s == QLatin1String("--standard-structure"))
                       || (s == QLatin1String("--standard"))) {
                // Structures:
                flags->resetFlags(Flags::NoMessagesStructure
                                  | Flags::AllInOneDirStructure);
                flags->setFlags(Flags::StandardStructure);
            } else if ((s == QLatin1String("--no-messages-structure"))
                       || (s == QLatin1String("--no-messages"))) {
                flags->resetFlags(Flags::StandardStructure
                                  | Flags::AllInOneDirStructure);
                flags->setFlags(Flags::NoMessagesStructure);
            } else if ((s == QLatin1String("--all-in-one-dir-structure"))
                     || (s == QLatin1String("--all-in-one-dir"))) {
                flags->resetFlags(Flags::StandardStructure
                                  | Flags::NoMessagesStructure);
                flags->setFlags(Flags::AllInOneDirStructure);
            } else if (s == QLatin1String("--qmake")) {
                // Build systems (qmake, cmake and scons can be build simultaneously):
                flags->setFlags(Flags::Qmake);
            } else if (s == QLatin1String("--cmake")) {
                flags->setFlags(Flags::Cmake);
            } else if (s == QLatin1String("--scons")) {
                flags->setFlags(Flags::Scons);
            } else if (s == QLatin1String("--no-build-system")) {
                flags->resetFlags(Flags::Qmake | Flags::Cmake | Flags::Scons);
                flags->setFlags(Flags::NoBuildSystem);
            } else if (s.startsWith(QLatin1String("--msgSuffix="))) {
                // Suffixes:
                flags->setMethodSuffix(s.mid(12));
            } else if (s.startsWith(QLatin1String("--objSuffix="))) {
                flags->setObjectSuffix(s.mid(12));
            } else if (s.startsWith(QLatin1String("--endLine="))) {
                // End line:
                flags->setEndLine(s.mid(10));
            } else if (s.startsWith(QLatin1String("--tabulation="))) {
                // Tabulation:
                flags->setTab(s.mid(13).toInt());
            } else if (s == QLatin1String("--force")) { // Force:
                flags->setForced(true);
            } else {
                qWarning() << "WARNING: unrecognised command: "
                           << s << ". Converter will continue.";
            }
        } else if (s.startsWith(QLatin1String("-")) && (endOfOptions == false)) {
            // Handles '-' arguments
            for (int i = 1; i < s.size(); i++) {
                QChar chr = s.at(i);

                if (chr == ('a')) {
                    flags->resetFlags(Flags::Synchronous);
                    flags->setFlags(Flags::Asynchronous);
                } else if (chr == ('s')) {
                    flags->resetFlags(Flags::DebugMode
                                      | Flags::CompactMode
                                      | Flags::FullMode);
                    flags->setFlags(Flags::Subclass);
                } else if (chr == ('n')) {
                    flags->resetFlags(Flags::Qmake
                                      | Flags::Cmake
                                      | Flags::Scons);
                    flags->setFlags(Flags::NoBuildSystem);
                } else if (chr == ('f')) {
                    flags->setForced(true);
                } else {
                    qWarning() << "WARNING: unrecognised command: "
                               << s << ". Converter will continue.";
                }
            }
        } else if ((s != QString()) && (s != appFilePath)) {
            // Handles file names, class name etc.
            // Handles wsdl file, base class name, output dir.
            if (!wasFile) {
                wasFile = true;
                QString tmp = s;
                QUrl tempUrl(tmp);

                if (!QFile::exists(tmp) && tempUrl.isValid()) {
                    argList->insert(Path, tmp);;
                } else {
                    QFileInfo tempInfo(tmp);

                    if (tempInfo.isRelative()) {
                        tmp.prepend(qApp->applicationDirPath() + "/");
                        argList->insert(Path, tmp);
                    }
                }
            } else if (!wasOutDir) {
                wasOutDir = true;
                argList->insert(Dir, s);
            } else if (!wasClassName) {
                wasClassName = true;
                argList->insert(ClassName, s);
            }
        }
    }

    if (wasFile == false) {
        enterErrorState(QLatin1String("No WSDL file specified, conversion can no continue. "
                        "For help, type wsdlConvert --help."));
        return false;
    }

    return true;
}