Exemplo n.º 1
0
status_t
SoundsThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage sounds;
	status_t err;
	BMediaFiles bmfs;
	BString item;
	entry_ref entry;
	BEntry ent;
	BPath path;
	const char *p;
	float gain;
	int32 index;
	char *field_name;
	type_code field_code;
	int32 field_count;
	BMessage msg;

	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;
	
	err = MyMessage(theme, sounds);
	if (err)
		return err;

	bmfs.RewindRefs(BMediaFiles::B_SOUNDS);
	for (index = 0; sounds.GetInfo(B_ANY_TYPE, index,  
							GET_INFO_NAME_PTR(&field_name), 
							&field_code, 
							&field_count) == B_OK; index++) {
		if (field_code != B_MESSAGE_TYPE)
			continue;
		if (sounds.FindMessage(field_name, &msg) < B_OK)
			continue;
		/* remove old ref if any */
		if ((bmfs.GetRefFor(BMediaFiles::B_SOUNDS, field_name, &entry) >= B_OK)
				 && (entry.device >= 0))
			bmfs.RemoveRefFor(BMediaFiles::B_SOUNDS, field_name, entry);
		if (msg.FindString("sounds:file", &p) < B_OK)
			continue;
		path.SetTo(p);
		if (ent.SetTo(path.Path()) < B_OK)
			continue;
		if (ent.GetRef(&entry) < B_OK)
			continue;
		if (bmfs.SetRefFor(BMediaFiles::B_SOUNDS, field_name, entry) < B_OK)
			continue;
		if (msg.FindFloat("sounds:volume", &gain) < B_OK)
			continue;
#if defined(__ANTARES__) || defined(B_BEOS_VERSION_DANO)
		if (bmfs.SetAudioGainFor(BMediaFiles::B_SOUNDS, field_name, gain) < B_OK)
			continue;
#endif
	}

	return B_OK;
}