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