1 /* 2 PCWorld.cpp 3 4 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. 5 Copyright (C) 2004 beunited.org 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 23 #include "PCWorld.h" 24 #include "PCWindow.h" 25 #include "Preferences.h" 26 #include "ProcessController.h" 27 #include "Utilities.h" 28 29 #include <Alert.h> 30 #include <Application.h> 31 #include <Deskbar.h> 32 #include <Roster.h> 33 34 #include <stdio.h> 35 #include <stdlib.h> 36 #include <string.h> 37 38 39 class PCApplication : public BApplication { 40 public: 41 PCApplication(); 42 virtual ~PCApplication(); 43 44 virtual void ReadyToRun(); 45 virtual void ArgvReceived(int32 argc, char** argv); 46 }; 47 48 49 const char* kSignature = "application/x-vnd.Haiku-ProcessController"; 50 const char* kTrackerSig = "application/x-vnd.Be-TRAK"; 51 const char* kDeskbarSig = "application/x-vnd.Be-TSKB"; 52 const char* kTerminalSig = "application/x-vnd.Haiku-Terminal"; 53 const char* kPreferencesFileName = "ProcessController Prefs"; 54 55 const char* kPosPrefName = "Position"; 56 const char* kVersionName = "Version"; 57 const int kCurrentVersion = 311; 58 59 thread_id id = 0; 60 61 62 PCApplication::PCApplication() 63 : 64 BApplication(kSignature) 65 { 66 } 67 68 69 PCApplication::~PCApplication() 70 { 71 if (id) { 72 status_t returnValue; 73 wait_for_thread(id, &returnValue); 74 } 75 } 76 77 78 void 79 PCApplication::ReadyToRun() 80 { 81 BDeskbar deskbar; 82 if (!deskbar.HasItem(kDeskbarItemName)) { 83 // We're not yet installed in the Deskbar, ask if we should 84 BAlert* alert = new BAlert("", 85 "Do you want ProcessController to live in the Deskbar?", "Don't", 86 "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 87 alert->SetShortcut(0, B_ESCAPE); 88 89 if (alert->Go() != 0) { 90 BDeskbar deskbar; 91 if (!deskbar.HasItem(kDeskbarItemName)) 92 move_to_deskbar(deskbar); 93 Quit(); 94 return; 95 } 96 } else { 97 BAlert* alert = new BAlert("", 98 "ProcessController is already installed in Deskbar.", "OK", NULL, 99 NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 100 alert->SetShortcut(0, B_ESCAPE); 101 alert->Go(); 102 } 103 104 new PCWindow(); 105 106 // quit other eventually running instances 107 BList list; 108 be_roster->GetAppList(kSignature, &list); 109 long count = list.CountItems(); 110 if (count > 1) { 111 for (long i = 0; i < count - 1; i++) { 112 BMessenger* otherme = new BMessenger(NULL, (team_id)list.ItemAt(i)); 113 BMessage* message = new BMessage(B_QUIT_REQUESTED); 114 otherme->SendMessage(message); 115 delete otherme; 116 } 117 } 118 } 119 120 121 void 122 PCApplication::ArgvReceived(int32 argc, char **argv) 123 { 124 if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) { 125 team_id tracker = be_roster->TeamFor(kTrackerSig); 126 if (tracker >= 0) { 127 BMessenger messenger(NULL, tracker); 128 messenger.SendMessage(B_QUIT_REQUESTED); 129 int k = 500; 130 do { 131 snooze(10000); 132 } while (be_roster->IsRunning(kTrackerSig) && k-- > 0); 133 } 134 remove("/boot/home/config/settings/Tracker/tracker_shelf"); 135 launch(kTrackerSig, "/boot/system/Tracker"); 136 } else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) { 137 BDeskbar deskbar; 138 if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName)) 139 move_to_deskbar(deskbar); 140 } else if (argc > 1) { 141 // print a simple usage string 142 printf("Usage: %s [-deskbar]\n", argv[0]); 143 printf("(c) 1996-2001 Georges-Edouard Berenger, berenger@francenet.fr\n"); 144 } 145 146 Quit(); 147 } 148 149 150 // #pragma mark - 151 152 153 int 154 main() 155 { 156 PCApplication application; 157 application.Run(); 158 159 return B_OK; 160 } 161 162