void TTracker::ReadyToRun() { gStatusWindow = new BStatusWindow(); InitMimeTypes(); InstallDefaultTemplates(); InstallIndices(); InstallTemporaryBackgroundImages(); fTrashWatcher = new BTrashWatcher(); fTrashWatcher->Run(); fClipboardRefsWatcher = new BClipboardRefsWatcher(); fClipboardRefsWatcher->Run(); fTaskLoop = new StandAloneTaskLoop(true); // open desktop window BContainerWindow *deskWindow = NULL; BDirectory deskDir; if (FSGetDeskDir(&deskDir) == B_OK) { // create desktop BEntry entry; deskDir.GetEntry(&entry); Model *model = new Model(&entry, true); if (model->InitCheck() == B_OK) { AutoLock<WindowList> lock(&fWindowList); deskWindow = new BDeskWindow(&fWindowList); AutoLock<BWindow> windowLock(deskWindow); deskWindow->CreatePoseView(model); deskWindow->Init(); if (TrackerSettings().ShowDisksIcon()) { // create model for root of everything BEntry entry("/"); Model model(&entry); if (model.InitCheck() == B_OK) { // add the root icon to desktop window BMessage message; message.what = B_NODE_MONITOR; message.AddInt32("opcode", B_ENTRY_CREATED); message.AddInt32("device", model.NodeRef()->device); message.AddInt64("node", model.NodeRef()->node); message.AddInt64("directory", model.EntryRef()->directory); message.AddString("name", model.EntryRef()->name); deskWindow->PostMessage(&message, deskWindow->PoseView()); } } } else delete model; } // kick off building the mime type list for find panels, etc. fMimeTypeList = new MimeTypeList(); if (!BootedInSafeMode()) { // kick of transient query killer DeleteTransientQueriesTask::StartUpTransientQueryCleaner(); // the mount_server will have mounted the previous volumes already. _OpenPreviouslyOpenedWindows(); } }
void ServerWindow::DCCGetDialog ( BString nick, BString file, BString size, BString ip, BString port) { BMessage msg (DCC_ACCEPT), reply; msg.AddString ("bowser:nick", nick.String()); msg.AddString ("bowser:file", file.String()); msg.AddString ("bowser:size", size.String()); msg.AddString ("bowser:ip", ip.String()); msg.AddString ("bowser:port", port.String()); //bool handled (false); // ignore this part until some minor details with DCC Prefs are worked out /* const char *directory = "/boot/home/"; entry_ref ref; BEntry entry; create_directory (directory, 0777); if (entry.SetTo (directory) == B_NO_ERROR if (entry.GetRef (&ref) == B_NO_ERROR) { BDirectory dir (&ref); BEntry file_entry; struct stat s; if (file_entry.SetTo (&dir, file.String()) == B_NO_ERROR && file_entry.GetStat (&s) == B_NO_ERROR && S_ISREG (s.st_mode)) { BString buffer; BAlert *alert; int32 which; buffer << "The file \"" << file << "\" already exists in the specified folder. " "Do you want to continue the transfer?"; alert = new BAlert ( "DCC Request", buffer.String(), "Refuse", "Get", "Resume", B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); which = alert->Go(); if (which == 0) { return; } if (which == 2) { BFile file (&file_entry, B_READ_ONLY); off_t position; BPath path; file.GetSize (&position); file_entry.GetPath (&path); msg.AddString ("path", path.Path()); msg.AddInt64 ("pos", position); AddResumeData (&msg); return; } } msg.AddRef ("directory", &ref); msg.AddString ("name", file); sMsgr.SendMessage (&msg); handled = true; } } */ BFilePanel *panel; BString text; text << nick << ": " << file << " (" << size << " bytes)"; panel = new BFilePanel ( B_SAVE_PANEL, &sMsgr, 0, 0, false, &msg); panel->SetButtonLabel (B_DEFAULT_BUTTON, "Accept"); panel->SetButtonLabel (B_CANCEL_BUTTON, "Refuse"); panel->SetSaveText (file.String()); if (panel->Window()->Lock()) { panel->Window()->SetTitle (text.String()); panel->Window()->AddFilter (new DCCFileFilter (panel, msg)); panel->Window()->Unlock(); } panel->Show(); }
void PersonView::BuildGroupMenu() { if (fGroups == NULL) return; BMenuItem* item; while ((item = fGroups->ItemAt(0)) != NULL) { fGroups->RemoveItem(item); delete item; } int32 count = 0; BVolumeRoster volumeRoster; BVolume volume; while (volumeRoster.GetNextVolume(&volume) == B_OK) { BQuery query; query.SetVolume(&volume); char buffer[256]; snprintf(buffer, sizeof(buffer), "%s=*", fCategoryAttribute.String()); query.SetPredicate(buffer); query.Fetch(); BEntry entry; while (query.GetNextEntry(&entry) == B_OK) { BFile file(&entry, B_READ_ONLY); attr_info info; if (file.InitCheck() == B_OK && file.GetAttrInfo(fCategoryAttribute, &info) == B_OK && info.size > 1) { if (info.size > (off_t)sizeof(buffer)) info.size = sizeof(buffer); if (file.ReadAttr(fCategoryAttribute.String(), B_STRING_TYPE, 0, buffer, info.size) < 0) { continue; } const char *text = buffer; while (true) { char* offset = strstr(text, ","); if (offset != NULL) offset[0] = '\0'; if (!fGroups->FindItem(text)) { int32 index = 0; while ((item = fGroups->ItemAt(index)) != NULL) { if (strcmp(text, item->Label()) < 0) break; index++; } BMessage* message = new BMessage(M_GROUP_MENU); message->AddString("group", text); fGroups->AddItem(new BMenuItem(text, message), index); count++; } if (offset) { text = offset + 1; while (*text == ' ') text++; } else break; } } } } if (count == 0) { fGroups->AddItem(item = new BMenuItem( B_TRANSLATE_CONTEXT("none", "Groups list"), new BMessage(M_GROUP_MENU))); item->SetEnabled(false); } fGroups->SetTargetForItems(this); }
static status_t add_to_message(TReadHelper& source, BMessage& target, tiff_tag& tag, const char* name, type_code type) { type_code defaultType = B_INT32_TYPE; double doubleValue = 0.0; int32 intValue = 0; switch (tag.type) { case TIFF_STRING_TYPE: { if (type != B_ANY_TYPE && type != B_STRING_TYPE) return B_BAD_VALUE; char* buffer = (char*)malloc(tag.length); if (buffer == NULL) return B_NO_MEMORY; source(buffer, tag.length); // remove trailing spaces int32 i = tag.length; while ((--i > 0 && isspace(buffer[i])) || !buffer[i]) { buffer[i] = '\0'; } status_t status = target.AddString(name, buffer); free(buffer); return status; } case TIFF_UNDEFINED_TYPE: { if (type != B_ANY_TYPE && type != B_STRING_TYPE && type != B_RAW_TYPE) return B_BAD_VALUE; char* buffer = (char*)malloc(tag.length); if (buffer == NULL) return B_NO_MEMORY; source(buffer, tag.length); status_t status; if (type == B_STRING_TYPE) status = target.AddString(name, buffer); else status = target.AddData(name, B_RAW_TYPE, buffer, tag.length); free(buffer); return status; } // unsigned case TIFF_UINT8_TYPE: intValue = source.Next<uint8>(); break; case TIFF_UINT16_TYPE: defaultType = B_INT32_TYPE; intValue = source.Next<uint16>(); break; case TIFF_UINT32_TYPE: defaultType = B_INT32_TYPE; intValue = source.Next<uint32>(); break; case TIFF_UFRACTION_TYPE: { defaultType = B_DOUBLE_TYPE; double value = source.Next<uint32>(); doubleValue = value / source.Next<uint32>(); break; } // signed case TIFF_INT8_TYPE: intValue = source.Next<int8>(); break; case TIFF_INT16_TYPE: intValue = source.Next<int16>(); break; case TIFF_INT32_TYPE: intValue = source.Next<int32>(); break; case TIFF_FRACTION_TYPE: { defaultType = B_DOUBLE_TYPE; double value = source.Next<int32>(); doubleValue = value / source.Next<int32>(); break; } // floating point case TIFF_FLOAT_TYPE: defaultType = B_FLOAT_TYPE; doubleValue = source.Next<float>(); break; case TIFF_DOUBLE_TYPE: defaultType = B_DOUBLE_TYPE; doubleValue = source.Next<double>(); break; default: return B_BAD_VALUE; } if (defaultType == B_INT32_TYPE) doubleValue = intValue; else intValue = int32(doubleValue + 0.5); if (type == B_ANY_TYPE) type = defaultType; switch (type) { case B_INT32_TYPE: return target.AddInt32(name, intValue); case B_FLOAT_TYPE: return target.AddFloat(name, doubleValue); case B_DOUBLE_TYPE: return target.AddDouble(name, doubleValue); default: return B_BAD_VALUE; } }
EthernetSettingsView::EthernetSettingsView() : BView("EthernetSettingsView", 0, NULL), fCurrentSettings(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fSocket = socket(AF_INET, SOCK_DGRAM, 0); _GatherInterfaces(); // build the GUI BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL); SetLayout(rootLayout); BGridView* controlsGroup = new BGridView(); BGridLayout* layout = controlsGroup->GridLayout(); // insets float inset = ceilf(be_plain_font->Size() * 0.7); rootLayout->SetInsets(inset, inset, inset, inset); rootLayout->SetSpacing(inset); layout->SetSpacing(inset, inset); BPopUpMenu* deviceMenu = new BPopUpMenu(B_TRANSLATE("<no adapter>")); for (int32 i = 0; i < fInterfaces.CountItems(); i++) { BString& name = *fInterfaces.ItemAt(i); BString label = name; BMessage* info = new BMessage(kMsgInfo); info->AddString("interface", name.String()); BMenuItem* item = new BMenuItem(label.String(), info); deviceMenu->AddItem(item); } BPopUpMenu* modeMenu = new BPopUpMenu("modes"); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"), new BMessage(kMsgStaticMode))); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"), new BMessage(kMsgDHCPMode))); modeMenu->AddSeparatorItem(); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"), new BMessage(kMsgDisabledMode))); BPopUpMenu* networkMenu = new BPopUpMenu("networks"); fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu); layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0); layout->AddItem(fDeviceMenuField->CreateMenuBarLayoutItem(), 1, 0); fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), networkMenu); layout->AddItem(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1); layout->AddItem(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1); fTypeMenuField = new BMenuField(B_TRANSLATE("Mode:"), modeMenu); layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2); layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2); fIPTextControl = new BTextControl(B_TRANSLATE("IP address:"), "", NULL); SetupTextControl(fIPTextControl); BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem(); layoutItem->SetExplicitMinSize(BSize( fIPTextControl->StringWidth("XXX.XXX.XXX.XXX") + inset, B_SIZE_UNSET)); layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3); layout->AddItem(layoutItem, 1, 3); fNetMaskTextControl = new BTextControl(B_TRANSLATE("Netmask:"), "", NULL); SetupTextControl(fNetMaskTextControl); layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4); layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4); fGatewayTextControl = new BTextControl(B_TRANSLATE("Gateway:"), "", NULL); SetupTextControl(fGatewayTextControl); layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5); layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5); // TODO: Replace the DNS text controls by a BListView with add/remove // functionality and so on... fPrimaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #1:"), "", NULL); SetupTextControl(fPrimaryDNSTextControl); layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6); layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6); fSecondaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #2:"), "", NULL); SetupTextControl(fSecondaryDNSTextControl); layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7); layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7); fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL); SetupTextControl(fDomainTextControl); layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8); layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8); fErrorMessage = new BStringView("error", ""); fErrorMessage->SetAlignment(B_ALIGN_LEFT); fErrorMessage->SetFont(be_bold_font); fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); layout->AddView(fErrorMessage, 1, 9); // button group (TODO: move to window, but take care of // enabling/disabling) BGroupView* buttonGroup = new BGroupView(B_HORIZONTAL); fRevertButton = new BButton(B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); fRevertButton->SetEnabled(false); buttonGroup->GroupLayout()->AddView(fRevertButton); buttonGroup->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply)); fApplyButton->SetEnabled(false); buttonGroup->GroupLayout()->AddView(fApplyButton); rootLayout->AddView(controlsGroup); rootLayout->AddView(buttonGroup); }
// -------------------------------------------------------------- void ControlsWindow::MessageReceived ( BMessage * msg ) { switch (msg->what) { case SET_DEVICE_MSG: { ssize_t data_size; SANE_Status status; const SANE_Device * device_info; if ( msg->FindData("device", B_RAW_TYPE, (const void **) &device_info, &data_size) != B_OK ) break; m_device_info = device_info; if ( m_device ) sane_close(m_device); m_device = NULL; ScannerOptionView * option; BView * child; child = m_panel->ChildAt(0); while ( child ) { option = dynamic_cast<ScannerOptionView *>(child); if ( option ) option->RemoveSelf(); child = child->NextSibling(); }; status = sane_open(m_device_info->name, &m_device); if ( status != SANE_STATUS_GOOD ) { fprintf (stderr, "sane_open: %s\n", sane_strstatus (status)); BAlert * alert = new BAlert("sane_open", sane_strstatus(status), "Argh"); alert->Go(); break; }; const SANE_Option_Descriptor * desc; // m_options_lv->MakeEmpty(); printf("Options for device %s:\n", m_device_info->name); int opt = 1; // skip first option (option 0 = number of options) BRect r = m_panel->Bounds(); r.top = 80; r.InsetBy(8, 8); while ( (desc = sane_get_option_descriptor(m_device, opt)) != NULL ) { if (desc->type != SANE_TYPE_GROUP) { ScannerOptionView * ov = new ScannerOptionView(r, desc->name, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, 0, m_device, opt); if ( ov->Build() == B_OK ) { m_panel->AddChild(ov); r.top += ov->Bounds().Height(); m_tooltip->SetText(ov, desc->desc); } else delete ov; }; BString label; if (desc->type == SANE_TYPE_GROUP) label << "-- "; label << desc->title; if (desc->type == SANE_TYPE_GROUP) label << " --"; printf(" %d: name = %s\n" " title = %s\n" " desc = %s\n" " type = %d\n" " unit = %s\n" " size = %d\n" " cap = 0x%0x\n", opt, desc->name, desc->title, desc->desc, desc->type, get_unit2(desc->unit), desc->size, desc->cap); // m_options_lv->AddItem(new BStringItem(label.String())); opt++; }; BMessage * msg; msg = new BMessage(MainWindow::DEVICE_CHANGED_MSG); msg->AddString("device_name", m_device_info->name); m_parent_window->PostMessage(msg); delete msg; break; }; case SCAN_MSG: { SANE_Handle device; device = Device(); if ( ! device ) break; if ( m_scan_thread_id != -1 ) { // already launched... m_cancel_scan = true; break; }; m_cancel_scan = false; m_scan_thread_id = spawn_thread(_ScanThread, "scan", B_NORMAL_PRIORITY, this); resume_thread(m_scan_thread_id); break; }; default: inherited::MessageReceived(msg); } }
void AboutView::_AddCopyrightsFromAttribute() { #ifdef __HAIKU__ // open the app executable file char appPath[B_PATH_NAME_LENGTH]; int appFD; if (BPrivate::get_app_path(appPath) != B_OK || (appFD = open(appPath, O_RDONLY)) < 0) { return; } // open the attribute int attrFD = fs_fopen_attr(appFD, "COPYRIGHTS", B_STRING_TYPE, O_RDONLY); close(appFD); if (attrFD < 0) return; // attach it to a FILE FILE* attrFile = fdopen(attrFD, "r"); if (attrFile == NULL) { close(attrFD); return; } CObjectDeleter<FILE, int> _(attrFile, fclose); // read and parse the copyrights BMessage package; BString fieldName; BString fieldValue; char lineBuffer[LINE_MAX]; while (char* line = fgets(lineBuffer, sizeof(lineBuffer), attrFile)) { // chop off line break size_t lineLen = strlen(line); if (lineLen > 0 && line[lineLen - 1] == '\n') line[--lineLen] = '\0'; // flush previous field, if a new field begins, otherwise append if (lineLen == 0 || !isspace(line[0])) { // new field -- flush the previous one if (fieldName.Length() > 0) { fieldValue = trim_string(fieldValue.String(), fieldValue.Length()); package.AddString(fieldName.String(), fieldValue); fieldName = ""; } } else if (fieldName.Length() > 0) { // append to current field fieldValue += line; continue; } else { // bogus line -- ignore continue; } if (lineLen == 0) continue; // parse new field char* colon = strchr(line, ':'); if (colon == NULL) { // bogus line -- ignore continue; } fieldName.SetTo(line, colon - line); fieldName = trim_string(line, colon - line); if (fieldName.Length() == 0) { // invalid field name continue; } fieldValue = colon + 1; if (fieldName == "Package") { // flush the current package _AddPackageCredit(PackageCredit(package)); package.MakeEmpty(); } } // flush current package _AddPackageCredit(PackageCredit(package)); #endif }
//--------------------------------------------------------------- // Copy File, not only data but also attributes ;-) //--------------------------------------------------------------- void TJerFile::CopyFile( const char *sourcepath, const char *destinationpath ) { BFile *source = 0L, *destination = 0L; entry_ref ref; uint8 data[2048]; int32 len = 2048; char buf[B_ATTR_NAME_LENGTH]; void *buffer = NULL; int32 lengthR,lengthW; attr_info attribute; BEntry entry( sourcepath ); if( B_OK == entry.InitCheck() ) { if( B_OK == entry.GetRef( &ref ) ) { source = new BFile( &ref ,B_READ_ONLY); } else { string truc("Error opening file in read only mode: "); truc = truc + sourcepath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } } else { string truc("Error constructing file object: "); truc = truc + sourcepath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } entry.SetTo( destinationpath ); if( B_OK == entry.InitCheck() ) { if( B_OK == entry.GetRef( &ref ) ) { destination = new BFile( &ref ,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); } else { string truc("Error opening file in read write mode: "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } } else { string truc("Error destination constructing file object: "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } if( source && destination ) { BMessage *AMessage; AMessage = new BMessage(B_UPDATE_STATUS_BAR); AMessage->AddFloat("delta",1.0); AMessage->AddString("text","Copy..."); AMessage->AddString("trailingtext",destinationpath); MyInvoker.Invoke(AMessage); delete AMessage; while (source->GetNextAttrName(buf) == B_NO_ERROR) { source->GetAttrInfo(buf,&attribute); if (buffer!=NULL) { free(buffer); } buffer = (void *)malloc(sizeof(char)*(attribute.size +1)); lengthR = source->ReadAttr(buf,attribute.type,0,buffer,attribute.size); lengthW = destination->WriteAttr(buf,attribute.type,0,buffer,lengthR); if (lengthR!=lengthW) { string truc("Error copying attribute for file : "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } switch(lengthR) { case B_ENTRY_NOT_FOUND: { GeneralException excep("The attribute doesn't exist.","BJerFile::CopyFile"); throw(excep); break; } case B_FILE_ERROR : { GeneralException excep2("The object is uninitialized.","BJerFile::CopyFile"); throw(excep2); break; } } switch(lengthW) { case B_FILE_ERROR : { GeneralException excep3("This object is a read-only BFile.","BJerFile::CopyFile"); throw(excep3); break; } case B_NOT_ALLOWED : { GeneralException excep4("The node is on a read-only volume.","BJerFile::CopyFile"); throw(excep4); break; } case B_DEVICE_FULL : { GeneralException excep5("Out of disk space.","BJerFile::CopyFile"); throw(excep5); break; } case B_NO_MEMORY : { GeneralException excep6("Not enough memory.","BJerFile::CopyFile"); throw(excep6); break; } } } for( ;; ) { len = source->Read( data, len ); if( len == 0 ) break; destination->Write( data, len ); if( len != 2048 ) break; } //---------- freeing some resources... delete source; delete destination; } }
void ListAgent::MessageReceived (BMessage *msg) { switch (msg->what) { case M_THEME_FONT_CHANGE: { int32 which (msg->FindInt16 ("which")); if (which == F_LISTAGENT) { activeTheme->ReadLock(); listView->SetFont (B_FONT_ROW, &activeTheme->FontAt (F_LISTAGENT)); activeTheme->ReadUnlock(); listView->Invalidate(); } } break; case M_THEME_FOREGROUND_CHANGE: { int32 which (msg->FindInt16 ("which")); bool refresh (false); switch (which) { case C_BACKGROUND: activeTheme->ReadLock(); listView->SetColor (B_COLOR_BACKGROUND, activeTheme->ForegroundAt (C_BACKGROUND)); activeTheme->ReadUnlock(); refresh = true; break; case C_TEXT: activeTheme->ReadLock(); listView->SetColor (B_COLOR_TEXT, activeTheme->ForegroundAt (C_TEXT)); activeTheme->ReadUnlock(); refresh = true; break; case C_SELECTION: activeTheme->ReadLock(); listView->SetColor (B_COLOR_SELECTION, activeTheme->ForegroundAt (C_SELECTION)); activeTheme->ReadUnlock(); refresh = true; break; default: break; } if (refresh) Invalidate(); } break; case M_STATUS_ADDITEMS: { vision_app->pClientWin()->pStatusView()->AddItem (new StatusItem (S_STATUS_LISTCOUNT, ""), true); vision_app->pClientWin()->pStatusView()->AddItem (new StatusItem (S_STATUS_LISTSTAT, ""), true); vision_app->pClientWin()->pStatusView()->AddItem (new StatusItem (S_STATUS_LISTFILTER, "", STATUS_ALIGN_LEFT), true); BString cString; cString << listView->CountRows(); vision_app->pClientWin()->pStatusView()->SetItemValue (0, cString.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue (1, statusStr.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue (2, filter.String(), true); } break; case M_LIST_COMMAND: { if (!processing) { BMessage sMsg (M_SERVER_SEND); BString command ("LIST"); BString params (msg->FindString ("cmd")); if (params != "-9z99") { command.Append (" "); command.Append (params); } sMsg.AddString ("data", command.String()); fSMsgr->SendMessage (&sMsg); processing = true; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (0, "0", true); } } break; case M_LIST_BEGIN: { BMessage msg (M_LIST_UPDATE); listUpdateTrigger = new BMessageRunner (BMessenger(this), &msg, 3000000); statusStr = S_LIST_STATUS_LOADING; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (1, statusStr.String(), true); } break; case M_LIST_DONE: { if (listUpdateTrigger) { delete listUpdateTrigger; listUpdateTrigger = 0; } statusStr = S_LIST_STATUS_DONE; listView->SetSortingEnabled (true); listView->SetSortColumn (channelColumn, true, true); if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (1, statusStr.String(), true); mFind->SetEnabled (true); mFindAgain->SetEnabled (true); mFilter->SetEnabled (true); processing = false; // empty out any remaining channels that fell below the batch cut off AddBatch(); BString cString; cString << listView->CountRows(); if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (0, cString.String(), true); } break; case M_LIST_EVENT: { const char *channel, *users, *topic; msg->FindString ("channel", &channel); msg->FindString ("users", &users); msg->FindString ("topic", &topic); BRow *row (new BRow ()); BStringField *channelField (new BStringField (channel)); BIntegerField *userField (new BIntegerField (atoi(users))); BStringField *topicField (new BStringField (topic)); row->SetField (channelField, channelColumn->LogicalFieldNum()); row->SetField (userField, usersColumn->LogicalFieldNum()); row->SetField (topicField, topicColumn->LogicalFieldNum()); fBuildList.AddItem (row); if (fBuildList.CountItems() == LIST_BATCH_SIZE) AddBatch(); } break; #ifdef __INTEL__ case M_LIST_FILTER: if (msg->HasString ("text")) { const char *buffer; msg->FindString ("text", &buffer); if (filter != buffer) { filter = buffer; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (2, filter.String(), true); regfree (&re); memset (&re, 0, sizeof (re)); regcomp ( &re, filter.String(), REG_EXTENDED | REG_ICASE | REG_NOSUB); BRow *currentRow; BStringField *channel, *topic; while (hiddenItems.CountItems() != 0) { currentRow = hiddenItems.RemoveItemAt (0L); listView->AddRow (currentRow); } if (filter != NULL) { int32 k (0); while (k < listView->CountRows()) { currentRow = listView->RowAt (k); channel = (BStringField *)currentRow->GetField (0); topic = (BStringField *)currentRow->GetField (2); if ((regexec (&re, channel->String(), 0, 0, 0) != REG_NOMATCH) || (regexec (&re, topic->String(), 0, 0, 0) != REG_NOMATCH)) { k++; continue; } else { listView->RemoveRow (currentRow); hiddenItems.AddItem (currentRow); } } } fMsgr.SendMessage (M_LIST_DONE); processing = true; } } else { PromptWindow *prompt (new PromptWindow ( BPoint ((Window()->Frame().right/2) - 100, (Window()->Frame().bottom/2) - 50), " Filter:", "List Filter", filter.String(), this, new BMessage (M_LIST_FILTER), new RegExValidate ("Filter"), true)); prompt->Show(); } break; case M_LIST_FIND: if (msg->HasString ("text")) { int32 selection (listView->IndexOf(listView->CurrentSelection())); const char *buffer; msg->FindString ("text", &buffer); if (strlen (buffer) == 0) { find = buffer; break; } if (selection < 0) { selection = 0; } else { ++selection; } if (find != buffer) { regfree (&fre); memset (&fre, 0, sizeof (fre)); regcomp ( &fre, buffer, REG_EXTENDED | REG_ICASE | REG_NOSUB); find = buffer; } BStringField *field; int32 i; for (i = selection; i < listView->CountRows(); ++i) { field = (BStringField *)listView->RowAt (i)->GetField (0); if (regexec (&fre, field->String(), 0, 0, 0) != REG_NOMATCH) break; } if (i < listView->CountRows()) { BRow* row = listView->RowAt (i); listView->DeselectAll(); listView->AddToSelection (row); listView->ScrollTo(row); listView->Refresh(); } else { listView->DeselectAll(); } } else { PromptWindow *prompt (new PromptWindow ( BPoint ((Window()->Frame().right / 2) - 100, (Window()->Frame().bottom/2) - 50), S_LIST_PROMPT_LABEL, S_LIST_PROMPT_TITLE, find.String(), this, new BMessage (M_LIST_FIND), new RegExValidate ("Find:"), true)); prompt->Show(); } break; case M_LIST_FAGAIN: if (find.Length()) { msg->AddString ("text", find.String()); msg->what = M_LIST_FIND; fMsgr.SendMessage (msg); } break; #endif case M_LIST_INVOKE: { BMessage msg (M_SUBMIT); BString buffer; BRow *row (listView->CurrentSelection()); if (row) { buffer = "/JOIN "; buffer += ((BStringField *)row->GetField(0))->String(); msg.AddBool ("history", false); msg.AddBool ("clear", false); msg.AddString ("input", buffer.String()); fSMsgr->SendMessage (&msg); } } break; case M_CLIENT_QUIT: { fSMsgr->SendMessage(M_LIST_SHUTDOWN); BMessage deathchant (M_OBITUARY); deathchant.AddPointer ("agent", this); deathchant.AddPointer ("item", fAgentWinItem); vision_app->pClientWin()->PostMessage (&deathchant); } break; default: BView::MessageReceived (msg); } }
status_t Converter::CreateNode(BMessage *nodeS,BMessage *connectionS,TiXmlElement *parent,int32 level, int32 thisLine) { TiXmlNode *node; BMessage *pDocNode = new BMessage(P_C_CLASS_TYPE); BMessage *data = new BMessage(); BMessage *pattern = new BMessage(); int32 line = 0; for( node = parent->FirstChild("node"); node;) { CreateConnection(connectionS, parent,node->ToElement()); CreateNode(nodeS,connectionS, node->ToElement(),level+1, line); line++; node = node->NextSibling(); } if (parent->Attribute("TEXT")) data->AddString("Name",parent->Attribute("TEXT")); else data->AddString("Name","Unnamed"); if (parent->Attribute("ID")) { const char *idString = parent->Attribute("ID"); int32 id = GetID(idString); pDocNode->AddPointer("this",(void *)id); } if (parent->Attribute("CREATED")) pDocNode->AddInt32("Node::created",atoi(parent->Attribute("CREATED"))); if (parent->Attribute("MODIFIED")) pDocNode->AddInt32("Node::modified",atoi(parent->Attribute("MODIFIED"))); if (parent->Attribute("BACKGROUND_COLOR")) pattern->AddInt32("FillColor",GetRGB(parent->Attribute("BACKGROUND_COLOR"))); if (parent->Attribute("COLOR")) pattern->AddInt32("BorderColor",GetRGB(parent->Attribute("COLOR"))); //find all Attributes for (node = parent->FirstChild("arrowlink"); node;) { CreateConnection(connectionS,parent,node->ToElement()); node = node->NextSibling(); } pDocNode->AddMessage("Node::Data",data); pDocNode->AddMessage("Node::Pattern",pattern); BRect *nodeRect = new BRect(100,100,200,150); if (pDocNode->FindRect("Node::frame",nodeRect) != B_OK) { int32 left, top, right, bottom; if (level == 0) { left = X_START; top = Y_START; } else { if (parent->Attribute("POSITION")) { if (strcmp(parent->Attribute("POSITION"),"left") != 0) left = (level*(NODE_WIDTH+10))+X_START; else left = X_START-(level*(NODE_WIDTH+10)); } top = (thisLine*(NODE_HEIGHT+10))+ 10; } right = left + NODE_WIDTH; bottom = top + NODE_HEIGHT; nodeRect->Set(left,top, right, bottom); pDocNode->AddRect("Node::frame",*nodeRect); } nodeS->AddMessage("node",pDocNode); }
void TJerFile::GetDiffFile(const char *ASrcDir,const char *ADestDir,BList *Diff) { //----------------------------------------- // We are looking for files not found in Dest... //----------------------------------------- BList ASrcList; BList ADestList; char name1[B_FILE_NAME_LENGTH]; char name2[B_FILE_NAME_LENGTH]; off_t Size1; off_t Size2; int32 CRC1,CRC2; BPath P1; BPath P2; char *RelativePath1; char *RelativePath2; bool EntryFound = false; entry_ref *buf_entry,*buf_entry2,*copy_entry; BMessage *AMessage; BFile *file2; BFile *file1; GetAllFile(ASrcDir,&ASrcList); GetAllFile(ADestDir,&ADestList); AMessage = new BMessage(B_RESET_STATUS_BAR); AMessage->AddFloat("maximum",ASrcList.CountItems()); MyInvoker.Invoke(AMessage); delete AMessage; for (int ind=0;ind < ASrcList.CountItems();ind++ ) { buf_entry = (entry_ref *)(ASrcList.ItemAt(ind)); if (buf_entry!=NULL) { BEntry E1(buf_entry); E1.GetName(name1); E1.GetPath(&P1); GetRelativePath(ASrcDir,P1.Path(),&RelativePath1); file1 = new BFile(buf_entry,B_READ_ONLY); // printf("Checking file ....%s \n",P1.Path()); // The Message is put here to update when the link files are found too. AMessage = new BMessage(B_UPDATE_STATUS_BAR); AMessage->AddFloat("delta",1.0); AMessage->AddString("text","Checking..."); AMessage->AddString("trailingtext",P1.Path()); MyInvoker.Invoke(AMessage); delete AMessage; if (file1->InitCheck()==B_NO_ERROR) //Because of linkfiles.... { try { file1->GetSize(&Size1); if (CalculateCRC==true) { printf("CRC Calculation First File...\n"); CRC1 = CRCFile(file1); } // printf("Checking file ....%s Size: %d CRC: %d \n",P1.Path(),Size1,CRC1); EntryFound = false; } catch(GeneralException &e) { delete file1; printf("Exception in File1..."); throw; } delete file1; for (int ind2=0;ind2 < ADestList.CountItems();ind2++ ) { buf_entry2 = (entry_ref *)(ADestList.ItemAt(ind2)); if (buf_entry2!=NULL) { BEntry E2(buf_entry2); E2.GetName(name2); E2.GetPath(&P2); GetRelativePath(ADestDir,P2.Path(),&RelativePath2); if ((strcmp(name1,name2)==0) && (strcmp(RelativePath1,RelativePath2)==0)) { // printf("name1 : %s, name2 : %s \n",name1,name2); // printf("RP1 : %s, RP2 : %s \n",RelativePath1,RelativePath2); // printf("PAth1 : %s, Path2 : %s \n",P1.Path(),P2.Path()); file2 = new BFile(buf_entry2,B_READ_ONLY); file2->GetSize(&Size2); // printf("Size2 %d\n",Size2); if (Size1==Size2) { //CRC Test try { if (CalculateCRC==true) { printf("CRC Calculation Second File...\n"); CRC2 = CRCFile(file2); if (CRC1==CRC2) { EntryFound = true; delete file2; break; //Data found... } } } catch(GeneralException &e) { printf("Error in GetDiffFile %s\n",P2.Path()); throw; } } delete file2; } } } if (EntryFound==false) { copy_entry = new entry_ref; *copy_entry = *buf_entry; Diff->AddItem(copy_entry); /* BMessage AMessage(GET_FILES); AMessage.AddRef("ref",copy_entry); int result = MyInvoker.Invoke(&AMessage); if (result!= B_OK) { if (result == B_BAD_PORT_ID) { ShowMessage("Bad Port"); } else if (result == B_TIMED_OUT) { ShowMessage("TIMED_OUT"); } else ShowMessage("Other Error"); } */ } } // End of InitCheck } } // Just to let the main loop that we have finished checking... for the moment we only // use it to test if the OutLineList is void.... /* BMessage AMessage2(END_CHECKING); int result2 = MyInvoker.Invoke(&AMessage2); if (result2!= B_OK) { if (result2 == B_BAD_PORT_ID) { ShowMessage("Bad Port"); } else if (result2 == B_TIMED_OUT) { ShowMessage("TIMED_OUT"); } else ShowMessage("Other Error"); } */ }
void TextDocumentTest::_UpdateFontmenus(bool setInitialfont) { BFont font = BFont(); BMenu* stylemenu = NULL; font_family fontFamilyName, currentFamily; font_style fontStyleName, currentStyle; //GetFont(&font); font.GetFamilyAndStyle(¤tFamily, ¤tStyle); const int32 fontfamilies = count_font_families(); fFontFamilyMenu->RemoveItems(0, fFontFamilyMenu->CountItems(), true); for (int32 i = 0; i < fontfamilies; i++) { if (get_font_family(i, &fontFamilyName) == B_OK) { stylemenu = new BPopUpMenu(fontFamilyName); stylemenu->SetLabelFromMarked(false); const int32 styles = count_font_styles(fontFamilyName); //TODO change msg.. to a suitable msg BMessage* familyMsg = new BMessage('todo'); familyMsg->AddString("_family", fontFamilyName); BMenuItem* familyItem = new BMenuItem(stylemenu, familyMsg); fFontFamilyMenu->AddItem(familyItem); for (int32 j = 0; j < styles; j++) { if (get_font_style(fontFamilyName, j, &fontStyleName) == B_OK) { //TODO change msg.. to a suitable msg BMessage* fontMsg = new BMessage('todo'); fontMsg->AddString("_family", fontFamilyName); fontMsg->AddString("_style", fontStyleName); BMenuItem* styleItem = new BMenuItem(fontStyleName, fontMsg); styleItem->SetMarked(false); // setInitialfont is used when we attach the FontField if (!strcmp(fontStyleName, currentStyle) && !strcmp(fontFamilyName, currentFamily) && setInitialfont) { styleItem->SetMarked(true); familyItem->SetMarked(true); BString string; string << currentFamily << " " << currentStyle; if (fFontMenuField) fFontMenuField->MenuItem()->SetLabel(string.String()); } stylemenu->AddItem(styleItem); } } stylemenu->SetRadioMode(true); stylemenu->SetTargetForItems(this); } } fFontFamilyMenu->SetLabelFromMarked(false); fFontFamilyMenu->SetTargetForItems(this); }
BMailFilterAction HaikuMailFormatFilter::HeaderFetched(entry_ref& ref, BFile& file, BMessage& attributes) { file.Seek(0, SEEK_SET); // TODO: attributes.AddInt32(B_MAIL_ATTR_CONTENT, length); attributes.AddInt32(B_MAIL_ATTR_ACCOUNT_ID, fAccountID); attributes.AddString(B_MAIL_ATTR_ACCOUNT, fAccountName); BString header; off_t size; if (file.GetSize(&size) == B_OK) { char* buffer = header.LockBuffer(size); if (buffer == NULL) return B_NO_MEMORY; ssize_t bytesRead = file.Read(buffer, size); if (bytesRead < 0) return bytesRead; if (bytesRead != size) return B_IO_ERROR; header.UnlockBuffer(size); } for (int i = 0; gDefaultFields[i].rfc_name; ++i) { BString target; status_t status = extract_from_header(header, gDefaultFields[i].rfc_name, target); if (status != B_OK) continue; switch (gDefaultFields[i].attr_type){ case B_STRING_TYPE: sanitize_white_space(target); attributes.AddString(gDefaultFields[i].attr_name, target); break; case B_TIME_TYPE: { time_t when; when = ParseDateWithTimeZone(target); if (when == -1) when = time(NULL); // Use current time if it's undecodable. attributes.AddData(B_MAIL_ATTR_WHEN, B_TIME_TYPE, &when, sizeof(when)); break; } } } BString senderName = _ExtractName(attributes.FindString(B_MAIL_ATTR_FROM)); attributes.AddString(B_MAIL_ATTR_NAME, senderName); // Generate a file name for the incoming message. See also // Message::RenderTo which does a similar thing for outgoing messages. BString name = attributes.FindString(B_MAIL_ATTR_SUBJECT); SubjectToThread(name); // Extract the core subject words. if (name.Length() <= 0) name = "No Subject"; attributes.AddString(B_MAIL_ATTR_THREAD, name); // Convert the date into a year-month-day fixed digit width format, so that // sorting by file name will give all the messages with the same subject in // order of date. time_t dateAsTime = 0; const time_t* datePntr; ssize_t dateSize; char numericDateString[40]; struct tm timeFields; if (attributes.FindData(B_MAIL_ATTR_WHEN, B_TIME_TYPE, (const void**)&datePntr, &dateSize) == B_OK) dateAsTime = *datePntr; localtime_r(&dateAsTime, &timeFields); snprintf(numericDateString, sizeof(numericDateString), "%04d%02d%02d%02d%02d%02d", timeFields.tm_year + 1900, timeFields.tm_mon + 1, timeFields.tm_mday, timeFields.tm_hour, timeFields.tm_min, timeFields.tm_sec); name << " " << numericDateString; BString workerName = attributes.FindString(B_MAIL_ATTR_FROM); extract_address_name(workerName); name << " " << workerName; name.Truncate(222); // reserve space for the unique number // Get rid of annoying characters which are hard to use in the shell. name.ReplaceAll('/', '_'); name.ReplaceAll('\'', '_'); name.ReplaceAll('"', '_'); name.ReplaceAll('!', '_'); name.ReplaceAll('<', '_'); name.ReplaceAll('>', '_'); _RemoveExtraWhitespace(name); _RemoveLeadingDots(name); // Avoid files starting with a dot. if (!attributes.HasString(B_MAIL_ATTR_STATUS)) attributes.AddString(B_MAIL_ATTR_STATUS, "New"); _SetType(attributes, B_PARTIAL_MAIL_TYPE); ref.set_name(name.String()); return B_MOVE_MAIL_ACTION; }
bool TTracker::QuitRequested() { // don't allow user quitting if (CurrentMessage() && CurrentMessage()->FindBool("shortcut")) { // but allow quitting to hide fSettingsWindow int32 index = 0; BWindow *window = NULL; while ((window = WindowAt(index++)) != NULL) { if (window == fSettingsWindow) { if (fSettingsWindow->Lock()) { if (!fSettingsWindow->IsHidden() && fSettingsWindow->IsActive()) fSettingsWindow->Hide(); fSettingsWindow->Unlock(); } break; } } return false; } gStatusWindow->AttemptToQuit(); // try quitting the copy/move/empty trash threads BMessage message; AutoLock<WindowList> lock(&fWindowList); // save open windows in a message inside an attribute of the desktop int32 count = fWindowList.CountItems(); for (int32 i = 0; i < count; i++) { BContainerWindow *window = dynamic_cast<BContainerWindow *> (fWindowList.ItemAt(i)); if (window && window->Lock()) { if (window->TargetModel() && !window->PoseView()->IsDesktopWindow()) { if (window->TargetModel()->IsRoot()) message.AddBool("open_disks_window", true); else { BEntry entry; BPath path; const entry_ref *ref = window->TargetModel()->EntryRef(); if (entry.SetTo(ref) == B_OK && entry.GetPath(&path) == B_OK) { int8 flags = window->IsMinimized() ? kOpenWindowMinimized : kOpenWindowNoFlags; uint32 deviceFlags = GetVolumeFlags(window->TargetModel()); // save state for every window which is // a) already open on another workspace // b) on a volume not capable of writing attributes if (window != FindContainerWindow(ref) || (deviceFlags & (B_FS_HAS_ATTR | B_FS_IS_READONLY)) != B_FS_HAS_ATTR) { BMessage stateMessage; window->SaveState(stateMessage); window->SetSaveStateEnabled(false); // This is to prevent its state to be saved to the node when closed. message.AddMessage("window state", &stateMessage); flags |= kOpenWindowHasState; } const char *target; bool pathAlreadyExists = false; for (int32 index = 0;message.FindString("paths", index, &target) == B_OK;index++) { if (!strcmp(target,path.Path())) { pathAlreadyExists = true; break; } } if (!pathAlreadyExists) message.AddString("paths", path.Path()); message.AddInt8(path.Path(), flags); } } } window->Unlock(); } } lock.Unlock(); // write windows to open on disk BDirectory deskDir; if (!BootedInSafeMode() && FSGetDeskDir(&deskDir) == B_OK) { // if message is empty, delete the corresponding attribute if (message.CountNames(B_ANY_TYPE)) { size_t size = (size_t)message.FlattenedSize(); char *buffer = new char[size]; message.Flatten(buffer, (ssize_t)size); deskDir.WriteAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, size); delete [] buffer; } else deskDir.RemoveAttr(kAttrOpenWindows); } for (int32 count = 0; count < 50; count++) { // wait 5 seconds for the copiing/moving to quit if (gStatusWindow->AttemptToQuit()) break; snooze(100000); } return _inherited::QuitRequested(); }
int32 Grepper::_GrepperThread() { BMessage message; char fileName[B_PATH_NAME_LENGTH]; char tempString[B_PATH_NAME_LENGTH]; char command[B_PATH_NAME_LENGTH + 32]; BPath tempFile; sprintf(fileName, "/tmp/SearchText%ld", fThreadId); tempFile.SetTo(fileName); while (!fMustQuit && fIterator->GetNextName(fileName)) { message.MakeEmpty(); message.what = MSG_REPORT_FILE_NAME; message.AddString("filename", fileName); fTarget.SendMessage(&message); message.MakeEmpty(); message.what = MSG_REPORT_RESULT; message.AddString("filename", fileName); BEntry entry(fileName); entry_ref ref; entry.GetRef(&ref); message.AddRef("ref", &ref); if (!entry.Exists()) { if (fIterator->NotifyNegatives()) fTarget.SendMessage(&message); continue; } if (!_EscapeSpecialChars(fileName, B_PATH_NAME_LENGTH)) { sprintf(tempString, B_TRANSLATE("%s: Not enough room to escape " "the filename."), fileName); message.MakeEmpty(); message.what = MSG_REPORT_ERROR; message.AddString("error", tempString); fTarget.SendMessage(&message); continue; } sprintf(command, "grep -hn %s %s \"%s\" > \"%s\"", fCaseSensitive ? "" : "-i", fPattern, fileName, tempFile.Path()); int res = system(command); if (res == 0 || res == 1) { FILE *results = fopen(tempFile.Path(), "r"); if (results != NULL) { while (fgets(tempString, B_PATH_NAME_LENGTH, results) != 0) { if (fEncoding > 0) { char* tempdup = strdup_to_utf8(fEncoding, tempString, strlen(tempString)); message.AddString("text", tempdup); free(tempdup); } else message.AddString("text", tempString); } if (message.HasString("text") || fIterator->NotifyNegatives()) fTarget.SendMessage(&message); fclose(results); continue; } } sprintf(tempString, B_TRANSLATE("%s: There was a problem running grep."), fileName); message.MakeEmpty(); message.what = MSG_REPORT_ERROR; message.AddString("error", tempString); fTarget.SendMessage(&message); } // We wait with removing the temporary file until after the // entire search has finished, to prevent a lot of flickering // if the Tracker window for /tmp/ might be open. remove(tempFile.Path()); message.MakeEmpty(); message.what = MSG_SEARCH_FINISHED; fTarget.SendMessage(&message); return 0; }
/*! \brief Overrides the super class version to handle the MIME specific messages. \param message The message to be handled */ void MIMEManager::MessageReceived(BMessage *message) { BMessage reply; status_t err; switch (message->what) { case B_REG_MIME_SET_PARAM: HandleSetParam(message); break; case B_REG_MIME_DELETE_PARAM: HandleDeleteParam(message); break; case B_REG_MIME_START_WATCHING: case B_REG_MIME_STOP_WATCHING: { BMessenger messenger; err = message->FindMessenger("target", &messenger); if (!err) { err = message->what == B_REG_MIME_START_WATCHING ? fDatabase.StartWatching(messenger) : fDatabase.StopWatching(messenger); } reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_INSTALL: case B_REG_MIME_DELETE: { const char *type; err = message->FindString("type", &type); if (!err) err = message->what == B_REG_MIME_INSTALL ? fDatabase.Install(type) : fDatabase.Delete(type); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_GET_INSTALLED_TYPES: { const char *supertype; err = message->FindString("supertype", &supertype); if (err == B_NAME_NOT_FOUND) err = fDatabase.GetInstalledTypes(&reply); else if (!err) err = fDatabase.GetInstalledTypes(supertype, &reply); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_GET_INSTALLED_SUPERTYPES: { err = fDatabase.GetInstalledSupertypes(&reply); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_GET_SUPPORTING_APPS: { const char *type; err = message->FindString("type", &type); if (!err) err = fDatabase.GetSupportingApps(type, &reply); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_GET_ASSOCIATED_TYPES: { const char *extension; err = message->FindString("extension", &extension); if (!err) err = fDatabase.GetAssociatedTypes(extension, &reply); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_SNIFF: { BString str; entry_ref ref; const char *filename; err = message->FindString("filename", &filename); if (!err) err = fDatabase.GuessMimeType(filename, &str); else if (err == B_NAME_NOT_FOUND) { err = message->FindRef("file ref", &ref); if (!err) err = fDatabase.GuessMimeType(&ref, &str); else if (err == B_NAME_NOT_FOUND) { const void *data; ssize_t dataSize; err = message->FindData("data", B_RAW_TYPE, &data, &dataSize); if (!err) err = fDatabase.GuessMimeType(data, dataSize, &str); } } if (!err) err = reply.AddString("mime type", str); reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); break; } case B_REG_MIME_CREATE_APP_META_MIME: case B_REG_MIME_UPDATE_MIME_INFO: { using BPrivate::Storage::Mime::MimeUpdateThread; using BPrivate::Storage::Mime::CreateAppMetaMimeThread; using BPrivate::Storage::Mime::UpdateMimeInfoThread; entry_ref root; bool recursive; bool synchronous = false; int32 force; MimeUpdateThread *thread = NULL; status_t threadStatus = B_NO_INIT; bool messageIsDetached = false; bool stillOwnsThread = true; // Gather our arguments err = message->FindRef("entry", &root); if (!err) err = message->FindBool("recursive", &recursive); if (!err) err = message->FindBool("synchronous", &synchronous); if (!err) err = message->FindInt32("force", &force); // Detach the message for synchronous calls if (!err && synchronous) { DetachCurrentMessage(); messageIsDetached = true; } // Create the appropriate flavor of mime update thread if (!err) { switch (message->what) { case B_REG_MIME_CREATE_APP_META_MIME: thread = new(nothrow) CreateAppMetaMimeThread( synchronous ? "create_app_meta_mime (s)" : "create_app_meta_mime (a)", B_NORMAL_PRIORITY + 1, &fDatabase, fDatabaseLocker, BMessenger(&fThreadManager), &root, recursive, force, synchronous ? message : NULL); break; case B_REG_MIME_UPDATE_MIME_INFO: thread = new(nothrow) UpdateMimeInfoThread(synchronous ? "update_mime_info (s)" : "update_mime_info (a)", B_NORMAL_PRIORITY + 1, &fDatabase, fDatabaseLocker, BMessenger(&fThreadManager), &root, recursive, force, synchronous ? message : NULL); break; default: err = B_BAD_VALUE; break; } } if (!err) err = thread ? B_OK : B_NO_MEMORY; if (!err) err = threadStatus = thread->InitCheck(); // Launch the thread if (!err) { err = fThreadManager.LaunchThread(thread); if (!err) { stillOwnsThread = false; } } // If something went wrong, we need to notify the sender regardless. However, // if this is a synchronous call, we've already detached the message, and must // be careful that it gets deleted once and only once. Thus, if the MimeUpdateThread // object was created successfully, we don't need to delete the message, as that // object has assumed control of it. Otherwise, we are still responsible. if (err || !synchronous) { // Send the reply reply.what = B_REG_RESULT; reply.AddInt32("result", err); message->SendReply(&reply, this); } // Delete the message if necessary if (messageIsDetached && threadStatus != B_OK) delete message; // Delete the thread if necessary if (stillOwnsThread) delete thread; break; } default: printf("MIMEMan: msg->what == %" B_PRIx32 " (%.4s)\n", message->what, (char*)&(message->what)); BLooper::MessageReceived(message); break; } }
bool ServerAgent::ParseENums (const char *data, const char *sWord) { int num (atoi (sWord)); switch (num) { case ZERO: // 0 { // wasn't a numeric, or the server is playing tricks on us } return false; case ERR_UNKNOWNCOMMAND: // 421 { BString tempString (RestOfString (data, 4)), badCmd (GetWord (data, 4)); if (badCmd == "VISION_LAG_CHECK") { int32 difference (system_time() - fLagCheck); if (difference > 0) { int32 secs (difference / 1000000); int32 milli (difference / 1000 - secs * 1000); char lag[15] = ""; sprintf (lag, "%0" B_PRId32 ".%03" B_PRId32, secs, milli); fMyLag = lag; fLagCount = 0; fCheckingLag = false; fMsgr.SendMessage (M_LAG_CHANGED); } } else { tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); } } return true; case RPL_WELCOME: // 001 case RPL_YOURHOST: // 002 case RPL_CREATED: // 003 case RPL_MYINFO: // 004 { fConnected = true; fIsConnecting = false; fInitialMotd = true; fRetry = 0; if (num == RPL_WELCOME) { BString message = B_TRANSLATE("Established"); message.Prepend("[@] ").Append("\n"); Display(message.String(), C_ERROR, C_BACKGROUND, F_SERVER); } if (fNetworkData.FindBool ("lagCheck")) { fMyLag = "0.000"; fMsgr.SendMessage (M_LAG_CHANGED); } BString theNick (GetWord (data, 3)); fMyNick = theNick; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (STATUS_NICK, theNick.String()); BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Prepend ("* "); theMsg.Append ("\n"); Display (theMsg.String()); if (num == RPL_MYINFO) { // set "real" hostname fServerHostName = (GetWord (data, 1)); fServerHostName.RemoveFirst (":"); BString hostName (fId.String()); hostName += " - ["; hostName += fServerHostName.String(); hostName += "]"; fAgentWinItem->SetName (hostName.String()); // detect IRCd fIrcdtype = IRCD_STANDARD; if (theMsg.FindFirst("hybrid") > 0) fIrcdtype = IRCD_HYBRID; // ultimate and unreal share the same numerics, so treat them with the same // identifier for now else if ((theMsg.FindFirst("UltimateIRCd") > 0) || (theMsg.FindFirst("Unreal") > 0)) fIrcdtype = IRCD_ULTIMATE; else if (theMsg.FindFirst("comstud") > 0) fIrcdtype = IRCD_COMSTUD; else if (theMsg.FindFirst("u2.") > 0) fIrcdtype = IRCD_UNDERNET; else if (theMsg.FindFirst("PTlink") > 0) fIrcdtype = IRCD_PTLINK; else if (theMsg.FindFirst ("CR") > 0) fIrcdtype = IRCD_CONFERENCEROOM; else if (theMsg.FindFirst ("nn-") > 0) fIrcdtype = IRCD_NEWNET; } } return true; case RPL_PROTOCTL: // 005 { // this numeric also serves as RPL_NNMAP on Newnet BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Append ("\n"); switch (fIrcdtype) { case IRCD_NEWNET: { // RPL_NNMAP Display (theMsg.String()); } break; default: { // RPL_PROTOCTL theMsg.Prepend ("* "); Display (theMsg.String()); } } } return true; case RPL_LUSERHIGHESTCONN: // 250 case RPL_LUSERCLIENT: // 251 case RPL_LUSEROP: // 252 case RPL_LUSERUNKNOWN: // 253 case RPL_LUSERCHANNELS: // 254 case RPL_LUSERME: // 255 case RPL_LUSERLOCAL: // 265 case RPL_LUSERGLOBAL: // 266 { BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Prepend ("* "); theMsg.Append ("\n"); Display (theMsg.String()); } return true; /// strip and send to server agent /// case RPL_ULMAP: // 006 case RPL_ULMAPEND: // 007 case RPL_U2MAP: // 015 case RPL_U2MAPEND: // 017 case RPL_TRACELINK: // 200 case RPL_TRACECONNECTING: // 201 case RPL_TRACEHANDSHAKE: // 202 case RPL_TRACEUNKNOWN: // 203 case RPL_TRACEOPERATOR: // 204 case RPL_TRACEUSER: // 205 case RPL_TRACESERVER: // 206 case RPL_TRACENEWTYPE: // 208 case RPL_TRACECLASS: // 209 case RPL_STATSLINKINFO: // 211 case RPL_STATSCOMMANDS: // 212 case RPL_STATSCLINE: // 213 case RPL_STATSNLINE: // 214 case RPL_STATSILINE: // 215 case RPL_STATSKLINE: // 216 case RPL_STATSQLINE: // 217 case RPL_STATSYLINE: // 218 case RPL_ENDOFSTATS: // 219 case RPL_STATSBLINE: // 220 case RPL_DALSTATSE: // 223 case RPL_DALSTATSF: // 224 case RPL_DALSTATSZ: // 225 case RPL_DALSTATSN: // 226 case RPL_DALSTATSG: // 227 case RPL_STATSLLINE: // 241 case RPL_STATSUPTIME: // 242 case RPL_STATSOLINE: // 243 case RPL_STATSHLINE: // 244 case RPL_STATSSLINE: // 245 case RPL_DALSTATSX: // 246 case RPL_STATSXLINE: // 247 case RPL_STATSPLINE: // 249 case RPL_ADMINME: // 256 case RPL_ADMINLOC1: // 257 case RPL_ADMINLOC2: // 258 case RPL_ADMINEMAIL: // 259 case RPL_TRACELOG: // 261 case RPL_ENDOFTRACE: // 262 case RPL_SILELIST: // 271 case RPL_ENDOFSILELIST: // 272 case RPL_ENDOFWHO: // 315 case RPL_CHANSERVURL: // 328 case RPL_COMMANDSYNTAX: // 334 case RPL_VERSION: // 351 case RPL_WHOREPLY: // 352 case RPL_BANLIST: // 367 case RPL_ENDOFBANLIST: // 368 case RPL_INFO: // 371 case RPL_ENDOFINFO: // 374 case RPL_YOUREOPER: // 381 case RPL_REHASHING: // 382 case RPL_TIME: // 391 case ERR_NOORIGIN: // 409 case ERR_NOTEXTTOSEND: // 412 case ERR_TOOMANYAWAY: // 429 case ERR_NICKCHANGETOOFAST: // 438 case ERR_TARGETCHANGETOOFAST: // 439 case ERR_SUMMONDISABLED: // 445 case ERR_USERSDISABLED: // 446 case ERR_NOTREGISTERED: // 451 case ERR_NEEDMOREPARMS: // 461 case ERR_PASSWDMISMATCH: // 464 case ERR_YOUREBANNEDCREEP: // 465 case ERR_NOPRIVILEGES: // 481 case ERR_NOOPERHOST: // 491 case ERR_USERSDONTMATCH: // 502 case ERR_SILELISTFULL: // 511 case ERR_TOOMANYWATCH: // 512 case ERR_TOOMANYDCC: // 514 case ERR_CANTINVITE: // 518 case ERR_LISTSYNTAX: // 521 case ERR_WHOSYNTAX: // 522 case ERR_WHOLIMEXCEED: // 523 case RPL_LOGON: // 600 case RPL_LOGOFF: // 601 case RPL_WATCHOFF: // 602 case RPL_WATCHSTAT: // 603 case RPL_NOWON: // 604 case RPL_NOWOFF: // 605 case RPL_WATCHLIST: // 606 case RPL_ENDOFWATCHLIST: // 607 case RPL_DCCALLOWLIST: // 618 case RPL_DCCALLOWEND: // 619 case RPL_DCCALLOW: // 620 { BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); } return true; case RPL_UMODEIS: // 221 { BString theMode (GetWord (data, 4)); BString tempString = B_TRANSLATE("Your current mode is %1"); tempString.ReplaceFirst("%1", theMode); tempString += '\n'; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS); PostActive (&msg); } return true; /// strip and send to active agent /// case RPL_TRYAGAIN: // 263 case RPL_UNAWAY: // 305 case RPL_NOWAWAY: // 306 case ERR_NOSUCHNICK: // 401 case ERR_NOSUCHSERVER: // 402 case ERR_NOSUCHCHANNEL: // 403 case ERR_CANNOTSENDTOCHAN: // 404 case ERR_TOOMANYCHANNELS: // 405 case ERR_WASNOSUCHNICK: // 406 case ERR_TOOMANYTARGETS: // 407 case ERR_NOCOLORSONCHAN: // 408 case ERR_YOUCANTDOTHAT: // 460 case ERR_CHANOPRIVSNEEDED: // 482 { BString tempString ("[x] "); if (num == ERR_CHANOPRIVSNEEDED) tempString += RestOfString (data, 5); else tempString += RestOfString (data, 4); tempString.RemoveFirst (":"); tempString.Append ("\n"); BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_AWAY: // 301 { BString theNick (GetWord(data, 4)); BString tempString ("[x] "), theReason (RestOfString(data, 5)); theReason.RemoveFirst(":"); tempString += "Away: "; tempString += theReason; tempString += '\n'; if (fRemoteAwayMessages.find(theNick) != fRemoteAwayMessages.end()) { if (fRemoteAwayMessages[theNick] == theReason) { return true; } } fRemoteAwayMessages[theNick] = theReason; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_USERHOST: // 302 { BString theHost (GetWord (data, 4)), theHostname (GetAddress (theHost.String())); theHost.RemoveFirst (":"); BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); if (fGetLocalIP && (tempString.IFindFirst (fMyNick.String()) == 0)) { fGetLocalIP = false; struct addrinfo *info; struct addrinfo hints; memset(&hints, 0, sizeof(addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; int result = getaddrinfo(theHostname.String(), NULL, &hints, &info); if (result == 0) { char addr_buf[INET6_ADDRSTRLEN]; getnameinfo(info->ai_addr, info->ai_addrlen, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); fLocalip = addr_buf; printf("Got address: %s\n", fLocalip.String()); freeaddrinfo(info); return true; } } } return true; case RPL_ISON: // 303 { BString nicks (RestOfString (data, 4)); BString onlined, offlined; nicks.RemoveFirst (":"); int hasChanged (0); BMessage msg (M_NOTIFYLIST_UPDATE); for (int32 i = 0; i < fNotifyNicks.CountItems(); i++) { NotifyListItem *item (((NotifyListItem *)fNotifyNicks.ItemAt(i))); int32 nickidx (nicks.IFindFirst(item->Text())); // make sure that the nick isn't a partial match. if ((nickidx >= 0) && ((nicks[nickidx + strlen(item->Text())] == ' ') || (nicks[nickidx + strlen(item->Text())] == '\0'))) { if (item->GetState() != true) { item->SetState (true); hasChanged = 1; if (onlined.Length()) onlined << ", "; onlined << item->Text(); #ifdef USE_INFOPOPPER if (be_roster->IsRunning(InfoPopperAppSig) == true) { entry_ref ref = vision_app->AppRef(); BMessage infoMsg(InfoPopper::AddMessage); infoMsg.AddString("appTitle", S_INFOPOPPER_TITLE); infoMsg.AddString("title", fId.String()); infoMsg.AddInt8("type", (int8)InfoPopper::Information); infoMsg.AddInt32("iconType", InfoPopper::Attribute); infoMsg.AddRef("iconRef", &ref); BString content; content << item->Text() << " is online"; infoMsg.AddString("content", content); BMessenger(InfoPopperAppSig).SendMessage(&infoMsg); }; #endif } } else { if (item->GetState() == true) { item->SetState (false); hasChanged = 2; if (offlined.Length()) offlined << ", "; offlined << item->Text(); #ifdef USE_INFOPOPPER if (be_roster->IsRunning(InfoPopperAppSig) == true) { entry_ref ref = vision_app->AppRef(); BMessage infoMsg(InfoPopper::AddMessage); infoMsg.AddString("appTitle", S_INFOPOPPER_TITLE); infoMsg.AddString("title", fId.String()); infoMsg.AddInt8("type", (int8)InfoPopper::Information); infoMsg.AddInt32("iconType", InfoPopper::Attribute); infoMsg.AddRef("iconRef", &ref); BString content; content << item->Text() << " is offline"; infoMsg.AddString("content", content); BMessenger(InfoPopperAppSig).SendMessage(&infoMsg); }; #endif } } #ifdef __HAIKU__ if (offlined.Length()) { BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Vision")); entry_ref ref = vision_app->AppRef(); notification.SetOnClickFile(&ref); notification.SetTitle(fServerName.String()); BString content; content << offlined; if (offlined.FindFirst(' ') > -1) content << " are offline"; else content << " is offline"; notification.SetContent(content); notification.Send(); } if (onlined.Length()) { BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Vision")); entry_ref ref = vision_app->AppRef(); notification.SetOnClickFile(&ref); notification.SetTitle(fServerName.String()); BString content; content << onlined; if (onlined.FindFirst(' ') > -1) content << " are online"; else content << " is online"; notification.SetContent(content); notification.Send(); } #endif } fNotifyNicks.SortItems(SortNotifyItems); msg.AddPointer ("list", &fNotifyNicks); msg.AddPointer ("source", this); msg.AddInt32 ("change", hasChanged); Window()->PostMessage (&msg); } return true; case RPL_WHOISIDENTIFIED: // 307 { BString theInfo (RestOfString (data, 5)); theInfo.RemoveFirst (":"); if (theInfo == "-9z99") { // USERIP reply? (RPL_U2USERIP) BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); return true; } BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theInfo; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISADMIN: // 308 case RPL_WHOISSERVICESADMIN: // 309 case RPL_WHOISHELPOP: // 310 case RPL_WHOISOPERATOR: // 313 case RPL_WHOISREGNICK: // 320 case RPL_WHOISACTUALLY: // 338 case RPL_WHOISMASK: // 550 case RPL_WHOWASIP: // 612 case RPL_WHOISUSERMODESALT: // 614 case RPL_WHOISUSERMODES: // 615 case RPL_WHOISREALHOSTNAME: // 616 { BString theInfo (RestOfString (data, 5)); theInfo.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theInfo; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISUSER: // 311 { BString theNick (GetWord (data, 4)), theIdent (GetWord (data, 5)), theAddress (GetWord (data, 6)), theName (RestOfString (data, 8)); theName.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theNick; buffer += " ("; buffer += theIdent; buffer += "@"; buffer += theAddress; buffer += ")\n"; buffer += "[x] "; buffer += theName; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISSERVER: // 312 { BString theNick (GetWord (data, 4)), theServer (GetWord (data, 5)), theInfo (RestOfString (data, 6)); theInfo.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] Server: "; buffer += theServer; buffer += " ("; buffer += theInfo; buffer += ")\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOWASUSER: // 314 { BString theNick (GetWord (data, 4)), theIdent (GetWord (data, 5)), theAddress (GetWord (data, 6)), theName (RestOfString (data, 8)), tempString ("[x] "); theName.RemoveFirst (":"); tempString += B_TRANSLATE("%1 was (%2)"); tempString.ReplaceFirst("%1", theNick); BString nickString = theIdent << "@" << theAddress; tempString.ReplaceFirst("%2", nickString.String()); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_WHOISIDLE: // 317 { BString theNick (GetWord (data, 4)), tempString ("[x] "), tempString2 ("[x] "), theTime (GetWord (data, 5)), signOnTime (GetWord (data, 6)); int64 idleTime (strtoul(theTime.String(), NULL, 0)); tempString += B_TRANSLATE("Idle"); tempString += ": "; tempString += DurationString(idleTime * 1000 * 1000); tempString += "\n"; int32 serverTime = strtoul(signOnTime.String(), NULL, 0); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%A %b %d %Y %I:%M %p %Z", &ptr); BString signOnTimeParsed (str); signOnTimeParsed.RemoveAll ("\n"); tempString2 += B_TRANSLATE("Signon"); tempString2 += ": "; tempString2 += signOnTimeParsed; tempString2 += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); PackDisplay (&msg, tempString2.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_ENDOFWHOIS: // 318 case RPL_ENDOFNAMES: // 366 case RPL_ENDOFWHOWAS: // 369 { // nothing } return true; case RPL_WHOISCHANNELS: // 319 { BString theChannels (RestOfString (data, 5)); theChannels.RemoveFirst(":"); BMessage display (M_DISPLAY); BString buffer = "[x] "; buffer += B_TRANSLATE("Channels"); buffer += ": "; buffer += theChannels; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_LISTSTART: // 321 { BMessage msg (M_LIST_BEGIN); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_LIST: // 322 { BMessage msg (M_LIST_EVENT); BString channel (GetWord (data, 4)), users (GetWord (data, 5)), topic (RestOfString (data, 6)); topic.RemoveFirst (":"); msg.AddString ("channel", channel.String()); msg.AddString ("users", users.String()); msg.AddString ("topic", topic.String()); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_LISTEND: // 323 { BMessage msg (M_LIST_DONE); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_CHANNELMODEIS: // 324 { BString theChan (GetWord (data, 4)), theMode (GetWord (data, 5)), tempStuff (RestOfString (data, 6)); if (tempStuff != "-9z99") { theMode.Append(" "); theMode.Append(tempStuff); // avoid extra space w/o params } ClientAgent *aClient (ActiveClient()), *theClient (Client (theChan.String())); BString tempString("*** "); tempString += B_TRANSLATE("Channel mode for %1: %2"); tempString.ReplaceFirst("%1", theChan.String()); tempString.ReplaceFirst("%2", theMode.String()); tempString += '\n'; BMessage msg (M_CHANNEL_MODES); msg.AddString ("msgz", tempString.String()); msg.AddString ("chan", theChan.String()); msg.AddString ("mode", theMode.String()); if (theClient) theClient->fMsgr.SendMessage (&msg); else if (aClient) aClient->fMsgr.SendMessage (&msg); else Display (tempString.String(), C_OP); } return true; case RPL_CHANNELMLOCK: // 325 { BString theChan (GetWord (data, 4)), mLock (GetWord (data, 8)), lockMessage ("*** "); lockMessage += B_TRANSLATE("Channel mode lock for %1: %2"); lockMessage.ReplaceFirst("%1", theChan); lockMessage.ReplaceFirst("%2", mLock); lockMessage += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, lockMessage.String(), C_OP, C_BACKGROUND, F_TEXT); ClientAgent *theClient (Client (theChan.String())); if (theClient) theClient->fMsgr.SendMessage (&display); else fMsgr.SendMessage (&display); } return true; case RPL_CHANNELCREATED: // 329 { BString theChan (GetWord (data, 4)), theTime (GetWord (data, 5)), tempString; int32 serverTime (strtoul(theTime.String(), NULL, 0)); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%a %b %d %Y %I:%M %p %Z",&ptr); BString theTimeParsed (str); theTimeParsed.RemoveAll ("\n"); tempString = B_TRANSLATE("Channel %1 was created at %2"); tempString.ReplaceFirst("%1", theChan); tempString.ReplaceFirst("%2", theTimeParsed); tempString += '\n'; Display (tempString.String()); } return true; case RPL_NOTOPIC: // 331 { BString theChan (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("No topic set in %1"); tempString.ReplaceFirst("%1", theChan); tempString += '\n'; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case RPL_TOPIC: // 332 { BString theChannel (GetWord (data, 4)), theTopic (RestOfString (data, 5)); ClientAgent *client (Client (theChannel.String())); theTopic.RemoveFirst (":"); if (client) { BMessage display (M_DISPLAY); BString buffer; buffer += "*** "; buffer += B_TRANSLATE("Topic: %1"); buffer.ReplaceFirst("%1", theTopic); buffer += '\n'; PackDisplay (&display, buffer.String(), C_WHOIS); BMessage msg (M_CHANNEL_TOPIC); msg.AddString ("topic", theTopic.String()); msg.AddMessage ("display", &display); if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&msg); } } return true; case RPL_TOPICSET: // 333 { BString channel (GetWord (data, 4)), user (GetWord (data, 5)), theTime (GetWord (data, 6)); int32 serverTime (strtoul(theTime.String(), NULL, 0)); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%A %b %d %Y %I:%M %p %Z",&ptr); BString theTimeParsed (str); theTimeParsed.RemoveAll ("\n"); ClientAgent *client (Client (channel.String())); if (client) { BMessage display (M_DISPLAY); BString buffer = "*** "; buffer += B_TRANSLATE("Topic set by %1 at %2"); buffer.ReplaceFirst("%1", user); buffer.ReplaceFirst("%2", theTimeParsed); buffer += '\n'; PackDisplay (&display, buffer.String(), C_WHOIS); if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&display); } } return true; case RPL_INVITING: // 341 { BString channel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString; tempString += "*** "; tempString += B_TRANSLATE("%1 has been invited to %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", channel); tempString += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, tempString.String(), C_WHOIS); PostActive (&display); } return true; case RPL_NAMEREPLY: // 353 { BString channel (GetWord (data, 5)), names (RestOfString (data, 6)); ClientAgent *client (Client (channel.String())); names.RemoveFirst (":"); BString tempString ("*** "); tempString += B_TRANSLATE("Users in %1: %2"); tempString.ReplaceFirst("%1", channel); tempString.ReplaceFirst("%2", names); tempString += '\n'; Display (tempString.String(), C_TEXT); if (client) // in the channel { BMessage msg (M_CHANNEL_NAMES); BString nick; int32 place (1); while ((nick = GetWord (names.String(), place)) != "-9z99") { const char *sNick (nick.String()); bool founder (false), protect (false), op (false), voice (false), helper (false), ignored; if (nick[0] == '*') { ++sNick; founder = true; } else if (nick[0] == '!') { ++sNick; protect = true; } else if (nick[0] == '@') { ++sNick; op = true; } else if (nick[0] == '+') { ++sNick; voice = true; } else if (nick[0] == '%') { ++sNick; helper = true; } ignored = false; // BMessage aMsg (M_IS_IGNORED), reply; // aMsg.AddString ("server", fServerName.String()); // aMsg.AddString ("nick", sNick); // be_app_messenger.SendMessage (&aMsg, &reply); // reply.FindBool ("ignored", &ignored); msg.AddString ("nick", nick.String()); msg.AddBool ("founder", founder); msg.AddBool ("protect", protect); msg.AddBool ("op", op); msg.AddBool ("voice", voice); msg.AddBool ("helper", helper); msg.AddBool ("ignored", ignored); ++place; } if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&msg); } } return true; case RPL_MOTD: // 372 case RPL_MOTDALT: // 378 case RPL_OPERMOTDSTART: // 609 case RPL_OPERMOTD: // 610 case RPL_OPERENDOFMOTD: // 611 { BString tempString (RestOfString(data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); } return true; case RPL_MOTDSTART: // 375 { BString tempString ("- "); tempString += B_TRANSLATE("Server Message Of the Day"); tempString += ":\n"; Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); } return true; case RPL_ENDOFMOTD: // 376 case ERR_NOMOTD: // 422 { BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); if (fInitialMotd && fCmds.Length()) { BMessage msg (M_SUBMIT_INPUT); const char *place (fCmds.String()), *eol; msg.AddInt32 ("which", PASTE_MULTI_NODELAY); while ((eol = strchr (place, '\n')) != 0) { BString line; line.Append (place, eol - place); msg.AddString ("data", line.String()); ParseAutoexecChans (line); place = eol + 1; } if (*place) { // check in case this was the only line ParseAutoexecChans (BString(place)); msg.AddString ("data", place); } msg.AddInt32 ("which", 3); msg.AddBool ("autoexec", true); fMsgr.SendMessage (&msg); } BString IPCommand ("/userhost "); IPCommand += fMyNick; ParseCmd (IPCommand.String()); if (fReconnecting) { BString reString = "[@] "; reString += B_TRANSLATE("Successful reconnect"); reString += "\n"; Display (reString.String(), C_ERROR); DisplayAll (reString.String(), C_ERROR, C_BACKGROUND, F_SERVER); fMsgr.SendMessage (M_REJOIN_ALL); fReconnecting = false; } fInitialMotd = false; } return true; case RPL_USERSSTART: // 392 { // empty for now } return true; case RPL_USERS: // 393 { // empty for now } return true; case ERR_ERRONEOUSNICKNAME: // 432 case ERR_NICKNAMEINUSE: // 433 case ERR_RESOURCEUNAVAILABLE: // 437 { BString theNick (GetWord (data, 4)); if (fIsConnecting) { BString nextNick (GetNextNick()); if (nextNick != "") { BString tempString = "* "; tempString += B_TRANSLATE("Nickname \"%1\" in use or unavailable, trying \"%2\""); tempString.ReplaceFirst("%1", theNick.String()); tempString.ReplaceFirst("%2", nextNick.String()); tempString += "\n"; Display (tempString.String()); tempString = "NICK "; tempString += nextNick; SendData (tempString.String()); return true; } else { BString tempString = "* "; tempString += B_TRANSLATE("All your pre-selected nicknames are in use."); tempString += "\n"; Display (tempString.String()); tempString = "* "; tempString += B_TRANSLATE("Please type /NICK <NEWNICK> to try another."); tempString += "\n"; Display (tempString.String()); return true; } } BString tempString = "[x] "; tempString += B_TRANSLATE("Nickname/Channel \"%1\" is already in use or unavailable."); tempString.ReplaceFirst("%1", theNick); tempString += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, tempString.String(), C_NICK); PostActive (&display); } return true; case ERR_USERNOTINCHANNEL: // 441 { BString theChannel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("%1 not in %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_NOTONCHANNEL: // 442 { BString theChannel (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("You're not in %1."); tempString.ReplaceFirst("%1", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_USERONCHANNEL: // 443 { BString theChannel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("%1 is already in %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_KEYSET: // 467 { BString theChannel (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("Channel key already set in %1."); tempString.ReplaceFirst("%1", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_UNKNOWNMODE: // 472 { BString theMode (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("Unknown channel mode: '%1'."); tempString.ReplaceFirst("%1", theMode); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT); PostActive (&msg); } return true; case ERR_INVITEONLYCHAN: // 473 { BString theChan (GetWord (data, 4)), tempString ("[x] "), theReason (RestOfString (data, 5)); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason < " "; tempString += B_TRANSLATE("(invite only)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_BANNEDFROMCHAN: // 474 { BString theChan (GetWord (data, 4)), tempString ("[x] "), theReason (RestOfString (data, 5)); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason < " "; tempString += B_TRANSLATE("(you're banned)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_BADCHANNELKEY: // 475 { BString theChan (GetWord(data, 4)), theReason (RestOfString(data, 5)), tempString("[x] "); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason << " "; tempString += B_TRANSLATE("(bad channel key)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_UMODEUNKNOWNFLAG: // 501 { BMessage msg (M_DISPLAY); BString buffer = "[x] "; buffer += B_TRANSLATE("Unknown mode flag."); buffer += "\n"; PackDisplay (&msg, buffer.String(), C_QUIT); PostActive (&msg); } return true; // not sure what these numerics are, // but they are usually on-connect messages case RPL_290: // 290 case RPL_291: // 291 case RPL_292: // 292 { BString tempString (RestOfString(data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); tempString.Prepend ("- "); Display (tempString.String()); } return true; case RPL_WHOISREGISTEREDBOT: // 617 { // conflicts with RPL_DCCALLOWCHANGE BString theNick (GetWord (data, 4)), theMessage (RestOfString (data, 5)), tempString; theNick.RemoveFirst (":"); theMessage.RemoveFirst (":"); theMessage.Append ("\n"); switch (fIrcdtype) { case IRCD_ULTIMATE: { tempString += "[@] "; tempString += theMessage; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } break; default: { tempString += theNick; tempString += " "; tempString += theMessage; Display (tempString.String()); } } } return true; default: break; } return false; }
void CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, off_t size) { // Setup the controls fSizeSlider = new SizeSlider("Slider", B_TRANSLATE("Partition size"), NULL, offset, offset + size); fSizeSlider->SetPosition(1.0); fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER)); fSizeTextControl = new BTextControl("Size Control", "", "", NULL); for(int32 i = 0; i < 256; i++) fSizeTextControl->TextView()->DisallowChar(i); for(int32 i = '0'; i <= '9'; i++) fSizeTextControl->TextView()->AllowChar(i); _UpdateSizeTextControl(); fSizeTextControl->SetModificationMessage( new BMessage(MSG_SIZE_TEXTCONTROL)); fNameTextControl = new BTextControl("Name Control", B_TRANSLATE("Partition name:"), "", NULL); if (!parent->SupportsChildName()) fNameTextControl->SetEnabled(false); fTypePopUpMenu = new BPopUpMenu("Partition Type"); int32 cookie = 0; BString supportedType; while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) { BMessage* message = new BMessage(MSG_PARTITION_TYPE); message->AddString("type", supportedType); BMenuItem* item = new BMenuItem(supportedType, message); fTypePopUpMenu->AddItem(item); if (strcmp(supportedType, kPartitionTypeBFS) == 0) item->SetMarked(true); } fTypeMenuField = new BMenuField(B_TRANSLATE("Partition type:"), fTypePopUpMenu); const float spacing = be_control_look->DefaultItemSpacing(); BGroupLayout* layout = new BGroupLayout(B_VERTICAL, spacing); layout->SetInsets(spacing, spacing, spacing, spacing); SetLayout(layout); AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) .Add(fSizeSlider) .Add(fSizeTextControl) .Add(BGridLayoutBuilder(0.0, 5.0) .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) .Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1) .Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1) ) ); status_t err = parent->GetParameterEditor(B_CREATE_PARAMETER_EDITOR, &fEditor); if (err == B_OK && fEditor != NULL) AddChild(fEditor->View()); else fEditor = NULL; BButton* okButton = new BButton(B_TRANSLATE("Create"), new BMessage(MSG_OK)); AddChild(BGroupLayoutBuilder(B_HORIZONTAL, spacing) .AddGlue() .Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(MSG_CANCEL))) .Add(okButton) ); SetDefaultButton(okButton); AddToSubset(fWindow); layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); }
void configure_interface(int socket, const char* name, char* const* args, int32 argCount) { ifreq request; if (!prepare_request(request, name)) return; uint32 index = 0; if (ioctl(socket, SIOCGIFINDEX, &request, sizeof(request)) >= 0) index = request.ifr_index; bool hasAddress = false, hasMask = false, hasPeer = false; bool hasBroadcast = false, doAutoConfig = false; struct sockaddr address, mask, peer, broadcast; int mtu = -1, metric = -1, media = -1; int addFlags = 0, currentFlags = 0, removeFlags = 0; // try to parse address family int32 familyIndex; int32 i = 0; if (get_address_family(args[i], familyIndex)) i++; if (kFamilies[familyIndex].family != AF_INET) { close(socket); // replace socket with one of the correct address family socket = ::socket(kFamilies[familyIndex].family, SOCK_DGRAM, 0); if (socket < 0) { fprintf(stderr, "%s: Address family \"%s\" is not available.\n", kProgramName, kFamilies[familyIndex].name); exit(1); } } if (index == 0) { // the interface does not exist yet, we have to add it first request.ifr_parameter.base_name[0] = '\0'; request.ifr_parameter.device[0] = '\0'; request.ifr_parameter.sub_type = 0; // the default device is okay for us if (ioctl(socket, SIOCAIFADDR, &request, sizeof(request)) < 0) { fprintf(stderr, "%s: Could not add interface: %s\n", kProgramName, strerror(errno)); exit(1); } } // try to parse address if (parse_address(familyIndex, args[i], address)) { hasAddress = true; i++; if (parse_address(familyIndex, args[i], mask)) { hasMask = true; i++; } } // parse parameters and flags while (i < argCount) { if (!strcmp(args[i], "peer")) { if (!parse_address(familyIndex, args[i + 1], peer)) { fprintf(stderr, "%s: Option 'peer' needs valid address " "parameter\n", kProgramName); exit(1); } hasPeer = true; i++; } else if (!strcmp(args[i], "nm") || !strcmp(args[i], "netmask")) { if (hasMask) { fprintf(stderr, "%s: Netmask is specified twice\n", kProgramName); exit(1); } if (!parse_address(familyIndex, args[i + 1], mask)) { fprintf(stderr, "%s: Option 'netmask' needs valid address " "parameter\n", kProgramName); exit(1); } hasMask = true; i++; } else if (!strcmp(args[i], "bc") || !strcmp(args[i], "broadcast")) { if (hasBroadcast) { fprintf(stderr, "%s: broadcast address is specified twice\n", kProgramName); exit(1); } if (!parse_address(familyIndex, args[i + 1], broadcast)) { fprintf(stderr, "%s: Option 'broadcast' needs valid address " "parameter\n", kProgramName); exit(1); } hasBroadcast = true; addFlags |= IFF_BROADCAST; i++; } else if (!strcmp(args[i], "mtu")) { mtu = args[i + 1] ? strtol(args[i + 1], NULL, 0) : 0; if (mtu <= 500) { fprintf(stderr, "%s: Option 'mtu' expected valid max transfer " "unit size\n", kProgramName); exit(1); } i++; } else if (!strcmp(args[i], "metric")) { if (i + 1 >= argCount) { fprintf(stderr, "%s: Option 'metric' exptected parameter\n", kProgramName); exit(1); } metric = strtol(args[i + 1], NULL, 0); i++; } else if (!strcmp(args[i], "media")) { if (ioctl(socket, SIOCGIFMEDIA, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Unable to detect media type\n", kProgramName); exit(1); } if (i + 1 >= argCount) { fprintf(stderr, "%s: Option 'media' exptected parameter\n", kProgramName); exit(1); } if (!media_parse_subtype(args[i + 1], IFM_TYPE(request.ifr_media), &media)) { fprintf(stderr, "%s: Invalid parameter for option 'media': " "'%s'\n", kProgramName, args[i + 1]); exit(1); } i++; } else if (!strcmp(args[i], "up") || !strcmp(args[i], "-down")) { addFlags |= IFF_UP; } else if (!strcmp(args[i], "down") || !strcmp(args[i], "-up")) { removeFlags |= IFF_UP; } else if (!strcmp(args[i], "bcast")) { addFlags |= IFF_BROADCAST; } else if (!strcmp(args[i], "-bcast")) { removeFlags |= IFF_BROADCAST; } else if (!strcmp(args[i], "promisc")) { addFlags |= IFF_PROMISC; } else if (!strcmp(args[i], "-promisc")) { removeFlags |= IFF_PROMISC; } else if (!strcmp(args[i], "allmulti")) { addFlags |= IFF_ALLMULTI; } else if (!strcmp(args[i], "-allmulti")) { removeFlags |= IFF_ALLMULTI; } else if (!strcmp(args[i], "loopback")) { addFlags |= IFF_LOOPBACK; } else if (!strcmp(args[i], "auto-config")) { doAutoConfig = true; } else usage(1); i++; } if ((addFlags & removeFlags) != 0) { fprintf(stderr, "%s: Contradicting flags specified\n", kProgramName); exit(1); } if (doAutoConfig && (hasAddress || hasMask || hasBroadcast || hasPeer)) { fprintf(stderr, "%s: Contradicting changes specified\n", kProgramName); exit(1); } // set address/mask/broadcast/peer if (hasAddress) { memcpy(&request.ifr_addr, &address, address.sa_len); if (ioctl(socket, SIOCSIFADDR, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting address failed: %s\n", kProgramName, strerror(errno)); exit(1); } } if (ioctl(socket, SIOCGIFFLAGS, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Getting flags failed: %s\n", kProgramName, strerror(errno)); exit(1); } currentFlags = request.ifr_flags; if (hasMask) { memcpy(&request.ifr_mask, &mask, mask.sa_len); if (ioctl(socket, SIOCSIFNETMASK, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting subnet mask failed: %s\n", kProgramName, strerror(errno)); exit(1); } } if (hasBroadcast) { memcpy(&request.ifr_broadaddr, &broadcast, broadcast.sa_len); if (ioctl(socket, SIOCSIFBRDADDR, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting broadcast address failed: %s\n", kProgramName, strerror(errno)); exit(1); } } if (hasPeer) { memcpy(&request.ifr_dstaddr, &peer, peer.sa_len); if (ioctl(socket, SIOCSIFDSTADDR, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting peer address failed: %s\n", kProgramName, strerror(errno)); exit(1); } } // set flags if (hasAddress || hasMask || hasBroadcast || hasPeer) removeFlags = IFF_AUTO_CONFIGURED | IFF_CONFIGURING; if (addFlags || removeFlags) { request.ifr_flags = (currentFlags & ~removeFlags) | addFlags; if (ioctl(socket, SIOCSIFFLAGS, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting flags failed: %s\n", kProgramName, strerror(errno)); } } // set options if (mtu != -1) { request.ifr_mtu = mtu; if (ioctl(socket, SIOCSIFMTU, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting MTU failed: %s\n", kProgramName, strerror(errno)); } } if (metric != -1) { request.ifr_metric = metric; if (ioctl(socket, SIOCSIFMETRIC, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting metric failed: %s\n", kProgramName, strerror(errno)); } } if (media != -1) { request.ifr_media = media; if (ioctl(socket, SIOCSIFMEDIA, &request, sizeof(struct ifreq)) < 0) { fprintf(stderr, "%s: Setting media failed: %s\n", kProgramName, strerror(errno)); } } // start auto configuration, if asked for if (doAutoConfig) { BMessage message(kMsgConfigureInterface); message.AddString("device", name); BMessage address; address.AddString("family", "inet"); address.AddBool("auto_config", true); message.AddMessage("address", &address); BMessenger networkServer(kNetServerSignature); if (networkServer.IsValid()) { BMessage reply; status_t status = networkServer.SendMessage(&message, &reply); if (status != B_OK) { fprintf(stderr, "%s: Sending auto-config message failed: %s\n", kProgramName, strerror(status)); } else if (reply.FindInt32("status", &status) == B_OK && status != B_OK) { fprintf(stderr, "%s: Auto-configuring failed: %s\n", kProgramName, strerror(status)); } } else { fprintf(stderr, "%s: The net_server needs to run for the auto " "configuration!\n", kProgramName); } } }
void PreferenceFont::AttachedToWindow (void) { BView::AttachedToWindow(); SetViewColor (Parent()->ViewColor()); // Moved this here because Gord has 3000 fonts, // and he was complaining that the preferences // window was coming up slow. This will postpone it // until he wants to change the fonts. Can you believe it, // 3000!?!? if (clientFont[0] == 0) { int32 i, family_count (count_font_families()); float label_width (0.0); for (i = 0; ControlLabels[i]; ++i) if (be_plain_font->StringWidth (ControlLabels[i]) > label_width) label_width = be_plain_font->StringWidth (ControlLabels[i]); FontStat *font_stat = new FontStat [family_count]; for (i = 0; i < family_count; ++i) { uint32 flags; *font_stat[i].family = '\0'; font_stat[i].style_count = 0; font_stat[i].styles = 0; if (get_font_family (i, &font_stat[i].family, &flags) == B_OK && (font_stat[i].style_count = count_font_styles (font_stat[i].family)) > 0) { font_stat[i].styles = new font_style [font_stat[i].style_count]; for (int32 j = 0; j < font_stat[i].style_count; ++j) { *font_stat[i].styles[j] = '\0'; get_font_style (font_stat[i].family, j, font_stat[i].styles + j, &flags); } } } BMenu *parentMenu[2][5]; BRect frame (Bounds()); font_height fh; float height; GetFontHeight (&fh); height = fh.ascent + fh.descent + fh.leading + 20; for (i = 0; i < 5; ++i) { font_family cur_family; font_style cur_style; float cur_size; int32 j; bowser_app->GetClientFont (i)->GetFamilyAndStyle ( &cur_family, &cur_style); cur_size = bowser_app->GetClientFont (i)->Size(); parentMenu[0][i] = new BMenu ("Font"); parentMenu[1][i] = new BMenu ("Size"); clientFont[i] = new BMenuField ( BRect (0, i * height, 185, 20 + i * height), "clientFont", ControlLabels[i], parentMenu[0][i]); AddChild (clientFont[i]); fontSize[i] = new BMenuField ( BRect (210, i * height, frame.right, 20 + i * height), "fontSize", "", parentMenu[1][i]); fontSize[i]->Menu()->SetRadioMode (true); fontSize[i]->SetDivider (0.0); AddChild (fontSize[i]); clientFont[i]->SetDivider (label_width + 5.0); for (j = 0; j < family_count; ++j) if (*font_stat[j].family && font_stat[j].style_count) { BMenu *menu (new BMenu (font_stat[j].family)); parentMenu[0][i]->AddItem (menu); for (int32 k = 0; k < font_stat[j].style_count; ++k) { BMessage *msg (new BMessage (M_FONT_CHANGE)); BMenuItem *item; msg->AddString ("family", font_stat[j].family); msg->AddString ("style", font_stat[j].styles[k]); msg->AddInt32 ("which", i); menu->AddItem (item = new BMenuItem (font_stat[j].styles[k], msg)); if (strcmp (font_stat[j].family, cur_family) == 0 && strcmp (font_stat[j].styles[k], cur_style) == 0) { item->SetMarked (true); clientFont[i]->MenuItem()->SetLabel (font_stat[j].family); } } } for (j = 0; FontSizes[j]; ++j) { BMessage *msg (new BMessage (M_FONT_SIZE_CHANGE)); BMenuItem *item; char buffer[32]; sprintf (buffer, "%ld", FontSizes[j]); msg->AddInt32 ("size", FontSizes[j]); msg->AddInt32 ("which", i); parentMenu[1][i]->AddItem (item = new BMenuItem (buffer, msg)); if (FontSizes[j] == cur_size) item->SetMarked (true); } } for (i = 0; i < family_count; ++i) delete [] font_stat[i].styles; delete [] font_stat; } for (int32 i = 0; i < 5; ++i) { fontSize[i]->Menu()->SetLabelFromMarked (true); fontSize[i]->MenuItem()->SetLabel (fontSize[i]->Menu()->FindMarked()->Label()); fontSize[i]->Menu()->SetTargetForItems (this); for (int32 j = 0; j < clientFont[i]->Menu()->CountItems(); ++j) { BMenuItem *item (clientFont[i]->Menu()->ItemAt (j)); item->Submenu()->SetTargetForItems (this); } } ResizeTo (Frame().Width(), clientFont[4]->Frame().bottom); }
void CannaLooper::_ProcessResult(uint32 result) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing result = %d\n", result)); if ((result & GUIDELINE_APPEARED) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "GUIDELINE_APPEARED\n")); if (fCanna->MikakuteiLength() != 0) { // usual guideline i.e. kouho BMessage* msg = new BMessage(B_INPUT_METHOD_EVENT); msg->AddInt32("be:opcode", B_INPUT_METHOD_LOCATION_REQUEST); fOwner->EnqueueMessage(msg); SERIAL_PRINT(("CannaLooper: B_INPUT_METHOD_LOCATION_REQUEST has " "been sent\n")); } else { // guideline exists, but no mikakutei string - means extend mode // and such. SERIAL_PRINT((" GUIDELINE_APPEARED: calling " "GenerateKouho()...\n")); fKouhoWindow->PostMessage(fCanna->GenerateKouhoString()); SERIAL_PRINT((" GUIDELINE_APPEARED: posting KouhoMsg to " "KouhoWindow %x...\n", fKouhoWindow)); fKouhoWindow->PostMessage(KOUHO_WINDOW_SHOW_ALONE); } } if ((result & GUIDELINE_DISAPPEARED) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "GUIDELINE_DISAPPEARED\n")); fKouhoWindow->PostMessage(KOUHO_WINDOW_HIDE); } if ((result & MODE_CHANGED) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "MODE_CHANGED\n")); BMessage message(PALETTE_WINDOW_BUTTON_UPDATE); message.AddInt32("mode", fCanna->GetMode()); fPaletteWindow->PostMessage(&message); SERIAL_PRINT(("CannaLooper: PALETTE_BUTTON_UPDATE has been sent. " "mode = %d\n", fCanna->GetMode())); } if ((result & GUIDELINE_CHANGED) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "GUIDELINE_CHANGED\n")); fKouhoWindow->PostMessage(fCanna->GenerateKouhoString()); } if ((result & THROUGH_INPUT) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "THROUGH_INPUT\n")); EnqueueMessage(DetachCurrentMessage()); } if ((result & NEW_INPUT_STARTED) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "NEW_INPUT_STARTED\n")); SendInputStarted(); } if ((result & KAKUTEI_EXISTS) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "KAKUTEI_EXISTS\n")); BMessage* msg = new BMessage(B_INPUT_METHOD_EVENT); msg->AddInt32("be:opcode", B_INPUT_METHOD_CHANGED); msg->AddString("be:string", fCanna->GetKakuteiStr()); msg->AddInt32("be:clause_start", 0); msg->AddInt32("be:clause_end", fCanna->KakuteiLength()); msg->AddInt32("be:selection", fCanna->KakuteiLength()); msg->AddInt32("be:selection", fCanna->KakuteiLength()); msg->AddBool("be:confirmed", true); fOwner->EnqueueMessage(msg); SERIAL_PRINT(("CannaLooper: B_INPUT_METHOD_CHANGED (confired) has " "been sent\n")); // if both kakutei and mikakutei exist, do not send B_INPUT_STOPPED if (!(result & MIKAKUTEI_EXISTS)) SendInputStopped(); } if ((result & MIKAKUTEI_EXISTS) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "MIKAKUTEI_EXISTS\n" )); int32 start, finish; BMessage* msg = new BMessage(B_INPUT_METHOD_EVENT); msg->AddInt32("be:opcode", B_INPUT_METHOD_CHANGED); msg->AddString("be:string", fCanna->GetMikakuteiStr()); if (fCanna->HasRev()) { fCanna->GetRevPosition( &start, &finish); msg->AddInt32("be:clause_start", 0); msg->AddInt32("be:clause_end", start); msg->AddInt32("be:clause_start", start); msg->AddInt32("be:clause_end", finish); msg->AddInt32("be:clause_start", finish); msg->AddInt32("be:clause_end", fCanna->MikakuteiLength()); } else { start = finish = fCanna->MikakuteiLength(); msg->AddInt32("be:clause_start", 0); msg->AddInt32("be:clause_end", fCanna->MikakuteiLength()); } msg->AddInt32("be:selection", start); msg->AddInt32("be:selection", finish); //msg->AddBool("be:confirmed", false); fOwner->EnqueueMessage(msg); SERIAL_PRINT(("CannaLooper: B_INPUT_METHOD_CHANGED (non-confirmed) " "has been sent\n")); } if ((result & MIKAKUTEI_BECOME_EMPTY) != 0) { SERIAL_PRINT(("CannaLooper: _ProcessResult() processing " "MIKAKUTEI_BECOME_EMPTY\n" )); BMessage* msg = new BMessage(B_INPUT_METHOD_EVENT); msg->AddInt32("be:opcode", B_INPUT_METHOD_CHANGED); msg->AddString("be:string", B_EMPTY_STRING); msg->AddInt32("be:clause_start", 0); msg->AddInt32("be:clause_end", 0); msg->AddInt32("be:selection", 0); msg->AddInt32("be:selection", 0); msg->AddBool( "be:confirmed", true); fOwner->EnqueueMessage(msg); SERIAL_PRINT(( "CannaLooper: B_INPUT_METHOD_CHANGED (NULL, confired) " "has been sent\n")); SendInputStopped(); } }
void LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index) { int16 opcodeExpected; BMessage reply; status_t status; // Handle command complete information request->FindInt16("opcodeExpected", index, &opcodeExpected); if (request->IsSourceWaiting() == false) { TRACE_BT("LocalDeviceImpl: Nobody waiting for the event\n"); } switch ((uint16)opcodeExpected) { case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION): { struct hci_rp_read_loc_version* version = JumpEventHeader<struct hci_rp_read_loc_version, struct hci_ev_cmd_complete>(event); if (version->status == BT_OK) { if (!IsPropertyAvailable("hci_version")) fProperties->AddInt8("hci_version", version->hci_version); if (!IsPropertyAvailable("hci_revision")) { fProperties->AddInt16("hci_revision", version->hci_revision); } if (!IsPropertyAvailable("lmp_version")) fProperties->AddInt8("lmp_version", version->lmp_version); if (!IsPropertyAvailable("lmp_subversion")) { fProperties->AddInt16("lmp_subversion", version->lmp_subversion); } if (!IsPropertyAvailable("manufacturer")) { fProperties->AddInt16("manufacturer", version->manufacturer); } } TRACE_BT("LocalDeviceImpl: Reply for Local Version %x\n", version->status); reply.AddInt8("status", version->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_PG_TIMEOUT): { struct hci_rp_read_page_timeout* pageTimeout = JumpEventHeader<struct hci_rp_read_page_timeout, struct hci_ev_cmd_complete>(event); if (pageTimeout->status == BT_OK) { fProperties->AddInt16("page_timeout", pageTimeout->page_timeout); TRACE_BT("LocalDeviceImpl: Page Timeout=%x\n", pageTimeout->page_timeout); } reply.AddInt8("status", pageTimeout->status); reply.AddInt32("result", pageTimeout->page_timeout); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_FEATURES): { struct hci_rp_read_loc_features* features = JumpEventHeader<struct hci_rp_read_loc_features, struct hci_ev_cmd_complete>(event); if (features->status == BT_OK) { if (!IsPropertyAvailable("features")) { fProperties->AddData("features", B_ANY_TYPE, &features->features, 8); uint16 packetType = HCI_DM1 | HCI_DH1 | HCI_HV1; bool roleSwitch = (features->features[0] & LMP_RSWITCH) != 0; bool encryptCapable = (features->features[0] & LMP_ENCRYPT) != 0; if (features->features[0] & LMP_3SLOT) packetType |= (HCI_DM3 | HCI_DH3); if (features->features[0] & LMP_5SLOT) packetType |= (HCI_DM5 | HCI_DH5); if (features->features[1] & LMP_HV2) packetType |= (HCI_HV2); if (features->features[1] & LMP_HV3) packetType |= (HCI_HV3); fProperties->AddInt16("packet_type", packetType); fProperties->AddBool("role_switch_capable", roleSwitch); fProperties->AddBool("encrypt_capable", encryptCapable); TRACE_BT("LocalDeviceImpl: Packet type %x role switch %d encrypt %d\n", packetType, roleSwitch, encryptCapable); } } TRACE_BT("LocalDeviceImpl: Reply for Local Features %x\n", features->status); reply.AddInt8("status", features->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE): { struct hci_rp_read_buffer_size* buffer = JumpEventHeader<struct hci_rp_read_buffer_size, struct hci_ev_cmd_complete>(event); if (buffer->status == BT_OK) { if (!IsPropertyAvailable("acl_mtu")) fProperties->AddInt16("acl_mtu", buffer->acl_mtu); if (!IsPropertyAvailable("sco_mtu")) fProperties->AddInt8("sco_mtu", buffer->sco_mtu); if (!IsPropertyAvailable("acl_max_pkt")) fProperties->AddInt16("acl_max_pkt", buffer->acl_max_pkt); if (!IsPropertyAvailable("sco_max_pkt")) fProperties->AddInt16("sco_max_pkt", buffer->sco_max_pkt); } TRACE_BT("LocalDeviceImpl: Reply for Read Buffer Size %x\n", buffer->status); reply.AddInt8("status", buffer->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); } break; case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): { struct hci_rp_read_bd_addr* readbdaddr = JumpEventHeader<struct hci_rp_read_bd_addr, struct hci_ev_cmd_complete>(event); if (readbdaddr->status == BT_OK) { reply.AddData("bdaddr", B_ANY_TYPE, &readbdaddr->bdaddr, sizeof(bdaddr_t)); } TRACE_BT("LocalDeviceImpl: Read bdaddr status = %x\n", readbdaddr->status); reply.AddInt8("status", readbdaddr->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); } break; case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV): { struct hci_read_dev_class_reply* classDev = JumpEventHeader<struct hci_read_dev_class_reply, struct hci_ev_cmd_complete>(event); if (classDev->status == BT_OK) { reply.AddData("devclass", B_ANY_TYPE, &classDev->dev_class, sizeof(classDev->dev_class)); } TRACE_BT("LocalDeviceImpl: Read DeviceClass status = %x DeviceClass = [%x][%x][%x]\n", classDev->status, classDev->dev_class[0], classDev->dev_class[1], classDev->dev_class[2]); reply.AddInt8("status", classDev->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME): { struct hci_rp_read_local_name* readLocalName = JumpEventHeader<struct hci_rp_read_local_name, struct hci_ev_cmd_complete>(event); if (readLocalName->status == BT_OK) { reply.AddString("friendlyname", (const char*)readLocalName->local_name); } TRACE_BT("LocalDeviceImpl: Friendly name status %x\n", readLocalName->status); reply.AddInt8("status", readLocalName->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY): { uint8* statusReply = (uint8*)(event + 1); // TODO: This reply has to match the BDADDR of the outgoing message TRACE_BT("LocalDeviceImpl: pincode accept status %x\n", *statusReply); reply.AddInt8("status", *statusReply); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore //ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected); ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY): { uint8* statusReply = (uint8*)(event + 1); // TODO: This reply might match the BDADDR of the outgoing message // => FindPetition should be expanded.... TRACE_BT("LocalDeviceImpl: pincode reject status %x\n", *statusReply); reply.AddInt8("status", *statusReply); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected); break; } case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_STORED_LINK_KEY): { struct hci_read_stored_link_key_reply* linkKeyRetrieval = JumpEventHeader<struct hci_read_stored_link_key_reply, struct hci_ev_cmd_complete>(event); TRACE_BT("LocalDeviceImpl: Status %s MaxKeys=%d, KeysRead=%d\n", BluetoothError(linkKeyRetrieval->status), linkKeyRetrieval->max_num_keys, linkKeyRetrieval->num_keys_read); reply.AddInt8("status", linkKeyRetrieval->status); status = request->SendReply(&reply); //printf("Sending reply... %ld\n", status); // debug reply.PrintToStream(); ClearWantedEvent(request); break; } case PACK_OPCODE(OGF_LINK_CONTROL, OCF_LINK_KEY_NEG_REPLY): case PACK_OPCODE(OGF_LINK_CONTROL, OCF_LINK_KEY_REPLY): { struct hci_cp_link_key_reply_reply* linkKeyReply = JumpEventHeader<struct hci_cp_link_key_reply_reply, struct hci_ev_cmd_complete>(event); TRACE_BT("LocalDeviceImpl: Status %s addresss=%s\n", BluetoothError(linkKeyReply->status), bdaddrUtils::ToString(linkKeyReply->bdaddr).String()); ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected); break; } case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_SCAN_ENABLE): { struct hci_read_scan_enable* scanEnable = JumpEventHeader<struct hci_read_scan_enable, struct hci_ev_cmd_complete>(event); if (scanEnable->status == BT_OK) { fProperties->AddInt8("scan_enable", scanEnable->enable); TRACE_BT("LocalDeviceImpl: enable = %x\n", scanEnable->enable); } reply.AddInt8("status", scanEnable->status); reply.AddInt8("scan_enable", scanEnable->enable); status = request->SendReply(&reply); printf("Sending reply. scan_enable = %d\n", scanEnable->enable); // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); break; } // place here all CC that just replies a uint8 status case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_PG_TIMEOUT): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_CA_TIMEOUT): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_AUTH_ENABLE): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_LOCAL_NAME): case PACK_OPCODE(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR): { reply.AddInt8("status", *(uint8*)(event + 1)); TRACE_BT("LocalDeviceImpl: %s for %s status %x\n", __FUNCTION__, BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event + 1)); status = request->SendReply(&reply); printf("%s: Sending reply write...\n", __func__); if (status < B_OK) printf("%s: Error sending reply write!\n", __func__); ClearWantedEvent(request); break; } default: TRACE_BT("LocalDeviceImpl: Command Complete not handled\n"); break; } }
void EthernetSettingsView::_ShowConfiguration(Settings* settings) { fCurrentSettings = settings; // Clear the inputs. fIPTextControl->SetText(""); fGatewayTextControl->SetText(""); fNetMaskTextControl->SetText(""); fPrimaryDNSTextControl->SetText(""); fSecondaryDNSTextControl->SetText(""); fDomainTextControl->SetText(""); fDeviceMenuField->SetEnabled(settings != NULL); fTypeMenuField->SetEnabled(settings != NULL); bool enableControls = false; BMenuItem* item; if (settings == NULL || settings->IsDisabled()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled")); else if (settings->AutoConfigure()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP")); else { item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static")); enableControls = true; } if (item != NULL) item->SetMarked(true); if (settings == NULL) { if (!fNetworkMenuField->IsHidden(fNetworkMenuField)) fNetworkMenuField->Hide(); _EnableTextControls(false); return; } // Show/hide networks menu BNetworkDevice device(settings->Name()); if (fNetworkMenuField->IsHidden(fNetworkMenuField) && device.IsWireless()) { fNetworkMenuField->Show(); Window()->InvalidateLayout(); } else if (!fNetworkMenuField->IsHidden(fNetworkMenuField) && !device.IsWireless()) { fNetworkMenuField->Hide(); Window()->InvalidateLayout(); } if (device.IsWireless()) { // Rebuild network menu BMenu* menu = fNetworkMenuField->Menu(); menu->RemoveItems(0, menu->CountItems(), true); wireless_network network; int32 count = 0; uint32 cookie = 0; while (device.GetNextNetwork(cookie, network) == B_OK) { BMessage* message = new BMessage(kMsgNetwork); message->AddString("device", device.Name()); message->AddString("name", network.name); BMenuItem* item = new WirelessNetworkMenuItem(network.name, network.signal_strength, (network.flags & B_NETWORK_IS_ENCRYPTED) != 0, message); if (fCurrentSettings->WirelessNetwork() == network.name) item->SetMarked(true); menu->AddItem(item); count++; } if (count == 0) { BMenuItem* item = new BMenuItem( B_TRANSLATE("<no wireless networks found>"), NULL); item->SetEnabled(false); menu->AddItem(item); } else { BMenuItem* item = new BMenuItem( B_TRANSLATE("Choose automatically"), NULL); if (menu->FindMarked() == NULL) item->SetMarked(true); menu->AddItem(item, 0); menu->AddItem(new BSeparatorItem(), 1); } menu->SetTargetForItems(this); } item = fDeviceMenuField->Menu()->FindItem(settings->Name()); if (item != NULL) item->SetMarked(true); fIPTextControl->SetText(settings->IP()); fGatewayTextControl->SetText(settings->Gateway()); fNetMaskTextControl->SetText(settings->Netmask()); if (settings->NameServers().CountItems() >= 2) { fSecondaryDNSTextControl->SetText( settings->NameServers().ItemAt(1)->String()); } if (settings->NameServers().CountItems() >= 1) { fPrimaryDNSTextControl->SetText( settings->NameServers().ItemAt(0)->String()); } fDomainTextControl->SetText(settings->Domain()); _EnableTextControls(enableControls); }
BMessage *DragonView::_MakeDragMessage( void ) { DragonApp *app = dynamic_cast<DragonApp *>( be_app ); BMessage *msg = new BMessage( B_SIMPLE_DATA ); // We can handle any image type that's supported by the currently // installed Translators. // // A "real" application would want to add the Translators in order, // from best to worst using the quality and capability data in the // Translator information structure. It would also want to make sure // that there weren't any duplicate types in the drag message. BTranslatorRoster *translators = BTranslatorRoster::Default(); translator_id *all_translators = NULL; int32 num_translators = 0; status_t retval = translators->GetAllTranslators( &all_translators, &num_translators ); if( retval == B_OK ) { // Only add translators that support appropriate inputs/outputs. for( int32 idx = 0; idx < num_translators; idx++ ) { const translation_format *in_formats = NULL; int32 num_in = 0; // Get the list of input formats for this Translator. retval = translators->GetInputFormats( all_translators[idx], &in_formats, &num_in ); if( retval != B_OK ) continue; // Make sure it supports BBitmap inputs. for( int32 in = 0; in < num_in; in++ ) { if( !strcmp( in_formats[in].MIME, "image/x-be-bitmap" ) ) { // Add this translator's output formats to the message. const translation_format *out_formats = NULL; int32 num_out = 0; retval = translators->GetOutputFormats( all_translators[idx], &out_formats, &num_out ); if( retval != B_OK ) break; for( int32 out = 0; out < num_out; out++ ) { // Add every type except "image/x-be-bitmap", // which won't be of any use to us. if( strcmp( out_formats[out].MIME, "image/x-be-bitmap" ) ) { msg->AddString( "be:types", out_formats[out].MIME ); msg->AddString( "be:filetypes", out_formats[out].MIME ); msg->AddString( "be:type_descriptions", out_formats[out].name ); } } } } } } // We can also handle raw data. msg->AddString( "be:types", B_FILE_MIME_TYPE ); msg->AddString( "be:filetypes", B_FILE_MIME_TYPE ); msg->AddString( "be:type_descriptions", app->rsrc_strings->FindString( RSRC_Raw_Data ) ); // Add the actions that we'll support. B_LINK_TARGET doesn't make much // sense in this context, so we'll leave it out. B_MOVE_TARGET is a // B_COPY_TARGET followed by B_TRASH_TARGET... msg->AddInt32( "be:actions", B_COPY_TARGET ); msg->AddInt32( "be:actions", B_TRASH_TARGET ); msg->AddInt32( "be:actions", B_MOVE_TARGET ); // A file name for dropping onto things (like the Tracker) that create // files. msg->AddString( "be:clip_name", "Dropped Bitmap" ); return msg; }
/*! This function translates the styled text in fromStream and inserts it at the end of the text in intoView, using the BTranslatorRoster *roster to do the translation. The structs that make it possible to work with the translated data are defined in /boot/develop/headers/be/translation/TranslatorFormats.h \param source the stream with the styled text \param intoView the view where the test will be inserted roster, BTranslatorRoster used to do the translation \param the encoding to use, defaults to UTF-8 \return B_BAD_VALUE, if fromStream or intoView is NULL \return B_ERROR, if any other error occurred \return B_OK, if successful */ status_t BTranslationUtils::GetStyledText(BPositionIO* source, BTextView* intoView, const char* encoding, BTranslatorRoster* roster) { if (source == NULL || intoView == NULL) return B_BAD_VALUE; // Use default Translator if none is specified if (roster == NULL) { roster = BTranslatorRoster::Default(); if (roster == NULL) return B_ERROR; } BMessage config; if (encoding != NULL && encoding[0]) config.AddString("be:encoding", encoding); // Translate the file from whatever format it is to B_STYLED_TEXT_FORMAT // we understand BMallocIO mallocIO; if (roster->Translate(source, NULL, &config, &mallocIO, B_STYLED_TEXT_FORMAT) < B_OK) return B_BAD_TYPE; const uint8* buffer = (const uint8*)mallocIO.Buffer(); // make sure there is enough data to fill the stream header const size_t kStreamHeaderSize = sizeof(TranslatorStyledTextStreamHeader); if (mallocIO.BufferLength() < kStreamHeaderSize) return B_BAD_DATA; // copy the stream header from the mallio buffer TranslatorStyledTextStreamHeader header = *(reinterpret_cast<const TranslatorStyledTextStreamHeader *>(buffer)); // convert the stm_header.header struct to the host format const size_t kRecordHeaderSize = sizeof(TranslatorStyledTextRecordHeader); swap_data(B_UINT32_TYPE, &header.header, kRecordHeaderSize, B_SWAP_BENDIAN_TO_HOST); swap_data(B_INT32_TYPE, &header.version, sizeof(int32), B_SWAP_BENDIAN_TO_HOST); if (header.header.magic != 'STXT') return B_BAD_TYPE; // copy the text header from the mallocIO buffer uint32 offset = header.header.header_size + header.header.data_size; const size_t kTextHeaderSize = sizeof(TranslatorStyledTextTextHeader); if (mallocIO.BufferLength() < offset + kTextHeaderSize) return B_BAD_DATA; TranslatorStyledTextTextHeader textHeader = *(const TranslatorStyledTextTextHeader *)(buffer + offset); // convert the stm_header.header struct to the host format swap_data(B_UINT32_TYPE, &textHeader.header, kRecordHeaderSize, B_SWAP_BENDIAN_TO_HOST); swap_data(B_INT32_TYPE, &textHeader.charset, sizeof(int32), B_SWAP_BENDIAN_TO_HOST); if (textHeader.header.magic != 'TEXT' || textHeader.charset != B_UNICODE_UTF8) return B_BAD_TYPE; offset += textHeader.header.header_size; if (mallocIO.BufferLength() < offset + textHeader.header.data_size) { // text buffer misses its end; handle this gracefully textHeader.header.data_size = mallocIO.BufferLength() - offset; } const char* text = (const char*)buffer + offset; // point text pointer at the actual character data bool hasStyles = false; if (mallocIO.BufferLength() > offset + textHeader.header.data_size) { // If the stream contains information beyond the text data // (which means that this data is probably styled text data) offset += textHeader.header.data_size; const size_t kStyleHeaderSize = sizeof(TranslatorStyledTextStyleHeader); if (mallocIO.BufferLength() >= offset + kStyleHeaderSize) { TranslatorStyledTextStyleHeader styleHeader = *(reinterpret_cast<const TranslatorStyledTextStyleHeader *>(buffer + offset)); swap_data(B_UINT32_TYPE, &styleHeader.header, kRecordHeaderSize, B_SWAP_BENDIAN_TO_HOST); swap_data(B_UINT32_TYPE, &styleHeader.apply_offset, sizeof(uint32), B_SWAP_BENDIAN_TO_HOST); swap_data(B_UINT32_TYPE, &styleHeader.apply_length, sizeof(uint32), B_SWAP_BENDIAN_TO_HOST); if (styleHeader.header.magic == 'STYL') { offset += styleHeader.header.header_size; if (mallocIO.BufferLength() >= offset + styleHeader.header.data_size) hasStyles = true; } } } text_run_array *runArray = NULL; if (hasStyles) runArray = BTextView::UnflattenRunArray(buffer + offset); if (runArray != NULL) { intoView->Insert(intoView->TextLength(), text, textHeader.header.data_size, runArray); #ifdef ANTARES_TARGET_PLATFORM_ANTARES BTextView::FreeRunArray(runArray); #else free(runArray); #endif } else { intoView->Insert(intoView->TextLength(), text, textHeader.header.data_size); } return B_OK; }
status_t WinampSkinThemesAddon::AddNames(BMessage &names) { names.AddString(Z_THEME_WINAMP_SKIN_SETTINGS, "CLAmp/SoundPlay Skin Settings"); return B_OK; }
void VisionApp::MessageReceived(BMessage* msg) { switch (msg->what) { case M_ABOUT_CLOSE: { fAboutWin = 0; if (fShuttingDown) PostMessage(B_QUIT_REQUESTED); } break; case M_SETUP_SHOW: { if (fSetupWin) fSetupWin->Activate(); else { fSetupWin = new SetupWindow(); fSetupWin->Show(); } } break; case M_SETUP_CLOSE: { SaveSettings(); fSetupWin = 0; if (fClientWin == NULL) PostMessage(B_QUIT_REQUESTED); } break; case M_PREFS_SHOW: { if (fPrefsWin) fPrefsWin->Activate(); else { fPrefsWin = new PrefsWindow(); fPrefsWin->Show(); } } break; case M_PREFS_CLOSE: { SaveSettings(); fPrefsWin = 0; } break; case M_NETWORK_SHOW: { if (fNetWin) fNetWin->Activate(); else { fNetWin = new NetworkWindow(); fNetWin->Show(); } } break; case M_NETWORK_CLOSE: { SaveSettings(); fNetWin = 0; } break; case M_CONNECT_NETWORK: { BRect clientWinRect(GetRect("clientWinRect")); BMessage netData = GetNetwork(msg->FindString("network")); // sanity check if (netData.IsEmpty()) break; if (netData.FindBool("useDefaults")) { netData.RemoveName("nick"); netData.RemoveName("realname"); netData.RemoveName("ident"); BMessage netDefaults(GetNetwork("defaults")); netData.AddString("realname", netDefaults.FindString("realname")); netData.AddString("ident", netDefaults.FindString("ident")); const char* nick(NULL); for (int32 i = 0; (nick = netDefaults.FindString("nick", i)) != NULL; i++) netData.AddString("nick", nick); } if (fClientWin == NULL) { fClientWin = new ClientWindow(clientWinRect); fWinThread = fClientWin->Thread(); fClientWin->Show(); } BMessage connMsg(M_MAKE_NEW_NETWORK); connMsg.AddMessage("network", &netData); fClientWin->PostMessage(&connMsg); } break; case M_JOIN_CHANNEL: { if (fClientWin == NULL) break; fClientWin->PostMessage(msg); } break; case M_DCC_FILE_WIN: { if (fDccFileWin) { fDccFileWin->PostMessage(msg); } else { DCCConnect* view; msg->FindPointer("view", reinterpret_cast<void**>(&view)); fDccFileWin = new DCCFileWindow(view); fDccFileWin->Show(); } } break; case M_DCC_MESSENGER: if (msg->IsSourceWaiting()) { BMessenger msgr(fDccFileWin); BMessage reply; reply.AddMessenger("msgr", msgr); msg->SendReply(&reply); } break; case M_DCC_FILE_WIN_DONE: { fDccFileWin = 0; } break; case M_DCC_COMPLETE: { Broadcast(msg); } break; case M_LOAD_URL: { BString url(msg->FindString("url")); if (url.Length() > 0) { LoadURL(url.String()); } } break; default: BApplication::MessageReceived(msg); } }
BeAccessibleWindow::BeAccessibleWindow(BRect frame, BList* recentFiles) : BWindow(frame, "BeAccessible", B_TITLED_WINDOW, 0) { //Create MenuBar BRect rect = Bounds(); rect.bottom = MENU_BAR_HEIGHT; fMenuBar = new BMenuBar(rect, "MenuBar"); AddChild(fMenuBar); //Create Menus fFileMenu = new BMenu("File"); fMenuBar->AddItem(fFileMenu); fOpenRecentMenu = new BMenu("Open Recent"); fToolsMenu = new BMenu("Tools"); fMenuBar->AddItem(fToolsMenu); //Create MenuItems fFileMenu->AddItem(new BMenuItem("New", new BMessage(MENU_FILE_NEW_MSG), 'N')); fFileMenu->AddItem(new BMenuItem("Open", new BMessage(MENU_FILE_OPEN_MSG), 'O')); fFileMenu->AddSeparatorItem(); BMenu* externalDataMenu = new BMenu("Get External Data"); fFileMenu->AddItem(externalDataMenu); fImportItem = new BMenuItem("Import Text File", new BMessage(IMPORT_FILE_REQUESTED_MSG)); externalDataMenu->AddItem(fImportItem); fFileMenu->AddSeparatorItem(); fCloseItem = new BMenuItem("Close", new BMessage(MENU_FILE_CLOSE_MSG), 'W'); fFileMenu->AddItem(fCloseItem); fFileMenu->AddSeparatorItem(); BMenuItem* about = new BMenuItem("About BeAccessible", new BMessage(B_ABOUT_REQUESTED)); fFileMenu->AddItem(about); about->SetTarget(be_app); fFileMenu->AddSeparatorItem(); BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); quitItem->SetTarget(be_app); fFileMenu->AddItem(quitItem); fCompactItem = new BMenuItem("Compact", new BMessage(COMPACT_DATABASE_MSG)); fToolsMenu->AddItem(fCompactItem); // Create MenuItems for recent files for(int i = 0; i < recentFiles->CountItems(); i++) { BString* file = (BString*)recentFiles->ItemAt(i); BPath path(file->String()); BMessage* fileMsg = new BMessage(OPEN_DATABASE_MSG); fileMsg->AddString("path", file->String()); fOpenRecentMenu->AddItem(new BMenuItem(path.Leaf(), fileMsg)); } // Add the Open Recent menu between the Open and Close menu items fFileMenu->AddItem(fOpenRecentMenu, 2); fCloseItem->SetEnabled(false); fCompactItem->SetEnabled(false); fImportItem->SetEnabled(false); //Set up View frame.OffsetTo(B_ORIGIN); fMainView = new BView(frame, "BeAccessibleView", B_FOLLOW_ALL, B_WILL_DRAW); fMainView->SetViewColor(216,216,216,0); AddChild(fMainView); Show(); //Set up File->Open and File->Save panels BMessage newMsg(NEW_FILE_REQUESTED), importMsg(IMPORT_FILE_MSG); fOpenFile = new BFilePanel(B_OPEN_PANEL, NULL, NULL, 0, false); fNewFile = new BFilePanel(B_SAVE_PANEL, NULL, NULL, 0, false, &newMsg); fImportFile = new BFilePanel(B_OPEN_PANEL, NULL, NULL, 0, false, &importMsg); //Edit the look of the ImportFile panel fImportFile->Window()->SetTitle("BeAccessible: Import"); fImportFile->SetButtonLabel(B_DEFAULT_BUTTON, "Import"); //Initalize data members fTabView = NULL; fTableTab = NULL; fQueryTab = NULL; fNewGrid = NULL; fPath = new BString; }
void CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, off_t size) { // Setup the controls fSizeSlider = new SizeSlider("Slider", TR("Partition size"), NULL, offset, offset + size); fSizeSlider->SetPosition(1.0); fNameTextControl = new BTextControl("Name Control", TR("Partition name:"), "", NULL); if (!parent->SupportsChildName()) fNameTextControl->SetEnabled(false); fTypePopUpMenu = new BPopUpMenu("Partition Type"); int32 cookie = 0; BString supportedType; while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) { BMessage* message = new BMessage(MSG_PARTITION_TYPE); message->AddString("type", supportedType); BMenuItem* item = new BMenuItem(supportedType, message); fTypePopUpMenu->AddItem(item); if (strcmp(supportedType, kPartitionTypeBFS) == 0) item->SetMarked(true); } fTypeMenuField = new BMenuField(TR("Partition type:"), fTypePopUpMenu, NULL); const float spacing = be_control_look->DefaultItemSpacing(); BGroupLayout* layout = new BGroupLayout(B_VERTICAL, spacing); layout->SetInsets(spacing, spacing, spacing, spacing); SetLayout(layout); AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) .Add(fSizeSlider) .Add(BGridLayoutBuilder(0.0, 5.0) .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) .Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1) .Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1) ) ); parent->GetChildCreationParameterEditor(NULL, &fEditor); if (fEditor) AddChild(fEditor->View()); BButton* okButton = new BButton(TR("Create"), new BMessage(MSG_OK)); AddChild(BGroupLayoutBuilder(B_HORIZONTAL, spacing) .AddGlue() .Add(new BButton(TR("Cancel"), new BMessage(MSG_CANCEL))) .Add(okButton) ); SetDefaultButton(okButton); AddToSubset(fWindow); layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); }
float PBox::BuildGUI(BMessage viewTemplate, BMessage settings, BView *view) { BMessage curr; float yOffset = kEdgeOffset + kControlOffset; float xOffset = 0; const float kControlWidth = view->Bounds().Width() - (kEdgeOffset * 2); BMessage postAdded; for (int i=0; viewTemplate.FindMessage("setting",i,&curr) == B_OK; i++ ) { char temp[512]; // get text etc from template const char * name = curr.FindString("name"); const char * desc = curr.FindString("description"); const char * value = NULL; int32 type = -1; bool secret = false; bool freeText = true; bool multiLine = false; BView *control = NULL; BMenu *menu = NULL; BMessage* enabling = NULL; if ( name != NULL && strcmp(name,"app_sig") == 0 ) { // skip app-sig setting continue; } if (curr.FindInt32("type", &type) != B_OK) { printf("Error getting type for %s, skipping\n", name); continue; }; switch (type) { case B_STRING_TYPE: { if (curr.FindString("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); // menu->SetDivider(be_plain_font->StringWidth(name) + 10); for (int j = 0; curr.FindString("valid_value", j); j++) { menu->AddItem(new BMenuItem(curr.FindString("valid_value", j),NULL)); }; value = NULL; value = curr.FindString("default"); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); value = settings.FindString(name); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); } else { // It's a free-text setting if (curr.FindBool("multi_line", &multiLine) != B_OK) multiLine = false; value = settings.FindString(name); if (!value) value = curr.FindString("default"); if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_INT32_TYPE: { if (curr.FindInt32("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); int32 v = 0; for ( int j = 0; curr.FindInt32("valid_value",j,&v) == B_OK; j++ ) { sprintf(temp,"%ld", v); menu->AddItem(new BMenuItem(temp, NULL)); }; if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } if ( settings.FindInt32(name,&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } } else { // It's a free-text (but number) setting int32 v = 0; if (settings.FindInt32(name,&v) == B_OK) { sprintf(temp,"%ld",v); value = temp; } else if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; } if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_BOOL_TYPE: { bool active; if (settings.FindBool(name, &active) != B_OK) { if (curr.FindBool("default", &active) != B_OK) { active = false; }; }; for (int j = 0; curr.FindString("enable_control", j); j++) { if(!enabling) enabling = new BMessage('enab'); enabling->AddString("enable_control",curr.FindString("enable_control",j) ); if(!active) postAdded.AddString("disable",curr.FindString("enable_control", j)); }; control = new BCheckBox(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), enabling); if (active) ((BCheckBox*)control)->SetValue(B_CONTROL_ON); } break; default: { continue; }; }; if (!value) value = ""; if (!control) { if (freeText) { if (multiLine == false) { control = new BTextControl( BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), value, NULL); if (secret) { ((BTextControl *)control)->TextView()->HideTyping(true); ((BTextControl *)control)->SetText(_T(value)); }; ((BTextControl *)control)->SetDivider(kDividerWidth); } else { BRect rect; BRect textRect; if (desc) //andrea: add description only if available. { BRect labelRect(0, 0, kDividerWidth, fFontHeight); BStringView *label = new BStringView(labelRect, "NA", _T(desc), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); view->AddChild(label); label->MoveTo(kEdgeOffset, yOffset); rect = BRect(0, 0, kControlWidth - kDividerWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kEdgeOffset + kControlOffset; xOffset = kEdgeOffset + kDividerWidth; } else { rect = BRect(0, 0, kControlWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kControlOffset; xOffset = 0; } textRect = rect; textRect.InsetBy(kEdgeOffset, kEdgeOffset); textRect.OffsetTo(1.0, 1.0); BTextView *textView = new BTextView(rect, name, textRect, B_FOLLOW_ALL_SIDES, B_WILL_DRAW); control = new BScrollView("NA", textView, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE, false, true); textView->SetText(_T(value)); }; } else { control = new BMenuField(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), menu); float size=kDividerWidth; if(control->StringWidth(_T(desc)) > kDividerWidth) size=control->StringWidth(_T(desc)) + 20; ((BMenuField *)control)->SetDivider(size); }; }; view->AddChild(control); if(enabling) ((BCheckBox*)control)->SetTarget(this); float h, w = 0; control->GetPreferredSize(&w, &h); if (h < control->Bounds().Height()) h = control->Bounds().Height(); control->MoveTo(kEdgeOffset + xOffset, yOffset); yOffset += kControlOffset + h ; xOffset = 0; }; for (int j = 0; postAdded.FindString("disable", j); j++) { const char* name=postAdded.FindString("disable", j); BView* viewz=view->FindView(name); if(viewz) ((BControl*)viewz)->SetEnabled(false); } //if ( yOffset < view->Bounds().Height() ) // yOffset = view->Bounds().Height(); return yOffset;//view->ResizeTo( view->Bounds().Width(), yOffset }