| [2] | 1 | /**************************************************************************** | 
|---|
|  | 2 | ** | 
|---|
|  | 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
|  | 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
|  | 5 | ** | 
|---|
|  | 6 | ** This file is part of the qmake application of the Qt Toolkit. | 
|---|
|  | 7 | ** | 
|---|
|  | 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
|  | 9 | ** Commercial Usage | 
|---|
|  | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
|  | 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
|  | 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
|  | 13 | ** a written agreement between you and Nokia. | 
|---|
|  | 14 | ** | 
|---|
|  | 15 | ** GNU Lesser General Public License Usage | 
|---|
|  | 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
|  | 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
|  | 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
|  | 19 | ** packaging of this file.  Please review the following information to | 
|---|
|  | 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
|  | 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
|  | 22 | ** | 
|---|
|  | 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
|  | 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
|  | 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
|  | 26 | ** package. | 
|---|
|  | 27 | ** | 
|---|
|  | 28 | ** GNU General Public License Usage | 
|---|
|  | 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
|  | 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
|  | 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
|  | 32 | ** packaging of this file.  Please review the following information to | 
|---|
|  | 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
|  | 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
|  | 35 | ** | 
|---|
|  | 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
|  | 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
|  | 38 | ** $QT_END_LICENSE$ | 
|---|
|  | 39 | ** | 
|---|
|  | 40 | ****************************************************************************/ | 
|---|
|  | 41 |  | 
|---|
|  | 42 | #include "property.h" | 
|---|
|  | 43 | #include "option.h" | 
|---|
|  | 44 |  | 
|---|
|  | 45 | #include <qdir.h> | 
|---|
|  | 46 | #include <qmap.h> | 
|---|
|  | 47 | #include <qsettings.h> | 
|---|
|  | 48 | #include <qstringlist.h> | 
|---|
|  | 49 | #include <stdio.h> | 
|---|
|  | 50 |  | 
|---|
|  | 51 | QT_BEGIN_NAMESPACE | 
|---|
|  | 52 |  | 
|---|
|  | 53 | QStringList qmake_mkspec_paths(); //project.cpp | 
|---|
|  | 54 |  | 
|---|
|  | 55 | QMakeProperty::QMakeProperty() : settings(0) | 
|---|
|  | 56 | { | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | QMakeProperty::~QMakeProperty() | 
|---|
|  | 60 | { | 
|---|
|  | 61 | delete settings; | 
|---|
|  | 62 | settings = 0; | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | void QMakeProperty::initSettings() | 
|---|
|  | 66 | { | 
|---|
|  | 67 | if(!settings) { | 
|---|
|  | 68 | settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake"); | 
|---|
|  | 69 | settings->setFallbacksEnabled(false); | 
|---|
|  | 70 | } | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | QString | 
|---|
|  | 74 | QMakeProperty::keyBase(bool version) const | 
|---|
|  | 75 | { | 
|---|
|  | 76 | if (version) | 
|---|
|  | 77 | return QString(qmake_version()) + "/"; | 
|---|
|  | 78 | return QString(); | 
|---|
|  | 79 | } | 
|---|
|  | 80 |  | 
|---|
|  | 81 | QString | 
|---|
|  | 82 | QMakeProperty::value(QString v, bool just_check) | 
|---|
|  | 83 | { | 
|---|
|  | 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") | 
|---|
| [27] | 107 | return qmake_mkspec_paths().join(Option::target_mode == Option::TARG_WIN_MODE || | 
|---|
|  | 108 | Option::target_mode == Option::TARG_OS2_MODE ? ";" : ":"); | 
|---|
| [2] | 109 | else if(v == "QMAKE_VERSION") | 
|---|
|  | 110 | return qmake_version(); | 
|---|
|  | 111 | #ifdef QT_VERSION_STR | 
|---|
|  | 112 | else if(v == "QT_VERSION") | 
|---|
|  | 113 | return QT_VERSION_STR; | 
|---|
|  | 114 | #endif | 
|---|
|  | 115 |  | 
|---|
|  | 116 | initSettings(); | 
|---|
|  | 117 | int slash = v.lastIndexOf('/'); | 
|---|
|  | 118 | QVariant var = settings->value(keyBase(slash == -1) + v); | 
|---|
|  | 119 | bool ok = var.isValid(); | 
|---|
|  | 120 | QString ret = var.toString(); | 
|---|
|  | 121 | if(!ok) { | 
|---|
|  | 122 | QString version = qmake_version(); | 
|---|
|  | 123 | if(slash != -1) { | 
|---|
|  | 124 | version = v.left(slash-1); | 
|---|
|  | 125 | v = v.mid(slash+1); | 
|---|
|  | 126 | } | 
|---|
|  | 127 | settings->beginGroup(keyBase(false)); | 
|---|
|  | 128 | QStringList subs = settings->childGroups(); | 
|---|
|  | 129 | settings->endGroup(); | 
|---|
|  | 130 | subs.sort(); | 
|---|
|  | 131 | for (int x = subs.count() - 1; x >= 0; x--) { | 
|---|
|  | 132 | QString s = subs[x]; | 
|---|
|  | 133 | if(s.isEmpty() || s > version) | 
|---|
|  | 134 | continue; | 
|---|
|  | 135 | var = settings->value(keyBase(false) + s + "/" + v); | 
|---|
|  | 136 | ok = var.isValid(); | 
|---|
|  | 137 | ret = var.toString(); | 
|---|
|  | 138 | if (ok) { | 
|---|
|  | 139 | if(!just_check) | 
|---|
|  | 140 | debug_msg(1, "Fell back from %s -> %s for '%s'.", version.toLatin1().constData(), | 
|---|
|  | 141 | s.toLatin1().constData(), v.toLatin1().constData()); | 
|---|
|  | 142 | return ret; | 
|---|
|  | 143 | } | 
|---|
|  | 144 | } | 
|---|
|  | 145 | } | 
|---|
|  | 146 | return ok ? ret : QString(); | 
|---|
|  | 147 | } | 
|---|
|  | 148 |  | 
|---|
|  | 149 | bool | 
|---|
|  | 150 | QMakeProperty::hasValue(QString v) | 
|---|
|  | 151 | { | 
|---|
|  | 152 | return !value(v, true).isNull(); | 
|---|
|  | 153 | } | 
|---|
|  | 154 |  | 
|---|
|  | 155 | void | 
|---|
|  | 156 | QMakeProperty::setValue(QString var, const QString &val) | 
|---|
|  | 157 | { | 
|---|
|  | 158 | initSettings(); | 
|---|
|  | 159 | settings->setValue(keyBase() + var, val); | 
|---|
|  | 160 | } | 
|---|
|  | 161 |  | 
|---|
|  | 162 | bool | 
|---|
|  | 163 | QMakeProperty::exec() | 
|---|
|  | 164 | { | 
|---|
|  | 165 | bool ret = true; | 
|---|
|  | 166 | if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) { | 
|---|
|  | 167 | if(Option::prop::properties.isEmpty()) { | 
|---|
|  | 168 | initSettings(); | 
|---|
|  | 169 | settings->beginGroup(keyBase(false)); | 
|---|
|  | 170 | QStringList subs = settings->childGroups(); | 
|---|
|  | 171 | settings->endGroup(); | 
|---|
|  | 172 | subs.sort(); | 
|---|
|  | 173 | for(int x = subs.count() - 1; x >= 0; x--) { | 
|---|
|  | 174 | QString s = subs[x]; | 
|---|
|  | 175 | if(s.isEmpty()) | 
|---|
|  | 176 | continue; | 
|---|
|  | 177 | settings->beginGroup(keyBase(false) + s); | 
|---|
|  | 178 | QStringList keys = settings->childKeys(); | 
|---|
|  | 179 | settings->endGroup(); | 
|---|
|  | 180 | for(QStringList::ConstIterator it2 = keys.begin(); it2 != keys.end(); it2++) { | 
|---|
|  | 181 | QString ret = settings->value(keyBase(false) + s + "/" + (*it2)).toString(); | 
|---|
|  | 182 | if(s != qmake_version()) | 
|---|
|  | 183 | fprintf(stdout, "%s/", s.toLatin1().constData()); | 
|---|
|  | 184 | fprintf(stdout, "%s:%s\n", (*it2).toLatin1().constData(), ret.toLatin1().constData()); | 
|---|
|  | 185 | } | 
|---|
|  | 186 | } | 
|---|
|  | 187 | QStringList specialProps; | 
|---|
|  | 188 | specialProps.append("QT_INSTALL_PREFIX"); | 
|---|
|  | 189 | specialProps.append("QT_INSTALL_DATA"); | 
|---|
|  | 190 | specialProps.append("QT_INSTALL_DOCS"); | 
|---|
|  | 191 | specialProps.append("QT_INSTALL_HEADERS"); | 
|---|
|  | 192 | specialProps.append("QT_INSTALL_LIBS"); | 
|---|
|  | 193 | specialProps.append("QT_INSTALL_BINS"); | 
|---|
|  | 194 | specialProps.append("QT_INSTALL_PLUGINS"); | 
|---|
|  | 195 | specialProps.append("QT_INSTALL_TRANSLATIONS"); | 
|---|
|  | 196 | specialProps.append("QT_INSTALL_CONFIGURATION"); | 
|---|
|  | 197 | specialProps.append("QT_INSTALL_EXAMPLES"); | 
|---|
|  | 198 | specialProps.append("QT_INSTALL_DEMOS"); | 
|---|
|  | 199 | specialProps.append("QMAKE_MKSPECS"); | 
|---|
|  | 200 | specialProps.append("QMAKE_VERSION"); | 
|---|
|  | 201 | #ifdef QT_VERSION_STR | 
|---|
|  | 202 | specialProps.append("QT_VERSION"); | 
|---|
|  | 203 | #endif | 
|---|
|  | 204 | foreach (QString prop, specialProps) | 
|---|
|  | 205 | fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), value(prop).toLatin1().constData()); | 
|---|
|  | 206 | return true; | 
|---|
|  | 207 | } | 
|---|
|  | 208 | for(QStringList::ConstIterator it = Option::prop::properties.begin(); | 
|---|
|  | 209 | it != Option::prop::properties.end(); it++) { | 
|---|
|  | 210 | if(Option::prop::properties.count() > 1) | 
|---|
|  | 211 | fprintf(stdout, "%s:", (*it).toLatin1().constData()); | 
|---|
|  | 212 | if(!hasValue((*it))) { | 
|---|
|  | 213 | ret = false; | 
|---|
|  | 214 | fprintf(stdout, "**Unknown**\n"); | 
|---|
|  | 215 | } else { | 
|---|
|  | 216 | fprintf(stdout, "%s\n", value((*it)).toLatin1().constData()); | 
|---|
|  | 217 | } | 
|---|
|  | 218 | } | 
|---|
|  | 219 | } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) { | 
|---|
|  | 220 | for(QStringList::ConstIterator it = Option::prop::properties.begin(); | 
|---|
|  | 221 | it != Option::prop::properties.end(); it++) { | 
|---|
|  | 222 | QString var = (*it); | 
|---|
|  | 223 | it++; | 
|---|
|  | 224 | if(it == Option::prop::properties.end()) { | 
|---|
|  | 225 | ret = false; | 
|---|
|  | 226 | break; | 
|---|
|  | 227 | } | 
|---|
|  | 228 | if(!var.startsWith(".")) | 
|---|
|  | 229 | setValue(var, (*it)); | 
|---|
|  | 230 | } | 
|---|
|  | 231 | } | 
|---|
|  | 232 | return ret; | 
|---|
|  | 233 | } | 
|---|
|  | 234 |  | 
|---|
|  | 235 | QT_END_NAMESPACE | 
|---|