2 * Copyright 2000, International Business Machines Corporation and others.
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
15 #include <afs/param.h>
19 #include "afs_shl_ext.h"
20 #include "volume_info.h"
21 #include "partition_info_dlg.h"
22 #include "volume_inf.h"
30 static char THIS_FILE
[] = __FILE__
;
33 /////////////////////////////////////////////////////////////////////////////
37 CVolumeInfo::CVolumeInfo(CWnd
* pParent
/*=NULL*/)
40 InitModalIndirect (TaLocale_GetDialogResource (CVolumeInfo::IDD
), pParent
);
42 //{{AFX_DATA_INIT(CVolumeInfo)
50 CVolumeInfo::~CVolumeInfo()
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
);
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
)
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
;
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
);
120 if (m_pVolInfo
[nIndex
].m_nDup
!= -1)
121 return m_pVolInfo
[nIndex
].m_nDup
;
126 void CVolumeInfo::OnSelChangeList()
128 m_nCurIndex
= GetCurVolInfoIndex();
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);
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
);
155 void CVolumeInfo::SetFiles(const CStringArray
& files
)
162 void CVolumeInfo::OnChangeNewQuota()
164 if (m_List
.m_hWnd
== 0)
168 GetDlgItem(IDC_NEW_QUOTA
)->GetWindowText(strQuota
);
170 if (strQuota
.IsEmpty())
173 if (!UpdateData(TRUE
))
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
);
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
)) {
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
]);
200 void CVolumeInfo::OnDeltaPosQuotaSpin(NMHDR
* pNMHDR
, LRESULT
* pResult
)
202 NM_UPDOWN
* pNMUpDown
= (NM_UPDOWN
*)pNMHDR
;
204 unsigned __int64 nNewQuota
= m_nNewQuota
+ pNMUpDown
->iDelta
* 1024;
208 m_nNewQuota
= nNewQuota
;
217 void CVolumeInfo::ShowInfo()
219 m_List
.ResetContent();
221 for (int i
= 0; i
< m_Files
.GetSize(); i
++) {
224 if (m_pVolInfo
[i
].m_strErrorMsg
.GetLength() > 0)
225 strEntry
= m_pVolInfo
[i
].m_strFileName
+ "\t(Error: " + m_pVolInfo
[i
].m_strErrorMsg
+ ")";
228 unsigned __int64 nQuota
;
229 if (m_pVolInfo
[i
].m_nDup
== -1)
230 nQuota
= m_pVolInfo
[i
].m_nNewQuota
;
232 nQuota
= m_pVolInfo
[m_pVolInfo
[i
].m_nDup
].m_nNewQuota
;
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
);
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
);