1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir #include "abspilot.hxx"
31*cdf0e10cSrcweir #include "abpilot.hrc"
32*cdf0e10cSrcweir #include "abpresid.hrc"
33*cdf0e10cSrcweir #include "componentmodule.hxx"
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
36*cdf0e10cSrcweir #include "typeselectionpage.hxx"
37*cdf0e10cSrcweir #include "admininvokationpage.hxx"
38*cdf0e10cSrcweir #include "tableselectionpage.hxx"
39*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
40*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
41*cdf0e10cSrcweir #include "abpfinalpage.hxx"
42*cdf0e10cSrcweir #include "fieldmappingpage.hxx"
43*cdf0e10cSrcweir #include "fieldmappingimpl.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //.........................................................................
46*cdf0e10cSrcweir namespace abp
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir //.........................................................................
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #define STATE_SELECT_ABTYPE         0
51*cdf0e10cSrcweir #define STATE_INVOKE_ADMIN_DIALOG   1
52*cdf0e10cSrcweir #define STATE_TABLE_SELECTION       2
53*cdf0e10cSrcweir #define STATE_MANUAL_FIELD_MAPPING  3
54*cdf0e10cSrcweir #define STATE_FINAL_CONFIRM         4
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #define PATH_COMPLETE               1
57*cdf0e10cSrcweir #define PATH_NO_SETTINGS            2
58*cdf0e10cSrcweir #define PATH_NO_FIELDS              3
59*cdf0e10cSrcweir #define PATH_NO_SETTINGS_NO_FIELDS  4
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	using namespace ::svt;
62*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
63*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	//=====================================================================
66*cdf0e10cSrcweir 	//= OAddessBookSourcePilot
67*cdf0e10cSrcweir 	//=====================================================================
68*cdf0e10cSrcweir 	//---------------------------------------------------------------------
69*cdf0e10cSrcweir 	OAddessBookSourcePilot::OAddessBookSourcePilot(Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB)
70*cdf0e10cSrcweir 		:OAddessBookSourcePilot_Base( _pParent, ModuleRes( RID_DLG_ADDRESSBOOKSOURCEPILOT ),
71*cdf0e10cSrcweir             WZB_HELP | WZB_FINISH | WZB_CANCEL | WZB_NEXT | WZB_PREVIOUS )
72*cdf0e10cSrcweir 		,m_xORB(_rxORB)
73*cdf0e10cSrcweir 		,m_aNewDataSource(_rxORB)
74*cdf0e10cSrcweir 		,m_eNewDataSourceType( AST_INVALID )
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		SetPageSizePixel(LogicToPixel(Size(WINDOW_SIZE_X, WINDOW_SIZE_Y), MAP_APPFONT));
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		ShowButtonFixedLine(sal_True);
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir         declarePath( PATH_COMPLETE,
81*cdf0e10cSrcweir             STATE_SELECT_ABTYPE,
82*cdf0e10cSrcweir             STATE_INVOKE_ADMIN_DIALOG,
83*cdf0e10cSrcweir             STATE_TABLE_SELECTION,
84*cdf0e10cSrcweir             STATE_MANUAL_FIELD_MAPPING,
85*cdf0e10cSrcweir             STATE_FINAL_CONFIRM,
86*cdf0e10cSrcweir             WZS_INVALID_STATE
87*cdf0e10cSrcweir         );
88*cdf0e10cSrcweir         declarePath( PATH_NO_SETTINGS,
89*cdf0e10cSrcweir             STATE_SELECT_ABTYPE,
90*cdf0e10cSrcweir             STATE_TABLE_SELECTION,
91*cdf0e10cSrcweir             STATE_MANUAL_FIELD_MAPPING,
92*cdf0e10cSrcweir             STATE_FINAL_CONFIRM,
93*cdf0e10cSrcweir             WZS_INVALID_STATE
94*cdf0e10cSrcweir         );
95*cdf0e10cSrcweir         declarePath( PATH_NO_FIELDS,
96*cdf0e10cSrcweir             STATE_SELECT_ABTYPE,
97*cdf0e10cSrcweir             STATE_INVOKE_ADMIN_DIALOG,
98*cdf0e10cSrcweir             STATE_TABLE_SELECTION,
99*cdf0e10cSrcweir             STATE_FINAL_CONFIRM,
100*cdf0e10cSrcweir             WZS_INVALID_STATE
101*cdf0e10cSrcweir         );
102*cdf0e10cSrcweir         declarePath( PATH_NO_SETTINGS_NO_FIELDS,
103*cdf0e10cSrcweir             STATE_SELECT_ABTYPE,
104*cdf0e10cSrcweir             STATE_TABLE_SELECTION,
105*cdf0e10cSrcweir             STATE_FINAL_CONFIRM,
106*cdf0e10cSrcweir             WZS_INVALID_STATE
107*cdf0e10cSrcweir         );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 		m_pPrevPage->SetHelpId(HID_ABSPILOT_PREVIOUS);
110*cdf0e10cSrcweir 		m_pNextPage->SetHelpId(HID_ABSPILOT_NEXT);
111*cdf0e10cSrcweir 		m_pCancel->SetHelpId(HID_ABSPILOT_CANCEL);
112*cdf0e10cSrcweir 		m_pFinish->SetHelpId(HID_ABSPILOT_FINISH);
113*cdf0e10cSrcweir 		m_pHelp->SetUniqueId(UID_ABSPILOT_HELP);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		m_pCancel->SetClickHdl( LINK( this, OAddessBookSourcePilot, OnCancelClicked) );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 		// some initial settings
118*cdf0e10cSrcweir #ifdef MACOSX
119*cdf0e10cSrcweir         m_aSettings.eType = AST_MACAB;
120*cdf0e10cSrcweir #elif WITH_MOZILLA
121*cdf0e10cSrcweir #ifdef UNX
122*cdf0e10cSrcweir 		m_aSettings.eType = AST_MORK;
123*cdf0e10cSrcweir #else
124*cdf0e10cSrcweir 		m_aSettings.eType = AST_OE;
125*cdf0e10cSrcweir #endif
126*cdf0e10cSrcweir #else
127*cdf0e10cSrcweir 		m_aSettings.eType = AST_OTHER;
128*cdf0e10cSrcweir #endif
129*cdf0e10cSrcweir 		m_aSettings.sDataSourceName = String(ModuleRes(RID_STR_DEFAULT_NAME));
130*cdf0e10cSrcweir 		m_aSettings.bRegisterDataSource = false;
131*cdf0e10cSrcweir 		m_aSettings.bIgnoreNoTable = false;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 		defaultButton(WZB_NEXT);
134*cdf0e10cSrcweir 		enableButtons(WZB_FINISH, sal_False);
135*cdf0e10cSrcweir 		ActivatePage();
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         typeSelectionChanged( m_aSettings.eType );
138*cdf0e10cSrcweir 	}
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	//---------------------------------------------------------------------
141*cdf0e10cSrcweir 	String OAddessBookSourcePilot::getStateDisplayName( WizardState _nState ) const
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         sal_uInt16 nResId = 0;
144*cdf0e10cSrcweir         switch ( _nState )
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             case STATE_SELECT_ABTYPE:        nResId = STR_SELECT_ABTYPE; break;
147*cdf0e10cSrcweir             case STATE_INVOKE_ADMIN_DIALOG:  nResId = STR_INVOKE_ADMIN_DIALOG; break;
148*cdf0e10cSrcweir             case STATE_TABLE_SELECTION:      nResId = STR_TABLE_SELECTION; break;
149*cdf0e10cSrcweir             case STATE_MANUAL_FIELD_MAPPING: nResId = STR_MANUAL_FIELD_MAPPING; break;
150*cdf0e10cSrcweir             case STATE_FINAL_CONFIRM:        nResId = STR_FINAL_CONFIRM; break;
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir         DBG_ASSERT( nResId, "OAddessBookSourcePilot::getStateDisplayName: don't know this state!" );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         String sDisplayName;
155*cdf0e10cSrcweir         if ( nResId )
156*cdf0e10cSrcweir         {
157*cdf0e10cSrcweir             svt::OLocalResourceAccess aAccess( ModuleRes( RID_DLG_ADDRESSBOOKSOURCEPILOT ), RSC_MODALDIALOG );
158*cdf0e10cSrcweir             sDisplayName = String( ModuleRes( nResId ) );
159*cdf0e10cSrcweir         }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         return sDisplayName;
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	//---------------------------------------------------------------------
165*cdf0e10cSrcweir 	void OAddessBookSourcePilot::implCommitAll()
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 		// in real, the data source already exists in the data source context
168*cdf0e10cSrcweir 		// Thus, if the user changed the name, we have to rename the data source
169*cdf0e10cSrcweir 		if ( m_aSettings.sDataSourceName != m_aNewDataSource.getName() )
170*cdf0e10cSrcweir 			m_aNewDataSource.rename( m_aSettings.sDataSourceName );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		// 1. the data source
173*cdf0e10cSrcweir 		m_aNewDataSource.store();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 		// 2. check if we need to register the data source
176*cdf0e10cSrcweir 		if ( m_aSettings.bRegisterDataSource )
177*cdf0e10cSrcweir 			m_aNewDataSource.registerDataSource(m_aSettings.sRegisteredDataSourceName);
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 		// 3. write the data source / table names into the configuration
180*cdf0e10cSrcweir 		addressconfig::writeTemplateAddressSource( getORB(), m_aSettings.bRegisterDataSource ? m_aSettings.sRegisteredDataSourceName : m_aSettings.sDataSourceName, m_aSettings.sSelectedTable );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		// 4. write the field mapping
183*cdf0e10cSrcweir 		fieldmapping::writeTemplateAddressFieldMapping( getORB(), m_aSettings.aFieldMapping );
184*cdf0e10cSrcweir 	}
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	//---------------------------------------------------------------------
187*cdf0e10cSrcweir 	void OAddessBookSourcePilot::implCleanup()
188*cdf0e10cSrcweir 	{
189*cdf0e10cSrcweir 		if ( m_aNewDataSource.isValid() )
190*cdf0e10cSrcweir 			m_aNewDataSource.remove();
191*cdf0e10cSrcweir 	}
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	//---------------------------------------------------------------------
194*cdf0e10cSrcweir 	IMPL_LINK( OAddessBookSourcePilot, OnCancelClicked, void*, /*NOTINTERESTEDIN*/ )
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir 		// do cleanups
197*cdf0e10cSrcweir 		implCleanup();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 		// reset the click hdl
200*cdf0e10cSrcweir 		m_pCancel->SetClickHdl( Link() );
201*cdf0e10cSrcweir 		// simulate the click again - this time, the default handling of the button will strike ....
202*cdf0e10cSrcweir 		m_pCancel->Click();
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		return 0L;
205*cdf0e10cSrcweir 	}
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	//---------------------------------------------------------------------
208*cdf0e10cSrcweir 	sal_Bool OAddessBookSourcePilot::Close()
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		implCleanup();
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 		return OAddessBookSourcePilot_Base::Close();
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 	//---------------------------------------------------------------------
216*cdf0e10cSrcweir 	sal_Bool OAddessBookSourcePilot::onFinish()
217*cdf0e10cSrcweir 	{
218*cdf0e10cSrcweir 		if ( !OAddessBookSourcePilot_Base::onFinish() )
219*cdf0e10cSrcweir 			return sal_False;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		implCommitAll();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		addressconfig::markPilotSuccess( getORB() );
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 		return sal_True;
226*cdf0e10cSrcweir 	}
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	//---------------------------------------------------------------------
229*cdf0e10cSrcweir 	void OAddessBookSourcePilot::enterState( WizardState _nState )
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		switch ( _nState )
232*cdf0e10cSrcweir 		{
233*cdf0e10cSrcweir 			case STATE_SELECT_ABTYPE:
234*cdf0e10cSrcweir                 impl_updateRoadmap( static_cast< TypeSelectionPage* >( GetPage( STATE_SELECT_ABTYPE ) )->getSelectedType() );
235*cdf0e10cSrcweir                 break;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 			case STATE_FINAL_CONFIRM:
238*cdf0e10cSrcweir 				if ( !needManualFieldMapping( ) )
239*cdf0e10cSrcweir 					implDoAutoFieldMapping();
240*cdf0e10cSrcweir 				break;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 			case STATE_TABLE_SELECTION:
243*cdf0e10cSrcweir 				implDefaultTableName();
244*cdf0e10cSrcweir 				break;
245*cdf0e10cSrcweir 		}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		OAddessBookSourcePilot_Base::enterState(_nState);
248*cdf0e10cSrcweir 	}
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     //---------------------------------------------------------------------
251*cdf0e10cSrcweir     sal_Bool OAddessBookSourcePilot::prepareLeaveCurrentState( CommitPageReason _eReason )
252*cdf0e10cSrcweir     {
253*cdf0e10cSrcweir         if ( !OAddessBookSourcePilot_Base::prepareLeaveCurrentState( _eReason ) )
254*cdf0e10cSrcweir             return sal_False;
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         if ( _eReason == eTravelBackward )
257*cdf0e10cSrcweir             return sal_True;
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         sal_Bool bAllow = sal_True;
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         switch ( getCurrentState() )
262*cdf0e10cSrcweir         {
263*cdf0e10cSrcweir         case STATE_SELECT_ABTYPE:
264*cdf0e10cSrcweir             implCreateDataSource();
265*cdf0e10cSrcweir             if ( needAdminInvokationPage() )
266*cdf0e10cSrcweir                 break;
267*cdf0e10cSrcweir             // no break here
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir         case STATE_INVOKE_ADMIN_DIALOG:
270*cdf0e10cSrcweir     		if ( !connectToDataSource( sal_False ) )
271*cdf0e10cSrcweir             {
272*cdf0e10cSrcweir 	    		// connecting did not succeed -> do not allow proceeding
273*cdf0e10cSrcweir                 bAllow = sal_False;
274*cdf0e10cSrcweir 		    	break;
275*cdf0e10cSrcweir             }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir             // ........................................................
278*cdf0e10cSrcweir             // now that we connected to the data source, check whether we need the "table selection" page
279*cdf0e10cSrcweir             const StringBag& aTables = m_aNewDataSource.getTableNames();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 			if ( aTables.empty() )
282*cdf0e10cSrcweir             {
283*cdf0e10cSrcweir                 if ( RET_YES != QueryBox( this, ModuleRes( RID_QRY_NOTABLES ) ).Execute() )
284*cdf0e10cSrcweir                 {
285*cdf0e10cSrcweir                     // cannot ask the user, or the user chose to use this data source, though there are no tables
286*cdf0e10cSrcweir                     bAllow = sal_False;
287*cdf0e10cSrcweir                     break;
288*cdf0e10cSrcweir                 }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 		        m_aSettings.bIgnoreNoTable = true;
291*cdf0e10cSrcweir 			}
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir             if ( aTables.size() == 1 )
294*cdf0e10cSrcweir 			    // remember the one and only table we have
295*cdf0e10cSrcweir 			    m_aSettings.sSelectedTable = *aTables.begin();
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir             break;
298*cdf0e10cSrcweir         }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir         impl_updateRoadmap( m_aSettings.eType );
301*cdf0e10cSrcweir         return bAllow;
302*cdf0e10cSrcweir     }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	//---------------------------------------------------------------------
305*cdf0e10cSrcweir 	void OAddessBookSourcePilot::implDefaultTableName()
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		const StringBag& rTableNames = getDataSource().getTableNames();
308*cdf0e10cSrcweir 		if ( rTableNames.end() != rTableNames.find( getSettings().sSelectedTable ) )
309*cdf0e10cSrcweir 			// already a valid table selected
310*cdf0e10cSrcweir 			return;
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 		const sal_Char* pGuess = NULL;
313*cdf0e10cSrcweir 		switch ( getSettings().eType )
314*cdf0e10cSrcweir 		{
315*cdf0e10cSrcweir 			case AST_MORK		        :
316*cdf0e10cSrcweir 			case AST_THUNDERBIRD        : pGuess = "Personal Address book"; break;
317*cdf0e10cSrcweir 			case AST_LDAP		        : pGuess = "LDAP Directory"; break;
318*cdf0e10cSrcweir 			case AST_EVOLUTION          :
319*cdf0e10cSrcweir 			case AST_EVOLUTION_GROUPWISE:
320*cdf0e10cSrcweir 			case AST_EVOLUTION_LDAP     : pGuess = "Personal"; break;
321*cdf0e10cSrcweir             default:
322*cdf0e10cSrcweir                 DBG_ERROR( "OAddessBookSourcePilot::implDefaultTableName: unhandled case!" );
323*cdf0e10cSrcweir                 return;
324*cdf0e10cSrcweir 		}
325*cdf0e10cSrcweir 		const ::rtl::OUString sGuess = ::rtl::OUString::createFromAscii( pGuess );
326*cdf0e10cSrcweir 		if ( rTableNames.end() != rTableNames.find( sGuess ) )
327*cdf0e10cSrcweir 			getSettings().sSelectedTable = sGuess;
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	//---------------------------------------------------------------------
331*cdf0e10cSrcweir 	void OAddessBookSourcePilot::implDoAutoFieldMapping()
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		DBG_ASSERT( !needManualFieldMapping( ), "OAddessBookSourcePilot::implDoAutoFieldMapping: invalid call!" );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 		fieldmapping::defaultMapping( getORB(), m_aSettings.aFieldMapping );
336*cdf0e10cSrcweir 	}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	//---------------------------------------------------------------------
339*cdf0e10cSrcweir 	void OAddessBookSourcePilot::implCreateDataSource()
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		if (m_aNewDataSource.isValid())
342*cdf0e10cSrcweir 		{	// we already have a data source object
343*cdf0e10cSrcweir 			if ( m_aSettings.eType == m_eNewDataSourceType )
344*cdf0e10cSrcweir 				// and it already has the correct type
345*cdf0e10cSrcweir 				return;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 			// it has a wrong type -> remove it
348*cdf0e10cSrcweir 			m_aNewDataSource.remove();
349*cdf0e10cSrcweir 		}
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 		ODataSourceContext aContext( getORB() );
352*cdf0e10cSrcweir 		aContext.disambiguate( m_aSettings.sDataSourceName );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 		switch (m_aSettings.eType)
355*cdf0e10cSrcweir 		{
356*cdf0e10cSrcweir 			case AST_MORK:
357*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewMORK( m_aSettings.sDataSourceName );
358*cdf0e10cSrcweir 				break;
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 			case AST_THUNDERBIRD:
361*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewThunderbird( m_aSettings.sDataSourceName );
362*cdf0e10cSrcweir 				break;
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 			case AST_EVOLUTION:
365*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewEvolution( m_aSettings.sDataSourceName );
366*cdf0e10cSrcweir 				break;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 			case AST_EVOLUTION_GROUPWISE:
369*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewEvolutionGroupwise( m_aSettings.sDataSourceName );
370*cdf0e10cSrcweir 				break;
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 			case AST_EVOLUTION_LDAP:
373*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewEvolutionLdap( m_aSettings.sDataSourceName );
374*cdf0e10cSrcweir 				break;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 			case AST_KAB:
377*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewKab( m_aSettings.sDataSourceName );
378*cdf0e10cSrcweir 				break;
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 			case AST_MACAB:
381*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewMacab( m_aSettings.sDataSourceName );
382*cdf0e10cSrcweir 				break;
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 			case AST_LDAP:
385*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewLDAP( m_aSettings.sDataSourceName );
386*cdf0e10cSrcweir 				break;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 			case AST_OUTLOOK:
389*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewOutlook( m_aSettings.sDataSourceName );
390*cdf0e10cSrcweir 				break;
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 			case AST_OE:
393*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewOE( m_aSettings.sDataSourceName );
394*cdf0e10cSrcweir 				break;
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 			case AST_OTHER:
397*cdf0e10cSrcweir 				m_aNewDataSource = aContext.createNewDBase( m_aSettings.sDataSourceName );
398*cdf0e10cSrcweir 				break;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir             case AST_INVALID:
401*cdf0e10cSrcweir                 DBG_ERROR( "OAddessBookSourcePilot::implCreateDataSource: illegal data source type!" );
402*cdf0e10cSrcweir                 break;
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 		m_eNewDataSourceType = m_aSettings.eType;
405*cdf0e10cSrcweir 	}
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	//---------------------------------------------------------------------
408*cdf0e10cSrcweir 	sal_Bool OAddessBookSourcePilot::connectToDataSource( sal_Bool _bForceReConnect )
409*cdf0e10cSrcweir 	{
410*cdf0e10cSrcweir 		DBG_ASSERT( m_aNewDataSource.isValid(), "OAddessBookSourcePilot::implConnect: invalid current data source!" );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 		WaitObject aWaitCursor( this );
413*cdf0e10cSrcweir 		if ( _bForceReConnect && m_aNewDataSource.isConnected( ) )
414*cdf0e10cSrcweir 			m_aNewDataSource.disconnect( );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 		return m_aNewDataSource.connect( this );
417*cdf0e10cSrcweir 	}
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	//---------------------------------------------------------------------
420*cdf0e10cSrcweir 	OWizardPage* OAddessBookSourcePilot::createPage(WizardState _nState)
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		switch (_nState)
423*cdf0e10cSrcweir 		{
424*cdf0e10cSrcweir 			case STATE_SELECT_ABTYPE:
425*cdf0e10cSrcweir 				return new TypeSelectionPage( this );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 			case STATE_INVOKE_ADMIN_DIALOG:
428*cdf0e10cSrcweir 				return new AdminDialogInvokationPage( this );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 			case STATE_TABLE_SELECTION:
431*cdf0e10cSrcweir 				return new TableSelectionPage( this );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 			case STATE_MANUAL_FIELD_MAPPING:
434*cdf0e10cSrcweir 				return new FieldMappingPage( this );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 			case STATE_FINAL_CONFIRM:
437*cdf0e10cSrcweir 				return new FinalPage( this );
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 			default:
440*cdf0e10cSrcweir 				DBG_ERROR("OAddessBookSourcePilot::createPage: invalid state!");
441*cdf0e10cSrcweir 				return NULL;
442*cdf0e10cSrcweir 		}
443*cdf0e10cSrcweir 	}
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     //---------------------------------------------------------------------
446*cdf0e10cSrcweir     void OAddessBookSourcePilot::impl_updateRoadmap( AddressSourceType _eType )
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         bool bSettingsPage = needAdminInvokationPage( _eType );
449*cdf0e10cSrcweir         bool bTablesPage   = needTableSelection( _eType );
450*cdf0e10cSrcweir         bool bFieldsPage   = needManualFieldMapping( _eType );
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir         bool bConnected = m_aNewDataSource.isConnected();
453*cdf0e10cSrcweir         bool bCanSkipTables =
454*cdf0e10cSrcweir                 (   m_aNewDataSource.hasTable( m_aSettings.sSelectedTable )
455*cdf0e10cSrcweir                 ||  m_aSettings.bIgnoreNoTable
456*cdf0e10cSrcweir                 );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir         enableState( STATE_INVOKE_ADMIN_DIALOG, bSettingsPage );
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir         enableState( STATE_TABLE_SELECTION,
461*cdf0e10cSrcweir             bTablesPage &&  ( bConnected ? !bCanSkipTables : !bSettingsPage )
462*cdf0e10cSrcweir             // if we do not need a settings page, we connect upon "Next" on the first page
463*cdf0e10cSrcweir         );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir         enableState( STATE_MANUAL_FIELD_MAPPING,
466*cdf0e10cSrcweir                 bFieldsPage && bConnected && m_aNewDataSource.hasTable( m_aSettings.sSelectedTable )
467*cdf0e10cSrcweir         );
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir         enableState( STATE_FINAL_CONFIRM,
470*cdf0e10cSrcweir             bConnected && bCanSkipTables
471*cdf0e10cSrcweir         );
472*cdf0e10cSrcweir     }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     //---------------------------------------------------------------------
475*cdf0e10cSrcweir     void OAddessBookSourcePilot::typeSelectionChanged( AddressSourceType _eType )
476*cdf0e10cSrcweir     {
477*cdf0e10cSrcweir         PathId nCurrentPathID( PATH_COMPLETE );
478*cdf0e10cSrcweir         bool bSettingsPage = needAdminInvokationPage( _eType );
479*cdf0e10cSrcweir         bool bFieldsPage = needManualFieldMapping( _eType );
480*cdf0e10cSrcweir         if ( !bSettingsPage )
481*cdf0e10cSrcweir             if ( !bFieldsPage )
482*cdf0e10cSrcweir                 nCurrentPathID = PATH_NO_SETTINGS_NO_FIELDS;
483*cdf0e10cSrcweir             else
484*cdf0e10cSrcweir                 nCurrentPathID = PATH_NO_SETTINGS;
485*cdf0e10cSrcweir         else
486*cdf0e10cSrcweir             if ( !bFieldsPage )
487*cdf0e10cSrcweir                 nCurrentPathID = PATH_NO_FIELDS;
488*cdf0e10cSrcweir             else
489*cdf0e10cSrcweir                 nCurrentPathID = PATH_COMPLETE;
490*cdf0e10cSrcweir         activatePath( nCurrentPathID, true );
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir         m_aNewDataSource.disconnect();
493*cdf0e10cSrcweir         m_aSettings.bIgnoreNoTable = false;
494*cdf0e10cSrcweir         impl_updateRoadmap( _eType );
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir //.........................................................................
498*cdf0e10cSrcweir }	// namespace abp
499*cdf0e10cSrcweir //.........................................................................
500*cdf0e10cSrcweir 
501