tools/linguist/shared/translator.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the Qt Linguist of the Qt Toolkit.
     7 ** This file is part of the Qt Linguist of the Qt Toolkit.
     8 **
     8 **
    42 #include "translator.h"
    42 #include "translator.h"
    43 
    43 
    44 #include "simtexth.h"
    44 #include "simtexth.h"
    45 
    45 
    46 #include <stdio.h>
    46 #include <stdio.h>
       
    47 #ifdef Q_OS_WIN
       
    48 #include <io.h> // required for _setmode, to avoid _O_TEXT streams...
       
    49 #include <fcntl.h> // for _O_BINARY
       
    50 #endif
    47 
    51 
    48 #include <QtCore/QDebug>
    52 #include <QtCore/QDebug>
    49 #include <QtCore/QDir>
    53 #include <QtCore/QDir>
    50 #include <QtCore/QFile>
    54 #include <QtCore/QFile>
    51 #include <QtCore/QFileInfo>
    55 #include <QtCore/QFileInfo>
   205     cd.m_sourceDir = QFileInfo(filename).absoluteDir();
   209     cd.m_sourceDir = QFileInfo(filename).absoluteDir();
   206     cd.m_sourceFileName = filename;
   210     cd.m_sourceFileName = filename;
   207 
   211 
   208     QFile file;
   212     QFile file;
   209     if (filename.isEmpty() || filename == QLatin1String("-")) {
   213     if (filename.isEmpty() || filename == QLatin1String("-")) {
       
   214 #ifdef Q_OS_WIN
       
   215         // QFile is broken for text files
       
   216         ::_setmode(0, _O_BINARY);
       
   217 #endif
   210         if (!file.open(stdin, QIODevice::ReadOnly)) {
   218         if (!file.open(stdin, QIODevice::ReadOnly)) {
   211             cd.appendError(QString::fromLatin1("Cannot open stdin!? (%1)")
   219             cd.appendError(QString::fromLatin1("Cannot open stdin!? (%1)")
   212                 .arg(file.errorString()));
   220                 .arg(file.errorString()));
   213             return false;
   221             return false;
   214         }
   222         }
   241 
   249 
   242 bool Translator::save(const QString &filename, ConversionData &cd, const QString &format) const
   250 bool Translator::save(const QString &filename, ConversionData &cd, const QString &format) const
   243 {
   251 {
   244     QFile file;
   252     QFile file;
   245     if (filename.isEmpty() || filename == QLatin1String("-")) {
   253     if (filename.isEmpty() || filename == QLatin1String("-")) {
       
   254 #ifdef Q_OS_WIN
       
   255         // QFile is broken for text files
       
   256         ::_setmode(1, _O_BINARY);
       
   257 #endif
   246         if (!file.open(stdout, QIODevice::WriteOnly)) {
   258         if (!file.open(stdout, QIODevice::WriteOnly)) {
   247             cd.appendError(QString::fromLatin1("Cannot open stdout!? (%1)")
   259             cd.appendError(QString::fromLatin1("Cannot open stdout!? (%1)")
   248                 .arg(file.errorString()));
   260                 .arg(file.errorString()));
   249             return false;
   261             return false;
   250         }
   262         }