17 #ifndef AW_QUESTION_HXX
24 #ifndef MACROEXITOR_HXX
25 #define MACROEXITOR_HXX
27 #define TRY_TO_QUIT_ARB_FREQUENCY 250 // ms
35 virtual GBDATA *get_gbmain_checked_for_save() = 0;
41 GBK_terminate(
"The exit mechanism didn't work, but resistance is futile.");
44 unsigned exit_delayed() {
45 if (need_to_delay_exit()) {
47 static long milliSeconds = 0;
48 static int lastDecaSeconds = 0;
51 int seconds = milliSeconds/1000;
52 int decaSeconds = seconds/10;
54 if (decaSeconds != lastDecaSeconds) {
55 const char *msg =
GBS_global_string(
"waited %i seconds for macro termination", seconds);
57 int after = (10-decaSeconds)*10;
58 msg =
GBS_global_string(
"%s. Will terminate unconditionally in %i seconds", msg, after);
61 lastDecaSeconds = decaSeconds;
74 perform_exit_or_terminate();
77 static unsigned exit_delayed(
AW_root*,
MacroExitor *exitor) {
return exitor->exit_delayed(); }
79 static bool user_does_confirm_quit__if_server(
GBDATA *
gb_main,
const char *appName) {
80 bool shallQuit =
true;
88 char *question =
NULp;
92 question =
GBS_global_string_copy(
"You last saved your data %li:%02li minutes ago\nSure to quit?", secs/60, secs%60);
96 question =
ARB_strdup(
"You never saved any data.\nSure to quit?");
103 fprintf(stderr,
"[NDEBUG version would query user with: '%s' -> '%s']\n", question, quit_buttons);
106 fprintf(stderr,
"[NDEBUG version would also quit %s w/o query]\n", appName);
112 shallQuit =
aw_question(
"quit_arb", question, quit_buttons) == 0;
147 if (need_to_delay_exit()) {
153 aw_message(
"[macro is still running. But time will pass faster because you are in a hurry]");
157 makeTimedCallback(MacroExitor::exit_delayed,
this));
169 if (user_does_confirm_quit__if_server(get_gbmain_checked_for_save(), quitWhat)) {
170 perform_exit_or_terminate();
181 #error MacroExitor.hxx included twice
182 #endif // MACROEXITOR_HXX
void maybe_exit_delayed()
char * ARB_strdup(const char *str)
const char * GBS_global_string(const char *templat,...)
char * GBS_string_eval(const char *insource, const char *icommand)
void add_timed_callback(int ms, const TimedCallback &tcb)
bool is_performing_delayed_exit() const
AliDataPtr after(AliDataPtr data, size_t pos)
void GBK_terminate(const char *error) __ATTR__NORETURN
GB_ULONG GB_time_of_day(void)
long GB_read_clients(GBDATA *gbd)
void ARB_sleep(int amount, TimeUnit tu)
long GB_last_saved_clock(GBDATA *gb_main)
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
GB_ULONG GB_last_saved_time(GBDATA *gb_main)
#define TRY_TO_QUIT_ARB_FREQUENCY
bool is_executing_macro_as_server(AW_root *root)
void aw_message(const char *msg)
long GB_read_clock(GBDATA *gbd)
MacroExitor(AW_root *aw_root_, const char *appName)
AW_root * get_root() const
char * GBS_global_string_copy(const char *templat,...)