xref: /AOO41X/main/extensions/source/abpilot/abpfinalpage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "abpfinalpage.hxx"
31*cdf0e10cSrcweir #include "addresssettings.hxx"
32*cdf0e10cSrcweir #include "abspilot.hxx"
33*cdf0e10cSrcweir #include <tools/debug.hxx>
34*cdf0e10cSrcweir #include <tools/urlobj.hxx>
35*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
36*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
37*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
38*cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_
39*cdf0e10cSrcweir #include <svl/filenotation.hxx>
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
42*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
43*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
44*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //.........................................................................
47*cdf0e10cSrcweir namespace abp
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir //.........................................................................
50*cdf0e10cSrcweir 	using namespace ::svt;
51*cdf0e10cSrcweir 	using namespace ::utl;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	const SfxFilter* lcl_getBaseFilter()
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
56*cdf0e10cSrcweir 		const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
57*cdf0e10cSrcweir 		OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
58*cdf0e10cSrcweir 		return pFilter;
59*cdf0e10cSrcweir 	}
60*cdf0e10cSrcweir 	//=====================================================================
61*cdf0e10cSrcweir 	//= FinalPage
62*cdf0e10cSrcweir 	//=====================================================================
63*cdf0e10cSrcweir 	//---------------------------------------------------------------------
64*cdf0e10cSrcweir 	FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
65*cdf0e10cSrcweir 		:AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
66*cdf0e10cSrcweir 		,m_aExplanation			( this, ModuleRes( FT_FINISH_EXPL ) )
67*cdf0e10cSrcweir 		,m_aLocationLabel		( this, ModuleRes( FT_LOCATION ) )
68*cdf0e10cSrcweir 		,m_aLocation			( this, ModuleRes( CBB_LOCATION ) )
69*cdf0e10cSrcweir 		,m_aBrowse				( this, ModuleRes( PB_BROWSE ) )
70*cdf0e10cSrcweir 		,m_aRegisterName		( this, ModuleRes( CB_REGISTER_DS ) )
71*cdf0e10cSrcweir 		,m_aNameLabel			( this, ModuleRes( FT_NAME_EXPL ) )
72*cdf0e10cSrcweir 		,m_aName				( this, ModuleRes( ET_DATASOURCENAME ) )
73*cdf0e10cSrcweir 		,m_aDuplicateNameError	( this, ModuleRes( FT_DUPLICATENAME ) )
74*cdf0e10cSrcweir         ,m_aLocationController( ::comphelper::ComponentContext( _pParent->getORB() ), m_aLocation, m_aBrowse )
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		FreeResource();
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
79*cdf0e10cSrcweir 		m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
80*cdf0e10cSrcweir 		m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
81*cdf0e10cSrcweir 		m_aRegisterName.Check(sal_True);
82*cdf0e10cSrcweir 	}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//---------------------------------------------------------------------
85*cdf0e10cSrcweir 	sal_Bool FinalPage::isValidName() const
86*cdf0e10cSrcweir 	{
87*cdf0e10cSrcweir 		::rtl::OUString sCurrentName(m_aName.GetText());
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 		if (0 == sCurrentName.getLength())
90*cdf0e10cSrcweir 			// the name must not be empty
91*cdf0e10cSrcweir 			return sal_False;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 		if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
94*cdf0e10cSrcweir 			// there already is a data source with this name
95*cdf0e10cSrcweir 			return sal_False;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 		return sal_True;
98*cdf0e10cSrcweir 	}
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	//---------------------------------------------------------------------
101*cdf0e10cSrcweir 	void FinalPage::setFields()
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		AddressSettings& rSettings = getSettings();
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 		INetURLObject aURL( rSettings.sDataSourceName );
106*cdf0e10cSrcweir 		if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
107*cdf0e10cSrcweir 		{
108*cdf0e10cSrcweir 			String sPath = SvtPathOptions().GetWorkPath();
109*cdf0e10cSrcweir 			sPath += '/';
110*cdf0e10cSrcweir 			sPath += String(rSettings.sDataSourceName);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 			const SfxFilter* pFilter = lcl_getBaseFilter();
113*cdf0e10cSrcweir 			if ( pFilter )
114*cdf0e10cSrcweir 			{
115*cdf0e10cSrcweir 				String sExt = pFilter->GetDefaultExtension();
116*cdf0e10cSrcweir 				sPath += sExt.GetToken(1,'*');
117*cdf0e10cSrcweir 			}
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 			aURL.SetURL(sPath);
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir 		OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
122*cdf0e10cSrcweir 		rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
123*cdf0e10cSrcweir         m_aLocationController.setURL( rSettings.sDataSourceName );
124*cdf0e10cSrcweir 		String sName = aURL.getName( );
125*cdf0e10cSrcweir 		xub_StrLen nPos = sName.Search(String(aURL.GetExtension()));
126*cdf0e10cSrcweir 		if ( nPos != STRING_NOTFOUND )
127*cdf0e10cSrcweir 		{
128*cdf0e10cSrcweir 			sName.Erase(nPos-1,4);
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 		m_aName.SetText(sName);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		OnRegister(&m_aRegisterName);
133*cdf0e10cSrcweir 	}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	//---------------------------------------------------------------------
136*cdf0e10cSrcweir 	void FinalPage::initializePage()
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		AddressBookSourcePage::initializePage();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 		setFields();
141*cdf0e10cSrcweir 	}
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	//---------------------------------------------------------------------
144*cdf0e10cSrcweir     sal_Bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
145*cdf0e10cSrcweir 	{
146*cdf0e10cSrcweir 		if (!AddressBookSourcePage::commitPage(_eReason))
147*cdf0e10cSrcweir 			return sal_False;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         if  (   ( ::svt::WizardTypes::eTravelBackward != _eReason )
150*cdf0e10cSrcweir             &&  ( !m_aLocationController.prepareCommit() )
151*cdf0e10cSrcweir             )
152*cdf0e10cSrcweir             return sal_False;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 		AddressSettings& rSettings = getSettings();
155*cdf0e10cSrcweir 		rSettings.sDataSourceName = m_aLocationController.getURL();
156*cdf0e10cSrcweir 		rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
157*cdf0e10cSrcweir 		if ( rSettings.bRegisterDataSource )
158*cdf0e10cSrcweir 			rSettings.sRegisteredDataSourceName = m_aName.GetText();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 		return sal_True;
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	//---------------------------------------------------------------------
164*cdf0e10cSrcweir 	void FinalPage::ActivatePage()
165*cdf0e10cSrcweir 	{
166*cdf0e10cSrcweir 		AddressBookSourcePage::ActivatePage();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 		// get the names of all data sources
169*cdf0e10cSrcweir 		ODataSourceContext aContext( getORB() );
170*cdf0e10cSrcweir 		aContext.getDataSourceNames( m_aInvalidDataSourceNames );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		// give the name edit the focus
173*cdf0e10cSrcweir 		m_aLocation.GrabFocus();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 		// default the finish button
176*cdf0e10cSrcweir 		getDialog()->defaultButton( WZB_FINISH );
177*cdf0e10cSrcweir 	}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	//---------------------------------------------------------------------
180*cdf0e10cSrcweir 	void FinalPage::DeactivatePage()
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		AddressBookSourcePage::DeactivatePage();
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 		// default the "next" button, again
185*cdf0e10cSrcweir 		getDialog()->defaultButton( WZB_NEXT );
186*cdf0e10cSrcweir 		// disable the finish button
187*cdf0e10cSrcweir 		getDialog()->enableButtons( WZB_FINISH, sal_False );
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	//---------------------------------------------------------------------
191*cdf0e10cSrcweir 	bool FinalPage::canAdvance() const
192*cdf0e10cSrcweir 	{
193*cdf0e10cSrcweir 		return false;
194*cdf0e10cSrcweir 	}
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	//---------------------------------------------------------------------
197*cdf0e10cSrcweir 	void FinalPage::implCheckName()
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		sal_Bool bValidName = isValidName();
200*cdf0e10cSrcweir 		sal_Bool bEmptyName = 0 == m_aName.GetText().Len();
201*cdf0e10cSrcweir 		sal_Bool bEmptyLocation = 0 == m_aLocation.GetText().Len();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 		// enable or disable the finish button
204*cdf0e10cSrcweir 		getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		// show the error message for an invalid name
207*cdf0e10cSrcweir 		m_aDuplicateNameError.Show( !bValidName && !bEmptyName );
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	//---------------------------------------------------------------------
211*cdf0e10cSrcweir 	IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		implCheckName();
214*cdf0e10cSrcweir 		return 0L;
215*cdf0e10cSrcweir 	}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
218*cdf0e10cSrcweir 	IMPL_LINK( FinalPage, OnRegister, CheckBox*, EMPTYARG )
219*cdf0e10cSrcweir 	{
220*cdf0e10cSrcweir 		sal_Bool bEnable = m_aRegisterName.IsChecked();
221*cdf0e10cSrcweir 		m_aNameLabel.Enable(bEnable);
222*cdf0e10cSrcweir 		m_aName.Enable(bEnable);
223*cdf0e10cSrcweir 		implCheckName();
224*cdf0e10cSrcweir 		return 0L;
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir //.........................................................................
227*cdf0e10cSrcweir }	// namespace abp
228*cdf0e10cSrcweir //.........................................................................
229*cdf0e10cSrcweir 
230