From 02ea0fac4470bcf0bdc57723d14ac1fb98112043 Mon Sep 17 00:00:00 2001 From: jakob Date: Wed, 17 May 2017 08:37:05 -0400 Subject: [PATCH] get_status returns a string rather than an integer. --- apidoc/python/source/reference.rst | 4 ++-- src/api.c | 6 ++++-- src/python_api.c | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apidoc/python/source/reference.rst b/apidoc/python/source/reference.rst index 18644b1..27f2492 100644 --- a/apidoc/python/source/reference.rst +++ b/apidoc/python/source/reference.rst @@ -31,9 +31,9 @@ State .. function:: get_status() - Return the user's current status. 0 indicates online and available, 1 indicates away, and 2 indicates busy. + Return a string representing the user's current status. Can be either "online", "away", or "busy". - :rtype: int + :rtype: string .. function:: get_status_message() diff --git a/src/api.c b/src/api.c index 721b973..fbb0488 100644 --- a/src/api.c +++ b/src/api.c @@ -82,6 +82,7 @@ char *api_get_status_message(void) return NULL; tox_self_get_status_message(user_tox, status); + status[len] = '\0'; return (char *) status; } @@ -92,12 +93,13 @@ void api_send(const char *msg) char *name = api_get_nick(); char timefrmt[TIME_STR_SIZE]; - get_time_str(timefrmt, sizeof(timefrmt)); self_window = get_active_window(); + get_time_str(timefrmt, sizeof(timefrmt)); + line_info_add(self_window, timefrmt, name, NULL, OUT_MSG, 0, 0, "%s", msg); - free(name); cqueue_add(self_window->chatwin->cqueue, msg, strlen(msg), OUT_MSG, self_window->chatwin->hst->line_end->id + 1); + free(name); } void api_execute(const char *input, int mode) diff --git a/src/python_api.c b/src/python_api.c index 73577f1..6f1fa3d 100644 --- a/src/python_api.c +++ b/src/python_api.c @@ -64,14 +64,25 @@ static PyObject *python_api_get_nick(PyObject *self, PyObject *args) static PyObject *python_api_get_status(PyObject *self, PyObject *args) { - TOX_USER_STATUS status; PyObject *ret; if (!PyArg_ParseTuple(args, "")) return NULL; - status = api_get_status(); - ret = Py_BuildValue("i", status); + switch (api_get_status()) { + case TOX_USER_STATUS_NONE: + ret = Py_BuildValue("s", "online"); + break; + + case TOX_USER_STATUS_AWAY: + ret = Py_BuildValue("s", "away"); + break; + + case TOX_USER_STATUS_BUSY: + ret = Py_BuildValue("s", "busy"); + break; + } + return ret; }