Changeset 357 for trunk/src


Ignore:
Timestamp:
Nov 28, 2009, 8:49:40 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Make the Qt library portable on OS/2 by replacing hard-coded paths with paths relative to the QtCore DLL (or the application executable if Qt is built as a static library). Add two new locations to search for qt.conf/qtsys.conf for providing more portability and easier system integration. See #78 for more details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/global/qlibraryinfo.cpp

    r2 r357  
    4141
    4242#include "qdir.h"
    43 #include "qfile.h"   
     43#include "qfile.h"
    4444#include "qconfig.h"
    4545#include "qsettings.h"
     
    5858#  include "private/qcore_mac_p.h"
    5959#endif
     60
     61#ifdef Q_OS_OS2
     62
     63#include "qt_os2.h"
     64
     65static const char *qt_module_path()
     66{
     67    static char path[CCHMAXPATH] = {'\0'};
     68    if (!path[0]) {
     69        HMODULE hmod;
     70        ULONG objNum, offset;
     71        DosQueryModFromEIP(&hmod, &objNum, sizeof(path), path, &offset,
     72                           (ULONG)qt_module_path);
     73        DosQueryModuleName(hmod, sizeof(path), path);
     74        char *slash = strrchr(path, '\\');
     75        if (slash)
     76            *slash = '\0';
     77    }
     78    return path;
     79}
     80
     81#endif // Q_OS_OS2
    6082
    6183#include "qconfig.cpp"
     
    137159                qtconfig = pwd.filePath(QLatin1String("qt.conf"));
    138160            }
     161#ifdef Q_OS_OS2
     162    if (!QFile::exists(qtconfig)) {
     163        // search in the directory that contains the DLL or EXE where this
     164        // code is located (e.g. QtCore.dll or app.exe if Qt is a static lib)
     165        qtconfig = QString::fromLocal8Bit(qt_module_path());
     166        qtconfig = QDir::fromNativeSeparators(qtconfig) +
     167                   QLatin1String("/qt.conf");
     168        qtconfig = QDir::cleanPath(qtconfig);
     169
     170        if (!QFile::exists(qtconfig)) {
     171            // search in the system-wide location
     172            qtconfig = QString::fromLocal8Bit(qgetenv("ETC"));
     173            if (qtconfig.isEmpty())
     174                qtconfig = QDir::rootPath();
     175            qtconfig = QDir::fromNativeSeparators(qtconfig) +
     176                       QLatin1String("/qt/qtsys.conf");
     177            qtconfig = QDir::cleanPath(qtconfig);
     178        }
     179    }
     180#endif
    139181    }
    140182#endif
     
    296338        }
    297339
    298         if (path)
     340        if (path) {
    299341            ret = QString::fromLocal8Bit(path);
     342#ifdef Q_OS_OS2
     343            // expand environment variables in the form $(ENVVAR)
     344            int rep;
     345            QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
     346            reg_var.setMinimal(true);
     347            while((rep = reg_var.indexIn(ret)) != -1) {
     348                ret.replace(rep, reg_var.matchedLength(),
     349                            QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
     350                                reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
     351            }
     352#endif
     353        }
    300354    } else {
    301355        QString key;
     
    431485            // we make the prefix path absolute to the executable's directory
    432486#ifdef QT_BUILD_QMAKE
    433             return QFileInfo(qmake_libraryInfoFile()).absolutePath();
     487            QFileInfo fi(qmake_libraryInfoFile());
     488            return QDir::cleanPath(QDir(fi.absolutePath()).absoluteFilePath(ret));
    434489#else
     490#ifdef Q_OS_OS2
     491            QSettings *config = QLibraryInfoPrivate::configuration();
     492            if (config) {
     493                // if we read paths from qt[sys].conf, the Prefix is relative to
     494                // the directory we load qt[sys].conf from
     495                QFileInfo fi(config->fileName());
     496                return QDir::cleanPath(QDir(fi.absolutePath()).absoluteFilePath(ret));
     497            }
     498            else
     499#endif
    435500            if (QCoreApplication::instance()) {
    436501#ifdef Q_OS_MAC
     
    444509                }
    445510#endif
    446                 return QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(ret);
     511                return QDir::cleanPath(QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(ret));
    447512            } else {
    448513                return QDir::current().absoluteFilePath(ret);
     
    451516        } else {
    452517            // we make any other path absolute to the prefix directory
    453             return QDir(location(PrefixPath)).absoluteFilePath(ret);
     518            return QDir::cleanPath(QDir(location(PrefixPath)).absoluteFilePath(ret));
    454519        }
    455520    }
    456     return ret;
     521    return QDir::cleanPath(ret);
    457522}
    458523
Note: See TracChangeset for help on using the changeset viewer.