Re: How to make a new add-in for GNote.



On 10-09-23 2:54 AM, Aurimas Černius wrote:
Hi,

I want to start a new add in for GNote but I do not know how to do it.

I think the best thing to do it is to simply take a look at source code
of existing Gnote addins.

And if anybody wants to add this to the repository, here is a little write up on how the module system works that I wrote last year.

This should help.

Hub

This is the addin framework from gnote. It is meant
to provide lean a mean module implementing several interfaces.

Modules declaration:

-Create a class MyModule that inherite from sharp::DynamicModule.
-Implement the various virtual functions needed for a module
 (see DynamicModule.hpp)
-You need to declare the entry point using:
  DECLARE_MODULE(MyModule);

Module implementation:

The module implementation is a factory to instanciate the 
interfaces implementations.

-In the module contructor you must declare the interfaces 
 implementation using:
  ADD_INTERFACE(MyInterfaceImplementation)
 MyInterfaceImplementation is one of the interface you implement. 
 There can be any number for the module. It is the name of the 
 class whose declaration should be accesssible.
-MyModule::id() returns a unique id, which is a string.

Generic Interface:

A generic interface define an interface for the module functionality.
This is how the app will call your module.
-A generic interface is class that inherit from sharp::IInterface and 
sigc::trackable.
-It should define the following static member:
  static const char * IFACE_NAME;
 Its value is a string. It should be unique to all the interfaces
 and this is how we will know what your module provides.

Interface Implementation

-MyInterfaceImplementation inherit for said generic interface.
-MyInterfaceImplementation should define and implement a static 
constructor with the following signature and implementation.
 static MyInterface *MyInterface::create()
 { return new MyInterface; }

Loading Modules:

-Declare an instance of sharp::ModuleManager.
-Call add_path() to add directories where to load modules from
-Call load_modules() to load them all.
-Call get_modules() to obtain the list of loaded modules.

Querying interfaces:

-On the module ask it if implements an interface with has_interface()
-Ask for the interface using query_interface() and obtain a IfaceFactoryBase*
-Intanciate the interface.

Sample code:

  sharp::ModuleManager module_manager;
  module_manager.add_path("/usr/local/share/myapp/addins");
  module_manager.load_modules();
  const sharp::ModuleList & modules = module_manager.get_modules();

  for(sharp::ModuleList::const_iterator iter = modules.begin();
    iter != modules.end() ++iter) {
      const DynamicModule * dynamicmodule = *iter;
      if(dynamicmodule->has_interface("foo::MyInterface")) {
          IfaceFactoryBase *factory = dynamicmodule->query_interface("foo::MyInterface");
	  MyInterface * iface = factory();
    	  // ...
      }
  }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]