1/*
2 * Copyright 2009, Stephan A��mus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#include <Application.h>
11
12
13class DelayShutdownApp : public BApplication {
14public:
15	DelayShutdownApp()
16		:
17		BApplication("application/x-vnd.Haiku-DelayShutdown"),
18		fDelay(5LL),
19		fQuit(false)
20	{
21	}
22
23	virtual	void ArgvReceived(int32 argc, char* argv[])
24	{
25		if (argc <= 1) {
26			_PrintUsageAndQuit();
27			return;
28		}
29
30		int32 index = 1;
31
32		while (index < argc) {
33			if (strcmp(argv[index], "-d") == 0) {
34				if (index + 1 < argc)
35					fDelay = atoi(argv[++index]);
36				else {
37					_PrintUsageAndQuit();
38					return;
39				}
40			} else if (strcmp(argv[index], "-q") == 0) {
41				fQuit = true;
42			} else {
43				_PrintUsageAndQuit();
44				return;
45			}
46			index++;
47		}
48	}
49
50	virtual bool QuitRequested()
51	{
52		snooze(fDelay * 1000000);
53		return fQuit;
54	}
55
56private:
57	void _PrintUsageAndQuit()
58	{
59		printf("usage:\n"
60			"\t-d <x>  - wait x seconds before replying the quit\n"
61			"\t          request.\n"
62			"\t-q      - respond positively to the quit request\n"
63			"\t          (default: don't quit).\n");
64		PostMessage(B_QUIT_REQUESTED);
65	}
66
67	bigtime_t	fDelay;
68	bool		fQuit;
69};
70
71
72int
73main(int argc, char* argv[])
74{
75	DelayShutdownApp app;
76	app.Run();
77
78	return 0;
79}
80