示例#1
0
// adds a new group if it doesn't exist yet; returns its hItem
HTREEITEM CCList::AddGroup(TCString GroupName)
{
	if (GroupName == L"")
		return TVI_ROOT;

	MGROUP hGroupId = Clist_GroupExists(GroupName);
	if (hGroupId == NULL)
		return nullptr;

	MCONTACT hContact = UINT_PTR(hGroupId) - 1 + HCONTACT_ISGROUP;
	HTREEITEM hGroupItem = FindContact(hContact);
	if (hGroupItem)
		return hGroupItem; // exists already, just return its handle

	TVINSERTSTRUCT tvIns = {};
	tvIns.hParent = TVI_ROOT;
	tvIns.item.pszText = wcsrchr(GroupName, '\\');
	if (tvIns.item.pszText) {
		TCString ParentGroupName(L"");
		tvIns.hParent = AddGroup(ParentGroupName.DiffCat(GroupName, tvIns.item.pszText));
		tvIns.item.pszText++;
	}
	else tvIns.item.pszText = GroupName;

	tvIns.hInsertAfter = TVI_ROOT;
	tvIns.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
	tvIns.item.state = tvIns.item.stateMask = TVIS_BOLD | TVIS_EXPANDED;
	tvIns.item.iImage = tvIns.item.iSelectedImage = IMAGE_GROUPOPEN;
	tvIns.item.lParam = Items.AddElem(CCLItemData(hContact));
	return TreeView_InsertItem(hTreeView, &tvIns);
}
/**
 * name:	toDB
 * class:	CExImContactBase
 * desc:	searches the database for a contact representing the one
 *			identified by this class or creates a new one if it was not found
 * param:	hMetaContact - a meta contact to add this contact to
 * return:	handle of the contact if successful
 **/
HANDLE CExImContactBase::toDB()
{
	// create new contact if none exists
	if (_hContact == INVALID_HANDLE_VALUE && _pszProto && _pszUIDKey && _dbvUID.type != DBVT_DELETED) {
		PROTOACCOUNT* pszAccount = 0;
		if (NULL == (pszAccount = ProtoGetAccount( _pszProto ))) {
			//account does not exist
			_hContact = INVALID_HANDLE_VALUE;
			return INVALID_HANDLE_VALUE;
		}
		if (!IsAccountEnabled(pszAccount)) {
			;
		}
		// create new contact
		_hContact = DB::Contact::Add();
		if (!_hContact) {
			_hContact = INVALID_HANDLE_VALUE;
			return INVALID_HANDLE_VALUE;
		}
		// Add the protocol to the new contact
		if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)_hContact, (LPARAM)_pszProto)) {
			DB::Contact::Delete(_hContact);
			_hContact = INVALID_HANDLE_VALUE;
			return INVALID_HANDLE_VALUE;
		}
		// write uid to protocol module
		if (db_set(_hContact, _pszProto, _pszUIDKey, &_dbvUID)) {
			DB::Contact::Delete(_hContact);
			_hContact = INVALID_HANDLE_VALUE;
			return INVALID_HANDLE_VALUE;
		}
		// write nick and display name
		if (_pszNick) db_set_utf(_hContact, _pszProto, SET_CONTACT_NICK, _pszNick);
		if (_pszDisp) db_set_utf(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, _pszDisp);

		// add group
		if (_pszGroup) {
			ptrT ptszGroup( mir_utf8decodeT(_pszGroup));
			db_set_ts(_hContact, MOD_CLIST, "Group", ptszGroup);
			if ( Clist_GroupExists(ptszGroup) == NULL) {
				HANDLE hGroup = Clist_CreateGroup(NULL, NULL);
				if (hGroup) {
					// renaming twice is stupid but the only way to avoid error dialog telling shit like
					// a group with that name does exist
					CallService(MS_CLIST_GROUPRENAME, (WPARAM)hGroup, (LPARAM)ptszGroup);
				}
			}
		}
	}
	return _hContact;
}
示例#3
0
void CSkypeOptionsMain::OnApply()
{
	ptrA szNewSkypename(m_skypename.GetTextA()),	 
		 szOldSkypename(m_proto->getStringA(SKYPE_SETTINGS_ID));
	pass_ptrA szNewPassword(m_password.GetTextA()),
			szOldPassword(m_proto->getStringA("Password"));
	if (mir_strcmpi(szNewSkypename, szOldSkypename) || mir_strcmp(szNewPassword, szOldPassword))
		m_proto->delSetting("TokenExpiresIn");
	m_proto->setString(SKYPE_SETTINGS_ID, szNewSkypename);
	m_proto->setString("Password", szNewPassword);
	ptrT group(m_group.GetText());
	if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group))
		Clist_CreateGroup(0, group);
}
示例#4
0
void CList_CreateGroup(TCHAR* group)
{
    if (!group)
        return;

    g_Settings.hGroup = Clist_GroupExists(group);

    if(g_Settings.hGroup == 0) {
        g_Settings.hGroup = (HANDLE)CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)group);

        if(g_Settings.hGroup) {
            CallService(MS_CLUI_GROUPADDED, (WPARAM)g_Settings.hGroup, 0);
            CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)g_Settings.hGroup, 1);
        }
    }
}
示例#5
0
void CToxOptionsMain::OnApply()
{
	ptrT group(m_group.GetText());
	if (mir_tstrlen(group) > 0 && Clist_GroupExists(group))
		Clist_CreateGroup(0, group);

	if (m_proto->IsOnline())
	{
		CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_TCHAR, (LPARAM)ptrT(m_nickname.GetText()));

		// todo: add checkbox
		m_proto->setTString("Password", pass_ptrT(m_password.GetText()));

		m_proto->SaveToxProfile();
	}
}
示例#6
0
void CSametimeProto::AddGroup(const char* name, bool expanded)
{
	if (name && mir_strcmp(name, "MetaContacts Hidden Group") == 0)
		return;

	if (name && mir_strcmp(name, Translate("None")) == 0)
		return;

	ptrT ptszGroup(mir_utf8decodeT(name));
	HANDLE hGroup = Clist_GroupExists(ptszGroup);
	if (hGroup == NULL) {
		hGroup = Clist_CreateGroup(NULL, ptszGroup);
		if (hGroup) {
			CallService(MS_CLUI_GROUPADDED, (WPARAM)hGroup, 0);
			CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)hGroup, expanded ? 1 : 0);
		}
	}
}
示例#7
0
void CSteamOptionsMain::OnApply()
{
	TCHAR *group = m_group.GetText();
	if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group))
		Clist_GroupCreate(0, group);

	if (m_proto->IsOnline())
	{
		// may be we should show message box with warning?
		m_proto->SetStatus(ID_STATUS_OFFLINE);
	}
	if (m_username.IsChanged())
	{
		m_proto->delSetting("SteamID");
		m_proto->delSetting("TokenSecret");
	}
	if (m_password.IsChanged())
	{
		m_proto->delSetting("TokenSecret");
	}
	mir_free(group);
}
示例#8
0
void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
	CToxThread toxThread;

	ptrT profilePath(m_proto->GetToxProfilePath());
	if (!m_proto->IsFileExists(profilePath))
	{
		HANDLE hProfile = CreateFile(profilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hProfile == NULL)
		{
			m_proto->logger->Log(__FUNCTION__": failed to create tox profile");
			return;
		}
		CloseHandle(hProfile);
	}

	if (m_proto->InitToxCore(&toxThread))
	{
		ptrT group(m_group.GetText());
		if (mir_tstrlen(group) > 0 && Clist_GroupExists(group))
			Clist_CreateGroup(0, group);

		m_proto->UninitToxCore(&toxThread);

		m_toxAddress.Enable();
		m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));

		m_nickname.SetText(ptrT(m_proto->getTStringA("Nick")));
		m_password.SetText(ptrT(m_proto->getTStringA("Password")));
		m_group.SetText(ptrT(m_proto->getTStringA(TOX_SETTINGS_GROUP)));

		ShowWindow(m_profileCreate.GetHwnd(), FALSE);
		ShowWindow(m_profileImport.GetHwnd(), FALSE);

		ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
		ShowWindow(m_profileExport.GetHwnd(), TRUE);
	}
}
示例#9
0
void CSametimeProto::ExportContactsToList(mwSametimeList* user_list)
{
	debugLog(_T("CSametimeProto::ExportContactsToList() start"));
	mwSametimeGroup* stgroup = 0;
	char* group_name;
	char* group_alias;
	mwSametimeGroupType group_type;
	bool group_open;

	mwSametimeUser* stuser;
	char* user_alias;
	char* user_shortName;
	mwSametimeUserType user_type;
	DBVARIANT dbv, dbv2;
	char buff[256];
	mwAwareIdBlock id_block;
	mwIdBlock uid;

	GList* gl = 0;
	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
			if (dbv.pszVal) {
				if (GetAwareIdFromContact(hContact, &id_block)) {
					if (!db_get_utf(hContact, "CList", "Group", &dbv2)) {
						group_alias = _strdup(dbv2.pszVal);
						db_free(&dbv2);
					}
					else
						group_alias = _strdup(Translate("None"));

					if (group_alias) {
						mir_snprintf(buff, "GT_%s", group_alias);
						group_type = (mwSametimeGroupType)db_get_b(0, szProtoGroups, buff, (BYTE)mwSametimeGroup_NORMAL);
						// apparently we don't want to upload contacts in dynamic groups - see gaim sametime plugin comments
						if (group_type == mwSametimeGroup_DYNAMIC) {
							db_free(&dbv);
							free(id_block.user);
							free(group_alias);
							hContact = db_find_next(hContact, m_szModuleName);
							continue;
						}

						mir_snprintf(buff, "GN_%s", group_alias);
						if (!db_get_utf(0, szProtoGroups, buff, &dbv2)) {
							group_name = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							group_name = _strdup(group_alias);

						//group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1);

						ptrT ptszGroup(mir_utf8decodeT(group_alias));
						HANDLE hGroup = Clist_GroupExists(ptszGroup);
						if (hGroup) {
							int expanded;
							CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, (LPARAM)&expanded);
							group_open = (expanded != 0);
						}
						else {
							mir_snprintf(buff, "GO_%s", group_alias);
							group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1);
						}

						stgroup = 0;
						stgroup = mwSametimeList_findGroup(user_list, group_name);
						if (!stgroup) {
							if (group_name) stgroup = mwSametimeGroup_new(user_list, group_type, group_name);
							mwSametimeGroup_setAlias(stgroup, group_alias);
							mwSametimeGroup_setOpen(stgroup, group_open);
						}

						free(group_name);
						free(group_alias);

						if (!db_get_utf(hContact, m_szModuleName, "Name", &dbv2)) {
							user_shortName = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							user_shortName = 0;

						if (!db_get_utf(hContact, "CList", "MyHandle", &dbv2)) {
							user_alias = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							user_alias = 0;

						user_type = (mwSametimeUserType)db_get_b(hContact, m_szModuleName, "type", (BYTE)mwSametimeUser_NORMAL);

						uid.user = id_block.user;
						uid.community = id_block.community;

						stuser = mwSametimeUser_new(stgroup, user_type, &uid);
						if (user_shortName) {
							mwSametimeUser_setShortName(stuser, user_shortName);
							free(user_shortName);
						}
						if (user_alias) {
							mwSametimeUser_setAlias(stuser, user_alias);
							free(user_alias);
						}
					}

					free(id_block.user);
				}
			}
			db_free(&dbv);
		}
	}
}
示例#10
0
void importSettings(HANDLE hContact, char *importstring )
{
	char module[256] = "", setting[256] = "", *end;
	int i=0, value, type;
	importstring = strtok(importstring, "\n");

	SetCursor(LoadCursor(NULL,IDC_WAIT));

	while (importstring != NULL)
	{
		i=0;
		rtrim(importstring);
		if (importstring[i] == '\0')
		{
			importstring = strtok(NULL, "\n");
			continue;
		}
		else if (!strncmp(&importstring[i],"SETTINGS:",strlen("SETTINGS:")))
		{
			importstring = strtok(NULL, "\n");
			continue;
		}
		else if (!strncmp(&importstring[i],"CONTACT:", strlen("CONTACT:")))
		{
			int len, add = 1;
			hContact = INVALID_HANDLE_VALUE;

			i = i + (int)strlen("CONTACT:");
			len = (int)strlen(&importstring[i]);

			if (len > 10)
			{
				char uid[256]="",szUID[256]="",szProto[512]="";
				char *p1,*p2;

				p1 = strrchr(&importstring[i], '>*{');
				p2 = strrchr(&importstring[i], '}*');

				if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szUID))
				{
					strncpy(szUID, p1+1, p2-p1-2);

					p1 = strrchr(&importstring[i], ')*<');
					p2 = strrchr(&importstring[i], '>*{');

					if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(uid))
					{
						strncpy(uid, p1+1, p2-p1-3);

						p1 = strrchr(&importstring[i], ' *(');
						p2 = strrchr(&importstring[i], ')*<');

						if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szProto))
						{
							char *protouid;
							strncpy(szProto, p1+1, p2-p1-3);

							protouid = (char*)CallProtoService(szProto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
							if ((int)protouid!=CALLSERVICE_NOTFOUND)
							{
								if (!mir_strcmp(protouid, uid))
        							hContact = CheckNewContact(szProto, uid, szUID);
        					}
	        				else
        						hContact = CheckNewContact(szProto, uid, szUID);
						}
					}
				}
			}

 			if (hContact == INVALID_HANDLE_VALUE)
 			{
				HANDLE temp = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0);
				if (temp)
					hContact = temp;
			}
		}
		else if (importstring[i] == '[' && !strchr(&importstring[i+1],'=') )// get the module
		{
			if (end = strpbrk(&importstring[i+1], "]")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(module, &importstring[i+1]);
			}
		}
		else if (importstring[i] == '-' && importstring[i+1] == '[' &&
			!strchr(&importstring[i+2],'='))// get the module
		{
			if (end = strpbrk(&importstring[i+2], "]")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(module, &importstring[i+2]);
				deleteModule(module, hContact, 1);
			}
		}
		else if (strstr(&importstring[i], "=") && module[0]) // get the setting
		{
			if (end = strpbrk(&importstring[i+1], "=")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(setting, &importstring[i]);

				// get the type
				type = *(end+1);
				if (lstrcmp(module, "CList") == 0 && lstrcmp(setting, "Group") == 0)
				{
					WCHAR* GroupName = mir_a2u(end+2);
					if (!GroupName)
						continue;
					HANDLE GroupHandle = Clist_GroupExists(GroupName);
					if(GroupHandle == 0) {
						GroupHandle = (HANDLE)CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)GroupName);

						if(GroupHandle) {
							CallService(MS_CLUI_GROUPADDED, (WPARAM)GroupHandle, 0);
							CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)GroupHandle, 1);
						}
					}
					mir_free(GroupName);
				}
				switch (type)
				{
					case 'b':
					case 'B':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingByte(hContact, module, setting, (BYTE)value);
						break;
					case 'w':
					case 'W':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingWord(hContact, module, setting, (WORD)value);
						break;
					case 'd':
					case 'D':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingDword(hContact, module, setting, (DWORD)value);
						break;
					case 's':
					case 'S':
						DBWriteContactSettingString(hContact,module, setting, (end+2));
						break;
					case 'g':
					case 'G':
						{	char *pstr;
							for(pstr=end+2;*pstr;pstr++){
								if(*pstr=='\\'){
									switch(pstr[1]){
									case 'n': *pstr='\n'; break;
									case 't': *pstr='\t'; break;
									case 'r': *pstr='\r'; break;
									default:  *pstr=pstr[1]; break;
									}
									MoveMemory(pstr+1,pstr+2,lstrlenA(pstr+2)+1);
						}	}	}
					case 'u':
					case 'U':
						DBWriteContactSettingStringUtf(hContact,module, setting, (end+2));
						break;
					case 'l':
					case 'L':
						DBDeleteContactSetting(hContact, module, setting);
						break;
					case 'n':
					case 'N':
						WriteBlobFromString(hContact, module, setting, (end+2), (int)strlen((end+2)));
						break;
				}
			}
		}
		importstring = strtok(NULL, "\n");
	}
	SetCursor(LoadCursor(NULL,IDC_ARROW));
}