Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

property.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 **
00004 ** Implementation of QMakeProperty class.
00005 **
00006 ** Copyright (C) 1992-2003 Trolltech AS.  All rights reserved.
00007 **
00008 ** This file is part of qmake.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech AS of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00020 ** file in accordance with the Qt Commercial License Agreement provided
00021 ** with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #include "property.h"
00037 #include "option.h"
00038 #include <qsettings.h>
00039 #include <qdir.h>
00040 #include <qmap.h>
00041 #include <qstringlist.h>
00042 #include <stdio.h>
00043 
00044 QStringList qmake_mkspec_paths(); //project.cpp
00045 
00046 QMakeProperty::QMakeProperty() : sett(NULL)
00047 {
00048 }
00049 
00050 QMakeProperty::~QMakeProperty()
00051 {
00052     delete sett;;
00053     sett = NULL;
00054 }
00055 
00056 
00057 bool QMakeProperty::initSettings()
00058 {
00059     if(sett)
00060         return TRUE;
00061     sett = new QSettings;
00062     return TRUE;
00063 }
00064 
00065 QString
00066 QMakeProperty::keyBase(bool version) const
00067 {
00068     QString ret = "/QMake/properties/";
00069     if(version)
00070         ret += QString(qmake_version()) + "/";
00071     return ret;
00072 }
00073 
00074 
00075 QString
00076 QMakeProperty::value(QString v, bool just_check)
00077 {
00078     if(v == "QT_INSTALL_PREFIX") {
00079 #ifdef QT_INSTALL_PREFIX
00080         return QT_INSTALL_PREFIX;
00081 #elif defined(HAVE_QCONFIG_CPP)
00082         return qInstallPath();
00083 #endif
00084     } else if(v == "QT_INSTALL_DATA") {
00085 #ifdef QT_INSTALL_DATA
00086         return QT_INSTALL_DATA;
00087 #elif defined(HAVE_QCONFIG_CPP)
00088         return qInstallPathData();
00089 #endif
00090     } else if(v == "QMAKE_MKSPECS") {
00091         return qmake_mkspec_paths().join(Option::target_mode == Option::TARG_WIN_MODE ? ";" : ":");
00092     } else if(v == "QMAKE_VERSION") {
00093         return qmake_version();
00094     }
00095 
00096     if(initSettings()) {
00097         bool ok;
00098         int slash = v.findRev('/');
00099         QString ret = sett->readEntry(keyBase(slash == -1) + v, QString::null, &ok);
00100         if(!ok) {
00101             QString version = qmake_version();
00102             if(slash != -1) {
00103                 version = v.left(slash-1);
00104                 v = v.mid(slash+1);
00105             }
00106             QStringList subs = sett->subkeyList(keyBase(FALSE));
00107             subs.sort();
00108             for(QStringList::Iterator it = subs.fromLast(); it != subs.end(); --it) {
00109                 if((*it).isEmpty() || (*it) > version)
00110                     continue;
00111                 ret = sett->readEntry(keyBase(FALSE) + (*it) + "/" + v, QString::null, &ok);
00112                 if(ok) {
00113                     if(!just_check)
00114                         debug_msg(1, "Fell back from %s -> %s for '%s'.", version.latin1(),
00115                                   (*it).latin1(), v.latin1());
00116                     return ret;
00117                 }
00118             }
00119         }
00120         return ok ? ret : QString::null;
00121     }
00122     return QString::null;
00123 }
00124 
00125 bool
00126 QMakeProperty::hasValue(QString v)
00127 {
00128     if(initSettings())
00129         return !value(v, TRUE).isNull();
00130     return FALSE;
00131 }
00132 
00133 void
00134 QMakeProperty::setValue(QString var, const QString &val)
00135 {
00136     if(initSettings())
00137         sett->writeEntry(keyBase() + var, val);
00138 }
00139 
00140 bool
00141 QMakeProperty::exec()
00142 {
00143     bool ret = TRUE;
00144     if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
00145         if(Option::prop::properties.isEmpty() && initSettings()) {
00146             QStringList subs = sett->subkeyList(keyBase(FALSE));
00147             subs.sort();
00148             for(QStringList::Iterator it = subs.fromLast(); it != subs.end(); --it) {
00149                 if((*it).isEmpty())
00150                     continue;
00151                 QStringList keys = sett->entryList(keyBase(FALSE) + (*it));
00152                 for(QStringList::Iterator it2 = keys.begin(); it2 != keys.end(); it2++) {
00153                     QString ret = sett->readEntry(keyBase(FALSE) + (*it) + "/" + (*it2));
00154                     if((*it) != qmake_version())
00155                         fprintf(stdout, "%s/", (*it).latin1());
00156                     fprintf(stdout, "%s:%s\n", (*it2).latin1(), ret.latin1());
00157                 }
00158             }
00159             return TRUE;
00160         }
00161         for(QStringList::Iterator it = Option::prop::properties.begin(); 
00162             it != Option::prop::properties.end(); it++) {
00163             if(Option::prop::properties.count() > 1)
00164                 fprintf(stdout, "%s:", (*it).latin1());
00165             if(!hasValue((*it))) {
00166                 ret = FALSE;
00167                 fprintf(stdout, "**Unknown**\n");
00168             } else {
00169                 fprintf(stdout, "%s\n", value((*it)).latin1());
00170             }
00171         }
00172     } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
00173         for(QStringList::Iterator it = Option::prop::properties.begin(); 
00174             it != Option::prop::properties.end(); it++) {
00175             QString var = (*it);
00176             it++;
00177             if(it == Option::prop::properties.end()) {
00178                 ret = FALSE;
00179                 break;
00180             }
00181             if(!var.startsWith("."))
00182                 setValue(var, (*it));
00183         }
00184     }
00185     return ret;
00186 }

Generated on Sat Nov 5 16:18:28 2005 for OPIE by  doxygen 1.4.2