1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /plugins command to list installed plugins

This commit is contained in:
James Booth 2013-09-01 23:27:10 +01:00
parent 5a4446dfac
commit 54ea41d5b6
4 changed files with 60 additions and 2 deletions

View File

@ -94,6 +94,7 @@ static gboolean _cmd_autoaway(gchar **args, struct cmd_help_t help);
static gboolean _cmd_autoping(gchar **args, struct cmd_help_t help);
static gboolean _cmd_away(gchar **args, struct cmd_help_t help);
static gboolean _cmd_beep(gchar **args, struct cmd_help_t help);
static gboolean _cmd_bookmark(gchar **args, struct cmd_help_t help);
static gboolean _cmd_caps(gchar **args, struct cmd_help_t help);
static gboolean _cmd_chat(gchar **args, struct cmd_help_t help);
static gboolean _cmd_chlog(gchar **args, struct cmd_help_t help);
@ -124,12 +125,12 @@ static gboolean _cmd_nick(gchar **args, struct cmd_help_t help);
static gboolean _cmd_notify(gchar **args, struct cmd_help_t help);
static gboolean _cmd_online(gchar **args, struct cmd_help_t help);
static gboolean _cmd_outtype(gchar **args, struct cmd_help_t help);
static gboolean _cmd_plugins(gchar **args, struct cmd_help_t help);
static gboolean _cmd_prefs(gchar **args, struct cmd_help_t help);
static gboolean _cmd_priority(gchar **args, struct cmd_help_t help);
static gboolean _cmd_quit(gchar **args, struct cmd_help_t help);
static gboolean _cmd_reconnect(gchar **args, struct cmd_help_t help);
static gboolean _cmd_rooms(gchar **args, struct cmd_help_t help);
static gboolean _cmd_bookmark(gchar **args, struct cmd_help_t help);
static gboolean _cmd_roster(gchar **args, struct cmd_help_t help);
static gboolean _cmd_software(gchar **args, struct cmd_help_t help);
static gboolean _cmd_splash(gchar **args, struct cmd_help_t help);
@ -757,6 +758,14 @@ static struct cmd_t command_defs[] =
" : /account rename work gtalk",
NULL } } },
{ "/plugins",
_cmd_plugins, parse_args, 0, 0, NULL,
{ "/plugins", "Show installed plugins.",
{ "/plugins",
"-------------",
"Show currently installed plugins.",
NULL } } },
{ "/prefs",
_cmd_prefs, parse_args, 0, 1, NULL,
{ "/prefs [area]", "Show configuration.",
@ -1867,6 +1876,27 @@ _cmd_about(gchar **args, struct cmd_help_t help)
return TRUE;
}
static gboolean
_cmd_plugins(gchar **args, struct cmd_help_t help)
{
GSList *plugins = plugins_get_list();
GSList *curr = plugins;
if (curr == NULL) {
cons_show("No plugins installed.");
} else {
cons_show("Installed plugins:");
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
char *lang = plugins_get_lang_string(plugin);
cons_show(" %s (%s)", plugin->name, lang);
curr = g_slist_next(curr);
}
}
g_slist_free(curr);
return TRUE;
}
static gboolean
_cmd_prefs(gchar **args, struct cmd_help_t help)
{

View File

@ -2,6 +2,7 @@
#include <dlfcn.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <glib.h>
@ -40,8 +41,10 @@ c_plugin_create(const char * const filename)
return NULL;
}
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
plugin = malloc(sizeof(ProfPlugin));
plugin->name = g_strdup(filename);
plugin->name = strdup(module_name);
plugin->lang = LANG_C;
plugin->module = handle;
plugin->init_func = c_init_hook;
@ -51,6 +54,7 @@ c_plugin_create(const char * const filename)
plugin->on_message_send_func = c_on_message_send_hook;
g_string_free(path, TRUE);
g_free(module_name);
return plugin;
}

View File

@ -91,6 +91,28 @@ plugins_init(void)
return;
}
GSList *
plugins_get_list(void)
{
return plugins;
}
char *
plugins_get_lang_string(ProfPlugin *plugin)
{
switch (plugin->lang)
{
case LANG_PYTHON:
return "Python";
case LANG_RUBY:
return "Ruby";
case LANG_C:
return "C";
default:
return "Unknown";
}
}
void
plugins_on_start(void)
{

View File

@ -45,6 +45,8 @@ typedef struct prof_plugin_t {
} ProfPlugin;
void plugins_init(void);
GSList * plugins_get_list(void);
char * plugins_get_lang_string(ProfPlugin *plugin);
void plugins_on_start(void);
void plugins_on_connect(const char * const account_name, const char * const fulljid);
char * plugins_on_message_received(const char * const jid, const char *message);