xref: /haiku/src/apps/autoraise/AutoRaiseApp.cpp (revision f75a7bf508f3156d63a14f8fd77c5e0ca4d08c42)
1 #include "AutoRaiseApp.h"
2 #include "AutoRaiseIcon.h"
3 
4 AutoRaiseApp::AutoRaiseApp()
5 	: BApplication( APP_SIG )
6 {
7 	removeFromDeskbar(NULL);
8 	_directToDeskbar = false;
9 
10 	//since the tray item shows an icon, and the class TrayView needs to be able to know the location
11 	//of the executing binary, we write into the settings file this critical information when the app is fired up
12 	app_info info;
13 	be_app->GetAppInfo(&info);
14 
15 	//now, put the path into the settings file
16 	AutoRaiseSettings settings;
17 	settings.SetAppPath(info.ref);
18 }
19 
20 AutoRaiseApp::~AutoRaiseApp()
21 {
22 	return;
23 }
24 
25 void AutoRaiseApp::ArgvReceived(int32 argc, char ** argv)
26 {
27 	BString option;
28 	bool inDeskbar = false, persist = false;
29 
30 	for (int32 i = 1; i < argc; i++)
31 	{
32 		option = argv[i];
33 		if (option.IFindFirst("deskbar") != B_ERROR)
34 			inDeskbar = true;
35 
36 		if (option.IFindFirst("persist") != B_ERROR)
37 			persist = true;
38 	}
39 
40 	if (inDeskbar && !persist)
41 	{
42 		printf(APP_NAME" being put into Tray (one shot)...\n");
43 
44 		PutInTray(false);
45 
46 		_directToDeskbar = true;
47 
48 	}
49 	else if (inDeskbar && persist)
50 	{
51 		printf(APP_NAME" being put into Tray (persistant)...\n");
52 
53 		PutInTray(true);
54 
55 		_directToDeskbar = true;
56 	}
57 	else
58 	{
59 		printf("\nUsage: "APP_NAME" [options]\n\t--deskbar\twill not open window, will just put "APP_NAME" into tray\n\t--persist will put "APP_NAME" into tray such that it remains between bootings\n");
60 	}
61 
62 	be_app_messenger.SendMessage(B_QUIT_REQUESTED);
63 }
64 
65 void AutoRaiseApp::ReadyToRun()
66 {
67 	if (!_directToDeskbar)
68 	{
69 		printf("\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open window, will just put " APP_NAME " into tray\n\t--persist will put " APP_NAME " into tray such that it remains between bootings\n");
70 		BAlert *alert = new BAlert("usage box", APP_NAME ", (c) 2002, mmu_man\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open window, will just put " APP_NAME " into tray\n\t--persist will put "APP_NAME" into tray such that it remains between bootings\n", "Ok", NULL, NULL,
71             B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
72         alert->SetShortcut(0, B_ENTER);
73    	    alert->Go();
74 		be_app_messenger.SendMessage(B_QUIT_REQUESTED);
75 	}
76 }
77 
78 void AutoRaiseApp::PutInTray(bool persist)
79 {
80 	BDeskbar db;
81 
82 	if (!persist)
83 		db.AddItem(new TrayView);
84 	else {
85 		BRoster roster;
86 		entry_ref ref;
87 		roster.FindApp(APP_SIG, &ref);
88 		int32 id;
89 		db.AddItem(&ref, &id);
90 	}
91 }
92 
93 int main()
94 {
95 	AutoRaiseApp *app = new AutoRaiseApp();
96 	app->Run();
97 
98 }
99