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 QtVersitOrganizer 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
34#ifndef QVERSITORGANIZERPLUGINSEARCH_H
35#define QVERSITORGANIZERPLUGINSEARCH_H
36
37//
38// W A R N I N G
39// -------------
40//
41// This file is not part of the Qt API. It exists purely as an
42// implementation detail. This header file may change from version to
43// version without notice, or even be removed.
44//
45// We mean it.
46//
47
48#include <QtCore/qcoreapplication.h>
49#if !defined QT_NO_DEBUG
50#include <QtCore/qdebug.h>
51#endif
52#include <QtCore/qdir.h>
53#include <QtCore/qstringlist.h>
54
55#include <QtVersitOrganizer/qversitorganizerglobal.h>
56
57QT_BEGIN_NAMESPACE_VERSITORGANIZER
58
59#define CHECKDIR(dir) (dir).exists()
60
61inline QStringList mobilityPlugins(const QString& plugintype)
62{
63#if !defined QT_NO_DEBUG
64 const bool showDebug = qgetenv(varName: "QT_DEBUG_PLUGINS").toInt() > 0;
65#endif
66
67 QStringList paths = QCoreApplication::libraryPaths();
68#ifdef QTM_PLUGIN_PATH
69 paths << QLatin1String(QTM_PLUGIN_PATH);
70#endif
71#if !defined QT_NO_DEBUG
72 if (showDebug)
73 qDebug() << "Plugin paths:" << paths;
74#endif
75
76 // Temp variable to avoid multiple identical paths
77 // (we don't convert the list to set first, because that loses the order)
78 QSet<QString> processed;
79
80 /* The list of discovered plugins */
81 QStringList plugins;
82
83 /* Enumerate our plugin paths */
84 for (int i=0; i < paths.count(); i++) {
85 if (processed.contains(value: paths.at(i)))
86 continue;
87 processed.insert(value: paths.at(i));
88 QDir pluginsDir(paths.at(i));
89 if (!CHECKDIR(pluginsDir))
90 continue;
91
92#if defined(Q_OS_WIN)
93 if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
94 pluginsDir.cdUp();
95#elif defined(Q_OS_MAC)
96 if (pluginsDir.dirName() == QLatin1String("MacOS")) {
97 pluginsDir.cdUp();
98 pluginsDir.cdUp();
99 pluginsDir.cdUp();
100 }
101#endif
102
103 QString subdir(QStringLiteral("plugins/"));
104 subdir += plugintype;
105 if (pluginsDir.path().endsWith(QStringLiteral("/plugins"))
106 || pluginsDir.path().endsWith(QStringLiteral("/plugins/")))
107 subdir = plugintype;
108
109 if (CHECKDIR(QDir(pluginsDir.filePath(subdir)))) {
110 pluginsDir.cd(dirName: subdir);
111 QStringList files = pluginsDir.entryList(filters: QDir::Files);
112
113#if !defined QT_NO_DEBUG
114 if (showDebug)
115 qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files;
116#endif
117
118 for (int j=0; j < files.count(); j++) {
119 plugins << pluginsDir.absoluteFilePath(fileName: files.at(i: j));
120 }
121 }
122 }
123
124 /* Add application path + plugintype */
125 QDir appldir(QCoreApplication::applicationDirPath());
126 if(appldir.cd(dirName: plugintype)){
127 if (!processed.contains(value: appldir.absolutePath())){
128 processed.insert(value: appldir.absolutePath());
129 QStringList files = appldir.entryList(filters: QDir::Files);
130#if !defined QT_NO_DEBUG
131 if (showDebug)
132 qDebug() << "Looking for " << plugintype << " plugins in" << appldir.path() << files;
133#endif
134 for (int j=0; j < files.count(); j++) {
135 plugins << appldir.absoluteFilePath(fileName: files.at(i: j));
136 }
137 }
138 }
139
140 return plugins;
141}
142
143QT_END_NAMESPACE_VERSITORGANIZER
144
145#endif // QVERSITORGANIZERPLUGINSEARCH_H
146

source code of qtpim/src/versitorganizer/qversitorganizerpluginsearch_p.h