About Hybrid Share
Hybrid Share is a User Friendly Application for Mac, Windows and Linux users, that allow you to Share file (and Talk) istantly with your friends...
Hybrid Share RSS Month's News
November 2017 News
Powered By
SourceForge.net Logo

How to write a Hybrid Share plug-in

You could expand Hybrid Share using Plugins. So, in this mini lesson I'll try to teach you, how could you write Hybrid Share Plugin. First you need to have installed Hybrid Share Core. Check with "pkg-config --list-all" if you have 'hybrid-share-plugin', if there isn't in your system you have to install it (Install Hybrid Share Package or compile Hybrid Share Core).

Now We're ready to write something. Simple Hybrid Share Plugin is composed by two Files (classes):

  • Info.cs - That contains the Plugin's Information
  • PluginName.cs - That contains the Plugin Code

Obviously you could use more classes if your plugin requires that.

In This Examples, will see how to open Informations Dialog when Main Window is opened.

Ok, Open your favourite Text Editor (vim, gedit, ...) and write this piece of code. This class it used by Plugin Manager to Lookup plugin and to decide when load it, using priority (negative number start as first). Remember to Set Namespace as HybridShare.Plugins.MY_PLUGIN_NAME.

// [ Info.cs ]
using System;
using HybridShare;
using HybridShare.PluginLib;

namespace HybridShare.Plugins.HelloPlugin {
   // Plugin Informations Class
   public class Info : PluginInfo {
      public Info() {
         this.authors = new string[] {
             "Matteo Bertozzi"

         this.priority = 0;
         this.version = "0.1";
         this.name = "Hello Plugin";
         this.web = "http://hybrid-share.sf.net";

The Second step is writing the Plugin's Main Class. You have to create a new class that extends Plugin Abstract Class (HybridShare.PluginLib.Plugin).

When Plugin Manager load your plugin, it create first an instance of your class, so it call Your Constructor and then it Run Initialize() Method, so you have to overload it from base class (Plugin). At Initialize() Method will be passed the Hybrid Share Application Interface (HybridShare.PluginLib.IHybridShare), this object permits you to comunicate with all the applications. Another method that you have to implement is Uninitialize() that will be called by Plugin Manager when the application is going to shutdown.

Hybrid Share and Niry Sharp have many utility classes already implemented, so take a look at the API Documentations. Documentation of Hybrid Share Core/Plugin API is very useful when you are implementing plugin, so take a look at it.

...But now, re-open your favourite text editor and write the main class. You need to instance your Info class into the Plugin Constructor, and then you have to implement Initialize() and Uninitialize(). In This example i've used the Hybrid Share Application Instance to Add Event when the Main Window is started, so when the event arrive we could run our Information Message Dialog.

// [ HelloPlugin.cs ]
using HybridShare;
using HybridShare.Utils;
using HybridShare.GUI.Base;
using HybridShare.PluginLib;

namespace HybridShare.Plugins.HelloPlugin {
   public class HelloPlugin : Plugin {
      private IHybridShare hybridShare = null;

      // Class Constructors
      public HelloPlugin() {
         // Initialize Plugin Info
         this.pluginInfo = new Info();

      // Initialize Plugin
      public override void Initialize (IHybridShare iHybridShare) {
         this.hybridShare = iHybridShare;

         // Initialize GUI Events
         hybridShare.MainWindowStarted += new BlankEventHandler(OnMainWinStart);

      // UnInitialize Plugin
      public override void Uninitialize() {

      // Main Window Started Event Handler
      private void OnMainWinStart (object sender) {
            Dialogs.MessageInfo("Hello World Plugin", "This is a Test!");

And Finally we have to compile our code. Open your favourite shell and Run the compilation command (I use gmcs insted mcs because this one support .NET 2.0), Remember that you need to compile as Library (dll).

gmcs -target:library HelloPlugin.cs Info.cs -out:helloPlugin.dll

Once that compiler has finished its work, you could copy your dll into Plugins Directory. There're two places where Hybrid Share looks for plugins. The first is into Application Installation Path into Plugins Folder. And the second is in the user's home at "~/.hybrid-share-1.x/Plugins/". The first is visibile from all your machine users, The second its only of that user, so choose what's better for you.

The Last Step of This Mini-Lesson is try the Plugin. Run Hybrid Share, Do Login if Auto Login is not set, and you'll find you "Hello World" information dialog...

For more informations you could contact me (theo.bertozzi@gmail.com).