void ZLBlockTreeView::ensureVisible(ZLBlockTreeNode *node) { if (visibilityMode(node) == VISIBLE) { return; } for (ZLBlockTreeNode *parent = node->parent(); parent != 0; parent = parent->parent()) { parent->open(true); } ZLBlockTreeNode *previous = node->previous(); setFirstVisibleNode(previous != 0 ? previous : node); if (previous && visibilityMode(node) != VISIBLE) { setFirstVisibleNode(node); } }
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); }
/*! * executes visibility delegate functionality, ie. calls CBTEngSettings to set the visibility mode; * when operation completes, emits commandCompleted signal * Parameters: Qlist<QVariant> where first item is VisibilityMode integer specifying operation; * for BtTemporary a 2nd parameter is give which signifies the number of minutes to stay visible. */ void BtDelegateVisibility::exec( const QVariant ¶ms ) { int minutes, err = 0; if (mActiveHandling) { // complete command with error emit delegateCompleted(KErrInUse, this); return; } mActiveHandling = true; // read 1st parameter BTUI_ASSERT_X(params.toList().at(0).isValid(), "BtDelegateVisibility::exec", "invalid parameter"); VisibilityMode btQtMode = (VisibilityMode)params.toList().at(0).toInt(); mOperation = BtEngVisibilityMode(btQtMode); // verify that we are setting visibility to a new value, otherwise we won't get a callback TBTVisibilityMode visibilityMode( EBTVisibilityModeNoScans ); err = mBtengSettings->GetVisibilityMode( visibilityMode ); if (err) { mActiveHandling = false; emit delegateCompleted(err, this); return; } if (visibilityMode == mOperation) { mActiveHandling = false; emit delegateCompleted(KErrNone, this); return; } switch (mOperation) { case EBTVisibilityModeGeneral : err = mBtengSettings->SetVisibilityMode(mOperation, 0); break; case EBTVisibilityModeHidden: err = mBtengSettings->SetVisibilityMode(mOperation, 0); break; case EBTVisibilityModeTemporary: BTUI_ASSERT_X(params.toList().at(1).isValid(), "BtDelegateVisibility::exec", "invalid time parameter"); minutes = params.toList().at(1).toInt(); BTUI_ASSERT_X(((minutes >= 0 ) && (minutes <= MAX_TEMPORARY_VISIBILITY)), "BtDelegateVisibility::exec", "invalid time parameter"); err = mBtengSettings->SetVisibilityMode(mOperation, minutes); break; default: // error BTUI_ASSERT_X(false, "BtDelegateVisibility::exec", "invalid parameter"); } if (err) { // complete command with error mActiveHandling = false; emit delegateCompleted(err, this); } }