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