OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / pluginmanager / widgetpluginpath.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef WIDGETPLUGINPATH_H
34 #define WIDGETPLUGINPATH_H
35
36 #include "widgetpluginmanager.h"
37
38 #include <QtCore/QObject>
39 #include <QWeakPointer>
40 #include <QtCore/QList>
41 #include <QtCore/QDir>
42 #include <QtGui/QStandardItem>
43
44 QT_BEGIN_NAMESPACE
45 class QString;
46 class QAbstractItemModel;
47 QT_END_NAMESPACE
48
49 namespace QmlDesigner {
50 class IWidgetPlugin;
51 namespace Internal {
52
53
54
55 // Dumb plugin data structure. Note that whereas QObjects can
56 // casted to an interface, QWeakPointer does not work with the
57 // interface class, so, we need a separate QWeakPointer as a guard
58 // to detect the deletion of a plugin instance which can happen
59 // in theory.
60 struct WidgetPluginData {
61     WidgetPluginData(const QString &p = QString());
62
63     QString path;
64     bool failed;
65     QString errorMessage;
66     QWeakPointer<QObject> instanceGuard;
67     IWidgetPlugin *instance;
68 };
69
70
71 // PluginPath: Manages a plugin directory. It does nothing
72 // on construction following the "as lazy as possible" principle.
73 // In the "loaded" stage, it scans the directories and creates
74 // a list of PluginData for the libraries found.
75 // getInstances() will return the fully initialized list of
76 // IPlugins.
77
78 class WidgetPluginPath {
79 public:
80     explicit WidgetPluginPath(const QDir &path);
81
82
83     void getInstances(WidgetPluginManager::IWidgetPluginList *list);
84
85     QDir path() const { return m_path; }
86
87     //  Convenience to populate a "About Plugin" dialog with
88     // plugins from that path. Forces initialization.
89     QStandardItem *createModelItem();
90
91 private:
92     typedef QList<WidgetPluginData> PluginDataList;
93
94     static QStringList libraryFilePaths(const QDir &dir);
95     void clear();
96     void ensureLoaded();
97
98     QDir m_path;
99     bool m_loaded;
100     PluginDataList m_plugins;
101 };
102
103 } // namespace Internal
104 } // namespace QmlDesigner
105 #endif // WIDGETPLUGINPATH_H