-
Notifications
You must be signed in to change notification settings - Fork 2
/
SettingsDialog.cpp
95 lines (79 loc) · 2.45 KB
/
SettingsDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* WhatPulse Logitech Gaming Keyboard Widget
*
* This widget uses the WhatPulse Client API to retrieve statistics from the WhatPulse Client
* and display them on a Logitech Gaming Keyboard LCD screen. It also serves as an open example
* of how the Client API can be used.
*
* This has been tested on a G19 and G510. It requires the WhatPulse Client and that the
* client API has been enabled in the Settings tab.
*
* WhatPulse (c) 2016 - http://whatpulse.org
*/
#include "stdafx.h"
#include "WhatPulseLogitech.h"
#include "SettingsDialog.h"
#include "afxdialogex.h"
#include "IniHandler.h"
extern WhatPulseLogitech dlg;
extern LPWSTR iniFile;
// SettingsDialog dialog
IMPLEMENT_DYNAMIC(SettingsDialog, CDialog)
BEGIN_MESSAGE_MAP(SettingsDialog, CDialog)
ON_BN_CLICKED(IDC_EXITWIDGET, OnExitClientClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
SettingsDialog::SettingsDialog(CWnd* pParent /*=NULL*/)
: CDialog(SettingsDialog::IDD, pParent)
{
}
SettingsDialog::~SettingsDialog()
{
}
afx_msg void SettingsDialog::ShowWindow(int nCmdShow)
{
// Load Client API URL from the settings ini file
CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(iniFile);
const char *pVal = ini.GetValue("Settings", "ClientAPIURL", "http://localhost:3490/v1/unpulsed");
m_clientAPIURL.SetWindowTextW(CA2W(pVal));
pVal = ini.GetValue("Settings", "RefreshSeconds", "5");
m_refreshRate.SetWindowTextW(CA2W(pVal));
// Set window ontop and in center of screen
SetWindowPos(&this->wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
CenterWindow();
CDialog::ShowWindow(nCmdShow);
}
void
SettingsDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CLIENTAPIURL, m_clientAPIURL);
DDX_Control(pDX, IDC_REFRESHRATE, m_refreshRate);
}
void
SettingsDialog::OnExitClientClicked()
{
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
}
void
SettingsDialog::OnOK()
{
wchar_t text[MAX_PATH];
// Save settings to ini configuration file
CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(iniFile);
// Retrieve and save the URL
m_clientAPIURL.GetWindowText(text, MAX_PATH);
ini.SetValue("Settings", "ClientAPIURL", convertWStringToString(text).c_str());
// Retrieve and save the refresh rate
m_refreshRate.GetWindowText(text, MAX_PATH);
ini.SetValue("Settings", "RefreshSeconds", convertWStringToString(text).c_str());
// Save to ini file
ini.SaveFile(iniFile);
// Restart timer in the main window to reset the refresh rate
dlg.restartStatsTimer();
CDialog::OnOK();
}