status_t AppUsage::Unflatten(type_code code, const void* buffer, ssize_t numBytes) { if (code != kTypeCode) return B_ERROR; BMessage msg; status_t status = B_ERROR; status = msg.Unflatten((const char*)buffer); if (status == B_OK) { msg.FindString("signature", &fName); msg.FindBool("allow", &fAllow); type_code type; int32 count = 0; status = msg.GetInfo("notification", &type, &count); if (status != B_OK) return status; for (int32 i = 0; i < count; i++) { NotificationReceived *notification = new NotificationReceived(); msg.FindFlat("notification", i, notification); fNotifications[notification->Title()] = notification; } status = B_OK; } return status; }
status_t Enclosure::Unflatten(type_code /*code*/, const void *buffer, ssize_t /*numBytes*/) { BMessage flat; status_t ret = flat.Unflatten((char *)buffer); fProgress = NULL; if (ret == B_OK) { // Compulsory if (flat.FindString("url", &fURL) != B_OK) ret = B_ERROR; // Optional if (flat.FindString("mime", &fMIME) != B_OK) fMIME = ""; if (flat.FindString("description", &fDescription) != B_OK) fDescription = ""; if (flat.FindInt32("size", &fSize) != B_OK) fSize = -1; if (flat.FindInt32("state", reinterpret_cast<int32 *>(&fState)) != B_OK) fState = Error; flat.FindRef("localRef", &fLocalRef); DownloadProgress progress; if (flat.FindFlat("progress", &progress) == B_OK) { fProgress = new DownloadProgress(progress); }; }; return ret; };
status_t NotificationsView::Load(BMessage& settings) { type_code type; int32 count = 0; if (settings.GetInfo("app_usage", &type, &count) != B_OK) return B_ERROR; // Clean filters appusage_t::iterator auIt; for (auIt = fAppFilters.begin(); auIt != fAppFilters.end(); auIt++) delete auIt->second; fAppFilters.clear(); // Add new filters for (int32 i = 0; i < count; i++) { AppUsage* app = new AppUsage(); settings.FindFlat("app_usage", i, app); fAppFilters[app->Name()] = app; } // Load the applications list _PopulateApplications(); return B_OK; }
status_t BNetworkRoster::GetNextPersistentNetwork(uint32* cookie, wireless_network& network) const { BMessenger networkServer(kNetServerSignature); BMessage message(kMsgGetPersistentNetwork); message.AddInt32("index", (int32)*cookie); BMessage reply; status_t result = networkServer.SendMessage(&message, &reply); if (result != B_OK) return result; status_t status; if (reply.FindInt32("status", &status) != B_OK) return B_ERROR; if (status != B_OK) return status; BMessage networkMessage; if (reply.FindMessage("network", &networkMessage) != B_OK) return B_ERROR; BString networkName; if (networkMessage.FindString("name", &networkName) != B_OK) return B_ERROR; memset(network.name, 0, sizeof(network.name)); strncpy(network.name, networkName.String(), sizeof(network.name)); BNetworkAddress address; if (networkMessage.FindFlat("address", &network.address) != B_OK) network.address.Unset(); if (networkMessage.FindUInt32("flags", &network.flags) != B_OK) network.flags = 0; if (networkMessage.FindUInt32("authentication_mode", &network.authentication_mode) != B_OK) { network.authentication_mode = B_NETWORK_AUTHENTICATION_NONE; } if (networkMessage.FindUInt32("cipher", &network.cipher) != B_OK) network.cipher = B_NETWORK_CIPHER_NONE; if (networkMessage.FindUInt32("group_cipher", &network.group_cipher) != B_OK) { network.group_cipher = B_NETWORK_CIPHER_NONE; } if (networkMessage.FindUInt32("key_mode", &network.key_mode) != B_OK) network.key_mode = B_KEY_MODE_NONE; 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; }
void NotificationWindow::_LoadAppFilters(BMessage& settings) { type_code type; int32 count = 0; if (settings.GetInfo("app_usage", &type, &count) != B_OK) return; for (int32 i = 0; i < count; i++) { AppUsage* app = new AppUsage(); settings.FindFlat("app_usage", i, app); fAppFilters[app->Name()] = app; } }
void NotificationWindow::LoadAppFilters(bool startMonitor) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; path.Append(kSettingsDirectory); if (create_directory(path.Path(), 0755) != B_OK) return; path.Append(kFiltersSettings); BFile file(path.Path(), B_READ_ONLY); BMessage settings; if (settings.Unflatten(&file) != B_OK) return; type_code type; int32 count = 0; if (settings.GetInfo("app_usage", &type, &count) != B_OK) return; for (int32 i = 0; i < count; i++) { AppUsage* app = new AppUsage(); settings.FindFlat("app_usage", i, app); fAppFilters[app->Name()] = app; } if (startMonitor) { node_ref nref; BEntry entry(path.Path()); entry.GetNodeRef(&nref); if (watch_node(&nref, B_WATCH_ALL, BMessenger(this)) != B_OK) { BAlert* alert = new BAlert(B_TRANSLATE("Warning"), B_TRANSLATE("Couldn't start filter monitor." " Live filter changes disabled."), B_TRANSLATE("Darn.")); alert->Go(); } } }
feed_list_t FeedListener::Feeds(void) { feed_list_t feeds; BMessage getFeedList(FeedKit::Private::ToServer::GetFeedList); BMessage feedList; if (SendMessage(&getFeedList, &feedList) == B_OK) { Feed feed; for (int32 i = 0; feedList.FindFlat("feed", i, &feed) == B_OK; i++) { Feed *copy = new Feed(&feed); feed = Feed(); feeds.push_back(copy); }; }; return feeds; };
status_t FindFont(BMessage &message, const char *name, int32 index, BFont *f) { #ifdef B_BEOS_VERSION_DANO return message.FindFlat(name, index, f); #else const void *data; ssize_t len; status_t err = message.FindData(name, 'FONt', index, &data, &len); #define DERR(e) { PRINT(("%s: err: %s\n", __FUNCTION__, strerror(e))); } if (err < B_OK) return err; if (len > (ssize_t)sizeof(*f)) return E2BIG; // Hack: only Dano has BFont : public BFlattenable memcpy((void *)f, data, len); return B_OK; #endif }