From d03d6e606b40157d910ddf99ab018156abeb8ef0 Mon Sep 17 00:00:00 2001 From: "berkeviktor@aol.com" Date: Mon, 28 Feb 2011 18:59:32 +0100 Subject: add wdk changes to named branch --- plugins/xtray/xchat.cpp | 319 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 319 insertions(+) create mode 100644 plugins/xtray/xchat.cpp (limited to 'plugins/xtray/xchat.cpp') diff --git a/plugins/xtray/xchat.cpp b/plugins/xtray/xchat.cpp new file mode 100644 index 00000000..581970f1 --- /dev/null +++ b/plugins/xtray/xchat.cpp @@ -0,0 +1,319 @@ +/* X-Tray + * Copyright (C) 1998, 2005 Peter Zelezny, Michael Hotaling + * + * X-Tray 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 2 of the License, or + * (at your option) any later version. + * + * X-Tray 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 X-Tray; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include "plugin.h" +#include "xtray.h" +#include "resource.h" +#include "xchat.h" +#include "utility.h" + +// from util.c of xchat source code ( slightly modified to fit X-Tray Syntax ) +char *xchat_strip_color (char *text) +{ + int nc = 0; + int i = 0; + int col = 0; + int len = strlen(text); + char *new_str = (char *)malloc(len + 2); + + while (len > 0) + { + if ((col && isdigit(*text) && (nc < 2)) || (col && isdigit(*(text+1)) && (nc < 3) && (*text == ','))) + { + nc++; + + if(*text == ',') + { + nc = 0; + } + } + else + { + col = 0; + + switch (*text) + { + case '\003': /*ATTR_COLOR: */ + { + col = 1; + nc = 0; + } + break; + case '\007': /*ATTR_BEEP: */ + case '\017': /*ATTR_RESET: */ + case '\026': /*ATTR_REVERSE: */ + case '\002': /*ATTR_BOLD: */ + case '\037': /*ATTR_UNDERLINE: */ + break; + default: + { + new_str[i] = *text; + i++; + } + break; + } + } + + text++; + len--; + } + + new_str[i] = 0; + + return new_str; +} + +void check_special_chars (char *cmd) +{ + int occur = 0; + int len = strlen (cmd); + int i = 0, j = 0; + char *buf; + + if (!len) + return; + + buf = (char *)malloc (len + 1); + + if (buf) + { + while (cmd[j]) + { + switch (cmd[j]) + { + case '%': + { + occur++; + + switch (cmd[j + 1]) + { + case 'R': + buf[i] = '\026'; + break; + case 'U': + buf[i] = '\037'; + break; + case 'B': + buf[i] = '\002'; + break; + case 'C': + buf[i] = '\003'; + break; + case 'O': + buf[i] = '\017'; + break; + case '%': + buf[i] = '%'; + break; + default: + buf[i] = '%'; + j--; + break; + } + + j++; + } + break; + default: + { + buf[i] = cmd[j]; + } + break; + } + + j++; + i++; + } + + buf[i] = 0; + + if (occur) + strcpy (cmd, buf); + + free (buf); + } +} + +void xchat_globally_away(TCHAR *tszAway) +{ + char szTemp[512]; + char szAway[512]; + + ConvertString(tszAway, szAway, 512); + _snprintf(szTemp, 512, "ALLSERV AWAY %s\0", szAway); + check_special_chars(szTemp); + xchat_exec(szTemp); +} + +void xchat_away(TCHAR *tszAway) +{ + char szTemp[512]; + char szAway[512]; + + ConvertString(tszAway, szAway, 512); + _snprintf(szTemp, 512, szAway); + check_special_chars(szTemp); + xchat_commandf(ph, "AWAY %s\0", szTemp); +} + +void xchat_globally_back() +{ + std::vector xs; + std::vector::iterator xsi; + xchat_list *xl = xchat_list_get(ph, "channels"); + + if(xl) + { + while(xchat_list_next(ph, xl)) + { + xsi = std::find(xs.begin(), xs.end(), xchat_list_int(ph, xl, "id")); + + if((xsi == xs.end()) && + ((strlen(xchat_list_str(ph, xl, "server")) > 0) || + (strlen(xchat_list_str(ph, xl, "channel")) > 0))) + { + xs.push_back(xchat_list_int(ph, xl, "id")); + xchat_set_context(ph, (xchat_context *)xchat_list_str(ph, xl, "context")); + xchat_back(); + } + } + + xchat_list_free(ph, xl); + } +} + + + +void xchat_back() +{ + if(xchat_get_info(ph, "away")) + { + xchat_command(ph, "BACK"); + } +} + +HMENU setServerMenu() +{ + HMENU sTemp = CreateMenu(); + TCHAR wszServer[128]; + TCHAR wszNick[128]; + TCHAR wszMenuEntry[256]; + + std::vector xs; + std::vector::iterator xsi; + xchat_list *xl = xchat_list_get(ph, "channels"); + + AppendMenu(sTemp, MF_STRING, ACT_AWAY, _T("Set Globally Away")); + AppendMenu(sTemp, MF_STRING, ACT_BACK, _T("Set Globally Back")); + AppendMenu(sTemp, MF_SEPARATOR, 0, NULL); + + if(xl) + { + while(xchat_list_next(ph, xl)) + { + xsi = std::find(xs.begin(), xs.end(), xchat_list_int(ph, xl, "id")); + + if( (xsi == xs.end()) && + ((strlen(xchat_list_str(ph, xl, "server")) > 0) || + (strlen(xchat_list_str(ph, xl, "channel")) > 0))) + { + xchat_set_context(ph, (xchat_context *)xchat_list_str(ph, xl, "context")); + xs.push_back(xchat_list_int(ph, xl, "id")); + + char *network = _strdup(xchat_list_str(ph, xl, "network")); + char *server = _strdup(xchat_list_str(ph, xl, "server")); + char *nick = _strdup(xchat_get_info(ph, "nick")); + + if(network != NULL) + { + ConvertString(network, wszServer, 128); + } + else + { + ConvertString(server, wszServer, 128); + } + + if(server != NULL) + { + ConvertString(nick, wszNick, 128); + _sntprintf(wszMenuEntry, 256, _T("%s @ %s\0"), wszNick, wszServer); + + if(!xchat_get_info(ph, "away")) + { + AppendMenu(sTemp, MF_STRING, (xchat_list_int(ph, xl, "id") + 1), wszMenuEntry); + } + else + { + AppendMenu(sTemp, (MF_CHECKED | MF_STRING), (xchat_list_int(ph, xl, "id") + 1), wszMenuEntry); + } + } + + free(network); + free(server); + free(nick); + } + } + + xchat_list_free(ph, xl); + } + + return sTemp; +} + +struct _xchat_context *xchat_find_server(int find_id) +{ + xchat_context *xc; + xchat_list *xl = xchat_list_get(ph, "channels"); + int id; + + if(!xl) + return NULL; + + while(xchat_list_next(ph, xl)) + { + id = xchat_list_int(ph, xl, "id"); + + if(id == -1) + { + return NULL; + } + else if(id == find_id) + { + xc = (xchat_context *)xchat_list_str(ph, xl, "context"); + + xchat_list_free(ph, xl); + + return xc; + } + } + + xchat_list_free(ph, xl); + + return NULL; +} + +void xchat_exec(char *command) +{ + xchat_set_context(ph, xchat_find_context(ph, NULL, NULL)); + xchat_command(ph, command); +} \ No newline at end of file -- cgit 1.4.1 From ab3e3926abce49f0741edf90a1300d4cdcc79670 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Wed, 30 Nov 2011 02:22:38 +0100 Subject: use global xchat-plugin.h for xtray --- plugins/xtray/callbacks.cpp | 3 +- plugins/xtray/makefile.mak | 2 +- plugins/xtray/plugin.h | 335 -------------------------------------------- plugins/xtray/utility.cpp | 3 +- plugins/xtray/xchat.cpp | 3 +- plugins/xtray/xtray.cpp | 4 +- 6 files changed, 9 insertions(+), 341 deletions(-) delete mode 100644 plugins/xtray/plugin.h (limited to 'plugins/xtray/xchat.cpp') diff --git a/plugins/xtray/callbacks.cpp b/plugins/xtray/callbacks.cpp index 443cb05d..1b7f452f 100644 --- a/plugins/xtray/callbacks.cpp +++ b/plugins/xtray/callbacks.cpp @@ -22,8 +22,9 @@ #include #include #include + +#include "xchat-plugin.h" #include "utility.h" -#include "plugin.h" #include "xtray.h" #include "xchat.h" #include "callbacks.h" diff --git a/plugins/xtray/makefile.mak b/plugins/xtray/makefile.mak index d1f8d295..ec2c94b3 100644 --- a/plugins/xtray/makefile.mak +++ b/plugins/xtray/makefile.mak @@ -20,7 +20,7 @@ xtray.def: echo xchat_plugin_deinit >> xtray.def .cpp.obj: - $(CC) $(CPPFLAGS) /c $< + $(CC) $(CPPFLAGS) /I.. /c $< res: rc /nologo resource.rc diff --git a/plugins/xtray/plugin.h b/plugins/xtray/plugin.h deleted file mode 100644 index 50b0de21..00000000 --- a/plugins/xtray/plugin.h +++ /dev/null @@ -1,335 +0,0 @@ -/* You can distribute this header with your plugins for easy compilation */ -#ifndef XCHAT_PLUGIN_H -#define XCHAT_PLUGIN_H - -#include - -#define XCHAT_IFACE_MAJOR 1 -#define XCHAT_IFACE_MINOR 9 -#define XCHAT_IFACE_MICRO 11 -#define XCHAT_IFACE_VERSION ((XCHAT_IFACE_MAJOR * 10000) + \ - (XCHAT_IFACE_MINOR * 100) + \ - (XCHAT_IFACE_MICRO)) - -#define XCHAT_PRI_HIGHEST 127 -#define XCHAT_PRI_HIGH 64 -#define XCHAT_PRI_NORM 0 -#define XCHAT_PRI_LOW (-64) -#define XCHAT_PRI_LOWEST (-128) - -#define XCHAT_FD_READ 1 -#define XCHAT_FD_WRITE 2 -#define XCHAT_FD_EXCEPTION 4 -#define XCHAT_FD_NOTSOCKET 8 - -#define XCHAT_EAT_NONE 0 /* pass it on through! */ -#define XCHAT_EAT_XCHAT 1 /* don't let xchat see this event */ -#define XCHAT_EAT_PLUGIN 2 /* don't let other plugins see this event */ -#define XCHAT_EAT_ALL (XCHAT_EAT_XCHAT|XCHAT_EAT_PLUGIN) /* don't let anything see this event */ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _xchat_plugin xchat_plugin; -typedef struct _xchat_list xchat_list; -typedef struct _xchat_hook xchat_hook; -#ifndef PLUGIN_C -typedef struct _xchat_context xchat_context; -#endif - -#ifndef PLUGIN_C -struct _xchat_plugin -{ - /* these are only used on win32 */ - xchat_hook *(*xchat_hook_command) (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], char *word_eol[], void *user_data), - const char *help_text, - void *userdata); - xchat_hook *(*xchat_hook_server) (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], char *word_eol[], void *user_data), - void *userdata); - xchat_hook *(*xchat_hook_print) (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], void *user_data), - void *userdata); - xchat_hook *(*xchat_hook_timer) (xchat_plugin *ph, - int timeout, - int (*callback) (void *user_data), - void *userdata); - xchat_hook *(*xchat_hook_fd) (xchat_plugin *ph, - int fd, - int flags, - int (*callback) (int fd, int flags, void *user_data), - void *userdata); - void *(*xchat_unhook) (xchat_plugin *ph, - xchat_hook *hook); - void (*xchat_print) (xchat_plugin *ph, - const char *text); - void (*xchat_printf) (xchat_plugin *ph, - const char *format, ...); - void (*xchat_command) (xchat_plugin *ph, - const char *command); - void (*xchat_commandf) (xchat_plugin *ph, - const char *format, ...); - int (*xchat_nickcmp) (xchat_plugin *ph, - const char *s1, - const char *s2); - int (*xchat_set_context) (xchat_plugin *ph, - xchat_context *ctx); - xchat_context *(*xchat_find_context) (xchat_plugin *ph, - const char *servname, - const char *channel); - xchat_context *(*xchat_get_context) (xchat_plugin *ph); - const char *(*xchat_get_info) (xchat_plugin *ph, - const char *id); - int (*xchat_get_prefs) (xchat_plugin *ph, - const char *name, - const char **string, - int *integer); - xchat_list * (*xchat_list_get) (xchat_plugin *ph, - const char *name); - void (*xchat_list_free) (xchat_plugin *ph, - xchat_list *xlist); - const char * const * (*xchat_list_fields) (xchat_plugin *ph, - const char *name); - int (*xchat_list_next) (xchat_plugin *ph, - xchat_list *xlist); - const char * (*xchat_list_str) (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - int (*xchat_list_int) (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - void * (*xchat_plugingui_add) (xchat_plugin *ph, - const char *filename, - const char *name, - const char *desc, - const char *version, - char *reserved); - void (*xchat_plugingui_remove) (xchat_plugin *ph, - void *handle); - int (*xchat_emit_print) (xchat_plugin *ph, - const char *event_name, ...); - int (*xchat_read_fd) (xchat_plugin *ph, - void *src, - char *buf, - int *len); - time_t (*xchat_list_time) (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - char *(*xchat_gettext) (xchat_plugin *ph, - const char *msgid); - void (*xchat_send_modes) (xchat_plugin *ph, - const char **targets, - int ntargets, - int modes_per_line, - char sign, - char mode); - char *(*xchat_strip) (xchat_plugin *ph, - const char *str, - int len, - int flags); - void (*xchat_free) (xchat_plugin *ph, - void *ptr); -}; -#endif - - - -xchat_hook * -xchat_hook_command (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], char *word_eol[], void *user_data), - const char *help_text, - void *userdata); - -xchat_hook * -xchat_hook_server (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], char *word_eol[], void *user_data), - void *userdata); - -xchat_hook * -xchat_hook_print (xchat_plugin *ph, - const char *name, - int pri, - int (*callback) (char *word[], void *user_data), - void *userdata); - -xchat_hook * -xchat_hook_timer (xchat_plugin *ph, - int timeout, - int (*callback) (void *user_data), - void *userdata); - -xchat_hook * -xchat_hook_fd (xchat_plugin *ph, - int fd, - int flags, - int (*callback) (int fd, int flags, void *user_data), - void *userdata); - -void * -xchat_unhook (xchat_plugin *ph, - xchat_hook *hook); - -void -xchat_print (xchat_plugin *ph, - const char *text); - -void -xchat_printf (xchat_plugin *ph, - const char *format, ...); - -void -xchat_command (xchat_plugin *ph, - const char *command); - -void -xchat_commandf (xchat_plugin *ph, - const char *format, ...); - -int -xchat_nickcmp (xchat_plugin *ph, - const char *s1, - const char *s2); - -int -xchat_set_context (xchat_plugin *ph, - xchat_context *ctx); - -xchat_context * -xchat_find_context (xchat_plugin *ph, - const char *servname, - const char *channel); - -xchat_context * -xchat_get_context (xchat_plugin *ph); - -const char * -xchat_get_info (xchat_plugin *ph, - const char *id); - -int -xchat_get_prefs (xchat_plugin *ph, - const char *name, - const char **string, - int *integer); - -xchat_list * -xchat_list_get (xchat_plugin *ph, - const char *name); - -void -xchat_list_free (xchat_plugin *ph, - xchat_list *xlist); - -const char * const * -xchat_list_fields (xchat_plugin *ph, - const char *name); - -int -xchat_list_next (xchat_plugin *ph, - xchat_list *xlist); - -const char * -xchat_list_str (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - -int -xchat_list_int (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - -time_t -xchat_list_time (xchat_plugin *ph, - xchat_list *xlist, - const char *name); - -void * -xchat_plugingui_add (xchat_plugin *ph, - const char *filename, - const char *name, - const char *desc, - const char *version, - char *reserved); - -void -xchat_plugingui_remove (xchat_plugin *ph, - void *handle); - -int -xchat_emit_print (xchat_plugin *ph, - const char *event_name, ...); - -char * -xchat_gettext (xchat_plugin *ph, - const char *msgid); - -void -xchat_send_modes (xchat_plugin *ph, - const char **targets, - int ntargets, - int modes_per_line, - char sign, - char mode); - -char * -xchat_strip (xchat_plugin *ph, - const char *str, - int len, - int flags); - -void -xchat_free (xchat_plugin *ph, - void *ptr); - -#if !defined(PLUGIN_C) && defined(WIN32) -#ifndef XCHAT_PLUGIN_HANDLE -#define XCHAT_PLUGIN_HANDLE (ph) -#endif -#define xchat_hook_command ((XCHAT_PLUGIN_HANDLE)->xchat_hook_command) -#define xchat_hook_server ((XCHAT_PLUGIN_HANDLE)->xchat_hook_server) -#define xchat_hook_print ((XCHAT_PLUGIN_HANDLE)->xchat_hook_print) -#define xchat_hook_timer ((XCHAT_PLUGIN_HANDLE)->xchat_hook_timer) -#define xchat_hook_fd ((XCHAT_PLUGIN_HANDLE)->xchat_hook_fd) -#define xchat_unhook ((XCHAT_PLUGIN_HANDLE)->xchat_unhook) -#define xchat_print ((XCHAT_PLUGIN_HANDLE)->xchat_print) -#define xchat_printf ((XCHAT_PLUGIN_HANDLE)->xchat_printf) -#define xchat_command ((XCHAT_PLUGIN_HANDLE)->xchat_command) -#define xchat_commandf ((XCHAT_PLUGIN_HANDLE)->xchat_commandf) -#define xchat_nickcmp ((XCHAT_PLUGIN_HANDLE)->xchat_nickcmp) -#define xchat_set_context ((XCHAT_PLUGIN_HANDLE)->xchat_set_context) -#define xchat_find_context ((XCHAT_PLUGIN_HANDLE)->xchat_find_context) -#define xchat_get_context ((XCHAT_PLUGIN_HANDLE)->xchat_get_context) -#define xchat_get_info ((XCHAT_PLUGIN_HANDLE)->xchat_get_info) -#define xchat_get_prefs ((XCHAT_PLUGIN_HANDLE)->xchat_get_prefs) -#define xchat_list_get ((XCHAT_PLUGIN_HANDLE)->xchat_list_get) -#define xchat_list_free ((XCHAT_PLUGIN_HANDLE)->xchat_list_free) -#define xchat_list_fields ((XCHAT_PLUGIN_HANDLE)->xchat_list_fields) -#define xchat_list_str ((XCHAT_PLUGIN_HANDLE)->xchat_list_str) -#define xchat_list_int ((XCHAT_PLUGIN_HANDLE)->xchat_list_int) -#define xchat_list_time ((XCHAT_PLUGIN_HANDLE)->xchat_list_time) -#define xchat_list_next ((XCHAT_PLUGIN_HANDLE)->xchat_list_next) -#define xchat_plugingui_add ((XCHAT_PLUGIN_HANDLE)->xchat_plugingui_add) -#define xchat_plugingui_remove ((XCHAT_PLUGIN_HANDLE)->xchat_plugingui_remove) -#define xchat_emit_print ((XCHAT_PLUGIN_HANDLE)->xchat_emit_print) -#define xchat_gettext ((XCHAT_PLUGIN_HANDLE)->xchat_gettext) -#define xchat_send_modes ((XCHAT_PLUGIN_HANDLE)->xchat_send_modes) -#define xchat_strip ((XCHAT_PLUGIN_HANDLE)->xchat_strip) -#define xchat_free ((XCHAT_PLUGIN_HANDLE)->xchat_free) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/plugins/xtray/utility.cpp b/plugins/xtray/utility.cpp index 4faed90b..66489bc0 100644 --- a/plugins/xtray/utility.cpp +++ b/plugins/xtray/utility.cpp @@ -20,8 +20,9 @@ #include #include #include + +#include "xchat-plugin.h" #include "utility.h" -#include "plugin.h" #include "xtray.h" #include "callbacks.h" #include "resource.h" diff --git a/plugins/xtray/xchat.cpp b/plugins/xtray/xchat.cpp index 581970f1..47ce46a9 100644 --- a/plugins/xtray/xchat.cpp +++ b/plugins/xtray/xchat.cpp @@ -21,7 +21,8 @@ #include #include #include -#include "plugin.h" + +#include "xchat-plugin.h" #include "xtray.h" #include "resource.h" #include "xchat.h" diff --git a/plugins/xtray/xtray.cpp b/plugins/xtray/xtray.cpp index a7c8c8bd..33ce125f 100644 --- a/plugins/xtray/xtray.cpp +++ b/plugins/xtray/xtray.cpp @@ -22,14 +22,14 @@ #include #include #include + +#include "xchat-plugin.h" #include "resource.h" #include "callbacks.h" -#include "plugin.h" #include "utility.h" #include "xtray.h" #include "sdTray.h" #include "sdAlerts.h" -#include "plugin.h" /*****************************************************/ /**** Don't want to pollute the namespace do we? *****/ -- cgit 1.4.1