Пример #1
0
//TODO: add support of URL
void Translator::translateHtml(QString filePath, QDir &docDir)
{
    QFileInfo fileInfo(filePath);
    auto cmd = new QProcess(this);

    QTemporaryFile tmpDoc("document.html");
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));
    QStringList args;
    qApp->processEvents();
    //deshtml
#ifdef Q_OS_WIN
    //windows bug with backslash
    //use replace to fix windows bug
    args << "/u" << "/c" << "type" << "\"" + filePath.replace('/', QDir::separator()) + "\""
         << "|" << "apertium-deshtml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!tmpDoc.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpDoc.setTextModeEnabled(true);
    tmpDoc.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    tmpDoc.close();
    //rehtml
    //FIXME: rehtml or rehtml-noent???
    args.clear();
#ifdef Q_OS_WIN
    args << "/u" << "/c" << "type" << "\"" + tmpDoc.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-rehtml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    QFile newDoc(trFilePath);
    if (!newDoc.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    newDoc.write(cmd->readAllStandardOutput());
    newDoc.close();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
    //#else
    //    // cmd->start("ar", QStringList() << "x" << "data.tmp");
    //#endif
}
Пример #2
0
bool CTcpClient::sqlBindValue(const QString &placeholder, const QVariant &val){
    sendMessage("<"+TCP_SQL_BIND+">"+placeholder+"</"+TCP_SQL_BIND+"><"+TCP_SQL_BINDVALUE+">"+val.toString()+"</"+TCP_SQL_BINDVALUE+">");
    waitForBytesWritten();
    waitForReadyRead();

    return m_retourSql;
}
Пример #3
0
QStringList CTcpClient::connectedPostes()
{
    sendMessage("", TCP_GET_POSTES_CO);
    waitForBytesWritten();
    waitForReadyRead();
    return m_lstPostesCo;
}
Пример #4
0
bool Connection::connectToPeer(QString address, int port) {
    qDebug() << "connect to " << address << ":" << port;
    twofish_key = Twofish::generateKey();

    this->connectToHost(address, port);
    if (!waitForConnected(PING_TIMEOUT)) {
        qDebug() << "failed to connect";
        return false;
    }
    this->blockSignals(true);
    QDataStream friend_stream(this);

    QString request = "REQUEST_CONNECT";
    friend_stream << request;
    friend_stream << name;
    friend_stream << ownPublicKey;

    QString s = Rsa::crypt(twofish_key, friendRsaKey).get_str(16).c_str();
    friend_stream << s;

    waitForReadyRead(PING_TIMEOUT);
    QString answer;
    friend_stream >> answer;
    this->blockSignals(false);
    if (answer == "REQUEST_CONNECT_OK") {
        twofish = new Twofish(twofish_key, 128);
        qDebug() << "connected";
        return true;
    } else {
        qDebug() << "connection failed";
    }
    return false;
}
Пример #5
0
bool  QLocalSocket_QtDShell::__override_waitForReadyRead(int  msecs0, bool static_call)
{
    if (static_call) {
        return QLocalSocket::waitForReadyRead((int )msecs0);
    } else {
        return waitForReadyRead((int )msecs0);
    }
}
Пример #6
0
bool  QTemporaryFile_QtDShell::__override_waitForReadyRead(int  msecs0, bool static_call)
{
    if (static_call) {
        return QIODevice::waitForReadyRead((int )msecs0);
    } else {
        return waitForReadyRead((int )msecs0);
    }
}
bool ServerSocket::waitNextMessage(int timeout)
{
    if (this->bytesAvailable())
        return true;
    if (waitForReadyRead(timeout))
        return true;
    return false;
}
Пример #8
0
/*!
 * \brief Translating txt files not on Linux.
 *
 * \warning There are some problems with translating of documents
 * on Windows platform. All document translation functions should be rewrited.
 */
void Translator::translateTxt(QString filePath, QDir &docDir)
{
    QFile f(filePath);
    QFileInfo fileInfo(filePath);
    QTemporaryFile tmpDoc(fileInfo.baseName());
    auto cmd = new QProcess(this);
#ifdef Q_OS_WIN
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));
#endif
    qApp->processEvents();
    //destxt
    cmd->start("cmd.exe", QStringList() << "/u" << "/c" << "type" << "\"" + filePath.replace('/',
                                                                                             QDir::separator()) + "\""
               << "|" << "apertium-destxt");
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!tmpDoc.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpDoc.setTextModeEnabled(true);
    tmpDoc.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    //retxt
    cmd->start("cmd.exe", QStringList() << "/u" << "/c" << "type" << "\"" +
               tmpDoc.fileName().replace('/', QDir::separator())
               + "\"" << "|" << "apertium-retxt");
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    QFile newDoc(trFilePath);
    if (!newDoc.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    newDoc.write(cmd->readAllStandardOutput());
    newDoc.close();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
}
Пример #9
0
qint64 QSerial::readData(char *data, qint64 maxlen)
{
	if ( !buffer.isEmpty() ) {
		int i;
		for( i=0;!buffer.isEmpty() && i<maxlen;i++ )
			data[i] = buffer.dequeue();
		return i;
	}
#ifdef WIN32
	int retVal=0;
	COMSTAT Win_ComStat;
	DWORD Win_BytesRead=0;
	DWORD Win_ErrorMask=0;
	ClearCommError(fh, &Win_ErrorMask, &Win_ComStat);
	if (Win_ComStat.cbInQue &&
		(!ReadFile(fh, (void*)data, (DWORD)maxlen, &Win_BytesRead, NULL)
		 || Win_BytesRead==0)) {
		printf( "Error while reading\n" );
		return -1;
	} else
		retVal = ((int)Win_BytesRead);
	return retVal;
#else
	char buf[BUFSIZ];
	ssize_t len = 0;
	if ( waitForReadyRead(0) )
		len = ::read( io_port, buf, BUFSIZ );
#ifdef DEBUG_SERIAL
	QByteArray ba = "<-("+QByteArray::number( (uint)len )+") ";
	for( int j=0;j<len;j++ )
		ba += "0x"+QByteArray::number( (unsigned char )buf[j], 16 )+" ";
	ba += "\n";
	logFile->write( ba );
	logFile->flush();
#endif
	if ( len < 1 ) {
		//qDebug( "len: %i", len );
		//isatend = true;
		return len;
	}
	if ( maxlen ) 
		memcpy( data, buf, ( len >= maxlen ? maxlen : len ) );
	for( int i=maxlen;i<len;i++ )
		buffer.enqueue( buf[i] );
	while( buffer.count() > MAXQUEUESIZE )
		buffer.dequeue();
	return ( len >= maxlen ? maxlen : len );
#endif
}
Пример #10
0
 QByteArray waitForPrompt()
 {
     QByteArray output;
     while (!output.endsWith("(gdb) ")) {
         Q_ASSERT(state() == QProcess::Running);
         waitForReadyRead();
         QByteArray l = readAll();
         //qDebug() << l;
         output.append(l);
     }
     output.chop(7); //remove (gdb) prompt
     if (output.contains("Traceback") || output.contains("Exception")) {
         qDebug() << output;
         QTest::qFail("Unexpected Python Exception", __FILE__, __LINE__);
     }
     return output;
 }
Пример #11
0
bool Connection::sendMessage(QString msg) {
    QDataStream stream(this);

    QString request = "MESSAGE";
    stream << request;

    qDebug() << "send msg: " << msg;
    ByteArray encrypted = twofish->encrypt_qstr(msg);
    ByteArray::write(stream, encrypted);

    waitForReadyRead(PING_TIMEOUT);
    QString answer;
    stream >> answer;
    if(answer == "MESSAGE_DELIVERED") {
        return true;
    }
    return false;
}
Пример #12
0
void QSerial::readIntoBuffer( void )
{
#if ( defined( __linux__ ) | defined( __APPLE__ ) )
		char buf[BUFSIZ];
	ssize_t len = 0;
	if ( waitForReadyRead(0))
		len = ::read( io_port, buf, BUFSIZ );
#ifdef DEBUG_SERIAL
	QByteArray ba = "<-("+QByteArray::number( (int)len )+") ";
	for( int j=0;j<len;j++ )
		ba += "0x"+QByteArray::number( (unsigned char )buf[j], 16 )+" ";
	ba += "\n";
	logFile->write( ba );
#endif
	if ( len < 1 ) {
		isatend = true;
		return;
	}
	for( int i=0;i<len;i++ )
		buffer.enqueue( buf[i] );
	while( buffer.count() > MAXQUEUESIZE )
		buffer.dequeue();
#endif
}
Пример #13
0
void Translator::translateXlsx(QString filePath, QDir &docDir)
{
    QFileInfo fileInfo(filePath);
    QTemporaryDir dir(docDir.absoluteFilePath(fileInfo.baseName() + ".XXXXXX"));
    auto cmd = new QProcess(this);
    QDir exep (qApp->applicationDirPath());
#ifndef Q_OS_LINUX
    cmd->start(exep.absoluteFilePath("7z"), QStringList() << "t" << fileInfo.absoluteFilePath());
#endif
    cmd->waitForReadyRead();
    QString res = cmd->readAllStandardOutput();
    if (res.contains("ERROR")) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    cmd->waitForFinished();
    cmd->start(exep.absoluteFilePath("7z"), QStringList() << "x" << "-y" << fileInfo.absoluteFilePath()
               << "-o" + dir.path());
    cmd->waitForReadyRead();
    cmd->waitForFinished();
    QStringList args;
    //for (QString sheetName : sheetDir.entryList(QStringList() << "sheet*.xml")) {
    QFile sheet (QDir(dir.path() + "/xl").absoluteFilePath("sharedStrings.xml"));
    QTemporaryFile tmpSheet(sheet.fileName());
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));

    qApp->processEvents();
    //desxlsx
    args << "/u" << "/c" << "type" << "\"" + sheet.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-desxlsx";
    cmd->setNativeArguments(args.join(' '));
    args.clear();
    cmd->start("cmd.exe");
    cmd->waitForReadyRead();
    cmd->waitForFinished();
    if (!tmpSheet.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpSheet.setTextModeEnabled(true);
    tmpSheet.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    tmpSheet.close();
    //rexlsx
    args << "/u" << "/c" << "type" << "\"" + tmpSheet.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-rexlsx";
    cmd->setNativeArguments(args.join(" "));
    args.clear();
    cmd->start("cmd.exe");
    cmd->waitForReadyRead();
    if (!sheet.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    sheet.write(cmd->readAllStandardOutput());
    cmd->waitForFinished();

    sheet.close();
    cmd->setWorkingDirectory(dir.path());
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    QFile(trFilePath).remove();
    args << "a" << "-tzip" << "-y"
         << "\"" + trFilePath + "\""
         << "\"" + dir.path() + "/*\"";
    cmd->setNativeArguments(args.join(' '));
    cmd->start(exep.absoluteFilePath("7z"));
    cmd->waitForFinished();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
}
Пример #14
0
bool DhQAbstractSocket::DvhwaitForReadyRead() {
  return waitForReadyRead();
}
Пример #15
0
void Translator::translateDocx(QString filePath, QDir &docDir)
{
    QFileInfo fileInfo(filePath);
    QTemporaryDir dir(docDir.absoluteFilePath(fileInfo.baseName() + ".XXXXXX"));
    auto cmd = new QProcess(this);
    QDir exep (qApp->applicationDirPath());
    cmd->start(exep.absoluteFilePath("7z"), QStringList() << "t" << fileInfo.absoluteFilePath());
    cmd->waitForReadyRead();
    if (cmd->readAllStandardOutput().contains("ERROR")) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    cmd->waitForFinished();
    cmd->start(exep.absoluteFilePath("7z"), QStringList() << "x" << "-y" << fileInfo.absoluteFilePath()
               << "-o" + dir.path());
    cmd->waitForReadyRead();
    cmd->waitForFinished();

    QTemporaryFile tmpDoc("document.xml");
    QFile doc(dir.path() + "/word/document.xml");
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));
    QStringList args;
    qApp->processEvents();
    //deswxml
#ifdef Q_OS_WIN
    //windows bug with backslash
    //use replace to fix windows bug
    args << "/u" << "/c" << "type" << "\"" + doc.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-deswxml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!tmpDoc.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpDoc.setTextModeEnabled(true);
    tmpDoc.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    tmpDoc.close();
    //rewxml
    args.clear();
#ifdef Q_OS_WIN
    args << "/u" << "/c" << "type" << "\"" + tmpDoc.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-rewxml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!doc.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    doc.write(cmd->readAllStandardOutput());
    doc.close();
    cmd->setWorkingDirectory(dir.path());
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    cmd->start(exep.absoluteFilePath("7z"), QStringList() << "a" << "-tzip" << "-y"
               << trFilePath << dir.path() + "/*");
    cmd->waitForFinished();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
}
Пример #16
0
bool DhQIODevice::DvhwaitForReadyRead(int x1) {
  return waitForReadyRead(x1);
}
Пример #17
0
bool DhQAbstractSocket::DvhwaitForReadyRead(int x1) {
  return waitForReadyRead(x1);
}