Группа :: Сети/Чат
Пакет: gaim
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: gaim-plugins.patch
diff -u -r --new-file gaim-0.61.orig/plugins/Makefile.am gaim-0.61/plugins/Makefile.am
--- gaim-0.61.orig/plugins/Makefile.am 2003-03-10 07:30:15 +0200
+++ gaim-0.61/plugins/Makefile.am 2003-04-16 17:06:09 +0300
@@ -12,6 +12,7 @@
history_la_LDFLAGS = -module -avoid-version
timestamp_la_LDFLAGS = -module -avoid-version
idle_la_LDFLAGS = -module -avoid-version
+recode_la_LDFLAGS = -module -avoid-version
if PLUGINS
@@ -22,7 +23,8 @@
spellchk.la \
history.la \
timestamp.la \
- idle.la
+ idle.la \
+ recode.la
autorecon_la_SOURCES = autorecon.c
iconaway_la_SOURCES = iconaway.c
@@ -31,6 +33,7 @@
history_la_SOURCES = history.c
timestamp_la_SOURCES = timestamp.c
idle_la_SOURCES = idle.c
+recode_la_SOURCES = recode.c
endif
diff -u -r --new-file gaim-0.61.orig/plugins/recode.c gaim-0.61/plugins/recode.c
--- gaim-0.61.orig/plugins/recode.c 1970-01-01 03:00:00 +0300
+++ gaim-0.61/plugins/recode.c 2003-04-16 17:05:22 +0300
@@ -0,0 +1,257 @@
+/* recode gaim plugin
+ *
+ * Grigory Bakunov <black@asplinux.ru>
+ * Partitialy based on spellchk plugin
+ */
+
+#define GAIM_PLUGINS
+#include "gaim.h"
+#include <glib.h>
+#include <iconv.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+static GtkWidget *configwin = NULL;
+static GtkWidget *entry_their = NULL;
+static GtkWidget *entry_our = NULL;
+
+static iconv_t send = (iconv_t) -1;
+static iconv_t recv = (iconv_t) -1;
+static gboolean send_b=FALSE;
+static gboolean recv_b=FALSE;
+
+static gchar send_c[16];
+static gchar recv_c[16];
+
+static gchar *rcfile = NULL;
+gchar *name() {
+ return "Recoder";
+}
+
+gchar *description() {
+ return "Recode messages from one charset to another. For example from KOI8-R to CP1251.";
+}
+iconv_t conv_iconv_open(gchar* charsetto, gchar* charsetfrm) {
+ iconv_t ict;
+ if (charsetfrm == NULL || charsetto == NULL ||
+ charsetfrm[0] == 0 || charsetto[0] == 0)
+ return (iconv_t)( -1);
+ ict = iconv_open (charsetto, charsetfrm);
+ if (ict == (iconv_t)( -1)) {
+ do_error_dialog("Incorrect charsets","Gaim: Recode error");
+ };
+ return ict;
+};
+static
+
+gchar* conv_iconv_convert(iconv_t ict, gchar** buf) {
+ size_t res, inlen, outlen;
+ gchar* bufret;
+ gchar* buf2=g_strdup(*buf);
+ if (*buf==NULL) return NULL;
+ bufret=buf2;
+ if (buf2==NULL) return NULL;
+ inlen = strlen(buf2)+1;
+ outlen = inlen;
+ if (ict == (iconv_t)( -1)) {
+ do_error_dialog("Incorrect charsets", "Gaim: Recode error");
+ g_free(buf2);
+ return NULL;
+ };
+ res = iconv (ict, buf, (size_t*) &inlen, &buf2, &outlen);
+ if ((iconv_t)(res) == (iconv_t)( -1)) {
+ do_error_dialog("Conversion failed", "Gaim: Recode error");
+ g_free(buf2);
+ return NULL;
+ };
+ return bufret;
+}
+
+
+static void set_conf() {
+ if (configwin && entry_their && entry_our)
+ {
+ gtk_entry_set_text(GTK_ENTRY(entry_their),send_c);
+ gtk_entry_set_text(GTK_ENTRY(entry_our),recv_c);
+ }
+ if (send != (iconv_t) -1) {
+ iconv_close(send);
+ }
+ send=conv_iconv_open(send_c,recv_c);
+ if (recv != (iconv_t) -1)
+ iconv_close(recv);
+ recv=conv_iconv_open(recv_c,send_c);
+}
+
+static void rem_conf() {
+ send_c[0]='\0';
+ recv_c[0]='\0';
+
+ if (configwin && entry_their && entry_our)
+ {
+ gtk_entry_set_text(GTK_ENTRY(entry_their),send_c);
+ gtk_entry_set_text(GTK_ENTRY(entry_our),recv_c);
+ }
+ if (send != (iconv_t) -1) {
+ iconv_close(send);
+ send = (iconv_t) -1;
+ }
+ if (recv != (iconv_t) -1) {
+ iconv_close(recv);
+ recv = (iconv_t) -1;
+ }
+}
+
+
+static void recode_send(struct gaim_connection *gc, gchar *who, gchar **message, gpointer m) {
+ gchar* buf2;
+ gchar* buf;
+ buf2=g_strdup(*message);
+ buf=conv_iconv_convert(send , message);
+ if (buf!=NULL) {
+ *message = buf;
+ g_free(buf2);
+ }
+ else *message = buf2;
+
+ return;
+}
+
+static void recode_recv(struct gaim_connection *gc, gchar *who, gchar **message, gpointer m) {
+ gchar* buf2;
+ gchar* buf;
+ buf2=g_strdup(*message);
+ buf=conv_iconv_convert(recv , message);
+ if (buf!=NULL) {
+ *message = buf;
+ g_free(buf2);
+ }
+ else *message = buf2;
+}
+
+static void load_conf() {
+ FILE* fl;
+ fl=fopen (rcfile,"r");
+ if (fl==NULL) return;
+ fscanf(fl,"%s %s",recv_c,send_c);
+ fclose(fl);
+ set_conf();
+}
+
+
+char *gaim_plugin_init(GModule *handle) {
+ send_c[0]='\0';
+ recv_c[0]='\0';
+ send = (iconv_t) -1;
+ recv = (iconv_t) -1;
+ rcfile = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, ".gaim", G_DIR_SEPARATOR_S ,"recode_charsets",NULL);
+ load_conf();
+ gaim_signal_connect(handle, event_im_displayed_sent, recode_send, NULL);
+ gaim_signal_connect(handle, event_im_recv, recode_recv, NULL);
+ return NULL;
+}
+
+void gaim_plugin_remove() {
+
+}
+
+static void on_button_cancel_clicked() {
+ if (configwin)
+ gtk_widget_destroy(configwin);
+ configwin = NULL;
+}
+
+static void on_button_ok_clicked() {
+ FILE* fl;
+ strcpy(send_c,gtk_entry_get_text(GTK_ENTRY(entry_their)));
+ strcpy(recv_c,gtk_entry_get_text(GTK_ENTRY(entry_our)));
+ fl=fopen (rcfile,"w");
+ if (fl==NULL) return;
+ fprintf(fl,"%s\n%s",recv_c,send_c);
+ fclose(fl);
+ load_conf();
+ on_button_cancel_clicked();
+}
+
+void gaim_plugin_config() {
+ GtkWidget *vbox1;
+ GtkWidget *label_head;
+ GtkWidget *table1;
+ GtkWidget *label_to;
+ GtkWidget *label_from;
+ GtkWidget *hbox2;
+ GtkWidget *button_ok;
+ GtkWidget *button_cancel;
+
+
+ if (configwin) return;
+ configwin = gtk_window_new(GTK_WINDOW_DIALOG);
+
+ gtk_window_set_title(GTK_WINDOW(configwin), "Recoding Config");
+ vbox1 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox1);
+ gtk_container_add (GTK_CONTAINER (configwin), vbox1);
+
+ label_head = gtk_label_new (_("Recoding configuration"));
+ gtk_widget_show (label_head);
+ gtk_box_pack_start (GTK_BOX (vbox1), label_head, FALSE, FALSE, 0);
+
+ table1 = gtk_table_new (2, 2, FALSE);
+ gtk_widget_show (table1);
+ gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
+
+ label_to = gtk_label_new (_(" Our charset"));
+ gtk_widget_show (label_to);
+ gtk_table_attach (GTK_TABLE (table1), label_to, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label_to), 0, 0.5);
+
+ label_from = gtk_label_new (_(" Their charset"));
+ gtk_widget_show (label_from);
+ gtk_table_attach (GTK_TABLE (table1), label_from, 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label_from), 0, 0.5);
+
+ entry_their = gtk_entry_new ();
+ gtk_widget_show (entry_their);
+ gtk_table_attach (GTK_TABLE (table1), entry_their, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ entry_our = gtk_entry_new ();
+ gtk_widget_show (entry_our);
+ gtk_table_attach (GTK_TABLE (table1), entry_our, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ hbox2 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_show (hbox2);
+ gtk_box_pack_start (GTK_BOX (vbox1), hbox2, TRUE, TRUE, 0);
+
+ button_ok = gtk_button_new_with_label (_("OK"));
+ gtk_widget_show (button_ok);
+ gtk_box_pack_start (GTK_BOX (hbox2), button_ok, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (button_ok), 4);
+
+ button_cancel = gtk_button_new_with_label (_("Cancel"));
+ gtk_widget_show (button_cancel);
+ gtk_box_pack_start (GTK_BOX (hbox2), button_cancel, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (button_cancel), 4);
+
+ gtk_signal_connect (GTK_OBJECT (button_ok), "clicked",
+ GTK_SIGNAL_FUNC (on_button_ok_clicked),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button_cancel), "clicked",
+ GTK_SIGNAL_FUNC (on_button_cancel_clicked),
+ NULL);
+ set_conf();
+ gtk_widget_show(configwin);
+}