equal
deleted
inserted
replaced
19 #include <QDir> |
19 #include <QDir> |
20 #include <QFileInfo> |
20 #include <QFileInfo> |
21 #include <QPluginLoader> |
21 #include <QPluginLoader> |
22 #include <cpplugininterface.h> |
22 #include <cpplugininterface.h> |
23 #include <cppluginplatinterface.h> |
23 #include <cppluginplatinterface.h> |
24 #include "cpbasepath.h" |
24 #include <cplauncherinterface.h> |
|
25 #include <cpbasepath.h> |
25 #include "cputility.h" |
26 #include "cputility.h" |
26 #include <cplogger.h> |
27 #include <cplogger.h> |
27 |
28 |
28 |
29 |
29 /*! |
30 /*! |
35 #define PLUGINFILE_SUFFIX "dll" |
36 #define PLUGINFILE_SUFFIX "dll" |
36 #else |
37 #else |
37 #define PLUGINFILE_SUFFIX "qtplugin" |
38 #define PLUGINFILE_SUFFIX "qtplugin" |
38 #endif |
39 #endif |
39 |
40 |
40 template <typename PLUGIN> |
41 template <typename INTERFACE> |
41 static PLUGIN* loadPlugin(const QString &pluginFile) |
42 static INTERFACE* loadPluginInterface(const QString &pluginFile) |
42 { |
43 { |
43 CPPERF_LOG( QLatin1String("Loading plugin: ") + pluginFile ); |
44 CPPERF_LOG( QLatin1String("Loading plugin: ") + pluginFile ); |
44 |
45 |
45 QFileInfo fileInfo(pluginFile); |
46 QFileInfo fileInfo(pluginFile); |
46 |
47 |
59 } |
60 } |
60 } |
61 } |
61 } |
62 } |
62 |
63 |
63 QPluginLoader loader(fileInfo.absoluteFilePath()); |
64 QPluginLoader loader(fileInfo.absoluteFilePath()); |
64 PLUGIN *plugin = qobject_cast<PLUGIN*> (loader.instance()); |
65 INTERFACE *plugin = qobject_cast<INTERFACE*> (loader.instance()); |
65 if (!plugin) { |
66 if (!plugin) { |
66 loader.unload(); |
67 loader.unload(); |
67 } |
68 } |
68 |
69 |
69 CPPERF_LOG( QLatin1String("Load plugin ") + (plugin ? QLatin1String("succeed.") : QLatin1String("failed.")) ); |
70 CPPERF_LOG( QLatin1String("Load plugin ") + (plugin ? QLatin1String("succeed.") : QLatin1String("failed.")) ); |
82 C:/resource/qt/plugins/controlpanel/sampleplugin.dll |
83 C:/resource/qt/plugins/controlpanel/sampleplugin.dll |
83 */ |
84 */ |
84 |
85 |
85 CpPluginInterface *CpPluginLoader::loadCpPlugin(const QString &pluginFile) |
86 CpPluginInterface *CpPluginLoader::loadCpPlugin(const QString &pluginFile) |
86 { |
87 { |
87 return loadPlugin<CpPluginInterface>(pluginFile); |
88 return ::loadPluginInterface<CpPluginInterface>(pluginFile); |
88 } |
89 } |
89 |
90 |
90 |
91 |
91 /*! |
92 /*! |
92 \deprecated CpPluginPlatInterface *CpPluginLoader::loadPlatCpPlugin(const QString &) is deprecated. |
93 \deprecated CpPluginPlatInterface *CpPluginLoader::loadPlatCpPlugin(const QString &) is deprecated. |
93 please use CpPluginInterface to implement controlpanel plugin and use CpPluginLoader::loadCpPlugin(const QString &) to load the plugin. |
94 please use CpPluginInterface to implement controlpanel plugin and use CpPluginLoader::loadCpPluginInterface(const QString &) to load the plugin. |
94 */ |
95 */ |
95 |
96 |
96 CpPluginPlatInterface *CpPluginLoader::loadPlatCpPlugin(const QString &pluginFile) |
97 CpPluginPlatInterface *CpPluginLoader::loadPlatCpPlugin(const QString &pluginFile) |
97 { |
98 { |
98 return loadPlugin<CpPluginPlatInterface>(pluginFile); |
99 return ::loadPluginInterface<CpPluginPlatInterface>(pluginFile); |
|
100 } |
|
101 |
|
102 CpPluginInterface *CpPluginLoader::loadCpPluginInterface(const QString &pluginFile) |
|
103 { |
|
104 return ::loadPluginInterface<CpPluginInterface>(pluginFile); |
|
105 } |
|
106 |
|
107 CpLauncherInterface *CpPluginLoader::loadCpLauncherInterface(const QString &pluginFile) |
|
108 { |
|
109 return ::loadPluginInterface<CpLauncherInterface>(pluginFile); |
99 } |
110 } |
100 |
111 |
101 |
112 |