From: Kurt Pattyn Date: Mon, 26 Aug 2013 10:58:04 +0000 (+0200) Subject: Add tr() to translatable strings X-Git-Tag: v5.3.0-alpha1~256 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0faf88538248f0164301723b7d50447fe80f030b;p=contrib%2Fqtwebsockets.git Add tr() to translatable strings --- diff --git a/src/dataprocessor_p.cpp b/src/dataprocessor_p.cpp index ef32ff5..3d94b45 100644 --- a/src/dataprocessor_p.cpp +++ b/src/dataprocessor_p.cpp @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "dataprocessor_p.h" #include "qwebsocketprotocol.h" +#include "qwebsocket.h" #include #include #include @@ -302,7 +303,7 @@ Frame Frame::readFrame(QTcpSocket *pSocket) bool ok = pSocket->waitForReadyRead(5000); if (!ok) { - frame.setError(QWebSocketProtocol::CC_GOING_AWAY, "Timeout when reading data from socket."); + frame.setError(QWebSocketProtocol::CC_GOING_AWAY, QWebSocket::tr("Timeout when reading data from socket.")); isDone = true; } else @@ -419,7 +420,7 @@ Frame Frame::readFrame(QTcpSocket *pSocket) } else if (payloadLength > MAX_FRAME_SIZE_IN_BYTES) { - frame.setError(QWebSocketProtocol::CC_TOO_MUCH_DATA, "Maximum framesize exceeded."); + frame.setError(QWebSocketProtocol::CC_TOO_MUCH_DATA, QWebSocket::tr("Maximum framesize exceeded.")); processingState = PS_DISPATCH_RESULT; } else @@ -483,21 +484,21 @@ bool Frame::checkValidity() { if (m_rsv1 || m_rsv2 || m_rsv3) { - setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Rsv field is non-zero"); + setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Rsv field is non-zero")); } else if (QWebSocketProtocol::isOpCodeReserved(m_opCode)) { - setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Used reserved opcode"); + setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Used reserved opcode")); } else if (isControlFrame()) { if (m_length > 125) { - setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Controle frame is larger than 125 bytes"); + setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Controle frame is larger than 125 bytes")); } else if (!m_isFinalFrame) { - setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Controle frames cannot be fragmented"); + setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Controle frames cannot be fragmented")); } else { @@ -568,13 +569,13 @@ void DataProcessor::process(QTcpSocket *pSocket) if (!m_isFragmented && frame.isContinuationFrame()) { clear(); - Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Received Continuation frame /*with FIN=true*/, while there is nothing to continue."); + Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Received Continuation frame /*with FIN=true*/, while there is nothing to continue.")); return; } if (m_isFragmented && frame.isDataFrame() && !frame.isContinuationFrame()) { clear(); - Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, "All data frames after the initial data frame must have opcode 0 (continuation)."); + Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("All data frames after the initial data frame must have opcode 0 (continuation).")); return; } if (!frame.isContinuationFrame()) @@ -586,7 +587,7 @@ void DataProcessor::process(QTcpSocket *pSocket) if ((messageLength + quint64(frame.getPayload().length())) > MAX_MESSAGE_SIZE_IN_BYTES) { clear(); - Q_EMIT errorEncountered(QWebSocketProtocol::CC_TOO_MUCH_DATA, "Received message is too big."); + Q_EMIT errorEncountered(QWebSocketProtocol::CC_TOO_MUCH_DATA, QWebSocket::tr("Received message is too big.")); return; } @@ -597,7 +598,7 @@ void DataProcessor::process(QTcpSocket *pSocket) if (failed) { clear(); - Q_EMIT errorEncountered(QWebSocketProtocol::CC_WRONG_DATATYPE, "Invalid UTF-8 code encountered."); + Q_EMIT errorEncountered(QWebSocketProtocol::CC_WRONG_DATATYPE, QWebSocket::tr("Invalid UTF-8 code encountered.")); return; } else diff --git a/src/qwebsocket_p.cpp b/src/qwebsocket_p.cpp index c2786d0..1498b8b 100644 --- a/src/qwebsocket_p.cpp +++ b/src/qwebsocket_p.cpp @@ -101,7 +101,7 @@ QWebSocketPrivate::~QWebSocketPrivate() { if (state() == QAbstractSocket::ConnectedState) { - close(QWebSocketProtocol::CC_GOING_AWAY, "Connection closed"); + close(QWebSocketProtocol::CC_GOING_AWAY, QWebSocket::tr("Connection closed")); } releaseConnections(m_pSocket); m_pSocket->deleteLater(); @@ -546,7 +546,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary) } else { - setErrorString("WebSocket::doWriteFrames: Error writing bytes to socket: " + m_pSocket->errorString()); + setErrorString(QWebSocket::tr("Error writing bytes to socket: %1.").arg(m_pSocket->errorString())); qDebug() << errorString(); m_pSocket->flush(); Q_EMIT q_ptr->error(QAbstractSocket::NetworkError); @@ -558,7 +558,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary) } if (payloadWritten != data.size()) { - setErrorString("Bytes written " + QString::number(payloadWritten) + " != " + QString::number(data.size())); + setErrorString(QWebSocket::tr("Bytes written %1 != %2.").arg(payloadWritten).arg(data.size())); qDebug() << errorString(); Q_EMIT q_ptr->error(QAbstractSocket::NetworkError); } @@ -686,7 +686,7 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket) } if (!ok) { - errorDescription = "WebSocket::processHandshake: Invalid statusline in response: " + statusLine; + errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(statusLine); } else { @@ -722,12 +722,12 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket) ok = (accept == acceptKey); if (!ok) { - errorDescription = "WebSocket::processHandshake: Accept-Key received from server " + acceptKey + " does not match the client key " + accept; + errorDescription = QWebSocket::tr("Accept-Key received from server %1 does not match the client key %2.").arg(acceptKey).arg(accept); } } else { - errorDescription = "WebSocket::processHandshake: Invalid statusline in response: " + statusLine; + errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(statusLine); } } else if (httpStatusCode == 400) //HTTP/1.1 400 Bad Request @@ -739,20 +739,20 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket) { //if needed to switch protocol version, then we are finished here //because we cannot handle other protocols than the RFC one (v13) - errorDescription = "WebSocket::processHandshake: Server requests a version that we don't support: " + versions.join(", "); + errorDescription = QWebSocket::tr("Handshake: Server requests a version that we don't support: %1.").arg(versions.join(", ")); ok = false; } else { //we tried v13, but something different went wrong - errorDescription = "WebSocket::processHandshake: Unknown error condition encountered. Aborting connection."; + errorDescription = QWebSocket::tr("Unknown error condition encountered. Aborting connection."); ok = false; } } } else { - errorDescription = "WebSocket::processHandshake: Unhandled http status code " + QString::number(httpStatusCode); + errorDescription = QWebSocket::tr("Unhandled http status code: %1.").arg(httpStatusCode); ok = false; } @@ -889,7 +889,7 @@ void QWebSocketPrivate::processControlFrame(QWebSocketProtocol::OpCode opCode, Q if (!QWebSocketProtocol::isCloseCodeValid(closeCode)) { closeCode = QWebSocketProtocol::CC_PROTOCOL_ERROR; - closeReason = QString("Invalid close code %1 detected").arg(closeCode); + closeReason = QWebSocket::tr("Invalid close code %1 detected.").arg(closeCode); } else { @@ -902,7 +902,7 @@ void QWebSocketPrivate::processControlFrame(QWebSocketProtocol::OpCode opCode, Q if (failed) { closeCode = QWebSocketProtocol::CC_WRONG_DATATYPE; - closeReason = "Invalid UTF-8 code encountered."; + closeReason = QWebSocket::tr("Invalid UTF-8 code encountered."); } } } diff --git a/src/qwebsocketserver_p.cpp b/src/qwebsocketserver_p.cpp index d5e3dcb..2c185b9 100644 --- a/src/qwebsocketserver_p.cpp +++ b/src/qwebsocketserver_p.cpp @@ -54,7 +54,7 @@ QWebSocketServerPrivate::~QWebSocketServerPrivate() while (!m_pendingConnections.isEmpty()) { QWebSocket *pWebSocket = m_pendingConnections.dequeue(); - pWebSocket->close(QWebSocketProtocol::CC_GOING_AWAY, "Server closed."); + pWebSocket->close(QWebSocketProtocol::CC_GOING_AWAY, QWebSocketServer::tr("Server closed.")); pWebSocket->deleteLater(); } m_pTcpServer->deleteLater(); @@ -310,27 +310,31 @@ void QWebSocketServerPrivate::handshakeReceived() } else { - qDebug() << "QWebSocketServerPrivate::handshakeReceived: Upgrading to WebSocket failed."; + //TODO: should set or emit error + qDebug() << QWebSocketServer::tr("Upgrading to websocket failed."); } } else { - qDebug() << "QWebSocketServerPrivate::handshakeReceived: Cannot upgrade to websocket."; + //TODO: should set or emit error + qDebug() << QWebSocketServer::tr("Cannot upgrade to websocket."); } } else { - qDebug() << "QWebSocketServerPrivate::handshakeReceived: Invalid response. This should not happen!!!"; + //TODO: should set or emit error + qDebug() << QWebSocketServer::tr("Invalid response received."); } if (!success) { - qDebug() << "QWebSocketServerPrivate::handshakeReceived: Closing socket because of invalid or unsupported request"; + //TODO: should set or emit error + qDebug() << QWebSocketServer::tr("Closing socket because of invalid or unsupported request."); pTcpSocket->close(); } } else { - qDebug() << "WebSocketServerPrivate::handshakeReceived: Sender socket is NULL. This should not happen!!!"; + qWarning() << "Sender socket is NULL. This should not happen, otherwise it is a Qt bug!!!"; } }