From 80f47570a5b87aa2b9dff4b7d67ea2b414887cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 14 Jun 2005 19:49:18 +0000 Subject: [PATCH] Some cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13124 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/pulse/Common.h | 2 +- src/apps/pulse/Jamfile | 3 +- src/apps/pulse/Pulse.rdef | 2 +- src/apps/pulse/PulseApp.cpp | 225 +++++++++++++++++++-------------- src/apps/pulse/PulseApp.h | 14 +- src/apps/pulse/PulseWindow.cpp | 103 +++++++++------ src/apps/pulse/PulseWindow.h | 13 +- 7 files changed, 212 insertions(+), 150 deletions(-) diff --git a/src/apps/pulse/Common.h b/src/apps/pulse/Common.h index 54d87e89bc..b21284c3d7 100644 --- a/src/apps/pulse/Common.h +++ b/src/apps/pulse/Common.h @@ -30,7 +30,7 @@ enum { ITEM_OFFSET = 27 }; -#define APP_SIGNATURE "application/x-vnd.Be-PULS" +#define APP_SIGNATURE "application/x-vnd.Haiku-Pulse" #define PV_NORMAL_MODE 'pvnm' #define PV_MINI_MODE 'pvmm' diff --git a/src/apps/pulse/Jamfile b/src/apps/pulse/Jamfile index 6dd7c28a27..a687d69418 100644 --- a/src/apps/pulse/Jamfile +++ b/src/apps/pulse/Jamfile @@ -21,7 +21,8 @@ App Pulse : BottomPrefsView.cpp PulseView.cpp PulseWindow.cpp $(r5_src) - : libbe.so +# : libbe.so + : libopenbeos.so : Pulse.rdef ; if $(HAIKU_COMPATIBLE) { diff --git a/src/apps/pulse/Pulse.rdef b/src/apps/pulse/Pulse.rdef index 13c64a05d2..cd7975e31f 100644 --- a/src/apps/pulse/Pulse.rdef +++ b/src/apps/pulse/Pulse.rdef @@ -69,7 +69,7 @@ resource app_version internal = 0, short_info = "Pulse 1.0.0", - long_info = "Pulse 1.0.0 ©2004 Haiku" + long_info = "Pulse 1.0.0 ©2005 Haiku" }; resource app_flags B_SINGLE_LAUNCH; diff --git a/src/apps/pulse/PulseApp.cpp b/src/apps/pulse/PulseApp.cpp index 9c60d7c6ce..67e305bde9 100644 --- a/src/apps/pulse/PulseApp.cpp +++ b/src/apps/pulse/PulseApp.cpp @@ -1,96 +1,34 @@ /* + * Copyright 2002-2005 Haiku + * Distributed under the terms of the MIT license. + * + * Updated by Sikosis (beos@gravity24hr.com) + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + * Written by: Daniel Switkin + */ -"Pulse" Updated by Sikosis (beos@gravity24hr.com) - -(C)2002 OpenBeOS under MIT license - -Copyright 1999, Be Incorporated. All Rights Reserved. -This file may be used under the terms of the Be Sample Code License. - -*/ - -//**************************************************************************************** -// -// File: PulseApp.cpp -// -// Written by: Daniel Switkin -// -// Copyright 1999, Be Incorporated -// -//**************************************************************************************** #include "PulseApp.h" #include "Common.h" #include "PulseWindow.h" #include "DeskbarPulseView.h" + #include #include #include + #include #include #include #include -// Make sure we don't disable the last CPU - this is needed by -// descendants of PulseView for the popup menu and for CPUButton -// both as a replicant and not -bool LastEnabledCPU(int my_cpu) { - system_info sys_info; - get_system_info(&sys_info); - if (sys_info.cpu_count == 1) return true; - - for (int x = 0; x < sys_info.cpu_count; x++) { - if (x == my_cpu) continue; - if (_kget_cpu_state_(x) == 1) return false; - } - return true; -} -// Ensure that the mini mode and deskbar mode always show an indicator -// for each CPU, at least one pixel wide -int GetMinimumViewWidth() { - system_info sys_info; - get_system_info(&sys_info); - return (sys_info.cpu_count * 2) + 1; -} - -void Usage() { - printf("Usage: Pulse [--mini] [-w width] [--width=width]\n" - "\t[--deskbar] [--normal] [--framecolor 0xrrggbb]\n" - "\t[--activecolor 0xrrggbb] [--idlecolor 0xrrggbb]\n"); - exit(0); -} - -bool LoadInDeskbar() { - PulseApp *pulseapp = (PulseApp *)be_app; - BDeskbar *deskbar = new BDeskbar(); - // Don't allow two copies in the Deskbar at once - if (deskbar->HasItem("DeskbarPulseView")) { - delete deskbar; - return false; - } - - // Must be 16 pixels high, the width is retrieved from the Prefs class - int width = pulseapp->prefs->deskbar_icon_width; - int min_width = GetMinimumViewWidth(); - if (width < min_width) { - pulseapp->prefs->deskbar_icon_width = min_width; - width = min_width; - } - - BRect rect(0, 0, width - 1, 15); - DeskbarPulseView *replicant = new DeskbarPulseView(rect); - status_t err = deskbar->AddItem(replicant); - delete replicant; - delete deskbar; - if (err != B_OK) { - BAlert *alert = new BAlert(NULL, strerror(err), "OK"); - alert->Go(NULL); - return false; - } else return true; -} - -PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) { +PulseApp::PulseApp(int argc, char **argv) + : BApplication(APP_SIGNATURE) +{ prefs = new Prefs(); int mini = false, deskbar = false, normal = false; @@ -109,12 +47,13 @@ PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) { {"help", 0, 0, 'h'}, {0,0,0,0} }; - int c = getopt_long (argc, argv, "hw:", long_options, &option_index); - if (c == -1) break; - + int c = getopt_long(argc, argv, "hw:", long_options, &option_index); + if (c == -1) + break; + switch (c) { case 0: - switch(option_index) { + switch (option_index) { case 2: /* framecolor */ case 3: /* activecolor */ case 4: /* idlecolor */ @@ -147,28 +86,38 @@ PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) { Usage(); break; default: - printf ("?? getopt returned character code 0%o ??\n", c); + printf("?? getopt returned character code 0%o ??\n", c); break; } } if (deskbar) { prefs->window_mode = DESKBAR_MODE; - if (activecolor != 0) prefs->deskbar_active_color = activecolor; - if (idlecolor != 0) prefs->deskbar_idle_color = idlecolor; - if (framecolor != 0) prefs->deskbar_frame_color = framecolor; + if (activecolor != 0) + prefs->deskbar_active_color = activecolor; + if (idlecolor != 0) + prefs->deskbar_idle_color = idlecolor; + if (framecolor != 0) + prefs->deskbar_frame_color = framecolor; } else if (mini) { prefs->window_mode = MINI_WINDOW_MODE; - if (activecolor != 0) prefs->mini_active_color = activecolor; - if (idlecolor != 0) prefs->mini_idle_color = idlecolor; - if (framecolor != 0) prefs->mini_frame_color = framecolor; - } else if (normal) prefs->window_mode = NORMAL_WINDOW_MODE; - + if (activecolor != 0) + prefs->mini_active_color = activecolor; + if (idlecolor != 0) + prefs->mini_idle_color = idlecolor; + if (framecolor != 0) + prefs->mini_frame_color = framecolor; + } else if (normal) + prefs->window_mode = NORMAL_WINDOW_MODE; + prefs->Save(); BuildPulse(); } -void PulseApp::BuildPulse() { + +void +PulseApp::BuildPulse() +{ PulseWindow *pulsewindow = NULL; if (prefs->window_mode == NORMAL_WINDOW_MODE) { pulsewindow = new PulseWindow(prefs->normal_window_rect); @@ -186,19 +135,105 @@ void PulseApp::BuildPulse() { pulsewindow = new PulseWindow(prefs->normal_window_rect); } } - + pulsewindow->Show(); } -PulseApp::~PulseApp() { + +PulseApp::~PulseApp() +{ // Load the replicant after we save our preferences so they don't // get overwritten by DeskbarPulseView's instance prefs->Save(); - if (prefs->window_mode == DESKBAR_MODE) LoadInDeskbar(); + if (prefs->window_mode == DESKBAR_MODE) + LoadInDeskbar(); + delete prefs; } -int main(int argc, char **argv) { + +// #pragma mark - + + +/** Make sure we don't disable the last CPU - this is needed by + * descendants of PulseView for the popup menu and for CPUButton + * both as a replicant and not. + */ + +bool +LastEnabledCPU(int my_cpu) +{ + system_info sys_info; + get_system_info(&sys_info); + if (sys_info.cpu_count == 1) + return true; + + for (int x = 0; x < sys_info.cpu_count; x++) { + if (x == my_cpu) continue; + if (_kget_cpu_state_(x) == 1) return false; + } + return true; +} + + +/** Ensure that the mini mode and deskbar mode always show an indicator + * for each CPU, at least one pixel wide. + */ + +int +GetMinimumViewWidth() +{ + system_info sys_info; + get_system_info(&sys_info); + return (sys_info.cpu_count * 2) + 1; +} + + +void +Usage() +{ + printf("Usage: Pulse [--mini] [-w width] [--width=width]\n" + "\t[--deskbar] [--normal] [--framecolor 0xrrggbb]\n" + "\t[--activecolor 0xrrggbb] [--idlecolor 0xrrggbb]\n"); + exit(0); +} + + +bool +LoadInDeskbar() +{ + PulseApp *pulseapp = (PulseApp *)be_app; + BDeskbar *deskbar = new BDeskbar(); + // Don't allow two copies in the Deskbar at once + if (deskbar->HasItem("DeskbarPulseView")) { + delete deskbar; + return false; + } + + // Must be 16 pixels high, the width is retrieved from the Prefs class + int width = pulseapp->prefs->deskbar_icon_width; + int min_width = GetMinimumViewWidth(); + if (width < min_width) { + pulseapp->prefs->deskbar_icon_width = min_width; + width = min_width; + } + + BRect rect(0, 0, width - 1, 15); + DeskbarPulseView *replicant = new DeskbarPulseView(rect); + status_t err = deskbar->AddItem(replicant); + delete replicant; + delete deskbar; + if (err != B_OK) { + BAlert *alert = new BAlert(NULL, strerror(err), "OK"); + alert->Go(NULL); + return false; + } else return true; +} + + +int +main(int argc, char **argv) +{ PulseApp *pulseapp = new PulseApp(argc, argv); pulseapp->Run(); delete pulseapp; diff --git a/src/apps/pulse/PulseApp.h b/src/apps/pulse/PulseApp.h index fc19930b71..dc3e7fec2d 100644 --- a/src/apps/pulse/PulseApp.h +++ b/src/apps/pulse/PulseApp.h @@ -11,23 +11,25 @@ #ifndef PULSEAPP_H #define PULSEAPP_H + #include #include "Prefs.h" -bool LastEnabledCPU(int my_cpu); -int GetMinimumViewWidth(); -bool LoadInDeskbar(); -void Usage(); class PulseApp : public BApplication { public: PulseApp(int argc, char **argv); ~PulseApp(); - + Prefs *prefs; private: void BuildPulse(); }; -#endif +extern bool LastEnabledCPU(int cpu); +extern int GetMinimumViewWidth(); +extern bool LoadInDeskbar(); +extern void Usage(); + +#endif // PULSEAPP_H diff --git a/src/apps/pulse/PulseWindow.cpp b/src/apps/pulse/PulseWindow.cpp index e01a98ba2f..844f7fcc44 100644 --- a/src/apps/pulse/PulseWindow.cpp +++ b/src/apps/pulse/PulseWindow.cpp @@ -8,43 +8,62 @@ // //**************************************************************************************** + #include "PulseWindow.h" #include "PulseApp.h" #include "Common.h" + #include "DeskbarPulseView.h" #include #include + #include #include -PulseWindow::PulseWindow(BRect rect) : - BWindow(rect, "Pulse", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { +PulseWindow::PulseWindow(BRect rect) : + BWindow(rect, "Pulse", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +{ SetPulseRate(200000); - + PulseApp *pulseapp = (PulseApp *)be_app; BRect bounds = Bounds(); - normalpulseview = new NormalPulseView(bounds); - AddChild(normalpulseview); - - minipulseview = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); - AddChild(minipulseview); - - mode = pulseapp->prefs->window_mode; - if (mode == MINI_WINDOW_MODE) { + fNormalPulseView = new NormalPulseView(bounds); + AddChild(fNormalPulseView); + + fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); + AddChild(fMiniPulseView); + + fMode = pulseapp->prefs->window_mode; + if (fMode == MINI_WINDOW_MODE) { SetLook(B_MODAL_WINDOW_LOOK); SetFeel(B_NORMAL_WINDOW_FEEL); SetFlags(B_NOT_ZOOMABLE); - normalpulseview->Hide(); + fNormalPulseView->Hide(); SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); ResizeTo(rect.Width(), rect.Height()); - } else minipulseview->Hide(); - - prefswindow = NULL; + } else + fMiniPulseView->Hide(); + + fPrefsWindow = NULL; } -void PulseWindow::MessageReceived(BMessage *message) { - switch(message->what) { + +PulseWindow::~PulseWindow() +{ + PulseApp *pulseapp = (PulseApp *)be_app; + + if (fMode == NORMAL_WINDOW_MODE) + pulseapp->prefs->normal_window_rect = Frame(); + else if (fMode == MINI_WINDOW_MODE) + pulseapp->prefs->mini_window_rect = Frame(); +} + + +void +PulseWindow::MessageReceived(BMessage *message) +{ + switch (message->what) { case PV_NORMAL_MODE: case PV_MINI_MODE: case PV_DESKBAR_MODE: @@ -52,25 +71,25 @@ void PulseWindow::MessageReceived(BMessage *message) { break; case PRV_NORMAL_FADE_COLORS: case PRV_NORMAL_CHANGE_COLOR: - normalpulseview->UpdateColors(message); + fNormalPulseView->UpdateColors(message); break; case PRV_MINI_CHANGE_COLOR: - minipulseview->UpdateColors(message); + fMiniPulseView->UpdateColors(message); break; case PRV_QUIT: - prefswindow = NULL; + fPrefsWindow = NULL; break; case PV_PREFERENCES: { // If the window is already open, bring it to the front - if (prefswindow != NULL) { - prefswindow->Activate(true); + if (fPrefsWindow != NULL) { + fPrefsWindow->Activate(true); break; } // Otherwise launch a new preferences window PulseApp *pulseapp = (PulseApp *)be_app; - prefswindow = new PrefsWindow(pulseapp->prefs->prefs_window_rect, + fPrefsWindow = new PrefsWindow(pulseapp->prefs->prefs_window_rect, "Pulse Preferences", new BMessenger(this), pulseapp->prefs); - prefswindow->Show(); + fPrefsWindow->Show(); break; } case PV_ABOUT: { @@ -84,8 +103,10 @@ void PulseWindow::MessageReceived(BMessage *message) { break; case PV_CPU_MENU_ITEM: // Call the correct version based on whose menu sent the message - if (minipulseview->IsHidden()) normalpulseview->ChangeCPUState(message); - else minipulseview->ChangeCPUState(message); + if (fMiniPulseView->IsHidden()) + fNormalPulseView->ChangeCPUState(message); + else + fMiniPulseView->ChangeCPUState(message); break; default: BWindow::MessageReceived(message); @@ -93,18 +114,21 @@ void PulseWindow::MessageReceived(BMessage *message) { } } -void PulseWindow::SetMode(int newmode) { + +void +PulseWindow::SetMode(int newmode) +{ PulseApp *pulseapp = (PulseApp *)be_app; switch (newmode) { case PV_NORMAL_MODE: - if (mode == MINI_WINDOW_MODE) { + if (fMode == MINI_WINDOW_MODE) { pulseapp->prefs->mini_window_rect = Frame(); pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; pulseapp->prefs->Save(); } - minipulseview->Hide(); - normalpulseview->Show(); - mode = NORMAL_WINDOW_MODE; + fMiniPulseView->Hide(); + fNormalPulseView->Show(); + fMode = NORMAL_WINDOW_MODE; SetType(B_TITLED_WINDOW); SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), @@ -113,14 +137,14 @@ void PulseWindow::SetMode(int newmode) { pulseapp->prefs->normal_window_rect.top); break; case PV_MINI_MODE: - if (mode == NORMAL_WINDOW_MODE) { + if (fMode == NORMAL_WINDOW_MODE) { pulseapp->prefs->normal_window_rect = Frame(); pulseapp->prefs->window_mode = MINI_WINDOW_MODE; pulseapp->prefs->Save(); } - normalpulseview->Hide(); - minipulseview->Show(); - mode = MINI_WINDOW_MODE; + fNormalPulseView->Hide(); + fMiniPulseView->Show(); + fMode = MINI_WINDOW_MODE; SetLook(B_MODAL_WINDOW_LOOK); SetFeel(B_NORMAL_WINDOW_FEEL); SetFlags(B_NOT_ZOOMABLE); @@ -140,13 +164,10 @@ void PulseWindow::SetMode(int newmode) { } } -PulseWindow::~PulseWindow() { - PulseApp *pulseapp = (PulseApp *)be_app; - if (mode == NORMAL_WINDOW_MODE) pulseapp->prefs->normal_window_rect = Frame(); - else if (mode == MINI_WINDOW_MODE) pulseapp->prefs->mini_window_rect = Frame(); -} -bool PulseWindow::QuitRequested() { +bool +PulseWindow::QuitRequested() +{ be_app->PostMessage(B_QUIT_REQUESTED); return true; } diff --git a/src/apps/pulse/PulseWindow.h b/src/apps/pulse/PulseWindow.h index 384bf5b736..0a263d4da4 100644 --- a/src/apps/pulse/PulseWindow.h +++ b/src/apps/pulse/PulseWindow.h @@ -11,11 +11,14 @@ #ifndef PULSEWINDOW_H #define PULSEWINDOW_H + #include + #include "NormalPulseView.h" #include "MiniPulseView.h" #include "PrefsWindow.h" + class PulseWindow : public BWindow { public: PulseWindow(BRect rect); @@ -25,10 +28,10 @@ class PulseWindow : public BWindow { void SetMode(int newmode); private: - NormalPulseView *normalpulseview; - MiniPulseView *minipulseview; - PrefsWindow *prefswindow; - int mode; + NormalPulseView* fNormalPulseView; + MiniPulseView* fMiniPulseView; + PrefsWindow* fPrefsWindow; + int32 fMode; }; -#endif +#endif // PULSEWINDOW_H