windows-misc-20050102
[openafs.git] / src / WINNT / afssvrmgr / svc_create.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 "svc_create.h"
17 #include "svc_general.h"
18 #include "propcache.h"
19
20
21 /*
22  * PROTOTYPES _________________________________________________________________
23  *
24  */
25
26 BOOL CALLBACK Services_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
27
28 void Services_Create_OnInitDialog (HWND hDlg, LPIDENT lpi);
29 void Services_Create_OnType (HWND hDlg);
30 void Services_Create_OnApply (HWND hDlg);
31 void Services_Create_EnableOK (HWND hDlg);
32
33
34 /*
35  * ROUTINES ___________________________________________________________________
36  *
37  */
38
39 void Services_Create (LPIDENT lpiServer)
40 {
41    HWND hCurrent;
42
43    if ((hCurrent = PropCache_Search (pcSVC_CREATE, NULL)) != NULL)
44       {
45       SetFocus (hCurrent);
46       }
47    else
48       {
49       LPPROPSHEET psh = PropSheet_Create (IDS_SVC_ADD_TITLE, FALSE);
50       psh->sh.dwFlags |= PSH_NOAPPLYNOW;
51
52       PropSheet_AddTab (psh, IDS_SVC_ADD_TAB, IDD_SVC_CREATE, (DLGPROC)Services_Create_DlgProc, (LPARAM)lpiServer, TRUE);
53       PropSheet_ShowModeless (psh);
54       }
55 }
56
57
58 BOOL CALLBACK Services_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
59 {
60    if (AfsAppLib_HandleHelp (IDD_SVC_CREATE, hDlg, msg, wp, lp))
61       return TRUE;
62
63    switch (msg)
64       {
65       case WM_INITDIALOG_SHEET:
66          PropCache_Add (pcSVC_CREATE, NULL, hDlg);
67          break;
68
69       case WM_DESTROY_SHEET:
70          PropCache_Delete (hDlg);
71          break;
72
73       case WM_INITDIALOG:
74          Services_Create_OnInitDialog (hDlg, (LPIDENT)( ((LPPROPSHEETPAGE)lp)->lParam ));
75          break;
76
77       case WM_COMMAND:
78          switch (LOWORD(wp))
79             {
80             case IDAPPLY:
81                Services_Create_OnApply (hDlg);
82                break;
83
84             case IDC_SVC_NAME:
85                TCHAR szService[ cchNAME ];
86                GetDlgItemText (hDlg, IDC_SVC_NAME, szService, cchNAME);
87
88                TCHAR szLogFile[ MAX_PATH ];
89                Services_GuessLogName (szLogFile, szService);
90                if (szLogFile[0] != TEXT('\0'))
91                   SetDlgItemText (hDlg, IDC_SVC_LOGFILE, szLogFile);
92
93                Services_Create_EnableOK (hDlg);
94                break;
95
96             case IDC_SVC_COMMAND:
97                Services_Create_EnableOK (hDlg);
98                break;
99
100             case IDC_SVC_TYPE_SIMPLE:
101             case IDC_SVC_TYPE_CRON:
102                Services_Create_OnType (hDlg);
103                break;
104             }
105          break;
106       }
107
108    return FALSE;
109 }
110
111
112 void Services_Create_OnInitDialog (HWND hDlg, LPIDENT lpi)
113 {
114    CheckDlgButton (hDlg, IDC_SVC_TYPE_SIMPLE, TRUE);
115    CheckDlgButton (hDlg, IDC_SVC_RUNNOW, TRUE);
116
117    LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
118    lpp->hCombo = GetDlgItem (hDlg, IDC_SVC_SERVER);
119    lpp->lpiSelect = lpi;
120    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);
121
122    HWND hName = GetDlgItem (hDlg, IDC_SVC_NAME);
123    CB_StartChange (hName, TRUE);
124    CB_AddItem (hName, TEXT("buserver"), 0);
125    CB_AddItem (hName, TEXT("fileserver"), 0);
126    CB_AddItem (hName, TEXT("kaserver"), 0);
127    CB_AddItem (hName, TEXT("ptserver"), 0);
128    CB_AddItem (hName, TEXT("salvager"), 0);
129    CB_AddItem (hName, TEXT("upclient"), 0);
130    CB_AddItem (hName, TEXT("upserver"), 0);
131    CB_AddItem (hName, TEXT("vlserver"), 0);
132    CB_AddItem (hName, TEXT("volserver"), 0);
133    CB_EndChange (hName, 0);
134
135    Services_Create_EnableOK (hDlg);
136    Services_Create_OnType (hDlg);
137 }
138
139
140 void Services_Create_OnType (HWND hDlg)
141 {
142    AFSSERVICETYPE type;
143    if (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_FS))
144       type = SERVICETYPE_FS;
145    else if (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_CRON))
146       type = SERVICETYPE_CRON;
147    else // (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_SIMPLE))
148       type = SERVICETYPE_SIMPLE;
149
150    EnableWindow (GetDlgItem (hDlg, IDC_SVC_RUNNOW), (type == SERVICETYPE_SIMPLE));
151    EnableWindow (GetDlgItem (hDlg, IDC_SVC_RUNDAY),  (type == SERVICETYPE_CRON));
152    EnableWindow (GetDlgItem (hDlg, IDC_SVC_RUNTIME), (type == SERVICETYPE_CRON));
153
154    HWND hDay = GetDlgItem (hDlg, IDC_SVC_RUNDAY);
155    CB_StartChange (hDay, TRUE);
156    CB_AddItem (hDay, IDS_RECUR_DAILY,    -1);
157    CB_AddItem (hDay, IDS_RECUR_SUNDAY,    0);
158    CB_AddItem (hDay, IDS_RECUR_MONDAY,    1);
159    CB_AddItem (hDay, IDS_RECUR_TUESDAY,   2);
160    CB_AddItem (hDay, IDS_RECUR_WEDNESDAY, 3);
161    CB_AddItem (hDay, IDS_RECUR_THURSDAY,  4);
162    CB_AddItem (hDay, IDS_RECUR_FRIDAY,    5);
163    CB_AddItem (hDay, IDS_RECUR_SATURDAY,  6);
164    CB_EndChange (hDay, -1);
165 }
166
167
168 void Services_Create_OnApply (HWND hDlg)
169 {
170    LPSVC_CREATE_PARAMS lpp = New (SVC_CREATE_PARAMS);
171    lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SVC_SERVER));
172    GetDlgItemText (hDlg, IDC_SVC_NAME, lpp->szService, cchNAME);
173    GetDlgItemText (hDlg, IDC_SVC_COMMAND, lpp->szCommand, cchNAME);
174    GetDlgItemText (hDlg, IDC_SVC_PARAMS, lpp->szParams, cchNAME);
175    GetDlgItemText (hDlg, IDC_SVC_LOGFILE, lpp->szLogFile, cchNAME);
176    GetDlgItemText (hDlg, IDC_SVC_NOTIFIER, lpp->szNotifier, cchNAME);
177
178    if (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_FS))
179       lpp->type = SERVICETYPE_FS;
180    else if (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_CRON))
181       lpp->type = SERVICETYPE_CRON;
182    else // (IsDlgButtonChecked (hDlg, IDC_SVC_TYPE_SIMPLE))
183       lpp->type = SERVICETYPE_SIMPLE;
184
185    if (lpp->type == SERVICETYPE_SIMPLE)
186       {
187       lpp->fRunNow = IsDlgButtonChecked (hDlg, IDC_SVC_RUNNOW);
188       }
189    else if (lpp->type == SERVICETYPE_CRON)
190       {
191       TI_GetTime (GetDlgItem (hDlg, IDC_SVC_RUNTIME), &lpp->stIfCron);
192       lpp->stIfCron.wDayOfWeek = (WORD)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SVC_RUNDAY));
193       // wDayOfWeek: -1==daily, 0==sunday etc
194       }
195
196    StartTask (taskSVC_CREATE, NULL, lpp);
197 }
198
199
200 void Services_Create_EnableOK (HWND hDlg)
201 {
202    BOOL fEnable = TRUE;
203
204    if (!IsWindowEnabled (GetDlgItem (hDlg, IDC_SVC_SERVER)))
205       fEnable = FALSE;
206
207    if (fEnable)
208       {
209       TCHAR szText[ cchRESOURCE ];
210       GetDlgItemText (hDlg, IDC_SVC_NAME, szText, cchRESOURCE);
211       if (szText[0] == TEXT('\0'))
212          fEnable = FALSE;
213       }
214
215    if (fEnable)
216       {
217       TCHAR szText[ cchRESOURCE ];
218       GetDlgItemText (hDlg, IDC_SVC_COMMAND, szText, cchRESOURCE);
219       if (szText[0] == TEXT('\0'))
220          fEnable = FALSE;
221       }
222
223    EnableWindow (GetDlgItem (GetParent(hDlg), IDOK), fEnable);
224 }
225