void NotificationWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: { LoadSettings(); LoadAppFilters(); break; } case kResizeToFit: ResizeAll(); 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: { int32 type; const char* content = NULL; const char* title = NULL; const char* app = NULL; BMessage reply(B_REPLY); bool messageOkay = true; if (message->FindInt32("type", &type) != B_OK) type = B_INFORMATION_NOTIFICATION; if (message->FindString("content", &content) != B_OK) messageOkay = false; if (message->FindString("title", &title) != B_OK) messageOkay = false; if (message->FindString("app", &app) != B_OK && message->FindString("appTitle", &app) != B_OK) messageOkay = false; if (messageOkay) { NotificationView* view = new NotificationView(this, (notification_type)type, app, title, content, new BMessage(*message)); appfilter_t::iterator fIt = fAppFilters.find(app); bool allow = false; if (fIt == fAppFilters.end()) { app_info info; BMessenger messenger = message->ReturnAddress(); if (messenger.IsValid()) be_roster->GetRunningAppInfo(messenger.Team(), &info); else be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info); AppUsage* appUsage = new AppUsage(info.ref, app, true); fAppFilters[app] = appUsage; appUsage->Allowed(title, (notification_type)type); allow = true; } else allow = fIt->second->Allowed(title, (notification_type)type); if (allow) { appview_t::iterator aIt = fAppViews.find(app); AppGroupView* group = NULL; if (aIt == fAppViews.end()) { group = new AppGroupView(this, app); fAppViews[app] = group; fBorder->AddChild(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: { void* _ptr; message->FindPointer("view", &_ptr); NotificationView* info = reinterpret_cast<NotificationView*>(_ptr); fBorder->RemoveChild(info); std::vector<NotificationView*>::iterator i = find(fViews.begin(), fViews.end(), info); if (i != fViews.end()) fViews.erase(i); delete info; ResizeAll(); break; } default: BWindow::MessageReceived(message); } }
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 TPanelWindowView::MessageReceived( BMessage *message ) { if ( fDebugLevel >= 20 ) message->PrintToStream(); if ( message->what == B_GET_PROPERTY || message->what == B_SET_PROPERTY || message->what == B_COUNT_PROPERTIES || message->what == B_CREATE_PROPERTY || message->what == B_DELETE_PROPERTY || message->what == B_EXECUTE_PROPERTY ) { int32 index, what; BMessage specifier; const char *property; if ( message->GetCurrentSpecifier( &index, &specifier, &what, &property ) == B_OK ) { BMessage reply( B_REPLY ); if ( message->what == B_GET_PROPERTY || message->what == B_COUNT_PROPERTIES || message->what == B_EXECUTE_PROPERTY ) { if ( GetOptions( property, &reply ) ) reply.AddInt32( "error", 0 ); else reply.AddInt32( "error", -1 ); } else if ( message->what == B_SET_PROPERTY ) { if ( SetOptions( property, message ) ) reply.AddInt32( "error", 0 ); else reply.AddInt32( "error", -1 ); } else if ( message->what == B_CREATE_PROPERTY ) { if ( !strcasecmp( property, "tab" ) ) { int32 index; if ( message->FindInt32( "index", &index ) != B_OK ) index = -1; TShortcutPanel *panel = new TShortcutPanel( this ); fPanels.Lock(); if ( index >= 0 ) { TInnerPanel *rightpanel = fPanels.ItemAt(index); AddPanel( panel, rightpanel ); } else { AddPanel( panel ); } fPanels.Unlock(); ChangedSize(0); reply.AddInt32( "error", 0 ); } else reply.AddInt32( "error", -1 ); } else if ( message->what == B_DELETE_PROPERTY ) { int32 index; if ( specifier.FindInt32( "index", &index ) != B_OK ) reply.AddInt32( "error", -1 ); else { fPanels.Lock(); TInnerPanel *panel = fPanels.ItemAt(index); if ( !panel ) reply.AddInt32( "error", -1 ); else { if ( panel != fRunningAppPanel ) { RemovePanel( panel ); reply.AddInt32( "error", 0 ); } else reply.AddInt32( "error", -1 ); } fPanels.Unlock(); } } message->SendReply( &reply ); } return; } if ( message->WasDropped() ) { BPoint point = message->DropPoint(); ConvertFromScreen( &point ); TInnerPanel *panel = PanelAt( point ); if ( message->what == 'IDRG' ) { TPanelIcon *item; if ( message->FindPointer( "source", (void**)&item ) == B_OK ) { TRaisingIconPanel *previous_parent = item->fParent; TRaisingIconPanel *rpanel; if ( modifiers() & B_CONTROL_KEY ) { rpanel = new TShortcutPanel(this); bool left = false; if ( point.x < (panel->Frame().left+(panel->Frame().Width()/2) ) ) { left = true; } rpanel = new TShortcutPanel(this); AddPanel( rpanel, left ? panel : 0 ); } else rpanel = dynamic_cast<TRaisingIconPanel*>(panel); if ( rpanel && rpanel != fRunningAppPanel ) { TPanelIcon *icon = rpanel->IconAt( point, true ); if ( previous_parent == fRunningAppPanel && dynamic_cast<TShortcutPanel*>(rpanel) ) { int32 index = rpanel->IndexOf(icon); AddShortcut( dynamic_cast<TShortcutPanel*>(rpanel), dynamic_cast<TAppPanelIcon*>(item)->Ref(), index ); } else if ( !dynamic_cast<TTrashIcon*>(icon) || (modifiers() & B_SHIFT_KEY) ) { previous_parent->RemoveItem( item, false ); int32 index = rpanel->IndexOf(icon); rpanel->AddItem( item, index ); } else { if ( item->Removable() ) RemoveShortcut(item); } if ( previous_parent->CountItems() == 0 && previous_parent != fRunningAppPanel ) RemovePanel( previous_parent ); } } } else { if ( panel && panel->HitsFrame( point ) ) { panel->HandleDroppedMessage( message, point ); } else { HandleDroppedMessage( message, point ); } } return; } switch ( message->what ) { case kPanelWindowViewTimer: { if ( DoIconSmallerWithTime() == 0 ) { fTimer->SetInterval( 999999999 ); } break; } case T_MENU_CLOSED: { DebugCall( 8, "Got T_MENU_CLOSED" ); TAwarePopupMenu *source; if ( message->FindPointer( "source", (void**)&source ) == B_OK ) { if ( source == fOpenMenu ) { DebugCall( 9, "fOpenMenu is now 0" ); fOpenMenu = 0; BPoint point; uint32 buttons; GetMouse( &point, &buttons ); if ( !Bounds().Contains( point ) ) Window()->PostMessage(B_EXITED_VIEW); } } break; } case B_SOME_APP_LAUNCHED: { team_id tid; if ( message->FindInt32( "be:team", &tid ) != B_OK ) break; const char *sig; if ( message->FindString( "be:signature", &sig ) != B_OK ) break; entry_ref ref; if ( message->FindRef( "be:ref", &ref ) != B_OK ) break; int32 flags; if ( message->FindInt32( "be:flags", &flags ) != B_OK ) break; if ( sig && strlen(sig) && ( ( flags & B_BACKGROUND_APP ) == 0 ) ) AddTeam( tid, sig, ref ); break; } case B_SOME_APP_QUIT: { team_id tid; if ( message->FindInt32( "be:team", &tid ) != B_OK ) break; RemoveTeam( tid ); break; } case B_SOME_APP_ACTIVATED: { team_id tid; if ( message->FindInt32( "be:team", &tid ) == B_OK ) { TAppPanelIcon *icon = ItemWith( tid ); if ( icon != fLastActiveAppIcon ) { DebugCall( 10, "B_SOME_APP_ACTIVATED %p[..]->%p[%i]", fLastActiveAppIcon, icon, tid ); if ( fLastActiveAppIcon ) fLastActiveAppIcon->SetActive( false ); if ( icon ) icon->SetActive( true ); fLastActiveAppIcon = icon; } } BString temp; message->FindString( "be:signature", &temp ); if ( temp != "application/x-vnd.Be-TSKB" ) fLastActivatedAppSig = temp; break; } case kDoBubbleHelp: { BPoint point; uint32 buttons; GetMouse(&point, &buttons); if ( fPreviousMousePosition != point ) { if ( fBubbleCounter > 0 ) { if ( fBubbleCounter >= 6 ) { fBubbleHelp->HideBubble(); } fBubbleCounter = 0; } fPreviousMousePosition = point; } else { BRegion region; GetClippingRegion(®ion); if ( region.Contains( point ) ) { fBubbleCounter ++; if ( fBubbleCounter == 6 ) { ConvertToScreen(&point); TBubbleTarget *target = fBubbleHelp->TargetAt( point ); if (dynamic_cast<TTrackerIcon*>(target)) { TTrackerIcon *trackerIcon = dynamic_cast<TTrackerIcon*>(target); point.x = Window()->Frame().left + trackerIcon->ContentLocation().x + trackerIcon->Frame().Width() + 4; point.y = Window()->Frame().top; float height = TBubbleHelp::BubbleHeight(target); point.y += height; point.y += (Window()->Frame().Height() - height)/2 -4; } fBubbleHelp->ShowBubble( point, target ); } // else if ( fBubbleCounter == 12 ) // { // fBubbleHelp->HideBubble(); // } } } break; } case 'flsh': { BMessenger target; if ( message->FindMessenger("source", &target ) == B_OK && target.IsValid() ) { TAppPanelIcon *teamicon = ItemWith( target.Team() ); if ( teamicon ) { // todo: flashing teamicon->Flash(); } } break; } case 'mctx': { // todo: context menus break; } default: BView::MessageReceived(message); } }
void NotificationView::_LoadIcon() { // First try to get the icon from the caller application app_info info; BMessenger msgr = fDetails->ReturnAddress(); if (msgr.IsValid()) be_roster->GetRunningAppInfo(msgr.Team(), &info); else if (fType == B_PROGRESS_NOTIFICATION) be_roster->GetAppInfo("application/x-vnd.Haiku-notification_server", &info); BPath path; path.SetTo(&info.ref); fBitmap = _ReadNodeIcon(path.Path(), fParent->IconSize()); if (fBitmap) return; // If that failed get icons from app_server if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) != B_OK) return; path.Append("app_server"); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() != B_OK) return; BResources res(&file); if (res.InitCheck() != B_OK) return; // Which one should we choose? const char* iconName = ""; switch (fType) { case B_INFORMATION_NOTIFICATION: iconName = "info"; break; case B_ERROR_NOTIFICATION: iconName = "stop"; break; case B_IMPORTANT_NOTIFICATION: iconName = "warn"; break; default: return; } // Allocate the bitmap fBitmap = new BBitmap(BRect(0, 0, (float)B_LARGE_ICON - 1, (float)B_LARGE_ICON - 1), B_RGBA32); if (!fBitmap || fBitmap->InitCheck() != B_OK) { fBitmap = NULL; return; } // Load raw icon data size_t size = 0; const uint8* data = (const uint8*)res.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size); if ((data == NULL || BIconUtils::GetVectorIcon(data, size, fBitmap) != B_OK)) fBitmap = NULL; }