summaryrefslogtreecommitdiff
path: root/RecentContacts/V_RecentContacts.cpp
diff options
context:
space:
mode:
authormataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-26 15:41:10 +0000
committermataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-26 15:41:10 +0000
commitf04d64869f3b1de54fb343f28f955584780001b8 (patch)
tree5453dc10de3d980de79ffe019fa0b5fcb692a27d /RecentContacts/V_RecentContacts.cpp
parent7aff1e4cb053394db57c2814d5fe1e6493e0cc75 (diff)
Project folders rename part 3
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@215 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
Diffstat (limited to 'RecentContacts/V_RecentContacts.cpp')
-rw-r--r--RecentContacts/V_RecentContacts.cpp830
1 files changed, 830 insertions, 0 deletions
diff --git a/RecentContacts/V_RecentContacts.cpp b/RecentContacts/V_RecentContacts.cpp
new file mode 100644
index 0000000..040b7d4
--- /dev/null
+++ b/RecentContacts/V_RecentContacts.cpp
@@ -0,0 +1,830 @@
+
+#include "V_RecentContacts.h"
+
+
+
+
+extern int onOptInitialise(WPARAM wParam, LPARAM lParam);
+
+
+using namespace std;
+static const basic_string <char>::size_type npos = -1;
+
+char *szProto;
+HINSTANCE hInst = NULL;
+PLUGINLINK *pluginLink = NULL;
+HANDLE hMenu = NULL;
+HANDLE hPrebuildMenu = NULL;
+HANDLE hSystemModulesLoaded = NULL;
+HANDLE hTopToolbarLoaded = NULL;
+HANDLE hTopToolbarButtonShowList = NULL;
+HANDLE hMsgWndEvent = NULL;
+HANDLE hWindowList = NULL;
+HANDLE hMenuItemRemove = NULL;
+HANDLE hOptInitialise = NULL;
+HANDLE hContactSetting = NULL;
+HANDLE hLastUC_ServiceList[2] = {0};
+HANDLE hLastUC_HooksList[] = {0};
+BOOL IsMessageAPI = FALSE;
+
+LastUCOptions LastUCOpt = {0};
+
+//static void InitOptions(){
+//}
+
+
+PLUGININFOEX pluginInfo={
+ sizeof(PLUGININFOEX),
+ "Recent Contacts",
+ PLUGIN_MAKE_VERSION(0,0,2,0),
+ "Adds a menu item in main menu, which open the window with list of last used contacts names,"
+ " sorted in order from most recent to least."
+ ,
+ "ValeraVi, Kildor",
+ "kostia@ngs.ru",
+ "© 2005 ValeraVi, © 2009 Kildor",
+ "http://kildor.miranda.im",
+ 0, // not unicode
+ 0, //doesn't replace anything built-in
+ { 0x0e5f3b9d, 0xebcd, 0x44d7, {0x93, 0x74, 0xd8, 0xe5, 0xd8, 0x8d, 0xf4, 0xe3}}
+ /* 0e5f3b9d-ebcd-44d7-9374-d8e5d88df4e3 */
+};
+
+PLUGININFO oldpluginInfo={
+ sizeof(PLUGININFO),
+ pluginInfo.shortName,
+ pluginInfo.version,
+ pluginInfo.description,
+ pluginInfo.author,
+ pluginInfo.authorEmail,
+ pluginInfo.copyright,
+ pluginInfo.homepage,
+ pluginInfo.flags,
+ pluginInfo.replacesDefaultModule
+};
+
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
+{
+ return &oldpluginInfo;
+}
+
+extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
+{
+ static const MUUID interfaces[] = {MIID_RECENTCONTACTS, MIID_LAST};
+ return interfaces;
+}
+
+void LoadDBSettings()
+{
+ ZeroMemory(&LastUCOpt, sizeof(LastUCOpt));
+
+ LastUCOpt.MaxShownContacts = (INT)DBGetContactSettingByte( NULL, dbLastUC_ModuleName, dbLastUC_MaxShownContacts, 0 );
+ LastUCOpt.HideOffline = DBGetContactSettingByte( NULL, dbLastUC_ModuleName, dbLastUC_HideOfflineContacts, 0 );
+
+ DBVARIANT dbv;
+ dbv.type = DBVT_ASCIIZ;
+ dbv.pszVal = NULL;
+ if(db_get(NULL, dbLastUC_ModuleName, dbLastUC_DateTimeFormat, &dbv) == 0 && dbv.pszVal[0]!=0 )
+ {
+ LastUCOpt.DateTimeFormat = dbv.pszVal;
+
+ DBFreeVariant(&dbv);
+ }
+ else
+ {
+ LastUCOpt.DateTimeFormat = "(%Y-%m-%d %H:%M) ";
+ }
+
+}
+
+
+void ShowListMainDlgProc_AdjustListPos(HWND hDlg, LASTUC_DLG_DATA *DlgDat)
+{
+ HWND hList = GetDlgItem(hDlg, IDC_CONTACTS_LIST);
+ if(hList == NULL)
+ return;
+ RECT rc;
+ SIZE cur;
+ GetWindowRect(hDlg, &rc);
+ cur.cx = rc.right - rc.left;
+ cur.cy = rc.bottom - rc.top;
+ rc.left = DlgDat->ListUCRect.left;
+ rc.top = DlgDat->ListUCRect.top;
+ rc.right = DlgDat->ListUCRect.right + cur.cx - DlgDat->WindowMinSize.cx;
+ rc.bottom = DlgDat->ListUCRect.bottom + cur.cy - DlgDat->WindowMinSize.cy;
+ MoveWindow(hList, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
+ LVCOLUMN lvc;
+ ZeroMemory(&lvc, sizeof(lvc));
+ lvc.mask = LVCF_WIDTH;
+ lvc.cx = rc.right - rc.left - GetSystemMetrics(SM_CYHSCROLL) - 4;
+ if(lvc.cx < 10)
+ lvc.cx = 10;
+ ListView_SetColumn(hList, 0, &lvc);
+}
+
+BOOL ShowListMainDlgProc_OpenContact(HWND hList, int item)
+{
+ if(item != -1)
+ {
+ LVITEM lvi;
+ ZeroMemory(&lvi, sizeof(lvi));
+ lvi.mask = LVIF_PARAM;
+ lvi.lParam = NULL;
+ lvi.iItem = item;
+ lvi.iSubItem = 0;
+ ListView_GetItem(hList, &lvi);
+ if(lvi.lParam != NULL)
+ {
+// CallService(MS_MSG_SENDMESSAGE, (WPARAM)lvi.lParam, NULL);
+// CallService("SRMsg/LaunchMessageWindow", (WPARAM)lvi.lParam, NULL);
+ CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)lvi.lParam, NULL);
+
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+BOOL ShowListMainDlgProc_OpenContactMenu(HWND hDlg, HWND hList, int item, LASTUC_DLG_DATA *DlgDat)
+{
+ if(item != -1)
+ {
+ LVITEM lvi;
+ ZeroMemory(&lvi, sizeof(lvi));
+ lvi.mask = LVIF_PARAM;
+ lvi.lParam = NULL;
+ lvi.iItem = item;
+ lvi.iSubItem = 0;
+ ListView_GetItem(hList, &lvi);
+ if(lvi.lParam != NULL)
+ {
+ HMENU hCMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)lvi.lParam, NULL);
+ if(hCMenu != NULL)
+ {
+ POINT p;
+ GetCursorPos(&p);
+ DlgDat->hContact = (HANDLE) lvi.lParam;
+ BOOL ret = TrackPopupMenu(hCMenu, 0, p.x, p.y, 0, hDlg, NULL);
+ DestroyMenu(hCMenu);
+ if(ret)
+ return TRUE;
+ DlgDat->hContact = NULL;
+ }
+ }
+ }
+ return FALSE;
+}
+
+void wSetData(char **Data, const char *Value)
+{
+ if (Value[0] != 0)
+ {
+ char *newData = (char*)mir_alloc(strlen(Value)+3);
+ strcpy(newData, Value);
+ *Data = newData;
+ }
+ else
+ *Data = "";
+}
+void wfree(char **Data)
+{
+ if (*Data && strlen(*Data) > 0) mir_free(*Data);
+ *Data = NULL;
+}
+
+
+HWND hwndContactTree = NULL;
+
+BOOL WINAPI ShowListMainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ LASTUC_DLG_DATA *DlgDat;
+
+ DlgDat = (LASTUC_DLG_DATA *)GetWindowLong(hDlg, GWL_USERDATA);
+ HWND hList = GetDlgItem(hDlg, IDC_CONTACTS_LIST);
+ if(hList == NULL)
+ return FALSE;
+
+ switch( msg )
+ {
+ case WM_INITDIALOG:
+ {
+ RECT rc;
+ POINT p;
+ SAVEWINDOWPOS pos;
+
+ TranslateDialogDefault(hDlg);
+ DlgDat = new LASTUC_DLG_DATA;
+ ZeroMemory(DlgDat, sizeof(LASTUC_DLG_DATA));
+ DlgDat->Contacts = (cmultimap*)lParam;
+ GetWindowRect(hDlg, &rc);
+ DlgDat->WindowMinSize.cx = rc.right - rc.left;
+ DlgDat->WindowMinSize.cy = rc.bottom - rc.top;
+ GetWindowRect(hList, &DlgDat->ListUCRect);
+ p.x = DlgDat->ListUCRect.left;
+ p.y = DlgDat->ListUCRect.top;
+ ScreenToClient(hDlg, &p);
+ DlgDat->ListUCRect.left = p.x;
+ DlgDat->ListUCRect.top = p.y;
+ p.x = DlgDat->ListUCRect.right;
+ p.y = DlgDat->ListUCRect.bottom;
+ ScreenToClient(hDlg, &p);
+ DlgDat->ListUCRect.right = p.x;
+ DlgDat->ListUCRect.bottom = p.y;
+ SetWindowLong(hDlg, GWL_USERDATA, (LONG)DlgDat);
+
+ //set listview styles
+ ListView_SetExtendedListViewStyleEx(hList,
+ LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP
+ | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT, -1);
+
+ //LVBKIMAGE lvbki;
+ //ZeroMemory(&lvbki, sizeof(lvbki));
+ //lvbki.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_TILE;
+ //DBVARIANT dbv;
+ //dbv.type = DBVT_ASCIIZ;
+ //dbv.pszVal = NULL;
+ //db_get(NULL, "CLC", "BkBitmap", &dbv);
+ //if(dbv.pszVal != NULL)
+ //{
+ // if(ServiceExists(MS_UTILS_PATHTOABSOLUTE))
+ // {
+ // char szPath[MAX_PATH];
+ // if(CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)dbv.pszVal, (LPARAM)szPath))
+ // {
+ // lvbki.pszImage = szPath;
+ // ListView_SetBkImage(hList, &lvbki);
+ // }
+ // }
+ //}
+ //DBFreeVariant(&dbv);
+
+ // add header columns to listview
+ LVCOLUMN lvc;
+ ZeroMemory(&lvc, sizeof(lvc));
+ lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
+ lvc.fmt = LVCFMT_LEFT;
+ lvc.iSubItem = 0;
+ lvc.pszText = Translate(strLastUC_WndListHeadNameColumn);
+ lvc.cx = 10;
+ ListView_InsertColumn(hList, 0, &lvc);
+
+ // add conacts to listview
+ HIMAGELIST hImgList = (HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0);
+ if(hImgList != NULL)
+ ListView_SetImageList(hList, hImgList, LVSIL_SMALL);
+ LVITEM lvi;
+ ZeroMemory(&lvi, sizeof(lvi));
+ lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
+ cmultimap::iterator curContact;
+ int i;
+ string str;
+ char strtim[256 + 16];
+ char *cname;
+ string strtimformat;
+ DBVARIANT dbv;
+ dbv.type = DBVT_ASCIIZ;
+ dbv.pszVal = NULL;
+ if(db_get(NULL, dbLastUC_ModuleName, dbLastUC_DateTimeFormat, &dbv) == 0)
+ {
+ strtimformat = dbv.pszVal;
+ DBFreeVariant(&dbv);
+ }
+ else
+ strtimformat = dbLastUC_DateTimeFormatDefault;
+
+// strtimformat = LastUCOpt.DateTimeFormat;
+ //if(db_get(NULL, dbLastUC_ModuleName, dbLastUC_MaxShownContacts, &dbv) == 0)
+ //{
+ // strtimformat = dbv.bVal;
+ // DBFreeVariant(&dbv);
+ //}
+// MaxShownContacts = db_byte_get(NULL, dbLastUC_ModuleName, dbLastUC_MaxShownContacts, 0);
+// HideOfflineContacts = db_byte_get(NULL, dbLastUC_ModuleName, dbLastUC_HideOfflineContacts, 0);
+
+ for(i = 0, curContact = DlgDat->Contacts->begin(); curContact != DlgDat->Contacts->end(); curContact++)
+ {
+ if(curContact->second != NULL && db_byte_get(curContact->second, dbLastUC_ModuleName, dbLastUC_IgnoreContact, 0) == 0 )
+ {
+
+ lvi.iItem = i;
+ lvi.iSubItem = 0;
+ lvi.lParam = (LPARAM)curContact->second;
+ if((cname = (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)curContact->second, 0)) != NULL)
+ {
+ if (LastUCOpt.HideOffline == 1) {
+ szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)curContact->second, 0);
+ if (szProto !=NULL && DBGetContactSettingWord((HANDLE)curContact->second, szProto, "Status", ID_STATUS_OFFLINE)== ID_STATUS_OFFLINE)
+ continue;
+ }
+ strftime(strtim, 256, strtimformat.c_str(), _localtime64(&curContact->first));
+ strtim[255] = 0;
+ str = strtim;
+ str += cname;
+ lvi.pszText = (LPSTR)str.c_str();
+ lvi.iImage = CallService(MS_CLIST_GETCONTACTICON, (WPARAM)curContact->second, 0);
+ ListView_InsertItem(hList, &lvi);
+ i++;
+ }
+ }
+ if (LastUCOpt.MaxShownContacts > 0 && i >= LastUCOpt.MaxShownContacts)
+ break;
+ }
+
+ pos.hContact = NULL;
+ pos.hwnd = hDlg;
+ pos.szModule = dbLastUC_ModuleName;
+ pos.szNamePrefix = dbLastUC_WindowPosPrefix;
+ CallService(MS_UTILS_RESTOREWINDOWPOSITION, 0, (LPARAM)(SAVEWINDOWPOS*)&pos);
+ SendMessage(hDlg, WM_SIZE, 0, 0);
+ WindowList_Add(hWindowList, hDlg, NULL);
+
+ return TRUE;
+ }
+
+ case WM_ACTIVATE:
+ {
+ if(LOWORD(wParam) == WA_INACTIVE)
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ LPNMHDR lpNmhdr;
+ lpNmhdr = (LPNMHDR)lParam;
+ if(lpNmhdr->hwndFrom == hList)
+ {
+ if(lpNmhdr->code == NM_CLICK || lpNmhdr->code == NM_RCLICK)
+ {
+ RECT r;
+ POINT p;
+ GetCursorPos(&p);
+ GetWindowRect(hList, &r);
+ if(PtInRect(&r, p))
+ {
+ LVHITTESTINFO lvh;
+ ZeroMemory(&lvh, sizeof(lvh));
+ lvh.pt = p;
+ ScreenToClient(hList, &lvh.pt);
+ ListView_HitTest(hList, &lvh);
+ if((lvh.flags & (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)) &&
+ lvh.iItem != -1)
+ {
+ if(lpNmhdr->code == NM_CLICK)
+ {
+ if(ShowListMainDlgProc_OpenContact(hList, lvh.iItem))
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
+ }
+ else
+ {
+ ShowListMainDlgProc_OpenContactMenu(hDlg, hList, lvh.iItem, DlgDat);
+ }
+ }
+ }
+ }
+ else if(lpNmhdr->code == NM_RETURN)
+ {
+ if(ShowListMainDlgProc_OpenContact(hList, ListView_GetNextItem(hList, -1, LVIS_SELECTED)))
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
+ }
+ }
+ break;
+ }
+
+ case WM_MEASUREITEM:
+ {
+ return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);
+ }
+
+ case WM_DRAWITEM:
+ {
+ return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);
+ }
+
+ case WM_COMMAND:
+ {
+ if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)DlgDat->hContact))
+ break;
+
+ switch(wParam)
+ {
+ case IDOK:
+ ShowListMainDlgProc_OpenContact(hList, ListView_GetNextItem(hList, -1, LVIS_SELECTED));
+ case IDCANCEL:
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
+ break;
+ }
+ break;
+ }
+
+ case WM_GETMINMAXINFO:
+ {
+ MINMAXINFO *mmi = (MINMAXINFO *) lParam;
+ mmi->ptMinTrackSize.x = 100;
+ mmi->ptMinTrackSize.y = 150;
+ return 0;
+ }
+
+
+ case WM_SIZE:
+ {
+ ShowListMainDlgProc_AdjustListPos(hDlg, DlgDat);
+ break;
+ }
+
+ case WM_CLOSE:
+ {
+ DestroyWindow(hDlg);
+ break;
+ }
+
+ case WM_DESTROY:
+ {
+ // Save current window position.
+ SAVEWINDOWPOS pos;
+ pos.hContact = NULL;
+ pos.hwnd = hDlg;
+ pos.szModule = dbLastUC_ModuleName;
+ pos.szNamePrefix = dbLastUC_WindowPosPrefix;
+ CallService(MS_UTILS_SAVEWINDOWPOSITION, 0, (LPARAM)(SAVEWINDOWPOS*)&pos);
+ delete DlgDat->Contacts;
+ delete DlgDat;
+ // Remove entry from Window list
+ WindowList_Remove(hWindowList, hDlg);
+ break;
+ }
+
+ }
+ return FALSE;
+}
+
+
+int OnMenuCommandShowList(WPARAM wParam, LPARAM lParam)
+{
+ cmultimap *contacts = new cmultimap;
+
+ __time64_t curTime;
+ //DWORD t;
+ DBEVENTINFO dbe;
+ ZeroMemory(&dbe, sizeof(dbe));
+ dbe.cbSize = sizeof(dbe);
+ BYTE buf[1];
+ dbe.pBlob = buf;
+ HANDLE curEvent;
+ HANDLE curContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
+ for(; curContact != NULL; curContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)curContact, 0))
+ {
+// if(IsMessageAPI)
+ {
+ curTime = ((__time64_t)db_dword_get(curContact, dbLastUC_ModuleName, dbLastUC_LastUsedTimeLo, -1)) |
+ (((__time64_t)db_dword_get(curContact, dbLastUC_ModuleName, dbLastUC_LastUsedTimeHi, -1)) << 32);
+ //use TabSRMM last used time. ! NOT used, because bug: TabSRMM reset last used time to time when miranda started at miranda start!
+ //t = ((DWORD)db_dword_get(curContact, "Tab_SRMsg", "isRecent", -1));
+ //if(t != -1)
+ //{
+ // if(curTime == -1 || (__time64_t)t > curTime)
+ // curTime = (__time64_t)t;
+ //}
+ }
+// else
+ {
+ curEvent = (HANDLE)CallService(MS_DB_EVENT_FINDLAST, (WPARAM)curContact, 0);
+ if(curEvent != NULL)
+ {
+ for( ; curEvent != NULL; curEvent = (HANDLE)CallService(MS_DB_EVENT_FINDPREV, (WPARAM)curEvent, 0))
+ {
+ dbe.cbBlob = 1;
+ if(CallService(MS_DB_EVENT_GET, (WPARAM)curEvent, (LPARAM)&dbe) != 0)
+ {
+ curEvent = NULL;
+ break;
+ }
+ if((dbe.flags & (DBEF_READ | DBEF_SENT)) && dbe.eventType < 2000)
+ break;
+ }
+ if(curEvent != NULL)
+ if(curTime == -1 || (__time64_t)dbe.timestamp > curTime)
+ curTime = (__time64_t)dbe.timestamp;
+ }
+ }
+ if(curTime != -1)
+ contacts->insert(cpair(curTime, curContact));
+ }
+
+ HWND hWndMain;
+ if((hWndMain = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_LASTUC_DIALOG), NULL, ShowListMainDlgProc, (LPARAM)contacts)) == NULL)
+ {
+ //delete contacts;
+ return -1;
+ }
+ ShowWindow(hWndMain, SW_SHOW);
+
+ if(hTopToolbarButtonShowList != NULL)
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTopToolbarButtonShowList, TTBST_RELEASED);
+ return 0;
+}
+
+static int OnContactSettingChanged( WPARAM wParam, LPARAM lParam )
+{
+ HANDLE hContact = ( HANDLE )wParam;
+ DBCONTACTWRITESETTING* pdbcws = ( DBCONTACTWRITESETTING* )lParam;
+
+ if ( hContact == NULL )
+ {
+ if(( 0 == stricmp( pdbcws->szModule, dbLastUC_ModuleName) ) ){
+ LoadDBSettings();
+// ApplyOptionsChanges();
+ }
+ }
+ return (0);
+}
+
+
+int Create_TopToolbarShowList(WPARAM wParam, LPARAM lParam)
+{
+ if (ServiceExists(MS_TTB_ADDBUTTON))
+ {
+ TTBButton ttbb;
+
+ ZeroMemory(&ttbb, sizeof(ttbb));
+ ttbb.cbSize = sizeof(ttbb);
+ ttbb.hbBitmapUp =
+ ttbb.hbBitmapDown = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_CMD_SHOWLASTUSED));
+ ttbb.pszServiceUp =
+ ttbb.pszServiceDown = msLastUC_ShowList;
+ ttbb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP|TTBBF_DRAWBORDER;
+ ttbb.name = Translate(msLastUC_ShowListName);
+
+ hTopToolbarButtonShowList = (HANDLE)CallService(MS_TTB_ADDBUTTON, (WPARAM)&ttbb, 0);
+ if((int)hTopToolbarButtonShowList == -1)
+ hTopToolbarButtonShowList = NULL;
+ }
+
+ return 0;
+}
+
+int Create_MenuitemShowList(void)
+{
+ CLISTMENUITEM mi;
+
+ //int ignored = DBGetContactSettingByte()
+
+// mi.ptszName = fcOpt.bHideAll ? _T("Show all thumbs") : _T("Hide all thumbs");
+
+ ZeroMemory(&mi, sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 0;
+ mi.flags = 0;
+// mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SHOWRECENT));
+// mi.hIcon = LoadIconExEx( "recent_main", IDI_SHOWRECENT );
+ mi.hIcon = ( HICON )CallService( MS_SKIN2_GETICON, 0, ( LPARAM )"recent_main" );
+
+ mi.pszName = Translate(msLastUC_ShowListName);
+ mi.pszService = msLastUC_ShowList;
+
+ CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM)&mi);
+
+ ZeroMemory( &mi,sizeof( mi ) );
+
+ mi.cbSize = sizeof( mi );
+ mi.position = 0xFFFFF;
+// mi.flags = CMIF_TCHAR;
+ mi.hIcon = ( HICON )CallService( MS_SKIN2_GETICON, 0, ( LPARAM )"recent_main" );
+ mi.ptszName = _T("Toggle Ignore");
+ mi.pszService = V_RECENTCONTACTS_TOGGLE_IGNORE;
+ //hMenuItemRemove = (HANDLE)CallService( MS_CLIST_ADDCONTACTMENUITEM,0, ( LPARAM )&mi );
+ hMenuItemRemove = (HANDLE)CallService( MS_CLIST_ADDCONTACTMENUITEM,0, ( LPARAM )&mi );
+
+ return 0;
+}
+
+BOOL SaveLastUsedTimeStamp(HANDLE hContact)
+{
+ __time64_t ct = _time64(NULL);
+ db_dword_set(hContact, dbLastUC_ModuleName, dbLastUC_LastUsedTimeLo, (DWORD)ct);
+ db_dword_set(hContact, dbLastUC_ModuleName, dbLastUC_LastUsedTimeHi, (DWORD)(ct >> 32));
+ return TRUE;
+}
+
+//HICON LoadIconExEx( const char* IcoLibName, int NonIcoLibIcon )
+//{
+// if ( ServiceExists( MS_SKIN2_GETICON ) ) {
+// char szSettingName[64];
+// mir_snprintf( szSettingName, sizeof( szSettingName ), "%s", IcoLibName );
+// return ( HICON )CallService( MS_SKIN2_GETICON, 0, ( LPARAM )szSettingName );
+// }
+// else
+// return ( HICON )LoadImage( hInst, MAKEINTRESOURCE( NonIcoLibIcon ), IMAGE_ICON, 0, 0, 0 );
+//}
+
+
+int OnMsgEvent(WPARAM wParam, LPARAM lParam)
+{
+ MessageWindowEventData *ed = (MessageWindowEventData *)lParam;
+// char str[40]; LoadSkinnedIcon
+// sprintf(str, "%i", ed->uType);
+// db_msg_dbg(str);
+ if(ed->hContact == NULL)
+ return 0;
+ if(ed->uType == MSG_WINDOW_EVT_OPEN)
+ SaveLastUsedTimeStamp(ed->hContact);
+ else if(ed->uType == MSG_WINDOW_EVT_CUSTOM)
+ {
+ struct TABSRMM_SessionInfo *si = (struct TABSRMM_SessionInfo*) ed->local;
+ if(si != NULL)
+ {
+ if(si->evtCode == tabMSG_WINDOW_EVT_CUSTOM_BEFORESEND)
+ SaveLastUsedTimeStamp(ed->hContact);
+ }
+ }
+ return 0;
+}
+
+static void iconsInit(void)
+{
+ SKINICONDESC sid = {0};
+ char szFile[MAX_PATH];
+ sid.cbSize = SKINICONDESC_SIZE_V1;
+
+ sid.pszSection = Translate(msLastUC_ShowListName);
+ GetModuleFileNameA(hInst, szFile, MAX_PATH);
+ sid.pszDefaultFile = szFile;
+
+ sid.pszDescription = Translate(msLastUC_IconName);
+ sid.pszName = "recent_main";
+ sid.iDefaultIndex = -IDI_SHOWRECENT;
+ CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
+ }
+
+static int OnPrebuildContactMenu (WPARAM wParam, LPARAM lParam)
+{
+ CLISTMENUITEM clmi;
+
+ ZeroMemory( &clmi, sizeof( clmi ) );
+ clmi.cbSize = sizeof( clmi );
+ clmi.flags = CMIM_NAME;
+
+ if (DBGetContactSettingByte((HANDLE)wParam, dbLastUC_ModuleName, dbLastUC_IgnoreContact, 0) == 0)
+ {
+ clmi.pszName = _T("Ignore Contact");
+ }
+ else
+ {
+ clmi.pszName = _T("Show Contact");
+ }
+
+ CallService( MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItemRemove, (LPARAM)&clmi );
+
+ return 0;
+
+}
+
+
+int OnModulesLoaded(WPARAM wParam, LPARAM lParam)
+{
+ iconsInit();
+ Create_MenuitemShowList();
+ IsMessageAPI = (CallService(MS_MSG_GETWINDOWAPI, 0, 0) != CALLSERVICE_NOTFOUND);
+ //maxShownContacts = ;
+ LoadDBSettings();
+
+
+
+ if ( ServiceExists(MS_UPDATE_REGISTER))
+ {
+ Update update = {0};
+ char szVersion[16];
+
+ update.cbSize = sizeof(Update);
+
+ update.szComponentName = pluginInfo.shortName;
+ update.pbVersion = (BYTE *)CreateVersionString(pluginInfo.version, szVersion);
+ update.cpbVersion = strlen((char *)update.pbVersion);
+
+ update.szUpdateURL = UPDATER_AUTOREGISTER;
+
+ // these are the three lines that matter - the archive, the page containing the version string, and the text (or data)
+ // before the version that we use to locate it on the page
+ // (note that if the update URL and the version URL point to standard file listing entries, the backend xml
+ // data will be used to check for updates rather than the actual web page - this is not true for beta urls)
+ update.szBetaUpdateURL = "http://kildor.miranda.im/miranda/recentcontacts.zip";
+ update.szBetaVersionURL = "http://kildor.miranda.im/miranda/recentcontacts.txt";
+ update.szBetaChangelogURL = "http://kildor.miranda.im/miranda/recentcontacts_changes.txt";
+ update.pbBetaVersionPrefix = (BYTE *)"RecentContacts ";
+ update.cpbBetaVersionPrefix = strlen((char *)update.pbBetaVersionPrefix);
+
+ CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
+ }
+#if 0
+ if (ServiceExists(MS_FONT_REGISTERT))
+ {
+ FontIDT fid={0};
+
+ fid.cbSize=sizeof(fid);
+ fid.group = _T("Console");
+ fid.name,TranslateT = "Text";
+ fid.dbSettingsGroup = "Console";
+ fid.prefix = "ConsoleFont";
+
+ fid.backgroundGroup = _T("Console");
+ fid.backgroundName = _T("Background");
+
+ fid.flags = FIDF_DEFAULTVALID;
+
+ fid.deffontsettings.charset = DEFAULT_CHARSET;
+ fid.deffontsettings.colour = RGB(0, 0, 0);
+ fid.deffontsettings.size = 10;
+ fid.deffontsettings.style = 0;
+ _tcsncpy(fid.deffontsettings.szFace, _T("Tahoma"), LF_FACESIZE);
+
+ CallService(MS_FONT_REGISTERT,(WPARAM)&fid,0);
+
+ hHooks[i++] = HookEvent(ME_FONT_RELOAD,OnFontChange);
+ }
+
+#endif
+
+ if (ServiceExists(MS_HOTKEY_REGISTER))
+ { // hotkeys
+ HOTKEYDESC hotkey = {0};
+ hotkey.cbSize = sizeof(hotkey);
+ hotkey.pszName = msLastUC_ShowList;
+ hotkey.pszDescription = msLastUC_HotkeyName;
+ hotkey.pszSection = "Contacts";
+ hotkey.pszService = msLastUC_ShowList;
+ hotkey.DefHotKey = MAKEWORD('R', HOTKEYF_CONTROL | HOTKEYF_SHIFT);
+ CallService(MS_HOTKEY_REGISTER, 0, (LPARAM)&hotkey);
+ }
+
+ return 0;
+}
+
+
+int ToggleIgnore (WPARAM wParam, LPARAM lParam)
+{
+ if (wParam != NULL)
+ {
+ int state;
+ HANDLE hContact = ( HANDLE )wParam;
+ state = DBGetContactSettingByte(hContact, dbLastUC_ModuleName, dbLastUC_IgnoreContact, 0) == 0 ? 1 : 0 ;
+ DBWriteContactSettingByte(hContact, dbLastUC_ModuleName, dbLastUC_IgnoreContact, state);
+ return state;
+ }
+ return -1;
+
+}
+
+
+
+#ifdef __cplusplus
+extern "C"
+#endif
+__declspec(dllexport) int Load(PLUGINLINK *link)
+{
+ int i = 0, h = 0;
+ pluginLink = link;
+ CoInitialize(NULL);
+ hWindowList=(HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST,0,0);
+// InitOptions();
+ hLastUC_ServiceList[i++] = CreateServiceFunction(msLastUC_ShowList, OnMenuCommandShowList);
+ hLastUC_ServiceList[i++] = CreateServiceFunction(V_RECENTCONTACTS_TOGGLE_IGNORE, ToggleIgnore);
+ hLastUC_HooksList[h++] = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+ hLastUC_HooksList[h++] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu );
+ hLastUC_HooksList[h++] = HookEvent(ME_TTB_MODULELOADED, Create_TopToolbarShowList);
+ hLastUC_HooksList[h++] = HookEvent(ME_MSG_WINDOWEVENT, OnMsgEvent);
+ hLastUC_HooksList[h++] = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged );
+ hLastUC_HooksList[h++] = HookEvent(ME_OPT_INITIALISE, onOptInitialise);
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+#endif
+__declspec(dllexport) int Unload(void)
+{
+ int i;
+
+ for (i=0; i<sizeof(hLastUC_ServiceList); ++i)
+ if (hLastUC_ServiceList[i])
+ DestroyServiceFunction(hLastUC_ServiceList[i]);
+
+ for (i=0; i<sizeof(hLastUC_HooksList); ++i)
+ if (hLastUC_HooksList[i])
+ UnhookEvent(hLastUC_HooksList[i]);
+
+
+ CoUninitialize();
+ return 0;
+}