summaryrefslogtreecommitdiff
path: root/worldtime_protocol/worldtimeproto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'worldtime_protocol/worldtimeproto.cpp')
-rw-r--r--worldtime_protocol/worldtimeproto.cpp71
1 files changed, 48 insertions, 23 deletions
diff --git a/worldtime_protocol/worldtimeproto.cpp b/worldtime_protocol/worldtimeproto.cpp
index 88bca3a..2c06f53 100644
--- a/worldtime_protocol/worldtimeproto.cpp
+++ b/worldtime_protocol/worldtimeproto.cpp
@@ -7,6 +7,9 @@ PLUGINLINK *pluginLink;
HANDLE hContactDblClick = 0;
HANDLE hMenuEdit;
+MM_INTERFACE mmi;
+LIST_INTERFACE li;
+
int previousMode,
mcStatus = ID_STATUS_OFFLINE;
@@ -29,6 +32,9 @@ INT_PTR GetCaps(WPARAM wParam,LPARAM lParam)
break;
case PFLAGNUM_4:
break;
+ case PFLAGNUM_5:
+ ret = PF2_ONLINE | PF2_LONGAWAY;
+ break;
case PFLAG_UNIQUEIDTEXT:
ret = (INT_PTR) Translate(PROTO);
break;
@@ -112,7 +118,7 @@ INT_PTR GetStatus(WPARAM wParam,LPARAM lParam)
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
"World Time Protocol",
- PLUGIN_MAKE_VERSION(0, 1, 1, 0),
+ PLUGIN_MAKE_VERSION(0, 1, 2, 0),
"Adds 'contacts' showing the time at specified locations around the world.",
"Scott Ellis",
"mail@scottellis.com.au",
@@ -237,20 +243,32 @@ void DestroyServiceFunctions() {
DestroyServiceFunction(hServices[i]);
}
+
+void replaceStr(TCHAR* str, size_t nchar, TCHAR* rstr)
+{
+ size_t lenr = _tcslen(rstr) * sizeof(TCHAR);
+ size_t lenNew = (_tcslen(str) - nchar + 1) * sizeof(TCHAR) + lenr;
+
+ nchar *= sizeof(TCHAR);
+
+ memmove(str + lenr, str + nchar, lenNew - lenr);
+ memcpy(str, rstr, lenr);
+}
+
+
+
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
SYSTEMTIME st, other_st;
TCHAR date_buf[512], time_buf[512];
- std::string buf;
MyGetSystemTime(&st);
- TIME_ZONE_INFORMATION here_tzi, tzi;
+ TIME_ZONE_INFORMATION here_tzi = {0}, tzi = {0};
LISTITEM pa;
DBVARIANT dbv;
WORD status;
char *proto;
-
BOOL daylight_here = (GetTimeZoneInformation(&here_tzi) == TIME_ZONE_ID_DAYLIGHT);
HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
@@ -281,20 +299,23 @@ VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
GetDateFormat(LOCALE_USER_DEFAULT, 0, &other_st, 0, date_buf, 512);
}
- std::string::size_type pos;
- buf = clist_format_string;
- pos = buf.find ("%n");
- if(pos != std::string::npos)
- buf.replace(pos, 2, pa.pszText);
- pos = buf.find ("%t");
- if(pos != std::string::npos)
- buf.replace(pos, 2, time_buf);
- pos = buf.find ("%d");
- if(pos != std::string::npos)
- buf.replace(pos, 2, date_buf);
-
- pos = buf.find ("%o");
- if(pos != std::string::npos) {
+
+ TCHAR buf[1024];
+ TCHAR* pos;
+ _tcscpy(buf, clist_format_string);
+ pos = strstr(buf, "%n");
+ if (pos != NULL)
+ replaceStr(pos, 2, pa.pszText);
+ pos = strstr(buf, "%t");
+ if (pos != NULL)
+ replaceStr(pos, 2, time_buf);
+ pos = strstr(buf, "%d");
+ if (pos != NULL)
+ replaceStr(pos, 2, date_buf);
+
+ pos = strstr(buf, "%o");
+ if(pos != NULL)
+ {
int other_offset, offset;
if(tzi.StandardDate.wMonth) {
@@ -329,16 +350,16 @@ VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
//if(offset < -12 * 60) offset += 24 * 60;
mir_snprintf(temp_buf, sizeof(temp_buf), "%+g", offset/60.0);
- buf.replace(pos, 2, temp_buf);
+ replaceStr(pos, 2, temp_buf);
}
if(!DBGetContactSetting(pa.hContact, "CList", "MyHandle", &dbv)) {
// only write if times are different
- if(strcmp(dbv.pszVal, buf.c_str()))
- DBWriteContactSettingString(pa.hContact, "CList", "MyHandle", buf.c_str());
+ if(strcmp(dbv.pszVal, buf))
+ DBWriteContactSettingString(pa.hContact, "CList", "MyHandle", buf);
DBFreeVariant(&dbv);
} else
- DBWriteContactSettingString(pa.hContact, "CList", "MyHandle", buf.c_str());
+ DBWriteContactSettingString(pa.hContact, "CList", "MyHandle", buf);
if(!DBGetContactSetting(pa.hContact, PROTO, "FirstName", &dbv)) {
// only write if times are different
@@ -435,7 +456,7 @@ int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
menu.cbSize=sizeof(menu);
menu.flags = CMIM_ALL;
- menu.hIcon=LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_PROTO));
+ menu.hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_PROTO), IMAGE_ICON, 0, 0, 0);
menu.position = -200000;
menu.pszName = (char *)Translate("Edit...");
@@ -443,6 +464,7 @@ int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
menu.pszContactOwner = PROTO;
hMenuEdit = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&menu);
+ DestroyIcon(menu.hIcon);
}
build_timezone_list();
@@ -458,6 +480,9 @@ extern "C" WORLDTIMEPROTO_API int Load(PLUGINLINK *link)
{
pluginLink=link;
+ mir_getMMI(&mmi);
+ mir_getLI(&li);
+
previousMode = mcStatus = ID_STATUS_OFFLINE;
PROTOCOLDESCRIPTOR pd = {0};