Skip to content

Commit 64a2462

Browse files
committed
Merge pull request #2 from pkarneliuk/master
add timeout CLI option
2 parents 046572c + 31174c3 commit 64a2462

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/main.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ static Ihandle *filterText, *filterButton;
2626
Ihandle *filterSelectList;
2727
// timer to update icons
2828
static Ihandle *stateIcon;
29-
static Ihandle *timer;
29+
static Ihandle *timer = NULL;
30+
static Ihandle *timeout = NULL;
3031

3132
void showStatus(const char *line);
3233
static int uiOnDialogShow(Ihandle *ih, int state);
3334
static int uiStopCb(Ihandle *ih);
3435
static int uiStartCb(Ihandle *ih);
3536
static int uiTimerCb(Ihandle *ih);
37+
static int uiTimeoutCb(Ihandle *ih);
3638
static int uiListSelectCb(Ihandle *ih, char *text, int item, int state);
3739
static int uiFilterTextCb(Ihandle *ih);
3840
static void uiSetupModule(Module *module, Ihandle *parent);
@@ -120,6 +122,7 @@ void init(int argc, char* argv[]) {
120122
UINT ix;
121123
Ihandle *topVbox, *bottomVbox, *dialogVBox, *controlHbox;
122124
Ihandle *noneIcon, *doingIcon, *errorIcon;
125+
char* arg_value = NULL;
123126

124127
// fill in config
125128
loadConfig();
@@ -242,6 +245,18 @@ void init(int argc, char* argv[]) {
242245
IupSetAttribute(timer, "TIME", STR(ICON_UPDATE_MS));
243246
IupSetCallback(timer, "ACTION_CB", uiTimerCb);
244247

248+
// setup timeout of program
249+
arg_value = IupGetGlobal("timeout");
250+
if(arg_value != NULL)
251+
{
252+
char valueBuf[16];
253+
sprintf(valueBuf, "%s000", arg_value); // convert from seconds to milliseconds
254+
255+
timeout = IupTimer();
256+
IupStoreAttribute(timeout, "TIME", valueBuf);
257+
IupSetCallback(timeout, "ACTION_CB", uiTimeoutCb);
258+
IupSetAttribute(timeout, "RUN", "YES");
259+
}
245260
}
246261

247262
void startup() {
@@ -255,7 +270,10 @@ void startup() {
255270
}
256271

257272
void cleanup() {
258-
IupDestroy(timer);
273+
274+
if(timeout) { IupDestroy(timeout); }
275+
if(timer) { IupDestroy(timer); }
276+
259277
IupClose();
260278
endTimePeriod(); // try close if not closing
261279
}
@@ -382,6 +400,11 @@ static int uiTimerCb(Ihandle *ih) {
382400
return IUP_DEFAULT;
383401
}
384402

403+
static int uiTimeoutCb(Ihandle *ih) {
404+
UNREFERENCED_PARAMETER(ih);
405+
return IUP_CLOSE;
406+
}
407+
385408
static int uiListSelectCb(Ihandle *ih, char *text, int item, int state) {
386409
UNREFERENCED_PARAMETER(text);
387410
UNREFERENCED_PARAMETER(ih);

0 commit comments

Comments
 (0)