void InfoCommand::onItemsFetched(KJob *job) { if (job->error() != 0) { emit error(job->errorString()); emit finished(RuntimeError); return; } ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job); Q_ASSERT(fetchJob!=0); Item::List items = fetchJob->items(); if (items.count()<1) { emit error(i18nc("@info:shell", "Cannot find '%1' as a collection or item", mEntityArg)); emit finished(RuntimeError); return; } mInfoItem = new Item(items.first()); fetchParentPath(mInfoItem->parentCollection()); }
Expression::Ptr Expression::constantPropagate(const StaticContext::Ptr &context) const { Q_ASSERT(context); /* Optimization: We rewrite literals to literals here, which is pointless. * Maybe we should have a property which says "doesn't disable elimination * but don't eliminate me." */ if(staticType()->cardinality().allowsMany()) { Item::Iterator::Ptr it(evaluateSequence(context->dynamicContext())); Item::List result; Item item(it->next()); while(item) { result.append(item); item = it->next(); } switch(result.count()) { case 0: return EmptySequence::create(this, context); case 1: return rewrite(Expression::Ptr(new Literal(result.first())), context); default: return rewrite(Expression::Ptr(new LiteralSequence(result)), context); } } else { const Item item(evaluateSingleton(context->dynamicContext())); if(item) return rewrite(Expression::Ptr(new Literal(item)), context); else return EmptySequence::create(this, context); } }