summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcaja-private/caja-file-operations.c20
-rw-r--r--libcaja-private/caja-progress-info.c116
-rw-r--r--libcaja-private/caja-progress-info.h2
3 files changed, 68 insertions, 70 deletions
diff --git a/libcaja-private/caja-file-operations.c b/libcaja-private/caja-file-operations.c
index 1006fe12..28473282 100644
--- a/libcaja-private/caja-file-operations.c
+++ b/libcaja-private/caja-file-operations.c
@@ -913,11 +913,11 @@ f (const char *format, ...) {
return res;
}
-#define op_job_new(__type, parent_window, dostart) ((__type *)(init_common (sizeof(__type), parent_window, dostart)))
+#define op_job_new(__type, parent_window, should_start) ((__type *)(init_common (sizeof(__type), parent_window, should_start)))
static gpointer
init_common (gsize job_size,
- GtkWindow *parent_window, gboolean dostart)
+ GtkWindow *parent_window, gboolean should_start)
{
CommonJob *common;
GdkScreen *screen;
@@ -928,7 +928,7 @@ init_common (gsize job_size,
common->parent_window = parent_window;
eel_add_weak_pointer (&common->parent_window);
}
- common->progress = caja_progress_info_new (dostart);
+ common->progress = caja_progress_info_new (should_start);
common->cancellable = caja_progress_info_get_cancellable (common->progress);
common->time = g_timer_new ();
common->inhibit_cookie = -1;
@@ -1779,7 +1779,7 @@ trash_files (CommonJob *job, GList *files, int *files_skipped)
for (l = files;
l != NULL && !job_aborted (job);
l = l->next) {
- caja_progress_info_get_ready(job->progress);
+ caja_progress_info_get_ready (job->progress);
file = l->data;
@@ -4084,7 +4084,7 @@ copy_move_file (CopyMoveJob *copy_job,
retry:
- caja_progress_info_get_ready(job->progress);
+ caja_progress_info_get_ready (job->progress);
error = NULL;
flags = G_FILE_COPY_NOFOLLOW_SYMLINKS;
@@ -4710,7 +4710,7 @@ move_file_prepare (CopyMoveJob *move_job,
}
retry:
- caja_progress_info_get_ready(job->progress);
+ caja_progress_info_get_ready (job->progress);
flags = G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_NO_FALLBACK_FOR_MOVE;
if (overwrite) {
@@ -4944,7 +4944,7 @@ common = &job->common;
for (l = fallbacks;
l != NULL && !job_aborted (common);
l = l->next) {
- caja_progress_info_get_ready(common->progress);
+ caja_progress_info_get_ready (common->progress);
fallback = l->data;
src = fallback->file;
@@ -5366,7 +5366,7 @@ link_job (GIOSchedulerJob *io_job,
for (l = job->files;
l != NULL && !job_aborted (common);
l = l->next) {
- caja_progress_info_get_ready(common->progress);
+ caja_progress_info_get_ready (common->progress);
src = l->data;
@@ -5513,7 +5513,7 @@ set_permissions_file (SetPermissionsJob *job,
caja_progress_info_pulse_progress (common->progress);
- caja_progress_info_get_ready(common->progress);
+ caja_progress_info_get_ready (common->progress);
free_info = FALSE;
if (info == NULL) {
@@ -5875,7 +5875,7 @@ create_job (GIOSchedulerJob *io_job,
count = 1;
retry:
- caja_progress_info_get_ready(common->progress);
+ caja_progress_info_get_ready (common->progress);
error = NULL;
if (job->make_dir) {
diff --git a/libcaja-private/caja-progress-info.c b/libcaja-private/caja-progress-info.c
index 23ab516e..e42021df 100644
--- a/libcaja-private/caja-progress-info.c
+++ b/libcaja-private/caja-progress-info.c
@@ -96,7 +96,7 @@ static GList *active_progress_infos = NULL;
static GtkStatusIcon *status_icon = NULL;
static int n_progress_ops = 0;
-
+static void update_status_icon_and_window (void);
G_LOCK_DEFINE_STATIC(progress_info);
@@ -226,16 +226,15 @@ status_icon_activate_cb (GtkStatusIcon *icon,
}
}
+/* Creates a Singleton progress_window */
static GtkWidget *
-get_progress_window (gboolean docreate)
+get_progress_window ()
{
static GtkWidget *progress_window = NULL;
GtkWidget *vbox;
- if (progress_window != NULL || !docreate)
- {
+ if (progress_window != NULL)
return progress_window;
- }
progress_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (progress_window),
@@ -257,8 +256,6 @@ get_progress_window (gboolean docreate)
gtk_container_add (GTK_CONTAINER (progress_window),
vbox);
- gtk_widget_show_all (progress_window);
-
g_signal_connect (progress_window,
"delete_event",
(GCallback)delete_event, NULL);
@@ -268,7 +265,7 @@ get_progress_window (gboolean docreate)
(GCallback)status_icon_activate_cb,
progress_window);
- gtk_status_icon_set_visible (status_icon, FALSE);
+ update_status_icon_and_window ();
return progress_window;
}
@@ -352,11 +349,7 @@ update_data (ProgressWidgetData *data)
static GtkWidget *
get_widgets_container ()
{
- GtkWidget * window = get_progress_window (FALSE);
-
- if (window == NULL)
- return NULL;
-
+ GtkWidget * window = get_progress_window ();
return gtk_bin_get_child (GTK_BIN (window));
}
static void
@@ -370,8 +363,9 @@ foreach_get_running_operations (GtkWidget * widget, int * n)
}
static int
-get_running_operations (GtkWidget * container)
+get_running_operations ()
{
+ GtkWidget * container = get_widgets_container();
int n = 0;
gtk_container_foreach (GTK_CONTAINER(container),
@@ -394,8 +388,9 @@ foreach_get_queued_widget (GtkWidget * widget, GtkWidget ** out)
}
static GtkWidget *
-get_first_queued_widget (GtkWidget * container)
+get_first_queued_widget ()
{
+ GtkWidget * container = get_widgets_container();
GtkWidget * out = NULL;
gtk_container_foreach (GTK_CONTAINER(container),
@@ -446,19 +441,20 @@ progress_info_set_waiting(CajaProgressInfo *info, gboolean waiting)
}
static void
-widget_reposition_as_queued (GtkWidget * widget, GtkWidget * container)
+widget_reposition_as_queued (GtkWidget * widget)
{
- gtk_box_reorder_child (GTK_BOX(container), widget, n_progress_ops-1);
+ gtk_box_reorder_child (GTK_BOX(get_widgets_container ()), widget, n_progress_ops-1);
}
/* Reposition the widget so that it sits right before the first stopped widget */
static void
-widget_reposition_as_paused (GtkWidget * widget, GtkWidget * container)
+widget_reposition_as_paused (GtkWidget * widget)
{
ProgressWidgetData *data;
GList *children, *child;
gboolean abort = FALSE;
int i, mypos = -1;
+ GtkWidget * container = get_widgets_container();
children = gtk_container_get_children (GTK_CONTAINER(container));
@@ -487,12 +483,13 @@ widget_reposition_as_paused (GtkWidget * widget, GtkWidget * container)
/* Reposition the widget so that it sits right after the last running widget */
static void
-widget_reposition_as_running (GtkWidget * widget, GtkWidget * container)
+widget_reposition_as_running (GtkWidget * widget)
{
ProgressWidgetData *data;
GList *children, *child;
gboolean abort = FALSE;
int i, mypos = -1;
+ GtkWidget * container = get_widgets_container();
children = gtk_container_get_children (GTK_CONTAINER(container));
@@ -520,15 +517,12 @@ widget_reposition_as_running (GtkWidget * widget, GtkWidget * container)
}
}
-static void update_queue (GtkWidget * container);
+static void update_queue ();
static void
widget_state_transit_to (ProgressWidgetData *data,
ProgressWidgetState newstate)
{
- // here container cannot be NULL
- GtkWidget * container = get_widgets_container ();
-
data->state = newstate;
if (newstate == STATE_PAUSING ||
@@ -540,13 +534,13 @@ widget_state_transit_to (ProgressWidgetData *data,
}
if (newstate == STATE_QUEUED) {
- widget_reposition_as_queued (data->widget, container);
- update_queue (container);
+ widget_reposition_as_queued (data->widget);
+ update_queue ();
} else if (newstate == STATE_PAUSED) {
- widget_reposition_as_paused (data->widget, container);
- update_queue (container);
+ widget_reposition_as_paused (data->widget);
+ update_queue ();
} else if (newstate == STATE_RUNNING) {
- widget_reposition_as_running (data->widget, container);
+ widget_reposition_as_running (data->widget);
}
start_button_update_view (data->btstart, data->state);
@@ -555,13 +549,13 @@ widget_state_transit_to (ProgressWidgetData *data,
}
static void
-update_queue (GtkWidget * container)
+update_queue ()
{
GtkWidget *next;
ProgressWidgetData *data;
- if (get_running_operations (container) == 0) {
- next = get_first_queued_widget (container);
+ if (get_running_operations () == 0) {
+ next = get_first_queued_widget ();
if (next != NULL) {
data = (ProgressWidgetData*) g_object_get_data (
@@ -602,11 +596,13 @@ update_status_icon_and_window (void)
if (n_progress_ops == 0)
{
gtk_status_icon_set_visible (status_icon, FALSE);
- gtk_widget_hide (get_progress_window (TRUE));
+ gtk_widget_hide (get_progress_window ());
}
else
{
+ gtk_widget_show_all (get_progress_window ());
gtk_status_icon_set_visible (status_icon, TRUE);
+ gtk_window_present (GTK_WINDOW (get_progress_window ()));
}
}
@@ -616,10 +612,7 @@ op_finished (ProgressWidgetData *data)
gtk_widget_destroy (data->widget);
n_progress_ops--;
-
- GtkWidget * container = get_widgets_container ();
- if (container != NULL)
- update_queue (container);
+ update_queue ();
update_status_icon_and_window ();
}
@@ -754,7 +747,7 @@ queue_button_init (ProgressWidgetData *data)
#if GTK_CHECK_VERSION (3, 10, 0)
image = gtk_image_new_from_icon_name ("undo", GTK_ICON_SIZE_BUTTON);
#else
- image = gtk_image_new_from_stock(GTK_STOCK_UNDO, GTK_ICON_SIZE_BUTTON);
+ image = gtk_image_new_from_stock (GTK_STOCK_UNDO, GTK_ICON_SIZE_BUTTON);
#endif
gtk_container_add (GTK_CONTAINER (button), image);
@@ -880,41 +873,33 @@ progress_widget_new (CajaProgressInfo *info)
static void
handle_new_progress_info (CajaProgressInfo *info)
{
- GtkWidget *window, *progress, *container;;
+ GtkWidget *window, *progress;
- window = get_progress_window (TRUE);
+ window = get_progress_window ();
progress = progress_widget_new (info);
gtk_box_pack_start (GTK_BOX (gtk_bin_get_child (GTK_BIN (window))),
progress,
FALSE, FALSE, 6);
- gtk_window_present (GTK_WINDOW (window));
-
n_progress_ops++;
- // TODO use user defined policies
- container = get_widgets_container ();
- if (container != NULL) {
- if (info->waiting && get_running_operations (container) > 0)
- widget_state_transit_to (info->widget, STATE_QUEUED);
- else
- widget_state_transit_to (info->widget, STATE_RUNNING);
- }
-
- update_status_icon_and_window ();
+ if (info->waiting && get_running_operations () > 0)
+ widget_state_transit_to (info->widget, STATE_QUEUED);
+ else
+ widget_state_transit_to (info->widget, STATE_RUNNING);
}
static gboolean
-new_op_started_timeout (CajaProgressInfo *info)
-{
+delayed_window_showup (CajaProgressInfo *info)
+{
if (caja_progress_info_get_is_paused (info))
{
return TRUE;
}
if (!caja_progress_info_get_is_finished (info))
{
- handle_new_progress_info (info);
+ update_status_icon_and_window ();
}
g_object_unref (info);
return FALSE;
@@ -923,10 +908,24 @@ new_op_started_timeout (CajaProgressInfo *info)
static void
new_op_started (CajaProgressInfo *info)
{
+ GtkWidget * container;
+
g_signal_handlers_disconnect_by_func (info, (GCallback)new_op_started, NULL);
- g_timeout_add_seconds (2,
- (GSourceFunc)new_op_started_timeout,
+
+ if (!caja_progress_info_get_is_finished (info)) {
+ handle_new_progress_info (info);
+
+ /* Start the job when no other job is running */
+ // TODO use user defined policies
+ if (info->waiting) {
+ if (get_running_operations () == 0)
+ progress_info_set_waiting (info, FALSE);
+ }
+
+ g_timeout_add_seconds (2,
+ (GSourceFunc)delayed_window_showup,
g_object_ref (info));
+ }
}
static void
@@ -942,13 +941,12 @@ caja_progress_info_init (CajaProgressInfo *info)
}
CajaProgressInfo *
-caja_progress_info_new (gboolean dostart)
+caja_progress_info_new (gboolean should_start)
{
CajaProgressInfo *info;
info = g_object_new (CAJA_TYPE_PROGRESS_INFO, NULL);
- info->waiting = !dostart;
-
+ info->waiting = !should_start;
return info;
}
diff --git a/libcaja-private/caja-progress-info.h b/libcaja-private/caja-progress-info.h
index dc5fe57a..2640b77e 100644
--- a/libcaja-private/caja-progress-info.h
+++ b/libcaja-private/caja-progress-info.h
@@ -50,7 +50,7 @@ GType caja_progress_info_get_type (void) G_GNUC_CONST;
All methods are threadsafe.
*/
-CajaProgressInfo *caja_progress_info_new (gboolean dostart);
+CajaProgressInfo *caja_progress_info_new (gboolean should_start);
void caja_progress_info_get_ready (CajaProgressInfo *info);
GList * caja_get_all_progress_info (void);