Exemplo n.º 1
0
void
v_indexInit(
    v_index index,
    c_type instanceType,
    c_array keyList,
    v_reader reader)
{
    c_property keyProperty;
    c_structure keyStructure;
    c_char fieldName[16];
    c_char *keyExpr;
    c_size i,nrOfKeys,totalSize;

    assert(index != NULL);
    assert(C_TYPECHECK(index,v_index));
    assert(C_TYPECHECK(instanceType,c_type));

    keyProperty = c_property(c_metaResolve(c_metaObject(instanceType),"key"));
    if (keyProperty) {
        keyStructure = c_structure(keyProperty->type);
        nrOfKeys = c_arraySize(keyStructure->members);
        c_free(keyProperty);
    } else {
        nrOfKeys = 0;
    }

    if (nrOfKeys>0) {
        totalSize = nrOfKeys * strlen("key.field0,");
        if (nrOfKeys > 9) {
            /* For each key number greater than one digit
             * i.e. number of keys > 9 add one additional
             * character space to the total size.
             */
            totalSize += (nrOfKeys-9);
            if (nrOfKeys > 99) {
                /* For each key number greater than two digits
                 * i.e. number of keys > 99 add one additional
                 * character space to the total size.
                 */
                totalSize += (nrOfKeys-99);
            }
        }
        keyExpr = (char *)os_alloca(totalSize);
        keyExpr[0] = 0;
        for (i=0;i<nrOfKeys;i++) {
            os_sprintf(fieldName,"key.field%d",i);
            os_strcat(keyExpr,fieldName);
            if (i<(nrOfKeys-1)) { os_strcat(keyExpr,","); }
        }
    } else {
        keyExpr = NULL;
    }

    index->reader = reader;
    index->sourceKeyList = createKeyList(instanceType, keyList);
    index->messageKeyList = c_keep(keyList);    /* keyList is either topic->messageKeyList or a user-defined keylist */
    index->objects = c_tableNew(instanceType,keyExpr);
    index->notEmptyList = c_tableNew(instanceType,keyExpr);

    if(keyExpr){
        os_freea(keyExpr);
    }
    index->objectType = c_keep(instanceType);
}
Exemplo n.º 2
0
bool KAccelBase::updateConnections()
{
#ifdef Q_WS_X11
    kdDebug(125) << "KAccelBase::updateConnections()  this = " << this << endl;
    // Retrieve the list of keys to be connected, sorted by priority.
    //  (key, variation, seq)
    QValueVector< X > rgKeys;
    createKeyList(rgKeys);
    m_rgActionsNonUnique.clear();

    KKeyToActionMap mapKeyToAction;
    for(uint i = 0; i < rgKeys.size(); i++)
    {
        X &x = rgKeys[i];
        KKeyServer::Key &key = x.key;
        ActionInfo info;
        bool bNonUnique = false;

        info.pAction = m_rgActions.actionPtr(x.iAction);
        info.iSeq = x.iSeq;
        info.iVariation = x.iVari;

        // If this is a multi-key shortcut,
        if(info.pAction->shortcut().seq(info.iSeq).count() > 1)
            bNonUnique = true;
        // If this key is requested by more than one action,
        else if(i < rgKeys.size() - 1 && key == rgKeys[i + 1].key)
        {
            // If multiple actions requesting this key
            //  have the same priority as the first one,
            if(info.iVariation == rgKeys[i + 1].iVari && info.iSeq == rgKeys[i + 1].iSeq)
                bNonUnique = true;

            kdDebug(125) << "key conflict = " << key.key().toStringInternal() << " action1 = " << info.pAction->name()
                         << " action2 = " << m_rgActions.actionPtr(rgKeys[i + 1].iAction)->name() << " non-unique = " << bNonUnique << endl;

            // Skip over the other records with this same key.
            while(i < rgKeys.size() - 1 && key == rgKeys[i + 1].key)
                i++;
        }

        if(bNonUnique)
        {
            // Remove connection to single action if there is one
            if(m_mapKeyToAction.contains(key))
            {
                KAccelAction *pAction = m_mapKeyToAction[key].pAction;
                if(pAction)
                {
                    m_mapKeyToAction.remove(key);
                    disconnectKey(*pAction, key);
                    pAction->decConnections();
                    m_rgActionsNonUnique.append(pAction);
                }
            }
            // Indicate that no single action is associated with this key.
            m_rgActionsNonUnique.append(info.pAction);
            info.pAction = 0;
        }

        // kdDebug(125) << "mapKeyToAction[" << key.toStringInternal() << "] = " << info.pAction << endl;
        mapKeyToAction[key] = info;
    }

    // Disconnect keys which no longer have bindings:
    for(KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it)
    {
        const KKeyServer::Key &key = it.key();
        KAccelAction *pAction = (*it).pAction;
        // If this key is longer used or it points to a different action now,
        if(!mapKeyToAction.contains(key) || mapKeyToAction[key].pAction != pAction)
        {
            if(pAction)
            {
                disconnectKey(*pAction, key);
                pAction->decConnections();
            }
            else
                disconnectKey(key);
        }
    }

    // Connect any unconnected keys:
    // In other words, connect any keys which are present in the
    //  new action map, but which are _not_ present in the old one.
    for(KKeyToActionMap::iterator it = mapKeyToAction.begin(); it != mapKeyToAction.end(); ++it)
    {
        const KKeyServer::Key &key = it.key();
        KAccelAction *pAction = (*it).pAction;
        if(!m_mapKeyToAction.contains(key) || m_mapKeyToAction[key].pAction != pAction)
        {
            // TODO: Decide what to do if connect fails.
            //  Probably should remove this item from map.
            if(pAction)
            {
                if(connectKey(*pAction, key))
                    pAction->incConnections();
            }
            else
                connectKey(key);
        }
    }

    // Store new map.
    m_mapKeyToAction = mapKeyToAction;

#ifndef NDEBUG
    for(KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it)
    {
        kdDebug(125) << "Key: " << it.key().key().toStringInternal() << " => '" << (((*it).pAction) ? (*it).pAction->name() : QString::null) << "'"
                     << endl;
    }
#endif
#endif // Q_WS_X11
    return true;
}