12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "event-loop.h"
- #include "purple.h"
- #include <glib.h>
- /**
- * The following eventloop functions are used in both pidgin and purple-text. If your
- * application uses glib mainloop, you can safely use this verbatim.
- */
- #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
- #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
- typedef struct _PurpleGLibIOClosure {
- PurpleInputFunction function;
- guint result;
- gpointer data;
- } PurpleGLibIOClosure;
- static void purple_glib_io_destroy(gpointer data)
- {
- g_free(data);
- }
- static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
- {
- PurpleGLibIOClosure *closure = data;
- PurpleInputCondition purple_cond = 0;
- if (condition & PURPLE_GLIB_READ_COND)
- purple_cond |= PURPLE_INPUT_READ;
- if (condition & PURPLE_GLIB_WRITE_COND)
- purple_cond |= PURPLE_INPUT_WRITE;
- closure->function(closure->data, g_io_channel_unix_get_fd(source),
- purple_cond);
- return TRUE;
- }
- static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
- gpointer data)
- {
- PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
- GIOChannel *channel;
- GIOCondition cond = 0;
- closure->function = function;
- closure->data = data;
- if (condition & PURPLE_INPUT_READ)
- cond |= PURPLE_GLIB_READ_COND;
- if (condition & PURPLE_INPUT_WRITE)
- cond |= PURPLE_GLIB_WRITE_COND;
- #if defined _WIN32 && !defined WINPIDGIN_USE_GLIB_IO_CHANNEL
- channel = wpurple_g_io_channel_win32_new_socket(fd);
- #else
- channel = g_io_channel_unix_new(fd);
- #endif
- closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
- purple_glib_io_invoke, closure, purple_glib_io_destroy);
- g_io_channel_unref(channel);
- return closure->result;
- }
- static PurpleEventLoopUiOps glib_eventloops =
- {
- g_timeout_add,
- g_source_remove,
- glib_input_add,
- g_source_remove,
- NULL,
- #if GLIB_CHECK_VERSION(2,14,0)
- g_timeout_add_seconds,
- #else
- NULL,
- #endif
- /* padding */
- NULL,
- NULL,
- NULL
- };
- void
- sapphire_set_eventloop(void)
- {
- purple_eventloop_set_ui_ops(&glib_eventloops);
- }
- /*** End of the eventloop functions. ***/
|