1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtVersit module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33#ifndef QVERSITPLUGINSEARCH_H
34#define QVERSITPLUGINSEARCH_H
35
36//
37// W A R N I N G
38// -------------
39//
40// This file is not part of the Qt API. It exists purely as an
41// implementation detail. This header file may change from version to
42// version without notice, or even be removed.
43//
44// We mean it.
45//
46
47#include <QtCore/qcoreapplication.h>
48#if !defined QT_NO_DEBUG
49#include <QtCore/qdebug.h>
50#endif
51#include <QtCore/qdir.h>
52#include <QtCore/qstringlist.h>
53
54#include <QtVersit/qversitglobal.h>
55
56QT_BEGIN_NAMESPACE_VERSIT
57
58#define CHECKDIR(dir) (dir).exists()
59
60inline QStringList mobilityPlugins(const QString& plugintype)
61{
62#if !defined QT_NO_DEBUG
63 const bool showDebug = qgetenv(varName: "QT_DEBUG_PLUGINS").toInt() > 0;
64#endif
65
66 QStringList paths = QCoreApplication::libraryPaths();
67#ifdef QTM_PLUGIN_PATH
68 paths << QLatin1String(QTM_PLUGIN_PATH);
69#endif
70#if !defined QT_NO_DEBUG
71 if (showDebug)
72 qDebug() << "Plugin paths:" << paths;
73#endif
74
75 // Temp variable to avoid multiple identical paths
76 // (we don't convert the list to set first, because that loses the order)
77 QSet<QString> processed;
78
79 /* The list of discovered plugins */
80 QStringList plugins;
81
82 /* Enumerate our plugin paths */
83 for (int i=0; i < paths.count(); i++) {
84 if (processed.contains(value: paths.at(i)))
85 continue;
86 processed.insert(value: paths.at(i));
87 QDir pluginsDir(paths.at(i));
88 if (!CHECKDIR(pluginsDir))
89 continue;
90
91#if defined(Q_OS_WIN)
92 if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
93 pluginsDir.cdUp();
94#elif defined(Q_OS_MAC)
95 if (pluginsDir.dirName() == QLatin1String("MacOS")) {
96 pluginsDir.cdUp();
97 pluginsDir.cdUp();
98 pluginsDir.cdUp();
99 }
100#endif
101
102 QString subdir(QStringLiteral("plugins/"));
103 subdir += plugintype;
104 if (pluginsDir.path().endsWith(QStringLiteral("/plugins"))
105 || pluginsDir.path().endsWith(QStringLiteral("/plugins/")))
106 subdir = plugintype;
107
108 if (CHECKDIR(QDir(pluginsDir.filePath(subdir)))) {
109 pluginsDir.cd(dirName: subdir);
110 QStringList files = pluginsDir.entryList(filters: QDir::Files);
111
112#if !defined QT_NO_DEBUG
113 if (showDebug)
114 qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files;
115#endif
116
117 for (int j=0; j < files.count(); j++) {
118 plugins << pluginsDir.absoluteFilePath(fileName: files.at(i: j));
119 }
120 }
121 }
122
123 /* Add application path + plugintype */
124 QDir appldir(QCoreApplication::applicationDirPath());
125 if(appldir.cd(dirName: plugintype)){
126 if (!processed.contains(value: appldir.absolutePath())){
127 processed.insert(value: appldir.absolutePath());
128 QStringList files = appldir.entryList(filters: QDir::Files);
129#if !defined QT_NO_DEBUG
130 if (showDebug)
131 qDebug() << "Looking for " << plugintype << " plugins in" << appldir.path() << files;
132#endif
133 for (int j=0; j < files.count(); j++) {
134 plugins << appldir.absoluteFilePath(fileName: files.at(i: j));
135 }
136 }
137 }
138
139 return plugins;
140}
141
142QT_END_NAMESPACE_VERSIT
143
144#endif // QVERSITPLUGINSEARCH_H
145

source code of qtpim/src/versit/qversitpluginsearch_p.h