1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00
profanity/src/plugins/plugins.c

106 lines
2.6 KiB
C
Raw Normal View History

/*
2013-08-02 19:58:04 -04:00
* plugins.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity 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 3 of the License, or
* (at your option) any later version.
*
* Profanity 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 Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config/preferences.h"
2013-08-04 13:43:46 -04:00
#include "plugins/callbacks.h"
2013-08-02 19:48:22 -04:00
#include "plugins/plugins.h"
#include "plugins/python_api.h"
#include "plugins/python_plugins.h"
#include "ui/ui.h"
2013-08-02 19:22:00 -04:00
static GSList* plugins;
2013-08-04 11:42:25 -04:00
void
2013-08-02 19:48:22 -04:00
plugins_init(void)
{
2013-08-02 18:52:16 -04:00
plugins = NULL;
2013-08-02 18:36:47 -04:00
2013-08-17 18:21:32 -04:00
python_init();
2013-08-02 18:36:47 -04:00
// load plugins
gchar **plugins_load = prefs_get_plugins();
if (plugins_load != NULL) {
int i;
for (i = 0; i < g_strv_length(plugins_load); i++)
{
gchar *filename = plugins_load[i];
if (g_str_has_suffix(filename, ".py")) {
2013-08-17 17:51:25 -04:00
ProfPlugin *plugin = python_plugin_create(filename);
if (plugin != NULL) {
plugins = g_slist_append(plugins, plugin);
2013-08-17 17:51:25 -04:00
cons_show("Loaded plugin: %s", filename);
}
2013-08-02 18:36:47 -04:00
}
}
2013-08-02 18:52:16 -04:00
// initialise plugins
GSList *curr = plugins;
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS);
python_check_error();
curr = g_slist_next(curr);
}
}
2013-07-24 19:54:31 -04:00
return;
}
void
plugins_on_start(void)
{
GSList *curr = plugins;
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
plugin->on_start_func(plugin);
curr = g_slist_next(curr);
}
2013-08-02 19:22:00 -04:00
}
2013-08-02 19:58:04 -04:00
void
plugins_on_connect(void)
{
GSList *curr = plugins;
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
plugin->on_connect_func(plugin);
curr = g_slist_next(curr);
}
2013-08-02 19:58:04 -04:00
}
void
plugins_on_message_received(const char * const jid, const char * const message)
{
GSList *curr = plugins;
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
plugin->on_message_received_func(plugin, jid, message);
curr = g_slist_next(curr);
2013-08-02 18:36:47 -04:00
}
}
2013-08-02 18:52:16 -04:00
void
plugins_shutdown(void)
2013-08-02 19:22:00 -04:00
{
2013-08-17 18:21:32 -04:00
python_shutdown();
2013-08-02 19:22:00 -04:00
}