File indexing completed on 2024-05-12 16:39:39
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> 0003 Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KEXIPARTMANAGER_H 0022 #define KEXIPARTMANAGER_H 0023 0024 //! @todo KEXI3 #include "kexistaticpart.h" 0025 #include "kexiinternalpart.h" 0026 0027 #include <KDbResult> 0028 0029 class KexiInternal; 0030 0031 namespace KexiPart 0032 { 0033 class Info; 0034 class Part; 0035 0036 typedef QHash<QString, Info*> PartInfoDict; 0037 typedef QHash<QString, Info*>::iterator PartInfoDictIterator; 0038 typedef QList<Info*> PartInfoList; 0039 typedef QList<Info*>::iterator PartInfoListIterator; 0040 typedef QHash<QString, Part*> PartDict; 0041 0042 /** 0043 * @short KexiPart's manager: looks up and instantiates KexiPart-based plugins 0044 * 0045 * It creates instances only when needed. 0046 */ 0047 class KEXICORE_EXPORT Manager : public QObject, public KDbResultable 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 ~Manager(); 0053 0054 /** 0055 * \return a part object for specified plugin ID @a pluginId, e.g. "org.kexi-project.table" 0056 * @note For compatibility with Kexi <= 2, if a string without any dot is provided, "org.kexi-project." 0057 * will be prepended to the ID. 0058 * Dynamically loads a plugin using KexiPart::Info if needed. Returns 0 if loading failed. 0059 */ 0060 Part *partForPluginId(const QString& pluginId); 0061 0062 /** 0063 * \return a part object for specified info. Dlopens a part using KexiPart::Info 0064 * if needed. Return 0 if loading failed. 0065 */ 0066 Part *part(Info *info); 0067 0068 /** 0069 * \return the info for a corresponding plugin ID, e.g. "org.kexi-project.table" 0070 * @note For compatibility with Kexi <= 2, if a string without any dot is provided, "org.kexi-project." 0071 * will be prepended to the ID. 0072 */ 0073 Info *infoForPluginId(const QString& pluginId); 0074 0075 /** 0076 * @return a list of the available KexiParts-based plugins in a well-defined order 0077 * Can return 0 if no plugins have been found, what means the installation is broken. 0078 */ 0079 PartInfoList* infoList(); 0080 0081 Q_SIGNALS: 0082 void partLoaded(KexiPart::Part*); 0083 void newObjectRequested(KexiPart::Info *info); 0084 0085 protected: 0086 //! Used by StaticPart 0087 //! @todo KEXI3 void insertStaticPart(KexiPart::StaticPart* part); 0088 0089 //! Used by KexiInternalPart 0090 KexiInternalPart* internalPartForPluginId(const QString& pluginId); 0091 0092 private: 0093 /** 0094 * creates an empty instance 0095 */ 0096 explicit Manager(QObject *parent = 0); 0097 0098 /** 0099 * Queries the plugin system and creates a list of available parts. 0100 * @return false if required servicetype was not found (what means the installation is broken). 0101 */ 0102 //! @todo Allow refreshing!!!! (will need calling removeClient() by Part objects) 0103 //! @todo This method generates a few warnings, maybe we want to optionally display them somewhere (via the message handler)? 0104 bool lookup(); 0105 0106 template <typename PartClass> 0107 PartClass* part(Info *info, QHash<QString, PartClass*> *partDict); 0108 0109 Q_DISABLE_COPY(Manager) 0110 0111 class Private; 0112 Private* const d; 0113 0114 //! @todo KEXI3 friend KexiPart::StaticPart::StaticPart(const QString&, const QString&, const QString&); 0115 friend class ::KexiInternal; 0116 friend KexiInternalPart* KexiInternalPart::part(KDbMessageHandler*, const QString&); 0117 }; 0118 0119 } 0120 0121 #endif