Пример #1
0
int FindReplDlg::GetFindText(CComboBox& wnd, bsString& text)
{
	int len;
	char *tp;
	int sel = wnd.GetCurSel();
	if (sel == -1)
	{
		len = wnd.GetWindowTextLength()+1;
		tp = new char[len];
		wnd.GetWindowText(tp, len);
		sel = wnd.FindStringExact(-1, tp);
		if (sel == -1)
		{
			sel = wnd.InsertString(0, tp);
			wnd.SetCurSel(sel);
		}
		int cnt;
		while ((cnt = wnd.GetCount()) >= 20)
			wnd.DeleteString(cnt-1);
	}
	else
	{
		len = wnd.GetLBTextLen(sel)+1;
		tp = new char[len];
		wnd.GetLBText(sel, tp);
	}
	text.Attach(tp);
	return sel;
}
LRESULT FavHubProperties::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	if(wID == IDOK)
	{
		TCHAR buf[1024];
		GetDlgItemText(IDC_HUBADDR, buf, 256);
		if(buf[0] == '\0') {
			WinUtil::showMessageBox(TSTRING(INCOMPLETE_FAV_HUB), MB_ICONWARNING);
			return 0;
		}

		//check the primary address for dupes
		string addresses = Text::fromT(buf);
		size_t pos = addresses.find(";");

		if (!FavoriteManager::getInstance()->isUnique(pos != string::npos ? addresses.substr(0, pos) : addresses, entry->getToken())){
			WinUtil::showMessageBox(TSTRING(FAVORITE_HUB_ALREADY_EXISTS), MB_ICONWARNING);
			return 0;
		}

		//validate the encoding
		GetDlgItemText(IDC_ENCODING, buf, 512);
		if(_tcschr(buf, _T('.')) == NULL && _tcscmp(buf, Text::toT(Text::utf8).c_str()) != 0 && _tcscmp(buf, _T("System default")) != 0)
		{
			WinUtil::showMessageBox(TSTRING(INVALID_ENCODING), MB_ICONWARNING);
			return 0;
		}

		//set the values
		entry->setEncoding(Text::fromT(buf));
		entry->setServerStr(addresses);

		GetDlgItemText(IDC_HUBNAME, buf, 256);
		entry->setName(Text::fromT(buf));
		GetDlgItemText(IDC_HUBDESCR, buf, 256);
		entry->setDescription(Text::fromT(buf));
		GetDlgItemText(IDC_HUBPASS, buf, 256);
		entry->setPassword(Text::fromT(buf));
		entry->setStealth(IsDlgButtonChecked(IDC_STEALTH) == 1);
		entry->setFavNoPM(IsDlgButtonChecked(IDC_FAV_NO_PM) == 1);

		//Hub settings
		GetDlgItemText(IDC_NICK, buf, 256);
		entry->get(HubSettings::Nick) = Text::fromT(buf);

		GetDlgItemText(IDC_USERDESC, buf, 256);
		entry->get(HubSettings::Description) = Text::fromT(buf);

		GetDlgItemText(IDC_EMAIL, buf, 256);
		entry->get(HubSettings::Email) = Text::fromT(buf);

		GetDlgItemText(IDC_AWAY_MSG, buf, 1024);
		entry->get(HubSettings::AwayMsg) = Text::fromT(buf);

		entry->get(HubSettings::ShowJoins) = to3bool(IsDlgButtonChecked(IDC_SHOW_JOIN));
		entry->get(HubSettings::FavShowJoins) = to3bool(IsDlgButtonChecked(IDC_SHOW_JOIN));
		entry->get(HubSettings::LogMainChat) = to3bool(IsDlgButtonChecked(IDC_LOGMAINCHAT));
		entry->get(HubSettings::ChatNotify) = to3bool(IsDlgButtonChecked(IDC_CHAT_NOTIFY));
		entry->get(HubSettings::AcceptFailovers) = to3bool(IsDlgButtonChecked(IDC_FAILOVER));

		auto val = HubSettings::getMinInt();
		if (!IsDlgButtonChecked(IDC_SEARCH_INTERVAL_DEFAULT)) {
			GetDlgItemText(IDC_FAV_SEARCH_INTERVAL_BOX, buf, 512);
			val = Util::toInt(Text::fromT(buf));
		}
		entry->get(HubSettings::SearchInterval) = val;

		
		CComboBox combo;
		combo.Attach(GetDlgItem(IDC_FAV_DLG_GROUP));
	
		if(combo.GetCurSel() == 0)
		{
			entry->setGroup(Util::emptyString);
		}
		else
		{
			tstring text(combo.GetWindowTextLength() + 1, _T('\0'));
			combo.GetWindowText(&text[0], text.size());
			text.resize(text.size()-1);
			entry->setGroup(Text::fromT(text));
		}
		combo.Detach();


		// connection modes
		auto getConnMode = [](const CComboBox& combo) -> int {
			 if (combo.GetCurSel() == 1)
				return SettingsManager::INCOMING_DISABLED;
			else if (combo.GetCurSel() == 2)
				return SettingsManager::INCOMING_ACTIVE;
			else if (combo.GetCurSel() == 3)
				return SettingsManager::INCOMING_PASSIVE;

			return HubSettings::getMinInt();
		};

		entry->get(HubSettings::Connection) = getConnMode(modeCombo4);
		entry->get(HubSettings::Connection6) = getConnMode(modeCombo6);

		//external ip addresses
		GetDlgItemText(IDC_SERVER4, buf, 512);
		entry->get(HubSettings::UserIp) = Text::fromT(buf);

		GetDlgItemText(IDC_SERVER6, buf, 512);
		entry->get(HubSettings::UserIp6) = Text::fromT(buf);

		auto p = ShareManager::getInstance()->getProfiles();

		if(hideShare) {
			entry->setShareProfile(*(p.end()-1));
		} else {
			if(entry->isAdcHub()) {
				entry->setShareProfile(p[ctrlProfile.GetCurSel()]);
			} else {
				entry->setShareProfile(p[0]);
			}
		}

		FavoriteManager::getInstance()->save();
	}
	loaded = false;
	EndDialog(wID);
	return 0;
}
Пример #3
0
LRESULT FavHubProperties::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	if(wID == IDOK)
	{
		TCHAR buf[512];
		GetDlgItemText(IDC_HUBADDR, buf, 256);
		if(buf[0] == '\0') {
			MessageBox(CTSTRING(INCOMPLETE_FAV_HUB), _T(""), MB_ICONWARNING | MB_OK);
			return 0;
		}
		entry->setServer(Text::fromT(buf));
		GetDlgItemText(IDC_HUBNAME, buf, 256);
		entry->setName(Text::fromT(buf));
		GetDlgItemText(IDC_HUBDESCR, buf, 256);
		entry->setDescription(Text::fromT(buf));
		GetDlgItemText(IDC_HUBNICK, buf, 256);
		entry->setNick(Text::fromT(buf));
		GetDlgItemText(IDC_HUBPASS, buf, 256);
		entry->setPassword(Text::fromT(buf));
		GetDlgItemText(IDC_HUBUSERDESCR, buf, 256);
		entry->setUserDescription(Text::fromT(buf));
		entry->setStealth(IsDlgButtonChecked(IDC_STEALTH) == 1);
		GetDlgItemText(IDC_RAW_ONE, buf, 512);
		entry->setRawOne(Text::fromT(buf));
		GetDlgItemText(IDC_RAW_TWO, buf, 512);
		entry->setRawTwo(Text::fromT(buf));
		GetDlgItemText(IDC_RAW_THREE, buf, 512);
		entry->setRawThree(Text::fromT(buf));
		GetDlgItemText(IDC_RAW_FOUR, buf, 512);
		entry->setRawFour(Text::fromT(buf));
		GetDlgItemText(IDC_RAW_FIVE, buf, 512);
		entry->setRawFive(Text::fromT(buf));
		GetDlgItemText(IDC_SERVER, buf, 512);
		entry->setIP(Text::fromT(buf));
		GetDlgItemText(IDC_FAV_SEARCH_INTERVAL_BOX, buf, 512);
		entry->setSearchInterval(Util::toUInt32(Text::fromT(buf)));
		
		GetDlgItemText(IDC_ENCODING, buf, 512);
		if(_tcschr(buf, _T('.')) == NULL && _tcscmp(buf, Text::toT(Text::utf8).c_str()) != 0 && _tcscmp(buf, _T("System default")) != 0)
		{
			MessageBox(_T("Invalid encoding!"), _T(""), MB_ICONWARNING | MB_OK);
			return 0;
		}
		entry->setEncoding(Text::fromT(buf));
		
		CComboBox combo;
		combo.Attach(GetDlgItem(IDC_FAV_DLG_GROUP));
	
		if(combo.GetCurSel() == 0)
		{
			entry->setGroup(Util::emptyString);
		}
		else
		{
			tstring text(combo.GetWindowTextLength() + 1, _T('\0'));
			combo.GetWindowText(&text[0], text.size());
			text.resize(text.size()-1);
			entry->setGroup(Text::fromT(text));
		}
		combo.Detach();

		int	ct = -1;
		if(IsDlgButtonChecked(IDC_DEFAULT))
			ct = 0;
		else if(IsDlgButtonChecked(IDC_ACTIVE))
			ct = 1;
		else if(IsDlgButtonChecked(IDC_PASSIVE))
			ct = 2;

		entry->setMode(ct);

		FavoriteManager::getInstance()->save();
	}
	EndDialog(wID);
	return 0;
}
Пример #4
0
bool FavHubGeneralPage::write() {
	TCHAR buf[1024];
	GetDlgItemText(IDC_HUBADDR, buf, 256);
	if (buf[0] == '\0') {
		WinUtil::showMessageBox(TSTRING(INCOMPLETE_FAV_HUB), MB_ICONWARNING);
		return false;
	}

	//check the primary address for dupes
	string addresses = Text::fromT(buf);
	size_t pos = addresses.find(";");

	if (!FavoriteManager::getInstance()->isUnique(pos != string::npos ? addresses.substr(0, pos) : addresses, entry->getToken())) {
		WinUtil::showMessageBox(TSTRING(FAVORITE_HUB_ALREADY_EXISTS), MB_ICONWARNING);
		return false;
	}

	//validate the encoding
	GetDlgItemText(IDC_ENCODING, buf, 512);
	if (_tcschr(buf, _T('.')) == NULL && _tcscmp(buf, Text::toT(Text::utf8).c_str()) != 0 && ctrlEncoding.GetCurSel() != 0)
	{
		WinUtil::showMessageBox(TSTRING_F(INVALID_ENCODING, buf), MB_ICONWARNING);
		return false;
	}

	//set the values
	entry->get(HubSettings::NmdcEncoding) = ctrlEncoding.GetCurSel() != 0 ? Text::fromT(buf) : Util::emptyString;
	entry->setServer(addresses);

	GetDlgItemText(IDC_HUBNAME, buf, 256);
	entry->setName(Text::fromT(buf));
	GetDlgItemText(IDC_HUBDESCR, buf, 256);
	entry->setDescription(Text::fromT(buf));
	GetDlgItemText(IDC_HUBPASS, buf, 256);
	entry->setPassword(Text::fromT(buf));

	//Hub settings
	GetDlgItemText(IDC_NICK, buf, 256);
	entry->get(HubSettings::Nick) = Text::fromT(buf);

	GetDlgItemText(IDC_USERDESC, buf, 256);
	entry->get(HubSettings::Description) = Text::fromT(buf);

	GetDlgItemText(IDC_EMAIL, buf, 256);
	entry->get(HubSettings::Email) = Text::fromT(buf);

	CComboBox combo;
	combo.Attach(GetDlgItem(IDC_FAV_DLG_GROUP));

	if (combo.GetCurSel() == 0)
	{
		entry->setGroup(Util::emptyString);
	}
	else
	{
		tstring text(combo.GetWindowTextLength() + 1, _T('\0'));
		combo.GetWindowText(&text[0], text.size());
		text.resize(text.size() - 1);
		entry->setGroup(Text::fromT(text));
	}
	combo.Detach();

	auto p = ShareManager::getInstance()->getProfiles();

	ProfileToken token = HUB_SETTING_DEFAULT_INT;
	if (hideShare) {
		token = SP_HIDDEN;
	}
	else if (entry->isAdcHub() && ctrlProfile.GetCurSel() != 0) {
		token = p[ctrlProfile.GetCurSel() - 1]->getToken();
	}

	entry->get(HubSettings::ShareProfile) = token;

	//FavoriteManager::getInstance()->save();

	return true;
}