Esempio n. 1
0
nserror amiga_dt_picture_init(void)
{
	char dt_mime[50];
	struct DataType *dt, *prevdt = NULL;
	lwc_string *type;
	lwc_error lerror;
	nserror error;
	BPTR fh = 0;
	struct Node *node = NULL;

	while((dt = ObtainDataType(DTST_RAM, NULL,
			DTA_DataType, prevdt,
			DTA_GroupID, GID_PICTURE, // we only support images for now
			TAG_DONE)) != NULL)
	{
		ReleaseDataType(prevdt);
		prevdt = dt;

		do {
			node = ami_mime_from_datatype(dt, &type, node);

			if(node)
			{
				error = content_factory_register_handler(
					lwc_string_data(type), 
					&amiga_dt_picture_content_handler);

				if (error != NSERROR_OK)
					return error;
			}

		}while (node != NULL);

	}

	ReleaseDataType(prevdt);

	return NSERROR_OK;
}
Esempio n. 2
0
char *amiga_dt_picture_datatype(struct content *c)
{
	const uint8 *data;
	ULONG size;
	struct DataType *dt;
	char *filetype = NULL;
	
	data = (uint8 *)content__get_source_data(c, &size);

	if(dt = ObtainDataType(DTST_MEMORY, NULL,
					DTA_SourceAddress, data,
					DTA_SourceSize, size,
					DTA_GroupID, GID_PICTURE,
					TAG_DONE)) {
		filetype = strdup(dt->dtn_Header->dth_Name);
		ReleaseDataType(dt);
	}
	
	if(filetype == NULL) filetype = strdup("DataTypes");
	return filetype;
}
Esempio n. 3
0
const char *fetch_filetype(const char *unix_path)
{
	static char mimetype[50];
	STRPTR ttype = NULL;
	struct DiskObject *dobj = NULL;
	BPTR lock = 0;
    struct DataTypeHeader *dth = NULL;
    struct DataType *dtn;
	BOOL found = FALSE;

	/* First try getting a tooltype "MIMETYPE" and use that as the MIME type.  Will fail over
		to default icons if the file doesn't have a real icon. */

	if(dobj = GetIconTags(unix_path,ICONGETA_FailIfUnavailable,FALSE,
						TAG_DONE))
	{
		ttype = FindToolType(dobj->do_ToolTypes, "MIMETYPE");
		if(ttype)
		{
			strcpy(mimetype,ttype);
			found = TRUE;
		}

		FreeDiskObject(dobj);
	}

	/* If that didn't work, have a go at guessing it using datatypes.library.  This isn't
		accurate - the base names differ from those used by MIME and it relies on the
		user having a datatype installed which can handle the file. */

	if(!found)
	{
		if (lock = Lock (unix_path, ACCESS_READ))
		{
			if (dtn = ObtainDataTypeA (DTST_FILE, (APTR)lock, NULL))
			{
				dth = dtn->dtn_Header;

				switch(dth->dth_GroupID)
				{
					case GID_SYSTEM:
						sprintf(mimetype,"application/%s",dth->dth_BaseName);
					break;
					case GID_TEXT:
					case GID_DOCUMENT:
						if(strcmp("ascii",dth->dth_BaseName)==0)
						{
							sprintf(mimetype,"text/plain",dth->dth_BaseName);
						}
						else if(strcmp("simplehtml",dth->dth_BaseName)==0)
						{
							sprintf(mimetype,"text/html",dth->dth_BaseName);
						}
						else
						{
							sprintf(mimetype,"text/%s",dth->dth_BaseName);
						}
					break;
					case GID_SOUND:
					case GID_INSTRUMENT:
					case GID_MUSIC:
						sprintf(mimetype,"audio/%s",dth->dth_BaseName);
					break;
					case GID_PICTURE:
						sprintf(mimetype,"image/%s",dth->dth_BaseName);
					break;
					case GID_ANIMATION:
					case GID_MOVIE:
						sprintf(mimetype,"video/%s",dth->dth_BaseName);
					break;
				}
				found = TRUE;
				ReleaseDataType(dtn);
			}
			UnLock(lock);
		}
	}

	if(!found) strcpy(mimetype,"text/html"); /* If all else fails */

	//printf("%s: %s\n",unix_path,mimetype);

	return mimetype;
}