1 |
torben |
20 |
/*************************************************************************** |
2 |
|
|
* Copyright (C) 2007 by Torben Nielsen * |
3 |
|
|
* torben@t-hoerup.dk * |
4 |
|
|
* * |
5 |
|
|
* This program is free software; you can redistribute it and/or modify * |
6 |
|
|
* it under the terms of the GNU General Public License as published by * |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
8 |
|
|
* (at your option) any later version. * |
9 |
|
|
* * |
10 |
|
|
* This program is distributed in the hope that it will be useful, * |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 |
|
|
* GNU General Public License for more details. * |
14 |
|
|
* * |
15 |
|
|
* You should have received a copy of the GNU General Public License * |
16 |
|
|
* along with this program; if not, write to the * |
17 |
|
|
* Free Software Foundation, Inc., * |
18 |
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 |
|
|
***************************************************************************/ |
20 |
|
|
|
21 |
|
|
#include "wxcputhrottleframe.h" |
22 |
|
|
|
23 |
torben |
21 |
#include "SysMetrix.xpm" |
24 |
torben |
25 |
#include <wx/tglbtn.h> //togglebutton |
25 |
torben |
21 |
|
26 |
torben |
25 |
|
27 |
|
|
enum |
28 |
|
|
{ |
29 |
|
|
ID_SLIDER = 2000, |
30 |
|
|
ID_RADIOBOX, |
31 |
|
|
ID_TIMER |
32 |
|
|
}; |
33 |
|
|
|
34 |
torben |
20 |
BEGIN_EVENT_TABLE( wxCpuThrottleFrame, wxDialog ) |
35 |
|
|
EVT_CLOSE( wxCpuThrottleFrame::OnClose ) |
36 |
torben |
25 |
EVT_TIMER( ID_TIMER, wxCpuThrottleFrame::OnTimer ) |
37 |
|
|
EVT_RADIOBOX( ID_RADIOBOX, wxCpuThrottleFrame::OnRadiobutton) |
38 |
torben |
20 |
END_EVENT_TABLE() |
39 |
|
|
|
40 |
|
|
|
41 |
torben |
24 |
|
42 |
torben |
25 |
|
43 |
torben |
24 |
wxCpuThrottleFrame::wxCpuThrottleFrame( ) |
44 |
torben |
25 |
: wxDialog(NULL, -1, wxT("wxCpuThrottle"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ), |
45 |
|
|
mIcon(SysMetrix_xpm), |
46 |
|
|
mWritable(true), |
47 |
|
|
mTimer(this, ID_TIMER) |
48 |
torben |
21 |
{ |
49 |
torben |
25 |
try |
50 |
|
|
{ |
51 |
|
|
mParser.ReadAcpiFile(); |
52 |
|
|
} |
53 |
|
|
catch ( ... ) |
54 |
|
|
{ |
55 |
torben |
221 |
wxMessageBox(wxT("Could not open kernel file - aborting program")); |
56 |
torben |
25 |
OnQuit(); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
try |
60 |
|
|
{ |
61 |
|
|
mParser.SetState( mParser.GetCurrentState() ); |
62 |
|
|
} |
63 |
|
|
catch ( ...) |
64 |
|
|
{ |
65 |
|
|
mWritable = false; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
|
69 |
torben |
21 |
SetIcon(mIcon); |
70 |
torben |
24 |
|
71 |
torben |
20 |
mTrayIcon = new TrayIcon(this); |
72 |
|
|
mTrayIcon->SetIcon(mIcon,wxT("wxCpuThrottle") ); |
73 |
torben |
24 |
|
74 |
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL ); |
75 |
|
|
|
76 |
torben |
25 |
|
77 |
|
|
wxArrayString strings; |
78 |
|
|
strings.Alloc(mParser.GetStateCount() ); |
79 |
torben |
24 |
|
80 |
torben |
25 |
for (int i=0; i<mParser.GetStateCount() ; i++) |
81 |
|
|
{ |
82 |
torben |
221 |
std::string statedesc = mParser.GetStateDescription(i); |
83 |
|
|
strings.Add( wxString(statedesc.c_str(),wxConvISO8859_1) ); |
84 |
torben |
25 |
} |
85 |
torben |
24 |
|
86 |
torben |
25 |
mButtonbox = new wxRadioBox(this, ID_RADIOBOX, wxT("Throttle values"), wxDefaultPosition, wxDefaultSize,strings,1); |
87 |
|
|
|
88 |
|
|
mButtonbox->Enable( mWritable ); |
89 |
|
|
|
90 |
|
|
mainSizer->Add( mButtonbox, 1, wxEXPAND,0); |
91 |
|
|
|
92 |
torben |
24 |
SetSizer(mainSizer); |
93 |
|
|
mainSizer->SetSizeHints(this ); |
94 |
|
|
|
95 |
torben |
25 |
mTimer.Start(1000); |
96 |
torben |
24 |
|
97 |
torben |
25 |
|
98 |
torben |
20 |
} |
99 |
|
|
|
100 |
torben |
25 |
void wxCpuThrottleFrame::OnQuit( /*wxCommandEvent& WXUNUSED( event )*/ ) |
101 |
torben |
20 |
{ |
102 |
torben |
25 |
mTimer.Stop(); |
103 |
torben |
20 |
delete mTrayIcon; |
104 |
torben |
21 |
mTrayIcon = 0; |
105 |
|
|
|
106 |
torben |
20 |
Close(TRUE); |
107 |
|
|
wxExit(); |
108 |
|
|
|
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
void wxCpuThrottleFrame::OnClose( wxCloseEvent& WXUNUSED( event ) ) |
112 |
|
|
{ |
113 |
|
|
Show(false); |
114 |
|
|
} |
115 |
|
|
|
116 |
torben |
25 |
void wxCpuThrottleFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) |
117 |
|
|
{ |
118 |
|
|
mParser.ReadAcpiFile(); |
119 |
|
|
mButtonbox->SetSelection( mParser.GetCurrentState() ); |
120 |
torben |
221 |
|
121 |
|
|
std::string statedesc = mParser.GetStateDescription( mParser.GetCurrentState() ); |
122 |
torben |
25 |
|
123 |
|
|
wxString tooltip = wxT("wxCpuThrottle - "); |
124 |
torben |
221 |
tooltip += wxString(statedesc.c_str(), wxConvISO8859_1); |
125 |
torben |
25 |
|
126 |
|
|
mTrayIcon->SetIcon( mIcon, tooltip ); |
127 |
|
|
} |
128 |
|
|
|
129 |
torben |
21 |
void wxCpuThrottleFrame::SetPosition() |
130 |
|
|
{ |
131 |
|
|
const int freeBorder = 20; |
132 |
|
|
wxSize screenSize = ::wxGetDisplaySize(); |
133 |
|
|
wxSize mySize = GetSize(); |
134 |
|
|
Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); |
135 |
|
|
} |
136 |
torben |
25 |
|
137 |
|
|
|
138 |
|
|
void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event) |
139 |
|
|
{ |
140 |
|
|
mParser.SetState( mButtonbox->GetSelection() ); |
141 |
|
|
} |