Qball's Weblog

GObject based plugins and vala in GMPC

Tags gmpc 

It is something I have been preparing for a while now and today I took the first step that makes things work.
GMPC now supports GObject based plugins ( a base abstract class with interfaces).
This part of the code is written in vala, so I hope to offer the possibility of vala-written plugin soon.

Adding support for the GObject based plugins in the existing code was luckily very easy. I started wrapping the access to the plugins in the previous 2 releases, so I had not modify one file only, to get it working (and some pointers types).

The example plugin:

?View Code CSHARP
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
/* Gnome Music Player Client (GMPC)
 * Copyright (C) 2004-2009 Qball Cow <qball @sarine.nl>
 * Project homepage: http://gmpc.wikia.com/
 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
using GLib;
using Gtk;
using Gmpc;
 
public class  Gmpc.TestPlugin : Gmpc.PluginBase, Gmpc.Plugin2.Preferences {
    public const int[3] version = {,,2};
    /*********************************************************************************
     * Plugin base functions 
     * These functions are required.
     ********************************************************************************/
    public override weak int[3] get_version() {
        return this.version;
    }
    /**
     * The name of the plugin
     */
    public override weak string get_name() {
        return "Vala test plugin";
    }
 
    /**
     * Tells the plugin to save itself
     */
    public override void save_yourself()
    {
        stdout.printf("Vala plugin save myself\n");
        /* nothing to save */
    }
 
    /**
     * Get set enabled
     */
    public override bool get_enabled() {
        return (bool)config.get_int_with_default(this.get_name(), "enabled", 1);
    }
    public override void set_enabled(bool state) {
       config.set_int(this.get_name(), "enabled", (int)state); 
    }
 
 
    /*********************************************************************************
     * Plugin preferences functions 
     ********************************************************************************/
    public void pane_construct(Gtk.Container container)
    {
        var box = new Gtk.HBox(false,6);
        var label = new Gtk.Label ("This is a test preferences pane");
        box.pack_start(label, false, false,);
 
        container.add(box);
 
        container.show_all();
        stdout.printf("%s: Create preferences panel\n",this.get_name());
    }
    public void pane_destroy(Gtk.Container container)
    {
        Gtk.Bin bin = (Gtk.Bin) container;
        bin.child.destroy();
        stdout.printf("%s: Destroy preferences panel\n",this.get_name());
    }
 
    /*********************************************************************************
     * Private  
     ********************************************************************************/
 
    /* Plugin functions */
    private void connection_changed(Gmpc.Connection conn,MPD.Server server, int connect){
        stdout.printf("%s: Connection changed: %i\n",this.get_name(), connect);
    }
    construct {
        stdout.printf("create %s\n", this.get_name());
        gmpcconn.connection_changed += connection_changed;
    }
    ~TestPlugin() {
        stdout.printf("Destroying %s\n", this.get_name());
 
    }
}
</qball>