1 /* This file is part of the KDE project
2    Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
3    Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef KEXIPARTMANAGER_H
22 #define KEXIPARTMANAGER_H
23 
24 //! @todo KEXI3 #include "kexistaticpart.h"
25 #include "kexiinternalpart.h"
26 
27 #include <KDbResult>
28 
29 class KexiInternal;
30 
31 namespace KexiPart
32 {
33 class Info;
34 class Part;
35 
36 typedef QHash<QString, Info*> PartInfoDict;
37 typedef QHash<QString, Info*>::iterator PartInfoDictIterator;
38 typedef QList<Info*> PartInfoList;
39 typedef QList<Info*>::iterator PartInfoListIterator;
40 typedef QHash<QString, Part*> PartDict;
41 
42 /**
43  * @short KexiPart's manager: looks up and instantiates KexiPart-based plugins
44  *
45  * It creates instances only when needed.
46  */
47 class KEXICORE_EXPORT Manager : public QObject, public KDbResultable
48 {
49     Q_OBJECT
50 
51 public:
52     ~Manager();
53 
54     /**
55      * \return a part object for specified plugin ID @a pluginId, e.g. "org.kexi-project.table"
56      * @note For compatibility with Kexi <= 2, if a string without any dot is provided, "org.kexi-project."
57      *       will be prepended to the ID.
58      * Dynamically loads a plugin using KexiPart::Info if needed. Returns 0 if loading failed.
59      */
60     Part *partForPluginId(const QString& pluginId);
61 
62     /**
63      * \return a part object for specified info. Dlopens a part using KexiPart::Info
64      * if needed. Return 0 if loading failed.
65      */
66     Part *part(Info *info);
67 
68     /**
69      * \return the info for a corresponding plugin ID, e.g. "org.kexi-project.table"
70      * @note For compatibility with Kexi <= 2, if a string without any dot is provided, "org.kexi-project."
71      *       will be prepended to the ID.
72      */
73     Info *infoForPluginId(const QString& pluginId);
74 
75     /**
76      * @return a list of the available KexiParts-based plugins in a well-defined order
77      * Can return 0 if no plugins have been found, what means the installation is broken.
78      */
79     PartInfoList* infoList();
80 
81 Q_SIGNALS:
82     void partLoaded(KexiPart::Part*);
83     void newObjectRequested(KexiPart::Info *info);
84 
85 protected:
86     //! Used by StaticPart
87     //! @todo KEXI3 void insertStaticPart(KexiPart::StaticPart* part);
88 
89     //! Used by KexiInternalPart
90     KexiInternalPart* internalPartForPluginId(const QString& pluginId);
91 
92 private:
93     /**
94      * creates an empty instance
95      */
96     explicit Manager(QObject *parent = 0);
97 
98     /**
99      * Queries the plugin system and creates a list of available parts.
100      * @return false if required servicetype was not found (what means the installation is broken).
101      */
102     //! @todo Allow refreshing!!!! (will need calling removeClient() by Part objects)
103     //! @todo This method generates a few warnings, maybe we want to optionally display them somewhere (via the message handler)?
104     bool lookup();
105 
106     template <typename PartClass>
107     PartClass* part(Info *info, QHash<QString, PartClass*> *partDict);
108 
109     Q_DISABLE_COPY(Manager)
110 
111     class Private;
112     Private* const d;
113 
114     //! @todo KEXI3 friend KexiPart::StaticPart::StaticPart(const QString&, const QString&, const QString&);
115     friend class ::KexiInternal;
116     friend KexiInternalPart* KexiInternalPart::part(KDbMessageHandler*, const QString&);
117 };
118 
119 }
120 
121 #endif
122