Imported ProcessController from BeUnited's CVS into our repository.
Doesn't compile yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17568 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
48f09a2bd2
commit
ed7a35012e
@ -16,6 +16,7 @@ SubInclude HAIKU_TOP src apps mediaplayer ;
|
||||
SubInclude HAIKU_TOP src apps midiplayer ;
|
||||
SubInclude HAIKU_TOP src apps people ;
|
||||
SubInclude HAIKU_TOP src apps poorman ;
|
||||
SubInclude HAIKU_TOP src apps processcontroller ;
|
||||
SubInclude HAIKU_TOP src apps pulse ;
|
||||
SubInclude HAIKU_TOP src apps showimage ;
|
||||
SubInclude HAIKU_TOP src apps soundrecorder ;
|
||||
|
121
src/apps/processcontroller/AboutPC.cpp
Normal file
121
src/apps/processcontroller/AboutPC.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
AboutPC.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 "PCWorld.h"
|
||||
#include "AboutPC.h"
|
||||
#include "WindowsTools.h"
|
||||
#include <Button.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Mime.h>
|
||||
#include <stdio.h>
|
||||
#include "URLView.h"
|
||||
|
||||
const char* kProgramName = "ProcessController 3.1.1";
|
||||
const char* SendTexte = "Send your bug reports & comments to:";
|
||||
|
||||
const char* kAboutProgramName = "ProcessController";
|
||||
const char* kAboutEmail = "contact@beuntied.org";
|
||||
//const char* kAboutEmail = "berenger@francenet.fr";
|
||||
//const char* kAboutWeb = "http://home.foni.net/~berenger/";
|
||||
//const char* kAboutWeb = "http://stv.steinberg.de/~georges/besoft/";
|
||||
const char* kAboutWeb = "http://www.beunited.org/index.php?page=developer";
|
||||
|
||||
AboutPC::AboutPC(BRect r):BWindow(CenterRect(r, 530, 200), B_EMPTY_STRING,
|
||||
B_MODAL_WINDOW, B_NOT_RESIZABLE+B_NOT_ZOOMABLE+B_NOT_MINIMIZABLE+B_NOT_CLOSABLE)
|
||||
{
|
||||
BRect rect;
|
||||
AboutView *topview;
|
||||
|
||||
// View de fond
|
||||
rect = Bounds();
|
||||
AddChild(topview = new AboutView(rect));
|
||||
BButton *ok;
|
||||
topview->AddChild(ok = new BButton(BRect(rect.right-125, rect.bottom-40, rect.right-25, rect.bottom-16), NULL, "Thanks!", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_LEFT));
|
||||
ok->MakeDefault(true);
|
||||
visible_window(this);
|
||||
Show();
|
||||
}
|
||||
|
||||
#define kTop 163
|
||||
#define kStep 12
|
||||
#define kLeft 70
|
||||
|
||||
AboutView::AboutView(BRect frame)
|
||||
: BView(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW)
|
||||
{
|
||||
fIcon = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT);
|
||||
BMimeType(kSignature).GetIcon(fIcon, B_LARGE_ICON);
|
||||
float middle = Frame ().Width () / 2;
|
||||
BRect rect (middle, 112, 0, 0);
|
||||
char subject[256];
|
||||
sprintf (subject, "About %s (%s, %s)", kProgramName, __DATE__, __TIME__);
|
||||
mailtoView* mailto = new mailtoView (rect, kAboutEmail, subject);
|
||||
AddChild (mailto);
|
||||
rect.Set (kLeft - 2, kTop + kStep + 2, kLeft - 2, 0);
|
||||
URLView* urlview = new URLView (rect, kAboutWeb);
|
||||
AddChild (urlview);
|
||||
}
|
||||
|
||||
AboutView::~AboutView()
|
||||
{
|
||||
if (fIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
void AboutView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
void AboutView::Draw(BRect /*updateRect*/)
|
||||
{
|
||||
static rgb_color panel_color = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
static rgb_color dark_panel_color = tint_color(panel_color, B_DARKEN_1_TINT);
|
||||
BRect r = Bounds();
|
||||
SetDrawingMode(B_OP_OVER);
|
||||
DrawBitmap(fIcon, BPoint(20, 156));
|
||||
SetDrawingMode(B_OP_COPY);
|
||||
r.bottom = 80;
|
||||
SetHighColor(dark_panel_color);
|
||||
FillRect(r);
|
||||
SetHighColor(kBordeaux);
|
||||
SetLowColor(dark_panel_color);
|
||||
if (fFont.SetFamilyAndFace ("Baskerville", B_BOLD_FACE | B_ITALIC_FACE) != B_OK)
|
||||
fFont.SetFamilyAndFace ("Baskerville BT", B_BOLD_FACE | B_ITALIC_FACE);
|
||||
fFont.SetSize(45);
|
||||
SetFont(&fFont, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE);
|
||||
DrawString(kProgramName, BPoint((r.Width()-StringWidth(kProgramName))/2, 50));
|
||||
fFont.SetFamilyAndFace ("Swis721 BT", B_REGULAR_FACE);
|
||||
fFont.SetSize(10);
|
||||
SetFont(&fFont, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE);
|
||||
SetHighColor(kBlack);
|
||||
SetLowColor(panel_color);
|
||||
DrawString(SendTexte, BPoint((r.Width()-StringWidth(SendTexte))/2, 106));
|
||||
MovePenTo(kLeft, kTop);
|
||||
DrawString("Halifax, ");
|
||||
DrawString(__DATE__);
|
||||
DrawString(", ");
|
||||
DrawString(__TIME__);
|
||||
DrawString(".");
|
||||
DrawString("© www.beuntied.org, 2004. Original by Georges-Edouard Berenger.", BPoint(kLeft, kTop + kStep));
|
||||
}
|
54
src/apps/processcontroller/AboutPC.h
Normal file
54
src/apps/processcontroller/AboutPC.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
AboutPC.h
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef _ABOUT_PC_H_
|
||||
#define _ABOUT_PC_H_
|
||||
|
||||
class BBitmap;
|
||||
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <Font.h>
|
||||
|
||||
class AboutPC : public BWindow {
|
||||
|
||||
public:
|
||||
AboutPC(BRect r);
|
||||
};
|
||||
|
||||
class AboutView : public BView {
|
||||
|
||||
public:
|
||||
AboutView(BRect frame);
|
||||
~AboutView();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
private:
|
||||
BFont fFont;
|
||||
BBitmap *fIcon;
|
||||
};
|
||||
|
||||
#define CenterRect(r, W, H) BRect(r.left+(r.Width()-W)/2, r.top+(r.Height()-H)/3, r.right-(r.Width()-W)/2, r.bottom-2*(r.Height()-H)/3)
|
||||
|
||||
#endif // _ABOUT_PC_H_
|
57
src/apps/processcontroller/AutoIcon.cpp
Normal file
57
src/apps/processcontroller/AutoIcon.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
AutoIcon.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 "AutoIcon.h"
|
||||
#include "PCUtils.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Entry.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Roster.h>
|
||||
|
||||
AutoIcon::~AutoIcon ()
|
||||
{
|
||||
if (fBitmap)
|
||||
delete fBitmap;
|
||||
}
|
||||
|
||||
BBitmap* AutoIcon::bitmap ()
|
||||
{
|
||||
if (fBitmap == 0)
|
||||
{
|
||||
fBitmap = new BBitmap (BRect (0, 0, 15, 15), B_COLOR_8_BIT);
|
||||
if (fSignature)
|
||||
{
|
||||
entry_ref ref;
|
||||
be_roster->FindApp (fSignature, &ref);
|
||||
if (BNodeInfo::GetTrackerIcon(&ref, fBitmap, B_MINI_ICON) != B_OK)
|
||||
fBitmap->SetBits(k_app_mini, 256, 0, B_COLOR_8_BIT);
|
||||
}
|
||||
if (fbits)
|
||||
fBitmap->SetBits (fbits, 256, 0, B_COLOR_8_BIT);
|
||||
}
|
||||
return fBitmap;
|
||||
}
|
||||
|
||||
|
48
src/apps/processcontroller/AutoIcon.h
Normal file
48
src/apps/processcontroller/AutoIcon.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
|
||||
AutoIcon.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _AUTO_ICON_H_
|
||||
#define _AUTO_ICON_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class BBitmap;
|
||||
|
||||
class AutoIcon {
|
||||
|
||||
public:
|
||||
AutoIcon (const char* signature): fSignature (signature), fbits (0), fBitmap (0) {}
|
||||
AutoIcon (const uchar* bits): fSignature (0), fbits (bits), fBitmap (0) {}
|
||||
~AutoIcon ();
|
||||
|
||||
operator BBitmap* () { return bitmap (); }
|
||||
BBitmap* bitmap ();
|
||||
|
||||
private:
|
||||
const char* fSignature;
|
||||
const uchar* fbits;
|
||||
BBitmap * fBitmap;
|
||||
};
|
||||
|
||||
#endif // _AUTO_ICON_H_
|
58
src/apps/processcontroller/Colors.h
Normal file
58
src/apps/processcontroller/Colors.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
//Useful until be gets around to making these sorts of things
|
||||
//globals akin to be_plain_font, etc.
|
||||
|
||||
#ifndef _COLORS_H_
|
||||
#define _COLORS_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
// ui_color(B_PANEL_BACKGROUND_COLOR)
|
||||
// ui_color(B_MENU_BACKGROUND_COLOR)
|
||||
// ui_color(B_WINDOW_TAB_COLOR)
|
||||
// ui_color(B_KEYBOARD_NAVIGATION_COLOR)
|
||||
// ui_color(B_DESKTOP_COLOR)
|
||||
// tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)
|
||||
|
||||
//Other colors
|
||||
const rgb_color kBlack = {0, 0, 0, 255};
|
||||
const rgb_color kWhite = {255,255,255, 255};
|
||||
const rgb_color kRed = {255,0, 0, 255};
|
||||
const rgb_color kGreen = {0, 203,0, 255};
|
||||
const rgb_color kLightGreen = {90, 240,90, 255};
|
||||
const rgb_color kBlue = {49, 61, 225, 255};
|
||||
const rgb_color kLightBlue = {64, 162,255, 255};
|
||||
const rgb_color kPurple = {144,64, 221, 255};
|
||||
const rgb_color kLightPurple = {166,74, 255, 255};
|
||||
const rgb_color kLavender = {193,122,255, 255};
|
||||
const rgb_color kYellow = {255,203,0, 255};
|
||||
const rgb_color kOrange = {255,163,0, 255};
|
||||
const rgb_color kFlesh = {255,231,186, 255};
|
||||
const rgb_color kTan = {208,182,121, 255};
|
||||
const rgb_color kBrown = {154,110,45, 255};
|
||||
const rgb_color kLightMetallicBlue = {143,166,240, 255};
|
||||
const rgb_color kMedMetallicBlue = {75, 96, 154, 255};
|
||||
const rgb_color kDarkMetallicBlue = {78, 89, 126, 255};
|
||||
|
||||
const rgb_color kGebHighlight = {152, 152, 203, 255};
|
||||
const rgb_color kBordeaux = {80, 0, 0, 255};
|
||||
|
||||
#endif // _COLORS_H_
|
156
src/apps/processcontroller/IconMenuItem.cpp
Normal file
156
src/apps/processcontroller/IconMenuItem.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
|
||||
IconMenuItem.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 "IconMenuItem.h"
|
||||
#include <Application.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Roster.h>
|
||||
#include <parsedate.h>
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
IconMenuItem::IconMenuItem(BBitmap* icon, const char* title,
|
||||
BMessage* msg, bool drawText, bool purge)
|
||||
:BMenuItem(title, msg), fIcon(icon), fDrawText(drawText), fPurge(purge)
|
||||
|
||||
{
|
||||
if (!fIcon)
|
||||
DefaultIcon(NULL);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
IconMenuItem::IconMenuItem(BBitmap* icon, BMenu* menu, bool drawText, bool purge)
|
||||
:BMenuItem(menu), fIcon(icon), fDrawText(drawText), fPurge(purge)
|
||||
|
||||
{
|
||||
if (!fIcon)
|
||||
DefaultIcon(NULL);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
IconMenuItem::IconMenuItem(const char* mime, const char* title, BMessage* msg, bool drawText)
|
||||
:BMenuItem(title, msg), fIcon(NULL), fDrawText(drawText)
|
||||
|
||||
{
|
||||
DefaultIcon(mime);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
IconMenuItem::~IconMenuItem()
|
||||
{
|
||||
if (fPurge && fIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void IconMenuItem::DrawContent()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
DrawIcon();
|
||||
if (fDrawText) {
|
||||
loc = ContentLocation();
|
||||
loc.x += 20;
|
||||
Menu()->MovePenTo(loc);
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void IconMenuItem::Highlight(bool hilited)
|
||||
{
|
||||
BMenuItem::Highlight(hilited);
|
||||
DrawIcon();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void IconMenuItem::DrawIcon()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
loc = ContentLocation();
|
||||
BRect frame = Frame();
|
||||
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
|
||||
Menu()->SetDrawingMode(B_OP_OVER);
|
||||
if (fIcon)
|
||||
Menu()->DrawBitmap(fIcon, loc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void IconMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize(width, height);
|
||||
int limit = IconMenuItem::MinHeight();
|
||||
if (*height < limit)
|
||||
*height = limit;
|
||||
if (fDrawText)
|
||||
*width += 20;
|
||||
else
|
||||
*width = 16;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void IconMenuItem::DefaultIcon(const char* mime)
|
||||
{
|
||||
BRect r(0, 0, 15, 15);
|
||||
fIcon = new BBitmap(r, B_COLOR_8_BIT);
|
||||
if (mime) {
|
||||
BMimeType mimeType(mime);
|
||||
if (mimeType.GetIcon(fIcon, B_MINI_ICON)!=B_OK)
|
||||
fDrawText = true;
|
||||
} else {
|
||||
app_info info;
|
||||
be_app->GetAppInfo(&info);
|
||||
if (BNodeInfo::GetTrackerIcon(&info.ref, fIcon, B_MINI_ICON)!=B_OK)
|
||||
fDrawText = true;
|
||||
}
|
||||
fPurge = true;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
int IconMenuItem::MinHeight()
|
||||
{
|
||||
static int minheight = -1;
|
||||
if (minheight < 0)
|
||||
minheight = before_dano() ? 16 : 17;
|
||||
return minheight;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
bool before_dano()
|
||||
{
|
||||
static int old_version = -1;
|
||||
if (old_version < 0)
|
||||
{
|
||||
system_info sys_info;
|
||||
get_system_info(&sys_info);
|
||||
time_t kernelTime = parsedate(sys_info.kernel_build_date, time(NULL));
|
||||
struct tm * date = gmtime(&kernelTime);
|
||||
old_version = (date->tm_year < 101 || date->tm_year == 101 && date->tm_mon < 10);
|
||||
}
|
||||
return old_version;
|
||||
}
|
60
src/apps/processcontroller/IconMenuItem.h
Normal file
60
src/apps/processcontroller/IconMenuItem.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
|
||||
IconMenuItem.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 _ICON_MENU_ITEM_H_
|
||||
#define _ICON_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
class BBitmap;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class IconMenuItem : public BMenuItem {
|
||||
|
||||
public:
|
||||
IconMenuItem(BBitmap*, const char* title,
|
||||
BMessage*, bool drawText = true, bool purge = false);
|
||||
IconMenuItem(BBitmap*, BMenu*,
|
||||
bool drawText = true, bool purge = false);
|
||||
IconMenuItem(const char* mime, const char* title, BMessage*,
|
||||
bool drawText = true);
|
||||
virtual ~IconMenuItem();
|
||||
virtual void DrawContent();
|
||||
virtual void Highlight(bool isHighlighted);
|
||||
virtual void GetContentSize(float* width, float* height);
|
||||
static int MinHeight();
|
||||
|
||||
private:
|
||||
void DefaultIcon(const char* mime);
|
||||
void DrawIcon();
|
||||
|
||||
BBitmap* fIcon;
|
||||
bool fDrawText;
|
||||
bool fPurge;
|
||||
};
|
||||
|
||||
bool before_dano();
|
||||
|
||||
#endif // _ICON_MENU_ITEM_H_
|
34
src/apps/processcontroller/Jamfile
Normal file
34
src/apps/processcontroller/Jamfile
Normal file
@ -0,0 +1,34 @@
|
||||
SubDir HAIKU_TOP src apps processcontroller ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
#UsePrivateHeaders shared ;
|
||||
|
||||
Application ProcessController :
|
||||
AboutPC.cpp
|
||||
AutoIcon.cpp
|
||||
IconMenuItem.cpp
|
||||
KernelMemoryBarMenuItem.cpp
|
||||
MemoryBarMenu.cpp
|
||||
MemoryBarMenuItem.cpp
|
||||
MemorySpyWindow.cpp
|
||||
NoiseBarMenuItem.cpp
|
||||
PCUtils.cpp
|
||||
PCView.cpp
|
||||
PCView2.cpp
|
||||
PCWindow.cpp
|
||||
PCWorld.cpp
|
||||
Preferences.cpp
|
||||
PrintMessage.cpp
|
||||
PriorityMenu.cpp
|
||||
QuitMenu.cpp
|
||||
ReadableLong.cpp
|
||||
TeamBarMenu.cpp
|
||||
TeamBarMenuItem.cpp
|
||||
ThreadBarMenu.cpp
|
||||
ThreadBarMenuItem.cpp
|
||||
URLView.cpp
|
||||
WindowsTools.cpp
|
||||
: be #tracker translation
|
||||
: #ProcessController.rdef
|
||||
;
|
164
src/apps/processcontroller/KernelMemoryBarMenuItem.cpp
Normal file
164
src/apps/processcontroller/KernelMemoryBarMenuItem.cpp
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
|
||||
KernelMemoryBarMenuItem.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 "KernelMemoryBarMenuItem.h"
|
||||
#include "Colors.h"
|
||||
#include "PCView.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// --------------------------------------------------------------
|
||||
KernelMemoryBarMenuItem::KernelMemoryBarMenuItem (system_info* sinfo)
|
||||
:BMenuItem ("System Resources & Caches...", NULL)
|
||||
{
|
||||
fTotalWriteMemory = -1;
|
||||
fLastSum = -1;
|
||||
fGrenze1 = -1;
|
||||
fGrenze2 = -1;
|
||||
fPhsysicalMemory = float (int (sinfo->max_pages * B_PAGE_SIZE / 1024));
|
||||
fCommitedMemory = float (int (sinfo->used_pages * B_PAGE_SIZE / 1024));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::DrawContent ()
|
||||
{
|
||||
DrawBar (true);
|
||||
Menu ()->MovePenTo (ContentLocation ());
|
||||
BMenuItem::DrawContent ();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::UpdateSituation (float commitedMemory, float totalWriteMemory)
|
||||
{
|
||||
if (commitedMemory < totalWriteMemory)
|
||||
totalWriteMemory = commitedMemory;
|
||||
fCommitedMemory = commitedMemory;
|
||||
fTotalWriteMemory = totalWriteMemory;
|
||||
DrawBar (false);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::DrawBar (bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame ();
|
||||
BMenu* menu = Menu ();
|
||||
// draw the bar itself
|
||||
BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5, frame.right - kMargin, frame.top + 13);
|
||||
if (fTotalWriteMemory < 0)
|
||||
return;
|
||||
if (fLastSum < 0)
|
||||
force = true;
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gFrameColor);
|
||||
menu->StrokeRect (cadre);
|
||||
}
|
||||
cadre.InsetBy (1, 1);
|
||||
BRect r = cadre;
|
||||
float grenze1 = cadre.left + (cadre.right - cadre.left) * fTotalWriteMemory / fPhsysicalMemory;
|
||||
float grenze2 = cadre.left + (cadre.right - cadre.left) * fCommitedMemory / fPhsysicalMemory;
|
||||
if (grenze1 > cadre.right)
|
||||
grenze1 = cadre.right;
|
||||
if (grenze2 > cadre.right)
|
||||
grenze2 = cadre.right;
|
||||
r.right = grenze1;
|
||||
if (!force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gKernelColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gKernelColor);
|
||||
// menu->SetHighColor (gKernelColor);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT));
|
||||
else
|
||||
menu->SetHighColor (kLavender);
|
||||
// menu->SetHighColor (gUserColor);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
r.left = grenze2;
|
||||
r.right = cadre.right;
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor (kWhite);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
menu->SetHighColor (kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
|
||||
// draw the value
|
||||
double sum = fTotalWriteMemory * FLT_MAX + fCommitedMemory;
|
||||
if (force || sum != fLastSum)
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
menu->SetLowColor (gMenuBackColorSelected);
|
||||
menu->SetHighColor (gMenuBackColorSelected);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu->SetLowColor (gMenuBackColor);
|
||||
menu->SetHighColor (gMenuBackColor);
|
||||
}
|
||||
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom);
|
||||
menu->FillRect (trect);
|
||||
menu->SetHighColor (kBlack);
|
||||
char infos[128];
|
||||
sprintf (infos, "%.1f MB", fTotalWriteMemory / 1024.f);
|
||||
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1);
|
||||
menu->DrawString (infos, loc);
|
||||
sprintf (infos, "%.1f MB", fCommitedMemory / 1024.f);
|
||||
loc.x = cadre.left - kMargin - menu->StringWidth (infos);
|
||||
menu->DrawString (infos, loc);
|
||||
fLastSum = sum;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::GetContentSize (float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize (width, height);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 20 + kBarWidth;
|
||||
}
|
50
src/apps/processcontroller/KernelMemoryBarMenuItem.h
Normal file
50
src/apps/processcontroller/KernelMemoryBarMenuItem.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
|
||||
KernelMemoryBarMenuItem.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_
|
||||
#define _KERNEL_MEMORY_BAR_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class KernelMemoryBarMenuItem : public BMenuItem {
|
||||
|
||||
public:
|
||||
KernelMemoryBarMenuItem (system_info* sinfo);
|
||||
virtual void DrawContent ();
|
||||
virtual void GetContentSize (float* width, float* height);
|
||||
void DrawBar (bool force);
|
||||
void UpdateSituation (float commitedMemory, float totalWriteMemory);
|
||||
|
||||
private:
|
||||
float fTotalWriteMemory;
|
||||
float fPhsysicalMemory;
|
||||
float fCommitedMemory;
|
||||
double fLastSum;
|
||||
float fGrenze1;
|
||||
float fGrenze2;
|
||||
};
|
||||
|
||||
#endif // _KERNEL_MEMORY_BAR_MENU_ITEM_H_
|
160
src/apps/processcontroller/MemoryBarMenu.cpp
Normal file
160
src/apps/processcontroller/MemoryBarMenu.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
|
||||
MemoryBarMenu.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 <Roster.h>
|
||||
#include <Bitmap.h>
|
||||
#include <stdlib.h>
|
||||
#include "MemoryBarMenu.h"
|
||||
#include "MemoryBarMenuItem.h"
|
||||
#include "KernelMemoryBarMenuItem.h"
|
||||
#include "PCView.h"
|
||||
#include <Window.h>
|
||||
|
||||
#define EXTRA 10
|
||||
|
||||
MemoryBarMenu::MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo)
|
||||
:BMenu (name), fFirstShow (true)
|
||||
{
|
||||
fTeamCount = sinfo->used_teams + EXTRA;
|
||||
SetFlags (Flags () | B_PULSE_NEEDED);
|
||||
fTeamList = (team_id*) malloc (sizeof (team_id) * fTeamCount);
|
||||
int k;
|
||||
for (k = 0; k < sinfo->used_teams; k++)
|
||||
fTeamList[k] = infos[k].tminfo.team;
|
||||
while (k < fTeamCount)
|
||||
fTeamList[k++] = -1;
|
||||
fRecycleCount = EXTRA;
|
||||
fRecycleList = (MRecycleItem*) malloc (sizeof (MRecycleItem) * fRecycleCount);
|
||||
SetFont (be_plain_font);
|
||||
AddItem (new KernelMemoryBarMenuItem (sinfo));
|
||||
}
|
||||
|
||||
MemoryBarMenu::~MemoryBarMenu()
|
||||
{
|
||||
free (fTeamList);
|
||||
free (fRecycleList);
|
||||
}
|
||||
|
||||
void MemoryBarMenu::Draw (BRect updateRect)
|
||||
{
|
||||
if (fFirstShow)
|
||||
{
|
||||
Pulse ();
|
||||
fFirstShow = false;
|
||||
}
|
||||
BMenu::Draw (updateRect);
|
||||
}
|
||||
|
||||
void MemoryBarMenu::Pulse ()
|
||||
{
|
||||
system_info sinfo;
|
||||
get_system_info (&sinfo);
|
||||
int commitedMemory = int (sinfo.used_pages * B_PAGE_SIZE / 1024);
|
||||
Window ()->BeginViewTransaction ();
|
||||
|
||||
// create the list of items to remove, for their team is gone. Update the old teams.
|
||||
int lastRecycle = 0;
|
||||
int firstRecycle = 0;
|
||||
int k;
|
||||
MemoryBarMenuItem *item;
|
||||
int total = 0;
|
||||
for (k = 1; (item = (MemoryBarMenuItem*) ItemAt (k)) != NULL; k++) {
|
||||
int m = item->UpdateSituation (commitedMemory);
|
||||
if (m < 0) {
|
||||
if (lastRecycle == fRecycleCount) {
|
||||
fRecycleCount += EXTRA;
|
||||
fRecycleList = (MRecycleItem*) realloc (fRecycleList, sizeof (MRecycleItem) * fRecycleCount);
|
||||
}
|
||||
fRecycleList[lastRecycle].index = k;
|
||||
fRecycleList[lastRecycle++].item = item;
|
||||
} else {
|
||||
if (lastRecycle > 0) {
|
||||
RemoveItems (fRecycleList[0].index, lastRecycle, true);
|
||||
k -= lastRecycle;
|
||||
lastRecycle = 0;
|
||||
}
|
||||
total += m;
|
||||
}
|
||||
}
|
||||
|
||||
// Look new teams that have appeared. Create an item for them, or recycle from the list.
|
||||
int32 cookie = 0;
|
||||
infosPack infos;
|
||||
item = NULL;
|
||||
while (get_next_team_info (&cookie, &infos.tminfo) == B_OK) {
|
||||
int j = 0;
|
||||
while (j < fTeamCount && infos.tminfo.team != fTeamList[j])
|
||||
j++;
|
||||
if (infos.tminfo.team != fTeamList[j]) {
|
||||
// new team
|
||||
team_info info;
|
||||
j = 0;
|
||||
while (j < fTeamCount && fTeamList[j] != -1)
|
||||
if (get_team_info (fTeamList[j], &info) != B_OK)
|
||||
fTeamList[j] = -1;
|
||||
else
|
||||
j++;
|
||||
if (j == fTeamCount) {
|
||||
fTeamCount += 10;
|
||||
fTeamList = (team_id*) realloc (fTeamList, sizeof (team_id) * fTeamCount);
|
||||
}
|
||||
fTeamList[j] = infos.tminfo.team;
|
||||
if (!get_team_name_and_icon (infos, true)) {
|
||||
// the team is already gone!
|
||||
delete infos.tmicon;
|
||||
fTeamList[j] = -1;
|
||||
} else {
|
||||
if (!item && firstRecycle < lastRecycle) {
|
||||
item = fRecycleList[firstRecycle++].item;
|
||||
}
|
||||
if (item)
|
||||
item->Reset (infos.tmname, infos.tminfo.team, infos.tmicon, true);
|
||||
else
|
||||
AddItem (item = new MemoryBarMenuItem (infos.tmname, infos.tminfo.team, infos.tmicon, true, NULL));
|
||||
int m = item->UpdateSituation (commitedMemory);
|
||||
if (m >= 0) {
|
||||
total += m;
|
||||
item = NULL;
|
||||
} else
|
||||
fTeamList[j] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item) {
|
||||
RemoveItem (item);
|
||||
delete item;
|
||||
}
|
||||
|
||||
// Delete the items that haven't been recycled.
|
||||
if (firstRecycle < lastRecycle)
|
||||
RemoveItems (IndexOf (fRecycleList[firstRecycle].item), lastRecycle - firstRecycle, true);
|
||||
|
||||
fLastTotalTime = system_time ();
|
||||
KernelMemoryBarMenuItem *kernelItem;
|
||||
if ((kernelItem = (KernelMemoryBarMenuItem*) ItemAt (0)) != NULL)
|
||||
kernelItem->UpdateSituation (commitedMemory, total);
|
||||
|
||||
Window()->EndViewTransaction();
|
||||
Window()->Flush();
|
||||
}
|
56
src/apps/processcontroller/MemoryBarMenu.h
Normal file
56
src/apps/processcontroller/MemoryBarMenu.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
MemoryBarMenu.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _MEMORY_BAR_MENU_H_
|
||||
#define _MEMORY_BAR_MENU_H_
|
||||
|
||||
#include "PCUtils.h"
|
||||
|
||||
#include <Menu.h>
|
||||
|
||||
class MemoryBarMenuItem;
|
||||
|
||||
typedef struct {
|
||||
MemoryBarMenuItem* item;
|
||||
int index;
|
||||
} MRecycleItem;
|
||||
|
||||
class MemoryBarMenu : public BMenu
|
||||
{
|
||||
public:
|
||||
MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo);
|
||||
virtual ~MemoryBarMenu ();
|
||||
virtual void Draw (BRect updateRect);
|
||||
virtual void Pulse ();
|
||||
|
||||
private:
|
||||
team_id* fTeamList;
|
||||
int fTeamCount;
|
||||
MRecycleItem* fRecycleList;
|
||||
int fRecycleCount;
|
||||
bigtime_t fLastTotalTime;
|
||||
bool fFirstShow;
|
||||
};
|
||||
|
||||
#endif // _MEMORY_BAR_MENU_H_
|
244
src/apps/processcontroller/MemoryBarMenuItem.cpp
Normal file
244
src/apps/processcontroller/MemoryBarMenuItem.cpp
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
|
||||
MemoryBarMenuItem.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 "MemoryBarMenuItem.h"
|
||||
#include "MemoryBarMenu.h"
|
||||
#include "Colors.h"
|
||||
#include <Bitmap.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// --------------------------------------------------------------
|
||||
MemoryBarMenuItem::MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message)
|
||||
:BMenuItem (label, message), fTeamID (team), fIcon (icon), fDeleteIcon (DeleteIcon)
|
||||
{
|
||||
Init ();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::Init ()
|
||||
{
|
||||
fWriteMemory = -1;
|
||||
fAllMemory = -1;
|
||||
fGrenze1 = -1;
|
||||
fGrenze2 = -1;
|
||||
fLastCommited = -1;
|
||||
fLastWrite = -1;
|
||||
fLastAll = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
MemoryBarMenuItem::~MemoryBarMenuItem ()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawContent ()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
DrawIcon ();
|
||||
if (fWriteMemory < 0)
|
||||
BarUpdate ();
|
||||
else
|
||||
DrawBar (true);
|
||||
loc = ContentLocation ();
|
||||
loc.x += 20;
|
||||
Menu ()->MovePenTo (loc);
|
||||
BMenuItem::DrawContent ();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawIcon ()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
loc = ContentLocation ();
|
||||
BRect frame = Frame();
|
||||
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
|
||||
Menu ()->SetDrawingMode (B_OP_OVER);
|
||||
if (fIcon)
|
||||
Menu ()->DrawBitmap (fIcon, loc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawBar (bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame ();
|
||||
BMenu* menu = Menu ();
|
||||
// draw the bar itself
|
||||
BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5, frame.right - kMargin, frame.top + 13);
|
||||
if (fWriteMemory < 0)
|
||||
return;
|
||||
if (fGrenze1 < 0)
|
||||
force = true;
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gFrameColor);
|
||||
menu->StrokeRect (cadre);
|
||||
}
|
||||
cadre.InsetBy (1, 1);
|
||||
BRect r = cadre;
|
||||
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory;
|
||||
float grenze2 = cadre.left + (cadre.right - cadre.left) * float (fAllMemory) / fCommitedMemory;
|
||||
if (grenze1 > cadre.right)
|
||||
grenze1 = cadre.right;
|
||||
if (grenze2 > cadre.right)
|
||||
grenze2 = cadre.right;
|
||||
r.right = grenze1;
|
||||
if (!force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gKernelColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gKernelColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gUserColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gUserColor);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
r.left = grenze2;
|
||||
r.right = cadre.right;
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor (kWhite);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
menu->SetHighColor (kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
|
||||
// draw the value
|
||||
if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
|
||||
{
|
||||
if (selected)
|
||||
menu->SetLowColor (gMenuBackColorSelected);
|
||||
else
|
||||
menu->SetLowColor (gMenuBackColor);
|
||||
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
|
||||
{
|
||||
menu->SetHighColor (menu->LowColor ());
|
||||
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom);
|
||||
menu->FillRect (trect);
|
||||
fLastWrite = fWriteMemory;
|
||||
fLastAll = fAllMemory;
|
||||
}
|
||||
fLastCommited = fCommitedMemory;
|
||||
menu->SetHighColor (kBlack);
|
||||
char infos[128];
|
||||
// if (fWriteMemory >= 1024)
|
||||
// sprintf (infos, "%.1f MB", float (fWriteMemory) / 1024.f);
|
||||
// else
|
||||
sprintf (infos, "%d KB", fWriteMemory);
|
||||
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1);
|
||||
menu->DrawString (infos, loc);
|
||||
// if (fAllMemory >= 1024)
|
||||
// sprintf (infos, "%.1f MB", float (fAllMemory) / 1024.f);
|
||||
// else
|
||||
sprintf (infos, "%d KB", fAllMemory);
|
||||
loc.x = cadre.left - kMargin - menu->StringWidth (infos);
|
||||
menu->DrawString (infos, loc);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::GetContentSize (float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize (width, height);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 30 + kBarWidth + kMargin + kTextWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
int MemoryBarMenuItem::UpdateSituation (int commitedMemory)
|
||||
{
|
||||
fCommitedMemory = commitedMemory;
|
||||
BarUpdate ();
|
||||
return fWriteMemory;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::BarUpdate ()
|
||||
{
|
||||
area_info ainfo;
|
||||
int32 cookie = 0;
|
||||
size_t lram_size = 0;
|
||||
size_t lwram_size = 0;
|
||||
bool exists = false;
|
||||
while (get_next_area_info (fTeamID, &cookie, &ainfo) == B_OK)
|
||||
{
|
||||
exists = true;
|
||||
lram_size += ainfo.ram_size;
|
||||
int zone = (int (ainfo.address) & 0xf0000000) >> 24;
|
||||
if ((ainfo.protection & B_WRITE_AREA)
|
||||
&& (zone & 0xf0) != 0xA0 // Exclude media buffers
|
||||
&& (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
|
||||
lwram_size += ainfo.ram_size;
|
||||
}
|
||||
if (!exists) {
|
||||
team_info infos;
|
||||
exists = get_team_info(fTeamID, &infos) == B_OK;
|
||||
}
|
||||
if (exists) {
|
||||
fWriteMemory = lwram_size / 1024;
|
||||
fAllMemory = lram_size / 1024;
|
||||
DrawBar (false);
|
||||
} else
|
||||
fWriteMemory = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::Reset (char* name, team_id team, BBitmap* icon, bool DeleteIcon)
|
||||
{
|
||||
SetLabel (name);
|
||||
fTeamID = team;
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
fDeleteIcon = DeleteIcon;
|
||||
fIcon = icon;
|
||||
Init ();
|
||||
}
|
63
src/apps/processcontroller/MemoryBarMenuItem.h
Normal file
63
src/apps/processcontroller/MemoryBarMenuItem.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
|
||||
MemoryBarMenuItem.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _MEMORY_BAR_MENU_ITEM_H_
|
||||
#define _MEMORY_BAR_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
class BBitmap;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class MemoryBarMenuItem : public BMenuItem {
|
||||
|
||||
public:
|
||||
MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message);
|
||||
virtual ~MemoryBarMenuItem ();
|
||||
virtual void DrawContent ();
|
||||
virtual void GetContentSize (float* width, float* height);
|
||||
void DrawIcon ();
|
||||
void DrawBar (bool force);
|
||||
int UpdateSituation (int commitedMemory);
|
||||
void BarUpdate ();
|
||||
void Init ();
|
||||
void Reset (char* name, team_id team, BBitmap* icon, bool DeleteIcon);
|
||||
|
||||
private:
|
||||
int fPhysicalMemory;
|
||||
int fCommitedMemory;
|
||||
int fWriteMemory;
|
||||
int fAllMemory;
|
||||
int fLastCommited;
|
||||
int fLastWrite;
|
||||
int fLastAll;
|
||||
team_id fTeamID;
|
||||
BBitmap* fIcon;
|
||||
float fGrenze1;
|
||||
float fGrenze2;
|
||||
bool fDeleteIcon;
|
||||
};
|
||||
|
||||
#endif // _MEMORY_BAR_MENU_ITEM_H_
|
67
src/apps/processcontroller/MemorySpyWindow.cpp
Normal file
67
src/apps/processcontroller/MemorySpyWindow.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
MemorySpyWindow.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 "MemorySpyWindow.h"
|
||||
|
||||
const char* kPositionPrefName = "MemorySpyWindowPosition";
|
||||
|
||||
MemorySpyWindow::MemorySpyWindow (team_id team)
|
||||
: BWindow (BRect (100, 100, 200, 150)), B_EMPTY_STRING, B_FLOATING_WINDOW_LOOK,
|
||||
B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
team_info tinfo;
|
||||
get
|
||||
get_team_name_and_icon ();
|
||||
be_roster->GetRunningAppInfo(tminfo->team, &info)
|
||||
GebsPreferences tPreferences (kPreferencesFileName);
|
||||
gPreferences.LoadWindowPosition (this, kPositionPrefName);
|
||||
SetPulseRate(150000);
|
||||
|
||||
MMView *mmView;
|
||||
BView *view;
|
||||
|
||||
// set up a rectangle and instantiate a new view
|
||||
// view rect should be same size as window rect but with left top at (0, 0)
|
||||
frame.OffsetTo(B_ORIGIN);
|
||||
view = new BView(frame, "Main", B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
AddChild(view);
|
||||
view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
// View About
|
||||
view->AddChild(new TriggerAboutView(frame.LeftBottom()));
|
||||
|
||||
frame.InsetBy(10, 10);
|
||||
mmView = new MMView(frame);
|
||||
|
||||
// add view to window
|
||||
view->AddChild(mmView);
|
||||
Show();
|
||||
}
|
||||
|
||||
bool MemorySpyWindow::QuitRequested()
|
||||
{
|
||||
GebsPreferences tPreferences (kPreferencesFileName);
|
||||
tPreferences.SaveWindowPosition (this, kPositionPrefName);
|
||||
be_app->PostMessage (B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
42
src/apps/processcontroller/MemorySpyWindow.h
Normal file
42
src/apps/processcontroller/MemorySpyWindow.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
MemorySpyWindow.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _MEMORY_SPY_WINDOW_H_
|
||||
#define _MEMORY_SPY_WINDOW_H_
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
class MemorySpyWindow : public BWindow {
|
||||
|
||||
public:
|
||||
MemorySpyWindow (team_id team);
|
||||
bool QuitRequested ();
|
||||
|
||||
private:
|
||||
system_info fSysInfos;
|
||||
app_info fTeamInfo;
|
||||
BBitmap* fBitmap;
|
||||
};
|
||||
|
||||
#endif // _MEMORY_SPY_WINDOW_H_
|
123
src/apps/processcontroller/NoiseBarMenuItem.cpp
Normal file
123
src/apps/processcontroller/NoiseBarMenuItem.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
|
||||
NoiseBarMenuItem.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 "NoiseBarMenuItem.h"
|
||||
#include "Colors.h"
|
||||
#include "PCView.h"
|
||||
|
||||
// --------------------------------------------------------------
|
||||
NoiseBarMenuItem::NoiseBarMenuItem()
|
||||
:BMenuItem("Gone Teams...", NULL)
|
||||
{
|
||||
fBusyWaiting = -1;
|
||||
fLost = -1;
|
||||
fGrenze1 = -1;
|
||||
fGrenze2 = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void NoiseBarMenuItem::DrawContent()
|
||||
{
|
||||
DrawBar(true);
|
||||
Menu()->MovePenTo(ContentLocation());
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void NoiseBarMenuItem::DrawBar(bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame();
|
||||
BMenu* menu = Menu ();
|
||||
frame.right -= 24;
|
||||
frame.left = frame.right-kBarWidth;
|
||||
frame.top += 5;
|
||||
frame.bottom = frame.top+8;
|
||||
if (fBusyWaiting < 0)
|
||||
return;
|
||||
if (fGrenze1 < 0)
|
||||
force = true;
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor(gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor(gFrameColor);
|
||||
menu->StrokeRect(frame);
|
||||
}
|
||||
frame.InsetBy(1, 1);
|
||||
BRect r = frame;
|
||||
float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting;
|
||||
float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost);
|
||||
if (grenze1 > frame.right)
|
||||
grenze1 = frame.right;
|
||||
if (grenze2 > frame.right)
|
||||
grenze2 = frame.right;
|
||||
r.right = grenze1;
|
||||
if (!force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT));
|
||||
else
|
||||
menu->SetHighColor(kGreen);
|
||||
// menu->SetHighColor(gKernelColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
if (r.left < r.right) {
|
||||
menu->SetHighColor(kBlack);
|
||||
// menu->SetHighColor(gUserColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze2;
|
||||
r.right = frame.right;
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor(gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor(kWhite);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
menu->SetHighColor(kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void NoiseBarMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize(width, height);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 20+kBarWidth;
|
||||
}
|
47
src/apps/processcontroller/NoiseBarMenuItem.h
Normal file
47
src/apps/processcontroller/NoiseBarMenuItem.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
NoiseBarMenuItem.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _NOISE_BAR_MENU_ITEM_H_
|
||||
#define _NOISE_BAR_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class NoiseBarMenuItem : public BMenuItem {
|
||||
|
||||
public:
|
||||
NoiseBarMenuItem();
|
||||
virtual void DrawContent();
|
||||
virtual void GetContentSize(float* width, float* height);
|
||||
void DrawBar(bool force);
|
||||
double fBusyWaiting;
|
||||
double fLost;
|
||||
|
||||
private:
|
||||
float fGrenze1;
|
||||
float fGrenze2;
|
||||
};
|
||||
|
||||
#endif // _NOISE_BAR_MENU_ITEM_H_
|
127
src/apps/processcontroller/PCUtils.cpp
Normal file
127
src/apps/processcontroller/PCUtils.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
|
||||
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 <string.h>
|
||||
#include <Alert.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Roster.h>
|
||||
#include <Deskbar.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "icons.data"
|
||||
|
||||
#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") == 0)
|
||||
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 st = be_roster->Launch (signature);
|
||||
if (st != B_OK && path)
|
||||
{
|
||||
entry_ref ref;
|
||||
if (get_ref_for_path (path, &ref) == B_OK)
|
||||
st = be_roster->Launch (&ref);
|
||||
}
|
||||
return (st == 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 ainfo;
|
||||
be_roster->GetAppInfo (kSignature, &ainfo);
|
||||
ref = ainfo.ref;
|
||||
}
|
||||
|
||||
void move_to_deskbar (BDeskbar & db)
|
||||
{
|
||||
entry_ref ref;
|
||||
find_self (ref);
|
||||
db.AddItem (&ref);
|
||||
}
|
51
src/apps/processcontroller/PCUtils.h
Normal file
51
src/apps/processcontroller/PCUtils.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
|
||||
PCUtils.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PCUTILS_H_
|
||||
#define _PCUTILS_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
class BDeskbar;
|
||||
class BBitmap;
|
||||
struct entry_ref;
|
||||
|
||||
typedef struct {
|
||||
team_info tminfo;
|
||||
BBitmap *tmicon;
|
||||
char tmname[B_PATH_NAME_LENGTH];
|
||||
thread_info *thinfo;
|
||||
} infosPack;
|
||||
|
||||
bool get_team_name_and_icon(infosPack &infopack, bool icon = false);
|
||||
bool launch (const char* mime, const char* path);
|
||||
void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float mix);
|
||||
void find_self (entry_ref & ref);
|
||||
void move_to_deskbar (BDeskbar & db);
|
||||
|
||||
extern const uchar k_cpu_mini[];
|
||||
extern const uchar k_app_mini[];
|
||||
|
||||
#endif // _PCUTILS_H_
|
642
src/apps/processcontroller/PCView.cpp
Normal file
642
src/apps/processcontroller/PCView.cpp
Normal file
@ -0,0 +1,642 @@
|
||||
/*
|
||||
|
||||
PCView.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 "IconMenuItem.h"
|
||||
#include "PCWorld.h"
|
||||
#include "AboutPC.h"
|
||||
#include "Preferences.h"
|
||||
#include "PCUtils.h"
|
||||
#include "Colors.h"
|
||||
#include <Dragger.h>
|
||||
#include <Alert.h>
|
||||
#include <Screen.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Roster.h>
|
||||
#include <Deskbar.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Path.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Directory.h>
|
||||
|
||||
const char* kDeskbarItemName = "ProcessController";
|
||||
const char* kClassName = "ProcessController";
|
||||
|
||||
const char* kMimicPulsePref = "mimic_pulse";
|
||||
const char* kFrameColorPref = "deskbar_frame_color";
|
||||
const char* kIdleColorPref = "deskbar_idle_color";
|
||||
const char* kActiveColorPref = "deskbar_active_color";
|
||||
|
||||
const char* kPuseSettings = "Pulse_settings";
|
||||
|
||||
const rgb_color kKernelBlue = {20, 20, 231, 255};
|
||||
const rgb_color kIdleGreen = {110, 190,110, 255};
|
||||
|
||||
ProcessController* gPCView;
|
||||
int32 gCPUcount;
|
||||
rgb_color gUserColor;
|
||||
rgb_color gUserColorSelected;
|
||||
rgb_color gIdleColor;
|
||||
rgb_color gIdleColorSelected;
|
||||
rgb_color gKernelColor;
|
||||
rgb_color gKernelColorSelected;
|
||||
rgb_color gFrameColor;
|
||||
rgb_color gFrameColorSelected;
|
||||
rgb_color gMenuBackColorSelected;
|
||||
rgb_color gMenuBackColor;
|
||||
rgb_color gWhiteSelected;
|
||||
ThreadBarMenu* gCurrentThreadBarMenu;
|
||||
bool gInDeskbar = false;
|
||||
int32 gMimicPulse = 0;
|
||||
|
||||
#define DEBUG_THREADS 1
|
||||
|
||||
long thread_quit_application(void *arg);
|
||||
long thread_debug_thread(void *arg);
|
||||
|
||||
typedef struct {
|
||||
thread_id thread;
|
||||
sem_id sem;
|
||||
time_t totalTime;
|
||||
} Tdebug_thead_param;
|
||||
|
||||
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
||||
extern "C" _EXPORT BView *instantiate_deskbar_item(void)
|
||||
{
|
||||
gInDeskbar = true;
|
||||
return new ProcessController ();
|
||||
}
|
||||
|
||||
ProcessController::ProcessController(BRect frame, bool temp)
|
||||
:BView(frame, kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini),
|
||||
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig),
|
||||
fTemp(temp)
|
||||
{
|
||||
if (!temp) {
|
||||
Init();
|
||||
frame.OffsetTo(B_ORIGIN);
|
||||
frame.top = frame.bottom - 7;
|
||||
frame.left = frame.right - 7;
|
||||
BDragger* dw = new BDragger(frame, this);
|
||||
AddChild(dw);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessController::ProcessController(BMessage *data):BView(data),
|
||||
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini),
|
||||
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig),
|
||||
fTemp (false)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
ProcessController::ProcessController ()
|
||||
:BView(BRect (0, 0, 15, 15), kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini),
|
||||
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig),
|
||||
fTemp (false)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
ProcessController::~ProcessController()
|
||||
{
|
||||
if (!fTemp) {
|
||||
if (gPopupThreadID)
|
||||
{
|
||||
status_t return_value;
|
||||
wait_for_thread (gPopupThreadID, &return_value);
|
||||
}
|
||||
}
|
||||
delete fMessageRunner;
|
||||
gPCView = NULL;
|
||||
}
|
||||
|
||||
void ProcessController::Init()
|
||||
{
|
||||
gPCView = this;
|
||||
fMessageRunner = NULL;
|
||||
memset(fLastBarHeight, 0, sizeof(fLastBarHeight));
|
||||
fLastMemoryHeight = 0;
|
||||
memset(fCPUTimes, 0, sizeof(fCPUTimes));
|
||||
memset(fPrevActive, 0, sizeof(fPrevActive));
|
||||
fPrevTime = 0;
|
||||
}
|
||||
|
||||
ProcessController *ProcessController::Instantiate(BMessage *data)
|
||||
{
|
||||
if (!validate_instantiation(data, kClassName))
|
||||
return NULL;
|
||||
return new ProcessController(data);
|
||||
}
|
||||
|
||||
status_t ProcessController::Archive(BMessage *data, bool deep) const
|
||||
{
|
||||
BView::Archive(data, deep);
|
||||
data->AddString("add_on", kSignature);
|
||||
data->AddString("class", kClassName);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
void ProcessController::MessageReceived(BMessage *message)
|
||||
{
|
||||
team_id team;
|
||||
thread_id thread;
|
||||
BAlert *alert;
|
||||
char question[1000];
|
||||
switch (message->what) {
|
||||
case 'Puls':
|
||||
Update ();
|
||||
DoDraw (false);
|
||||
break;
|
||||
|
||||
case 'QtTm':
|
||||
if (message->FindInt32("team", &team) == B_OK)
|
||||
resume_thread(spawn_thread(thread_quit_application, "Quit application", B_NORMAL_PRIORITY, (void*) team));
|
||||
break;
|
||||
|
||||
case 'KlTm':
|
||||
if (message->FindInt32("team", &team) == B_OK) {
|
||||
infosPack infos;
|
||||
if (get_team_info(team, &infos.tminfo) == B_OK) {
|
||||
get_team_name_and_icon(infos);
|
||||
sprintf(question, "Do you really want to kill the team \"%s\"?", infos.tmname);
|
||||
alert = new BAlert("", question, "Cancel", "Yes, Kill this Team!", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->SetShortcut(0, B_ESCAPE);
|
||||
if (alert->Go())
|
||||
kill_team(team);
|
||||
} else {
|
||||
alert = new BAlert("", "This team is already gone...", "Ok!", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'KlTh':
|
||||
if (message->FindInt32("thread", &thread) == B_OK) {
|
||||
thread_info thinfo;
|
||||
if (get_thread_info(thread, &thinfo) == B_OK) {
|
||||
#if DEBUG_THREADS
|
||||
sprintf(question, "What do you want to do with the thread \"%s\"?", thinfo.name);
|
||||
alert = new BAlert("", question, "Cancel", "Debug this Thread!", "Kill this thread!", B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
#define KILL 2
|
||||
#else
|
||||
sprintf(question, "Are you sure you want to kill the thread \"%s\"?", thinfo.name);
|
||||
alert = new BAlert("", question, "Cancel", "Kill this thread!", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
#define KILL 1
|
||||
#endif
|
||||
alert->SetShortcut(0, B_ESCAPE);
|
||||
int r = alert->Go();
|
||||
if (r == KILL)
|
||||
kill_thread(thread);
|
||||
#if DEBUG_THREADS
|
||||
else if (r == 1) {
|
||||
Tdebug_thead_param* param = new Tdebug_thead_param;
|
||||
param->thread = thread;
|
||||
if (thinfo.state == B_THREAD_WAITING)
|
||||
param->sem = thinfo.sem;
|
||||
else
|
||||
param->sem = -1;
|
||||
param->totalTime = thinfo.user_time+thinfo.kernel_time;
|
||||
resume_thread(spawn_thread(thread_debug_thread, "Debug thread", B_NORMAL_PRIORITY, param));
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
alert = new BAlert("", "This thread is already gone...", "Ok!", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'PrTh':
|
||||
if (message->FindInt32("thread", &thread) == B_OK) {
|
||||
long new_priority;
|
||||
if (message->FindInt32("priority", &new_priority) == B_OK)
|
||||
set_thread_priority(thread, new_priority);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Trac':
|
||||
launch (kTrackerSig, "/boot/beos/system/Tracker");
|
||||
break;
|
||||
|
||||
case 'Dbar':
|
||||
launch (kDeskbarSig, "/boot/beos/system/Deskbar");
|
||||
break;
|
||||
|
||||
case 'Term':
|
||||
launch (kTerminalSig, "/boot/beos/apps/Terminal");
|
||||
break;
|
||||
|
||||
case 'AlDb':
|
||||
{
|
||||
if (!be_roster->IsRunning(kDeskbarSig))
|
||||
launch (kDeskbarSig, "/boot/beos/system/Deskbar");
|
||||
BDeskbar db;
|
||||
if (gInDeskbar || db.HasItem (kDeskbarItemName))
|
||||
db.RemoveItem (kDeskbarItemName);
|
||||
else
|
||||
move_to_deskbar (db);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'CPU ':
|
||||
{
|
||||
int32 cpu;
|
||||
if (message->FindInt32 ("cpu", &cpu) == B_OK)
|
||||
{
|
||||
bool last = true;
|
||||
for (int p = 0; p < gCPUcount; p++)
|
||||
if (p != cpu && _kget_cpu_state_ (p))
|
||||
{
|
||||
last = false;
|
||||
break;
|
||||
}
|
||||
if (last)
|
||||
{
|
||||
alert = new BAlert("", "This is the last active processor...\nYou can't turn it off!",
|
||||
"That's no Fun!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->Go ();
|
||||
}
|
||||
else
|
||||
_kset_cpu_state_ (cpu, !_kget_cpu_state_ (cpu));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Colo':
|
||||
{
|
||||
GebsPreferences tPreferences (kPreferencesFileName);
|
||||
gMimicPulse = (gMimicPulse == 0);
|
||||
tPreferences.SaveInt32 (gMimicPulse, kMimicPulsePref);
|
||||
DefaultColors ();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Docu':
|
||||
{
|
||||
entry_ref ref;
|
||||
find_self (ref);
|
||||
BEntry entry (&ref);
|
||||
BDirectory parent;
|
||||
entry.GetParent (&parent);
|
||||
entry.SetTo (&parent, "ProcessController's Doc/ProcessController's Notice.html");
|
||||
BPath path (&entry);
|
||||
if (path.InitCheck () == B_OK)
|
||||
{
|
||||
char url[B_PATH_NAME_LENGTH + 64];
|
||||
sprintf (url, "file://%s", path.Path ());
|
||||
char* argv[2];
|
||||
argv[0] = url;
|
||||
argv[1] = 0;
|
||||
be_roster->Launch ("text/html", 1, argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert = new BAlert("", "ProcessController's documentation could not be found. You may want to reinstall ProcessController...",
|
||||
"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->Go ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case B_ABOUT_REQUESTED:
|
||||
new AboutPC (BScreen ().Frame ());
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived (message);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessController::DefaultColors ()
|
||||
{
|
||||
swap_color.red = 203;
|
||||
swap_color.green = 0;
|
||||
swap_color.blue = 0;
|
||||
swap_color.alpha = 255;
|
||||
bool set = false;
|
||||
if (gMimicPulse)
|
||||
{
|
||||
BPath prefpath;
|
||||
if (find_directory (B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK)
|
||||
{
|
||||
BDirectory prefdir (prefpath.Path ());
|
||||
BEntry entry;
|
||||
prefdir.FindEntry (kPuseSettings, &entry);
|
||||
BFile file (&entry, B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK)
|
||||
{
|
||||
int32 f, i, a;
|
||||
if (file.ReadAttr(kFrameColorPref, B_INT32_TYPE, 0, &f, 4) == 4 &&
|
||||
file.ReadAttr(kActiveColorPref, B_INT32_TYPE, 0, &a, 4) == 4 &&
|
||||
file.ReadAttr(kIdleColorPref, B_INT32_TYPE, 0, &i, 4) == 4)
|
||||
{
|
||||
active_color.red = (a & 0xff000000) >> 24;
|
||||
active_color.green = (a & 0x00ff0000) >> 16;
|
||||
active_color.blue = (a & 0x0000ff00) >> 8;
|
||||
active_color.alpha = 255;
|
||||
|
||||
idle_color.red = (i & 0xff000000) >> 24;
|
||||
idle_color.green = (i & 0x00ff0000) >> 16;
|
||||
idle_color.blue = (i & 0x0000ff00) >> 8;
|
||||
idle_color.alpha = 255;
|
||||
|
||||
frame_color.red = (f & 0xff000000) >> 24;
|
||||
frame_color.green = (f & 0x00ff0000) >> 16;
|
||||
frame_color.blue = (f & 0x0000ff00) >> 8;
|
||||
frame_color.alpha = 255;
|
||||
|
||||
mix_colors (memory_color, active_color, swap_color, 0.8);
|
||||
|
||||
set = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BAlert * alert = new BAlert("", "I couldn't read Pulse's preferences...",
|
||||
"Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->Go ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BAlert * alert = new BAlert("", "I couldn't find Pulse's preferences...",
|
||||
"Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->Go ();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!set)
|
||||
{
|
||||
active_color = kKernelBlue;
|
||||
active_color = tint_color (active_color, B_LIGHTEN_2_TINT);
|
||||
idle_color = active_color;
|
||||
idle_color.green /= 3;
|
||||
idle_color.red /= 3;
|
||||
idle_color.blue /= 3;
|
||||
frame_color = kBlack;
|
||||
mix_colors (memory_color, active_color, swap_color, 0.2);
|
||||
}
|
||||
// idle_color = kWhite;
|
||||
}
|
||||
|
||||
void ProcessController::AttachedToWindow ()
|
||||
{
|
||||
BView::AttachedToWindow ();
|
||||
if (Parent ())
|
||||
SetViewColor (B_TRANSPARENT_COLOR);
|
||||
else
|
||||
SetViewColor (kBlack);
|
||||
GebsPreferences tPreferences (kPreferencesFileName, NULL, false);
|
||||
tPreferences.ReadInt32 (gMimicPulse, kMimicPulsePref);
|
||||
DefaultColors ();
|
||||
system_info sys_info;
|
||||
get_system_info (&sys_info);
|
||||
gCPUcount = sys_info.cpu_count;
|
||||
Update ();
|
||||
gIdleColor = kIdleGreen;
|
||||
gIdleColorSelected = tint_color (gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT);
|
||||
gKernelColor = kKernelBlue;
|
||||
gKernelColorSelected = tint_color (gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT);
|
||||
// gKernelColor = tint_color(gUserColor, B_DARKEN_1_TINT);
|
||||
gUserColor = tint_color (gKernelColor, B_LIGHTEN_2_TINT);
|
||||
gUserColorSelected = tint_color (gUserColor, 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);
|
||||
gMenuBackColor = ui_color (B_MENU_BACKGROUND_COLOR);
|
||||
// Depending on which version of the system we use, choose the menu selection 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);
|
||||
BMessenger messenger (this);
|
||||
BMessage message ('Puls');
|
||||
fMessageRunner = new BMessageRunner (messenger, &message, 250000, -1);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
void ProcessController::Draw(BRect)
|
||||
{
|
||||
SetDrawingMode (B_OP_COPY);
|
||||
DoDraw (true);
|
||||
}
|
||||
|
||||
void ProcessController::DoDraw (bool force)
|
||||
{
|
||||
//gCPUcount = 1;
|
||||
BRect bounds (Bounds ());
|
||||
|
||||
float h = floorf (bounds.Height ()) - 2;
|
||||
float top = 1, left = 1;
|
||||
float bottom = top + h;
|
||||
float bar_width = layout[gCPUcount].cpu_width;
|
||||
// interspace
|
||||
float right = left + gCPUcount * (bar_width + layout[gCPUcount].cpu_inter) - layout[gCPUcount].cpu_inter; // right of CPU frame...
|
||||
if (force && Parent ())
|
||||
{
|
||||
SetHighColor (Parent ()->ViewColor ());
|
||||
FillRect (BRect (right + 1, top - 1, right + 2, bottom + 1));
|
||||
}
|
||||
|
||||
if (force)
|
||||
{
|
||||
SetHighColor (frame_color);
|
||||
StrokeRect (BRect (left - 1, top - 1, right, bottom + 1));
|
||||
if (gCPUcount == 2)
|
||||
StrokeLine (BPoint (left + bar_width, top), BPoint (left + bar_width, bottom));
|
||||
}
|
||||
float leftMem = bounds.Width () - layout[gCPUcount].mem_width;
|
||||
if (force)
|
||||
StrokeRect (BRect (leftMem - 1, top - 1, leftMem + layout[gCPUcount].mem_width, bottom + 1));
|
||||
|
||||
for (int x = 0; x < gCPUcount; x++)
|
||||
{
|
||||
right = left + bar_width - 1;
|
||||
float rem = fCPUTimes[x] * (h + 1);
|
||||
float bar_height = floorf (rem);
|
||||
rem -= bar_height;
|
||||
float limit = bottom - bar_height; // horizontal line
|
||||
float previous_limit = bottom - fLastBarHeight[x];
|
||||
float idle_top = top;
|
||||
if (!force && previous_limit > top)
|
||||
idle_top = previous_limit - 1;
|
||||
if (limit > idle_top)
|
||||
{
|
||||
SetHighColor (idle_color);
|
||||
FillRect (BRect (left, idle_top, right, limit - 1));
|
||||
}
|
||||
if (bar_height <= h)
|
||||
{
|
||||
rgb_color fraction_color;
|
||||
mix_colors (fraction_color, idle_color, active_color, rem);
|
||||
SetHighColor (fraction_color);
|
||||
StrokeLine (BPoint (left, bottom - bar_height), BPoint (right, bottom - bar_height));
|
||||
}
|
||||
float active_bottom = bottom;
|
||||
if (!force && previous_limit < bottom)
|
||||
active_bottom = previous_limit + 1;
|
||||
if (limit < active_bottom)
|
||||
{
|
||||
SetHighColor(active_color);
|
||||
FillRect(BRect(left, limit + 1, right, active_bottom));
|
||||
}
|
||||
left += layout[gCPUcount].cpu_width + layout[gCPUcount].cpu_inter;
|
||||
fLastBarHeight[x] = bar_height;
|
||||
}
|
||||
float rightMem = bounds.Width () - 1;
|
||||
float rem = fMemoryUsage * (h + 1);
|
||||
float bar_height = floorf (rem);
|
||||
rem -= bar_height;
|
||||
|
||||
rgb_color used_memory_color;
|
||||
float sq = fMemoryUsage * fMemoryUsage;
|
||||
sq *= sq;
|
||||
sq *= sq;
|
||||
mix_colors (used_memory_color, memory_color, swap_color, sq);
|
||||
|
||||
float limit = bottom - bar_height; // horizontal line
|
||||
float previous_limit = bottom - fLastMemoryHeight;
|
||||
float free_top = top;
|
||||
if (!force && previous_limit > top)
|
||||
free_top = previous_limit - 1;
|
||||
if (limit > free_top)
|
||||
{
|
||||
SetHighColor (idle_color);
|
||||
FillRect (BRect (leftMem, free_top, rightMem, limit - 1));
|
||||
}
|
||||
if (bar_height <= h)
|
||||
{
|
||||
rgb_color fraction_color;
|
||||
mix_colors (fraction_color, idle_color, used_memory_color, rem);
|
||||
SetHighColor (fraction_color);
|
||||
StrokeLine (BPoint (leftMem, bottom - bar_height), BPoint (rightMem, bottom - bar_height));
|
||||
}
|
||||
float used_bottom = bottom;
|
||||
// if (!force && previous_limit < bottom)
|
||||
// used_bottom = previous_limit + 1;
|
||||
if (limit < used_bottom)
|
||||
{
|
||||
SetHighColor (used_memory_color);
|
||||
FillRect (BRect (leftMem, limit + 1, rightMem, used_bottom));
|
||||
}
|
||||
fLastMemoryHeight = bar_height;
|
||||
}
|
||||
|
||||
void ProcessController::Update () {
|
||||
system_info sys_info;
|
||||
get_system_info(&sys_info);
|
||||
bigtime_t now = system_time();
|
||||
|
||||
fMemoryUsage = float(sys_info.used_pages) / float(sys_info.max_pages);
|
||||
// Calculate work done since last call to Update() for each CPU
|
||||
for (int x = 0; x < gCPUcount; x++) {
|
||||
bigtime_t load = sys_info.cpu_infos[x].active_time - fPrevActive[x];
|
||||
bigtime_t passed = now - fPrevTime;
|
||||
float cpu_time = float(load) / float(passed);
|
||||
fPrevActive[x] = sys_info.cpu_infos[x].active_time;
|
||||
if (load > passed)
|
||||
fPrevActive[x] -= load - passed; // save overload for next period...
|
||||
if (cpu_time < 0) cpu_time = 0;
|
||||
if (cpu_time > 1) cpu_time = 1;
|
||||
fCPUTimes[x] = cpu_time;
|
||||
}
|
||||
fPrevTime = now;
|
||||
}
|
||||
|
||||
long thread_quit_application(void *arg)
|
||||
{
|
||||
BMessenger messenger (NULL, (team_id) arg);
|
||||
messenger.SendMessage (B_QUIT_REQUESTED);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
long thread_debug_thread (void *arg)
|
||||
{
|
||||
Tdebug_thead_param* param = (Tdebug_thead_param*) arg;
|
||||
thread_info thinfo;
|
||||
get_thread_info(param->thread, &thinfo);
|
||||
char texte[4096];
|
||||
sprintf (texte, "db %d", int(param->thread));
|
||||
system (texte);
|
||||
if (param->sem >= 0 && thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem) {
|
||||
snooze(1000000);
|
||||
get_thread_info(param->thread, &thinfo);
|
||||
if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time)
|
||||
{
|
||||
// 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;
|
||||
thread_info thinfo;
|
||||
infosPack infos;
|
||||
if (get_sem_info (param->sem, &sinfo) == B_OK && get_thread_info (param->thread, &thinfo) == B_OK && get_team_info (thinfo.team, &infos.tminfo) == B_OK)
|
||||
{
|
||||
sprintf (texte, "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);
|
||||
if (sinfo.team == thinfo.team)
|
||||
strcat (texte, "This semaphore belongs to the thread's team.\n\nShould I release this semaphore?\n");
|
||||
else
|
||||
{
|
||||
get_team_name_and_icon (infos);
|
||||
char moretexte[1024];
|
||||
sprintf (moretexte, "\nWARNING! This semaphore belongs to the team \"%s\"!\n\nShould I release this semaphore anyway?\n", infos.tmname);
|
||||
strcat (texte, moretexte);
|
||||
}
|
||||
BAlert* alert = new BAlert("", texte, "Cancel", "Release", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->SetShortcut(0, B_ESCAPE);
|
||||
if (alert->Go())
|
||||
{
|
||||
get_thread_info (param->thread, &thinfo);
|
||||
if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time)
|
||||
release_sem(param->sem);
|
||||
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->Go();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete param;
|
||||
return B_OK;
|
||||
}
|
97
src/apps/processcontroller/PCView.h
Normal file
97
src/apps/processcontroller/PCView.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
|
||||
PCView.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PCVIEW_H_
|
||||
#define _PCVIEW_H_
|
||||
|
||||
#include <View.h>
|
||||
#include "AutoIcon.h"
|
||||
|
||||
class BMessageRunner;
|
||||
|
||||
class ThreadBarMenu;
|
||||
|
||||
class _EXPORT ProcessController : public BView {
|
||||
|
||||
public:
|
||||
ProcessController(BRect frame, bool temp=false);
|
||||
ProcessController(BMessage *data);
|
||||
ProcessController();
|
||||
virtual ~ProcessController();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void Draw(BRect updateRect);
|
||||
void DoDraw (bool force);
|
||||
static ProcessController *Instantiate(BMessage *data);
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
|
||||
void Update ();
|
||||
void DefaultColors ();
|
||||
|
||||
AutoIcon fProcessControllerIcon;
|
||||
AutoIcon fProcessorIcon;
|
||||
AutoIcon fTrackerIcon;
|
||||
AutoIcon fDeskbarIcon;
|
||||
AutoIcon fTerminalIcon;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
bool fTemp;
|
||||
float fMemoryUsage;
|
||||
float fLastBarHeight[B_MAX_CPU_COUNT];
|
||||
float fLastMemoryHeight;
|
||||
double fCPUTimes[B_MAX_CPU_COUNT];
|
||||
bigtime_t fPrevActive[B_MAX_CPU_COUNT];
|
||||
bigtime_t fPrevTime;
|
||||
BMessageRunner *fMessageRunner;
|
||||
rgb_color frame_color, active_color, idle_color, memory_color, swap_color;
|
||||
};
|
||||
|
||||
extern ProcessController* gPCView;
|
||||
extern int32 gCPUcount;
|
||||
extern rgb_color gIdleColor;
|
||||
extern rgb_color gIdleColorSelected;
|
||||
extern rgb_color gKernelColor;
|
||||
extern rgb_color gKernelColorSelected;
|
||||
extern rgb_color gUserColor;
|
||||
extern rgb_color gUserColorSelected;
|
||||
extern rgb_color gFrameColor;
|
||||
extern rgb_color gFrameColorSelected;
|
||||
extern rgb_color gMenuBackColor;
|
||||
extern rgb_color gMenuBackColorSelected;
|
||||
extern rgb_color gWhiteSelected;
|
||||
extern ThreadBarMenu* gCurrentThreadBarMenu;
|
||||
extern thread_id gPopupThreadID;
|
||||
extern team_id gAppServerTeamID;
|
||||
extern const char* kDeskbarItemName;
|
||||
extern bool gInDeskbar;
|
||||
extern int32 gMimicPulse;
|
||||
|
||||
#define kBarWidth 100
|
||||
#define kTextWidth 110
|
||||
#define kMargin 12
|
||||
|
||||
#endif // _PCVIEW_H_
|
210
src/apps/processcontroller/PCView2.cpp
Normal file
210
src/apps/processcontroller/PCView2.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
|
||||
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 "QuitMenu.h"
|
||||
#include "IconMenuItem.h"
|
||||
#include "TeamBarMenu.h"
|
||||
#include "TeamBarMenuItem.h"
|
||||
#include "ThreadBarMenu.h"
|
||||
#include "MemoryBarMenu.h"
|
||||
#include "MemoryBarMenuItem.h"
|
||||
#include "PCWorld.h"
|
||||
#include "Preferences.h"
|
||||
#include "PCUtils.h"
|
||||
#include "AutoIcon.h"
|
||||
#include <Screen.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Roster.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Deskbar.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 (¶m->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;
|
||||
system_info sinfo;
|
||||
int32 mcookie, hcookie;
|
||||
long m, h;
|
||||
BMenuItem *item;
|
||||
bool top = param->top;
|
||||
|
||||
get_system_info(&sinfo);
|
||||
infosPack *infos = new infosPack[sinfo.used_teams];
|
||||
for (m = 0, mcookie = 0; m < sinfo.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 {
|
||||
sinfo.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, sinfo.used_teams);
|
||||
QuitPopup->SetFont (be_plain_font);
|
||||
popup->AddItem (QuitPopup);
|
||||
|
||||
//Memory Usage section
|
||||
MemoryBarMenu* MemoryPopup = new MemoryBarMenu ("Spy Memory Usage", infos, &sinfo);
|
||||
int commitedMemory = int (sinfo.used_pages * B_PAGE_SIZE / 1024);
|
||||
for (m = 0; m < sinfo.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, sinfo.used_teams);
|
||||
for (m = 0; m < sinfo.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);
|
||||
|
||||
item = new BMenuItem("Read Documentation", new BMessage ('Docu'));
|
||||
item->SetTarget (gPCView);
|
||||
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 < sinfo.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;
|
||||
}
|
113
src/apps/processcontroller/PCWindow.cpp
Normal file
113
src/apps/processcontroller/PCWindow.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
|
||||
PCWindow.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 "PCWorld.h"
|
||||
#include "PCWindow.h"
|
||||
#include "PCView.h"
|
||||
#include "Preferences.h"
|
||||
#include "PCUtils.h"
|
||||
#include <StringView.h>
|
||||
#include <Dragger.h>
|
||||
#include <Deskbar.h>
|
||||
#include <Alert.h>
|
||||
#include <Roster.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)
|
||||
{
|
||||
BView *topview;
|
||||
BStringView *manuel;
|
||||
BRect rect;
|
||||
|
||||
GebsPreferences tPreferences(kPreferencesFileName);
|
||||
int32 version = 0;
|
||||
tPreferences.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())
|
||||
{
|
||||
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
|
||||
// view rect should be same size as window rect but with left top at (0, 0)
|
||||
rect.Set(0, 0, 15, 15);
|
||||
rect.OffsetTo(8, 9);
|
||||
topview->AddChild(new ProcessController(rect));
|
||||
|
||||
// make window visible
|
||||
Show();
|
||||
wasShowing = BDragger::AreDraggersDrawn ();
|
||||
BDragger::ShowAllDraggers ();
|
||||
}
|
||||
|
||||
PCWindow::~PCWindow ()
|
||||
{
|
||||
if (!wasShowing)
|
||||
BDragger::HideAllDraggers ();
|
||||
}
|
||||
|
||||
bool PCWindow::QuitRequested()
|
||||
{
|
||||
GebsPreferences tPreferences(kPreferencesFileName);
|
||||
tPreferences.SaveWindowPosition(this, kPosPrefName);
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
41
src/apps/processcontroller/PCWindow.h
Normal file
41
src/apps/processcontroller/PCWindow.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
|
||||
PCWindow.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PCWINDOW_H_
|
||||
#define _PCWINDOW_H_
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
class PCWindow : public BWindow {
|
||||
|
||||
public:
|
||||
PCWindow();
|
||||
~PCWindow();
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
bool wasShowing;
|
||||
};
|
||||
|
||||
#endif // _PCWINDOW_H_
|
109
src/apps/processcontroller/PCWorld.cpp
Normal file
109
src/apps/processcontroller/PCWorld.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
|
||||
PCWorld.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 "PCWorld.h"
|
||||
#include "PCWindow.h"
|
||||
#include "PCView.h"
|
||||
#include "PCUtils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Roster.h>
|
||||
#include <Deskbar.h>
|
||||
|
||||
const char *kSignature = "application/x-vnd.Geb-ProcessController";
|
||||
const char *kTrackerSig = "application/x-vnd.Be-TRAK";
|
||||
const char *kDeskbarSig = "application/x-vnd.Be-TSKB";
|
||||
const char *kTerminalSig = "application/x-vnd.Be-SHEL";
|
||||
const char* kPreferencesFileName = "ProcessController Prefs";
|
||||
|
||||
thread_id id = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
PCApplication application;
|
||||
application.Run();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
PCApplication::PCApplication():BApplication(kSignature)
|
||||
{
|
||||
}
|
||||
|
||||
PCApplication::~PCApplication()
|
||||
{
|
||||
status_t thread_return_value;
|
||||
if (id) {
|
||||
wait_for_thread(id, &thread_return_value);
|
||||
id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PCApplication::ReadyToRun ()
|
||||
{
|
||||
new PCWindow();
|
||||
// quitter les autres ProcessController eventuels...
|
||||
BList list;
|
||||
be_roster->GetAppList (kSignature, &list);
|
||||
long pc_count = list.CountItems ();
|
||||
if (pc_count > 1) {
|
||||
for (long k = 0; k < pc_count-1; k++) {
|
||||
BMessenger* otherme = new BMessenger (NULL, (team_id) list.ItemAt (k));
|
||||
BMessage* message = new BMessage (B_QUIT_REQUESTED);
|
||||
otherme->SendMessage (message);
|
||||
delete otherme;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PCApplication::ArgvReceived (int32 argc, char **argv)
|
||||
{
|
||||
if (argc == 2 && strcmp (argv[1], "-desktop-reset") == 0)
|
||||
{
|
||||
team_id tracker = be_roster->TeamFor (kTrackerSig);
|
||||
if (tracker >= 0)
|
||||
{
|
||||
BMessenger messenger (NULL, tracker);
|
||||
messenger.SendMessage (B_QUIT_REQUESTED);
|
||||
int k = 500;
|
||||
do {
|
||||
snooze (10000);
|
||||
} while (be_roster->IsRunning (kTrackerSig) && k-- > 0);
|
||||
}
|
||||
remove ("/boot/home/config/settings/Tracker/tracker_shelf");
|
||||
launch (kTrackerSig, "/boot/beos/system/Tracker");
|
||||
}
|
||||
else if (argc == 2 && strcmp (argv[1], "-deskbar") == 0)
|
||||
{
|
||||
BDeskbar db;
|
||||
if (!gInDeskbar && !db.HasItem (kDeskbarItemName))
|
||||
move_to_deskbar (db);
|
||||
}
|
||||
else if (argc > 1) {
|
||||
// print a simple usage string
|
||||
printf( "Usage: %s [-deskbar]\n", argv[0]);
|
||||
printf( "(c) 1997-2001 Georges-Edouard Berenger, berenger@francenet.fr\n");
|
||||
}
|
||||
Quit ();
|
||||
}
|
56
src/apps/processcontroller/PCWorld.h
Normal file
56
src/apps/processcontroller/PCWorld.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
PCWorld.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PCWORLD_H_
|
||||
#define _PCWORLD_H_
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
extern const char *kSignature;
|
||||
extern const char *kTrackerSig;
|
||||
extern const char *kDeskbarSig;
|
||||
extern const char *kTerminalSig;
|
||||
|
||||
extern const char *kPosPrefName;
|
||||
extern const char *kPreferencesFileName;
|
||||
|
||||
class PCApplication : public BApplication {
|
||||
|
||||
public:
|
||||
PCApplication();
|
||||
~PCApplication();
|
||||
virtual void ReadyToRun();
|
||||
virtual void ArgvReceived(int32 argc, char **argv);
|
||||
};
|
||||
|
||||
extern const uchar k_app_mini[];
|
||||
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_
|
269
src/apps/processcontroller/Preferences.cpp
Normal file
269
src/apps/processcontroller/Preferences.cpp
Normal file
@ -0,0 +1,269 @@
|
||||
/*
|
||||
|
||||
Preferences.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 "Preferences.h"
|
||||
#include "Locker.h"
|
||||
#include "WindowsTools.h"
|
||||
|
||||
#include <Path.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Directory.h>
|
||||
#include <File.h>
|
||||
#include <Mime.h>
|
||||
#include <Alert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char* kDirectory = "Geb";
|
||||
|
||||
GebsPreferences::GebsPreferences(const char* thename, const char* thesignature, bool doSave) : BMessage('Pref'), BLocker("Preferences", true), fSavePreferences(doSave)
|
||||
{
|
||||
fNewPreferences = false;
|
||||
fSettingsFile = 0;
|
||||
BPath prefpath;
|
||||
fName=strdup(thename);
|
||||
if (thesignature)
|
||||
fSignature=strdup(thesignature);
|
||||
else
|
||||
fSignature=NULL;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath)==B_OK) {
|
||||
BDirectory prefdir(prefpath.Path());
|
||||
BEntry entry;
|
||||
prefdir.FindEntry(kDirectory, &entry, true);
|
||||
prefdir.SetTo(&entry);
|
||||
prefdir.FindEntry(fName, &entry);
|
||||
BFile file(&entry, B_READ_ONLY);
|
||||
if (file.InitCheck()==B_OK)
|
||||
Unflatten(&file);
|
||||
else
|
||||
fNewPreferences=true;
|
||||
}
|
||||
}
|
||||
|
||||
GebsPreferences::GebsPreferences(const entry_ref &ref, const char* thesignature, bool doSave)
|
||||
: BMessage('Pref'), BLocker("Preferences", true), fSavePreferences (doSave)
|
||||
{
|
||||
fSettingsFile = new entry_ref (ref);
|
||||
fNewPreferences = false;
|
||||
BPath prefpath;
|
||||
fName = 0;
|
||||
if (thesignature)
|
||||
fSignature = strdup(thesignature);
|
||||
else
|
||||
fSignature = NULL;
|
||||
BFile file (fSettingsFile, B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK)
|
||||
Unflatten(&file);
|
||||
else
|
||||
fNewPreferences = true;
|
||||
}
|
||||
|
||||
GebsPreferences::~GebsPreferences()
|
||||
{
|
||||
if (fSavePreferences) {
|
||||
BFile file;
|
||||
status_t set = B_ERROR;
|
||||
if (fSettingsFile)
|
||||
file.SetTo (fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||
else
|
||||
{
|
||||
BPath prefpath;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true)==B_OK) {
|
||||
BDirectory prefdir(prefpath.Path());
|
||||
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)
|
||||
{
|
||||
Flatten (&file);
|
||||
if (fSignature)
|
||||
file.WriteAttr ("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature, strlen(fSignature)+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// implement saving somewhere else!
|
||||
char error[1024];
|
||||
sprintf (error, "Your setting file could not be saved!\n(%s)", strerror (file.InitCheck ()));
|
||||
BAlert *alert = new BAlert("Error saving file", error,
|
||||
"Damned!", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
free (fName);
|
||||
if (fSignature)
|
||||
free (fSignature);
|
||||
}
|
||||
|
||||
status_t GebsPreferences::MakeEmpty()
|
||||
{
|
||||
status_t st;
|
||||
Lock();
|
||||
st=BMessage::MakeEmpty();
|
||||
Unlock();
|
||||
return st;
|
||||
}
|
||||
|
||||
void GebsPreferences::SaveWindowPosition(BWindow* window, const char* name)
|
||||
{
|
||||
BRect rect=window->Frame();
|
||||
Lock();
|
||||
if (HasPoint(name))
|
||||
ReplacePoint(name, rect.LeftTop());
|
||||
else
|
||||
AddPoint(name, rect.LeftTop());
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void GebsPreferences::LoadWindowPosition(BWindow* window, const char* name)
|
||||
{
|
||||
BPoint p;
|
||||
Lock();
|
||||
if (FindPoint(name, &p)==B_OK) {
|
||||
window->MoveTo(p);
|
||||
visible_window(window);
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void GebsPreferences::SaveWindowFrame(BWindow* window, const char* name)
|
||||
{
|
||||
BRect rect=window->Frame();
|
||||
Lock();
|
||||
if (HasRect(name))
|
||||
ReplaceRect(name, rect);
|
||||
else
|
||||
AddRect(name, rect);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void GebsPreferences::LoadWindowFrame(BWindow* window, const char* name)
|
||||
{
|
||||
BRect f;
|
||||
Lock();
|
||||
if (FindRect(name, &f)==B_OK) {
|
||||
window->MoveTo(f.LeftTop());
|
||||
window->ResizeTo(f.Width(), f.Height());
|
||||
visible_window(window);
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void GebsPreferences::SaveInt32(int32 val, const char* name)
|
||||
{
|
||||
Lock();
|
||||
if (HasInt32(name))
|
||||
ReplaceInt32(name, val);
|
||||
else
|
||||
AddInt32(name, val);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
bool GebsPreferences::ReadInt32(int32 &val, const char* name)
|
||||
{
|
||||
Lock();
|
||||
int32 readVal;
|
||||
bool found=FindInt32(name, &readVal)==B_OK;
|
||||
if (found)
|
||||
val=readVal;
|
||||
Unlock();
|
||||
return found;
|
||||
}
|
||||
|
||||
void GebsPreferences::SaveFloat(float val, const char* name)
|
||||
{
|
||||
Lock();
|
||||
if (HasFloat(name))
|
||||
ReplaceFloat(name, val);
|
||||
else
|
||||
AddFloat(name, val);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
bool GebsPreferences::ReadFloat(float &val, const char* name)
|
||||
{
|
||||
Lock();
|
||||
float readVal;
|
||||
bool found=FindFloat(name, &readVal)==B_OK;
|
||||
if (found)
|
||||
val=readVal;
|
||||
Unlock();
|
||||
return found;
|
||||
}
|
||||
|
||||
void GebsPreferences::SaveRect(BRect &rect, const char* name)
|
||||
{
|
||||
Lock();
|
||||
if (HasRect(name))
|
||||
ReplaceRect(name, rect);
|
||||
else
|
||||
AddRect(name, rect);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
BRect & GebsPreferences::ReadRect(BRect &rect, const char* name)
|
||||
{
|
||||
Lock();
|
||||
BRect loaded;
|
||||
if (FindRect(name, &loaded)==B_OK)
|
||||
rect=loaded;
|
||||
Unlock();
|
||||
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)
|
||||
{
|
||||
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();
|
||||
return loaded;
|
||||
}
|
67
src/apps/processcontroller/Preferences.h
Normal file
67
src/apps/processcontroller/Preferences.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
Preferences.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 _Preferences_H_
|
||||
#define _Preferences_H_
|
||||
|
||||
#include <Window.h>
|
||||
#include <Message.h>
|
||||
#include <Locker.h>
|
||||
|
||||
class GebsPreferences : public BMessage, public BLocker {
|
||||
|
||||
public:
|
||||
GebsPreferences (const char* thename, const char* thesignature=NULL, bool doSave=true);
|
||||
GebsPreferences (const entry_ref &ref, const char* thesignature=NULL, bool doSave=true);
|
||||
~GebsPreferences ();
|
||||
status_t MakeEmpty ();
|
||||
void SaveWindowPosition (BWindow* window, const char* name);
|
||||
void LoadWindowPosition (BWindow* window, const char* name);
|
||||
void SaveWindowFrame (BWindow* window, const char* name);
|
||||
void LoadWindowFrame (BWindow* window, const char* name);
|
||||
void SaveInt32 (int32 val, const char* name);
|
||||
bool ReadInt32 (int32 &val, const char* name);
|
||||
void SaveFloat (float val, const char* name);
|
||||
bool ReadFloat (float &val, const char* name);
|
||||
void SaveRect (BRect &rect, const char* name);
|
||||
BRect& ReadRect (BRect &rect, const char* name);
|
||||
void SaveString (BString &string, const char* name);
|
||||
void SaveString (const char* string, const char* name);
|
||||
bool ReadString (BString &string, const char* name);
|
||||
bool fNewPreferences;
|
||||
bool fSavePreferences;
|
||||
char *fName;
|
||||
char *fSignature;
|
||||
entry_ref *fSettingsFile;
|
||||
};
|
||||
|
||||
extern GebsPreferences gPreferences;
|
||||
|
||||
// ggPreferences.LoadWindowPosition(this, kPosPrefName);
|
||||
// ggPreferences.SaveWindowPosition(this, kPosPrefName);
|
||||
|
||||
// ggPreferences.LoadWindowFrame(this, frame);
|
||||
// ggPreferences.SaveWindowFrame(this, frame);
|
||||
|
||||
#endif // _Preferences_H_
|
698
src/apps/processcontroller/PrintMessage.cpp
Normal file
698
src/apps/processcontroller/PrintMessage.cpp
Normal file
@ -0,0 +1,698 @@
|
||||
/*
|
||||
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
src/apps/processcontroller/PrintMessage.h
Normal file
42
src/apps/processcontroller/PrintMessage.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
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_
|
92
src/apps/processcontroller/PriorityMenu.cpp
Normal file
92
src/apps/processcontroller/PriorityMenu.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
|
||||
PriorityMenu.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 "PriorityMenu.h"
|
||||
#include "PCView.h"
|
||||
#include <Window.h>
|
||||
#include <MenuItem.h>
|
||||
#include <stdio.h>
|
||||
|
||||
PriorityMenu::PriorityMenu (thread_id thread, int32 priority) :
|
||||
BMenu (B_EMPTY_STRING), fThreadID (thread), fPriority (priority)
|
||||
{
|
||||
}
|
||||
|
||||
void PriorityMenu::Update (int32 priority)
|
||||
{
|
||||
if (priority != fPriority && CountItems () > 0)
|
||||
RemoveItems (0, CountItems (), true);
|
||||
if (CountItems () < 1)
|
||||
BuildMenu ();
|
||||
fPriority = priority;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char name[32];
|
||||
long priority;
|
||||
} PriorityRec;
|
||||
|
||||
static PriorityRec priorities[] = {
|
||||
{"Idle", 0},
|
||||
{"Lowest Active", 1},
|
||||
{"Low", 5},
|
||||
{"Normal", 10},
|
||||
{"Display", 15},
|
||||
{"Urgent Display", 20},
|
||||
{"Real Time Display", 100},
|
||||
{"Urgent", 110},
|
||||
{"Real Time", 120},
|
||||
{"", -1}
|
||||
};
|
||||
|
||||
PriorityRec customPriority = { "Custom", 0 };
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void PriorityMenu::BuildMenu ()
|
||||
{
|
||||
BMenuItem* item;
|
||||
BMessage* message;
|
||||
char name[B_OS_NAME_LENGTH + 20];
|
||||
long found = false;
|
||||
|
||||
for (long index = 0; ; index++) {
|
||||
PriorityRec *priority = &priorities[index];
|
||||
if (priority->priority < 0)
|
||||
break;
|
||||
if (!found && fPriority < priority->priority) {
|
||||
priority = &customPriority;
|
||||
priority->priority = fPriority;
|
||||
index--;
|
||||
}
|
||||
message = new BMessage('PrTh');
|
||||
message->AddInt32("thread", fThreadID);
|
||||
message->AddInt32("priority", priority->priority);
|
||||
sprintf(name, "%s Priority [%d]", priority->name, (int) priority->priority);
|
||||
item = new BMenuItem(name, message);
|
||||
item->SetTarget(gPCView);
|
||||
if (fPriority == priority->priority)
|
||||
found = true, item->SetMarked(true);
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
44
src/apps/processcontroller/PriorityMenu.h
Normal file
44
src/apps/processcontroller/PriorityMenu.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
PriorityMenu.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PRIORITY_MENU_H_
|
||||
#define _PRIORITY_MENU_H_
|
||||
|
||||
#include <Menu.h>
|
||||
|
||||
class PriorityMenu : public BMenu
|
||||
{
|
||||
public:
|
||||
PriorityMenu (thread_id thread, int32 priority);
|
||||
|
||||
void Update (int32 priority);
|
||||
void BuildMenu ();
|
||||
|
||||
private:
|
||||
thread_id fThreadID;
|
||||
int32 fPriority;
|
||||
};
|
||||
|
||||
|
||||
#endif // _PRIORITY_MENU_H_
|
139
src/apps/processcontroller/QuitMenu.cpp
Normal file
139
src/apps/processcontroller/QuitMenu.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
|
||||
QuitMenu.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 <Roster.h>
|
||||
#include <Window.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "QuitMenu.h"
|
||||
#include "IconMenuItem.h"
|
||||
#include "PCView.h"
|
||||
|
||||
class QuitMenuItem : public IconMenuItem {
|
||||
|
||||
public:
|
||||
QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge = false);
|
||||
team_id Team() { return fTeam; }
|
||||
|
||||
private:
|
||||
team_id fTeam;
|
||||
};
|
||||
|
||||
QuitMenuItem::QuitMenuItem(team_id team, BBitmap* icon, const char* title, BMessage* m, bool purge) :
|
||||
IconMenuItem(icon, title, m, true, purge), fTeam(team)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
QuitMenu::QuitMenu(const char* title, infosPack * infos, int infosCount) :
|
||||
BMenu(title), fInfos(infos), fInfosCount(infosCount), fMe(NULL)
|
||||
{
|
||||
SetTargetForItems(gPCView);
|
||||
}
|
||||
|
||||
void QuitMenu::AttachedToWindow()
|
||||
{
|
||||
if (!fMe)
|
||||
fMe = new BMessenger(this);
|
||||
be_roster->StartWatching(*fMe, B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||
BList apps;
|
||||
team_id tmid;
|
||||
be_roster->GetAppList(&apps);
|
||||
for (int t = CountItems() - 1; t >= 0; t--) {
|
||||
QuitMenuItem* item = (QuitMenuItem*) ItemAt(t);
|
||||
bool found = false;
|
||||
for (int a = 0; !found && (tmid = (team_id) apps.ItemAt(a)) != 0; a++)
|
||||
if (item->Team() == tmid)
|
||||
found = true;
|
||||
if (!found)
|
||||
RemoveItem(t);
|
||||
}
|
||||
for (int a = 0; (tmid = (team_id) apps.ItemAt(a)) != 0; a++)
|
||||
AddTeam(tmid);
|
||||
BMenu::AttachedToWindow();
|
||||
}
|
||||
|
||||
void QuitMenu::DetachedFromWindow()
|
||||
{
|
||||
BMenu::DetachedFromWindow();
|
||||
be_roster->StopWatching(*fMe);
|
||||
delete fMe;
|
||||
fMe = NULL;
|
||||
}
|
||||
|
||||
void QuitMenu::AddTeam(team_id tmid)
|
||||
{
|
||||
int t = 0;
|
||||
QuitMenuItem* item;
|
||||
while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL)
|
||||
if (item->Team() == tmid)
|
||||
return;
|
||||
t = 0;
|
||||
while (t < fInfosCount && tmid != fInfos[t].tminfo.team)
|
||||
t++;
|
||||
BMessage* message = new BMessage ('QtTm');
|
||||
message->AddInt32 ("team", tmid);
|
||||
item = NULL;
|
||||
if (t < fInfosCount)
|
||||
item = new QuitMenuItem (tmid, fInfos[t].tmicon, fInfos[t].tmname, message);
|
||||
else {
|
||||
infosPack infos;
|
||||
if (get_team_info(tmid, &infos.tminfo) == B_OK && get_team_name_and_icon(infos, true))
|
||||
item = new QuitMenuItem (tmid, infos.tmicon, infos.tmname, message, true);
|
||||
}
|
||||
if (item) {
|
||||
item->SetTarget (gPCView);
|
||||
AddItem (item);
|
||||
} else
|
||||
delete message;
|
||||
}
|
||||
|
||||
void QuitMenu::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case B_SOME_APP_LAUNCHED:
|
||||
{
|
||||
int32 tmid;
|
||||
if (msg->FindInt32("be:team", &tmid) == B_OK)
|
||||
AddTeam(tmid);
|
||||
break;
|
||||
}
|
||||
case B_SOME_APP_QUIT:
|
||||
{
|
||||
int32 tmid;
|
||||
if (msg->FindInt32("be:team", &tmid) == B_OK) {
|
||||
QuitMenuItem* item;
|
||||
int t = 0;
|
||||
while ((item = (QuitMenuItem*) ItemAt(t++)) != NULL)
|
||||
if (item->Team() == tmid) {
|
||||
delete RemoveItem(--t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BMenu::MessageReceived(msg);
|
||||
}
|
||||
}
|
46
src/apps/processcontroller/QuitMenu.h
Normal file
46
src/apps/processcontroller/QuitMenu.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
|
||||
QuitMenu.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _QUIT_MENU_H_
|
||||
#define _QUIT_MENU_H_
|
||||
|
||||
#include <Menu.h>
|
||||
#include <Messenger.h>
|
||||
#include "PCUtils.h"
|
||||
|
||||
class QuitMenu : public BMenu
|
||||
{
|
||||
public:
|
||||
QuitMenu(const char* title, infosPack * infos, int infosCount);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
void AddTeam(team_id tmid);
|
||||
private:
|
||||
const infosPack *fInfos;
|
||||
int fInfosCount;
|
||||
BMessenger *fMe;
|
||||
};
|
||||
|
||||
#endif // _QUIT_MENU_H_
|
268
src/apps/processcontroller/ReadableLong.cpp
Normal file
268
src/apps/processcontroller/ReadableLong.cpp
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
|
||||
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
src/apps/processcontroller/ReadableLong.h
Normal file
35
src/apps/processcontroller/ReadableLong.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
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_
|
186
src/apps/processcontroller/TeamBarMenu.cpp
Normal file
186
src/apps/processcontroller/TeamBarMenu.cpp
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
|
||||
TeamBarMenu.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 <Roster.h>
|
||||
#include <Bitmap.h>
|
||||
#include <stdlib.h>
|
||||
#include "TeamBarMenu.h"
|
||||
#include "ThreadBarMenu.h"
|
||||
#include "TeamBarMenuItem.h"
|
||||
#include "NoiseBarMenuItem.h"
|
||||
#include "PCView.h"
|
||||
#include <Window.h>
|
||||
|
||||
#define EXTRA 10
|
||||
|
||||
TeamBarMenu::TeamBarMenu (const char *title, infosPack *infos, int32 teamCount)
|
||||
:BMenu (title), fTeamCount (teamCount+EXTRA), fFirstShow (true)
|
||||
{
|
||||
SetFlags (Flags () | B_PULSE_NEEDED);
|
||||
fTeamList = (team_id*) malloc (sizeof (team_id) * fTeamCount);
|
||||
int k;
|
||||
for (k = 0; k < teamCount; k++)
|
||||
fTeamList[k] = infos[k].tminfo.team;
|
||||
while (k < fTeamCount)
|
||||
fTeamList[k++] = -1;
|
||||
fRecycleCount = EXTRA;
|
||||
fRecycleList = (TRecycleItem*) malloc (sizeof (TRecycleItem) * fRecycleCount);
|
||||
SetFont (be_plain_font);
|
||||
gCurrentThreadBarMenu = NULL;
|
||||
fLastTotalTime = system_time ();
|
||||
AddItem (new NoiseBarMenuItem ());
|
||||
}
|
||||
|
||||
TeamBarMenu::~TeamBarMenu ()
|
||||
{
|
||||
gCurrentThreadBarMenu = NULL;
|
||||
free (fTeamList);
|
||||
free (fRecycleList);
|
||||
}
|
||||
|
||||
void TeamBarMenu::Draw (BRect updateRect)
|
||||
{
|
||||
BMenu::Draw (updateRect);
|
||||
if (fFirstShow)
|
||||
{
|
||||
Pulse ();
|
||||
fFirstShow = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TeamBarMenu::Pulse ()
|
||||
{
|
||||
// Window ()->SetPulseRate (50000);
|
||||
Window ()->BeginViewTransaction ();
|
||||
|
||||
// create the list of items to remove, for their team is gone. Update the old teams.
|
||||
int lastRecycle = 0;
|
||||
int firstRecycle = 0;
|
||||
int k;
|
||||
TeamBarMenuItem *item;
|
||||
double total = 0;
|
||||
for (k = 1; (item = (TeamBarMenuItem*) ItemAt(k)) != NULL; k++) {
|
||||
item->BarUpdate();
|
||||
if (item->fKernel < 0) {
|
||||
if (lastRecycle == fRecycleCount) {
|
||||
fRecycleCount += EXTRA;
|
||||
fRecycleList = (TRecycleItem*) realloc(fRecycleList, sizeof(TRecycleItem)*fRecycleCount);
|
||||
}
|
||||
fRecycleList[lastRecycle].index = k;
|
||||
fRecycleList[lastRecycle++].item = item;
|
||||
} else {
|
||||
if (lastRecycle > 0) {
|
||||
RemoveItems(fRecycleList[0].index, lastRecycle, true);
|
||||
k -= lastRecycle;
|
||||
lastRecycle = 0;
|
||||
}
|
||||
total += item->fUser+item->fKernel;
|
||||
}
|
||||
}
|
||||
|
||||
// Look new teams that have appeared. Create an item for them, or recycle from the list.
|
||||
int32 cookie = 0;
|
||||
infosPack infos;
|
||||
item = NULL;
|
||||
while (get_next_team_info(&cookie, &infos.tminfo) == B_OK) {
|
||||
int j = 0;
|
||||
while (j < fTeamCount && infos.tminfo.team != fTeamList[j])
|
||||
j++;
|
||||
if (infos.tminfo.team != fTeamList[j]) {
|
||||
// new team
|
||||
team_info info;
|
||||
j = 0;
|
||||
while (j < fTeamCount && fTeamList[j] != -1)
|
||||
if (get_team_info(fTeamList[j], &info) != B_OK)
|
||||
fTeamList[j] = -1;
|
||||
else
|
||||
j++;
|
||||
if (j == fTeamCount) {
|
||||
fTeamCount += 10;
|
||||
fTeamList = (team_id*) realloc(fTeamList, sizeof(team_id)*fTeamCount);
|
||||
}
|
||||
fTeamList[j] = infos.tminfo.team;
|
||||
if (!get_team_name_and_icon(infos, true)) {
|
||||
// the team is already gone!
|
||||
delete infos.tmicon;
|
||||
fTeamList[j] = -1;
|
||||
} else {
|
||||
if (!item && firstRecycle < lastRecycle) {
|
||||
item = fRecycleList[firstRecycle++].item;
|
||||
}
|
||||
if (item) {
|
||||
item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true);
|
||||
} else {
|
||||
BMessage* kill_team = new BMessage('KlTm');
|
||||
kill_team->AddInt32("team", infos.tminfo.team);
|
||||
item = new TeamBarMenuItem(new ThreadBarMenu(infos.tmname, infos.tminfo.team, infos.tminfo.thread_count),
|
||||
kill_team, infos.tminfo.team, infos.tmicon, true);
|
||||
item->SetTarget(gPCView);
|
||||
AddItem(item);
|
||||
item->BarUpdate();
|
||||
}
|
||||
if (item->fKernel >= 0) {
|
||||
total += item->fUser+item->fKernel;
|
||||
item = NULL;
|
||||
} else {
|
||||
fTeamList[j] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item) {
|
||||
RemoveItem(item);
|
||||
delete item;
|
||||
}
|
||||
|
||||
// Delete the items that haven't been recycled.
|
||||
if (firstRecycle < lastRecycle)
|
||||
RemoveItems(IndexOf(fRecycleList[firstRecycle].item), lastRecycle-firstRecycle, true);
|
||||
|
||||
total /= gCPUcount;
|
||||
total = 1-total;
|
||||
|
||||
fLastTotalTime = system_time ();
|
||||
NoiseBarMenuItem *noiseItem;
|
||||
if ((noiseItem = (NoiseBarMenuItem*) ItemAt(0)) != NULL) {
|
||||
noiseItem->fBusyWaiting = 0;
|
||||
noiseItem->fLost = (total >= 0 ? total : 0);
|
||||
noiseItem->DrawBar(false);
|
||||
}
|
||||
|
||||
// status_t st;
|
||||
// if (gCurrentThreadBarMenu && (st = gCurrentThreadBarMenu->LockLooperWithTimeout(50000)) == B_OK) {
|
||||
if (gCurrentThreadBarMenu && gCurrentThreadBarMenu->LockLooperWithTimeout(25000) == B_OK) {
|
||||
gCurrentThreadBarMenu->Window()->BeginViewTransaction();
|
||||
gCurrentThreadBarMenu->Update();
|
||||
gCurrentThreadBarMenu->Window()->EndViewTransaction();
|
||||
gCurrentThreadBarMenu->Window()->Flush();
|
||||
gCurrentThreadBarMenu->UnlockLooper();
|
||||
}
|
||||
// else
|
||||
// if (st == B_TIMED_OUT)
|
||||
// beep();
|
||||
Window()->EndViewTransaction();
|
||||
Window()->Flush();
|
||||
}
|
55
src/apps/processcontroller/TeamBarMenu.h
Normal file
55
src/apps/processcontroller/TeamBarMenu.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
|
||||
TeamBarMenu.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _TEAM_BAR_MENU_H_
|
||||
#define _TEAM_BAR_MENU_H_
|
||||
|
||||
#include "PCUtils.h"
|
||||
|
||||
#include <Menu.h>
|
||||
|
||||
class TeamBarMenuItem;
|
||||
|
||||
typedef struct {
|
||||
TeamBarMenuItem* item;
|
||||
int index;
|
||||
} 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;
|
||||
int fTeamCount;
|
||||
TRecycleItem* fRecycleList;
|
||||
int fRecycleCount;
|
||||
bigtime_t fLastTotalTime;
|
||||
bool fFirstShow;
|
||||
};
|
||||
|
||||
#endif // _TEAM_BAR_MENU_H_
|
218
src/apps/processcontroller/TeamBarMenuItem.cpp
Normal file
218
src/apps/processcontroller/TeamBarMenuItem.cpp
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
|
||||
TeamBarMenuItem.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 "TeamBarMenuItem.h"
|
||||
#include "ThreadBarMenu.h"
|
||||
#include "ThreadBarMenuItem.h"
|
||||
#include "Colors.h"
|
||||
#include <Bitmap.h>
|
||||
|
||||
#define B_USAGE_SELF 0
|
||||
|
||||
// --------------------------------------------------------------
|
||||
TeamBarMenuItem::TeamBarMenuItem(BMenu *menu, BMessage *kill_team, team_id team, BBitmap* icon, bool DeleteIcon)
|
||||
:BMenuItem(menu, kill_team), fTeamID(team), fIcon(icon), fDeleteIcon(DeleteIcon)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::Init()
|
||||
{
|
||||
team_info tminfo;
|
||||
get_team_info(fTeamID, &tminfo);
|
||||
get_team_usage_info(fTeamID, B_USAGE_SELF, &fTeamUsageInfo);
|
||||
if (fTeamID == B_SYSTEM_TEAM) {
|
||||
thread_info thinfos;
|
||||
bigtime_t idle = 0;
|
||||
for (int t = 1; t <= gCPUcount; t++)
|
||||
if (get_thread_info(t, &thinfos) == B_OK)
|
||||
idle += thinfos.kernel_time + thinfos.user_time;
|
||||
fTeamUsageInfo.kernel_time += fTeamUsageInfo.user_time;
|
||||
fTeamUsageInfo.user_time = idle;
|
||||
}
|
||||
fLastTime = system_time();
|
||||
fKernel = -1;
|
||||
fGrenze1 = -1;
|
||||
fGrenze2 = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
TeamBarMenuItem::~TeamBarMenuItem()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::DrawContent()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
DrawIcon();
|
||||
if (fKernel < 0)
|
||||
BarUpdate();
|
||||
else
|
||||
DrawBar(true);
|
||||
loc = ContentLocation();
|
||||
loc.x += 20;
|
||||
Menu()->MovePenTo(loc);
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::DrawIcon()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
loc = ContentLocation();
|
||||
BRect frame = Frame();
|
||||
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
|
||||
BMenu* menu = Menu ();
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
if (fIcon)
|
||||
menu->DrawBitmap(fIcon, loc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::DrawBar(bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame();
|
||||
BMenu* menu = Menu ();
|
||||
frame.right -= 24;
|
||||
frame.left = frame.right-kBarWidth;
|
||||
frame.top += 5;
|
||||
frame.bottom = frame.top+8;
|
||||
if (fKernel < 0)
|
||||
return;
|
||||
if (fGrenze1 < 0)
|
||||
force = true;
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gFrameColor);
|
||||
menu->StrokeRect(frame);
|
||||
}
|
||||
frame.InsetBy(1, 1);
|
||||
BRect r = frame;
|
||||
float grenze1 = frame.left+(frame.right-frame.left)*fKernel/gCPUcount;
|
||||
float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser)/gCPUcount;
|
||||
if (grenze1 > frame.right)
|
||||
grenze1 = frame.right;
|
||||
if (grenze2 > frame.right)
|
||||
grenze2 = frame.right;
|
||||
r.right = grenze1;
|
||||
if (!force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gKernelColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gKernelColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColorSelected : gUserColorSelected);
|
||||
else
|
||||
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColor : gUserColor);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
r.left = grenze2;
|
||||
r.right = frame.right;
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor (kWhite);
|
||||
menu->FillRect (r);
|
||||
}
|
||||
menu->SetHighColor (kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize(width, height);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 40+kBarWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::BarUpdate()
|
||||
{
|
||||
team_usage_info usage;
|
||||
if (get_team_usage_info(fTeamID, B_USAGE_SELF, &usage) == B_OK) {
|
||||
bigtime_t now = system_time();
|
||||
bigtime_t idle = 0;
|
||||
if (fTeamID == B_SYSTEM_TEAM) {
|
||||
thread_info thinfos;
|
||||
for (int t = 1; t <= gCPUcount; t++)
|
||||
if (get_thread_info(t, &thinfos) == B_OK)
|
||||
idle += thinfos.kernel_time + thinfos.user_time;
|
||||
usage.kernel_time += usage.user_time;
|
||||
usage.user_time = idle;
|
||||
idle -= fTeamUsageInfo.user_time;
|
||||
}
|
||||
fKernel = double(usage.kernel_time-fTeamUsageInfo.kernel_time-idle)/double(now-fLastTime);
|
||||
fUser = double(usage.user_time-fTeamUsageInfo.user_time)/double(now-fLastTime);
|
||||
if (fKernel < 0)
|
||||
fKernel = 0;
|
||||
fLastTime = now;
|
||||
fTeamUsageInfo = usage;
|
||||
DrawBar(false);
|
||||
} else
|
||||
fKernel = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void TeamBarMenuItem::Reset(char* name, team_id team, BBitmap* icon, bool DeleteIcon)
|
||||
{
|
||||
SetLabel(name);
|
||||
fTeamID = team;
|
||||
Init();
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
fDeleteIcon = DeleteIcon;
|
||||
fIcon = icon;
|
||||
Message()->ReplaceInt32("team", team);
|
||||
((ThreadBarMenu*) Submenu())->Reset(team);
|
||||
BarUpdate();
|
||||
}
|
59
src/apps/processcontroller/TeamBarMenuItem.h
Normal file
59
src/apps/processcontroller/TeamBarMenuItem.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
|
||||
TeamBarMenuItem.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _TEAM_BAR_MENU_ITEM_H_
|
||||
#define _TEAM_BAR_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
class BBitmap;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class TeamBarMenuItem : public BMenuItem {
|
||||
|
||||
public:
|
||||
TeamBarMenuItem(BMenu *menu, BMessage *kill_team, team_id team, BBitmap* icon, bool DeleteIcon);
|
||||
virtual ~TeamBarMenuItem();
|
||||
virtual void DrawContent();
|
||||
virtual void GetContentSize(float* width, float* height);
|
||||
void DrawIcon();
|
||||
void DrawBar(bool force);
|
||||
void BarUpdate();
|
||||
void Init();
|
||||
void Reset(char* name, team_id team, BBitmap* icon, bool DeleteIcon);
|
||||
double fUser;
|
||||
double fKernel;
|
||||
|
||||
private:
|
||||
team_id fTeamID;
|
||||
BBitmap* fIcon;
|
||||
team_usage_info fTeamUsageInfo;
|
||||
bigtime_t fLastTime;
|
||||
float fGrenze1;
|
||||
float fGrenze2;
|
||||
bool fDeleteIcon;
|
||||
};
|
||||
|
||||
#endif // _TEAM_BAR_MENU_ITEM_H_
|
141
src/apps/processcontroller/ThreadBarMenu.cpp
Normal file
141
src/apps/processcontroller/ThreadBarMenu.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
|
||||
ThreadBarMenu.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 "ThreadBarMenu.h"
|
||||
#include "ThreadBarMenuItem.h"
|
||||
#include "PriorityMenu.h"
|
||||
#include "PCView.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXTRA 20
|
||||
|
||||
ThreadBarMenu::ThreadBarMenu(const char *title, team_id team, int32 thread_count):
|
||||
BMenu(title), fThreadsRecCount(thread_count+EXTRA), fTeam(team)
|
||||
{
|
||||
SetFont(be_plain_font);
|
||||
fThreadsRec = (ThreadRec*) malloc(sizeof(ThreadRec)*fThreadsRecCount);
|
||||
Init();
|
||||
fRound = 0; // for syslog
|
||||
AddNew();
|
||||
}
|
||||
|
||||
ThreadBarMenu::~ThreadBarMenu()
|
||||
{
|
||||
free(fThreadsRec);
|
||||
if (gCurrentThreadBarMenu == this)
|
||||
gCurrentThreadBarMenu = NULL;
|
||||
}
|
||||
|
||||
void ThreadBarMenu::Init()
|
||||
{
|
||||
int k = 0;
|
||||
while (k < fThreadsRecCount)
|
||||
fThreadsRec[k++].thread = -1;
|
||||
fRound = 1;
|
||||
}
|
||||
|
||||
void ThreadBarMenu::Reset(team_id team)
|
||||
{
|
||||
fTeam = team;
|
||||
RemoveItems(0, CountItems(), true);
|
||||
Init();
|
||||
}
|
||||
|
||||
void ThreadBarMenu::AttachedToWindow()
|
||||
{
|
||||
BMenu::AttachedToWindow();
|
||||
}
|
||||
|
||||
void ThreadBarMenu::Draw(BRect r)
|
||||
{
|
||||
gCurrentThreadBarMenu = this;
|
||||
BMenu::Draw(r);
|
||||
}
|
||||
|
||||
void ThreadBarMenu::AddNew()
|
||||
{
|
||||
thread_info info;
|
||||
int32 cookie = 0;
|
||||
int32 k = 0;
|
||||
while (get_next_thread_info(fTeam, &cookie, &info) == B_OK) {
|
||||
int lastk = k;
|
||||
while (k < fThreadsRecCount && fThreadsRec[k].thread != info.thread)
|
||||
k++;
|
||||
if (k == fThreadsRecCount) {
|
||||
k = 0;
|
||||
while (k < lastk && fThreadsRec[k].thread != info.thread)
|
||||
k++;
|
||||
if (k == lastk)
|
||||
k = fThreadsRecCount; // flag that the search didn't work.
|
||||
}
|
||||
if (k == fThreadsRecCount) {
|
||||
// printf("*** Thread %d %s/%s, user %Ld, kernel %Ld\n", info.thread, info.name, info.user_time, info.kernel_time);
|
||||
// this is a new thread...
|
||||
k = 0;
|
||||
while (k < fThreadsRecCount && !(fThreadsRec[k].thread == -1 || fThreadsRec[k].last_round+1 < fRound))
|
||||
k++;
|
||||
if (k == fThreadsRecCount) {
|
||||
fThreadsRecCount += EXTRA;
|
||||
fThreadsRec = (ThreadRec*) realloc(fThreadsRec, sizeof(ThreadRec)*fThreadsRecCount);
|
||||
lastk = k;
|
||||
while (lastk < fThreadsRecCount)
|
||||
fThreadsRec[lastk++].thread = -1;
|
||||
}
|
||||
fThreadsRec[k].thread = info.thread;
|
||||
BMessage* kill_thread = new BMessage('KlTh');
|
||||
kill_thread->AddInt32("thread", info.thread);
|
||||
|
||||
PriorityMenu* prio = new PriorityMenu(info.thread, info.priority);
|
||||
prio->SetFont(be_plain_font);
|
||||
ThreadBarMenuItem* threadbarmenuitem = new ThreadBarMenuItem(info.name, info.thread, prio, kill_thread);
|
||||
threadbarmenuitem->SetTarget(gPCView);
|
||||
AddItem(threadbarmenuitem);
|
||||
}
|
||||
fThreadsRec[k].last_round = fRound;
|
||||
}
|
||||
fRound++;
|
||||
}
|
||||
|
||||
void ThreadBarMenu::Update()
|
||||
{
|
||||
AddNew();
|
||||
int32 k, del;
|
||||
del = -1;
|
||||
ThreadBarMenuItem *item;
|
||||
for (k = 0; (item = (ThreadBarMenuItem*) ItemAt(k)) != NULL; k++) {
|
||||
item->BarUpdate();
|
||||
item->DrawBar(false);
|
||||
if (item->fKernel < 0) {
|
||||
if (del < 0)
|
||||
del = k;
|
||||
} else if (del >= 0) {
|
||||
RemoveItems(del, k-del, true);
|
||||
k = del;
|
||||
del = -1;
|
||||
}
|
||||
}
|
||||
if (del >= 0)
|
||||
RemoveItems(del, k-del, true);
|
||||
}
|
54
src/apps/processcontroller/ThreadBarMenu.h
Normal file
54
src/apps/processcontroller/ThreadBarMenu.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
ThreadBarMenu.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _THREAD_BAR_MENU_H_
|
||||
#define _THREAD_BAR_MENU_H_
|
||||
|
||||
#include <Menu.h>
|
||||
|
||||
typedef struct {
|
||||
thread_id thread;
|
||||
int last_round;
|
||||
} ThreadRec;
|
||||
|
||||
class ThreadBarMenu : public BMenu
|
||||
{
|
||||
public:
|
||||
ThreadBarMenu (const char *title, team_id team, int32 thread_count);
|
||||
virtual ~ThreadBarMenu ();
|
||||
virtual void AttachedToWindow ();
|
||||
virtual void Draw (BRect updateRect);
|
||||
void AddNew ();
|
||||
void Update ();
|
||||
void Init ();
|
||||
void Reset (team_id team);
|
||||
|
||||
private:
|
||||
ThreadRec* fThreadsRec;
|
||||
int fThreadsRecCount;
|
||||
team_id fTeam;
|
||||
int fRound;
|
||||
};
|
||||
|
||||
#endif // _THREAD_BAR_MENU_H_
|
168
src/apps/processcontroller/ThreadBarMenuItem.cpp
Normal file
168
src/apps/processcontroller/ThreadBarMenuItem.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
|
||||
ThreadBarMenuItem.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 "ThreadBarMenuItem.h"
|
||||
#include "PriorityMenu.h"
|
||||
#include "Colors.h"
|
||||
#include "PCView.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// --------------------------------------------------------------
|
||||
ThreadBarMenuItem::ThreadBarMenuItem(const char* title, thread_id thread, BMenu *menu, BMessage* msg)
|
||||
:BMenuItem(menu, msg), fThreadID(thread)
|
||||
{
|
||||
SetLabel(title);
|
||||
get_thread_info(fThreadID, &fThreadInfo);
|
||||
fLastTime = system_time();
|
||||
fKernel = -1;
|
||||
fGrenze1 = -1;
|
||||
fGrenze2 = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void ThreadBarMenuItem::DrawContent()
|
||||
{
|
||||
if (fKernel < 0)
|
||||
BarUpdate();
|
||||
DrawBar(true);
|
||||
Menu()->MovePenTo(ContentLocation());
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void ThreadBarMenuItem::DrawBar(bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame();
|
||||
BMenu* menu = Menu ();
|
||||
frame.right -= 24;
|
||||
frame.left = frame.right-kBarWidth;
|
||||
frame.top += 3;
|
||||
frame.bottom = frame.top+8;
|
||||
if (fKernel < 0)
|
||||
return;
|
||||
if (fGrenze1 < 0)
|
||||
force = true;
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor(gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor(gFrameColor);
|
||||
menu->StrokeRect(frame);
|
||||
}
|
||||
frame.InsetBy(1, 1);
|
||||
BRect r = frame;
|
||||
float grenze1 = frame.left+(frame.right-frame.left)*fKernel;
|
||||
float grenze2 = frame.left+(frame.right-frame.left)*(fKernel+fUser);
|
||||
if (grenze1 > frame.right)
|
||||
grenze1 = frame.right;
|
||||
if (grenze2 > frame.right)
|
||||
grenze2 = frame.right;
|
||||
r.right = grenze1;
|
||||
if (!force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor(gKernelColorSelected);
|
||||
else
|
||||
menu->SetHighColor(gKernelColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor(fThreadID <= gCPUcount ? gIdleColorSelected : gUserColorSelected);
|
||||
else
|
||||
menu->SetHighColor(fThreadID <= gCPUcount ? gIdleColor : gUserColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
r.left = grenze2;
|
||||
r.right = frame.right;
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor(gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor(kWhite);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
menu->SetHighColor(kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void ThreadBarMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
BMenuItem::GetContentSize(width, height);
|
||||
// if (*height < 16)
|
||||
// *height = 16;
|
||||
*width += 10+kBarWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void ThreadBarMenuItem::Highlight(bool on)
|
||||
{
|
||||
if (on) {
|
||||
PriorityMenu * popup = (PriorityMenu *) Submenu ();
|
||||
if (popup)
|
||||
popup->Update (fThreadInfo.priority);
|
||||
}
|
||||
BMenuItem::Highlight (on);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void ThreadBarMenuItem::BarUpdate()
|
||||
{
|
||||
thread_info info;
|
||||
if (get_thread_info(fThreadID, &info) == B_OK) {
|
||||
bigtime_t now = system_time();
|
||||
fKernel = double(info.kernel_time-fThreadInfo.kernel_time)/double(now-fLastTime);
|
||||
fUser = double(info.user_time-fThreadInfo.user_time)/double(now-fLastTime);
|
||||
if (fThreadID <= gCPUcount) {
|
||||
fUser += fKernel;
|
||||
fKernel = 0;
|
||||
}
|
||||
fThreadInfo.user_time = info.user_time;
|
||||
fThreadInfo.kernel_time = info.kernel_time;
|
||||
fLastTime = now;
|
||||
if (IsSelected ()) {
|
||||
PriorityMenu * popup = (PriorityMenu *) Submenu ();
|
||||
if (popup && info.priority != fThreadInfo.priority)
|
||||
popup->Update (info.priority);
|
||||
}
|
||||
fThreadInfo.priority = info.priority;
|
||||
} else
|
||||
fKernel = -1;
|
||||
}
|
||||
|
53
src/apps/processcontroller/ThreadBarMenuItem.h
Normal file
53
src/apps/processcontroller/ThreadBarMenuItem.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
|
||||
ThreadBarMenuItem.h
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _THREAD_BAR_MENU_ITEM_H_
|
||||
#define _THREAD_BAR_MENU_ITEM_H_
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
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 ();
|
||||
double fUser;
|
||||
double fKernel;
|
||||
|
||||
private:
|
||||
thread_id fThreadID;
|
||||
thread_info fThreadInfo;
|
||||
bigtime_t fLastTime;
|
||||
float fGrenze1;
|
||||
float fGrenze2;
|
||||
};
|
||||
|
||||
#endif // _THREAD_BAR_MENU_ITEM_H_
|
||||
|
160
src/apps/processcontroller/URLView.cpp
Normal file
160
src/apps/processcontroller/URLView.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
|
||||
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
src/apps/processcontroller/URLView.h
Normal file
56
src/apps/processcontroller/URLView.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
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_
|
59
src/apps/processcontroller/WindowsTools.cpp
Normal file
59
src/apps/processcontroller/WindowsTools.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
|
||||
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
src/apps/processcontroller/WindowsTools.h
Normal file
33
src/apps/processcontroller/WindowsTools.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
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_
|
52
src/apps/processcontroller/icons.data
Normal file
52
src/apps/processcontroller/icons.data
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
|
||||
icons.data
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
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,
|
||||
0x0,0xfa,0xfa,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xfa,0xfa,0xfa,0xfa,0xfa,0x0,0x0,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0x0,0x1f,0xfa,0xfa,0xfa,0xfa,0x1f,0x5d,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xf9,0x1f,0x1f,0xfa,0x1f,0x5d,0x5d,0x0,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0x0,0x0,0xf9,0xf9,0xf9,0x1f,0x5d,0x5d,0x5d,0x0,0xff,0xff,0xff,0xff,0xff,0x0,0x60,0x1,0xf9,0xf9,0xf9,0xf9,0x5d,
|
||||
0x5d,0x5d,0x0,0x0,0xff,0xff,0xff,0x0,0x60,0x60,0x1,0xf9,0xf9,0xf9,0xf9,0x5d,0x5d,0x5d,0x0,0xa3,0x0,0x0,0x0,0x1f,0x60,0x60,0x60,0x1,0xf9,
|
||||
0xf9,0xf9,0x5d,0x5d,0x0,0xa3,0x1f,0x2d,0x0,0x0,0x86,0x1f,0x1f,0x60,0x1f,0x0,0x0,0xf9,0x5d,0x0,0xa3,0x1f,0x2d,0x2d,0x0,0x0,0x86,0x86,
|
||||
0x86,0x1f,0xd5,0x27,0x0,0x0,0x0,0xa3,0x1f,0x2d,0x2d,0x2e,0x0,0x0,0x86,0x86,0x86,0x86,0xd5,0x28,0x1,0xca,0xca,0xa3,0xa3,0x2d,0x2d,0x2e,
|
||||
0x0,0x0,0x86,0x86,0x86,0x86,0xd5,0xd5,0x0,0xca,0xa3,0xa3,0xa3,0x2d,0x2d,0x2d,0x0,0x0,0x86,0x86,0x86,0x86,0xd5,0xd5,0x0,0xa3,0xa3,0xa3,
|
||||
0xa3,0x2d,0x2d,0x2e,0x1,0xff,0x0,0x0,0x86,0x86,0xd5,0xd5,0x1,0x0,0x0,0xa3,0xa3,0x2d,0x2e,0x0,0x11,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x11,
|
||||
0x11,0xff,0x0,0x0,0x0,0x0,0x11,0x11};
|
||||
|
||||
const uchar k_cpu_mini[] = {
|
||||
0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0x0B, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x04, 0x0C, 0x04, 0x04, 0x0A, 0x04, 0x04, 0x04, 0x08, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x04, 0x04, 0x0C, 0x14, 0x14, 0x16, 0x0C, 0x04, 0x05, 0x0A, 0x04, 0x07, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x04, 0x10, 0x11, 0x12, 0x10, 0x05, 0x14, 0x09, 0x0A, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x04, 0x04, 0x0F, 0x10, 0x11, 0x0C, 0x1B, 0x13, 0x19, 0x09, 0x04, 0x07, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x07, 0x15, 0x0A, 0x03, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x13, 0x10, 0x0E, 0x0B, 0x0E, 0x10, 0x12, 0x09, 0x11, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x04, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x05, 0x04, 0x05, 0x04, 0x07, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x04, 0x04, 0x0D, 0x10, 0x0D, 0x05, 0x11, 0x12, 0x0E, 0x08, 0x04, 0x07, 0xFF, 0xFF,
|
||||
0x00, 0x09, 0x04, 0x04, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05, 0x04, 0x04, 0x07, 0x00, 0xFF,
|
||||
0xFF, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
Loading…
Reference in New Issue
Block a user