void MessageReceived(BMessage* message) { switch (message->what) { case 'BOOM': if (!fBoom) { fBoom = _MakeButton("BOOM"); fLayout2->AddView(fBoom, fLeft, fTop, fRight, fBottom); } else { if (fBoom->IsHidden(fBoom)) fBoom->Show(); else fBoom->Hide(); } break; case 'arcv': { BView* view = GetLayout()->View(); BMessage archive; status_t err = view->Archive(&archive, true); BWindow* window = new BWindow(BRect(30, 30, 400, 400), "ALM Friend Test Clone", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS); window->SetLayout(new BGroupLayout(B_VERTICAL)); BView* clone; if (err == B_OK) err = BUnarchiver::InstantiateObject(&archive, clone); if (err != B_OK) window->AddChild(new BStringView("", "An error occurred!")); else { window->AddChild(clone); } window->Show(); break; } default: BWindow::MessageReceived(message); } }
/*! The add-ons must support the exported C function API if they do, they will be loaded and added to deskbar primary function is the Instantiate function */ status_t TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) { if (!entry) return B_ERROR; node_ref nodeRef; entry->GetNodeRef(&nodeRef); // no duplicates if (NodeExists(nodeRef)) return B_ERROR; BNode node(entry); BPath path; status_t status = entry->GetPath(&path); if (status < B_OK) return status; // load the add-on image_id image = load_add_on(path.Path()); if (image < B_OK) return image; // get the view loading function symbol // we first look for a symbol that takes an image_id // and entry_ref pointer, if not found, go with normal // instantiate function BView* (*entryFunction)(image_id, const entry_ref*); BView* (*itemFunction)(void); BView* view = NULL; entry_ref ref; entry->GetRef(&ref); if (get_image_symbol(image, kInstantiateEntryCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { view = (*entryFunction)(image, &ref); } else if (get_image_symbol(image, kInstantiateItemCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { view = (*itemFunction)(); } else { unload_add_on(image); return B_ERROR; } if (view == NULL || IconExists(view->Name())) { delete view; unload_add_on(image); return B_ERROR; } BMessage* data = new BMessage; view->Archive(data); delete view; AddIcon(data, id, &ref); // add the rep; adds info to list if (addToSettings) { fAddOnSettings.AddString(kReplicantPathField, path.Path()); _SaveSettings(); } return B_OK; }
void BShelf::MessageReceived(BMessage *msg) { if (msg->what == kDeleteReplicant) { BHandler *replicant = NULL; if (msg->FindPointer("_target", (void **)&replicant) == B_OK) { BView *view = dynamic_cast<BView *>(replicant); if (view != NULL) DeleteReplicant(view); } return; } BMessage replyMsg(B_REPLY); status_t err = B_BAD_SCRIPT_SYNTAX; BMessage specifier; int32 what; const char *prop; int32 index; if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) return BHandler::MessageReceived(msg); switch (msg->what) { case B_DELETE_PROPERTY: case B_GET_PROPERTY: case B_GET_SUPPORTED_SUITES: if (strcmp(prop, "Replicant") == 0) { BMessage reply; int32 i; uint32 ID; BView *replicant = NULL; BMessage *repMessage = NULL; err = _GetProperty(&specifier, &reply); if (err == B_OK) err = reply.FindInt32("index", &i); if (err == B_OK && msg->what == B_DELETE_PROPERTY) { // Delete Replicant err = DeleteReplicant(i); break; } if (err == B_OK && msg->what == B_GET_SUPPORTED_SUITES) { err = replyMsg.AddString("suites", "suite/vnd.Be-replicant"); if (err == B_OK) { BPropertyInfo propInfo(sReplicantPropertyList); err = replyMsg.AddFlat("messages", &propInfo); } break; } if (err == B_OK ) repMessage = ReplicantAt(i, &replicant, &ID, &err); if (err == B_OK && replicant) { msg->PopSpecifier(); BMessage archive; err = replicant->Archive(&archive); if (err == B_OK && msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) { err = replyMsg.AddMessage("result", &archive); break; } // now handles the replicant suite err = B_BAD_SCRIPT_SYNTAX; if (msg->what != B_GET_PROPERTY) break; if (strcmp(prop, "ID") == 0) { err = replyMsg.AddInt32("result", ID); } else if (strcmp(prop, "Name") == 0) { err = replyMsg.AddString("result", replicant->Name()); } else if (strcmp(prop, "Signature") == 0) { const char *add_on = NULL; err = repMessage->FindString("add_on", &add_on); if (err == B_OK) err = replyMsg.AddString("result", add_on); } else if (strcmp(prop, "Suites") == 0) { err = replyMsg.AddString("suites", "suite/vnd.Be-replicant"); if (err == B_OK) { BPropertyInfo propInfo(sReplicantPropertyList); err = replyMsg.AddFlat("messages", &propInfo); } } } break; } return BHandler::MessageReceived(msg); case B_COUNT_PROPERTIES: if (strcmp(prop, "Replicant") == 0) { err = replyMsg.AddInt32("result", CountReplicants()); break; } return BHandler::MessageReceived(msg); case B_CREATE_PROPERTY: { BMessage replicantMsg; BPoint pos; if (msg->FindMessage("data", &replicantMsg) == B_OK && msg->FindPoint("location", &pos) == B_OK) { err = AddReplicant(&replicantMsg, pos); } } break; } if (err < B_OK) { replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; if (err == B_BAD_SCRIPT_SYNTAX) replyMsg.AddString("message", "Didn't understand the specifier(s)"); else replyMsg.AddString("message", strerror(err)); } replyMsg.AddInt32("error", err); msg->SendReply(&replyMsg); }
/*! The add-ons must support the exported C function API if they do, they will be loaded and added to deskbar primary function is the Instantiate function */ status_t TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool force) { if (!entry) return B_ERROR; node_ref nodeRef; entry->GetNodeRef(&nodeRef); // no duplicates if (NodeExists(nodeRef)) return B_ERROR; BNode node(entry); if (!force) { status_t error = node.InitCheck(); if (error != B_OK) return error; uint64 deskbarID; ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, &deskbarID, sizeof(fDeskbarSecurityCode)); if (size != sizeof(fDeskbarSecurityCode) || deskbarID != fDeskbarSecurityCode) { // no code or code doesn't match return B_ERROR; } } BPath path; status_t status = entry->GetPath(&path); if (status < B_OK) return status; // load the add-on image_id image = load_add_on(path.Path()); if (image < B_OK) return image; // get the view loading function symbol // we first look for a symbol that takes an image_id // and entry_ref pointer, if not found, go with normal // instantiate function BView* (*entryFunction)(image_id, const entry_ref*); BView* (*itemFunction)(void); BView* view = NULL; entry_ref ref; entry->GetRef(&ref); if (get_image_symbol(image, kInstantiateEntryCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { view = (*entryFunction)(image, &ref); } else if (get_image_symbol(image, kInstantiateItemCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { view = (*itemFunction)(); } else { unload_add_on(image); return B_ERROR; } if (view == NULL || IconExists(view->Name())) { delete view; unload_add_on(image); return B_ERROR; } BMessage* data = new BMessage; view->Archive(data); delete view; AddIcon(data, id, &ref); // add the rep; adds info to list node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, &fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); return B_OK; }