OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / cesdkhandler.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
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 #include "cesdkhandler.h"
34
35 #include <utils/environment.h>
36
37 #include <QtCore/QFile>
38 #include <QtCore/QDebug>
39 #include <QtCore/QXmlStreamReader>
40
41 using namespace ProjectExplorer;
42 using namespace ProjectExplorer::Internal;
43 using Utils::Environment;
44
45 CeSdkInfo::CeSdkInfo()
46     : m_major(0), m_minor(0)
47 {
48 }
49
50 void CeSdkInfo::addToEnvironment(Environment &env)
51 {
52     qDebug() << "adding " << name() << "to Environment";
53     env.set("INCLUDE", m_include);
54     env.set("LIB", m_lib);
55     env.prependOrSetPath(m_bin);
56 }
57
58 CeSdkHandler::CeSdkHandler()
59 {
60 }
61
62 bool CeSdkHandler::parse(const QString &vsdir)
63 {
64     // look at the file at %VCInstallDir%/vcpackages/WCE.VCPlatform.config
65     // and scan through all installed sdks...
66     m_list.clear();
67
68     VCInstallDir = vsdir;
69
70     QDir vStudioDir(VCInstallDir);
71     if (!vStudioDir.cd("vcpackages"))
72         return false;
73
74     QFile configFile(vStudioDir.absoluteFilePath(QLatin1String("WCE.VCPlatform.config")));
75     qDebug()<<"##";
76     if (!configFile.exists() || !configFile.open(QIODevice::ReadOnly))
77         return false;
78
79     qDebug()<<"parsing";
80
81     QString currentElement;
82     CeSdkInfo currentItem;
83     QXmlStreamReader xml(&configFile);
84     while (!xml.atEnd()) {
85         xml.readNext();
86         if (xml.isStartElement()) {
87             currentElement = xml.name().toString();
88             if (currentElement == QLatin1String("Platform"))
89                 currentItem = CeSdkInfo();
90             else if (currentElement == QLatin1String("Directories")) {
91                 QXmlStreamAttributes attr = xml.attributes();
92                 currentItem.m_include = fixPaths(attr.value(QLatin1String("Include")).toString());
93                 currentItem.m_lib = fixPaths(attr.value(QLatin1String("Library")).toString());
94                 currentItem.m_bin = fixPaths(attr.value(QLatin1String("Path")).toString());
95             }
96         } else if (xml.isEndElement()) {
97             if (xml.name().toString() == QLatin1String("Platform"))
98                 m_list.append(currentItem);
99         } else if (xml.isCharacters() && !xml.isWhitespace()) {
100             if (currentElement == QLatin1String("PlatformName"))
101                 currentItem.m_name = xml.text().toString();
102             else if (currentElement == QLatin1String("OSMajorVersion"))
103                 currentItem.m_major = xml.text().toString().toInt();
104             else if (currentElement == QLatin1String("OSMinorVersion"))
105                 currentItem.m_minor = xml.text().toString().toInt();
106         }
107     }
108
109     if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
110         qWarning("CeSdkHandler::parse(): XML ERROR: %d : %s", int(xml.lineNumber()), qPrintable(xml.errorString()));
111         return false;
112     }
113     return m_list.size() > 0 ? true : false;
114 }
115
116 CeSdkInfo CeSdkHandler::find(const QString &name)
117 {
118     qDebug() << "looking for platform " << name;
119     for (QList<CeSdkInfo>::iterator it = m_list.begin(); it != m_list.end(); ++it) {
120         qDebug() << "...." << it->name();
121         if (it->name() == name)
122             return *it;
123     }
124     return CeSdkInfo();
125 }