From e2940ab6f0f144dafb0b1c5e9056265b94ba0596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 25 May 2006 13:43:27 +0000 Subject: [PATCH] Some changes to make it better fit into a Haiku distribution: * Fixed Terminal signature to Haiku's Terminal. * Removed documentation menu item. * Minor cleanups. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17589 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/processcontroller/PCUtils.cpp | 92 ++++--- src/apps/processcontroller/PCView.cpp | 356 ++++++++++++------------- src/apps/processcontroller/PCView2.cpp | 155 ++++++----- src/apps/processcontroller/PCWorld.cpp | 118 ++++---- 4 files changed, 376 insertions(+), 345 deletions(-) diff --git a/src/apps/processcontroller/PCUtils.cpp b/src/apps/processcontroller/PCUtils.cpp index 92b3359d12..60b7e4a2ed 100644 --- a/src/apps/processcontroller/PCUtils.cpp +++ b/src/apps/processcontroller/PCUtils.cpp @@ -1,9 +1,7 @@ /* - PCUtils.cpp - ProcessController - © 2000, Georges-Edouard Berenger, All Rights Reserved. + ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. Copyright (C) 2004 beunited.org This library is free software; you can redistribute it and/or @@ -19,36 +17,43 @@ 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 +#include "icons.data" + #include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include "icons.data" +#include +#include + #define snooze_time 1000000 team_id gAppServerTeamID = -1; -bool get_team_name_and_icon(infosPack & infopack, bool icon) + +bool +get_team_name_and_icon(infosPack& infopack, bool icon) { - if (gAppServerTeamID == -1 && strcmp (infopack.tminfo.args, "/boot/beos/system/servers/app_server") == 0) + if (gAppServerTeamID == -1 && !strcmp(infopack.tminfo.args, "/boot/beos/system/servers/app_server")) gAppServerTeamID = infopack.tminfo.team; - bool nameFromArgs = false; - bool tryTrackerIcon = true; - for (int len = strlen(infopack.tminfo.args) - 1; len >= 0 && infopack.tminfo.args[len] == ' '; len--) + + 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) { @@ -68,29 +73,36 @@ bool get_team_name_and_icon(infosPack & infopack, bool icon) nameFromArgs = true; tryTrackerIcon = (status == B_OK); } - strncpy(infopack.tmname, nameFromArgs ? infopack.tminfo.args : info.ref.name, B_PATH_NAME_LENGTH - 1); + + 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) + +bool +launch(const char* signature, const char* path) { - status_t st = be_roster->Launch (signature); - if (st != B_OK && path) - { + status_t status = be_roster->Launch(signature); + if (status != B_OK && path) { entry_ref ref; - if (get_ref_for_path (path, &ref) == B_OK) - st = be_roster->Launch (&ref); + if (get_ref_for_path(path, &ref) == B_OK) + status = be_roster->Launch(&ref); } - return (st == B_OK); + return status == B_OK; } -void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float mix) + +void +mix_colors(rgb_color &target, rgb_color & first, rgb_color & second, float mix) { target.red = (uint8)(second.red * mix + (1. - mix) * first.red); target.green = (uint8)(second.green * mix + (1. - mix) * first.green); @@ -98,30 +110,34 @@ void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float target.alpha = (uint8)(second.alpha * mix + (1. - mix) * first.alpha); } -void find_self (entry_ref & ref) + +void +find_self(entry_ref& ref) { - int32 cookie = 0; - image_info info; - while (get_next_image_info (0, &cookie, &info) == B_OK) - { + 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)) - { + && (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; + app_info appInfo; + be_roster->GetAppInfo(kSignature, &appInfo); + ref = appInfo.ref; } -void move_to_deskbar (BDeskbar & db) + +void +move_to_deskbar(BDeskbar& deskbar) { - entry_ref ref; - find_self (ref); - db.AddItem (&ref); + entry_ref ref; + find_self(ref); + + deskbar.AddItem(&ref); } diff --git a/src/apps/processcontroller/PCView.cpp b/src/apps/processcontroller/PCView.cpp index 9e5f4b3020..66e0b27ebc 100644 --- a/src/apps/processcontroller/PCView.cpp +++ b/src/apps/processcontroller/PCView.cpp @@ -84,16 +84,22 @@ typedef struct { } Tdebug_thead_param; extern "C" _EXPORT BView *instantiate_deskbar_item(void); -extern "C" _EXPORT BView *instantiate_deskbar_item(void) + +extern "C" _EXPORT BView * +instantiate_deskbar_item(void) { gInDeskbar = true; - return new ProcessController (); + 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), + : 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) { @@ -106,37 +112,48 @@ ProcessController::ProcessController(BRect frame, bool temp) } } -ProcessController::ProcessController(BMessage *data):BView(data), - fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini), - fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig), - fTemp (false) +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) + +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; + if (gPopupThreadID) { + status_t return_value; wait_for_thread (gPopupThreadID, &return_value); } } + delete fMessageRunner; gPCView = NULL; } -void ProcessController::Init() + +void +ProcessController::Init() { gPCView = this; fMessageRunner = NULL; @@ -147,14 +164,19 @@ void ProcessController::Init() fPrevTime = 0; } -ProcessController *ProcessController::Instantiate(BMessage *data) + +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 + +status_t +ProcessController::Archive(BMessage *data, bool deep) const { BView::Archive(data, deep); data->AddString("add_on", kSignature); @@ -162,7 +184,9 @@ status_t ProcessController::Archive(BMessage *data, bool deep) const return B_OK; } -void ProcessController::MessageReceived(BMessage *message) + +void +ProcessController::MessageReceived(BMessage *message) { team_id team; thread_id thread; @@ -173,7 +197,7 @@ void ProcessController::MessageReceived(BMessage *message) 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)); @@ -239,159 +263,124 @@ void ProcessController::MessageReceived(BMessage *message) set_thread_priority(thread, new_priority); } break; - + case 'Trac': - launch (kTrackerSig, "/boot/beos/system/Tracker"); + launch(kTrackerSig, "/boot/beos/system/Tracker"); break; case 'Dbar': - launch (kDeskbarSig, "/boot/beos/system/Deskbar"); + launch(kDeskbarSig, "/boot/beos/system/Deskbar"); break; case 'Term': - launch (kTerminalSig, "/boot/beos/apps/Terminal"); + 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); - } + { + if (!be_roster->IsRunning(kDeskbarSig)) + launch(kDeskbarSig, "/boot/beos/system/Deskbar"); + BDeskbar deskbar; + if (gInDeskbar || deskbar.HasItem (kDeskbarItemName)) + deskbar.RemoveItem (kDeskbarItemName); + else + move_to_deskbar(deskbar); 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 (); + { + 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; } - else - _kset_cpu_state_ (cpu, !_kget_cpu_state_ (cpu)); } + 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 (); - } - } + case 'Colo': + { + GebsPreferences tPreferences(kPreferencesFileName); + gMimicPulse = (gMimicPulse == 0); + tPreferences.SaveInt32(gMimicPulse, kMimicPulsePref); + DefaultColors(); break; + } case B_ABOUT_REQUESTED: - new AboutPC (BScreen ().Frame ()); + new AboutPC(BScreen().Frame()); break; - + default: - BView::MessageReceived (message); + BView::MessageReceived(message); } } -void ProcessController::DefaultColors () + +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; + + 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) - { + 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) - { + 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 - { + } 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 - { + } 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) - { + + if (!set) { active_color = kKernelBlue; active_color = tint_color (active_color, B_LIGHTEN_2_TINT); idle_color = active_color; @@ -404,41 +393,46 @@ void ProcessController::DefaultColors () // idle_color = kWhite; } -void ProcessController::AttachedToWindow () + +void +ProcessController::AttachedToWindow() { - BView::AttachedToWindow (); - if (Parent ()) - SetViewColor (B_TRANSPARENT_COLOR); + BView::AttachedToWindow(); + if (Parent()) + SetViewColor(B_TRANSPARENT_COLOR); else - SetViewColor (kBlack); - GebsPreferences tPreferences (kPreferencesFileName, NULL, false); - tPreferences.ReadInt32 (gMimicPulse, kMimicPulsePref); - DefaultColors (); + SetViewColor(kBlack); + + GebsPreferences tPreferences(kPreferencesFileName, NULL, false); + tPreferences.ReadInt32(gMimicPulse, kMimicPulsePref); + DefaultColors(); system_info sys_info; - get_system_info (&sys_info); + get_system_info(&sys_info); gCPUcount = sys_info.cpu_count; - Update (); + Update(); gIdleColor = kIdleGreen; - gIdleColorSelected = tint_color (gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT); + gIdleColorSelected = tint_color(gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT); gKernelColor = kKernelBlue; - gKernelColorSelected = tint_color (gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT); + gKernelColorSelected = tint_color(gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT); // gKernelColor = tint_color(gUserColor, B_DARKEN_1_TINT); - gUserColor = tint_color (gKernelColor, B_LIGHTEN_2_TINT); - 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); + 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 + 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'); + 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; @@ -456,31 +450,33 @@ layoutT layout[] = { { 1, 1, 1 }, { 1, 0, 3 } }; // 8 -void ProcessController::Draw(BRect) + +void +ProcessController::Draw(BRect) { - SetDrawingMode (B_OP_COPY); - DoDraw (true); + SetDrawingMode(B_OP_COPY); + DoDraw(true); } -void ProcessController::DoDraw (bool force) + +void +ProcessController::DoDraw(bool force) { //gCPUcount = 1; - BRect bounds (Bounds ()); + BRect bounds(Bounds()); - float h = floorf (bounds.Height ()) - 2; + float h = floorf(bounds.Height ()) - 2; float top = 1, left = 1; float 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 ()) - { + if (force && Parent()) { SetHighColor (Parent ()->ViewColor ()); FillRect (BRect (right + 1, top - 1, right + 2, bottom + 1)); } - if (force) - { + if (force) { SetHighColor (frame_color); StrokeRect (BRect (left - 1, top - 1, right, bottom + 1)); if (gCPUcount == 2) @@ -489,9 +485,8 @@ void ProcessController::DoDraw (bool force) 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++) - { + + for (int x = 0; x < gCPUcount; x++) { right = left + bar_width - 1; float rem = fCPUTimes[x] * (h + 1); float bar_height = floorf (rem); @@ -501,13 +496,11 @@ void ProcessController::DoDraw (bool force) float idle_top = top; if (!force && previous_limit > top) idle_top = previous_limit - 1; - if (limit > idle_top) - { + if (limit > idle_top) { SetHighColor (idle_color); FillRect (BRect (left, idle_top, right, limit - 1)); } - if (bar_height <= h) - { + if (bar_height <= h) { rgb_color fraction_color; mix_colors (fraction_color, idle_color, active_color, rem); SetHighColor (fraction_color); @@ -516,8 +509,7 @@ void ProcessController::DoDraw (bool force) float active_bottom = bottom; if (!force && previous_limit < bottom) active_bottom = previous_limit + 1; - if (limit < active_bottom) - { + if (limit < active_bottom) { SetHighColor(active_color); FillRect(BRect(left, limit + 1, right, active_bottom)); } @@ -540,13 +532,11 @@ void ProcessController::DoDraw (bool force) float free_top = top; if (!force && previous_limit > top) free_top = previous_limit - 1; - if (limit > free_top) - { + if (limit > free_top) { SetHighColor (idle_color); FillRect (BRect (leftMem, free_top, rightMem, limit - 1)); } - if (bar_height <= h) - { + if (bar_height <= h) { rgb_color fraction_color; mix_colors (fraction_color, idle_color, used_memory_color, rem); SetHighColor (fraction_color); @@ -555,15 +545,17 @@ void ProcessController::DoDraw (bool force) float used_bottom = bottom; // if (!force && previous_limit < bottom) // used_bottom = previous_limit + 1; - if (limit < used_bottom) - { + if (limit < used_bottom) { SetHighColor (used_memory_color); FillRect (BRect (leftMem, limit + 1, rightMem, used_bottom)); } fLastMemoryHeight = bar_height; } -void ProcessController::Update () { + +void +ProcessController::Update() +{ system_info sys_info; get_system_info(&sys_info); bigtime_t now = system_time(); @@ -584,14 +576,18 @@ void ProcessController::Update () { fPrevTime = now; } -long thread_quit_application(void *arg) + +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) + +long +thread_debug_thread(void *arg) { Tdebug_thead_param* param = (Tdebug_thead_param*) arg; thread_info thinfo; @@ -602,34 +598,36 @@ long thread_debug_thread (void *arg) 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) - { + 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) - { + 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 - { + 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); + + BAlert* alert = new BAlert("", texte, "Cancel", "Release", NULL, + B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetShortcut(0, B_ESCAPE); - if (alert->Go()) - { + 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 - { + 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(); } diff --git a/src/apps/processcontroller/PCView2.cpp b/src/apps/processcontroller/PCView2.cpp index 4d5da4986a..0a89f2cf6d 100644 --- a/src/apps/processcontroller/PCView2.cpp +++ b/src/apps/processcontroller/PCView2.cpp @@ -1,9 +1,7 @@ /* - PCView2.cpp - - ProcessController - © 2000, Georges-Edouard Berenger, All Rights Reserved. + + ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. Copyright (C) 2004 beunited.org This library is free software; you can redistribute it and/or @@ -19,28 +17,31 @@ 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 "AutoIcon.h" #include "IconMenuItem.h" +#include "MemoryBarMenu.h" +#include "MemoryBarMenuItem.h" +#include "PCUtils.h" +#include "PCWorld.h" +#include "Preferences.h" +#include "QuitMenu.h" #include "TeamBarMenu.h" #include "TeamBarMenuItem.h" #include "ThreadBarMenu.h" -#include "MemoryBarMenu.h" -#include "MemoryBarMenuItem.h" -#include "PCWorld.h" -#include "Preferences.h" -#include "PCUtils.h" -#include "AutoIcon.h" -#include + #include -#include -#include #include +#include +#include +#include + #include + #define addtopbottom(x) if (top) popup->AddItem(x); else popup->AddItem(x, 0) long thread_popup(void *arg); @@ -49,50 +50,59 @@ int32 gPopupFlag = 0; thread_id gPopupThreadID = 0; typedef struct { - BPoint where; - BRect clickToOpenRect; - bool top; + BPoint where; + BRect clickToOpenRect; + bool top; } Tpopup_param; -void ProcessController::MouseDown(BPoint where) + +void +ProcessController::MouseDown(BPoint where) { if (atomic_add (&gPopupFlag, 1) > 0) { atomic_add (&gPopupFlag, -1); return; } - Tpopup_param* param = new Tpopup_param; + + 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); + + gPopupThreadID = spawn_thread(thread_popup, "Popup holder thread", + B_URGENT_DISPLAY_PRIORITY, param); resume_thread(gPopupThreadID); } -long thread_popup(void *arg) + +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++) { + Tpopup_param* param = (Tpopup_param*) arg; + int32 mcookie, hcookie; + long m, h; + BMenuItem* item; + bool top = param->top; + + system_info systemInfo; + get_system_info(&systemInfo); + infosPack* infos = new infosPack[systemInfo.used_teams]; + // TODO: this doesn't necessarily get all teams + for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) { infos[m].tmicon = NULL; infos[m].tmname[0] = 0; infos[m].thinfo = NULL; if (get_next_team_info(&mcookie, &infos[m].tminfo) == B_OK) { infos[m].thinfo = new thread_info[infos[m].tminfo.thread_count]; - for (h = 0, hcookie = 0; h < infos[m].tminfo.thread_count; h++) + 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; + systemInfo.used_teams = m; infos[m].tminfo.team = -1; } } @@ -101,48 +111,48 @@ long thread_popup(void *arg) 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); + BMenu* QuitPopup = new QuitMenu("Quit an Application", infos, systemInfo.used_teams); + QuitPopup->SetFont(be_plain_font); + popup->AddItem(QuitPopup); - //Memory Usage section - MemoryBarMenu* MemoryPopup = new MemoryBarMenu ("Spy Memory Usage", infos, &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++) { + // Memory Usage section + MemoryBarMenu* MemoryPopup = new MemoryBarMenu("Spy Memory Usage", infos, &systemInfo); + int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024); + for (m = 0; m < systemInfo.used_teams; m++) { if (infos[m].tminfo.team >= 0) { - 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); + MemoryBarMenuItem* memoryItem = new MemoryBarMenuItem(infos[m].tmname, infos[m].tminfo.team, infos[m].tmicon, false, NULL); + MemoryPopup->AddItem(memoryItem); + memoryItem->UpdateSituation(commitedMemory); } } - addtopbottom (CPUPopup); - addtopbottom (new BSeparatorItem ()); + + addtopbottom(MemoryPopup); + + // CPU Load section + TeamBarMenu* CPUPopup = new TeamBarMenu("Kill, Debug, or Change Priority", infos, systemInfo.used_teams); + for (m = 0; m < systemInfo.used_teams; m++) { + if (infos[m].tminfo.team >= 0) { + ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].tmname, infos[m].tminfo.team, infos[m].tminfo.thread_count); + BMessage* kill_team = new BMessage('KlTm'); + kill_team->AddInt32("team", infos[m].tminfo.team); + TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team, infos[m].tminfo.team, infos[m].tmicon, false); + item->SetTarget(gPCView); + CPUPopup->AddItem(item); + } + } + + addtopbottom(CPUPopup); + addtopbottom(new BSeparatorItem()); // CPU on/off section - if (gCPUcount > 1) - { - for (int i = 0; i < gCPUcount; i++) - { + 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)) + if (_kget_cpu_state_(i)) item->SetMarked (true); item->SetTarget(gPCView); addtopbottom(item); @@ -180,22 +190,19 @@ long thread_popup(void *arg) item->SetMarked (gMimicPulse); addtopbottom (item); - item = new BMenuItem("Read Documentation", new BMessage ('Docu')); - item->SetTarget (gPCView); - addtopbottom (item); + addtopbottom(new BSeparatorItem ()); - addtopbottom (new BSeparatorItem ()); - - item = new IconMenuItem (gPCView->fProcessControllerIcon, "About ProcessController", new BMessage(B_ABOUT_REQUESTED)); + 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++) { + for (m = 0; m < systemInfo.used_teams; m++) { if (infos[m].tminfo.team >= 0) { delete[] infos[m].thinfo; delete infos[m].tmicon; diff --git a/src/apps/processcontroller/PCWorld.cpp b/src/apps/processcontroller/PCWorld.cpp index d4abe90c2c..ce117c2876 100644 --- a/src/apps/processcontroller/PCWorld.cpp +++ b/src/apps/processcontroller/PCWorld.cpp @@ -1,9 +1,7 @@ /* - PCWorld.cpp - - ProcessController - © 2000, Georges-Edouard Berenger, All Rights Reserved. + + ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. Copyright (C) 2004 beunited.org This library is free software; you can redistribute it and/or @@ -19,91 +17,103 @@ 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 -#include + #include #include -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"; +#include +#include -thread_id id = 0; +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.Haiku-Terminal"; +const char* kPreferencesFileName = "ProcessController Prefs"; -int main() -{ - PCApplication application; - application.Run(); - return B_OK; -} +thread_id id = 0; -PCApplication::PCApplication():BApplication(kSignature) + +PCApplication::PCApplication() + : BApplication(kSignature) { } + PCApplication::~PCApplication() { - status_t thread_return_value; if (id) { - wait_for_thread(id, &thread_return_value); - id = 0; + status_t returnValue; + wait_for_thread(id, &returnValue); } } -void PCApplication::ReadyToRun () + +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); + + // quit other eventually running instances + BList list; + be_roster->GetAppList(kSignature, &list); + long count = list.CountItems(); + if (count > 1) { + for (long i = 0; i < count - 1; i++) { + BMessenger* otherme = new BMessenger(NULL, (team_id)list.ItemAt(i)); + BMessage* message = new BMessage(B_QUIT_REQUESTED); + otherme->SendMessage(message); delete otherme; } } } -void PCApplication::ArgvReceived (int32 argc, char **argv) + +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); + 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); + 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) { + remove("/boot/home/config/settings/Tracker/tracker_shelf"); + launch(kTrackerSig, "/boot/beos/system/Tracker"); + } else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) { + BDeskbar deskbar; + if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName)) + move_to_deskbar(deskbar); + } 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 (); + + Quit(); } + + +// #pragma mark - + + +int +main() +{ + PCApplication application; + application.Run(); + + return B_OK; +} +