filter_result Server::ImMessage(BMessage* msg) { filter_result result = B_DISPATCH_MESSAGE; int32 im_what = msg->FindInt32("im_what"); switch (im_what) { case IM_CONTACT_LIST: { int i = 0; BString id; while (msg->FindString("id", i++, &id) == B_OK) { bool found = false; ContactLinker* item = fRosterMap.ValueFor(id, &found); if (found) continue; item = new ContactLinker(id.String(), Looper()); item->SetProtocolLooper(_LooperFromMessage(msg)); fRosterMap.AddItem(id, item); } result = B_SKIP_MESSAGE; break; } case IM_OWN_STATUS_SET: { //msg->PrintToStream(); int32 status; const char* protocol; if (msg->FindInt32("status", &status) != B_OK) return B_SKIP_MESSAGE; if (msg->FindString("protocol", &protocol) != B_OK) return B_SKIP_MESSAGE; AccountManager* accountManager = AccountManager::Get(); accountManager->SetStatus((CayaStatus)status); break; } case IM_STATUS_SET: { int32 status; if (msg->FindInt32("status", &status) != B_OK) return B_SKIP_MESSAGE; ContactLinker* linker = _EnsureContactLinker(msg); if (!linker) break; linker->SetNotifyStatus((CayaStatus)status); BString statusMsg; if (msg->FindString("message", &statusMsg) == B_OK) { linker->SetNotifyPersonalStatus(statusMsg); linker->GetChatWindow()->UpdatePersonalMessage(); } break; } case IM_CONTACT_INFO: { ContactLinker* linker = _EnsureContactLinker(msg); if (!linker) break; const char* name = NULL; if ((msg->FindString("name", &name) == B_OK) && (strcmp(name, "") != 0)) linker->SetNotifyName(name); BString status; if (msg->FindString("message", &status) == B_OK) { linker->SetNotifyPersonalStatus(status); linker->GetChatWindow()->UpdatePersonalMessage(); } break; } case IM_EXTENDED_CONTACT_INFO: { ContactLinker* linker = _EnsureContactLinker(msg); if (!linker) break; if (linker->GetName().Length() > 0) break; const char* name = NULL; if ((msg->FindString("full name", &name) == B_OK) && (strcmp(name, "") != 0)) linker->SetNotifyName(name); break; } case IM_AVATAR_SET: { ContactLinker* linker = _EnsureContactLinker(msg); if (!linker) break; entry_ref ref; if (msg->FindRef("ref", &ref) == B_OK) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); linker->SetNotifyAvatarBitmap(bitmap); } else linker->SetNotifyAvatarBitmap(NULL); break; } case IM_SEND_MESSAGE: { // Route this message through the appropriate ProtocolLooper ContactLinker* linker = _EnsureContactLinker(msg); if (linker->GetProtocolLooper()) linker->GetProtocolLooper()->PostMessage(msg); break; } case IM_MESSAGE_RECEIVED: { BString id = msg->FindString("id"); if (id.Length() > 0) { bool found = false; ContactLinker* item = fRosterMap.ValueFor(id, &found); if (found) { ChatWindow* win = item->GetChatWindow(); item->ShowWindow(); win->PostMessage(msg); } } result = B_SKIP_MESSAGE; break; } case IM_CONTACT_STARTED_TYPING: case IM_CONTACT_STOPPED_TYPING: { BString id = msg->FindString("id"); if (id.Length() > 0) { bool found = false; ContactLinker* item = fRosterMap.ValueFor(id, &found); if (found) { ChatWindow* win = item->GetChatWindow(); item->ShowWindow(true); win->PostMessage(msg); } } result = B_SKIP_MESSAGE; break; } case IM_PROGRESS: { const char* protocol = NULL; const char* title = NULL; const char* message = NULL; float progress = 0.0f; if (msg->FindString("protocol", &protocol) != B_OK) return result; if (msg->FindString("title", &title) != B_OK) return result; if (msg->FindString("message", &message) != B_OK) return result; if (msg->FindFloat("progress", &progress) != B_OK) return result; if (!CayaPreferences::Item()->NotifyProtocolStatus) break; CayaProtocolAddOn* addOn = ProtocolManager::Get()->ProtocolAddOn(protocol); BNotification notification(B_PROGRESS_NOTIFICATION); notification.SetGroup(BString("Caya")); notification.SetTitle(title); notification.SetIcon(addOn->Icon()); notification.SetContent(message); notification.SetProgress(progress); notification.Send(); break; } case IM_NOTIFICATION: { int32 type = (int32)B_INFORMATION_NOTIFICATION; const char* protocol = NULL; const char* title = NULL; const char* message = NULL; if (msg->FindString("protocol", &protocol) != B_OK) return result; if (msg->FindInt32("type", &type) != B_OK) return result; if (msg->FindString("title", &title) != B_OK) return result; if (msg->FindString("message", &message) != B_OK) return result; if (!CayaPreferences::Item()->NotifyProtocolStatus) break; CayaProtocolAddOn* addOn = ProtocolManager::Get()->ProtocolAddOn(protocol); BNotification notification((notification_type)type); notification.SetGroup(BString("Caya")); notification.SetTitle(title); notification.SetIcon(addOn->Icon()); notification.SetContent(message); notification.Send(); break; } default: break; } return result; }
void MainWindow::MessageReceived(BMessage* message) { switch (message->what) { case kSearchContact: { void* control = NULL; if (message->FindPointer("source", &control) != B_OK) return; SearchBarTextControl* searchBox = static_cast<SearchBarTextControl*>(control); if (searchBox == NULL) return; RosterMap map = fServer->RosterItems(); for (uint32 i = 0; i < map.CountItems(); i++) { ContactLinker* linker = map.ValueAt(i); RosterItem* item = linker->GetRosterItem(); // If the search filter has been deleted show all the items, // otherwise remove the item in order to show only items // that matches the search criteria if (strcmp(searchBox->Text(), "") == 0) AddItem(item); else if (linker->GetName().IFindFirst(searchBox->Text()) == B_ERROR) RemoveItem(item); else AddItem(item); UpdateListItem(item); } break; } case CAYA_SHOW_SETTINGS: { PreferencesDialog* dialog = new PreferencesDialog(); dialog->Show(); break; } case CAYA_OPEN_CHAT_WINDOW: { int index = message->FindInt32("index"); RosterItem* ritem = ItemAt(index); if (ritem != NULL) ritem->GetContactLinker()->ShowWindow(false, true); break; } case CAYA_REPLICANT_STATUS_SET: { int32 status; message->FindInt32("status", &status); AccountManager* accountManager = AccountManager::Get(); accountManager->SetStatus((CayaStatus)status); break; } case CAYA_REPLICANT_SHOW_WINDOW: { if (LockLooper()) { SetWorkspaces(B_CURRENT_WORKSPACE); if ((IsMinimized() || IsHidden()) || fWorkspaceChanged) { Minimize(false); Show(); fWorkspaceChanged = false; } else if ((!IsMinimized() || !IsHidden()) || (!fWorkspaceChanged)) { Minimize(true); } UnlockLooper(); } break; } case IM_MESSAGE: ImMessage(message); break; case IM_ERROR: ImError(message); break; case B_ABOUT_REQUESTED: be_app->PostMessage(message); break; default: BWindow::MessageReceived(message); } }