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
25 #include "Preferences.h"
26 #include "ProcessController.h"
27 #include "Utilities.h"
30 #include <Application.h>
33 #include <FindDirectory.h>
42 #undef B_TRANSLATION_CONTEXT
43 #define B_TRANSLATION_CONTEXT "ProcessController"
46 class PCApplication
: public BApplication
{
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;
69 PCApplication::PCApplication()
71 BApplication(kSignature
)
76 PCApplication::~PCApplication()
80 wait_for_thread(id
, &returnValue
);
86 PCApplication::ReadyToRun()
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) {
99 if (!deskbar
.HasItem(kDeskbarItemName
))
100 move_to_deskbar(deskbar
);
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
);
115 // quit other eventually running instances
117 be_roster
->GetAppList(kSignature
, &list
);
118 int32 count
= list
.CountItems();
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
);
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
);
135 BMessenger
messenger(NULL
, tracker
);
136 messenger
.SendMessage(B_QUIT_REQUESTED
);
140 } while (be_roster
->IsRunning(kTrackerSig
) && k
-- > 0);
143 if (find_directory(B_USER_SETTINGS_DIRECTORY
, &shelfPath
) == B_OK
144 && shelfPath
.Append("Tracker/tracker_shelf") == B_OK
) {
145 remove(shelfPath
.Path());
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) {
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"));
173 PCApplication application
;