Exemplo n.º 1
0
void DHTClass::ReadSensor()
{
	// Remove this?
	delay(dht.getMinimumSamplingPeriod());

	float temperature = dht.getTemperature();
	if (isnan(temperature)) {
		Serial.println("Failed reading temperature from DHT");
	}
	else {
		this->mySensorGw->send(MyMessage(this->childIdTemp, V_TEMP).set(temperature, 1));
		Serial.print("Temp: ");
		Serial.println(temperature);
	}

	float humidity = dht.getHumidity();
	if (isnan(humidity)) {
		Serial.println("Failed reading humidity from DHT");
	}
	else {
		this->mySensorGw->send(MyMessage(this->childIdHum, V_HUM).set(humidity, 1));
		Serial.print("Humidity: ");
		Serial.println(humidity);
	}
}
status_t
UISettingsThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage uisettings;
	BMessage names;
	BFont fnt;
	status_t err;
	
	(void)flags;
	err = MyMessage(theme, uisettings);
	if (err)
		uisettings.MakeEmpty();
	
	err = get_ui_settings(&uisettings, &names);
	if (err)
		return err;
	
	// hack for legacy fonts
	err = BFont::GetStandardFont(B_PLAIN_FONT, &fnt);
	uisettings.AddFlat("be:f:be_plain_font", &fnt);
	err = BFont::GetStandardFont(B_BOLD_FONT, &fnt);
	uisettings.AddFlat("be:f:be_bold_font", &fnt);
	err = BFont::GetStandardFont(B_FIXED_FONT, &fnt);
	uisettings.AddFlat("be:f:be_fixed_font", &fnt);

	err = SetMyMessage(theme, uisettings);
	return err;
}
status_t
ScreensaverThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage screensaver;
	status_t err;
	BPath path;
	BString str;
	BMessage settings;
	BMessage modsettings;
	
	(void)flags;
	err = MyMessage(theme, screensaver);
	if (err)
		screensaver.MakeEmpty();
	
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
		return B_ERROR;
	path.Append("ScreenSaver_settings");
	BFile f(path.Path(), B_READ_ONLY);
	if (settings.Unflatten(&f) < B_OK)
		return B_ERROR;
	if (settings.FindString("modulename", &str) >= B_OK) {
		screensaver.AddString(Z_THEME_SS_MODULE, str.String());
		BString msname(MS_NAME);
		msname += str.String();
		if (settings.FindMessage(msname.String(), &modsettings) >= B_OK) {
		screensaver.AddMessage(Z_THEME_SS_MODULE_SETTINGS, &modsettings);
		}
	}
	
	err = SetMyMessage(theme, screensaver);
	return err;
}
Exemplo n.º 4
0
status_t
WinampSkinThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage skin;
	BString name;
	status_t err = B_ERROR;
	
	(void)flags;
	err = MyMessage(theme, skin);
	if (err)
		skin.MakeEmpty();

	if (WhichApp() == USE_CL)
		err = CLSkin(&name);
	else
		err = SPSkin(&name);
	/* try the other way round */
	if (err) {
		if (WhichApp() == USE_CL)
			err = CLSkin(&name, true);
		else
			err = SPSkin(&name, true);
	}
	if (!err)
		skin.AddString("winamp:skin", name);
	err = SetMyMessage(theme, skin);
	return err;
}
Exemplo n.º 5
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;
}
status_t
TerminalThemesAddon::InstallFiles(BMessage &theme, BDirectory &folder)
{
	BMessage termpref;
	status_t err;
	
	(void)folder;
	err = MyMessage(theme, termpref);
	if (err)
		termpref.MakeEmpty();
	
	return B_OK;
}
status_t
TerminalThemesAddon::MakeThemeR5(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	status_t err;
	struct termprefs tp;
	BPath pTermPref;
	
	(void)flags;
	err = MyMessage(theme, termpref);
	if (err)
		termpref.MakeEmpty();
	
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK)
		return EINVAL;
	pTermPref.Append("Terminal");
	BFile fTermPref(pTermPref.Path(), B_READ_ONLY);
	if (fTermPref.InitCheck() != B_OK)
		return fTermPref.InitCheck();
	if (fTermPref.Read(&tp, sizeof(struct termprefs)) < (ssize_t)sizeof(struct termprefs))
		return EIO;
	if ((tp.magic != TP_MAGIC) || (tp.version != TP_VERSION))
		return EINVAL;
	termpref.AddInt32(TP_COLS, tp.p.cols);
	termpref.AddInt32(TP_ROWS, tp.p.rows);
	termpref.AddInt32(TP_TABWIDTH, tp.p.tab_width);
	BFont tFont;
	font_family ff;
	font_style fs;
	BString str(tp.p.font);
	str.Truncate(str.FindFirst('/'));
	strncpy(ff, str.String(), sizeof(ff));
	str.SetTo(tp.p.font);
	str.Remove(0, str.FindFirst('/')+1);
	strncpy(fs, str.String(), sizeof(fs));
	tFont.SetFamilyAndStyle(ff, fs);
	tFont.SetSize(tp.p.font_size);
	AddFont(termpref, TP_FONT, &tFont);
	AddRGBColor(termpref, TP_BG, tp.p.bg);
	AddRGBColor(termpref, TP_FG, tp.p.fg);
	AddRGBColor(termpref, TP_CURBG, tp.p.curbg);
	AddRGBColor(termpref, TP_CURFG, tp.p.curfg);
	AddRGBColor(termpref, TP_SELBG, tp.p.selbg);
	AddRGBColor(termpref, TP_SELFG, tp.p.selfg);
	termpref.AddInt32(TP_ENCODING, tp.p.encoding);

	err = SetMyMessage(theme, termpref);
	return B_OK;
}
status_t
TerminalThemesAddon::BackupFiles(BMessage &theme, BDirectory &folder)
{
	BMessage termpref;
	status_t err;
	
	(void)folder;
	err = MyMessage(theme, termpref);
	if (err)
		termpref.MakeEmpty();
	
	entry_ref ref;
	//find_font_file(&ref, ff, fs);
	return B_OK;
}
Exemplo n.º 9
0
status_t
WinampSkinThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage skin;
	BString name;
	status_t err;
	
	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;
	
	err = MyMessage(theme, skin);
	if (err)
		return err;
	
	err = skin.FindString("winamp:skin", &name);
	if (err)
		return err;
	SetCLSkin(&name);
	SetSPSkin(&name);
	return B_OK;
}
status_t
UISettingsThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage uisettings;
	BFont fnt;
	status_t err;
	uint32 uiflags = 0;

	(void)flags;
	err = MyMessage(theme, uisettings);
	if (err)
		return err;

	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE)
		uiflags |= B_SAVE_UI_SETTINGS;
	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY)
		uiflags |= B_APPLY_UI_SETTINGS;
	if (!uiflags)
		return B_OK;

	// hack for legacy fonts
	err = uisettings.FindFlat("be:f:be_plain_font", &fnt);
	uisettings.RemoveName("be:f:be_plain_font");
	if (err == B_OK)
		BFont::SetStandardFont(B_PLAIN_FONT, &fnt);

	err = uisettings.FindFlat("be:f:be_bold_font", &fnt);
	uisettings.RemoveName("be:f:be_bold_font");
	if (err == B_OK)
		BFont::SetStandardFont(B_BOLD_FONT, &fnt);

	err = uisettings.FindFlat("be:f:be_fixed_font", &fnt);
	uisettings.RemoveName("be:f:be_fixed_font");
 	if (err == B_OK)
		BFont::SetStandardFont(B_FIXED_FONT, &fnt);
	
	update_ui_settings(uisettings, uiflags);
	
	return B_OK;
}
status_t
ScreensaverThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage screensaver;
	status_t err;
	BPath path;
	BString str;
	BMessage settings;
	BMessage modsettings;
	
	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;
	
	err = MyMessage(theme, screensaver);
	if (err)
		return err;
	
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
		return B_ERROR;
	path.Append("ScreenSaver_settings");
	BFile f(path.Path(), B_READ_WRITE);
	if (settings.Unflatten(&f) < B_OK)
		return B_ERROR;
	if (screensaver.FindString(Z_THEME_SS_MODULE, &str) >= B_OK) {
		if (settings.ReplaceString("modulename", str.String()) < B_OK)
			if (settings.AddString("modulename", str.String()) < B_OK)
				return B_ERROR;
		if (screensaver.FindMessage(Z_THEME_SS_MODULE_SETTINGS, &modsettings) >= B_OK) {
			BString msname(MS_NAME);
			msname += str.String();
			if (settings.ReplaceMessage(msname.String(), &modsettings) < B_OK)
				settings.AddMessage(msname.String(), &modsettings);
		}
		f.Seek(0LL, SEEK_SET);
		if (settings.Flatten(&f) < B_OK)
			return B_ERROR;
	}
	
	return err;
}
Exemplo n.º 12
0
status_t
SoundsThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage sounds;
	status_t err;
	BMediaFiles bmfs;
	BString item;
	entry_ref entry;
	BEntry ent;
	BPath path;
	float gain;
	
	(void)flags;
	err = MyMessage(theme, sounds);
	if (err)
		sounds.MakeEmpty();
	
	bmfs.RewindRefs(BMediaFiles::B_SOUNDS);
	while (bmfs.GetNextRef(&item, &entry) == B_OK) {
		BMessage msg('SndI');
		path.Unset();
		ent.SetTo(&entry);
		ent.GetPath(&path);
		//printf("\t%s: %s\n", item.String(), path.Path());
		if (path.Path()) {
			msg.AddString("sounds:file", path.Path());
			gain = 1.0;
#if defined(__ANTARES__) || defined(B_BEOS_VERSION_DANO)
			bmfs.GetAudioGainFor(BMediaFiles::B_SOUNDS, item.String(), &gain);
#endif
			msg.AddFloat("sounds:volume", gain);
		}
		sounds.AddMessage(item.String(), &msg);
	}
	
	err = SetMyMessage(theme, sounds);
	return err;
}
Exemplo n.º 13
0
status_t
TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	struct termprefs tp;
	int32 ival;
	rgb_color color;
	BString s;

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

	if (termpref.FindInt32(TP_COLS, &ival) < B_OK)
		ival = 80;
	s = "";
	s << ival;
	lines.AddString(PREF_COLS, s.String());

	if (termpref.FindInt32(TP_ROWS, &ival) < B_OK)
		ival = 25;
	s = "";
	s << ival;
	lines.AddString(PREF_ROWS, s.String());

	if (termpref.FindInt32(TP_TABWIDTH, &ival) >= B_OK) {
		//XXX: handle that ?
	}

	BFont tFont;
	tp.p.font_size = 12;
	strcpy(tp.p.font, "Courier10 BT/Roman");
	if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) {
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		s = "";
		s << ff;
		lines.AddString(PREF_HALF_FONT_FAMILY, s.String());
		s = "";
		s << fs;
		lines.AddString(PREF_HALF_FONT_STYLE, s.String());
		s = "";
		s << tFont.Size();
		lines.AddString(PREF_HALF_FONT_SIZE, s.String());
	}
	
	if (FindRGBColor(termpref, TP_BG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_TEXT_BACK_COLOR, s.String());
	
	if (FindRGBColor(termpref, TP_FG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_TEXT_FORE_COLOR, s.String());

	if (FindRGBColor(termpref, TP_CURBG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_CURSOR_BACK_COLOR, s.String());

	if (FindRGBColor(termpref, TP_CURFG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_CURSOR_FORE_COLOR, s.String());

	if (FindRGBColor(termpref, TP_SELBG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_SELECT_BACK_COLOR, s.String());

	if (FindRGBColor(termpref, TP_SELFG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_SELECT_FORE_COLOR, s.String());
	
	/* XXX: handle PREF_IM_FORE_COLOR PREF_IM_BACK_COLOR PREF_IM_SELECT_COLOR */

	
	if (termpref.FindInt32(TP_ENCODING, &ival) != B_OK)
		ival = 0; // UTF-8
	s = "";
	s << ival;
	//XXX: shouldn't really be touched...
	//lines.AddString(, s.String());
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		SaveHaikuTerminalSettings(lines);
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)(teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) {
					err = B_OK;
					//XXX: WRITEME
/*					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
*/
				}
			}
		}
	}
	
	return B_OK;
}
status_t
TerminalThemesAddon::MakeThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	BString value;
	int n, i;
	
	(void)flags;
	err = MyMessage(theme, termpref);
	if (err)
		termpref.MakeEmpty();
	
	err = LoadHaikuTerminalSettings(lines);
	
	for (i = 0; i < NENTS(sHaikuPrefsMapInt32); i++) {
		int v;

		if (lines.FindString(sHaikuPrefsMapInt32[i].pref, &value) < B_OK)
			continue;

		n = sscanf(value.String(), "%d", &v);
		//printf("n=%d '%s'\n", n, value.String());

		if (n == 1)
			termpref.AddInt32(sHaikuPrefsMapInt32[i].name, v);
	}

	for (i = 0; i < NENTS(sHaikuPrefsMapColors); i++) {
		int r, g, b;

		if (lines.FindString(sHaikuPrefsMapColors[i].pref, &value) < B_OK)
			continue;

		n = sscanf(value.String(), "%d%*[, ]%d%*[, ]%d", &r, &g, &b);
		//printf("n=%d '%s' %d,%d,%d\n", n, value.String(), r, g, b);

		if (n == 3) {
			rgb_color c = make_color(r, g, b, 255);
			AddRGBColor(termpref, sHaikuPrefsMapColors[i].name, c);
		}
	}

	BFont font;
	BString s;
	font_family family;
	font_style style;
	float size = 12.0;
	memset(&family, 0, sizeof(family));
	memset(&style, 0, sizeof(style));

	if (lines.FindString(PREF_HALF_FONT_FAMILY, &s) == B_OK)
		strncpy(family, s.String(), B_FONT_FAMILY_LENGTH);

	if (lines.FindString(PREF_HALF_FONT_STYLE, &s) == B_OK)
		strncpy(style, s.String(), B_FONT_STYLE_LENGTH);

	font.SetFamilyAndStyle(family, style);

	if (lines.FindString(PREF_HALF_FONT_SIZE, &s) == B_OK)
		sscanf(s.String(), "%f", &size);

	font.SetSize(size);

	//termpref.PrintToStream();

	err = SetMyMessage(theme, termpref);
	return B_OK;
}
Exemplo n.º 15
0
status_t
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
	backgrounds.RemoveName(B__DESKTOP_COLOR);

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

	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");
	tracker.SendMessage(&m);

	return B_OK;

getout:
	delete [] pAttr;
	return err;
}
status_t
TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	int32 ival;
	rgb_color color;
	BString s;
	int i;

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

	for (i = 0; i < NENTS(sHaikuPrefsMapInt32); i++) {
		if (termpref.FindInt32(sHaikuPrefsMapInt32[i].name, &ival) < B_OK)
			ival = sHaikuPrefsMapInt32[i].def;
		s = "";
		s << ival;
		lines.AddString(sHaikuPrefsMapInt32[i].pref, s.String());
	}

	for (i = 0; i < NENTS(sHaikuPrefsMapColors); i++) {
		if (FindRGBColor(termpref, sHaikuPrefsMapColors[i].name, 0, &color) != B_OK)
			color = sHaikuPrefsMapColors[i].def;
		s = "";
		s << color.red << ", " << color.green << ", " << color.blue;
		lines.AddString(sHaikuPrefsMapColors[i].pref, s.String());
	}

	BFont tFont;
	for (i = 0; FindFont(termpref, TP_FONT, i, &tFont) == B_OK; i++) {
		// at least set the size
		s = "";
		s << (int32)tFont.Size();
		lines.AddString(PREF_HALF_FONT_SIZE, s.String());
		//tFont.PrintToStream();
		//printf("fixed: %d\n", tFont.IsFixed());
		//printf("f&h fixed: %d\n", tFont.IsFullAndHalfFixed());
		// don't even try to set the font if it's not there or not fixed
		if (!tFont.IsFixed() && !tFont.IsFullAndHalfFixed())
			continue;
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		s = "";
		s << ff;
		lines.AddString(PREF_HALF_FONT_FAMILY, s.String());
		s = "";
		s << fs;
		lines.AddString(PREF_HALF_FONT_STYLE, s.String());
	}

	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		SaveHaikuTerminalSettings(lines);
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)((addr_t)teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) {
					err = B_OK;
					//XXX: WRITEME
/*					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
*/
				}
			}
		}
	}
	
	return B_OK;
}
Exemplo n.º 17
0
status_t
BackgroundThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	struct attr_info ai;
	char *pAttr;
	BScreen bs;
	rgb_color last_color = {0, 0, 0, 254};
	rgb_color col;
	int last_change = 0;
	int i;
	
	(void)flags;
	err = MyMessage(theme, backgrounds);
	if (err)
		backgrounds.MakeEmpty();
	
	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	if (nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai) < B_OK)
		return EIO;
	pAttr = new char[ai.size];
	if (pAttr == NULL)
		return ENOMEM;
	err = nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, ai.size);
	if (err < B_OK)
		goto getout;
	err = backgrounds.Unflatten(pAttr);
	if (err < B_OK)
		goto getout;

	// make sure other colors are removed
	backgrounds.RemoveName(B__DESKTOP_COLOR);

	// get desktop color... XXX: move it in ui_settings ?
	// should work as the rest of the fields (grouping)
	for (i = 0; i < count_workspaces(); i++) {
		col = bs.DesktopColor(i);
		if (memcmp(&last_color, &col, sizeof(rgb_color))) {
			last_change = i;
			last_color = col;
		}
	}
	//printf("ws col cnt %d\n", last_change);
	for (i = 0; i <= last_change; i++) {
		col = bs.DesktopColor(i);
		AddRGBColor(backgrounds, B__DESKTOP_COLOR, col);
		//backgrounds->AddData(B__DESKTOP_COLOR, (type_code)'RGBC', &col, 4);
	}

	err = SetMyMessage(theme, backgrounds);
	return err;

getout:
	delete [] pAttr;
	return err;
}
status_t
TerminalThemesAddon::ApplyThemeR5(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	status_t err;
	struct termprefs tp;
	
	err = MyMessage(theme, termpref);
	if (err)
		return err;
	tp.magic = TP_MAGIC;
	tp.version = TP_VERSION;
	tp.x = 0; // don't open at specific coords
	tp.y = 0;
	if (termpref.FindInt32(TP_COLS, (int32 *)&tp.p.cols) != B_OK)
		tp.p.cols = 80;
	if (termpref.FindInt32(TP_ROWS, (int32 *)&tp.p.rows) != B_OK)
		tp.p.rows = 25;
	if (termpref.FindInt32(TP_TABWIDTH, (int32 *)&tp.p.tab_width) != B_OK)
		tp.p.tab_width = 8;
	BFont tFont;
	tp.p.font_size = 12;
	strcpy(tp.p.font, "Courier10 BT/Roman");
	if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) {
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		strcpy(tp.p.font, ff);
		strcat(tp.p.font, "/");
		strcat(tp.p.font, fs);
		tp.p.font_size = (uint32)tFont.Size();
	}
	tp.p.cursor_blink_rate = 1000000;
	tp.p.refresh_rate = 0;
	
	if (FindRGBColor(termpref, TP_BG, 0, &tp.p.bg) != B_OK)
		tp.p.bg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_FG, 0, &tp.p.fg) != B_OK)
		tp.p.fg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_CURBG, 0, &tp.p.curbg) != B_OK)
		tp.p.curbg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_CURFG, 0, &tp.p.curfg) != B_OK)
		tp.p.curfg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELBG, 0, &tp.p.selbg) != B_OK)
		tp.p.selbg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELFG, 0, &tp.p.selfg) != B_OK)
		tp.p.selfg = make_color(255,255,255,255);
	
	if (termpref.FindInt32(TP_ENCODING, (int32 *)&tp.p.encoding) != B_OK)
		tp.p.encoding = 0; // UTF-8
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		BPath pTermPref;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK)
			return EINVAL;
		pTermPref.Append("Terminal");
		BFile fTermPref(pTermPref.Path(), B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE);
		if (fTermPref.InitCheck() != B_OK) {
			return fTermPref.InitCheck();
		}
		fTermPref.Write(&tp, sizeof(struct termprefs));
		BNodeInfo ni(&fTermPref);
		if (ni.InitCheck() == B_OK)
			ni.SetType("application/x-vnd.Be-pref");
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)((addr_t)teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kBeOSTerminalAppSig)) {
					err = B_OK;
					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", (int32)0);
					err = msgr.SendMessage(&msg);
				}
			}
		}
	}
	
	return B_OK;
}
Exemplo n.º 19
0
void DallasClass::ReadSensor()
{
	this->sensors.requestTemperatures();
	float temperature = static_cast<float>(static_cast<int>(sensors.getTempCByIndex(0) * 10.)) / 10.;
	this->mySensorGw->send(MyMessage(this->childId, V_TEMP).set(temperature, 1));
}
Exemplo n.º 20
0
status_t
TerminalThemesAddon::MakeThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	BPath pTermPref;
	
	(void)flags;
	err = MyMessage(theme, termpref);
	if (err)
		termpref.MakeEmpty();
	
	err = LoadHaikuTerminalSettings(lines);
	
	//XXX: WRITEME

/*
	char buffer[1024];
	char key[B_FIELD_NAME_LENGTH], data[512];
	int n;
	FILE *file;
	while (fgets(buffer, sizeof(buffer), file) != NULL) {
		if (*buffer == '#')
			continue;

		n = sscanf(buffer, "%*[\"]%[^\"]%*[\"]%*[^\"]%*[\"]%[^\"]", key, data);
		if (n == 2) {
			if (strstr(key, " Color")) {
				rgb_color color;
				int r, g, b;
				n = sscanf(data, "%3d, %3d, %3d", &r, &g, &b);
				color.red = r;
				color.green = g;
				color.blue = b;
				color.alpha = 255;
				
			} else
				lines.AddString(key, data);
		}
	}
*/
/*
	BFile fTermPref(pTermPref.Path(), B_READ_ONLY);
	if (fTermPref.InitCheck() != B_OK)
		return fTermPref.InitCheck();
	if (fTermPref.Read(&tp, sizeof(struct termprefs)) < (ssize_t)sizeof(struct termprefs))
		return EIO;
	if ((tp.magic != TP_MAGIC) || (tp.version != TP_VERSION))
		return EINVAL;
	termpref.AddInt32(TP_COLS, tp.p.cols);
	termpref.AddInt32(TP_ROWS, tp.p.rows);
	termpref.AddInt32(TP_TABWIDTH, tp.p.tab_width);
	BFont tFont;
	font_family ff;
	font_style fs;
	BString str(tp.p.font);
	str.Truncate(str.FindFirst('/'));
	strncpy(ff, str.String(), sizeof(ff));
	str.SetTo(tp.p.font);
	str.Remove(0, str.FindFirst('/')+1);
	strncpy(fs, str.String(), sizeof(fs));
	tFont.SetFamilyAndStyle(ff, fs);
	tFont.SetSize(tp.p.font_size);
	AddFont(termpref, TP_FONT, &tFont);
	AddRGBColor(termpref, TP_BG, tp.p.bg);
	AddRGBColor(termpref, TP_FG, tp.p.fg);
	AddRGBColor(termpref, TP_CURBG, tp.p.curbg);
	AddRGBColor(termpref, TP_CURFG, tp.p.curfg);
	AddRGBColor(termpref, TP_SELBG, tp.p.selbg);
	AddRGBColor(termpref, TP_SELFG, tp.p.selfg);
	termpref.AddInt32(TP_ENCODING, tp.p.encoding);
*/
	err = SetMyMessage(theme, termpref);
	return B_OK;
}