diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/python/python.c | 94 | ||||
-rw-r--r-- | plugins/sysinfo/hwmon.c | 2 | ||||
-rw-r--r-- | plugins/sysinfo/parse.c | 2 |
3 files changed, 74 insertions, 24 deletions
diff --git a/plugins/python/python.c b/plugins/python/python.c index 0fed65ca..8b768799 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -249,6 +249,7 @@ typedef struct { PyObject *plugin; PyObject *callback; PyObject *userdata; + char *name; void *data; /* A handle, when type == HOOK_XCHAT */ } Hook; @@ -283,7 +284,8 @@ static PyObject *Plugin_New(char *filename, PyObject *xcoobj); static PyObject *Plugin_GetCurrent(); static PluginObject *Plugin_ByString(char *str); static Hook *Plugin_AddHook(int type, PyObject *plugin, PyObject *callback, - PyObject *userdata, void *data); + PyObject *userdata, char *name, void *data); +static Hook *Plugin_FindHook(PyObject *plugin, char *name); static void Plugin_RemoveHook(PyObject *plugin, Hook *hook); static void Plugin_RemoveAllHooks(PyObject *plugin); @@ -356,13 +358,7 @@ Usage: /PY LOAD <filename>\n\ /* Remove if/when HexChat supports this command for plugins */ static const char reload[] = "Usage: RELOAD <name>, reloads a python script"; -static const char about[] = "\ -\n\ -X-Chat Python Interface " VERSION "\n\ -\n\ -Copyright (c) 2002-2003 Gustavo Niemeyer <niemeyer@conectiva.com>\n\ -\n"; - +static const char about[] = "HexChat Python " PY_VERSION " Interface Version " VERSION "\n"; /* ===================================================================== */ /* Utility functions */ @@ -498,18 +494,20 @@ Callback_Command(char *word[], char *word_eol[], void *userdata) PyObject *retobj; PyObject *word_list, *word_eol_list; int ret = 0; + PyObject *plugin; - BEGIN_PLUGIN(hook->plugin); + plugin = hook->plugin; + BEGIN_PLUGIN(plugin); word_list = Util_BuildList(word+1); if (word_list == NULL) { - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return 0; } word_eol_list = Util_BuildList(word_eol+1); if (word_eol_list == NULL) { Py_DECREF(word_list); - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return 0; } @@ -528,7 +526,7 @@ Callback_Command(char *word[], char *word_eol[], void *userdata) PyErr_Print(); } - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return ret; } @@ -548,6 +546,7 @@ Callback_Print(char *word[], void *userdata) int next = 0; int i; int ret = 0; + PyObject *plugin; /* Cut off the message identifier. */ word += 1; @@ -579,13 +578,14 @@ Callback_Print(char *word[], void *userdata) } word_eol[i] = ""; - BEGIN_PLUGIN(hook->plugin); + plugin = hook->plugin; + BEGIN_PLUGIN(plugin); word_list = Util_BuildList(word); if (word_list == NULL) { g_free(word_eol_raw); g_free(word_eol); - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return 0; } word_eol_list = Util_BuildList(word_eol); @@ -593,7 +593,7 @@ Callback_Print(char *word[], void *userdata) g_free(word_eol_raw); g_free(word_eol); Py_DECREF(word_list); - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return 0; } @@ -614,7 +614,7 @@ Callback_Print(char *word[], void *userdata) PyErr_Print(); } - END_PLUGIN(hook->plugin); + END_PLUGIN(plugin); return ret; } @@ -1168,7 +1168,7 @@ Plugin_ByString(char *str) static Hook * Plugin_AddHook(int type, PyObject *plugin, PyObject *callback, - PyObject *userdata, void *data) + PyObject *userdata, char *name, void *data) { Hook *hook = (Hook *) g_malloc(sizeof(Hook)); if (hook == NULL) { @@ -1181,6 +1181,7 @@ Plugin_AddHook(int type, PyObject *plugin, PyObject *callback, hook->callback = callback; Py_INCREF(userdata); hook->userdata = userdata; + hook->name = g_strdup (name); hook->data = NULL; Plugin_SetHooks(plugin, g_slist_append(Plugin_GetHooks(plugin), hook)); @@ -1188,6 +1189,26 @@ Plugin_AddHook(int type, PyObject *plugin, PyObject *callback, return hook; } +static Hook * +Plugin_FindHook(PyObject *plugin, char *name) +{ + Hook *hook = NULL; + GSList *plugin_hooks = Plugin_GetHooks(plugin); + + while (plugin_hooks) + { + if (g_strcmp0 (((Hook *)plugin_hooks->data)->name, name) == 0) + { + hook = (Hook *)plugin_hooks->data; + break; + } + + plugin_hooks = g_slist_next(plugin_hooks); + } + + return hook; +} + static void Plugin_RemoveHook(PyObject *plugin, Hook *hook) { @@ -1207,6 +1228,8 @@ Plugin_RemoveHook(PyObject *plugin, Hook *hook) hook)); Py_DECREF(hook->callback); Py_DECREF(hook->userdata); + if (hook->name) + g_free(hook->name); g_free(hook); } } @@ -1225,6 +1248,8 @@ Plugin_RemoveAllHooks(PyObject *plugin) } Py_DECREF(hook->callback); Py_DECREF(hook->userdata); + if (hook->name) + g_free(hook->name); g_free(hook); list = list->next; } @@ -1696,7 +1721,7 @@ Module_hexchat_hook_command(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL); + hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, name, NULL); if (hook == NULL) return NULL; @@ -1732,7 +1757,7 @@ Module_hexchat_hook_server(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL); + hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL, NULL); if (hook == NULL) return NULL; @@ -1768,7 +1793,7 @@ Module_hexchat_hook_print(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL); + hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, name, NULL); if (hook == NULL) return NULL; @@ -1803,7 +1828,7 @@ Module_hexchat_hook_timer(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL); + hook = Plugin_AddHook(HOOK_XCHAT, plugin, callback, userdata, NULL, NULL); if (hook == NULL) return NULL; @@ -1836,7 +1861,7 @@ Module_hexchat_hook_unload(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - hook = Plugin_AddHook(HOOK_UNLOAD, plugin, callback, userdata, NULL); + hook = Plugin_AddHook(HOOK_UNLOAD, plugin, callback, userdata, NULL, NULL); if (hook == NULL) return NULL; @@ -1847,13 +1872,29 @@ static PyObject * Module_hexchat_unhook(PyObject *self, PyObject *args) { PyObject *plugin; + PyObject *obj; Hook *hook; - if (!PyArg_ParseTuple(args, "l:unhook", &hook)) + if (!PyArg_ParseTuple(args, "O:unhook", &obj)) return NULL; plugin = Plugin_GetCurrent(); if (plugin == NULL) return NULL; - Plugin_RemoveHook(plugin, hook); + + if (PyUnicode_Check (obj)) + { + hook = Plugin_FindHook(plugin, PyUnicode_AsUTF8 (obj)); + while (hook) + { + Plugin_RemoveHook(plugin, hook); + hook = Plugin_FindHook(plugin, PyUnicode_AsUTF8 (obj)); + } + } + else + { + hook = (Hook *)PyLong_AsLong(obj); + Plugin_RemoveHook(plugin, hook); + } + Py_INCREF(Py_None); return Py_None; } @@ -1903,6 +1944,7 @@ Module_xchat_get_list(PyObject *self, PyObject *args) PyObject *attr = NULL; const char *sattr; int iattr; + time_t tattr; switch(fields[i][0]) { case 's': sattr = hexchat_list_str(ph, list, (char*)fld); @@ -1912,6 +1954,10 @@ Module_xchat_get_list(PyObject *self, PyObject *args) iattr = hexchat_list_int(ph, list, (char*)fld); attr = PyLong_FromLong((long)iattr); break; + case 't': + tattr = hexchat_list_time(ph, list, (char*)fld); + attr = PyLong_FromLong((long)tattr); + break; case 'p': sattr = hexchat_list_str(ph, list, (char*)fld); if (strcmp(fld, "context") == 0) { diff --git a/plugins/sysinfo/hwmon.c b/plugins/sysinfo/hwmon.c index 3cc2fb8d..389244ac 100644 --- a/plugins/sysinfo/hwmon.c +++ b/plugins/sysinfo/hwmon.c @@ -34,6 +34,7 @@ int hwmon_chip_present() return 0; } +#if 0 void get_hwmon_chip_name(char *name) { char *position, buffer[bsize]; @@ -47,6 +48,7 @@ void get_hwmon_chip_name(char *name) fclose(fp); } } +#endif void get_hwmon_temp(unsigned int *value, unsigned int *sensor) { diff --git a/plugins/sysinfo/parse.c b/plugins/sysinfo/parse.c index 76002900..ed6ba146 100644 --- a/plugins/sysinfo/parse.c +++ b/plugins/sysinfo/parse.c @@ -438,8 +438,10 @@ int xs_parse_hwmon_chip(char *chip) { if (!hwmon_chip_present()) return 1; +#if 0 else get_hwmon_chip_name(chip); +#endif return 0; } |