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