/* cvsnt control panel Copyright (C) 2004-5 Tony Hoyle and March-Hare Software Ltd This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // RepositoryPage.cpp : implementation file // #include "stdafx.h" #include "resource.h" #include "NewRootDialog.h" #include "RepositoryPage.h" #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define MAX_REPOSITORIES 1024 ///////////////////////////////////////////////////////////////////////////// // CRepositoryPage property page IMPLEMENT_DYNCREATE(CRepositoryPage, CTooltipPropertyPage) CRepositoryPage::CRepositoryPage() : CTooltipPropertyPage(CRepositoryPage::IDD) { //{{AFX_DATA_INIT(CRepositoryPage) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } CRepositoryPage::~CRepositoryPage() { } void CRepositoryPage::DoDataExchange(CDataExchange* pDX) { CTooltipPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRepositoryPage) DDX_Control(pDX, IDC_DELETEROOT, m_btDelete); DDX_Control(pDX, IDC_ADDROOT, m_btAdd); DDX_Control(pDX, IDC_EDITROOT, m_btEdit); DDX_Control(pDX, IDC_ROOTLIST, m_listRoot); //}}AFX_DATA_MAP DDX_Control(pDX, IDC_SERVERNAME, m_edServerName); } BEGIN_MESSAGE_MAP(CRepositoryPage, CTooltipPropertyPage) //{{AFX_MSG_MAP(CRepositoryPage) ON_BN_CLICKED(IDC_ADDROOT, OnAddroot) ON_BN_CLICKED(IDC_DELETEROOT, OnDeleteroot) ON_BN_CLICKED(IDC_EDITROOT, OnEditroot) //}}AFX_MSG_MAP ON_NOTIFY(NM_DBLCLK, IDC_ROOTLIST, OnNMDblclkRootlist) ON_NOTIFY(LVN_ITEMCHANGED, IDC_ROOTLIST, OnLvnItemchangedRootlist) ON_EN_CHANGE(IDC_SERVERNAME, OnEnChangeServername) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRepositoryPage message handlers BOOL CRepositoryPage::OnInitDialog() { DWORD bufLen,dwType; TCHAR buf[_MAX_PATH]; CTooltipPropertyPage::OnInitDialog(); m_listRoot.InsertColumn(0,_T("Name"),LVCFMT_LEFT,130); m_listRoot.InsertColumn(1,_T("Root"),LVCFMT_LEFT,200); m_listRoot.InsertColumn(2,_T("Description"),LVCFMT_LEFT,230); if(GetRootList() && g_bPrivileged) GetParent()->PostMessage(PSM_CHANGED, (WPARAM)m_hWnd); /* SetModified happens too early */ DrawRootList(); OnLvnItemchangedRootlist(NULL,NULL); bufLen=sizeof(buf); if(RegQueryValueEx(g_hServerKey,_T("InstallPath"),NULL,&dwType,(BYTE*)buf,&bufLen)) { // Not set *buf='\0'; } m_szInstallPath=buf; bufLen=sizeof(buf); if(RegQueryValueEx(g_hServerKey,_T("ServerName"),NULL,&dwType,(BYTE*)buf,&bufLen)) { char host[1024]; if(!gethostname(host,sizeof(host))) { char *p=strchr(host,'.'); if(p) *p='\0'; MultiByteToWideChar(CP_ACP,0,host,-1,buf,sizeof(buf)/sizeof(wchar_t)); } else { wcscpy(buf,L"localhost?"); } } m_edServerName.SetWindowText(buf); m_btAdd.EnableWindow(g_bPrivileged); m_edServerName.EnableWindow(g_bPrivileged); return TRUE; } int CRepositoryPage::GetListSelection(CListCtrl& list) { int nItem = -1; POSITION nPos = list.GetFirstSelectedItemPosition(); if (nPos) nItem = list.GetNextSelectedItem(nPos); return nItem; } BOOL CRepositoryPage::OnApply() { RebuildRootList(); return CTooltipPropertyPage::OnApply(); } bool CRepositoryPage::GetRootList() { TCHAR buf[MAX_PATH],buf2[MAX_PATH],buf3[512]; std::wstring prefix; DWORD bufLen,dwVal,dwVal2,dwVal3; DWORD dwType; CString tmp; int drive; bool bModified = false; bufLen=sizeof(buf); if(!RegQueryValueEx(g_hServerKey,_T("RepositoryPrefix"),NULL,&dwType,(BYTE*)buf,&bufLen)) { TCHAR *p = buf; while((p=_tcschr(p,'\\'))!=NULL) *p='/'; p=buf+_tcslen(buf)-1; if(*p=='/') *p='\0'; prefix = buf; bModified = true; /* Save will delete this value */ } drive = _getdrive() + 'A' - 1; for(int n=0; n=0) { m_Roots[n].valid=false; continue; } int i = m_listRoot.InsertItem(n,m_Roots[n].name.c_str()); m_listRoot.SetItem(i,0,LVIF_PARAM,0,0,0,0,n,0); m_listRoot.SetItem(i,1,LVIF_TEXT,m_Roots[n].root.c_str(),0,0,0,0,0); m_listRoot.SetItem(i,2,LVIF_TEXT,m_Roots[n].description.c_str(),0,0,0,0,0); } } void CRepositoryPage::RebuildRootList() { std::wstring path,alias,desc,name; DWORD pub,def,onl; TCHAR tmp[64]; int j; size_t n; for(n=0; n(pNMHDR); if (!pNMListView || (pNMListView->uChanged & LVIF_STATE && ((pNMListView->uNewState & LVIS_SELECTED) != (pNMListView->uOldState & LVIS_SELECTED)))) { m_btAdd.EnableWindow(g_bPrivileged && m_listRoot.GetItemCount()0 && GetListSelection(m_listRoot)>=0); m_btEdit.EnableWindow(g_bPrivileged && m_listRoot.GetItemCount()>0 && GetListSelection(m_listRoot)>=0); } if(pResult) *pResult = 0; } void CRepositoryPage::OnEnChangeServername() { SetModified(); }