xref: /reactos/dll/cpl/powercfg/alarms.c (revision 682f85ad)
1 /*
2  * PROJECT:         ReactOS Power Configuration Applet
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            dll/cpl/powercfg/alarms.c
5  * PURPOSE:         alarms tab of applet
6  * PROGRAMMERS:     Alexander Wurzinger (Lohnegrim at gmx dot net)
7  *                  Johannes Anderwald (johannes.anderwald@reactos.org)
8  *                  Martin Rottensteiner
9  *                  Dmitry Chapyshev (lentind@yandex.ru)
10  */
11 
12 #include "powercfg.h"
13 
14 static BOOLEAN
15 Ala_InitData(HWND hwndDlg)
16 {
17     TCHAR szAction[MAX_PATH];
18     TCHAR szText[MAX_PATH];
19     TCHAR szSound[MAX_PATH];
20     TCHAR szMessage[MAX_PATH];
21     TCHAR szTemp[MAX_PATH];
22     TCHAR szBatteryLevel[MAX_PATH];
23     TCHAR szProgram[MAX_PATH];
24 
25     if (!ReadGlobalPwrPolicy(&gGPP))
26     {
27         return FALSE;
28     }
29 
30     if (gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].Enable)
31     {
32         CheckDlgButton(hwndDlg, IDC_ALARM1,
33             gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].Enable ? BST_CHECKED : BST_UNCHECKED);
34 
35         if (LoadString(hApplet, IDS_PERCENT, szTemp, MAX_PATH))
36         {
37             _stprintf(szBatteryLevel, szTemp, gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].BatteryLevel);
38             SetDlgItemText(hwndDlg, IDC_ALARMVALUE1, szBatteryLevel);
39         }
40 
41         SendDlgItemMessage(hwndDlg, IDC_ALARMBAR1,
42             TBM_SETRANGE,
43             (WPARAM)TRUE,
44             (LPARAM)MAKELONG(0, 100));
45         SendDlgItemMessage(hwndDlg, IDC_ALARMBAR1,
46             TBM_SETTICFREQ,
47             (WPARAM)TRUE,
48             (LPARAM)20);
49         SendDlgItemMessage(hwndDlg, IDC_ALARMBAR1,
50             TBM_SETPOS,
51             (WPARAM)TRUE,
52             (LPARAM)gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].BatteryLevel);
53 
54         if (LoadString(hApplet, gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].PowerPolicy.Action+IDS_PowerActionNone1, szAction, MAX_PATH))
55         {
56             SetDlgItemText(hwndDlg, IDC_ALARMAKTION1, szAction);
57         }
58 
59         memset(szMessage, 0x0, sizeof(szMessage));
60         LoadString(hApplet, IDS_NOACTION, szMessage, MAX_PATH);
61 
62         if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_TEXT)
63         {
64             if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_SOUND)
65             {
66                 if (LoadString(hApplet, IDS_SOUND, szSound, MAX_PATH) && LoadString(hApplet, IDS_TEXT, szText, MAX_PATH))
67                 {
68                     _stprintf(szMessage,_T("%s, %s"),szSound,szText);
69                 }
70             }
71             else
72             {
73                 if (LoadString(hApplet, IDS_TEXT, szText, MAX_PATH))
74                 {
75                     _stprintf(szMessage,_T("%s"),szText);
76                 }
77             }
78         }
79         else
80         {
81             if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_LOW].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_SOUND)
82             {
83                 if (LoadString(hApplet, IDS_SOUND, szSound, MAX_PATH))
84                 {
85                     _stprintf(szMessage,_T("%s"),szSound);
86                 }
87             }
88         }
89 
90         SetDlgItemText(hwndDlg, IDC_ALARMMSG1, szMessage);
91 
92         if (LoadString(hApplet, IDS_PowerActionNone2, szProgram, MAX_PATH))
93         {
94             SetDlgItemText(hwndDlg, IDC_ALARMPROG1, szProgram);
95         }
96     }
97 
98     if (gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].Enable)
99     {
100         CheckDlgButton(hwndDlg, IDC_ALARM2,
101             gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].Enable ? BST_CHECKED : BST_UNCHECKED);
102 
103         if (LoadString(hApplet, IDS_PERCENT, szTemp, MAX_PATH))
104         {
105             _stprintf(szBatteryLevel, szTemp, gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].BatteryLevel);
106             SetDlgItemText(hwndDlg, IDC_ALARMVALUE2, szBatteryLevel);
107         }
108 
109         SendDlgItemMessage(hwndDlg, IDC_ALARMBAR2,
110             TBM_SETRANGE,
111             (WPARAM)TRUE,
112             (LPARAM)MAKELONG(0, 100));
113         SendDlgItemMessage(hwndDlg, IDC_ALARMBAR2,
114             TBM_SETPOS,
115             (WPARAM)TRUE,
116             (LPARAM)gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].BatteryLevel);
117 
118         if (LoadString(hApplet, gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].PowerPolicy.Action+IDS_PowerActionNone1, szAction, MAX_PATH))
119         {
120             SetDlgItemText(hwndDlg, IDC_ALARMAKTION2, szAction);
121         }
122 
123         memset(szMessage, 0x0, sizeof(szMessage));
124         LoadString(hApplet, IDS_NOACTION, szMessage, MAX_PATH);
125 
126         if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_TEXT)
127         {
128             if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_SOUND)
129             {
130                 if (LoadString(hApplet, IDS_TEXT, szText, MAX_PATH) && LoadString(hApplet, IDS_SOUND, szSound, MAX_PATH))
131                 {
132                     _stprintf(szMessage,_T("%s, %s"),szSound,szText);
133                 }
134             }
135             else
136             {
137                 if (LoadString(hApplet, IDS_TEXT, szText, MAX_PATH))
138                 {
139                     _stprintf(szMessage,_T("%s"),szText);
140                 }
141             }
142         }
143         else
144         {
145             if (LOWORD(gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].PowerPolicy.EventCode) & POWER_LEVEL_USER_NOTIFY_SOUND)
146             {
147                 if (LoadString(hApplet, IDS_SOUND, szSound, MAX_PATH))
148                 {
149                     _stprintf(szMessage,_T("%s"),szSound);
150                 }
151             }
152         }
153 
154         SetDlgItemText(hwndDlg, IDC_ALARMMSG2, szMessage);
155 
156         if (LoadString(hApplet, IDS_PowerActionNone2, szProgram, MAX_PATH))
157         {
158             SetDlgItemText(hwndDlg, IDC_ALARMPROG2, szProgram);
159         }
160     }
161 
162     return TRUE;
163 }
164 
165 /* Property page dialog callback */
166 INT_PTR CALLBACK
167 AlarmsDlgProc(HWND hwndDlg,
168               UINT uMsg,
169               WPARAM wParam,
170               LPARAM lParam)
171 {
172     UNREFERENCED_PARAMETER(lParam);
173     UNREFERENCED_PARAMETER(wParam);
174 
175     switch (uMsg)
176     {
177         case WM_INITDIALOG:
178             if (!Ala_InitData(hwndDlg))
179             {
180                 // TODO:
181                 // Handle initialization error
182             }
183             return TRUE;
184 
185         default:
186             break;
187     }
188 
189     return FALSE;
190 }
191