Exemplo n.º 1
0
QList<CatItem> Catalog::getOperationChildren(InputList & inputData){
    CatItem target = inputData.getStatementObject();
    CatBuilder::updateItem(target,2,UserEvent::SELECTED);
    CatItem tag =inputData.getOperationTarget();
    if(tag.getchildTypeToTake()!=(BaseChildRelation::ChildRelType)0){
        return target.getTypeParents(tag.getchildTypeToTake());
    } else {
        return cat_store.getItemsByKey(inputData.getUserKeys(), &inputData, 30);
    }
}
Exemplo n.º 2
0
QList<CatItem> Catalog::extractStubs(CatItem& it){
    QList<CatItem> res;
    QList<CatItem> items = it.getParents();
    it.setChildStubbed(false);
    items.append(it.getChildren());
    for(int i=0; i<items.count();i++){
        if(items[i].isStub()){
            res.append(items[i]);
        }
    }
    return res;
}
Exemplo n.º 3
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.º 4
0
void TrieNode::addItemPiece(CatItem it, Tuple tpl, QString pieceName, int position, bool is_description){
    int charChanges = MIN((log(it.getFullWeight())-1), KEY_SKIP_SWITCH_LIMIT-1);
    ItemRep ir(it, tpl, charChanges, position, is_description);
    ir.setName(pieceName);
    insertRep(ir);

}
Exemplo n.º 5
0
bool PreviewPane::setItem(CatItem it, bool justTesting) {
    m_item = it;
    m_loadType = UNKNOWN_HTML;
    if(!justTesting){
        settings()->setFontSize(QWebSettings::MinimumFontSize,18);
        settings()->setFontSize(QWebSettings::MinimumLogicalFontSize,18);
        settings()->setFontSize(QWebSettings::DefaultFontSize,18);
        settings()->setFontSize(QWebSettings::DefaultFixedFontSize,18);
    //    QString styleSheetPath = (USER_APP_DIR + BROWSER_OPTION_DIR + BROWSER_STYLE_SHEET);
        QString styleSheetPath = m_item.getPreviewCSSPath();
        settings()->setUserStyleSheetUrl(QUrl(styleSheetPath));
    }
    if(justTesting ){
        if((int)it.getTagLevel() >=(int)CatItem::KEY_WORD){
            return false;
        }
        if(it.getItemType() == CatItem::LOCAL_DATA_FOLDER){
            return false;
        }
        QFileInfo f(it.getPath());
        if(f.isDir()){
            return false;
        }
    }


    if(!justTesting){
        setVisible(false);
    }
    if(it.hasLabel(PREVIEW_URL_KEY)){
        if(!justTesting){
            QUrl url(it.getCustomString(PREVIEW_URL_KEY));
            qDebug() << "setting url:" << url.toString();
            setUrl(url);
            load(url);
            loadingStart();
        }
        return true;
    } else if(it.hasLabel(FIREFOX_PLUGIN_NAME)
        && !it.hasLabel(STREAM_SOURCE_PATH)){
        if(!justTesting){
            setHtml (HTTP_CONTENT_LOADING_MSG);
            QUrl url = it.previewUrl();


            qDebug() << "setting url:" << url.toString();
            //startGettingUrlHtml(url);
            setUrl(url);
            load(url);
            loadingStart();
            //setReaderScript(true);
            connect(this, SIGNAL(loadProgress(int)),this, SLOT(progressLoading(int)));
        }
        return true;
    } else if(it.getMimeType() == DEFAULT_HTML_MIME_TYPE &&
Exemplo n.º 6
0
void MyListWidget::setCurrentItem(CatItem catItem){
    for(int i=0; i< count();i++){
        QListWidgetItem* listWidgetItem = item(i);
        if((listWidgetItem->data((ROLE_ITEM_PATH)).toString() == catItem.getPath())){
            setCurrentRow(i);
            break;
        }
    }
}
Exemplo n.º 7
0
QList<CatItem> Catalog::getOperations(InputList & inputData){
    QList<CatItem> res;
    CatItem target = inputData.getStatementObject();
    CatBuilder::updateItem(target,2,UserEvent::SELECTED);
    QList<CatItem> tags = (target.getTypeParents(BaseChildRelation::TAG_PARENT));
    if(tags.count()>0){
        CatItem removeTagItem(OP_REMOVE_PATH,REMOVE_TAG_NAME);
        removeTagItem.setItemType(CatItem::OPERATION);
        removeTagItem.setOrganizingType(CatItem::TAG);
        removeTagItem.setTakesAnykeys(true);
        removeTagItem.setMatchType(CatItem::EXTERNAL_INFO);
        removeTagItem.setIcon(TAG_ICON_NAME);
        removeTagItem.setUseLongName(true);
        removeTagItem.setChildTypeToTake(BaseChildRelation::TAG_PARENT);
        removeTagItem.setIsTempItem(true);
        res.append(removeTagItem);
    }
    res.append(cat_store.getOperations(&inputData, 30));
    return res;
}
Exemplo n.º 8
0
void testpluginPlugin::extendCatalog(SearchInfo* , QList<CatItem>* r)
{
    r=r;
#ifdef TEST_GUI
    qDebug() << "testpluginPlugin::extendCatalog";
    QList <CatItem> in_list = *(info->itemListPtr);
    QString extend_suffix = "/extended/";
    CatItem me(itemPath);

    for(int i=0;i< in_list.count();i++){
        if(in_list[i].getPath().right(extend_suffix.length()) !=extend_suffix){
            CatItem e = in_list[i];
            CatItem f(e.getPath() + extend_suffix, e.getName() + extend_suffix);
            f.setExternalWeight(0,me);
            r->append(f);
        }
    }
#endif

}
Exemplo n.º 9
0
void TrieNode::insertFull(CatItem it, QList<int> kl,
                           int charChanges,Tuple tpl  )
{
    if(!it.hasRealName()){ return;}

    if(tpl.isEmpty())
        {tpl = mp_container->getInternalId(it); }

    ItemRep ir(it, tpl, charChanges);
    if(kl.length() > 0)
        {ir.setMatchKeyList(kl);}
    insertRep(ir);

    if(it.getName().contains(" ")){
        QList<QString> descriptionWords = it.getDescription().split(' ');
        for(int i=0; i<MIN(descriptionWords.length(),MAX_WORDS_IN_KEY_SEARCH); i++){
            if(!descriptionWords[i].isEmpty() && descriptionWords[i].count()>5){
                addItemPiece(it,tpl,descriptionWords[i],i, false);
            }
        }
    }
}
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
0
void CatBuilder::setShown(CatItem it, UserEvent etv) {
    it.setBestMatchType(it.getMatchType());
    cat->setShown(it, etv);
}
Exemplo n.º 14
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.º 15
0
bool WeightLess (CatItem & a, CatItem & b) {
    return (a.getFullWeight() > b.getFullWeight());
}
Exemplo n.º 16
0
void CatBuilder::catalogTask() {
    qDebug() << "CatBuilder task starting: " << (int)this;
    mp_userItems = new QList<CatItem>;
    mp_extension_results = new QList<CatItem>;
    mp_timelyItems = new QList<CatItem>;
    gMainWidget->fillBuilderInfo(this);

    Q_ASSERT(cat);
    Q_ASSERT(plugins_ptr);
    QList<CatItem> insertList;
    //bool success=false;
    SearchInfo inf;
    inf.m_extensionType = m_extensionType;
    switch (m_extensionType) {
//        case LOAD:
//            success = plugins_ptr->loadCatalogs(&(insertList));
//            if(!success) {
//                plugins_ptr->getCatalogs(&(insertList));
//            }
//            break;
    case UserEvent::CATALOGUE_LOAD:
        plugins_ptr->getCatalogs(&(insertList));
        break;
    case UserEvent::CATALOGUE_EXTEND:
        doExtension(&insertList);
        break;
    case UserEvent::BACKGROUND_SEARCH:
    default:
    {
        inf.m_userKeys = this->m_userKeys;
        inf.m_keyWords = this->m_keywords;
        inf.itemListPtr = (mp_userItems);
        plugins_ptr->backgroundSearch(&inf, &(insertList));
    }
    break;

    }
    QList<CatItem> mergedItems = cat->indexItemList(&insertList);
    mp_extension_results->clear();
    for(int i=0; i<mergedItems.count(); i++) {
        CatItem it = mergedItems[i];
        if(it.getIsTimeDependant())
        {
            mp_timelyItems->append(mergedItems[i]);
        }
        if(it.getMatchType() == CatItem::USER_KEYWORD) {
            setShown(it, UserEvent::KEYS_TYPE);
            continue;
        }
        mp_extension_results->append(it);

        //plugins_ptr->itemLoading(&it,UserEvent::JUST_FOUND);
    }
    QList<CatItem> res;
    inf.itemListPtr = &mergedItems;
    qDebug() << "give plugins another go at found items";
    plugins_ptr->itemsLoading(&inf,&res);
    res = cat->indexItemList(&res);
    mergedItems.append(res);
    mp_extension_results->clear();
    for(int i=0; i<mergedItems.count(); i++) {
        mp_extension_results->append(mergedItems[i]);
    }

    if(UserEvent::BACKGROUND_SEARCH == m_extensionType) {
        //emit backgroundSearchDone(this,m_userKeys);
        gMainWidget->backgroundSearchDone(this,m_userKeys);

        qDebug() << "search done for: " << (int)this;
    } else if( UserEvent::STANDARD_UPDATE== m_extensionType ||
               UserEvent::CATALOGUE_EXTEND== m_extensionType ||
               UserEvent::CATALOGUE_LOAD== m_extensionType ||
               UserEvent::CATALOGUE_SAVE== m_extensionType ) {
        //emit catalogFinished(this);
        gMainWidget->catalogBuilt(this);
        qDebug() << "catabuilt for: " << (int)this;
    }
    qDebug() << "run done for: " << (int)this;
    emit finished();

}
Exemplo n.º 17
0
QString summarizeMessage(CatItem it){
    QString res;

    if(it.hasLabel(NAME_IS_TITLE_KEY_STR)){
        res+= it.getName() + " ";
    }

    if(it.hasLabel(AUTHOR_KEY_STR)){
        res+= QString("<br>") + FROM_PERSON__PHRASE + it.getAuthor();
    }

    if(!it.getDescription().isEmpty()){
        res+=it.getDescription();
    } else if(!it.getLongText().isEmpty()){
        res+=it.getLongText().left(UI_MAX_MESSAGE_DESCRIPTION_LEN);
    }

    if(it.hasLabel(TIME_EXPLICITELY_SET_KEY_STR)){
        res+="(";
        time_t tm = (MAX(it.getCreationTime(), it.getModificationTime()));
        QDateTime t;
        t.fromTime_t(tm);
        res+= contextualTimeString(t);
        res+=")";
    }

    return res;
}
Exemplo n.º 18
0
bool TrieNode::breadthSearch(QHash<qint32,CatItem>& alreadyFound, QString matchString,
                    int desired, int depth, int digDepth, int skipDepth, ItemFilter* filter){


    bool worthLookingFurther = (digDepth >0);
    if(skipDepth<=0){
        worthLookingFurther = true;

        QLinkedList<ItemRep>::iterator i = m_bestItems.begin();
        for(;i != m_bestItems.end();i++){

            //This step optimizes - skip what you know is wrong before paying for a full check
            QList<int> outIndex;
            CatItem it_approx((*i).getName(),(*i).getName());
            if(!matchString.isEmpty() && !userkey_match(it_approx,matchString, &outIndex))
                { continue; }

            CatItem::ItemType mt = (*i).getItemType();
            if(!CatItem::matchOrganizingTypes(filter->getOrganizeingType(),mt))
                {continue;}

            //Now the "real" matching
            CatItem it = mp_container->getByInternalIdProtectMe((*i).getInternalId());
            outIndex.clear();

            //We want to allow names that are parts of the main name...
            if(!matchString.isEmpty() && !userkey_match(it,matchString, &outIndex)){
                if(matchString.length() < MIN_SUBSTR_MATCH_LEN)
                    { continue; }
                if(!it.getName().contains(matchString))
                    { continue; }
            }

            if (!filter || filter->acceptItem(&(it) )){
                worthLookingFurther =true;
                if(outIndex.length() > 0){
                    it.setMatchIndex(outIndex);
                }
                //it.setMatchIndex((*i).getMatchIndex());
                alreadyFound[it.getItemId()] = it;
            }
            if(alreadyFound.count() > desired){ return false; }
        }
    }


    if(depth<=0){ return true; }

    if(worthLookingFurther || matchString.length() <=BROAD_KEYSEARCH_MAXLEN ||
       (skipDepth) > 0) {
        for(int i=0;i < m_entries.count();i++){
            if(!m_entries[i]){continue;}
            m_entries[i]->breadthSearch(alreadyFound, matchString, desired, depth-1,
                                      digDepth-1,
                                      skipDepth-1, filter);
            if(alreadyFound.count() > desired){ return false; }
        }
    }

    return worthLookingFurther;
}
Exemplo n.º 19
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;
}