changeset 22216:b99d6d21cd79

Add accessor and update finch to not touch the internals of PurpleXfer.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 26 Jan 2008 21:58:51 +0000
parents 07c2b8fa7bb4
children ad357ca94de9
files ChangeLog.API finch/gntft.c libpurple/ft.c libpurple/ft.h
diffstat 4 files changed, 49 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sat Jan 26 21:39:29 2008 +0000
+++ b/ChangeLog.API	Sat Jan 26 21:58:51 2008 +0000
@@ -40,6 +40,8 @@
 		* Added some more accessor functions:
 			* purple_chat_get_account
 			* purple_connection_get_prpl
+			* purple_xfer_get_start_time
+			* purple_xfer_get_end_time
 
 	Pidgin:
 		Added:
--- a/finch/gntft.c	Sat Jan 26 21:39:29 2008 +0000
+++ b/finch/gntft.c	Sat Jan 26 21:58:51 2008 +0000
@@ -168,9 +168,15 @@
 stop_button_cb(GntButton *button)
 {
 	PurpleXfer *selected_xfer = gnt_tree_get_selection_data(GNT_TREE(xfer_dialog->tree));
-	if (selected_xfer && selected_xfer->status != PURPLE_XFER_STATUS_CANCEL_LOCAL &&
-			selected_xfer->status != PURPLE_XFER_STATUS_CANCEL_REMOTE &&
-			selected_xfer->status != PURPLE_XFER_STATUS_DONE)
+	PurpleXferStatusType status;
+
+	if (!selected_xfer)
+		return;
+
+	status = purple_xfer_get_status(selected_xfer);
+	if (status != PURPLE_XFER_STATUS_CANCEL_LOCAL &&
+			status != PURPLE_XFER_STATUS_CANCEL_REMOTE &&
+			status != PURPLE_XFER_STATUS_DONE)
 		purple_xfer_cancel_local(selected_xfer);
 }
 
@@ -397,14 +403,12 @@
 	time_t elapsed, now;
 	char *kbsec;
 
-	if (xfer->end_time != 0)
-		now = xfer->end_time;
-	else
+	if ((now = purple_xfer_get_end_time(xfer)) == 0)
 		now = time(NULL);
 
 	kb_sent = purple_xfer_get_bytes_sent(xfer) / 1024.0;
 	kb_rem  = purple_xfer_get_bytes_remaining(xfer) / 1024.0;
-	elapsed = (xfer->start_time > 0 ? now - xfer->start_time : 0);
+	elapsed = (purple_xfer_get_start_time(xfer) > 0 ? now - purple_xfer_get_start_time(xfer) : 0);
 	kbps    = (elapsed > 0 ? (kb_sent / elapsed) : 0);
 
 	g_return_if_fail(xfer_dialog != NULL);
--- a/libpurple/ft.c	Sat Jan 26 21:39:29 2008 +0000
+++ b/libpurple/ft.c	Sat Jan 26 21:58:51 2008 +0000
@@ -669,6 +669,22 @@
 	return xfer->remote_port;
 }
 
+time_t
+purple_xfer_get_start_time(const PurpleXfer *xfer)
+{
+	g_return_val_if_fail(xfer != NULL, 0);
+
+	return xfer->start_time;
+}
+
+time_t
+purple_xfer_get_end_time(const PurpleXfer *xfer)
+{
+	g_return_val_if_fail(xfer != NULL, 0);
+
+	return xfer->end_time;
+}
+
 void
 purple_xfer_set_completed(PurpleXfer *xfer, gboolean completed)
 {
--- a/libpurple/ft.h	Sat Jan 26 21:39:29 2008 +0000
+++ b/libpurple/ft.h	Sat Jan 26 21:58:51 2008 +0000
@@ -358,6 +358,26 @@
 unsigned int purple_xfer_get_remote_port(const PurpleXfer *xfer);
 
 /**
+ * Returns the time the transfer of a file started.
+ *
+ * @param xfer  The file transfer.
+ *
+ * @return The time when the transfer started.
+ * @since 2.4.0
+ */
+time_t purple_xfer_get_start_time(const PurpleXfer *xfer);
+
+/**
+ * Returns the time the transfer of a file ended.
+ *
+ * @param xfer  The file transfer.
+ *
+ * @return The time when the transfer ended.
+ * @since 2.4.0
+ */
+time_t purple_xfer_get_end_time(const PurpleXfer *xfer);
+
+/**
  * Sets the completed state for the file transfer.
  *
  * @param xfer      The file transfer.