[file-roller] progress dialog: show the archive name in the main message



commit 9e741444ddfc986a996bd20356fb0028d84eb347
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Jun 18 18:17:35 2012 +0200

    progress dialog: show the archive name in the main message
    
    ...and simplified the code a bit

 src/fr-window.c |  187 +++++++++++++++++++++----------------------------------
 1 files changed, 70 insertions(+), 117 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index aa5658c..d68bab1 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -269,7 +269,6 @@ struct _FrWindowPrivateData {
 	guint            help_message_cid;
 	guint            list_info_cid;
 	guint            progress_cid;
-	char *           last_status_message;
 
 	GtkWidget *      up_arrows[5];
 	GtkWidget *      down_arrows[5];
@@ -354,7 +353,6 @@ struct _FrWindowPrivateData {
 
 	GtkWidget        *progress_dialog;
 	GtkWidget        *pd_action;
-	GtkWidget        *pd_archive;
 	GtkWidget        *pd_message;
 	GtkWidget        *pd_progress_bar;
 	GtkWidget        *pd_cancel_button;
@@ -366,7 +364,6 @@ struct _FrWindowPrivateData {
 	gboolean          progress_pulse;
 	guint             progress_timeout;  /* Timeout to display the progress dialog. */
 	guint             hide_progress_timeout;  /* Timeout to hide the progress dialog. */
-	FrAction          pd_last_action;
 	char             *pd_last_archive;
 	char             *working_archive;
 	double            pd_last_fraction;
@@ -619,7 +616,6 @@ fr_window_free_private_data (FrWindow *window)
 	g_free (window->priv->pd_last_archive);
 	g_free (window->priv->pd_last_message);
 	g_free (window->priv->extract_here_dir);
-	g_free (window->priv->last_status_message);
 
 	g_settings_set_enum (window->priv->settings_listing, PREF_LISTING_SORT_METHOD, window->priv->sort_method);
 	g_settings_set_enum (window->priv->settings_listing, PREF_LISTING_SORT_TYPE, window->priv->sort_type);
@@ -2295,76 +2291,77 @@ progress_dialog_response (GtkDialog *dialog,
 }
 
 
-static const char*
-get_message_from_action (FrAction action)
+static char*
+get_action_description (FrAction    action,
+			const char *uri)
 {
-	char *message = "";
+	char *basename;
+	char *message;
+
+	basename = (uri != NULL) ? g_uri_display_basename (uri) : NULL;
 
+	message = NULL;
 	switch (action) {
 	case FR_ACTION_CREATING_NEW_ARCHIVE:
-		message = _("Creating archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Creating \"%s\""), basename);
 		break;
 	case FR_ACTION_LOADING_ARCHIVE:
-		message = _("Loading archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Loading \"%s\""), basename);
 		break;
 	case FR_ACTION_LISTING_CONTENT:
-		message = _("Reading archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Reading \"%s\""), basename);
 		break;
 	case FR_ACTION_DELETING_FILES:
-		message = _("Deleting files from archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Deleting files from \"%s\""), basename);
 		break;
 	case FR_ACTION_TESTING_ARCHIVE:
-		message = _("Testing archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Testing \"%s\""), basename);
 		break;
 	case FR_ACTION_GETTING_FILE_LIST:
-		message = _("Getting the file list");
+		message = g_strdup (_("Getting the file list"));
 		break;
 	case FR_ACTION_COPYING_FILES_FROM_REMOTE:
-		message = _("Copying the file list");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Copying the files to add to \"%s\""), basename);
 		break;
 	case FR_ACTION_ADDING_FILES:
-		message = _("Adding files to archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Adding files to \"%s\""), basename);
 		break;
 	case FR_ACTION_EXTRACTING_FILES:
-		message = _("Extracting files from archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Extracting files from \"%s\""), basename);
 		break;
 	case FR_ACTION_COPYING_FILES_TO_REMOTE:
-		message = _("Copying the file list");
+		message = g_strdup (_("Copying the extracted files to the destination"));
 		break;
 	case FR_ACTION_CREATING_ARCHIVE:
-		message = _("Creating archive");
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Creating \"%s\""), basename);
 		break;
 	case FR_ACTION_SAVING_REMOTE_ARCHIVE:
-		message = _("Saving archive");
-		break;
-	default:
-		message = "";
+		/* Translators: %s is a filename */
+		message = g_strdup_printf (_("Saving \"%s\""), basename);
 		break;
 	}
 
-	return message;
-}
-
-
-static void
-progress_dialog__set_last_action (FrWindow *window,
-				  FrAction  action)
-{
-	const char *title;
-	char       *markup;
+	g_free (basename);
 
-	window->priv->pd_last_action = action;
-	title = get_message_from_action (window->priv->pd_last_action);
-	markup = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>", title);
-	gtk_label_set_markup (GTK_LABEL (window->priv->pd_action), markup);
-	g_free (markup);
+	return message;
 }
 
 
 static void
-pd_update_archive_name (FrWindow *window)
+progress_dialog_update_action_description (FrWindow *window)
 {
-	char *current_archive;
+	const char *current_archive;
+	char       *description;
+	char       *description_markup;
 
 	if (window->priv->convert_data.converting)
 		current_archive = window->priv->convert_data.new_file;
@@ -2373,28 +2370,17 @@ pd_update_archive_name (FrWindow *window)
 	else
 		current_archive = window->priv->archive_uri;
 
-	if (strcmp_null_tolerant (window->priv->pd_last_archive, current_archive) != 0) {
-		g_free (window->priv->pd_last_archive);
-		if (current_archive == NULL) {
-			window->priv->pd_last_archive = NULL;
-			gtk_label_set_text (GTK_LABEL (window->priv->pd_archive), "");
-#ifdef LOG_PROGRESS
-			g_print ("archive name > (none)\n");
-#endif
-		}
-		else {
-			char *name;
+	g_free (window->priv->pd_last_archive);
+	window->priv->pd_last_archive = NULL;
+	if (current_archive != NULL)
+		window->priv->pd_last_archive = g_strdup (current_archive);
 
-			window->priv->pd_last_archive = g_strdup (current_archive);
+	description = get_action_description (window->priv->action, window->priv->pd_last_archive);
+	description_markup = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>", description);
+	gtk_label_set_markup (GTK_LABEL (window->priv->pd_action), description_markup);
 
-			name = g_uri_display_basename (window->priv->pd_last_archive);
-			gtk_label_set_text (GTK_LABEL (window->priv->pd_archive), name);
-#ifdef LOG_PROGRESS
-			g_print ("archive name > %s\n", name);
-#endif
-			g_free (name);
-		}
-	}
+	g_free (description_markup);
+	g_free (description);
 }
 
 
@@ -2407,7 +2393,7 @@ fr_window_working_archive_cb (FrCommand  *command,
 	window->priv->working_archive = NULL;
 	if (archive_filename != NULL)
 		window->priv->working_archive = g_strdup (archive_filename);
-	pd_update_archive_name (window);
+	progress_dialog_update_action_description (window);
 
 	return TRUE;
 }
@@ -2418,6 +2404,11 @@ fr_window_message_cb (FrCommand  *command,
 		      const char *msg,
 		      FrWindow   *window)
 {
+	if (window->priv->pd_last_message != msg) {
+		g_free (window->priv->pd_last_message);
+		window->priv->pd_last_message = g_strdup (msg);
+	}
+
 	if (window->priv->progress_dialog == NULL)
 		return TRUE;
 
@@ -2428,10 +2419,7 @@ fr_window_message_cb (FrCommand  *command,
 			msg = NULL;
 	}
 
-	if (msg == NULL) {
-		gtk_label_set_text (GTK_LABEL (window->priv->pd_message), "");
-	}
-	else {
+	if (msg != NULL) {
 		char *utf8_msg;
 
 		if (! g_utf8_validate (msg, -1, NULL))
@@ -2459,15 +2447,10 @@ fr_window_message_cb (FrCommand  *command,
 
 		g_free (utf8_msg);
 	}
+	else
+		gtk_label_set_text (GTK_LABEL (window->priv->pd_message), "");
 
-	if (window->priv->convert_data.converting) {
-		if (window->priv->pd_last_action != FR_ACTION_CREATING_ARCHIVE)
-			progress_dialog__set_last_action (window, FR_ACTION_CREATING_ARCHIVE);
-	}
-	else if (window->priv->pd_last_action != window->priv->action)
-		progress_dialog__set_last_action (window, window->priv->action);
-
-	pd_update_archive_name (window);
+	progress_dialog_update_action_description (window);
 
 	return TRUE;
 }
@@ -2500,7 +2483,6 @@ create_the_progress_dialog (FrWindow *window)
 		flags |= GTK_DIALOG_MODAL;
 	}
 
-	window->priv->pd_last_action = window->priv->action;
 	window->priv->progress_dialog = gtk_dialog_new_with_buttons ((window->priv->batch_mode ? window->priv->batch_title : NULL),
 								     parent,
 								     flags,
@@ -2533,15 +2515,10 @@ create_the_progress_dialog (FrWindow *window)
 	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
 	gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
 
-	/* action label */
+	/* action description */
 
 	lbl = window->priv->pd_action = gtk_label_new ("");
 
-	markup = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>",
-					  get_message_from_action (window->priv->pd_last_action));
-	gtk_label_set_markup (GTK_LABEL (lbl), markup);
-	g_free (markup);
-
 	align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
 	gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 12, 0, 0);
 
@@ -2556,28 +2533,8 @@ create_the_progress_dialog (FrWindow *window)
 
 	g_free (window->priv->pd_last_archive);
 	window->priv->pd_last_archive = NULL;
-	if (window->priv->archive_uri != NULL) {
-		GtkWidget *hbox;
-		char      *name;
-
-		hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-		gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
-
-		lbl = gtk_label_new ("");
-		markup = g_markup_printf_escaped ("<b>%s</b>", _("Archive:"));
-		gtk_label_set_markup (GTK_LABEL (lbl), markup);
-		g_free (markup);
-		gtk_box_pack_start (GTK_BOX (hbox), lbl, FALSE, FALSE, 0);
-
+	if (window->priv->archive_uri != NULL)
 		window->priv->pd_last_archive = g_strdup (window->priv->archive_uri);
-		name = g_uri_display_basename (window->priv->pd_last_archive);
-		lbl = window->priv->pd_archive = gtk_label_new (name);
-		g_free (name);
-
-		gtk_misc_set_alignment (GTK_MISC (lbl), 0.0, 0.5);
-		gtk_label_set_ellipsize (GTK_LABEL (lbl), PANGO_ELLIPSIZE_END);
-		gtk_box_pack_start (GTK_BOX (hbox), lbl, TRUE, TRUE, 0);
-	}
 
 	/* progress and details */
 
@@ -2599,7 +2556,7 @@ create_the_progress_dialog (FrWindow *window)
 	lbl = window->priv->pd_message = gtk_label_new ("");
 
 	attr_list = pango_attr_list_new ();
-	pango_attr_list_insert (attr_list, pango_attr_style_new (PANGO_STYLE_ITALIC));
+	pango_attr_list_insert (attr_list, pango_attr_size_new (9000));
 	gtk_label_set_attributes (GTK_LABEL (lbl), attr_list);
 	pango_attr_list_unref (attr_list);
 
@@ -2609,6 +2566,8 @@ create_the_progress_dialog (FrWindow *window)
 
 	gtk_widget_show_all (hbox);
 
+	progress_dialog_update_action_description (window);
+
 	/* signals */
 
 	g_signal_connect (G_OBJECT (window->priv->progress_dialog),
@@ -2638,7 +2597,7 @@ display_progress_dialog (gpointer data)
 			gtk_widget_show (GTK_WIDGET (window));
 		gtk_widget_hide (window->priv->progress_bar);
 		gtk_widget_show (window->priv->progress_dialog);
-		fr_window_message_cb (NULL, window->priv->last_status_message, window);
+		fr_window_message_cb (NULL, window->priv->pd_last_message, window);
 	}
 
 	window->priv->progress_timeout = 0;
@@ -2791,12 +2750,9 @@ fr_window_push_message (FrWindow   *window,
 	if (! gtk_widget_get_mapped (GTK_WIDGET (window)))
 		return;
 
-	g_free (window->priv->last_status_message);
-	window->priv->last_status_message = g_strdup (msg);
-
-	gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar), window->priv->progress_cid, window->priv->last_status_message);
-	if (window->priv->progress_dialog != NULL)
-		gtk_label_set_text (GTK_LABEL (window->priv->pd_message), window->priv->last_status_message);
+	gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar),
+			    window->priv->progress_cid,
+			    msg);
 }
 
 
@@ -2816,9 +2772,8 @@ action_started (FrArchive *archive,
 		FrAction   action,
 		gpointer   data)
 {
-	FrWindow   *window = data;
-	const char *message;
-	char       *full_msg;
+	FrWindow *window = data;
+	char     *message;
 
 	window->priv->action = action;
 	fr_window_start_activity_mode (window);
@@ -2827,9 +2782,9 @@ action_started (FrArchive *archive,
 	debug (DEBUG_INFO, "%s [START] (FR::Window)\n", action_names[action]);
 #endif
 
-	message = get_message_from_action (action);
-	full_msg = g_strdup_printf ("%s, %s", message, _("please waitâ"));
-	fr_window_push_message (window, full_msg);
+	message = get_action_description (action, window->priv->pd_last_archive);
+	fr_window_push_message (window, message);
+	g_free (message);
 
 	switch (action) {
 	case FR_ACTION_EXTRACTING_FILES:
@@ -2842,10 +2797,8 @@ action_started (FrArchive *archive,
 
 	if (archive->command != NULL) {
 		fr_command_progress (archive->command, -1.0);
-		fr_command_message (archive->command, message);
+		fr_command_message (archive->command, _("Please waitâ"));
 	}
-
-	g_free (full_msg);
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]