コード例 #1
0
ファイル: iniparser.cpp プロジェクト: devnev/ds1edit-loader
	void writePreserving(QFile& inFile, QTextStream& out, const AttributeMap& data)
	{
		FNTRACE("ini", "", "writePreserving", QString("in, out, %1 rows of data").arg(data.size()));

		int i, j;
		QChar c;
		QString name;
		size_t lineNumber = 0;
		QString line;
		typedef QSet<AttributeMap::key_type> KeySet;
		KeySet unwrittenKeys = KeySet::fromList(data.keys());

		if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text))
			ETHROW(Exception(QString("Unable to open %1 for reading.").arg(inFile.fileName())));
		QTextStream in(&inFile);

		while (!(line = in.readLine()).isNull())
		{
			++lineNumber;
			//std::cout << lineNumber << ": " << line.toStdString() << ":\n";

			for (i = 0; line[i].isSpace(); ++i) { out << line[i]; }

			if (line[i].isNull()) { out << '\n'; continue; }
			else if (line[i] == COMMENT_BEGIN) { out << line.mid(i) << '\n'; continue; }

			for (j = i; !(c = line[i]).isNull() && c!=COMMENT_BEGIN && c!=ASSIGNER; ++i) ;
			//std::cout << "non-empty, ";
			if (c != ASSIGNER) // non-empty line that isn't assignment -> invalid
				ETHROW(ParseError(inFile.fileName(), lineNumber, "Unknown non-empty line."));
			for (--i; line[i].isSpace(); --i) ; // last character of name
			name = line.mid(j, i - j + 1);
			//std::cout << "name: " << name.toStdString() << ' ';

			for ( ; line[j]!=ASSIGNER; ++j) out << line[j];
			out << ASSIGNER;
			i = j + 1;

			for ( ; line[i].isSpace(); ++i) out << line[i];

			if (data.contains(name))
			{
				//std::cout << "known ";
				out << data.value(name);
				unwrittenKeys.remove(name);
				for (j = i; !line[i].isNull() && line[i]!=COMMENT_BEGIN; ++i) ; // EOL || comment
				for (--i; line[i].isSpace(); --i) ; // last character of value
				++i; // first character after value
			}

			out << line.mid(i) << '\n';
			//std::cout << '\n';
		}

		if (unwrittenKeys.size())
		{
			out << '\n' << COMMENT_BEGIN << "Following lines were generated by Ds1edit Loader:\n";
			for (KeySet::iterator key = unwrittenKeys.begin();
				key != unwrittenKeys.end(); ++key)
				out << (*key) << ' ' << ASSIGNER << ' ' << data.value(*key) << '\n';
		}

		//in.resize(in.pos()+1);
		inFile.close();
	}
コード例 #2
0
ファイル: validationEGL.cpp プロジェクト: bsergean/angle
Error ValidateCreateImageKHR(const Display *display,
                             gl::Context *context,
                             EGLenum target,
                             EGLClientBuffer buffer,
                             const AttributeMap &attributes)
{
    Error error = ValidateContext(display, context);
    if (error.isError())
    {
        return error;
    }

    const DisplayExtensions &displayExtensions = display->getExtensions();

    if (!displayExtensions.imageBase && !displayExtensions.image)
    {
        // It is out of spec what happens when calling an extension function when the extension is
        // not available.
        // EGL_BAD_DISPLAY seems like a reasonable error.
        return Error(EGL_BAD_DISPLAY, "EGL_KHR_image not supported.");
    }

    // TODO(geofflang): Complete validation from EGL_KHR_image_base:
    // If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is itself an
    // EGLImage sibling, the error EGL_BAD_ACCESS is generated.

    for (AttributeMap::const_iterator attributeIter = attributes.begin();
         attributeIter != attributes.end(); attributeIter++)
    {
        EGLint attribute = attributeIter->first;
        EGLint value     = attributeIter->second;

        switch (attribute)
        {
            case EGL_IMAGE_PRESERVED_KHR:
                switch (value)
                {
                    case EGL_TRUE:
                    case EGL_FALSE:
                        break;

                    default:
                        return Error(EGL_BAD_PARAMETER,
                                     "EGL_IMAGE_PRESERVED_KHR must be EGL_TRUE or EGL_FALSE.");
                }
                break;

            case EGL_GL_TEXTURE_LEVEL_KHR:
                if (!displayExtensions.glTexture2DImage &&
                    !displayExtensions.glTextureCubemapImage && !displayExtensions.glTexture3DImage)
                {
                    return Error(EGL_BAD_PARAMETER,
                                 "EGL_GL_TEXTURE_LEVEL_KHR cannot be used without "
                                 "KHR_gl_texture_*_image support.");
                }

                if (value < 0)
                {
                    return Error(EGL_BAD_PARAMETER, "EGL_GL_TEXTURE_LEVEL_KHR cannot be negative.");
                }
                break;

            case EGL_GL_TEXTURE_ZOFFSET_KHR:
                if (!displayExtensions.glTexture3DImage)
                {
                    return Error(EGL_BAD_PARAMETER,
                                 "EGL_GL_TEXTURE_ZOFFSET_KHR cannot be used without "
                                 "KHR_gl_texture_3D_image support.");
                }
                break;

            default:
                return Error(EGL_BAD_PARAMETER, "invalid attribute: 0x%X", attribute);
        }
    }

    switch (target)
    {
        case EGL_GL_TEXTURE_2D_KHR:
        {
            if (!displayExtensions.glTexture2DImage)
            {
                return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_2D_image not supported.");
            }

            if (buffer == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "buffer cannot reference a 2D texture with the name 0.");
            }

            const gl::Texture *texture =
                context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer));
            if (texture == nullptr || texture->getTarget() != GL_TEXTURE_2D)
            {
                return Error(EGL_BAD_PARAMETER, "target is not a 2D texture.");
            }

            if (texture->getBoundSurface() != nullptr)
            {
                return Error(EGL_BAD_ACCESS, "texture has a surface bound to it.");
            }

            EGLint level = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0);
            if (texture->getWidth(GL_TEXTURE_2D, static_cast<size_t>(level)) == 0 ||
                texture->getHeight(GL_TEXTURE_2D, static_cast<size_t>(level)) == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "target 2D texture does not have a valid size at specified level.");
            }

            if (level > 0 && (!texture->isMipmapComplete() ||
                              static_cast<size_t>(level) >= texture->getMipCompleteLevels()))
            {
                return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero.");
            }

            if (level == 0 && !texture->isMipmapComplete() &&
                TextureHasNonZeroMipLevelsSpecified(context, texture))
            {
                return Error(EGL_BAD_PARAMETER,
                             "if level is zero and the texture is incomplete, it must have no mip "
                             "levels specified except zero.");
            }
        }
        break;

        case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
        case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
        case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
        case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
        case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
        case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
        {
            if (!displayExtensions.glTextureCubemapImage)
            {
                return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_cubemap_image not supported.");
            }

            if (buffer == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "buffer cannot reference a cubemap texture with the name 0.");
            }

            const gl::Texture *texture =
                context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer));
            if (texture == nullptr || texture->getTarget() != GL_TEXTURE_CUBE_MAP)
            {
                return Error(EGL_BAD_PARAMETER, "target is not a cubemap texture.");
            }

            if (texture->getBoundSurface() != nullptr)
            {
                return Error(EGL_BAD_ACCESS, "texture has a surface bound to it.");
            }

            EGLint level       = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0);
            GLenum cubeMapFace = egl_gl::EGLCubeMapTargetToGLCubeMapTarget(target);
            if (texture->getWidth(cubeMapFace, static_cast<size_t>(level)) == 0 ||
                texture->getHeight(cubeMapFace, static_cast<size_t>(level)) == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "target cubemap texture does not have a valid size at specified level "
                             "and face.");
            }

            if (level > 0 && (!texture->isMipmapComplete() ||
                              static_cast<size_t>(level) >= texture->getMipCompleteLevels()))
            {
                return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero.");
            }

            if (level == 0 && !texture->isMipmapComplete() &&
                TextureHasNonZeroMipLevelsSpecified(context, texture))
            {
                return Error(EGL_BAD_PARAMETER,
                             "if level is zero and the texture is incomplete, it must have no mip "
                             "levels specified except zero.");
            }

            if (level == 0 && !texture->isMipmapComplete() &&
                CubeTextureHasUnspecifiedLevel0Face(texture))
            {
                return Error(EGL_BAD_PARAMETER,
                             "if level is zero and the texture is incomplete, it must have all of "
                             "its faces specified at level zero.");
            }
        }
        break;

        case EGL_GL_TEXTURE_3D_KHR:
        {
            if (!displayExtensions.glTexture3DImage)
            {
                return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_3D_image not supported.");
            }

            if (buffer == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "buffer cannot reference a 3D texture with the name 0.");
            }

            const gl::Texture *texture =
                context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer));
            if (texture == nullptr || texture->getTarget() != GL_TEXTURE_3D)
            {
                return Error(EGL_BAD_PARAMETER, "target is not a 3D texture.");
            }

            if (texture->getBoundSurface() != nullptr)
            {
                return Error(EGL_BAD_ACCESS, "texture has a surface bound to it.");
            }

            EGLint level   = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0);
            EGLint zOffset = attributes.get(EGL_GL_TEXTURE_ZOFFSET_KHR, 0);
            if (texture->getWidth(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0 ||
                texture->getHeight(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0 ||
                texture->getDepth(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "target 3D texture does not have a valid size at specified level.");
            }

            if (static_cast<size_t>(zOffset) >=
                texture->getDepth(GL_TEXTURE_3D, static_cast<size_t>(level)))
            {
                return Error(EGL_BAD_PARAMETER,
                             "target 3D texture does not have enough layers for the specified Z "
                             "offset at the specified level.");
            }

            if (level > 0 && (!texture->isMipmapComplete() ||
                              static_cast<size_t>(level) >= texture->getMipCompleteLevels()))
            {
                return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero.");
            }

            if (level == 0 && !texture->isMipmapComplete() &&
                TextureHasNonZeroMipLevelsSpecified(context, texture))
            {
                return Error(EGL_BAD_PARAMETER,
                             "if level is zero and the texture is incomplete, it must have no mip "
                             "levels specified except zero.");
            }
        }
        break;

        case EGL_GL_RENDERBUFFER_KHR:
        {
            if (!displayExtensions.glRenderbufferImage)
            {
                return Error(EGL_BAD_PARAMETER, "KHR_gl_renderbuffer_image not supported.");
            }

            if (attributes.contains(EGL_GL_TEXTURE_LEVEL_KHR))
            {
                return Error(EGL_BAD_PARAMETER,
                             "EGL_GL_TEXTURE_LEVEL_KHR cannot be used in conjunction with a "
                             "renderbuffer target.");
            }

            if (buffer == 0)
            {
                return Error(EGL_BAD_PARAMETER,
                             "buffer cannot reference a renderbuffer with the name 0.");
            }

            const gl::Renderbuffer *renderbuffer =
                context->getRenderbuffer(egl_gl::EGLClientBufferToGLObjectHandle(buffer));
            if (renderbuffer == nullptr)
            {
                return Error(EGL_BAD_PARAMETER, "target is not a renderbuffer.");
            }

            if (renderbuffer->getSamples() > 0)
            {
                return Error(EGL_BAD_PARAMETER, "target renderbuffer cannot be multisampled.");
            }
        }
        break;

        default:
            return Error(EGL_BAD_PARAMETER, "invalid target: 0x%X", target);
    }

    return Error(EGL_SUCCESS);
}
コード例 #3
0
bool WidgetRegistrationS60::registerAppL(const QString& appId,
                                         const QString& appTitle,
                                         const QString& appPath,
                                         const QString& dataPath,
                                         const QString& iconPath,
                                         const AttributeMap& attr,
                                         const QString& type,
                                         unsigned long size,
                                         const QString& startPath,
                                         int& widgetUid,
                                         QString& convertedIconPath,
                                         bool hideIcon)
{
    LOG("WidgetRegistrationS60::registerAppL()" << " appId : " << appId << " appTitle : " << 
            appTitle << " appPath : " << appPath << " iconPath : " << iconPath << " startPath : " << 
            startPath);

    if (appId.isEmpty() || appTitle.isEmpty() || appPath.isEmpty())
        return false;

    // S60 requires widgetProps as CWidgetPropertyValue
    RPointerArray<CWidgetPropertyValue> propertyValues(EWidgetPropertyIdCount);
    CleanupStack::PushL(TCleanupItem(PointerArrayCleanup, &propertyValues)); // pushed 1

    RWidgetRegistryClientSession registryClient;
    User::LeaveIfError(registryClient.Connect());
    CleanupClosePushL( registryClient ); // pushed 2

    RFs rfs;
    User::LeaveIfError(rfs.Connect());
    CleanupClosePushL(rfs); // pushed 3
    User::LeaveIfError(rfs.ShareProtected());

    // empty values
    for (TInt i = 0; i < EWidgetPropertyIdCount; ++i) {
        CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
        CleanupStack::PushL(value); // pushed 4
        propertyValues.AppendL(value);
        CleanupStack::Pop(value); // pushed 3
    }

    *(propertyValues[EWidgetPropertyListVersion]) = KWidgetPropertyListVersion71CWRT;
    *(propertyValues[EFileSize]) = size;

    SwiUI::CWidgetRegistrationS60Apparc* appArc = SwiUI::CWidgetRegistrationS60Apparc::NewL(rfs);
    CleanupStack::PushL(appArc); // pushed 4

    // get drive letter from appPath
    TUint driveLetter = appPath[0].unicode();

    // Generate our UID based on UIDs in the Qt WidgetRegistry
    int iUid = WebAppRegistry::instance()->nextAvailableUid();
    widgetUid = iUid;

    if (iUid == 0) {
        LOG("WidgetRegistrationS60::registerAppL() - registryClient.GetAvailableUidL() failed");
        CleanupStack::PopAndDestroy( 4, &propertyValues );
        return false;
    }

    // convert icon to required format and sizes
    QString newIconPath = "";
    if (!processIconL(iUid, newIconPath, iconPath, QDir::toNativeSeparators(dataPath))) {
        LOG("WidgetRegistrationS60::registerAppL() - processIconL() failed");
        CleanupStack::PopAndDestroy( 4, &propertyValues );
        return false;
        }

    // FIXME this translation doesn't cover all cases, if generalized
    // must cover S60 WRT names and W3C names
    QString appPathNative = QDir::toNativeSeparators(appPath);
    // FIXME enforce canonicalization in caller
    // must end in QDir::separator()
    if (QDir::separator() != appPathNative.at(appPathNative.count()-1)) {
        appPathNative.append(QDir::separator());
    }
    TPtrC16 basePathSymbian(reinterpret_cast<const TUint16*>
                            (appPathNative.constData()));
    *(propertyValues[EBasePath]) = basePathSymbian;

    QString driveName = appPathNative.left(2);
    TPtrC16 driveNameSymbian(reinterpret_cast<const TUint16*>
                             (driveName.constData()));
    *(propertyValues[EDriveName]) = driveNameSymbian;

    TPtrC16 mainHtmlSymbian(reinterpret_cast<const TUint16*>
                            (startPath.constData()));
    *(propertyValues[EMainHTML]) = mainHtmlSymbian;

    TPtrC16 identifierSymbian(reinterpret_cast<const TUint16*>
                              (appId.constData()));
    *(propertyValues[EBundleIdentifier]) = identifierSymbian;

    if (attr.contains(W3CSettingsKey::WIDGET_VERSION)) {
        QString ver = attr.value(W3CSettingsKey::WIDGET_VERSION).toString();
        if(!(ver.isEmpty())) {
            TPtrC16 version(reinterpret_cast<const TUint16*>
                            (attr.value(W3CSettingsKey::WIDGET_VERSION).toString().constData()));
            *(propertyValues[EBundleVersion]) = version;
        }
    }

    if (appTitle.isEmpty()) {
        // FIXME this probably should cause registration failure
        *(propertyValues[EBundleDisplayName]) = identifierSymbian;
    } else {
        TPtrC16 titleSymbian(reinterpret_cast<const TUint16*>
                             (appTitle.constData()));
        *(propertyValues[EBundleDisplayName]) = titleSymbian;
    }

    // TODO: We decided to drop BundleName and just use
    // DisplayName but the registry code has errors in it and uses
    // BundleName when it should use DisplayName so as a workaround,
    // set BundleName to DisplayName.  Should eventually remove
    // BundleName from set of registry values.
    const TDesC& name = *(propertyValues[EBundleDisplayName]);
    *(propertyValues[EBundleName]) = name;

    convertedIconPath = newIconPath;

    if (!newIconPath.isEmpty()) {
        // FIXME enforce canonicalization in caller
        // strangely icon path doesn't include icon file name
        int li = newIconPath.lastIndexOf(QDir::separator());
        if (li > 0) {
            newIconPath = newIconPath.left(li+1);
            TPtrC16 iconPathSymbian(reinterpret_cast<const TUint16*>
                                    (newIconPath.constData()));
            *(propertyValues[EIconPath]) = iconPathSymbian;
        }
    }

    *(propertyValues[EUid]) = iUid;

    *(propertyValues[EMiniViewEnable]) = 0;
    if (attr.contains(W3CSettingsKey::WIDGET_VIEWMODES)) {
        QStringList viewModeList = attr.value(W3CSettingsKey::WIDGET_VIEWMODES).toString().split(" ");
        foreach (const QString &str, viewModeList) {
            if (str.contains("minimized", Qt::CaseInsensitive)) {
                *(propertyValues[EMiniViewEnable]) = 1;
                break;
            }
        }
    }