1 | /****************************************************************************
|
---|
2 | ** $Id: property.cpp 8 2005-11-16 19:36:46Z dmik $
|
---|
3 | **
|
---|
4 | ** Implementation of QMakeProperty class.
|
---|
5 | **
|
---|
6 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
7 | **
|
---|
8 | ** This file is part of qmake.
|
---|
9 | **
|
---|
10 | ** This file may be distributed under the terms of the Q Public License
|
---|
11 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
12 | ** LICENSE.QPL included in the packaging of this file.
|
---|
13 | **
|
---|
14 | ** This file may be distributed and/or modified under the terms of the
|
---|
15 | ** GNU General Public License version 2 as published by the Free Software
|
---|
16 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
17 | ** packaging of this file.
|
---|
18 | **
|
---|
19 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
---|
20 | ** file in accordance with the Qt Commercial License Agreement provided
|
---|
21 | ** with the Software.
|
---|
22 | **
|
---|
23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
25 | **
|
---|
26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
27 | ** information about Qt Commercial License Agreements.
|
---|
28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
30 | **
|
---|
31 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
32 | ** not clear to you.
|
---|
33 | **
|
---|
34 | **********************************************************************/
|
---|
35 |
|
---|
36 | #include "property.h"
|
---|
37 | #include "option.h"
|
---|
38 | #include <qsettings.h>
|
---|
39 | #include <qdir.h>
|
---|
40 | #include <qmap.h>
|
---|
41 | #include <qstringlist.h>
|
---|
42 | #include <stdio.h>
|
---|
43 |
|
---|
44 | QStringList qmake_mkspec_paths(); //project.cpp
|
---|
45 |
|
---|
46 | QMakeProperty::QMakeProperty() : sett(NULL)
|
---|
47 | {
|
---|
48 | }
|
---|
49 |
|
---|
50 | QMakeProperty::~QMakeProperty()
|
---|
51 | {
|
---|
52 | delete sett;;
|
---|
53 | sett = NULL;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | bool QMakeProperty::initSettings()
|
---|
58 | {
|
---|
59 | if(sett)
|
---|
60 | return TRUE;
|
---|
61 | sett = new QSettings;
|
---|
62 | return TRUE;
|
---|
63 | }
|
---|
64 |
|
---|
65 | QString
|
---|
66 | QMakeProperty::keyBase(bool version) const
|
---|
67 | {
|
---|
68 | QString ret = "/QMake/properties/";
|
---|
69 | if(version)
|
---|
70 | ret += QString(qmake_version()) + "/";
|
---|
71 | return ret;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | QString
|
---|
76 | QMakeProperty::value(QString v, bool just_check)
|
---|
77 | {
|
---|
78 | if(v == "QT_INSTALL_PREFIX") {
|
---|
79 | #ifdef QT_INSTALL_PREFIX
|
---|
80 | return QT_INSTALL_PREFIX;
|
---|
81 | #elif defined(HAVE_QCONFIG_CPP)
|
---|
82 | return qInstallPath();
|
---|
83 | #endif
|
---|
84 | } else if(v == "QT_INSTALL_DATA") {
|
---|
85 | #ifdef QT_INSTALL_DATA
|
---|
86 | return QT_INSTALL_DATA;
|
---|
87 | #elif defined(HAVE_QCONFIG_CPP)
|
---|
88 | return qInstallPathData();
|
---|
89 | #endif
|
---|
90 | } else if(v == "QMAKE_MKSPECS") {
|
---|
91 | return qmake_mkspec_paths().join(
|
---|
92 | (Option::target_mode == Option::TARG_WIN_MODE ||
|
---|
93 | Option::target_mode == Option::TARG_OS2_MODE) ? ";" : ":");
|
---|
94 | } else if(v == "QMAKE_VERSION") {
|
---|
95 | return qmake_version();
|
---|
96 | }
|
---|
97 |
|
---|
98 | if(initSettings()) {
|
---|
99 | bool ok;
|
---|
100 | int slash = v.findRev('/');
|
---|
101 | QString ret = sett->readEntry(keyBase(slash == -1) + v, QString::null, &ok);
|
---|
102 | if(!ok) {
|
---|
103 | QString version = qmake_version();
|
---|
104 | if(slash != -1) {
|
---|
105 | version = v.left(slash-1);
|
---|
106 | v = v.mid(slash+1);
|
---|
107 | }
|
---|
108 | QStringList subs = sett->subkeyList(keyBase(FALSE));
|
---|
109 | subs.sort();
|
---|
110 | for(QStringList::Iterator it = subs.fromLast(); it != subs.end(); --it) {
|
---|
111 | if((*it).isEmpty() || (*it) > version)
|
---|
112 | continue;
|
---|
113 | ret = sett->readEntry(keyBase(FALSE) + (*it) + "/" + v, QString::null, &ok);
|
---|
114 | if(ok) {
|
---|
115 | if(!just_check)
|
---|
116 | debug_msg(1, "Fell back from %s -> %s for '%s'.", version.latin1(),
|
---|
117 | (*it).latin1(), v.latin1());
|
---|
118 | return ret;
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | return ok ? ret : QString::null;
|
---|
123 | }
|
---|
124 | return QString::null;
|
---|
125 | }
|
---|
126 |
|
---|
127 | bool
|
---|
128 | QMakeProperty::hasValue(QString v)
|
---|
129 | {
|
---|
130 | if(initSettings())
|
---|
131 | return !value(v, TRUE).isNull();
|
---|
132 | return FALSE;
|
---|
133 | }
|
---|
134 |
|
---|
135 | void
|
---|
136 | QMakeProperty::setValue(QString var, const QString &val)
|
---|
137 | {
|
---|
138 | if(initSettings())
|
---|
139 | sett->writeEntry(keyBase() + var, val);
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool
|
---|
143 | QMakeProperty::exec()
|
---|
144 | {
|
---|
145 | bool ret = TRUE;
|
---|
146 | if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
|
---|
147 | if(Option::prop::properties.isEmpty() && initSettings()) {
|
---|
148 | QStringList subs = sett->subkeyList(keyBase(FALSE));
|
---|
149 | subs.sort();
|
---|
150 | for(QStringList::Iterator it = subs.fromLast(); it != subs.end(); --it) {
|
---|
151 | if((*it).isEmpty())
|
---|
152 | continue;
|
---|
153 | QStringList keys = sett->entryList(keyBase(FALSE) + (*it));
|
---|
154 | for(QStringList::Iterator it2 = keys.begin(); it2 != keys.end(); it2++) {
|
---|
155 | QString ret = sett->readEntry(keyBase(FALSE) + (*it) + "/" + (*it2));
|
---|
156 | if((*it) != qmake_version())
|
---|
157 | fprintf(stdout, "%s/", (*it).latin1());
|
---|
158 | fprintf(stdout, "%s:%s\n", (*it2).latin1(), ret.latin1());
|
---|
159 | }
|
---|
160 | }
|
---|
161 | return TRUE;
|
---|
162 | }
|
---|
163 | for(QStringList::Iterator it = Option::prop::properties.begin();
|
---|
164 | it != Option::prop::properties.end(); it++) {
|
---|
165 | if(Option::prop::properties.count() > 1)
|
---|
166 | fprintf(stdout, "%s:", (*it).latin1());
|
---|
167 | if(!hasValue((*it))) {
|
---|
168 | ret = FALSE;
|
---|
169 | fprintf(stdout, "**Unknown**\n");
|
---|
170 | } else {
|
---|
171 | fprintf(stdout, "%s\n", value((*it)).latin1());
|
---|
172 | }
|
---|
173 | }
|
---|
174 | } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
|
---|
175 | for(QStringList::Iterator it = Option::prop::properties.begin();
|
---|
176 | it != Option::prop::properties.end(); it++) {
|
---|
177 | QString var = (*it);
|
---|
178 | it++;
|
---|
179 | if(it == Option::prop::properties.end()) {
|
---|
180 | ret = FALSE;
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | if(!var.startsWith("."))
|
---|
184 | setValue(var, (*it));
|
---|
185 | }
|
---|
186 | }
|
---|
187 | return ret;
|
---|
188 | }
|
---|