1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
<para>
This section explains the steps required to write a plugin for Parole using
the C language interface.
</para>
<para>
A simple example can be found in the parole plugins dir shipped with the source code, the sample
plugin.
</para>
<para>
As a basics, the plugin needs to implement <link linkend="ParoleProviderPlugin"><type>ParoleProviderPlugin</type></link>
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 <link linkend="ParoleProviderPlayer"><type>ParoleProviderPlayer</type></link>
interface used by plugins to access the the Parole player backend.
</para>
<sect1>
<title>Plugin structure.</title>
sample-plugin.c
<programlisting>
#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) {
}
</programlisting>
sample-provider.h
<programlisting>
#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_ */
</programlisting>
sample-provider.c
<programlisting>
#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);
}
</programlisting>
</sect1>
|