summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/delphi/m_timezones.inc28
-rw-r--r--include/m_timezones.h31
-rw-r--r--plugins/Clist_modern/src/modern_cachefuncs.cpp2
-rw-r--r--plugins/Clist_nicer/src/clcitems.cpp5
-rw-r--r--plugins/TabSRMM/src/msgdlgutils.cpp2
-rw-r--r--plugins/UserInfoEx/src/ctrl_tzcombo.cpp4
-rw-r--r--plugins/UserInfoEx/src/svc_contactinfo.cpp2
-rw-r--r--plugins/UserInfoEx/src/svc_timezone.cpp2
-rw-r--r--protocols/Skype/src/skype_dialogs.cpp4
-rw-r--r--src/core/stdmsg/src/msgdialog.cpp4
-rw-r--r--src/core/stduserinfo/stdinfo.cpp4
-rw-r--r--src/modules/clist/contacts.cpp2
-rw-r--r--src/modules/utils/timezones.cpp224
13 files changed, 137 insertions, 177 deletions
diff --git a/include/delphi/m_timezones.inc b/include/delphi/m_timezones.inc
index 927d24c277..b669d7386e 100644
--- a/include/delphi/m_timezones.inc
+++ b/include/delphi/m_timezones.inc
@@ -43,17 +43,17 @@ type
cbSize:size_t;
createByName :function (tszName:TChar; dwFlags:dword):THANDLE; cdecl;
- createByContact:function (hContact:HCONTACT; dwFlags:dword):THANDLE;
- storeByContact :procedure(hContact:HCONTACT; hTZ:THANDLE); cdecl;
+ createByContact:function (hContact:HCONTACT; szModule:pAnsiChar; dwFlags:dword):THANDLE;
+ storeByContact :procedure(hContact:HCONTACT; szModule:pAnsiChar; hTZ:THANDLE); cdecl;
printDateTime:function(hTZ:THANDLE; szFormat:TChar; szDest:TChar;
cbDest:int; dwFlags:dword):int; cdecl;
printTimeStamp:function(hTZ:THANDLE; ts:mir_time; szFormat:TChar; szDest:TChar;
cbDest:int; dwFlags:dword):int; cdecl;
- prepareList :function (hContact:HCONTACT; hWnd:HWND; dwFlags:dword):int; cdecl;
- selectListItem :function (hContact:HCONTACT; hWnd:HWND; dwFlags:dword):int; cdecl;
- storeListResults:procedure(hContact:HCONTACT; hWnd:HWND; dwFlags:dword); cdecl;
+ prepareList :function (hContact:HCONTACT; szModule:pAnsiChar; hWnd:HWND; dwFlags:dword):int; cdecl;
+ selectListItem :function (hContact:HCONTACT; szModule:pAnsiChar; hWnd:HWND; dwFlags:dword):int; cdecl;
+ storeListResults:procedure(hContact:HCONTACT; szModule:pAnsiChar; hWnd:HWND; dwFlags:dword); cdecl;
getTimeZoneTime:function(hTZ:THANDLE; var st:SYSTEMTIME):int; cdecl;
timeStampToTimeZoneTimeStamp:function(hTZ:THANDLE; ts:mir_time):time_t; cdecl;
@@ -61,29 +61,13 @@ type
getTzi :function(hTZ:THANDLE):PTimeZoneInformation; cdecl;
getTzName :function(hTZ:THANDLE):TChar; cdecl;
getTzDescription:function(TZName:TChar):TChar; cdecl;
-(*
- int printDateTimeByContact (HCONTACT hContact, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags)
- { return printDateTime(createByContact(hContact, dwFlags), szFormat, szDest, cbDest, dwFlags); }
-
- int printTimeStampByContact(HCONTACT hContact, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags)
- { return printTimeStamp(createByContact(hContact, dwFlags), ts, szFormat, szDest, cbDest, dwFlags); }
-
- LPTIME_ZONE_INFORMATION getTziByContact(HCONTACT hContact)
- { return getTzi(createByContact(hContact, 0)); }
-
- int getTimeZoneTimeByContact(HCONTACT hContact, SYSTEMTIME *st)
- { return getTimeZoneTime(createByContact(hContact, 0), st); }
-
- mir_time timeStampToTimeZoneTimeStampByContact(HCONTACT hContact, mir_time ts)
- { return timeStampToTimeZoneTimeStamp(createByContact(hContact, 0), ts); }
-*)
end;
// every protocol should declare this variable to use the Time API
//extern TIME_API tmi;
{
-a service to obtain the Time API
+a service to obtain the Time API
wParam = 0;
lParam = (LPARAM)(TIME_API*).
diff --git a/include/m_timezones.h b/include/m_timezones.h
index 0072c1ab74..57ae348dd4 100644
--- a/include/m_timezones.h
+++ b/include/m_timezones.h
@@ -43,19 +43,19 @@ typedef struct
{
size_t cbSize;
- HANDLE (*createByName)(LPCTSTR tszName, DWORD dwFlags);
- HANDLE (*createByContact)(MCONTACT hContact, DWORD dwFlags);
- void (*storeByContact)(MCONTACT hContact, HANDLE hTZ);
+ HANDLE (*createByName)(LPCTSTR tszName, DWORD dwFlags);
+ HANDLE (*createByContact)(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags);
+ void (*storeByContact)(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ);
- int (*printDateTime)(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags);
- int (*printTimeStamp)(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags);
+ int (*printDateTime)(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags);
+ int (*printTimeStamp)(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags);
- int (*prepareList)(MCONTACT hContact, HWND hWnd, DWORD dwFlags);
- int (*selectListItem)(MCONTACT hContact, HWND hWnd, DWORD dwFlags);
- void (*storeListResults)(MCONTACT hContact, HWND hWnd, DWORD dwFlags);
+ int (*prepareList)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags);
+ int (*selectListItem)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags);
+ void (*storeListResults)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags);
- int (*getTimeZoneTime)(HANDLE hTZ, SYSTEMTIME *st);
- mir_time (*timeStampToTimeZoneTimeStamp)(HANDLE hTZ, mir_time ts);
+ int (*getTimeZoneTime)(HANDLE hTZ, SYSTEMTIME *st);
+ mir_time (*timeStampToTimeZoneTimeStamp)(HANDLE hTZ, mir_time ts);
LPTIME_ZONE_INFORMATION (*getTzi)(HANDLE hTZ);
LPCTSTR (*getTzName)(HANDLE hTZ);
@@ -63,19 +63,20 @@ typedef struct
#ifdef __cplusplus
int printDateTimeByContact (MCONTACT hContact, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags)
- { return printDateTime(createByContact(hContact, dwFlags), szFormat, szDest, cbDest, dwFlags); }
+ { return printDateTime(createByContact(hContact, 0, dwFlags), szFormat, szDest, cbDest, dwFlags); }
int printTimeStampByContact(MCONTACT hContact, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags)
- { return printTimeStamp(createByContact(hContact, dwFlags), ts, szFormat, szDest, cbDest, dwFlags); }
+ { return printTimeStamp(createByContact(hContact, 0, dwFlags), ts, szFormat, szDest, cbDest, dwFlags);
+ }
LPTIME_ZONE_INFORMATION getTziByContact(MCONTACT hContact)
- { return getTzi(createByContact(hContact, 0)); }
+ { return getTzi(createByContact(hContact, 0, 0)); }
int getTimeZoneTimeByContact(MCONTACT hContact, SYSTEMTIME *st)
- { return getTimeZoneTime(createByContact(hContact, 0), st); }
+ { return getTimeZoneTime(createByContact(hContact, 0, 0), st); }
mir_time timeStampToTimeZoneTimeStampByContact(MCONTACT hContact, mir_time ts)
- { return timeStampToTimeZoneTimeStamp(createByContact(hContact, 0), ts); }
+ { return timeStampToTimeZoneTimeStamp(createByContact(hContact, 0, 0), ts); }
#endif
} TIME_API;
diff --git a/plugins/Clist_modern/src/modern_cachefuncs.cpp b/plugins/Clist_modern/src/modern_cachefuncs.cpp
index 44415f83b4..8c9e5b4137 100644
--- a/plugins/Clist_modern/src/modern_cachefuncs.cpp
+++ b/plugins/Clist_modern/src/modern_cachefuncs.cpp
@@ -62,7 +62,7 @@ void Cache_GetTimezone(ClcData *dat, MCONTACT hContact)
if (dat && dat->hWnd == pcli->hwndContactTree) {
DWORD flags = dat->contact_time_show_only_if_different ? TZF_DIFONLY : 0;
- pdnce->hTimeZone = tmi.createByContact ? tmi.createByContact(hContact, flags) : 0;
+ pdnce->hTimeZone = tmi.createByContact(hContact, 0, flags);
}
}
diff --git a/plugins/Clist_nicer/src/clcitems.cpp b/plugins/Clist_nicer/src/clcitems.cpp
index 421e588307..fc994cb0bc 100644
--- a/plugins/Clist_nicer/src/clcitems.cpp
+++ b/plugins/Clist_nicer/src/clcitems.cpp
@@ -325,8 +325,9 @@ BYTE GetCachedStatusMsg(TExtraCache *p, char *szProto)
static void TZ_LoadTimeZone(MCONTACT hContact, struct TExtraCache *c, const char *szProto)
{
DWORD flags = 0;
- if (cfg::dat.bShowLocalTimeSelective) flags |= TZF_DIFONLY;
- c->hTimeZone = tmi.createByContact(hContact, flags);
+ if (cfg::dat.bShowLocalTimeSelective)
+ flags |= TZF_DIFONLY;
+ c->hTimeZone = tmi.createByContact(hContact, 0, flags);
}
void ReloadExtraInfo(MCONTACT hContact)
diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp
index 63dd0cddd6..06ad8cb2cc 100644
--- a/plugins/TabSRMM/src/msgdlgutils.cpp
+++ b/plugins/TabSRMM/src/msgdlgutils.cpp
@@ -1629,7 +1629,7 @@ void TSAPI LoadOwnAvatar(TWindowData *dat)
void TSAPI LoadTimeZone(TWindowData *dat)
{
if (dat)
- dat->hTimeZone = tmi.createByContact ? tmi.createByContact(dat->hContact, TZF_KNOWNONLY) : 0;
+ dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY);
}
/*
diff --git a/plugins/UserInfoEx/src/ctrl_tzcombo.cpp b/plugins/UserInfoEx/src/ctrl_tzcombo.cpp
index dfa4084a83..9b4ffac422 100644
--- a/plugins/UserInfoEx/src/ctrl_tzcombo.cpp
+++ b/plugins/UserInfoEx/src/ctrl_tzcombo.cpp
@@ -59,7 +59,7 @@ CBaseCtrl* CTzCombo::CreateObj(HWND hDlg, WORD idCtrl, LPCSTR pszSetting)
//set the adress of our timezone handle as itemdata
//caller can obtain the handle htz to extract all relevant information
ctrl->_curSel = 0;
- tmi.prepareList(NULL, hCtrl, TZF_PLF_CB);
+ tmi.prepareList(NULL, NULL, hCtrl, TZF_PLF_CB);
}
//fallback use old UIEX method
else {
@@ -206,7 +206,7 @@ void CTzCombo::OnApply(MCONTACT hContact, LPCSTR pszProto)
if (_Flags.B.hasCustom || !hContact) {
//use new core tz interface
if (tmi.storeListResults) {
- tmi.storeListResults(hContact, _hwnd, TZF_PLF_CB);
+ tmi.storeListResults(hContact, NULL, _hwnd, TZF_PLF_CB);
if (!hContact) {
_Flags.B.hasCustom = 0;
_Flags.B.hasProto = 1;
diff --git a/plugins/UserInfoEx/src/svc_contactinfo.cpp b/plugins/UserInfoEx/src/svc_contactinfo.cpp
index 7e98c90852..ed30f18c8d 100644
--- a/plugins/UserInfoEx/src/svc_contactinfo.cpp
+++ b/plugins/UserInfoEx/src/svc_contactinfo.cpp
@@ -565,7 +565,7 @@ INT_PTR GetContactInfo(WPARAM wParam, LPARAM lParam)
case CNF_TIMEZONE:
//use new core tz interface
if (tmi.prepareList) {
- HANDLE hTz = tmi.createByContact(ci->hContact, TZF_KNOWNONLY);
+ HANDLE hTz = tmi.createByContact(ci->hContact, 0, TZF_KNOWNONLY);
if (hTz) {
LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz);
int offset = tzi->Bias + tzi->StandardBias;
diff --git a/plugins/UserInfoEx/src/svc_timezone.cpp b/plugins/UserInfoEx/src/svc_timezone.cpp
index e1027f4b6a..8318e911bc 100644
--- a/plugins/UserInfoEx/src/svc_timezone.cpp
+++ b/plugins/UserInfoEx/src/svc_timezone.cpp
@@ -41,7 +41,7 @@ INT_PTR GetContactTimeZoneInformation(WPARAM wParam,LPARAM lParam)
{
//use new core tz interface
LPTIME_ZONE_INFORMATION pTimeZoneInformation = (LPTIME_ZONE_INFORMATION)lParam;
- (*pTimeZoneInformation) = *tmi.getTzi(tmi.createByContact(wParam, 0));
+ (*pTimeZoneInformation) = *tmi.getTzi(tmi.createByContact(wParam, 0, 0));
return (pTimeZoneInformation == NULL);
}
diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp
index 775180ccc8..a3aa8df4dc 100644
--- a/protocols/Skype/src/skype_dialogs.cpp
+++ b/protocols/Skype/src/skype_dialogs.cpp
@@ -780,8 +780,8 @@ INT_PTR CALLBACK CSkypeProto::HomeSkypeDlgProc(HWND hwndDlg, UINT msg, WPARAM wP
}
}
- tmi.prepareList((MCONTACT)lParam, ::GetDlgItem(hwndDlg, IDC_TIMEZONE), TZF_PLF_CB);
- HANDLE hTimeZone = tmi.createByContact ? tmi.createByContact(NULL, 0) : 0;
+ tmi.prepareList(lParam, NULL, ::GetDlgItem(hwndDlg, IDC_TIMEZONE), TZF_PLF_CB);
+ HANDLE hTimeZone = tmi.createByContact(NULL, 0, 0);
LPCTSTR TzDescr = tmi.getTzDescription(tmi.getTzName(hTimeZone));
::SetDlgItemText(hwndDlg, IDC_TIMEZONE, TzDescr);
}
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp
index 7c84d5239e..1f2141cb42 100644
--- a/src/core/stdmsg/src/msgdialog.cpp
+++ b/src/core/stdmsg/src/msgdialog.cpp
@@ -689,7 +689,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
dat->hContact = newData->hContact;
- dat->hTimeZone = tmi.createByContact(dat->hContact, TZF_KNOWNONLY);
+ dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY);
dat->wMinute = 61;
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING);
@@ -1161,7 +1161,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
}
case DM_NEWTIMEZONE:
- dat->hTimeZone = tmi.createByContact(dat->hContact, TZF_KNOWNONLY);
+ dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY);
dat->wMinute = 61;
SendMessage(hwndDlg, WM_SIZE, 0, 0);
break;
diff --git a/src/core/stduserinfo/stdinfo.cpp b/src/core/stduserinfo/stdinfo.cpp
index 50741b8eab..4240d7d8b1 100644
--- a/src/core/stduserinfo/stdinfo.cpp
+++ b/src/core/stduserinfo/stdinfo.cpp
@@ -244,7 +244,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
TranslateDialogDefault(hwndDlg);
SetTimer(hwndDlg, 1, 1000, NULL);
- tmi.prepareList(lParam, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB);
+ tmi.prepareList(lParam, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB);
SendMessage(hwndDlg, WM_TIMER, 0, 0);
break;
@@ -300,7 +300,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- tmi.storeListResults(hContact, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB);
+ tmi.storeListResults(hContact, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB);
}
}
break;
diff --git a/src/modules/clist/contacts.cpp b/src/modules/clist/contacts.cpp
index 9385b2dc5e..597a217199 100644
--- a/src/modules/clist/contacts.cpp
+++ b/src/modules/clist/contacts.cpp
@@ -335,7 +335,7 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) {
break;
case CNF_TIMEZONE: {
- HANDLE hTz = tmi.createByContact(ci->hContact, TZF_KNOWNONLY);
+ HANDLE hTz = tmi.createByContact(ci->hContact, 0, TZF_KNOWNONLY);
if (hTz)
{
LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz);
diff --git a/src/modules/utils/timezones.cpp b/src/modules/utils/timezones.cpp
index dab7f94089..9db7e89fa7 100644
--- a/src/modules/utils/timezones.cpp
+++ b/src/modules/utils/timezones.cpp
@@ -32,14 +32,14 @@ TIME_API tmi;
typedef DWORD (WINAPI *pfnGetDynamicTimeZoneInformation_t)(DYNAMIC_TIME_ZONE_INFORMATION *pdtzi);
static pfnGetDynamicTimeZoneInformation_t pfnGetDynamicTimeZoneInformation;
-typedef struct _REG_TZI_FORMAT
+struct REG_TZI_FORMAT
{
LONG Bias;
LONG StandardBias;
LONG DaylightBias;
SYSTEMTIME StandardDate;
SYSTEMTIME DaylightDate;
-} REG_TZI_FORMAT;
+};
#define MIM_TZ_DISPLAYLEN 128
@@ -48,27 +48,27 @@ struct MIM_TIMEZONE
unsigned hash;
int offset;
- TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone
- wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs)
- // every hour should be sufficient.
+ TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone
+ wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs)
+ // every hour should be sufficient.
TIME_ZONE_INFORMATION tzi;
static int compareBias(const MIM_TIMEZONE* p1, const MIM_TIMEZONE* p2)
{ return p2->tzi.Bias - p1->tzi.Bias; }
};
-typedef struct
+struct TZ_INT_INFO
{
- DWORD timestamp; // last time updated
- MIM_TIMEZONE myTZ; // set to my own timezone
-} TZ_INT_INFO;
+ DWORD timestamp; // last time updated
+ MIM_TIMEZONE myTZ; // set to my own timezone
+};
static TZ_INT_INFO myInfo;
static OBJLIST<MIM_TIMEZONE> g_timezones(55, NumericKeySortT);
static LIST<MIM_TIMEZONE> g_timezonesBias(55, MIM_TIMEZONE::compareBias);
-void FormatTime (const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest);
+void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest);
void UnixTimeToFileTime(mir_time ts, LPFILETIME pft);
mir_time FileTimeToUnixTime(LPFILETIME pft);
@@ -81,8 +81,7 @@ static int timeapiGetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st)
MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
if (tz == UTC_TIME_HANDLE)
GetSystemTime(st);
- else if (tz && tz != &myInfo.myTZ)
- {
+ else if (tz && tz != &myInfo.myTZ) {
SYSTEMTIME sto;
GetSystemTime(&sto);
return !fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &sto, st);
@@ -106,8 +105,7 @@ static LPCTSTR timeapiGetTzName(HANDLE hTZ)
static LPCTSTR timeapiGetTzDescription(LPCTSTR TZname)
{
- for (int i=0; i < g_timezonesBias.getCount(); i++)
- {
+ for (int i = 0; i < g_timezonesBias.getCount(); i++) {
MIM_TIMEZONE *tz = g_timezonesBias[i];
if (!lstrcmp(tz->tszName, TZname))
@@ -168,25 +166,24 @@ static HANDLE timeapiGetInfoByName(LPCTSTR tszName, DWORD dwFlags)
return tz;
}
-static HANDLE timeapiGetInfoByContact(MCONTACT hContact, DWORD dwFlags)
+static HANDLE timeapiGetInfoByContact(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags)
{
if (hContact == NULL)
return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ;
+ if (szModule == NULL) szModule = "UserInfo";
+
DBVARIANT dbv;
- if (!db_get_ts(hContact, "UserInfo", "TzName", &dbv))
- {
+ if (!db_get_ts(hContact, szModule, "TzName", &dbv)) {
HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags);
db_free(&dbv);
if (res) return res;
}
- signed char timezone = (signed char)db_get_b(hContact, "UserInfo", "Timezone", -1);
- if (timezone == -1)
- {
+ signed char timezone = (signed char)db_get_b(hContact, szModule, "Timezone", -1);
+ if (timezone == -1) {
char *szProto = GetContactProto(hContact);
- if (!db_get_ts(hContact, szProto, "TzName", &dbv))
- {
+ if (!db_get_ts(hContact, szProto, "TzName", &dbv)) {
HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags);
db_free(&dbv);
if (res) return res;
@@ -194,12 +191,10 @@ static HANDLE timeapiGetInfoByContact(MCONTACT hContact, DWORD dwFlags)
timezone = (signed char)db_get_b(hContact, szProto, "Timezone", -1);
}
- if (timezone != -1)
- {
+ if (timezone != -1) {
MIM_TIMEZONE tzsearch;
tzsearch.tzi.Bias = timezone * 30;
- if (myInfo.myTZ.tzi.Bias == tzsearch.tzi.Bias)
- {
+ if (myInfo.myTZ.tzi.Bias == tzsearch.tzi.Bias) {
if (dwFlags & TZF_DIFONLY) return NULL;
return &myInfo.myTZ;
}
@@ -208,18 +203,15 @@ static HANDLE timeapiGetInfoByContact(MCONTACT hContact, DWORD dwFlags)
while (i >= 0 && g_timezonesBias[i]->tzi.Bias == tzsearch.tzi.Bias) --i;
int delta = LONG_MAX;
- for (int j = ++i; j < g_timezonesBias.getCount() && g_timezonesBias[j]->tzi.Bias == tzsearch.tzi.Bias; ++j)
- {
+ for (int j = ++i; j < g_timezonesBias.getCount() && g_timezonesBias[j]->tzi.Bias == tzsearch.tzi.Bias; ++j) {
int delta1 = abs(g_timezonesBias[j]->tzi.DaylightDate.wMonth - myInfo.myTZ.tzi.DaylightDate.wMonth);
- if (delta1 <= delta)
- {
+ if (delta1 <= delta) {
delta = delta1;
i = j;
}
}
- if (i >= 0)
- {
+ if (i >= 0) {
MIM_TIMEZONE *tz = g_timezonesBias[i];
return ((dwFlags & TZF_DIFONLY) && IsSameTime(tz)) ? NULL : tz;
}
@@ -227,21 +219,18 @@ static HANDLE timeapiGetInfoByContact(MCONTACT hContact, DWORD dwFlags)
return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ;
}
-static void timeapiSetInfoByContact(MCONTACT hContact, HANDLE hTZ)
+static void timeapiSetInfoByContact(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ)
{
- MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
-
- if (hContact == NULL) return;
+ if (szModule == NULL) szModule = "UserInfo";
- if (tz)
- {
- db_set_ts(hContact, "UserInfo", "TzName", tz->tszName);
- db_set_b(hContact, "UserInfo", "Timezone", (char)((tz->tzi.Bias + tz->tzi.StandardBias) / 30));
+ MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
+ if (tz) {
+ db_set_ts(hContact, szModule, "TzName", tz->tszName);
+ db_set_b(hContact, szModule, "Timezone", (char)((tz->tzi.Bias + tz->tzi.StandardBias) / 30));
}
- else
- {
- db_unset(hContact, "UserInfo", "TzName");
- db_unset(hContact, "UserInfo", "Timezone");
+ else {
+ db_unset(hContact, szModule, "TzName");
+ db_unset(hContact, szModule, "Timezone");
}
}
@@ -256,7 +245,6 @@ static int timeapiPrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int
return 1;
FormatTime(&st, szFormat, szDest, cbDest);
-
return 0;
}
@@ -269,8 +257,7 @@ static int timeapiPrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTS
FILETIME ft;
if (tz == NULL) tz = &myInfo.myTZ;
- if (tz == NULL)
- {
+ if (tz == NULL) {
FILETIME lft;
UnixTimeToFileTime(ts, &lft);
@@ -278,8 +265,7 @@ static int timeapiPrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTS
}
else if (tz == UTC_TIME_HANDLE)
UnixTimeToFileTime(ts, &ft);
- else
- {
+ else {
if (tz->offset == INT_MIN)
CalcTsOffset(tz);
@@ -300,14 +286,12 @@ static LPTIME_ZONE_INFORMATION timeapiGetTzi(HANDLE hTZ)
return tz ? &tz->tzi : &myInfo.myTZ.tzi;
}
-
static mir_time timeapiTimeStampToTimeZoneTimeStamp(HANDLE hTZ, mir_time ts)
{
MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
if (tz == NULL) tz = &myInfo.myTZ;
- if (tz == NULL)
- {
+ if (tz == NULL) {
FILETIME ft, lft;
UnixTimeToFileTime(ts, &ft);
@@ -323,21 +307,20 @@ static mir_time timeapiTimeStampToTimeZoneTimeStamp(HANDLE hTZ, mir_time ts)
return ts + tz->offset;
}
-typedef struct
+struct ListMessages
{
UINT addStr, getSel, setSel, getData, setData;
-} ListMessages;
-
-static const ListMessages lbMessages =
-{ LB_ADDSTRING, LB_GETCURSEL, LB_SETCURSEL, LB_GETITEMDATA, LB_SETITEMDATA };
+};
-static const ListMessages cbMessages =
-{ CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_GETITEMDATA, CB_SETITEMDATA };
+static const ListMessages lbMessages = { LB_ADDSTRING, LB_GETCURSEL, LB_SETCURSEL, LB_GETITEMDATA, LB_SETITEMDATA };
+static const ListMessages cbMessages = { CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_GETITEMDATA, CB_SETITEMDATA };
-static const ListMessages *GetListMessages(HWND hWnd, DWORD dwFlags)
+static const ListMessages* GetListMessages(HWND hWnd, DWORD dwFlags)
{
- if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB)))
- {
+ if (hWnd == NULL)
+ return NULL;
+
+ if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB))) {
TCHAR tszClassName[128];
GetClassName(hWnd, tszClassName, SIZEOF(tszClassName));
if (!_tcsicmp(tszClassName, _T("COMBOBOX")))
@@ -346,38 +329,44 @@ static const ListMessages *GetListMessages(HWND hWnd, DWORD dwFlags)
dwFlags |= TZF_PLF_LB;
}
if (dwFlags & TZF_PLF_CB)
- return & cbMessages;
+ return &cbMessages;
else if (dwFlags & TZF_PLF_LB)
- return & lbMessages;
+ return &lbMessages;
else
return NULL;
}
+///////////////////////////////////////////////////////////////////////////////
-static int timeapiSelectListItem(MCONTACT hContact, HWND hWnd, DWORD dwFlags)
+static int timeapiSelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags)
{
- if (hWnd == NULL) // nothing to do
+ const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags);
+ if (lstMsg == NULL)
return -1;
- const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags);
- if (lstMsg == NULL) return -1;
+ if (szModule == NULL) szModule = "UserInfo";
int iSelection = 0;
- if (hContact)
- {
- DBVARIANT dbv;
- if (!db_get_ts(hContact, "UserInfo", "TzName", &dbv))
- {
- unsigned hash = mir_hashstrT(dbv.ptszVal);
- for (int i=0; i < g_timezonesBias.getCount(); i++)
- {
- if (hash == g_timezonesBias[i]->hash)
- {
+ ptrT tszName(db_get_tsa(hContact, szModule, "TzName"));
+ if (tszName != NULL) {
+ unsigned hash = mir_hashstrT(tszName);
+ for (int i = 0; i < g_timezonesBias.getCount(); i++) {
+ if (hash == g_timezonesBias[i]->hash) {
+ iSelection = i + 1;
+ break;
+ }
+ }
+ }
+ else {
+ signed char cBias = db_get_b(hContact, szModule, "Timezone", -100);
+ if (cBias != -100) {
+ int iBias = cBias * 30;
+ for (int i = 0; i < g_timezonesBias.getCount(); i++) {
+ if (iBias == g_timezonesBias[i]->tzi.Bias) {
iSelection = i + 1;
break;
}
}
- db_free(&dbv);
}
}
@@ -385,45 +374,41 @@ static int timeapiSelectListItem(MCONTACT hContact, HWND hWnd, DWORD dwFlags)
return iSelection;
}
-
-static int timeapiPrepareList(MCONTACT hContact, HWND hWnd, DWORD dwFlags)
+static int timeapiPrepareList(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags)
{
- if (hWnd == NULL) // nothing to do
- return 0;
-
const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags);
- if (lstMsg == NULL) return 0;
+ if (lstMsg == NULL)
+ return 0;
SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)TranslateT("<unspecified>"));
- for (int i=0; i < g_timezonesBias.getCount(); i++)
- {
+ for (int i = 0; i < g_timezonesBias.getCount(); i++) {
MIM_TIMEZONE *tz = g_timezonesBias[i];
SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)tz->szDisplay);
SendMessage(hWnd, lstMsg->setData, i + 1, (LPARAM)tz);
}
- return timeapiSelectListItem(hContact, hWnd, dwFlags);
+ return timeapiSelectListItem(hContact, szModule, hWnd, dwFlags);
}
-
-static void timeapiStoreListResult(MCONTACT hContact, HWND hWnd, DWORD dwFlags)
+static void timeapiStoreListResult(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags)
{
+ if (szModule == NULL) szModule = "UserInfo";
+
const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags);
- if (lstMsg == NULL) return;
-
- LRESULT offset = SendMessage(hWnd, lstMsg->getSel, 0, 0);
- if (offset > 0)
- {
- MIM_TIMEZONE *tz = (MIM_TIMEZONE*)SendMessage(hWnd, lstMsg->getData, offset, 0);
- if ((INT_PTR)tz != CB_ERR && tz != NULL)
- timeapiSetInfoByContact(hContact, tz);
+ if (lstMsg) {
+ LRESULT offset = SendMessage(hWnd, lstMsg->getSel, 0, 0);
+ if (offset > 0) {
+ MIM_TIMEZONE *tz = (MIM_TIMEZONE*)SendMessage(hWnd, lstMsg->getData, offset, 0);
+ if ((INT_PTR)tz != CB_ERR && tz != NULL)
+ timeapiSetInfoByContact(hContact, szModule, tz);
+ }
+ else timeapiSetInfoByContact(hContact, szModule, NULL);
}
- else
- timeapiSetInfoByContact(hContact, NULL);
}
+///////////////////////////////////////////////////////////////////////////////
static INT_PTR GetTimeApi(WPARAM, LPARAM lParam)
{
@@ -462,20 +447,19 @@ static INT_PTR TimestampToLocal(WPARAM wParam, LPARAM)
static INT_PTR TimestampToStringT(WPARAM wParam, LPARAM lParam)
{
DBTIMETOSTRINGT *tts = (DBTIMETOSTRINGT*)lParam;
- if (tts == NULL) return 0;
-
- timeapiPrintTimeStamp(NULL, (mir_time)wParam, tts->szFormat, tts->szDest, tts->cbDest, 0);
+ if (tts != NULL)
+ timeapiPrintTimeStamp(NULL, (mir_time)wParam, tts->szFormat, tts->szDest, tts->cbDest, 0);
return 0;
}
static INT_PTR TimestampToStringA(WPARAM wParam, LPARAM lParam)
{
DBTIMETOSTRING *tts = (DBTIMETOSTRING*)lParam;
- if (tts == NULL) return 0;
-
- TCHAR *szDest = (TCHAR*)alloca(tts->cbDest);
- timeapiPrintTimeStamp(NULL, (mir_time)wParam, StrConvT(tts->szFormat), szDest, tts->cbDest, 0);
- WideCharToMultiByte(CP_ACP, 0, szDest, -1, tts->szDest, tts->cbDest, NULL, NULL);
+ if (tts != NULL) {
+ TCHAR *szDest = (TCHAR*)alloca(tts->cbDest);
+ timeapiPrintTimeStamp(NULL, (mir_time)wParam, StrConvT(tts->szFormat), szDest, tts->cbDest, 0);
+ WideCharToMultiByte(CP_ACP, 0, szDest, -1, tts->szDest, tts->cbDest, NULL, NULL);
+ }
return 0;
}
@@ -495,24 +479,19 @@ extern "C" __declspec(dllexport) void RecalculateTime(void)
bool found = false;
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
- if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID)
- {
+ if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) {
TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName);
_tcscpy(myInfo.myTZ.tszName, myTzKey);
mir_free(myTzKey);
found = true;
}
- for (int i=0; i < g_timezones.getCount(); i++)
- {
+ for (int i = 0; i < g_timezones.getCount(); i++) {
MIM_TIMEZONE &tz = g_timezones[i];
if (tz.offset != INT_MIN) tz.offset = INT_MIN;
- if (!found)
- {
- if (!wcscmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) ||
- !wcscmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName))
- {
+ if (!found) {
+ if (!wcscmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || !wcscmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) {
_tcscpy(myInfo.myTZ.tszName, tz.tszName);
found = true;
}
@@ -535,17 +514,14 @@ void InitTimeZones(void)
if (IsWinVerVistaPlus())
pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation");
- if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey))
- {
+ if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) {
DWORD dwIndex = 0;
HKEY hSubKey;
TCHAR tszName[MIM_TZ_NAMELEN];
DWORD dwSize = SIZEOF(tszName);
- while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL))
- {
- if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey))
- {
+ while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) {
+ if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) {
dwSize = sizeof(tszName);
DWORD dwLength = sizeof(tzi);
@@ -587,8 +563,6 @@ void InitTimeZones(void)
CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRING, TimestampToStringA);
-
-
tmi.cbSize = sizeof(tmi);
GetTimeApi(0, (LPARAM)&tmi);
}