Пример #1
0
void KoXmlWriter::addProcessingInstruction( const char* cstr )
{
    prepareForTextNode();
    writeCString( "<?" );
    addTextNode( cstr );
    writeCString( "?>");
}
Пример #2
0
void KoXmlWriter::addConfigItem( const QString & configName, short value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type", "short" );
    addTextNode( QString::number( value ) );
    endElement();
}
Пример #3
0
void KoXmlWriter::addConfigItem( const QString & configName, bool value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type",  "boolean" );
    addTextNode( value ? "true" : "false" );
    endElement();
}
Пример #4
0
void KoXmlWriter::addConfigItem( const QString & configName, const QString& value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type",  "string" );
    addTextNode( value );
    endElement();
}
Пример #5
0
void Parser::flush(const char* end) {
	int len = end - mNodeStart;
	EASSERT(len >= 0);
	if(len > 0) {
		addTextNode(mNodeStart, len);
		mNodeStart = end;
	}
}
Пример #6
0
void KoXmlWriter::addTextSpan( const QString& text, const QMap<int, int>& tabCache )
{
    uint len = text.length();
    int nrSpaces = 0; // number of consecutive spaces
    bool leadingSpace = false;
    QString str;
    str.reserve( len );

    // Accumulate chars either in str or in nrSpaces (for spaces).
    // Flush str when writing a subelement (for spaces or for another reason)
    // Flush nrSpaces when encountering two or more consecutive spaces
    for ( uint i = 0; i < len ; ++i ) {
        QChar ch = text[i];
        if ( ch != ' ' ) {
            if ( nrSpaces > 0 ) {
                // For the first space we use ' '.
                // "it is good practice to use (text:s) for the second and all following SPACE 
                // characters in a sequence." (per the ODF spec)
                // however, per the HTML spec, "authors should not rely on user agents to render 
                // white space immediately after a start tag or immediately before an end tag"
                // (and both we and OO.o ignore leading spaces in <text:p> or <text:h> elements...)
                if (!leadingSpace)
                {
                    str += ' ';
                    --nrSpaces;
                }
                if ( nrSpaces > 0 ) { // there are more spaces
                    if ( !str.isEmpty() )
                        addTextNode( str );
                    str = QString::null;
                    startElement( "text:s" );
                    if ( nrSpaces > 1 ) // it's 1 by default
                        addAttribute( "text:c", nrSpaces );
                    endElement();
                }
            }
            nrSpaces = 0;
            leadingSpace = false;
        }
        switch ( ch.unicode() ) {
        case '\t':
            if ( !str.isEmpty() )
                addTextNode( str );
            str = QString::null;
            startElement( "text:tab" );
            if ( tabCache.contains( i ) )
                addAttribute( "text:tab-ref", tabCache[i] + 1 );
            endElement();
            break;
        case '\n':
            if ( !str.isEmpty() )
                addTextNode( str );
            str = QString::null;
            startElement( "text:line-break" );
            endElement();
            break;
        case ' ':
            if ( i == 0 )
                leadingSpace = true;
            ++nrSpaces;
            break;
        default:
            str += text[i];
            break;
        }
    }
    // either we still have text in str or we have spaces in nrSpaces
    if ( !str.isEmpty() ) {
        addTextNode( str );
    }
    if ( nrSpaces > 0 ) { // there are more spaces
        startElement( "text:s" );
        if ( nrSpaces > 1 ) // it's 1 by default
            addAttribute( "text:c", nrSpaces );
        endElement();
    }
}
Пример #7
0
void KoXmlWriter::addTextSpan(const QString& text, const QMap<int, int>& tabCache)
{
    int len = text.length();
    int nrSpaces = 0; // number of consecutive spaces
    bool leadingSpace = false;
    QString str;
    str.reserve(len);

    // Accumulate chars either in str or in nrSpaces (for spaces).
    // Flush str when writing a subelement (for spaces or for another reason)
    // Flush nrSpaces when encountering two or more consecutive spaces
    for (int i = 0; i < len ; ++i) {
        QChar ch = text[i];
        ushort unicode = ch.unicode();
        if (unicode == ' ') {
            if (i == 0)
                leadingSpace = true;
            ++nrSpaces;
        } else {
            if (nrSpaces > 0) {
                // For the first space we use ' '.
                // "it is good practice to use (text:s) for the second and all following SPACE
                // characters in a sequence." (per the ODF spec)
                // however, per the HTML spec, "authors should not rely on user agents to render
                // white space immediately after a start tag or immediately before an end tag"
                // (and both we and OO.o ignore leading spaces in <text:p> or <text:h> elements...)
                if (!leadingSpace) {
                    str += ' ';
                    --nrSpaces;
                }
                if (nrSpaces > 0) {   // there are more spaces
                    if (!str.isEmpty())
                        addTextNode(str);
                    str.clear();
                    startElement("text:s");
                    if (nrSpaces > 1)   // it's 1 by default
                        addAttribute("text:c", nrSpaces);
                    endElement();
                }
            }
            nrSpaces = 0;
            leadingSpace = false;

            switch (unicode) {
            case '\t':
                if (!str.isEmpty())
                    addTextNode(str);
                str.clear();
                startElement("text:tab");
                if (tabCache.contains(i))
                    addAttribute("text:tab-ref", tabCache[i] + 1);
                endElement();
                break;
            // gracefully handle \f form feed in text input.
            // otherwise the xml will not be valid.
            // \f can be added e.g. in ascii import filter.
            case '\f':
            case '\n':
            case QChar::LineSeparator:
                if (!str.isEmpty())
                    addTextNode(str);
                str.clear();
                startElement("text:line-break");
                endElement();
                break;
            default:
                // don't add stuff that is not allowed in xml. The stuff we need we have already handled above
                if (ch.unicode() >= 0x20) {
                    str += text[i];
                }
                break;
            }
        }
    }
    // either we still have text in str or we have spaces in nrSpaces
    if (!str.isEmpty()) {
        addTextNode(str);
    }
    if (nrSpaces > 0) {   // there are more spaces
        startElement("text:s");
        if (nrSpaces > 1)   // it's 1 by default
            addAttribute("text:c", nrSpaces);
        endElement();
    }
}
Пример #8
0
// Write out the config file for the whole application
int configAppSaveXml()
{
	if (bCmdOptUsed) {
		return 1;
	}

	char configName[MAX_PATH];
	createConfigName(configName);

	try {
		char tempStr[64] = "";

		// root
		ticpp::Document doc;
		ticpp::Declaration decl("1.0", "UTF-8", "");
		doc.LinkEndChild(&decl);

		ticpp::Element root("configuration");
		setAttr(root, "version", configVersion);
		ticpp::Comment comment("Don't edit this file manually unless you know what you're doing\n" \
					APP_TITLE " will restore default settings when this file is deleted");
		doc.LinkEndChild(&comment);
		doc.LinkEndChild(&root);

		// title
		sprintf(tempStr, "0x%06X", nBurnVer);
		addTextNode(root, "version", tempStr);

		// emulation
		ticpp::Element emulation("emulation");
		root.LinkEndChild(&emulation);
		setAttr(emulation, "asm-68k", bBurnUseASM68K);
		setAttr(emulation, "all-ram", bDrvSaveAll);

		// video
		ticpp::Element video("video");
		root.LinkEndChild(&video);

		ticpp::Element fullscreen("fullscreen");
		video.LinkEndChild(&fullscreen);
		setAttr(fullscreen, "width", nVidWidth);
		setAttr(fullscreen, "height", nVidHeight);
		setAttr(fullscreen, "depth", nVidDepth);
		setAttr(fullscreen, "refresh", nVidRefresh);

		ticpp::Element adjust("adjust");
		video.LinkEndChild(&adjust);
		setAttr(adjust, "rotate-vertical", nVidRotationAdjust);

		ticpp::Element screen_size("screen-size");
		video.LinkEndChild(&screen_size);
		setAttr(screen_size, "window", nWindowSize);

		ticpp::Element window_position("window-position");
		video.LinkEndChild(&window_position);
		setAttr(window_position, "x", nWindowPosX);
		setAttr(window_position, "y", nWindowPosY);

		ticpp::Element stretch("stretch");
		video.LinkEndChild(&stretch);
		setAttr(stretch, "full-stretch", bVidFullStretch);
		setAttr(stretch, "correct-aspect", bVidCorrectAspect);

		ticpp::Element color("color");
		video.LinkEndChild(&color);
		setAttr(color, "enable", bcolorAdjust);
		setAttr(color, "contrast", color_contrast);
		setAttr(color, "brightness", color_brightness);
		setAttr(color, "gamma", color_gamma);
		setAttr(color, "grayscale", color_grayscale);
		setAttr(color, "invert", color_invert);

		ticpp::Element vsync("vsync");
		video.LinkEndChild(&vsync);
		setAttr(vsync, "enable", bVidVSync);

		ticpp::Element triple_buffer("triple-buffer");
		video.LinkEndChild(&triple_buffer);
		setAttr(triple_buffer, "enable", bVidTripleBuffer);

		// video render
		ticpp::Element render("render");
		video.LinkEndChild(&render);

		ticpp::Element render_driver("render-driver");
		render.LinkEndChild(&render_driver);
		setAttr(render_driver, "driver", nVidSelect);
		setAttr(render_driver, "adapter", nVidAdapter);

		ticpp::Element filter("filter");
		render.LinkEndChild(&filter);
		setAttr(filter, "linear", vidFilterLinear);
		setAttr(filter, "use-pixelfilter", vidUseFilter);
		setAttr(filter, "pixel-filter", nVidFilter);

		ticpp::Element option("option");
		render.LinkEndChild(&option);
		setAttr(option, "force-16bit", bVidForce16bit);
		setAttr(option, "hardware-vertex", vidHardwareVertex);
		setAttr(option, "motion-blur", vidMotionBlur);
		setAttr(option, "projection", nVid3DProjection);
		setAttr(option, "angel", fVidScreenAngle);
		setAttr(option, "curvature", fVidScreenCurvature);
		setAttr(option, "dxmanager", nVidDXTextureManager);

		setAttr(option, "x-offset", nXOffset);
		setAttr(option, "y-offset", nYOffset);
		setAttr(option, "x-scale",  nXScale);
		setAttr(option, "y-scale",  nYScale);

		// video others
		ticpp::Element monitor("monitor");
		video.LinkEndChild(&monitor);
		setAttr(monitor, "auto-aspect", autoVidScrnAspect);
		setAttr(monitor, "aspect-x", nVidScrnAspectX);
		setAttr(monitor, "aspect-y", nVidScrnAspectY);

		ticpp::Element frame("frame");
		video.LinkEndChild(&frame);
		setAttr(frame, "auto-frameskip", autoFrameSkip);
		setAttr(frame, "force-60hz", bForce60Hz);

		// audio
		ticpp::Element audio("audio");
		root.LinkEndChild(&audio);
		addTextNode(audio, "sound", audSelect);

		ticpp::Element device("device");
		audio.LinkEndChild(&device);
		setAttr(device, "ds", dsDevice);
		setAttr(device, "xa2", xa2Device);
		setAttr(device, "oal", oalDevice);

		ticpp::Element audio_set("setting");
		audio.LinkEndChild(&audio_set);
		setAttr(audio_set, "rate", nAudSampleRate);
		setAttr(audio_set, "frame", nAudSegCount);
		setAttr(audio_set, "dsp", nAudDSPModule);
		setAttr(audio_set, "pcm-interp", nInterpolation);
		setAttr(audio_set, "fm-interp", nFMInterpolation);
		setAttr(audio_set, "stereo-upmix", audStereoUpmixing);

		// gui
		ticpp::Element gui("gui");
		root.LinkEndChild(&gui);
		addTextNode(gui, "language", szLanguage);
		//addTextNode(gui, "gamelist", szTransGamelistFile);

		ticpp::Element chat("chat-font");
		gui.LinkEndChild(&chat);
		setAttr(chat, "min-size", nMinChatFontSize);
		setAttr(chat, "max-size", nMaxChatFontSize);

		ticpp::Element menu("menu");
		gui.LinkEndChild(&menu);
		setAttr(menu, "modeless", bModelessMenu);
		setAttr(menu, "style", menuNewStyle);

		ticpp::Element gui_misc("gui-misc");
		gui.LinkEndChild(&gui_misc);
		setAttr(gui_misc, "on-top", bShowOnTop);
		setAttr(gui_misc, "auto-fullscreen", bFullscreenOnStart);
		setAttr(gui_misc, "lastRom", nLastRom);
		setAttr(gui_misc, "lastFilter", nLastFilter);

		setAttr(gui_misc, "hideChildren", HideChildren);
		setAttr(gui_misc, "showThreeFourPlayerOnly", ThreeOrFourPlayerOnly);
		setAttr(gui_misc, "arcadeJoyStickSettings", ArcadeJoystick);

		// gui load game dialog
		ticpp::Element gamelist("gamelist-dlg");
		gui.LinkEndChild(&gamelist);
		setAttr(gamelist, "options", nLoadMenuShowX);
		//setAttr(gamelist, "drivers", nLoadDriverShowX);
		//setAttr(gamelist, "sys-sel", nSystemSel);
		//setAttr(gamelist, "tab-sel", nTabSel);
		//addTextNode(gamelist, "user-filter", szUserFilterStr);

		// gui ips
		ticpp::Element ips("ips");
		gui.LinkEndChild(&ips);
		setAttr(ips, "language", nPatchLang);
		setAttr(ips, "dependancy", bEnforceDep);

		//ticpp::Element skin("skin");
		//gui.LinkEndChild(&skin);
		//setAttr(skin, "use-placeholder", bVidUsePlaceholder);
		//setAttr(skin, "random", nRandomSkin);
		//addTextNode(skin, NULL, szPlaceHolder);

		// preferences
		ticpp::Element preference("preferences");
		root.LinkEndChild(&preference);

		ticpp::Element settings("settings");
		preference.LinkEndChild(&settings);
		setAttr(settings, "always-processkey", bAlwaysProcessKey);
		setAttr(settings, "auto-pause", bAutoPause);
		//setAttr(settings, "avi-audio", nAviIntAudio);
		//setAttr(settings, "use-gdip", bUseGdip);
		ticpp::Element fastforward("fastforward");
		preference.LinkEndChild(&fastforward);
		setAttr(fastforward, "speed", nFastSpeed);
		ticpp::Element thread("thread");
		preference.LinkEndChild(&thread);
		setAttr(thread, "priority", nAppThreadPriority);
		ticpp::Element autofire("autofire");
		preference.LinkEndChild(&autofire);
		setAttr(autofire, "enable", nAutofireEnabled);
		setAttr(autofire, "default-delay", autofireDefaultDelay);
		ticpp::Element macro("macro");
		preference.LinkEndChild(&macro);
		setAttr(macro, "enable", nInputMacroEnabled);

		// pref misc
		ticpp::Element pref_misc("misc");
		preference.LinkEndChild(&pref_misc);
		setAttr(pref_misc, "effect", nShowEffect);

		ticpp::Element controls("controls");
		preference.LinkEndChild(&controls);
		for (int i = 0; i < 4; i++) {
			sprintf(tempStr, "default%d", i);
			addTextNode(controls, tempStr, szPlayerDefaultIni[i]);
		}

		// paths
		ticpp::Element paths("paths");
		root.LinkEndChild(&paths);

		ticpp::Element rom_path("rom");
		paths.LinkEndChild(&rom_path);
		for (int i = 0; i < DIRS_MAX; i++) {
			addTextNode(rom_path, "path", szAppRomPaths[i]);
		}

		ticpp::Element misc_path("misc");
		paths.LinkEndChild(&misc_path);
		for (int i = PATH_PREVIEW; i < PATH_SUM; i++) {
			sprintf(tempStr, "path%d", i);
			addTextNode(misc_path, tempStr, szMiscPaths[i]);
		}

		// hotkeys
		ticpp::Element hotkeys("hotkeys");
		root.LinkEndChild(&hotkeys);

		/*for (int i = 0; !lastCustomKey(customKeys[i]); i++) {
			CustomKey& customkey = customKeys[i];

			ticpp::Element key(customkey.config_code);
			hotkeys.LinkEndChild(&key);
			setAttr(key, "key", customkey.key);
			setAttr(key, "mod", customkey.keymod);
		}*/

		// save file
		doc.SaveFile(configName, TIXML_ENCODING_UTF8);
	}
	catch (ticpp::Exception& ex) {
		return 1;
	}

	return 0;
}