bool DictEngine::sourceRequestEvent(const QString &query) { // FIXME: this is COMPLETELY broken .. it can only look up one query at a time! // a DataContainer subclass that does the look up should probably be made if (m_currentQuery == query) { return false; } if (m_tcpSocket) { m_tcpSocket->abort(); //stop if lookup is in progress and new query is requested m_tcpSocket->deleteLater(); m_tcpSocket = 0; } QStringList queryParts = query.split(':', QString::SkipEmptyParts); if (queryParts.isEmpty()) { return false; } m_currentWord = queryParts.last(); m_currentQuery = query; //asked for a dictionary? if (queryParts.count() > 1) { setDict(queryParts[queryParts.count()-2]); //default to wordnet } else { setDict(QStringLiteral("wn")); } //asked for a server? if (queryParts.count() > 2) { setServer(queryParts[queryParts.count()-3]); //default to wordnet } else { setServer(QStringLiteral("dict.org")); } if (m_currentWord.simplified().isEmpty()) { setData(m_currentWord, m_dictName, QString()); } else { setData(m_currentWord, m_dictName, QString()); m_tcpSocket = new QTcpSocket(this); m_tcpSocket->abort(); connect(m_tcpSocket, &QTcpSocket::disconnected, this, &DictEngine::socketClosed); if (m_currentWord == QLatin1String("list-dictionaries")) { connect(m_tcpSocket, &QTcpSocket::readyRead, this, &DictEngine::getDicts); } else { connect(m_tcpSocket, &QTcpSocket::readyRead, this, &DictEngine::getDefinition); } m_tcpSocket->connectToHost(m_serverName, 2628); } return true; }
void DingWidget::loadDict( QString name ) { lines.clear(); //as we will load a new list we have to //remove the old one Config cfg( "odict" ); cfg.setGroup( "Method_" + name ); QFile file( cfg.readEntry( "file" ) ); if( file.open( IO_ReadOnly ) ) { QTextStream stream( &file ); stream.setEncoding(QTextStream::UnicodeUTF8); while ( !stream.eof() ) { lines.append( stream.readLine() ); } file.close(); } setDict( name ); loadValues(); }
Item::e_sercode Item::deserialize( Stream *file, VMachine *vm ) { byte type = FLC_ITEM_NIL; if ( file->read((byte *) &type, 1 ) == 0 ) return sc_eof; if( ! file->good() ) return sc_ferror; switch( type ) { case FLC_ITEM_NIL: setNil(); return sc_ok; case FLC_ITEM_UNB: setUnbound(); return sc_ok; case FLC_ITEM_BOOL: { byte bval; file->read( (byte *) &bval, sizeof( bval ) ); if ( file->good() ) { setBoolean( bval != 0 ); return sc_ok; } return sc_ferror; } return sc_ok; case FLC_ITEM_INT: { int64 val; file->read( (byte *) &val, sizeof( val ) ); if ( file->good() ) { setInteger(endianInt64(val) ); return sc_ok; } return sc_ferror; } break; case FLC_ITEM_RANGE: { int64 val1; int64 val2; int64 val3; //byte isOpen; file->read( (byte *) &val1, sizeof( val1 ) ); file->read( (byte *) &val2, sizeof( val2 ) ); file->read( (byte *) &val3, sizeof( val3 ) ); //file->read( (byte *) &isOpen, sizeof( isOpen ) ); val1 = endianInt64( val1 ); val2 = endianInt64( val2 ); val3 = endianInt64( val3 ); if ( file->good() ) { setRange( new CoreRange( val1, val2, val3 ) ); return sc_ok; } return sc_ferror; } break; case FLC_ITEM_NUM: { numeric val; file->read( (byte *) &val, sizeof( val ) ); if ( file->good() ) { setNumeric( endianNum( val ) ); return sc_ok; } return sc_ferror; } break; case FLC_ITEM_LBIND: { int32 id; file->read( (byte*) &id, sizeof(id) ); String name; if ( ! name.deserialize( file ) ) return file->bad() ? sc_ferror : sc_invformat; setLBind( new CoreString( name ) ); } break; case FLC_ITEM_STRING: { CoreString *cs = new CoreString; setString( cs ); if ( ! cs->deserialize( file ) ) { return file->bad() ? sc_ferror : sc_invformat; } if ( file->good() ) { return sc_ok; } return sc_ferror; } break; case FLC_ITEM_MEMBUF |0x80: { // get the function pointer in the stream /*MemBuf *(*deserializer)( VMachine *, Stream * ); file->read( &deserializer, sizeof( deserializer ) ); if ( ! file->good() ) { return sc_ferror; } MemBuf *mb = deserializer( vm, file ); if( mb == 0 ) { return sc_invformat; }*/ MemBuf* mb; if( file->read( &mb, sizeof( mb ) ) == sizeof(mb) ) { setMemBuf( mb ); return sc_ok; } return sc_eof; } case FLC_ITEM_MEMBUF: { MemBuf *mb = MemBuf::deserialize( vm, file ); if ( file->good() && mb != 0 ) { setMemBuf( mb ); return sc_ok; } return sc_ferror; } break; case FLC_ITEM_ARRAY: { int32 val; file->read( (byte *) &val, sizeof( val ) ); e_sercode retval = sc_ok; if ( file->good() ) { val = endianInt32(val); CoreArray *array = new CoreArray(); array->resize(val); for( int i = 0; i < val; i ++ ) { retval = array->items()[i].deserialize( file, vm ); if( retval != sc_ok ) { break; } } if ( retval == sc_ok ) { setArray( array ); return sc_ok; } return retval; } } break; case FLC_ITEM_DICT: { byte blessed; file->read( &blessed, 1 ); int32 val; file->read( (byte *) &val, sizeof( val ) ); if ( file->good() ) { val = endianInt32(val); LinearDict *dict = new LinearDict( val ); LinearDictEntry *elems = dict->entries(); e_sercode retval = sc_ok; for( int i = 0; i < val; i ++ ) { LinearDictEntry *entry = elems + i; retval = entry->key().deserialize( file, vm ); if( retval == sc_ok ) retval = entry->value().deserialize( file, vm ); if ( retval != sc_ok ) break; dict->length( i + 1 ); } if( retval == sc_ok ) { CoreDict* cdict = new CoreDict( dict ); cdict->bless( blessed ? true : false ); setDict( cdict ); return sc_ok; } else delete dict; return retval; } } break; case FLC_ITEM_FUNC | 0x80: case FLC_ITEM_FUNC: { if( vm == 0 ) return sc_missvm; return deserialize_function( file, vm ); } break; case FLC_ITEM_METHOD: { if( vm == 0 ) return sc_missvm; Item obj; Item func; e_sercode sc; sc = obj.deserialize( file, vm ); if ( sc != sc_ok ) return sc; sc = func.deserialize( file, vm ); if ( sc != sc_ok ) return sc; if ( func.isFunction() ) setMethod( obj, func.asMethodFunc() ); else if ( func.isArray() && func.isCallable() ) { setMethod( obj, func.asArray() ); } else return sc_invformat; return sc_ok; } case FLC_ITEM_OBJECT | 0x80: case FLC_ITEM_OBJECT: { bool bLive = type != FLC_ITEM_OBJECT; if( vm == 0 ) return sc_missvm; // read the module name Symbol *sym; LiveModule *lmod; e_sercode sc = deserialize_symbol( file, vm, &sym, &lmod ); if ( sc != sc_ok ) return sc; Item *clitem = &lmod->globals()[ sym->itemId() ]; // Create the core object, but don't fill attribs. CoreObject *object = clitem->dereference()->asClass()->createInstance(0, true); if ( ! object->deserialize( file, bLive ) ) { return sc_missclass; } setObject( object ); return file->good() ? sc_ok : sc_ferror; } break; case FLC_ITEM_CLASS: return deserialize_class( file, vm ); case FLC_ITEM_CLSMETHOD: { e_sercode sc = deserialize_class( file, vm ); if ( sc != sc_ok ) return sc; return deserialize_function( file, vm ); } break; default: return sc_invformat; } return sc_ferror; }