SweepBox::SweepBox(Vector3D<double> pos, double width, double length, double height, Vector3D<double> velocity) { _SetType(SWEEPBOX); SetSize(width, length, height); _SetPos(pos); _SetVelocity(velocity); }
Box::Box(Vector3D<double> pos, double width, double length, double height) { _SetType(BOX); _SetPos(pos); _SetSize(width, length, height); mSweepBox = SharedPtr<SweepBox>(new SweepBox); }
/*============================================================================= -- Constructors for Box. =============================================================================*/ Box::Box() { mWidth = 32; mLength = 32; mHeight = 32; mSweepBox = SharedPtr<SweepBox>(new SweepBox); _SetType(BOX); }
Box::Box(WeakPtr<SweepBox> sweepBox) { _SetType(BOX); _SetId(sweepBox.lock()->GetId()); _SetPos(sweepBox.lock()->GetPos()); _SetSize(sweepBox.lock()->GetWidth(), sweepBox.lock()->GetLength(), sweepBox.lock()->GetHeight()); _SetVelocity(sweepBox.lock()->GetVelocity());//TODO this is probably unecessary, so optimize out mSweepBox = SharedPtr<SweepBox>(new SweepBox); }
BEGIN_NS_SDK XmlConfigFile::XmlConfigFile( const std::string& strName, const std::string& strFilePath ): ConfigFile(strName, strFilePath) { _SetType(E_XML); int nError = m_xmlDoc.LoadFile(strFilePath.c_str()); if (tinyxml2::XML_SUCCESS != nError) { LOGE<<"Init file is failed, error code:"<<nError; } }
/*============================================================================= -- Constructor for Actor. =============================================================================*/ Actor::Actor() { mInventory = SharedPtr<Inventory>(new Inventory); _SetType(ACTOR); }
void ApplicationTypesWindow::MessageReceived(BMessage* message) { switch (message->what) { case kMsgTypeSelected: { int32 index; if (message->FindInt32("index", &index) == B_OK) { MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index); if (item != NULL) { BMimeType type(item->Type()); _SetType(&type); } else _SetType(NULL); } break; } case kMsgTypeInvoked: { int32 index; if (message->FindInt32("index", &index) == B_OK) { MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index); if (item != NULL) { BMimeType type(item->Type()); entry_ref ref; if (type.GetAppHint(&ref) == B_OK) { BMessage refs(B_REFS_RECEIVED); refs.AddRef("refs", &ref); be_app->PostMessage(&refs); } } } break; } case kMsgEdit: fTypeListView->Invoke(); break; case kMsgRemoveUninstalled: _RemoveUninstalled(); break; case B_META_MIME_CHANGED: { const char* type; int32 which; if (message->FindString("be:type", &type) != B_OK || message->FindInt32("be:which", &which) != B_OK) { break; } if (fCurrentType.Type() == NULL) break; if (!strcasecmp(fCurrentType.Type(), type)) { if (which != B_MIME_TYPE_DELETED) _SetType(&fCurrentType, which); else _SetType(NULL); } break; } default: BWindow::MessageReceived(message); } }
ApplicationTypesWindow::ApplicationTypesWindow(const BMessage& settings) : BWindow(_Frame(settings), B_TRANSLATE("Application types"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { float padding = be_control_look->DefaultItemSpacing(); BAlignment labelAlignment = be_control_look->DefaultLabelAlignment(); BAlignment fullWidthTopAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP); // Application list fTypeListView = new MimeTypeListView("listview", "application", true, true); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetInvocationMessage(new BMessage(kMsgTypeInvoked)); // TODO: this isn't the perfect solution, but otherwise the window contents // will jump chaotically fTypeListView->SetExplicitMinSize(BSize(200, B_SIZE_UNSET)); fTypeListView->SetExplicitMaxSize(BSize(250, B_SIZE_UNSET)); BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); BButton* button = new BButton("remove", B_TRANSLATE("Remove uninstalled"), new BMessage(kMsgRemoveUninstalled)); // "Information" group BBox* infoBox = new BBox((char*)NULL); infoBox->SetLabel(B_TRANSLATE("Information")); infoBox->SetExplicitAlignment(fullWidthTopAlignment); fNameView = new StringView(B_TRANSLATE("Name:"), NULL); fNameView->TextView()->SetExplicitAlignment(labelAlignment); fNameView->LabelView()->SetExplicitAlignment(labelAlignment); fSignatureView = new StringView(B_TRANSLATE("Signature:"), NULL); fSignatureView->TextView()->SetExplicitAlignment(labelAlignment); fSignatureView->LabelView()->SetExplicitAlignment(labelAlignment); fPathView = new StringView(B_TRANSLATE("Path:"), NULL); fPathView->TextView()->SetExplicitAlignment(labelAlignment); fPathView->LabelView()->SetExplicitAlignment(labelAlignment); BLayoutBuilder::Grid<>(infoBox, padding, padding) .SetInsets(padding, padding * 2, padding, padding) .Add(fNameView->LabelView(), 0, 0) .Add(fNameView->TextView(), 1, 0, 2) .Add(fSignatureView->LabelView(), 0, 1) .Add(fSignatureView->TextView(), 1, 1, 2) .Add(fPathView->LabelView(), 0, 2) .Add(fPathView->TextView(), 1, 2, 2); // "Version" group BBox* versionBox = new BBox(""); versionBox->SetLabel(B_TRANSLATE("Version")); versionBox->SetExplicitAlignment(fullWidthTopAlignment); fVersionView = new StringView(B_TRANSLATE("Version:"), NULL); fVersionView->TextView()->SetExplicitAlignment(labelAlignment); fVersionView->LabelView()->SetExplicitAlignment(labelAlignment); fDescriptionLabel = new StringView(B_TRANSLATE("Description:"), NULL); fDescriptionLabel->LabelView()->SetExplicitAlignment(labelAlignment); fDescriptionView = new BTextView("description"); fDescriptionView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fDescriptionView->SetLowColor(fDescriptionView->ViewColor()); fDescriptionView->MakeEditable(false); BLayoutBuilder::Grid<>(versionBox, padding, padding) .SetInsets(padding, padding * 2, padding, padding) .Add(fVersionView->LabelView(), 0, 0) .Add(fVersionView->TextView(), 1, 0) .Add(fDescriptionLabel->LabelView(), 0, 1) .Add(fDescriptionView, 1, 1, 2, 2); // Launch and Tracker buttons fEditButton = new BButton(B_TRANSLATE("Edit" B_UTF8_ELLIPSIS), new BMessage(kMsgEdit)); // launch and tracker buttons get messages in _SetType() fLaunchButton = new BButton(B_TRANSLATE("Launch")); fTrackerButton = new BButton( B_TRANSLATE("Show in Tracker" B_UTF8_ELLIPSIS)); BLayoutBuilder::Group<>(this, B_HORIZONTAL, padding) .AddGroup(B_VERTICAL, padding, 3) .Add(scrollView) .AddGroup(B_HORIZONTAL) .Add(button) .AddGlue() .End() .End() .AddGroup(B_VERTICAL, padding) .Add(infoBox) .Add(versionBox) .AddGroup(B_HORIZONTAL, padding) .Add(fEditButton) .Add(fLaunchButton) .Add(fTrackerButton) .AddGlue() .End() .AddGlue() .End() .SetInsets(padding, padding, padding, padding); BMimeType::StartWatching(this); _SetType(NULL); }
/*============================================================================= -- Constructors for SweepBox. =============================================================================*/ SweepBox::SweepBox() { mWidth = 32; mLength = 1; _SetType(SWEEPBOX); }
void FileTypesWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_SIMPLE_DATA: type_code type; if (message->GetInfo("refs", &type) == B_OK && type == B_REF_TYPE) { be_app->PostMessage(message); } break; case kMsgToggleIcons: { BMenuItem* item; if (message->FindPointer("source", (void **)&item) != B_OK) break; item->SetMarked(!fTypeListView->IsShowingIcons()); fTypeListView->ShowIcons(item->IsMarked()); // update settings BMessage update(kMsgSettingsChanged); update.AddBool("show_icons", item->IsMarked()); be_app_messenger.SendMessage(&update); break; } case kMsgToggleRule: { BMenuItem* item; if (message->FindPointer("source", (void **)&item) != B_OK) break; item->SetMarked(fRuleControl->IsHidden()); _ShowSnifferRule(item->IsMarked()); // update settings BMessage update(kMsgSettingsChanged); update.AddBool("show_rule", item->IsMarked()); be_app_messenger.SendMessage(&update); break; } case kMsgTypeSelected: { int32 index; if (message->FindInt32("index", &index) == B_OK) { MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index); if (item != NULL) { BMimeType type(item->Type()); _SetType(&type); } else _SetType(NULL); } break; } case kMsgAddType: { if (fNewTypeWindow == NULL) { fNewTypeWindow = new NewFileTypeWindow(this, fCurrentType.Type()); fNewTypeWindow->Show(); } else fNewTypeWindow->Activate(); break; } case kMsgNewTypeWindowClosed: fNewTypeWindow = NULL; break; case kMsgRemoveType: { if (fCurrentType.Type() == NULL) break; BAlert* alert; if (fCurrentType.IsSupertypeOnly()) { alert = new BPrivate::OverrideAlert("FileTypes Request", "Removing a super type cannot be reverted.\n" "All file types that belong to this super type " "will be lost!\n\n" "Are you sure you want to do this? To remove the whole " "group, hold down the Shift key and press \"Remove\".", "Remove", B_SHIFT_KEY, "Cancel", 0, NULL, 0, B_WIDTH_AS_USUAL, B_STOP_ALERT); } else { alert = new BAlert("FileTypes Request", "Removing a file type cannot be reverted.\n" "Are you sure you want to remove it?", "Remove", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); } if (alert->Go()) break; status_t status = fCurrentType.Delete(); if (status != B_OK) fprintf(stderr, "Could not remove file type: %s\n", strerror(status)); break; } case kMsgSelectNewType: { const char* type; if (message->FindString("type", &type) == B_OK) fTypeListView->SelectNewType(type); break; } // File Recognition group case kMsgExtensionSelected: { int32 index; if (message->FindInt32("index", &index) == B_OK) { BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); fRemoveExtensionButton->SetEnabled(item != NULL); } break; } case kMsgExtensionInvoked: { if (fCurrentType.Type() == NULL) break; int32 index; if (message->FindInt32("index", &index) == B_OK) { BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); if (item == NULL) break; BWindow* window = new ExtensionWindow(this, fCurrentType, item->Text()); window->Show(); } break; } case kMsgAddExtension: { if (fCurrentType.Type() == NULL) break; BWindow* window = new ExtensionWindow(this, fCurrentType, NULL); window->Show(); break; } case kMsgRemoveExtension: { int32 index = fExtensionListView->CurrentSelection(); if (index < 0 || fCurrentType.Type() == NULL) break; BMessage extensions; if (fCurrentType.GetFileExtensions(&extensions) == B_OK) { extensions.RemoveData("extensions", index); fCurrentType.SetFileExtensions(&extensions); } break; } case kMsgRuleEntered: { // check rule BString parseError; if (BMimeType::CheckSnifferRule(fRuleControl->Text(), &parseError) != B_OK) { parseError.Prepend("Recognition rule is not valid:\n\n"); error_alert(parseError.String()); } else fCurrentType.SetSnifferRule(fRuleControl->Text()); break; } // Description group case kMsgTypeEntered: { fCurrentType.SetShortDescription(fTypeNameControl->Text()); break; } case kMsgDescriptionEntered: { fCurrentType.SetLongDescription(fDescriptionControl->Text()); break; } // Preferred Application group case kMsgPreferredAppChosen: { const char* signature; if (message->FindString("signature", &signature) != B_OK) signature = NULL; fCurrentType.SetPreferredApp(signature); break; } case kMsgSelectPreferredApp: { BMessage panel(kMsgOpenFilePanel); panel.AddString("title", "Select preferred application"); panel.AddInt32("message", kMsgPreferredAppOpened); panel.AddMessenger("target", this); be_app_messenger.SendMessage(&panel); break; } case kMsgPreferredAppOpened: _AdoptPreferredApplication(message, false); break; case kMsgSamePreferredAppAs: { BMessage panel(kMsgOpenFilePanel); panel.AddString("title", "Select same preferred application as"); panel.AddInt32("message", kMsgSamePreferredAppAsOpened); panel.AddMessenger("target", this); be_app_messenger.SendMessage(&panel); break; } case kMsgSamePreferredAppAsOpened: _AdoptPreferredApplication(message, true); break; // Extra Attributes group case kMsgAttributeSelected: { int32 index; if (message->FindInt32("index", &index) == B_OK) { AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); fRemoveAttributeButton->SetEnabled(item != NULL); } break; } case kMsgAttributeInvoked: { if (fCurrentType.Type() == NULL) break; int32 index; if (message->FindInt32("index", &index) == B_OK) { AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); if (item == NULL) break; BWindow* window = new AttributeWindow(this, fCurrentType, item); window->Show(); } break; } case kMsgAddAttribute: { if (fCurrentType.Type() == NULL) break; BWindow* window = new AttributeWindow(this, fCurrentType, NULL); window->Show(); break; } case kMsgRemoveAttribute: { int32 index = fAttributeListView->CurrentSelection(); if (index < 0 || fCurrentType.Type() == NULL) break; BMessage attributes; if (fCurrentType.GetAttrInfo(&attributes) == B_OK) { const char* kAttributeNames[] = { "attr:public_name", "attr:name", "attr:type", "attr:editable", "attr:viewable", "attr:extra", "attr:alignment", "attr:width", "attr:display_as" }; for (uint32 i = 0; i < sizeof(kAttributeNames) / sizeof(kAttributeNames[0]); i++) { attributes.RemoveData(kAttributeNames[i], index); } fCurrentType.SetAttrInfo(&attributes); } break; } case B_META_MIME_CHANGED: { const char* type; int32 which; if (message->FindString("be:type", &type) != B_OK || message->FindInt32("be:which", &which) != B_OK) break; if (fCurrentType.Type() == NULL) break; if (!strcasecmp(fCurrentType.Type(), type)) { if (which != B_MIME_TYPE_DELETED) _SetType(&fCurrentType, which); else _SetType(NULL); } else { // this change could still affect our current type if (which == B_MIME_TYPE_DELETED #ifdef __ANTARES__ || which == B_SUPPORTED_TYPES_CHANGED #endif || which == B_PREFERRED_APP_CHANGED) _UpdatePreferredApps(&fCurrentType); } break; } default: BWindow::MessageReceived(message); } }
FileTypesWindow::FileTypesWindow(const BMessage& settings) : BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), fNewTypeWindow(NULL) { bool showIcons; bool showRule; if (settings.FindBool("show_icons", &showIcons) != B_OK) showIcons = true; if (settings.FindBool("show_rule", &showRule) != B_OK) showRule = false; // add the menu BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); AddChild(menuBar); BMenu* menu = new BMenu("File"); BMenuItem* item; menu->AddItem(item = new BMenuItem("New resource file" B_UTF8_ELLIPSIS, NULL, 'N', B_COMMAND_KEY)); item->SetEnabled(false); BMenu* recentsMenu = BRecentFilesList::NewFileListMenu("Open" B_UTF8_ELLIPSIS, NULL, NULL, be_app, 10, false, NULL, kSignature); item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel)); item->SetShortcut('O', B_COMMAND_KEY); menu->AddItem(item); menu->AddItem(new BMenuItem("Application types" B_UTF8_ELLIPSIS, new BMessage(kMsgOpenApplicationTypesWindow))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("About FileTypes" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); menu->SetTargetForItems(be_app); menuBar->AddItem(menu); menu = new BMenu("Settings"); item = new BMenuItem("Show icons in list", new BMessage(kMsgToggleIcons)); item->SetMarked(showIcons); item->SetTarget(this); menu->AddItem(item); item = new BMenuItem("Show recognition rule", new BMessage(kMsgToggleRule)); item->SetMarked(showRule); item->SetTarget(this); menu->AddItem(item); menuBar->AddItem(menu); // MIME Types list BRect rect = Bounds(); rect.top = menuBar->Bounds().Height() + 1.0f; BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(topView); BButton* button = new BButton(rect, "add", "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddType), B_FOLLOW_BOTTOM); button->ResizeToPreferred(); button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height()); topView->AddChild(button); rect = button->Frame(); rect.OffsetBy(rect.Width() + 8.0f, 0.0f); fRemoveTypeButton = new BButton(rect, "remove", "Remove", new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM); fRemoveTypeButton->ResizeToPreferred(); topView->AddChild(fRemoveTypeButton); rect.bottom = rect.top - 10.0f; rect.top = 10.0f; rect.left = 10.0f; rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f; if (rect.right < 180) rect.right = 180; fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); topView->AddChild(scrollView); // "Icon" group font_height plainHeight; be_plain_font->GetHeight(&plainHeight); float height = ceilf(plainHeight.ascent + plainHeight.descent + plainHeight.leading) + 2.0f; BFont font(be_bold_font); float labelWidth = font.StringWidth("Icon"); font_height boldHeight; font.GetHeight(&boldHeight); BRect innerRect; fIconView = new TypeIconView(innerRect, "icon", B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); fIconView->ResizeToPreferred(); rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f; rect.bottom = rect.top + ceilf(boldHeight.ascent) + max_c(fIconView->Bounds().Height(), button->Bounds().Height() * 2.0f + height + 4.0f) + 12.0f; rect.top -= 2.0f; fIconBox = new BBox(rect); fIconBox->SetLabel("Icon"); topView->AddChild(fIconBox); innerRect.left = 8.0f; innerRect.top = plainHeight.ascent + 3.0f + (rect.Height() - boldHeight.ascent - fIconView->Bounds().Height()) / 2.0f; if (innerRect.top + fIconView->Bounds().Height() > fIconBox->Bounds().Height() - 6.0f) innerRect.top = fIconBox->Bounds().Height() - 6.0f - fIconView->Bounds().Height(); fIconView->MoveTo(innerRect.LeftTop()); fIconBox->AddChild(fIconView); // "File Recognition" group BRect rightRect(rect); rightRect.left = rect.right + 8.0f; rightRect.right = topView->Bounds().Width() - 8.0f; fRecognitionBox = new BBox(rightRect, NULL, B_FOLLOW_LEFT_RIGHT); fRecognitionBox->SetLabel("File recognition"); topView->AddChild(fRecognitionBox); innerRect = fRecognitionBox->Bounds().InsetByCopy(8.0f, 4.0f); innerRect.top += ceilf(boldHeight.ascent); fExtensionLabel = new StringView(innerRect, "extension", "Extensions:", NULL); fExtensionLabel->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); fExtensionLabel->ResizeToPreferred(); fRecognitionBox->AddChild(fExtensionLabel); innerRect.top += fExtensionLabel->Bounds().Height() + 2.0f; innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f; innerRect.bottom = innerRect.top + button->Bounds().Height(); fAddExtensionButton = new BButton(innerRect, "add ext", "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddExtension), B_FOLLOW_RIGHT); fRecognitionBox->AddChild(fAddExtensionButton); innerRect.OffsetBy(0, innerRect.Height() + 4.0f); fRemoveExtensionButton = new BButton(innerRect, "remove ext", "Remove", new BMessage(kMsgRemoveExtension), B_FOLLOW_RIGHT); fRecognitionBox->AddChild(fRemoveExtensionButton); innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; innerRect.left = 10.0f; innerRect.top = fAddExtensionButton->Frame().top + 2.0f; innerRect.bottom = innerRect.bottom - 2.0f; // take scrollview border into account fExtensionListView = new ExtensionListView(innerRect, "listview ext", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT); fExtensionListView->SetSelectionMessage(new BMessage(kMsgExtensionSelected)); fExtensionListView->SetInvocationMessage(new BMessage(kMsgExtensionInvoked)); scrollView = new BScrollView("scrollview ext", fExtensionListView, B_FOLLOW_LEFT_RIGHT, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fRecognitionBox->AddChild(scrollView); innerRect.left = 8.0f; innerRect.top = innerRect.bottom + 10.0f; innerRect.right = fRecognitionBox->Bounds().right - 8.0f; innerRect.bottom = innerRect.top + 20.0f; fRuleControl = new BTextControl(innerRect, "rule", "Rule:", "", new BMessage(kMsgRuleEntered), B_FOLLOW_LEFT_RIGHT); //fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fRuleControl->SetDivider(fRuleControl->StringWidth(fRuleControl->Label()) + 6.0f); fRuleControl->Hide(); fRecognitionBox->AddChild(fRuleControl); // "Description" group rect.top = rect.bottom + 8.0f; rect.bottom = rect.top + ceilf(boldHeight.ascent) + 24.0f; rect.right = rightRect.right; fDescriptionBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); fDescriptionBox->SetLabel("Description"); topView->AddChild(fDescriptionBox); innerRect = fDescriptionBox->Bounds().InsetByCopy(8.0f, 6.0f); innerRect.top += ceilf(boldHeight.ascent); innerRect.bottom = innerRect.top + button->Bounds().Height(); fInternalNameView = new StringView(innerRect, "internal", "Internal name:", "", B_FOLLOW_LEFT_RIGHT); labelWidth = fInternalNameView->StringWidth(fInternalNameView->Label()) + 2.0f; fInternalNameView->SetDivider(labelWidth); fInternalNameView->SetEnabled(false); fInternalNameView->ResizeToPreferred(); fDescriptionBox->AddChild(fInternalNameView); innerRect.OffsetBy(0, fInternalNameView->Bounds().Height() + 5.0f); fTypeNameControl = new BTextControl(innerRect, "type", "Type name:", "", new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT); fTypeNameControl->SetDivider(labelWidth); fTypeNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fDescriptionBox->ResizeBy(0, fInternalNameView->Bounds().Height() + fTypeNameControl->Bounds().Height() * 2.0f); fDescriptionBox->AddChild(fTypeNameControl); innerRect.OffsetBy(0, fTypeNameControl->Bounds().Height() + 5.0f); fDescriptionControl = new BTextControl(innerRect, "description", "Description:", "", new BMessage(kMsgDescriptionEntered), B_FOLLOW_LEFT_RIGHT); fDescriptionControl->SetDivider(labelWidth); fDescriptionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fDescriptionBox->AddChild(fDescriptionControl); // "Preferred Application" group rect = fDescriptionBox->Frame(); rect.top = rect.bottom + 8.0f; rect.bottom = rect.top + ceilf(boldHeight.ascent) + button->Bounds().Height() + 14.0f; fPreferredBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); fPreferredBox->SetLabel("Preferred application"); topView->AddChild(fPreferredBox); innerRect = fPreferredBox->Bounds().InsetByCopy(8.0f, 6.0f); innerRect.top += ceilf(boldHeight.ascent); innerRect.left = innerRect.right - button->StringWidth( "Same as" B_UTF8_ELLIPSIS) - 24.0f; innerRect.bottom = innerRect.top + button->Bounds().Height(); fSameAsButton = new BButton(innerRect, "same as", "Same as" B_UTF8_ELLIPSIS, new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_RIGHT); fPreferredBox->AddChild(fSameAsButton); innerRect.OffsetBy(-innerRect.Width() - 6.0f, 0.0f); fSelectButton = new BButton(innerRect, "select", "Select" B_UTF8_ELLIPSIS, new BMessage(kMsgSelectPreferredApp), B_FOLLOW_RIGHT); fPreferredBox->AddChild(fSelectButton); menu = new BPopUpMenu("preferred"); menu->AddItem(item = new BMenuItem("None", new BMessage(kMsgPreferredAppChosen))); item->SetMarked(true); innerRect.right = innerRect.left - 6.0f; innerRect.left = 8.0f; fPreferredField = new BMenuField(innerRect, "preferred", NULL, menu, true, B_FOLLOW_LEFT_RIGHT); float width; fPreferredField->GetPreferredSize(&width, &height); fPreferredField->ResizeTo(innerRect.Width(), height); fPreferredField->MoveBy(0.0f, (innerRect.Height() - height) / 2.0f); fPreferredBox->AddChild(fPreferredField); // "Extra Attributes" group rect.top = rect.bottom + 8.0f; rect.bottom = topView->Bounds().Height() - 8.0f; fAttributeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM); fAttributeBox->SetLabel("Extra attributes"); topView->AddChild(fAttributeBox); innerRect = fAttributeBox->Bounds().InsetByCopy(8.0f, 6.0f); innerRect.top += ceilf(boldHeight.ascent); innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f; innerRect.bottom = innerRect.top + button->Bounds().Height(); fAddAttributeButton = new BButton(innerRect, "add attr", "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute), B_FOLLOW_RIGHT); fAttributeBox->AddChild(fAddAttributeButton); innerRect.OffsetBy(0, innerRect.Height() + 4.0f); fRemoveAttributeButton = new BButton(innerRect, "remove attr", "Remove", new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); fAttributeBox->AddChild(fRemoveAttributeButton); /* innerRect.OffsetBy(0, innerRect.Height() + 4.0f); button = new BButton(innerRect, "push attr", "Push Up", new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); fAttributeBox->AddChild(button); */ innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; innerRect.left = 10.0f; innerRect.top = 8.0f + ceilf(boldHeight.ascent); innerRect.bottom = fAttributeBox->Bounds().bottom - 10.0f; // take scrollview border into account fAttributeListView = new AttributeListView(innerRect, "listview attr", B_FOLLOW_ALL); fAttributeListView->SetSelectionMessage(new BMessage(kMsgAttributeSelected)); fAttributeListView->SetInvocationMessage(new BMessage(kMsgAttributeInvoked)); scrollView = new BScrollView("scrollview attr", fAttributeListView, B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fAttributeBox->AddChild(scrollView); SetSizeLimits(rightRect.left + 72.0f + font.StringWidth("jpg") + font.StringWidth(fRecognitionBox->Label()), 32767.0f, rect.top + 2.0f * button->Bounds().Height() + boldHeight.ascent + 32.0f + menuBar->Bounds().Height(), 32767.0f); _SetType(NULL); _ShowSnifferRule(showRule); BMimeType::StartWatching(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; }
void HaikuMailFormatFilter::BodyFetched(const entry_ref& ref, BFile& file, BMessage& attributes) { _SetType(attributes, B_MAIL_TYPE); }
FileTypesWindow::FileTypesWindow(const BMessage& settings) : BWindow(_Frame(settings), B_TRANSLATE_SYSTEM_NAME("FileTypes"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fNewTypeWindow(NULL) { bool showIcons; bool showRule; if (settings.FindBool("show_icons", &showIcons) != B_OK) showIcons = true; if (settings.FindBool("show_rule", &showRule) != B_OK) showRule = false; float padding = be_control_look->DefaultItemSpacing(); BAlignment labelAlignment = be_control_look->DefaultLabelAlignment(); BAlignment fullAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); // add the menu BMenuBar* menuBar = new BMenuBar(""); BMenu* menu = new BMenu(B_TRANSLATE("File")); BMenuItem* item = new BMenuItem( B_TRANSLATE("New resource file" B_UTF8_ELLIPSIS), NULL, 'N', B_COMMAND_KEY); item->SetEnabled(false); menu->AddItem(item); BMenu* recentsMenu = BRecentFilesList::NewFileListMenu( B_TRANSLATE("Open" B_UTF8_ELLIPSIS), NULL, NULL, be_app, 10, false, NULL, kSignature); item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel)); item->SetShortcut('O', B_COMMAND_KEY); menu->AddItem(item); menu->AddItem(new BMenuItem( B_TRANSLATE("Application types" B_UTF8_ELLIPSIS), new BMessage(kMsgOpenApplicationTypesWindow))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); menu->SetTargetForItems(be_app); menuBar->AddItem(menu); menu = new BMenu(B_TRANSLATE("Settings")); item = new BMenuItem(B_TRANSLATE("Show icons in list"), new BMessage(kMsgToggleIcons)); item->SetMarked(showIcons); item->SetTarget(this); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Show recognition rule"), new BMessage(kMsgToggleRule)); item->SetMarked(showRule); item->SetTarget(this); menu->AddItem(item); menuBar->AddItem(menu); menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); // MIME Types list BButton* addTypeButton = new BButton("add", B_TRANSLATE("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddType)); fRemoveTypeButton = new BButton("remove", B_TRANSLATE("Remove"), new BMessage(kMsgRemoveType) ); fTypeListView = new MimeTypeListView("typeview", NULL, showIcons, false); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetExplicitMinSize(BSize(200, B_SIZE_UNSET)); BScrollView* typeListScrollView = new BScrollView("scrollview", fTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); // "Icon" group fIconView = new TypeIconView("icon"); fIconBox = new BBox("Icon BBox"); fIconBox->SetLabel(B_TRANSLATE("Icon")); BLayoutBuilder::Group<>(fIconBox, B_VERTICAL, padding) .SetInsets(padding) .AddGlue(1) .Add(fIconView, 3) .AddGlue(1); // "File Recognition" group fRecognitionBox = new BBox("Recognition Box"); fRecognitionBox->SetLabel(B_TRANSLATE("File recognition")); fRecognitionBox->SetExplicitAlignment(fullAlignment); fExtensionLabel = new StringView(B_TRANSLATE("Extensions:"), NULL); fExtensionLabel->LabelView()->SetExplicitAlignment(labelAlignment); fAddExtensionButton = new BButton("add ext", B_TRANSLATE("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddExtension)); fAddExtensionButton->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fRemoveExtensionButton = new BButton("remove ext", B_TRANSLATE("Remove"), new BMessage(kMsgRemoveExtension)); fExtensionListView = new ExtensionListView("listview ext", B_SINGLE_SELECTION_LIST); fExtensionListView->SetSelectionMessage( new BMessage(kMsgExtensionSelected)); fExtensionListView->SetInvocationMessage( new BMessage(kMsgExtensionInvoked)); BScrollView* scrollView = new BScrollView("scrollview ext", fExtensionListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fRuleControl = new BTextControl("rule", B_TRANSLATE("Rule:"), "", new BMessage(kMsgRuleEntered)); fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fRuleControl->Hide(); BLayoutBuilder::Grid<>(fRecognitionBox, padding, padding / 2) .SetInsets(padding, padding * 2, padding, padding) .Add(fExtensionLabel->LabelView(), 0, 0) .Add(scrollView, 0, 1, 2, 2) .Add(fAddExtensionButton, 2, 1) .Add(fRemoveExtensionButton, 2, 2) .Add(fRuleControl, 0, 3, 3, 1); // "Description" group fDescriptionBox = new BBox("description BBox"); fDescriptionBox->SetLabel(B_TRANSLATE("Description")); fDescriptionBox->SetExplicitAlignment(fullAlignment); fInternalNameView = new StringView(B_TRANSLATE("Internal name:"), NULL); fInternalNameView->SetEnabled(false); fTypeNameControl = new BTextControl("type", B_TRANSLATE("Type name:"), "", new BMessage(kMsgTypeEntered)); fDescriptionControl = new BTextControl("description", B_TRANSLATE("Description:"), "", new BMessage(kMsgDescriptionEntered)); BLayoutBuilder::Grid<>(fDescriptionBox, padding / 2, padding / 2) .SetInsets(padding, padding * 2, padding, padding) .Add(fInternalNameView->LabelView(), 0, 0) .Add(fInternalNameView->TextView(), 1, 0) .Add(fTypeNameControl->CreateLabelLayoutItem(), 0, 1) .Add(fTypeNameControl->CreateTextViewLayoutItem(), 1, 1, 2) .Add(fDescriptionControl->CreateLabelLayoutItem(), 0, 2) .Add(fDescriptionControl->CreateTextViewLayoutItem(), 1, 2, 2); // "Preferred Application" group fPreferredBox = new BBox("preferred BBox"); fPreferredBox->SetLabel(B_TRANSLATE("Preferred application")); menu = new BPopUpMenu("preferred"); menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), new BMessage(kMsgPreferredAppChosen))); item->SetMarked(true); fPreferredField = new BMenuField("preferred", (char*)NULL, menu); fSelectButton = new BButton("select", B_TRANSLATE("Select" B_UTF8_ELLIPSIS), new BMessage(kMsgSelectPreferredApp)); fSameAsButton = new BButton("same as", B_TRANSLATE("Same as" B_UTF8_ELLIPSIS), new BMessage(kMsgSamePreferredAppAs)); BLayoutBuilder::Group<>(fPreferredBox, B_HORIZONTAL, padding) .SetInsets(padding, padding * 2, padding, padding) .Add(fPreferredField) .Add(fSelectButton) .Add(fSameAsButton); // "Extra Attributes" group fAttributeBox = new BBox("Attribute Box"); fAttributeBox->SetLabel(B_TRANSLATE("Extra attributes")); fAddAttributeButton = new BButton("add attr", B_TRANSLATE("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddAttribute)); fAddAttributeButton->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fRemoveAttributeButton = new BButton("remove attr", B_TRANSLATE("Remove"), new BMessage(kMsgRemoveAttribute)); fRemoveAttributeButton->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fMoveUpAttributeButton = new BButton("move up attr", B_TRANSLATE("Move up"), new BMessage(kMsgMoveUpAttribute)); fMoveUpAttributeButton->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fMoveDownAttributeButton = new BButton("move down attr", B_TRANSLATE("Move down"), new BMessage(kMsgMoveDownAttribute)); fMoveDownAttributeButton->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fAttributeListView = new AttributeListView("listview attr"); fAttributeListView->SetSelectionMessage( new BMessage(kMsgAttributeSelected)); fAttributeListView->SetInvocationMessage( new BMessage(kMsgAttributeInvoked)); BScrollView* attributesScroller = new BScrollView("scrollview attr", fAttributeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); BLayoutBuilder::Group<>(fAttributeBox, B_HORIZONTAL, padding) .SetInsets(padding, padding * 2, padding, padding) .Add(attributesScroller, 1.0f) .AddGroup(B_VERTICAL, padding / 2, 0.0f) .SetInsets(0) .Add(fAddAttributeButton) .Add(fRemoveAttributeButton) .AddStrut(padding) .Add(fMoveUpAttributeButton) .Add(fMoveDownAttributeButton) .AddGlue(); fMainSplitView = new BSplitView(B_HORIZONTAL, floorf(padding / 2)); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .SetInsets(0) .Add(menuBar) .AddGroup(B_HORIZONTAL, 0) .SetInsets(padding, padding, padding, padding) .AddSplit(fMainSplitView) .AddGroup(B_VERTICAL, padding) .Add(typeListScrollView) .AddGroup(B_HORIZONTAL, padding) .Add(addTypeButton) .Add(fRemoveTypeButton) .AddGlue() .End() .End() // Right side .AddGroup(B_VERTICAL, padding) .AddGroup(B_HORIZONTAL, padding) .Add(fIconBox, 1) .Add(fRecognitionBox, 3) .End() .Add(fDescriptionBox) .Add(fPreferredBox) .Add(fAttributeBox, 5); _SetType(NULL); _ShowSnifferRule(showRule); float leftWeight; float rightWeight; if (settings.FindFloat("left_split_weight", &leftWeight) != B_OK || settings.FindFloat("right_split_weight", &rightWeight) != B_OK) { leftWeight = 0.2; rightWeight = 1.0 - leftWeight; } fMainSplitView->SetItemWeight(0, leftWeight, false); fMainSplitView->SetItemWeight(1, rightWeight, true); BMimeType::StartWatching(this); }