vfs: check userland buffers before reading them.
[haiku.git] / src / apps / processcontroller / PCWorld.cpp
blob140ef54e29025011c1ab805ed8a4e56f99a1df91
1 /*
2 PCWorld.cpp
4 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
5 Copyright (C) 2004 beunited.org
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.
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.
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
23 #include "PCWorld.h"
24 #include "PCWindow.h"
25 #include "Preferences.h"
26 #include "ProcessController.h"
27 #include "Utilities.h"
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>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
42 #undef B_TRANSLATION_CONTEXT
43 #define B_TRANSLATION_CONTEXT "ProcessController"
46 class PCApplication : public BApplication {
47 public:
48 PCApplication();
49 virtual ~PCApplication();
51 virtual void ReadyToRun();
52 virtual void ArgvReceived(int32 argc, char** argv);
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";
62 const char* kPosPrefName = "Position";
63 const char* kVersionName = "Version";
64 const int kCurrentVersion = 311;
66 thread_id id = 0;
69 PCApplication::PCApplication()
71 BApplication(kSignature)
76 PCApplication::~PCApplication()
78 if (id) {
79 status_t returnValue;
80 wait_for_thread(id, &returnValue);
85 void
86 PCApplication::ReadyToRun()
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);
97 if (alert->Go() != 0) {
98 BDeskbar deskbar;
99 if (!deskbar.HasItem(kDeskbarItemName))
100 move_to_deskbar(deskbar);
101 Quit();
102 return;
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();
113 new PCWindow();
115 // quit other eventually running instances
116 BList list;
117 be_roster->GetAppList(kSignature, &list);
118 int32 count = list.CountItems();
119 if (count > 1) {
120 for (int32 i = 0; i < count - 1; i++) {
121 BMessenger otherme(NULL, (addr_t)list.ItemAt(i));
122 BMessage message(B_QUIT_REQUESTED);
123 otherme.SendMessage(&message);
129 void
130 PCApplication::ArgvReceived(int32 argc, char **argv)
132 if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) {
133 team_id tracker = be_roster->TeamFor(kTrackerSig);
134 if (tracker >= 0) {
135 BMessenger messenger(NULL, tracker);
136 messenger.SendMessage(B_QUIT_REQUESTED);
137 int k = 500;
138 do {
139 snooze(10000);
140 } while (be_roster->IsRunning(kTrackerSig) && k-- > 0);
142 BPath shelfPath;
143 if (find_directory(B_USER_SETTINGS_DIRECTORY, &shelfPath) == B_OK
144 && shelfPath.Append("Tracker/tracker_shelf") == B_OK) {
145 remove(shelfPath.Path());
147 BPath trackerPath;
148 if (find_directory(B_SYSTEM_DIRECTORY, &trackerPath) == B_OK
149 && trackerPath.Append("Tracker") == B_OK) {
150 launch(kTrackerSig, trackerPath.Path());
152 } else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) {
153 BDeskbar deskbar;
154 if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName))
155 move_to_deskbar(deskbar);
156 } else if (argc > 1) {
157 // print a simple usage string
158 printf(B_TRANSLATE("Usage: %s [-deskbar]\n"), argv[0]);
159 printf(B_TRANSLATE("(c) 1996-2001 Georges-Edouard Berenger, "
160 "berenger@francenet.fr\n"));
163 Quit();
167 // #pragma mark -
171 main()
173 PCApplication application;
174 application.Run();
176 return B_OK;