44 #include <QtCore/qdebug.h> 45 #include <QtCore/qdir.h> 46 #include <QtCore/qfileinfo.h> 47 #include <QtCore/qpluginloader.h> 48 #include <QtCore/qlibraryinfo.h> 49 #include <QtCore/qalgorithms.h> 50 #include <QtDeclarative/qdeclarativeextensioninterface.h> 51 #include <private/qdeclarativeglobal_p.h> 52 #include <private/qdeclarativetypenamecache_p.h> 53 #include <private/qdeclarativeengine_p.h> 56 #include "private/qcore_symbian_p.h" 85 QUrl *
base = 0,
bool *typeRecursionDetected = 0);
95 bool importExtension(
const QString &absoluteFilePath,
const QString &uri,
181 for (
int ii = 0; ii <
set.uris.count(); ++ii) {
183 int major =
set.majversions.at(ii);
184 int minor =
set.minversions.at(ii);
193 cache->
add(name, type);
206 iter !=
d->
set.
end(); ++iter) {
214 cache->
add(iter.key(), nc);
249 if (type_return || url_return) {
250 if (
d->
find(type,vmaj,vmin,type_return,url_return, errorString)) {
251 if (qmlImportTrace()) {
252 if (type_return && *type_return && url_return && !url_return->
isEmpty())
254 << type <<
" => " << (*type_return)->typeName() <<
" " << *url_return;
255 if (type_return && *type_return)
257 << type <<
" => " << (*type_return)->typeName();
258 if (url_return && !url_return->
isEmpty())
260 << type <<
" => " << *url_return;
283 int *vmaj,
int *vmin)
const 291 QUrl *
base,
bool *typeRecursionDetected)
293 int vmaj = majversions.at(i);
294 int vmin = minversions.at(i);
302 if (vmajor) *vmajor = vmaj;
303 if (vminor) *vminor = vmin;
311 bool typeWasDeclaredInQmldir =
false;
312 if (!qmldircomponents.
isEmpty()) {
316 typeWasDeclaredInQmldir =
true;
326 if (base && *base == candidate) {
327 if (typeRecursionDetected)
328 *typeRecursionDetected =
true;
332 *url_return = candidate;
339 if (!typeWasDeclaredInQmldir && !isLibrary.at(i)) {
344 if (base && *base == url) {
345 if (typeRecursionDetected)
346 *typeRecursionDetected =
true;
358 : ref(1), typeLoader(loader){
376 for (
int i = 0; i < qmldirErrors.
size(); ++i)
389 #if defined(QT_LIBINFIX) && defined(Q_OS_SYMBIAN) 390 if (resolvedFilePath.
isEmpty()) {
396 if (!resolvedFilePath.
isEmpty()) {
397 if (!database->
importPlugin(resolvedFilePath, uri, errorString)) {
399 *errorString = QDeclarativeImportDatabase::tr(
"plugin cannot be loaded for module \"%1\": %2").
arg(uri).
arg(*errorString);
404 *errorString = QDeclarativeImportDatabase::tr(
"module \"%1\" plugin \"%2\" not found").
arg(uri).
arg(plugin.
name);
425 QString stableRelativePath = dir;
426 foreach(
const QString &path, paths) {
428 stableRelativePath = dir.
mid(path.
length()+1);
437 if (lastSlash >= 0) {
438 int versionDot = stableRelativePath.indexOf(
QLatin1Char(
'.'), lastSlash);
440 stableRelativePath = stableRelativePath.left(versionDot);
444 return stableRelativePath;
448 const QString& uri_arg,
const QString& prefix,
int vmaj,
int vmin,
459 s =
set.value(prefix);
464 bool appendInstead =
false;
467 appendInstead =
true;
472 bool versionFound =
false;
480 if (vmaj >= 0 && vmin >= 0) {
486 if (!absoluteFilePath.
isEmpty()) {
492 if (!
importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
499 if (vmaj >= 0 && vmin >= 0) {
505 if (!absoluteFilePath.
isEmpty()) {
511 if (!
importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
525 if (!absoluteFilePath.
isEmpty()) {
531 if (!
importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString))
544 if (!versionFound && qmldircomponents.
isEmpty()) {
548 *errorString = QDeclarativeImportDatabase::tr(
"module \"%1\" version %2.%3 is not installed").
arg(uri_arg).
arg(vmaj).
arg(vmin);
550 *errorString = QDeclarativeImportDatabase::tr(
"module \"%1\" is not installed").
arg(uri_arg);
559 if (!localFileOrQrc.
isEmpty()) {
562 if (dir.
isEmpty() || !dirinfo.exists() || !dirinfo.isDir()) {
564 *errorString = QDeclarativeImportDatabase::tr(
"\"%1\": no such directory").
arg(uri_arg);
571 if (!
importExtension(localFileOrQrc,uri,database,&qmldircomponents,errorString))
579 if (localFileOrQrc.
isEmpty() || !dirinfo.exists() || !dirinfo.isDir()) {
582 *errorString = QDeclarativeImportDatabase::tr(
"import \"%1\" has no qmldir and no namespace").
arg(uri);
584 *errorString = QDeclarativeImportDatabase::tr(
"\"%1\": no such directory").
arg(uri);
597 if (!versionFound && vmaj > -1 && vmin > -1 && !qmldircomponents.
isEmpty()) {
601 int highest_maj = INT_MIN;
602 int highest_min = INT_MIN;
603 for (; it != qmldircomponents.
end(); ++
it) {
604 if (it->majorVersion > highest_maj || (it->majorVersion == highest_maj && it->minorVersion > highest_min)) {
605 highest_maj = it->majorVersion;
606 highest_min = it->minorVersion;
608 if (it->majorVersion < lowest_maj || (it->majorVersion == lowest_maj && it->minorVersion < lowest_min)) {
609 lowest_maj = it->majorVersion;
610 lowest_min = it->minorVersion;
613 if (lowest_maj > vmaj || (lowest_maj == vmaj && lowest_min > vmin)
614 || highest_maj < vmaj || (highest_maj == vmaj && highest_min < vmin))
616 *errorString = QDeclarativeImportDatabase::tr(
"module \"%1\" version %2.%3 is not installed").
arg(uri_arg).
arg(vmaj).
arg(vmin);
647 s =
set.value(namespaceName);
650 *errorString = QDeclarativeImportDatabase::tr(
"- %1 is not a namespace").
arg(namespaceName);
653 int nslash = type.
indexOf(
'/',slash+1);
656 *errorString = QDeclarativeImportDatabase::tr(
"- nested namespaces not allowed");
664 if (s->
find(
typeLoader, unqualifiedtype,vmajor,vminor,type_return,url_return, &
base, errorString))
678 return set.value(type);
684 bool typeRecursionDetected =
false;
685 for (
int i=0; i<urls.count(); ++i) {
686 if (find_helper(typeLoader, i, type, vmajor, vminor, type_return, url_return, base, &typeRecursionDetected)) {
687 if (qmlCheckTypes()) {
689 for (
int j = i+1; j<urls.count(); ++j) {
690 if (find_helper(typeLoader, j, type, vmajor, vminor, 0, 0, base)) {
703 u1 = QDeclarativeImportDatabase::tr(
"local directory");
707 u2 = QDeclarativeImportDatabase::tr(
"local directory");
713 = QDeclarativeImportDatabase::tr(
"is ambiguous. Found in %1 and in %2")
717 = QDeclarativeImportDatabase::tr(
"is ambiguous. Found in %1 in version %2.%3 and %4.%5")
719 .
arg(majversions.at(i)).arg(minversions.at(i))
720 .arg(majversions.at(j)).arg(minversions.at(j));
730 if (typeRecursionDetected)
731 *errorString = QDeclarativeImportDatabase::tr(
"is instantiated recursively");
733 *errorString = QDeclarativeImportDatabase::tr(
"is not a type");
753 #ifndef QT_NO_SETTINGS 756 #if defined(Q_OS_SYMBIAN) 759 QString tempPath = installImportsPath;
763 RFs& fs = qt_s60GetRFs();
764 TPtrC tempPathPtr(reinterpret_cast<const TText*> (tempPath.
constData()));
766 _LIT(KStartDir,
"Y:");
767 TFileName dirPath(KStartDir);
768 dirPath.Append(tempPathPtr);
769 TFindFile finder(fs);
770 TInt err = finder.FindByDir(tempPathPtr, dirPath);
771 while (err == KErrNone) {
772 QString foundDir(reinterpret_cast<const QChar *>(finder.File().Ptr()),
773 finder.File().Length());
788 #endif // QT_NO_SETTINGS 792 if (!envImportPath.
isEmpty()) {
793 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 799 for (
int ii = paths.
count() - 1; ii >= 0; --ii)
833 if (qmlImportTrace())
835 << uri <<
" " << vmaj <<
'.' << vmin <<
" " 839 return d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, importDb, errorString);
859 if (!qmldirPluginPathIsRelative)
860 searchPaths.
prepend(qmldirPluginPath);
862 foreach (
const QString &pluginPath, searchPaths) {
867 if (qmldirPluginPathIsRelative)
872 resolvedPath = pluginPath;
879 QDir dir(resolvedPath);
881 QString pluginFileName = prefix;
883 pluginFileName += baseName;
893 if (qmlImportTrace())
894 qDebug() <<
"QDeclarativeImportDatabase::resolvePlugin: Could not resolve plugin" << baseName
923 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) 930 #elif defined(Q_OS_SYMBIAN) 937 # if defined(Q_OS_DARWIN) 951 # else // Generic Unix 954 # if defined(Q_OS_HPUX) 964 # elif defined(Q_OS_AIX) 966 # elif defined(Q_OS_UNIX) 1000 if (qmlImportTrace())
1001 qDebug().nospace() <<
"QDeclarativeImportDatabase::addPluginPath: " << path;
1018 if (qmlImportTrace())
1019 qDebug().nospace() <<
"QDeclarativeImportDatabase::addImportPath: " << path;
1062 if (qmlImportTrace())
1063 qDebug().nospace() <<
"QDeclarativeImportDatabase::importPlugin: " << uri <<
" from " << filePath;
1065 #ifndef QT_NO_LIBRARY 1070 bool typesRegistered = qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath);
1072 if (typesRegistered) {
1073 Q_ASSERT_X(qmlEnginePluginsWithRegisteredTypes()->value(absoluteFilePath) == uri,
1074 "QDeclarativeImportDatabase::importExtension",
1075 "Internal error: Plugin imported previously with different uri");
1078 if (!engineInitialized || !typesRegistered) {
1081 *errorString = tr(
"File name case mismatch for \"%1\"").
arg(absoluteFilePath);
1086 if (!loader.
load()) {
1095 const char *moduleId = bytes.
constData();
1096 if (!typesRegistered) {
1099 qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath, uri);
1100 iface->registerTypes(moduleId);
1102 if (!engineInitialized) {
1107 iface->initializeEngine(
engine, moduleId);
The QDir class provides access to directory structures and their contents.
static QString urlToLocalFileOrQrc(const QUrl &url)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QDeclarativeImports & operator=(const QDeclarativeImports &)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
bool add(const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString &uri_arg, const QString &prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QDeclarativeImportDatabase *database, QString *errorString)
#define QT_END_NAMESPACE
This macro expands to.
QString errorString() const
Returns a text string with the description of the last error that occurred.
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
QDeclarativeImportDatabase(QDeclarativeEngine *)
const QChar at(int i) const
Returns the character at the given index position in the string.
QDir dir() const
Returns the path of the object's parent directory as a QDir object.
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
static bool greaterThan(const QString &s1, const QString &s2)
#define it(className, varName)
bool load()
Loads the plugin and returns true if the plugin was loaded successfully; otherwise returns false...
bool addImport(QDeclarativeImportDatabase *, const QString &uri, const QString &prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, const QDeclarativeDirComponents &qmldircomponentsnetwork, QString *errorString)
Adds information to imports such that subsequent calls to resolveType() will resolve types qualified ...
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
QList< QDeclarativeError > errors(const QString &uri) const
QString & replace(int i, int len, QChar after)
The QByteArray class provides an array of bytes.
void chop(int n)
Removes n characters from the end of the string.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
int length() const
Returns the number of characters in this string.
QString resolvedUri(const QString &dir_arg, QDeclarativeImportDatabase *database)
QSet< QString > qmlDirFilesForWhichPluginsHaveBeenLoaded
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
void add(const QString &, int)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes)
bool importPlugin(const QString &filePath, const QString &uri, QString *errorString)
QString absoluteFilePath() const
Returns an absolute path including the file name.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
bool resolveType(const QByteArray &type, QDeclarativeType **type_return, QUrl *url_return, int *version_major, int *version_minor, QDeclarativeImportedNamespace **ns_return, QString *errorString=0) const
The given (namespace qualified) type is resolved to either.
int count(const T &t) const
Returns the number of occurrences of value in the list.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
QStringList filePluginPath
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
bool find(QDeclarativeTypeLoader *typeLoader, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, QString *errorString=0)
QSet< QString > initializedPlugins
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
The QChar class provides a 16-bit Unicode character.
QHash< QString, QDeclarativeImportedNamespace *> set
The QDeclarativeImports class encapsulates one QML document's import statements.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Q_CORE_EXPORT void qDebug(const char *,...)
bool QDeclarative_isFileCaseCorrect(const QString &fileName)
Returns true if the case of fileName is equivalent to the file case of fileName on disk...
static QString toString(Register *reg, int type, bool *ok=0)
void append(const T &t)
Inserts value at the end of the list.
static QString applicationDirPath()
Returns the directory that contains the application executable.
QUrl baseUrl() const
Returns the base URL to be used for all relative file imports added.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QList< Component > components() const
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
QStringList pluginPathList() const
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
bool contains(const T &value) const
void addPluginPath(const QString &path)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
QDeclarativeImportsPrivate * d
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
void setImportPathList(const QStringList &paths)
void prepend(const T &t)
Inserts value at the beginning of the list.
const T & at(int i) const
Returns the item at index position i in the list.
~QDeclarativeImportsPrivate()
QString description() const
Returns the error description.
The QStringList class provides a list of strings.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
const_iterator insert(const T &value)
QDeclarativeImportsPrivate(QDeclarativeTypeLoader *loader)
static QDeclarativeTypeNameCache * cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeImportedNamespace &set, QDeclarativeTypeNameCache *cache)
#define DEFINE_BOOL_CONFIG_OPTION(name, var)
const QDeclarativeDirParser * qmlDirParser(const QString &absoluteFilePath)
Return a QDeclarativeDirParser for absoluteFilePath.
Q_OUTOFLINE_TEMPLATE void qReverse(RandomAccessIterator begin, RandomAccessIterator end)
QByteArray qmlTypeName() const
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName, const QStringList &suffixes, const QString &prefix=QString())
Returns the result of the merge of baseName with path, suffixes, and prefix.
QDeclarativeEngine * engine
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
void setPluginPathList(const QStringList &paths)
void populateCache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const
QString scheme() const
Returns the scheme of the URL.
#define Q_ASSERT_X(cond, where, what)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
void addImportPath(const QString &dir)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
QStringList importPathList() const
The QDeclarativeEngine class provides an environment for instantiating QML components.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QDeclarativeImportedNamespace * findNamespace(const QString &type)
QStringList fileImportPath
static QString location(LibraryLocation)
Returns the location specified by loc.
int size() const
Returns the number of items in the list.
QString canonicalPath() const
Returns the canonical path, i.e.
bool find_helper(QDeclarativeTypeLoader *typeLoader, int i, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, bool *typeRecursionDetected=0)
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
QDeclarativeTypeNameCache * typeNamespace
bool importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeImportDatabase *database, QDeclarativeDirComponents *components, QString *errorString)
void setBaseUrl(const QUrl &url)
Sets the base URL to be used for all relative file imports added.
~QDeclarativeImportDatabase()
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
QString absoluteFilePath(const QString &path)
Returns the absolute filename of path via a directory cache for files named "qmldir", "*.qml", "*.js" Returns a empty string if the path does not exist.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
QObject * instance()
Returns the root component object of the plugin.
QDeclarativeImportedNamespace unqualifiedset
QDeclarativeTypeLoader * typeLoader
bool find(const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QString *errorString)
Data * data(const QString &) const
char at(int i) const
Returns the character at index position i in the byte array.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
The QFileInfo class provides system-independent file information.
QMap< QString, QString > StringStringMap
#define qPrintable(string)
QList< QDeclarativeDirComponents > qmlDirComponents
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool availableInVersion(int vmajor, int vminor) const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
QList< Plugin > plugins() const
The QDeclarativeImportDatabase class manages the QML imports for a QDeclarativeEngine.
The QPluginLoader class loads a plugin at run-time.