changeset 7738:b14442b31a9b

[gaim-migrate @ 8383] This patch from Tim R. (I'll remember your last name next time), snazzes up the file transfer dialog a bit. I also went in and hacked on gtkcellrenderer a bit, so that if you expand the column, the renderer will grow. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 04 Dec 2003 05:58:26 +0000
parents c497b3bb7581
children 2850079ad35f
files src/ft.c src/ft.h src/gtkcellrendererprogress.c src/gtkft.c
diffstat 4 files changed, 93 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/ft.c	Thu Dec 04 05:31:54 2003 +0000
+++ b/src/ft.c	Thu Dec 04 05:58:26 2003 +0000
@@ -184,6 +184,14 @@
 	return xfer->account;
 }
 
+GaimXferCancelType
+gaim_xfer_is_canceled(const GaimXfer *xfer)
+{
+	g_return_val_if_fail(xfer != NULL, TRUE);
+
+	return xfer->canceled;
+}
+
 gboolean
 gaim_xfer_is_completed(const GaimXfer *xfer)
 {
@@ -276,6 +284,14 @@
 	return xfer->remote_port;
 }
 
+static void
+gaim_xfer_set_canceled(GaimXfer *xfer, GaimXferCancelType canceled)
+{
+	g_return_if_fail(xfer != NULL);
+
+	xfer->canceled = canceled;
+}
+
 void
 gaim_xfer_set_completed(GaimXfer *xfer, gboolean completed)
 {
@@ -610,6 +626,8 @@
 
 	g_return_if_fail(xfer != NULL);
 
+	gaim_xfer_set_canceled(xfer, GAIM_XFER_CANCEL_LOCAL);
+
 	if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND)
 	{
 		if (xfer->ops.cancel_send != NULL)
@@ -649,6 +667,8 @@
 
 	g_return_if_fail(xfer != NULL);
 
+	gaim_xfer_set_canceled(xfer, GAIM_XFER_CANCEL_REMOTE);
+
 	if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND)
 	{
 		if (xfer->ops.cancel_send != NULL)
--- a/src/ft.h	Thu Dec 04 05:31:54 2003 +0000
+++ b/src/ft.h	Thu Dec 04 05:58:26 2003 +0000
@@ -41,6 +41,13 @@
 
 } GaimXferType;
 
+typedef enum
+{
+	GAIM_XFER_CANCEL_NOT = 0,
+	GAIM_XFER_CANCEL_LOCAL,
+	GAIM_XFER_CANCEL_REMOTE
+} GaimXferCancelType;
+
 /**
  * File transfer UI operations.
  *
@@ -89,6 +96,7 @@
 	size_t bytes_sent;            /**< The number of bytes sent.           */
 	size_t bytes_remaining;       /**< The number of bytes remaining.      */
 
+	GaimXferCancelType canceled;            /**< File Transfer is canceled.          */
 	gboolean completed;           /**< File Transfer is completed.         */
 
 	/* I/O operations. */
@@ -180,6 +188,15 @@
 GaimAccount *gaim_xfer_get_account(const GaimXfer *xfer);
 
 /**
+ * Returns true if the file transfer was canceled.
+ *
+ * @param xfer The file transfer.
+ *
+ * @return Whether or not the transfer was canceled.
+ */
+GaimXferCancelType gaim_xfer_is_canceled(const GaimXfer *xfer);
+
+/**
  * Returns the completed state for a file transfer.
  *
  * @param xfer The file transfer.
--- a/src/gtkcellrendererprogress.c	Thu Dec 04 05:31:54 2003 +0000
+++ b/src/gtkcellrendererprogress.c	Thu Dec 04 05:58:26 2003 +0000
@@ -260,13 +260,10 @@
 	GtkCellRendererProgress *cellprogress = (GtkCellRendererProgress *) cell;
 	
 	gint width, height;
-	gint x_offset, y_offset;
 	GtkStateType state;
 
-	gtk_cell_renderer_progress_get_size (cell, widget, cell_area,
-					   &x_offset, &y_offset,
-					   &width, &height);
-	
+	width = cell_area->width;
+	height = cell_area->height;
 	
 	if (GTK_WIDGET_HAS_FOCUS (widget))
 		state = GTK_STATE_ACTIVE;
@@ -282,15 +279,15 @@
 		       window,
 		       GTK_STATE_NORMAL, GTK_SHADOW_IN, 
 		       NULL, widget, "trough",
-		       cell_area->x + x_offset + cell->xpad,
-		       cell_area->y + y_offset + cell->ypad,
+		       cell_area->x + cell->xpad,
+		       cell_area->y + cell->ypad,
 		       width - 1, height - 1);
 	gtk_paint_box (widget->style,
 		       window,
 		       state, GTK_SHADOW_OUT,
 		       NULL, widget, "bar",
-		       cell_area->x + x_offset + cell->xpad + 1,
-		       cell_area->y + y_offset + cell->ypad + 1,
+		       cell_area->x + cell->xpad + 1,
+		       cell_area->y + cell->ypad + 1,
 		       (width - 3) * cellprogress->progress,
 		       height - 3);
 }
--- a/src/gtkft.c	Thu Dec 04 05:31:54 2003 +0000
+++ b/src/gtkft.c	Thu Dec 04 05:58:26 2003 +0000
@@ -204,8 +204,15 @@
 
 	gtk_label_set_text(GTK_LABEL(dialog->user_label), xfer->who);
 
-	gtk_label_set_text(GTK_LABEL(dialog->filename_label),
+	if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) {
+		gtk_label_set_text(GTK_LABEL(dialog->filename_label),
 					   gaim_xfer_get_filename(xfer));
+	} else {
+		char *tmp;
+		tmp = g_path_get_basename(gaim_xfer_get_local_filename(xfer));
+		gtk_label_set_text(GTK_LABEL(dialog->filename_label), tmp);
+		g_free(tmp);
+	}
 
 	gtk_label_set_text(GTK_LABEL(dialog->status_label), status);
 
@@ -251,8 +258,16 @@
 		gtk_widget_set_sensitive(dialog->resume_button, FALSE);
 
 		gtk_widget_set_sensitive(dialog->remove_button, TRUE);
-	}
-	else {
+	} else if (gaim_xfer_is_canceled(xfer)) {
+		gtk_widget_hide(dialog->stop_button);
+		gtk_widget_show(dialog->remove_button);
+
+		gtk_widget_set_sensitive(dialog->open_button,  FALSE);
+		gtk_widget_set_sensitive(dialog->pause_button,  FALSE);
+		gtk_widget_set_sensitive(dialog->resume_button, FALSE);
+
+		gtk_widget_set_sensitive(dialog->remove_button, TRUE);
+	} else {
 		gtk_widget_show(dialog->stop_button);
 		gtk_widget_hide(dialog->remove_button);
 
@@ -604,8 +619,8 @@
 	gtk_widget_show(checkbox);
 
 	/* "Download Details" arrow */
-	disclosure = gaim_disclosure_new(_("Show download details"),
-									 _("Hide download details"));
+	disclosure = gaim_disclosure_new(_("Show transfer details"),
+									 _("Hide transfer details"));
 	dialog->disclosure = disclosure;
 	gtk_box_pack_start(GTK_BOX(vbox2), disclosure, FALSE, FALSE, 0);
 	gtk_widget_show(disclosure);
@@ -746,6 +761,7 @@
 	GaimXferType type;
 	GdkPixbuf *pixbuf;
 	char *size_str, *remaining_str;
+	char *lfilename;
 
 	g_return_if_fail(dialog != NULL);
 	g_return_if_fail(xfer != NULL);
@@ -768,14 +784,18 @@
 									GTK_ICON_SIZE_MENU, NULL);
 
 	gtk_list_store_append(dialog->model, &data->iter);
+	lfilename = g_path_get_basename(gaim_xfer_get_local_filename(xfer));
 	gtk_list_store_set(dialog->model, &data->iter,
 					   COLUMN_STATUS, pixbuf,
 					   COLUMN_PROGRESS, 0.0,
-					   COLUMN_FILENAME, gaim_xfer_get_filename(xfer),
+					   COLUMN_FILENAME, (type == GAIM_XFER_RECEIVE)
+					                     ? gaim_xfer_get_filename(xfer)
+							     : lfilename,
 					   COLUMN_SIZE, size_str,
 					   COLUMN_REMAINING, remaining_str,
 					   COLUMN_DATA, xfer,
 					   -1);
+	g_free(lfilename);
 
 	gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dialog->tree));
 
@@ -823,9 +843,9 @@
 								GaimXfer *xfer)
 {
 	GaimGtkXferUiData *data;
-#if 0
 	GdkPixbuf *pixbuf;
-#endif
+	gchar *status;
+
 
 	g_return_if_fail(dialog != NULL);
 	g_return_if_fail(xfer != NULL);
@@ -835,31 +855,42 @@
 	if (data == NULL)
 		return;
 
-	gtk_list_store_remove(GTK_LIST_STORE(dialog->model), &data->iter);
+
+	if ((gaim_xfer_is_canceled(xfer) == GAIM_XFER_CANCEL_LOCAL) && (dialog->auto_clear)) {
+		gtk_list_store_remove(GTK_LIST_STORE(dialog->model), &data->iter);
 
-	g_free(data->name);
-	g_free(data);
+		g_free(data->name);
+		g_free(data);
 
-	xfer->ui_data = NULL;
+		xfer->ui_data = NULL;
 
-	dialog->num_transfers--;
+		dialog->num_transfers--;
 
-	if (dialog->num_transfers == 0 && !dialog->keep_open)
-		gaim_gtkxfer_dialog_hide(dialog);
+		if (dialog->num_transfers == 0 && !dialog->keep_open)
+			gaim_gtkxfer_dialog_hide(dialog);
 
-#if 0
+		return;
+	}
+
 	data = GAIM_GTKXFER(xfer);
 
 	pixbuf = gtk_widget_render_icon(dialog->window,
 									GAIM_STOCK_FILE_CANCELED,
 									GTK_ICON_SIZE_MENU, NULL);
 
+	if (gaim_xfer_is_canceled(xfer) == GAIM_XFER_CANCEL_LOCAL)
+		status = _("Canceled");
+	else
+		status = _("Failed");
+
 	gtk_list_store_set(dialog->model, &data->iter,
-					   COLUMN_STATUS, pixbuf,
-					   -1);
+	                   COLUMN_STATUS, pixbuf,
+	                   COLUMN_REMAINING, status,
+	                   -1);
 
 	g_object_unref(pixbuf);
-#endif
+
+	update_buttons(dialog, xfer);
 }
 
 void