diff options
author | George Hazan <ghazan@miranda.im> | 2023-02-24 16:03:33 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-02-24 16:03:33 +0300 |
commit | 8e4a54868c87fe20c1825861d6ed3f66c5927dfa (patch) | |
tree | 389d343d7fe855fb725f900abd3ac4c1cc4565a2 /plugins/WhenWasIt/src | |
parent | 71fcd78ec9a08c7d613f57620fff155d7681d4ef (diff) |
fixes #3130 (WhenWasIt ведёт себя странно)
Diffstat (limited to 'plugins/WhenWasIt/src')
-rw-r--r-- | plugins/WhenWasIt/src/add_birthday.cpp | 6 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/date_utils.cpp | 22 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/date_utils.h | 3 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/dlg_handlers.cpp | 264 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/dlg_handlers.h | 18 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/hooked_events.cpp | 9 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/notifiers.cpp | 198 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/services.cpp | 149 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/services.h | 6 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/version.h | 2 |
10 files changed, 328 insertions, 349 deletions
diff --git a/plugins/WhenWasIt/src/add_birthday.cpp b/plugins/WhenWasIt/src/add_birthday.cpp index 802da3df80..455132e47d 100644 --- a/plugins/WhenWasIt/src/add_birthday.cpp +++ b/plugins/WhenWasIt/src/add_birthday.cpp @@ -94,8 +94,12 @@ public: } }; -INT_PTR AddBirthdayService(WPARAM hContact, LPARAM) +INT_PTR AddBirthdayService(WPARAM hContact, LPARAM bAsIs) { + // if called from the contacts' popup menu, always edit custom birthday in UserInfo module + if (!bAsIs) + hContact = -hContact; + HWND hWnd = WindowList_Find(hAddBirthdayWndsList, hContact); if (!hWnd) (new CAddBirthdayDlg(hContact))->Show(); diff --git a/plugins/WhenWasIt/src/date_utils.cpp b/plugins/WhenWasIt/src/date_utils.cpp index 179d9174f1..5ae9d36a07 100644 --- a/plugins/WhenWasIt/src/date_utils.cpp +++ b/plugins/WhenWasIt/src/date_utils.cpp @@ -33,17 +33,12 @@ bool IsDOBValid(int, int month, int day) return (month != 0 && day != 0);
}
-const char* GetModule(MCONTACT hContact, int mode)
-{
- return (mode == DOB_PROTOCOL) ? Proto_GetBaseAccountName(hContact) : "UserInfo";
-}
-
int GetContactDOB(MCONTACT hContact, int &year, int &month, int &day, int iModule)
{
if (iModule != DOB_PROTOCOL) {
- year = db_get_w(hContact, "UserInfo", "BirthYear", 0);
- month = db_get_b(hContact, "UserInfo", "BirthMonth", 0);
- day = db_get_b(hContact, "UserInfo", "BirthDay", 0);
+ year = db_get_w(hContact, "UserInfo", "BirthYear");
+ month = db_get_b(hContact, "UserInfo", "BirthMonth");
+ day = db_get_b(hContact, "UserInfo", "BirthDay");
if (IsDOBValid(year, month, day))
return DOB_USERINFO;
if (iModule == DOB_USERINFO)
@@ -51,9 +46,9 @@ int GetContactDOB(MCONTACT hContact, int &year, int &month, int &day, int iModul }
char *szProto = Proto_GetBaseAccountName(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);
+ year = db_get_w(hContact, szProto, "BirthYear");
+ month = db_get_b(hContact, szProto, "BirthMonth");
+ day = db_get_b(hContact, szProto, "BirthDay");
if (IsDOBValid(year, month, day))
return DOB_PROTOCOL;
@@ -178,9 +173,12 @@ void DeleteBirthday(MCONTACT hContact) void SaveBirthday(MCONTACT hContact, int year, int month, int day, int mode)
{
- auto *szModule = GetModule(hContact, mode);
+ auto *szModule = (mode == DOB_PROTOCOL) ? Proto_GetBaseAccountName(hContact) : "UserInfo";
db_set_dw(hContact, szModule, "BirthYear", year);
db_set_b(hContact, szModule, "BirthMonth", month);
db_set_b(hContact, szModule, "BirthDay", day);
+
+ int age = GetContactAge(year, month, day);
+ db_set_b(hContact, szModule, "Age", age);
}
diff --git a/plugins/WhenWasIt/src/date_utils.h b/plugins/WhenWasIt/src/date_utils.h index 9eb72e6ff8..3809b7a22d 100644 --- a/plugins/WhenWasIt/src/date_utils.h +++ b/plugins/WhenWasIt/src/date_utils.h @@ -42,6 +42,7 @@ int GetContactAge(int year, int month, int day); void SaveBirthday(MCONTACT hContact, int year, int month, int day, int mode);
void DeleteBirthday(MCONTACT hContact);
-const char *GetModule(MCONTACT hContact, int mode);
+wchar_t *BuildDTBText(int dtb, wchar_t *name, wchar_t *text, int size);
+wchar_t *BuildDABText(int dab, wchar_t *name, wchar_t *text, int size);
#endif //H_WWI_DATE_UTILS_H
\ No newline at end of file diff --git a/plugins/WhenWasIt/src/dlg_handlers.cpp b/plugins/WhenWasIt/src/dlg_handlers.cpp index ce856c2f75..9089bd83a4 100644 --- a/plugins/WhenWasIt/src/dlg_handlers.cpp +++ b/plugins/WhenWasIt/src/dlg_handlers.cpp @@ -71,56 +71,62 @@ int CALLBACK BirthdaysCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam) /////////////////////////////////////////////////////////////////////////////////////////
// Basic list dialog
-CBasicListDlg::CBasicListDlg(int dlgId) :
- CDlgBase(g_plugin, dlgId),
- m_list(this, IDC_BIRTHDAYS_LIST)
+class CBasicListDlg : public CDlgBase
{
- m_list.OnDoubleClick = Callback(this, &CBasicListDlg::onDblClick_List);
- m_list.OnBuildMenu = Callback(this, &CBasicListDlg::onMenu_List);
-}
+ MCONTACT SelectedItem()
+ {
+ int count = m_list.GetItemCount();
+
+ LVITEM item = {};
+ item.mask = LVIF_PARAM;
+ for (int i = 0; i < count; i++) {
+ if (m_list.GetItemState(i, LVIS_SELECTED)) {
+ item.iItem = i;
+ m_list.GetItem(&item);
+
+ int res = item.lParam;
+ return (res < 0) ? -res : res;
+ }
+ }
+ return 0;
+ }
-MCONTACT CBasicListDlg::SelectedItem()
-{
- int count = m_list.GetItemCount();
+protected:
+ CCtrlListView m_list;
- LVITEM item = {};
- item.mask = LVIF_PARAM;
- for (int i = 0; i < count; i++) {
- if (m_list.GetItemState(i, LVIS_SELECTED)) {
- item.iItem = i;
- m_list.GetItem(&item);
+ CBasicListDlg(int dlgId) :
+ CDlgBase(g_plugin, dlgId),
+ m_list(this, IDC_BIRTHDAYS_LIST)
+ {
+ m_list.OnDoubleClick = Callback(this, &CBasicListDlg::onDblClick_List);
+ m_list.OnBuildMenu = Callback(this, &CBasicListDlg::onMenu_List);
+ }
- int res = item.lParam;
- return (res < 0) ? -res : res;
- }
+ void Sort(int iCol)
+ {
+ BirthdaysSortParams params = {};
+ params.hList = m_list.GetHwnd();
+ params.column = iCol;
+ m_list.SortItemsEx(BirthdaysCompare, (LPARAM)¶ms);
}
- return 0;
-}
-void CBasicListDlg::onDblClick_List(CCtrlListView::TEventInfo*)
-{
- if (MCONTACT hContact = SelectedItem())
- CallService(MS_WWI_ADD_BIRTHDAY, hContact, 0);
-}
+ void onDblClick_List(CCtrlListView::TEventInfo *)
+ {
+ if (MCONTACT hContact = SelectedItem())
+ AddBirthdayService(hContact, TRUE);
+ }
-void CBasicListDlg::onMenu_List(CContextMenuPos *pos)
-{
- if (MCONTACT hContact = SelectedItem()) {
- HMENU hMenu = Menu_BuildContactMenu(hContact);
- if (hMenu != nullptr) {
- Clist_MenuProcessCommand(TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pos->pt.x, pos->pt.y, 0, m_list.GetHwnd(), nullptr), MPCF_CONTACTMENU, hContact);
- DestroyMenu(hMenu);
+ void onMenu_List(CContextMenuPos *pos)
+ {
+ if (MCONTACT hContact = SelectedItem()) {
+ HMENU hMenu = Menu_BuildContactMenu(hContact);
+ if (hMenu != nullptr) {
+ Clist_MenuProcessCommand(TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pos->pt.x, pos->pt.y, 0, m_list.GetHwnd(), nullptr), MPCF_CONTACTMENU, hContact);
+ DestroyMenu(hMenu);
+ }
}
}
-}
-
-void CBasicListDlg::Sort(int iCol)
-{
- BirthdaysSortParams params = {};
- params.hList = m_list.GetHwnd();
- params.column = iCol;
- m_list.SortItemsEx(BirthdaysCompare, (LPARAM)¶ms);
-}
+};
/////////////////////////////////////////////////////////////////////////////////////////
// Birthday list dialog
@@ -165,16 +171,15 @@ class CBirthdaysDlg : public CBasicListDlg PROTOACCOUNT *pAcc = Proto_GetAccount(szProto);
wchar_t *ptszAccName = (pAcc == nullptr) ? TranslateT("Unknown") : pAcc->tszAccountName;
- LVITEM item = { 0 };
- item.mask = LVIF_TEXT | LVIF_PARAM;
- item.iItem = entry;
- item.lParam = (iModule == DOB_PROTOCOL) ? hContact : -hContact;
- item.pszText = ptszAccName;
-
- if (bAdd)
+ if (bAdd) {
+ LVITEM item = {};
+ item.mask = LVIF_TEXT | LVIF_PARAM;
+ item.iItem = entry;
+ item.lParam = (iModule == DOB_PROTOCOL) ? hContact : -hContact;
+ item.pszText = ptszAccName;
m_list.InsertItem(&item);
- else
- m_list.SetItemText(entry, 0, ptszAccName);
+ }
+ else m_list.SetItemText(entry, 0, ptszAccName);
m_list.SetItemText(entry, 1, Clist_GetContactDisplayName(hContact));
@@ -254,7 +259,7 @@ public: m_list.InsertColumn(5, &col);
LoadBirthdays();
- int column = g_plugin.getByte("SortColumn", 0);
+ int column = g_plugin.getByte("SortColumn");
Sort(column);
Utils_RestoreWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayList");
@@ -323,7 +328,7 @@ INT_PTR ShowListService(WPARAM, LPARAM) if (!g_pDialog)
(new CBirthdaysDlg())->Show();
else
- ShowWindow(g_pDialog->GetHwnd(), SW_SHOW);
+ g_pDialog->Show();
return 0;
}
@@ -340,41 +345,148 @@ void CloseBirthdayList() }
/////////////////////////////////////////////////////////////////////////////////////////
-// Popups
-int HandlePopupClick(HWND hWnd, int action)
+static class CUpcomingDlg *g_pUpcomingDlg = nullptr;
+
+class CUpcomingDlg : public CBasicListDlg
{
- MCONTACT hContact;
+ int timeout;
+
+ CTimer m_timer;
+
+public:
+ CUpcomingDlg() :
+ CBasicListDlg(IDD_UPCOMING),
+ m_timer(this, 1002)
+ {
+ SetMinSize(400, 160);
+
+ m_timer.OnEvent = Callback(this, &CUpcomingDlg::onTimer);
+ }
+
+ bool OnInitDialog() override
+ {
+ Window_SetIcon_IcoLib(m_hwnd, hListMenu);
+
+ g_pUpcomingDlg = this;
+ timeout = g_plugin.cDlgTimeout;
+
+ m_list.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
+
+ LVCOLUMN col;
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.pszText = TranslateT("Contact");
+ col.cx = 300;
+ m_list.InsertColumn(0, &col);
+
+ col.pszText = TranslateT("Age");
+ col.cx = 45;
+ m_list.InsertColumn(1, &col);
+
+ col.pszText = TranslateT("DTB");
+ col.cx = 45;
+ m_list.InsertColumn(2, &col);
+
+ m_list.SetColumnWidth(0, LVSCW_AUTOSIZE);
+
+ if (timeout > 0)
+ m_timer.Start(1000);
+
+ Utils_RestoreWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ g_pUpcomingDlg = nullptr;
+ Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
+ Window_FreeIcon_IcoLib(m_hwnd);
+ m_timer.Stop();
+ }
- switch (action) {
- case 2: //OPEN MESSAGE WINDOW
- hContact = (MCONTACT)PUGetContact(hWnd);
- if (hContact)
- CallServiceSync(MS_MSG_SENDMESSAGE, hContact, 0);
+ void OnResize() override
+ {
+ RECT rcWin;
+ GetWindowRect(m_hwnd, &rcWin);
+
+ int cx = rcWin.right - rcWin.left;
+ int cy = rcWin.bottom - rcWin.top;
+ SetWindowPos(m_list.GetHwnd(), nullptr, 0, 0, (cx - 30), (cy - 80), (SWP_NOZORDER | SWP_NOMOVE));
+
+ m_list.SetColumnWidth(0, (cx - 150));
+ SetWindowPos(GetDlgItem(m_hwnd, IDOK), nullptr, ((cx / 2) - 95), (cy - 67), 0, 0, SWP_NOSIZE);
+ RedrawWindow(m_hwnd, nullptr, nullptr, (RDW_FRAME | RDW_INVALIDATE));
+ }
+
+ void onTimer(CTimer *)
+ {
+ const int MAX_SIZE = 512;
+ wchar_t buffer[MAX_SIZE];
+ timeout--;
+ mir_snwprintf(buffer, (timeout != 2) ? TranslateT("Closing in %d seconds") : TranslateT("Closing in %d second"), timeout);
+ SetDlgItemText(m_hwnd, IDOK, buffer);
+
+ if (timeout <= 0)
+ Close();
+ }
+
+ void AddBirthDay(MCONTACT hContact, wchar_t *message, int dtb, int age)
+ {
+ LVFINDINFO fi = { 0 };
+ fi.flags = LVFI_PARAM;
+ fi.lParam = (LPARAM)hContact;
+ if (-1 != m_list.FindItem(-1, &fi))
+ return; /* Allready in list. */
+
+ int index = m_list.GetItemCount();
+ LVITEM item = { 0 };
+ item.iItem = index;
+ item.mask = LVIF_PARAM | LVIF_TEXT;
+ item.lParam = (LPARAM)hContact;
+ item.pszText = message;
+ m_list.InsertItem(&item);
+
+ wchar_t buffer[512];
+ mir_snwprintf(buffer, L"%d", age);
+ m_list.SetItemText(index, 1, buffer);
+
+ mir_snwprintf(buffer, L"%d", dtb);
+ m_list.SetItemText(index, 2, buffer);
+
+ Sort(2);
+ }
+};
+
+int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age)
+{
+ wchar_t text[1024];
+ BuildDTBText(dtb, Clist_GetContactDisplayName(hContact), text, _countof(text));
- case 1: //DISMISS
- PUDeletePopup(hWnd);
- break;
+ if (!g_pUpcomingDlg) {
+ g_pUpcomingDlg = new CUpcomingDlg();
+ g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
+ g_pUpcomingDlg->AddBirthDay(hContact, text, dtb, age);
return 0;
}
-LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+int DialogNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
- switch (msg) {
- case WM_COMMAND:
- switch (HIWORD(wParam)) {
- case STN_CLICKED:
- HandlePopupClick(hWnd, g_plugin.lPopupClick);
- break;
- }
- break;
+ wchar_t text[1024];
+ BuildDABText(dab, Clist_GetContactDisplayName(hContact), text, _countof(text));
- case WM_CONTEXTMENU:
- HandlePopupClick(hWnd, g_plugin.rPopupClick);
- break;
+ if (!g_pUpcomingDlg) {
+ g_pUpcomingDlg = new CUpcomingDlg();
+ g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
- return DefWindowProc(hWnd, msg, wParam, lParam);
+ g_pUpcomingDlg->AddBirthDay(hContact, text, -dab, age);
+ return 0;
+}
+
+void CloseUpcoming()
+{
+ if (g_pUpcomingDlg)
+ g_pUpcomingDlg->Close();
}
diff --git a/plugins/WhenWasIt/src/dlg_handlers.h b/plugins/WhenWasIt/src/dlg_handlers.h index d9678427c1..1a59891968 100644 --- a/plugins/WhenWasIt/src/dlg_handlers.h +++ b/plugins/WhenWasIt/src/dlg_handlers.h @@ -37,22 +37,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int OnOptionsInitialise(WPARAM wParam, LPARAM);
-class CBasicListDlg : public CDlgBase
-{
- MCONTACT SelectedItem();
-
-protected:
- CCtrlListView m_list;
-
- CBasicListDlg(int dlgId);
-
- void Sort(int iCol);
-
- void onDblClick_List(CCtrlListView::TEventInfo*);
- void onMenu_List(CContextMenuPos *pos);
-};
-
-INT_PTR CALLBACK DlgProcUpcoming(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
#endif //M_WWI_DIALOG_HANDLERS_H
\ No newline at end of file diff --git a/plugins/WhenWasIt/src/hooked_events.cpp b/plugins/WhenWasIt/src/hooked_events.cpp index e356854b44..1f4d822080 100644 --- a/plugins/WhenWasIt/src/hooked_events.cpp +++ b/plugins/WhenWasIt/src/hooked_events.cpp @@ -92,7 +92,7 @@ int RefreshContactListIcons(MCONTACT hContact) return 0;
bool hidden = Contact::IsHidden(hContact);
- int ignored = db_get_dw(hContact, "Ignore", "Mask1", 0);
+ int ignored = db_get_dw(hContact, "Ignore", "Mask1");
ignored = ((ignored & 0x3f) != 0) ? 1 : 0;
int ok = 1;
if (g_plugin.notifyFor & EXCLUDE_HIDDEN)
@@ -107,11 +107,7 @@ int RefreshContactListIcons(MCONTACT hContact) int dab = NotifyMissedContactBirthday(hContact, today, g_plugin.daysAfter);
if (ok && (dtb >= 0 || dab > 0)) {
- int year, month, day;
- int mode = GetContactDOB(hContact, year, month, day);
- int age = GetContactAge(year, month, day);
- db_set_b(hContact, GetModule(hContact, mode), "Age", age);
-
+ int age = GetContactAge(hContact);
if (bShouldCheckBirthdays && g_plugin.bUsePopups) {
if (dtb >= 0) {
bBirthdayFound = 1; //only set it if we're called from our CheckBirthdays service
@@ -177,4 +173,3 @@ VOID CALLBACK OnDateChangeTimer(HWND, UINT, UINT_PTR, DWORD) currentDay = now.wDay;
}
-
diff --git a/plugins/WhenWasIt/src/notifiers.cpp b/plugins/WhenWasIt/src/notifiers.cpp index deb357fcf2..3ca8ad1849 100644 --- a/plugins/WhenWasIt/src/notifiers.cpp +++ b/plugins/WhenWasIt/src/notifiers.cpp @@ -20,6 +20,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
+/////////////////////////////////////////////////////////////////////////////////////////
+// Popups
+
+static int HandlePopupClick(HWND hWnd, int action)
+{
+ MCONTACT hContact;
+
+ switch (action) {
+ case 2: //OPEN MESSAGE WINDOW
+ hContact = (MCONTACT)PUGetContact(hWnd);
+ if (hContact)
+ CallServiceSync(MS_MSG_SENDMESSAGE, hContact, 0);
+
+ case 1: //DISMISS
+ PUDeletePopup(hWnd);
+ break;
+ }
+
+ return 0;
+}
+
+static LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_COMMAND:
+ switch (HIWORD(wParam)) {
+ case STN_CLICKED:
+ HandlePopupClick(hWnd, g_plugin.lPopupClick);
+ break;
+ }
+ break;
+
+ case WM_CONTEXTMENU:
+ HandlePopupClick(hWnd, g_plugin.rPopupClick);
+ break;
+ }
+
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+}
+
void FillPopupData(POPUPDATAW &ppd, int dtb)
{
int popupTimeout = (dtb == 0) ? g_plugin.popupTimeoutToday : g_plugin.popupTimeout;
@@ -40,7 +80,7 @@ void PopupNotifyNoBirthdays() PUAddPopupW(&ppd);
}
-wchar_t *BuildDTBText(int dtb, wchar_t *name, wchar_t *text, int size)
+wchar_t* BuildDTBText(int dtb, wchar_t *name, wchar_t *text, int size)
{
if (dtb > 1)
mir_snwprintf(text, size, TranslateT("%s has birthday in %d days."), name, dtb);
@@ -52,7 +92,7 @@ wchar_t *BuildDTBText(int dtb, wchar_t *name, wchar_t *text, int size) return text;
}
-wchar_t *BuildDABText(int dab, wchar_t *name, wchar_t *text, int size)
+wchar_t* BuildDABText(int dab, wchar_t *name, wchar_t *text, int size)
{
if (dab > 1)
mir_snwprintf(text, size, TranslateT("%s had birthday %d days ago."), name, dab);
@@ -94,17 +134,16 @@ int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age) sex = TranslateT("He/She");
break;
}
+
if (age > 0) {
if (dtb > 0)
- mir_snwprintf(ppd.lpwzText, MAX_SECONDLINE, TranslateT("%s\n%s will be %d years old."), text, sex, age);
+ mir_snwprintf(ppd.lpwzText, TranslateT("%s\n%s will be %d years old."), text, sex, age);
else
- mir_snwprintf(ppd.lpwzText, MAX_SECONDLINE, TranslateT("%s\n%s just turned %d."), text, sex, age);
+ mir_snwprintf(ppd.lpwzText, TranslateT("%s\n%s just turned %d."), text, sex, age);
}
- else
- mir_wstrncpy(ppd.lpwzText, text, MAX_SECONDLINE - 1);
+ else mir_wstrncpy(ppd.lpwzText, text, MAX_SECONDLINE - 1);
PUAddPopupW(&ppd);
-
return 0;
}
@@ -149,151 +188,6 @@ int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age) /////////////////////////////////////////////////////////////////////////////////////////
-static class CUpcomingDlg *g_pUpcomingDlg = nullptr;
-
-class CUpcomingDlg : public CBasicListDlg
-{
- int timeout;
-
- CTimer m_timer;
-
-public:
- CUpcomingDlg() :
- CBasicListDlg(IDD_UPCOMING),
- m_timer(this, 1002)
- {
- SetMinSize(400, 160);
-
- m_timer.OnEvent = Callback(this, &CUpcomingDlg::onTimer);
- }
-
- bool OnInitDialog() override
- {
- Window_SetIcon_IcoLib(m_hwnd, hListMenu);
-
- g_pUpcomingDlg = this;
- timeout = g_plugin.cDlgTimeout;
-
- m_list.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
-
- LVCOLUMN col;
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.pszText = TranslateT("Contact");
- col.cx = 300;
- m_list.InsertColumn(0, &col);
-
- col.pszText = TranslateT("Age");
- col.cx = 45;
- m_list.InsertColumn(1, &col);
-
- col.pszText = TranslateT("DTB");
- col.cx = 45;
- m_list.InsertColumn(2, &col);
-
- m_list.SetColumnWidth(0, LVSCW_AUTOSIZE);
-
- if (timeout > 0)
- m_timer.Start(1000);
-
- Utils_RestoreWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
- return true;
- }
-
- void OnDestroy() override
- {
- g_pUpcomingDlg = nullptr;
- Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
- Window_FreeIcon_IcoLib(m_hwnd);
- m_timer.Stop();
- }
-
- void OnResize() override
- {
- RECT rcWin;
- GetWindowRect(m_hwnd, &rcWin);
-
- int cx = rcWin.right - rcWin.left;
- int cy = rcWin.bottom - rcWin.top;
- SetWindowPos(m_list.GetHwnd(), nullptr, 0, 0, (cx - 30), (cy - 80), (SWP_NOZORDER | SWP_NOMOVE));
-
- m_list.SetColumnWidth(0, (cx - 150));
- SetWindowPos(GetDlgItem(m_hwnd, IDOK), nullptr, ((cx / 2) - 95), (cy - 67), 0, 0, SWP_NOSIZE);
- RedrawWindow(m_hwnd, nullptr, nullptr, (RDW_FRAME | RDW_INVALIDATE));
- }
-
- void onTimer(CTimer *)
- {
- const int MAX_SIZE = 512;
- wchar_t buffer[MAX_SIZE];
- timeout--;
- mir_snwprintf(buffer, (timeout != 2) ? TranslateT("Closing in %d seconds") : TranslateT("Closing in %d second"), timeout);
- SetDlgItemText(m_hwnd, IDOK, buffer);
-
- if (timeout <= 0)
- Close();
- }
-
- void AddBirthDay(MCONTACT hContact, wchar_t *message, int dtb, int age)
- {
- LVFINDINFO fi = { 0 };
- fi.flags = LVFI_PARAM;
- fi.lParam = (LPARAM)hContact;
- if (-1 != m_list.FindItem(-1, &fi))
- return; /* Allready in list. */
-
- int index = m_list.GetItemCount();
- LVITEM item = { 0 };
- item.iItem = index;
- item.mask = LVIF_PARAM | LVIF_TEXT;
- item.lParam = (LPARAM)hContact;
- item.pszText = message;
- m_list.InsertItem(&item);
-
- wchar_t buffer[512];
- mir_snwprintf(buffer, L"%d", age);
- m_list.SetItemText(index, 1, buffer);
-
- mir_snwprintf(buffer, L"%d", dtb);
- m_list.SetItemText(index, 2, buffer);
-
- Sort(2);
- }
-};
-
-int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age)
-{
- wchar_t text[1024];
- BuildDTBText(dtb, Clist_GetContactDisplayName(hContact), text, _countof(text));
-
- if (!g_pUpcomingDlg) {
- g_pUpcomingDlg = new CUpcomingDlg();
- g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
- }
-
- g_pUpcomingDlg->AddBirthDay(hContact, text, dtb, age);
- return 0;
-}
-
-int DialogNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
-{
- wchar_t text[1024];
- BuildDABText(dab, Clist_GetContactDisplayName(hContact), text, _countof(text));
-
- if (!g_pUpcomingDlg) {
- g_pUpcomingDlg = new CUpcomingDlg();
- g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
- }
-
- g_pUpcomingDlg->AddBirthDay(hContact, text, -dab, age);
- return 0;
-}
-
-void CloseUpcoming()
-{
- if (g_pUpcomingDlg)
- g_pUpcomingDlg->Close();
-}
-
int SoundNotifyBirthday(int dtb)
{
if (dtb == 0)
diff --git a/plugins/WhenWasIt/src/services.cpp b/plugins/WhenWasIt/src/services.cpp index d3cea83f54..7ea3973d82 100644 --- a/plugins/WhenWasIt/src/services.cpp +++ b/plugins/WhenWasIt/src/services.cpp @@ -25,21 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int bShouldCheckBirthdays = 0;
int bBirthdayFound = 0;
-int InitServices()
-{
- Log("%s", "Entering function " __FUNCTION__);
-
- CreateServiceFunction(MS_WWI_CHECK_BIRTHDAYS, CheckBirthdaysService);
- CreateServiceFunction(MS_WWI_LIST_SHOW, ShowListService);
- CreateServiceFunction(MS_WWI_ADD_BIRTHDAY, AddBirthdayService);
- CreateServiceFunction(MS_WWI_REFRESH_USERDETAILS, RefreshUserDetailsService);
- CreateServiceFunction(MS_WWI_IMPORT_BIRTHDAYS, ImportBirthdaysService);
- CreateServiceFunction(MS_WWI_EXPORT_BIRTHDAYS, ExportBirthdaysService);
-
- Log("%s", "Leaving function " __FUNCTION__);
- return 0;
-}
-
/*
returns -1 if notify is not necesarry
returns daysToBirthday if it should notify
@@ -83,7 +68,7 @@ INT_PTR CheckBirthdaysService(WPARAM, LPARAM lParam) SYSTEMTIME today;
GetLocalTime(&today);
- uint32_t lastChecked = g_plugin.getDword("LastChecked", 0); //get last checked date
+ uint32_t lastChecked = g_plugin.getDword("LastChecked"); //get last checked date
int lcDay = LOBYTE(LOWORD(lastChecked));
int lcMonth = HIBYTE(LOWORD(lastChecked));
int lcYear = HIWORD(lastChecked);
@@ -146,7 +131,7 @@ void __cdecl RefreshUserDetailsWorkerThread(void*) ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done refreshing user details"), hRefreshUserDetails);
}
-INT_PTR RefreshUserDetailsService(WPARAM, LPARAM)
+static INT_PTR RefreshUserDetailsService(WPARAM, LPARAM)
{
mir_forkthread(RefreshUserDetailsWorkerThread);
return 0;
@@ -155,63 +140,7 @@ INT_PTR RefreshUserDetailsService(WPARAM, LPARAM) /////////////////////////////////////////////////////////////////////////////////////////
// Birthdays import
-INT_PTR ImportBirthdaysService(WPARAM, LPARAM)
-{
- wchar_t fileName[1024] = { 0 };
- OPENFILENAME of = { 0 };
- of.lStructSize = sizeof(OPENFILENAME);
- //of.g_plugin.getInst() = g_plugin.getInst();
- wchar_t filter[MAX_PATH];
- mir_snwprintf(filter, L"%s (*" BIRTHDAY_EXTENSION L")%c*" BIRTHDAY_EXTENSION L"%c", TranslateT("Birthdays files"), 0, 0);
- of.lpstrFilter = filter;
- of.lpstrFile = fileName;
- of.nMaxFile = _countof(fileName);
- of.lpstrTitle = TranslateT("Please select a file to import birthdays from...");
- of.Flags = OFN_FILEMUSTEXIST;
-
- if (GetOpenFileName(&of)) {
- wchar_t buffer[2048];
- mir_snwprintf(buffer, TranslateT("Importing birthdays from file: %s"), fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hImportBirthdays);
- DoImport(fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done importing birthdays"), hImportBirthdays);
- }
-
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Birthdays export
-
-INT_PTR ExportBirthdaysService(WPARAM, LPARAM)
-{
- wchar_t fileName[1024] = { 0 };
- OPENFILENAME of = { 0 };
- of.lStructSize = sizeof(OPENFILENAME);
- //of.g_plugin.getInst() = g_plugin.getInst();
- wchar_t filter[MAX_PATH];
- mir_snwprintf(filter, L"%s (*" BIRTHDAY_EXTENSION L")%c*" BIRTHDAY_EXTENSION L"%c%s (*.*)%c*.*%c", TranslateT("Birthdays files"), 0, 0, TranslateT("All Files"), 0, 0);
- of.lpstrFilter = filter;
- of.lpstrFile = fileName;
- of.nMaxFile = _countof(fileName);
- of.lpstrTitle = TranslateT("Please select a file to export birthdays to...");
-
- if (GetSaveFileName(&of)) {
- wchar_t buffer[2048];
- wchar_t *fn = wcsrchr(fileName, '\\') + 1;
- if (!wcschr(fn, '.'))
- mir_wstrcat(fileName, BIRTHDAY_EXTENSION);
-
- mir_snwprintf(buffer, TranslateT("Exporting birthdays to file: %s"), fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hExportBirthdays);
- DoExport(fileName);
- ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done exporting birthdays"), hExportBirthdays);
- }
-
- return 0;
-}
-
-int DoImport(wchar_t *fileName)
+static int DoImport(wchar_t *fileName)
{
FILE *fin = _wfopen(fileName, L"rt");
if (!fin) {
@@ -256,7 +185,35 @@ int DoImport(wchar_t *fileName) return 0;
}
-int DoExport(wchar_t *fileName)
+static INT_PTR ImportBirthdaysService(WPARAM, LPARAM)
+{
+ wchar_t fileName[1024] = { 0 };
+ OPENFILENAME of = { 0 };
+ of.lStructSize = sizeof(OPENFILENAME);
+ //of.g_plugin.getInst() = g_plugin.getInst();
+ wchar_t filter[MAX_PATH];
+ mir_snwprintf(filter, L"%s (*" BIRTHDAY_EXTENSION L")%c*" BIRTHDAY_EXTENSION L"%c", TranslateT("Birthdays files"), 0, 0);
+ of.lpstrFilter = filter;
+ of.lpstrFile = fileName;
+ of.nMaxFile = _countof(fileName);
+ of.lpstrTitle = TranslateT("Please select a file to import birthdays from...");
+ of.Flags = OFN_FILEMUSTEXIST;
+
+ if (GetOpenFileName(&of)) {
+ wchar_t buffer[2048];
+ mir_snwprintf(buffer, TranslateT("Importing birthdays from file: %s"), fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hImportBirthdays);
+ DoImport(fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done importing birthdays"), hImportBirthdays);
+ }
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Birthdays export
+
+static int DoExport(wchar_t *fileName)
{
FILE *fout = _wfopen(fileName, L"wt");
if (!fout) {
@@ -284,3 +241,45 @@ int DoExport(wchar_t *fileName) fclose(fout);
return 0;
}
+
+static INT_PTR ExportBirthdaysService(WPARAM, LPARAM)
+{
+ wchar_t fileName[1024] = { 0 };
+ OPENFILENAME of = { 0 };
+ of.lStructSize = sizeof(OPENFILENAME);
+ //of.g_plugin.getInst() = g_plugin.getInst();
+ wchar_t filter[MAX_PATH];
+ mir_snwprintf(filter, L"%s (*" BIRTHDAY_EXTENSION L")%c*" BIRTHDAY_EXTENSION L"%c%s (*.*)%c*.*%c", TranslateT("Birthdays files"), 0, 0, TranslateT("All Files"), 0, 0);
+ of.lpstrFilter = filter;
+ of.lpstrFile = fileName;
+ of.nMaxFile = _countof(fileName);
+ of.lpstrTitle = TranslateT("Please select a file to export birthdays to...");
+
+ if (GetSaveFileName(&of)) {
+ wchar_t buffer[2048];
+ wchar_t *fn = wcsrchr(fileName, '\\') + 1;
+ if (!wcschr(fn, '.'))
+ mir_wstrcat(fileName, BIRTHDAY_EXTENSION);
+
+ mir_snwprintf(buffer, TranslateT("Exporting birthdays to file: %s"), fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), buffer, hExportBirthdays);
+ DoExport(fileName);
+ ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done exporting birthdays"), hExportBirthdays);
+ }
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// module entry point
+
+int InitServices()
+{
+ CreateServiceFunction(MS_WWI_CHECK_BIRTHDAYS, CheckBirthdaysService);
+ CreateServiceFunction(MS_WWI_LIST_SHOW, ShowListService);
+ CreateServiceFunction(MS_WWI_ADD_BIRTHDAY, AddBirthdayService);
+ CreateServiceFunction(MS_WWI_REFRESH_USERDETAILS, RefreshUserDetailsService);
+ CreateServiceFunction(MS_WWI_IMPORT_BIRTHDAYS, ImportBirthdaysService);
+ CreateServiceFunction(MS_WWI_EXPORT_BIRTHDAYS, ExportBirthdaysService);
+ return 0;
+}
diff --git a/plugins/WhenWasIt/src/services.h b/plugins/WhenWasIt/src/services.h index 105bec9973..1cf092ac4b 100644 --- a/plugins/WhenWasIt/src/services.h +++ b/plugins/WhenWasIt/src/services.h @@ -40,14 +40,8 @@ int InitServices(); int NotifyContactBirthday(MCONTACT hContact, time_t now, int daysInAdvance);
int NotifyMissedContactBirthday(MCONTACT hContact, time_t now, int daysAfter);
-int DoExport(wchar_t *fileName);
-int DoImport(wchar_t *fileName);
-
INT_PTR CheckBirthdaysService(WPARAM wParam, LPARAM lParam);
INT_PTR ShowListService(WPARAM wParam, LPARAM lParam);
INT_PTR AddBirthdayService(WPARAM wParam, LPARAM lParam);
-INT_PTR RefreshUserDetailsService(WPARAM wParam, LPARAM lParam);
-INT_PTR ImportBirthdaysService(WPARAM wParam, LPARAM lParam);
-INT_PTR ExportBirthdaysService(WPARAM wParam, LPARAM lParam);
#endif //M_EXCHANGE_SERVICES_H
\ No newline at end of file diff --git a/plugins/WhenWasIt/src/version.h b/plugins/WhenWasIt/src/version.h index 9ffd0afdd1..e803e94b21 100644 --- a/plugins/WhenWasIt/src/version.h +++ b/plugins/WhenWasIt/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 4
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|