mirror of https://github.com/OpenVPN/openvpn-gui
localize connection time display in tray tooltip
parent
c874ba68b4
commit
2e53dbd254
|
@ -95,6 +95,31 @@ SetGUILanguage(LANGID langId)
|
||||||
gui_language = langId;
|
gui_language = langId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LocalizedTime(const time_t t, LPTSTR buf, size_t size)
|
||||||
|
{
|
||||||
|
/* Convert Unix timestamp to Win32 SYSTEMTIME */
|
||||||
|
SYSTEMTIME st;
|
||||||
|
LONGLONG tmp = Int32x32To64(t, 10000000) + 116444736000000000;
|
||||||
|
FILETIME ft = { .dwLowDateTime = (DWORD) tmp, .dwHighDateTime = tmp >> 32};
|
||||||
|
FileTimeToSystemTime(&ft, &st);
|
||||||
|
|
||||||
|
int date_size = 0, time_size = 0;
|
||||||
|
LCID locale = MAKELCID(GetGUILanguage(), SORT_DEFAULT);
|
||||||
|
|
||||||
|
if (size > 0) {
|
||||||
|
date_size = GetDateFormat(locale, DATE_SHORTDATE, &st, NULL,
|
||||||
|
buf, size);
|
||||||
|
if (date_size)
|
||||||
|
buf[date_size - 1] = ' ';
|
||||||
|
}
|
||||||
|
if (size - date_size > 0) {
|
||||||
|
time_size = GetTimeFormat(locale, TIME_NOSECONDS, &st, NULL,
|
||||||
|
buf + date_size, size - date_size);
|
||||||
|
}
|
||||||
|
return date_size + time_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
LoadStringLang(UINT stringId, LANGID langId, PTSTR buffer, int bufferSize, va_list args)
|
LoadStringLang(UINT stringId, LANGID langId, PTSTR buffer, int bufferSize, va_list args)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef LOCALIZATION_H
|
#ifndef LOCALIZATION_H
|
||||||
#define LOCALIZATION_H
|
#define LOCALIZATION_H
|
||||||
|
|
||||||
|
int LocalizedTime(const time_t, LPTSTR, size_t);
|
||||||
PTSTR LoadLocalizedString(const UINT, ...);
|
PTSTR LoadLocalizedString(const UINT, ...);
|
||||||
int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...);
|
int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...);
|
||||||
void ShowLocalizedMsg(const UINT, ...);
|
void ShowLocalizedMsg(const UINT, ...);
|
||||||
|
|
7
tray.c
7
tray.c
|
@ -259,7 +259,6 @@ SetTrayIcon(conn_state_t state)
|
||||||
TCHAR msg[500];
|
TCHAR msg[500];
|
||||||
TCHAR msg_connected[100];
|
TCHAR msg_connected[100];
|
||||||
TCHAR msg_connecting[100];
|
TCHAR msg_connecting[100];
|
||||||
TCHAR connected_since[50];
|
|
||||||
int i, config = 0;
|
int i, config = 0;
|
||||||
BOOL first_conn;
|
BOOL first_conn;
|
||||||
UINT icon_id;
|
UINT icon_id;
|
||||||
|
@ -291,11 +290,11 @@ SetTrayIcon(conn_state_t state)
|
||||||
|
|
||||||
if (CountConnState(connected) == 1) {
|
if (CountConnState(connected) == 1) {
|
||||||
/* Append "Connected since and assigned IP" to message */
|
/* Append "Connected since and assigned IP" to message */
|
||||||
_tcsftime(connected_since, _countof(connected_since), _T("%b %d, %H:%M"),
|
TCHAR time[50];
|
||||||
localtime(&o.conn[config].connected_since));
|
|
||||||
|
|
||||||
|
LocalizedTime(o.conn[config].connected_since, time, _countof(time));
|
||||||
_tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _countof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _countof(msg) - _tcslen(msg) - 1);
|
||||||
_tcsncat(msg, connected_since, _countof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, time, _countof(msg) - _tcslen(msg) - 1);
|
||||||
|
|
||||||
if (_tcslen(o.conn[config].ip) > 0) {
|
if (_tcslen(o.conn[config].ip) > 0) {
|
||||||
TCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, o.conn[config].ip);
|
TCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, o.conn[config].ip);
|
||||||
|
|
Loading…
Reference in New Issue