static TCHAR* parseContact(ARGUMENTSINFO *ai) { if (ai->argc < 3 || ai->argc > 4) return NULL; int n = 0; if (ai->argc == 4 && *ai->targv[3] != 'r') n = ttoi(ai->targv[3]) - 1; CONTACTSINFO ci = { 0 }; ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = getContactInfoFlags(ai->targv[2]); int count = getContactFromString(&ci); if (count == 0 || ci.hContacts == NULL) return NULL; if (ai->argc == 4 && *ai->targv[3] == 'r') n = rand() % count; if (count != 1 && ai->argc != 4) { mir_free(ci.hContacts); return NULL; } MCONTACT hContact = ci.hContacts[n]; log_debugA("contact: %x", hContact); mir_free(ci.hContacts); return encodeContactToString(hContact); }
static INT_PTR CALLBACK clistDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { switch(msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE, (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE) | (CLS_SHOWHIDDEN) | (CLS_NOHIDEOFFLINE)) & ~CLS_CHECKBOXES & ~CLS_USEGROUPS ); ResetCList(hwndDlg); CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, IDC_NULL); EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); break; case VARM_SETSUBJECT: { LPARAM res = 0; MCONTACT hItem, hContact = wParam; log_debugA("VARM_SETSUBJECT: %u", hContact); if (hContact == INVALID_CONTACT_ID) { TCHAR *tszContact = db_get_tsa(NULL, MODULENAME, SETTING_SUBJECT); log_debugA("VARM_SETSUBJECT: %s", tszContact); if (tszContact != NULL) { hContact = decodeContactFromString(tszContact); log_debugA("VARM_SETSUBJECT decoded: %u", hContact); mir_free(tszContact); } } if ((hContact != INVALID_CONTACT_ID) && (hContact != NULL)) hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); else hItem = NULL; if (hItem != NULL) res = (LPARAM)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SELECTITEM, (WPARAM)hItem, 0); CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, hItem==NULL?IDC_NULL:IDC_CONTACT); EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)res); } return TRUE; case VARM_GETSUBJECT: SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (IsDlgButtonChecked(hwndDlg, IDC_CONTACT) ? SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETSELECTION, 0, 0) : 0)); return TRUE; case WM_SIZE: if (!IsIconic(hwndDlg)) { UTILRESIZEDIALOG urd = { sizeof(urd) }; urd.hInstance = hInst; urd.hwndDlg = hwndDlg; urd.lParam = 0; /* ! uses ANSI version ! */ urd.lpTemplate = MAKEINTRESOURCEA(IDD_CLIST_DIALOG); urd.pfnResizer = clistDialogResize; CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); SendMessage(hwndDlg, WM_MOVE, 0, 0); } break; case WM_SHOWWINDOW: if ((wParam) && (IsDlgButtonChecked(hwndDlg, IDC_CONTACT))) SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_NULL: case IDC_CONTACT: CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, LOWORD(wParam)); EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); if (IsDlgButtonChecked(hwndDlg, IDC_CONTACT)) SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); break; } break; case WM_NOTIFY: switch (((NMHDR *) lParam)->idFrom) { case IDC_CLIST: switch (((NMHDR *) lParam)->code) { case CLN_OPTIONSCHANGED: ResetCList(hwndDlg); break; } break; } break; case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: db_unset(NULL, MODULENAME, SETTING_SUBJECT); MCONTACT hContact = (MCONTACT)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0); if (hContact != NULL) { TCHAR *tszContact = encodeContactToString(hContact); if (tszContact != NULL) { db_set_ts(NULL, MODULENAME, SETTING_SUBJECT, tszContact); mir_free(tszContact); } } break; } return FALSE; }