* Moved "install to Deskbar" alert into the application.

* If you install ProcessController to the Deskbar after startup, its window
  is not opened anymore.
* When you install ProcessController, the Deskbar is only restarted if needed;
  this can probably be removed completely under Haiku.
* Renamed some menu items.
* Removed "Use Pulse's settings" menu item.
* Fixed remaining issues from bug #633 as far as ProcessController was concerned.
* Removed unused source files.
* Big cleanup, even though there could be done much much more.
* Compacted the source files a bit, merged PCView.cpp and PCView2.cpp to
  ProcessController.cpp to match the name of the class.
* Renamed PCUtils.{cpp|h} to Utilities.{cpp|h}


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17647 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-30 01:32:41 +00:00
parent c8882988b7
commit a12827f24d
40 changed files with 1285 additions and 2543 deletions
+11 -16
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
AutoIcon.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,30 +15,30 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "AutoIcon.h" #include "AutoIcon.h"
#include "PCUtils.h" #include "Utilities.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <Entry.h> #include <Entry.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Roster.h> #include <Roster.h>
AutoIcon::~AutoIcon ()
AutoIcon::~AutoIcon()
{ {
if (fBitmap) delete fBitmap;
delete fBitmap;
} }
BBitmap* AutoIcon::bitmap ()
BBitmap*
AutoIcon::bitmap()
{ {
if (fBitmap == 0) if (fBitmap == NULL) {
{
fBitmap = new BBitmap (BRect (0, 0, 15, 15), B_COLOR_8_BIT); fBitmap = new BBitmap (BRect (0, 0, 15, 15), B_COLOR_8_BIT);
if (fSignature) if (fSignature) {
{
entry_ref ref; entry_ref ref;
be_roster->FindApp (fSignature, &ref); be_roster->FindApp (fSignature, &ref);
if (BNodeInfo::GetTrackerIcon(&ref, fBitmap, B_MINI_ICON) != B_OK) if (BNodeInfo::GetTrackerIcon(&ref, fBitmap, B_MINI_ICON) != B_OK)
@@ -54,4 +50,3 @@ BBitmap* AutoIcon::bitmap ()
return fBitmap; return fBitmap;
} }
+17 -20
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
AutoIcon.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,30 +15,31 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _AUTO_ICON_H_ #ifndef _AUTO_ICON_H_
#define _AUTO_ICON_H_ #define _AUTO_ICON_H_
#include <SupportDefs.h> #include <SupportDefs.h>
class BBitmap; class BBitmap;
class AutoIcon {
public: class AutoIcon {
AutoIcon (const char* signature): fSignature (signature), fbits (0), fBitmap (0) {} public:
AutoIcon (const uchar* bits): fSignature (0), fbits (bits), fBitmap (0) {} AutoIcon(const char* signature)
~AutoIcon (); : fSignature (signature), fbits (0), fBitmap (0) {}
AutoIcon(const uchar* bits)
operator BBitmap* () { return bitmap (); } : fSignature (0), fbits (bits), fBitmap (0) {}
BBitmap* bitmap (); ~AutoIcon();
private: operator BBitmap*() { return bitmap(); }
const char* fSignature; BBitmap* bitmap();
const uchar* fbits;
BBitmap * fBitmap; private:
const char* fSignature;
const uchar* fbits;
BBitmap * fBitmap;
}; };
#endif // _AUTO_ICON_H_ #endif // _AUTO_ICON_H_
+2 -7
View File
@@ -9,22 +9,17 @@ Application ProcessController :
MemoryBarMenu.cpp MemoryBarMenu.cpp
MemoryBarMenuItem.cpp MemoryBarMenuItem.cpp
NoiseBarMenuItem.cpp NoiseBarMenuItem.cpp
PCUtils.cpp ProcessController.cpp
PCView.cpp
PCView2.cpp
PCWindow.cpp PCWindow.cpp
PCWorld.cpp PCWorld.cpp
Preferences.cpp Preferences.cpp
PrintMessage.cpp
PriorityMenu.cpp PriorityMenu.cpp
QuitMenu.cpp QuitMenu.cpp
ReadableLong.cpp
TeamBarMenu.cpp TeamBarMenu.cpp
TeamBarMenuItem.cpp TeamBarMenuItem.cpp
ThreadBarMenu.cpp ThreadBarMenu.cpp
ThreadBarMenuItem.cpp ThreadBarMenuItem.cpp
URLView.cpp Utilities.cpp
WindowsTools.cpp
: be : be
: ProcessController.rdef : ProcessController.rdef
; ;
@@ -19,22 +19,23 @@
#include "KernelMemoryBarMenuItem.h" #include "KernelMemoryBarMenuItem.h"
#include "MemoryBarMenu.h"
#include "Colors.h" #include "Colors.h"
#include "PCView.h" #include "MemoryBarMenu.h"
#include "ProcessController.h"
#include <stdio.h> #include <stdio.h>
KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info* sinfo) KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info& systemInfo)
: BMenuItem("System Resources & Caches...", NULL) : BMenuItem("System Resources & Caches...", NULL)
{ {
fTotalWriteMemory = -1; fTotalWriteMemory = -1;
fLastSum = -1; fLastSum = -1;
fGrenze1 = -1; fGrenze1 = -1;
fGrenze2 = -1; fGrenze2 = -1;
fPhsysicalMemory = float(int(sinfo->max_pages * B_PAGE_SIZE / 1024)); fPhsysicalMemory = float(int(systemInfo.max_pages * B_PAGE_SIZE / 1024));
fCommitedMemory = float(int(sinfo->used_pages * B_PAGE_SIZE / 1024)); fCommitedMemory = float(int(systemInfo.used_pages * B_PAGE_SIZE / 1024));
} }
@@ -25,7 +25,7 @@
class KernelMemoryBarMenuItem : public BMenuItem { class KernelMemoryBarMenuItem : public BMenuItem {
public: public:
KernelMemoryBarMenuItem(system_info* systemInfo); KernelMemoryBarMenuItem(system_info& systemInfo);
virtual void DrawContent(); virtual void DrawContent();
virtual void GetContentSize(float* _width, float* _height); virtual void GetContentSize(float* _width, float* _height);
void DrawBar(bool force); void DrawBar(bool force);
+25 -24
View File
@@ -21,7 +21,7 @@
#include "MemoryBarMenu.h" #include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h" #include "MemoryBarMenuItem.h"
#include "KernelMemoryBarMenuItem.h" #include "KernelMemoryBarMenuItem.h"
#include "PCView.h" #include "ProcessController.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <Roster.h> #include <Roster.h>
@@ -35,18 +35,19 @@
float gMemoryTextWidth; float gMemoryTextWidth;
MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* sinfo) MemoryBarMenu::MemoryBarMenu(const char* name, info_pack* infos,
system_info& systemInfo)
: BMenu(name), : BMenu(name),
fFirstShow(true) fFirstShow(true)
{ {
fTeamCount = sinfo->used_teams + EXTRA; fTeamCount = systemInfo.used_teams + EXTRA;
SetFlags(Flags() | B_PULSE_NEEDED); SetFlags(Flags() | B_PULSE_NEEDED);
fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount); fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount);
int k; int k;
for (k = 0; k < sinfo->used_teams; k++) { for (k = 0; k < systemInfo.used_teams; k++) {
fTeamList[k] = infos[k].tminfo.team; fTeamList[k] = infos[k].team_info.team;
} }
while (k < fTeamCount) { while (k < fTeamCount) {
@@ -58,7 +59,7 @@ MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* si
fRecycleCount = EXTRA; fRecycleCount = EXTRA;
fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount); fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount);
SetFont(be_plain_font); SetFont(be_plain_font);
AddItem(new KernelMemoryBarMenuItem(sinfo)); AddItem(new KernelMemoryBarMenuItem(systemInfo));
} }
@@ -95,8 +96,8 @@ MemoryBarMenu::Pulse()
int k; int k;
MemoryBarMenuItem *item; MemoryBarMenuItem *item;
int total = 0; int total = 0;
for (k = 1; (item = (MemoryBarMenuItem*) ItemAt (k)) != NULL; k++) { for (k = 1; (item = (MemoryBarMenuItem*)ItemAt(k)) != NULL; k++) {
int m = item->UpdateSituation (commitedMemory); int m = item->UpdateSituation(commitedMemory);
if (m < 0) { if (m < 0) {
if (lastRecycle == fRecycleCount) { if (lastRecycle == fRecycleCount) {
fRecycleCount += EXTRA; fRecycleCount += EXTRA;
@@ -117,20 +118,20 @@ MemoryBarMenu::Pulse()
// Look new teams that have appeared. Create an item for them, or recycle from the list. // Look new teams that have appeared. Create an item for them, or recycle from the list.
int32 cookie = 0; int32 cookie = 0;
infosPack infos; info_pack infos;
item = NULL; item = NULL;
while (get_next_team_info(&cookie, &infos.tminfo) == B_OK) { while (get_next_team_info(&cookie, &infos.team_info) == B_OK) {
int j = 0; int j = 0;
while (j < fTeamCount && infos.tminfo.team != fTeamList[j]) { while (j < fTeamCount && infos.team_info.team != fTeamList[j]) {
j++; j++;
} }
if (infos.tminfo.team != fTeamList[j]) { if (infos.team_info.team != fTeamList[j]) {
// new team // new team
team_info info; team_info info;
j = 0; j = 0;
while (j < fTeamCount && fTeamList[j] != -1) { while (j < fTeamCount && fTeamList[j] != -1) {
if (get_team_info (fTeamList[j], &info) != B_OK) if (get_team_info(fTeamList[j], &info) != B_OK)
fTeamList[j] = -1; fTeamList[j] = -1;
else else
j++; j++;
@@ -138,23 +139,23 @@ MemoryBarMenu::Pulse()
if (j == fTeamCount) { if (j == fTeamCount) {
fTeamCount += 10; fTeamCount += 10;
fTeamList = (team_id*)realloc(fTeamList, sizeof (team_id) * fTeamCount); fTeamList = (team_id*)realloc(fTeamList, sizeof(team_id) * fTeamCount);
} }
fTeamList[j] = infos.tminfo.team; fTeamList[j] = infos.team_info.team;
if (!get_team_name_and_icon(infos, true)) { if (!get_team_name_and_icon(infos, true)) {
// the team is already gone! // the team is already gone!
delete infos.tmicon; delete infos.team_icon;
fTeamList[j] = -1; fTeamList[j] = -1;
} else { } else {
if (!item && firstRecycle < lastRecycle) { if (!item && firstRecycle < lastRecycle)
item = fRecycleList[firstRecycle++].item; item = fRecycleList[firstRecycle++].item;
}
if (item) if (item)
item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true); item->Reset(infos.team_name, infos.team_info.team, infos.team_icon, true);
else { else {
AddItem(item = new MemoryBarMenuItem (infos.tmname, AddItem(item = new MemoryBarMenuItem(infos.team_name,
infos.tminfo.team, infos.tmicon, true, NULL)); infos.team_info.team, infos.team_icon, true, NULL));
} }
int m = item->UpdateSituation(commitedMemory); int m = item->UpdateSituation(commitedMemory);
@@ -178,10 +179,10 @@ MemoryBarMenu::Pulse()
lastRecycle - firstRecycle, true); lastRecycle - firstRecycle, true);
} }
fLastTotalTime = system_time (); fLastTotalTime = system_time();
KernelMemoryBarMenuItem *kernelItem; KernelMemoryBarMenuItem *kernelItem;
if ((kernelItem = (KernelMemoryBarMenuItem*)ItemAt(0)) != NULL) if ((kernelItem = (KernelMemoryBarMenuItem*)ItemAt(0)) != NULL)
kernelItem->UpdateSituation (commitedMemory, total); kernelItem->UpdateSituation(commitedMemory, total);
Window()->EndViewTransaction(); Window()->EndViewTransaction();
Window()->Flush(); Window()->Flush();
+3 -3
View File
@@ -20,7 +20,7 @@
#define _MEMORY_BAR_MENU_H_ #define _MEMORY_BAR_MENU_H_
#include "PCUtils.h" #include "Utilities.h"
#include <Menu.h> #include <Menu.h>
@@ -34,8 +34,8 @@ typedef struct {
class MemoryBarMenu : public BMenu { class MemoryBarMenu : public BMenu {
public: public:
MemoryBarMenu(const char* name, infosPack *infos, MemoryBarMenu(const char* name, info_pack* infos,
system_info* sinfo); system_info& systemInfo);
virtual ~MemoryBarMenu(); virtual ~MemoryBarMenu();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
@@ -18,10 +18,11 @@
*/ */
#include "PCView.h"
#include "MemoryBarMenuItem.h" #include "MemoryBarMenuItem.h"
#include "MemoryBarMenu.h"
#include "Colors.h" #include "Colors.h"
#include "MemoryBarMenu.h"
#include "ProcessController.h"
#include <Bitmap.h> #include <Bitmap.h>
@@ -93,12 +94,18 @@ MemoryBarMenuItem::DrawIcon()
void void
MemoryBarMenuItem::DrawBar(bool force) MemoryBarMenuItem::DrawBar(bool force)
{ {
// only draw anything if something has changed
if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll
&& fCommitedMemory == fLastCommited)
return;
bool selected = IsSelected(); bool selected = IsSelected();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu(); BMenu* menu = Menu();
// draw the bar itself // draw the bar itself
BRect cadre(frame.right - kMargin - kBarWidth, frame.top + 5,
BRect rect(frame.right - kMargin - kBarWidth, frame.top + 5,
frame.right - kMargin, frame.top + 13); frame.right - kMargin, frame.top + 13);
if (fWriteMemory < 0) if (fWriteMemory < 0)
return; return;
@@ -111,17 +118,17 @@ MemoryBarMenuItem::DrawBar(bool force)
menu->SetHighColor(gFrameColorSelected); menu->SetHighColor(gFrameColorSelected);
else else
menu->SetHighColor(gFrameColor); menu->SetHighColor(gFrameColor);
menu->StrokeRect(cadre); menu->StrokeRect(rect);
} }
cadre.InsetBy(1, 1); rect.InsetBy(1, 1);
BRect r = cadre; BRect r = rect;
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory; float grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory;
float grenze2 = cadre.left + (cadre.right - cadre.left) * float (fAllMemory) / fCommitedMemory; float grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory;
if (grenze1 > cadre.right) if (grenze1 > rect.right)
grenze1 = cadre.right; grenze1 = rect.right;
if (grenze2 > cadre.right) if (grenze2 > rect.right)
grenze2 = cadre.right; grenze2 = rect.right;
r.right = grenze1; r.right = grenze1;
if (!force) if (!force)
r.left = fGrenze1; r.left = fGrenze1;
@@ -152,7 +159,7 @@ MemoryBarMenuItem::DrawBar(bool force)
} }
r.left = grenze2; r.left = grenze2;
r.right = cadre.right; r.right = rect.right;
if (!force) if (!force)
r.right = fGrenze2; r.right = fGrenze2;
@@ -169,41 +176,38 @@ MemoryBarMenuItem::DrawBar(bool force)
fGrenze1 = grenze1; fGrenze1 = grenze1;
fGrenze2 = grenze2; fGrenze2 = grenze2;
// draw the value fLastCommited = fCommitedMemory;
if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite
|| fAllMemory != fLastAll) {
if (selected)
menu->SetLowColor(gMenuBackColorSelected);
else
menu->SetLowColor(gMenuBackColor);
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll) { // Draw the values if necessary; if only fCommitedMemory changes, only
menu->SetHighColor(menu->LowColor()); // the bar might have to be updated
BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
cadre.left - kMargin, frame.bottom);
menu->FillRect(trect);
fLastWrite = fWriteMemory;
fLastAll = fAllMemory;
}
fLastCommited = fCommitedMemory;
menu->SetHighColor(kBlack);
char infos[128]; if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll)
// if (fWriteMemory >= 1024) return;
// sprintf(infos, "%.1f MB", float (fWriteMemory) / 1024.f);
// else
sprintf(infos, "%d KB", fWriteMemory);
BPoint loc(cadre.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth (infos), if (selected)
cadre.bottom + 1); menu->SetLowColor(gMenuBackColorSelected);
menu->DrawString(infos, loc); else
// if (fAllMemory >= 1024) menu->SetLowColor(gMenuBackColor);
// sprintf (infos, "%.1f MB", float (fAllMemory) / 1024.f);
// else BRect textRect(rect.left - kMargin - gMemoryTextWidth, frame.top,
sprintf(infos, "%d KB", fAllMemory); rect.left - kMargin, frame.bottom);
loc.x = cadre.left - kMargin - menu->StringWidth(infos); menu->FillRect(textRect, B_SOLID_LOW);
menu->DrawString(infos, loc);
} fLastWrite = fWriteMemory;
fLastAll = fAllMemory;
menu->SetHighColor(kBlack);
char infos[128];
sprintf(infos, "%d KB", fWriteMemory);
BPoint loc(rect.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
rect.bottom + 1);
menu->DrawString(infos, loc);
sprintf(infos, "%d KB", fAllMemory);
loc.x = rect.left - kMargin - menu->StringWidth(infos);
menu->DrawString(infos, loc);
} }
@@ -240,11 +244,11 @@ MemoryBarMenuItem::BarUpdate()
lram_size += ainfo.ram_size; lram_size += ainfo.ram_size;
// TODO: this won't work this way anymore under Haiku! // TODO: this won't work this way anymore under Haiku!
int zone = (int (ainfo.address) & 0xf0000000) >> 24; // int zone = (int (ainfo.address) & 0xf0000000) >> 24;
if ((ainfo.protection & B_WRITE_AREA) if ((ainfo.protection & B_WRITE_AREA) != 0)
&& (zone & 0xf0) != 0xA0 // Exclude media buffers
&& (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
lwram_size += ainfo.ram_size; lwram_size += ainfo.ram_size;
// && (zone & 0xf0) != 0xA0 // Exclude media buffers
// && (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
} }
if (!exists) { if (!exists) {
team_info info; team_info info;
+24 -24
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
NoiseBarMenuItem.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,16 +15,17 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "NoiseBarMenuItem.h"
#include "Colors.h"
#include "PCView.h"
// -------------------------------------------------------------- #include "NoiseBarMenuItem.h"
#include "Colors.h"
#include "ProcessController.h"
NoiseBarMenuItem::NoiseBarMenuItem() NoiseBarMenuItem::NoiseBarMenuItem()
:BMenuItem("Gone Teams...", NULL) : BMenuItem("Gone Teams...", NULL)
{ {
fBusyWaiting = -1; fBusyWaiting = -1;
fLost = -1; fLost = -1;
@@ -36,20 +33,22 @@ NoiseBarMenuItem::NoiseBarMenuItem()
fGrenze2 = -1; fGrenze2 = -1;
} }
// --------------------------------------------------------------
void NoiseBarMenuItem::DrawContent() void
NoiseBarMenuItem::DrawContent()
{ {
DrawBar(true); DrawBar(true);
Menu()->MovePenTo(ContentLocation()); Menu()->MovePenTo(ContentLocation());
BMenuItem::DrawContent(); BMenuItem::DrawContent();
} }
// --------------------------------------------------------------
void NoiseBarMenuItem::DrawBar(bool force) void
NoiseBarMenuItem::DrawBar(bool force)
{ {
bool selected = IsSelected (); bool selected = IsSelected ();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu (); BMenu* menu = Menu ();
frame.right -= 24; frame.right -= 24;
frame.left = frame.right-kBarWidth; frame.left = frame.right-kBarWidth;
frame.top += 5; frame.top += 5;
@@ -66,9 +65,9 @@ void NoiseBarMenuItem::DrawBar(bool force)
menu->StrokeRect(frame); menu->StrokeRect(frame);
} }
frame.InsetBy(1, 1); frame.InsetBy(1, 1);
BRect r = frame; BRect r = frame;
float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting; float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting;
float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost); float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost);
if (grenze1 > frame.right) if (grenze1 > frame.right)
grenze1 = frame.right; grenze1 = frame.right;
if (grenze2 > frame.right) if (grenze2 > frame.right)
@@ -78,7 +77,7 @@ void NoiseBarMenuItem::DrawBar(bool force)
r.left = fGrenze1; r.left = fGrenze1;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor (tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT)); menu->SetHighColor(tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT));
else else
menu->SetHighColor(kGreen); menu->SetHighColor(kGreen);
// menu->SetHighColor(gKernelColor); // menu->SetHighColor(gKernelColor);
@@ -113,8 +112,9 @@ void NoiseBarMenuItem::DrawBar(bool force)
fGrenze2 = grenze2; fGrenze2 = grenze2;
} }
// --------------------------------------------------------------
void NoiseBarMenuItem::GetContentSize(float* width, float* height) void
NoiseBarMenuItem::GetContentSize(float* width, float* height)
{ {
BMenuItem::GetContentSize(width, height); BMenuItem::GetContentSize(width, height);
if (*height < 16) if (*height < 16)
-143
View File
@@ -1,143 +0,0 @@
/*
PCUtils.cpp
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "PCUtils.h"
#include "PCWorld.h"
#include "PCView.h"
#include "icons.data"
#include <Alert.h>
#include <Bitmap.h>
#include <Deskbar.h>
#include <FindDirectory.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <stdio.h>
#include <string.h>
#define snooze_time 1000000
team_id gAppServerTeamID = -1;
bool
get_team_name_and_icon(infosPack& infopack, bool icon)
{
if (gAppServerTeamID == -1 && !strcmp(infopack.tminfo.args, "/boot/beos/system/servers/app_server"))
gAppServerTeamID = infopack.tminfo.team;
bool nameFromArgs = false;
bool tryTrackerIcon = true;
for (int len = strlen(infopack.tminfo.args) - 1; len >= 0 && infopack.tminfo.args[len] == ' '; len--) {
infopack.tminfo.args[len] = 0;
}
app_info info;
status_t status = be_roster->GetRunningAppInfo(infopack.tminfo.team, &info);
if (status == B_OK || infopack.tminfo.team == B_SYSTEM_TEAM) {
if (infopack.tminfo.team == B_SYSTEM_TEAM) {
BPath kernel;
find_directory(B_BEOS_SYSTEM_DIRECTORY, &kernel, true);
system_info sinfo;
get_system_info(&sinfo);
kernel.Append(sinfo.kernel_name);
get_ref_for_path(kernel.Path(), &info.ref);
nameFromArgs = true;
}
} else {
BEntry entry(infopack.tminfo.args, true);
status = entry.GetRef(&info.ref);
if (status != B_OK || strncmp(infopack.tminfo.args, "/boot/beos/system/", 18) != 0)
nameFromArgs = true;
tryTrackerIcon = (status == B_OK);
}
strncpy(infopack.tmname, nameFromArgs ? infopack.tminfo.args : info.ref.name,
B_PATH_NAME_LENGTH - 1);
if (icon) {
infopack.tmicon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT);
if (!tryTrackerIcon || BNodeInfo::GetTrackerIcon(&info.ref, infopack.tmicon, B_MINI_ICON) != B_OK)
infopack.tmicon->SetBits(k_app_mini, 256, 0, B_COLOR_8_BIT);
} else
infopack.tmicon = NULL;
return true;
}
bool
launch(const char* signature, const char* path)
{
status_t status = be_roster->Launch(signature);
if (status != B_OK && path) {
entry_ref ref;
if (get_ref_for_path(path, &ref) == B_OK)
status = be_roster->Launch(&ref);
}
return status == B_OK;
}
void
mix_colors(rgb_color &target, rgb_color & first, rgb_color & second, float mix)
{
target.red = (uint8)(second.red * mix + (1. - mix) * first.red);
target.green = (uint8)(second.green * mix + (1. - mix) * first.green);
target.blue = (uint8)(second.blue * mix + (1. - mix) * first.blue);
target.alpha = (uint8)(second.alpha * mix + (1. - mix) * first.alpha);
}
void
find_self(entry_ref& ref)
{
int32 cookie = 0;
image_info info;
while (get_next_image_info (0, &cookie, &info) == B_OK) {
if (((uint32) info.text <= (uint32) move_to_deskbar
&& (uint32) info.text + (uint32) info.text_size > (uint32) move_to_deskbar)
|| ((uint32) info.data <= (uint32) move_to_deskbar
&& (uint32) info.data + (uint32) info.data_size > (uint32) move_to_deskbar)) {
if (get_ref_for_path (info.name, &ref) == B_OK)
return;
}
}
// This works, but not always... :(
app_info appInfo;
be_roster->GetAppInfo(kSignature, &appInfo);
ref = appInfo.ref;
}
void
move_to_deskbar(BDeskbar& deskbar)
{
entry_ref ref;
find_self(ref);
deskbar.AddItem(&ref);
}
-217
View File
@@ -1,217 +0,0 @@
/*
PCView2.cpp
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "PCView.h"
#include "AutoIcon.h"
#include "IconMenuItem.h"
#include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h"
#include "PCUtils.h"
#include "PCWorld.h"
#include "Preferences.h"
#include "QuitMenu.h"
#include "TeamBarMenu.h"
#include "TeamBarMenuItem.h"
#include "ThreadBarMenu.h"
#include <Bitmap.h>
#include <Deskbar.h>
#include <PopUpMenu.h>
#include <Roster.h>
#include <Screen.h>
#include <stdio.h>
#define addtopbottom(x) if (top) popup->AddItem(x); else popup->AddItem(x, 0)
long thread_popup(void *arg);
int32 gPopupFlag = 0;
thread_id gPopupThreadID = 0;
typedef struct {
BPoint where;
BRect clickToOpenRect;
bool top;
} Tpopup_param;
void
ProcessController::MouseDown(BPoint where)
{
if (atomic_add (&gPopupFlag, 1) > 0) {
atomic_add (&gPopupFlag, -1);
return;
}
Tpopup_param* param = new Tpopup_param;
ConvertToScreen(&where);
param->where = where;
param->clickToOpenRect = Frame ();
ConvertToScreen (&param->clickToOpenRect);
param->top = where.y < BScreen(this->Window()).Frame().bottom-50;
gPopupThreadID = spawn_thread(thread_popup, "Popup holder thread",
B_URGENT_DISPLAY_PRIORITY, param);
resume_thread(gPopupThreadID);
}
long
thread_popup(void *arg)
{
Tpopup_param* param = (Tpopup_param*) arg;
int32 mcookie, hcookie;
long m, h;
BMenuItem* item;
bool top = param->top;
system_info systemInfo;
get_system_info(&systemInfo);
infosPack* infos = new infosPack[systemInfo.used_teams];
// TODO: this doesn't necessarily get all teams
for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
infos[m].tmicon = NULL;
infos[m].tmname[0] = 0;
infos[m].thinfo = NULL;
if (get_next_team_info(&mcookie, &infos[m].tminfo) == B_OK) {
infos[m].thinfo = new thread_info[infos[m].tminfo.thread_count];
for (h = 0, hcookie = 0; h < infos[m].tminfo.thread_count; h++) {
if (get_next_thread_info(infos[m].tminfo.team, &hcookie, &infos[m].thinfo[h]) != B_OK)
infos[m].thinfo[h].thread = -1;
}
get_team_name_and_icon(infos[m], true);
} else {
systemInfo.used_teams = m;
infos[m].tminfo.team = -1;
}
}
BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
popup->SetFont(be_plain_font);
// Quit section
BMenu* QuitPopup = new QuitMenu("Quit an Application", infos, systemInfo.used_teams);
QuitPopup->SetFont(be_plain_font);
popup->AddItem(QuitPopup);
// Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu("Spy Memory Usage", infos, &systemInfo);
int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) {
MemoryBarMenuItem* memoryItem = new MemoryBarMenuItem(infos[m].tmname, infos[m].tminfo.team, infos[m].tmicon, false, NULL);
MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(commitedMemory);
}
}
addtopbottom(MemoryPopup);
// CPU Load section
TeamBarMenu* CPUPopup = new TeamBarMenu("Kill, Debug, or Change Priority", infos, systemInfo.used_teams);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) {
ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].tmname, infos[m].tminfo.team, infos[m].tminfo.thread_count);
BMessage* kill_team = new BMessage('KlTm');
kill_team->AddInt32("team", infos[m].tminfo.team);
TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team, infos[m].tminfo.team, infos[m].tmicon, false);
item->SetTarget(gPCView);
CPUPopup->AddItem(item);
}
}
addtopbottom(CPUPopup);
addtopbottom(new BSeparatorItem());
// CPU on/off section
if (gCPUcount > 1) {
for (int i = 0; i < gCPUcount; i++) {
char item_name[32];
sprintf (item_name, "Processor %d", i + 1);
BMessage* m = new BMessage ('CPU ');
m->AddInt32 ("cpu", i);
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
if (_kget_cpu_state_(i))
item->SetMarked (true);
item->SetTarget(gPCView);
addtopbottom(item);
}
addtopbottom (new BSeparatorItem ());
}
if (!be_roster->IsRunning(kTrackerSig)) {
item = new IconMenuItem(gPCView->fTrackerIcon, "Launch Tracker", new BMessage('Trac'));
item->SetTarget(gPCView);
addtopbottom(item);
}
if (!be_roster->IsRunning(kDeskbarSig)) {
item = new IconMenuItem(gPCView->fDeskbarIcon, "Launch Deskbar", new BMessage('Dbar'));
item->SetTarget(gPCView);
addtopbottom(item);
}
item = new IconMenuItem(gPCView->fTerminalIcon, "New Terminal", new BMessage('Term'));
item->SetTarget(gPCView);
addtopbottom(item);
addtopbottom(new BSeparatorItem());
if (be_roster->IsRunning(kDeskbarSig)) {
item = new BMenuItem("Live in the Deskbar", new BMessage ('AlDb'));
BDeskbar db;
item->SetMarked (gInDeskbar || db.HasItem (kDeskbarItemName));
item->SetTarget (gPCView);
addtopbottom (item);
}
item = new BMenuItem("Use Pulse's Settings for Colors", new BMessage ('Colo'));
item->SetTarget (gPCView);
item->SetMarked (gMimicPulse);
addtopbottom (item);
addtopbottom(new BSeparatorItem ());
item = new IconMenuItem(gPCView->fProcessControllerIcon, "About ProcessController",
new BMessage(B_ABOUT_REQUESTED));
item->SetTarget(gPCView);
addtopbottom(item);
param->where.x -= 5;
param->where.y -= 8;
popup->Go(param->where, true, true, param->clickToOpenRect);
delete popup;
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) {
delete[] infos[m].thinfo;
delete infos[m].tmicon;
}
}
delete[] infos;
delete param;
atomic_add (&gPopupFlag, -1);
gPopupThreadID = 0;
return B_OK;
}
+35 -69
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
PCWindow.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,95 +15,65 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCWorld.h" #include "PCWorld.h"
#include "PCWindow.h" #include "PCWindow.h"
#include "PCView.h"
#include "Preferences.h" #include "Preferences.h"
#include "PCUtils.h" #include "ProcessController.h"
#include <StringView.h> #include "Utilities.h"
#include <Dragger.h>
#include <Deskbar.h>
#include <Alert.h> #include <Alert.h>
#include <Application.h>
#include <Deskbar.h>
#include <Dragger.h>
#include <Roster.h> #include <Roster.h>
#include <StringView.h>
const char* kPosPrefName = "Position";
const char* kVersionName = "Version";
const int kCurrentVersion = 310;
PCWindow::PCWindow():BWindow(BRect(100, 150, 590, 175), "ProcessController", B_TITLED_WINDOW, B_NOT_ZOOMABLE+B_NOT_RESIZABLE, 0) PCWindow::PCWindow()
: BWindow(BRect(100, 150, 131, 181), "ProcessController", B_TITLED_WINDOW,
B_NOT_H_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
{ {
BView *topview; GebsPreferences preferences(kPreferencesFileName);
BStringView *manuel; preferences.SaveInt32(kCurrentVersion, kVersionName);
BRect rect; preferences.LoadWindowPosition(this, kPosPrefName);
GebsPreferences tPreferences(kPreferencesFileName); SetSizeLimits(Bounds().Width(), Bounds().Width(), 31, 32767);
int32 version = 0; BRect rect = Bounds();
tPreferences.ReadInt32 (version, kVersionName);
if (version != kCurrentVersion) BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
{ topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BAlert* alert = new BAlert("", "Do you want ProcessController to live in the Deskbar?", AddChild(topView);
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetShortcut(0, B_ESCAPE);
if (alert->Go())
{
team_id deskbar = be_roster->TeamFor (kDeskbarSig);
if (deskbar >= 0)
{
BMessenger messenger (NULL, deskbar);
messenger.SendMessage (B_QUIT_REQUESTED);
int k = 500;
do {
snooze (10000);
} while (be_roster->IsRunning (kDeskbarSig) && k-- > 0);
}
be_roster->Launch (kDeskbarSig);
int k = 500;
do {
snooze (10000);
} while (!be_roster->IsRunning (kDeskbarSig) && k-- > 0);
BDeskbar db;
if (!db.HasItem (kDeskbarItemName))
move_to_deskbar (db);
}
}
tPreferences.SaveInt32 (kCurrentVersion, kVersionName);
tPreferences.LoadWindowPosition(this, kPosPrefName);
rect = Bounds();
AddChild(topview = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW));
topview->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rect.left = 28;
rect.top = 9;
rect.bottom = rect.top+16;
manuel = new BStringView(rect, NULL, "Drag this Replicant out of here, or click on it, and ask it to \"Live in the Deskbar\"");
topview->AddChild(manuel);
manuel->SetFont(be_bold_font);
// set up a rectangle && instantiate a new view // set up a rectangle && instantiate a new view
// view rect should be same size as window rect but with left top at (0, 0) // view rect should be same size as window rect but with left top at (0, 0)
rect.Set(0, 0, 15, 15); rect.Set(0, 0, 15, 15);
rect.OffsetTo(8, 9); rect.OffsetTo((Bounds().Width() - 16) / 2, (Bounds().Height() - 16) / 2);
topview->AddChild(new ProcessController(rect)); topView->AddChild(new ProcessController(rect));
// make window visible // make window visible
Show(); Show();
wasShowing = BDragger::AreDraggersDrawn (); fDraggersAreDrawn = BDragger::AreDraggersDrawn();
BDragger::ShowAllDraggers (); BDragger::ShowAllDraggers();
} }
PCWindow::~PCWindow ()
PCWindow::~PCWindow()
{ {
if (!wasShowing) if (!fDraggersAreDrawn)
BDragger::HideAllDraggers (); BDragger::HideAllDraggers();
} }
bool PCWindow::QuitRequested()
bool
PCWindow::QuitRequested()
{ {
GebsPreferences tPreferences(kPreferencesFileName); GebsPreferences tPreferences(kPreferencesFileName);
tPreferences.SaveWindowPosition(this, kPosPrefName); tPreferences.SaveWindowPosition(this, kPosPrefName);
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }
+9 -13
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
PCWindow.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,23 +15,23 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _PCWINDOW_H_ #ifndef _PCWINDOW_H_
#define _PCWINDOW_H_ #define _PCWINDOW_H_
#include <Window.h> #include <Window.h>
class PCWindow : public BWindow { class PCWindow : public BWindow {
public:
PCWindow();
~PCWindow();
public: virtual bool QuitRequested();
PCWindow();
~PCWindow();
virtual bool QuitRequested();
private: private:
bool wasShowing; bool fDraggersAreDrawn;
}; };
#endif // _PCWINDOW_H_ #endif // _PCWINDOW_H_
+67 -7
View File
@@ -22,21 +22,38 @@
#include "PCWorld.h" #include "PCWorld.h"
#include "PCWindow.h" #include "PCWindow.h"
#include "PCView.h" #include "Preferences.h"
#include "PCUtils.h" #include "ProcessController.h"
#include "Utilities.h"
#include <Roster.h> #include <Alert.h>
#include <Application.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <Roster.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
class PCApplication : public BApplication {
public:
PCApplication();
virtual ~PCApplication();
virtual void ReadyToRun();
virtual void ArgvReceived(int32 argc, char **argv);
};
const char* kSignature = "application/x-vnd.Geb-ProcessController"; const char* kSignature = "application/x-vnd.Geb-ProcessController";
const char* kTrackerSig = "application/x-vnd.Be-TRAK"; const char* kTrackerSig = "application/x-vnd.Be-TRAK";
const char* kDeskbarSig = "application/x-vnd.Be-TSKB"; const char* kDeskbarSig = "application/x-vnd.Be-TSKB";
const char* kTerminalSig = "application/x-vnd.Haiku-Terminal"; const char* kTerminalSig = "application/x-vnd.Haiku-Terminal";
const char* kPreferencesFileName = "ProcessController Prefs"; const char* kPreferencesFileName = "ProcessController Prefs";
const char* kPosPrefName = "Position";
const char* kVersionName = "Version";
const int kCurrentVersion = 311;
thread_id id = 0; thread_id id = 0;
@@ -59,8 +76,51 @@ PCApplication::~PCApplication()
void void
PCApplication::ReadyToRun() PCApplication::ReadyToRun()
{ {
GebsPreferences preferences(kPreferencesFileName);
int32 version = 0;
preferences.ReadInt32(version, kVersionName);
if (version != kCurrentVersion) {
BAlert* alert = new BAlert("", "Do you want ProcessController to live in the Deskbar?",
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetShortcut(0, B_ESCAPE);
if (alert->Go()) {
bool hasOne = false;
{
BDeskbar deskbar;
if (deskbar.HasItem(kDeskbarItemName))
hasOne = true;
}
if (hasOne) {
// Restart deskbar to make sure the new version is picked up
team_id deskbarTeam = be_roster->TeamFor(kDeskbarSig);
if (deskbarTeam >= 0) {
BMessenger messenger(NULL, deskbarTeam);
messenger.SendMessage(B_QUIT_REQUESTED);
int k = 500;
do {
snooze (10000);
} while (be_roster->IsRunning(kDeskbarSig) && k-- > 0);
}
be_roster->Launch(kDeskbarSig);
int k = 500;
do {
snooze (10000);
} while (!be_roster->IsRunning(kDeskbarSig) && k-- > 0);
}
BDeskbar deskbar;
if (!deskbar.HasItem(kDeskbarItemName))
move_to_deskbar(deskbar);
Quit();
return;
}
}
new PCWindow(); new PCWindow();
// quit other eventually running instances // quit other eventually running instances
BList list; BList list;
be_roster->GetAppList(kSignature, &list); be_roster->GetAppList(kSignature, &list);
@@ -77,7 +137,7 @@ PCApplication::ReadyToRun()
void void
PCApplication::ArgvReceived (int32 argc, char **argv) PCApplication::ArgvReceived(int32 argc, char **argv)
{ {
if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) { if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) {
team_id tracker = be_roster->TeamFor(kTrackerSig); team_id tracker = be_roster->TeamFor(kTrackerSig);
@@ -97,8 +157,8 @@ PCApplication::ArgvReceived (int32 argc, char **argv)
move_to_deskbar(deskbar); move_to_deskbar(deskbar);
} else if (argc > 1) { } else if (argc > 1) {
// print a simple usage string // print a simple usage string
printf( "Usage: %s [-deskbar]\n", argv[0]); printf("Usage: %s [-deskbar]\n", argv[0]);
printf( "(c) 1997-2001 Georges-Edouard Berenger, [email protected]\n"); printf("(c) 1996-2001 Georges-Edouard Berenger, [email protected]\n");
} }
Quit(); Quit();
+19 -27
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
PCWorld.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,38 +15,34 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _PCWORLD_H_ #ifndef _PCWORLD_H_
#define _PCWORLD_H_ #define _PCWORLD_H_
#include <Application.h>
extern const char *kSignature; #include <OS.h>
extern const char *kTrackerSig;
extern const char *kDeskbarSig;
extern const char *kTerminalSig;
extern const char *kPosPrefName;
extern const char *kPreferencesFileName;
class PCApplication : public BApplication { extern const char* kSignature;
extern const char* kTrackerSig;
extern const char* kDeskbarSig;
extern const char* kTerminalSig;
public: extern const char* kPosPrefName;
PCApplication(); extern const char* kPreferencesFileName;
~PCApplication();
virtual void ReadyToRun();
virtual void ArgvReceived(int32 argc, char **argv);
};
extern const uchar k_app_mini[]; extern const char* kPosPrefName;
extern const char* kProgramName; extern const char* kVersionName;
extern const char* kPCSemaphoreName; extern const int kCurrentVersion;
extern thread_id id;
extern "C" int _kget_cpu_state_ (int cpu); extern const uchar k_app_mini[];
extern "C" int _kset_cpu_state_ (int cpu, int enabled); extern const char* kProgramName;
extern const char* kPCSemaphoreName;
extern thread_id id;
extern "C" int _kget_cpu_state_(int cpu);
extern "C" int _kset_cpu_state_(int cpu, int enabled);
#endif // _PCWORLD_H_ #endif // _PCWORLD_H_
+150 -120
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Preferences.cpp
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,187 +15,209 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "Preferences.h" #include "Preferences.h"
#include "Locker.h" #include "Utilities.h"
#include "WindowsTools.h"
#include <Path.h> #include <Alert.h>
#include <string.h>
#include <stdlib.h>
#include <FindDirectory.h>
#include <Directory.h> #include <Directory.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h>
#include <Locker.h>
#include <Mime.h> #include <Mime.h>
#include <Alert.h> #include <Path.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* kDirectory = "Geb";
GebsPreferences::GebsPreferences(const char* thename, const char* thesignature, bool doSave) : BMessage('Pref'), BLocker("Preferences", true), fSavePreferences(doSave) GebsPreferences::GebsPreferences(const char* name, const char* signature, bool doSave)
: BMessage('Pref'), BLocker("Preferences", true),
fSavePreferences(doSave)
{ {
fNewPreferences = false; fNewPreferences = false;
fSettingsFile = 0; fSettingsFile = 0;
BPath prefpath; BPath prefpath;
fName=strdup(thename); fName = strdup(name);
if (thesignature) if (signature)
fSignature=strdup(thesignature); fSignature = strdup(signature);
else else
fSignature=NULL; fSignature = NULL;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath)==B_OK) {
BDirectory prefdir(prefpath.Path()); if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) {
BEntry entry; BDirectory prefdir(prefpath.Path());
prefdir.FindEntry(kDirectory, &entry, true); BEntry entry;
prefdir.SetTo(&entry);
prefdir.FindEntry(fName, &entry); prefdir.FindEntry(fName, &entry);
BFile file(&entry, B_READ_ONLY);
if (file.InitCheck()==B_OK) BFile file(&entry, B_READ_ONLY);
if (file.InitCheck() == B_OK)
Unflatten(&file); Unflatten(&file);
else else
fNewPreferences=true; fNewPreferences = true;
} }
} }
GebsPreferences::GebsPreferences(const entry_ref &ref, const char* thesignature, bool doSave)
: BMessage('Pref'), BLocker("Preferences", true), fSavePreferences (doSave) GebsPreferences::GebsPreferences(const entry_ref &ref, const char* signature, bool doSave)
: BMessage('Pref'), BLocker("Preferences", true),
fSavePreferences(doSave)
{ {
fSettingsFile = new entry_ref (ref); fSettingsFile = new entry_ref(ref);
fNewPreferences = false; fNewPreferences = false;
BPath prefpath; BPath prefpath;
fName = 0; fName = NULL;
if (thesignature) if (signature)
fSignature = strdup(thesignature); fSignature = strdup(signature);
else else
fSignature = NULL; fSignature = NULL;
BFile file (fSettingsFile, B_READ_ONLY);
BFile file(fSettingsFile, B_READ_ONLY);
if (file.InitCheck() == B_OK) if (file.InitCheck() == B_OK)
Unflatten(&file); Unflatten(&file);
else else
fNewPreferences = true; fNewPreferences = true;
} }
GebsPreferences::~GebsPreferences() GebsPreferences::~GebsPreferences()
{ {
if (fSavePreferences) { if (fSavePreferences) {
BFile file; BFile file;
status_t set = B_ERROR; status_t set = B_ERROR;
if (fSettingsFile) if (fSettingsFile)
file.SetTo (fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); file.SetTo (fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
else else {
{ BPath prefpath;
BPath prefpath; if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true) == B_OK) {
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true)==B_OK) { BDirectory prefdir(prefpath.Path());
BDirectory prefdir(prefpath.Path()); set = prefdir.CreateFile(fName, &file, false);
BDirectory gebprefdir;
BEntry entry;
if (prefdir.FindEntry(kDirectory, &entry, true)==B_OK)
gebprefdir.SetTo(&entry);
else
prefdir.CreateDirectory (kDirectory, &gebprefdir);
if (gebprefdir.InitCheck () == B_OK)
set = gebprefdir.CreateFile (fName, &file, false);
} }
} }
if (file.InitCheck () == B_OK)
{ if (file.InitCheck () == B_OK) {
Flatten (&file); Flatten(&file);
if (fSignature) if (fSignature) {
file.WriteAttr ("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature, strlen(fSignature)+1); file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature,
} strlen(fSignature)+1);
else }
{ } else {
// implement saving somewhere else! // implement saving somewhere else!
char error[1024]; char error[1024];
sprintf (error, "Your setting file could not be saved!\n(%s)", strerror (file.InitCheck ())); sprintf(error, "Your setting file could not be saved!\n(%s)",
strerror(file.InitCheck()));
BAlert *alert = new BAlert("Error saving file", error, BAlert *alert = new BAlert("Error saving file", error,
"Damned!", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); "Damned!", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go(); alert->Go();
} }
} }
free (fName); free(fName);
if (fSignature) free(fSignature);
free (fSignature);
} }
status_t GebsPreferences::MakeEmpty()
status_t
GebsPreferences::MakeEmpty()
{ {
status_t st;
Lock(); Lock();
st=BMessage::MakeEmpty(); status_t status = BMessage::MakeEmpty();
Unlock(); Unlock();
return st; return status;
} }
void GebsPreferences::SaveWindowPosition(BWindow* window, const char* name)
void
GebsPreferences::SaveWindowPosition(BWindow* window, const char* name)
{ {
BRect rect=window->Frame();
Lock(); Lock();
BRect rect = window->Frame();
if (HasPoint(name)) if (HasPoint(name))
ReplacePoint(name, rect.LeftTop()); ReplacePoint(name, rect.LeftTop());
else else
AddPoint(name, rect.LeftTop()); AddPoint(name, rect.LeftTop());
Unlock(); Unlock();
} }
void GebsPreferences::LoadWindowPosition(BWindow* window, const char* name)
void
GebsPreferences::LoadWindowPosition(BWindow* window, const char* name)
{ {
BPoint p;
Lock(); Lock();
if (FindPoint(name, &p)==B_OK) {
BPoint p;
if (FindPoint(name, &p) == B_OK) {
window->MoveTo(p); window->MoveTo(p);
visible_window(window); make_window_visible(window);
} }
Unlock(); Unlock();
} }
void GebsPreferences::SaveWindowFrame(BWindow* window, const char* name)
void
GebsPreferences::SaveWindowFrame(BWindow* window, const char* name)
{ {
BRect rect=window->Frame();
Lock(); Lock();
BRect rect = window->Frame();
if (HasRect(name)) if (HasRect(name))
ReplaceRect(name, rect); ReplaceRect(name, rect);
else else
AddRect(name, rect); AddRect(name, rect);
Unlock(); Unlock();
} }
void GebsPreferences::LoadWindowFrame(BWindow* window, const char* name)
void
GebsPreferences::LoadWindowFrame(BWindow* window, const char* name)
{ {
BRect f;
Lock(); Lock();
if (FindRect(name, &f)==B_OK) {
window->MoveTo(f.LeftTop()); BRect frame;
window->ResizeTo(f.Width(), f.Height()); if (FindRect(name, &frame) == B_OK) {
visible_window(window); window->MoveTo(frame.LeftTop());
window->ResizeTo(frame.Width(), frame.Height());
make_window_visible(window);
} }
Unlock(); Unlock();
} }
void GebsPreferences::SaveInt32(int32 val, const char* name)
void
GebsPreferences::SaveInt32(int32 value, const char* name)
{ {
Lock(); Lock();
if (HasInt32(name)) if (HasInt32(name))
ReplaceInt32(name, val); ReplaceInt32(name, value);
else else
AddInt32(name, val); AddInt32(name, value);
Unlock(); Unlock();
} }
bool GebsPreferences::ReadInt32(int32 &val, const char* name)
bool
GebsPreferences::ReadInt32(int32 &val, const char* name)
{ {
Lock(); Lock();
int32 readVal; int32 readVal;
bool found=FindInt32(name, &readVal)==B_OK; bool found = FindInt32(name, &readVal) == B_OK;
if (found) if (found)
val=readVal; val = readVal;
Unlock(); Unlock();
return found; return found;
} }
void GebsPreferences::SaveFloat(float val, const char* name)
void
GebsPreferences::SaveFloat(float val, const char* name)
{ {
Lock(); Lock();
if (HasFloat(name)) if (HasFloat(name))
@@ -209,18 +227,22 @@ void GebsPreferences::SaveFloat(float val, const char* name)
Unlock(); Unlock();
} }
bool GebsPreferences::ReadFloat(float &val, const char* name)
bool
GebsPreferences::ReadFloat(float &val, const char* name)
{ {
Lock(); Lock();
float readVal; float readVal;
bool found=FindFloat(name, &readVal)==B_OK; bool found = FindFloat(name, &readVal)==B_OK;
if (found) if (found)
val=readVal; val = readVal;
Unlock(); Unlock();
return found; return found;
} }
void GebsPreferences::SaveRect(BRect &rect, const char* name)
void
GebsPreferences::SaveRect(BRect &rect, const char* name)
{ {
Lock(); Lock();
if (HasRect(name)) if (HasRect(name))
@@ -230,40 +252,48 @@ void GebsPreferences::SaveRect(BRect &rect, const char* name)
Unlock(); Unlock();
} }
BRect & GebsPreferences::ReadRect(BRect &rect, const char* name)
BRect &
GebsPreferences::ReadRect(BRect &rect, const char* name)
{ {
Lock(); Lock();
BRect loaded; BRect loaded;
if (FindRect(name, &loaded)==B_OK) if (FindRect(name, &loaded)==B_OK)
rect=loaded; rect = loaded;
Unlock(); Unlock();
return rect; return rect;
} }
void GebsPreferences::SaveString (BString &string, const char* name)
{
Lock ();
if (HasString (name))
ReplaceString (name, string);
else
AddString (name, string);
Unlock ();
}
void GebsPreferences::SaveString (const char* string, const char* name) void
{ GebsPreferences::SaveString(BString &string, const char* name)
Lock ();
if (HasString (name))
ReplaceString (name, string);
else
AddString (name, string);
Unlock ();
}
bool GebsPreferences::ReadString (BString &string, const char* name)
{ {
Lock(); Lock();
bool loaded = FindString (name, &string) == B_OK; if (HasString(name))
ReplaceString(name, string);
else
AddString(name, string);
Unlock();
}
void
GebsPreferences::SaveString(const char* string, const char* name)
{
Lock();
if (HasString(name))
ReplaceString(name, string);
else
AddString(name, string);
Unlock();
}
bool
GebsPreferences::ReadString(BString &string, const char* name)
{
Lock();
bool loaded = FindString(name, &string) == B_OK;
Unlock(); Unlock();
return loaded; return loaded;
} }
-698
View File
@@ -1,698 +0,0 @@
/*
PrintMessage.cpp
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "PrintMessage.h"
#include "ReadableLong.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <AppFileInfo.h>
#include <Path.h>
#include <SymLink.h>
#include <fs_attr.h>
#include <Application.h>
#include <Resources.h>
#include <PropertyInfo.h>
#include <Roster.h>
int32 gHexalinesPref=9;
void do_print_message(pchar & texte, BMessage* message);
void print_type(pchar & texte, ulong type, void* pvoid, ssize_t size);
void tab_to(pchar & texte, int n);
void print_hex(pchar & texte, void* pvoid, ssize_t size, int extra_space);
void ajoute(pchar & texte, const char* mot, long length=0);
inline void ajoute(pchar & texte, const char c) { *texte++=c; }
const char* specifiers[] = {
"B_NO_SPECIFIER",
"B_DIRECT_SPECIFIER",
"B_INDEX_SPECIFIER",
"B_REVERSE_INDEX_SPECIFIER",
"B_RANGE_SPECIFIER",
"B_REVERSE_RANGE_SPECIFIER",
"B_NAME_SPECIFIER",
"B_ID_SPECIFIER",
NULL };
const int kTabType=22;
const int kTabName=25;
const int kTabNum=12;
const char* indent1=" | ";
const char* indent2=" > ";
const char* indent3=" \" ";
const int maxprefix=1000;
char gPrefix[maxprefix];
void print_message(pchar & texte, BMessage* message, bool dig)
{
gPrefix[0]=0;
if (dig) {
#if B_BEOS_VERSION > B_BEOS_VERSION_5
const char* name;
#else
char * name;
#endif
ulong type;
off_t size;
long m;
long count, k;
entry_ref ref;
bool found=false;
for (k=0; message->GetInfo(B_REF_TYPE, k, &name, &type, &count)==B_OK; k++)
for (m=0; m<count; m++)
if (message->FindRef(name, m, &ref)==B_OK) {
BEntry entry(&ref, true);
if (entry.InitCheck()==B_OK && entry.IsFile()) {
found=true;
ajoute(texte, "File");
BPath path;
entry.GetPath(&path);
texte+=sprintf(texte, ": %s\n", path.Path());
entry.GetSize(&size);
if (size==0)
ajoute(texte, " Empty file.\n");
else {
BFile file(&entry, B_READ_ONLY);
BResources rsrc;
if (rsrc.SetTo(&file)==B_OK) {
ajoute(texte, " Resource file:\n");
// file has resource file
int32 index=0;
type_code typeFound;
int32 idFound;
const char* nameFound;
size_t lengthFound;
while (rsrc.GetResourceInfo(index++, &typeFound, &idFound, &nameFound, &lengthFound)) {
void* resource=rsrc.FindResource(typeFound, idFound, &lengthFound);
if (resource) {
texte+=sprintf(texte, " %d", int(idFound));
tab_to(texte, 5);
ajoute(texte, long_to_be_string(typeFound));
tab_to(texte, 1+kTabType);
texte+=sprintf(texte, "\"%s\"", nameFound);
tab_to(texte, 1+kTabType+kTabName);
strcpy(gPrefix, " ");
print_type(texte, typeFound, resource, lengthFound);
free(resource);
} else
texte+=sprintf(texte, "Could not read resource of type %s with id=%d\n", long_to_be_string(typeFound), int(idFound));
}
} else {
char* content=new char[size];
if (file.Read(content, size)==size) {
BMessage inmessage;
strcpy(gPrefix, " > ");
if (inmessage.Unflatten(content)==B_OK) {
ajoute(texte, " BMessage file:\n");
do_print_message(texte, &inmessage);
} else {
ajoute(texte, " Not a BMessage, not a resource file.\n");
print_hex(texte, content, size, 0);
//print_type(texte, B_RAW_TYPE, content, size);
}
} else
ajoute(texte, " The file's content could not be read.\n");
delete[] content;
}
}
}
}
if (!found)
ajoute(texte, "(No file referenced in the BMessage)");
} else
do_print_message(texte, message);
*texte=0;
}
void do_print_message(pchar & texte, BMessage* message)
{
#if B_BEOS_VERSION > B_BEOS_VERSION_5
const char* name;
#else
char * name;
#endif
ulong type;
void* data;
ssize_t size;
long m;
long count, k;
int lPrefix=strlen(gPrefix);
ajoute(texte, gPrefix);
ajoute(texte, "What=");
ajoute(texte, long_to_be_string(message->what));
ajoute(texte, "\n");
for (k=0; message->GetInfo(B_ANY_TYPE, k, &name, &type, &count)==B_OK; k++) {
for (m=0; m<count; m++) {
if (message->FindData(name, type, m, (const void**) &data, &size)==B_OK) {
ajoute(texte, gPrefix);
ajoute(texte, long_to_be_string(type));
tab_to(texte, lPrefix+kTabType);
if (count>1)
texte+=sprintf(texte, "\"%s\" #%d", name, (int) m+1);
else
texte+=sprintf(texte, "\"%s\"", name);
tab_to(texte, lPrefix+kTabType+kTabName);
if (type==B_REF_TYPE) {
entry_ref ref;
message->FindRef(name, m, &ref);
print_type(texte, type, &ref, sizeof(ref));
} else if (type==B_MESSENGER_TYPE) {
BMessenger messenger;
message->FindMessenger(name, m, &messenger);
print_type(texte, type, &messenger, sizeof(messenger));
} else
print_type(texte, type, data, size);
} else
texte+=sprintf(texte, "%sError retreiving data.\n", gPrefix);
}
}
}
void print_type(pchar & texte, ulong type, void* pvoid, ssize_t size)
{
union Data {
char c;
double d;
float f;
int8 i8;
uint8 ui8;
int16 i16;
uint16 ui16;
int32 i32;
uint32 ui32;
int64 i64;
uint64 ui64;
time_t time;
rgb_color rgb;
version_info vinfos;
};
Data* data=(Data*) pvoid;
char* txtdata=(char*) pvoid;
BMessage local;
bool cr=true;
int lPrefix=strlen(gPrefix);
int max=maxprefix-lPrefix-1;
long_to_be_string(type);
switch (type) {
case B_BOOL_TYPE:
ajoute(texte, '0'+data->c);
break;
case B_CHAR_TYPE:
ajoute(texte, data->c);
break;
case B_DOUBLE_TYPE:
texte+=sprintf(texte, "%f", data->d);
break;
case B_FLOAT_TYPE:
texte+=sprintf(texte, "%f", data->f);
break;
case B_UINT8_TYPE:
texte+=sprintf(texte, "%u (0x%.2hX)", data->ui8, data->ui8);
break;
case B_INT8_TYPE:
texte+=sprintf(texte, "%d (0x%.2hX)", data->i8, data->ui8);
break;
case B_INT16_TYPE:
texte+=sprintf(texte, "%hd (0x%.4hX)", data->i16, data->i16);
break;
case B_UINT16_TYPE:
texte+=sprintf(texte, "%hu (0x%.4hX)", data->ui16, data->ui16);
break;
case B_INT32_TYPE:
case B_SSIZE_T_TYPE:
texte+=sprintf(texte, "%ld (%s", data->i32, long_to_be_string(data->ui32));
if (data->i32<=B_ERRORS_END)
texte+=sprintf(texte, " %s", strerror(data->i32));
ajoute(texte, ')');
break;
case B_UINT32_TYPE:
case B_SIZE_T_TYPE:
texte+=sprintf(texte, "%lu (%s)", data->ui32, long_to_be_string(data->ui32));
break;
case B_INT64_TYPE:
case B_OFF_T_TYPE:
texte+=sprintf(texte, "%Ld (0x%.16LX)", data->i64, data->i64);
break;
case B_UINT64_TYPE:
texte+=sprintf(texte, "%Lu (0x%.16LX)", data->ui64, data->ui64);
break;
case B_ASCII_TYPE:
case B_STRING_TYPE:
case B_MIME_TYPE:
case B_MIME_STRING_TYPE:
case 'MSIG':
{
long tt=0;
while (txtdata[tt]!=0 && txtdata[tt]!='\n')
tt++;
if (txtdata[tt]!=0) {
ajoute(texte, "Multiline texte follows:\n");
ajoute(texte, gPrefix);
ajoute(texte, indent3);
tt=0;
while (txtdata[tt]!=0 && tt<size) {
ajoute(texte, txtdata[tt]);
if (txtdata[tt++]=='\n') {
ajoute(texte, gPrefix);
ajoute(texte, indent3);
}
}
} else {
ajoute(texte, '"');
tt=0;
while (txtdata[tt]!=0 && tt<size)
ajoute(texte, txtdata[tt++]);
ajoute(texte, '"');
}
}
break;
case B_POINTER_TYPE:
texte+=sprintf(texte, "%p", pvoid);
break;
case B_POINT_TYPE:
{
BPoint *point=(BPoint*) pvoid;
texte+=sprintf(texte, "x=%.2f", point->x);
tab_to(texte, lPrefix+kTabType+kTabName+kTabNum);
texte+=sprintf(texte, "y=%.2f", point->y);
}
break;
case B_RECT_TYPE:
{
BRect *rect=(BRect*) pvoid;
texte+=sprintf(texte, "l=%.2f", rect->left);
tab_to(texte, lPrefix+kTabType+kTabName+kTabNum);
texte+=sprintf(texte, "t=%.2f", rect->top);
tab_to(texte, lPrefix+kTabType+kTabName+2*kTabNum);
texte+=sprintf(texte, "r=%.2f", rect->right);
tab_to(texte, lPrefix+kTabType+kTabName+3*kTabNum);
texte+=sprintf(texte, "b=%.2f", rect->bottom);
}
break;
case B_REF_TYPE:
{
entry_ref *ref=(entry_ref*) pvoid;
off_t size;
texte+=sprintf(texte, "\n%s ", gPrefix);
BEntry entry(ref, false);
if (entry.InitCheck()==B_OK) {
if (entry.IsFile())
ajoute(texte, "File");
else if (entry.IsDirectory())
ajoute(texte, "Directory");
else if (entry.IsSymLink())
ajoute(texte, "Link");
else ajoute(texte, "The entry points to an unexisting object");
BPath path;
entry.GetPath(&path);
texte+=sprintf(texte, ": %s\n", path.Path());
BNode node(&entry);
if (entry.IsSymLink()) {
texte+=sprintf(texte, "%s ", gPrefix);
BEntry target(ref, true);
if (target.GetPath(&path)==B_OK)
texte+=sprintf(texte, "Valid target: ");
else
texte+=sprintf(texte, "Invalid target: ");
char linkto[B_PATH_NAME_LENGTH+1];
BSymLink link(ref);
if (link.InitCheck()==B_OK) {
linkto[link.ReadLink(linkto, B_PATH_NAME_LENGTH)]=0;
texte+=sprintf(texte, "%s\n", linkto);
} else
ajoute(texte, "Unreadable link.\n");
} else if (entry.IsFile()) {
node.GetSize(&size);
texte+=sprintf(texte, "%s Size: %Ld byte", gPrefix, size);
if (size!=1)
ajoute(texte, 's');
ajoute(texte, ".\n");
}
char attribute[B_ATTR_NAME_LENGTH];
cr=false;
strncat(gPrefix, indent2, max);
while (node.GetNextAttrName(attribute)==B_OK) {
attr_info infos;
size_t length;
node.GetAttrInfo(attribute, &infos);
ajoute(texte, gPrefix);
ajoute(texte, long_to_be_string(infos.type));
tab_to(texte, strlen(gPrefix)+kTabType);
texte+=sprintf(texte, "\"%s\"", attribute);
tab_to(texte, strlen(gPrefix)+kTabType+kTabName);
char* buffeur=new char[infos.size+1];
length=node.ReadAttr(attribute, infos.type, 0, buffeur, infos.size);
if (length==infos.size) {
buffeur[length]=0;
print_type(texte, infos.type, buffeur, infos.size);
} else
texte+=sprintf(texte, "[attribute not read properly (%s)]\n", strerror(length));
delete[] buffeur;
}
gPrefix[lPrefix]=0;
} else
ajoute(texte, "Bad ref.");
}
break;
case B_MESSAGE_TYPE:
if (local.Unflatten(txtdata)==B_OK) {
ajoute(texte, '\n');
strncat(gPrefix, indent1, max);
do_print_message(texte, &local);
gPrefix[lPrefix]=0;
cr=false;
} else
ajoute(texte, "[invalid message]");
break;
case B_TIME_TYPE:
{
char* t=ctime(&data->time);
if (t) {
ajoute(texte, t);
cr=false;
}
}
break;
case B_RGB_32_BIT_TYPE:
case B_RGB_COLOR_TYPE:
texte+=sprintf(texte, "r=%u", data->rgb.red);
tab_to(texte, lPrefix+kTabType+kTabName+kTabNum);
texte+=sprintf(texte, "g=%u", data->rgb.green);
tab_to(texte, lPrefix+kTabType+kTabName+2*kTabNum);
texte+=sprintf(texte, "b=%u", data->rgb.blue);
tab_to(texte, lPrefix+kTabType+kTabName+3*kTabNum);
texte+=sprintf(texte, "a=%u", data->rgb.alpha);
break;
case B_PROPERTY_INFO_TYPE:
{
BPropertyInfo pinfo;
if (pinfo.Unflatten(B_PROPERTY_INFO_TYPE, pvoid, size)==B_OK) {
const property_info *infos=pinfo.Properties();
if (infos) {
int k=0;
int count=pinfo.CountProperties();
while (count-->0) {
texte+=sprintf(texte, "\n%s Name[%d]=%s\n%s ", gPrefix, k+1, infos[k].name, gPrefix);
int j=0;
do {
ajoute(texte, ' ');
if (infos[k].commands[j]==0)
ajoute(texte, "All possible commands.");
else
ajoute(texte, long_to_be_string(infos[k].commands[j]));
} while (j<9 && infos[k].commands[j]!=0 && infos[k].commands[++j]!=0);
texte+=sprintf(texte, "\n%s ", gPrefix);
j=0;
do {
if (infos[k].specifiers[j]==0)
ajoute(texte, " All possible specifiers.");
else {
ajoute(texte, ' ');
uint32 s=0;
while (specifiers[s]!=NULL && s!=infos[k].specifiers[j])
s++;
if (specifiers[s])
ajoute(texte, specifiers[s]);
else
texte+=sprintf(texte, "%d", (int) infos[k].specifiers[j]);
}
} while (j<9 && infos[k].specifiers[j]!=0 && infos[k].specifiers[++j]!=0);
if (infos[k].usage) {
texte+=sprintf(texte, "\n%s Usage=", gPrefix);
if (infos[k].usage)
ajoute(texte, infos[k].usage);
}
if (infos[k].extra_data)
texte+=sprintf(texte, "\n%s Extra Data: %lu", gPrefix, infos[k].extra_data);
k++;
}
} else
ajoute(texte, "Empty.");
} else
ajoute(texte, "Invalid.");
}
break;
case 'APPV':
{
struct version_info *vinfos=(struct version_info*) pvoid;
const char* variety[]= { "Development", "Alpha", "Beta", "Gamma", "Golden Master", "Final" };
for (int32 v=0; (unsigned)size>=sizeof(version_info); size-=sizeof(version_info), v++, vinfos++) {
texte+=sprintf(texte, "\n%s%s", gPrefix, indent1);
if (v==B_APP_VERSION_KIND)
ajoute(texte, "Application");
else if (v==B_SYSTEM_VERSION_KIND)
ajoute(texte, "System");
else
ajoute(texte, "Extra");
texte+=sprintf(texte, " Version: %lu.%lu.%lu ", vinfos->major, vinfos->middle, vinfos->minor);
if (vinfos->variety<6)
ajoute(texte, variety[vinfos->variety]);
else
texte+=sprintf(texte, "Unknown Variety (%lu)", vinfos->variety);
texte+=sprintf(texte, " #%lu", vinfos->internal);
vinfos->short_info[63]=0;
texte+=sprintf(texte, "\n%s%s Short Info: %s", gPrefix, indent1, vinfos->short_info);
vinfos->long_info[255]=0;
texte+=sprintf(texte, "\n%s%s Long Info: %s", gPrefix, indent1, vinfos->long_info);
}
if (size>0)
texte+=sprintf(texte, "\n%s with %lu extra byte(s)", gPrefix, size);
}
break;
case B_MESSENGER_TYPE:
{
BMessenger *messenger=(BMessenger*) pvoid;
if (!messenger->IsValid())
ajoute(texte, "Invalid Messenger");
else {
if (messenger->IsTargetLocal()) {
BLooper *looper;
BHandler *handler=messenger->Target(&looper);
if (!handler) {
team_info tminfo;
texte+=sprintf(texte, "\n%s%sLooper: ", gPrefix, indent1);
if (get_team_info(looper->Team(), &tminfo)==B_OK)
texte+=sprintf(texte, "\n%s%s Team #%d", gPrefix, indent1, (int) looper->Team());
else
texte+=sprintf(texte, "\n%s%s Team #%d (not found)", gPrefix, indent1, (int) looper->Team());
thread_info thinfo;
if (get_thread_info(looper->Thread(), &thinfo)==B_OK)
texte+=sprintf(texte, "\n%s%s Thread #%d %s", gPrefix, indent1, (int) looper->Thread(), thinfo.name);
else
texte+=sprintf(texte, "\n%s%s Thread #%d (not found)", gPrefix, indent1, (int) looper->Thread());
handler=looper;
}
texte+=sprintf(texte, "\n%s%sHandler: %s", gPrefix, indent1, handler->Name());
} else {
app_info info;
ajoute(texte, "Remote Looper:");
if (be_roster->GetRunningAppInfo(messenger->Team(), &info)==B_OK) {
BEntry entry(&info.ref);
char appname[B_FILE_NAME_LENGTH];
entry.GetName(appname);
texte+=sprintf(texte, " Team #%d \"%s\" (%s)", (int) messenger->Team(), appname, info.signature);
} else
texte+=sprintf(texte, " Team #%d (team not found)", (int) messenger->Team());
}
}
}
break;
case 'ICON':
case 'MICN':
texte+=sprintf(texte, "[%d bytes of icon]", (int) size);
break;
case B_ANY_TYPE:
case B_COLOR_8_BIT_TYPE:
case B_GRAYSCALE_8_BIT_TYPE:
case B_MONOCHROME_1_BIT_TYPE:
case B_OBJECT_TYPE:
case B_PATTERN_TYPE:
case B_RAW_TYPE:
default:
// if (size==1)
// ajoute(texte, "[Unsupported (one byte)]");
// else
// texte+=sprintf(texte, "[Unsupported (%d bytes)]", size);
// Type is not known. Try to interpret it as an archived object...
BMessage archive;
if (archive.Unflatten(txtdata)==B_OK) {
ajoute(texte, "Is an archived object in a BMessage\n");
strncat(gPrefix, indent2, max);
do_print_message(texte, &archive);
gPrefix[lPrefix]=0;
cr=false;
} else {
print_hex(texte, pvoid, size, kTabType+kTabName);
// int32 *pint=(int32 *) pvoid;
// long done=0;
// int tab=lPrefix+kTabType+kTabName;
// while (done<size && (done<gHexalinesPref*16 || size-done<=16)) {
// texte+=sprintf(texte, "%.4lX - ", done);
// int todo=size-done;
// if (todo>=16) {
// todo=16;
// int32 *cp=&pint[done/4];
// texte+=sprintf(texte, "%.8lX %.8lX %.8lX %.8lX ", B_HOST_TO_BENDIAN_INT32(*cp), B_HOST_TO_BENDIAN_INT32(cp[1]),
// B_HOST_TO_BENDIAN_INT32(cp[2]), B_HOST_TO_BENDIAN_INT32(cp[3]));
// } else {
// int32 intbuff[4];
// memcpy(intbuff, &txtdata[done], size-done);
// texte+=sprintf(texte, "%.8lX %.8lX %.8lX %.8lX ", B_HOST_TO_BENDIAN_INT32(*intbuff), B_HOST_TO_BENDIAN_INT32(intbuff[1]),
// B_HOST_TO_BENDIAN_INT32(intbuff[2]), B_HOST_TO_BENDIAN_INT32(intbuff[3]));
// int efface=(16-(size-done))*2;
// char *e=texte;
// while (efface>0) {
// e--;
// if (*e!=' ') {
// *e=' ';
// efface--;
// }
// }
// }
// for (int n=0; n<todo; n++, done) {
// char c=txtdata[done++];
// if (!isprint(c))
// c='.';
// ajoute(texte, c);
// // if (done % 8 == 0)
// // ajoute(texte, ' ');
// }
// if (done<size) {
// texte+=sprintf(texte, "\n%s", gPrefix);
// tab_to(texte, tab);
// }
// }
// if (done<size)
// texte+=sprintf(texte, " [%d bytes remaining of %d bytes]", (int) (size-done), (int) size);
}
break;
}
if (cr)
ajoute(texte, '\n');
}
void ajoute(pchar & texte, const char* mot, long length)
{
long k;
if (length==0)
while (mot[length])
ajoute(texte, mot[length++]);
else
for (k=0; mot[k]!=0 && k<length; k++)
ajoute(texte, mot[k]);
}
void tab_to(pchar & texte, int n)
{
int p=0;
while (texte[-p-1]!='\n')
p++;
if (p<n) {
while (p++<n)
ajoute(texte, ' ');
} else
if (texte[p-1]!=' ')
ajoute(texte, ' ');
}
void print_hex(pchar & texte, void* pvoid, ssize_t size, int extra_space)
{
int32 *pint=(int32 *) pvoid;
char* txtdata=(char*) pvoid;
long done=0;
int tab=strlen(gPrefix)+extra_space;
if (extra_space == 0)
ajoute (texte, gPrefix);
while (done<size && (done<gHexalinesPref*16 || size-done<=16)) {
texte+=sprintf(texte, "%04lX - ", done);
int todo=size-done;
if (todo>=16) {
todo=16;
int32 *cp=&pint[done/4];
texte+=sprintf(texte, "%.8lX %.8lX %.8lX %.8lX ", B_HOST_TO_BENDIAN_INT32(*cp), B_HOST_TO_BENDIAN_INT32(cp[1]),
B_HOST_TO_BENDIAN_INT32(cp[2]), B_HOST_TO_BENDIAN_INT32(cp[3]));
} else {
int32 intbuff[4];
memcpy(intbuff, &txtdata[done], size-done);
texte+=sprintf(texte, "%.8lX %.8lX %.8lX %.8lX ", B_HOST_TO_BENDIAN_INT32(*intbuff), B_HOST_TO_BENDIAN_INT32(intbuff[1]),
B_HOST_TO_BENDIAN_INT32(intbuff[2]), B_HOST_TO_BENDIAN_INT32(intbuff[3]));
int efface=(16-(size-done))*2;
char *e=texte;
while (efface>0) {
e--;
if (*e!=' ') {
*e=' ';
efface--;
}
}
}
for (int n=0; n<todo; n++, done) {
char c=txtdata[done++];
if (c >= 0 && c < ' ')
c='.';
ajoute(texte, c);
// if (done % 8 == 0)
// ajoute(texte, ' ');
}
if (done<size) {
texte+=sprintf(texte, "\n%s", gPrefix);
if (extra_space>0)
tab_to(texte, tab);
}
}
if (done<size)
texte+=sprintf(texte, " [%d bytes remaining of %d bytes]", (int) (size-done), (int) size);
}
-42
View File
@@ -1,42 +0,0 @@
/*
print_message.h
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _PRINT_MESSAGE_H_
#define _PRINT_MESSAGE_H_
#include <SupportDefs.h>
class BMessage;
typedef char* pchar;
void print_message(pchar & texte, BMessage* message, bool dig=false);
extern int32 gHexalinesPref;
// texte=new char[5000000];
// print_message(texte,message);
// ...
// delete[] texte;
#endif // _PRINT_MESSAGE_H_
+26 -20
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
PriorityMenu.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,29 +15,38 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PriorityMenu.h" #include "PriorityMenu.h"
#include "PCView.h" #include "ProcessController.h"
#include <Window.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Window.h>
#include <stdio.h> #include <stdio.h>
PriorityMenu::PriorityMenu (thread_id thread, int32 priority) :
BMenu (B_EMPTY_STRING), fThreadID (thread), fPriority (priority) PriorityMenu::PriorityMenu(thread_id thread, int32 priority)
: BMenu(B_EMPTY_STRING),
fThreadID(thread),
fPriority(priority)
{ {
} }
void PriorityMenu::Update (int32 priority)
void
PriorityMenu::Update(int32 priority)
{ {
if (priority != fPriority && CountItems () > 0) if (priority != fPriority && CountItems() > 0)
RemoveItems (0, CountItems (), true); RemoveItems(0, CountItems(), true);
if (CountItems () < 1) if (CountItems() < 1)
BuildMenu (); BuildMenu();
fPriority = priority; fPriority = priority;
} }
typedef struct { typedef struct {
char name[32]; char name[32];
long priority; long priority;
@@ -62,13 +67,14 @@ static PriorityRec priorities[] = {
PriorityRec customPriority = { "Custom", 0 }; PriorityRec customPriority = { "Custom", 0 };
// --------------------------------------------------------------
void PriorityMenu::BuildMenu () void
PriorityMenu::BuildMenu()
{ {
BMenuItem* item; BMenuItem* item;
BMessage* message; BMessage* message;
char name[B_OS_NAME_LENGTH + 20]; char name[B_OS_NAME_LENGTH + 20];
long found = false; long found = false;
for (long index = 0; ; index++) { for (long index = 0; ; index++) {
PriorityRec *priority = &priorities[index]; PriorityRec *priority = &priorities[index];
@@ -82,7 +88,7 @@ void PriorityMenu::BuildMenu ()
message = new BMessage('PrTh'); message = new BMessage('PrTh');
message->AddInt32("thread", fThreadID); message->AddInt32("thread", fThreadID);
message->AddInt32("priority", priority->priority); message->AddInt32("priority", priority->priority);
sprintf(name, "%s Priority [%d]", priority->name, (int) priority->priority); sprintf(name, "%s Priority [%d]", priority->name, (int)priority->priority);
item = new BMenuItem(name, message); item = new BMenuItem(name, message);
item->SetTarget(gPCView); item->SetTarget(gPCView);
if (fPriority == priority->priority) if (fPriority == priority->priority)
@@ -1,6 +1,4 @@
/* /*
PCView.cpp
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
Copyright (c) 2006 Haiku, Inc. All Rights Reserved. Copyright (c) 2006 Haiku, Inc. All Rights Reserved.
@@ -20,14 +18,24 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCView.h"
#include "ProcessController.h"
#include "AutoIcon.h"
#include "Colors.h"
#include "IconMenuItem.h" #include "IconMenuItem.h"
#include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h"
#include "PCWorld.h" #include "PCWorld.h"
#include "Preferences.h" #include "Preferences.h"
#include "PCUtils.h" #include "QuitMenu.h"
#include "Colors.h" #include "TeamBarMenu.h"
#include "TeamBarMenuItem.h"
#include "ThreadBarMenu.h"
#include "Utilities.h"
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <Directory.h> #include <Directory.h>
#include <Dragger.h> #include <Dragger.h>
@@ -35,6 +43,7 @@
#include <FindDirectory.h> #include <FindDirectory.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <TextView.h> #include <TextView.h>
@@ -73,6 +82,19 @@ ThreadBarMenu* gCurrentThreadBarMenu;
bool gInDeskbar = false; bool gInDeskbar = false;
int32 gMimicPulse = 0; int32 gMimicPulse = 0;
#define addtopbottom(x) if (top) popup->AddItem(x); else popup->AddItem(x, 0)
long thread_popup(void *arg);
int32 gPopupFlag = 0;
thread_id gPopupThreadID = 0;
typedef struct {
BPoint where;
BRect clickToOpenRect;
bool top;
} Tpopup_param;
#define DEBUG_THREADS 1 #define DEBUG_THREADS 1
long thread_quit_application(void *arg); long thread_quit_application(void *arg);
@@ -84,6 +106,27 @@ typedef struct {
time_t totalTime; time_t totalTime;
} Tdebug_thead_param; } Tdebug_thead_param;
// Bar layout depending on number of CPUs
typedef struct {
float cpu_width;
float cpu_inter;
float mem_width;
} layoutT;
layoutT layout[] = {
{ 1, 1, 1 },
{ 5, 1, 5 }, // 1
{ 3, 1, 4 }, // 2
{ 1, 1, 1 },
{ 2, 0, 3 }, // 4
{ 1, 1, 1 },
{ 1, 1, 1 },
{ 1, 1, 1 },
{ 1, 0, 3 } // 8
};
extern "C" _EXPORT BView *instantiate_deskbar_item(void); extern "C" _EXPORT BView *instantiate_deskbar_item(void);
extern "C" _EXPORT BView * extern "C" _EXPORT BView *
@@ -94,8 +137,12 @@ instantiate_deskbar_item(void)
} }
// #pragma mark -
ProcessController::ProcessController(BRect frame, bool temp) ProcessController::ProcessController(BRect frame, bool temp)
: BView(frame, kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW), : BView(frame, kDeskbarItemName, B_FOLLOW_TOP_BOTTOM,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fProcessControllerIcon(kSignature), fProcessControllerIcon(kSignature),
fProcessorIcon(k_cpu_mini), fProcessorIcon(k_cpu_mini),
fTrackerIcon(kTrackerSig), fTrackerIcon(kTrackerSig),
@@ -105,11 +152,12 @@ ProcessController::ProcessController(BRect frame, bool temp)
{ {
if (!temp) { if (!temp) {
Init(); Init();
frame.OffsetTo(B_ORIGIN); frame.OffsetTo(B_ORIGIN);
frame.top = frame.bottom - 7; frame.top = frame.bottom - 7;
frame.left = frame.right - 7; frame.left = frame.right - 7;
BDragger* dw = new BDragger(frame, this); BDragger* dragger = new BDragger(frame, this, B_FOLLOW_BOTTOM);
AddChild(dw); AddChild(dragger);
} }
} }
@@ -206,10 +254,10 @@ ProcessController::MessageReceived(BMessage *message)
case 'KlTm': case 'KlTm':
if (message->FindInt32("team", &team) == B_OK) { if (message->FindInt32("team", &team) == B_OK) {
infosPack infos; info_pack infos;
if (get_team_info(team, &infos.tminfo) == B_OK) { if (get_team_info(team, &infos.team_info) == B_OK) {
get_team_name_and_icon(infos); get_team_name_and_icon(infos);
sprintf(question, "Do you really want to kill the team \"%s\"?", infos.tmname); sprintf(question, "Do you really want to kill the team \"%s\"?", infos.team_name);
alert = new BAlert("", question, "Cancel", "Yes, Kill this Team!", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert = new BAlert("", question, "Cancel", "Yes, Kill this Team!", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetShortcut(0, B_ESCAPE); alert->SetShortcut(0, B_ESCAPE);
if (alert->Go()) if (alert->Go())
@@ -360,6 +408,7 @@ ProcessController::DefaultColors()
bool set = false; bool set = false;
if (gMimicPulse) { if (gMimicPulse) {
// TODO: remove this?
BPath prefpath; BPath prefpath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) {
BDirectory prefdir(prefpath.Path ()); BDirectory prefdir(prefpath.Path ());
@@ -412,7 +461,6 @@ ProcessController::DefaultColors()
frame_color = kBlack; frame_color = kBlack;
mix_colors (memory_color, active_color, swap_color, 0.2); mix_colors (memory_color, active_color, swap_color, 0.2);
} }
// idle_color = kWhite;
} }
@@ -428,49 +476,50 @@ ProcessController::AttachedToWindow()
GebsPreferences tPreferences(kPreferencesFileName, NULL, false); GebsPreferences tPreferences(kPreferencesFileName, NULL, false);
tPreferences.ReadInt32(gMimicPulse, kMimicPulsePref); tPreferences.ReadInt32(gMimicPulse, kMimicPulsePref);
DefaultColors(); DefaultColors();
system_info sys_info;
get_system_info(&sys_info); system_info info;
gCPUcount = sys_info.cpu_count; get_system_info(&info);
gCPUcount = info.cpu_count;
Update(); Update();
gIdleColor = kIdleGreen; gIdleColor = kIdleGreen;
gIdleColorSelected = tint_color(gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT); gIdleColorSelected = tint_color(gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT);
gKernelColor = kKernelBlue; gKernelColor = kKernelBlue;
gKernelColorSelected = tint_color(gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT); gKernelColorSelected = tint_color(gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT);
// gKernelColor = tint_color(gUserColor, B_DARKEN_1_TINT);
gUserColor = tint_color(gKernelColor, B_LIGHTEN_2_TINT); gUserColor = tint_color(gKernelColor, B_LIGHTEN_2_TINT);
gUserColorSelected = tint_color(gUserColor, B_HIGHLIGHT_BACKGROUND_TINT); gUserColorSelected = tint_color(gUserColor, B_HIGHLIGHT_BACKGROUND_TINT);
gFrameColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_HIGHLIGHT_BACKGROUND_TINT); gFrameColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_HIGHLIGHT_BACKGROUND_TINT);
gFrameColorSelected = tint_color(gFrameColor, B_HIGHLIGHT_BACKGROUND_TINT); gFrameColorSelected = tint_color(gFrameColor, B_HIGHLIGHT_BACKGROUND_TINT);
gMenuBackColor = ui_color(B_MENU_BACKGROUND_COLOR); gMenuBackColor = ui_color(B_MENU_BACKGROUND_COLOR);
// Depending on which version of the system we use, choose the menu selection color... gMenuBackColorSelected = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR);
if (before_dano())
gMenuBackColorSelected = tint_color(gMenuBackColor, B_HIGHLIGHT_BACKGROUND_TINT); // R5 & before
else
gMenuBackColorSelected = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR); // Dano & up
gWhiteSelected = tint_color(kWhite, B_HIGHLIGHT_BACKGROUND_TINT); gWhiteSelected = tint_color(kWhite, B_HIGHLIGHT_BACKGROUND_TINT);
BMessenger messenger (this); BMessenger messenger(this);
BMessage message ('Puls'); BMessage message('Puls');
fMessageRunner = new BMessageRunner (messenger, &message, 250000, -1); fMessageRunner = new BMessageRunner(messenger, &message, 250000, -1);
} }
typedef struct {
float cpu_width;
float cpu_inter;
float mem_width;
} layoutT;
layoutT layout[] = { void
{ 1, 1, 1 }, ProcessController::MouseDown(BPoint where)
{ 5, 1, 5 }, // 1 {
{ 3, 1, 4 }, // 2 if (atomic_add(&gPopupFlag, 1) > 0) {
{ 1, 1, 1 }, atomic_add(&gPopupFlag, -1);
{ 2, 0, 3 }, // 4 return;
{ 1, 1, 1 }, }
{ 1, 1, 1 },
{ 1, 1, 1 }, Tpopup_param* param = new Tpopup_param;
{ 1, 0, 3 } }; // 8 ConvertToScreen(&where);
param->where = where;
param->clickToOpenRect = Frame ();
ConvertToScreen (&param->clickToOpenRect);
param->top = where.y < BScreen(this->Window()).Frame().bottom-50;
gPopupThreadID = spawn_thread(thread_popup, "Popup holder thread",
B_URGENT_DISPLAY_PRIORITY, param);
resume_thread(gPopupThreadID);
}
void void
@@ -484,126 +533,276 @@ ProcessController::Draw(BRect)
void void
ProcessController::DoDraw(bool force) ProcessController::DoDraw(bool force)
{ {
//gCPUcount = 1;
BRect bounds(Bounds()); BRect bounds(Bounds());
float h = floorf(bounds.Height ()) - 2; float h = floorf(bounds.Height ()) - 2;
float top = 1, left = 1; float top = 1, left = 1;
float bottom = top + h; float bottom = top + h;
float bar_width = layout[gCPUcount].cpu_width; float barWidth = layout[gCPUcount].cpu_width;
// interspace // interspace
float right = left + gCPUcount * (bar_width + layout[gCPUcount].cpu_inter) - layout[gCPUcount].cpu_inter; // right of CPU frame... float right = left + gCPUcount * (barWidth + layout[gCPUcount].cpu_inter)
- layout[gCPUcount].cpu_inter; // right of CPU frame...
if (force && Parent()) { if (force && Parent()) {
SetHighColor (Parent ()->ViewColor ()); SetHighColor(Parent()->ViewColor ());
FillRect (BRect (right + 1, top - 1, right + 2, bottom + 1)); FillRect(BRect(right + 1, top - 1, right + 2, bottom + 1));
} }
if (force) { if (force) {
SetHighColor (frame_color); SetHighColor(frame_color);
StrokeRect (BRect (left - 1, top - 1, right, bottom + 1)); StrokeRect(BRect(left - 1, top - 1, right, bottom + 1));
if (gCPUcount == 2) if (gCPUcount == 2)
StrokeLine (BPoint (left + bar_width, top), BPoint (left + bar_width, bottom)); StrokeLine(BPoint(left + barWidth, top), BPoint(left + barWidth, bottom));
} }
float leftMem = bounds.Width () - layout[gCPUcount].mem_width; float leftMem = bounds.Width() - layout[gCPUcount].mem_width;
if (force) if (force)
StrokeRect (BRect (leftMem - 1, top - 1, leftMem + layout[gCPUcount].mem_width, bottom + 1)); StrokeRect(BRect(leftMem - 1, top - 1, leftMem + layout[gCPUcount].mem_width, bottom + 1));
for (int x = 0; x < gCPUcount; x++) { for (int x = 0; x < gCPUcount; x++) {
right = left + bar_width - 1; right = left + barWidth - 1;
float rem = fCPUTimes[x] * (h + 1); float rem = fCPUTimes[x] * (h + 1);
float bar_height = floorf (rem); float barHeight = floorf (rem);
rem -= bar_height; rem -= barHeight;
float limit = bottom - bar_height; // horizontal line float limit = bottom - barHeight; // horizontal line
float previous_limit = bottom - fLastBarHeight[x]; float previousLimit = bottom - fLastBarHeight[x];
float idle_top = top; float idleTop = top;
if (!force && previous_limit > top)
idle_top = previous_limit - 1; if (!force && previousLimit > top)
if (limit > idle_top) { idleTop = previousLimit - 1;
SetHighColor (idle_color); if (limit > idleTop) {
FillRect (BRect (left, idle_top, right, limit - 1)); SetHighColor(idle_color);
FillRect(BRect(left, idleTop, right, limit - 1));
} }
if (bar_height <= h) { if (barHeight <= h) {
rgb_color fraction_color; rgb_color fraction_color;
mix_colors (fraction_color, idle_color, active_color, rem); mix_colors(fraction_color, idle_color, active_color, rem);
SetHighColor (fraction_color); SetHighColor(fraction_color);
StrokeLine (BPoint (left, bottom - bar_height), BPoint (right, bottom - bar_height)); StrokeLine(BPoint(left, bottom - barHeight), BPoint(right, bottom - barHeight));
} }
float active_bottom = bottom; float active_bottom = bottom;
if (!force && previous_limit < bottom) if (!force && previousLimit < bottom)
active_bottom = previous_limit + 1; active_bottom = previousLimit + 1;
if (limit < active_bottom) { if (limit < active_bottom) {
SetHighColor(active_color); SetHighColor(active_color);
FillRect(BRect(left, limit + 1, right, active_bottom)); FillRect(BRect(left, limit + 1, right, active_bottom));
} }
left += layout[gCPUcount].cpu_width + layout[gCPUcount].cpu_inter; left += layout[gCPUcount].cpu_width + layout[gCPUcount].cpu_inter;
fLastBarHeight[x] = bar_height; fLastBarHeight[x] = barHeight;
} }
float rightMem = bounds.Width () - 1; float rightMem = bounds.Width () - 1;
float rem = fMemoryUsage * (h + 1); float rem = fMemoryUsage * (h + 1);
float bar_height = floorf (rem); float barHeight = floorf (rem);
rem -= bar_height; rem -= barHeight;
rgb_color used_memory_color; rgb_color used_memory_color;
float sq = fMemoryUsage * fMemoryUsage; float sq = fMemoryUsage * fMemoryUsage;
sq *= sq; sq *= sq;
sq *= sq; sq *= sq;
mix_colors (used_memory_color, memory_color, swap_color, sq); mix_colors(used_memory_color, memory_color, swap_color, sq);
float limit = bottom - bar_height; // horizontal line float limit = bottom - barHeight; // horizontal line
float previous_limit = bottom - fLastMemoryHeight; float previousLimit = bottom - fLastMemoryHeight;
float free_top = top; float free_top = top;
if (!force && previous_limit > top) if (!force && previousLimit > top)
free_top = previous_limit - 1; free_top = previousLimit - 1;
if (limit > free_top) { if (limit > free_top) {
SetHighColor (idle_color); SetHighColor (idle_color);
FillRect (BRect (leftMem, free_top, rightMem, limit - 1)); FillRect(BRect(leftMem, free_top, rightMem, limit - 1));
} }
if (bar_height <= h) { if (barHeight <= h) {
rgb_color fraction_color; rgb_color fraction_color;
mix_colors (fraction_color, idle_color, used_memory_color, rem); mix_colors(fraction_color, idle_color, used_memory_color, rem);
SetHighColor (fraction_color); SetHighColor(fraction_color);
StrokeLine (BPoint (leftMem, bottom - bar_height), BPoint (rightMem, bottom - bar_height)); StrokeLine(BPoint(leftMem, bottom - barHeight), BPoint(rightMem, bottom - barHeight));
} }
float used_bottom = bottom; float usedBottom = bottom;
// if (!force && previous_limit < bottom) // if (!force && previousLimit < bottom)
// used_bottom = previous_limit + 1; // usedBottom = previousLimit + 1;
if (limit < used_bottom) { if (limit < usedBottom) {
SetHighColor (used_memory_color); SetHighColor(used_memory_color);
FillRect (BRect (leftMem, limit + 1, rightMem, used_bottom)); FillRect(BRect(leftMem, limit + 1, rightMem, usedBottom));
} }
fLastMemoryHeight = bar_height; fLastMemoryHeight = barHeight;
} }
void void
ProcessController::Update() ProcessController::Update()
{ {
system_info sys_info; system_info info;
get_system_info(&sys_info); get_system_info(&info);
bigtime_t now = system_time(); bigtime_t now = system_time();
fMemoryUsage = float(sys_info.used_pages) / float(sys_info.max_pages); fMemoryUsage = float(info.used_pages) / float(info.max_pages);
// Calculate work done since last call to Update() for each CPU // Calculate work done since last call to Update() for each CPU
for (int x = 0; x < gCPUcount; x++) { for (int x = 0; x < gCPUcount; x++) {
bigtime_t load = sys_info.cpu_infos[x].active_time - fPrevActive[x]; bigtime_t load = info.cpu_infos[x].active_time - fPrevActive[x];
bigtime_t passed = now - fPrevTime; bigtime_t passed = now - fPrevTime;
float cpu_time = float(load) / float(passed); float cpuTime = float(load) / float(passed);
fPrevActive[x] = sys_info.cpu_infos[x].active_time;
fPrevActive[x] = info.cpu_infos[x].active_time;
if (load > passed) if (load > passed)
fPrevActive[x] -= load - passed; // save overload for next period... fPrevActive[x] -= load - passed; // save overload for next period...
if (cpu_time < 0) cpu_time = 0; if (cpuTime < 0)
if (cpu_time > 1) cpu_time = 1; cpuTime = 0;
fCPUTimes[x] = cpu_time; if (cpuTime > 1)
cpuTime = 1;
fCPUTimes[x] = cpuTime;
} }
fPrevTime = now; fPrevTime = now;
} }
// #pragma mark -
long
thread_popup(void *arg)
{
Tpopup_param* param = (Tpopup_param*) arg;
int32 mcookie, hcookie;
long m, h;
BMenuItem* item;
bool top = param->top;
system_info systemInfo;
get_system_info(&systemInfo);
info_pack* infos = new info_pack[systemInfo.used_teams];
// TODO: this doesn't necessarily get all teams
for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
infos[m].team_icon = NULL;
infos[m].team_name[0] = 0;
infos[m].thread_info = NULL;
if (get_next_team_info(&mcookie, &infos[m].team_info) == B_OK) {
infos[m].thread_info = new thread_info[infos[m].team_info.thread_count];
for (h = 0, hcookie = 0; h < infos[m].team_info.thread_count; h++) {
if (get_next_thread_info(infos[m].team_info.team, &hcookie, &infos[m].thread_info[h]) != B_OK)
infos[m].thread_info[h].thread = -1;
}
get_team_name_and_icon(infos[m], true);
} else {
systemInfo.used_teams = m;
infos[m].team_info.team = -1;
}
}
BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
popup->SetFont(be_plain_font);
// Quit section
BMenu* QuitPopup = new QuitMenu("Quit an Application", infos, systemInfo.used_teams);
QuitPopup->SetFont(be_plain_font);
popup->AddItem(QuitPopup);
// Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu("Memory Usage", infos, systemInfo);
int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
MemoryBarMenuItem* memoryItem = new MemoryBarMenuItem(infos[m].team_name, infos[m].team_info.team, infos[m].team_icon, false, NULL);
MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(commitedMemory);
}
}
addtopbottom(MemoryPopup);
// CPU Load section
TeamBarMenu* CPUPopup = new TeamBarMenu("Threads and CPU Usage", infos, systemInfo.used_teams);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].team_name, infos[m].team_info.team, infos[m].team_info.thread_count);
BMessage* kill_team = new BMessage('KlTm');
kill_team->AddInt32("team", infos[m].team_info.team);
TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team, infos[m].team_info.team, infos[m].team_icon, false);
item->SetTarget(gPCView);
CPUPopup->AddItem(item);
}
}
addtopbottom(CPUPopup);
addtopbottom(new BSeparatorItem());
// CPU on/off section
if (gCPUcount > 1) {
for (int i = 0; i < gCPUcount; i++) {
char item_name[32];
sprintf (item_name, "Processor %d", i + 1);
BMessage* m = new BMessage ('CPU ');
m->AddInt32 ("cpu", i);
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
if (_kget_cpu_state_(i))
item->SetMarked (true);
item->SetTarget(gPCView);
addtopbottom(item);
}
addtopbottom (new BSeparatorItem ());
}
if (!be_roster->IsRunning(kTrackerSig)) {
item = new IconMenuItem(gPCView->fTrackerIcon, "Launch Tracker", new BMessage('Trac'));
item->SetTarget(gPCView);
addtopbottom(item);
}
if (!be_roster->IsRunning(kDeskbarSig)) {
item = new IconMenuItem(gPCView->fDeskbarIcon, "Launch Deskbar", new BMessage('Dbar'));
item->SetTarget(gPCView);
addtopbottom(item);
}
item = new IconMenuItem(gPCView->fTerminalIcon, "New Terminal", new BMessage('Term'));
item->SetTarget(gPCView);
addtopbottom(item);
addtopbottom(new BSeparatorItem());
if (be_roster->IsRunning(kDeskbarSig)) {
item = new BMenuItem("Live in the Deskbar", new BMessage('AlDb'));
BDeskbar deskbar;
item->SetMarked(gInDeskbar || deskbar.HasItem(kDeskbarItemName));
item->SetTarget(gPCView);
addtopbottom(item);
}
#if 0
item = new BMenuItem("Use Pulse's Settings for Colors", new BMessage ('Colo'));
item->SetTarget (gPCView);
item->SetMarked (gMimicPulse);
addtopbottom (item);
#endif
addtopbottom(new BSeparatorItem ());
item = new IconMenuItem(gPCView->fProcessControllerIcon, "About ProcessController",
new BMessage(B_ABOUT_REQUESTED));
item->SetTarget(gPCView);
addtopbottom(item);
param->where.x -= 5;
param->where.y -= 8;
popup->Go(param->where, true, true, param->clickToOpenRect);
delete popup;
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
delete[] infos[m].thread_info;
delete infos[m].team_icon;
}
}
delete[] infos;
delete param;
atomic_add (&gPopupFlag, -1);
gPopupThreadID = 0;
return B_OK;
}
long long
thread_quit_application(void *arg) thread_quit_application(void *arg)
{ {
BMessenger messenger (NULL, (team_id) arg); BMessenger messenger(NULL, (team_id)arg);
messenger.SendMessage (B_QUIT_REQUESTED); messenger.SendMessage(B_QUIT_REQUESTED);
return B_OK; return B_OK;
} }
@@ -614,9 +813,9 @@ thread_debug_thread(void *arg)
Tdebug_thead_param* param = (Tdebug_thead_param*) arg; Tdebug_thead_param* param = (Tdebug_thead_param*) arg;
thread_info thinfo; thread_info thinfo;
get_thread_info(param->thread, &thinfo); get_thread_info(param->thread, &thinfo);
char texte[4096]; char text[4096];
sprintf (texte, "db %d", int(param->thread)); sprintf(text, "db %d", int(param->thread));
system (texte); system(text);
if (param->sem >= 0 && thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem) { if (param->sem >= 0 && thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem) {
snooze(1000000); snooze(1000000);
get_thread_info(param->thread, &thinfo); get_thread_info(param->thread, &thinfo);
@@ -626,28 +825,30 @@ thread_debug_thread(void *arg)
// the thread has been waiting for this semaphore since the before the alert, not doing anything... Let's push it out of there! // the thread has been waiting for this semaphore since the before the alert, not doing anything... Let's push it out of there!
sem_info sinfo; sem_info sinfo;
thread_info thinfo; thread_info thinfo;
infosPack infos; info_pack infos;
if (get_sem_info(param->sem, &sinfo) == B_OK if (get_sem_info(param->sem, &sinfo) == B_OK
&& get_thread_info(param->thread, &thinfo) == B_OK && get_thread_info(param->thread, &thinfo) == B_OK
&& get_team_info(thinfo.team, &infos.tminfo) == B_OK) { && get_team_info(thinfo.team, &infos.team_info) == B_OK) {
sprintf (texte, "This thread is waiting for the semaphore called \"%s\". As long as it waits for this semaphore, " sprintf (text, "This thread is waiting for the semaphore called \"%s\". As long as it waits for this semaphore, "
"you won't be able to debug that thread.\n", sinfo.name); "you won't be able to debug that thread.\n", sinfo.name);
if (sinfo.team == thinfo.team) if (sinfo.team == thinfo.team)
strcat (texte, "This semaphore belongs to the thread's team.\n\nShould I release this semaphore?\n"); strcat(text, "This semaphore belongs to the thread's team.\n\nShould I release this semaphore?\n");
else { else {
get_team_name_and_icon (infos); get_team_name_and_icon(infos);
char moretexte[1024]; char moreText[1024];
sprintf (moretexte, "\nWARNING! This semaphore belongs to the team \"%s\"!\n\nShould I release this semaphore anyway?\n", infos.tmname); sprintf(moreText, "\nWARNING! This semaphore belongs to the team \"%s\"!\n\nShould I release this semaphore anyway?\n",
strcat (texte, moretexte); infos.team_name);
strcat(text, moreText);
} }
BAlert* alert = new BAlert("", texte, "Cancel", "Release", NULL, BAlert* alert = new BAlert("", text, "Cancel", "Release", NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT); B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetShortcut(0, B_ESCAPE); alert->SetShortcut(0, B_ESCAPE);
if (alert->Go()) { if (alert->Go()) {
get_thread_info (param->thread, &thinfo); get_thread_info (param->thread, &thinfo);
if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time) if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem
&& param->totalTime == thinfo.user_time + thinfo.kernel_time)
release_sem(param->sem); release_sem(param->sem);
else { else {
alert = new BAlert("", "The semaphore wasn't released, because it wasn't necessary anymore!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert = new BAlert("", "The semaphore wasn't released, because it wasn't necessary anymore!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
@@ -84,7 +84,6 @@ extern rgb_color gMenuBackColorSelected;
extern rgb_color gWhiteSelected; extern rgb_color gWhiteSelected;
extern ThreadBarMenu* gCurrentThreadBarMenu; extern ThreadBarMenu* gCurrentThreadBarMenu;
extern thread_id gPopupThreadID; extern thread_id gPopupThreadID;
extern team_id gAppServerTeamID;
extern const char* kDeskbarItemName; extern const char* kDeskbarItemName;
extern bool gInDeskbar; extern bool gInDeskbar;
extern int32 gMimicPulse; extern int32 gMimicPulse;
+62 -41
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
QuitMenu.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,62 +15,76 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "QuitMenu.h"
#include "IconMenuItem.h"
#include "ProcessController.h"
#include <Roster.h> #include <Roster.h>
#include <Window.h> #include <Window.h>
#include <stdio.h> #include <stdio.h>
#include "QuitMenu.h"
#include "IconMenuItem.h"
#include "PCView.h"
class QuitMenuItem : public IconMenuItem { class QuitMenuItem : public IconMenuItem {
public:
QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge = false);
team_id Team() { return fTeam; }
public: private:
QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge = false); team_id fTeam;
team_id Team() { return fTeam; }
private:
team_id fTeam;
}; };
QuitMenuItem::QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge) : QuitMenuItem::QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge) :
IconMenuItem(icon, title, m, true, purge), fTeam(team) IconMenuItem(icon, title, m, true, purge), fTeam(team)
{ {
} }
//-------------------------------------------------------------------------------------------------
QuitMenu::QuitMenu(const char* title, infosPack * infos, int infosCount) : // #pragma mark -
BMenu(title), fInfos(infos), fInfosCount(infosCount), fMe(NULL)
QuitMenu::QuitMenu(const char* title, info_pack* infos, int infosCount)
: BMenu(title),
fInfos(infos),
fInfosCount(infosCount),
fMe(NULL)
{ {
SetTargetForItems(gPCView); SetTargetForItems(gPCView);
} }
void QuitMenu::AttachedToWindow()
void
QuitMenu::AttachedToWindow()
{ {
if (!fMe) if (!fMe)
fMe = new BMessenger(this); fMe = new BMessenger(this);
be_roster->StartWatching(*fMe, B_REQUEST_LAUNCHED | B_REQUEST_QUIT); be_roster->StartWatching(*fMe, B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
BList apps; BList apps;
team_id tmid; team_id tmid;
be_roster->GetAppList(&apps); be_roster->GetAppList(&apps);
for (int t = CountItems() - 1; t >= 0; t--) { for (int t = CountItems() - 1; t >= 0; t--) {
QuitMenuItem* item = (QuitMenuItem*) ItemAt(t); QuitMenuItem* item = (QuitMenuItem*)ItemAt(t);
bool found = false; bool found = false;
for (int a = 0; !found && (tmid = (team_id) apps.ItemAt(a)) != 0; a++) for (int a = 0; !found && (tmid = (team_id)apps.ItemAt(a)) != 0; a++)
if (item->Team() == tmid) if (item->Team() == tmid)
found = true; found = true;
if (!found) if (!found)
RemoveItem(t); RemoveItem(t);
} }
for (int a = 0; (tmid = (team_id) apps.ItemAt(a)) != 0; a++) for (int a = 0; (tmid = (team_id) apps.ItemAt(a)) != 0; a++) {
AddTeam(tmid); AddTeam(tmid);
}
BMenu::AttachedToWindow(); BMenu::AttachedToWindow();
} }
void QuitMenu::DetachedFromWindow()
void
QuitMenu::DetachedFromWindow()
{ {
BMenu::DetachedFromWindow(); BMenu::DetachedFromWindow();
be_roster->StopWatching(*fMe); be_roster->StopWatching(*fMe);
@@ -82,57 +92,68 @@ void QuitMenu::DetachedFromWindow()
fMe = NULL; fMe = NULL;
} }
void QuitMenu::AddTeam(team_id tmid)
void
QuitMenu::AddTeam(team_id tmid)
{ {
int t = 0; int t = 0;
QuitMenuItem* item; QuitMenuItem* item;
while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL) while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL) {
if (item->Team() == tmid) if (item->Team() == tmid)
return; return;
}
t = 0; t = 0;
while (t < fInfosCount && tmid != fInfos[t].tminfo.team) while (t < fInfosCount && tmid != fInfos[t].team_info.team) {
t++; t++;
}
BMessage* message = new BMessage ('QtTm'); BMessage* message = new BMessage ('QtTm');
message->AddInt32 ("team", tmid); message->AddInt32 ("team", tmid);
item = NULL; item = NULL;
if (t < fInfosCount) if (t < fInfosCount)
item = new QuitMenuItem (tmid, fInfos[t].tmicon, fInfos[t].tmname, message); item = new QuitMenuItem(tmid, fInfos[t].team_icon, fInfos[t].team_name, message);
else { else {
infosPack infos; info_pack infos;
if (get_team_info(tmid, &infos.tminfo) == B_OK && get_team_name_and_icon(infos, true)) if (get_team_info(tmid, &infos.team_info) == B_OK
item = new QuitMenuItem (tmid, infos.tmicon, infos.tmname, message, true); && get_team_name_and_icon(infos, true))
item = new QuitMenuItem(tmid, infos.team_icon, infos.team_name, message, true);
} }
if (item) { if (item) {
item->SetTarget (gPCView); item->SetTarget(gPCView);
AddItem (item); AddItem(item);
} else } else
delete message; delete message;
} }
void QuitMenu::MessageReceived(BMessage *msg)
void
QuitMenu::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_SOME_APP_LAUNCHED: case B_SOME_APP_LAUNCHED:
{ {
int32 tmid; int32 tmid;
if (msg->FindInt32("be:team", &tmid) == B_OK) if (msg->FindInt32("be:team", &tmid) == B_OK)
AddTeam(tmid); AddTeam(tmid);
break; break;
} }
case B_SOME_APP_QUIT: case B_SOME_APP_QUIT:
{ {
int32 tmid; int32 tmid;
if (msg->FindInt32("be:team", &tmid) == B_OK) { if (msg->FindInt32("be:team", &tmid) == B_OK) {
QuitMenuItem* item; QuitMenuItem* item;
int t = 0; int t = 0;
while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL) while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL) {
if (item->Team() == tmid) { if (item->Team() == tmid) {
delete RemoveItem(--t); delete RemoveItem(--t);
return; return;
} }
}
} }
break; break;
} }
default: default:
BMenu::MessageReceived(msg); BMenu::MessageReceived(msg);
} }
+17 -20
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
QuitMenu.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,28 +15,29 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _QUIT_MENU_H_ #ifndef _QUIT_MENU_H_
#define _QUIT_MENU_H_ #define _QUIT_MENU_H_
#include "Utilities.h"
#include <Menu.h> #include <Menu.h>
#include <Messenger.h> #include <Messenger.h>
#include "PCUtils.h"
class QuitMenu : public BMenu
{ class QuitMenu : public BMenu {
public: public:
QuitMenu(const char* title, infosPack * infos, int infosCount); QuitMenu(const char* title, info_pack* infos, int infosCount);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
void AddTeam(team_id tmid); void AddTeam(team_id tmid);
private:
const infosPack *fInfos; private:
int fInfosCount; const info_pack* fInfos;
BMessenger *fMe; int fInfosCount;
BMessenger* fMe;
}; };
#endif // _QUIT_MENU_H_ #endif // _QUIT_MENU_H_
-268
View File
@@ -1,268 +0,0 @@
/*
ReadableLong.cpp
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ReadableLong.h"
#include "ctype.h"
#include "stdio.h"
typedef struct {
const char *name;
ulong value;
} TBeValue;
const TBeValue bevalue[] = {
{ "B_ERROR", 0xffff },
{ "B_OK", 0 },
// AppDefs.h
{ "B_ABOUT_REQUESTED", '_ABR' },
{ "B_APP_ACTIVATED", '_ACT' }, // Also B_WINDOW_ACTIVATED
{ "B_ARGV_RECEIVED", '_ARG' },
{ "B_QUIT_REQUESTED", '_QRQ' }, // Also B_CLOSE_REQUESTED
{ "B_CANCEL", '_CNC' },
{ "B_KEY_DOWN", '_KYD' },
{ "B_KEY_UP", '_KYU' },
{ "B_UNMAPPED_KEY_DOWN", '_UKD' },
{ "B_UNMAPPED_KEY_UP", '_UKU' },
{ "B_MODIFIERS_CHANGED", '_MCH' },
{ "B_MINIMIZE", '_WMN' },
{ "B_MOUSE_DOWN", '_MDN' },
{ "B_MOUSE_MOVED", '_MMV' },
{ "B_MOUSE_ENTER_EXIT", '_MEX' },
{ "B_MOUSE_UP", '_MUP' },
{ "B_OPEN_IN_WORKSPACE", '_OWS' },
{ "B_PULSE", '_PUL' },
{ "B_READY_TO_RUN", '_RTR' },
{ "B_REFS_RECEIVED", '_RRC' },
{ "B_SCREEN_CHANGED", '_SCH' },
{ "B_VALUE_CHANGED", '_VCH' },
{ "B_VIEW_MOVED", '_VMV' },
{ "B_VIEW_RESIZED", '_VRS' },
{ "B_WINDOW_MOVED", '_WMV' },
{ "B_WINDOW_RESIZED", '_WRS' },
{ "B_WORKSPACES_CHANGED", '_WCG' },
{ "B_WORKSPACE_ACTIVATED", '_WAC' },
{ "B_ZOOM", '_WZM' },
{ "_APP_MENU_", '_AMN' },
{ "_BROWSER_MENUS_", '_BRM' },
{ "_MENU_EVENT_", '_MEV' },
{ "_PING_", '_PBL' },
{ "_QUIT_", '_QIT' },
{ "_VOLUME_MOUNTED_", '_NVL' },
{ "_VOLUME_UNMOUNTED_", '_VRM' },
{ "_MESSAGE_DROPPED_", '_MDP' },
{ "_DISPOSE_DRAG_", '_DPD' },
{ "_MENUS_DONE_", '_MND' },
{ "_SHOW_DRAG_HANDLES_", '_SDH' },
{ "_EVENTS_PENDING_", '_EVP' },
{ "_UPDATE_", '_UPD' },
{ "_UPDATE_IF_NEEDED_", '_UPN' },
{ "_PRINTER_INFO_", '_PIN' },
{ "_SETUP_PRINTER_", '_SUP' },
{ "_SELECT_PRINTER_", '_PSL' },
{ "B_SET_PROPERTY", 'PSET' },
{ "B_GET_PROPERTY", 'PGET' },
{ "B_CREATE_PROPERTY", 'PCRT' },
{ "B_DELETE_PROPERTY", 'PDEL' },
{ "B_COUNT_PROPERTIES", 'PCNT' },
{ "B_EXECUTE_PROPERTY", 'PEXE' },
{ "B_GET_SUPPORTED_SUITES", 'SUIT' },
{ "B_UNDO", 'UNDO' },
{ "B_CUT", 'CCUT' },
{ "B_COPY", 'COPY' },
{ "B_PASTE", 'PSTE' },
{ "B_SELECT_ALL", 'SALL' },
{ "B_SAVE_REQUESTED", 'SAVE' },
{ "B_MESSAGE_NOT_UNDERSTOOD", 'MNOT' },
{ "B_NO_REPLY", 'NONE' },
{ "B_REPLY", 'RPLY' },
{ "B_SIMPLE_DATA", 'DATA' },
{ "B_MIME_DATA", 'MIME' },
{ "B_ARCHIVED_OBJECT", 'ARCV' },
{ "B_UPDATE_STATUS_BAR", 'SBUP' },
{ "B_RESET_STATUS_BAR", 'SBRS' },
{ "B_NODE_MONITOR", 'NDMN' },
{ "B_QUERY_UPDATE", 'QUPD' },
{ "B_ENDORSABLE", 'ENDO' },
{ "B_COPY_TARGET", 'DDCP' },
{ "B_MOVE_TARGET", 'DDMV' },
{ "B_TRASH_TARGET", 'DDRM' },
{ "B_LINK_TARGET", 'DDLN' },
{ "B_INPUT_DEVICES_CHANGED", 'IDCH' },
{ "B_INPUT_METHOD_EVENT", 'IMEV' },
{ "B_WINDOW_MOVE_TO", 'WDMT' },
{ "B_WINDOW_MOVE_BY", 'WDMB' },
{ "B_SILENT_RELAUNCH", 'AREL' },
// Clipboard.h
{ "B_CLIPBOARD_CHANGED", 'CLCH' },
// MediaNode.h
{ "B_NODE_FAILED_START", 'TRI0' },
{ "B_NODE_FAILED_STOP", 'TRI1' },
{ "B_NODE_FAILED_SEEK", 'TRI2' },
{ "B_NODE_FAILED_SET_RUN_MODE", 'TRI3' },
{ "B_NODE_FAILED_TIME_WARP", 'TRI4' },
{ "B_NODE_FAILED_PREROLL", 'TRI5' },
{ "B_NODE_FAILED_SET_TIME_SOURCE_FOR", 'TRI6' },
{ "B_NODE_IN_DISTRESS", 'TRI7' },
// TypeConstants.h
{ "B_ANY_TYPE", 'ANYT' },
{ "B_ASCII_TYPE", 'TEXT' },
{ "B_BOOL_TYPE", 'BOOL' },
{ "B_CHAR_TYPE", 'CHAR' },
{ "B_COLOR_8_BIT_TYPE", 'CLRB' },
{ "B_DOUBLE_TYPE", 'DBLE' },
{ "B_FLOAT_TYPE", 'FLOT' },
{ "B_GRAYSCALE_8_BIT_TYPE", 'GRYB' },
{ "B_INT64_TYPE", 'LLNG' },
{ "B_INT32_TYPE", 'LONG' },
{ "B_INT16_TYPE", 'SHRT' },
{ "B_INT8_TYPE", 'BYTE' },
{ "B_MESSAGE_TYPE", 'MSGG' },
{ "B_MESSENGER_TYPE", 'MSNG' },
{ "B_MIME_TYPE", 'MIME' },
{ "B_MONOCHROME_1_BIT_TYPE", 'MNOB' },
{ "B_OBJECT_TYPE", 'OPTR' },
{ "B_OFF_T_TYPE", 'OFFT' },
{ "B_PATTERN_TYPE", 'PATN' },
{ "B_POINTER_TYPE", 'PNTR' },
{ "B_POINT_TYPE", 'BPNT' },
{ "B_RAW_TYPE", 'RAWT' },
{ "B_RECT_TYPE", 'RECT' },
{ "B_REF_TYPE", 'RREF' },
{ "B_RGB_32_BIT_TYPE", 'RGBB' },
{ "B_RGB_COLOR_TYPE", 'RGBC' },
{ "B_SIZE_T_TYPE", 'SIZT' },
{ "B_SSIZE_T_TYPE", 'SSZT' },
{ "B_STRING_TYPE", 'CSTR' },
{ "B_TIME_TYPE", 'TIME' },
{ "B_UINT64_TYPE", 'ULLG' },
{ "B_UINT32_TYPE", 'ULNG' },
{ "B_UINT16_TYPE", 'USHT' },
{ "B_UINT8_TYPE", 'UBYT' },
{ "B_MEDIA_PARAMETER_TYPE", 'BMCT' },
{ "B_MEDIA_PARAMETER_WEB_TYPE", 'BMCW' },
{ "B_MEDIA_PARAMETER_GROUP_TYPE", 'BMCG' },
{ "_DEPRECATED_TYPE_1_", 'PATH' },
// Mime.h
{ "B_MIME_STRING_TYPE", 'MIMS' },
{ "B_META_MIME_CHANGED", 'MMCH' },
// NetPositive.h
{ "B_NETPOSITIVE_OPEN_URL", 'NPOP'},
{ "B_NETPOSITIVE_BACK", 'NPBK' },
{ "B_NETPOSITIVE_FORWARD", 'NPFW' },
{ "B_NETPOSITIVE_HOME", 'NPHM' },
{ "B_NETPOSITIVE_RELOAD", 'NPRL' },
{ "B_NETPOSITIVE_STOP", 'NPST' },
// ParameterWeb.h
{ "B_MEDIA_PARAMETER_TYPE", 'BMCT' },
{ "B_MEDIA_PARAMETER_WEB_TYPE", 'BMCW' },
{ "B_MEDIA_PARAMETER_GROUP_TYPE", 'BMCG' },
// PropertyInfo.h
{ "B_PROPERTY_INFO_TYPE", 'SCTD' },
// ResourceStrings.h
{ "RESOURCE_TYPE", 'CSTR' },
// Roster.h
{ "B_SOME_APP_LAUNCHED", 'BRAS' },
{ "B_SOME_APP_QUIT", 'BRAQ' },
{ "B_SOME_APP_ACTIVATED", 'BRAW' },
// TranslatorFormats.h
{ "B_TRANSLATOR_BITMAP", 'bits' },
{ "B_TRANSLATOR_PICTURE", 'pict' },
{ "B_TRANSLATOR_TEXT", 'TEXT' },
{ "B_TRANSLATOR_SOUND", 'nois' },
{ "B_TRANSLATOR_MIDI", 'midi' },
{ "B_TRANSLATOR_MEDIA", 'mhi!' },
{ "B_TRANSLATOR_NONE", 'none' },
{ "B_GIF_FORMAT", 'GIF ' },
{ "B_JPEG_FORMAT", 'JPEG' },
{ "B_PNG_FORMAT", 'PNG ' },
{ "B_PPM_FORMAT", 'PPM ' },
{ "B_TGA_FORMAT", 'TGA ' },
{ "B_BMP_FORMAT", 'BMP ' },
{ "B_TIFF_FORMAT", 'TIFF' },
{ "B_DXF_FORMAT", 'DXF ' },
{ "B_EPS_FORMAT", 'EPS ' },
{ "B_PICT_FORMAT", 'PICT' },
{ "B_WAV_FORMAT", 'WAV ' },
{ "B_AIFF_FORMAT", 'AIFF' },
{ "B_CD_FORMAT", 'CD ' },
{ "B_AU_FORMAT", 'AU ' },
{ "B_STYLED_TEXT_FORMAT", 'STXT' },
{ "STYLE_HEADER_MAGIC", 'STYL' },
// TranslationUtils.h
{ "B_TRANSLATION_MENU", 'BTMN' },
// USB.h
{ "USB_SUPPORT_DESCRIPTOR", '_USB' },
// MediaDefs.h
{ "B_MEDIA_NODE_CREATED", 'TRIA' },
{ "B_MEDIA_NODE_DELETED", 'TRIB' },
{ "B_MEDIA_CONNECTION_MADE", 'TRIC' },
{ "B_MEDIA_CONNECTION_BROKEN", 'TRID' },
{ "B_MEDIA_BUFFER_CREATED", 'TRIE' },
{ "B_MEDIA_BUFFER_DELETED", 'TRIF' },
{ "B_MEDIA_TRANSPORT_STATE", 'TRIG' },
{ "B_MEDIA_PARAMETER_CHANGED", 'TRIH' },
{ "B_MEDIA_FORMAT_CHANGED", 'TRII' },
{ "B_MEDIA_WEB_CHANGED", 'TRIJ' },
{ "B_MEDIA_DEFAULT_CHANGED", 'TRIK' },
{ NULL, 0 }
};
const char* long_to_string(ulong ulg)
{
static char string[10];
// string[0]=(ulg >> 24) & 0xff;
// string[1]=(ulg >> 16) & 0xff;
// string[2]=(ulg >> 8) & 0xff;
// string[3]=ulg & 0xff;
// string[4]=0;
string[6]=0;
string[0]='\'';
string[1]=(ulg >> 24) & 0xff;
string[2]=(ulg >> 16) & 0xff;
string[3]=(ulg >> 8) & 0xff;
string[4]=ulg & 0xff;
string[5]='\'';
if (!(isprint(string[1]) && isprint(string[2]) && isprint(string[3]) && isprint(string[4])))
sprintf(string, "0x%.8lX", ulg);
return string;
}
ulong string_to_long(void* st)
{
char* string=(char*) st;
ulong ulg;
ulg=string[3]+(string[2] << 8)+(string[1] << 16)+(string[0] << 24);
return ulg;
}
const char* long_to_be_string(ulong type)
{
int k=0;
while (bevalue[k].name!=NULL) {
if (bevalue[k].value==type)
return bevalue[k].name;
k++;
}
return long_to_string(type);
}
-35
View File
@@ -1,35 +0,0 @@
/*
ReadableLong.h
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _READABLE_LONG_H_
#define _READABLE_LONG_H_
#include <SupportDefs.h>
const char* long_to_string(ulong ulg);
ulong string_to_long(void* st);
const char* long_to_be_string(ulong type);
#endif // _READABLE_LONG_H_
+61 -56
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
TeamBarMenu.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,73 +15,85 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <Roster.h>
#include <Bitmap.h>
#include <stdlib.h>
#include "TeamBarMenu.h" #include "TeamBarMenu.h"
#include "ThreadBarMenu.h" #include "ThreadBarMenu.h"
#include "TeamBarMenuItem.h" #include "TeamBarMenuItem.h"
#include "NoiseBarMenuItem.h" #include "NoiseBarMenuItem.h"
#include "PCView.h" #include "ProcessController.h"
#include <Bitmap.h>
#include <Roster.h>
#include <Window.h> #include <Window.h>
#include <stdlib.h>
#define EXTRA 10 #define EXTRA 10
TeamBarMenu::TeamBarMenu (const char *title, infosPack *infos, int32 teamCount)
:BMenu (title), fTeamCount (teamCount+EXTRA), fFirstShow (true) TeamBarMenu::TeamBarMenu(const char* title, info_pack* infos, int32 teamCount)
: BMenu(title),
fTeamCount(teamCount+EXTRA),
fFirstShow(true)
{ {
SetFlags (Flags () | B_PULSE_NEEDED); SetFlags(Flags() | B_PULSE_NEEDED);
fTeamList = (team_id*) malloc (sizeof (team_id) * fTeamCount); fTeamList = (team_id*)malloc(sizeof(team_id) * fTeamCount);
int k; int k;
for (k = 0; k < teamCount; k++) for (k = 0; k < teamCount; k++) {
fTeamList[k] = infos[k].tminfo.team; fTeamList[k] = infos[k].team_info.team;
while (k < fTeamCount) }
while (k < fTeamCount) {
fTeamList[k++] = -1; fTeamList[k++] = -1;
}
fRecycleCount = EXTRA; fRecycleCount = EXTRA;
fRecycleList = (TRecycleItem*) malloc (sizeof (TRecycleItem) * fRecycleCount); fRecycleList = (TRecycleItem*)malloc(sizeof(TRecycleItem) * fRecycleCount);
SetFont (be_plain_font); SetFont(be_plain_font);
gCurrentThreadBarMenu = NULL; gCurrentThreadBarMenu = NULL;
fLastTotalTime = system_time (); fLastTotalTime = system_time();
AddItem (new NoiseBarMenuItem ()); AddItem(new NoiseBarMenuItem());
} }
TeamBarMenu::~TeamBarMenu ()
TeamBarMenu::~TeamBarMenu()
{ {
gCurrentThreadBarMenu = NULL; gCurrentThreadBarMenu = NULL;
free (fTeamList); free(fTeamList);
free (fRecycleList); free(fRecycleList);
} }
void TeamBarMenu::Draw (BRect updateRect)
void
TeamBarMenu::Draw(BRect updateRect)
{ {
BMenu::Draw (updateRect); BMenu::Draw (updateRect);
if (fFirstShow) if (fFirstShow) {
{ Pulse();
Pulse ();
fFirstShow = false; fFirstShow = false;
} }
} }
void TeamBarMenu::Pulse ()
void
TeamBarMenu::Pulse()
{ {
// Window ()->SetPulseRate (50000); Window()->BeginViewTransaction();
Window ()->BeginViewTransaction ();
// create the list of items to remove, for their team is gone. Update the old teams. // create the list of items to remove, for their team is gone. Update the old teams.
int lastRecycle = 0; int lastRecycle = 0;
int firstRecycle = 0; int firstRecycle = 0;
int k; int k;
TeamBarMenuItem *item; TeamBarMenuItem *item;
double total = 0; double total = 0;
for (k = 1; (item = (TeamBarMenuItem*) ItemAt(k)) != NULL; k++) { for (k = 1; (item = (TeamBarMenuItem*)ItemAt(k)) != NULL; k++) {
item->BarUpdate(); item->BarUpdate();
if (item->fKernel < 0) { if (item->fKernel < 0) {
if (lastRecycle == fRecycleCount) { if (lastRecycle == fRecycleCount) {
fRecycleCount += EXTRA; fRecycleCount += EXTRA;
fRecycleList = (TRecycleItem*) realloc(fRecycleList, sizeof(TRecycleItem)*fRecycleCount); fRecycleList = (TRecycleItem*)realloc(fRecycleList,
sizeof(TRecycleItem)*fRecycleCount);
} }
fRecycleList[lastRecycle].index = k; fRecycleList[lastRecycle].index = k;
fRecycleList[lastRecycle++].item = item; fRecycleList[lastRecycle++].item = item;
@@ -100,16 +108,16 @@ void TeamBarMenu::Pulse ()
} }
// Look new teams that have appeared. Create an item for them, or recycle from the list. // Look new teams that have appeared. Create an item for them, or recycle from the list.
int32 cookie = 0; int32 cookie = 0;
infosPack infos; info_pack infos;
item = NULL; item = NULL;
while (get_next_team_info(&cookie, &infos.tminfo) == B_OK) { while (get_next_team_info(&cookie, &infos.team_info) == B_OK) {
int j = 0; int j = 0;
while (j < fTeamCount && infos.tminfo.team != fTeamList[j]) while (j < fTeamCount && infos.team_info.team != fTeamList[j])
j++; j++;
if (infos.tminfo.team != fTeamList[j]) { if (infos.team_info.team != fTeamList[j]) {
// new team // new team
team_info info; team_info info;
j = 0; j = 0;
while (j < fTeamCount && fTeamList[j] != -1) while (j < fTeamCount && fTeamList[j] != -1)
if (get_team_info(fTeamList[j], &info) != B_OK) if (get_team_info(fTeamList[j], &info) != B_OK)
@@ -118,30 +126,31 @@ void TeamBarMenu::Pulse ()
j++; j++;
if (j == fTeamCount) { if (j == fTeamCount) {
fTeamCount += 10; fTeamCount += 10;
fTeamList = (team_id*) realloc(fTeamList, sizeof(team_id)*fTeamCount); fTeamList = (team_id*)realloc(fTeamList, sizeof(team_id)*fTeamCount);
} }
fTeamList[j] = infos.tminfo.team; fTeamList[j] = infos.team_info.team;
if (!get_team_name_and_icon(infos, true)) { if (!get_team_name_and_icon(infos, true)) {
// the team is already gone! // the team is already gone!
delete infos.tmicon; delete infos.team_icon;
fTeamList[j] = -1; fTeamList[j] = -1;
} else { } else {
if (!item && firstRecycle < lastRecycle) { if (!item && firstRecycle < lastRecycle) {
item = fRecycleList[firstRecycle++].item; item = fRecycleList[firstRecycle++].item;
} }
if (item) { if (item) {
item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true); item->Reset(infos.team_name, infos.team_info.team, infos.team_icon, true);
} else { } else {
BMessage* kill_team = new BMessage('KlTm'); BMessage* kill_team = new BMessage('KlTm');
kill_team->AddInt32("team", infos.tminfo.team); kill_team->AddInt32("team", infos.team_info.team);
item = new TeamBarMenuItem(new ThreadBarMenu(infos.tmname, infos.tminfo.team, infos.tminfo.thread_count), item = new TeamBarMenuItem(new ThreadBarMenu(infos.team_name,
kill_team, infos.tminfo.team, infos.tmicon, true); infos.team_info.team, infos.team_info.thread_count),
kill_team, infos.team_info.team, infos.team_icon, true);
item->SetTarget(gPCView); item->SetTarget(gPCView);
AddItem(item); AddItem(item);
item->BarUpdate(); item->BarUpdate();
} }
if (item->fKernel >= 0) { if (item->fKernel >= 0) {
total += item->fUser+item->fKernel; total += item->fUser + item->fKernel;
item = NULL; item = NULL;
} else { } else {
fTeamList[j] = -1; fTeamList[j] = -1;
@@ -161,16 +170,14 @@ void TeamBarMenu::Pulse ()
total /= gCPUcount; total /= gCPUcount;
total = 1-total; total = 1-total;
fLastTotalTime = system_time (); fLastTotalTime = system_time();
NoiseBarMenuItem *noiseItem; NoiseBarMenuItem* noiseItem;
if ((noiseItem = (NoiseBarMenuItem*) ItemAt(0)) != NULL) { if ((noiseItem = (NoiseBarMenuItem*)ItemAt(0)) != NULL) {
noiseItem->fBusyWaiting = 0; noiseItem->fBusyWaiting = 0;
noiseItem->fLost = (total >= 0 ? total : 0); noiseItem->fLost = (total >= 0 ? total : 0);
noiseItem->DrawBar(false); noiseItem->DrawBar(false);
} }
// status_t st;
// if (gCurrentThreadBarMenu && (st = gCurrentThreadBarMenu->LockLooperWithTimeout(50000)) == B_OK) {
if (gCurrentThreadBarMenu && gCurrentThreadBarMenu->LockLooperWithTimeout(25000) == B_OK) { if (gCurrentThreadBarMenu && gCurrentThreadBarMenu->LockLooperWithTimeout(25000) == B_OK) {
gCurrentThreadBarMenu->Window()->BeginViewTransaction(); gCurrentThreadBarMenu->Window()->BeginViewTransaction();
gCurrentThreadBarMenu->Update(); gCurrentThreadBarMenu->Update();
@@ -178,9 +185,7 @@ void TeamBarMenu::Pulse ()
gCurrentThreadBarMenu->Window()->Flush(); gCurrentThreadBarMenu->Window()->Flush();
gCurrentThreadBarMenu->UnlockLooper(); gCurrentThreadBarMenu->UnlockLooper();
} }
// else
// if (st == B_TIMED_OUT)
// beep();
Window()->EndViewTransaction(); Window()->EndViewTransaction();
Window()->Flush(); Window()->Flush();
} }
+18 -21
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
TeamBarMenu.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,16 +15,16 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _TEAM_BAR_MENU_H_ #ifndef _TEAM_BAR_MENU_H_
#define _TEAM_BAR_MENU_H_ #define _TEAM_BAR_MENU_H_
#include "PCUtils.h"
#include "Utilities.h"
#include <Menu.h> #include <Menu.h>
class TeamBarMenuItem; class TeamBarMenuItem;
typedef struct { typedef struct {
@@ -36,20 +32,21 @@ typedef struct {
int index; int index;
} TRecycleItem; } TRecycleItem;
class TeamBarMenu : public BMenu
{
public:
TeamBarMenu(const char *title, infosPack *infos, int32 teamCount);
virtual ~TeamBarMenu();
virtual void Draw (BRect updateRect);
virtual void Pulse();
team_id* fTeamList; class TeamBarMenu : public BMenu {
int fTeamCount; public:
TRecycleItem* fRecycleList; TeamBarMenu(const char* title, info_pack* infos, int32 teamCount);
int fRecycleCount; virtual ~TeamBarMenu();
bigtime_t fLastTotalTime;
bool fFirstShow; virtual void Draw(BRect updateRect);
virtual void Pulse();
team_id* fTeamList;
int fTeamCount;
TRecycleItem* fRecycleList;
int fRecycleCount;
bigtime_t fLastTotalTime;
bool fFirstShow;
}; };
#endif // _TEAM_BAR_MENU_H_ #endif // _TEAM_BAR_MENU_H_
+69 -50
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
TeamBarMenuItem.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,55 +15,64 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCView.h"
#include "TeamBarMenuItem.h" #include "TeamBarMenuItem.h"
#include "Colors.h"
#include "ProcessController.h"
#include "ThreadBarMenu.h" #include "ThreadBarMenu.h"
#include "ThreadBarMenuItem.h" #include "ThreadBarMenuItem.h"
#include "Colors.h"
#include <Bitmap.h> #include <Bitmap.h>
#define B_USAGE_SELF 0 #define B_USAGE_SELF 0
// --------------------------------------------------------------
TeamBarMenuItem::TeamBarMenuItem(BMenu *menu, BMessage *kill_team, team_id team, BBitmap* icon, bool DeleteIcon) TeamBarMenuItem::TeamBarMenuItem(BMenu *menu, BMessage *kill_team, team_id team,
:BMenuItem(menu, kill_team), fTeamID(team), fIcon(icon), fDeleteIcon(DeleteIcon) BBitmap* icon, bool deleteIcon)
: BMenuItem(menu, kill_team),
fTeamID(team),
fIcon(icon),
fDeleteIcon(deleteIcon)
{ {
Init(); Init();
} }
// --------------------------------------------------------------
void TeamBarMenuItem::Init() void
TeamBarMenuItem::Init()
{ {
team_info tminfo; team_info tminfo;
get_team_info(fTeamID, &tminfo); get_team_info(fTeamID, &tminfo);
get_team_usage_info(fTeamID, B_USAGE_SELF, &fTeamUsageInfo); get_team_usage_info(fTeamID, B_USAGE_SELF, &fTeamUsageInfo);
if (fTeamID == B_SYSTEM_TEAM) { if (fTeamID == B_SYSTEM_TEAM) {
thread_info thinfos; thread_info thinfos;
bigtime_t idle = 0; bigtime_t idle = 0;
for (int t = 1; t <= gCPUcount; t++) for (int t = 1; t <= gCPUcount; t++)
if (get_thread_info(t, &thinfos) == B_OK) if (get_thread_info(t, &thinfos) == B_OK)
idle += thinfos.kernel_time + thinfos.user_time; idle += thinfos.kernel_time + thinfos.user_time;
fTeamUsageInfo.kernel_time += fTeamUsageInfo.user_time; fTeamUsageInfo.kernel_time += fTeamUsageInfo.user_time;
fTeamUsageInfo.user_time = idle; fTeamUsageInfo.user_time = idle;
} }
fLastTime = system_time(); fLastTime = system_time();
fKernel = -1; fKernel = -1;
fGrenze1 = -1; fGrenze1 = -1;
fGrenze2 = -1; fGrenze2 = -1;
} }
// --------------------------------------------------------------
TeamBarMenuItem::~TeamBarMenuItem() TeamBarMenuItem::~TeamBarMenuItem()
{ {
if (fDeleteIcon) if (fDeleteIcon)
delete fIcon; delete fIcon;
} }
// --------------------------------------------------------------
void TeamBarMenuItem::DrawContent() void
TeamBarMenuItem::DrawContent()
{ {
BPoint loc; BPoint loc;
@@ -82,45 +87,50 @@ void TeamBarMenuItem::DrawContent()
BMenuItem::DrawContent(); BMenuItem::DrawContent();
} }
// --------------------------------------------------------------
void TeamBarMenuItem::DrawIcon()
{
BPoint loc;
loc = ContentLocation(); void
BRect frame = Frame(); TeamBarMenuItem::DrawIcon()
{
BPoint loc = ContentLocation();
BRect frame = Frame();
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2; loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
BMenu* menu = Menu ();
BMenu* menu = Menu ();
menu->SetDrawingMode(B_OP_OVER); menu->SetDrawingMode(B_OP_OVER);
if (fIcon) if (fIcon)
menu->DrawBitmap(fIcon, loc); menu->DrawBitmap(fIcon, loc);
} }
// --------------------------------------------------------------
void TeamBarMenuItem::DrawBar(bool force) void
TeamBarMenuItem::DrawBar(bool force)
{ {
bool selected = IsSelected (); bool selected = IsSelected ();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu (); BMenu* menu = Menu ();
frame.right -= 24; frame.right -= 24;
frame.left = frame.right-kBarWidth; frame.left = frame.right-kBarWidth;
frame.top += 5; frame.top += 5;
frame.bottom = frame.top+8; frame.bottom = frame.top+8;
if (fKernel < 0) if (fKernel < 0)
return; return;
if (fGrenze1 < 0) if (fGrenze1 < 0)
force = true; force = true;
if (force) { if (force) {
if (selected) if (selected)
menu->SetHighColor (gFrameColorSelected); menu->SetHighColor(gFrameColorSelected);
else else
menu->SetHighColor (gFrameColor); menu->SetHighColor(gFrameColor);
menu->StrokeRect(frame); menu->StrokeRect(frame);
} }
frame.InsetBy(1, 1); frame.InsetBy(1, 1);
BRect r = frame; BRect r = frame;
float grenze1 = frame.left+(frame.right-frame.left)*fKernel/gCPUcount; float grenze1 = frame.left+(frame.right-frame.left)*fKernel/gCPUcount;
float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser)/gCPUcount; float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser)/gCPUcount;
if (grenze1 > frame.right) if (grenze1 > frame.right)
grenze1 = frame.right; grenze1 = frame.right;
if (grenze2 > frame.right) if (grenze2 > frame.right)
@@ -130,44 +140,51 @@ void TeamBarMenuItem::DrawBar(bool force)
r.left = fGrenze1; r.left = fGrenze1;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor (gKernelColorSelected); menu->SetHighColor(gKernelColorSelected);
else else
menu->SetHighColor (gKernelColor); menu->SetHighColor(gKernelColor);
menu->FillRect(r); menu->FillRect(r);
} }
r.left = grenze1; r.left = grenze1;
r.right = grenze2; r.right = grenze2;
if (!force) { if (!force) {
if (fGrenze2 > r.left && r.left >= fGrenze1) if (fGrenze2 > r.left && r.left >= fGrenze1)
r.left = fGrenze2; r.left = fGrenze2;
if (fGrenze1 < r.right && r.right <= fGrenze2) if (fGrenze1 < r.right && r.right <= fGrenze2)
r.right = fGrenze1; r.right = fGrenze1;
} }
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColorSelected : gUserColorSelected); menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColorSelected : gUserColorSelected);
else else
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColor : gUserColor); menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColor : gUserColor);
menu->FillRect (r); menu->FillRect(r);
} }
r.left = grenze2; r.left = grenze2;
r.right = frame.right; r.right = frame.right;
if (!force) if (!force)
r.right = fGrenze2; r.right = fGrenze2;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor (gWhiteSelected); menu->SetHighColor(gWhiteSelected);
else else
menu->SetHighColor (kWhite); menu->SetHighColor(kWhite);
menu->FillRect (r); menu->FillRect(r);
} }
menu->SetHighColor (kBlack);
menu->SetHighColor(kBlack);
fGrenze1 = grenze1; fGrenze1 = grenze1;
fGrenze2 = grenze2; fGrenze2 = grenze2;
} }
// --------------------------------------------------------------
void TeamBarMenuItem::GetContentSize(float* width, float* height) void
TeamBarMenuItem::GetContentSize(float* width, float* height)
{ {
BMenuItem::GetContentSize(width, height); BMenuItem::GetContentSize(width, height);
if (*height < 16) if (*height < 16)
@@ -175,13 +192,14 @@ void TeamBarMenuItem::GetContentSize(float* width, float* height)
*width += 40+kBarWidth; *width += 40+kBarWidth;
} }
// --------------------------------------------------------------
void TeamBarMenuItem::BarUpdate() void
TeamBarMenuItem::BarUpdate()
{ {
team_usage_info usage; team_usage_info usage;
if (get_team_usage_info(fTeamID, B_USAGE_SELF, &usage) == B_OK) { if (get_team_usage_info(fTeamID, B_USAGE_SELF, &usage) == B_OK) {
bigtime_t now = system_time(); bigtime_t now = system_time();
bigtime_t idle = 0; bigtime_t idle = 0;
if (fTeamID == B_SYSTEM_TEAM) { if (fTeamID == B_SYSTEM_TEAM) {
thread_info thinfos; thread_info thinfos;
for (int t = 1; t <= gCPUcount; t++) for (int t = 1; t <= gCPUcount; t++)
@@ -202,15 +220,16 @@ void TeamBarMenuItem::BarUpdate()
fKernel = -1; fKernel = -1;
} }
// --------------------------------------------------------------
void TeamBarMenuItem::Reset(char* name, team_id team, BBitmap* icon, bool DeleteIcon) void
TeamBarMenuItem::Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon)
{ {
SetLabel(name); SetLabel(name);
fTeamID = team; fTeamID = team;
Init(); Init();
if (fDeleteIcon) if (fDeleteIcon)
delete fIcon; delete fIcon;
fDeleteIcon = DeleteIcon; fDeleteIcon = deleteIcon;
fIcon = icon; fIcon = icon;
Message()->ReplaceInt32("team", team); Message()->ReplaceInt32("team", team);
((ThreadBarMenu*) Submenu())->Reset(team); ((ThreadBarMenu*) Submenu())->Reset(team);
+11 -15
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
TeamBarMenuItem.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,34 +15,34 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _TEAM_BAR_MENU_ITEM_H_ #ifndef _TEAM_BAR_MENU_ITEM_H_
#define _TEAM_BAR_MENU_ITEM_H_ #define _TEAM_BAR_MENU_ITEM_H_
#include <MenuItem.h> #include <MenuItem.h>
class BBitmap; class BBitmap;
//---------------------------------------------------------------
class TeamBarMenuItem : public BMenuItem { class TeamBarMenuItem : public BMenuItem {
public:
TeamBarMenuItem(BMenu *menu, BMessage *kill_team,
team_id team, BBitmap* icon, bool deleteIcon);
virtual ~TeamBarMenuItem();
public: virtual void DrawContent();
TeamBarMenuItem(BMenu *menu, BMessage *kill_team, team_id team, BBitmap* icon, bool DeleteIcon); virtual void GetContentSize(float* width, float* height);
virtual ~TeamBarMenuItem();
virtual void DrawContent();
virtual void GetContentSize(float* width, float* height);
void DrawIcon(); void DrawIcon();
void DrawBar(bool force); void DrawBar(bool force);
void BarUpdate(); void BarUpdate();
void Init(); void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool DeleteIcon); void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
double fUser; double fUser;
double fKernel; double fKernel;
private: private:
team_id fTeamID; team_id fTeamID;
BBitmap* fIcon; BBitmap* fIcon;
team_usage_info fTeamUsageInfo; team_usage_info fTeamUsageInfo;
+35 -21
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
ThreadBarMenu.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,28 +15,33 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "ThreadBarMenu.h" #include "ThreadBarMenu.h"
#include "ThreadBarMenuItem.h"
#include "PriorityMenu.h" #include "PriorityMenu.h"
#include "PCView.h" #include "ProcessController.h"
#include "ThreadBarMenuItem.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#define EXTRA 20 #define EXTRA 20
ThreadBarMenu::ThreadBarMenu(const char *title, team_id team, int32 thread_count):
BMenu(title), fThreadsRecCount(thread_count+EXTRA), fTeam(team) ThreadBarMenu::ThreadBarMenu(const char *title, team_id team, int32 threadCount)
: BMenu(title),
fThreadsRecCount(threadCount + EXTRA),
fTeam(team)
{ {
SetFont(be_plain_font); SetFont(be_plain_font);
fThreadsRec = (ThreadRec*) malloc(sizeof(ThreadRec)*fThreadsRecCount); fThreadsRec = (ThreadRec*) malloc(sizeof(ThreadRec) * fThreadsRecCount);
Init(); Init();
fRound = 0; // for syslog fRound = 0; // for syslog
AddNew(); AddNew();
} }
ThreadBarMenu::~ThreadBarMenu() ThreadBarMenu::~ThreadBarMenu()
{ {
free(fThreadsRec); free(fThreadsRec);
@@ -48,37 +49,47 @@ ThreadBarMenu::~ThreadBarMenu()
gCurrentThreadBarMenu = NULL; gCurrentThreadBarMenu = NULL;
} }
void ThreadBarMenu::Init()
void
ThreadBarMenu::Init()
{ {
int k = 0; int k = 0;
while (k < fThreadsRecCount) while (k < fThreadsRecCount)
fThreadsRec[k++].thread = -1; fThreadsRec[k++].thread = -1;
fRound = 1; fRound = 1;
} }
void ThreadBarMenu::Reset(team_id team)
void
ThreadBarMenu::Reset(team_id team)
{ {
fTeam = team; fTeam = team;
RemoveItems(0, CountItems(), true); RemoveItems(0, CountItems(), true);
Init(); Init();
} }
void ThreadBarMenu::AttachedToWindow()
void
ThreadBarMenu::AttachedToWindow()
{ {
BMenu::AttachedToWindow(); BMenu::AttachedToWindow();
} }
void ThreadBarMenu::Draw(BRect r)
void
ThreadBarMenu::Draw(BRect r)
{ {
gCurrentThreadBarMenu = this; gCurrentThreadBarMenu = this;
BMenu::Draw(r); BMenu::Draw(r);
} }
void ThreadBarMenu::AddNew()
void
ThreadBarMenu::AddNew()
{ {
thread_info info; thread_info info;
int32 cookie = 0; int32 cookie = 0;
int32 k = 0; int32 k = 0;
while (get_next_thread_info(fTeam, &cookie, &info) == B_OK) { while (get_next_thread_info(fTeam, &cookie, &info) == B_OK) {
int lastk = k; int lastk = k;
while (k < fThreadsRecCount && fThreadsRec[k].thread != info.thread) while (k < fThreadsRecCount && fThreadsRec[k].thread != info.thread)
@@ -118,12 +129,15 @@ void ThreadBarMenu::AddNew()
fRound++; fRound++;
} }
void ThreadBarMenu::Update()
void
ThreadBarMenu::Update()
{ {
AddNew(); AddNew();
int32 k, del; int32 k, del;
del = -1; del = -1;
ThreadBarMenuItem *item; ThreadBarMenuItem *item;
for (k = 0; (item = (ThreadBarMenuItem*) ItemAt(k)) != NULL; k++) { for (k = 0; (item = (ThreadBarMenuItem*) ItemAt(k)) != NULL; k++) {
item->BarUpdate(); item->BarUpdate();
item->DrawBar(false); item->DrawBar(false);
+14 -19
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
ThreadBarMenu.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,32 +15,31 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _THREAD_BAR_MENU_H_ #ifndef _THREAD_BAR_MENU_H_
#define _THREAD_BAR_MENU_H_ #define _THREAD_BAR_MENU_H_
#include <Menu.h> #include <Menu.h>
typedef struct { typedef struct {
thread_id thread; thread_id thread;
int last_round; int last_round;
} ThreadRec; } ThreadRec;
class ThreadBarMenu : public BMenu class ThreadBarMenu : public BMenu {
{ public:
public: ThreadBarMenu(const char *title, team_id team, int32 threadCount);
ThreadBarMenu (const char *title, team_id team, int32 thread_count); virtual ~ThreadBarMenu();
virtual ~ThreadBarMenu (); virtual void AttachedToWindow();
virtual void AttachedToWindow (); virtual void Draw(BRect updateRect);
virtual void Draw (BRect updateRect); void AddNew();
void AddNew (); void Update();
void Update (); void Init();
void Init (); void Reset(team_id team);
void Reset (team_id team);
private: private:
ThreadRec* fThreadsRec; ThreadRec* fThreadsRec;
int fThreadsRecCount; int fThreadsRecCount;
team_id fTeam; team_id fTeam;
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
ThreadBarMenuItem.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,19 +15,20 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCView.h"
#include "ThreadBarMenuItem.h" #include "ThreadBarMenuItem.h"
#include "PriorityMenu.h"
#include "Colors.h" #include "Colors.h"
#include "PCView.h" #include "PriorityMenu.h"
#include "ProcessController.h"
#include <stdio.h> #include <stdio.h>
// --------------------------------------------------------------
ThreadBarMenuItem::ThreadBarMenuItem(const char* title, thread_id thread, BMenu *menu, BMessage* msg) ThreadBarMenuItem::ThreadBarMenuItem(const char* title, thread_id thread,
:BMenuItem(menu, msg), fThreadID(thread) BMenu *menu, BMessage* msg)
: BMenuItem(menu, msg), fThreadID(thread)
{ {
SetLabel(title); SetLabel(title);
get_thread_info(fThreadID, &fThreadInfo); get_thread_info(fThreadID, &fThreadInfo);
@@ -41,8 +38,9 @@ ThreadBarMenuItem::ThreadBarMenuItem(const char* title, thread_id thread, BMenu
fGrenze2 = -1; fGrenze2 = -1;
} }
// --------------------------------------------------------------
void ThreadBarMenuItem::DrawContent() void
ThreadBarMenuItem::DrawContent()
{ {
if (fKernel < 0) if (fKernel < 0)
BarUpdate(); BarUpdate();
@@ -51,12 +49,13 @@ void ThreadBarMenuItem::DrawContent()
BMenuItem::DrawContent(); BMenuItem::DrawContent();
} }
// --------------------------------------------------------------
void ThreadBarMenuItem::DrawBar(bool force) void
ThreadBarMenuItem::DrawBar(bool force)
{ {
bool selected = IsSelected (); bool selected = IsSelected();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu (); BMenu* menu = Menu();
frame.right -= 24; frame.right -= 24;
frame.left = frame.right-kBarWidth; frame.left = frame.right-kBarWidth;
frame.top += 3; frame.top += 3;
@@ -73,9 +72,9 @@ void ThreadBarMenuItem::DrawBar(bool force)
menu->StrokeRect(frame); menu->StrokeRect(frame);
} }
frame.InsetBy(1, 1); frame.InsetBy(1, 1);
BRect r = frame; BRect r = frame;
float grenze1 = frame.left+(frame.right-frame.left)*fKernel; float grenze1 = frame.left+(frame.right-frame.left)*fKernel;
float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser); float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser);
if (grenze1 > frame.right) if (grenze1 > frame.right)
grenze1 = frame.right; grenze1 = frame.right;
if (grenze2 > frame.right) if (grenze2 > frame.right)
@@ -121,8 +120,9 @@ void ThreadBarMenuItem::DrawBar(bool force)
fGrenze2 = grenze2; fGrenze2 = grenze2;
} }
// --------------------------------------------------------------
void ThreadBarMenuItem::GetContentSize(float* width, float* height) void
ThreadBarMenuItem::GetContentSize(float* width, float* height)
{ {
BMenuItem::GetContentSize(width, height); BMenuItem::GetContentSize(width, height);
// if (*height < 16) // if (*height < 16)
@@ -130,8 +130,9 @@ void ThreadBarMenuItem::GetContentSize(float* width, float* height)
*width += 10+kBarWidth; *width += 10+kBarWidth;
} }
// --------------------------------------------------------------
void ThreadBarMenuItem::Highlight(bool on) void
ThreadBarMenuItem::Highlight(bool on)
{ {
if (on) { if (on) {
PriorityMenu * popup = (PriorityMenu *) Submenu (); PriorityMenu * popup = (PriorityMenu *) Submenu ();
@@ -141,12 +142,13 @@ void ThreadBarMenuItem::Highlight(bool on)
BMenuItem::Highlight (on); BMenuItem::Highlight (on);
} }
// --------------------------------------------------------------
void ThreadBarMenuItem::BarUpdate() void
ThreadBarMenuItem::BarUpdate()
{ {
thread_info info; thread_info info;
if (get_thread_info(fThreadID, &info) == B_OK) { if (get_thread_info(fThreadID, &info) == B_OK) {
bigtime_t now = system_time(); bigtime_t now = system_time();
fKernel = double(info.kernel_time-fThreadInfo.kernel_time)/double(now-fLastTime); fKernel = double(info.kernel_time-fThreadInfo.kernel_time)/double(now-fLastTime);
fUser = double(info.user_time-fThreadInfo.user_time)/double(now-fLastTime); fUser = double(info.user_time-fThreadInfo.user_time)/double(now-fLastTime);
if (fThreadID <= gCPUcount) { if (fThreadID <= gCPUcount) {
+12 -17
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
ThreadBarMenuItem.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,29 +15,29 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _THREAD_BAR_MENU_ITEM_H_ #ifndef _THREAD_BAR_MENU_ITEM_H_
#define _THREAD_BAR_MENU_ITEM_H_ #define _THREAD_BAR_MENU_ITEM_H_
#include <MenuItem.h> #include <MenuItem.h>
//---------------------------------------------------------------
class ThreadBarMenuItem : public BMenuItem { class ThreadBarMenuItem : public BMenuItem {
public:
ThreadBarMenuItem(const char* title, thread_id thread,
BMenu* menu, BMessage* msg);
virtual void DrawContent();
virtual void GetContentSize(float* width, float* height);
virtual void Highlight(bool on);
void DrawBar(bool force);
void BarUpdate();
public:
ThreadBarMenuItem (const char* title, thread_id thread, BMenu *menu, BMessage* msg);
virtual void DrawContent ();
virtual void GetContentSize (float* width, float* height);
virtual void Highlight(bool on);
void DrawBar (bool force);
void BarUpdate ();
double fUser; double fUser;
double fKernel; double fKernel;
private: private:
thread_id fThreadID; thread_id fThreadID;
thread_info fThreadInfo; thread_info fThreadInfo;
bigtime_t fLastTime; bigtime_t fLastTime;
@@ -50,4 +46,3 @@ private:
}; };
#endif // _THREAD_BAR_MENU_ITEM_H_ #endif // _THREAD_BAR_MENU_ITEM_H_
-160
View File
@@ -1,160 +0,0 @@
/*
URLView.cpp
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "URLView.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Roster.h>
#include "Colors.h"
URLView::URLView(BRect frame, const char* url)
: BView(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW)
{
if (url == NULL)
url = "http://www.be.com";
fUrl = strdup (url);
}
URLView::~URLView()
{
free (fUrl);
}
void URLView::AttachedToWindow()
{
rgb_color back = ui_color(B_PANEL_BACKGROUND_COLOR);
SetViewColor (back);
SetLowColor (back);
SetHighColor (kBlue);
SetFont (be_plain_font);
font_height height;
GetFontHeight (&height);
float width = StringWidth (fUrl);
float r = width + 8;
BRect frame = Frame ();
BRect nframe = frame;
if (frame.right == frame.left)
nframe.right = nframe.left + r - 4;
else if (frame.right == 0)
{
nframe.left -= r/2;
nframe.right = nframe.left + r;
}
if (frame.bottom == 0)
nframe.bottom = frame.top + height.ascent + height.descent + 2;
if (frame.left != nframe.left || frame.top != nframe.top)
MoveTo (nframe.left, nframe.top);
if (frame.Width () != nframe.Width () || frame.Height () != nframe.Height ())
ResizeTo (nframe.Width (), nframe.Height ());
fLocation.x = ceil ((nframe.Width () - width) / 2) + 1;
fLocation.y = floor ((nframe.Height () + height.ascent - height.descent) / 2);
}
void URLView::Draw (BRect /*updateRect*/)
{
DrawString (fUrl, fLocation);
}
void URLView::MouseDown (BPoint /*where*/)
{
BPoint pos;
uint32 buttons;
BRect bounds = Bounds ();
bool inside = true;
InvertRect (bounds);
do
{
snooze (5000);
GetMouse (&pos, &buttons);
bool now = bounds.Contains (pos);
if (now != inside)
{
InvertRect (bounds);
Flush ();
inside = now;
}
} while (buttons != 0);
if (bounds.Contains (pos))
OpenURL ();
if (inside)
InvertRect (bounds);
}
void URLView::OpenURL ()
{
char* argv[2];
argv[0] = fUrl;
argv[1] = 0;
be_roster->Launch ("text/html", 1, argv);
}
mailtoView::mailtoView (BRect frame, const char* email, const char* subject, const char* texte)
: URLView (frame, email)
{
if (subject)
fSubject = strdup (subject);
else
fSubject = NULL;
if (texte)
fTexte = strdup (texte);
else
fTexte = NULL;
}
mailtoView::~mailtoView()
{
if (fSubject)
free (fSubject);
if (fTexte)
free (fTexte);
}
void mailtoView::OpenURL ()
{
int total = 7;
char** argv = new char*[total];
memset (argv, 0, total * sizeof (char*));
argv[0] = "email";
int argc = 0;
if (fUrl)
{
char email[256];
strcpy (email, "mailto:");
strcat (email, fUrl);
argv[++argc] = email;
}
if (fSubject)
{
argv[++argc] = "-subject";
argv[++argc] = fSubject;
}
if (fTexte)
{
argv[++argc] = "-body";
argv[++argc] = fTexte;
}
argv[++argc] = 0;
be_roster->Launch ("text/x-email", argc, argv);
}
-56
View File
@@ -1,56 +0,0 @@
/*
URLView.h
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _URLVIEW_H_
#define _URLVIEW_H_
#include <View.h>
class URLView : public BView {
public:
URLView (BRect frame, const char* url);
~URLView ();
virtual void AttachedToWindow ();
virtual void Draw (BRect updateRect);
virtual void MouseDown (BPoint where);
virtual void OpenURL ();
protected:
char* fUrl;
BPoint fLocation;
};
class mailtoView : public URLView {
public:
mailtoView (BRect frame, const char* email, const char* subject = NULL, const char* texte = NULL);
~mailtoView ();
virtual void OpenURL ();
protected:
char* fSubject;
char* fTexte;
};
#endif // _URLVIEW_H_
+176
View File
@@ -0,0 +1,176 @@
/*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Utilities.h"
#include "PCWorld.h"
#include "ProcessController.h"
#include "icons.h"
#include <Alert.h>
#include <Bitmap.h>
#include <Deskbar.h>
#include <FindDirectory.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
#include <Window.h>
#include <stdio.h>
#include <string.h>
bool
get_team_name_and_icon(info_pack& infoPack, bool icon)
{
BPath systemPath;
find_directory(B_BEOS_SYSTEM_DIRECTORY, &systemPath);
bool nameFromArgs = false;
bool tryTrackerIcon = true;
for (int len = strlen(infoPack.team_info.args) - 1;
len >= 0 && infoPack.team_info.args[len] == ' '; len--) {
infoPack.team_info.args[len] = 0;
}
app_info info;
status_t status = be_roster->GetRunningAppInfo(infoPack.team_info.team, &info);
if (status == B_OK || infoPack.team_info.team == B_SYSTEM_TEAM) {
if (infoPack.team_info.team == B_SYSTEM_TEAM) {
// Get icon and name from kernel
system_info systemInfo;
get_system_info(&systemInfo);
BPath kernelPath(systemPath);
kernelPath.Append(systemInfo.kernel_name);
get_ref_for_path(kernelPath.Path(), &info.ref);
nameFromArgs = true;
}
} else {
BEntry entry(infoPack.team_info.args, true);
status = entry.GetRef(&info.ref);
if (status != B_OK
|| strncmp(infoPack.team_info.args, systemPath.Path(), strlen(systemPath.Path())) != 0)
nameFromArgs = true;
tryTrackerIcon = (status == B_OK);
}
strncpy(infoPack.team_name, nameFromArgs ? infoPack.team_info.args : info.ref.name,
B_PATH_NAME_LENGTH - 1);
if (icon) {
infoPack.team_icon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT);
if (!tryTrackerIcon || BNodeInfo::GetTrackerIcon(&info.ref, infoPack.team_icon, B_MINI_ICON) != B_OK)
infoPack.team_icon->SetBits(k_app_mini, 256, 0, B_COLOR_8_BIT);
} else
infoPack.team_icon = NULL;
return true;
}
bool
launch(const char* signature, const char* path)
{
status_t status = be_roster->Launch(signature);
if (status != B_OK && path) {
entry_ref ref;
if (get_ref_for_path(path, &ref) == B_OK)
status = be_roster->Launch(&ref);
}
return status == B_OK;
}
void
mix_colors(rgb_color &target, rgb_color & first, rgb_color & second, float mix)
{
target.red = (uint8)(second.red * mix + (1. - mix) * first.red);
target.green = (uint8)(second.green * mix + (1. - mix) * first.green);
target.blue = (uint8)(second.blue * mix + (1. - mix) * first.blue);
target.alpha = (uint8)(second.alpha * mix + (1. - mix) * first.alpha);
}
void
find_self(entry_ref& ref)
{
int32 cookie = 0;
image_info info;
while (get_next_image_info (0, &cookie, &info) == B_OK) {
if (((uint32)info.text <= (uint32)move_to_deskbar
&& (uint32)info.text + (uint32)info.text_size > (uint32)move_to_deskbar)
|| ((uint32)info.data <= (uint32)move_to_deskbar
&& (uint32)info.data + (uint32)info.data_size > (uint32)move_to_deskbar)) {
if (get_ref_for_path (info.name, &ref) == B_OK)
return;
}
}
// This works, but not always... :(
app_info appInfo;
be_roster->GetAppInfo(kSignature, &appInfo);
ref = appInfo.ref;
}
void
move_to_deskbar(BDeskbar& deskbar)
{
entry_ref ref;
find_self(ref);
deskbar.AddItem(&ref);
}
void
make_window_visible(BWindow* window, bool mayResize)
{
uint32 flags = window->Flags();
BRect screen = BScreen(window).Frame();
BRect frame = window->Frame();
screen.InsetBy(4, 8);
screen.OffsetBy(0, 8);
if (mayResize) {
float width = frame.Width();
float height = frame.Height();
if (screen.Width() < width && !(flags & B_NOT_H_RESIZABLE))
width = screen.Width();
if (screen.Height() < height && !(flags & B_NOT_V_RESIZABLE))
height = screen.Height();
if (width != frame.Width() || height != frame.Height()) {
window->ResizeTo(width, height);
frame.right = frame.left + width;
frame.bottom = frame.top + height;
}
}
if (frame.right > screen.right)
window->MoveBy(screen.right-frame.right, 0);
if (frame.bottom > screen.bottom)
window->MoveBy(0, screen.bottom-frame.bottom);
if (frame.left < screen.left)
window->MoveTo(screen.left, frame.top);
if (frame.top < screen.top)
window->MoveBy(0, screen.top-frame.top);
}
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
PCUtils.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,33 +15,35 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UTILITIES_H
#define UTILITIES_H
#ifndef _PCUTILS_H_
#define _PCUTILS_H_
#include <OS.h> #include <OS.h>
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
class BDeskbar; class BDeskbar;
class BBitmap; class BBitmap;
class BWindow;
struct entry_ref; struct entry_ref;
typedef struct { typedef struct {
team_info tminfo; ::team_info team_info;
BBitmap *tmicon; BBitmap* team_icon;
char tmname[B_PATH_NAME_LENGTH]; char team_name[B_PATH_NAME_LENGTH];
thread_info *thinfo; ::thread_info* thread_info;
} infosPack; } info_pack;
bool get_team_name_and_icon(infosPack &infopack, bool icon = false); bool get_team_name_and_icon(info_pack& infoPack, bool icon = false);
bool launch (const char* mime, const char* path); bool launch(const char* mime, const char* path);
void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float mix); void mix_colors(rgb_color& target, rgb_color& first, rgb_color& second, float mix);
void find_self (entry_ref & ref); void find_self(entry_ref& ref);
void move_to_deskbar (BDeskbar & db); void move_to_deskbar(BDeskbar& deskbar);
void make_window_visible(BWindow* window, bool mayResize = false);
extern const uchar k_cpu_mini[]; extern const uchar k_cpu_mini[];
extern const uchar k_app_mini[]; extern const uchar k_app_mini[];
#endif // _PCUTILS_H_ #endif // UTILITIES_H
@@ -1,59 +0,0 @@
/*
WindowsTools.cpp
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "WindowsTools.h"
#include <Screen.h>
#include <Window.h>
_EXPORT void visible_window (BWindow* window, bool mayResize)
{
uint32 flags = window->Flags ();
BRect screen = BScreen (window).Frame ();
BRect frame = window->Frame ();
screen.InsetBy (4, 8);
screen.OffsetBy (0, 8);
if (mayResize)
{
float width = frame.Width ();
float height = frame.Height ();
if (screen.Width () < width && !(flags & B_NOT_H_RESIZABLE))
width = screen.Width ();
if (screen.Height () < height && !(flags & B_NOT_V_RESIZABLE))
height = screen.Height ();
if (width != frame.Width () || height != frame.Height ())
{
window->ResizeTo (width, height);
frame.right = frame.left + width;
frame.bottom = frame.top + height;
}
}
if (frame.right > screen.right)
window->MoveBy (screen.right-frame.right, 0);
if (frame.bottom > screen.bottom)
window->MoveBy (0, screen.bottom-frame.bottom);
if (frame.left < screen.left)
window->MoveTo (screen.left, frame.top);
if (frame.top < screen.top)
window->MoveBy (0, screen.top-frame.top);
}
-33
View File
@@ -1,33 +0,0 @@
/*
WindowsTools.h
ProcessController
(c) 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WINDOWS_TOOLS_H_
#define _WINDOWS_TOOLS_H_
#include "Colors.h"
class BWindow;
void visible_window(BWindow* window, bool mayResize = false);
#endif // _WINDOWS_TOOLS_H_
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
icons.data
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
const uchar k_app_mini[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, const uchar k_app_mini[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,