/*
* Copyright (C) 2001-2006 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "../client/DCPlusPlus.h"
#include "Resource.h"
#include "GeneralPage.h"
#include "../client/SettingsManager.h"
#include "../client/Socket.h"
#include "../client/LogManager.h"
#include "things.h"
PropPage::TextItem GeneralPage::texts[] = {
{ IDC_SETTINGS_PERSONAL_INFORMATION, ResourceManager::SETTINGS_PERSONAL_INFORMATION },
{ IDC_SETTINGS_NICK, ResourceManager::NICK },
{ IDC_SETTINGS_EMAIL, ResourceManager::EMAIL },
{ IDC_SETTINGS_DESCRIPTION, ResourceManager::DESCRIPTION },
{ IDC_SETTINGS_UPLOAD_SPEED, ResourceManager::SETTINGS_UPLOAD_LINE_SPEED },
{ IDC_SETTINGS_MEBIBYES, ResourceManager::MiBITSPS },
{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};
PropPage::Item GeneralPage::items[] = {
{ IDC_NICK, SettingsManager::NICK, PropPage::T_STR },
{ IDC_EMAIL, SettingsManager::EMAIL, PropPage::T_STR },
{ IDC_DESCRIPTION, SettingsManager::DESCRIPTION, PropPage::T_STR },
{ 0, 0, PropPage::T_END }
};
void GeneralPage::write()
{
PropPage::write((HWND)(*this), items);
SETSETTING(UPLOAD_SPEED, SettingsManager::connectionSpeeds[ctrlConnection.GetCurSel()]);
}
LRESULT GeneralPage::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
PropPage::translate((HWND)(*this), texts);
ctrlConnection.Attach(GetDlgItem(IDC_CONNECTION));
Connection.CreateFromImage(Images::Speeds().c_str(), 0, 0, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_SHARED| LR_LOADFROMFILE);
ctrlConnection.SetImageList(Connection);
int j = (int)SettingsManager::connectionSpeeds.size();
for(int i = 0; i < j; ++i) {
COMBOBOXEXITEM cbitem = {CBEIF_TEXT|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE};
tstring conn = Text::toT(SettingsManager::connectionSpeeds[i]);
cbitem.pszText = const_cast<TCHAR*>(conn.c_str());
cbitem.iItem = i;
cbitem.iImage = i+1;
cbitem.iSelectedImage = i+1;
ctrlConnection.InsertItem(&cbitem);
}
PropPage::read((HWND)(*this), items);
ctrlConnection.SetCurSel(ctrlConnection.FindStringExact(0, Text::toT(SETTING(UPLOAD_SPEED)).c_str()));
nick.Attach(GetDlgItem(IDC_NICK));
nick.LimitText(35);
desc.Attach(GetDlgItem(IDC_DESCRIPTION));
desc.LimitText(50);
desc.Detach();
return TRUE;
}
LRESULT GeneralPage::onTextChanged(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
TCHAR buf[SETTINGS_BUF_LEN];
GetDlgItemText(wID, buf, SETTINGS_BUF_LEN);
tstring old = buf;
// Strip '$', '|', '<', '>' and ' ' from text
TCHAR *b = buf, *f = buf, c;
while( (c = *b++) != 0 )
{
if(c != '$' && c != '|' && (wID == IDC_DESCRIPTION || c != ' ') && ( (wID != IDC_NICK && wID != IDC_DESCRIPTION && wID != IDC_SETTINGS_EMAIL) || (c != '<' && c != '>') ) )
*f++ = c;
}
*f = '\0';
if(old != buf)
{
// Something changed; update window text without changing cursor pos
CEdit tmp;
tmp.Attach(hWndCtl);
int start, end;
tmp.GetSel(start, end);
tmp.SetWindowText(buf);
if(start > 0) start--;
if(end > 0) end--;
tmp.SetSel(start, end);
tmp.Detach();
}
return TRUE;
}
LRESULT GeneralPage::onHelp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
HtmlHelp(m_hWnd, WinUtil::getHelpFile().c_str(), HH_HELP_CONTEXT, IDD_GENERALPAGE);
return 0;
}
LRESULT GeneralPage::onHelpInfo(LPNMHDR /*pnmh*/) {
HtmlHelp(m_hWnd, WinUtil::getHelpFile().c_str(), HH_HELP_CONTEXT, IDD_GENERALPAGE);
return 0;
}
/**
* @file
* $Id: GeneralPage.cpp 109 2006-10-31 03:21:46Z crakter $
*/