MCONTACT TwitterProto::AddToClientList(const char *name, const char *status) { // First, check if this contact exists MCONTACT hContact = UsernameToHContact(name); if (hContact) return hContact; if (in_chat_) AddChatContact(name); // If not, make a new contact! hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hContact) { if (Proto_AddToContact(hContact, m_szModuleName) == 0) { setString(hContact, TWITTER_KEY_UN, name); setWord(hContact, "Status", ID_STATUS_ONLINE); db_set_utf(hContact, "CList", "StatusMsg", status); std::string url = profile_base_url(twit_.get_base_url()) + http::url_encode(name); setString(hContact, "Homepage", url.c_str()); DBVARIANT dbv; if (!getTString(TWITTER_KEY_GROUP, &dbv)) { db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } return hContact; } CallService(MS_DB_CONTACT_DELETE, hContact, 0); } return 0; }
MCONTACT CToxProto::AddChatRoom(int groupNumber) { MCONTACT hContact = GetChatRoom(groupNumber); if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact, m_szModuleName); setWord(hContact, TOX_SETTINGS_CHAT_ID, groupNumber); TCHAR title[MAX_PATH]; mir_sntprintf(title, _T("%s #%d"), TranslateT("Group chat"), groupNumber); setTString(hContact, "Nick", title); DBVARIANT dbv; if (!db_get_s(NULL, "Chat", "AddToGroup", &dbv, DBVT_TCHAR)) { db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } setByte(hContact, "ChatRoom", 1); } return hContact; }
MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary) { MCONTACT hContact = FindContact(skypename); if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact, m_szModuleName); setString(hContact, SKYPE_SETTINGS_ID, skypename); DBVARIANT dbv; if (!getTString(SKYPE_SETTINGS_GROUP, &dbv)) { db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } setByte(hContact, "Auth", 1); setByte(hContact, "Grant", 1); if (isTemporary) db_set_b(hContact, "CList", "NotOnList", 1); } return hContact; }
INT_PTR addContact(WPARAM, LPARAM) { char tmp[256]; MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact, MODNAME); CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE); db_set_ts(hContact, MODNAME, "Nick", TranslateT("New Non-IM Contact")); DoPropertySheet(hContact); if (!db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp))) CallService(MS_DB_CONTACT_DELETE, hContact, 0); replaceAllStrings(hContact); return 0; }
MCONTACT CDropbox::GetDefaultContact() { if (!hDefaultContact) hDefaultContact = db_find_first(MODULE); if (!hDefaultContact) { hDefaultContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!Proto_AddToContact(hDefaultContact, MODULE)) { db_set_s(NULL, MODULE, "Nick", MODULE); db_set_s(hDefaultContact, MODULE, "Nick", MODULE); db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox"); } db_set_w(hDefaultContact, MODULE, "Status", HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); } return hDefaultContact; }
MCONTACT CQuotesProviderBase::CreateNewContact(const tstring& rsName) { MCONTACT hContact = MCONTACT(CallService(MS_DB_CONTACT_ADD, 0, 0)); if (hContact) { if (0 == Proto_AddToContact(hContact, QUOTES_PROTOCOL_NAME)) { tstring sProvName = GetInfo().m_sName; db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_PROVIDER, sProvName.c_str()); db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL, rsName.c_str()); db_set_ts(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, rsName.c_str()); mir_cslock lck(m_cs); m_aContacts.push_back(hContact); } else { CallService(MS_DB_CONTACT_DELETE, WPARAM(hContact), 0); hContact = NULL; } } return hContact; }
MCONTACT CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL temporary, BOOL stripResource) { if (jid == NULL || jid[0] == '\0') return NULL; TCHAR *s = NEWTSTR_ALLOCA(jid); TCHAR *q = NULL; // strip resource if present if (TCHAR *p = _tcschr(s, '@')) if ((q = _tcschr(p, '/')) != NULL) *q = '\0'; if (!stripResource && q != NULL) // so that resource is not stripped *q = '/'; // We can't use JabberHContactFromJID() here because of the stripResource option size_t len = mir_tstrlen(s); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { ptrT dbJid(getTStringA(hContact, "jid")); if (dbJid == NULL) continue; TCHAR *p = dbJid; // not null if (_tcslen(p) >= len && (p[len] == '\0' || p[len] == '/') && !_tcsnicmp(p, s, len)) return hContact; } MCONTACT hNewContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hNewContact, m_szModuleName); setTString(hNewContact, "jid", s); if (nick != NULL && *nick != '\0') setTString(hNewContact, "Nick", nick); if (temporary) db_set_b(hNewContact, "CList", "NotOnList", 1); else SendGetVcard(s); debugLog(_T("Create Jabber contact jid=%s, nick=%s"), s, nick); DBCheckIsTransportedContact(s, hNewContact); return hNewContact; }
MCONTACT SetupPseudocontact(LPCTSTR jid, LPCTSTR unreadCount, LPCSTR acc, LPCTSTR displayName) { MCONTACT hContact = db_get_dw(NULL, acc, PSEUDOCONTACT_LINK, 0); if (!hContact || !db_get_b(hContact, SHORT_PLUGIN_NAME, PSEUDOCONTACT_FLAG, 0)) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); db_set_dw(0, acc, PSEUDOCONTACT_LINK, hContact); db_set_b(hContact, SHORT_PLUGIN_NAME, PSEUDOCONTACT_FLAG, 1); Proto_AddToContact(hContact, acc); } // SetAvatar(hContact); if (displayName == NULL) { TCHAR *tszTemp = (TCHAR*)alloca((mir_tstrlen(jid) + mir_tstrlen(unreadCount) + 3 + 1) * sizeof(TCHAR)); FormatPseudocontactDisplayName(tszTemp, jid, unreadCount); db_set_ts(hContact, CLIST_MODULE_NAME, CONTACT_DISPLAY_NAME_SETTING, tszTemp); } else db_set_ts(hContact, CLIST_MODULE_NAME, CONTACT_DISPLAY_NAME_SETTING, displayName); db_set_ts(hContact, CLIST_MODULE_NAME, STATUS_MSG_SETTING, TranslateTS(MAIL_NOTIFICATIONS)); db_set_ts(hContact, SHORT_PLUGIN_NAME, UNREAD_THREADS_SETTING, unreadCount); return hContact; }
INT_PTR Meta_Convert(WPARAM wParam, LPARAM) { ptrT tszGroup(db_get_tsa(wParam, "CList", "Group")); // Create a new metacontact MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hMetaContact == NULL) return NULL; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMetaContact); if (cc == NULL) return 0; db_set_dw(hMetaContact, META_PROTO, "NumContacts", 0); cc->nSubs = 0; currDb->MetaSetDefault(cc); // explicitly write default sub to a db // Add the MetaContact protocol to the new meta contact Proto_AddToContact(hMetaContact, META_PROTO); if (tszGroup) db_set_ts(hMetaContact, "CList", "Group", tszGroup); // Assign the contact to the MetaContact just created (and make default). if (!Meta_Assign(wParam, hMetaContact, TRUE)) { MessageBox(0, TranslateT("There was a problem in assigning the contact to the metacontact"), TranslateT("Error"), MB_ICONEXCLAMATION); CallService(MS_DB_CONTACT_DELETE, hMetaContact, 0); return 0; } // hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled) if (!db_mc_isEnabled()) db_set_b(hMetaContact, "CList", "Hidden", 1); return hMetaContact; }
MCONTACT CSametimeProto::AddContact(mwSametimeUser* user, bool temporary) { debugLog(_T("CSametimeProto::AddContact() start")); const char* id = mwSametimeUser_getUser(user); const char* name = mwSametimeUser_getShortName(user); const char* nick = mwSametimeUser_getAlias(user); //const char* nick = mwSametimeUser_getShortName(user); mwSametimeUserType type = mwSametimeUser_getType(user); MCONTACT hContact = FindContactByUserId(id); bool new_contact = false; if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact) { debugLog(_T("AddContact(): Failed to create Sametime contact")); return NULL; ///TODO error handling } if (Proto_AddToContact(hContact, m_szModuleName) != 0) { CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); debugLog(_T("AddContact(): Failed to register Sametime contact")); return NULL; ///TODO error handling } new_contact = true; } else if (!temporary) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } // add to miranda if (new_contact) db_set_utf(hContact, m_szModuleName, "stid", id); if (name && mir_strlen(name)) db_set_utf(hContact, m_szModuleName, "Name", name); if (nick && mir_strlen(nick)) { db_set_utf(hContact, m_szModuleName, "Nick", nick); } else if (name && mir_strlen(name)) { db_set_utf(hContact, m_szModuleName, "Nick", name); } else { db_set_utf(hContact, m_szModuleName, "Nick", id); } db_set_b(hContact, m_szModuleName, "type", (BYTE)type); if (new_contact) { //add to our awareness list mwAwareIdBlock id_block; if (GetAwareIdFromContact(hContact, &id_block)) { GList* gl = g_list_prepend(NULL, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); free(id_block.user); } } if (temporary) { db_set_b(hContact, "CList", "NotOnList", 1); db_set_b(hContact, "CList", "Hidden", 1); } else { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } return hContact; }
INT_PTR AddToList(WPARAM, LPARAM lParam) { PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT *) lParam; DBVARIANT dbv; MCONTACT hContact; int sameurl = 0; int samename = 0; if (psr == NULL) return 0; if (psr->nick.t == NULL) { WErrorPopup((UINT_PTR)"ERROR", TranslateT("Please select site in Find/Add contacts...")); return 0; } // if contact with the same ID was not found, add it if (psr->cbSize != sizeof(PROTOSEARCHRESULT)) return NULL; // search for existing contact for (hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { // check ID to see if the contact already exist in the database if (db_get_ts(hContact, MODULENAME, "URL", &dbv)) continue; if (!mir_tstrcmpi(psr->nick.t, dbv.ptszVal)) { // remove the flag for not on list and hidden, thus make the // contact visible // and add them on the list sameurl ++; if (db_get_b(hContact, "CList", "NotOnList", 1)) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } } db_free(&dbv); } hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact, MODULENAME); /////////write to db db_set_b(hContact, MODULENAME, ON_TOP_KEY, 0); db_set_b(hContact, MODULENAME, DBLE_WIN_KEY, 1); db_set_s(hContact, MODULENAME, END_STRING_KEY, ""); db_set_b(hContact, MODULENAME, RWSPACE_KEY, 1); //Convert url into a name for contact TCHAR Cnick[255]; if (psr->nick.t != NULL) _tcsncpy(Cnick, psr->nick.t, _countof(Cnick)); else Cnick[0] = 0; TCHAR *Oldnick = _tcsstr(Cnick, _T("://")); if (Oldnick != 0) Oldnick += 3; else Oldnick = Cnick; TCHAR *Newnick = _tcsstr(Oldnick, _T("www.")); if (Newnick != 0) Newnick += 4; else { Newnick = _tcsstr(Oldnick, _T("WWW.")); if (Newnick != 0) Newnick += 4; else Newnick = Oldnick; } TCHAR *Nend = _tcschr(Newnick, '.'); if (Nend) *Nend = '\0'; for (MCONTACT hContact2 = db_find_first(MODULENAME); hContact2 != NULL; hContact2 = db_find_next(hContact2, MODULENAME)) { if (!db_get_ts(hContact2, MODULENAME, PRESERVE_NAME_KEY, &dbv)) { if (!mir_tstrcmpi(Newnick, dbv.ptszVal)) { // remove the flag for not on list and hidden, thus make the // contact visible // and add them on the list samename++; if (db_get_b(hContact2, "CList", "NotOnList", 1)) { db_unset(hContact2, "CList", "NotOnList"); db_unset(hContact2, "CList", "Hidden"); } db_free(&dbv); } } db_free(&dbv); } if ((sameurl > 0) || (samename > 0)) // contact has the same url or name as another contact, add rand num to name { srand((unsigned) time(NULL)); TCHAR ranStr[10]; _itot((int) 10000 *rand() / (RAND_MAX + 1.0), ranStr, 10); mir_tstrcat(Newnick, ranStr); } //end convert db_set_ts(hContact, "CList", "MyHandle", Newnick); db_set_ts(hContact, MODULENAME, PRESERVE_NAME_KEY, Newnick); db_set_ts(hContact, MODULENAME, "Nick", Newnick); db_set_b(hContact, MODULENAME, CLEAR_DISPLAY_KEY, 1); db_set_s(hContact, MODULENAME, START_STRING_KEY, ""); db_set_ts(hContact, MODULENAME, URL_KEY, psr->nick.t); db_set_ts(hContact, MODULENAME, "Homepage", psr->nick.t); db_set_b(hContact, MODULENAME, U_ALLSITE_KEY, 1); db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE); // ignore status change db_set_dw(hContact, "Ignore", "Mask", 8); Sleep(2); db_free(&dbv); return (INT_PTR)hContact; }
// protocol service function for adding a new contact onto contact list // lParam = PROTOSEARCHRESULT INT_PTR WeatherAddToList(WPARAM, LPARAM lParam) { PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)lParam; if (!psr || !psr->email.t) return 0; // search for existing contact for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { // check if it is a weather contact if (IsMyContact(hContact)) { DBVARIANT dbv; // check ID to see if the contact already exist in the database if (!db_get_ts(hContact, WEATHERPROTONAME, "ID", &dbv)) { if (!mir_tstrcmpi(psr->email.t, dbv.ptszVal)) { // remove the flag for not on list and hidden, thus make the contact visible // and add them on the list if (db_get_b(hContact, "CList", "NotOnList", 1)) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } db_free(&dbv); // contact is added, function quitting return (INT_PTR)hContact; } db_free(&dbv); } } } // if contact with the same ID was not found, add it if (psr->cbSize < sizeof(PROTOSEARCHRESULT)) return 0; MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact, WEATHERPROTONAME); // suppress online notification for the new contact CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE); // set contact info and settings TCHAR svc[256]; _tcsncpy(svc, psr->email.t, _countof(svc)); svc[_countof(svc) - 1] = 0; GetSvc(svc); // set settings by obtaining the default for the service if (psr->lastName.t[0] != 0) { WIDATA *sData = GetWIData(svc); db_set_ts(hContact, WEATHERPROTONAME, "MapURL", sData->DefaultMap); db_set_s(hContact, WEATHERPROTONAME, "InfoURL", sData->DefaultURL); } else { // if no valid service is found, create empty strings for MapURL and InfoURL db_set_s(hContact, WEATHERPROTONAME, "MapURL", ""); db_set_s(hContact, WEATHERPROTONAME, "InfoURL", ""); } // write the other info and settings to the database db_set_ts(hContact, WEATHERPROTONAME, "ID", psr->email.t); db_set_ts(hContact, WEATHERPROTONAME, "Nick", psr->nick.t); db_set_w(hContact, WEATHERPROTONAME, "Status", ID_STATUS_OFFLINE); AvatarDownloaded(hContact); TCHAR str[256]; mir_sntprintf(str, TranslateT("Current weather information for %s."), psr->nick.t); db_set_ts(hContact, WEATHERPROTONAME, "About", str); // make the last update tags to something invalid db_set_s(hContact, WEATHERPROTONAME, "LastLog", "never"); db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None"); db_set_s(hContact, WEATHERPROTONAME, "LastTemperature", "None"); // ignore status change db_set_dw(hContact, "Ignore", "Mask", 8); // if no default station is found, set the new contact as default station if (opt.Default[0] == 0) { DBVARIANT dbv; GetStationID(hContact, opt.Default, _countof(opt.Default)); opt.DefStn = hContact; if (!db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { // notification message box mir_sntprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION); } db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default); } // display the Edit Settings dialog box EditSettings(hContact, 0); return (INT_PTR)hContact; }
INT_PTR ImportContacts(WPARAM, LPARAM) { MCONTACT hContact; char name[256] = "", program[256] = "", programparam[256] = "", group[256] = "", line[2001] = ""; int icon = 40072, usetimer = 0, minutes = 1, timer = 0; char fn[MAX_PATH]; int i, j, contactDone = 0; if (!Openfile(fn, 1)) return 1; FILE *file = fopen(fn, "r"); if (!file) return 1; CMStringA tooltip; while (fgets(line, 2000, file)) { if (!mir_strcmp(line, "\r\n\0")) continue; if (!mir_strcmp(line, "[Non-IM Contact]\r\n")) contactDone = 0; else if (!strncmp(line, "Name=", mir_strlen("Name="))) { i = (int)mir_strlen("Name="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { name[j] = line[i++]; name[++j] = '\0'; } contactDone = 1; } else if (!strncmp(line, "ProgramString=", mir_strlen("ProgramString="))) { i = (int)mir_strlen("ProgramString="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { program[j] = line[i++]; program[++j] = '\0'; } } else if (!strncmp(line, "ProgramParamString=", mir_strlen("ProgramParamString="))) { i = (int)mir_strlen("ProgramParamString="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { programparam[j] = line[i++]; programparam[++j] = '\0'; } } else if (!strncmp(line, "Group=", mir_strlen("Group="))) { i = (int)mir_strlen("Group="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { group[j] = line[i++]; group[++j] = '\0'; } } else if (!strncmp(line, "ToolTip=", mir_strlen("ToolTip="))) { i = (int)mir_strlen("ToolTip="); tooltip = &line[i]; fgets(line, 2000, file); while (!strstr(line, "</tooltip>\r\n")) { tooltip.Append(line); fgets(line, 2000, file); } // the line that has the </tooltip> tooltip.Append(line); } else if (!strncmp(line, "Icon=", mir_strlen("Icon="))) { i = (int)mir_strlen("Icon="); sscanf(&line[i], "%d", &icon); } else if (!strncmp(line, "UseTimer=", mir_strlen("UseTimer="))) { i = (int)mir_strlen("UseTimer="); sscanf(&line[i], "%d", &usetimer); } else if (!strncmp(line, "Timer=", mir_strlen("Timer="))) { i = (int)mir_strlen("Timer="); sscanf(&line[i], "%d", &timer); } else if (!strncmp(line, "Minutes=", mir_strlen("Minutes="))) { i = (int)mir_strlen("Minutes="); sscanf(&line[i], "%d", &minutes); } else if (contactDone && !mir_strcmp(line, "[/Non-IM Contact]\r\n")) { if (!name) continue; size_t size = mir_strlen(name) + mir_strlen("Do you want to import this Non-IM Contact?\r\n\r\nName: \r\n") + 1; char *msg = (char*)malloc(size); mir_snprintf(msg, size, "Do you want to import this Non-IM Contact?\r\n\r\nName: %s\r\n", name); if (program[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(program) + mir_strlen("Program: \r\n") + 1); mir_strcat(msg, "Program: "); mir_strcat(msg, program); mir_strcat(msg, "\r\n"); } if (programparam[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(programparam) + mir_strlen("Program Parameters: \r\n") + 1); mir_strcat(msg, "Program Parameters: "); mir_strcat(msg, programparam); mir_strcat(msg, "\r\n"); } if (tooltip) { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tooltip) + mir_strlen("ToolTip: \r\n") + 1); mir_strcat(msg, "ToolTip: "); mir_strcat(msg, tooltip); mir_strcat(msg, "\r\n"); } if (group[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(group) + mir_strlen("Group: \r\n") + 1); mir_strcat(msg, "Group: "); mir_strcat(msg, group); mir_strcat(msg, "\r\n"); } if (icon) { char tmp[64]; if (icon == ID_STATUS_ONLINE) mir_snprintf(tmp, "Icon: Online\r\n"); else if (icon == ID_STATUS_AWAY) mir_snprintf(tmp, "Icon: Away\r\n"); else if (icon == ID_STATUS_NA) mir_snprintf(tmp, "Icon: NA\r\n"); else if (icon == ID_STATUS_DND) mir_snprintf(tmp, "Icon: DND\r\n"); else if (icon == ID_STATUS_OCCUPIED) mir_snprintf(tmp, "Icon: Occupied\r\n"); else if (icon == ID_STATUS_FREECHAT) mir_snprintf(tmp, "Icon: Free For Chat\r\n"); else if (icon == ID_STATUS_INVISIBLE) mir_snprintf(tmp, "Icon: Invisible\r\n"); else if (icon == ID_STATUS_ONTHEPHONE) mir_snprintf(tmp, "Icon: On The Phone\r\n"); else if (icon == ID_STATUS_OUTTOLUNCH) mir_snprintf(tmp, "Icon: Out To Lunch\r\n"); else { free(msg); continue; } char *msgtemp = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tmp) + 1); if (msgtemp) { msg = msgtemp; mir_strcat(msg, tmp); } } if (usetimer && timer) { char tmp[64], tmp2[8]; if (minutes) mir_strcpy(tmp2, "Minutes"); else mir_strcpy(tmp2, "Seconds"); mir_snprintf(tmp, "UseTimer: Yes\r\nTimer: %d %s", timer, tmp2); char *msgtemp = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tmp) + 1); if (msgtemp) { msg = msgtemp; mir_strcat(msg, tmp); } } if (MessageBoxA(0, msg, modFullname, MB_YESNO) == IDYES) { if (!(hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0))) { msg("contact did get created", ""); continue; } Proto_AddToContact(hContact, MODNAME); CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE); db_set_s(hContact, MODNAME, "Nick", Translate("New Non-IM Contact")); db_set_s(hContact, MODNAME, "Name", name); db_set_s(hContact, MODNAME, "ProgramString", program); // copy the ProgramParamString db_set_s(hContact, MODNAME, "ProgramParamString", programparam); // copy the group db_set_s(hContact, "CList", "Group", group); // copy the ToolTip db_set_s(hContact, MODNAME, "ToolTip", tooltip); // timer db_set_b(hContact, MODNAME, "UseTimer", (BYTE)usetimer); db_set_b(hContact, MODNAME, "Minutes", (BYTE)minutes); db_set_w(hContact, MODNAME, "Timer", (WORD)timer); //icon db_set_w(hContact, MODNAME, "Icon", (WORD)icon); replaceAllStrings(hContact); } free(msg); contactDone = 0; name[0] = '\0'; program[0] = '\0'; programparam[0] = '\0'; group[0] = '\0'; line[0] = '\0'; tooltip.Empty(); icon = 40072; usetimer = 0; minutes = 1; timer = 0; } } fclose(file); return 1; }
INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); SetWindowLongPtr(hwnd, GWLP_USERDATA, ((PROPSHEETPAGE*)lParam)->lParam); return TRUE; case WM_COMMAND: SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); switch (LOWORD(wParam)) { case IDC_EXPORT: ExportContact((MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA)); break; case IDC_DOIT: if (GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE))) { char newString[MAX_REPLACES][512], oldString[MAX_REPLACES][512]; char dbVar1[2000], dbVar2[2000]; int i = 0, j = 0, k = 0; char *string = oldString[k]; MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { char *replace = (char*)malloc(GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); GetDlgItemTextA(hwnd, IDC_STRING_REPLACE, replace, GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); // get the list of replace strings while (replace[i] != '\0') { if (replace[i] == ',') { string = newString[k]; j = 0; } else if (!strncmp(replace + i, "\r\n", 2)) { if (string == newString[k]) k--; if (k == MAX_REPLACES) break; string = oldString[++k]; i += 2; continue; } else { string[j] = replace[i]; string[++j] = '\0'; } i++; } free(replace); MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact2, MODNAME); CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); // blank dbVar2 so the replaceing doesnt crash.. mir_strcpy(dbVar2, ""); // copy the name (dbVar1 is the name) for (i = 0; i < k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "Name", dbVar2); // copy the ProgramString if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ProgramString", dbVar2); } // copy the ProgramParamString if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar2); } // copy the group if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, "CList", "Group", dbVar2); } // copy the ToolTip if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ToolTip", dbVar2); } // timer db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0)); db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0)); db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0)); //icon db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072)); replaceAllStrings(hContact2); } } else { char dbVar1[2000]; MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact2) { msg("contact did not get created", ""); return 0; } Proto_AddToContact(hContact2, MODNAME); CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); db_set_s(hContact2, MODNAME, "Name", dbVar1); if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramString", dbVar1); // copy the ProgramParamString if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar1); // copy the group if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) db_set_s(hContact2, "CList", "Group", dbVar1); // copy the ToolTip if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ToolTip", dbVar1); // timer db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0)); db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0)); db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0)); //icon db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072)); replaceAllStrings(hContact2); } } } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: return TRUE; } } break; } return FALSE; }