added logic to handle manual:on and manual:off modes and update menu checkboxes when user changes modes

git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@64 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
joshholtrop 2009-09-10 18:21:21 +00:00
parent 7fec0f3be8
commit e9c85c729e
2 changed files with 77 additions and 53 deletions

48
pppc.cc
View File

@ -117,12 +117,8 @@ void updateMenuInfo(HMENU hMenu, int index, const CHAR * itemstr, WORD id, bool
MENUITEMINFO mii; MENUITEMINFO mii;
memset(&mii, 0, sizeof(mii)); memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii); mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STRING | MIIM_ID; mii.fMask = MIIM_STRING | MIIM_ID | MIIM_STATE;
if (checked) mii.fState = checked ? MFS_CHECKED : 0;
{
mii.fMask |= MIIM_STATE;
mii.fState = MFS_CHECKED;
}
mii.wID = id; mii.wID = id;
mii.dwTypeData = (CHAR *) itemstr; mii.dwTypeData = (CHAR *) itemstr;
mii.cch = strlen(mii.dwTypeData); mii.cch = strlen(mii.dwTypeData);
@ -141,8 +137,6 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
m_config.read(config_file); m_config.read(config_file);
} }
event_start();
/* Load the application icon */ /* Load the application icon */
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
if (icon == 0) if (icon == 0)
@ -216,6 +210,8 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl; cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl;
} }
event_start();
/* begin capturing session notifications */ /* begin capturing session notifications */
session_notification_enable(m_hWnd); session_notification_enable(m_hWnd);
} }
@ -263,11 +259,20 @@ BOOL PPPC::mainLoop()
} }
break; break;
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(msg.wParam)) /* menu entry index */
{ {
case 0: /* exit */ int menu_index = LOWORD(msg.wParam);
if (menu_index == 0)
{
running = false; running = false;
break; }
else
{
int config_index = ((menu_index >> 8) & 0xFF) - 1;
int mode_index = ((menu_index) & 0xFF) - 1;
m_modes[config_index] = (ConfigEntryMode) mode_index;
updateConfigMenus(config_index);
update_pins();
}
} }
break; break;
} }
@ -295,6 +300,8 @@ PPPC::~PPPC()
void PPPC::event_start() void PPPC::event_start()
{ {
for (int sz = m_config.num_entries(), i = 0; i < sz; i++) for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
{
if (m_modes[i] == AUTO)
{ {
switch (m_config.entries[i].on_start) switch (m_config.entries[i].on_start)
{ {
@ -308,12 +315,15 @@ void PPPC::event_start()
break; break;
} }
} }
}
update_pins(); update_pins();
} }
void PPPC::event_exit() void PPPC::event_exit()
{ {
for (int sz = m_config.num_entries(), i = 0; i < sz; i++) for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
{
if (m_modes[i] == AUTO)
{ {
switch (m_config.entries[i].on_exit) switch (m_config.entries[i].on_exit)
{ {
@ -327,12 +337,15 @@ void PPPC::event_exit()
break; break;
} }
} }
}
update_pins(); update_pins();
} }
void PPPC::event_lock() void PPPC::event_lock()
{ {
for (int sz = m_config.num_entries(), i = 0; i < sz; i++) for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
{
if (m_modes[i] == AUTO)
{ {
switch (m_config.entries[i].on_lock) switch (m_config.entries[i].on_lock)
{ {
@ -346,13 +359,16 @@ void PPPC::event_lock()
break; break;
} }
} }
update_pins(); }
m_previous_pins = m_pins; m_previous_pins = m_pins;
update_pins();
} }
void PPPC::event_unlock() void PPPC::event_unlock()
{ {
for (int sz = m_config.num_entries(), i = 0; i < sz; i++) for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
{
if (m_modes[i] == AUTO)
{ {
switch (m_config.entries[i].on_unlock) switch (m_config.entries[i].on_unlock)
{ {
@ -370,10 +386,18 @@ void PPPC::event_unlock()
break; break;
} }
} }
}
update_pins(); update_pins();
} }
void PPPC::update_pins() void PPPC::update_pins()
{ {
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
{
if (m_modes[i] == MANUAL_OFF)
SET_BIT(m_pins, m_config.entries[i].pin, 0);
else if (m_modes[i] == MANUAL_ON)
SET_BIT(m_pins, m_config.entries[i].pin, 1);
}
pport_write(m_pins); pport_write(m_pins);
} }

2
pppc.h
View File

@ -11,7 +11,7 @@
class PPPC class PPPC
{ {
public: public:
enum ConfigEntryMode { AUTO, MANUAL_OFF, MANUAL_ON }; enum ConfigEntryMode { AUTO = 0, MANUAL_OFF = 1, MANUAL_ON = 2 };
static const char * ConfigEntryCaptions[3]; static const char * ConfigEntryCaptions[3];
PPPC(HINSTANCE hInstance, const char * config_file = NULL); PPPC(HINSTANCE hInstance, const char * config_file = NULL);