/soc/2013/ankitkv/gobjectification: 6043d2b7f55a: Started GObjec...
Ankit Vani
a at nevitus.org
Thu Sep 5 18:34:27 EDT 2013
Changeset: 6043d2b7f55a2d7c68e1a50dd85e1859fd0d9952
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-06 04:04 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/6043d2b7f55a
Description:
Started GObjectification of xfer.c
diffstat:
libpurple/xfer.c | 812 ++++++++++++++++++++++++++++--------------------------
libpurple/xfer.h | 2 +-
2 files changed, 426 insertions(+), 388 deletions(-)
diffs (truncated from 1678 to 300 lines):
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -46,12 +46,6 @@ typedef struct _PurpleXferPrivate Purpl
static PurpleXferUiOps *xfer_ui_ops = NULL;
static GList *xfers;
-/* TODO remove.
- * A hack to store more data since we can't extend the size of PurpleXfer
- * easily.
- */
-static GHashTable *xfers_data = NULL;
-
/** Private data for a file transfer */
struct _PurpleXferPrivate {
PurpleXferType type; /**< The type of transfer. */
@@ -129,21 +123,6 @@ struct _PurpleXferPrivate {
static int purple_xfer_choose_file(PurpleXfer *xfer);
-static void
-purple_xfer_priv_data_destroy(gpointer data)
-{
- PurpleXferPrivate *priv = data;
-
- if (priv->buffer)
- g_byte_array_free(priv->buffer, TRUE);
-
- g_free(priv->thumbnail_data);
-
- g_free(priv->thumbnail_mimetype);
-
- g_free(priv);
-}
-
static const gchar *
purple_xfer_status_type_to_string(PurpleXferStatus type)
{
@@ -168,135 +147,24 @@ purple_xfer_status_type_to_string(Purple
return "invalid state";
}
-GList *
-purple_xfers_get_all()
-{
- return xfers;
-}
-
-PurpleXfer *
-purple_xfer_new(PurpleAccount *account, PurpleXferType type, const char *who)
-{
- PurpleXfer *xfer;
- PurpleXferUiOps *ui_ops;
- PurpleXferPrivate *priv;
-
- g_return_val_if_fail(type != PURPLE_XFER_UNKNOWN, NULL);
- g_return_val_if_fail(account != NULL, NULL);
- g_return_val_if_fail(who != NULL, NULL);
-
- xfer = g_new0(PurpleXfer, 1);
- PURPLE_DBUS_REGISTER_POINTER(xfer, PurpleXfer);
-
- xfer->ref = 1;
- xfer->type = type;
- xfer->account = account;
- xfer->who = g_strdup(who);
- xfer->ui_ops = ui_ops = purple_xfers_get_ui_ops();
- xfer->message = NULL;
- xfer->current_buffer_size = FT_INITIAL_BUFFER_SIZE;
- xfer->fd = -1;
-
- priv = g_new0(PurpleXferPrivate, 1);
- priv->ready = PURPLE_XFER_READY_NONE;
-
- if (ui_ops && ui_ops->data_not_sent) {
- /* If the ui will handle unsent data no need for buffer */
- priv->buffer = NULL;
- } else {
- priv->buffer = g_byte_array_sized_new(FT_INITIAL_BUFFER_SIZE);
- }
-
- g_hash_table_insert(xfers_data, xfer, priv);
-
- ui_ops = purple_xfer_get_ui_ops(xfer);
-
- if (ui_ops != NULL && ui_ops->new_xfer != NULL)
- ui_ops->new_xfer(xfer);
-
- xfers = g_list_prepend(xfers, xfer);
-
- if (purple_debug_is_verbose())
- purple_debug_info("xfer", "new %p [%d]\n", xfer, xfer->ref);
-
- return xfer;
-}
-
-static void
-purple_xfer_destroy(PurpleXfer *xfer)
-{
- PurpleXferUiOps *ui_ops;
-
- g_return_if_fail(xfer != NULL);
-
- if (purple_debug_is_verbose())
- purple_debug_info("xfer", "destroyed %p [%d]\n", xfer, xfer->ref);
-
- /* Close the file browser, if it's open */
- purple_request_close_with_handle(xfer);
-
- if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED)
- purple_xfer_cancel_local(xfer);
-
- ui_ops = purple_xfer_get_ui_ops(xfer);
-
- if (ui_ops != NULL && ui_ops->destroy != NULL)
- ui_ops->destroy(xfer);
-
- g_free(xfer->who);
- g_free(xfer->filename);
- g_free(xfer->remote_ip);
- g_free(xfer->local_filename);
-
- g_hash_table_remove(xfers_data, xfer);
-
- PURPLE_DBUS_UNREGISTER_POINTER(xfer);
- xfers = g_list_remove(xfers, xfer);
- g_free(xfer);
-}
-
-void
-g_object_ref(PurpleXfer *xfer)
-{
- g_return_if_fail(xfer != NULL);
-
- xfer->ref++;
-
- if (purple_debug_is_verbose())
- purple_debug_info("xfer", "ref'd %p [%d]\n", xfer, xfer->ref);
-}
-
-void
-g_object_unref(PurpleXfer *xfer)
-{
- g_return_if_fail(xfer != NULL);
- g_return_if_fail(xfer->ref > 0);
-
- xfer->ref--;
-
- if (purple_debug_is_verbose())
- purple_debug_info("xfer", "unref'd %p [%d]\n", xfer, xfer->ref);
-
- if (xfer->ref == 0)
- purple_xfer_destroy(xfer);
-}
-
void
purple_xfer_set_status(PurpleXfer *xfer, PurpleXferStatus status)
{
- g_return_if_fail(xfer != NULL);
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
+
+ g_return_if_fail(priv != NULL);
if (purple_debug_is_verbose())
purple_debug_info("xfer", "Changing status of xfer %p from %s to %s\n",
- xfer, purple_xfer_status_type_to_string(xfer->status),
+ xfer, purple_xfer_status_type_to_string(priv->status),
purple_xfer_status_type_to_string(status));
- if (xfer->status == status)
+ if (priv->status == status)
return;
- xfer->status = status;
+ priv->status = status;
- if(xfer->type == PURPLE_XFER_SEND) {
+ if(priv->type == PURPLE_XFER_SEND) {
switch(status) {
case PURPLE_XFER_STATUS_ACCEPTED:
purple_signal_emit(purple_xfers_get_handle(), "file-send-accept", xfer);
@@ -314,7 +182,7 @@ purple_xfer_set_status(PurpleXfer *xfer,
default:
break;
}
- } else if(xfer->type == PURPLE_XFER_RECEIVE) {
+ } else if(priv->type == PURPLE_XFER_RECEIVE) {
switch(status) {
case PURPLE_XFER_STATUS_ACCEPTED:
purple_signal_emit(purple_xfers_get_handle(), "file-recv-accept", xfer);
@@ -344,13 +212,14 @@ purple_xfer_conversation_write_internal(
char *escaped;
gconstpointer thumbnail_data;
gsize size;
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
- g_return_if_fail(xfer != NULL);
+ g_return_if_fail(priv != NULL);
g_return_if_fail(message != NULL);
thumbnail_data = purple_xfer_get_thumbnail(xfer, &size);
- im = purple_conversations_find_im_with_account(xfer->who,
+ im = purple_conversations_find_im_with_account(priv->who,
purple_xfer_get_account(xfer));
if (im == NULL)
@@ -402,6 +271,7 @@ static void purple_xfer_show_file_error(
gchar *msg = NULL, *utf8;
PurpleXferType xfer_type = purple_xfer_get_xfer_type(xfer);
PurpleAccount *account = purple_xfer_get_account(xfer);
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
switch(xfer_type) {
@@ -421,7 +291,7 @@ static void purple_xfer_show_file_error(
g_free(utf8);
purple_xfer_conversation_write(xfer, msg, TRUE);
- purple_xfer_error(xfer_type, account, xfer->who, msg);
+ purple_xfer_error(xfer_type, account, priv->who, msg);
g_free(msg);
}
@@ -529,11 +399,13 @@ purple_xfer_choose_file_cancel_cb(void *
static int
purple_xfer_choose_file(PurpleXfer *xfer)
{
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
+
purple_request_file(xfer, NULL, purple_xfer_get_filename(xfer),
(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_RECEIVE),
G_CALLBACK(purple_xfer_choose_file_ok_cb),
G_CALLBACK(purple_xfer_choose_file_cancel_cb),
- purple_xfer_get_account(xfer), xfer->who, NULL,
+ purple_xfer_get_account(xfer), priv->who, NULL,
xfer);
return 0;
@@ -552,6 +424,7 @@ cancel_recv_cb(PurpleXfer *xfer)
static void
purple_xfer_ask_recv(PurpleXfer *xfer)
{
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
char *buf, *size_buf;
goffset size;
gconstpointer thumb;
@@ -560,36 +433,36 @@ purple_xfer_ask_recv(PurpleXfer *xfer)
/* If we have already accepted the request, ask the destination file
name directly */
if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_ACCEPTED) {
- PurpleBuddy *buddy = purple_blist_find_buddy(xfer->account, xfer->who);
+ PurpleBuddy *buddy = purple_blist_find_buddy(priv->account, priv->who);
if (purple_xfer_get_filename(xfer) != NULL)
{
size = purple_xfer_get_size(xfer);
size_buf = purple_str_size_to_units(size);
buf = g_strdup_printf(_("%s wants to send you %s (%s)"),
- buddy ? purple_buddy_get_alias(buddy) : xfer->who,
+ buddy ? purple_buddy_get_alias(buddy) : priv->who,
purple_xfer_get_filename(xfer), size_buf);
g_free(size_buf);
}
else
{
buf = g_strdup_printf(_("%s wants to send you a file"),
- buddy ? purple_buddy_get_alias(buddy) : xfer->who);
+ buddy ? purple_buddy_get_alias(buddy) : priv->who);
}
- if (xfer->message != NULL)
- serv_got_im(purple_account_get_connection(xfer->account),
- xfer->who, xfer->message, 0, time(NULL));
+ if (priv->message != NULL)
+ serv_got_im(purple_account_get_connection(priv->account),
+ priv->who, priv->message, 0, time(NULL));
if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
purple_request_accept_cancel_with_icon(xfer, NULL, buf, NULL,
- PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
+ PURPLE_DEFAULT_ACTION_NONE, priv->account, priv->who, NULL,
thumb, thumb_size, xfer,
G_CALLBACK(purple_xfer_choose_file),
G_CALLBACK(cancel_recv_cb));
} else {
purple_request_accept_cancel(xfer, NULL, buf, NULL,
- PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
+ PURPLE_DEFAULT_ACTION_NONE, priv->account, priv->who, NULL,
xfer, G_CALLBACK(purple_xfer_choose_file),
G_CALLBACK(cancel_recv_cb));
}
@@ -619,11 +492,12 @@ ask_accept_cancel(PurpleXfer *xfer)
static void
purple_xfer_ask_accept(PurpleXfer *xfer)
{
+ PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
char *buf, *buf2 = NULL;
- PurpleBuddy *buddy = purple_blist_find_buddy(xfer->account, xfer->who);
+ PurpleBuddy *buddy = purple_blist_find_buddy(priv->account, priv->who);
More information about the Commits
mailing list