18
18
* You should have received a copy of the GNU General Public License along
19
19
* with this program. If not, see <http://www.gnu.org/licenses/>.
21
22
public class Gazette.PluginManager : GLib.Object
23
24
delegate Gazette.Plugin ModuleInitFunc ();
28
29
Gee.List<string> names;
30
public PluginManager(Settings settings, string field, string plugin_dir)
31
public PluginManager (Settings settings, string field, string plugin_dir) {
32
32
settings_field = field;
33
33
this.settings = settings;
34
34
this.plugin_dir = plugin_dir;
35
35
plugin_hash = new Gee.HashMap<string,Gazette.Plugin>();
36
36
names = new Gee.ArrayList<string>();
38
39
public Gee.Collection<Gazette.Plugin> get_plugins () {
39
40
return plugin_hash.values;
41
public void load_plugins()
43
public void load_plugins () {
43
44
load_modules_from_dir(plugin_dir);
46
private void load_modules_from_dir (string path, bool force = false)
47
private void load_modules_from_dir (string path) {
48
48
File dir = File.new_for_path(path);
50
50
string attributes = FileAttribute.STANDARD_NAME + "," +
69
69
if(file_name.has_suffix(".plug"))
71
load_plugin_keyfile(file_path, dir.get_path (), force);
71
load_plugin_keyfile(file_path, dir.get_path ());
73
73
info = enumerator.next_file ();
109
109
/* We don't want our modules to ever unload */
110
110
module.make_resident ();
111
Gazette.Plugin plug = plugin_init();
111
Gazette.Plugin plug = plugin_init ();
113
debug ("Loaded module source: '%s'", module.name());
114
//message ("Loaded module source: '%s'", module.name());
113
debug ("Loaded module source: '%s', id: '%s'", module.name(), plug.id);
117
plugin_hash.set (file_path, plug);
116
plugin_hash.set (plug.id, (owned) plug);
120
void load_plugin_keyfile(string path, string parent, bool force)
119
void load_plugin_keyfile (string path, string parent) {
122
120
var keyfile = new KeyFile();
125
123
keyfile.load_from_file(path, KeyFileFlags.NONE);
126
124
string name = keyfile.get_string("Plugin", "Name");
128
if(force || name in settings.get_strv(settings_field))
126
if(name in settings.get_strv(settings_field))
130
128
load_module(Path.build_filename(parent, keyfile.get_string("Plugin", "File")));
135
warning("Couldn't open thie keyfile: %s, %s", path, e.message);
133
warning("Couldn't open the keyfile: %s, %s", path, e.message);
139
public Gee.List<string> get_available_plugins()
137
public Gee.List<string> get_available_plugins () {
144
public bool disable_plugin(string path)
146
string[] plugs = settings.get_strv(settings_field);
147
string[] plugs_ = new string[plugs.length - 1];
150
foreach(var name in plugs)
159
if(found) settings.set_strv(settings_field, plugs_);
141
public void disable_plugin (string id) {
142
debug(@"Disabling plugin. ID: $id");
143
var plug = plugin_hash[id];
144
plugin_hash.unset(id);