X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=c_purple.c;h=1130a5b1e71f1412ae7f0f158a6a5aecf5a0d1a5;hp=e5d5fa0aaa3d773a2081ed5475f43d5d17430c73;hb=bbd0f131da05d704e16ad19669fe7ef27a9ad6e0;hpb=30f1e323b5bd76f5789b6251454e388cc511e2d5 diff --git a/c_purple.c b/c_purple.c index e5d5fa0..1130a5b 100644 --- a/c_purple.c +++ b/c_purple.c @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia + * + * This file is part of python-purple. + * + * python-purple 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 3 of the License, or + * (at your option) any later version. + * + * python-purple 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 this program. If not, see . + * + */ + #include #include @@ -17,12 +37,8 @@ typedef struct _PurpleGLibIOClosure { 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) +static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, + gpointer data) { PurpleGLibIOClosure *closure = data; PurpleInputCondition purple_cond = 0; @@ -38,7 +54,7 @@ static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition return TRUE; } -static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, +guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1); @@ -55,120 +71,8 @@ static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInput channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, 0, cond, - purple_glib_io_invoke, closure, purple_glib_io_destroy); + purple_glib_io_invoke, closure, g_free); 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 -}; -/*** End of the eventloop functions. ***/ - -/*** Conversation uiops ***/ -/* FIXME: Revisit this function. Is it needed? How it should be more general?*/ -static void -write_conv(PurpleConversation *conv, const char *who, const char *alias, - const char *message, PurpleMessageFlags flags, time_t mtime) -{ - const char *name; - if (alias && *alias) - name = alias; - else if (who && *who) - name = who; - else - name = NULL; - - printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv), - purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)), - name, message); -} - -static PurpleConversationUiOps conv_uiops = -{ - NULL, /* create_conversation */ - NULL, /* destroy_conversation */ - NULL, /* write_chat */ - NULL, /* write_im */ - write_conv, /* write_conv */ - NULL, /* chat_add_users */ - NULL, /* chat_rename_user */ - NULL, /* chat_remove_users */ - NULL, /* chat_update_user */ - NULL, /* present */ - NULL, /* has_focus */ - NULL, /* custom_smiley_add */ - NULL, /* custom_smiley_write */ - NULL, /* custom_smiley_close */ - NULL, /* send_confirm */ - NULL, - NULL, - NULL, - NULL -}; - -/* FIXME: Is this a valid struct? */ -static void -ui_init(void) -{ - /** - * This should initialize the UI components for all the modules. Here we - * just initialize the UI for conversations. - */ - purple_conversations_set_ui_ops(&conv_uiops); -} - -static PurpleCoreUiOps core_uiops = -{ - NULL, - NULL, - ui_init, - NULL, - - /* padding */ - NULL, - NULL, - NULL, - NULL -}; - -void init_libpurple(void) -{ - /* Set a custom user directory (optional) */ - /* FIXME: Put a valid carman directory here*/ - purple_util_set_user_dir(CUSTOM_USER_DIRECTORY); - - /* We do not want any debugging for now to keep the noise to a minimum. */ - purple_debug_set_enabled(FALSE); - - purple_core_set_ui_ops(&core_uiops); - - purple_eventloop_set_ui_ops(&glib_eventloops); - - purple_plugins_add_search_path(CUSTOM_PLUGIN_PATH); - - if (!purple_core_init(UI_ID)) { - /* Initializing the core failed. Terminate. */ - fprintf(stderr, - "libpurple initialization failed. Dumping core.\n" - "Please report this!\n"); - abort(); - } - printf("libpurple initialized"); -}