Part II. Parole Plugin Tutorial

This section explains the steps required to write a plugin for Parole using the C language interface.

A simple example can be found in the parole plugins dir shipped with the source code, the sample plugin.

As a basics, the plugin needs to implement ParoleProviderPlugin interface, That is, the player use this interface to get if the plugin is configurable, to ask it to show its properties dialog when needed, to set the ParoleProviderPlayer interface used by plugins to access the the Parole player backend.

Plugin structure.

sample-plugin.c
#include "src/misc/parole.h"

#include "src/plugins/sample/sample-provider.h"

G_MODULE_EXPORT GType   parole_plugin_initialize(ParoleProviderPlugin *plugin);

G_MODULE_EXPORT void    parole_plugin_shutdown(void);

G_MODULE_EXPORT GType
parole_plugin_initialize(ParoleProviderPlugin *plugin) {
    xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
    sample_provider_register_type(plugin);
    return SAMPLE_TYPE_PROVIDER;
}

G_MODULE_EXPORT void
parole_plugin_shutdown(void) {
}
    
sample-provider.h
#ifndef SRC_PLUGINS_SAMPLE_SAMPLE_PROVIDER_H_
#define SRC_PLUGINS_SAMPLE_SAMPLE_PROVIDER_H_

#include "src/misc/parole.h"

G_BEGIN_DECLS

typedef struct _SampleProviderClass SampleProviderClass;
typedef struct _SampleProvider      SampleProvider;

#define SAMPLE_TYPE_PROVIDER             (sample_provider_get_type ())
#define SAMPLE_PROVIDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), SAMPLE_TYPE_PROVIDER, SampleProvider))
#define SAMPLE_PROVIDER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), SAMPLE_TYPE_PROVIDER, SampleProviderClass))
#define SAMPLE_IS_PROVIDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SAMPLE_TYPE_PROVIDER))
#define SAMPLE_IS_PROVIDER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), SAMPLE_TYPE_PROVIDER))
#define SAMPLE_PROVIDER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), SAMPLE_TYPE_PROVIDER, SampleProviderClass))

GType sample_provider_get_type           (void) G_GNUC_CONST G_GNUC_INTERNAL;

void  sample_provider_register_type      (ParoleProviderPlugin *plugin);

G_END_DECLS

#endif /* SRC_PLUGINS_SAMPLE_SAMPLE_PROVIDER_H_ */
    
sample-provider.c
#include "src/plugins/sample/sample-provider.h"

static void   sample_provider_iface_init(ParoleProviderPluginIface *iface);
static void   sample_provider_finalize(GObject                     *object);


struct _SampleProviderClass {
    GObjectClass parent_class;
};

struct _SampleProvider {
    GObject                 parent;
    ParoleProviderPlayer   *player;
};

PAROLE_DEFINE_TYPE_WITH_CODE(SampleProvider,
                             sample_provider,
                             G_TYPE_OBJECT,
                             PAROLE_IMPLEMENT_INTERFACE(PAROLE_TYPE_PROVIDER_PLUGIN,
                             sample_provider_iface_init));

static gboolean sample_provider_is_configurable(ParoleProviderPlugin *plugin) {
    return FALSE;
}

static void
sample_provider_set_player(ParoleProviderPlugin *plugin, ParoleProviderPlayer *player) {
    SampleProvider *provider;
    provider = SAMPLE_PROVIDER(plugin);

    provider->player = player;
}

static void
sample_provider_iface_init(ParoleProviderPluginIface *iface) {
    iface->get_is_configurable = sample_provider_is_configurable;
    iface->set_player = sample_provider_set_player;
}

static void sample_provider_class_init(SampleProviderClass *klass) {
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);

    gobject_class->finalize = sample_provider_finalize;
}

static void sample_provider_init(SampleProvider *provider) {
    provider->player = NULL;
}

static void sample_provider_finalize(GObject *object) {
    G_OBJECT_CLASS(sample_provider_parent_class)->finalize(object);
}