home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / private / qpluginmanager_p.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  6KB  |  212 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qpluginmanager_p.h   3.0.0   edited Sep 20 19:46 $
  3. **
  4. ** Definition of QPluginManager class
  5. **
  6. ** Created : 2000-01-01
  7. **
  8. ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QPLUGINMANAGER_H
  39. #define QPLUGINMANAGER_H
  40.  
  41. #ifndef QT_H
  42. #include "qgpluginmanager_p.h"
  43. #include "qstringlist.h"
  44. #include "qcomlibrary_p.h"
  45. #endif // QT_H
  46.  
  47. //
  48. //  W A R N I N G
  49. //  -------------
  50. //
  51. // This file is not part of the Qt API.  It exists for the convenience
  52. // of a number of Qt sources files.  This header file may change from
  53. // version to version without notice, or even be removed.
  54. //
  55. // We mean it.
  56. //
  57. //
  58.  
  59. #ifndef QT_NO_COMPONENT
  60.  
  61. template<class Type>
  62. class Q_EXPORT QPluginManager : public QGPluginManager
  63. {
  64. public:
  65.     QPluginManager( const QUuid& id, const QStringList& paths = QString::null, const QString &suffix = QString::null, bool cs = TRUE )
  66.     : QGPluginManager( id, cs )
  67.     {
  68.     for ( QStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it ) {
  69.         QString path = *it;
  70.         addLibraryPath( path + suffix );
  71.     }
  72.     }
  73.  
  74.     QPluginManager( const QUuid &id, const QString &file, bool cs = TRUE )
  75.     : QGPluginManager( id, cs )
  76.     {
  77.     addLibrary( file );
  78.     }
  79.  
  80.     QLibrary* addLibrary( const QString& file )
  81.     {
  82.     if ( file.isEmpty() )
  83.         return 0;
  84.  
  85.     QComLibrary *plugin = (QComLibrary*)libDict[file];
  86.     if ( plugin )
  87.         return plugin;
  88.  
  89.     // Create a library object, and try to get the desired interface
  90.     plugin = new QComLibrary( file );
  91.  
  92.     bool useful = FALSE;
  93.  
  94.     Type* iFace = 0;
  95.     plugin->queryInterface( interfaceId, (QUnknownInterface**) &iFace );
  96.     if ( iFace ) {
  97.         QFeatureListInterface *fliFace = 0;
  98.         QComponentInformationInterface *cpiFace = 0;
  99.         iFace->queryInterface( IID_QFeatureList, (QUnknownInterface**)&fliFace );
  100.         if ( !fliFace )
  101.         plugin->queryInterface( IID_QFeatureList, (QUnknownInterface**)&fliFace );
  102.         if ( !fliFace ) {
  103.         iFace->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
  104.         if ( !cpiFace )
  105.             plugin->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
  106.         }
  107.         QStringList fl;
  108.         if ( fliFace )
  109.         // Map all found features to the library
  110.         fl = fliFace->featureList();
  111.         else if ( cpiFace )
  112.         fl << cpiFace->name();
  113.  
  114.         for ( QStringList::Iterator f = fl.begin(); f != fl.end(); f++ ) {
  115.         useful = TRUE;
  116. #ifdef QT_CHECK_RANGE
  117.         QLibrary *old = 0;
  118.         if ( !(old = plugDict[*f]) )
  119.             plugDict.replace( *f, plugin );
  120.         else
  121.             qWarning("%s: Feature %s already defined in %s!", plugin->library().latin1(), (*f).latin1(), old->library().latin1() );
  122. #else
  123.         plugDict.replace( *f, plugin );
  124. #endif
  125.         }
  126.         if ( fliFace )
  127.         fliFace->release();
  128.         if ( cpiFace )
  129.         cpiFace->release();
  130.         iFace->release();
  131.     }
  132.  
  133.     if ( useful ) {
  134.         libDict.replace( file, plugin );
  135.         if ( !libList.contains( file ) )
  136.         libList.append( file );
  137.         return plugin;
  138.     } else {
  139.         delete plugin;
  140.         libList.remove( file );
  141.         return 0;
  142.     }
  143.     }
  144.  
  145.     bool removeLibrary( const QString& file )
  146.     {
  147.     if ( file.isEmpty() )
  148.         return FALSE;
  149.  
  150.     libList.remove( file );
  151.  
  152.     QComLibrary* plugin = (QComLibrary*)libDict[ file ];
  153.     if ( !plugin )
  154.         return FALSE;
  155.  
  156.     // Unregister all features of this plugin
  157.     Type *iFace = 0;
  158.     plugin->queryInterface( interfaceId, (QUnknownInterface**)&iFace );
  159.     if ( iFace ) {
  160.         QFeatureListInterface *fliFace = 0;
  161.         QComponentInformationInterface *cpiFace = 0;
  162.         iFace->queryInterface( IID_QFeatureList, (QUnknownInterface**)&iFace );
  163.         if ( !fliFace )
  164.         plugin->queryInterface( IID_QFeatureList, (QUnknownInterface**)&fliFace );
  165.         if ( !fliFace ) {
  166.         iFace->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
  167.         if ( !cpiFace )
  168.             plugin->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
  169.         }
  170.         QStringList fl;
  171.         if ( fliFace )
  172.         fl = fliFace->featureList();
  173.         else if ( cpiFace )
  174.         fl << cpiFace->name();
  175.  
  176.         for ( QStringList::Iterator f = fl.begin(); f != fl.end(); f++ ) {
  177.         plugDict.remove( *f );
  178.         }
  179.  
  180.         if ( fliFace )
  181.         fliFace->release();
  182.         if ( cpiFace )
  183.         cpiFace->release();
  184.         iFace->release();
  185.     }
  186.     bool unloaded = plugin->unload();
  187.     // This deletes the QLibrary object!
  188.     libDict.remove( file );
  189.  
  190.     return unloaded;
  191.     }
  192.  
  193.     QRESULT queryInterface(const QString& feature, Type** iface) const
  194.     {
  195.     QComLibrary* plugin = 0;
  196.     plugin = (QComLibrary*)library( feature );
  197.  
  198.     return plugin ? plugin->queryInterface( interfaceId, (QUnknownInterface**)iface ) : QE_NOINTERFACE;
  199.     }
  200.  
  201. #ifdef Q_QDOC
  202. #error "The Symbol Q_QDOC is reserved for documentation purposes."
  203.     void addLibraryPath( const QString& path );
  204.     const QLibrary* library( const QString& feature ) const;
  205.     QStringList featureList() const;
  206. #endif
  207. };
  208.  
  209. #endif //QT_NO_COMPONENT
  210.  
  211. #endif //QPLUGINMANAGER_H
  212.