* Fixed typos, this also closes ticket #4026.
* Fixed many coding style issues. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StatusView.h"
|
#include "StatusView.h"
|
||||||
#include "CPUFrequencyView.h"
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -19,14 +20,16 @@
|
|||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include "CPUFrequencyView.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
||||||
|
|
||||||
|
|
||||||
#define MAX_FREQ_STRING "9999MHz"
|
#define MAX_FREQ_STRING "9999MHz"
|
||||||
|
|
||||||
// messages FrequencySwitcher
|
// messages FrequencySwitcher
|
||||||
const uint32 kMsgDynamicPolicyPuls = '&dpp';
|
const uint32 kMsgDynamicPolicyPulse = '&dpp';
|
||||||
|
|
||||||
// messages menu
|
// messages menu
|
||||||
const uint32 kMsgPolicyDynamic = 'pody';
|
const uint32 kMsgPolicyDynamic = 'pody';
|
||||||
@@ -40,15 +43,14 @@ const char* kDeskbarItemName = "CPUFreqStatusView";
|
|||||||
|
|
||||||
|
|
||||||
FrequencySwitcher::FrequencySwitcher(CPUFreqDriverInterface* interface,
|
FrequencySwitcher::FrequencySwitcher(CPUFreqDriverInterface* interface,
|
||||||
BHandler* target)
|
BHandler* target)
|
||||||
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE),
|
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE),
|
||||||
fDriverInterface(interface),
|
fDriverInterface(interface),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
fMessageRunner(NULL),
|
fMessageRunner(NULL),
|
||||||
fCurrentFrequency(NULL),
|
fCurrentFrequency(NULL),
|
||||||
fDynamicPolicyStarted(false)
|
fDynamicPolicyStarted(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +62,10 @@ FrequencySwitcher::~FrequencySwitcher()
|
|||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
FrequencySwitcher::Filter(BMessage *message, BHandler **target)
|
FrequencySwitcher::Filter(BMessage* message, BHandler** target)
|
||||||
{
|
{
|
||||||
filter_result result = B_DISPATCH_MESSAGE;
|
filter_result result = B_DISPATCH_MESSAGE;
|
||||||
if (message->what == kMsgDynamicPolicyPuls) {
|
if (message->what == kMsgDynamicPolicyPulse) {
|
||||||
_CalculateDynamicState();
|
_CalculateDynamicState();
|
||||||
result = B_SKIP_MESSAGE;
|
result = B_SKIP_MESSAGE;
|
||||||
}
|
}
|
||||||
@@ -79,32 +81,31 @@ FrequencySwitcher::SetMode(const freq_preferences& pref)
|
|||||||
freq_info* currentState = fDriverInterface->GetCurrentFrequencyState();
|
freq_info* currentState = fDriverInterface->GetCurrentFrequencyState();
|
||||||
freq_info* state = NULL;
|
freq_info* state = NULL;
|
||||||
bool isDynamic = false;
|
bool isDynamic = false;
|
||||||
|
|
||||||
switch (pref.mode) {
|
switch (pref.mode) {
|
||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
isDynamic = true;
|
isDynamic = true;
|
||||||
fSteppingThreshold = pref.stepping_threshold;
|
fSteppingThreshold = pref.stepping_threshold;
|
||||||
if (fMessageRunner && fIntegrationTime != pref.integration_time)
|
if (fMessageRunner && fIntegrationTime != pref.integration_time) {
|
||||||
{
|
|
||||||
fIntegrationTime = pref.integration_time;
|
fIntegrationTime = pref.integration_time;
|
||||||
fMessageRunner->SetInterval(fIntegrationTime);
|
fMessageRunner->SetInterval(fIntegrationTime);
|
||||||
}
|
}
|
||||||
if (!fDynamicPolicyStarted)
|
if (!fDynamicPolicyStarted)
|
||||||
_StartDynamicPolicy(true, pref);
|
_StartDynamicPolicy(true, pref);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERFORMANCE:
|
case PERFORMANCE:
|
||||||
state = list->ItemAt(int32(0));
|
state = list->ItemAt(int32(0));
|
||||||
if (state != currentState)
|
if (state != currentState)
|
||||||
fDriverInterface->SetFrequencyState(state);
|
fDriverInterface->SetFrequencyState(state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOW_ENERGIE:
|
case LOW_ENERGIE:
|
||||||
state = list->ItemAt(stateCount - 1);
|
state = list->ItemAt(stateCount - 1);
|
||||||
if (state != currentState)
|
if (state != currentState)
|
||||||
fDriverInterface->SetFrequencyState(state);
|
fDriverInterface->SetFrequencyState(state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
if (pref.custom_stepping < stateCount) {
|
if (pref.custom_stepping < stateCount) {
|
||||||
state = list->ItemAt(pref.custom_stepping);
|
state = list->ItemAt(pref.custom_stepping);
|
||||||
@@ -112,7 +113,7 @@ FrequencySwitcher::SetMode(const freq_preferences& pref)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDynamic && fDynamicPolicyStarted) {
|
if (!isDynamic && fDynamicPolicyStarted) {
|
||||||
fDynamicPolicyStarted = false;
|
fDynamicPolicyStarted = false;
|
||||||
_StartDynamicPolicy(false, pref);
|
_StartDynamicPolicy(false, pref);
|
||||||
@@ -127,26 +128,24 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
get_system_info(&sysInfo);
|
get_system_info(&sysInfo);
|
||||||
bigtime_t now = system_time();
|
bigtime_t now = system_time();
|
||||||
bigtime_t activeTime = sysInfo.cpu_infos[0].active_time;
|
bigtime_t activeTime = sysInfo.cpu_infos[0].active_time;
|
||||||
|
|
||||||
// if the dynamic mode is not started firt init the prev values
|
// if the dynamic mode is not started first init the prev values
|
||||||
if (!fDynamicPolicyStarted) {
|
if (!fDynamicPolicyStarted) {
|
||||||
fPrevActiveTime = activeTime;
|
fPrevActiveTime = activeTime;
|
||||||
fPrevTime = now;
|
fPrevTime = now;
|
||||||
fDynamicPolicyStarted = true;
|
fDynamicPolicyStarted = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
float usage = (float)(activeTime - fPrevActiveTime )
|
float usage = (float)(activeTime - fPrevActiveTime )
|
||||||
/ (now - fPrevTime);
|
/ (now - fPrevTime);
|
||||||
if (usage >= 1.0)
|
if (usage >= 1.0)
|
||||||
usage = 0.9999999;
|
usage = 0.9999999;
|
||||||
|
|
||||||
int32 numberOfStates = fDriverInterface->GetNumberOfFrequencyStates();
|
int32 numberOfStates = fDriverInterface->GetNumberOfFrequencyStates();
|
||||||
for (int i = 0; i < numberOfStates; i++) {
|
for (int i = 0; i < numberOfStates; i++) {
|
||||||
float usageOfStep = ColorStepView::UsageOfStep(i, numberOfStates,
|
float usageOfStep = ColorStepView::UsageOfStep(i, numberOfStates,
|
||||||
fSteppingThreshold);
|
fSteppingThreshold);
|
||||||
|
|
||||||
if (usage < usageOfStep)
|
if (usage < usageOfStep) {
|
||||||
{
|
|
||||||
StateList* list = fDriverInterface->GetCpuFrequencyStates();
|
StateList* list = fDriverInterface->GetCpuFrequencyStates();
|
||||||
freq_info* newState = list->ItemAt(numberOfStates - 1 - i);
|
freq_info* newState = list->ItemAt(numberOfStates - 1 - i);
|
||||||
if (newState != fCurrentFrequency) {
|
if (newState != fCurrentFrequency) {
|
||||||
@@ -154,7 +153,7 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
fDriverInterface->SetFrequencyState(newState);
|
fDriverInterface->SetFrequencyState(newState);
|
||||||
fCurrentFrequency = newState;
|
fCurrentFrequency = newState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fPrevActiveTime = activeTime;
|
fPrevActiveTime = activeTime;
|
||||||
@@ -164,48 +163,46 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FrequencySwitcher::_StartDynamicPolicy(bool start,
|
FrequencySwitcher::_StartDynamicPolicy(bool start, const freq_preferences& pref)
|
||||||
const freq_preferences& pref)
|
|
||||||
{
|
{
|
||||||
if (start) {
|
if (start) {
|
||||||
if (!fMessageRunner) {
|
if (!fMessageRunner) {
|
||||||
fIntegrationTime = pref.integration_time;
|
fIntegrationTime = pref.integration_time;
|
||||||
fMessageRunner = new BMessageRunner(fTarget,
|
fMessageRunner = new BMessageRunner(fTarget,
|
||||||
new BMessage(kMsgDynamicPolicyPuls)
|
new BMessage(kMsgDynamicPolicyPulse), pref.integration_time, -1);
|
||||||
, pref.integration_time, -1);
|
|
||||||
fCurrentFrequency = fDriverInterface->GetCurrentFrequencyState();
|
fCurrentFrequency = fDriverInterface->GetCurrentFrequencyState();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
delete fMessageRunner;
|
||||||
if (fMessageRunner) {
|
fMessageRunner = NULL;
|
||||||
delete fMessageRunner;
|
|
||||||
fMessageRunner = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
||||||
PreferencesStorage<freq_preferences> * storage,
|
PreferencesStorage<freq_preferences>* storage,
|
||||||
CPUFreqDriverInterface* interface)
|
CPUFreqDriverInterface* interface)
|
||||||
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
|
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
fStorage(storage),
|
fStorage(storage),
|
||||||
fInterface(interface)
|
fInterface(interface)
|
||||||
{
|
{
|
||||||
fDynamicPerformance = new BMenuItem("Dynamic Performance",
|
fDynamicPerformance = new BMenuItem("Dynamic Performance",
|
||||||
new BMessage(kMsgPolicyDynamic));
|
new BMessage(kMsgPolicyDynamic));
|
||||||
fHighPerformance = new BMenuItem("High Performance",
|
fHighPerformance = new BMenuItem("High Performance",
|
||||||
new BMessage(kMsgPolicyPerformance));
|
new BMessage(kMsgPolicyPerformance));
|
||||||
fLowEnergie = new BMenuItem("Low Energie",
|
fLowEnergie = new BMenuItem("Low Energy",
|
||||||
new BMessage(kMsgPolicyLowEnergy));
|
new BMessage(kMsgPolicyLowEnergy));
|
||||||
|
|
||||||
menu->AddItem(fDynamicPerformance);
|
menu->AddItem(fDynamicPerformance);
|
||||||
menu->AddItem(fHighPerformance);
|
menu->AddItem(fHighPerformance);
|
||||||
menu->AddItem(fLowEnergie);
|
menu->AddItem(fLowEnergie);
|
||||||
|
|
||||||
fCustomStateMenu = new BMenu("Set State");
|
fCustomStateMenu = new BMenu("Set State");
|
||||||
|
|
||||||
StateList* stateList = fInterface->GetCpuFrequencyStates();
|
StateList* stateList = fInterface->GetCpuFrequencyStates();
|
||||||
for (int i = 0; i < stateList->CountItems(); i++) {
|
for (int i = 0; i < stateList->CountItems(); i++) {
|
||||||
freq_info* info = stateList->ItemAt(i);
|
freq_info* info = stateList->ItemAt(i);
|
||||||
@@ -213,16 +210,16 @@ FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
|||||||
label << info->frequency;
|
label << info->frequency;
|
||||||
label += " MHz";
|
label += " MHz";
|
||||||
fCustomStateMenu->AddItem(new BMenuItem(label.String(),
|
fCustomStateMenu->AddItem(new BMenuItem(label.String(),
|
||||||
new BMessage(kMsgPolicySetState)));
|
new BMessage(kMsgPolicySetState)));
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->AddItem(fCustomStateMenu);
|
menu->AddItem(fCustomStateMenu);
|
||||||
|
|
||||||
// set the target of the items
|
// set the target of the items
|
||||||
fDynamicPerformance->SetTarget(fTarget);
|
fDynamicPerformance->SetTarget(fTarget);
|
||||||
fHighPerformance->SetTarget(fTarget);
|
fHighPerformance->SetTarget(fTarget);
|
||||||
fLowEnergie->SetTarget(fTarget);
|
fLowEnergie->SetTarget(fTarget);
|
||||||
|
|
||||||
fCustomStateMenu->SetTargetForItems(fTarget);
|
fCustomStateMenu->SetTargetForItems(fTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,19 +239,18 @@ FrequencyMenu::_SetL1MenuLabelFrom(BMenuItem* item)
|
|||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
FrequencyMenu::Filter(BMessage* msg, BHandler** target)
|
||||||
{
|
{
|
||||||
filter_result result = B_DISPATCH_MESSAGE;
|
filter_result result = B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
BMenuItem* item, *superItem, *markedItem;
|
BMenuItem* item, *superItem, *markedItem;
|
||||||
msg->FindPointer("source", (void**)&item);
|
msg->FindPointer("source", (void**)&item);
|
||||||
if (!item) {
|
if (!item)
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
bool safeChanges = false;
|
bool safeChanges = false;
|
||||||
freq_preferences* pref = fStorage->GetPreferences();
|
freq_preferences* pref = fStorage->GetPreferences();
|
||||||
|
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case kMsgPolicyDynamic:
|
case kMsgPolicyDynamic:
|
||||||
pref->mode = DYNAMIC;
|
pref->mode = DYNAMIC;
|
||||||
@@ -262,25 +258,25 @@ FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
|||||||
safeChanges = true;
|
safeChanges = true;
|
||||||
msg->what = kUpdatedPreferences;
|
msg->what = kUpdatedPreferences;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgPolicyPerformance:
|
case kMsgPolicyPerformance:
|
||||||
pref->mode = PERFORMANCE;
|
pref->mode = PERFORMANCE;
|
||||||
_SetL1MenuLabelFrom(item);
|
_SetL1MenuLabelFrom(item);
|
||||||
safeChanges = true;
|
safeChanges = true;
|
||||||
msg->what = kUpdatedPreferences;
|
msg->what = kUpdatedPreferences;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgPolicyLowEnergy:
|
case kMsgPolicyLowEnergy:
|
||||||
pref->mode = LOW_ENERGIE;
|
pref->mode = LOW_ENERGIE;
|
||||||
_SetL1MenuLabelFrom(item);
|
_SetL1MenuLabelFrom(item);
|
||||||
safeChanges = true;
|
safeChanges = true;
|
||||||
msg->what = kUpdatedPreferences;
|
msg->what = kUpdatedPreferences;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgPolicySetState:
|
case kMsgPolicySetState:
|
||||||
pref->mode = CUSTOM;
|
pref->mode = CUSTOM;
|
||||||
pref->custom_stepping = item->Menu()->IndexOf(item);
|
pref->custom_stepping = item->Menu()->IndexOf(item);
|
||||||
|
|
||||||
superItem = item->Menu()->Supermenu()->Superitem();
|
superItem = item->Menu()->Supermenu()->Superitem();
|
||||||
if (superItem)
|
if (superItem)
|
||||||
superItem->SetLabel(item->Label());
|
superItem->SetLabel(item->Label());
|
||||||
@@ -291,15 +287,15 @@ FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
|||||||
if (markedItem)
|
if (markedItem)
|
||||||
markedItem->SetMarked(false);
|
markedItem->SetMarked(false);
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
safeChanges = true;
|
safeChanges = true;
|
||||||
msg->what = kUpdatedPreferences;
|
msg->what = kUpdatedPreferences;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safeChanges)
|
if (safeChanges)
|
||||||
fStorage->SavePreferences();
|
fStorage->SavePreferences();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,39 +303,43 @@ FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
|||||||
void
|
void
|
||||||
FrequencyMenu::UpdateMenu()
|
FrequencyMenu::UpdateMenu()
|
||||||
{
|
{
|
||||||
BMenuItem* customItem, *markedItem, *superItem;
|
|
||||||
|
|
||||||
freq_preferences* pref = fStorage->GetPreferences();
|
freq_preferences* pref = fStorage->GetPreferences();
|
||||||
switch (pref->mode) {
|
switch (pref->mode) {
|
||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
_SetL1MenuLabelFrom(fDynamicPerformance);
|
_SetL1MenuLabelFrom(fDynamicPerformance);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERFORMANCE:
|
case PERFORMANCE:
|
||||||
_SetL1MenuLabelFrom(fHighPerformance);
|
_SetL1MenuLabelFrom(fHighPerformance);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOW_ENERGIE:
|
case LOW_ENERGIE:
|
||||||
_SetL1MenuLabelFrom(fLowEnergie);
|
_SetL1MenuLabelFrom(fLowEnergie);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
markedItem = fCustomStateMenu->FindMarked();
|
{
|
||||||
|
BMenuItem* markedItem = fCustomStateMenu->FindMarked();
|
||||||
if (markedItem)
|
if (markedItem)
|
||||||
markedItem->SetMarked(false);
|
markedItem->SetMarked(false);
|
||||||
customItem = fCustomStateMenu->ItemAt(pref->custom_stepping);
|
BMenuItem* customItem
|
||||||
|
= fCustomStateMenu->ItemAt(pref->custom_stepping);
|
||||||
if (customItem)
|
if (customItem)
|
||||||
customItem->SetMarked(true);
|
customItem->SetMarked(true);
|
||||||
superItem = fCustomStateMenu->Supermenu()->Superitem();
|
BMenuItem* superItem = fCustomStateMenu->Supermenu()->Superitem();
|
||||||
if (superItem && customItem)
|
if (superItem && customItem)
|
||||||
superItem->SetLabel(customItem->Label());
|
superItem->SetLabel(customItem->Label());
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
StatusView::StatusView(BRect frame, bool inDeskbar,
|
StatusView::StatusView(BRect frame, bool inDeskbar,
|
||||||
PreferencesStorage<freq_preferences>* storage)
|
PreferencesStorage<freq_preferences>* storage)
|
||||||
: BView(frame, kDeskbarItemName, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
: BView(frame, kDeskbarItemName, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS),
|
B_WILL_DRAW | B_FRAME_EVENTS),
|
||||||
fInDeskbar(inDeskbar),
|
fInDeskbar(inDeskbar),
|
||||||
@@ -355,17 +355,16 @@ StatusView::StatusView(BRect frame, bool inDeskbar,
|
|||||||
B_FOLLOW_NONE);
|
B_FOLLOW_NONE);
|
||||||
AddChild(fDragger);
|
AddChild(fDragger);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storage) {
|
if (storage) {
|
||||||
fOwningStorage = false;
|
fOwningStorage = false;
|
||||||
fStorage = storage;
|
fStorage = storage;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fOwningStorage = true;
|
fOwningStorage = true;
|
||||||
fStorage = new PreferencesStorage<freq_preferences>("CPUFrequency",
|
fStorage = new PreferencesStorage<freq_preferences>("CPUFrequency",
|
||||||
kDefaultPreferences);
|
kDefaultPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Init();
|
_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +382,7 @@ StatusView::StatusView(BMessage* archive)
|
|||||||
|
|
||||||
fOwningStorage = true;
|
fOwningStorage = true;
|
||||||
fStorage = new PreferencesStorage<freq_preferences>(kPreferencesFileName,
|
fStorage = new PreferencesStorage<freq_preferences>(kPreferencesFileName,
|
||||||
kDefaultPreferences);
|
kDefaultPreferences);
|
||||||
_Init();
|
_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +425,7 @@ StatusView::_Quit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StatusView *
|
StatusView*
|
||||||
StatusView::Instantiate(BMessage* archive)
|
StatusView::Instantiate(BMessage* archive)
|
||||||
{
|
{
|
||||||
if (!validate_instantiation(archive, "StatusView"))
|
if (!validate_instantiation(archive, "StatusView"))
|
||||||
@@ -459,30 +458,29 @@ StatusView::AttachedToWindow()
|
|||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
|
|
||||||
// watching if the driver change the frequency
|
// watching if the driver change the frequency
|
||||||
fDriverInterface.StartWatching(this);
|
fDriverInterface.StartWatching(this);
|
||||||
|
|
||||||
// monitor preferences file
|
// monitor preferences file
|
||||||
fPrefFileWatcher = new PrefFileWatcher<freq_preferences>(fStorage, this);
|
fPrefFileWatcher = new PrefFileWatcher<freq_preferences>(fStorage, this);
|
||||||
AddFilter(fPrefFileWatcher);
|
AddFilter(fPrefFileWatcher);
|
||||||
|
|
||||||
// FrequencySwitcher
|
// FrequencySwitcher
|
||||||
fFrequencySwitcher = new FrequencySwitcher(&fDriverInterface, this);
|
fFrequencySwitcher = new FrequencySwitcher(&fDriverInterface, this);
|
||||||
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
||||||
AddFilter(fFrequencySwitcher);
|
AddFilter(fFrequencySwitcher);
|
||||||
|
|
||||||
// perferences menu
|
// perferences menu
|
||||||
fPreferencesMenu = new BPopUpMenu(B_EMPTY_STRING, false, false);
|
fPreferencesMenu = new BPopUpMenu(B_EMPTY_STRING, false, false);
|
||||||
fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this,
|
fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this, fStorage,
|
||||||
fStorage,
|
&fDriverInterface);
|
||||||
&fDriverInterface);
|
|
||||||
|
|
||||||
fPreferencesMenu->SetFont(be_plain_font);
|
fPreferencesMenu->SetFont(be_plain_font);
|
||||||
|
|
||||||
fPreferencesMenu->AddSeparatorItem();
|
fPreferencesMenu->AddSeparatorItem();
|
||||||
fOpenPrefItem = new BMenuItem("Open Speedstep Preferences" B_UTF8_ELLIPSIS,
|
fOpenPrefItem = new BMenuItem("Open Speedstep Preferences" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(kMsgOpenSSPreferences));
|
new BMessage(kMsgOpenSSPreferences));
|
||||||
fPreferencesMenu->AddItem(fOpenPrefItem);
|
fPreferencesMenu->AddItem(fOpenPrefItem);
|
||||||
fOpenPrefItem->SetTarget(this);
|
fOpenPrefItem->SetTarget(this);
|
||||||
|
|
||||||
@@ -492,7 +490,7 @@ StatusView::AttachedToWindow()
|
|||||||
fQuitItem->SetTarget(this);
|
fQuitItem->SetTarget(this);
|
||||||
}
|
}
|
||||||
AddFilter(fPreferencesMenuFilter);
|
AddFilter(fPreferencesMenuFilter);
|
||||||
|
|
||||||
fPreferencesMenuFilter->UpdateMenu();
|
fPreferencesMenuFilter->UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +499,7 @@ void
|
|||||||
StatusView::DetachedFromWindow()
|
StatusView::DetachedFromWindow()
|
||||||
{
|
{
|
||||||
fDriverInterface.StopWatching();
|
fDriverInterface.StopWatching();
|
||||||
|
|
||||||
if (RemoveFilter(fPrefFileWatcher))
|
if (RemoveFilter(fPrefFileWatcher))
|
||||||
delete fPrefFileWatcher;
|
delete fPrefFileWatcher;
|
||||||
if (RemoveFilter(fFrequencySwitcher))
|
if (RemoveFilter(fFrequencySwitcher))
|
||||||
@@ -525,16 +523,16 @@ StatusView::MessageReceived(BMessage* message)
|
|||||||
_SetupNewFreqString();
|
_SetupNewFreqString();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kUpdatedPreferences:
|
case kUpdatedPreferences:
|
||||||
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
||||||
fPreferencesMenuFilter->UpdateMenu();
|
fPreferencesMenuFilter->UpdateMenu();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ABOUT_REQUESTED:
|
case B_ABOUT_REQUESTED:
|
||||||
_AboutRequested();
|
_AboutRequested();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_QUIT_REQUESTED:
|
case B_QUIT_REQUESTED:
|
||||||
_Quit();
|
_Quit();
|
||||||
break;
|
break;
|
||||||
@@ -558,9 +556,9 @@ StatusView::Draw(BRect updateRect)
|
|||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
GetFontHeight(&fontHeight);
|
GetFontHeight(&fontHeight);
|
||||||
float height = fontHeight.ascent + fontHeight.descent;
|
float height = fontHeight.ascent + fontHeight.descent;
|
||||||
|
|
||||||
MovePenTo(0, height);
|
MovePenTo(0, height);
|
||||||
|
|
||||||
DrawString(fFreqString.String());
|
DrawString(fFreqString.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,13 +610,13 @@ StatusView::UpdateCPUFreqState()
|
|||||||
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StatusView::_Init()
|
StatusView::_Init()
|
||||||
{
|
{
|
||||||
fShowPopUpMenu = true;
|
fShowPopUpMenu = true;
|
||||||
fCurrentFrequency = fDriverInterface.GetCurrentFrequencyState();
|
fCurrentFrequency = fDriverInterface.GetCurrentFrequencyState();
|
||||||
|
|
||||||
_SetupNewFreqString();
|
_SetupNewFreqString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,10 +624,10 @@ StatusView::_Init()
|
|||||||
void
|
void
|
||||||
StatusView::_SetupNewFreqString()
|
StatusView::_SetupNewFreqString()
|
||||||
{
|
{
|
||||||
if (fCurrentFrequency)
|
if (fCurrentFrequency) {
|
||||||
fFreqString = ColorStepView::CreateFrequencyString(
|
fFreqString = ColorStepView::CreateFrequencyString(
|
||||||
fCurrentFrequency->frequency);
|
fCurrentFrequency->frequency);
|
||||||
else
|
} else
|
||||||
fFreqString = "? MHz";
|
fFreqString = "? MHz";
|
||||||
|
|
||||||
ResizeToPreferred();
|
ResizeToPreferred();
|
||||||
@@ -663,7 +661,10 @@ StatusView::_OpenPreferences()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" _EXPORT BView *
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" _EXPORT BView*
|
||||||
instantiate_deskbar_item(void)
|
instantiate_deskbar_item(void)
|
||||||
{
|
{
|
||||||
return new StatusView(BRect(0, 0, 15, 15), true, NULL);
|
return new StatusView(BRect(0, 0, 15, 15), true, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user