1#include "AutoRaiseApp.h"
2#include "AutoRaiseIcon.h"
3#include <Catalog.h>
4
5
6#undef B_TRANSLATION_CONTEXT
7#define B_TRANSLATION_CONTEXT "AutoRaiseApp"
8
9
10AutoRaiseApp::AutoRaiseApp()
11	: BApplication( APP_SIG )
12{
13	B_TRANSLATE_MARK_SYSTEM_NAME_VOID("AutoRaise");
14
15	removeFromDeskbar(NULL);
16	fPersist = true;
17	fDone = false;
18}
19
20AutoRaiseApp::~AutoRaiseApp()
21{
22	return;
23}
24
25void AutoRaiseApp::ArgvReceived(int32 argc, char ** argv)
26{
27	BString option;
28
29	for (int32 i = 1; i < argc; i++)
30	{
31		option = argv[i];
32		if (option.IFindFirst("deskbar") != B_ERROR)
33			fPersist = false;
34
35		if (option.IFindFirst("persist") != B_ERROR)
36			fPersist = true;
37
38		if (option.IFindFirst("-h") != B_ERROR
39			|| option.IFindFirst("help") != B_ERROR) {
40			BString usageNote =
41				"\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open "
42				"window, will just put " APP_NAME " into tray\n\t--persist (default) will put "
43				APP_NAME " into tray such that it remains across reboots";
44			puts(usageNote.String());
45			fDone = true;
46			be_app_messenger.SendMessage(B_QUIT_REQUESTED);
47		}
48	}
49}
50
51void AutoRaiseApp::ReadyToRun()
52{
53	if (!fDone)
54		PutInTray(fPersist);
55	be_app_messenger.SendMessage(B_QUIT_REQUESTED);
56}
57
58void AutoRaiseApp::PutInTray(bool persist)
59{
60	BDeskbar db;
61
62	if (!persist)
63		db.AddItem(new TrayView);
64	else {
65		BRoster roster;
66		entry_ref ref;
67		roster.FindApp(APP_SIG, &ref);
68		int32 id;
69		db.AddItem(&ref, &id);
70	}
71}
72
73int main()
74{
75	AutoRaiseApp *app = new AutoRaiseApp();
76	app->Run();
77}
78