Exemplo n.º 1
0
CatItem CatBuilder::updateItem(CatItem& it, int childDepth, UserEvent::LoadType lt) {
    if(!it.shouldUpdate(childDepth, lt)) {
        return it;
    }

    CatItem realItem;
    QList<int> matches = it.getMatchIndex();

    if(!it.getIsTempItem()) {
        QString path = it.getPath();
        realItem = getItem(path, childDepth);
        addSynonymChildren(realItem);

        //Our plugins can return items not in the database
        if(!realItem.isEmpty()) {
            //realItem.merge(it);
            it.merge(realItem);
        }
        if(lt!=UserEvent::IGNORE) {
            for(int i=0; i<childDepth; i++) {
                //avoiding address of reference of smart-pointer itme
                CatItem holder = it;
                if(plugins_ptr->itemLoading(&holder,lt)) {
                    cat->addItem(holder);
                    it = holder;
                }
            }
        }
    }
    it.setMatchIndex(matches);
    return it;
}
Exemplo n.º 2
0
ItemRep::ItemRep(CatItem it, Tuple internalId, int change_count,
                 short nthPiece, bool nameFromDescript){
    Q_ASSERT(!it.isEmpty());
    matchType = it.getMatchType();
    matchIndex = it.getMatchIndex();
    //description = it.fullDescription;
    m_internalId = internalId;
    m_name = it.getName();
    Q_ASSERT(!m_name.isEmpty());
    //Q_ASSERT(it.getFullWeight());
    totalWeight = it.getFullWeight();
    change_cn = change_count;
    l_to_match = -1;
    skip_m = false;
    this->itemType = it.getItemType();

    //change_cn = 0;

    m_nthPiece= nthPiece;
    m_name_from_description=nameFromDescript;

}
Exemplo n.º 3
0
QList<CatItem> Catalog::indexItemList(QList<CatItem>* catListPtr){
    Q_ASSERT(catListPtr);
    QList<CatItem> outList;
    cat_store.beginAddGroup();
    for(int i=0;i< catListPtr->count();i++){
        CatItem it = (*catListPtr)[i];
        if(it.isEmpty()){
            continue;
        }
        if(it.isForDBInsertOnly()){
            cat_store.addItemInGroup(it);
            continue;
        } else if(it.getIsTempItem()){
            outList.append((it));
        } else {
            outList.append(cat_store.addItemInGroup(it));
        }
        //THREAD_SLEEP;
    }
    cat_store.endAddGroup();
    return outList;
}
Exemplo n.º 4
0
int CatBuilder::launchObject(InputList& inputList, QList<CatItem> &outputList, QString* errString) {
    //up date catalogue with changes made to the existing item...

    CatItem baseItem = inputList.currentItem();
    if(!baseItem.isEmpty()) {
        cat->addItem(baseItem);
    }

    //cat->setExecuted(inputList);

    Q_ASSERT(plugins_ptr);
    plugins_ptr->preExecute(&inputList);
    QList<CatItem> output;
    int result = subexecute(inputList, output,errString);
    Q_ASSERT(cat);
    QList<CatItem> ci;
    ci.append( cat->setExecuted(&inputList));
    plugins_ptr->userItemsCreated(&ci);
    for(int i=0; i<output.count(); i++) {
        outputList.append(output[i]);
    }
    plugins_ptr->userItemsCreated(&ci);
    return result;
}
Exemplo n.º 5
0
QList<CatItem> Catalog::expandStubs(QString userKeys, QList<CatItem>* inList){

    QList<CatItem> stubs; QList<CatItem> oldStubs;
    QList<CatItem>* workingList = inList;
    QList<CatItem> res;
    bool refreshNeeded =false;
    int rep=0;

    QSet<QString> updated;
    while((workingList->length()>0)) {
        cat_store.beginAddGroup();
        for(int i=0; i<workingList->count();i++){
            CatItem toAdd = workingList->at(i);
            bool atStub = toAdd.isStub();
            if(plugins.itemLoading(&toAdd, UserEvent::BECOMING_VISIBLE)){
                if(toAdd.isForDelete()) {
                    cat_store.removeItem(workingList->at(i));
                    continue;
                }
                if(atStub) {
                    refreshNeeded = true;
                    //toAdd.setStub(false);
                    cat_store.addItemInGroup(toAdd);
                }
            }
            QList<CatItem> newStubs = extractStubs(toAdd);
            for(int j=0; j<newStubs.count(); j++){
                if(!updated.contains(newStubs[j].getPath())){
                    updated.insert(newStubs[j].getPath());
                    stubs.append(newStubs[j]);
                }
            }
        }
        oldStubs = stubs;
        workingList = &oldStubs;
        cat_store.endAddGroup();
        stubs.clear();
        Q_ASSERT(workingList->count() <1000);
        rep++;
        Q_ASSERT(rep<10);
    }

    cat_store.beginAddGroup();
    for(int i=0; i<inList->count();i++){
        CatItem toAdd = inList->at(i);
        if(toAdd.isForDBInsertOnly()){
            cat_store.addItemInGroup(toAdd);
            continue;
        }
        if(userKeys.isEmpty() || matches(&toAdd, userKeys) || toAdd.getTakesAnykeys()) {
            if(refreshNeeded){
                CatItem refreshed = cat_store.getItemByPath(toAdd.getPath());
                if(!refreshed.isEmpty()){
                    toAdd.mergeItem(refreshed,true);
                }
                toAdd.setMatchIndex(QList<int>());
            }
            if(!toAdd.hasLabel(BUILTIN))
                { res.append(toAdd);}
        }}
    cat_store.endAddGroup();
    return res;
}
Exemplo n.º 6
0
QList<CatItem> Catalog::parseRequest(InputList & inputData, int itemsDesired, int* beginPos){


    if(inputData.customVerbChosen() && !inputData.isOperationChosen()){
        return cat_store.getItemsByKey(inputData.getUserKeys(), &inputData, itemsDesired);
    }
    if(inputData.isOperationChosen()){
        return getOperationChildren(inputData);
    }

    if(!inputData.getParentItem().isEmpty() ){
        if(inputData.getParentItem().canFilterWith()){
            return cat_store.getAssociatedDocuments(&inputData, inputData.getParentItem(), itemsDesired);
        } else {
            CatItem par = cat_store.getItemByPath(inputData.getParentItem().getPath(),1);
            CatBuilder::updateItem(par,2,UserEvent::SELECTED);
            return par.getChildren();
        }
    }

    QList<CatItem> res;
    if(inputData.getUserKeys().length() >0){
        QString userKeys = inputData.getUserKeys();
        res.append(cat_store.getItemsByKey(userKeys, &inputData, itemsDesired, beginPos));
    } else if(inputData.slotCount() ==1 || inputData.isOperationChosen()){
        res.append(cat_store.getInitialItems(&inputData, itemsDesired, beginPos));
    }
    if(res.count()>0 && beginPos){ (*beginPos)++; }


    if(inputData.slotCount()>1 ){
        QList<CatItem> extra_actions;
        if(inputData.isCustomVerbChoosableByArgSig())
            { extra_actions = parseCustomVerbSelection(inputData); }

        QList<CatItem> operations = getOperations(inputData);

        if(extra_actions.count() > MAX_SEPERATE_VERBS){
            res.push_front(
                    CatItem::createTempfolder(EXTRA_ACTIONS_PSUEDO_FOLD_NAME, extra_actions));
        } else
            { res.append(extra_actions); }
        res.append(operations);


        //At "bare" verb - possibly w/ operation
        if(inputData.verbPosition() ==0){
            if(inputData.hasVerb() && !inputData.customVerbChosen() && inputData.nounList().length()==0){
                res.push_front(CatItem::createRunPseudoItem());
            }
            res.append(cat_store.getAssociatedDocuments(&inputData, inputData.getFilterItem(), itemsDesired));
        }
        if(inputData.atPossibleVerbSlot()){
            inputData.setDefaultVerbIfNeeded();
            CatItem defVerb = inputData.getItemDefaultVerb();
            if(!defVerb.isEmpty()) { res.append(defVerb); }

            QList<CatItem> associations = inputData.getNormalAssociation();
            CatItem defaultVerb = inputData.getItemDefaultVerb();
            if(!defaultVerb.isEmpty())
                { res.append(defaultVerb); }
            if(associations.count() > MAX_SEPERATE_VERBS){
                res.push_front(
                        CatItem::createTempfolder(ASSOCIATED_APPS_PSUEDO_FOLD_NAME, associations));
            } else
                { res.append(associations); }
        }
    }

    CatItem curArg = inputData.argChosenType();
    if(!curArg.isEmpty())
        { res.append(cat_store.getItemChildren(&inputData, curArg)); }
    qDebug() << res.count() << " items found";

    return res;
}