Fix regression introduced in 98a05681851db9d88b1364af52be543715fbe306
[qt-netbsd.git] / qmake / property.cpp
blob1ee653006ac6dfbfe7091b2f603ded2d658af26c
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 qmake application 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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "property.h"
43 #include "option.h"
45 #include <qdir.h>
46 #include <qmap.h>
47 #include <qsettings.h>
48 #include <qstringlist.h>
49 #include <stdio.h>
51 QT_BEGIN_NAMESPACE
53 QStringList qmake_mkspec_paths(); //project.cpp
55 QMakeProperty::QMakeProperty() : settings(0)
59 QMakeProperty::~QMakeProperty()
61 delete settings;
62 settings = 0;
65 void QMakeProperty::initSettings()
67 if(!settings) {
68 settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake");
69 settings->setFallbacksEnabled(false);
73 QString
74 QMakeProperty::keyBase(bool version) const
76 if (version)
77 return QString(qmake_version()) + "/";
78 return QString();
81 QString
82 QMakeProperty::value(QString v, bool just_check)
84 if(v == "QT_INSTALL_PREFIX")
85 return QLibraryInfo::location(QLibraryInfo::PrefixPath);
86 else if(v == "QT_INSTALL_DATA")
87 return QLibraryInfo::location(QLibraryInfo::DataPath);
88 else if(v == "QT_INSTALL_DOCS")
89 return QLibraryInfo::location(QLibraryInfo::DocumentationPath);
90 else if(v == "QT_INSTALL_HEADERS")
91 return QLibraryInfo::location(QLibraryInfo::HeadersPath);
92 else if(v == "QT_INSTALL_LIBS")
93 return QLibraryInfo::location(QLibraryInfo::LibrariesPath);
94 else if(v == "QT_INSTALL_BINS")
95 return QLibraryInfo::location(QLibraryInfo::BinariesPath);
96 else if(v == "QT_INSTALL_PLUGINS")
97 return QLibraryInfo::location(QLibraryInfo::PluginsPath);
98 else if(v == "QT_INSTALL_TRANSLATIONS")
99 return QLibraryInfo::location(QLibraryInfo::TranslationsPath);
100 else if(v == "QT_INSTALL_CONFIGURATION")
101 return QLibraryInfo::location(QLibraryInfo::SettingsPath);
102 else if(v == "QT_INSTALL_EXAMPLES")
103 return QLibraryInfo::location(QLibraryInfo::ExamplesPath);
104 else if(v == "QT_INSTALL_DEMOS")
105 return QLibraryInfo::location(QLibraryInfo::DemosPath);
106 else if(v == "QMAKE_MKSPECS")
107 return qmake_mkspec_paths().join(Option::target_mode == Option::TARG_WIN_MODE ? ";" : ":");
108 else if(v == "QMAKE_VERSION")
109 return qmake_version();
110 #ifdef QT_VERSION_STR
111 else if(v == "QT_VERSION")
112 return QT_VERSION_STR;
113 #endif
115 initSettings();
116 int slash = v.lastIndexOf('/');
117 QVariant var = settings->value(keyBase(slash == -1) + v);
118 bool ok = var.isValid();
119 QString ret = var.toString();
120 if(!ok) {
121 QString version = qmake_version();
122 if(slash != -1) {
123 version = v.left(slash-1);
124 v = v.mid(slash+1);
126 settings->beginGroup(keyBase(false));
127 QStringList subs = settings->childGroups();
128 settings->endGroup();
129 subs.sort();
130 for (int x = subs.count() - 1; x >= 0; x--) {
131 QString s = subs[x];
132 if(s.isEmpty() || s > version)
133 continue;
134 var = settings->value(keyBase(false) + s + "/" + v);
135 ok = var.isValid();
136 ret = var.toString();
137 if (ok) {
138 if(!just_check)
139 debug_msg(1, "Fell back from %s -> %s for '%s'.", version.toLatin1().constData(),
140 s.toLatin1().constData(), v.toLatin1().constData());
141 return ret;
145 return ok ? ret : QString();
148 bool
149 QMakeProperty::hasValue(QString v)
151 return !value(v, true).isNull();
154 void
155 QMakeProperty::setValue(QString var, const QString &val)
157 initSettings();
158 settings->setValue(keyBase() + var, val);
161 bool
162 QMakeProperty::exec()
164 bool ret = true;
165 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
166 if(Option::prop::properties.isEmpty()) {
167 initSettings();
168 settings->beginGroup(keyBase(false));
169 QStringList subs = settings->childGroups();
170 settings->endGroup();
171 subs.sort();
172 for(int x = subs.count() - 1; x >= 0; x--) {
173 QString s = subs[x];
174 if(s.isEmpty())
175 continue;
176 settings->beginGroup(keyBase(false) + s);
177 QStringList keys = settings->childKeys();
178 settings->endGroup();
179 for(QStringList::ConstIterator it2 = keys.begin(); it2 != keys.end(); it2++) {
180 QString ret = settings->value(keyBase(false) + s + "/" + (*it2)).toString();
181 if(s != qmake_version())
182 fprintf(stdout, "%s/", s.toLatin1().constData());
183 fprintf(stdout, "%s:%s\n", (*it2).toLatin1().constData(), ret.toLatin1().constData());
186 QStringList specialProps;
187 specialProps.append("QT_INSTALL_PREFIX");
188 specialProps.append("QT_INSTALL_DATA");
189 specialProps.append("QT_INSTALL_DOCS");
190 specialProps.append("QT_INSTALL_HEADERS");
191 specialProps.append("QT_INSTALL_LIBS");
192 specialProps.append("QT_INSTALL_BINS");
193 specialProps.append("QT_INSTALL_PLUGINS");
194 specialProps.append("QT_INSTALL_TRANSLATIONS");
195 specialProps.append("QT_INSTALL_CONFIGURATION");
196 specialProps.append("QT_INSTALL_EXAMPLES");
197 specialProps.append("QT_INSTALL_DEMOS");
198 specialProps.append("QMAKE_MKSPECS");
199 specialProps.append("QMAKE_VERSION");
200 #ifdef QT_VERSION_STR
201 specialProps.append("QT_VERSION");
202 #endif
203 foreach (QString prop, specialProps)
204 fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), value(prop).toLatin1().constData());
205 return true;
207 for(QStringList::ConstIterator it = Option::prop::properties.begin();
208 it != Option::prop::properties.end(); it++) {
209 if(Option::prop::properties.count() > 1)
210 fprintf(stdout, "%s:", (*it).toLatin1().constData());
211 if(!hasValue((*it))) {
212 ret = false;
213 fprintf(stdout, "**Unknown**\n");
214 } else {
215 fprintf(stdout, "%s\n", value((*it)).toLatin1().constData());
218 } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
219 for(QStringList::ConstIterator it = Option::prop::properties.begin();
220 it != Option::prop::properties.end(); it++) {
221 QString var = (*it);
222 it++;
223 if(it == Option::prop::properties.end()) {
224 ret = false;
225 break;
227 if(!var.startsWith("."))
228 setValue(var, (*it));
231 return ret;
234 QT_END_NAMESPACE