file-operations: fix toolbar button not showing soon

We were not taking into account the time the operations
takes to prepare the operation itself. That makes big
operations take more time than needed for show the toolbar
operations button feedback than expected (2 seconds).
Fix that exposing a new timer that takes into account all
the time since the start of the operation and use that
for deciding when to show the file operations toolbar button
or not.

https://bugzilla.gnome.org/show_bug.cgi?id=756096
parent 45a5c5a4
......@@ -49,6 +49,8 @@ struct _NautilusProgressInfo
GCancellable *cancellable;
guint cancellable_id;
GCancellable *details_in_thread_cancellable;
GTimer *progress_timer;
char *status;
char *details;
......@@ -90,6 +92,7 @@ nautilus_progress_info_finalize (GObject *object)
g_free (info->status);
g_free (info->details);
g_clear_object (&info->progress_timer);
g_cancellable_disconnect (info->cancellable, info->cancellable_id);
g_object_unref (info->cancellable);
g_cancellable_cancel (info->details_in_thread_cancellable);
......@@ -294,6 +297,7 @@ set_details_in_thread (GTask *task,
nautilus_progress_info_set_details (info, _("Cancelled"));
G_LOCK (progress_info);
info->cancel_at_idle = TRUE;
g_timer_stop (info->progress_timer);
queue_idle (info, TRUE);
G_UNLOCK (progress_info);
}
......@@ -330,6 +334,7 @@ nautilus_progress_info_init (NautilusProgressInfo *info)
manager = nautilus_progress_info_manager_dup_singleton ();
nautilus_progress_info_manager_add_new_info (manager, info);
g_object_unref (manager);
info->progress_timer = g_timer_new ();
}
NautilusProgressInfo *
......@@ -402,6 +407,7 @@ nautilus_progress_info_cancel (NautilusProgressInfo *info)
G_LOCK (progress_info);
g_cancellable_cancel (info->cancellable);
g_timer_stop (info->progress_timer);
G_UNLOCK (progress_info);
}
......@@ -481,6 +487,7 @@ nautilus_progress_info_pause (NautilusProgressInfo *info)
if (!info->paused) {
info->paused = TRUE;
g_timer_stop (info->progress_timer);
}
G_UNLOCK (progress_info);
......@@ -493,6 +500,7 @@ nautilus_progress_info_resume (NautilusProgressInfo *info)
if (info->paused) {
info->paused = FALSE;
g_timer_continue (info->progress_timer);
}
G_UNLOCK (progress_info);
......@@ -505,6 +513,7 @@ nautilus_progress_info_start (NautilusProgressInfo *info)
if (!info->started) {
info->started = TRUE;
g_timer_start (info->progress_timer);
info->start_at_idle = TRUE;
queue_idle (info, TRUE);
......@@ -520,6 +529,7 @@ nautilus_progress_info_finish (NautilusProgressInfo *info)
if (!info->finished) {
info->finished = TRUE;
g_timer_stop (info->progress_timer);
info->finish_at_idle = TRUE;
queue_idle (info, TRUE);
......@@ -691,6 +701,19 @@ nautilus_progress_info_get_elapsed_time (NautilusProgressInfo *info)
return elapsed_time;
}
gdouble
nautilus_progress_info_get_total_elapsed_time (NautilusProgressInfo *info)
{
gdouble elapsed_time;
G_LOCK (progress_info);
elapsed_time = info->elapsed_time + g_timer_elapsed (info->progress_timer,
NULL);
G_UNLOCK (progress_info);
return elapsed_time;
}
void
nautilus_progress_info_set_destination (NautilusProgressInfo *info,
GFile *file)
......
......@@ -85,6 +85,7 @@ gdouble nautilus_progress_info_get_remaining_time (NautilusProgressInfo *i
void nautilus_progress_info_set_elapsed_time (NautilusProgressInfo *info,
gdouble time);
gdouble nautilus_progress_info_get_elapsed_time (NautilusProgressInfo *info);
gdouble nautilus_progress_info_get_total_elapsed_time (NautilusProgressInfo *info);
void nautilus_progress_info_set_destination (NautilusProgressInfo *info,
GFile *file);
......
......@@ -347,7 +347,7 @@ static gboolean
should_show_progress_info (NautilusProgressInfo *info)
{
return nautilus_progress_info_get_elapsed_time (info) +
return nautilus_progress_info_get_total_elapsed_time (info) +
nautilus_progress_info_get_remaining_time (info) > OPERATION_MINIMUM_TIME;
}
......@@ -379,7 +379,7 @@ should_hide_operations_button (NautilusToolbar *self)
progress_infos = get_filtered_progress_infos (self);
for (l = progress_infos; l != NULL; l = l->next) {
if (nautilus_progress_info_get_elapsed_time (l->data) +
if (nautilus_progress_info_get_total_elapsed_time (l->data) +
nautilus_progress_info_get_remaining_time (l->data) > OPERATION_MINIMUM_TIME &&
!nautilus_progress_info_get_is_cancelled (l->data) &&
!nautilus_progress_info_get_is_finished (l->data)) {
......@@ -540,7 +540,7 @@ update_operations (NautilusToolbar *self)
GList *progress_infos;
GList *l;
GtkWidget *progress;
guint total_remaining_time = 0;
gboolean should_show_progress_button = FALSE;
gtk_container_foreach (GTK_CONTAINER (self->priv->operations_container),
(GtkCallback) gtk_widget_destroy,
......@@ -550,7 +550,8 @@ update_operations (NautilusToolbar *self)
progress_infos = get_filtered_progress_infos (self);
for (l = progress_infos; l != NULL; l = l->next) {
total_remaining_time = nautilus_progress_info_get_remaining_time (l->data);
should_show_progress_button = should_show_progress_button ||
should_show_progress_info (l->data);
g_signal_connect_swapped (l->data, "finished",
G_CALLBACK (on_progress_info_finished), self);
......@@ -575,7 +576,7 @@ update_operations (NautilusToolbar *self)
* estimated time is longer than a OPERATION_MINIMUM_TIME is odd, so show
* it only if the remaining time is bigger than again OPERATION_MINIMUM_TIME.
*/
if (total_remaining_time > OPERATION_MINIMUM_TIME &&
if (should_show_progress_button &&
!gtk_revealer_get_reveal_child (GTK_REVEALER (self->priv->operations_revealer))) {
add_operations_button_attention_style (self);
gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->operations_revealer),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment