예제 #1
0
bool DictWidget::lookup(const QString &word)
{
    if (word.isEmpty())
    {
        return false;
    }

    resetSimilarWordsOffset();

    // Clean the word.
    word_ = word.trimmed();

    // Title
    QString result;
    bool ret = dict_.translate(word_, result);

    formatResult(result);

    // Result
    doc_.setHtml(result);

    // Always stop timer as the screen can be updated later.
    launchTimer(false);

    updateVisibleWidgets();
    onDetailsClicked(true);
    return ret;
}
예제 #2
0
파일: connector.cpp 프로젝트: Gingar/port
void Connector::connectorThread( void ) {
	printf( "[Connector (%p)] Connector thread started: mode=%d\n",
		this, _isServer );

	if (_isServer) {
		AcceptorPtr acceptor(new Acceptor(_io, getEndpoint()));
		acceptor->async_accept(*_socket,
		    boost::bind(&Connector::handle_accept, this, acceptor, 
				    boost::asio::placeholders::error));

		    //	Launch timer ....
		    launchTimer( _acceptTimer, _connectTimeout, &Connector::onAcceptExpired );
	} else {
		_socket->async_connect(getEndpoint(),
			boost::bind(&Connector::handle_connect, this,
				boost::asio::placeholders::error));
	}

	try {
		_io.run();
	}
	catch (std::exception& e) {
		printf( "[Connector (%p)] Exception: %s\n", this, e.what() );
	}

	disconnected();
	printf( "[Connector (%p)] Info: Connector Thread Stopped\n", this );
}
예제 #3
0
void Connector::onKeepAliveIntervalExpired( const boost::system::error_code& error ) {
	if (!error) {
		//printf( "[Connector (%p)] Sending keep alive\n", this );

		//	Check keep alive data
		if (_keepAlive >= _maxKeepAliveRetry) {
			timeout();
		}
		else {
			_keepAlive++;
			_keepAliveHandler->send(this);
		}

		//	Re-launch timer
		launchTimer( _keepAliveTimer, _keepAliveInterval, &Connector::onKeepAliveIntervalExpired );
	}
}
예제 #4
0
bool DictWidget::lookup(const QString &word)
{
    if (word.isEmpty() || word_ == word.trimmed())
    {
        return false;
    }

    resetSimilarWordsOffset();

    // Clean the word.
    word_ = word.trimmed();

    //remove quotes (“ ” " ) If it in the words
    if(word_.contains(QChar(0x201C)) || word_.contains(QChar(0x201D)) || word_.contains(QChar(0x0022)))
    {
        word_.remove(QChar(0x201C));
        word_.remove(QChar(0x201D));
        word_.remove(QChar(0x0022));
    }

    // Title
    QString result;
    QString fuzzy_word("");
    bool ret = dict_.fuzzyTranslate(word_, result, fuzzy_word);
    fuzzy_word_ = fuzzy_word;

    formatResult(result, fuzzy_word);

    // Result
    doc_.setHtml(result);

    // Always stop timer as the screen can be updated later.
    launchTimer(false);

    update_parent_ = false;
    updateVisibleWidgets();
    onDetailsClicked(true);
    return ret;
}
예제 #5
0
void Connector::connected( void ) {
	if (!_isConnected) {
		if (!_onConnect.empty()) {
			printf( "[Connector (%p)] Connected\n", this );		
			_onConnect();
		}
		_isConnected = true;

		//	Add Keep Alive handler
		_keepAliveHandler = new KeepAliveHandler();
		_keepAliveHandler->onKeepAliveEvent( boost::bind(&Connector::onKeepAliveEvent, this, _1) );
		addHandler( connector::messages::keepAlive, _keepAliveHandler );

		if (_isServer) {
			printf( "[Connector (%p)] Launching keep alive timer: interval=%d, retry=%d\n",
				this, _keepAliveInterval, _maxKeepAliveRetry );
			
			//	Launch keep alive timer ....
			_keepAlive=0;
			launchTimer( _keepAliveTimer, _keepAliveInterval, &Connector::onKeepAliveIntervalExpired );
		}
	}
}
예제 #6
0
bool DictWidget::lookup(const QString &word, bool update_screen)
{
    if (word.isEmpty() || word_ == word.trimmed())
    {
        return false;
    }

    resetSimilarWordsOffset();

    // Clean the word.
    word_ = word.trimmed();

    // Title
    QString result;
    QString fuzzy_word("");
    bool ret = dict_.fuzzyTranslate(word_, result, fuzzy_word);

    formatResult(result, fuzzy_word);

    // Result
    doc_.setHtml(result);

    // Always stop timer as the screen can be updated later.
    launchTimer(false);

    updateVisibleWidgets();

    changeInternalState(EXPLANATION);
    checkSelectedButton();

    explanation_text_.show();
    explanation_text_.setFocus();
    similar_words_view_.hide();
    s_enable_update = update_screen;
    return ret;
}