[TIMEDATE] Implement the dynamic NTP status notification (#2352)

Time/Date control panel applet displays the status of the NTP server synchronization with the system informing the user the actual condition of the said sync, if it has failed or suceeded. The commit also implements IDS_INETTIMEWELCOME which serves as a placeholder as Time/Date loads the last successful attempt of NTP synchronization which I don't know how the CPL remembers it. With that said, IDS_INETTIMEWELCOME will stay for a while until someone figures out how timedate.cpl works internally.
CORE-16684
This commit is contained in:
Bișoc George 2020-02-24 11:56:02 +01:00 committed by GitHub
parent 11ecf5c969
commit 5a81a5bc14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 168 additions and 7 deletions

View file

@ -11,6 +11,7 @@
#include <stdlib.h>
DWORD WINAPI W32TimeSyncNow(LPCWSTR cmdline, UINT blocking, UINT flags);
SYNC_STATUS SyncStatus;
static VOID
CreateNTPServerList(HWND hwnd)
@ -89,7 +90,7 @@ CreateNTPServerList(HWND hwnd)
/* Set the selected server in the registry */
static VOID
SetNTPServer(HWND hwnd)
SetNTPServer(HWND hwnd, BOOL bBeginUpdate)
{
HKEY hKey;
HWND hList;
@ -97,6 +98,7 @@ SetNTPServer(HWND hwnd)
WCHAR szSel[4];
LONG lRet;
WCHAR buffer[256];
WCHAR szFormat[BUFSIZE];
hList = GetDlgItem(hwnd,
IDC_SERVERLIST);
@ -105,6 +107,15 @@ SetNTPServer(HWND hwnd)
SendDlgItemMessageW(hwnd, IDC_SERVERLIST, WM_GETTEXT, _countof(buffer), (LPARAM)buffer);
/* If the condition is true that means the user wants to update (synchronize) the time */
if (bBeginUpdate)
{
/* Inform the user that the synchronization is about to begin (depending on how reachable the NTP server is) */
StringCchPrintfW(szFormat, _countof(szFormat), SyncStatus.szSyncWait, buffer);
SyncStatus.lpszSyncStatus = szFormat;
SetDlgItemTextW(hwnd, IDC_SUCSYNC, SyncStatus.lpszSyncStatus);
}
/* If there is new data entered then save it in the registry
The same key name of "0" is used to store all user entered values
*/
@ -177,6 +188,87 @@ EnableDialogText(HWND hwnd)
EnableWindow(GetDlgItem(hwnd, IDC_NEXTSYNC), bChecked);
}
static VOID
SyncNTPStatusInit(HWND hwnd)
{
/* Initialize the Synchronization NTP status members */
LoadStringW(hApplet, IDS_INETTIMEWELCOME, SyncStatus.szSyncInit, _countof(SyncStatus.szSyncInit));
LoadStringW(hApplet, IDS_INETTIMESUCSYNC, SyncStatus.szSyncSuc, _countof(SyncStatus.szSyncSuc));
LoadStringW(hApplet, IDS_INETTIMESYNCING, SyncStatus.szSyncWait, _countof(SyncStatus.szSyncWait));
LoadStringW(hApplet, IDS_INETTIMEERROR, SyncStatus.szSyncErr, _countof(SyncStatus.szSyncErr));
LoadStringW(hApplet, IDS_INETTIMESUCFILL, SyncStatus.szSyncType, _countof(SyncStatus.szSyncType));
/*
* TODO: XP's and Server 2003's timedate.cpl loads the last successful attempt of the NTP synchronization
* displaying the last time and date of the said sync. I have no idea how does timedate.cpl remember its last
* successful sync so for the time being, we will only load the initial remark string.
*/
SyncStatus.lpszSyncStatus = SyncStatus.szSyncInit;
SetDlgItemTextW(hwnd, IDC_SUCSYNC, SyncStatus.lpszSyncStatus);
}
static VOID
UpdateNTPStatus(HWND hwnd, DWORD dwReason)
{
WCHAR szFormat[BUFSIZE];
WCHAR szNtpServerName[MAX_VALUE_NAME];
WCHAR szLocalDate[BUFSIZE];
WCHAR szLocalTime[BUFSIZE];
HWND hDlgComboList;
/* Retrieve the server NTP name from the edit box */
hDlgComboList = GetDlgItem(hwnd, IDC_SERVERLIST);
SendMessageW(hDlgComboList, WM_GETTEXT, _countof(szNtpServerName), (LPARAM)szNtpServerName);
/* Iterate over the case reasons so we can compute the exact status of the NTP synchronization */
switch (dwReason)
{
/* The NTP time synchronization has completed successfully */
case ERROR_SUCCESS:
{
/* Get the current date based on the locale identifier */
GetDateFormatW(LOCALE_USER_DEFAULT,
DATE_SHORTDATE,
NULL,
NULL,
szLocalDate,
_countof(szLocalDate));
/* Get the current time based on the locale identifier */
GetTimeFormatW(LOCALE_USER_DEFAULT,
TIME_NOSECONDS,
NULL,
NULL,
szLocalTime,
_countof(szLocalTime));
/* Format the resource sting with the given NTP server name and the current time data */
StringCchPrintfW(szFormat, _countof(szFormat), SyncStatus.szSyncSuc, szNtpServerName, szLocalDate, szLocalTime);
SyncStatus.lpszSyncStatus = szFormat;
SetDlgItemTextW(hwnd, IDC_SUCSYNC, SyncStatus.lpszSyncStatus);
break;
}
/* Empty field data has been caught -- simply tell the user to write the NTP name to continue */
case ERROR_INVALID_DATA:
{
SyncStatus.lpszSyncStatus = SyncStatus.szSyncType;
SetDlgItemTextW(hwnd, IDC_SUCSYNC, SyncStatus.lpszSyncStatus);
DPRINT("UpdateNTPStatus(): The user didn't submit any NTP server name!\n");
break;
}
/* General failure -- the NTP synchronization has failed for whatever reason */
default:
{
StringCchPrintfW(szFormat, _countof(szFormat), SyncStatus.szSyncErr, szNtpServerName);
SyncStatus.lpszSyncStatus = szFormat;
SetDlgItemTextW(hwnd, IDC_SUCSYNC, SyncStatus.lpszSyncStatus);
DPRINT("UpdateNTPStatus(): Failed to synchronize the time! (Error: %lu).\n", dwReason);
break;
}
}
}
static VOID
GetSyncSetting(HWND hwnd)
@ -216,6 +308,7 @@ OnInitDialog(HWND hwnd)
GetSyncSetting(hwnd);
EnableDialogText(hwnd);
CreateNTPServerList(hwnd);
SyncNTPStatusInit(hwnd);
}
static VOID
@ -273,13 +366,10 @@ InetTimePageProc(HWND hwndDlg,
{
DWORD dwError;
SetNTPServer(hwndDlg);
SetNTPServer(hwndDlg, TRUE);
dwError = W32TimeSyncNow(L"localhost", 0, 0);
if (dwError != ERROR_SUCCESS)
{
DPRINT("Failed to synchronize the time! Invalid NTP server name has been caught or no server name could be found (Error: %lu).\n", dwError);
}
UpdateNTPStatus(hwndDlg, dwError);
}
break;
@ -313,7 +403,7 @@ InetTimePageProc(HWND hwndDlg,
switch (lpnm->code)
{
case PSN_APPLY:
SetNTPServer(hwndDlg);
SetNTPServer(hwndDlg, FALSE);
if (SendDlgItemMessageW(hwndDlg, IDC_AUTOSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED)
OnAutoSync(TRUE);

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Следващо сверяване: %s at %s"
IDS_INETTIMESYNCING "Почакайте, докато РеактОС сверява времето с %s"
IDS_INETTIMEERROR "Възникна грешка при сверяване на времето %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Další synchronizace: %s v %s"
IDS_INETTIMESYNCING "Prosím čekejte, zatímco systém ReactOS synchronizuje čas s %s"
IDS_INETTIMEERROR "Při synchronizaci času s %s nastala chyba"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Next synchronization: %s at %s"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Nächste Synchronisierung am %s um %s."
IDS_INETTIMESYNCING "Bitte warten Sie, während ReactOS die Zeit mit %s synchronisiert."
IDS_INETTIMEERROR "Ein Fehler trat beim Synchronisieren mit %s auf."
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Next synchronization: %s at %s"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Next synchronization: %s at %s"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Próxima sincronización: %s a las %s"
IDS_INETTIMESYNCING "Por favor espere mientras ReactOS sincroniza la hora con %s"
IDS_INETTIMEERROR "Ha ocurrido un error mientras ReactOS se sincronizaba con %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -61,4 +61,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Next synchronization: %s at %s"
IDS_INETTIMESYNCING "Palun oodake, kuni ReactOS sünkroonib serveriga %s"
IDS_INETTIMEERROR "ReactOSi sünkroonimisel serveriga %s ilmnes tõrge."
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Hurrengo sinkronizatzea: %s-n %s-etan"
IDS_INETTIMESYNCING "Mesedez itxoin ReactOSek %s-rekin ordua sinkronizatu arte"
IDS_INETTIMEERROR "Errore bat gertatu da ReactOS %s-kin sinkronizatzen zen bitartean"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Prochaine synchronisation: %s à %s"
IDS_INETTIMESYNCING "Veuillez patienter pendant que ReactOS synchronise l'heure avec %s"
IDS_INETTIMEERROR "Une erreur a eu lieu pendant que ReactOS synchronisait avec %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "הסנכרון הבא: %s ב %s"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -56,4 +56,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "A következő szinkronizálás: %s %s-kor"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Penyelarasan berikutnya: %s pada %s"
IDS_INETTIMESYNCING "Harap menunggu saat ReactOS menyelaraskan waktu dengan %s"
IDS_INETTIMEERROR "Kesalahan terjadi ketika ReactOS menyelaraskan dengan %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Prossima sincronizzazione: %s alle %s"
IDS_INETTIMESYNCING "Sincronizzazione ora con %s"
IDS_INETTIMEERROR "E' stato rilevato un errore mentre ReactOS si stava sincronizzando con %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "次回の同期: %s %s"
IDS_INETTIMESYNCING "ReactOSが %s と同期する間、お待ちください"
IDS_INETTIMEERROR "ReactOSが %s と同期中にエラーが発生しました"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Volgende synchronisatie: %s om %s"
IDS_INETTIMESYNCING "ReactOS voert een synchronisatie met %s uit. Een ogenblik geduld."
IDS_INETTIMEERROR "Er is een fout opgetreden bij een poging om een synchronisatie met %s uit te voeren."
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Neste synkonisering: %s med %s"
IDS_INETTIMESYNCING "Vennligst vent mens ReactOS sykroniserer tiden med %s"
IDS_INETTIMEERROR "En feil har oppstatt mens ReactOS ble sykronisert med %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -63,4 +63,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Następna synchronizacja w dniu %s o %s"
IDS_INETTIMESYNCING "Proszę czekać, gdy ReactOS zsynchronizuje czas z %s"
IDS_INETTIMEERROR "Wystąpił błąd podczas próby synchronizacji czasu z %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Próxima sincronização: %s às %s"
IDS_INETTIMESYNCING "Aguarde enquanto o ReactOS é sincronizado com %s"
IDS_INETTIMEERROR "Erro enquanto o ReactOS estava sincronizando com %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -56,4 +56,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Următoarea sincronizare: %s la %s"
IDS_INETTIMESYNCING "Așteptați sincronizarea cu %s"
IDS_INETTIMEERROR "A survenit o eroare la sincronizarea cu %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Следующая синхронизация через: %s в %s"
IDS_INETTIMESYNCING "Подождите, пока РеактОС синхронизирует время с %s"
IDS_INETTIMEERROR "Возникла ошибка во время синхронизации с %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -61,4 +61,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Ďalšia synchronizácia: %s o %s"
IDS_INETTIMESYNCING "Počkajte prosím, kým ReactOS zosynchronizuje čas s %s"
IDS_INETTIMEERROR "Počas synchronizácie systému ReactOS s %s sa vyskytla chyba."
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -58,4 +58,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Sinkronizimi tjetër: %s në %s"
IDS_INETTIMESYNCING "Ju lutem prisni ndërkohë që ReactOS sinkronizon orën me %s"
IDS_INETTIMEERROR "Një gabim ndodhi gjatë sinkronizimit të ReactOS me %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -56,4 +56,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Next synchronization: %s at %s"
IDS_INETTIMESYNCING "Please wait while ReactOS synchronizes the time with %s"
IDS_INETTIMEERROR "An error occured while ReactOS was synchronizing with %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "การปรับเทียบต่อไป: %s ใน %s"
IDS_INETTIMESYNCING "โปรดรอ ReactOS กำลังปรับเทียบเวลาภายใน %s"
IDS_INETTIMEERROR "เกิดการผิดพลาดในขณะที่ ReactOS กำลังปรับเทียบเวลาภายใน %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -56,4 +56,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Bir Sonraki Eşleştirme: %s.%s"
IDS_INETTIMESYNCING "ReactOS, saati %s ile eşleştirirken lütfen bekleyiniz."
IDS_INETTIMEERROR "ReactOS, %s ile eşleştirirken bir yanlışlık oldu."
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -62,4 +62,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "Наступна синхронізація: %s в %s"
IDS_INETTIMESYNCING "Будь ласка зачекайте, поки ReactOS синхронізує час з %s"
IDS_INETTIMEERROR "Помилка під час синхронізації з %s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -54,4 +54,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "下次同步:%s 在 %s"
IDS_INETTIMESYNCING "请稍候ReactOS 正在同步 %s"
IDS_INETTIMEERROR "在 ReactOS 同步时发生了一个错误。%s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -56,4 +56,6 @@ BEGIN
IDS_INETTIMENEXTSYNC "下次同步:%s 在 %s"
IDS_INETTIMESYNCING "請等待ReactOS 正在同步 %s"
IDS_INETTIMEERROR "在 ReactOS 同步時發生了一個錯誤。%s"
IDS_INETTIMESUCFILL "Please type a NTP server name in order to synchronize the time"
IDS_INETTIMEWELCOME "Select a NTP server from the list or type a NTP server name to synchronize the computer's time"
END

View file

@ -36,3 +36,5 @@
#define IDS_INETTIMENEXTSYNC 1007
#define IDS_INETTIMESYNCING 1008
#define IDS_INETTIMEERROR 1009
#define IDS_INETTIMESUCFILL 1010
#define IDS_INETTIMEWELCOME 1011

View file

@ -17,6 +17,7 @@
#include <commctrl.h>
#include <cpl.h>
#include <debug.h>
#include <strsafe.h>
#include "resource.h"
@ -34,6 +35,16 @@ typedef struct
APPLET_PROC AppletProc;
} APPLET, *PAPPLET;
typedef struct
{
WCHAR szSyncSuc[BUFSIZE];
WCHAR szSyncWait[BUFSIZE];
WCHAR szSyncErr[BUFSIZE];
WCHAR szSyncType[BUFSIZE];
WCHAR szSyncInit[BUFSIZE];
LPWSTR lpszSyncStatus;
} SYNC_STATUS, *PSYNC_STATUS;
extern HINSTANCE hApplet;