void NotificationWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: { _LoadSettings(); _LoadAppFilters(); break; } case B_COUNT_PROPERTIES: { BMessage reply(B_REPLY); BMessage specifier; const char* property = NULL; bool messageOkay = true; if (message->FindMessage("specifiers", 0, &specifier) != B_OK) messageOkay = false; if (specifier.FindString("property", &property) != B_OK) messageOkay = false; if (strcmp(property, "message") != 0) messageOkay = false; if (messageOkay) reply.AddInt32("result", fViews.size()); else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } message->SendReply(&reply); break; } case B_CREATE_PROPERTY: case kNotificationMessage: { BMessage reply(B_REPLY); BNotification* notification = new BNotification(message); if (notification->InitCheck() == B_OK) { bigtime_t timeout; if (message->FindInt64("timeout", &timeout) != B_OK) timeout = -1; BMessenger messenger = message->ReturnAddress(); app_info info; if (messenger.IsValid()) be_roster->GetRunningAppInfo(messenger.Team(), &info); else be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info); NotificationView* view = new NotificationView(this, notification, timeout); bool allow = false; appfilter_t::iterator it = fAppFilters.find(info.signature); if (it == fAppFilters.end()) { AppUsage* appUsage = new AppUsage(notification->Group(), true); appUsage->Allowed(notification->Title(), notification->Type()); fAppFilters[info.signature] = appUsage; allow = true; } else { allow = it->second->Allowed(notification->Title(), notification->Type()); } if (allow) { BString groupName(notification->Group()); appview_t::iterator aIt = fAppViews.find(groupName); AppGroupView* group = NULL; if (aIt == fAppViews.end()) { group = new AppGroupView(this, groupName == "" ? NULL : groupName.String()); fAppViews[groupName] = group; GetLayout()->AddView(group); } else group = aIt->second; group->AddInfo(view); _ResizeAll(); reply.AddInt32("error", B_OK); } else reply.AddInt32("error", B_NOT_ALLOWED); } else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } message->SendReply(&reply); break; } case kRemoveView: { NotificationView* view = NULL; if (message->FindPointer("view", (void**)&view) != B_OK) return; views_t::iterator it = find(fViews.begin(), fViews.end(), view); if (it != fViews.end()) fViews.erase(it); _ResizeAll(); break; } default: BWindow::MessageReceived(message); } }
void NotificationWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: { _LoadSettings(); break; } case kNotificationMessage: { if (!fShouldRun) break; BMessage reply(B_REPLY); BNotification* notification = new BNotification(message); if (notification->InitCheck() == B_OK) { bigtime_t timeout; if (message->FindInt64("timeout", &timeout) != B_OK) timeout = fTimeout; BString sourceSignature(notification->SourceSignature()); BString sourceName(notification->SourceName()); bool allow = false; appfilter_t::iterator it = fAppFilters .find(sourceSignature.String()); AppUsage* appUsage = NULL; if (it == fAppFilters.end()) { if (sourceSignature.Length() > 0 && sourceName.Length() > 0) { appUsage = new AppUsage(sourceName.String(), sourceSignature.String(), true); fAppFilters[sourceSignature.String()] = appUsage; // TODO save back to settings file } allow = true; } else { appUsage = it->second; allow = appUsage->Allowed(); } if (allow) { BString groupName(notification->Group()); appview_t::iterator aIt = fAppViews.find(groupName); AppGroupView* group = NULL; if (aIt == fAppViews.end()) { group = new AppGroupView(this, groupName == "" ? NULL : groupName.String()); fAppViews[groupName] = group; GetLayout()->AddView(group); } else group = aIt->second; NotificationView* view = new NotificationView(notification, timeout, fIconSize); group->AddInfo(view); _ShowHide(); reply.AddInt32("error", B_OK); } else reply.AddInt32("error", B_NOT_ALLOWED); } else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } message->SendReply(&reply); break; } case kRemoveGroupView: { AppGroupView* view = NULL; if (message->FindPointer("view", (void**)&view) != B_OK) return; // It's possible that between sending this message, and us receiving // it, the view has become used again, in which case we shouldn't // delete it. if (view->HasChildren()) return; // this shouldn't happen if (fAppViews.erase(view->Group()) < 1) break; view->RemoveSelf(); delete view; _ShowHide(); break; } default: BWindow::MessageReceived(message); } }