1 //****************************************************************************************
3 // File: DeskbarPulseView.cpp
5 // Written by: Daniel Switkin
7 // Copyright 1999, Be Incorporated
9 //****************************************************************************************
12 #include "DeskbarPulseView.h"
19 #include <Application.h>
28 #undef B_TRANSLATION_CONTEXT
29 #define B_TRANSLATION_CONTEXT "DeskbarPulseView"
32 DeskbarPulseView::DeskbarPulseView(BRect rect
) : MiniPulseView(rect
, "DeskbarPulseView") {
38 DeskbarPulseView::DeskbarPulseView(BMessage
*message
) : MiniPulseView(message
) {
39 mode1
->SetLabel(B_TRANSLATE("Normal mode"));
40 mode1
->SetMessage(new BMessage(PV_NORMAL_MODE
));
41 mode2
->SetLabel(B_TRANSLATE("Mini mode"));
42 mode2
->SetMessage(new BMessage(PV_MINI_MODE
));
43 quit
= new BMenuItem(B_TRANSLATE("Quit"), new BMessage(PV_QUIT
), 0, 0);
44 popupmenu
->AddSeparatorItem();
45 popupmenu
->AddItem(quit
);
47 SetViewColor(B_TRANSPARENT_COLOR
);
50 active_color
.red
= (prefs
->deskbar_active_color
& 0xff000000) >> 24;
51 active_color
.green
= (prefs
->deskbar_active_color
& 0x00ff0000) >> 16;
52 active_color
.blue
= (prefs
->deskbar_active_color
& 0x0000ff00) >> 8;
54 idle_color
.red
= (prefs
->deskbar_idle_color
& 0xff000000) >> 24;
55 idle_color
.green
= (prefs
->deskbar_idle_color
& 0x00ff0000) >> 16;
56 idle_color
.blue
= (prefs
->deskbar_idle_color
& 0x0000ff00) >> 8;
58 frame_color
.red
= (prefs
->deskbar_frame_color
& 0xff000000) >> 24;
59 frame_color
.green
= (prefs
->deskbar_frame_color
& 0x00ff0000) >> 16;
60 frame_color
.blue
= (prefs
->deskbar_frame_color
& 0x0000ff00) >> 8;
61 SetViewColor(idle_color
);
67 void DeskbarPulseView::AttachedToWindow() {
68 BMessenger
messenger(this);
69 mode1
->SetTarget(messenger
);
70 mode2
->SetTarget(messenger
);
71 preferences
->SetTarget(messenger
);
72 about
->SetTarget(messenger
);
73 quit
->SetTarget(messenger
);
76 get_system_info(&sys_info
);
77 if (sys_info
.cpu_count
>= 2) {
78 for (unsigned int x
= 0; x
< sys_info
.cpu_count
; x
++)
79 cpu_menu_items
[x
]->SetTarget(messenger
);
82 // Use a BMessageRunner to deliver periodic messsages instead
83 // of Pulse() events from the Deskbar - this is to avoid changing
84 // the current pulse rate and affecting other replicants
85 messagerunner
= new BMessageRunner(messenger
, new BMessage(PV_REPLICANT_PULSE
),
89 void DeskbarPulseView::MouseDown(BPoint point
) {
93 GetMouse(&cursor
, &buttons
, true);
95 if (buttons
& B_PRIMARY_MOUSE_BUTTON
) {
96 BMessage
*message
= Window()->CurrentMessage();
97 int32 clicks
= message
->FindInt32("clicks");
99 BMessenger
messenger(this);
100 BMessage
*m
= new BMessage(PV_NORMAL_MODE
);
101 messenger
.SendMessage(m
);
103 } else MiniPulseView::MouseDown(point
);
106 void DeskbarPulseView::Pulse() {
107 // Override and do nothing here
110 void DeskbarPulseView::MessageReceived(BMessage
*message
) {
111 switch (message
->what
) {
121 if (prefswindow
!= NULL
) {
122 prefswindow
->Activate(true);
125 prefswindow
= new PrefsWindow(prefs
->prefs_window_rect
,
126 "Pulse settings", new BMessenger(this), prefs
);
130 PulseApp::ShowAbout(false);
136 case PRV_DESKBAR_CHANGE_COLOR
:
137 UpdateColors(message
);
139 case PRV_DESKBAR_ICON_WIDTH
: {
140 int width
= message
->FindInt32("width");
141 ResizeTo(width
- 1, 15);
145 case PV_REPLICANT_PULSE
:
152 case PV_CPU_MENU_ITEM
:
153 ChangeCPUState(message
);
156 BView::MessageReceived(message
);
161 DeskbarPulseView
*DeskbarPulseView::Instantiate(BMessage
*data
) {
162 if (!validate_instantiation(data
, "DeskbarPulseView")) return NULL
;
163 return new DeskbarPulseView(data
);
166 status_t
DeskbarPulseView::Archive(BMessage
*data
, bool deep
) const {
167 PulseView::Archive(data
, deep
);
168 data
->AddString("add_on", APP_SIGNATURE
);
169 data
->AddString("class", "DeskbarPulseView");
173 void DeskbarPulseView::Remove() {
174 // Remove ourselves from the deskbar by name
175 BDeskbar
*deskbar
= new BDeskbar();
176 status_t err
= deskbar
->RemoveItem("DeskbarPulseView");
179 snprintf(str
.LockBuffer(512), 512,
180 B_TRANSLATE("Removing from Deskbar failed.\n%s"), strerror(err
));
182 BAlert
*alert
= new BAlert(B_TRANSLATE("Info"), str
.String(),
184 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
190 void DeskbarPulseView::SetMode(bool normal
) {
191 if (normal
) prefs
->window_mode
= NORMAL_WINDOW_MODE
;
192 else prefs
->window_mode
= MINI_WINDOW_MODE
;
194 be_roster
->Launch(APP_SIGNATURE
);
197 DeskbarPulseView::~DeskbarPulseView() {
198 if (messagerunner
!= NULL
) delete messagerunner
;
199 if (prefswindow
!= NULL
&& prefswindow
->Lock()) prefswindow
->Quit();
200 if (prefs
!= NULL
) delete prefs
;