예제 #1
0
status_t 
Model::SetTo(const entry_ref *newRef, bool traverse, bool open, bool writable)
{
	delete fNode;
	fNode = NULL;
	DeletePreferredAppVolumeNameLinkTo();
	fIconFrom = kUnknownSource;
	fBaseType = kUnknownNode;
	fMimeType = "";

	BEntry tmpEntry(newRef, traverse);
	fStatus = tmpEntry.InitCheck();
	if (fStatus != B_OK)
		return fStatus;

	if (traverse)
		tmpEntry.GetRef(&fEntryRef);
	else
		fEntryRef = *newRef;

	fStatus = tmpEntry.GetStat(&fStatBuf);
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = OpenNode(writable);
	if (!open)
		CloseNode();
	
	return fStatus;
}
예제 #2
0
status_t 
Model::UpdateStatAndOpenNode(bool writable)
{
	if (IsNodeOpen() && (writable == IsNodeOpenForWriting()))
		return B_OK;
	
	// try reading the stat structure again
	BEntry tmpEntry(&fEntryRef);
	fStatus = tmpEntry.InitCheck();
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = tmpEntry.GetStat(&fStatBuf);
	if (fStatus != B_OK)
		return fStatus;

	OpenNodeCommon(writable);
	return fStatus;
}
예제 #3
0
void
Model::PrintToStream(int32 level, bool deep)
{
	PRINT(("model name %s, entry name %s, inode %Lx, dev %x, directory inode %Lx\n",
		Name() ? Name() : "**empty name**",
		EntryRef()->name ? EntryRef()->name : "**empty ref name**",
		NodeRef()->node,
		NodeRef()->device,
		EntryRef()->directory));
	PRINT(("type %s \n", MimeType()));

	PRINT(("model type: "));
	switch (fBaseType) {
		case kPlainNode:
			PRINT(("plain\n"));
			break;

		case kQueryNode:
			PRINT(("query\n"));
			break;

		case kQueryTemplateNode:
			PRINT(("query template\n"));
			break;

		case kExecutableNode:
			PRINT(("exe\n"));
			break;

		case kDirectoryNode:
			PRINT(("dir\n"));
			break;

		case kLinkNode:
			PRINT(("link\n"));
			break;

		case kRootNode:
			PRINT(("root\n"));
			break;

		case kVolumeNode:
			PRINT(("volume, name %s\n", fVolumeName ? fVolumeName : ""));
			break;

		default:
			PRINT(("unknown\n"));
			break;
	}

	if (level < 1)
		return;

	if (!IsVolume())
		PRINT(("preferred app %s\n", fPreferredAppName ? fPreferredAppName : ""));

	PRINT(("icon from: "));
	switch (IconFrom()) {
		case kUnknownSource:
			PRINT(("unknown\n"));
			break;
		case kUnknownNotFromNode:
			PRINT(("unknown but not from a node\n"));
			break;
		case kTrackerDefault:
			PRINT(("tracker default\n"));
			break;
		case kTrackerSupplied:
			PRINT(("tracker supplied\n"));
			break;
		case kMetaMime:
			PRINT(("metamime\n"));
			break;
		case kPreferredAppForType:
			PRINT(("preferred app for type\n"));
			break;
		case kPreferredAppForNode:
			PRINT(("preferred app for node\n"));
			break;
		case kNode:
			PRINT(("node\n"));
			break;
		case kVolume:
			PRINT(("volume\n"));
			break;
	}

	PRINT(("model %s opened %s \n", !IsNodeOpen() ? "not " : "",
		IsNodeOpenForWriting() ? "for writing" : ""));

	if (IsNodeOpen()) {
		node_ref nodeRef;
		fNode->GetNodeRef(&nodeRef);
		PRINT(("node ref of open Node %Lx %x\n", nodeRef.node, nodeRef.device));
	}

	if (deep && IsSymLink()) {
		BEntry tmpEntry(EntryRef(), true);
		Model tmp(&tmpEntry);
		PRINT(("symlink to:\n"));
		tmp.PrintToStream();
	}
	TrackIconSource(B_MINI_ICON);
	TrackIconSource(B_LARGE_ICON);
}
예제 #4
0
// ---------------------------------------------------------------------------------------
// This function will build the Tree
//
// Logic:
//      Go bottom up. Take two nodes at a time and create parent for all leaf nodes
//      Insert the parent nodes in a queue
//      Take two elements from the queue and create parent for all those nodes
//      Repeat this process until the queue is empty
//      Make sure to set the _colorRoot to the first node in the queue
// ---------------------------------------------------------------------------------------
void
RandomColorByWeight::buildTree()
{
    std::queue<std::shared_ptr<ColorNode>> colorNodesQueue;

    for (auto colorMapItr = _colorsMap.begin(); colorMapItr != _colorsMap.end(); colorMapItr++)
    {
        std::shared_ptr<ColorNode> elmnt1 = colorMapItr->second;

        // Go to the next element in the map
        colorMapItr++;

        if (colorMapItr != _colorsMap.end())
        {
            std::shared_ptr<ColorNode> elmnt2 = colorMapItr->second;
            std::shared_ptr<ColorNode> tmpEntry (new ColorNode(elmnt1->_weight + elmnt2->_weight));

            // Adjust left and right pointers of the new entry that we created
            tmpEntry->_left = elmnt1;
            tmpEntry->_right = elmnt2;

            // Add parent pointer to the child entries
            elmnt1->_parent = tmpEntry;
            elmnt2->_parent = tmpEntry;

            colorNodesQueue.push(tmpEntry);    
        }
        else
        {
            // We have reach the end of Map. So break out of the loop
            colorNodesQueue.push(elmnt1);    
            break;
        }
    }

    // Take two nodes from the stack and form a SumNode
    // Push the sumNode back into the stack
    // Repeat till the stack size is > 1
    while (!colorNodesQueue.empty())
    {
        // Get the next element from the stack
        std::shared_ptr<ColorNode> elmnt1 = colorNodesQueue.front();
        colorNodesQueue.pop();

        if (!colorNodesQueue.empty())
        {
            // Get the next element from the stack
            std::shared_ptr<ColorNode> elmnt2 = colorNodesQueue.front();
            colorNodesQueue.pop();

            std::shared_ptr<ColorNode> tmpEntry (new ColorNode(elmnt1->_weight + elmnt2->_weight));

            // Adjust left and right pointers of the new entry that we created
            tmpEntry->_left = elmnt1;
            tmpEntry->_right = elmnt2;

            // Add parent pointer to the child entries
            elmnt1->_parent = tmpEntry;
            elmnt2->_parent = tmpEntry;

            colorNodesQueue.push(tmpEntry);    
        }
        else
        {
            _colorRoot = elmnt1;
        }
    }
}