2 #include "example_plugin.h"
3 #include "example_settings_page.h"
4 #include "simple_viewer.h"
6 #include "../core/icore.h"
7 #include "../core/core_constants.h"
8 #include "../core/menu_manager.h"
10 #include "../../extension_system/iplugin_spec.h"
13 #include "nel/misc/debug.h"
16 #include <QtCore/QObject>
17 #include <QtGui/QMessageBox>
18 #include <QtGui/QMainWindow>
19 #include <QtGui/QMenu>
20 #include <QtGui/QAction>
21 #include <QtGui/QMenuBar>
26 ExamplePlugin::ExamplePlugin()
30 ExamplePlugin::~ExamplePlugin()
32 Q_FOREACH(QObject
*obj
, m_autoReleaseObjects
)
34 m_plugMan
->removeObject(obj
);
36 qDeleteAll(m_autoReleaseObjects
);
37 m_autoReleaseObjects
.clear();
40 bool ExamplePlugin::initialize(ExtensionSystem::IPluginManager
*pluginManager
, QString
*errorString
)
42 Q_UNUSED(errorString
);
43 m_plugMan
= pluginManager
;
45 addAutoReleasedObject(new ExampleSettingsPage(this));
46 addAutoReleasedObject(new ExampleContext(this));
47 addAutoReleasedObject(new ExampleCoreListener(this));
51 void ExamplePlugin::extensionsInitialized()
53 Core::ICore
*core
= Core::ICore::instance();
54 Core::MenuManager
*menuManager
= core
->menuManager();
55 QAction
*exampleAction1
= new QAction("Example1", this);
56 QAction
*exampleAction2
= new QAction("Example2", this);
57 QAction
*aboutQtAction
= menuManager
->action(Core::Constants::ABOUT_QT
);
58 QMenu
*helpMenu
= menuManager
->menu(Core::Constants::M_HELP
);
59 helpMenu
->insertAction(aboutQtAction
, exampleAction1
);
60 helpMenu
->addSeparator();
61 helpMenu
->addAction(exampleAction2
);
62 menuManager
->menuBar()->addMenu("ExampleMenu");
65 void ExamplePlugin::setNelContext(NLMISC::INelContext
*nelContext
)
68 // Ensure that a context doesn't exist yet.
69 // This only applies to platforms without PIC, e.g. Windows.
70 nlassert(!NLMISC::INelContext::isContextInitialised());
71 #endif // NL_OS_WINDOWS
72 m_LibContext
= new NLMISC::CLibraryContext(*nelContext
);
75 void ExamplePlugin::addAutoReleasedObject(QObject
*obj
)
77 m_plugMan
->addObject(obj
);
78 m_autoReleaseObjects
.prepend(obj
);
83 Q_EXPORT_PLUGIN(Plugin::ExamplePlugin
)