tools/linguist/shared/proreader.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Linguist of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "profileevaluator.h"
       
    43 
       
    44 #include <QtCore/QDir>
       
    45 #include <QtCore/QFileInfo>
       
    46 
       
    47 QT_BEGIN_NAMESPACE
       
    48 
       
    49 static QStringList getSources(const char *var, const char *vvar, const QStringList &baseVPaths,
       
    50                               const QString &projectDir, const ProFileEvaluator &visitor)
       
    51 {
       
    52     QStringList vPaths =
       
    53         visitor.absolutePathValues(QLatin1String(vvar), projectDir);
       
    54     vPaths += baseVPaths;
       
    55     vPaths.removeDuplicates();
       
    56     return visitor.absoluteFileValues(QLatin1String(var), projectDir, vPaths, 0);
       
    57 }
       
    58 
       
    59 void evaluateProFile(const ProFileEvaluator &visitor, QHash<QByteArray, QStringList> *varMap,
       
    60                      const QString &projectDir)
       
    61 {
       
    62     QStringList baseVPaths;
       
    63     baseVPaths += visitor.absolutePathValues(QLatin1String("VPATH"), projectDir);
       
    64     baseVPaths << projectDir; // QMAKE_ABSOLUTE_SOURCE_PATH
       
    65     baseVPaths += visitor.absolutePathValues(QLatin1String("DEPENDPATH"), projectDir);
       
    66     baseVPaths.removeDuplicates();
       
    67 
       
    68     QStringList sourceFiles;
       
    69     QString codecForTr;
       
    70     QString codecForSource;
       
    71     QStringList tsFileNames;
       
    72 
       
    73     // app/lib template
       
    74     sourceFiles += getSources("SOURCES", "VPATH_SOURCES", baseVPaths, projectDir, visitor);
       
    75 
       
    76     sourceFiles += getSources("FORMS", "VPATH_FORMS", baseVPaths, projectDir, visitor);
       
    77     sourceFiles += getSources("FORMS3", "VPATH_FORMS3", baseVPaths, projectDir, visitor);
       
    78 
       
    79     QStringList vPathsInc = baseVPaths;
       
    80     vPathsInc += visitor.absolutePathValues(QLatin1String("INCLUDEPATH"), projectDir);
       
    81     vPathsInc.removeDuplicates();
       
    82     sourceFiles += visitor.absoluteFileValues(QLatin1String("HEADERS"), projectDir, vPathsInc, 0);
       
    83 
       
    84     QDir proDir(projectDir);
       
    85     foreach (const QString &tsFile, visitor.values(QLatin1String("TRANSLATIONS")))
       
    86         tsFileNames << QFileInfo(proDir, tsFile).filePath();
       
    87 
       
    88     QStringList trcodec = visitor.values(QLatin1String("CODEC"))
       
    89         + visitor.values(QLatin1String("DEFAULTCODEC"))
       
    90         + visitor.values(QLatin1String("CODECFORTR"));
       
    91     if (!trcodec.isEmpty())
       
    92         codecForTr = trcodec.last();
       
    93 
       
    94     QStringList srccodec = visitor.values(QLatin1String("CODECFORSRC"));
       
    95     if (!srccodec.isEmpty())
       
    96         codecForSource = srccodec.last();
       
    97 
       
    98     sourceFiles.sort();
       
    99     sourceFiles.removeDuplicates();
       
   100     tsFileNames.sort();
       
   101     tsFileNames.removeDuplicates();
       
   102 
       
   103     varMap->insert("SOURCES", sourceFiles);
       
   104     varMap->insert("CODECFORTR", QStringList() << codecForTr);
       
   105     varMap->insert("CODECFORSRC", QStringList() << codecForSource);
       
   106     varMap->insert("TRANSLATIONS", tsFileNames);
       
   107 }
       
   108 
       
   109 bool evaluateProFile(const QString &fileName, bool verbose, QHash<QByteArray, QStringList> *varMap)
       
   110 {
       
   111     QFileInfo fi(fileName);
       
   112     if (!fi.exists())
       
   113         return false;
       
   114 
       
   115     ProFile pro(fi.absoluteFilePath());
       
   116 
       
   117     ProFileEvaluator visitor;
       
   118     visitor.setVerbose(verbose);
       
   119 
       
   120     if (!visitor.queryProFile(&pro))
       
   121         return false;
       
   122 
       
   123     if (!visitor.accept(&pro))
       
   124         return false;
       
   125 
       
   126     evaluateProFile(visitor, varMap, fi.absolutePath());
       
   127 
       
   128     return true;
       
   129 }
       
   130 
       
   131 QT_END_NAMESPACE