summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/WhenWasIt/WhenWasIt.vcxproj1
-rw-r--r--plugins/WhenWasIt/WhenWasIt.vcxproj.filters3
-rw-r--r--plugins/WhenWasIt/res/WhenWasIt.rc4
-rw-r--r--plugins/WhenWasIt/src/WhenWasIt.cpp10
-rw-r--r--plugins/WhenWasIt/src/add_birthday.cpp140
-rw-r--r--plugins/WhenWasIt/src/dlg_handlers.cpp711
-rw-r--r--plugins/WhenWasIt/src/dlg_handlers.h15
-rw-r--r--plugins/WhenWasIt/src/hooked_events.cpp16
-rw-r--r--plugins/WhenWasIt/src/notifiers.cpp159
-rw-r--r--plugins/WhenWasIt/src/notifiers.h10
-rw-r--r--plugins/WhenWasIt/src/resource.h1
-rw-r--r--plugins/WhenWasIt/src/services.cpp25
-rw-r--r--plugins/WhenWasIt/src/stdafx.h1
-rw-r--r--plugins/WhenWasIt/src/utils.cpp4
-rw-r--r--plugins/WhenWasIt/src/utils.h2
-rw-r--r--plugins/WhenWasIt/src/version.h6
16 files changed, 540 insertions, 568 deletions
diff --git a/plugins/WhenWasIt/WhenWasIt.vcxproj b/plugins/WhenWasIt/WhenWasIt.vcxproj
index ddab7f13e5..f0a5b19ae9 100644
--- a/plugins/WhenWasIt/WhenWasIt.vcxproj
+++ b/plugins/WhenWasIt/WhenWasIt.vcxproj
@@ -26,6 +26,7 @@
<Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
<ItemGroup>
+ <ClCompile Include="src\add_birthday.cpp" />
<ClCompile Include="src\birthdays.cpp" />
<ClCompile Include="src\date_utils.cpp" />
<ClCompile Include="src\dlg_handlers.cpp" />
diff --git a/plugins/WhenWasIt/WhenWasIt.vcxproj.filters b/plugins/WhenWasIt/WhenWasIt.vcxproj.filters
index 432ff774d0..c873dba007 100644
--- a/plugins/WhenWasIt/WhenWasIt.vcxproj.filters
+++ b/plugins/WhenWasIt/WhenWasIt.vcxproj.filters
@@ -38,6 +38,9 @@
<ClCompile Include="src\options.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\add_birthday.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\birthdays.h">
diff --git a/plugins/WhenWasIt/res/WhenWasIt.rc b/plugins/WhenWasIt/res/WhenWasIt.rc
index 061c855767..c8499b6003 100644
--- a/plugins/WhenWasIt/res/WhenWasIt.rc
+++ b/plugins/WhenWasIt/res/WhenWasIt.rc
@@ -106,7 +106,7 @@ STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Birthday list"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "Close",IDC_CLOSE,320,223,50,14
+ DEFPUSHBUTTON "Close",IDOK,320,223,50,14
CONTROL "",IDC_BIRTHDAYS_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,3,4,367,214
CONTROL "Show all contacts",IDC_SHOW_ALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,226,178,10
END
@@ -141,7 +141,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_SIZEB
CAPTION "Upcoming birthdays"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "Close",IDC_CLOSE,49,126,132,14
+ DEFPUSHBUTTON "Close",IDOK,49,126,132,14
CONTROL "",IDC_UPCOMING_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,4,4,223,119
END
diff --git a/plugins/WhenWasIt/src/WhenWasIt.cpp b/plugins/WhenWasIt/src/WhenWasIt.cpp
index 5f5d718ea5..8a97f7f513 100644
--- a/plugins/WhenWasIt/src/WhenWasIt.cpp
+++ b/plugins/WhenWasIt/src/WhenWasIt.cpp
@@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
HWND hBirthdaysDlg = nullptr;
-HWND hUpcomingDlg = nullptr;
MWindowList hAddBirthdayWndsList = nullptr;
CMPlugin g_plugin;
@@ -158,15 +157,6 @@ int CMPlugin::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);
- WindowList_Destroy(hAddBirthdayWndsList);
-
Log("%s", "Unhooking events ...");
UnhookEvents();
diff --git a/plugins/WhenWasIt/src/add_birthday.cpp b/plugins/WhenWasIt/src/add_birthday.cpp
new file mode 100644
index 0000000000..215c7c7761
--- /dev/null
+++ b/plugins/WhenWasIt/src/add_birthday.cpp
@@ -0,0 +1,140 @@
+/*
+WhenWasIt (birthday reminder) plugin for Miranda IM
+
+Copyright © 2006 Cristian Libotean
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+#define COLOR_USERINFO RGB(138, 190, 160)
+#define COLOR_MBIRTHDAY RGB(222, 222, 88)
+#define COLOR_BIRTHDAYREMINDER RGB(200, 120, 240)
+#define COLOR_MICQBIRTHDAY RGB(88, 88, 240)
+#define COLOR_PROTOCOL RGB(255, 153, 153)
+
+extern const wchar_t* szSaveModule[2];
+
+class CAddBirthdayDlg : public CDlgBase
+{
+ MCONTACT m_hContact;
+
+ CCtrlCombo cmbCompat;
+
+public:
+ CAddBirthdayDlg(MCONTACT hContact) :
+ CDlgBase(g_plugin, IDD_ADD_BIRTHDAY),
+ m_hContact(hContact),
+ cmbCompat(this, IDC_COMPATIBILITY)
+ {
+ }
+
+ bool OnInitDialog() override
+ {
+ WindowList_Add(hAddBirthdayWndsList, m_hwnd, m_hContact);
+ Utils_RestoreWindowPositionNoSize(m_hwnd, m_hContact, MODULENAME, "BirthdayWnd");
+
+ Window_SetIcon_IcoLib(m_hwnd, hAddBirthdayContact);
+
+ for (auto &it : szSaveModule)
+ cmbCompat.AddString(TranslateW(it));
+ cmbCompat.SetCurSel(g_plugin.cDefaultModule);
+
+ wchar_t *szTooltipText = TranslateT("Please select the module where you want the date of birth to be saved.\r\n\"UserInfo\" is the default location.\r\nUse \"Protocol module\" to make the data visible in User Details.\n\"mBirthday module\" uses the same module as mBirthday plugin.");
+
+ CMStringW buf(FORMAT, TranslateT("Set birthday for %s:"), Clist_GetContactDisplayName(m_hContact));
+ SetCaption(buf);
+
+ HWND hDate = GetDlgItem(m_hwnd, IDC_DATE);
+
+ int year, month, day;
+ int loc = GetContactDOB(m_hContact, year, month, day);
+ if (IsDOBValid(year, month, day)) {
+ SYSTEMTIME st = { 0 };
+ st.wDay = day;
+ st.wMonth = month;
+ st.wYear = year;
+ DateTime_SetSystemtime(hDate, GDT_VALID, &st);
+ }
+ else DateTime_SetSystemtime(hDate, GDT_NONE, NULL);
+
+ const wchar_t *szCurrentModuleTooltip;
+ switch (loc) {
+ case DOB_PROTOCOL:
+ DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_PROTOCOL);
+ buf.Format(TranslateT("%S protocol"), Proto_GetBaseAccountName(m_hContact));
+ szCurrentModuleTooltip = buf;
+ break;
+
+ case DOB_BIRTHDAYREMINDER:
+ DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_BIRTHDAYREMINDER);
+ szCurrentModuleTooltip = L"Birthday Reminder";
+ break;
+
+ case DOB_USERINFO:
+ DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_USERINFO);
+ szCurrentModuleTooltip = L"UserInfo";
+ break;
+
+ case DOB_MICQBIRTHDAY:
+ DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_MICQBIRTHDAY);
+ szCurrentModuleTooltip = L"mICQBirthday";
+ break;
+
+ default:
+ szCurrentModuleTooltip = nullptr;
+ break;
+ }
+
+ CreateToolTip(cmbCompat.GetHwnd(), szTooltipText, 500);
+ if (szCurrentModuleTooltip)
+ CreateToolTip(hDate, szCurrentModuleTooltip, 400);
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ HWND hDate = GetDlgItem(m_hwnd, IDC_DATE);
+ SYSTEMTIME st;
+ if (DateTime_GetSystemtime(hDate, &st) == GDT_VALID)
+ SaveBirthday(m_hContact, st.wYear, st.wMonth, st.wDay, cmbCompat.GetCurSel());
+ else
+ SaveBirthday(m_hContact, 0, 0, 0, SAVE_MODE_DELETEALL);
+
+ if (hBirthdaysDlg != nullptr)
+ SendMessage(hBirthdaysDlg, WWIM_UPDATE_BIRTHDAY, m_hContact, NULL);
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ RefreshContactListIcons(m_hContact); //the birthday might be changed, refresh icon.
+ Window_FreeIcon_IcoLib(m_hwnd);
+ Utils_SaveWindowPosition(m_hwnd, m_hContact, MODULENAME, "BirthdayWnd");
+ WindowList_Remove(hAddBirthdayWndsList, m_hwnd);
+ }
+};
+
+INT_PTR AddBirthdayService(WPARAM hContact, LPARAM)
+{
+ HWND hWnd = WindowList_Find(hAddBirthdayWndsList, hContact);
+ if (!hWnd)
+ (new CAddBirthdayDlg(hContact))->Show();
+ else
+ ShowWindow(hWnd, SW_SHOW);
+
+ return 0;
+}
diff --git a/plugins/WhenWasIt/src/dlg_handlers.cpp b/plugins/WhenWasIt/src/dlg_handlers.cpp
index e57619675d..9f8c0d582c 100644
--- a/plugins/WhenWasIt/src/dlg_handlers.cpp
+++ b/plugins/WhenWasIt/src/dlg_handlers.cpp
@@ -21,138 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-#define COLOR_USERINFO RGB(138, 190, 160)
-#define COLOR_MBIRTHDAY RGB(222, 222, 88)
-#define COLOR_BIRTHDAYREMINDER RGB(200, 120, 240)
-#define COLOR_PROTOCOL RGB(255, 153, 153)
-#define COLOR_MICQBIRTHDAY RGB(88, 88, 240)
-
-#define UPCOMING_TIMER_ID 1002
-
-#define MIN_BIRTHDAYS_WIDTH 200
-#define MIN_BIRTHDAYS_HEIGHT 200
-
-extern const wchar_t* szSaveModule[2];
-
-INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hWnd, GWLP_USERDATA);
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- SetWindowLongPtr(hWnd, GWLP_USERDATA, lParam);
-
- hContact = lParam;
- WindowList_Add(hAddBirthdayWndsList, hWnd, hContact);
- Utils_RestoreWindowPositionNoSize(hWnd, hContact, MODULENAME, "BirthdayWnd");
-
- Window_SetIcon_IcoLib(hWnd, hAddBirthdayContact);
-
- for (int i = 0; i < _countof(szSaveModule); i++)
- SendDlgItemMessage(hWnd, IDC_COMPATIBILITY, CB_ADDSTRING, 0, (LPARAM)TranslateW(szSaveModule[i]));
- SendDlgItemMessage(hWnd, IDC_COMPATIBILITY, CB_SETCURSEL, g_plugin.cDefaultModule, 0);
- break;
-
- case WM_SHOWWINDOW:
- {
- wchar_t *szTooltipText = TranslateT("Please select the module where you want the date of birth to be saved.\r\n\"UserInfo\" is the default location.\r\nUse \"Protocol module\" to make the data visible in User Details.\n\"mBirthday module\" uses the same module as mBirthday plugin.");
- wchar_t *szCurrentModuleTooltip = nullptr;
- char *szProto = Proto_GetBaseAccountName(hContact);
-
- wchar_t buffer[2048];
- mir_snwprintf(buffer, TranslateT("Set birthday for %s:"), Clist_GetContactDisplayName(hContact));
- SetWindowText(hWnd, buffer);
-
- HWND hDate = GetDlgItem(hWnd, IDC_DATE);
-
- int year, month, day;
- int loc = GetContactDOB(hContact, year, month, day);
- if (IsDOBValid(year, month, day)) {
- SYSTEMTIME st = { 0 };
- st.wDay = day;
- st.wMonth = month;
- st.wYear = year;
- DateTime_SetSystemtime(hDate, GDT_VALID, &st);
- }
- else DateTime_SetSystemtime(hDate, GDT_NONE, NULL);
-
- switch (loc) {
- case DOB_PROTOCOL:
- DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_PROTOCOL);
- mir_snwprintf(buffer, TranslateT("%S protocol"), szProto);
- szCurrentModuleTooltip = buffer;
- break;
-
- case DOB_BIRTHDAYREMINDER:
- DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_BIRTHDAYREMINDER);
- szCurrentModuleTooltip = L"Birthday Reminder";
- break;
-
- case DOB_USERINFO:
- DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_USERINFO);
- szCurrentModuleTooltip = L"UserInfo";
- break;
-
- case DOB_MICQBIRTHDAY:
- DateTime_SetMonthCalColor(hDate, MCSC_TITLEBK, COLOR_MICQBIRTHDAY);
- szCurrentModuleTooltip = L"mICQBirthday";
- break;
-
- default:
- szCurrentModuleTooltip = nullptr;
- break;
- }
-
- CreateToolTip(GetDlgItem(hWnd, IDC_COMPATIBILITY), szTooltipText, 500);
- if (szCurrentModuleTooltip)
- CreateToolTip(hDate, szCurrentModuleTooltip, 400);
- }
- break;
-
- case WM_DESTROY:
- RefreshContactListIcons(hContact); //the birthday might be changed, refresh icon.
- Window_FreeIcon_IcoLib(hWnd);
- Utils_SaveWindowPosition(hWnd, hContact, MODULENAME, "BirthdayWnd");
- WindowList_Remove(hAddBirthdayWndsList, hWnd);
- break;
-
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- hContact = (MCONTACT)GetWindowLongPtr(hWnd, GWLP_USERDATA);
- HWND hDate = GetDlgItem(hWnd, IDC_DATE);
- SYSTEMTIME st;
- if (DateTime_GetSystemtime(hDate, &st) == GDT_VALID) {
- int mode = SendDlgItemMessage(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);
-
- if (hBirthdaysDlg != nullptr)
- SendMessage(hBirthdaysDlg, WWIM_UPDATE_BIRTHDAY, hContact, NULL);
-
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- }
- break;
- }
-
- return FALSE;
-}
-
-void AddAnchorWindowToDeferList(HDWP &hdWnds, HWND window, RECT *rParent, WINDOWPOS *wndPos, int anchors)
-{
- if (nullptr == window) /* Wine fix. */
- return;
- RECT rChild = AnchorCalcPos(window, rParent, wndPos, anchors);
- hdWnds = DeferWindowPos(hdWnds, window, HWND_NOTOPMOST, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, SWP_NOZORDER);
-}
-
-
#define NA TranslateT("N/A")
wchar_t* GetBirthdayModule(int module, MCONTACT)
@@ -174,7 +42,7 @@ struct BirthdaysSortParams
int column;
};
-INT_PTR CALLBACK BirthdaysCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
+int CALLBACK BirthdaysCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
{
BirthdaysSortParams params = *(BirthdaysSortParams *)myParam;
const int maxSize = 1024;
@@ -184,8 +52,7 @@ INT_PTR CALLBACK BirthdaysCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam
ListView_GetItemText(params.hList, (int)lParam1, params.column, text1, _countof(text1));
ListView_GetItemText(params.hList, (int)lParam2, params.column, text2, _countof(text2));
- int res = 0;
-
+ int res;
if ((params.column == 2) || (params.column == 4)) {
wchar_t *err1, *err2;
value1 = wcstol(text1, &err1, 10);
@@ -200,412 +67,276 @@ INT_PTR CALLBACK BirthdaysCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam
}
else res = mir_wstrcmpi(text1, text2);
- res = (params.column == lastColumn) ? -res : res;
- return res;
+ return (params.column == lastColumn) ? -res : res;
}
-//only updates the birthday part of the list view entry. Won't update the szProto and the contact name (those shouldn't change anyway :))
-int UpdateBirthdayEntry(HWND hList, MCONTACT hContact, int entry, int bShowAll, int bShowCurrentAge, int bAdd)
-{
- int currentMonth, currentDay;
- int res = entry;
-
- if (bShowCurrentAge) {
- time_t now = Today();
- struct tm *today = gmtime(&now);
- currentDay = today->tm_mday + 1;
- currentMonth = today->tm_mon + 1;
- }
- else currentMonth = currentDay = 0;
-
- int year, month, day;
- int module = GetContactDOB(hContact, year, month, day);
- if (bShowAll || IsDOBValid(year, month, day)) {
- lastColumn = -1; //list isn't sorted anymore
- int dtb = DaysToBirthday(Today(), year, month, day);
- int age = GetContactAge(hContact);
- if (bShowCurrentAge)
- if (month > currentMonth || (month == currentMonth) && (day > currentDay)) // birthday still to come
- age--;
-
- char *szProto = Proto_GetBaseAccountName(hContact);
- 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 = hContact;
- item.pszText = ptszAccName;
-
- if (bAdd)
- ListView_InsertItem(hList, &item);
- else
- ListView_SetItemText(hList, entry, 0, ptszAccName);
-
- ListView_SetItemText(hList, entry, 1, Clist_GetContactDisplayName(hContact));
-
- wchar_t buffer[2048];
- if ((dtb <= 366) && (dtb >= 0))
- mir_snwprintf(buffer, L"%d", dtb);
- else
- mir_snwprintf(buffer, NA);
-
- ListView_SetItemText(hList, entry, 2, buffer);
- if ((month != 0) && (day != 0))
- mir_snwprintf(buffer, L"%04d-%02d-%02d", year, month, day);
- else
- mir_snwprintf(buffer, NA);
-
- ListView_SetItemText(hList, entry, 3, buffer);
-
- if (age < 400 && age > 0) //hopefully noone lives longer than this :)
- mir_snwprintf(buffer, L"%d", age);
- else
- mir_snwprintf(buffer, NA);
-
- ListView_SetItemText(hList, entry, 4, buffer);
- ListView_SetItemText(hList, entry, 5, GetBirthdayModule(module, hContact));
+/////////////////////////////////////////////////////////////////////////////////////////
+// Basic list dialog
- res++;
- }
- else if (!bShowAll && !bAdd)
- ListView_DeleteItem(hList, entry);
-
- return res;
+CBasicListDlg::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);
}
-static LRESULT CALLBACK BirthdaysListSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+void CBasicListDlg::onDblClick_List(CCtrlListView::TEventInfo*)
{
- LVITEM item = { 0 };
- MCONTACT hContact;
- int i, count;
-
- switch (msg) {
- case WM_KEYUP:
- if (wParam == VK_ESCAPE)
- SendMessage(GetParent(hWnd), WM_CLOSE, 0, 0);
- break;
-
- case WM_SYSKEYDOWN:
- if (wParam == 'X')
- SendMessage(GetParent(hWnd), WM_CLOSE, 0, 0);
- break;
-
- case WM_LBUTTONDBLCLK:
- count = ListView_GetItemCount(hWnd);
- item.mask = LVIF_PARAM;
- for (i = 0; i < count; i++) {
- if (ListView_GetItemState(hWnd, i, LVIS_SELECTED)) {
- item.iItem = i;
- ListView_GetItem(hWnd, &item);
- hContact = (MCONTACT)item.lParam;
- CallService(MS_WWI_ADD_BIRTHDAY, hContact, 0);
- break;
- }
+ 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);
+ CallService(MS_WWI_ADD_BIRTHDAY, (MCONTACT)item.lParam, 0);
+ break;
}
- break;
+ }
+}
- case WM_CONTEXTMENU:
- POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
- count = ListView_GetItemCount(hWnd);
- item.mask = LVIF_PARAM;
- for (i = 0; i < count; i++) {
- if (ListView_GetItemState(hWnd, i, LVIS_SELECTED)) {
- item.iItem = i;
- ListView_GetItem(hWnd, &item);
- hContact = (MCONTACT)item.lParam;
- HMENU hMenu = Menu_BuildContactMenu(hContact);
- if (hMenu != nullptr) {
- Clist_MenuProcessCommand(TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, nullptr), MPCF_CONTACTMENU, hContact);
- DestroyMenu(hMenu);
- }
- break;
+void CBasicListDlg::onMenu_List(CContextMenuPos *pos)
+{
+ 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);
+
+ HMENU hMenu = Menu_BuildContactMenu((MCONTACT)item.lParam);
+ if (hMenu != nullptr) {
+ Clist_MenuProcessCommand(TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pos->pt.x, pos->pt.y, 0, m_list.GetHwnd(), nullptr), MPCF_CONTACTMENU, (MCONTACT)item.lParam);
+ DestroyMenu(hMenu);
}
+ break;
}
- break;
}
- return mir_callNextSubclass(hWnd, BirthdaysListSubclassProc, msg, wParam, lParam);
}
-void SetBirthdaysCount(HWND hWnd)
+void CBasicListDlg::Sort(int iCol)
{
- int count = ListView_GetItemCount((GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST)));
- wchar_t title[512];
- mir_snwprintf(title, TranslateT("Birthday list (%d)"), count);
- SetWindowText(hWnd, title);
+ BirthdaysSortParams params = {};
+ params.hList = m_list.GetHwnd();
+ params.column = iCol;
+ m_list.SortItemsEx(BirthdaysCompare, (LPARAM)&params);
}
-int LoadBirthdays(HWND hWnd, int bShowAll)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Birthday list dialog
+
+class CBirthdaysDlg : public CBasicListDlg
{
- HWND hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
- ListView_DeleteAllItems(hList);
+ UI_MESSAGE_MAP(CBirthdaysDlg, CBasicListDlg);
+ UI_MESSAGE(WWIM_UPDATE_BIRTHDAY, OnUpdateContact);
+ UI_MESSAGE_MAP_END();
- int count = 0;
- for (auto &hContact : Contacts())
- count = UpdateBirthdayEntry(hList, hContact, count, bShowAll, g_plugin.cShowAgeMode, 1);
+ void SetBirthdaysCount()
+ {
+ SetCaption(CMStringW(FORMAT, TranslateT("Birthday list (%d)"), m_list.GetItemCount()));
+ }
- SetBirthdaysCount(hWnd);
- return 0;
-}
+ int LoadBirthdays(int bShowAll)
+ {
+ m_list.DeleteAllItems();
-INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- Window_SetIcon_IcoLib(hWnd, hListMenu);
- {
- HWND hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
-
- ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
-
- mir_subclassWindow(hList, BirthdaysListSubclassProc);
-
- LVCOLUMN col;
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.pszText = TranslateT("Protocol");
- col.cx = 80;
- ListView_InsertColumn(hList, 0, &col);
- col.pszText = TranslateT("Contact");
- col.cx = 180;
- ListView_InsertColumn(hList, 1, &col);
- col.pszText = TranslateT("DTB");
- col.cx = 50;
- ListView_InsertColumn(hList, 2, &col);
- col.pszText = TranslateT("Birthday");
- col.cx = 80;
- ListView_InsertColumn(hList, 3, &col);
- col.pszText = TranslateT("Age");
- col.cx = 50;
- ListView_InsertColumn(hList, 4, &col);
- col.pszText = TranslateT("Module");
- col.cx = 108;
- ListView_InsertColumn(hList, 5, &col);
-
- LoadBirthdays(hWnd, 0);
- int column = g_plugin.getByte("SortColumn", 0);
-
- BirthdaysSortParams params = {};
- params.hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
- params.column = column;
- ListView_SortItemsEx(params.hList, BirthdaysCompare, (LPARAM)&params);
-
- Utils_RestoreWindowPosition(hWnd, NULL, MODULENAME, "BirthdayList");
- }
- return TRUE;
+ int count = 0;
+ for (auto &hContact : Contacts())
+ count = UpdateBirthdayEntry(hContact, count, bShowAll, g_plugin.cShowAgeMode, 1);
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
+ SetBirthdaysCount();
+ return 0;
+ }
- case WWIM_UPDATE_BIRTHDAY:
- {
- MCONTACT hContact = wParam;
- HWND hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
- LVFINDINFO fi = { 0 };
-
- fi.flags = LVFI_PARAM;
- fi.lParam = (LPARAM)hContact;
- int idx = ListView_FindItem(hList, -1, &fi);
- if (-1 == idx)
- UpdateBirthdayEntry(hList, hContact, ListView_GetItemCount(hList), IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 1);
- else
- UpdateBirthdayEntry(hList, hContact, idx, IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 0);
- SetBirthdaysCount(hWnd);
+ INT_PTR OnUpdateContact(UINT, WPARAM hContact, LPARAM)
+ {
+ LVFINDINFO fi = { 0 };
+ fi.flags = LVFI_PARAM;
+ fi.lParam = hContact;
+ int idx = m_list.FindItem(-1, &fi);
+ if (-1 == idx)
+ UpdateBirthdayEntry(hContact, m_list.GetItemCount(), IsDlgButtonChecked(m_hwnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 1);
+ else
+ UpdateBirthdayEntry(hContact, idx, IsDlgButtonChecked(m_hwnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 0);
+ SetBirthdaysCount();
+ return 0;
+ }
+
+ //only updates the birthday part of the list view entry. Won't update the szProto and the contact name (those shouldn't change anyway :))
+ int UpdateBirthdayEntry(MCONTACT hContact, int entry, int bShowAll, int bShowCurrentAge, int bAdd)
+ {
+ int currentMonth, currentDay;
+ int res = entry;
+
+ if (bShowCurrentAge) {
+ time_t now = Today();
+ struct tm *today = gmtime(&now);
+ currentDay = today->tm_mday + 1;
+ currentMonth = today->tm_mon + 1;
}
- break;
+ else currentMonth = currentDay = 0;
+
+ int year, month, day;
+ int module = GetContactDOB(hContact, year, month, day);
+ if (bShowAll || IsDOBValid(year, month, day)) {
+ lastColumn = -1; //list isn't sorted anymore
+ int dtb = DaysToBirthday(Today(), year, month, day);
+ int age = GetContactAge(hContact);
+ if (bShowCurrentAge)
+ if (month > currentMonth || (month == currentMonth) && (day > currentDay)) // birthday still to come
+ age--;
- case WM_WINDOWPOSCHANGING:
- {
- HDWP hdWnds = BeginDeferWindowPos(2);
- RECT rParent;
- WINDOWPOS *wndPos = (WINDOWPOS *)lParam;
- GetWindowRect(hWnd, &rParent);
+ char *szProto = Proto_GetBaseAccountName(hContact);
+ PROTOACCOUNT *pAcc = Proto_GetAccount(szProto);
+ wchar_t *ptszAccName = (pAcc == nullptr) ? TranslateT("Unknown") : pAcc->tszAccountName;
- if (wndPos->cx < MIN_BIRTHDAYS_WIDTH)
- wndPos->cx = MIN_BIRTHDAYS_WIDTH;
+ LVITEM item = { 0 };
+ item.mask = LVIF_TEXT | LVIF_PARAM;
+ item.iItem = entry;
+ item.lParam = hContact;
+ item.pszText = ptszAccName;
- if (wndPos->cy < MIN_BIRTHDAYS_HEIGHT)
- wndPos->cy = MIN_BIRTHDAYS_HEIGHT;
+ if (bAdd)
+ m_list.InsertItem(&item);
+ else
+ m_list.SetItemText(entry, 0, ptszAccName);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_CLOSE), &rParent, wndPos, ANCHOR_RIGHT | ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_SHOW_ALL), &rParent, wndPos, ANCHOR_LEFT | ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST), &rParent, wndPos, ANCHOR_ALL);
+ m_list.SetItemText(entry, 1, Clist_GetContactDisplayName(hContact));
- EndDeferWindowPos(hdWnds);
- }
- break;
+ wchar_t buffer[2048];
+ if ((dtb <= 366) && (dtb >= 0))
+ mir_snwprintf(buffer, L"%d", dtb);
+ else
+ mir_snwprintf(buffer, NA);
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_CLOSE:
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- break;
+ m_list.SetItemText(entry, 2, buffer);
+ if ((month != 0) && (day != 0))
+ mir_snwprintf(buffer, L"%04d-%02d-%02d", year, month, day);
+ else
+ mir_snwprintf(buffer, NA);
+ m_list.SetItemText(entry, 3, buffer);
- case IDC_SHOW_ALL:
- LoadBirthdays(hWnd, IsDlgButtonChecked(hWnd, IDC_SHOW_ALL));
- break;
- }
- break;
+ if (age < 400 && age > 0) //hopefully noone lives longer than this :)
+ mir_snwprintf(buffer, L"%d", age);
+ else
+ mir_snwprintf(buffer, NA);
+ m_list.SetItemText(entry, 4, buffer);
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case IDC_BIRTHDAYS_LIST:
- switch (((LPNMHDR)lParam)->code) {
- case LVN_COLUMNCLICK:
- LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
- int column = lv->iSubItem;
- g_plugin.setByte("SortColumn", column);
- BirthdaysSortParams params = {};
- params.hList = GetDlgItem(hWnd, IDC_BIRTHDAYS_LIST);
- params.column = column;
- ListView_SortItemsEx(params.hList, BirthdaysCompare, (LPARAM)&params);
- lastColumn = (params.column == lastColumn) ? -1 : params.column;
- break;
- }
+ m_list.SetItemText(entry, 5, GetBirthdayModule(module, hContact));
+ res++;
}
- break;
-
- case WM_DESTROY:
- hBirthdaysDlg = nullptr;
- Utils_SaveWindowPosition(hWnd, NULL, MODULENAME, "BirthdayList");
- Window_FreeIcon_IcoLib(hWnd);
- lastColumn = -1;
- break;
+ else if (!bShowAll && !bAdd)
+ m_list.DeleteItem(entry);
+ return res;
}
- return 0;
-}
+ CCtrlCheck chkShowAll;
-INT_PTR CALLBACK DlgProcUpcoming(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static int timeout;
+public:
+ CBirthdaysDlg() :
+ CBasicListDlg(IDD_BIRTHDAYS),
+ chkShowAll(this, IDC_SHOW_ALL)
+ {
+ SetMinSize(200, 200);
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- Window_SetIcon_IcoLib(hWnd, hListMenu);
- {
- timeout = g_plugin.cDlgTimeout;
- HWND hList = GetDlgItem(hWnd, IDC_UPCOMING_LIST);
-
- mir_subclassWindow(hList, BirthdaysListSubclassProc);
- ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
-
- LVCOLUMN col;
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.pszText = TranslateT("Contact");
- col.cx = 300;
- ListView_InsertColumn(hList, 0, &col);
- col.pszText = TranslateT("Age");
- col.cx = 45;
- ListView_InsertColumn(hList, 1, &col);
- col.pszText = TranslateT("DTB");
- col.cx = 45;
- ListView_InsertColumn(hList, 2, &col);
-
- ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE);
-
- if (timeout > 0)
- SetTimer(hWnd, UPCOMING_TIMER_ID, 1000, nullptr);
- Utils_RestoreWindowPosition(hWnd, NULL, MODULENAME, "BirthdayListUpcoming");
- }
- return TRUE;
-
- case WM_TIMER:
- {
- 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(hWnd, IDC_CLOSE, buffer);
-
- if (timeout <= 0)
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- }
- break;
+ chkShowAll.OnChange = Callback(this, &CBirthdaysDlg::onChange_ShowAll);
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
+ m_list.OnColumnClick = Callback(this, &CBirthdaysDlg::onColumnClick);
+ }
- case WWIM_ADD_UPCOMING_BIRTHDAY:
- {
- PUpcomingBirthday data = (PUpcomingBirthday)wParam;
+ bool OnInitDialog() override
+ {
+ Window_SetIcon_IcoLib(m_hwnd, hListMenu);
+
+ m_list.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
+
+ LVCOLUMN col;
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.pszText = TranslateT("Protocol");
+ col.cx = 80;
+ m_list.InsertColumn(0, &col);
+
+ col.pszText = TranslateT("Contact");
+ col.cx = 180;
+ m_list.InsertColumn(1, &col);
+
+ col.pszText = TranslateT("DTB");
+ col.cx = 50;
+ m_list.InsertColumn(2, &col);
+
+ col.pszText = TranslateT("Birthday");
+ col.cx = 80;
+ m_list.InsertColumn(3, &col);
+
+ col.pszText = TranslateT("Age");
+ col.cx = 50;
+ m_list.InsertColumn(4, &col);
+
+ col.pszText = TranslateT("Module");
+ col.cx = 108;
+ m_list.InsertColumn(5, &col);
+
+ LoadBirthdays(0);
+ int column = g_plugin.getByte("SortColumn", 0);
+ Sort(column);
+
+ Utils_RestoreWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayList");
+ return true;
+ }
- HWND hList = GetDlgItem(hWnd, IDC_UPCOMING_LIST);
- LVITEM item = { 0 };
- LVFINDINFO fi = { 0 };
-
- fi.flags = LVFI_PARAM;
- fi.lParam = (LPARAM)data->hContact;
- if (-1 != ListView_FindItem(hList, -1, &fi))
- return 0; /* Allready in list. */
-
- int index = ListView_GetItemCount(hList);
- item.iItem = index;
- item.mask = LVIF_PARAM | LVIF_TEXT;
- item.lParam = (LPARAM)data->hContact;
- item.pszText = data->message;
- ListView_InsertItem(hList, &item);
-
- wchar_t buffer[512];
- mir_snwprintf(buffer, L"%d", data->age);
- ListView_SetItemText(hList, index, 1, buffer);
- mir_snwprintf(buffer, L"%d", data->dtb);
- ListView_SetItemText(hList, index, 2, buffer);
-
- BirthdaysSortParams params = {};
- params.hList = hList;
- params.column = 2;
- ListView_SortItemsEx(hList, BirthdaysCompare, (LPARAM)&params);
- }
- break;
+ int Resizer(UTILRESIZECONTROL *urc) override
+ {
+ switch (urc->wId) {
+ case IDC_SHOW_ALL:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_CLOSE:
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- break;
+ case IDC_BIRTHDAYS_LIST:
+ return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
}
- break;
- case WM_GETMINMAXINFO:
- ((LPMINMAXINFO)lParam)->ptMinTrackSize.x = 400;
- ((LPMINMAXINFO)lParam)->ptMinTrackSize.y = 160;
- ((LPMINMAXINFO)lParam)->ptMaxTrackSize.x = 600;
- ((LPMINMAXINFO)lParam)->ptMaxTrackSize.y = 530;
- break;
-
- case WM_SIZE:
- {
- HWND hList = GetDlgItem(hWnd, IDC_UPCOMING_LIST);
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
+ }
- RECT rcWin;
- GetWindowRect(hWnd, &rcWin);
+ void OnDestroy() override
+ {
+ hBirthdaysDlg = nullptr;
+ Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayList");
+ Window_FreeIcon_IcoLib(m_hwnd);
+ lastColumn = -1;
+ }
- int cx = rcWin.right - rcWin.left;
- int cy = rcWin.bottom - rcWin.top;
- SetWindowPos(hList, nullptr, 0, 0, (cx - 30), (cy - 80), (SWP_NOZORDER | SWP_NOMOVE));
- ListView_SetColumnWidth(hList, 0, (cx - 150));
- SetWindowPos(GetDlgItem(hWnd, IDC_CLOSE), nullptr, ((cx / 2) - 95), (cy - 67), 0, 0, SWP_NOSIZE);
- RedrawWindow(hWnd, nullptr, nullptr, (RDW_FRAME | RDW_INVALIDATE));
- }
- break;
+ void onChange_ShowAll(CCtrlCheck *pCheck)
+ {
+ LoadBirthdays(pCheck->GetState());
+ }
- case WM_DESTROY:
- hUpcomingDlg = nullptr;
- Utils_SaveWindowPosition(hWnd, NULL, MODULENAME, "BirthdayListUpcoming");
- Window_FreeIcon_IcoLib(hWnd);
- KillTimer(hWnd, UPCOMING_TIMER_ID);
- break;
+ void onColumnClick(CCtrlListView::TEventInfo *ev)
+ {
+ int column = ev->nmlv->iSubItem;
+ g_plugin.setByte("SortColumn", column);
+ Sort(column);
+
+ lastColumn = (column == lastColumn) ? -1 : column;
}
+};
+INT_PTR ShowListService(WPARAM, LPARAM)
+{
+ if (!hBirthdaysDlg)
+ (new CBirthdaysDlg())->Show();
+ else
+ ShowWindow(hBirthdaysDlg, SW_SHOW);
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Popups
+
int HandlePopupClick(HWND hWnd, int action)
{
MCONTACT hContact;
diff --git a/plugins/WhenWasIt/src/dlg_handlers.h b/plugins/WhenWasIt/src/dlg_handlers.h
index 8c8d41f08d..587a1c9936 100644
--- a/plugins/WhenWasIt/src/dlg_handlers.h
+++ b/plugins/WhenWasIt/src/dlg_handlers.h
@@ -38,8 +38,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int OnOptionsInitialise(WPARAM wParam, LPARAM);
-INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+class CBasicListDlg : public CDlgBase
+{
+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);
diff --git a/plugins/WhenWasIt/src/hooked_events.cpp b/plugins/WhenWasIt/src/hooked_events.cpp
index 71d19ec82f..789b36a4cc 100644
--- a/plugins/WhenWasIt/src/hooked_events.cpp
+++ b/plugins/WhenWasIt/src/hooked_events.cpp
@@ -28,6 +28,7 @@ UINT_PTR hCheckTimer = NULL;
UINT_PTR hDateChangeTimer = NULL;
static int currentDay = 0;
+void CloseUpcoming();
static int OnTopToolBarModuleLoaded(WPARAM, LPARAM)
{
@@ -49,7 +50,19 @@ static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam)
return 0;
}
-int OnModulesLoaded(WPARAM, LPARAM)
+static int OnShutdown(WPARAM, LPARAM)
+{
+ if (hBirthdaysDlg)
+ SendMessage(hBirthdaysDlg, WM_CLOSE, 0, 0);
+
+ CloseUpcoming();
+
+ WindowList_Broadcast(hAddBirthdayWndsList, WM_CLOSE, 0, 0);
+ WindowList_Destroy(hAddBirthdayWndsList);
+ return 0;
+}
+
+static int OnModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged);
HookEvent(ME_TTB_MODULELOADED, OnTopToolBarModuleLoaded);
@@ -60,6 +73,7 @@ int OnModulesLoaded(WPARAM, LPARAM)
int HookEvents()
{
+ HookEvent(ME_SYSTEM_SHUTDOWN, OnShutdown);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
HookEvent(ME_OPT_INITIALISE, OnOptionsInitialise);
return 0;
diff --git a/plugins/WhenWasIt/src/notifiers.cpp b/plugins/WhenWasIt/src/notifiers.cpp
index f72530dd9b..7c40bb8995 100644
--- a/plugins/WhenWasIt/src/notifiers.cpp
+++ b/plugins/WhenWasIt/src/notifiers.cpp
@@ -147,50 +147,153 @@ int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
return 0;
}
-int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static class CUpcomingDlg *g_pUpcomingDlg = nullptr;
+
+class CUpcomingDlg : public CBasicListDlg
{
- wchar_t *name = Clist_GetContactDisplayName(hContact);
+ int timeout;
- wchar_t text[1024];
- BuildDTBText(dtb, name, text, _countof(text));
- if (!hUpcomingDlg) {
- hUpcomingDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_UPCOMING), nullptr, DlgProcUpcoming);
- ShowWindow(hUpcomingDlg, g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
+ 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();
}
- TUpcomingBirthday data = { 0 };
- data.name = name;
- data.message = text;
- data.dtb = dtb;
- data.hContact = hContact;
- data.age = age;
+ 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];
+ BuildDABText(dtb, Clist_GetContactDisplayName(hContact), text, _countof(text));
- SendMessage(hUpcomingDlg, WWIM_ADD_UPCOMING_BIRTHDAY, (WPARAM)&data, NULL);
+ 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 *name = Clist_GetContactDisplayName(hContact);
-
wchar_t text[1024];
- BuildDABText(dab, name, text, _countof(text));
- if (!hUpcomingDlg) {
- hUpcomingDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_UPCOMING), nullptr, DlgProcUpcoming);
- ShowWindow(hUpcomingDlg, g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
- }
+ BuildDABText(dab, Clist_GetContactDisplayName(hContact), text, _countof(text));
- TUpcomingBirthday data = { 0 };
- data.name = name;
- data.message = text;
- data.dtb = -dab;
- data.hContact = hContact;
- data.age = age;
+ if (!g_pUpcomingDlg) {
+ g_pUpcomingDlg = new CUpcomingDlg();
+ g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
+ }
- SendMessage(hUpcomingDlg, WWIM_ADD_UPCOMING_BIRTHDAY, (WPARAM)&data, NULL);
+ 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/notifiers.h b/plugins/WhenWasIt/src/notifiers.h
index 3f22598539..d16d524090 100644
--- a/plugins/WhenWasIt/src/notifiers.h
+++ b/plugins/WhenWasIt/src/notifiers.h
@@ -29,16 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DUMMY_MODULE MODULENAME
#define DUMMY_SETTING "refreshIconsDummyVal"
-struct TUpcomingBirthday{
- MCONTACT hContact;
- wchar_t *name;
- wchar_t *message;
- int dtb;
- int age;
-};
-
-typedef TUpcomingBirthday *PUpcomingBirthday;
-
void PopupNotifyNoBirthdays();
int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age);
int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age);
diff --git a/plugins/WhenWasIt/src/resource.h b/plugins/WhenWasIt/src/resource.h
index 76f9354820..57eedddbb2 100644
--- a/plugins/WhenWasIt/src/resource.h
+++ b/plugins/WhenWasIt/src/resource.h
@@ -37,7 +37,6 @@
#define IDC_CLIST_STATIC 1012
#define IDC_BACKGROUND 1014
#define IDC_FOREGROUND 1015
-#define IDC_CLOSE 1015
#define IDC_BIRTHDAYS_LIST 1016
#define IDC_SHOW_ALL 1017
#define IDC_DATE 1020
diff --git a/plugins/WhenWasIt/src/services.cpp b/plugins/WhenWasIt/src/services.cpp
index 0e30a3b1c2..0226489c98 100644
--- a/plugins/WhenWasIt/src/services.cpp
+++ b/plugins/WhenWasIt/src/services.cpp
@@ -115,23 +115,8 @@ INT_PTR CheckBirthdaysService(WPARAM, LPARAM lParam)
return 0;
}
-INT_PTR ShowListService(WPARAM, LPARAM)
-{
- if (!hBirthdaysDlg)
- hBirthdaysDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_BIRTHDAYS), nullptr, DlgProcBirthdays);
-
- ShowWindow(hBirthdaysDlg, SW_SHOW);
- return 0;
-}
-
-INT_PTR AddBirthdayService(WPARAM hContact, LPARAM)
-{
- HWND hWnd = WindowList_Find(hAddBirthdayWndsList, hContact);
- if (!hWnd)
- hWnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADD_BIRTHDAY), nullptr, DlgProcAddBirthday, hContact);
-
- return ShowWindow(hWnd, SW_SHOW);
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Refresh users' details thread
void ShowPopupMessage(const wchar_t *title, const wchar_t *message, HANDLE icon)
{
@@ -167,6 +152,9 @@ INT_PTR RefreshUserDetailsService(WPARAM, LPARAM)
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Birthdays import
+
INT_PTR ImportBirthdaysService(WPARAM, LPARAM)
{
wchar_t fileName[1024] = { 0 };
@@ -192,6 +180,9 @@ INT_PTR ImportBirthdaysService(WPARAM, LPARAM)
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Birthdays export
+
INT_PTR ExportBirthdaysService(WPARAM, LPARAM)
{
wchar_t fileName[1024] = { 0 };
diff --git a/plugins/WhenWasIt/src/stdafx.h b/plugins/WhenWasIt/src/stdafx.h
index 2feb189db1..ed09270122 100644
--- a/plugins/WhenWasIt/src/stdafx.h
+++ b/plugins/WhenWasIt/src/stdafx.h
@@ -77,7 +77,6 @@ struct CMPlugin : public PLUGIN<CMPlugin>
};
extern HWND hBirthdaysDlg;
-extern HWND hUpcomingDlg;
extern MWindowList hAddBirthdayWndsList;
#endif //M_WWI_COMMONHEADERS_H \ No newline at end of file
diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp
index 027d7ee3da..5067e42768 100644
--- a/plugins/WhenWasIt/src/utils.cpp
+++ b/plugins/WhenWasIt/src/utils.cpp
@@ -236,7 +236,7 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos,
return rChild;
}
-void CreateToolTip(HWND target, wchar_t* tooltip, LPARAM width)
+void CreateToolTip(HWND target, const wchar_t* tooltip, LPARAM width)
{
HWND hwndToolTip = CreateWindow(TOOLTIPS_CLASS, nullptr, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, target, nullptr, nullptr, nullptr);
@@ -247,7 +247,7 @@ void CreateToolTip(HWND target, wchar_t* tooltip, LPARAM width)
ti.hwnd = target;
ti.uId = 0;
ti.hinst = nullptr;
- ti.lpszText = tooltip;
+ ti.lpszText = (LPWSTR)tooltip;
GetClientRect(target, &ti.rect);
SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, width);
diff --git a/plugins/WhenWasIt/src/utils.h b/plugins/WhenWasIt/src/utils.h
index f5afc2c1c0..5b4d967f28 100644
--- a/plugins/WhenWasIt/src/utils.h
+++ b/plugins/WhenWasIt/src/utils.h
@@ -49,6 +49,6 @@ wchar_t* GetContactID(MCONTACT hContact, char *szProto);
MCONTACT GetContactFromID(wchar_t *szID, char *szProto);
MCONTACT GetContactFromID(wchar_t *szID, wchar_t *szProto);
-void CreateToolTip(HWND target, wchar_t *tooltip, LPARAM width);
+void CreateToolTip(HWND target, const wchar_t *tooltip, LPARAM width);
#endif \ No newline at end of file
diff --git a/plugins/WhenWasIt/src/version.h b/plugins/WhenWasIt/src/version.h
index c1f40e84c3..c69c7c5e00 100644
--- a/plugins/WhenWasIt/src/version.h
+++ b/plugins/WhenWasIt/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 3
-#define __RELEASE_NUM 3
-#define __BUILD_NUM 6
+#define __MINOR_VERSION 4
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>