more-rx-updates-20060504
[openafs.git] / src / WINNT / afssvrmgr / set_rename.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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "svrmgr.h"
19 #include "set_rename.h"
20
21
22 /*
23  * PROTOTYPES _________________________________________________________________
24  *
25  */
26
27 BOOL CALLBACK Filesets_Rename_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
28 void Filesets_Rename_OnInitDialog (HWND hDlg, LPSET_RENAME_APPLY_PARAMS psrp);
29 void Filesets_Rename_EnableOK (HWND hDlg, LPSET_RENAME_APPLY_PARAMS psrp);
30
31
32 /*
33  * ROUTINES ___________________________________________________________________
34  *
35  */
36
37 void Filesets_ShowRename (LPIDENT lpiFileset)
38 {
39    LPSET_RENAME_INIT_PARAMS lpp = New (SET_RENAME_INIT_PARAMS);
40    memset (lpp, 0x00, sizeof(SET_RENAME_INIT_PARAMS));
41    lpp->lpiReq = lpiFileset;
42
43    StartTask (taskSET_RENAME_INIT, g.hMain, lpp);
44 }
45
46
47 void Filesets_OnEndTask_ShowRename (LPTASKPACKET ptp)
48 {
49    LPSET_RENAME_INIT_PARAMS lpp = (LPSET_RENAME_INIT_PARAMS)(ptp->lpUser);
50
51    TCHAR szSvrName[ cchNAME ];
52    TCHAR szAggName[ cchNAME ];
53    TCHAR szSetName[ cchNAME ];
54    lpp->lpiReq->GetServerName (szSvrName);
55    lpp->lpiReq->GetAggregateName (szAggName);
56    lpp->lpiReq->GetFilesetName (szSetName);
57
58    if (!ptp->rc)
59       {
60       ErrorDialog (ptp->status, IDS_ERROR_REFRESH_FILESET_STATUS, TEXT("%s%s%s"), szSvrName, szAggName, szSetName);
61       }
62    else if (!lpp->lpiRW) // couldn't find RW fileset entry?
63       {
64       ErrorDialog (ptp->status, IDS_ERROR_NOT_REPLICATED, TEXT("%s"), szSetName);
65       }
66    else
67       {
68       LPSET_RENAME_APPLY_PARAMS psrp = New (SET_RENAME_APPLY_PARAMS);
69       memset (psrp, 0x00, sizeof(SET_RENAME_APPLY_PARAMS));
70       psrp->lpiFileset = lpp->lpiRW;
71
72       INT_PTR rc = ModalDialogParam (IDD_SET_RENAME, GetActiveWindow(), (DLGPROC)Filesets_Rename_DlgProc, (LPARAM)psrp);
73       if (rc != IDOK)
74          {
75          Delete (psrp);
76          }
77       else
78          {
79          StartTask (taskSET_RENAME_APPLY, NULL, psrp);
80          }
81       }
82
83    Delete (lpp);
84 }
85
86
87 BOOL CALLBACK Filesets_Rename_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
88 {
89    if (AfsAppLib_HandleHelp (IDD_SET_RENAME, hDlg, msg, wp, lp))
90       return TRUE;
91
92    static LPSET_RENAME_APPLY_PARAMS psrp = NULL;
93    if (msg == WM_INITDIALOG)
94       psrp = (LPSET_RENAME_APPLY_PARAMS)lp;
95
96    if (psrp != NULL)
97       {
98       switch (msg)
99          {
100          case WM_INITDIALOG:
101             Filesets_Rename_OnInitDialog (hDlg, psrp);
102             break;
103
104          case WM_COMMAND:
105             switch (LOWORD(wp))
106                {
107                case IDOK:
108                case IDCANCEL:
109                   EndDialog (hDlg, LOWORD(wp));
110                   break;
111
112                case IDC_RENSET_NEW:
113                   Filesets_Rename_EnableOK (hDlg, psrp);
114                   break;
115
116                case IDHELP:
117                   WinHelp (hDlg, cszHELPFILENAME, HELP_CONTEXT, IDH_SVRMGR_RENAMEFILESET_OVERVIEW);
118                   break;
119                }
120             break;
121
122          case WM_DESTROY:
123             psrp = NULL;
124             break;
125          }
126       }
127
128    return FALSE;
129 }
130
131
132 void Filesets_Rename_OnInitDialog (HWND hDlg, LPSET_RENAME_APPLY_PARAMS psrp)
133 {
134    TCHAR szServer[ cchNAME ];
135    TCHAR szAggregate[ cchNAME ];
136    TCHAR szFileset[ cchNAME ];
137
138    psrp->lpiFileset->GetServerName (szServer);
139    psrp->lpiFileset->GetAggregateName (szAggregate);
140    psrp->lpiFileset->GetFilesetName (szFileset);
141
142    TCHAR szOld[ cchRESOURCE ];
143
144    GetDlgItemText (hDlg, IDC_RENSET_DESC, szOld, cchRESOURCE);
145    LPTSTR pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
146    SetDlgItemText (hDlg, IDC_RENSET_DESC, pszNew);
147    FreeString (pszNew);
148
149    SetDlgItemText (hDlg, IDC_RENSET_OLD, szFileset);
150    SetDlgItemText (hDlg, IDC_RENSET_NEW, szFileset);
151
152    PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg,IDC_RENSET_NEW), TRUE);
153
154    Filesets_Rename_EnableOK (hDlg, psrp);
155 }
156
157
158 void Filesets_Rename_EnableOK (HWND hDlg, LPSET_RENAME_APPLY_PARAMS psrp)
159 {
160    TCHAR szOld[ cchNAME ];
161
162    GetDlgItemText (hDlg, IDC_RENSET_OLD, szOld, cchNAME);
163    GetDlgItemText (hDlg, IDC_RENSET_NEW, psrp->szNewName, cchNAME);
164
165    BOOL fEnable = TRUE;
166
167    if (!psrp->szNewName[0])
168       {
169       fEnable = FALSE;
170       }
171    else if (!lstrcmpi (szOld, psrp->szNewName))
172       {
173       fEnable = FALSE;
174       }
175
176    EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
177 }
178