summaryrefslogtreecommitdiff
path: root/plugins/WhenWasIt/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-11-25 12:54:45 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-11-25 12:54:45 +0000
commitbd8a04455d9c991c15df2287e091abe4ba054efb (patch)
tree6af5485d60feef741669eb545a6378e7c209ab59 /plugins/WhenWasIt/src
parent7fdce14cd488e25e8e32e34098fbe9f5cb3021b7 (diff)
typed stub for MS_PROTO_GETCONTACTBASEPROTO
git-svn-id: http://svn.miranda-ng.org/main/trunk@2480 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/WhenWasIt/src')
-rw-r--r--plugins/WhenWasIt/src/WhenWasIt.cpp32
-rw-r--r--plugins/WhenWasIt/src/birthdays.cpp2
-rw-r--r--plugins/WhenWasIt/src/date_utils.cpp254
-rw-r--r--plugins/WhenWasIt/src/dlg_handlers.cpp115
-rw-r--r--plugins/WhenWasIt/src/hooked_events.cpp8
-rw-r--r--plugins/WhenWasIt/src/icons.cpp2
-rw-r--r--plugins/WhenWasIt/src/notifiers.cpp8
-rw-r--r--plugins/WhenWasIt/src/services.cpp326
-rw-r--r--plugins/WhenWasIt/src/utils.cpp209
-rw-r--r--plugins/WhenWasIt/src/utils.h1
10 files changed, 365 insertions, 592 deletions
diff --git a/plugins/WhenWasIt/src/WhenWasIt.cpp b/plugins/WhenWasIt/src/WhenWasIt.cpp
index de77127c7e..c99b540a22 100644
--- a/plugins/WhenWasIt/src/WhenWasIt.cpp
+++ b/plugins/WhenWasIt/src/WhenWasIt.cpp
@@ -29,8 +29,6 @@ int hLangpack;
CommonData commonData = {0};
-
-
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_DISPLAY_NAME,
@@ -41,13 +39,12 @@ PLUGININFOEX pluginInfo = {
__COPYRIGHT,
__AUTHORWEB,
UNICODE_AWARE,
- {0x2ff96c84, 0xb0b5, 0x470e, {0xbb, 0xf9, 0x90, 0x7b, 0x9f, 0x3f, 0x5d, 0x2f}} //{2ff96c84-b0b5-470e-bbf9-907b9f3f5d2f}
+ //{2ff96c84-b0b5-470e-bbf9-907b9f3f5d2f}
+ {0x2ff96c84, 0xb0b5, 0x470e, {0xbb, 0xf9, 0x90, 0x7b, 0x9f, 0x3f, 0x5d, 0x2f}}
};
extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD mirandaVersion)
{
-// Log("%s", "Entering function " __FUNCTION__);
-// Log("%s", "Leaving function " __FUNCTION__);
return &pluginInfo;
}
@@ -62,22 +59,15 @@ extern "C" int __declspec(dllexport) Load(void)
mir_getLP(&pluginInfo);
INITCOMMONCONTROLSEX icex;
-
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
-
InitCommonControlsEx(&icex);
- Log("%s", "Initialising miranda memory functions");
-
LoadIcons();
- //hBirthdaysDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_BIRTHDAYS), NULL, DlgProcBirthdays);
+
Log("%s", "Creating service functions ...");
InitServices();
-
- //Log("%s", "Creating events ...");
- //CreateEvents();
-
+
Log("%s", "Hooking events ...");
HookEvents();
@@ -93,14 +83,10 @@ extern "C" int __declspec(dllexport) Unload()
Log("%s", "Entering function " __FUNCTION__);
if (hBirthdaysDlg)
- {
SendMessage(hBirthdaysDlg, WM_CLOSE, 0, 0);
- }
if (hUpcomingDlg)
- {
SendMessage(hUpcomingDlg, WM_CLOSE, 0, 0);
- }
WindowList_Broadcast(hAddBirthdayWndsList, WM_CLOSE, 0, 0);
@@ -112,10 +98,8 @@ extern "C" int __declspec(dllexport) Unload()
Log("%s", "Destroying service functions ...");
DestroyServices();
-
-
+
Log("%s", "Leaving function " __FUNCTION__);
-
return 0;
}
@@ -123,9 +107,7 @@ bool WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
hInstance = hinstDLL;
if (fdwReason == DLL_PROCESS_ATTACH)
- {
- DisableThreadLibraryCalls(hinstDLL);
- }
-
+ DisableThreadLibraryCalls(hinstDLL);
+
return TRUE;
}
diff --git a/plugins/WhenWasIt/src/birthdays.cpp b/plugins/WhenWasIt/src/birthdays.cpp
index baed614aad..d69207b444 100644
--- a/plugins/WhenWasIt/src/birthdays.cpp
+++ b/plugins/WhenWasIt/src/birthdays.cpp
@@ -90,7 +90,7 @@ void CBirthdays::Realloc(int increaseCapacity)
int CBirthdays::Add(HANDLE hContact, HANDLE hClistIcon)
{
- if (!Contains(hContact))
+ if ( !Contains(hContact))
{
EnsureCapacity();
TBirthdayContact *item = (TBirthdayContact *) malloc(sizeof(TBirthdayContact));
diff --git a/plugins/WhenWasIt/src/date_utils.cpp b/plugins/WhenWasIt/src/date_utils.cpp
index e35710a2ca..856a2711ab 100644
--- a/plugins/WhenWasIt/src/date_utils.cpp
+++ b/plugins/WhenWasIt/src/date_utils.cpp
@@ -31,58 +31,43 @@ time_t Today()
int IsDOBValid(int year, int month, int day)
{
- return ((year != 0) && (month != 0) && (day != 0));
+ return (year != 0 && month != 0 && day != 0);
}
int GetContactDOB(HANDLE hContact, int &year, int &month, int &day)
{
- int res = DOB_USERINFO;
-
- //TCHAR *contact = GetContactName(hContact, NULL);
- year = DBGetContactSettingWord(hContact, "UserInfo", "DOBy", 0);
- month = DBGetContactSettingByte(hContact, "UserInfo", "DOBm", 0);
- day = DBGetContactSettingByte(hContact, "UserInfo", "DOBd", 0);
-
- if (!IsDOBValid(year, month, day))
- {
- res = DOB_MBIRTHDAY;
- year = DBGetContactSettingWord(hContact, "mBirthday", "BirthYear", 0);
- month = DBGetContactSettingByte(hContact, "mBirthday", "BirthMonth", 0);
- day = DBGetContactSettingByte(hContact, "mBirthday", "BirthDay", 0);
- }
-
- if (!IsDOBValid(year, month, day))
- {
- res = DOB_PROTOCOL;
- char protocol[512];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
- year = DBGetContactSettingWord(hContact, protocol, "BirthYear", 0);
- month = DBGetContactSettingByte(hContact, protocol, "BirthMonth", 0);
- day = DBGetContactSettingByte(hContact, protocol, "BirthDay", 0);
- }
-
- if (!IsDOBValid(year, month, day))
- {
- res = DOB_BIRTHDAYREMINDER;
- year = DBGetContactSettingWord(hContact, "BirthDay", "BirthYear", 0);
- month = DBGetContactSettingByte(hContact, "BirthDay", "BirthMonth", 0);
- day = DBGetContactSettingByte(hContact, "BirthDay", "BirthDay", 0);
- }
-
- if (!IsDOBValid(year, month, day))
- {
- res = DOB_MICQBIRTHDAY;
- year = DBGetContactSettingDword(hContact, "micqBirthday", "BirthYear", 0);
- month = DBGetContactSettingDword(hContact, "micqBirthday", "BirthMonth", 0);
- day = DBGetContactSettingDword(hContact, "micqBirthday", "BirthDay", 0);
- }
-
- if (!IsDOBValid(year, month, day))
- {
- res = DOB_UNKNOWN;
- }
- //free(contact);
- return res;
+ year = db_get_w(hContact, "UserInfo", "DOBy", 0);
+ month = db_get_b(hContact, "UserInfo", "DOBm", 0);
+ day = db_get_b(hContact, "UserInfo", "DOBd", 0);
+ if ( IsDOBValid(year, month, day))
+ return DOB_USERINFO;
+
+ year = db_get_w(hContact, "mBirthday", "BirthYear", 0);
+ month = db_get_b(hContact, "mBirthday", "BirthMonth", 0);
+ day = db_get_b(hContact, "mBirthday", "BirthDay", 0);
+ if ( IsDOBValid(year, month, day))
+ return DOB_MBIRTHDAY;
+
+ char *szProto = GetContactProto(hContact);
+ year = db_get_w(hContact, szProto, "BirthYear", 0);
+ month = db_get_b(hContact, szProto, "BirthMonth", 0);
+ day = db_get_b(hContact, szProto, "BirthDay", 0);
+ if ( IsDOBValid(year, month, day))
+ return DOB_PROTOCOL;
+
+ year = db_get_w(hContact, "BirthDay", "BirthYear", 0);
+ month = db_get_b(hContact, "BirthDay", "BirthMonth", 0);
+ day = db_get_b(hContact, "BirthDay", "BirthDay", 0);
+ if ( IsDOBValid(year, month, day))
+ return DOB_BIRTHDAYREMINDER;
+
+ year = db_get_dw(hContact, "micqBirthday", "BirthYear", 0);
+ month = db_get_dw(hContact, "micqBirthday", "BirthMonth", 0);
+ day = db_get_dw(hContact, "micqBirthday", "BirthDay", 0);
+ if ( IsDOBValid(year, month, day))
+ return DOB_MICQBIRTHDAY;
+
+ return DOB_UNKNOWN;
}
int GetContactAge(HANDLE hContact)
@@ -97,43 +82,35 @@ int GetContactAge(HANDLE hContact)
char GetContactGender(HANDLE hContact)
{
- char gender = DBGetContactSettingByte(hContact, "UserInfo", "Gender", 'U');
+ char gender = db_get_b(hContact, "UserInfo", "Gender", 'U');
if (gender == 'U')
- {
- char protocol[512];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
-
- gender = DBGetContactSettingByte(hContact, protocol, "Gender", 'U');
- }
+ gender = db_get_b(hContact, GetContactProto(hContact), "Gender", 'U');
+
return gender;
}
int IsLeapYear(int year)
{
- int yes = ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
- return yes;
+ return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
}
unsigned int GetDaysDifference(time_t time1, time_t time2)
{
errno = 0;
double diff = difftime(time1, time2);
- if (errno == 0)
- {
- diff = diff / (60 * 60 * 24);
- int days = (int) floor(diff);
- if (days < 0)
- {
- struct tm *date = gmtime(&time1);
- int leap = 0;
- if ((date->tm_mon > 2) && (IsLeapYear(date->tm_year))) //if month > feb and it's a leap year
- {
- leap = 1;
- }
- days = 365 + days + leap;
- }
- return days;
+ if (errno == 0) {
+ diff = diff / (60 * 60 * 24);
+ int days = (int) floor(diff);
+ if (days < 0) {
+ struct tm *date = gmtime(&time1);
+ int leap = 0;
+ if ((date->tm_mon > 2) && (IsLeapYear(date->tm_year))) //if month > feb and it's a leap year
+ leap = 1;
+
+ days = 365 + days + leap;
}
+ return days;
+ }
return 0x7fffffff;
}
@@ -158,37 +135,34 @@ int GetDaysDifferenceAfter(time_t time1, time_t time2)
unsigned int DaysToBirthday(time_t now, int ctYear, int ctMonth, int ctDay)
{
- if (IsDOBValid(ctYear, ctMonth, ctDay))
- {
- struct tm ct = {0};
- struct tm *tmp = gmtime(&now);
- ct.tm_year = tmp->tm_year;
- ct.tm_mon = ctMonth - 1;
- ct.tm_mday = ctDay;
- time_t ctBirthday = mktime(&ct);
- return GetDaysDifference(ctBirthday, now);
- }
+ if ( IsDOBValid(ctYear, ctMonth, ctDay)) {
+ struct tm ct = {0};
+ struct tm *tmp = gmtime(&now);
+ ct.tm_year = tmp->tm_year;
+ ct.tm_mon = ctMonth - 1;
+ ct.tm_mday = ctDay;
+ time_t ctBirthday = mktime(&ct);
+ return GetDaysDifference(ctBirthday, now);
+ }
return -1;
}
int DaysAfterBirthday(time_t now, int ctYear, int ctMonth, int ctDay)
{
- if (IsDOBValid(ctYear, ctMonth, ctDay))
- {
+ if ( IsDOBValid(ctYear, ctMonth, ctDay)) {
struct tm ct = {0};
struct tm *tmp = gmtime(&now);
ct.tm_year = tmp->tm_year;
ct.tm_mon = ctMonth - 1;
ct.tm_mday = ctDay;
time_t ctBirthday = mktime(&ct);
-
+
return GetDaysDifferenceAfter(ctBirthday, now);
}
-
+
return -1;
}
-
void FillProtocol(char *&sYear, char *&sMonth, char *&sDay)
{
sYear = "BirthYear";
@@ -218,66 +192,54 @@ int SaveBirthday(HANDLE hContact, int year, int month, int day, int mode)
char *sYear, *sdYear, *sd2Year;
char *sMonth, *sdMonth, *sd2Month;
char *sDay, *sdDay, *sd2Day;
- char protocol[256];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
+ char *protocol = GetContactProto(hContact);
- switch (mode)
- {
- case SAVE_MODE_MBIRTHDAY:
- {
- FillmBirthday(sModule, sYear, sMonth, sDay);
- FillStandard(sdModule, sdYear, sdMonth, sdDay);
- sd2Module = protocol;
- FillProtocol(sd2Year, sd2Month, sd2Day);
-
- break;
- }
-
- case SAVE_MODE_PROTOCOL:
- {
- sModule = protocol;
- FillProtocol(sYear, sMonth, sDay);
-
- FillmBirthday(sd2Module, sd2Year, sd2Month, sd2Day);
- FillStandard(sdModule, sdYear, sdMonth, sdDay);
-
- break;
- }
-
- case SAVE_MODE_STANDARD:
- default:
- {
- FillStandard(sModule, sYear, sMonth, sDay);
- FillmBirthday(sdModule, sdYear, sdMonth, sdDay);
- sd2Module = protocol;
- FillProtocol(sd2Year, sd2Month, sd2Day);
- break;
- }
- }
-
- if (mode == SAVE_MODE_DELETEALL)
- {
- DBDeleteContactSetting(hContact, sModule, sYear);
- DBDeleteContactSetting(hContact, sModule, sMonth);
- DBDeleteContactSetting(hContact, sModule, sDay);
- }
- else{
- db_set_dw(hContact, sModule, sYear, year);
- db_set_b(hContact, sModule, sMonth, month);
- db_set_b(hContact, sModule, sDay, day);
- }
-
- DBDeleteContactSetting(hContact, sdModule, sdYear);
- DBDeleteContactSetting(hContact, sdModule, sdMonth);
- DBDeleteContactSetting(hContact, sdModule, sdDay);
+ switch (mode) {
+ case SAVE_MODE_MBIRTHDAY:
+ FillmBirthday(sModule, sYear, sMonth, sDay);
+ FillStandard(sdModule, sdYear, sdMonth, sdDay);
+ sd2Module = protocol;
+ FillProtocol(sd2Year, sd2Month, sd2Day);
+ break;
+
+ case SAVE_MODE_PROTOCOL:
+ sModule = protocol;
+ FillProtocol(sYear, sMonth, sDay);
+
+ FillmBirthday(sd2Module, sd2Year, sd2Month, sd2Day);
+ FillStandard(sdModule, sdYear, sdMonth, sdDay);
+ break;
+
+ case SAVE_MODE_STANDARD:
+ default:
+ FillStandard(sModule, sYear, sMonth, sDay);
+ FillmBirthday(sdModule, sdYear, sdMonth, sdDay);
+ sd2Module = protocol;
+ FillProtocol(sd2Year, sd2Month, sd2Day);
+ break;
+ }
+
+ if (mode == SAVE_MODE_DELETEALL) {
+ db_unset(hContact, sModule, sYear);
+ db_unset(hContact, sModule, sMonth);
+ db_unset(hContact, sModule, sDay);
+ }
+ else {
+ db_set_dw(hContact, sModule, sYear, year);
+ db_set_b(hContact, sModule, sMonth, month);
+ db_set_b(hContact, sModule, sDay, day);
+ }
+
+ db_unset(hContact, sdModule, sdYear);
+ db_unset(hContact, sdModule, sdMonth);
+ db_unset(hContact, sdModule, sdDay);
- DBDeleteContactSetting(hContact, sd2Module, sd2Year);
- DBDeleteContactSetting(hContact, sd2Module, sd2Month);
- DBDeleteContactSetting(hContact, sd2Module, sd2Day);
+ db_unset(hContact, sd2Module, sd2Year);
+ db_unset(hContact, sd2Module, sd2Month);
+ db_unset(hContact, sd2Module, sd2Day);
- DBDeleteContactSetting(hContact, "BirthDay", "BirthYear");
- DBDeleteContactSetting(hContact, "BirthDay", "BirthMonth");
- DBDeleteContactSetting(hContact, "BirthDay", "BirthDay");
-
+ db_unset(hContact, "BirthDay", "BirthYear");
+ db_unset(hContact, "BirthDay", "BirthMonth");
+ db_unset(hContact, "BirthDay", "BirthDay");
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/WhenWasIt/src/dlg_handlers.cpp b/plugins/WhenWasIt/src/dlg_handlers.cpp
index 01eba03640..3f7f0f25cf 100644
--- a/plugins/WhenWasIt/src/dlg_handlers.cpp
+++ b/plugins/WhenWasIt/src/dlg_handlers.cpp
@@ -140,8 +140,6 @@ int EnlargeControl(HWND hCtrl, HWND hGroup, SIZE oldSize)
int offset = (rect.right - rect.left) - oldSize.cx;
SetWindowPos(hCtrl, HWND_TOP, 0, 0, size.cx + offset, oldSize.cy, SWP_NOMOVE);
SetWindowPos(hCtrl, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- //RedrawWindow(hCtrl, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASENOW);
-
return 0;
}
@@ -211,7 +209,6 @@ INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
CheckDlgButton(hWnd, IDC_OPENINBACKGROUND, (commonData.bOpenInBackground) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_NOBIRTHDAYS_POPUP, (commonData.bNoBirthdaysPopup) ? BST_CHECKED : BST_UNCHECKED);
- //CheckDlgButton(hWnd, IDC_SHOW_CURRENT_AGE, (bShowCurrentAge) ? BST_CHECKED : BST_UNCHECKED);
SendMessage(GetDlgItem(hWnd, IDC_AGE_COMBOBOX), CB_SETCURSEL, commonData.cShowAgeMode, 0);
CheckDlgButton(hWnd, IDC_IGNORE_SUBCONTACTS, (commonData.bIgnoreSubcontacts) ? BST_CHECKED : BST_UNCHECKED);
@@ -222,8 +219,7 @@ INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
CheckDlgButton(hWnd, IDC_USE_DIALOG, (commonData.bUseDialog) ? BST_CHECKED : BST_UNCHECKED);
EnableDialogGroup(hWnd, commonData.bUseDialog);
- if (ServiceExists(MS_POPUP_ADDPOPUPEX))
- {
+ if (ServiceExists(MS_POPUP_ADDPOPUPEX)) {
CheckDlgButton(hWnd, IDC_USE_POPUPS, commonData.bUsePopups ? BST_CHECKED : BST_UNCHECKED);
EnablePopupsGroup(hWnd, commonData.bUsePopups);
}
@@ -325,7 +321,7 @@ INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
GetWindowText(GetDlgItem(hWnd, IDC_CHECK_INTERVAL), buffer, maxSize);
commonData.checkInterval = _ttol(buffer);
- if (!commonData.checkInterval) { commonData.checkInterval = CHECK_INTERVAL; }
+ if ( !commonData.checkInterval) { commonData.checkInterval = CHECK_INTERVAL; }
GetWindowText(GetDlgItem(hWnd, IDC_POPUP_TIMEOUT), buffer, maxSize);
TCHAR *pos;
@@ -421,16 +417,14 @@ INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
HANDLE hContact = (HANDLE) GetWindowLongPtr(hWnd, GWLP_USERDATA);
const int maxSize = 2048;
TCHAR buffer[maxSize];
- char protocol[256];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
-
+ char *protocol = GetContactProto(hContact);
TCHAR *name = GetContactName(hContact, protocol);
_stprintf(buffer, TranslateT("Set birthday for %s:"), name);
free(name);
SetWindowText(hWnd, buffer);
HWND hDate = GetDlgItem(hWnd, IDC_DATE);
int loc = GetContactDOB(hContact, year, month, day);
- if (IsDOBValid(year, month, day)) {
+ if ( IsDOBValid(year, month, day)) {
SYSTEMTIME st = {0};
st.wDay = day;
st.wMonth = month;
@@ -470,7 +464,7 @@ INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
szCurrentModuleTooltip = NULL;
break;
}
- //CreateToolTip(GetDlgItem(hWnd, IDC_COMPATIBILITY), hWnd, szTooltipText);
+
CreateToolTip(GetDlgItem(hWnd, IDC_COMPATIBILITY), szTooltipText, 500);
if (szCurrentModuleTooltip)
CreateToolTip(hDate, szCurrentModuleTooltip, 400);
@@ -497,14 +491,11 @@ INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
SYSTEMTIME st;
HANDLE hContact = (HANDLE) GetWindowLongPtr(hWnd, GWLP_USERDATA);
HWND hDate = GetDlgItem(hWnd, IDC_DATE);
- if (DateTime_GetSystemtime(hDate, &st) == GDT_VALID)
- {
+ if (DateTime_GetSystemtime(hDate, &st) == GDT_VALID) {
int mode = SendMessage(GetDlgItem(hWnd, IDC_COMPATIBILITY), CB_GETCURSEL, 0, 0); //SAVE modes in date_utils.h are synced
SaveBirthday(hContact, st.wYear, st.wMonth, st.wDay, mode);
}
- else{
- SaveBirthday(hContact, 0, 0, 0, SAVE_MODE_DELETEALL);
- }
+ else SaveBirthday(hContact, 0, 0, 0, SAVE_MODE_DELETEALL);
if (hBirthdaysDlg != NULL)
SendMessage(hBirthdaysDlg, WWIM_UPDATE_BIRTHDAY, (WPARAM) hContact, NULL);
@@ -530,54 +521,31 @@ void AddAnchorWindowToDeferList(HDWP &hdWnds, HWND window, RECT *rParent, WINDOW
TCHAR *GetBirthdayModule(int module, HANDLE hContact, TCHAR *birthdayModule, int size)
{
- switch (module)
- {
- case DOB_MBIRTHDAY:
- {
- _tcsncpy(birthdayModule, _T("mBirthday"), size);
-
- break;
- }
-
- case DOB_PROTOCOL:
- {
- char protocol[512];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
+ switch (module) {
+ case DOB_MBIRTHDAY:
+ _tcsncpy(birthdayModule, _T("mBirthday"), size);
+ break;
- _sntprintf(birthdayModule, size, TranslateT("%S protocol"), protocol);
+ case DOB_PROTOCOL:
+ _sntprintf(birthdayModule, size, TranslateT("%S protocol"), GetContactProto(hContact));
+ break;
-
- break;
- }
-
- case DOB_BIRTHDAYREMINDER:
- {
- _tcsncpy(birthdayModule, _T("Birthday Reminder"), size);
-
- break;
- }
-
- case DOB_USERINFO:
- {
- _tcsncpy(birthdayModule, _T("UserInfo"), size);
-
- break;
- }
+ case DOB_BIRTHDAYREMINDER:
+ _tcsncpy(birthdayModule, _T("Birthday Reminder"), size);
+ break;
- case DOB_MICQBIRTHDAY:
- {
- _tcsncpy(birthdayModule, _T("mICQBirthday"), size);
+ case DOB_USERINFO:
+ _tcsncpy(birthdayModule, _T("UserInfo"), size);
+ break;
- break;
- }
-
- default:
- {
- _tcsncpy(birthdayModule, NA, size);
-
- break;
- }
- }
+ case DOB_MICQBIRTHDAY:
+ _tcsncpy(birthdayModule, _T("mICQBirthday"), size);
+ break;
+
+ default:
+ _tcsncpy(birthdayModule, NA, size);
+ break;
+ }
return birthdayModule;
}
@@ -629,7 +597,7 @@ int UpdateBirthdayEntry(HWND hList, HANDLE hContact, int entry, int bShowAll, in
int year, month, day;
TCHAR *name;
int module;
- char protocol[512];
+ char *protocol;
LVITEM item = {0};
int currentYear;
@@ -638,8 +606,7 @@ int UpdateBirthdayEntry(HWND hList, HANDLE hContact, int entry, int bShowAll, in
int res = entry;
- if (bShowCurrentAge)
- {
+ if (bShowCurrentAge) {
time_t now = Today();
struct tm *today = gmtime(&now);
currentDay = today->tm_mday + 1;
@@ -651,7 +618,7 @@ int UpdateBirthdayEntry(HWND hList, HANDLE hContact, int entry, int bShowAll, in
item.iItem = entry;
module = GetContactDOB(hContact, year, month, day);
- if ((bShowAll) || (IsDOBValid(year, month, day))) {
+ if (bShowAll || IsDOBValid(year, month, day)) {
lastColumn = -1; //list isn't sorted anymore
dtb = DaysToBirthday(Today(), year, month, day);
age = GetContactAge(hContact);
@@ -661,7 +628,7 @@ int UpdateBirthdayEntry(HWND hList, HANDLE hContact, int entry, int bShowAll, in
item.lParam = (LPARAM) hContact;
- GetContactProtocol(hContact, protocol, sizeof(protocol));
+ protocol = GetContactProto(hContact);
MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, protocol, -1, buffer, maxSize);
@@ -750,13 +717,11 @@ void SetBirthdaysCount(HWND hWnd)
int LoadBirthdays(HWND hWnd, int bShowAll)
{
- HANDLE hContact = db_find_first();
HWND hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
- //int bShowCurrentAge = DBGetContactSettingByte(NULL, ModuleName, "ShowCurrentAge", 0);
-
ListView_DeleteAllItems(hList);
int count = 0;
+ HANDLE hContact = db_find_first();
while (hContact) {
count = UpdateBirthdayEntry(hList, hContact, count, bShowAll, commonData.cShowAgeMode, 1);
hContact = db_find_next(hContact);
@@ -796,11 +761,11 @@ INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
col.cx = 50;
ListView_InsertColumn(hList, 4, &col);
col.pszText = TranslateT("Module");
- col.cx = 110;
+ col.cx = 108;
ListView_InsertColumn(hList, 5, &col);
LoadBirthdays(hWnd, 0);
- int column = DBGetContactSettingByte(NULL, ModuleName, "SortColumn", 0);
+ int column = db_get_b(NULL, ModuleName, "SortColumn", 0);
BirthdaysSortParams params = {0};
params.hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
@@ -808,10 +773,8 @@ INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
ListView_SortItemsEx(params.hList, BirthdaysCompare, (LPARAM) &params);
Utils_RestoreWindowPosition(hWnd,NULL,ModuleName,"BirthdayList");
-
- return TRUE;
- break;
}
+ return TRUE;
case WM_DESTROY:
hBirthdaysDlg = NULL;
@@ -829,7 +792,7 @@ INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
HANDLE hContact = (HANDLE) wParam;
int i;
int count = ListView_GetItemCount(hList);
- //int bShowCurrentAge = DBGetContactSettingByte(NULL, ModuleName, "ShowCurrentAge", 0);
+ //int bShowCurrentAge = db_get_b(NULL, ModuleName, "ShowCurrentAge", 0);
LVITEM item = {0};
int found = 0;
@@ -842,7 +805,7 @@ INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
found = 1;
}
}
- if (!found)
+ if ( !found)
UpdateBirthdayEntry(hList, hContact, count, IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), commonData.cShowAgeMode, 1);
SetBirthdaysCount(hWnd);
@@ -1053,4 +1016,4 @@ INT_PTR CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
return DefWindowProc(hWnd, msg, wParam, lParam);
-} \ No newline at end of file
+}
diff --git a/plugins/WhenWasIt/src/hooked_events.cpp b/plugins/WhenWasIt/src/hooked_events.cpp
index 26ba840ee5..fc47b37771 100644
--- a/plugins/WhenWasIt/src/hooked_events.cpp
+++ b/plugins/WhenWasIt/src/hooked_events.cpp
@@ -219,8 +219,8 @@ int OnExtraImageApply(WPARAM wParam, LPARAM lParam)
return 0;
int count = CallService(MS_DB_CONTACT_GETCOUNT, 0, 0);
- int hidden = DBGetContactSettingByte(hContact, "CList", "Hidden", 0);
- int ignored = DBGetContactSettingDword(hContact, "Ignore", "Mask1", 0);
+ int hidden = db_get_b(hContact, "CList", "Hidden", 0);
+ int ignored = db_get_dw(hContact, "Ignore", "Mask1", 0);
ignored = ((ignored & 0x3f) != 0) ? 1 : 0;
int ok = 1;
if (commonData.notifyFor & EXCLUDE_HIDDEN)
@@ -274,10 +274,10 @@ int UpdateTimers()
hCheckTimer = NULL;
}
- long interval = DBGetContactSettingDword(NULL, ModuleName, "Interval", CHECK_INTERVAL);
+ long interval = db_get_dw(NULL, ModuleName, "Interval", CHECK_INTERVAL);
interval *= 1000 * 60 * 60; //go from miliseconds to hours
hCheckTimer = SetTimer(NULL, 0, interval, (TIMERPROC) OnCheckTimer);
- if (!hDateChangeTimer)
+ if ( !hDateChangeTimer)
hDateChangeTimer = SetTimer(NULL, 0, 1000 * DATE_CHANGE_CHECK_INTERVAL, (TIMERPROC) OnDateChangeTimer);
return 0;
diff --git a/plugins/WhenWasIt/src/icons.cpp b/plugins/WhenWasIt/src/icons.cpp
index 6ac1627e97..d8099345f0 100644
--- a/plugins/WhenWasIt/src/icons.cpp
+++ b/plugins/WhenWasIt/src/icons.cpp
@@ -121,7 +121,7 @@ void FreeIcon(HICON &icon)
void FreeIcons()
{
static int bFreed = 0;
- if (!bFreed) {
+ if ( !bFreed) {
FreeIcon(hiCheckMenu);
FreeIcon(hiListMenu);
FreeIcon(hiAddBirthdayContact);
diff --git a/plugins/WhenWasIt/src/notifiers.cpp b/plugins/WhenWasIt/src/notifiers.cpp
index 7bc8e437ec..0c82dfadfc 100644
--- a/plugins/WhenWasIt/src/notifiers.cpp
+++ b/plugins/WhenWasIt/src/notifiers.cpp
@@ -70,7 +70,7 @@ int PopupNotifyBirthday(HANDLE hContact, int dtb, int age)
TCHAR *name = GetContactName(hContact, NULL);
const int MAX_SIZE = 1024;
TCHAR text[MAX_SIZE];
- //int bIgnoreSubcontacts = DBGetContactSettingByte(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
+ //int bIgnoreSubcontacts = db_get_b(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
if (commonData.bIgnoreSubcontacts)
{
HANDLE hMetacontact = (HANDLE) CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0);
@@ -122,7 +122,7 @@ int PopupNotifyMissedBirthday(HANDLE hContact, int dab, int age)
TCHAR *name = GetContactName(hContact, NULL);
const int MAX_SIZE = 1024;
TCHAR text[MAX_SIZE];
- //int bIgnoreSubcontacts = DBGetContactSettingByte(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
+ //int bIgnoreSubcontacts = db_get_b(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
if (commonData.bIgnoreSubcontacts) {
HANDLE hMetacontact = (HANDLE) CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0);
if (hMetacontact && hMetacontact != hContact) //not main metacontact
@@ -174,7 +174,7 @@ int DialogNotifyBirthday(HANDLE hContact, int dtb, int age)
TCHAR text[MAX_SIZE];
BuildDTBText(dtb, name, text, MAX_SIZE);
- if (!hUpcomingDlg) {
+ if ( !hUpcomingDlg) {
hUpcomingDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_UPCOMING), NULL, DlgProcUpcoming);
ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
@@ -200,7 +200,7 @@ int DialogNotifyMissedBirthday(HANDLE hContact, int dab, int age)
TCHAR text[MAX_SIZE];
BuildDABText(dab, name, text, MAX_SIZE);
- if (!hUpcomingDlg) {
+ if ( !hUpcomingDlg) {
hUpcomingDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_UPCOMING), NULL, DlgProcUpcoming);
ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
diff --git a/plugins/WhenWasIt/src/services.cpp b/plugins/WhenWasIt/src/services.cpp
index 76e9b36518..32241b33b9 100644
--- a/plugins/WhenWasIt/src/services.cpp
+++ b/plugins/WhenWasIt/src/services.cpp
@@ -37,26 +37,26 @@ int InitServices()
{
Log("%s", "Entering function " __FUNCTION__);
- commonData.foreground = DBGetContactSettingDword(NULL, ModuleName, "Foreground", FOREGROUND_COLOR);
- commonData.background = DBGetContactSettingDword(NULL, ModuleName, "Background", BACKGROUND_COLOR);
- commonData.checkInterval = DBGetContactSettingWord(NULL, ModuleName, "CheckInterval", CHECK_INTERVAL);
- commonData.daysInAdvance = DBGetContactSettingWord(NULL, ModuleName, "DaysInAdvance", DAYS_TO_NOTIFY);
- commonData.daysAfter = DBGetContactSettingWord(NULL, ModuleName, "DaysAfter", DAYS_TO_NOTIFY_AFTER);
- commonData.popupTimeout = DBGetContactSettingWord(NULL, ModuleName, "PopupTimeout", POPUP_TIMEOUT);
- commonData.popupTimeoutToday = DBGetContactSettingWord(NULL, ModuleName, "PopupTimeoutToday", commonData.popupTimeout);
- commonData.bUsePopups = DBGetContactSettingByte(NULL, ModuleName, "UsePopups", TRUE);
- commonData.bUseDialog = DBGetContactSettingByte(NULL, ModuleName, "UseDialog", TRUE);
- commonData.bIgnoreSubcontacts = DBGetContactSettingByte(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
- commonData.cShowAgeMode = DBGetContactSettingByte(NULL, ModuleName, "ShowCurrentAge", FALSE);
- commonData.bNoBirthdaysPopup = DBGetContactSettingByte(NULL, ModuleName, "NoBirthdaysPopup", FALSE);
- commonData.bOpenInBackground = DBGetContactSettingByte(NULL, ModuleName, "OpenInBackground", FALSE);
- commonData.cSoundNearDays = DBGetContactSettingByte(NULL, ModuleName, "SoundNearDays", BIRTHDAY_NEAR_DEFAULT_DAYS);
- commonData.cDefaultModule = DBGetContactSettingByte(NULL, ModuleName, "DefaultModule", 0);
- commonData.lPopupClick = DBGetContactSettingByte(NULL, ModuleName, "PopupLeftClick", 2);
- commonData.rPopupClick = DBGetContactSettingByte(NULL, ModuleName, "PopupRightClick", 1);
- commonData.bOncePerDay = DBGetContactSettingByte(NULL, ModuleName, "OncePerDay", 0);
- commonData.cDlgTimeout = DBGetContactSettingWord(NULL, ModuleName, "DlgTimeout", POPUP_TIMEOUT);
- commonData.notifyFor = DBGetContactSettingByte(NULL, ModuleName, "NotifyFor", 0);
+ commonData.foreground = db_get_dw(NULL, ModuleName, "Foreground", FOREGROUND_COLOR);
+ commonData.background = db_get_dw(NULL, ModuleName, "Background", BACKGROUND_COLOR);
+ commonData.checkInterval = db_get_w(NULL, ModuleName, "CheckInterval", CHECK_INTERVAL);
+ commonData.daysInAdvance = db_get_w(NULL, ModuleName, "DaysInAdvance", DAYS_TO_NOTIFY);
+ commonData.daysAfter = db_get_w(NULL, ModuleName, "DaysAfter", DAYS_TO_NOTIFY_AFTER);
+ commonData.popupTimeout = db_get_w(NULL, ModuleName, "PopupTimeout", POPUP_TIMEOUT);
+ commonData.popupTimeoutToday = db_get_w(NULL, ModuleName, "PopupTimeoutToday", commonData.popupTimeout);
+ commonData.bUsePopups = db_get_b(NULL, ModuleName, "UsePopups", TRUE);
+ commonData.bUseDialog = db_get_b(NULL, ModuleName, "UseDialog", TRUE);
+ commonData.bIgnoreSubcontacts = db_get_b(NULL, ModuleName, "IgnoreSubcontacts", FALSE);
+ commonData.cShowAgeMode = db_get_b(NULL, ModuleName, "ShowCurrentAge", FALSE);
+ commonData.bNoBirthdaysPopup = db_get_b(NULL, ModuleName, "NoBirthdaysPopup", FALSE);
+ commonData.bOpenInBackground = db_get_b(NULL, ModuleName, "OpenInBackground", FALSE);
+ commonData.cSoundNearDays = db_get_b(NULL, ModuleName, "SoundNearDays", BIRTHDAY_NEAR_DEFAULT_DAYS);
+ commonData.cDefaultModule = db_get_b(NULL, ModuleName, "DefaultModule", 0);
+ commonData.lPopupClick = db_get_b(NULL, ModuleName, "PopupLeftClick", 2);
+ commonData.rPopupClick = db_get_b(NULL, ModuleName, "PopupRightClick", 1);
+ commonData.bOncePerDay = db_get_b(NULL, ModuleName, "OncePerDay", 0);
+ commonData.cDlgTimeout = db_get_w(NULL, ModuleName, "DlgTimeout", POPUP_TIMEOUT);
+ commonData.notifyFor = db_get_b(NULL, ModuleName, "NotifyFor", 0);
hsCheckBirthdays = CreateServiceFunction(MS_WWI_CHECK_BIRTHDAYS, CheckBirthdaysService);
hsShowList = CreateServiceFunction(MS_WWI_LIST_SHOW, ShowListService);
@@ -94,9 +94,8 @@ int NotifyContactBirthday(HANDLE hContact, time_t now, int daysInAdvance)
GetContactDOB(hContact, year, month, day);
int daysToBirthday = DaysToBirthday(now, year, month, day);
if (daysInAdvance >= daysToBirthday)
- {
- return daysToBirthday;
- }
+ return daysToBirthday;
+
return -1;
}
@@ -120,15 +119,15 @@ int NotifyMissedContactBirthday(HANDLE hContact, time_t now, int daysAfter)
//the timer functions call this service with lParam = 1
//lParam = 0 - force check, lParam - 1 do not force it.
+
INT_PTR CheckBirthdaysService(WPARAM wParam, LPARAM lParam)
{
bBirthdayFound = 0; //no birthdays have been found in the given interval
- //int bNoBirthdaysPopup = DBGetContactSettingByte(NULL, ModuleName, "NoBirthdaysPopup", FALSE);
SYSTEMTIME today;
GetLocalTime(&today);
- DWORD lastChecked = DBGetContactSettingDword(NULL, ModuleName, "LastChecked", 0); //get last checked date
+ DWORD lastChecked = db_get_dw(NULL, ModuleName, "LastChecked", 0); //get last checked date
int lcDay = LOBYTE(LOWORD(lastChecked));
int lcMonth = HIBYTE(LOWORD(lastChecked));
int lcYear = HIWORD(lastChecked);
@@ -139,42 +138,32 @@ INT_PTR CheckBirthdaysService(WPARAM wParam, LPARAM lParam)
savedDaysAfter = commonData.daysAfter; //save value
if ((daysAfter > commonData.daysAfter) && (commonData.daysAfter > 0))//check for passed birthdays
- {
commonData.daysAfter = daysAfter; //bigger values of the two
- }
if ((lParam) && (commonData.bOncePerDay)) //if force check then we don't take OncePerDay into account
- {
- if ((lcDay == today.wDay) && (lcMonth == today.wMonth) && (lcYear == today.wYear))
- {
+ if (lcDay == today.wDay && lcMonth == today.wMonth && lcYear == today.wYear)
return 0; //already checked today
- }
- }
bShouldCheckBirthdays = 1;
RefreshAllContactListIcons();
if ((!bBirthdayFound) && (commonData.bNoBirthdaysPopup))
- {
PopupNotifyNoBirthdays();
- }
+
bShouldCheckBirthdays = 0;
-
+
commonData.daysAfter = savedDaysAfter; //restore previous value
if (lParam) //if not forced - i.e. timer check
- {
db_set_dw(NULL, ModuleName, "LastChecked", MAKELONG(MAKEWORD(today.wDay, today.wMonth), today.wYear)); //write the value in DB so we don't check again today
- }
return 0;
}
INT_PTR ShowListService(WPARAM wParam, LPARAM lParam)
{
- if (!hBirthdaysDlg)
- {
- hBirthdaysDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_BIRTHDAYS), NULL, DlgProcBirthdays);
- }
+ if ( !hBirthdaysDlg)
+ hBirthdaysDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_BIRTHDAYS), NULL, DlgProcBirthdays);
+
ShowWindow(hBirthdaysDlg, SW_SHOW);
return 0;
}
@@ -182,18 +171,16 @@ INT_PTR ShowListService(WPARAM wParam, LPARAM lParam)
INT_PTR AddBirthdayService(WPARAM wParam, LPARAM lParam)
{
HWND hWnd = WindowList_Find(hAddBirthdayWndsList, (HANDLE) wParam);
- if (!hWnd)
- {
- hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_ADD_BIRTHDAY), NULL, DlgProcAddBirthday);
- if (hWnd == NULL)
- {
- TCHAR buffer[1024];
- _stprintf(buffer, _T("Error #%d while trying to create add birthday dialog"), GetLastError());
- MessageBox(0, buffer, _T("Error"), MB_OK);
- }
- WindowList_Add(hAddBirthdayWndsList, hWnd, (HANDLE) wParam);
- SetWindowLongPtr(hWnd, GWLP_USERDATA, wParam);
+ if ( !hWnd) {
+ hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_ADD_BIRTHDAY), NULL, DlgProcAddBirthday);
+ if (hWnd == NULL) {
+ TCHAR buffer[1024];
+ _stprintf(buffer, _T("Error #%d while trying to create add birthday dialog"), GetLastError());
+ MessageBox(0, buffer, _T("Error"), MB_OK);
}
+ WindowList_Add(hAddBirthdayWndsList, hWnd, (HANDLE) wParam);
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, wParam);
+ }
return ShowWindow(hWnd, SW_SHOW);
}
@@ -205,55 +192,39 @@ void ShowPopupMessage(TCHAR *title, TCHAR *message, HICON icon)
_tcscpy(pd.lptzText, message);
pd.colorText = commonData.foreground;
pd.colorBack = commonData.background;
-
PUAddPopUpT(&pd);
}
DWORD WINAPI RefreshUserDetailsWorkerThread(LPVOID param)
{
- //MessageBox(0, "Inside worker thread", "Info", MB_OK);
- //POPUPDATA pd = {0};
- //pd.lchIcon = hiRefreshUserDetails;
- //strcpy(pd.lpzContactName, Translate("WhenWasIt"));
- //strcpy(pd.lpzText, Translate("Starting to refresh user details"));
- //PUAddPopUp(&pd);
ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Starting to refresh user details"), hiRefreshUserDetails);
- int delay = DBGetContactSettingWord(NULL, ModuleName, "UpdateDelay", REFRESH_DETAILS_DELAY);
- HANDLE hContact = db_find_first();
+ int delay = db_get_w(NULL, ModuleName, "UpdateDelay", REFRESH_DETAILS_DELAY);
int res;
- while (hContact != NULL)
- {
- res = CallContactService(hContact, PSS_GETINFO, 0, 0);
- hContact = db_find_next(hContact);
- if (hContact)
- {
- Sleep(delay); //sleep for a few seconds between requests
- }
- }
- //strcpy(pd.lpzText, Translate("Done refreshing user details"));
- //PUAddPopUp(&pd);
+
+ HANDLE hContact = db_find_first();
+ while (hContact != NULL) {
+ res = CallContactService(hContact, PSS_GETINFO, 0, 0);
+ hContact = db_find_next(hContact);
+ if (hContact)
+ Sleep(delay); //sleep for a few seconds between requests
+ }
ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done refreshing user details"), hiRefreshUserDetails);
- //MessageBox(0, "Leaving worker thread", "Info", MB_OK);
return 0;
}
INT_PTR RefreshUserDetailsService(WPARAM wParam, LPARAM lParam)
{
DWORD threadID;
- //MessageBox(0, "Before CreateThread()", "Info", MB_OK);
HANDLE result = CreateThread(NULL, 0, RefreshUserDetailsWorkerThread, NULL, 0, &threadID);
- //MessageBox(0, "After CreateThread()", "Info", MB_OK);
- if (!result)
- {
- TCHAR buffer[1024];
- _stprintf(buffer, _T("Could not create worker thread. Error#%d - threadID %d"), GetLastError(), threadID);
- MessageBox(0, buffer, _T("Error"), MB_OK | MB_ICONERROR);
+ if ( !result) {
+ TCHAR buffer[1024];
+ _stprintf(buffer, _T("Could not create worker thread. Error#%d - threadID %d"), GetLastError(), threadID);
+ MessageBox(0, buffer, _T("Error"), MB_OK | MB_ICONERROR);
}
+
if ((result != NULL) && (result != INVALID_HANDLE_VALUE))
- {
CloseHandle(result);
- }
-
+
return 0;
}
@@ -270,16 +241,15 @@ INT_PTR ImportBirthdaysService(WPARAM wParam, LPARAM lParam)
of.nMaxFile = 1024;
of.lpstrTitle = TranslateT("Please select a file to import birthdays from ...");
of.Flags = OFN_FILEMUSTEXIST;
-
- if (GetOpenFileName(&of))
- {
- TCHAR buffer[2048];
- mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("Importing birthdays from file: %s"), fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hiImportBirthdays);
- DoImport(fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done importing birthdays"), hiImportBirthdays);
- }
-
+
+ if ( GetOpenFileName(&of)) {
+ TCHAR buffer[2048];
+ mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("Importing birthdays from file: %s"), fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hiImportBirthdays);
+ DoImport(fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done importing birthdays"), hiImportBirthdays);
+ }
+
return 0;
}
@@ -295,126 +265,100 @@ INT_PTR ExportBirthdaysService(WPARAM wParam, LPARAM lParam)
of.lpstrFile = fileName;
of.nMaxFile = 1024;
of.lpstrTitle = TranslateT("Please select a file to export birthdays to ...");
- //of.Flags = OFN_ENABLESIZING | OFN_EXPLORER;
-
- if (GetSaveFileName(&of))
- {
- TCHAR buffer[2048];
- TCHAR *fn = _tcsrchr(fileName, _T('\\')) + 1;
- if (!_tcschr(fn, _T('.')))
- {
- _tcscat(fileName, _T(BIRTHDAY_EXTENSION));
- }
- _stprintf(buffer, TranslateT("Exporting birthdays to file: %s"), fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hiExportBirthdays);
- DoExport(fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done exporting birthdays"), hiExportBirthdays);
- }
-
+
+ if ( GetSaveFileName(&of)) {
+ TCHAR buffer[2048];
+ TCHAR *fn = _tcsrchr(fileName, _T('\\')) + 1;
+ if ( !_tcschr(fn, _T('.')))
+ _tcscat(fileName, _T(BIRTHDAY_EXTENSION));
+
+ _stprintf(buffer, TranslateT("Exporting birthdays to file: %s"), fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hiExportBirthdays);
+ DoExport(fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done exporting birthdays"), hiExportBirthdays);
+ }
+
return 0;
}
int DoImport(TCHAR *fileName)
{
FILE *fin = _tfopen(fileName, _T("rt"));
- if (!fin)
- {
- MessageBox(0, _T("Could not open file to import birthdays"), _T("Error"), MB_OK | MB_ICONERROR);
- return 1;
- }
+ if ( !fin) {
+ MessageBox(0, _T("Could not open file to import birthdays"), _T("Error"), MB_OK | MB_ICONERROR);
+ return 1;
+ }
- HANDLE hContact;
- int year, month, day;
- TCHAR *szHandle;
- TCHAR *szProto;
- const int maxSize = 4096;
- TCHAR buffer[maxSize];
- int tmp, tmp2;
- int mode = commonData.cDefaultModule; //DBGetContactSettingByte(NULL, ModuleName, "DefaultModule", 0);
- TCHAR *delAccount, *delProto;
+ int mode = commonData.cDefaultModule;
- while (!feof(fin))
- {
- _fgetts(buffer, maxSize, fin);
- if (buffer[0] == _T(COMMENT_CHAR))
- {
- continue;
- }
+ while (!feof(fin)) {
+ TCHAR buffer[4096];
+ _fgetts(buffer, SIZEOF(buffer), fin);
+ if (buffer[0] == _T(COMMENT_CHAR))
+ continue;
+
+ TCHAR *delAccount = _tcsstr(buffer, _T(" : "));
+ if (delAccount) {
+ int tmp = delAccount[0];
+ delAccount[0] = _T('\0');
+ TCHAR *delProto = _tcsrchr(buffer, _T('@'));
+ if (delProto) {
+ int tmp2 = delProto[0];
+ delProto[0] = _T('\0');
+
+ TCHAR *szHandle = buffer;
+ TCHAR *szProto = delProto + 1;
+ HANDLE hContact = GetContactFromID(szHandle, szProto);
+ if (hContact) {
+ delProto[0] = tmp;
+ delAccount[0] = tmp;
- delAccount = _tcsstr(buffer, _T(" : "));
- if (delAccount)
- {
- tmp = delAccount[0];
- delAccount[0] = _T('\0');
- delProto = _tcsrchr(buffer, _T('@'));
- if (delProto)
- {
- tmp2 = delProto[0];
- delProto[0] = _T('\0');
-
- szHandle = buffer;
- szProto = delProto + 1;
- hContact = GetContactFromID(szHandle, szProto);
- if (hContact)
- {
- delProto[0] = tmp;
- delAccount[0] = tmp;
- _stscanf(delAccount, _T(" : %02d/%02d/%04d"), &day, &month, &year);
- SaveBirthday(hContact, year, month, day, mode);
- }
- else{
- TCHAR tmp[2048];
- _stprintf(tmp, TranslateT(NOTFOUND_FORMAT), szHandle, szProto);
- ShowPopupMessage(TranslateT("Warning"), tmp, hiImportBirthdays);
- }
- }
+ int year, month, day;
+ _stscanf(delAccount, _T(" : %02d/%02d/%04d"), &day, &month, &year);
+ SaveBirthday(hContact, year, month, day, mode);
+ }
+ else {
+ TCHAR tmp[2048];
+ _stprintf(tmp, TranslateT(NOTFOUND_FORMAT), szHandle, szProto);
+ ShowPopupMessage(TranslateT("Warning"), tmp, hiImportBirthdays);
}
+ }
}
-
- fclose(fin);
+ }
+ fclose(fin);
return 0;
}
int DoExport(TCHAR *fileName)
{
FILE *fout = _tfopen(fileName, _T("wt"));
- if (!fout)
- {
- MessageBox(0, _T("Could not open file to export birthdays"), _T("Error"), MB_OK | MB_ICONERROR);
- return 1;
- }
+ if ( !fout) {
+ MessageBox(0, _T("Could not open file to export birthdays"), _T("Error"), MB_OK | MB_ICONERROR);
+ return 1;
+ }
_ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), _T("Please do not edit this file by hand. Use the export function of WhenWasIt plugin.\n"));
_ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), _T("Warning! Please do not mix Unicode and Ansi exported birthday files. You should use the same version (Ansi/Unicode) of WhenWasIt that was used to export the info.\n"));
-
_ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), _T("This file was exported with a Unicode version of WhenWasIt. Please only use a Unicode version of the plugin to import the birthdays.\n"));
-
+
HANDLE hContact = db_find_first();
- int year, month, day;
- TCHAR *szHandle;
- char szProto[256];
-
- while (hContact)
- {
- GetContactDOB(hContact, year, month, day);
- if (IsDOBValid(year, month, day))
- {
- szProto[0] = '\0';
- GetContactProtocol(hContact, szProto, sizeof(szProto));
- szHandle = GetContactID(hContact, szProto);
-
- if ((szHandle) && (strlen(szProto) > 0))
- {
- _ftprintf(fout, _T(BIRTHDAYS_EXPORT_FORMAT), szHandle, szProto, day, month, year);
- }
-
- if (szHandle) free(szHandle);
- }
-
- hContact = db_find_next(hContact);
+ while (hContact) {
+ int year, month, day;
+ GetContactDOB(hContact, year, month, day);
+ if ( IsDOBValid(year, month, day)) {
+ char *szProto = GetContactProto(hContact);
+ TCHAR *szHandle = GetContactID(hContact, szProto);
+
+ if ((szHandle) && (strlen(szProto) > 0))
+ _ftprintf(fout, _T(BIRTHDAYS_EXPORT_FORMAT), szHandle, szProto, day, month, year);
+
+ if (szHandle)
+ free(szHandle);
}
-
+
+ hContact = db_find_next(hContact);
+ }
+
fclose(fout);
-
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp
index 96a86ee8be..9d59dd9067 100644
--- a/plugins/WhenWasIt/src/utils.cpp
+++ b/plugins/WhenWasIt/src/utils.cpp
@@ -37,7 +37,7 @@ int Log(char *format, ...)
va_list vararg;
int tBytes;
FILE *fout = fopen(LOG_FILE, "at");
- if (!fout)
+ if ( !fout)
{
// MessageBox(0, "can't open file", NULL, MB_OK);
return -1;
@@ -159,161 +159,94 @@ int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, si
#pragma warning (disable: 4312)
TCHAR *GetContactName(HANDLE hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- int ret;
- char proto[200];
-
- ZeroMemory((void *) &ctInfo, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- if (szProto)
- {
- ctInfo.szProto = szProto;
- }
- else{
- GetContactProtocol(hContact, proto, sizeof(proto));
- ctInfo.szProto = proto;
- }
- ctInfo.dwFlag = CNF_DISPLAY;
-
- ctInfo.dwFlag += CNF_UNICODE;
-
+ CONTACTINFO ctInfo = { sizeof(ctInfo) };
+ ctInfo.szProto = (szProto) ? szProto : GetContactProto(hContact);
+ ctInfo.dwFlag = CNF_DISPLAY | CNF_UNICODE;
ctInfo.hContact = hContact;
//_debug_message("retrieving contact name for %d", hContact);
- ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
+ int ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
//_debug_message(" contact name %s", ctInfo.pszVal);
TCHAR *buffer;
- if (!ret)
- {
+ if ( !ret)
buffer = _tcsdup(ctInfo.pszVal);
- }
+
mir_free(ctInfo.pszVal);
if (ret)
- {
return NULL;
- }
return buffer;
}
-#pragma warning (default: 4312)
-
-#pragma warning (disable: 4312)
-void GetContactProtocol(HANDLE hContact, char *szProto, int size)
-{
- GetStringFromDatabase(hContact, "Protocol", "p", NULL, szProto, size);
-}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
TCHAR *GetContactID(HANDLE hContact)
{
- char protocol[256];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
-
- return GetContactID(hContact, protocol);
+ return GetContactID(hContact, GetContactProto(hContact));
}
TCHAR *GetContactID(HANDLE hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- int ret;
-
- ZeroMemory((void *) &ctInfo, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
+ CONTACTINFO ctInfo = { sizeof(ctInfo) };
ctInfo.szProto = szProto;
- ctInfo.dwFlag = CNF_UNIQUEID;
-
- ctInfo.dwFlag |= CNF_UNICODE;
-
+ ctInfo.dwFlag = CNF_UNIQUEID | CNF_UNICODE;
ctInfo.hContact = hContact;
- ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
+ int ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
TCHAR *buffer;
- if (!ret)
- {
- TCHAR tmp[16];
- switch (ctInfo.type)
- {
- case CNFT_BYTE:
- {
- _stprintf(tmp, _T("%d"), ctInfo.bVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_WORD:
- {
- _stprintf(tmp, _T("%d"), ctInfo.wVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_DWORD:
- {
- _stprintf(tmp, _T("%ld"), ctInfo.dVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_ASCIIZ:
- default:
- {
- buffer = _tcsdup(ctInfo.pszVal);
-
- break;
- }
- }
-
-
+ if ( !ret) {
+ TCHAR tmp[16];
+ switch (ctInfo.type) {
+ case CNFT_BYTE:
+ _stprintf(tmp, _T("%d"), ctInfo.bVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ case CNFT_WORD:
+ _stprintf(tmp, _T("%d"), ctInfo.wVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ case CNFT_DWORD:
+ _stprintf(tmp, _T("%ld"), ctInfo.dVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ default:
+ buffer = _tcsdup(ctInfo.pszVal);
+ break;
}
+ }
+
mir_free(ctInfo.pszVal);
- if (!ret)
- {
- return buffer;
- }
- else{
- return NULL;
- }
+ return (!ret) ? buffer : NULL;
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
HANDLE GetContactFromID(TCHAR *szID, char *szProto)
{
HANDLE hContact = db_find_first();
TCHAR *szHandle;
- char cProtocol[256];
int found = 0;
- while (hContact)
- {
- GetContactProtocol(hContact, cProtocol, sizeof(cProtocol));
- szHandle = GetContactID(hContact, cProtocol);
- if ((szHandle) && (_tcsicmp(szHandle, szID) == 0) && (_stricmp(szProto, cProtocol) == 0))
- {
- found = 1;
- }
- if (szHandle) free(szHandle);
-
- if (found)
- {
- break;
- }
- hContact = db_find_next(hContact);
- }
+ while (hContact) {
+ char *szProto = GetContactProto(hContact);
+ szHandle = GetContactID(hContact, szProto);
+ if (szHandle && !_tcsicmp(szHandle, szID) && !_stricmp(szProto, szProto))
+ found = 1;
+
+ if (szHandle)
+ free(szHandle);
+
+ if (found)
+ break;
+
+ hContact = db_find_next(hContact);
+ }
return hContact;
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
HANDLE GetContactFromID(TCHAR *szID, wchar_t *szProto)
{
char protocol[1024];
WideCharToMultiByte(CP_ACP, 0, szProto, -1, protocol, sizeof(protocol), NULL, NULL);
return GetContactFromID(szID, protocol);
}
-#pragma warning (default: 4312)
void ScreenToClient(HWND hWnd, LPRECT rect)
{
@@ -331,37 +264,31 @@ void ScreenToClient(HWND hWnd, LPRECT rect)
void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors)
{
- RECT rParent;
- RECT rChild;
-
if (parentPos->flags & SWP_NOSIZE)
- {
- return;
- }
+ return;
+
+ RECT rParent;
GetWindowRect(parentPos->hwnd, &rParent);
- rChild = AnchorCalcPos(window, &rParent, parentPos, anchors);
+
+ RECT rChild = AnchorCalcPos(window, &rParent, parentPos, anchors);
MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE);
}
RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors)
{
RECT rChild;
- RECT rTmp;
-
GetWindowRect(window, &rChild);
ScreenToClient(parentPos->hwnd, &rChild);
int cx = rParent->right - rParent->left;
int cy = rParent->bottom - rParent->top;
if ((cx == parentPos->cx) && (cy == parentPos->cy))
- {
- return rChild;
- }
+ return rChild;
+
if (parentPos->flags & SWP_NOSIZE)
- {
- return rChild;
- }
+ return rChild;
+ RECT rTmp;
rTmp.left = parentPos->x - rParent->left;
rTmp.right = (parentPos->x + parentPos->cx) - rParent->right;
rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom;
@@ -374,20 +301,16 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos,
rChild.bottom += cy;
//expanded the window accordingly, now we need to enforce the anchors
if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT)))
- {
- rChild.right -= cx;
- }
+ rChild.right -= cx;
+
if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM)))
- {
- rChild.bottom -= cy;
- }
+ rChild.bottom -= cy;
+
if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT)))
- {
- rChild.left += cx;
- }
+ rChild.left += cx;
+
if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP)))
- {
- rChild.top += cy;
- }
+ rChild.top += cy;
+
return rChild;
} \ No newline at end of file
diff --git a/plugins/WhenWasIt/src/utils.h b/plugins/WhenWasIt/src/utils.h
index 6d76c72d2a..6468ab63bc 100644
--- a/plugins/WhenWasIt/src/utils.h
+++ b/plugins/WhenWasIt/src/utils.h
@@ -49,6 +49,5 @@ TCHAR *GetContactID(HANDLE hContact);
TCHAR *GetContactID(HANDLE hContact, char *szProto);
HANDLE GetContactFromID(TCHAR *szID, char *szProto);
HANDLE GetContactFromID(TCHAR *szID, wchar_t *szProto);
-void GetContactProtocol(HANDLE hContact, char *szProto, int size);
#endif \ No newline at end of file