I just noticed I didn't differentiate bn_IN from bn when I added this translation.
[pidgin-git.git] / pidgin / gtkeventloop.c
blob4192a539caab57ddd6eabff11a1257eae7b4c094
1 /**
2 * @file gtk_eventloop.c Purple Event Loop API (gtk implementation)
3 * @ingroup pidgin
4 */
6 /* pidgin
8 * Pidgin is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #include <glib.h>
28 #include "gtkeventloop.h"
29 #include "eventloop.h"
30 #ifdef _WIN32
31 #include "win32dep.h"
32 #endif
34 #define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
35 #define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
37 typedef struct _PidginIOClosure {
38 PurpleInputFunction function;
39 guint result;
40 gpointer data;
42 } PidginIOClosure;
44 static gboolean pidgin_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
46 PidginIOClosure *closure = data;
47 PurpleInputCondition purple_cond = 0;
49 if (condition & PIDGIN_READ_COND)
50 purple_cond |= PURPLE_INPUT_READ;
51 if (condition & PIDGIN_WRITE_COND)
52 purple_cond |= PURPLE_INPUT_WRITE;
54 #if 0
55 purple_debug_misc("gtk_eventloop",
56 "CLOSURE: callback for %d, fd is %d\n",
57 closure->result, g_io_channel_unix_get_fd(source));
58 #endif
60 #ifdef _WIN32
61 if(! purple_cond) {
62 #ifdef DEBUG
63 purple_debug_misc("gtk_eventloop",
64 "CLOSURE received GIOCondition of 0x%x, which does not"
65 " match 0x%x (READ) or 0x%x (WRITE)\n",
66 condition, PIDGIN_READ_COND, PIDGIN_WRITE_COND);
67 #endif /* DEBUG */
69 return TRUE;
71 #endif /* _WIN32 */
73 closure->function(closure->data, g_io_channel_unix_get_fd(source),
74 purple_cond);
76 return TRUE;
79 static guint pidgin_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
80 gpointer data)
82 PidginIOClosure *closure = g_new0(PidginIOClosure, 1);
83 GIOChannel *channel;
84 GIOCondition cond = 0;
85 #ifdef _WIN32
86 static int use_glib_io_channel = -1;
88 if (use_glib_io_channel == -1)
89 use_glib_io_channel = (g_getenv("PIDGIN_GLIB_IO_CHANNEL") != NULL) ? 1 : 0;
90 #endif
92 closure->function = function;
93 closure->data = data;
95 if (condition & PURPLE_INPUT_READ)
96 cond |= PIDGIN_READ_COND;
97 if (condition & PURPLE_INPUT_WRITE)
98 cond |= PIDGIN_WRITE_COND;
100 #ifdef _WIN32
101 if (use_glib_io_channel == 0)
102 channel = wpurple_g_io_channel_win32_new_socket(fd);
103 else
104 #endif
105 channel = g_io_channel_unix_new(fd);
107 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
108 pidgin_io_invoke, closure, g_free);
110 #if 0
111 purple_debug_misc("gtk_eventloop",
112 "CLOSURE: adding input watcher %d for fd %d\n",
113 closure->result, fd);
114 #endif
116 g_io_channel_unref(channel);
117 return closure->result;
120 static PurpleEventLoopUiOps eventloop_ops =
122 g_timeout_add,
123 g_source_remove,
124 pidgin_input_add,
125 g_source_remove,
126 NULL, /* input_get_error */
127 #if GLIB_CHECK_VERSION(2,14,0)
128 g_timeout_add_seconds,
129 #else
130 NULL,
131 #endif
132 NULL,
133 NULL,
134 NULL
137 PurpleEventLoopUiOps *
138 pidgin_eventloop_get_ui_ops(void)
140 return &eventloop_ops;