Skip to content

Commit 5eea3e1

Browse files
zhuyaliangraveit65
authored andcommitted
Adding pause and start functions
change kill mode
1 parent b1d6ced commit 5eea3e1

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed

src/fr-process.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ struct _FrProcessPrivate {
218218

219219
gboolean running;
220220
gboolean stopping;
221+
gboolean suspend;
221222
gint current_command;
222223
gint error_command; /* command that coused an error. */
223224

@@ -333,7 +334,7 @@ fr_process_new (void)
333334

334335

335336
static void fr_process_stop_priv (FrProcess *process, gboolean emit_signal);
336-
337+
static int fr_switch_process_state (FrProcess *process);
337338

338339
static void
339340
fr_process_finalize (GObject *object)
@@ -1026,8 +1027,52 @@ fr_process_start (FrProcess *process)
10261027
start_current_command (process);
10271028
}
10281029
}
1029-
1030-
1030+
static int
1031+
fr_close_suspend_process(FrProcess *process)
1032+
{
1033+
int ret = -1;
1034+
g_return_val_if_fail(process != NULL, ret);
1035+
1036+
if (process->priv->suspend)
1037+
{
1038+
if (process->priv->command_pid > 0)
1039+
{
1040+
ret = killpg (process->priv->command_pid,SIGTERM);
1041+
ret = killpg (process->priv->command_pid,SIGCONT);
1042+
}
1043+
if(ret == 0)
1044+
process->priv->suspend = FALSE;
1045+
}
1046+
1047+
return ret;
1048+
}
1049+
static int
1050+
fr_switch_process_state (FrProcess *process)
1051+
{
1052+
int ret = -1;
1053+
g_return_val_if_fail(process != NULL, ret);
1054+
1055+
if (process->priv->stopping)
1056+
return ret;
1057+
1058+
if (process->priv->suspend)
1059+
{
1060+
1061+
if (process->priv->command_pid > 0)
1062+
ret = killpg (process->priv->command_pid,SIGCONT);
1063+
if(ret == 0)
1064+
process->priv->suspend = FALSE;
1065+
}
1066+
else
1067+
{
1068+
if (process->priv->command_pid > 0)
1069+
ret = killpg (process->priv->command_pid,SIGSTOP);
1070+
if(ret == 0)
1071+
process->priv->suspend = TRUE;
1072+
}
1073+
1074+
return ret;
1075+
}
10311076
static void
10321077
fr_process_stop_priv (FrProcess *process,
10331078
gboolean emit_signal)
@@ -1075,3 +1120,12 @@ fr_process_stop (FrProcess *process)
10751120
{
10761121
fr_process_stop_priv (process, TRUE);
10771122
}
1123+
int start_switch_state (FrProcess *process)
1124+
{
1125+
return fr_switch_process_state (process);
1126+
}
1127+
void start_close_suspend_process(FrProcess *process)
1128+
{
1129+
fr_close_suspend_process(process);
1130+
}
1131+

src/fr-process.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,6 @@ void fr_process_set_err_line_func (FrProcess *fr_proc,
132132
gpointer func_data);
133133
void fr_process_start (FrProcess *fr_proc);
134134
void fr_process_stop (FrProcess *fr_proc);
135-
135+
int start_switch_state (FrProcess *fr_proc);
136+
void start_close_suspend_process (FrProcess *fr_proc);
136137
#endif /* FR_PROCESS_H */

src/fr-window.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ struct _FrWindowPrivateData {
367367
GtkWidget *pd_open_destination_button;
368368
GtkWidget *pd_open_destination_and_quit_button;
369369
GtkWidget *pd_quit_button;
370+
GtkWidget *pd_state_button; //Switch state, pause state or start state
370371
GtkWidget *pd_icon;
371372
gboolean progress_pulse;
372373
guint progress_timeout; /* Timeout to display the progress dialog. */
@@ -2198,6 +2199,13 @@ real_close_progress_dialog (gpointer data)
21982199
}
21992200

22002201

2202+
static void close_suspend_process(FrWindow *window)
2203+
{
2204+
if (window->archive->process != NULL)
2205+
{
2206+
start_close_suspend_process(window->archive->process);
2207+
}
2208+
}
22012209
static void
22022210
close_progress_dialog (FrWindow *window,
22032211
gboolean close_now)
@@ -2227,6 +2235,7 @@ close_progress_dialog (FrWindow *window,
22272235
real_close_progress_dialog,
22282236
window);
22292237
}
2238+
close_suspend_process(window);
22302239
}
22312240

22322241

@@ -2283,6 +2292,31 @@ fr_window_view_extraction_destination_folder (FrWindow *window)
22832292
open_folder (GTK_WINDOW (window), fr_archive_get_last_extraction_destination (window->archive));
22842293
}
22852294

2295+
static void change_button_label(GtkWidget *button)
2296+
{
2297+
const gchar *state;
2298+
state = gtk_button_get_label(GTK_BUTTON(button));
2299+
if(g_strrstr("suspend",state) != NULL)
2300+
{
2301+
gtk_button_set_label(GTK_BUTTON(button),_("start"));
2302+
}
2303+
else
2304+
{
2305+
gtk_button_set_label(GTK_BUTTON(button),_("suspend"));
2306+
}
2307+
}
2308+
static void fr_state_switch(FrWindow *window)
2309+
{
2310+
int ret;
2311+
if (window->archive->process != NULL)
2312+
{
2313+
ret = start_switch_state (window->archive->process);
2314+
if(ret == 0)
2315+
{
2316+
change_button_label(window->priv->pd_state_button);
2317+
}
2318+
}
2319+
}
22862320

22872321
static void
22882322
progress_dialog_response (GtkDialog *dialog,
@@ -2319,6 +2353,9 @@ progress_dialog_response (GtkDialog *dialog,
23192353
case DIALOG_RESPONSE_QUIT:
23202354
fr_window_close (window);
23212355
break;
2356+
case GTK_RESPONSE_ACCEPT:
2357+
fr_state_switch (window);
2358+
break;
23222359
default:
23232360
break;
23242361
}
@@ -2531,7 +2568,8 @@ create_the_progress_dialog (FrWindow *window)
25312568
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);
25322569
window->priv->pd_close_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), "gtk-close", GTK_RESPONSE_CLOSE);
25332570
window->priv->pd_cancel_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), "gtk-cancel", GTK_RESPONSE_CANCEL);
2534-
2571+
/*add start button default suspend*/
2572+
window->priv->pd_state_button = gtk_dialog_add_button (GTK_DIALOG (window->priv->progress_dialog), _("suspend"), GTK_RESPONSE_ACCEPT);
25352573
d = GTK_DIALOG (window->priv->progress_dialog);
25362574
gtk_window_set_resizable (GTK_WINDOW (d), TRUE);
25372575
gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK);

0 commit comments

Comments
 (0)