11 #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
12 #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
14 typedef struct _PurpleGLibIOClosure {
15 PurpleInputFunction function;
18 } PurpleGLibIOClosure;
20 static void purple_glib_io_destroy(gpointer data)
25 static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
27 PurpleGLibIOClosure *closure = data;
28 PurpleInputCondition purple_cond = 0;
30 if (condition & PURPLE_GLIB_READ_COND)
31 purple_cond |= PURPLE_INPUT_READ;
32 if (condition & PURPLE_GLIB_WRITE_COND)
33 purple_cond |= PURPLE_INPUT_WRITE;
35 closure->function(closure->data, g_io_channel_unix_get_fd(source),
41 static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
44 PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
46 GIOCondition cond = 0;
48 closure->function = function;
51 if (condition & PURPLE_INPUT_READ)
52 cond |= PURPLE_GLIB_READ_COND;
53 if (condition & PURPLE_INPUT_WRITE)
54 cond |= PURPLE_GLIB_WRITE_COND;
56 channel = g_io_channel_unix_new(fd);
57 closure->result = g_io_add_watch_full(channel, 0, cond,
58 purple_glib_io_invoke, closure, purple_glib_io_destroy);
60 g_io_channel_unref(channel);
61 return closure->result;
64 static PurpleEventLoopUiOps glib_eventloops =
71 #if GLIB_CHECK_VERSION(2,14,0)
72 g_timeout_add_seconds,
82 /*** End of the eventloop functions. ***/
84 /*** Conversation uiops ***/
85 /* FIXME: Revisit this function. Is it needed? How it should be more general?*/
87 write_conv(PurpleConversation *conv, const char *who, const char *alias,
88 const char *message, PurpleMessageFlags flags, time_t mtime)
98 printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv),
99 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)),
103 static PurpleConversationUiOps conv_uiops =
105 NULL, /* create_conversation */
106 NULL, /* destroy_conversation */
107 NULL, /* write_chat */
109 write_conv, /* write_conv */
110 NULL, /* chat_add_users */
111 NULL, /* chat_rename_user */
112 NULL, /* chat_remove_users */
113 NULL, /* chat_update_user */
115 NULL, /* has_focus */
116 NULL, /* custom_smiley_add */
117 NULL, /* custom_smiley_write */
118 NULL, /* custom_smiley_close */
119 NULL, /* send_confirm */
126 /* FIXME: Is this a valid struct? */
131 * This should initialize the UI components for all the modules. Here we
132 * just initialize the UI for conversations.
134 purple_conversations_set_ui_ops(&conv_uiops);
137 static PurpleCoreUiOps core_uiops =
151 void init_libpurple(void)
153 /* Set a custom user directory (optional) */
154 /* FIXME: Put a valid carman directory here*/
155 purple_util_set_user_dir(CUSTOM_USER_DIRECTORY);
157 /* We do not want any debugging for now to keep the noise to a minimum. */
158 purple_debug_set_enabled(FALSE);
160 purple_core_set_ui_ops(&core_uiops);
162 purple_eventloop_set_ui_ops(&glib_eventloops);
164 purple_plugins_add_search_path(CUSTOM_PLUGIN_PATH);
166 if (!purple_core_init(UI_ID)) {
167 /* Initializing the core failed. Terminate. */
169 "libpurple initialization failed. Dumping core.\n"
170 "Please report this!\n");
173 printf("libpurple initialized");