void PairsWindow::MessageReceived(BMessage* message) { switch (message->what) { case MENU_NEW: NewGame(); break; case MENU_DIFFICULTY: { int32 rows; int32 cols; if (message->FindInt32("rows", &rows) == B_OK && message->FindInt32("cols", &cols) == B_OK) { SetGameSize(rows, cols); } break; } case MENU_ICON_SIZE: { int32 size; if (message->FindInt32("size", &size) == B_OK) { fPairsView->SetIconSize(size); _ResizeWindow(fPairsView->Rows(), fPairsView->Cols()); } break; } case MENU_QUIT: be_app->PostMessage(B_QUIT_REQUESTED); break; case kMsgCardButton: { if (!fIsPairsActive) break; int32 buttonNumber; if (message->FindInt32("button number", &buttonNumber) != B_OK) break; BObjectList<PairsButton>* pairsButtonList = fPairsView->PairsButtonList(); if (pairsButtonList == NULL) break; // look at what icon is behind a button int32 buttonCount = pairsButtonList->CountItems(); for (int32 i = 0; i < buttonCount; i++) { int32 iconPosition = fPairsView->GetIconPosition(i); if (iconPosition == buttonNumber) { fPairCardPosition = i % (buttonCount / 2); fButtonPosition = iconPosition; break; } } // gameplay fButtonClicks++; pairsButtonList->ItemAt(fButtonPosition)->Hide(); if (fIsFirstClick) { fPairCardTmpPosition = fPairCardPosition; fButtonTmpPosition = fButtonPosition; } else { delete fPairComparing; // message of message runner might not have arrived // yet, so it is deleted here to prevent any leaking // just in case BMessage message(kMsgPairComparing); fPairComparing = new BMessageRunner(BMessenger(this), &message, 5 * 100000L, 1); fIsPairsActive = false; } fIsFirstClick = !fIsFirstClick; break; } case kMsgPairComparing: { BObjectList<PairsButton>* pairsButtonList = fPairsView->PairsButtonList(); if (pairsButtonList == NULL) break; delete fPairComparing; fPairComparing = NULL; fIsPairsActive = true; if (fPairCardPosition == fPairCardTmpPosition) fFinishPairs++; else { pairsButtonList->ItemAt(fButtonPosition)->Show(); pairsButtonList->ItemAt(fButtonTmpPosition)->Show(); } // game end and results if (fFinishPairs == pairsButtonList->CountItems() / 2) { BString score; score << fButtonClicks; BString strAbout = B_TRANSLATE("%app%\n" "\twritten by Ralf Schülke\n" "\tCopyright 2008-2010, Haiku Inc.\n" "\n" "You completed the game in %num% clicks.\n"); strAbout.ReplaceFirst("%app%", B_TRANSLATE_SYSTEM_NAME("Pairs")); strAbout.ReplaceFirst("%num%", score); BAlert* alert = new BAlert("about", strAbout.String(), B_TRANSLATE("New game"), B_TRANSLATE("Quit game")); BTextView* view = alert->TextView(); BFont font; view->SetStylable(true); view->GetFont(&font); font.SetSize(18); font.SetFace(B_BOLD_FACE); view->SetFontAndColor(0, strlen(B_TRANSLATE_SYSTEM_NAME("Pairs")), &font); view->ResizeToPreferred(); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() == 0) NewGame(); else be_app->PostMessage(B_QUIT_REQUESTED); } break; } default: BWindow::MessageReceived(message); } }
void NetworkStatusView::_ShowConfiguration(BMessage* message) { static const struct information_entry { const char* label; int32 control; } kInformationEntries[] = { { B_TRANSLATE("Address"), SIOCGIFADDR }, { B_TRANSLATE("Broadcast"), SIOCGIFBRDADDR }, { B_TRANSLATE("Netmask"), SIOCGIFNETMASK }, { NULL } }; SocketOpener socket; if (socket.InitCheck() != B_OK) return; const char* name; if (message->FindString("interface", &name) != B_OK) return; ifreq request; if (!_PrepareRequest(request, name)) return; BString text(B_TRANSLATE("%ifaceName information:\n")); text.ReplaceFirst("%ifaceName", name); size_t boldLength = text.Length(); for (int i = 0; kInformationEntries[i].label; i++) { if (ioctl(socket, kInformationEntries[i].control, &request, sizeof(request)) < 0) { continue; } char address[32]; sockaddr_in* inetAddress = NULL; switch (kInformationEntries[i].control) { case SIOCGIFNETMASK: inetAddress = (sockaddr_in*)&request.ifr_mask; break; default: inetAddress = (sockaddr_in*)&request.ifr_addr; break; } if (inet_ntop(AF_INET, &inetAddress->sin_addr, address, sizeof(address)) == NULL) { return; } text << "\n" << kInformationEntries[i].label << ": " << address; } BAlert* alert = new BAlert(name, text.String(), B_TRANSLATE("OK")); BTextView* view = alert->TextView(); BFont font; view->SetStylable(true); view->GetFont(&font); font.SetFace(B_BOLD_FACE); view->SetFontAndColor(0, boldLength, &font); alert->Go(NULL); }