Some cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13124 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-06-14 19:49:18 +00:00
parent 57bbc53987
commit 80f47570a5
7 changed files with 212 additions and 150 deletions

View File

@ -30,7 +30,7 @@ enum {
ITEM_OFFSET = 27 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_NORMAL_MODE 'pvnm'
#define PV_MINI_MODE 'pvmm' #define PV_MINI_MODE 'pvmm'

View File

@ -21,7 +21,8 @@ App Pulse : BottomPrefsView.cpp
PulseView.cpp PulseView.cpp
PulseWindow.cpp PulseWindow.cpp
$(r5_src) $(r5_src)
: libbe.so # : libbe.so
: libopenbeos.so
: Pulse.rdef ; : Pulse.rdef ;
if $(HAIKU_COMPATIBLE) { if $(HAIKU_COMPATIBLE) {

View File

@ -69,7 +69,7 @@ resource app_version
internal = 0, internal = 0,
short_info = "Pulse 1.0.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; resource app_flags B_SINGLE_LAUNCH;

View File

@ -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 "PulseApp.h"
#include "Common.h" #include "Common.h"
#include "PulseWindow.h" #include "PulseWindow.h"
#include "DeskbarPulseView.h" #include "DeskbarPulseView.h"
#include <interface/Alert.h> #include <interface/Alert.h>
#include <interface/Rect.h> #include <interface/Rect.h>
#include <interface/Deskbar.h> #include <interface/Deskbar.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
// 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 PulseApp::PulseApp(int argc, char **argv)
// for each CPU, at least one pixel wide : BApplication(APP_SIGNATURE)
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) {
prefs = new Prefs(); prefs = new Prefs();
int mini = false, deskbar = false, normal = false; int mini = false, deskbar = false, normal = false;
@ -109,12 +47,13 @@ PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) {
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{0,0,0,0} {0,0,0,0}
}; };
int c = getopt_long (argc, argv, "hw:", long_options, &option_index); int c = getopt_long(argc, argv, "hw:", long_options, &option_index);
if (c == -1) break; if (c == -1)
break;
switch (c) { switch (c) {
case 0: case 0:
switch(option_index) { switch (option_index) {
case 2: /* framecolor */ case 2: /* framecolor */
case 3: /* activecolor */ case 3: /* activecolor */
case 4: /* idlecolor */ case 4: /* idlecolor */
@ -147,28 +86,38 @@ PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) {
Usage(); Usage();
break; break;
default: default:
printf ("?? getopt returned character code 0%o ??\n", c); printf("?? getopt returned character code 0%o ??\n", c);
break; break;
} }
} }
if (deskbar) { if (deskbar) {
prefs->window_mode = DESKBAR_MODE; prefs->window_mode = DESKBAR_MODE;
if (activecolor != 0) prefs->deskbar_active_color = activecolor; if (activecolor != 0)
if (idlecolor != 0) prefs->deskbar_idle_color = idlecolor; prefs->deskbar_active_color = activecolor;
if (framecolor != 0) prefs->deskbar_frame_color = framecolor; if (idlecolor != 0)
prefs->deskbar_idle_color = idlecolor;
if (framecolor != 0)
prefs->deskbar_frame_color = framecolor;
} else if (mini) { } else if (mini) {
prefs->window_mode = MINI_WINDOW_MODE; prefs->window_mode = MINI_WINDOW_MODE;
if (activecolor != 0) prefs->mini_active_color = activecolor; if (activecolor != 0)
if (idlecolor != 0) prefs->mini_idle_color = idlecolor; prefs->mini_active_color = activecolor;
if (framecolor != 0) prefs->mini_frame_color = framecolor; if (idlecolor != 0)
} else if (normal) prefs->window_mode = NORMAL_WINDOW_MODE; prefs->mini_idle_color = idlecolor;
if (framecolor != 0)
prefs->mini_frame_color = framecolor;
} else if (normal)
prefs->window_mode = NORMAL_WINDOW_MODE;
prefs->Save(); prefs->Save();
BuildPulse(); BuildPulse();
} }
void PulseApp::BuildPulse() {
void
PulseApp::BuildPulse()
{
PulseWindow *pulsewindow = NULL; PulseWindow *pulsewindow = NULL;
if (prefs->window_mode == NORMAL_WINDOW_MODE) { if (prefs->window_mode == NORMAL_WINDOW_MODE) {
pulsewindow = new PulseWindow(prefs->normal_window_rect); pulsewindow = new PulseWindow(prefs->normal_window_rect);
@ -186,19 +135,105 @@ void PulseApp::BuildPulse() {
pulsewindow = new PulseWindow(prefs->normal_window_rect); pulsewindow = new PulseWindow(prefs->normal_window_rect);
} }
} }
pulsewindow->Show(); pulsewindow->Show();
} }
PulseApp::~PulseApp() {
PulseApp::~PulseApp()
{
// Load the replicant after we save our preferences so they don't // Load the replicant after we save our preferences so they don't
// get overwritten by DeskbarPulseView's instance // get overwritten by DeskbarPulseView's instance
prefs->Save(); prefs->Save();
if (prefs->window_mode == DESKBAR_MODE) LoadInDeskbar(); if (prefs->window_mode == DESKBAR_MODE)
LoadInDeskbar();
delete prefs; 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 *pulseapp = new PulseApp(argc, argv);
pulseapp->Run(); pulseapp->Run();
delete pulseapp; delete pulseapp;

View File

@ -11,23 +11,25 @@
#ifndef PULSEAPP_H #ifndef PULSEAPP_H
#define PULSEAPP_H #define PULSEAPP_H
#include <app/Application.h> #include <app/Application.h>
#include "Prefs.h" #include "Prefs.h"
bool LastEnabledCPU(int my_cpu);
int GetMinimumViewWidth();
bool LoadInDeskbar();
void Usage();
class PulseApp : public BApplication { class PulseApp : public BApplication {
public: public:
PulseApp(int argc, char **argv); PulseApp(int argc, char **argv);
~PulseApp(); ~PulseApp();
Prefs *prefs; Prefs *prefs;
private: private:
void BuildPulse(); void BuildPulse();
}; };
#endif extern bool LastEnabledCPU(int cpu);
extern int GetMinimumViewWidth();
extern bool LoadInDeskbar();
extern void Usage();
#endif // PULSEAPP_H

View File

@ -8,43 +8,62 @@
// //
//**************************************************************************************** //****************************************************************************************
#include "PulseWindow.h" #include "PulseWindow.h"
#include "PulseApp.h" #include "PulseApp.h"
#include "Common.h" #include "Common.h"
#include "DeskbarPulseView.h" #include "DeskbarPulseView.h"
#include <interface/Alert.h> #include <interface/Alert.h>
#include <interface/Deskbar.h> #include <interface/Deskbar.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
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); SetPulseRate(200000);
PulseApp *pulseapp = (PulseApp *)be_app; PulseApp *pulseapp = (PulseApp *)be_app;
BRect bounds = Bounds(); BRect bounds = Bounds();
normalpulseview = new NormalPulseView(bounds); fNormalPulseView = new NormalPulseView(bounds);
AddChild(normalpulseview); AddChild(fNormalPulseView);
minipulseview = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs);
AddChild(minipulseview); AddChild(fMiniPulseView);
mode = pulseapp->prefs->window_mode; fMode = pulseapp->prefs->window_mode;
if (mode == MINI_WINDOW_MODE) { if (fMode == MINI_WINDOW_MODE) {
SetLook(B_MODAL_WINDOW_LOOK); SetLook(B_MODAL_WINDOW_LOOK);
SetFeel(B_NORMAL_WINDOW_FEEL); SetFeel(B_NORMAL_WINDOW_FEEL);
SetFlags(B_NOT_ZOOMABLE); SetFlags(B_NOT_ZOOMABLE);
normalpulseview->Hide(); fNormalPulseView->Hide();
SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
ResizeTo(rect.Width(), rect.Height()); ResizeTo(rect.Width(), rect.Height());
} else minipulseview->Hide(); } else
fMiniPulseView->Hide();
prefswindow = NULL;
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_NORMAL_MODE:
case PV_MINI_MODE: case PV_MINI_MODE:
case PV_DESKBAR_MODE: case PV_DESKBAR_MODE:
@ -52,25 +71,25 @@ void PulseWindow::MessageReceived(BMessage *message) {
break; break;
case PRV_NORMAL_FADE_COLORS: case PRV_NORMAL_FADE_COLORS:
case PRV_NORMAL_CHANGE_COLOR: case PRV_NORMAL_CHANGE_COLOR:
normalpulseview->UpdateColors(message); fNormalPulseView->UpdateColors(message);
break; break;
case PRV_MINI_CHANGE_COLOR: case PRV_MINI_CHANGE_COLOR:
minipulseview->UpdateColors(message); fMiniPulseView->UpdateColors(message);
break; break;
case PRV_QUIT: case PRV_QUIT:
prefswindow = NULL; fPrefsWindow = NULL;
break; break;
case PV_PREFERENCES: { case PV_PREFERENCES: {
// If the window is already open, bring it to the front // If the window is already open, bring it to the front
if (prefswindow != NULL) { if (fPrefsWindow != NULL) {
prefswindow->Activate(true); fPrefsWindow->Activate(true);
break; break;
} }
// Otherwise launch a new preferences window // Otherwise launch a new preferences window
PulseApp *pulseapp = (PulseApp *)be_app; 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); "Pulse Preferences", new BMessenger(this), pulseapp->prefs);
prefswindow->Show(); fPrefsWindow->Show();
break; break;
} }
case PV_ABOUT: { case PV_ABOUT: {
@ -84,8 +103,10 @@ void PulseWindow::MessageReceived(BMessage *message) {
break; break;
case PV_CPU_MENU_ITEM: case PV_CPU_MENU_ITEM:
// Call the correct version based on whose menu sent the message // Call the correct version based on whose menu sent the message
if (minipulseview->IsHidden()) normalpulseview->ChangeCPUState(message); if (fMiniPulseView->IsHidden())
else minipulseview->ChangeCPUState(message); fNormalPulseView->ChangeCPUState(message);
else
fMiniPulseView->ChangeCPUState(message);
break; break;
default: default:
BWindow::MessageReceived(message); 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; PulseApp *pulseapp = (PulseApp *)be_app;
switch (newmode) { switch (newmode) {
case PV_NORMAL_MODE: case PV_NORMAL_MODE:
if (mode == MINI_WINDOW_MODE) { if (fMode == MINI_WINDOW_MODE) {
pulseapp->prefs->mini_window_rect = Frame(); pulseapp->prefs->mini_window_rect = Frame();
pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE;
pulseapp->prefs->Save(); pulseapp->prefs->Save();
} }
minipulseview->Hide(); fMiniPulseView->Hide();
normalpulseview->Show(); fNormalPulseView->Show();
mode = NORMAL_WINDOW_MODE; fMode = NORMAL_WINDOW_MODE;
SetType(B_TITLED_WINDOW); SetType(B_TITLED_WINDOW);
SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(),
@ -113,14 +137,14 @@ void PulseWindow::SetMode(int newmode) {
pulseapp->prefs->normal_window_rect.top); pulseapp->prefs->normal_window_rect.top);
break; break;
case PV_MINI_MODE: case PV_MINI_MODE:
if (mode == NORMAL_WINDOW_MODE) { if (fMode == NORMAL_WINDOW_MODE) {
pulseapp->prefs->normal_window_rect = Frame(); pulseapp->prefs->normal_window_rect = Frame();
pulseapp->prefs->window_mode = MINI_WINDOW_MODE; pulseapp->prefs->window_mode = MINI_WINDOW_MODE;
pulseapp->prefs->Save(); pulseapp->prefs->Save();
} }
normalpulseview->Hide(); fNormalPulseView->Hide();
minipulseview->Show(); fMiniPulseView->Show();
mode = MINI_WINDOW_MODE; fMode = MINI_WINDOW_MODE;
SetLook(B_MODAL_WINDOW_LOOK); SetLook(B_MODAL_WINDOW_LOOK);
SetFeel(B_NORMAL_WINDOW_FEEL); SetFeel(B_NORMAL_WINDOW_FEEL);
SetFlags(B_NOT_ZOOMABLE); 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); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }

View File

@ -11,11 +11,14 @@
#ifndef PULSEWINDOW_H #ifndef PULSEWINDOW_H
#define PULSEWINDOW_H #define PULSEWINDOW_H
#include <interface/Window.h> #include <interface/Window.h>
#include "NormalPulseView.h" #include "NormalPulseView.h"
#include "MiniPulseView.h" #include "MiniPulseView.h"
#include "PrefsWindow.h" #include "PrefsWindow.h"
class PulseWindow : public BWindow { class PulseWindow : public BWindow {
public: public:
PulseWindow(BRect rect); PulseWindow(BRect rect);
@ -25,10 +28,10 @@ class PulseWindow : public BWindow {
void SetMode(int newmode); void SetMode(int newmode);
private: private:
NormalPulseView *normalpulseview; NormalPulseView* fNormalPulseView;
MiniPulseView *minipulseview; MiniPulseView* fMiniPulseView;
PrefsWindow *prefswindow; PrefsWindow* fPrefsWindow;
int mode; int32 fMode;
}; };
#endif #endif // PULSEWINDOW_H