예제 #1
0
bool
BitmapView::ClipboardHasBitmap(void)
{
	BMessage *clip = NULL, flattened;
	uint8 clipval = CLIP_NONE;
	bool returnval;
	
	if (be_clipboard->Lock()) {
		clip = be_clipboard->Data();
		if (!clip->IsEmpty()) {
			returnval = (clip->FindMessage("image/bitmap", &flattened) == B_OK);
			if (returnval)
				clipval = CLIP_BEOS;
			else {
				BString string;
				returnval = (clip->FindString("class", &string) == B_OK && string == "BBitmap");
				
				// Try method Gobe Productive uses if that, too, didn't work
				if (returnval)
					clipval = CLIP_SHOWIMAGE;
				else {
					returnval = (clip->FindMessage("image/x-vnd.Be-bitmap", &flattened) == B_OK);
					if (returnval)
						clipval = CLIP_SHOWIMAGE;
					else
						clipval = CLIP_NONE;
				}
			}
		}
		be_clipboard->Unlock();
	}
	return (clipval != CLIP_NONE)?true:false;
}
예제 #2
0
void 
Settings::Load(BFile* file)
{
	BMessage message;
	if (message.Unflatten(file) == B_OK) {
		// restore application settings
		BString mimetype;
		BString printer;
		for (int i = 0; message.FindString("message", i, &mimetype) == B_OK &&
			message.FindString("p", i, &printer ) == B_OK; i ++) {
			AddAppSettings(new AppSettings(mimetype.String(), printer.String()));
		}

		// restore printer settings
		BMessage page;
		BMessage job;
		for (int i = 0; message.FindString("P", i, &printer) == B_OK &&
			message.FindMessage("S", i, &page) == B_OK &&
			message.FindMessage("J", i, &job) == B_OK; i ++) {
			AddPrinterSettings(new PrinterSettings(printer.String(), &page, &job));
		}
		
		if (message.FindBool("UseConfigWindow", &fUseConfigWindow) != B_OK)
			fUseConfigWindow = true;
		
		if (message.FindRect("ConfigWindowFrame", &fConfigWindowFrame) != B_OK)
			fConfigWindowFrame = BRect(kConfigWindowFrame);
			
		if (message.FindString("DefaultPrinter", &fDefaultPrinter) != B_OK)
			fDefaultPrinter = "";
	}
}
예제 #3
0
void JsonToMessageTest::TestHaikuDepotFetchBatch()
{
	const unsigned char input[] = JSON_SAMPLE_HDS_FETCH_BATCH_PKGS;
	BMessage message;
	BMessage resultMessage;
	BMessage pkgsMessage;
	BMessage pkgMessage1;
	double modifyTimestampDouble;
	double expectedModifyTimestampDouble = 1488785331631.0;

	// ----------------------
	status_t result = BJson::Parse((char*)input,
		message);
	// ----------------------

	CPPUNIT_ASSERT_EQUAL(B_OK, result);

		// this is quite a large test input so a random sample "thing to
		// check" is chosen to indicate that the parse was successful.

	CPPUNIT_ASSERT_EQUAL_MESSAGE("result", B_OK,
		message.FindMessage("result", &resultMessage));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("pkgs", B_OK,
		resultMessage.FindMessage("pkgs", &pkgsMessage));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1", B_OK,
		pkgsMessage.FindMessage("1", &pkgMessage1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("modifyTimestamp", B_OK,
		pkgMessage1.FindDouble("modifyTimestamp", &modifyTimestampDouble));

	CPPUNIT_ASSERT_EQUAL(expectedModifyTimestampDouble, modifyTimestampDouble);
}
예제 #4
0
status_t
BMailAccountSettings::Reload()
{
	BFile file(&fAccountFile, B_READ_ONLY);
	status_t status = file.InitCheck();
	if (status != B_OK)
		return status;
	BMessage settings;
	settings.Unflatten(&file);

	int32 id;
	if (settings.FindInt32("id", &id) == B_OK)
		fAccountID = id;
	settings.FindString("name", &fAccountName);
	settings.FindString("real_name", &fRealName);
	settings.FindString("return_address", &fReturnAdress);

	BMessage inboundSettings;
	settings.FindMessage("inbound", &inboundSettings);
	fInboundSettings.Load(inboundSettings);
	BMessage outboundSettings;
	settings.FindMessage("outbound", &outboundSettings);
	fOutboundSettings.Load(outboundSettings);

	if (settings.FindBool("inbound_enabled", &fInboundEnabled) != B_OK)
		fInboundEnabled = true;
	if (settings.FindBool("outbound_enabled", &fOutboundEnabled) != B_OK)
		fOutboundEnabled = true;

	fModified = false;
	return B_OK;
}
void
DriverSettingsMessageAdapterTest::TestMessage()
{
	const settings_template kSubTemplate[] = {
		{B_BOOL_TYPE, "bool", NULL},
		{}
	};
	const settings_template kTemplate[] = {
		{B_MESSAGE_TYPE, "message", kSubTemplate},
		{}
	};
	Settings settingsA("message {\n"
		"    bool\n"
		"}\n");
	BMessage message;
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsA.ToMessage(kTemplate, message));
	BMessage subMessage;
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("bool", true, subMessage.GetBool("bool"));
	CPPUNIT_ASSERT_EQUAL(1, message.CountNames(B_ANY_TYPE));

	Settings settingsB("message {\n"
		"}\n");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsB.ToMessage(kTemplate, message));
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL(1, message.CountNames(B_ANY_TYPE));

	Settings settingsC("\n");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsC.ToMessage(kTemplate, message));
	CPPUNIT_ASSERT(message.IsEmpty());
}
예제 #6
0
status_t
ThemeManager::SetThemeAt(int32 id, BMessage &copyfrom)
{
	FENTRY;
	BMessage *theme;
	BMessage finfos;
	BMessage tinfos;
	BString s, s2;
	int32 i;

	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return ENOENT;
	copyfrom.FindMessage(Z_THEME_INFO_MESSAGE, &finfos);
	copyfrom.RemoveName(Z_THEME_INFO_MESSAGE);
	copyfrom.RemoveName(Z_THEME_LOCATION);
	theme->FindMessage(Z_THEME_INFO_MESSAGE, &tinfos);
	tinfos.RemoveName(Z_THEME_MODULE_TAG);
	for (i = 0; finfos.FindString(Z_THEME_MODULE_TAG, i, &s); i++)
		tinfos.AddString(Z_THEME_MODULE_TAG, s);
	*theme = copyfrom;
	return B_OK;
}
예제 #7
0
void
JsonToMessageTest::TestArrayB()
{
	BMessage message;
	BMessage subMessage;
	BMessage subSubMessage;
	BString stringValue;

	// ----------------------
	BJson::Parse(JSON_SAMPLE_ARRAY_B_IN, message);
	// ----------------------

	CPPUNIT_ASSERT_EQUAL_MESSAGE("!find [0]", B_OK,
		message.FindString("0", &stringValue));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("!eq [0]", BString("Whirinaki"), stringValue);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("!find [1]", B_OK,
		message.FindString("1", &stringValue));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("!eq [1]", BString("Wellington"), stringValue);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("!find [2]", B_OK,
		message.FindMessage("2", &subMessage));

	CPPUNIT_ASSERT_EQUAL_MESSAGE("!find [2.0]", B_OK,
		subMessage.FindMessage("key", &subSubMessage));

	CPPUNIT_ASSERT_EQUAL_MESSAGE("!find [2.0.0]", B_OK,
		subSubMessage.FindString("0", &stringValue));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("!eq [2.0.0]", BString("value"), stringValue);
}
예제 #8
0
void
LaunchDaemon::_AddRunTargets(BMessage& message)
{
	BMessage runMessage;
	for (int32 index = 0; message.FindMessage("run", index,
			&runMessage) == B_OK; index++) {
		BMessage conditions;
		bool pass = true;
		if (runMessage.FindMessage("if", &conditions) == B_OK) {
			Condition* condition = Conditions::FromMessage(conditions);
			if (condition != NULL) {
				pass = condition->Test(*this);
				debug_printf("Test: %s -> %d\n", condition->ToString().String(),
					pass);
				delete condition;
			} else
				debug_printf("Could not parse condition!\n");
		}

		if (pass) {
			_AddRunTargets(runMessage, NULL);
			_AddRunTargets(runMessage, "then");
		} else {
			_AddRunTargets(runMessage, "else");
		}
	}
}
void
DriverSettingsMessageAdapterTest::TestParent()
{
	const settings_template kSubTemplate[] = {
		{B_STRING_TYPE, "name", NULL, true},
		{B_BOOL_TYPE, "bool", NULL},
		{}
	};
	const settings_template kTemplate[] = {
		{B_MESSAGE_TYPE, "message", kSubTemplate},
		{}
	};
	Settings settingsA("message first {\n"
		"    bool\n"
		"}\n");
	BMessage message;
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsA.ToMessage(kTemplate, message));
	BMessage subMessage;
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("bool", true, subMessage.GetBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("first"),
		BString(subMessage.GetString("name")));

	Settings settingsB("message second\n");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsB.ToMessage(kTemplate, message));
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL(false, subMessage.HasBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("second"),
		BString(subMessage.GetString("name", "-/-")));

	const settings_template kSubSubTemplateC[] = {
		{B_STRING_TYPE, "subname", NULL, true},
		{B_BOOL_TYPE, "bool", NULL},
		{}
	};
	const settings_template kSubTemplateC[] = {
		{B_STRING_TYPE, "name", NULL, true},
		{B_MESSAGE_TYPE, "sub", kSubSubTemplateC},
		{}
	};
	const settings_template kTemplateC[] = {
		{B_MESSAGE_TYPE, "message", kSubTemplateC},
		{}
	};

	Settings settingsC("message other {\n"
		"    sub third {\n"
		"        hun audo\n"
		"    }\n"
		"    sub fourth\n"
		"}");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsC.ToMessage(kTemplateC, message));
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL(false, subMessage.HasBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("other"),
		BString(subMessage.GetString("name", "-/-")));
}
예제 #10
0
void
BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
	bool allowDrags)
{
	fContainerView = view;
	fStream = NULL;
	fEntry = entry;
	fFilter = NULL;
	fGenCount = 1;
	fAllowDragging = allowDrags;
	fDirty = true;
	fDisplayZombies = false;
	fAllowZombies = true;
	fTypeEnforced = false;

	if (entry)
		fStream = new BFile(entry, B_READ_ONLY);
	else
		fStream = stream;

	fFilter = new ShelfContainerViewFilter(this, fContainerView);

	fContainerView->AddFilter(fFilter);
	fContainerView->_SetShelf(this);

	if (fStream) {
		BMessage archive;

		if (archive.Unflatten(fStream) == B_OK) {
			bool allowZombies;
			if (archive.FindBool("_zom_dsp", &allowZombies) != B_OK)
				allowZombies = false;

			SetDisplaysZombies(allowZombies);

			if (archive.FindBool("_zom_alw", &allowZombies) != B_OK)
				allowZombies = true;

			SetAllowsZombies(allowZombies);

			int32 genCount;
			if (!archive.FindInt32("_sg_cnt", &genCount))
				genCount = 1;

			BMessage replicant;
			BMessage *replmsg = NULL;
			for (int32 i = 0; archive.FindMessage("replicant", i, &replicant) == B_OK; i++) {
				BPoint point;
				replmsg = new BMessage();
				replicant.FindPoint("position", &point);
				replicant.FindMessage("message", replmsg);
				AddReplicant(replmsg, point);
			}
		}
	}
}
status_t Converter::ConvertPDoc2FreeMind()
{
	status_t		err					= B_OK;
	BMessage		*inMessage			= new BMessage();
	BMessage		*tmpMessage			= new BMessage();
	void			*id					= NULL;

 	allConnections	= new BMessage();
	selected		= new BMessage();
	allNodes		= new BMessage();


	err = inMessage->Unflatten(in);
	if (err == B_OK)
	{
		inMessage->FindMessage("PDocument::allConnections",allConnections);
		inMessage->FindMessage("PDocument::selected",selected);
		inMessage->FindMessage("PDocument::allNodes",allNodes);
		int32 i = 0;
		while(allNodes->FindMessage("node",i,tmpMessage)==B_OK)
		{
			tmpMessage->FindPointer("this",&id);
			nodes[(int32)id]=tmpMessage;
			tmpMessage = new BMessage();
-			i++;
		}
		i = 0;
		while(allConnections->FindMessage("node",i,tmpMessage)==B_OK)
		{
			tmpMessage->FindPointer("this",&id);
			connections[(int32)id]=tmpMessage;
			tmpMessage = new BMessage();
			i++;
		}

		BMessage	*node= GuessStartNode();
		TiXmlDocument	doc;
		TiXmlElement	freeMap("map");
		freeMap.SetAttribute("version","0.9.0");
		freeMap.SetAttribute("background_color","#ffffff");
		TiXmlComment	comment("this File was gernerated by ProjectConceptor! - To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");
		freeMap.InsertEndChild(comment);

		tmpMessage=GuessStartNode();
	//	tmpMessage = nodes.begin()->second;
		freeMap.InsertEndChild(ProcessNode(tmpMessage));
		doc.InsertEndChild(freeMap);
		TiXmlPrinter	printer;
//		printer.SetStreamPrinting();
//		printer.SetLineBreak("\n");
//		printer.SetIndent("\t");
		doc.Accept( &printer );
		out->Write(printer.CStr(),strlen(printer.CStr()));
	}
	return err;
}
예제 #12
0
BMessage* Paste::Do(PDocument *doc, BMessage *settings)
{
	BMessage 	*clip				= NULL;
	BMessage	*node				= new BMessage();
	BMessage	*deIndexedNode		= NULL;
	BMessage	*connect			= NULL;
	bool		connectselect		= false;
	BMessage	*copyMessage		= new BMessage;
	int32		messagelen			= 0;
	int32		i					= 0;
	Indexer		*indexer			= new Indexer(doc);
	if (be_clipboard->Lock())
	{
		if (clip = be_clipboard->Data())
		{
//			clip->FindData("application/x-vnd.projectconceptor-document", B_MIME_TYPE, (const void **)&copyMessage, &messagelen);
			clip->FindMessage("test",copyMessage);
			copyMessage->PrintToStream();
		}
		be_clipboard->Unlock();
	}

	if (copyMessage)
	{
		BMessage	*inserter	= new BMessage(P_C_EXECUTE_COMMAND);
		BMessage	*select		= new BMessage(P_C_EXECUTE_COMMAND);
		inserter->AddString("Command::Name","Insert");
		select->AddString("Command::Name","Select");
		while (copyMessage->FindMessage("node",i,node) == B_OK)
		{
			if (node->what == P_C_CONNECTION_TYPE)
				deIndexedNode		= indexer->DeIndexConnection(node);
			else
			{
				deIndexedNode		= indexer->RegisterDeIndexNode(node);
				//only select nodes.. because es the copy and paste funktion with selected nodes dosent work proper
				select->AddPointer("node",deIndexedNode);
			}
			inserter->AddPointer("node",deIndexedNode);

			i++;
			node = new BMessage();
		}
		i=0;
		while (inserter->FindPointer("node",i,(void **)&node) == B_OK)
		{
			if (node->what != P_C_CONNECTION_TYPE)
				indexer->DeIndexNode(node);
			i++;
		}
		inserter->AddMessage("PCommand::subPCommand",select);
		PRINT_OBJECT(*inserter);
		(new BMessenger(NULL,doc))->SendMessage(inserter);
	}
	return settings;
}
예제 #13
0
status_t
TeamSettings::SetTo(const BMessage& archive,
	const TeamUiSettingsFactory& factory)
{
	_Unset();

	status_t error = archive.FindString("teamName", &fTeamName);
	if (error != B_OK)
		return error;

	// add breakpoints
	BMessage childArchive;
	for (int32 i = 0; archive.FindMessage("breakpoints", i, &childArchive)
			== B_OK; i++) {
		BreakpointSetting* breakpointSetting
			= new(std::nothrow) BreakpointSetting;
		if (breakpointSetting == NULL)
			return B_NO_MEMORY;

		error = breakpointSetting->SetTo(childArchive);
		if (error == B_OK && !fBreakpoints.AddItem(breakpointSetting))
			error = B_NO_MEMORY;
		if (error != B_OK) {
			delete breakpointSetting;
			return error;
		}
	}

	// add UI settings
	for (int32 i = 0; archive.FindMessage("uisettings", i, &childArchive)
		== B_OK; i++) {
		TeamUiSettings* setting = NULL;
		error = factory.Create(childArchive, setting);
		if (error == B_OK && !fUiSettings.AddItem(setting))
			error = B_NO_MEMORY;
		if (error != B_OK) {
			delete setting;
			return error;
		}
	}

	if (archive.FindMessage("filemanagersettings", &childArchive) == B_OK) {
		error = fFileManagerSettings->SetTo(childArchive);
		if (error != B_OK)
			return error;
	}

	if (archive.FindMessage("signalsettings", &childArchive) == B_OK) {
		error = fSignalSettings->SetTo(childArchive);
		if (error != B_OK)
			return error;
	}

	return B_OK;
}
예제 #14
0
void
LaunchDaemon::_AddJobs(Target* target, BMessage& message)
{
	BMessage job;
	for (int32 index = 0; message.FindMessage("service", index,
			&job) == B_OK; index++) {
		_AddJob(target, true, job);
	}

	for (int32 index = 0; message.FindMessage("job", index, &job) == B_OK;
			index++) {
		_AddJob(target, false, job);
	}
}
예제 #15
0
파일: MainApp.cpp 프로젝트: DonCN/haiku
bool
MainApp::QuitRequested()
{
	// Make sure we store the current playlist, if applicable.
	for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
		MainWin* playerWindow = dynamic_cast<MainWin*>(window);
		if (playerWindow == NULL)
			continue;

		BAutolock _(playerWindow);

		BMessage quitMessage;
		playerWindow->GetQuitMessage(&quitMessage);

		// Store the playlist if there is one. If the user has multiple
		// instances playing audio at the this time, the first instance wins.
		BMessage playlistArchive;
		if (quitMessage.FindMessage("playlist", &playlistArchive) == B_OK) {
			_StoreCurrentPlaylist(&playlistArchive);
			break;
		}
	}

	// Note: This needs to be done here, SettingsWindow::QuitRequested()
	// returns "false" always. (Standard BApplication quit procedure will
	// hang otherwise.)
	if (fSettingsWindow && fSettingsWindow->Lock())
		fSettingsWindow->Quit();
	fSettingsWindow = NULL;

	// store the current file panel ref in the global settings
	Settings::Default()->SetFilePanelFolder(fLastFilePanelFolder);

	return BApplication::QuitRequested();
}
예제 #16
0
status_t
ThemeManager::SetThemeKeywords(int32 id, BString keywords)
{
	FENTRY;
	status_t err;
	BMessage msg;
	BMessage *theme;
	
	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return EINVAL;
	
	err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
	if (err) {
		msg.MakeEmpty();
		theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
	}
	err = msg.ReplaceString(Z_THEME_KEYWORDS, keywords);
	if (err)
		err = msg.AddString(Z_THEME_KEYWORDS, keywords);
	if (err)
		return err;
	err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
	return err;
}
BObjectList<PootleProject>
PootleProjectsEndpoint::Get(int limit, int offset)
{
	BObjectList<PootleProject> objectlist(20, true);
	BString url;
	int32 count = -1;
	if (limit == -1)
		limit = 100;

	url.SetToFormat("?limit=%d&offset=%d", limit, offset);
	BMessage data = _GetAll(url, limit < 0 ? 0 : limit);
	data.GetInfo("data", NULL, &count);

	if (count < 0)
		return objectlist;

	for (int32 i = 0; i < count; i++) {
		BMessage msg;
		data.FindMessage("data", i, &msg);
		PootleProject *lang = new PootleProject(this, msg);
		objectlist.AddItem(lang);
	}
	
	return objectlist;
}
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;
}
예제 #19
0
/*!	\brief Returns a BDiskDevice for a given device, session or partition ID.

	The supplied \a device is initialized to the device the object identified
	by \a id belongs to.

	\param fieldName "device_id", "sesison_id" or "partition_id" according to
		   the type of object the device shall be retrieved for.
	\param id The ID of the device, session or partition to be retrieved.
	\param device Pointer to a pre-allocated BDiskDevice to be initialized
		   to the device to be retrieved.
	\return
	- \c B_OK: Everything went fine.
	- \c B_ENTRY_NOT_FOUND: A device, session or partition respectively with
		 ID \a id could not be found.
	- other error codes
*/
status_t
BDiskDeviceRoster::_GetObjectWithID(const char *fieldName, int32 id,
	BDiskDevice *device) const
{
	status_t error = (device ? B_OK : B_BAD_VALUE);
	// compose request message
	BMessage request(B_REG_GET_DISK_DEVICE);
	if (error == B_OK)
		error = request.AddInt32(fieldName, id);
	// send request
	BMessage reply;
	if (error == B_OK)
		error = fManager.SendMessage(&request, &reply);
	// analyze reply
	if (error == B_OK) {
		// result
		status_t result = B_OK;
		error = reply.FindInt32("result", &result);
		if (error == B_OK)
			error = result;
		// device
		BMessage archive;
		if (error == B_OK)
			error = reply.FindMessage("device", &archive);
		if (error == B_OK)
			error = device->_Unarchive(&archive);
	}
	return error;
}
예제 #20
0
status_t
ThemeManager::SetThemeDescription(int32 id, BString description)
{
	FENTRY;
	status_t err;
	BMessage msg;
	BMessage *theme;
	
	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return EINVAL;
	
	err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
	if (err) {
		msg.MakeEmpty();
		theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
	}
	err = msg.ReplaceString(Z_THEME_DESCRIPTION, description);
	if (err)
		err = msg.AddString(Z_THEME_DESCRIPTION, description);
	if (err)
		return err;
	err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
	return err;
}
예제 #21
0
status_t
BDaemonClient::_ExtractPackageInfoSet(const BMessage& message,
	const char* field, BPackageInfoSet& _infos)
{
	// get the number of items
	type_code type;
	int32 count;
	if (message.GetInfo(field, &type, &count) != B_OK) {
		// the field is missing
		return B_OK;
	}
	if (type != B_MESSAGE_TYPE)
		return B_BAD_DATA;

	for (int32 i = 0; i < count; i++) {
		BMessage archive;
		status_t error = message.FindMessage(field, i, &archive);
		if (error != B_OK)
			return error;

		BPackageInfo info(&archive, &error);
		if (error != B_OK)
			return error;

		error = _infos.AddInfo(info);
		if (error != B_OK)
			return error;
	}

	return B_OK;
}
예제 #22
0
void
LaunchDaemon::_SetEnvironment(BaseJob* job, const BMessage& message)
{
	BMessage environmentMessage;
	if (message.FindMessage("env", &environmentMessage) == B_OK)
		job->SetEnvironment(environmentMessage);
}
예제 #23
0
void
BrowsingHistory::_LoadSettings()
{
	if (fSettingsLoaded)
		return;

	fSettingsLoaded = true;

	BFile settingsFile;
	if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) {
		BMessage settingsArchive;
		settingsArchive.Unflatten(&settingsFile);
		if (settingsArchive.FindInt32("max history item age",
				&fMaxHistoryItemAge) != B_OK) {
			fMaxHistoryItemAge = 7;
		}
		BDateTime oldestAllowedDateTime
			= BDateTime::CurrentDateTime(B_LOCAL_TIME);
		oldestAllowedDateTime.Date().AddDays(-fMaxHistoryItemAge);

		BMessage historyItemArchive;
		for (int32 i = 0; settingsArchive.FindMessage("history item", i,
				&historyItemArchive) == B_OK; i++) {
			BrowsingHistoryItem item(&historyItemArchive);
			if (oldestAllowedDateTime < item.DateTime())
				_AddItem(item, true);
			historyItemArchive.MakeEmpty();
		}
	}
}
예제 #24
0
static void
print_log(const BMessage& log)
{
	time_t now = time(NULL);
	bigtime_t runtime = system_time();

	for (int32 index = 0;; index++) {
		BMessage item;
		if (log.FindMessage("item", index, &item) != B_OK)
			break;

		uint64 when;
		const char* message;
		if (item.FindUInt64("when", &when) != B_OK
			|| item.FindString("message", &message) != B_OK)
			break;

		time_t at = now - (runtime - when) / 1000000l;
		struct tm tm;
		localtime_r(&at, &tm);
		char label[256];
		strftime(label, sizeof(label), "%F %X", &tm);
		printf("%s %s\n", label, message);
	}
}
예제 #25
0
status_t
ThemeManager::SetThemeHasInfoFor(int32 id, BString module)
{
	FENTRY;
	status_t err;
	BMessage msg;
	BMessage *theme;
	
	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return EINVAL;
	
	err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
	if (err) {
		msg.MakeEmpty();
		theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
	}
	err = theme->AddString(Z_THEME_MODULE_TAG, module);
	if (err)
		return err;
	err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
	return err;
}
예제 #26
0
void
JsonToMessageTest::TestObjectA()
{
	BMessage message;
	BMessage subMessage;
	BString stringValue;

	// ----------------------
	BJson::Parse(JSON_SAMPLE_OBJECT_A_IN, message);
	// ----------------------

	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindString("weather", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("raining"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindString("humidity", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("too-high"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("daysOfWeek", &subMessage));

	CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindString("0", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("MON"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindString("1", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("TUE"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindString("2", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("WED"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindString("3", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("THR"), stringValue);

	CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindString("4", &stringValue));
	CPPUNIT_ASSERT_EQUAL(BString("FRI"), stringValue);
}
예제 #27
0
void
PictureView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_REFS_RECEIVED:
		case B_SIMPLE_DATA:
		{
			entry_ref ref;
			if (message->FindRef("refs", &ref) == B_OK
				&& _LoadPicture(&ref) == B_OK)
				MakeFocus(true);
			else
				_HandleDrop(message);
			break;
		}

		case B_MIME_DATA:
			// TODO
			break;

		case B_COPY_TARGET:
			_HandleDrop(message);
			break;

		case B_PASTE:
		{
			if (be_clipboard->Lock() != B_OK)
				break;

			BMessage* data = be_clipboard->Data();
			BMessage archivedBitmap;
			if (data->FindMessage("image/bitmap", &archivedBitmap) == B_OK) {
				BBitmap* picture = new(std::nothrow) BBitmap(&archivedBitmap);
				_SetPicture(picture);
			}

			be_clipboard->Unlock();
			break;
		}

		case B_DELETE:
		case B_TRASH_TARGET:
			_SetPicture(NULL);
			break;

		case kMsgLoadImage:
			fOpenPanel->SetTarget(BMessenger(this));
			fOpenPanel->Show();
			break;

		case kMsgPopUpMenuClosed:
			fShowingPopUpMenu = false;
			break;

		default:
			BView::MessageReceived(message);
			break;
	}
}
예제 #28
0
void
BreakpointsView::LoadSettings(const BMessage& settings)
{
	BMessage breakpointListSettings;
	if (settings.FindMessage("breakpointList", &breakpointListSettings)
		== B_OK)
		fListView->LoadSettings(breakpointListSettings);
}
예제 #29
0
void
LaunchDaemon::_AddJob(Target* target, bool service, BMessage& message)
{
	BString name = message.GetString("name");
	if (name.IsEmpty()) {
		// Invalid job description
		return;
	}
	name.ToLower();

	Job* job = FindJob(name);
	if (job == NULL) {
		job = new (std::nothrow) Job(name);
		if (job == NULL)
			return;

		job->SetService(service);
		job->SetCreateDefaultPort(service);
		job->SetTarget(target);
	}

	if (message.HasBool("disabled"))
		job->SetEnabled(!message.GetBool("disabled", !job->IsEnabled()));

	if (message.HasBool("legacy"))
		job->SetCreateDefaultPort(!message.GetBool("legacy", !service));

	_SetCondition(job, message);
	_SetEvent(job, message);
	_SetEnvironment(job, message);

	BMessage portMessage;
	for (int32 index = 0;
			message.FindMessage("port", index, &portMessage) == B_OK; index++) {
		job->AddPort(portMessage);
	}

	if (message.HasString("launch")) {
		job->Arguments().MakeEmpty();

		const char* argument;
		for (int32 index = 0; message.FindString("launch", index, &argument)
				== B_OK; index++) {
			job->AddArgument(argument);
		}
	}

	const char* requirement;
	for (int32 index = 0;
			message.FindString("requires", index, &requirement) == B_OK;
			index++) {
		job->AddRequirement(requirement);
	}
	if (fInitTarget != NULL)
		job->AddRequirement(fInitTarget->Name());

	fJobs.insert(std::make_pair(job->Title(), job));
}
예제 #30
0
void
BreakpointListView::LoadSettings(const BMessage& settings)
{
	BMessage tableSettings;
	if (settings.FindMessage("breakpointsTable", &tableSettings) == B_OK) {
		GuiSettingsUtils::UnarchiveTableSettings(tableSettings,
			fBreakpointsTable);
	}
}