nt-makefile-clean-targets-20010917
[openafs.git] / src / WINNT / client_exp / auth_dlg.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "stdafx.h"
16 #include "afs_shl_ext.h"
17 #include "auth_dlg.h"
18 #include "klog_dlg.h"
19 #include "unlog_dlg.h"
20 #include "gui2fs.h"
21
22 #ifdef _DEBUG
23 #define new DEBUG_NEW
24 #undef THIS_FILE
25 static char THIS_FILE[] = __FILE__;
26 #endif
27
28 /////////////////////////////////////////////////////////////////////////////
29 // CAuthDlg dialog
30
31
32 CAuthDlg::CAuthDlg(CWnd* pParent /*=NULL*/)
33         : CDialog()
34 {
35         InitModalIndirect (TaLocale_GetDialogResource (CAuthDlg::IDD), pParent);
36
37         //{{AFX_DATA_INIT(CAuthDlg)
38         //}}AFX_DATA_INIT
39 }
40
41
42 void CAuthDlg::DoDataExchange(CDataExchange* pDX)
43 {
44         CDialog::DoDataExchange(pDX);
45         //{{AFX_DATA_MAP(CAuthDlg)
46         DDX_Control(pDX, IDC_TOKEN_LIST, m_TokenList);
47         //}}AFX_DATA_MAP
48 }
49
50
51 BEGIN_MESSAGE_MAP(CAuthDlg, CDialog)
52         //{{AFX_MSG_MAP(CAuthDlg)
53         ON_BN_CLICKED(ID_GET_TOKENS, OnGetTokens)
54         ON_BN_CLICKED(ID_DISCARD_TOKENS, OnDiscardTokens)
55         ON_BN_CLICKED(IDHELP, OnHelp)
56         //}}AFX_MSG_MAP
57 END_MESSAGE_MAP()
58
59 /////////////////////////////////////////////////////////////////////////////
60 // CAuthDlg message handlers
61
62 BOOL CAuthDlg::OnInitDialog() 
63 {
64         CDialog::OnInitDialog();
65
66         // The final tab is for an extra CellName entry that is 
67         // there so we can easily parse it out when someone wants
68         // to get or discard tokens.  It is placed so the user can't
69         // see it.  It's kind of a hack, but not too bad.
70         int tabs[] = { 93, 211, 700 };
71         
72         m_TokenList.SetTabStops(sizeof(tabs) / sizeof(int), tabs);
73
74         FillTokenList();
75         
76         return TRUE;  // return TRUE unless you set the focus to a control
77                       // EXCEPTION: OCX Property Pages should return FALSE
78 }
79
80 void CAuthDlg::OnGetTokens() 
81 {
82         CKlogDlg dlg;
83
84         dlg.SetCellName(GetSelectedCellName());
85
86         if (dlg.DoModal() == IDOK)
87                 FillTokenList();
88 }
89
90 void CAuthDlg::OnDiscardTokens() 
91 {
92         CUnlogDlg dlg;
93
94         dlg.SetCellName(GetSelectedCellName());
95
96         if (dlg.DoModal() == IDOK)
97                 FillTokenList();
98 }
99
100 void CAuthDlg::FillTokenList()
101 {
102         m_TokenList.ResetContent();
103         
104         CStringArray tokenInfo;
105         if (!GetTokenInfo(tokenInfo))
106                 return;
107
108         for (int i = 0; i < tokenInfo.GetSize(); i++)
109                 m_TokenList.AddString(tokenInfo[i]);
110 }
111
112 CString CAuthDlg::GetSelectedCellName()
113 {
114         int nIndex = m_TokenList.GetCurSel();
115         if (nIndex < 0)
116                 return "";
117
118         CString strTokenInfo;
119         m_TokenList.GetText(nIndex, strTokenInfo);
120
121         int nPos = strTokenInfo.ReverseFind('\t');
122
123         return strTokenInfo.Mid(nPos + 1);
124 }
125
126 void CAuthDlg::OnHelp() 
127 {
128         ShowHelp(m_hWnd, AUTHENTICATION_HELP_ID);
129 }
130