diff options
-rw-r--r-- | src/fr-process.c | 60 | ||||
-rw-r--r-- | src/fr-process.h | 3 | ||||
-rw-r--r-- | src/fr-window.c | 40 |
3 files changed, 98 insertions, 5 deletions
diff --git a/src/fr-process.c b/src/fr-process.c index 7a65493..0ad5b1e 100644 --- a/src/fr-process.c +++ b/src/fr-process.c @@ -218,6 +218,7 @@ struct _FrProcessPrivate { gboolean running; gboolean stopping; + gboolean suspend; gint current_command; gint error_command; /* command that coused an error. */ @@ -333,7 +334,7 @@ fr_process_new (void) static void fr_process_stop_priv (FrProcess *process, gboolean emit_signal); - +static int fr_switch_process_state (FrProcess *process); static void fr_process_finalize (GObject *object) @@ -1026,8 +1027,52 @@ fr_process_start (FrProcess *process) start_current_command (process); } } - - +static int +fr_close_suspend_process(FrProcess *process) +{ + int ret = -1; + g_return_val_if_fail(process != NULL, ret); + + if (process->priv->suspend) + { + if (process->priv->command_pid > 0) + { + ret = killpg (process->priv->command_pid,SIGTERM); + ret = killpg (process->priv->command_pid,SIGCONT); + } + if(ret == 0) + process->priv->suspend = FALSE; + } + + return ret; +} +static int +fr_switch_process_state (FrProcess *process) +{ + int ret = -1; + g_return_val_if_fail(process != NULL, ret); + + if (process->priv->stopping) + return ret; + + if (process->priv->suspend) + { + + if (process->priv->command_pid > 0) + ret = killpg (process->priv->command_pid,SIGCONT); + if(ret == 0) + process->priv->suspend = FALSE; + } + else + { + if (process->priv->command_pid > 0) + ret = killpg (process->priv->command_pid,SIGSTOP); + if(ret == 0) + process->priv->suspend = TRUE; + } + + return ret; +} static void fr_process_stop_priv (FrProcess *process, gboolean emit_signal) @@ -1075,3 +1120,12 @@ fr_process_stop (FrProcess *process) { fr_process_stop_priv (process, TRUE); } +int start_switch_state (FrProcess *process) +{ + return fr_switch_process_state (process); +} +void start_close_suspend_process(FrProcess *process) +{ + fr_close_suspend_process(process); +} + diff --git a/src/fr-process.h b/src/fr-process.h index 8c907bd..feda7e8 100644 --- a/src/fr-process.h +++ b/src/fr-process.h @@ -132,5 +132,6 @@ void fr_process_set_err_line_func (FrProcess *fr_proc, gpointer func_data); void fr_process_start (FrProcess *fr_proc); void fr_process_stop (FrProcess *fr_proc); - +int start_switch_state (FrProcess *fr_proc); +void start_close_suspend_process (FrProcess *fr_proc); #endif /* FR_PROCESS_H */ diff --git a/src/fr-window.c b/src/fr-window.c index 9b7882f..cb08c55 100644 --- a/src/fr-window.c +++ b/src/fr-window.c @@ -367,6 +367,7 @@ struct _FrWindowPrivateData { GtkWidget *pd_open_destination_button; GtkWidget *pd_open_destination_and_quit_button; GtkWidget *pd_quit_button; + GtkWidget *pd_state_button; //Switch state, pause state or start state GtkWidget *pd_icon; gboolean progress_pulse; guint progress_timeout; /* Timeout to display the progress dialog. */ @@ -2198,6 +2199,13 @@ real_close_progress_dialog (gpointer data) } +static void close_suspend_process(FrWindow *window) +{ + if (window->archive->process != NULL) + { + start_close_suspend_process(window->archive->process); + } +} static void close_progress_dialog (FrWindow *window, gboolean close_now) @@ -2227,6 +2235,7 @@ close_progress_dialog (FrWindow *window, real_close_progress_dialog, window); } + close_suspend_process(window); } @@ -2283,6 +2292,31 @@ fr_window_view_extraction_destination_folder (FrWindow *window) open_folder (GTK_WINDOW (window), fr_archive_get_last_extraction_destination (window->archive)); } +static void change_button_label(GtkWidget *button) +{ + const gchar *state; + state = gtk_button_get_label(GTK_BUTTON(button)); + if(g_strrstr("suspend",state) != NULL) + { + gtk_button_set_label(GTK_BUTTON(button),_("start")); + } + else + { + gtk_button_set_label(GTK_BUTTON(button),_("suspend")); + } +} +static void fr_state_switch(FrWindow *window) +{ + int ret; + if (window->archive->process != NULL) + { + ret = start_switch_state (window->archive->process); + if(ret == 0) + { + change_button_label(window->priv->pd_state_button); + } + } +} static void progress_dialog_response (GtkDialog *dialog, @@ -2319,6 +2353,9 @@ progress_dialog_response (GtkDialog *dialog, case DIALOG_RESPONSE_QUIT: fr_window_close (window); break; + case GTK_RESPONSE_ACCEPT: + fr_state_switch (window); + break; default: break; } @@ -2531,7 +2568,8 @@ create_the_progress_dialog (FrWindow *window) window->priv->pd_open_destination_and_quit_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), _("Show the _Files and Quit"), DIALOG_RESPONSE_OPEN_DESTINATION_FOLDER_AND_QUIT); window->priv->pd_close_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), "gtk-close", GTK_RESPONSE_CLOSE); window->priv->pd_cancel_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), "gtk-cancel", GTK_RESPONSE_CANCEL); - + /*add start button default suspend*/ + window->priv->pd_state_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), _("suspend"), GTK_RESPONSE_ACCEPT); d = GTK_DIALOG (window->priv->progress_dialog); gtk_window_set_resizable (GTK_WINDOW (d), TRUE); gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK); |