Example #1
BackgroundThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	ssize_t flatSize;
	char *pAttr;

	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;

	err = MyMessage(theme, backgrounds);
	if (err)
		return err;

	// set desktop colors
	BScreen bs;
	rgb_color col;
	//const rgb_color *c;
	col = bs.DesktopColor(0); // by
	// should work as the rest of the fields (grouping)
	for (int i = 0; i < count_workspaces(); i++) {
		//ssize_t sz = 4;
		if (FindRGBColor(backgrounds, B__DESKTOP_COLOR, i, &col) != B_OK && i == 0)
		//if (backgrounds.FindData(B__DESKTOP_COLOR, (type_code)'RGBC', i, (const void **)&c, &sz) != B_OK && i == 0)
			break; // if no color at all, don't set them
		bs.SetDesktopColor(col, i, true);
	// make sure we don't leave our garbage in the message
	// as it would offset the next call by adding rgb_colors on existing ones

	BMessenger tracker("application/x-vnd.Be-TRAK");

	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	flatSize = backgrounds.FlattenedSize();
	pAttr = new char[flatSize];
	if (pAttr == NULL)
		return ENOMEM;
	err = backgrounds.Flatten(pAttr, flatSize);
	if (err < B_OK)
		goto getout;
	err = nDesktop.WriteAttr(B_BACKGROUND_INFO, B_MESSAGE_TYPE, 0LL, pAttr, flatSize);
	if (err < B_OK)
		goto getout;

	//m.AddSpecifier("Window", "Desktop");

	return B_OK;

	delete [] pAttr;
	return err;