void ArrayGraph::pushBackEdge(__uint32 a, __uint32 b, float desiredEdgeLength) { // get the index of a free element __uint32 e_index = m_numEdges++; // get the pair entry EdgeAdjInfo& e = edgeInfo(e_index); // (a,b) is the pair we are adding e.a = a; e.b = b; m_desiredEdgeLength[e_index] = desiredEdgeLength; m_desiredAvgEdgeLength += (double)desiredEdgeLength; // get the node info NodeAdjInfo& aInfo = nodeInfo(a); NodeAdjInfo& bInfo = nodeInfo(b); // if a is part of at least one edge if (aInfo.degree) { // adjust the links EdgeAdjInfo& a_e = edgeInfo(aInfo.lastEntry); // check which one is a if (a==a_e.a) a_e.a_next = e_index; else a_e.b_next = e_index; } else { // this edge is the first for a => set the firstEntry link aInfo.firstEntry = e_index; }; // same for b: if b is part of at least one edge if (bInfo.degree) { // adjust the links EdgeAdjInfo& b_e = edgeInfo(bInfo.lastEntry); // check which one is b if (b==b_e.a) b_e.a_next = e_index; else b_e.b_next = e_index; } else { // this edge is the first for b => set the firstEntry link bInfo.firstEntry = e_index; }; // and the lastEntry link aInfo.lastEntry = e_index; bInfo.lastEntry = e_index; // one more edge for each node aInfo.degree++; bInfo.degree++; };
/*! \brief Returns meta information for all dot properties, including properties inherited from base types. */ QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const { if (!isValid()) { qWarning() << "NodeMetaInfo is invalid"; return QHash<QString,PropertyMetaInfo>(); } QHash<QString,PropertyMetaInfo> propertiesInfo; foreach (const QString &propertyName, properties().keys()) { if (property(propertyName).hasDotSubProperties()) { QString propertyType = property(propertyName).type(); if (propertyType.right(1) == "*") propertyType = propertyType.left(propertyType.size() - 1).trimmed(); NodeMetaInfo nodeInfo(m_data->metaInfo.nodeMetaInfo(m_data->metaInfo.fromQtTypes(propertyType), majorVersion(), minorVersion())); if (nodeInfo.isValid()) { QHashIterator<QString,PropertyMetaInfo> iter(nodeInfo.properties()); while (iter.hasNext()) { iter.next(); if (!propertiesInfo.contains(iter.key()) && iter.key() != "objectName") propertiesInfo.insert(propertyName + '.' + iter.key(), iter.value()); } } } } return propertiesInfo; }
void MidiSettingsView::_RetrieveSoftSynthList() { BStringList paths; status_t status = BPathFinder::FindPaths(B_FIND_PATH_DATA_DIRECTORY, "synth", paths); if (status != B_OK) return; fListView->MakeEmpty(); for (int32 i = 0; i < paths.CountStrings(); i++) { BDirectory directory(paths.StringAt(i).String()); BEntry entry; if (directory.InitCheck() != B_OK) continue; while (directory.GetNextEntry(&entry) == B_OK) { BNode node(&entry); BNodeInfo nodeInfo(&node); char mimeType[B_MIME_TYPE_LENGTH]; // TODO: For some reason this doesn't work if (nodeInfo.GetType(mimeType) == B_OK /*&& !strcmp(mimeType, "audio/x-soundfont")*/) { BPath fullPath = paths.StringAt(i).String(); fullPath.Append(entry.Name()); fListView->AddItem(new BStringItem(fullPath.Path())); } } } }
void TSorterListItem::Init() { // Set DataType based on entry_ref BFile theFile; if ( theFile.SetTo(&m_EntryRef, B_READ_WRITE) == B_OK ) { // Create node BNodeInfo nodeInfo(&theFile); if (nodeInfo.InitCheck() == B_NO_ERROR) { if (IsAudio(nodeInfo)) m_DataType = kAudioType; else if (IsImage(nodeInfo)) m_DataType = kPictureType; else if (IsText(nodeInfo)) m_DataType = kTextType; else if (IsVideo(nodeInfo)) m_DataType = kVideoType; } else { m_DataType = kUnknownType; } theFile.Unset(); } }
void FileTypeWindow::_AdoptType(BMessage* message) { entry_ref ref; if (message == NULL || message->FindRef("refs", &ref) != B_OK) return; BNode node(&ref); status_t status = node.InitCheck(); char type[B_MIME_TYPE_LENGTH]; if (status == B_OK) { // get type from file BNodeInfo nodeInfo(&node); status = nodeInfo.InitCheck(); if (status == B_OK) { if (nodeInfo.GetType(type) != B_OK) type[0] = '\0'; } } if (status != B_OK) { error_alert(B_TRANSLATE("Could not open file"), status); return; } fCommonType = type; fTypeControl->SetText(type); _AdoptType(); }
//------------------------------ bool SceneGraphWriter::write( ) { createUniqueIdNodeMap(); NodeInfo nodeInfo( COLLADABU::Math::Matrix4::IDENTITY ); mNodeInfoStack.push( nodeInfo ); writeNodes( mVisualScene.getRootNodes()); return true; }
bool GwfObjectInfoReader::parseNode(const QDomElement &element) { std::auto_ptr<SCgNodeInfo> nodeInfo(new SCgNodeInfo()); if(!parseObject(element,nodeInfo.get())) return false; qreal& x = nodeInfo->posRef().rx(); qreal& y = nodeInfo->posRef().ry(); if (!getAttributeDouble(element, "x", x) || !getAttributeDouble(element, "y", y)) return false; // get content element QDomElement contEl = element.firstChildElement("content"); if (contEl.isNull()) { errorHaventContent(element.tagName()); return false; } // get content type int& cType = nodeInfo->contentTypeRef(); if (!getAttributeInt(contEl, "type", cType)) return false; // get mime type if (!getAttributeString(contEl, "mime_type", nodeInfo->contentMimeTypeRef())) return false; // set content to nodeInfo if (cType > 0 && cType < 5) { if (cType == 1 || cType == 2 || cType == 3) nodeInfo->contentDataRef() = QVariant(contEl.firstChild().nodeValue()); else if (cType == 4) { // get file name getAttributeString(contEl, "file_name", nodeInfo->contentFilenameRef()); QString cData = contEl.firstChild().nodeValue(); QByteArray arr = QByteArray::fromBase64(cData.toLocal8Bit()); nodeInfo->contentDataRef() = QVariant(arr); } else { mLastError = QObject::tr("Content type '%1' doesn't supported for now").arg(cType); return false; } } else if (cType != 0) { mLastError = QObject::tr("Unknown content type '%1'").arg(cType); return false; } mObjectsInfo[SCgNode::Type].append(nodeInfo.release()); return true; }
void ArrayGraph::allocate(__uint32 numNodes, __uint32 numEdges) { m_nodeXPos = (float*)MALLOC_16(numNodes*sizeof(float)); m_nodeYPos = (float*)MALLOC_16(numNodes*sizeof(float)); m_nodeSize = (float*)MALLOC_16(numNodes*sizeof(float)); m_nodeMoveRadius = (float*)MALLOC_16(numNodes*sizeof(float)); m_nodeAdj = (NodeAdjInfo*)MALLOC_16(numNodes*sizeof(NodeAdjInfo)); m_desiredEdgeLength = (float*)MALLOC_16(numEdges*sizeof(float)); m_edgeAdj = (EdgeAdjInfo*)MALLOC_16(numEdges*sizeof(EdgeAdjInfo)); for (__uint32 i=0; i < numNodes; i++) nodeInfo(i).degree = 0; };
bool is_resource(BFile& file) { BResources resources(&file); if (resources.InitCheck() != B_OK) return false; BNodeInfo nodeInfo(&file); char type[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(type) != B_OK || strcasecmp(type, B_RESOURCE_MIME_TYPE)) return false; return true; }
/*! Save the screenshot to the file with the specified filename and type. Note that any existing file with the same filename will be overwritten without warning. */ status_t Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType) const { BString fileNameString(fileName); // Generate a default filename when none is given if (fileNameString.Compare("") == 0) { BPath homePath; if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK) return B_ERROR; BEntry entry; int32 index = 1; BString extension = GetFileNameExtension(imageType); do { fileNameString.SetTo(homePath.Path()); fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++ << extension; entry.SetTo(fileNameString.String()); } while (entry.Exists()); } // Create the file BFile file(fileNameString, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); if (file.InitCheck() != B_OK) return B_ERROR; // Write the screenshot bitmap to the file BBitmapStream stream(*screenshot); BTranslatorRoster* roster = BTranslatorRoster::Default(); roster->Translate(&stream, NULL, NULL, &file, imageType, B_TRANSLATOR_BITMAP); *screenshot = NULL; // Set the file MIME attribute BNodeInfo nodeInfo(&file); if (nodeInfo.InitCheck() != B_OK) return B_ERROR; nodeInfo.SetType(_GetMimeString(imageType)); return B_OK; }
//------------------------------ bool SceneGraphWriter::writeNode(const COLLADAFW::Node* nodeToWriter ) { const NodeInfo& parentNodeInfo = mNodeInfoStack.top(); const COLLADABU::Math::Matrix4& parentWorldMatrix = parentNodeInfo.worldTransformation; COLLADABU::Math::Matrix4 worldMatrix = parentWorldMatrix * nodeToWriter->getTransformationMatrix(); NodeInfo nodeInfo( worldMatrix ); mNodeInfoStack.push(nodeInfo); writeNodes(nodeToWriter->getChildNodes()); storeInstanceGeometries( nodeToWriter->getInstanceGeometries(), worldMatrix); writeInstanceNodes( nodeToWriter->getInstanceNodes() ); mNodeInfoStack.pop(); return true; }
status_t TElementsSorter::HandleFile(entry_ref &theRef, struct stat &st) { { BFile theFile; if ( theFile.SetTo(&theRef, B_READ_WRITE) == B_OK ) { BNodeInfo nodeInfo(&theFile); if (nodeInfo.InitCheck() == B_NO_ERROR) { if ( IsSupportedType(nodeInfo) ) { // Pass the node info to all of our sorters. They will // know what to do with it. BMessage* refMessage = new BMessage(SORTER_REFS_MSG); refMessage->AddRef("FileRef", &theRef); for (int32 index = 0; index < fSorterList->CountItems(); index++) { TSorterContainer* sorter = static_cast<TSorterContainer*>(fSorterList->ItemAt(index)); if (sorter) sorter->MessageReceived(refMessage); } delete refMessage; // Get active list, sort and sync for (int32 sortIndex = 0; sortIndex < fSorterList->CountItems(); sortIndex++) { TSorterContainer* theContainer = static_cast<TSorterContainer*>(fSorterList->ItemAt(sortIndex)); if (theContainer) { if (theContainer->IsActive()) { theContainer->Sort(); SynchronizeLists(theContainer); break; } } } return B_NO_ERROR; } return B_ERROR; } } } return B_ERROR; }
void listview::BuildList(entry_ref ref) { startref = ref; // (new BAlert("Niue", "Rebuilding list", "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); //first off, clear all items fList->MakeEmpty(); //seperators BListItem *seperator; fList->AddItem(new TListItem("Source files:")); fList->AddItem(seperator = new TListItem(" ")); fList->AddItem(new TListItem("Resources:")); // and build the list dir.SetTo(&ref); // int count; while (dir.GetNextEntry(&entry, true) == B_NO_ERROR) { if (entry.IsFile()) { BNode node(&entry); BNodeInfo nodeInfo(&node); char type[256]; nodeInfo.GetType(type); BString t; t << type; if (t == "text/x-source-code") fList->AddItem(new TListItem(&entry, true), fList->IndexOf(seperator)); else fList->AddItem(new TListItem(&entry, false)); } } UpdateList(NULL,false); }
TMovieCue::TMovieCue(entry_ref &theRef, int16 id, TCueChannel *parent, BRect bounds, uint32 startTime) : TVisualCue(id, parent, bounds, startTime, "PictureCue") { // Init member variables m_Editor = NULL; m_File = NULL; // // Attempt to load data file // BNode theNode(&theRef); if (theNode.InitCheck() != B_OK) return; BNodeInfo nodeInfo(&theNode); if (nodeInfo.InitCheck() != B_OK) return; // First, make sure we have a valid ref if ( IsVideo(nodeInfo) ) { // Create a BMessage that includes the entry_ref to send to our open routine BMessage *theMessage = new BMessage(B_REFS_RECEIVED); theMessage->AddRef("refs", &theRef); bool retVal = LoadMovieFile(theMessage); // We are succesful. Init the cue if (retVal) { Init(); } // If we have an error, ask the user to locate a new data file else { ShowPanel(); } } }
nsGenericHTMLElement* NS_NewHTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo, PRUint32 aFromParser) { /* * nsHTMLAudioElement's will be created without a nsINodeInfo passed in * if someone says "var audio = new Audio();" in JavaScript, in a case like * that we request the nsINodeInfo from the document's nodeinfo list. */ nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo); if (!nodeInfo) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); NS_ENSURE_TRUE(doc, nsnull); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nsnull, kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, nsnull); } return new nsHTMLAudioElement(nodeInfo.forget(), aFromParser); }
nsGenericHTMLElement* NS_NewHTMLImageElement(already_AddRefed<nsINodeInfo> aNodeInfo, mozilla::dom::FromParser aFromParser) { /* * HTMLImageElement's will be created without a nsINodeInfo passed in * if someone says "var img = new Image();" in JavaScript, in a case like * that we request the nsINodeInfo from the document's nodeinfo list. */ nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo); if (!nodeInfo) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); NS_ENSURE_TRUE(doc, nullptr); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nullptr, kNameSpaceID_XHTML, nsIDOMNode::ELEMENT_NODE); NS_ENSURE_TRUE(nodeInfo, nullptr); } return new mozilla::dom::HTMLImageElement(nodeInfo.forget()); }
void GraphNodeInformationDatabase::FillDatabase() { FBlueprintActionDatabase::FActionRegistry const& actionDatabase = FBlueprintActionDatabase::Get().GetAllActions(); for (auto const& actionEntry : actionDatabase) { for (UBlueprintNodeSpawner const* nodeSpawner : actionEntry.Value) { UEdGraphNode* nodeTemplate = nodeSpawner->GetTemplateNode(); if (nodeTemplate != nullptr && nodeTemplate->IsA(UK2Node::StaticClass())) { UK2Node* ukNode = Cast<UK2Node>(nodeTemplate); FBlueprintNodeSignature signature = ukNode->GetSignature(); FGuid nodeSignatureGuid = signature.AsGuid(); GraphNodeInformation nodeInfo(*ukNode); m_GraphNodeInformation.Add(nodeSignatureGuid, nodeInfo); } } } m_HasBuiltDatabase = true; }
TeamListItem::TeamListItem(team_info &teamInfo) : fTeamInfo(teamInfo), fAppInfo(), fMiniIcon(BRect(0, 0, 15, 15), B_RGBA32), fLargeIcon(BRect(0, 0, 31, 31), B_RGBA32), fFound(false), fRefusingToQuit(false) { int32 cookie = 0; image_info info; if (get_next_image_info(teamInfo.team, &cookie, &info) == B_OK) { fPath = BPath(info.name); BNode node(info.name); BNodeInfo nodeInfo(&node); nodeInfo.GetTrackerIcon(&fMiniIcon, B_MINI_ICON); nodeInfo.GetTrackerIcon(&fLargeIcon, B_LARGE_ICON); } if (be_roster->GetRunningAppInfo(fTeamInfo.team, &fAppInfo) != B_OK) fAppInfo.signature[0] = '\0'; CacheLocalizedName(); }
bool FileIterator::_ExamineFile(BEntry& entry, char* buffer, bool textFilesOnly) { BPath path; if (entry.GetPath(&path) != B_OK) return false; strcpy(buffer, path.Path()); if (!textFilesOnly) return true; BMimeType mimeType; BNode node(&entry); BNodeInfo nodeInfo(&node); char mimeTypeString[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(mimeTypeString) != B_OK) { // try to get a MIME type before failing if (BMimeType::GuessMimeType(path.Path(), &mimeType) != B_OK) return false; nodeInfo.SetType(mimeType.Type()); } else mimeType.SetTo(mimeTypeString); BMimeType superType; if (mimeType.GetSupertype(&superType) == B_OK) { if (strcmp("text", superType.Type()) == 0 || strcmp("message", superType.Type()) == 0) { return true; } } return false; }
bool TRefFilter::Filter(const entry_ref *theRef, BNode *theNode, struct stat_beos *theStat, const char *mimetype) { // Create BEntry and traverse to get source ref BEntry entry(theRef, true); if (entry.InitCheck() != B_OK) { ERROR("TRefFilter::Filter() - Error creating BEntry -\n"); return false; } // Create a node from ref BNode localNode(theRef); if (localNode.InitCheck() != B_OK) { ERROR("TRefFilter::Filter() - Error creating BNode -\n"); return false; } // Get node info BNodeInfo nodeInfo(&localNode); if (nodeInfo.InitCheck() != B_OK) { ERROR("TRefFilter::Filter() - Error getting BNodeInfo -\n"); return false; } // Get stat info struct stat st; if (entry.GetStat(&st) != B_OK) { ERROR("TRefFilter::Filter() - Error getting stat info -\n"); return false; } switch(m_FilterType) { case kAudioFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow audio if (IsAudio(nodeInfo)) return true; } break; case kAudioAiffFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow audio if (IsAudioAiff(nodeInfo)) return true; } break; case kImageFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow images if (IsImage(nodeInfo)) return true; } break; case kTextFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow text if (IsText(nodeInfo)) return true; } break; case kVideoFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow video if (IsVideo(nodeInfo)) return true; } break; case kCueSheetFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; // Allow CueSheets if (IsCueSheet(nodeInfo)) return true; } break; case kDirectoryFilter: { // Allow directories if (S_ISDIR(st.st_mode)) return true; } break; default: return true; } // Fail if we get here return false; }
status_t TTracker::OpenRef(const entry_ref *ref, const node_ref *nodeToClose, const node_ref *nodeToSelect, OpenSelector selector, const BMessage *messageToBundle) { Model *model = NULL; BEntry entry(ref, true); status_t result = entry.InitCheck(); bool brokenLinkWithSpecificHandler = false; BString brokenLinkPreferredApp; if (result != B_OK) { model = new Model(ref, false); if (model->IsSymLink() && !model->LinkTo()) { model->GetPreferredAppForBrokenSymLink(brokenLinkPreferredApp); if (brokenLinkPreferredApp.Length() && brokenLinkPreferredApp != kTrackerSignature) brokenLinkWithSpecificHandler = true; } if (!brokenLinkWithSpecificHandler) { delete model; (new BAlert("", "There was an error resolving the link.", "Cancel", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); return result; } } else model = new Model(&entry); result = model->InitCheck(); if (result != B_OK) { delete model; return result; } bool openAsContainer = model->IsContainer(); if (openAsContainer && selector != kOpenWith) { // if folder or query has a preferred handler and it's not the // Tracker, open it by sending refs to the handling app // if we are responding to the final open of OpenWith, just // skip this and proceed to opening the container with Tracker model->OpenNode(); BNodeInfo nodeInfo(model->Node()); char preferredApp[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetPreferredApp(preferredApp) == B_OK && strcasecmp(preferredApp, kTrackerSignature) != 0) openAsContainer = false; model->CloseNode(); } if (openAsContainer || selector == kRunOpenWithWindow) { // special case opening plain folders, queries or using open with OpenContainerWindow(model, 0, selector); // window adopts model if (nodeToClose) CloseParentWaitingForChildSoon(ref, nodeToClose); } else if (model->IsQueryTemplate()) { // query template - open new find window (new FindWindow(model->EntryRef()))->Show(); if (nodeToClose) CloseParentWaitingForChildSoon(ref, nodeToClose); } else { delete model; // run Launch in a separate thread // and close parent if successfull if (nodeToClose) Thread::Launch(new EntryAndNodeDoSoonWithMessageFunctor<TTracker, bool (TTracker::*)(const entry_ref *, const node_ref *, const BMessage *)>(&TTracker::LaunchAndCloseParentIfOK, this, ref, nodeToClose, messageToBundle)); else { BMessage refsReceived(B_REFS_RECEIVED); if (messageToBundle) { refsReceived = *messageToBundle; refsReceived.what = B_REFS_RECEIVED; } refsReceived.AddRef("refs", ref); if (brokenLinkWithSpecificHandler) // This cruft is to support a hacky workaround for double-clicking // broken refs for cifs; should get fixed in R5 LaunchBrokenLink(brokenLinkPreferredApp.String(), &refsReceived); else TrackerLaunch(&refsReceived, true); } } if (nodeToSelect) SelectChildInParentSoon(ref, nodeToSelect); return B_OK; }
void PDocument::Save(void) { TRACE(); status_t err = B_OK; BTranslatorRoster *roster = BTranslatorRoster::Default(); BMessage *archived = new BMessage(); BMessage *saveSettings = new BMessage(); char *formatName = NULL; translator_info *translatorInfo = new translator_info; int32 tmpInt = 0; int32 outType = 0; bool locked = Lock(); documentSetting->FindMessage("saveSettings",saveSettings); if (saveSettings->FindInt32("translator_id",&tmpInt) == B_OK) { translatorInfo->translator = tmpInt; saveSettings->FindString("format::name",(const char**)&formatName); //saveSettings->FindString("format::MIME",(const char**)&formatMIME); strcpy((translatorInfo->name),formatName); strcpy((translatorInfo->MIME),P_C_DOCUMENT_MIMETYPE); saveSettings->FindInt32("format::type",(int32 *)&outType); translatorInfo->type = P_C_DOCUMENT_RAW_TYPE; // saveSettings->FindInt32("format::group",(int32 *)&tmpInt); translatorInfo->group = P_C_DOCUMENT_RAW_TYPE; // saveSettings->FindFloat("format::quality",(float *)&tmpFloat); translatorInfo->quality = 0.9; // saveSettings->FindFloat("format::capability",(float *)&tmpFloat); translatorInfo->capability = 0.9; Archive(archived,true); BPositionIO *input = new BMallocIO(); BFile *file = new BFile(entryRef,B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE); archived->Flatten(input); err= roster->Translate(input,translatorInfo,NULL,file,outType); if (err == B_OK) { BNodeInfo nodeInfo(file); nodeInfo.SetType(P_C_DOCUMENT_MIMETYPE); nodeInfo.SetPreferredApp(APP_SIGNATURE); } } else { Archive(archived,true); if (entryRef) { BFile *file= new BFile(entryRef,B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE); err=file->InitCheck(); PRINT(("ERROR\tSave file error %s\n",strerror(err))); err = archived->Flatten(file); if (err == B_OK) { BNodeInfo nodeInfo(file); nodeInfo.SetType(P_C_DOCUMENT_MIMETYPE); nodeInfo.SetPreferredApp(APP_SIGNATURE); } } } if (err==B_OK) { ResetModified(); window->SetTitle(Title()); } else PRINT(("ERROR:\tPDocument","Save error %s\n",strerror(err))); if (locked) Unlock(); }
void PairsView::_ReadRandomIcons() { // TODO: maybe read the icons only once at startup // clean out any previous icons for (int i = 0; i < fCardBitmaps.CountItems(); i++) delete ((BBitmap*)fCardBitmaps.ItemAt(i)); fCardBitmaps.MakeEmpty(); BDirectory appsDirectory; BDirectory prefsDirectory; BPath path; if (find_directory(B_BEOS_APPS_DIRECTORY, &path) == B_OK) appsDirectory.SetTo(path.Path()); if (find_directory(B_BEOS_PREFERENCES_DIRECTORY, &path) == B_OK) prefsDirectory.SetTo(path.Path()); // read vector icons from apps and prefs folder and put them // into a BList as BBitmaps BList bitmaps; BEntry entry; while (appsDirectory.GetNextEntry(&entry) == B_OK || prefsDirectory.GetNextEntry(&entry) == B_OK) { BNode node(&entry); BNodeInfo nodeInfo(&node); if (nodeInfo.InitCheck() < B_OK) continue; uint8* data; size_t size; type_code type; if (nodeInfo.GetIcon(&data, &size, &type) < B_OK) continue; if (type != B_VECTOR_ICON_TYPE) { delete[] data; continue; } BBitmap* bitmap = new BBitmap( BRect(0, 0, kBitmapSize - 1, kBitmapSize - 1), 0, B_RGBA32); if (BIconUtils::GetVectorIcon(data, size, bitmap) < B_OK) { delete[] data; delete bitmap; continue; } delete[] data; if (_HasBitmap(bitmaps, bitmap) || !bitmaps.AddItem(bitmap)) delete bitmap; else if (bitmaps.CountItems() >= 128) { // this is enough to choose from, stop eating memory... break; } } // pick random bitmaps from the ones we got in the list srand((unsigned)time(0)); for (int i = 0; i < fNumOfCards / 2; i++) { int32 index = rand() % bitmaps.CountItems(); BBitmap* bitmap = ((BBitmap*)bitmaps.RemoveItem(index)); if (bitmap == NULL) { char buffer[512]; snprintf(buffer, sizeof(buffer), B_TRANSLATE("Pairs did not find " "enough vector icons in the system; it needs at least %d."), fNumOfCards / 2); BString msgStr(buffer); msgStr << "\n"; BAlert* alert = new BAlert("Fatal", msgStr.String(), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_WIDEST, B_STOP_ALERT); alert->SetShortcut(0, B_ESCAPE); alert->Go(); exit(1); } fCardBitmaps.AddItem(bitmap); } // delete the remaining bitmaps from the list while (BBitmap* bitmap = (BBitmap*)bitmaps.RemoveItem(0L)) delete bitmap; }
bool TemplatesMenu::BuildMenu(bool addItems) { // Clear everything... fOpenItem = NULL; int32 count = CountItems(); while (count--) delete RemoveItem((int32)0); // Add the Folder IconMenuItem* menuItem = new IconMenuItem(B_TRANSLATE("New folder"), new BMessage(kNewFolder), B_DIR_MIMETYPE, B_MINI_ICON); AddItem(menuItem); menuItem->SetShortcut('N', 0); // The Templates folder BPath path; find_directory (B_USER_SETTINGS_DIRECTORY, &path, true); path.Append(kTemplatesDirectory); mkdir(path.Path(), 0777); count = 0; BEntry entry; BDirectory templatesDir(path.Path()); while (templatesDir.GetNextEntry(&entry) == B_OK) { BNode node(&entry); BNodeInfo nodeInfo(&node); char fileName[B_FILE_NAME_LENGTH]; entry.GetName(fileName); if (nodeInfo.InitCheck() == B_OK) { char mimeType[B_MIME_TYPE_LENGTH]; nodeInfo.GetType(mimeType); BMimeType mime(mimeType); if (mime.IsValid()) { if (count == 0) AddSeparatorItem(); count++; // If not adding items, we are just seeing if there // are any to list. So if we find one, immediately // bail and return the result. if (!addItems) break; entry_ref ref; entry.GetRef(&ref); BMessage* message = new BMessage(kNewEntryFromTemplate); message->AddRef("refs_template", &ref); message->AddString("name", fileName); AddItem(new IconMenuItem(fileName, message, &nodeInfo, B_MINI_ICON)); } } } AddSeparatorItem(); // This is the message sent to open the templates folder. BMessage* message = new BMessage(B_REFS_RECEIVED); entry_ref dirRef; if (templatesDir.GetEntry(&entry) == B_OK) entry.GetRef(&dirRef); message->AddRef("refs", &dirRef); // Add item to show templates folder. fOpenItem = new BMenuItem(B_TRANSLATE("Edit templates" B_UTF8_ELLIPSIS), message); AddItem(fOpenItem); if (dirRef == entry_ref()) fOpenItem->SetEnabled(false); return count > 0; }
void ImageFilePanel::SelectionChanged() { entry_ref ref; Rewind(); if (GetNextSelectedRef(&ref) == B_OK) { BEntry entry(&ref); BNode node(&ref); fImageView->ClearViewBitmap(); if (node.IsFile()) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); if (bitmap != NULL) { BRect dest(fImageView->Bounds()); if (bitmap->Bounds().Width() > bitmap->Bounds().Height()) { dest.InsetBy(0, (dest.Height() + 1 - ((bitmap->Bounds().Height() + 1) / (bitmap->Bounds().Width() + 1) * (dest.Width() + 1))) / 2); } else { dest.InsetBy((dest.Width() + 1 - ((bitmap->Bounds().Width() + 1) / (bitmap->Bounds().Height() + 1) * (dest.Height() + 1))) / 2, 0); } fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0); BString resolution; resolution << B_TRANSLATE("Resolution: ") << (int)(bitmap->Bounds().Width() + 1) << "x" << (int)(bitmap->Bounds().Height() + 1); fResolutionView->SetText(resolution.String()); delete bitmap; BNodeInfo nodeInfo(&node); char type[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(type) == B_OK) { BMimeType mimeType(type); mimeType.GetShortDescription(type); // if this fails, the MIME type will be displayed fImageTypeView->SetText(type); } else { BMimeType refType; if (BMimeType::GuessMimeType(&ref, &refType) == B_OK) { refType.GetShortDescription(type); // if this fails, the MIME type will be displayed fImageTypeView->SetText(type); } else fImageTypeView->SetText(""); } } } else { fResolutionView->SetText(""); fImageTypeView->SetText(""); } fImageView->Invalidate(); fResolutionView->Invalidate(); } BFilePanel::SelectionChanged(); }
void RocketView::MouseDown(BPoint where) { // focus the list for scrolling MakeFocus(true); uint32 buttons; // retrieve the button state from the MouseDown message if (Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons) == B_NO_ERROR) { // find item at the mouse location int32 item = IndexOf(where); // make sure item is valid if ((item >= 0) && (item < CountItems())) { // if clicked with second mouse button, let's do a context-sensitive menu if (buttons & B_SECONDARY_MOUSE_BUTTON) { BPoint point = where; ConvertToScreen(&point); // select this item Select(item); //see if we need to enable some features //mark as source int32 index; entry_ref *ref = NULL; TListItem *item; //finds selected item index = CurrentSelection(); item = dynamic_cast<TListItem *>(ItemAt(index)); if (item) ref = item->Ref(); BNode node(ref); BNodeInfo nodeInfo(&node); char type[256]; nodeInfo.GetType(type); BString t; t << type; /* if (t == "text/x-source-code") mnuLeft->ItemAt(0)->SetEnabled(false); else mnuLeft->ItemAt(0)->SetEnabled(true); */ mnuLeft->Go(point, true,true,(BRect(point.x,point.y,point.x + 1,point.y + 1)),true); return; } else if (buttons & B_PRIMARY_MOUSE_BUTTON) { if (CurrentSelection() == item) Invoke(); else Select(item); } } } }
void Project::Save(const char *path) { BString projectPath = fPath.GetFolder(); projectPath << "/"; BString data; data << "NAME=" << fName << "\nTARGETNAME=" << fTargetName << "\n"; data << "PLATFORM=" << sPlatformArray[fPlatform] << "\n"; switch (fSCMType) { case SCM_HG: { data << "SCM=hg\n"; break; } case SCM_GIT: { data << "SCM=git\n"; break; } case SCM_SVN: { data << "SCM=svn\n"; break; } case SCM_NONE: { data << "SCM=none\n"; break; } default: { break; } } for (int32 i = 0; i < CountGroups(); i++) { SourceGroup *group = GroupAt(i); data << "GROUP=" << group->name << "\n"; data << "EXPANDGROUP=" << (group->expanded ? "yes" : "no") << "\n"; for (int32 j = 0; j < group->filelist.CountItems(); j++) { SourceFile *file = group->filelist.ItemAt(j); BString temppath(file->GetPath().GetFullPath()); if (temppath.FindFirst(projectPath.String()) == 0) { // Absolute paths which include the project folder are stripped // down into relative paths temppath.RemoveFirst(projectPath.String()); } data << "SOURCEFILE=" << temppath << "\n"; if (file->GetDependencies() && strlen(file->GetDependencies()) > 0) data << "DEPENDENCY=" << file->GetDependencies() << "\n"; } } for (int32 i = 0; i < fLocalIncludeList.CountItems(); i++) data << "LOCALINCLUDE=" << fLocalIncludeList.ItemAt(i)->Relative() << "\n"; for (int32 i = 0; i < fSystemIncludeList.CountItems(); i++) { BString *string = fSystemIncludeList.ItemAt(i); BString include = *string; if (include[0] == '/') include.RemoveFirst(projectPath.String()); data << "SYSTEMINCLUDE=" << include << "\n"; } for (int32 i = 0; i < fLibraryList.CountItems(); i++) { SourceFile *file = (SourceFile*)fLibraryList.ItemAt(i); if (!file) continue; BString strpath(file->GetPath().GetFullPath()); if (gPlatform == PLATFORM_ZETA) { if (strpath.FindFirst("/boot/beos/etc/develop/zeta-r1-gcc2-x86/") == 0) strpath.ReplaceFirst("/boot/beos/etc/develop/zeta-r1-gcc2-x86/", "/boot/develop/"); } if (strpath.FindFirst(projectPath.String()) == 0) strpath.RemoveFirst(projectPath.String()); data << "LIBRARY=" << strpath.String() << "\n"; } data << "RUNARGS=" << fRunArgs << "\n"; data << "CCDEBUG=" << (fDebug ? "yes" : "no") << "\n"; data << "CCPROFILE=" << (fProfile ? "yes" : "no") << "\n"; data << "CCOPSIZE=" << (fOpSize ? "yes" : "no") << "\n"; data << "CCOPLEVEL=" << (int)fOpLevel << "\n"; data << "CCTARGETTYPE=" << fTargetType << "\n"; data << "CCEXTRA=" << fExtraCompilerOptions << "\n"; data << "LDEXTRA=" << fExtraLinkerOptions << "\n"; BFile file(path,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); if (file.InitCheck() != B_OK) { STRACE(2,("Couldn't create project file %s. Bailing out\n",path)); return; } STRACE(2,("Saved Project %s. Data as follows:\n%s\n",path,data.String())); file.Write(data.String(),data.Length()); fPath = path; fObjectPath = fPath.GetFolder(); BString objfolder("(Objects."); objfolder << GetName() << ")"; fObjectPath.Append(objfolder.String()); BNodeInfo nodeInfo(&file); nodeInfo.SetType(PROJECT_MIME_TYPE); UpdateBuildInfo(); }
void listview::MessageReceived(BMessage *msg) { switch (msg->what) { case ITEM_MENU_SELECTED_MSG: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); // nodeInfo.SetTo(); char type[256]; nodeInfo.GetType(type); BString t; t << type; // printf(type); // const char *text = type; // (new BAlert("Niue", type, "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); // if (t == "text/plain" || t == "text/rtf" || t == "text/x-makefile" || t == "text/x-vnd.Be.ResourceDef" || t == "text/x-source-code") // { BMessage msg(SHOW_FILE_MSG); msg.AddRef("refs", fileref); msg.AddPointer("YWin",this); be_app->PostMessage(&msg); // } // else // { // //be_roster->Launch(fileref); // } break; } case ITEM_MENU_INVOKED_MSG: { // entry_ref *fileref = FindItem(); // be_roster->Launch(fileref); break; } case MNU_LEFT_SET_SOURCE: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("text/x-source-code"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_MAKEFILE: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("text/x-makefile"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_RESOURCE: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("application/x-be-resource"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_TEXT: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("text/plain"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_IMAGE: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("image"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_AUDIO: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("audio"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_VIDEO: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("video"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_APP: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("application/x-vnd.Be-elfexecutable"); //rebuild list BuildList(startref); break; } case MNU_LEFT_SET_ARCHIVE: { entry_ref *fileref = FindItem(); BNode node(fileref); BNodeInfo nodeInfo(&node); nodeInfo.SetType("application/zip"); //rebuild list BuildList(startref); break; } case MNU_LEFT_OPEN_MSG: { entry_ref *fileref = FindItem(); be_roster->Launch(fileref); break; } case MNU_LEFT_TRACKER_MSG: { BString sysstring; BEntry direntry; BPath dirpath; dir.GetEntry(&direntry); direntry.GetPath(&dirpath); sysstring << "/system/Tracker "; sysstring << dirpath.Path(); //(new BAlert("Niue", sysstring.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); system(sysstring.String()); break; } case MNU_LEFT_TRASH_MSG: { //(new BAlert("Niue", "trash it", "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); entry_ref *fileref = FindItem(); BEntry fileentry; BDirectory trashdir; BPath trashpath; find_directory(B_TRASH_DIRECTORY, &trashpath, false); fileentry.SetTo(fileref); trashdir.SetTo(trashpath.Path()); fileentry.MoveTo(&trashdir, 0, true); break; } case MNU_LEFT_DUPLICATE_MSG: { BString duplistring; BEntry duplientry; BPath duplipath; entry_ref *fileref = FindItem(); duplientry.SetTo(fileref); duplientry.GetPath(&duplipath); duplistring << "cp "; duplistring << duplipath.Path(); duplistring << " "; duplistring << duplipath.Path(); duplistring << "_copy"; //(new BAlert("Niue", duplistring.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); system(duplistring.String()); break; } case MNU_LEFT_INFO_MSG: { //get item, create vars entry_ref *fileref = FindItem(); BEntry fileentry; fileentry.SetTo(fileref, true); //name char name[B_FILE_NAME_LENGTH]; fileentry.GetName(name); //size BFile file(fileref, B_READ_ONLY); off_t size; file.GetSize(&size); //kind BNode node(fileref); BNodeInfo nodeInfo(&node); char type[256]; nodeInfo.GetType(type); //path BPath path; fileentry.GetPath(&path); //build info string BString infostring; infostring << "\n"; infostring << name; infostring << "\n\nSize: "; infostring << size << " bytes"; infostring << "\n\nKind: "; infostring << type; infostring << "\n\nPath: "; infostring << path.Path(); infostring << "\n\n"; (new BAlert("Niue file info", infostring.String(), "Close", 0, 0, B_WIDTH_AS_USUAL, B_INFO_ALERT))->Go(); break; } case MNU_LEFT_NAME_MSG: { entry_ref *fileref = FindItem(); BEntry fileentry; fileentry.SetTo(fileref); int32 index = fList->CurrentSelection(); BRect itemrect = fList->ItemFrame(index); BRect textrect = ConvertToScreen(itemrect); textrect.top += 6; textrect.bottom += 5; textrect.left += 28; //textrect.right += 5; BWindow* renameWindow = new renamewindow(textrect, fileentry); renameWindow->Show(); break; } case MNU_LEFT_COPY_MSG: { entry_ref *fileref = FindItem(); BEntry fileentry; fileentry.SetTo(fileref); char name[B_FILE_NAME_LENGTH]; fileentry.GetName(name); BMessage savemsg(B_SAVE_REQUESTED); savemsg.AddBool("keepfile", true); //we are copying so we have to keep the original CopyPanel = new BFilePanel(B_SAVE_PANEL, 0, 0, B_DIRECTORY_NODE | B_FILE_NODE, false, &savemsg, 0, false, true); CopyPanel->SetTarget(this); CopyPanel->SetSaveText(name); CopyPanel->Show(); break; } case MNU_LEFT_MOVE_MSG: { entry_ref *fileref = FindItem(); BEntry fileentry; fileentry.SetTo(fileref); char name[B_FILE_NAME_LENGTH]; fileentry.GetName(name); BMessage savemsg(B_SAVE_REQUESTED); savemsg.AddBool("keepfile", false); //we are moving so no need to keep the original CopyPanel = new BFilePanel(B_SAVE_PANEL, 0, 0, B_DIRECTORY_NODE | B_FILE_NODE, false, &savemsg, 0, false, true); CopyPanel->SetTarget(this); CopyPanel->SetSaveText(name); CopyPanel->Show(); break; } case B_SAVE_REQUESTED: { //get item entry entry_ref *fileref = FindItem(); BEntry fileentry; fileentry.SetTo(fileref); BPath filepath; fileentry.GetPath(&filepath); //get destination entry_ref dirref; BEntry direntry; BPath dirpath; BString namestring; bool keepfile; if (msg->FindRef("directory", &dirref) == B_NO_ERROR && msg->FindString("name", &namestring) == B_NO_ERROR && msg->FindBool("keepfile", &keepfile) == B_NO_ERROR) { direntry.SetTo(&dirref, true); direntry.GetPath(&dirpath); BString copystring; if (keepfile == true) copystring << "cp "; else copystring << "mv "; copystring << filepath.Path(); copystring << " "; copystring << dirpath.Path(); copystring << "/"; copystring << namestring; //(new BAlert("Niue", copystring.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); system(copystring.String()); } break; } case B_SIMPLE_DATA: //someone dropped something on us { //(new BAlert("Niue", "Drop", "Ok", 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); be_app->PostMessage(msg); break; } } }
void Model::TrackIconSource(icon_size size) { PRINT(("tracking %s icon\n", size == B_LARGE_ICON ? "large" : "small")); BRect rect; if (size == B_MINI_ICON) rect.Set(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1); else rect.Set(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1); BBitmap bitmap(rect, B_CMAP8); BModelOpener opener(this); if (Node() == NULL) { PRINT(("track icon error - no node\n")); return; } if (IsSymLink()) { PRINT(("tracking symlink icon\n")); if (fLinkTo) { fLinkTo->TrackIconSource(size); return; } } if (fBaseType == kVolumeNode) { BVolume volume(NodeRef()->device); status_t result = volume.GetIcon(&bitmap, size); PRINT(("getting icon from volume %s\n", strerror(result))); } else { BNodeInfo nodeInfo(Node()); status_t err = nodeInfo.GetIcon(&bitmap, size); if (err == B_OK) { // file knew which icon to use, we are done PRINT(("track icon - got icon from file\n")); return; } char preferredApp[B_MIME_TYPE_LENGTH]; err = nodeInfo.GetPreferredApp(preferredApp); if (err == B_OK && preferredApp[0]) { BMimeType preferredAppType(preferredApp); err = preferredAppType.GetIconForType(MimeType(), &bitmap, size); if (err == B_OK) { PRINT(("track icon - got icon for type %s from preferred app %s for file\n", MimeType(), preferredApp)); return; } } BMimeType mimeType(MimeType()); err = mimeType.GetIcon(&bitmap, size); if (err == B_OK) { // the system knew what icon to use for the type, we are done PRINT(("track icon - signature %s, got icon from system\n", MimeType())); return; } err = mimeType.GetPreferredApp(preferredApp); if (err != B_OK) { // no preferred App for document, give up PRINT(("track icon - signature %s, no prefered app, error %s\n", MimeType(), strerror(err))); return; } BMimeType preferredAppType(preferredApp); err = preferredAppType.GetIconForType(MimeType(), &bitmap, size); if (err == B_OK) { // the preferred app knew icon to use for the type, we are done PRINT(("track icon - signature %s, got icon from preferred app %s\n", MimeType(), preferredApp)); return; } PRINT(("track icon - signature %s, preferred app %s, no icon, error %s\n", MimeType(), preferredApp, strerror(err))); } }
boost::optional<std::pair<std::shared_ptr<MasterNode>, std::string>> Master::bindClientToDomain(const std::shared_ptr<MasterClient>& client) { using RetType = std::pair<std::shared_ptr<MasterNode>, std::string>; auto room = client->room(); std::vector<Balancer<RetType>::Item> items; { std::lock_guard<std::recursive_mutex> lock(nodeConnectionsMutex); std::lock_guard<std::recursive_mutex> lock2(nodeThrottlesMutex); std::lock_guard<std::recursive_mutex> lock3(versionsMutex); for (const auto& c: nodes) { auto node = c.second; if (!node->isConnected()) continue; // Has room? auto verOrNone = node->findDomainForRoom(room); if (verOrNone) { auto ver = *verOrNone; if (client->doesAcceptVersion(ver)) return RetType(node, ver); } // Get node throttle value auto it = nodeThrottles.find(node->nodeInfo().nodeName); if (it == nodeThrottles.end()) continue; double nodeThrottle = it->second; if (nodeThrottle <= 0.0) continue; // For every domains of the node... for (const auto& domain: node->domainStatuses()) { auto it2 = versions.find(domain.versionName); if (it2 == versions.end()) continue; // Get version throttle value double versionThrottle = it2->second.throttle; if (versionThrottle <= 0.0) continue; // Client accepts the version? if (!client->doesAcceptVersion(it2->first)) continue; // Add as balancer item Balancer<RetType>::Item item; item.key = RetType(node, domain.versionName); item.current = static_cast<double>(domain.numClients); item.desired = nodeThrottle * versionThrottle; items.emplace_back(std::move(item)); } } } // Invoke balancer return Balancer<RetType>().performBalancing(items); }