diff --git a/plugins/connect.py b/plugins/connect.py new file mode 100644 index 00000000..ced28d44 --- /dev/null +++ b/plugins/connect.py @@ -0,0 +1,9 @@ +import prof + +user = "jabber.org" + +def prof_on_start(): + global user + prof.cons_show("") + prof.cons_show("Enter password for " + user) + prof.send_line("/connect " + user) diff --git a/plugins/cricket-score.py b/plugins/cricket-score.py index 9d1312f5..54047a89 100644 --- a/plugins/cricket-score.py +++ b/plugins/cricket-score.py @@ -3,17 +3,20 @@ import urllib2 import json import time -score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England" +#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England" +score_url = None summary = None # hooks def prof_init(version, status): - prof.register_timed(get_scores, 60) + if score_url: + prof.register_timed(get_scores, 60) def prof_on_start(): - get_scores() + if score_url: + get_scores() def get_scores(): global score_url diff --git a/src/plugins/api.c b/src/plugins/api.c index 8f2e671b..6b393698 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -25,6 +25,7 @@ #include #include "plugins/callbacks.h" +#include "profanity.h" #include "ui/notifier.h" #include "ui/ui.h" @@ -45,6 +46,7 @@ api_cons_show(PyObject *self, PyObject *args) } cons_show("%s", message); ui_current_page_off(); + ui_refresh(); return Py_BuildValue(""); } @@ -118,11 +120,25 @@ api_notify(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject* +api_send_line(PyObject *self, PyObject *args) +{ + char *line = NULL; + if (!PyArg_ParseTuple(args, "s", &line)) { + return NULL; + } + + prof_process_input(line); + + return Py_BuildValue(""); +} + static PyMethodDef apiMethods[] = { { "cons_alert", api_cons_alert, METH_NOARGS, "Highlight the console window in the status bar." }, { "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." }, { "register_command", api_register_command, METH_VARARGS, "Register a command." }, { "register_timed", api_register_timed, METH_VARARGS, "Register a timed function." }, + { "send_line", api_send_line, METH_VARARGS, "Send a line of input." }, { "notify", api_notify, METH_VARARGS, "Send desktop notification." }, { NULL, NULL, 0, NULL } }; diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index e4944005..a6e3805b 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -28,8 +28,6 @@ #include "ui/ui.h" static GSList* _get_module_names(void); -static void _init(void); -static void _on_start(void); static void _run_plugins(const char * const function, PyObject *p_args); static GSList* plugins; @@ -79,14 +77,21 @@ plugins_init(void) module_name = g_slist_next(module_name); } - _init(); - _check_error(); - _on_start(); + PyObject *p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS); + _run_plugins("prof_init", p_args); + Py_XDECREF(p_args); _check_error(); } return; } +void +plugins_on_start(void) +{ + _run_plugins("prof_on_start", NULL); + _check_error(); +} + void plugins_shutdown(void) { @@ -123,20 +128,6 @@ _get_module_names(void) } } -static void -_init(void) -{ - PyObject *p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS); - _run_plugins("prof_init", p_args); - Py_XDECREF(p_args); -} - -static void -_on_start(void) -{ - _run_plugins("prof_on_start", NULL); -} - static void _run_plugins(const char * const function, PyObject *p_args) { diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 903dcc49..50d96cdd 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -24,6 +24,7 @@ #define PLUGINS_H void plugins_init(void); +void plugins_on_start(void); void plugins_on_connect(void); void plugins_shutdown(void); gboolean plugins_command_run(const char * const cmd); diff --git a/src/profanity.c b/src/profanity.c index b6917b4e..826e4e6f 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -46,7 +46,6 @@ #include "ui/ui.h" #include "xmpp/xmpp.h" -static gboolean _process_input(char *inp); static void _handle_idle_time(void); static void _init(const int disable_tls, char *log_level); static void _shutdown(void); @@ -67,6 +66,9 @@ prof_run(const int disable_tls, char *log_level) char inp[INP_WIN_MAX]; int size = 0; + ui_refresh(); + plugins_on_start(); + while(cmd_result == TRUE) { wint_t ch = ERR; size = 0; @@ -98,7 +100,7 @@ prof_run(const int disable_tls, char *log_level) } inp[size++] = '\0'; - cmd_result = _process_input(inp); + cmd_result = prof_process_input(inp); } g_timer_destroy(timer); @@ -262,7 +264,6 @@ prof_handle_login_account_success(char *account_name) status_bar_refresh(); accounts_free_account(account); - plugins_on_connect(); } void @@ -510,8 +511,8 @@ prof_handle_disco_info(const char *from, GSList *identities, GSList *features) * Take a line of input and process it, return TRUE if profanity is to * continue, FALSE otherwise */ -static gboolean -_process_input(char *inp) +gboolean +prof_process_input(char *inp) { log_debug("Input recieved: %s", inp); gboolean result = FALSE; diff --git a/src/profanity.h b/src/profanity.h index 0cd59fd0..b89dc0c4 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -86,5 +86,6 @@ void prof_handle_already_in_group(const char * const contact, const char * const void prof_handle_not_in_group(const char * const contact, const char * const group); void prof_handle_group_add(const char * const contact, const char * const group); void prof_handle_group_remove(const char * const contact, const char * const group); +gboolean prof_process_input(char *inp); #endif diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index ed72d502..021e6575 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -28,6 +28,7 @@ #include #include "log.h" +#include "plugins/plugins.h" #include "profanity.h" #include "tools/autocomplete.h" #include "xmpp/connection.h" @@ -637,6 +638,8 @@ _roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, contact_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); presence_update(conn_presence, NULL, 0); + + plugins_on_connect(); } return 1;