xref: /haiku/src/apps/processcontroller/PCWorld.cpp (revision e2940ab6f0f144dafb0b1c5e9056265b94ba0596)
1ed7a3501SAxel Dörfler /*
2ed7a3501SAxel Dörfler 	PCWorld.cpp
3ed7a3501SAxel Dörfler 
4*e2940ab6SAxel 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 
22*e2940ab6SAxel Dörfler 
23ed7a3501SAxel Dörfler #include "PCWorld.h"
24ed7a3501SAxel Dörfler #include "PCWindow.h"
25ed7a3501SAxel Dörfler #include "PCView.h"
26ed7a3501SAxel Dörfler #include "PCUtils.h"
27*e2940ab6SAxel Dörfler 
28ed7a3501SAxel Dörfler #include <Roster.h>
29ed7a3501SAxel Dörfler #include <Deskbar.h>
30ed7a3501SAxel Dörfler 
31*e2940ab6SAxel Dörfler #include <stdio.h>
32*e2940ab6SAxel Dörfler #include <stdlib.h>
33*e2940ab6SAxel Dörfler 
34ed7a3501SAxel Dörfler const char* kSignature = "application/x-vnd.Geb-ProcessController";
35ed7a3501SAxel Dörfler const char* kTrackerSig = "application/x-vnd.Be-TRAK";
36ed7a3501SAxel Dörfler const char* kDeskbarSig = "application/x-vnd.Be-TSKB";
37*e2940ab6SAxel Dörfler const char* kTerminalSig = "application/x-vnd.Haiku-Terminal";
38ed7a3501SAxel Dörfler const char* kPreferencesFileName = "ProcessController Prefs";
39ed7a3501SAxel Dörfler 
40*e2940ab6SAxel Dörfler 
41ed7a3501SAxel Dörfler thread_id id = 0;
42ed7a3501SAxel Dörfler 
43ed7a3501SAxel Dörfler 
44*e2940ab6SAxel Dörfler PCApplication::PCApplication()
45*e2940ab6SAxel Dörfler 	: BApplication(kSignature)
46ed7a3501SAxel Dörfler {
47ed7a3501SAxel Dörfler }
48ed7a3501SAxel Dörfler 
49*e2940ab6SAxel Dörfler 
50ed7a3501SAxel Dörfler PCApplication::~PCApplication()
51ed7a3501SAxel Dörfler {
52ed7a3501SAxel Dörfler 	if (id) {
53*e2940ab6SAxel Dörfler 		status_t returnValue;
54*e2940ab6SAxel Dörfler 		wait_for_thread(id, &returnValue);
55ed7a3501SAxel Dörfler 	}
56ed7a3501SAxel Dörfler }
57ed7a3501SAxel Dörfler 
58*e2940ab6SAxel Dörfler 
59*e2940ab6SAxel Dörfler void
60*e2940ab6SAxel Dörfler PCApplication::ReadyToRun()
61ed7a3501SAxel Dörfler {
62ed7a3501SAxel Dörfler 	new PCWindow();
63*e2940ab6SAxel Dörfler 
64*e2940ab6SAxel Dörfler 	// quit other eventually running instances
65ed7a3501SAxel Dörfler 	BList list;
66ed7a3501SAxel Dörfler 	be_roster->GetAppList(kSignature, &list);
67*e2940ab6SAxel Dörfler 	long count = list.CountItems();
68*e2940ab6SAxel Dörfler 	if (count > 1) {
69*e2940ab6SAxel Dörfler 		for (long i = 0; i < count - 1; i++) {
70*e2940ab6SAxel Dörfler 			BMessenger* otherme = new BMessenger(NULL, (team_id)list.ItemAt(i));
71ed7a3501SAxel Dörfler 			BMessage* message = new BMessage(B_QUIT_REQUESTED);
72ed7a3501SAxel Dörfler 			otherme->SendMessage(message);
73ed7a3501SAxel Dörfler 			delete otherme;
74ed7a3501SAxel Dörfler 		}
75ed7a3501SAxel Dörfler 	}
76ed7a3501SAxel Dörfler }
77ed7a3501SAxel Dörfler 
78*e2940ab6SAxel Dörfler 
79*e2940ab6SAxel Dörfler void
80*e2940ab6SAxel Dörfler PCApplication::ArgvReceived (int32 argc, char **argv)
81ed7a3501SAxel Dörfler {
82*e2940ab6SAxel Dörfler 	if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) {
83ed7a3501SAxel Dörfler 		team_id tracker = be_roster->TeamFor(kTrackerSig);
84*e2940ab6SAxel Dörfler 		if (tracker >= 0) {
85ed7a3501SAxel Dörfler 			BMessenger messenger(NULL, tracker);
86ed7a3501SAxel Dörfler 			messenger.SendMessage(B_QUIT_REQUESTED);
87ed7a3501SAxel Dörfler 			int	k = 500;
88ed7a3501SAxel Dörfler 			do {
89ed7a3501SAxel Dörfler 				snooze(10000);
90ed7a3501SAxel Dörfler 			} while (be_roster->IsRunning(kTrackerSig) && k-- > 0);
91ed7a3501SAxel Dörfler 		}
92ed7a3501SAxel Dörfler 		remove("/boot/home/config/settings/Tracker/tracker_shelf");
93ed7a3501SAxel Dörfler 		launch(kTrackerSig, "/boot/beos/system/Tracker");
94*e2940ab6SAxel Dörfler 	} else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) {
95*e2940ab6SAxel Dörfler 		BDeskbar deskbar;
96*e2940ab6SAxel Dörfler 		if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName))
97*e2940ab6SAxel Dörfler 			move_to_deskbar(deskbar);
98*e2940ab6SAxel Dörfler 	} else if (argc > 1) {
99ed7a3501SAxel Dörfler 		// print a simple usage string
100ed7a3501SAxel Dörfler 		printf(	"Usage: %s [-deskbar]\n", argv[0]);
101ed7a3501SAxel Dörfler 		printf(	"(c) 1997-2001 Georges-Edouard Berenger, berenger@francenet.fr\n");
102ed7a3501SAxel Dörfler 	}
103*e2940ab6SAxel Dörfler 
104ed7a3501SAxel Dörfler 	Quit();
105ed7a3501SAxel Dörfler }
106*e2940ab6SAxel Dörfler 
107*e2940ab6SAxel Dörfler 
108*e2940ab6SAxel Dörfler //	#pragma mark -
109*e2940ab6SAxel Dörfler 
110*e2940ab6SAxel Dörfler 
111*e2940ab6SAxel Dörfler int
112*e2940ab6SAxel Dörfler main()
113*e2940ab6SAxel Dörfler {
114*e2940ab6SAxel Dörfler 	PCApplication application;
115*e2940ab6SAxel Dörfler 	application.Run();
116*e2940ab6SAxel Dörfler 
117*e2940ab6SAxel Dörfler 	return B_OK;
118*e2940ab6SAxel Dörfler }
119*e2940ab6SAxel Dörfler 
120