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 10 AutoRaiseApp::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 //since the tray item shows an icon, and the class TrayView needs to be 20 //able to know the location of the executing binary, we write into the 21 //settings file this critical information when the app is fired up 22 app_info info; 23 be_app->GetAppInfo(&info); 24 25 //now, put the path into the settings file 26 AutoRaiseSettings settings; 27 settings.SetAppPath(info.ref); 28 } 29 30 AutoRaiseApp::~AutoRaiseApp() 31 { 32 return; 33 } 34 35 void AutoRaiseApp::ArgvReceived(int32 argc, char ** argv) 36 { 37 BString option; 38 39 for (int32 i = 1; i < argc; i++) 40 { 41 option = argv[i]; 42 if (option.IFindFirst("deskbar") != B_ERROR) 43 fPersist = false; 44 45 if (option.IFindFirst("persist") != B_ERROR) 46 fPersist = true; 47 48 if (option.IFindFirst("-h") != B_ERROR 49 || option.IFindFirst("help") != B_ERROR) { 50 BString usageNote = 51 "\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open " 52 "window, will just put " APP_NAME " into tray\n\t--persist (default) will put " 53 APP_NAME " into tray such that it remains across reboots\n"; 54 printf(usageNote); 55 fDone = true; 56 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 57 } 58 } 59 } 60 61 void AutoRaiseApp::ReadyToRun() 62 { 63 if (!fDone) 64 PutInTray(fPersist); 65 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 66 } 67 68 void AutoRaiseApp::PutInTray(bool persist) 69 { 70 BDeskbar db; 71 72 if (!persist) 73 db.AddItem(new TrayView); 74 else { 75 BRoster roster; 76 entry_ref ref; 77 roster.FindApp(APP_SIG, &ref); 78 int32 id; 79 db.AddItem(&ref, &id); 80 } 81 } 82 83 int main() 84 { 85 AutoRaiseApp *app = new AutoRaiseApp(); 86 app->Run(); 87 } 88