Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / client_exp / volumeinfo.cpp
blob89a3258b38088a936e46baebf3ddaede1605a342
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include "stdafx.h"
11 #include <winsock2.h>
12 #include <ws2tcpip.h>
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
19 #include "afs_shl_ext.h"
20 #include "volume_info.h"
21 #include "partition_info_dlg.h"
22 #include "volume_inf.h"
23 #include "gui2fs.h"
24 #include <limits.h>
25 #include "msgs.h"
27 #ifdef _DEBUG
28 #define new DEBUG_NEW
29 #undef THIS_FILE
30 static char THIS_FILE[] = __FILE__;
31 #endif
33 /////////////////////////////////////////////////////////////////////////////
34 // CVolumeInfo dialog
37 CVolumeInfo::CVolumeInfo(CWnd* pParent /*=NULL*/)
38 : CDialog()
40 InitModalIndirect (TaLocale_GetDialogResource (CVolumeInfo::IDD), pParent);
42 //{{AFX_DATA_INIT(CVolumeInfo)
43 m_nNewQuota = 0;
44 //}}AFX_DATA_INIT
46 m_pVolInfo = 0;
47 m_nCurIndex = -1;
50 CVolumeInfo::~CVolumeInfo()
52 if (m_pVolInfo != 0)
53 delete [] m_pVolInfo;
56 void CVolumeInfo::DoDataExchange(CDataExchange* pDX)
58 CDialog::DoDataExchange(pDX);
59 //{{AFX_DATA_MAP(CVolumeInfo)
60 DDX_Control(pDX, IDC_QUOTA_SPIN, m_QuotaSpin);
61 DDX_Control(pDX, IDOK, m_Ok);
62 DDX_Control(pDX, IDC_PARTITION_INFO, m_ShowPartInfo);
63 DDX_Control(pDX, IDC_LIST, m_List);
64 DDX_Text(pDX, IDC_NEW_QUOTA, m_nNewQuota);
65 //}}AFX_DATA_MAP
68 BEGIN_MESSAGE_MAP(CVolumeInfo, CDialog)
69 //{{AFX_MSG_MAP(CVolumeInfo)
70 ON_LBN_SELCHANGE(IDC_LIST, OnSelChangeList)
71 ON_BN_CLICKED(IDC_PARTITION_INFO, OnPartitionInfo)
72 ON_EN_CHANGE(IDC_NEW_QUOTA, OnChangeNewQuota)
73 ON_NOTIFY(UDN_DELTAPOS, IDC_QUOTA_SPIN, OnDeltaPosQuotaSpin)
74 ON_BN_CLICKED(IDHELP, OnHelp)
75 //}}AFX_MSG_MAP
76 END_MESSAGE_MAP()
78 /////////////////////////////////////////////////////////////////////////////
79 // CVolumeInfo message handlers
81 BOOL CVolumeInfo::OnInitDialog()
83 ASSERT(m_Files.GetSize() > 0);
85 CDialog::OnInitDialog();
87 int tabs[] = { 79, 164, 214, 260, 301 };
89 m_List.SetTabStops(sizeof(tabs) / sizeof(int), tabs);
91 m_pVolInfo = new CVolInfo[m_Files.GetSize()];
93 for (int i = 0; i < m_Files.GetSize(); i++) {
94 GetVolumeInfo(m_Files[i], m_pVolInfo[i]);
95 // Check if this is a duplicate entry (same volume as earlier entry)
96 for (int j = 0; j < i; j++) {
97 if (m_pVolInfo[j].m_nID == m_pVolInfo[i].m_nID)
98 m_pVolInfo[i].m_nDup = j;
99 break;
103 ShowInfo();
105 m_QuotaSpin.SetRange(UD_MINVAL, UD_MAXVAL);
106 m_QuotaSpin.SetPos(0);
108 return TRUE; // return TRUE unless you set the focus to a control
109 // EXCEPTION: OCX Property Pages should return FALSE
112 int CVolumeInfo::GetCurVolInfoIndex()
114 int nListIndex = m_List.GetCurSel();
115 ASSERT(nListIndex >= 0);
117 int nIndex = m_List.GetItemData(nListIndex);
118 ASSERT(nIndex >= 0);
120 if (m_pVolInfo[nIndex].m_nDup != -1)
121 return m_pVolInfo[nIndex].m_nDup;
123 return nIndex;
126 void CVolumeInfo::OnSelChangeList()
128 m_nCurIndex = GetCurVolInfoIndex();
129 if (m_nCurIndex < 0)
130 return;
132 m_nNewQuota = m_pVolInfo[m_nCurIndex].m_nNewQuota;
134 m_ShowPartInfo.EnableWindow(TRUE);
135 CWnd *pNewQuota = GetDlgItem(IDC_NEW_QUOTA);
136 pNewQuota->EnableWindow(TRUE);
138 m_QuotaSpin.EnableWindow(TRUE);
139 m_QuotaSpin.SetPos(0);
141 UpdateData(FALSE);
144 void CVolumeInfo::OnPartitionInfo()
146 CPartitionInfoDlg dlg;
148 ASSERT(m_nCurIndex >= 0);
150 dlg.SetValues(m_pVolInfo[m_nCurIndex].m_nPartSize, m_pVolInfo[m_nCurIndex].m_nPartFree);
152 dlg.DoModal();
155 void CVolumeInfo::SetFiles(const CStringArray& files)
157 m_Files.RemoveAll();
159 m_Files.Copy(files);
162 void CVolumeInfo::OnChangeNewQuota()
164 if (m_List.m_hWnd == 0)
165 return;
167 CString strQuota;
168 GetDlgItem(IDC_NEW_QUOTA)->GetWindowText(strQuota);
170 if (strQuota.IsEmpty())
171 return;
173 if (!UpdateData(TRUE))
174 return;
176 ASSERT(m_nCurIndex >= 0);
178 m_pVolInfo[m_nCurIndex].m_nNewQuota = m_nNewQuota;
180 if (m_pVolInfo[m_nCurIndex].m_nNewQuota != m_pVolInfo[m_nCurIndex].m_nQuota)
181 m_Ok.EnableWindow(TRUE);
183 ShowInfo();
186 void CVolumeInfo::OnOK()
188 for (int i = 0; i < m_Files.GetSize(); i++) {
189 if ((m_pVolInfo[i].m_nDup == -1) && (m_pVolInfo[i].m_nQuota != m_pVolInfo[i].m_nNewQuota)) {
190 // CString strQuota;
191 // strQuota.Format("= %ld", m_pVolInfo[i].m_nNewQuota);
192 // AfxMessageBox("Setting quota for volume: " + m_pVolInfo[i].m_strName + strQuota);
193 SetVolInfo(m_pVolInfo[i]);
197 CDialog::OnOK();
200 void CVolumeInfo::OnDeltaPosQuotaSpin(NMHDR* pNMHDR, LRESULT* pResult)
202 NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
204 unsigned __int64 nNewQuota = m_nNewQuota + pNMUpDown->iDelta * 1024;
205 if (nNewQuota < 0)
206 return;
208 m_nNewQuota = nNewQuota;
210 UpdateData(FALSE);
212 OnChangeNewQuota();
214 *pResult = 0;
217 void CVolumeInfo::ShowInfo()
219 m_List.ResetContent();
221 for (int i = 0; i < m_Files.GetSize(); i++) {
223 CString strEntry;
224 if (m_pVolInfo[i].m_strErrorMsg.GetLength() > 0)
225 strEntry = m_pVolInfo[i].m_strFileName + "\t(Error: " + m_pVolInfo[i].m_strErrorMsg + ")";
226 else {
228 unsigned __int64 nQuota;
229 if (m_pVolInfo[i].m_nDup == -1)
230 nQuota = m_pVolInfo[i].m_nNewQuota;
231 else
232 nQuota = m_pVolInfo[m_pVolInfo[i].m_nDup].m_nNewQuota;
234 if (nQuota != 0) {
235 LONG nPercentUsed = (LONG)((double)m_pVolInfo[i].m_nUsed / nQuota * 100);
236 strEntry.Format(_T("%s\t%s\t%ld\t%ldK\t%ldK\t%ld%%"),
237 m_pVolInfo[i].m_strFileName,
238 m_pVolInfo[i].m_strName,
239 m_pVolInfo[i].m_nID, nQuota,
240 m_pVolInfo[i].m_nUsed, nPercentUsed);
241 } else {
242 strEntry.Format(_T("%s\t%s\t%ld\tUnlimited\t%ldK"),
243 m_pVolInfo[i].m_strFileName,
244 m_pVolInfo[i].m_strName,
245 m_pVolInfo[i].m_nID, m_pVolInfo[i].m_nUsed);
249 int nListIndex = m_List.AddString(strEntry);
250 ASSERT(nListIndex >= 0);
251 VERIFY(m_List.SetItemData(nListIndex, i) != LB_ERR);
255 void CVolumeInfo::OnHelp()
257 ShowHelp(m_hWnd, VOLUME_INFO_HELP_ID);