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 <Catalog.h> 32 #include <Deskbar.h> 33 #include <FindDirectory.h> 34 #include <Path.h> 35 #include <Roster.h> 36 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <string.h> 40 41 42 #undef B_TRANSLATION_CONTEXT 43 #define B_TRANSLATION_CONTEXT "ProcessController" 44 45 46 class PCApplication : public BApplication { 47 public: 48 PCApplication(); 49 virtual ~PCApplication(); 50 51 virtual void ReadyToRun(); 52 virtual void ArgvReceived(int32 argc, char** argv); 53 }; 54 55 56 const char* kSignature = "application/x-vnd.Haiku-ProcessController"; 57 const char* kTrackerSig = "application/x-vnd.Be-TRAK"; 58 const char* kDeskbarSig = "application/x-vnd.Be-TSKB"; 59 const char* kTerminalSig = "application/x-vnd.Haiku-Terminal"; 60 const char* kPreferencesFileName = "ProcessController Prefs"; 61 62 const char* kPosPrefName = "Position"; 63 const char* kVersionName = "Version"; 64 const int kCurrentVersion = 311; 65 66 thread_id id = 0; 67 68 69 PCApplication::PCApplication() 70 : 71 BApplication(kSignature) 72 { 73 } 74 75 76 PCApplication::~PCApplication() 77 { 78 if (id) { 79 status_t returnValue; 80 wait_for_thread(id, &returnValue); 81 } 82 } 83 84 85 void 86 PCApplication::ReadyToRun() 87 { 88 BDeskbar deskbar; 89 if (!deskbar.HasItem(kDeskbarItemName)) { 90 // We're not yet installed in the Deskbar, ask if we should 91 BAlert* alert = new BAlert(B_TRANSLATE("Info"), 92 B_TRANSLATE("You can run ProcessController in a window" 93 " or install it in the Deskbar."), B_TRANSLATE("Run in window"), 94 B_TRANSLATE("Install in Deskbar"), 95 NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 96 97 if (alert->Go() != 0) { 98 BDeskbar deskbar; 99 if (!deskbar.HasItem(kDeskbarItemName)) 100 move_to_deskbar(deskbar); 101 Quit(); 102 return; 103 } 104 } else { 105 BAlert* alert = new BAlert(B_TRANSLATE("Info"), 106 B_TRANSLATE("ProcessController is already installed in Deskbar."), 107 B_TRANSLATE("OK"), NULL, 108 NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 109 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 110 alert->Go(); 111 } 112 113 new PCWindow(); 114 115 // quit other eventually running instances 116 BList list; 117 be_roster->GetAppList(kSignature, &list); 118 long count = list.CountItems(); 119 if (count > 1) { 120 for (long i = 0; i < count - 1; i++) { 121 BMessenger* otherme = new BMessenger(NULL, (team_id)list.ItemAt(i)); 122 BMessage* message = new BMessage(B_QUIT_REQUESTED); 123 otherme->SendMessage(message); 124 delete otherme; 125 } 126 } 127 } 128 129 130 void 131 PCApplication::ArgvReceived(int32 argc, char **argv) 132 { 133 if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) { 134 team_id tracker = be_roster->TeamFor(kTrackerSig); 135 if (tracker >= 0) { 136 BMessenger messenger(NULL, tracker); 137 messenger.SendMessage(B_QUIT_REQUESTED); 138 int k = 500; 139 do { 140 snooze(10000); 141 } while (be_roster->IsRunning(kTrackerSig) && k-- > 0); 142 } 143 BPath shelfPath; 144 if (find_directory(B_USER_SETTINGS_DIRECTORY, &shelfPath) == B_OK 145 && shelfPath.Append("Tracker/tracker_shelf") == B_OK) { 146 remove(shelfPath.Path()); 147 } 148 BPath trackerPath; 149 if (find_directory(B_SYSTEM_DIRECTORY, &trackerPath) == B_OK 150 && trackerPath.Append("Tracker") == B_OK) { 151 launch(kTrackerSig, trackerPath.Path()); 152 } 153 } else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) { 154 BDeskbar deskbar; 155 if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName)) 156 move_to_deskbar(deskbar); 157 } else if (argc > 1) { 158 // print a simple usage string 159 printf(B_TRANSLATE("Usage: %s [-deskbar]\n"), argv[0]); 160 printf(B_TRANSLATE("(c) 1996-2001 Georges-Edouard Berenger, " 161 "berenger@francenet.fr\n")); 162 } 163 164 Quit(); 165 } 166 167 168 // #pragma mark - 169 170 171 int 172 main() 173 { 174 PCApplication application; 175 application.Run(); 176 177 return B_OK; 178 } 179 180