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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#include "StdAfx.h"
// extern HANDLE g_hWindowListEditSettings;
extern HGENMENU g_hMenuEditSettings;
extern HGENMENU g_hMenuOpenLogFile;
#ifdef CHART_IMPLEMENT
extern HGENMENU g_hMenuChart;
#endif
extern HGENMENU g_hMenuRefresh, g_hMenuRoot;
#define WINDOW_PREFIX_INFO "Currency Rate Info"
MCONTACT g_hContact;
inline bool IsMyContact(MCONTACT hContact)
{
return Proto_IsProtoOnContact(hContact, MODULENAME);
}
/////////////////////////////////////////////////////////////////////////////////////////
// User info dialog
class CurrencyRateInfoDlg : public CUserInfoPageDlg
{
CCtrlHyperlink url;
public:
CurrencyRateInfoDlg(int idDialog) :
CUserInfoPageDlg(g_plugin, idDialog),
url(this, IDC_SYSLINK_PROVIDER)
{
}
bool OnRefresh() override
{
::SetDlgItemTextW(m_hwnd, IDC_STATIC_CURRENCYRATE_NAME, GetContactName(m_hContact));
double dRate = 0.0;
if (true == CurrencyRates_DBReadDouble(m_hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, dRate)) {
wchar_t str[40];
swprintf_s(str, L"%.6lf", dRate);
::SetDlgItemTextW(m_hwnd, IDC_EDIT_PREVIOUS_RATE, str);
}
dRate = 0.0;
if (true == CurrencyRates_DBReadDouble(m_hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, dRate)) {
wchar_t str[40];
swprintf_s(str, L"%.6lf", dRate);
::SetDlgItemTextW(m_hwnd, IDC_EDIT_RATE, str);
}
time_t nFetchTime = g_plugin.getDword(m_hContact, DB_STR_CURRENCYRATE_FETCH_TIME, -1);
if (nFetchTime != -1) {
wchar_t szTime[50] = { 0 };
if (0 == _tctime_s(szTime, 50, &nFetchTime)) {
::SetDlgItemTextW(m_hwnd, IDC_EDIT_RATE_FETCH_TIME, szTime);
}
}
auto &pi = g_pCurrentProvider->GetInfo();
CMStringW provInfo(FORMAT, L"%s <a href=\"%s\">%s</a>", TranslateT("Info provided by"), pi.m_sURL.c_str(), pi.m_sName.c_str());
::SetDlgItemTextW(m_hwnd, IDC_SYSLINK_PROVIDER, provInfo);
return false;
}
void onClick_Url(CCtrlHyperlink *pLink)
{
::ShellExecute(m_hwnd, L"open", ptrW(pLink->GetText()), nullptr, nullptr, SW_SHOWNORMAL);
}
};
int CurrencyRatesEventFunc_OnUserInfoInit(WPARAM wp, LPARAM hContact)
{
if (NULL == hContact)
return 0;
if (false == IsMyContact(hContact))
return 0;
g_hContact = hContact;
USERINFOPAGE uip = {};
uip.position = -2000000000;
uip.pDialog = new CurrencyRateInfoDlg(IDD_DIALOG_CURRENCYRATE_INFO);
uip.szTitle.a = LPGEN("Currency Rate");
g_plugin.addUserInfo(wp, &uip);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Additional info dialog
struct CurrencyRateInfoDlg2 : public CurrencyRateInfoDlg
{
CurrencyRateInfoDlg2(MCONTACT hContact) :
CurrencyRateInfoDlg(IDD_DIALOG_CURRENCYRATE_INFO_1)
{
m_hContact = hContact;
}
bool OnInitDialog() override
{
MWindowList hWL = CModuleInfo::GetWindowList(WINDOW_PREFIX_INFO, false);
WindowList_Add(hWL, m_hwnd, m_hContact);
Utils_RestoreWindowPositionNoSize(m_hwnd, m_hContact, MODULENAME, WINDOW_PREFIX_INFO);
OnRefresh();
return true;
}
void OnDestroy() override
{
MWindowList hWL = CModuleInfo::GetWindowList(WINDOW_PREFIX_INFO, false);
WindowList_Remove(hWL, m_hwnd);
Utils_SaveWindowPosition(m_hwnd, m_hContact, MODULENAME, WINDOW_PREFIX_INFO);
}
};
int CurrencyRates_OnContactDoubleClick(WPARAM wp, LPARAM/* lp*/)
{
if (!g_pCurrentProvider)
return 0;
MCONTACT hContact = MCONTACT(wp);
MWindowList hWL = CModuleInfo::GetWindowList(WINDOW_PREFIX_INFO, true);
assert(hWL);
HWND hWnd = WindowList_Find(hWL, hContact);
if (nullptr != hWnd) {
SetForegroundWindow(hWnd);
SetFocus(hWnd);
}
else if (true == IsMyContact(hContact))
(new CurrencyRateInfoDlg2(hContact))->Show();
return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
INT_PTR CurrencyRatesMenu_EditSettings(WPARAM wp, LPARAM)
{
MCONTACT hContact = MCONTACT(wp);
if (NULL != hContact)
ShowSettingsDlg(hContact);
return 0;
}
namespace
{
bool get_log_file(MCONTACT hContact, CMStringW &rsLogfile)
{
rsLogfile = GetContactLogFileName(hContact);
return !rsLogfile.IsEmpty();
}
}
INT_PTR CurrencyRatesMenu_OpenLogFile(WPARAM wp, LPARAM)
{
MCONTACT hContact = MCONTACT(wp);
if (NULL == hContact)
return 0;
CMStringW sLogFileName;
if ((true == get_log_file(hContact, sLogFileName)) && (false == sLogFileName.IsEmpty()))
::ShellExecute(nullptr, L"open", sLogFileName.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
return 0;
}
INT_PTR CurrencyRatesMenu_RefreshContact(WPARAM wp, LPARAM)
{
MCONTACT hContact = MCONTACT(wp);
if (NULL == hContact)
return 0;
if (g_pCurrentProvider)
g_pCurrentProvider->RefreshContact(hContact);
return 0;
}
int CurrencyRates_PrebuildContactMenu(WPARAM wp, LPARAM)
{
Menu_EnableItem(g_hMenuEditSettings, false);
Menu_EnableItem(g_hMenuOpenLogFile, false);
#ifdef CHART_IMPLEMENT
Menu_EnableItem(g_hMenuChart, false);
#endif
Menu_EnableItem(g_hMenuRefresh, false);
MCONTACT hContact = MCONTACT(wp);
char *szProto = Proto_GetBaseAccountName(hContact);
if (mir_strcmp(szProto, MODULENAME)) {
Menu_ShowItem(g_hMenuRoot, false);
return 0;
}
Menu_ShowItem(g_hMenuRoot, true);
Menu_EnableItem(g_hMenuEditSettings, true);
Menu_EnableItem(g_hMenuRefresh, true);
CMStringW sLogFileName;
if (get_log_file(hContact, sLogFileName) && !sLogFileName.IsEmpty() && !_waccess(sLogFileName, 04)) {
#ifdef CHART_IMPLEMENT
Menu_EnableItem(g_hMenuChart, true);
#endif
Menu_EnableItem(g_hMenuOpenLogFile, true);
}
return 0;
}
|