コード例 #1
0
void LibraryView::showBook(shared_ptr<Book> book) {
	makeUpToDate();
	ZLBlockTreeNode::List bookNodes;
	std::queue<ZLBlockTreeNode*> nodesQueue;
	nodesQueue.push(&rootNode());
	while (!nodesQueue.empty()) {
		const ZLBlockTreeNode::List &children = nodesQueue.front()->children();
		nodesQueue.pop();
		for (ZLBlockTreeNode::List::const_iterator it = children.begin(); it != children.end(); ++it) {
			if ((*it)->isInstanceOf(BookNode::TYPE_ID)) {
				// TODO: replace with == for shared_ptr<Book>
				//if (((BookNode*)*it)->book() == book) {
				if (((BookNode*)*it)->book()->file() == book->file()) {
					bookNodes.push_back(*it);
				}
			} else {
				nodesQueue.push(*it);
			}
		}
	}
	if (bookNodes.empty()) {
		return;
	}
	ZLBlockTreeNode *nodeToShow = bookNodes[0];
	VisibilityMode mode = INVISIBLE;
	for (ZLBlockTreeNode::List::iterator it = bookNodes.begin(); it != bookNodes.end(); ++it) {
		VisibilityMode nodeMode = visibilityMode(*it);
		if ((nodeMode == VISIBLE && mode != VISIBLE) ||
				(nodeMode != INVISIBLE && mode == INVISIBLE)) {
			nodeToShow = *it;
			mode = nodeMode;
		}
	}
	ensureVisible(nodeToShow);
}
コード例 #2
0
ファイル: NetworkView.cpp プロジェクト: ALEXGUOQ/FBReader
void NetworkView::updateAccountDependents() {
	ZLBlockTreeNode::List rootChildren = rootNode().children();

	ZLBlockTreeNode::List::iterator nodeIt = rootChildren.begin();
	while (nodeIt != rootChildren.end() && (*nodeIt)->isInstanceOf(NetworkCatalogNode::TYPE_ID)) {
		NetworkCatalogNode &node = (NetworkCatalogNode &) **nodeIt;
		updateAccountDependents(node);
		++nodeIt;
	}
}
コード例 #3
0
ファイル: NetworkView.cpp プロジェクト: ALEXGUOQ/FBReader
void NetworkView::updateAccountDependents(NetworkCatalogNode &node) {
	std::set<ZLBlockTreeNode*> nodesToDelete;

	const NetworkItem::List &nodeItems = node.childrenItems();

	ZLBlockTreeNode::List nodeChildren = node.children();
	ZLBlockTreeNode::List::iterator nodeIt = nodeChildren.begin();

	size_t nodeCount = 0;
	for (size_t i = 0; i < nodeItems.size(); ++i) {
		shared_ptr<NetworkItem> currentItemPtr = nodeItems[i];
		NetworkItem &currentItem = *currentItemPtr;

		if (currentItem.typeId() != NetworkCatalogItem::TYPE_ID) {
			continue;
		}

		bool processed = false;
		while (nodeIt != nodeChildren.end()) {
			if (!(*nodeIt)->isInstanceOf(NetworkCatalogNode::TYPE_ID)) {
				++nodeIt;
				++nodeCount;
				continue;
			}
			NetworkCatalogNode &child = (NetworkCatalogNode &) **nodeIt;
			NetworkCatalogItem &childItem = child.item();
			if (&childItem == &currentItem) {
				if (processAccountDependent(child.item())) {
					updateAccountDependents(child);
				} else {
					nodesToDelete.insert(&child);
				}
				++nodeIt;
				++nodeCount;
				processed = true;
				break;
			} else {
				bool found = false;
				for (size_t j = i + 1; j < nodeItems.size(); ++j) {
					if (&childItem == &*nodeItems[j]) {
						found = true;
						break;
					}
				}
				if (!found) {
					nodesToDelete.insert(*nodeIt++);
					++nodeCount;
				} else {
					break;
				}
			}
		}
		if (!processed && processAccountDependent((NetworkCatalogItem &) currentItem)) {
			NetworkNodesFactory::createNetworkNode(&node, currentItemPtr, nodeCount++);
		}
	}

	while (nodeIt != nodeChildren.end()) {
		ZLBlockTreeNode *node = *nodeIt++;
		if (node->isInstanceOf(NetworkCatalogNode::TYPE_ID)) {
			nodesToDelete.insert(node);
		}
	}

	for (std::set<ZLBlockTreeNode*>::iterator it = nodesToDelete.begin(); it != nodesToDelete.end(); ++it) {
		delete *it;
	}
}
コード例 #4
0
ファイル: NetworkView.cpp プロジェクト: ALEXGUOQ/FBReader
void NetworkView::makeUpToDate() {
	NetworkLinkCollection &collection = NetworkLinkCollection::Instance();

	std::set<ZLBlockTreeNode*> nodesToDelete;
	ZLBlockTreeNode::List rootChildren = rootNode().children();

	ZLBlockTreeNode::List::iterator nodeIt = rootChildren.begin();
	size_t nodeCount = 0;
	for (size_t i = 0; i < collection.size(); ++i) {
		NetworkLink &link = collection.link(i);
		if (!link.OnOption.value()) {
			continue;
		}
		bool processed = false;
		while (nodeIt != rootChildren.end() &&
					 (*nodeIt)->isInstanceOf(NetworkCatalogNode::TYPE_ID)) {
			const NetworkLink &nodeLink = ((NetworkCatalogRootNode*)*nodeIt)->link();
			if (&nodeLink == &link) {
				++nodeIt;
				++nodeCount;
				processed = true;
				break;
			} else {
				bool found = false;
				for (size_t j = i + 1; j < collection.size(); ++j) {
					if (&nodeLink == &collection.link(j)) {
						found = true;
						break;
					}
				}
				if (!found) {
					nodesToDelete.insert(*nodeIt++);
					++nodeCount;
				} else {
					break;
				}
			}
		}
		if (!processed) {
			NetworkCatalogNode *ptr = new NetworkCatalogRootNode(&rootNode(), link, nodeCount++);
			ptr->item().onDisplayItem();
		}
	}

	SearchResultNode *srNode = 0;

	while (nodeIt != rootChildren.end()) {
		ZLBlockTreeNode *node = *nodeIt++;
		++nodeCount;
		if (node->isInstanceOf(SearchResultNode::TYPE_ID)) {
			srNode = (SearchResultNode*)node;
		} else {
			nodesToDelete.insert(node);
		}
	}

	const SearchResult &searchResult = SearchResult::lastSearchResult();
	shared_ptr<NetworkBookCollection> result = searchResult.collection();
	if (result.isNull()) {
		if (srNode != 0) {
			nodesToDelete.insert(srNode);
		}
	} else if (srNode == 0 || srNode->searchResult() != result) {
		if (srNode != 0) {
			nodesToDelete.insert(srNode);
		}
		srNode = new SearchResultNode(&rootNode(), result, searchResult.summary()); // at nodeCount ??? or not???
		NetworkNodesFactory::createSubnodes(srNode, *result);
	}

	for (std::set<ZLBlockTreeNode*>::iterator it = nodesToDelete.begin(); it != nodesToDelete.end(); ++it) {
		delete *it;
	}

	if (srNode != 0) {
		srNode->open(false);
		srNode->expandOrCollapseSubtree();
	}
}