Hide the back button on the initial wizard screen.
[people/sha0/mDNSResponder.git] / Clients / PrinterSetupWizard / PrinterSetupWizardSheet.h
1 /* -*- Mode: C; tab-width: 4 -*-
2  *
3  * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20
21 #include "secondpage.h"
22 #include "thirdpage.h"
23 #include "fourthpage.h"
24 #include "UtilTypes.h"
25 #include "Logger.h"
26 #include "dns_sd.h"
27 #include <stdexcept>
28 #include <map>
29
30 using namespace PrinterSetupWizard;
31
32 // CPrinterSetupWizardSheet
33
34 class CPrinterSetupWizardSheet : public CPropertySheet
35 {
36         DECLARE_DYNAMIC(CPrinterSetupWizardSheet)
37
38 public:
39
40         struct WizardException
41         {
42                 CString text;
43                 CString caption;
44         };
45
46 public:
47
48         CPrinterSetupWizardSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
49         virtual ~CPrinterSetupWizardSheet();
50
51         CPropertyPage*
52         GetLastPage();
53
54         void
55         SetLastPage(CPropertyPage * page );
56
57         void
58         SetSelectedPrinter(Printer * printer);
59
60         Printer*
61         GetSelectedPrinter();
62
63         OSStatus
64         LoadPrinterDriver(const CString & filename);
65
66         HCURSOR
67         GetCursor();
68
69         //
70         // handles end of process event
71         //
72         virtual LRESULT
73         OnProcessEvent(WPARAM inWParam, LPARAM inLParam);
74         
75         virtual LRESULT
76         OnSocketEvent(WPARAM inWParam, LPARAM inLParam);
77
78         virtual BOOL
79         OnCommand(WPARAM wParam, LPARAM lParam);
80
81         virtual BOOL
82         OnInitDialog();
83
84         virtual BOOL
85         OnSetCursor(CWnd * pWnd, UINT nHitTest, UINT message);
86
87         virtual void
88         OnContextMenu(CWnd * pWnd, CPoint pos);
89
90         afx_msg void
91         OnOK();
92
93         OSStatus
94         StartResolve( Printer * printer );
95
96         OSStatus
97         StopResolve( Printer * printer );
98
99         Printers                                m_printers;
100
101         HCURSOR                                 m_active;
102         HCURSOR                                 m_arrow;
103         HCURSOR                                 m_wait;
104
105 protected:
106         DECLARE_MESSAGE_MAP()
107         CSecondPage             m_pgSecond;
108         CThirdPage              m_pgThird;
109         CFourthPage             m_pgFourth;
110
111         void
112         OnServiceResolved(
113                 Service                         *       service);
114
115         void Init(void);
116
117 private:
118
119         // This is from <cups/http.h>
120         typedef enum http_encryption_e          /**** HTTP encryption values ****/
121         {
122                 HTTP_ENCRYPT_IF_REQUESTED,              /* Encrypt if requested (TLS upgrade) */
123                 HTTP_ENCRYPT_NEVER,                     /* Never encrypt */
124                 HTTP_ENCRYPT_REQUIRED,          /* Encryption is required (TLS upgrade) */
125                 HTTP_ENCRYPT_ALWAYS                     /* Always encrypt (SSL) */
126         } http_encryption_t;
127
128         typedef void*                           ( *httpConnectEncryptFunc )( const char* host, int port, http_encryption_t encryption );
129         typedef http_encryption_t       ( *cupsEncryptionFunc )( void );
130         typedef void                            ( *cupsSetEncryptionFunc )( http_encryption_t e );
131         typedef char*                           ( *cupsAdminCreateWindowsPPDFunc )( void * http, const char *dest, char *buffer, int bufsize );
132
133         class CUPSLibrary
134         {
135         public:
136
137                 CUPSLibrary()
138                         :
139                         httpConnectEncrypt( NULL ),
140                         cupsEncryption( NULL ),
141                         cupsSetEncryption( NULL ),
142                         cupsAdminCreateWindowsPPD( NULL ),
143                         library( NULL )
144                 {
145                         if ( ( library = LoadLibrary( TEXT( "libcups2.dll" ) ) ) != NULL )
146                         {
147                                 httpConnectEncrypt = ( httpConnectEncryptFunc ) GetProcAddress( library, "httpConnectEncrypt" );
148                                 cupsEncryption = ( cupsEncryptionFunc ) GetProcAddress( library, "cupsEncryption" );
149                                 cupsSetEncryption = ( cupsSetEncryptionFunc ) GetProcAddress( library, "cupsSetEncryption" );
150                                 cupsAdminCreateWindowsPPD = ( cupsAdminCreateWindowsPPDFunc ) GetProcAddress( library, "cupsAdminCreateWindowsPPD" );
151                         }
152                 }
153
154                 ~CUPSLibrary()
155                 {
156                         if ( library )
157                         {
158                                 FreeLibrary( library );
159                                 library = NULL;
160                         }
161                 }
162
163                 BOOL
164                 IsInstalled()
165                 {
166                         return ( ( httpConnectEncrypt != NULL ) && ( cupsEncryption != NULL ) && ( cupsSetEncryption != NULL ) && ( cupsAdminCreateWindowsPPD != NULL ) );
167                 }
168
169                 httpConnectEncryptFunc                  httpConnectEncrypt;
170                 cupsEncryptionFunc                              cupsEncryption;
171                 cupsSetEncryptionFunc                   cupsSetEncryption;
172                 cupsAdminCreateWindowsPPDFunc   cupsAdminCreateWindowsPPD;
173
174         private:
175
176                 HMODULE                                                 library;
177         };
178
179
180         static void DNSSD_API
181         OnBrowse(
182                 DNSServiceRef                   inRef,
183                 DNSServiceFlags                 inFlags,
184                 uint32_t                                inInterfaceIndex,
185                 DNSServiceErrorType     inErrorCode,
186                 const char *                    inName, 
187                 const char *                    inType, 
188                 const char *                    inDomain,       
189                 void *                                  inContext );
190
191         static void DNSSD_API
192         OnResolve(
193                 DNSServiceRef                   inRef,
194                 DNSServiceFlags                 inFlags,
195                 uint32_t                                inInterfaceIndex,
196                 DNSServiceErrorType             inErrorCode,
197                 const char *                    inFullName,     
198                 const char *                    inHostName, 
199                 uint16_t                                inPort,
200                 uint16_t                                inTXTSize,
201                 const char *                    inTXT,
202                 void *                                  inContext );
203
204         static void DNSSD_API
205         OnQuery(
206                 DNSServiceRef                   inRef, 
207                 DNSServiceFlags                 inFlags, 
208                 uint32_t                                inInterfaceIndex, 
209                 DNSServiceErrorType             inErrorCode,
210                 const char                      *       inFullName, 
211                 uint16_t                                inRRType, 
212                 uint16_t                                inRRClass, 
213                 uint16_t                                inRDLen, 
214                 const void                      *       inRData, 
215                 uint32_t                                inTTL, 
216                 void                            *       inContext);
217
218         Printer*
219         OnAddPrinter(
220                 uint32_t                                inInterfaceIndex,
221                 const char                      *       inName, 
222                 const char                      *       inType, 
223                 const char                      *       inDomain,
224                 bool                                    moreComing);
225
226         OSStatus
227         OnRemovePrinter(
228                 Printer                         *       printer,
229                 bool                                    moreComing);
230
231         OSStatus
232         OnAddService(
233                 Printer                         *       printer,
234                 uint32_t                                inInterfaceIndex,
235                 const char                      *       inName, 
236                 const char                      *       inType, 
237                 const char                      *       inDomain);
238
239         OSStatus
240         OnRemoveService(
241                 Service                         *       service);
242
243         void
244         OnResolveService(
245                 Service                         *       service );
246
247         static bool
248         OrderServiceFunc( const Service * a, const Service * b );
249
250         static bool
251         OrderQueueFunc( const Queue * q1, const Queue * q2 );
252
253         OSStatus
254         StartOperation( DNSServiceRef ref );
255
256         OSStatus
257         StopOperation( DNSServiceRef & ref );
258
259         OSStatus
260         StartBrowse();
261
262         OSStatus
263         StopBrowse();
264
265         OSStatus
266         StartResolve( Service * service );
267
268         OSStatus
269         StopResolve( Service * service );
270
271         OSStatus
272         ParseTextRecord( Service * service, Queue * q, uint16_t inTXTSize, const char * inTXT );
273
274         OSStatus
275         LoadPrinterNames();
276
277         Printer*
278         Lookup( const char * name );
279
280         OSStatus
281         InstallPrinter(Printer * printer);
282
283         OSStatus
284         InstallPrinterPDLAndLPR(Printer * printer, Service * service, DWORD protocol, Logger & log);
285
286         OSStatus
287         InstallPrinterIPP(Printer * printer, Service * service, Logger & log);
288         
289         OSStatus
290         InstallPrinterCUPS( Printer * printer, Service * service, CUPSLibrary & cupsLib );
291
292         OSStatus
293         InstallPrinterCUPS(Printer * printer, Service * service, CUPSLibrary & cupsLib, TCHAR * env );
294
295         static unsigned WINAPI
296         InstallDriverThread( LPVOID inParam );
297
298         typedef std::list<CString>                      PrinterNames;
299         typedef std::list<DNSServiceRef>        ServiceRefList;
300         static CPrinterSetupWizardSheet *       m_self;
301         PrinterNames                                            m_printerNames;
302         Printer                                                 *       m_selectedPrinter;
303         bool                                                            m_driverThreadFinished;
304         DWORD                                                           m_driverThreadExitCode;
305         ServiceRefList                                          m_serviceRefList;
306         DNSServiceRef                                           m_pdlBrowser;
307         DNSServiceRef                                           m_lprBrowser;
308         DNSServiceRef                                           m_ippBrowser;
309         DNSServiceRef                                           m_resolver;
310
311         CPropertyPage                                   *       m_lastPage;
312 };
313
314
315 inline Printer*
316 CPrinterSetupWizardSheet::GetSelectedPrinter()
317 {       
318         return m_selectedPrinter;
319 }
320
321
322 inline HCURSOR
323 CPrinterSetupWizardSheet::GetCursor()
324 {
325         return m_active;
326 }
327
328
329 inline CPropertyPage*
330 CPrinterSetupWizardSheet::GetLastPage()
331 {
332         return m_lastPage;
333 }
334
335
336 inline void
337 CPrinterSetupWizardSheet::SetLastPage(CPropertyPage * lastPage)
338 {
339         m_lastPage = lastPage;
340 }
341
342
343 // Service Types
344
345 #define kPDLServiceType         "_pdl-datastream._tcp."
346 #define kLPRServiceType         "_printer._tcp."
347 #define kIPPServiceType         "_ipp._tcp."