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
};
#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'

View File

@ -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) {

View File

@ -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;

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 "Common.h"
#include "PulseWindow.h"
#include "DeskbarPulseView.h"
#include <interface/Alert.h>
#include <interface/Rect.h>
#include <interface/Deskbar.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.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
// 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;

View File

@ -11,23 +11,25 @@
#ifndef PULSEAPP_H
#define PULSEAPP_H
#include <app/Application.h>
#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

View File

@ -8,43 +8,62 @@
//
//****************************************************************************************
#include "PulseWindow.h"
#include "PulseApp.h"
#include "Common.h"
#include "DeskbarPulseView.h"
#include <interface/Alert.h>
#include <interface/Deskbar.h>
#include <stdlib.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);
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;
}

View File

@ -11,11 +11,14 @@
#ifndef PULSEWINDOW_H
#define PULSEWINDOW_H
#include <interface/Window.h>
#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