xref: /haiku/src/apps/powerstatus/PowerStatusView.h (revision 40afabe6a340b294781b7b56560a121e13ebf184)
1 /*
2  * Copyright 2006-2014, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  *		Clemens Zeidler, haiku@Clemens-Zeidler.de
8  */
9 #ifndef POWER_STATUS_VIEW_H
10 #define POWER_STATUS_VIEW_H
11 
12 
13 #include <View.h>
14 
15 #include "DriverInterface.h"
16 
17 
18 class BFile;
19 
20 
21 class PowerStatusView : public BView {
22 public:
23 							PowerStatusView(
24 								PowerStatusDriverInterface* interface,
25 								BRect frame, int32 resizingMode,
26 								int batteryID = -1, bool inDeskbar = false);
27 
28 	virtual					~PowerStatusView();
29 
30 	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
31 
32 	virtual	void			AttachedToWindow();
33 	virtual	void			DetachedFromWindow();
34 
35 	virtual	void			MessageReceived(BMessage* message);
36 	virtual	void			Draw(BRect updateRect);
37 
38 
39 protected:
40 							PowerStatusView(BMessage* archive);
41 
42 	virtual void			Update(bool force = false);
43 
44 			void			FromMessage(const BMessage* message);
45 			status_t		ToMessage(BMessage* message) const;
46 
47 private:
48 			void			_GetBatteryInfo(battery_info* info, int batteryID);
49 			void			_Init();
50 			void			_SetLabel(char* buffer, size_t bufferLength);
51 			void			_DrawBattery(BRect rect);
52 
53 protected:
54 			PowerStatusDriverInterface*	fDriverInterface;
55 
56 			bool			fShowLabel;
57 			bool			fShowTime;
58 			bool			fShowStatusIcon;
59 
60 			int				fBatteryID;
61 			bool			fInDeskbar;
62 
63 			battery_info	fBatteryInfo;
64 
65 			int32			fPercent;
66 			time_t			fTimeLeft;
67 			bool			fOnline;
68 			bool			fHasBattery;
69 };
70 
71 
72 class PowerStatusReplicant : public PowerStatusView {
73 public:
74 							PowerStatusReplicant(BRect frame,
75 								int32 resizingMode, bool inDeskbar = false);
76 							PowerStatusReplicant(BMessage* archive);
77 	virtual					~PowerStatusReplicant();
78 
79 	static	PowerStatusReplicant* Instantiate(BMessage* archive);
80 	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
81 
82 	virtual	void			MessageReceived(BMessage* message);
83 	virtual	void			MouseDown(BPoint where);
84 
85 private:
86 			void			_AboutRequested();
87 			void			_Init();
88 			void			_Quit();
89 
90 			status_t		_GetSettings(BFile& file, int mode);
91 			void			_LoadSettings();
92 			void			_SaveSettings();
93 
94 			void			_OpenExtendedWindow();
95 
96 private:
97 			BWindow*		fExtendedWindow;
98 			bool			fMessengerExist;
99 			BMessenger*		fExtWindowMessenger;
100 };
101 
102 
103 #endif	// POWER_STATUS_VIEW_H
104