int fnTrayCalcChanged(const char *szChangedProto, int averageMode, int netProtoCount) { if (netProtoCount == 0) return cli.pfnTrayIconSetBaseInfo(ImageList_GetIcon(hCListImages, cli.pfnIconFromStatusMode(NULL, averageMode, NULL), ILD_NORMAL), NULL); int trayIconSetting = db_get_b(NULL, "CList", "TrayIcon", SETTING_TRAYICON_DEFAULT); if (averageMode > 0) { if (trayIconSetting != SETTING_TRAYICON_MULTI) return cli.pfnTrayIconSetBaseInfo(cli.pfnGetIconFromStatusMode(NULL, NULL, averageMode), NULL); if (db_get_b(NULL, "CList", "AlwaysMulti", SETTING_ALWAYSMULTI_DEFAULT)) return cli.pfnTrayIconSetBaseInfo(cli.pfnGetIconFromStatusMode(NULL, szChangedProto, CallProtoServiceInt(NULL, szChangedProto, PS_GETSTATUS, 0, 0)), (char*)szChangedProto); if (cli.trayIcon == NULL || cli.trayIcon[0].szProto == NULL) return cli.pfnTrayIconSetBaseInfo(cli.pfnGetIconFromStatusMode(NULL, NULL, averageMode), NULL); cli.pfnTrayIconDestroy(cli.hwndContactList); cli.pfnTrayIconInit(cli.hwndContactList); } else { switch (trayIconSetting) { case SETTING_TRAYICON_CYCLE: cli.cycleTimerId = SetTimer(NULL, 0, db_get_w(NULL, "CList", "CycleTime", SETTING_CYCLETIME_DEFAULT) * 1000, cli.pfnTrayCycleTimerProc); return cli.pfnTrayIconSetBaseInfo(ImageList_GetIcon (hCListImages, cli.pfnIconFromStatusMode(szChangedProto, CallProtoServiceInt(NULL, szChangedProto, PS_GETSTATUS, 0, 0), NULL), ILD_NORMAL), NULL); case SETTING_TRAYICON_MULTI: if (!cli.trayIcon) cli.pfnTrayIconRemove(NULL, NULL); else if ((cli.trayIconCount > 1 || netProtoCount == 1) || db_get_b(NULL, "CList", "AlwaysMulti", SETTING_ALWAYSMULTI_DEFAULT)) return cli.pfnTrayIconSetBaseInfo(cli.pfnGetIconFromStatusMode(NULL, szChangedProto, CallProtoServiceInt(NULL, szChangedProto, PS_GETSTATUS, 0, 0)), (char*)szChangedProto); else { cli.pfnTrayIconDestroy(cli.hwndContactList); cli.pfnTrayIconInit(cli.hwndContactList); } break; case SETTING_TRAYICON_SINGLE: ptrA szProto(db_get_sa(NULL, "CList", "PrimaryStatus")); return cli.pfnTrayIconSetBaseInfo(cli.pfnGetIconFromStatusMode(NULL, szProto, szProto ? CallProtoServiceInt(NULL, szProto, PS_GETSTATUS, 0, 0) : CallService(MS_CLIST_GETSTATUSMODE, 0, 0)), szProto); } } return -1; }
int CVkProto::OnDbEventRead(WPARAM, LPARAM hDbEvent) { debugLogA("CVkProto::OnDbEventRead"); MCONTACT hContact = db_event_getContact(hDbEvent); if (!hContact) return 0; CMStringA szProto(ptrA(db_get_sa(hContact, "Protocol", "p"))); if (szProto.IsEmpty() || szProto != m_szModuleName) return 0; if (m_vkOptions.iMarkMessageReadOn == MarkMsgReadOn::markOnRead) MarkMessagesRead(hContact); return 0; }
static TCHAR* parseProtoInfo(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; char *szRes = NULL; TCHAR *tszRes = NULL; ptrA szProto(mir_t2a(ai->targv[1])); if (!mir_tstrcmp(ai->targv[2], _T(STR_PINAME))) tszRes = Hlp_GetProtocolName(szProto); else if (!mir_tstrcmp(ai->targv[2], _T(STR_PIUIDTEXT))) { szRes = (char *)CallProtoService(szProto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDTEXT, 0); if (INT_PTR(szRes) == CALLSERVICE_NOTFOUND) return NULL; } else if (!mir_tstrcmp(ai->targv[2], _T(STR_PIUIDSETTING))) { szRes = (char *)CallProtoService(szProto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); if (INT_PTR(szRes) == CALLSERVICE_NOTFOUND) return NULL; } else if (!mir_tstrcmp(ai->targv[2], _T(STR_PINICK))) { CONTACTINFO ci; ci.cbSize = sizeof(CONTACTINFO); ci.dwFlag = CNF_DISPLAY | CNF_UNICODE; ci.hContact = NULL; ci.szProto = szProto; CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); tszRes = ci.pszVal; } if (szRes == NULL && tszRes == NULL) return NULL; if (szRes != NULL && tszRes == NULL) tszRes = mir_a2t(szRes); return tszRes; }
int cliTrayIconInit(HWND hwnd) { BYTE Mode; if (pcli->trayIconCount != 0) return 0; if (TimerID) { KillTimer(NULL, TimerID); TimerID = 0; } // Присутствуют ли в базе новые настройки? Если да, то обновление не нужно. if (-1 == db_get_b(NULL, "CList", "tiModeS", -1)) SettingsMigrate(); // Нужно узнать количество годных аккаунтов и неодинаковость их статусов. bool bDiffers; pcli->trayIconCount = GetGoodAccNum(&bDiffers, NULL); // Если таковых аккаунтов не нашлось вообще, то будем показывать основную иконку Миранды. if (!pcli->trayIconCount) { pcli->trayIconCount = 1; pcli->trayIcon = (trayIconInfo_t*)mir_calloc(sizeof(trayIconInfo_t) * pcli->trayIconCount); pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); OldMode = TRAY_ICON_MODE_GLOBAL; return 0; } if (!bDiffers) // all equal OldMode = Mode = db_get_b(NULL, "CList", "tiModeS", TRAY_ICON_MODE_GLOBAL); else OldMode = Mode = db_get_b(NULL, "CList", "tiModeV", TRAY_ICON_MODE_GLOBAL); // Некоторые режимы всегда показывают единственную иконку. if (Mode < 8) pcli->trayIconCount = 1; pcli->trayIcon = (trayIconInfo_t*)mir_calloc(sizeof(trayIconInfo_t) * pcli->trayIconCount); // Добавляем иконки. switch (Mode) { case TRAY_ICON_MODE_GLOBAL: pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); break; case TRAY_ICON_MODE_ACC: { ptrA szProto(db_get_sa(NULL, "CList", (!bDiffers) ? "tiAccS" : "tiAccV")); if (!szProto) break; PROTOACCOUNT *pa = Proto_GetAccount(szProto); if (!pa || !pa->ppro) pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); else pcli->pfnTrayIconAdd(hwnd, pa->szModuleName, NULL, pa->ppro->m_iStatus); } break; case TRAY_ICON_MODE_CYCLE: pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); pcli->cycleStep = 0; cliTrayCycleTimerProc(0, 0, 0, 0); // force icon update // Не сохраняем ID таймера в pcli, чтобы fnTrayIconUpdateBase не убивала его. TimerID = CLUI_SafeSetTimer(NULL, 0, db_get_w(NULL, "CList", "CycleTime", SETTING_CYCLETIME_DEFAULT) * 1000, cliTrayCycleTimerProc); break; case TRAY_ICON_MODE_ALL: PROTOACCOUNT **acc; int AccNum, i; Proto_EnumAccounts(&AccNum, &acc); for (i = AccNum; i--;) { if (!acc[i]->bIsVirtual && acc[i]->bIsVisible && !acc[i]->bDynDisabled && acc[i]->ppro) pcli->pfnTrayIconAdd(hwnd, acc[i]->szModuleName, NULL, acc[i]->ppro->m_iStatus); } break; } return 0; }
INT_PTR CALLBACK AddContactDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { AddDialogParam *acs = (AddDialogParam*)GetWindowLongPtr(hdlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: acs = new AddDialogParam(); acs->handleType = HANDLE_SEARCHRESULT; SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR)acs); Utils_RestoreWindowPositionNoSize(hdlg, NULL, "AddContact", ""); TranslateDialogDefault(hdlg); SendMessage(hdlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(ICON_ADD,1)); SendMessage(hdlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(ICON_ADD)); HookEventMessage(ME_SKIN2_ICONSCHANGED, hdlg, DM_ADDCONTACT_CHANGEICONS); HookEventMessage(ME_PROTO_ACCLISTCHANGED, hdlg, DM_ADDCONTACT_CHANGEACCLIST); { TCHAR *szGroup; for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) { int id = SendDlgItemMessage(hdlg, IDC_GROUP, CB_ADDSTRING, 0, (LPARAM)szGroup); SendDlgItemMessage(hdlg, IDC_GROUP, CB_SETITEMDATA, (WPARAM)id, (LPARAM)i); } } SendDlgItemMessage(hdlg, IDC_GROUP, CB_INSERTSTRING, 0, (LPARAM)TranslateT("None")); SendDlgItemMessage(hdlg, IDC_GROUP, CB_SETCURSEL, 0, 0); { ptrA szProto(db_get_sa(NULL, "AddContact", "LastProto")); if (szProto) acs->proto = szProto; } if (AddContactDlgAccounts(hdlg, acs)) { // By default check these checkboxes CheckDlgButton(hdlg, IDC_ADDED, BST_CHECKED); CheckDlgButton(hdlg, IDC_AUTH, BST_CHECKED); AddContactDlgOpts(hdlg, acs->proto); EnableWindow(GetDlgItem(hdlg, IDOK), FALSE); } break; case WM_COMMAND: switch (LOWORD(wparam)) { case IDC_USERID: if (HIWORD(wparam) == EN_CHANGE) { TCHAR szUserId[256]; if (GetDlgItemText(hdlg, IDC_USERID, szUserId, SIZEOF(szUserId))) { if (!IsWindowEnabled(GetDlgItem(hdlg, IDOK))) EnableWindow(GetDlgItem(hdlg, IDOK), TRUE); } else if (IsWindowEnabled(GetDlgItem(hdlg, IDOK))) EnableWindow(GetDlgItem(hdlg, IDOK), FALSE); } break; case IDC_PROTO: if (HIWORD(wparam) == CBN_SELCHANGE || HIWORD(wparam) == CBN_SELENDOK) { acs->proto = (char*)SendDlgItemMessage(hdlg, IDC_PROTO, CB_GETITEMDATA, (WPARAM)SendDlgItemMessage(hdlg, IDC_PROTO, CB_GETCURSEL, 0, 0), 0); // TODO remember last setting for each proto? AddContactDlgOpts(hdlg, acs->proto); } break; case IDC_ADDTEMP: AddContactDlgOpts(hdlg, acs->proto, TRUE); break; case IDC_AUTH: { DWORD flags = CallProtoService(acs->proto, PS_GETCAPS, PFLAGNUM_4, 0); if (flags & PF4_NOCUSTOMAUTH) { EnableWindow(GetDlgItem(hdlg, IDC_AUTHREQ), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_AUTHGB), FALSE); } else { EnableWindow(GetDlgItem(hdlg, IDC_AUTHREQ), IsDlgButtonChecked(hdlg, IDC_AUTH)); EnableWindow(GetDlgItem(hdlg, IDC_AUTHGB), IsDlgButtonChecked(hdlg, IDC_AUTH)); } } break; case IDOK: { TCHAR szUserId[256]; GetDlgItemText(hdlg, IDC_USERID, szUserId, SIZEOF(szUserId)); if (*rtrimt(szUserId) == 0 || (strstr(acs->proto, "GG") && _tcstoul(szUserId, NULL, 10) > INT_MAX) || // Gadu-Gadu protocol ((CallProtoService(acs->proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_NUMERICUSERID) && !_tcstoul(szUserId, NULL, 10))) { MessageBox(NULL, TranslateT("The contact cannot be added to your contact list. Please make sure the contact ID is entered correctly."), TranslateT("Add contact"), MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); break; } PROTOSEARCHRESULT *psr; if (strstr(acs->proto, "TLEN")) { // Tlen protocol if (_tcschr(szUserId, '@') == NULL) { MessageBox(NULL, TranslateT("The contact cannot be added to your contact list. Please make sure the contact ID is entered correctly."), TranslateT("Add contact"), MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); break; } psr = (PROTOSEARCHRESULT*)mir_calloc(sizeof(TLEN_SEARCH_RESULT)); psr->cbSize = sizeof(TLEN_SEARCH_RESULT); mir_snprintf(((TLEN_SEARCH_RESULT*)psr)->jid, SIZEOF(((TLEN_SEARCH_RESULT*)psr)->jid), "%S", szUserId); } else { psr = (PROTOSEARCHRESULT*)mir_calloc(sizeof(PROTOSEARCHRESULT)); psr->cbSize = sizeof(PROTOSEARCHRESULT); } psr->flags = PSR_TCHAR; psr->id = mir_tstrdup(szUserId); acs->psr = psr; HANDLE hContact = (HANDLE)CallProtoService(acs->proto, PS_ADDTOLIST, IsDlgButtonChecked(hdlg, IDC_ADDTEMP) ? PALF_TEMPORARY : 0, (LPARAM)acs->psr); if (hContact == NULL) { MessageBox(NULL, TranslateT("The contact cannot be added to your contact list. If you are not logged into the selected account, please try to do so. Also, make sure the contact ID is entered correctly."), TranslateT("Add contact"), MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); break; } TCHAR szHandle[256]; if (GetDlgItemText(hdlg, IDC_MYHANDLE, szHandle, SIZEOF(szHandle))) db_set_ts(hContact, "CList", "MyHandle", szHandle); int item = SendDlgItemMessage(hdlg, IDC_GROUP, CB_GETCURSEL, 0, 0); if (item > 0) { item = SendDlgItemMessage(hdlg, IDC_GROUP, CB_GETITEMDATA, item, 0); CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)hContact, item); } if (!IsDlgButtonChecked(hdlg, IDC_ADDTEMP)) { db_unset(hContact, "CList", "NotOnList"); if (IsDlgButtonChecked(hdlg, IDC_ADDED)) CallContactService(hContact, PSS_ADDED, 0, 0); if (IsDlgButtonChecked(hdlg, IDC_AUTH)) { DWORD flags = CallProtoService(acs->proto, PS_GETCAPS, PFLAGNUM_4, 0); if (flags & PF4_NOCUSTOMAUTH) CallContactService(hContact, PSS_AUTHREQUESTT, 0, 0); else { TCHAR szReason[512]; GetDlgItemText(hdlg, IDC_AUTHREQ, szReason, SIZEOF(szReason)); CallContactService(hContact, PSS_AUTHREQUESTT, 0, (LPARAM)szReason); } } } if (GetAsyncKeyState(VK_CONTROL)) CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)(const char*)NULL); } // fall through case IDCANCEL: if (GetParent(hdlg) == NULL) DestroyWindow(hdlg); else EndDialog(hdlg, 0); } break; case WM_CLOSE: /* if there is no parent for the dialog, its a modeless dialog and can't be killed using EndDialog() */ if (GetParent(hdlg) == NULL) DestroyWindow(hdlg); else EndDialog(hdlg, 0); break; case DM_ADDCONTACT_CHANGEICONS: Skin_ReleaseIcon((HICON)SendMessage(hdlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(ICON_ADD, 1))); Skin_ReleaseIcon((HICON)SendMessage(hdlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(ICON_ADD))); break; case DM_ADDCONTACT_CHANGEACCLIST: AddContactDlgAccounts(hdlg, acs); break; case WM_DESTROY: hAddDlg = NULL; Skin_ReleaseIcon((HICON)SendMessage(hdlg, WM_SETICON, ICON_BIG, 0)); Skin_ReleaseIcon((HICON)SendMessage(hdlg, WM_SETICON, ICON_SMALL, 0)); ImageList_Destroy((HIMAGELIST)SendDlgItemMessage(hdlg, IDC_PROTO, CBEM_GETIMAGELIST, 0, 0)); if (acs) { db_set_s(NULL, "AddContact", "LastProto", acs->proto); if (acs->psr) { mir_free(acs->psr->nick); mir_free(acs->psr->firstName); mir_free(acs->psr->lastName); mir_free(acs->psr->email); mir_free(acs->psr); } delete acs; } Utils_SaveWindowPosition(hdlg, NULL, "AddContact", ""); break; } return FALSE; }
int TrayCalcChanged(const char *szChangedProto, int averageMode, int netProtoCount) { HICON hIcon; int iIcon; HWND hwnd = pcli->hwndContactList; if (netProtoCount > 1) { if (averageMode > 0) { if (cfg::getByte("CList", "TrayIcon", SETTING_TRAYICON_DEFAULT) == SETTING_TRAYICON_MULTI) { if (cfg::getByte("CList", "AlwaysMulti", SETTING_ALWAYSMULTI_DEFAULT)) { iIcon = IconFromStatusMode(szChangedProto, averageMode, 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, szChangedProto); } if (pcli->trayIcon == NULL || pcli->trayIcon[0].szProto == NULL) { iIcon = IconFromStatusMode(NULL, averageMode, 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, NULL); } pcli->pfnTrayIconDestroy(hwnd); pcli->pfnTrayIconInit(hwnd); } else { iIcon = IconFromStatusMode(NULL, averageMode, 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, NULL); } } else { switch (cfg::getByte("CList", "TrayIcon", SETTING_TRAYICON_DEFAULT)) { case SETTING_TRAYICON_CYCLE: iIcon = IconFromStatusMode(szChangedProto, CallProtoService(szChangedProto, PS_GETSTATUS, 0, 0), 0, &hIcon); pcli->cycleTimerId = SetTimer(NULL, 0, cfg::getWord("CList", "CycleTime", SETTING_CYCLETIME_DEFAULT) * 1000, pcli->pfnTrayCycleTimerProc); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, NULL); case SETTING_TRAYICON_MULTI: if (!pcli->trayIcon) pcli->pfnTrayIconRemove(NULL, NULL); else if (cfg::getByte("CList", "AlwaysMulti", SETTING_ALWAYSMULTI_DEFAULT)) { iIcon = IconFromStatusMode(szChangedProto, CallProtoService(szChangedProto, PS_GETSTATUS, 0, 0), 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, szChangedProto); } pcli->pfnTrayIconDestroy(hwnd); pcli->pfnTrayIconInit(hwnd); break; case SETTING_TRAYICON_SINGLE: ptrA szProto( db_get_sa(NULL, "CList", "PrimaryStatus")); iIcon = IconFromStatusMode(szProto, szProto ? CallProtoService(szProto, PS_GETSTATUS, 0, 0) : CallService(MS_CLIST_GETSTATUSMODE, 0, 0), 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, NULL); } } } else { iIcon = IconFromStatusMode(NULL, averageMode, 0, &hIcon); hIcon = (hIcon) ? CopyIcon(hIcon) : ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL); return pcli->pfnTrayIconSetBaseInfo(hIcon, NULL); } return -1; }