Update ooo320-m1
[ooovba.git] / extensions / source / abpilot / abpfinalpage.cxx
blobf3b1d9fe4bfd82e03252a5fa0e5482ea6791ff3f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: abpfinalpage.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "abpfinalpage.hxx"
34 #include "addresssettings.hxx"
35 #include "abspilot.hxx"
36 #include <tools/debug.hxx>
37 #include <tools/urlobj.hxx>
38 #include <unotools/ucbhelper.hxx>
39 #include <sfx2/filedlghelper.hxx>
40 #include <svtools/pathoptions.hxx>
41 #ifndef SVTOOLS_FILENOTATION_HXX_
42 #include <svtools/filenotation.hxx>
43 #endif
44 #include <sfx2/docfilt.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <comphelper/componentcontext.hxx>
47 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49 //.........................................................................
50 namespace abp
52 //.........................................................................
53 using namespace ::svt;
54 using namespace ::utl;
56 const SfxFilter* lcl_getBaseFilter()
58 static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
59 const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
60 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
61 return pFilter;
63 //=====================================================================
64 //= FinalPage
65 //=====================================================================
66 //---------------------------------------------------------------------
67 FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
68 :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
69 ,m_aExplanation ( this, ModuleRes( FT_FINISH_EXPL ) )
70 ,m_aLocationLabel ( this, ModuleRes( FT_LOCATION ) )
71 ,m_aLocation ( this, ModuleRes( CBB_LOCATION ) )
72 ,m_aBrowse ( this, ModuleRes( PB_BROWSE ) )
73 ,m_aRegisterName ( this, ModuleRes( CB_REGISTER_DS ) )
74 ,m_aNameLabel ( this, ModuleRes( FT_NAME_EXPL ) )
75 ,m_aName ( this, ModuleRes( ET_DATASOURCENAME ) )
76 ,m_aDuplicateNameError ( this, ModuleRes( FT_DUPLICATENAME ) )
77 ,m_aLocationController( ::comphelper::ComponentContext( _pParent->getORB() ), m_aLocation, m_aBrowse )
79 FreeResource();
81 m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
82 m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
83 m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
84 m_aRegisterName.Check(TRUE);
87 //---------------------------------------------------------------------
88 sal_Bool FinalPage::isValidName() const
90 ::rtl::OUString sCurrentName(m_aName.GetText());
92 if (0 == sCurrentName.getLength())
93 // the name must not be empty
94 return sal_False;
96 if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
97 // there already is a data source with this name
98 return sal_False;
100 return sal_True;
103 //---------------------------------------------------------------------
104 void FinalPage::setFields()
106 AddressSettings& rSettings = getSettings();
108 INetURLObject aURL( rSettings.sDataSourceName );
109 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
111 String sPath = SvtPathOptions().GetWorkPath();
112 sPath += '/';
113 sPath += String(rSettings.sDataSourceName);
115 const SfxFilter* pFilter = lcl_getBaseFilter();
116 if ( pFilter )
118 String sExt = pFilter->GetDefaultExtension();
119 sPath += sExt.GetToken(1,'*');
122 aURL.SetURL(sPath);
124 OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
125 rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
126 m_aLocationController.setURL( rSettings.sDataSourceName );
127 String sName = aURL.getName( );
128 xub_StrLen nPos = sName.Search(String(aURL.GetExtension()));
129 if ( nPos != STRING_NOTFOUND )
131 sName.Erase(nPos-1,4);
133 m_aName.SetText(sName);
135 OnRegister(&m_aRegisterName);
138 //---------------------------------------------------------------------
139 void FinalPage::initializePage()
141 AddressBookSourcePage::initializePage();
143 setFields();
146 //---------------------------------------------------------------------
147 sal_Bool FinalPage::commitPage( CommitPageReason _eReason )
149 if (!AddressBookSourcePage::commitPage(_eReason))
150 return sal_False;
152 if ( ( eTravelBackward != _eReason )
153 && ( !m_aLocationController.prepareCommit() )
155 return sal_False;
157 AddressSettings& rSettings = getSettings();
158 rSettings.sDataSourceName = m_aLocationController.getURL();
159 rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
160 if ( rSettings.bRegisterDataSource )
161 rSettings.sRegisteredDataSourceName = m_aName.GetText();
163 return sal_True;
166 //---------------------------------------------------------------------
167 void FinalPage::ActivatePage()
169 AddressBookSourcePage::ActivatePage();
171 // get the names of all data sources
172 ODataSourceContext aContext( getORB() );
173 aContext.getDataSourceNames( m_aInvalidDataSourceNames );
175 // give the name edit the focus
176 m_aLocation.GrabFocus();
178 // default the finish button
179 getDialog()->defaultButton( WZB_FINISH );
182 //---------------------------------------------------------------------
183 void FinalPage::DeactivatePage()
185 AddressBookSourcePage::DeactivatePage();
187 // default the "next" button, again
188 getDialog()->defaultButton( WZB_NEXT );
189 // disable the finish button
190 getDialog()->enableButtons( WZB_FINISH, sal_False );
193 //---------------------------------------------------------------------
194 bool FinalPage::canAdvance() const
196 return false;
199 //---------------------------------------------------------------------
200 void FinalPage::implCheckName()
202 sal_Bool bValidName = isValidName();
203 sal_Bool bEmptyName = 0 == m_aName.GetText().Len();
204 sal_Bool bEmptyLocation = 0 == m_aLocation.GetText().Len();
206 // enable or disable the finish button
207 getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
209 // show the error message for an invalid name
210 m_aDuplicateNameError.Show( !bValidName && !bEmptyName );
213 //---------------------------------------------------------------------
214 IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
216 implCheckName();
217 return 0L;
220 // -----------------------------------------------------------------------------
221 IMPL_LINK( FinalPage, OnRegister, CheckBox*, EMPTYARG )
223 BOOL bEnable = m_aRegisterName.IsChecked();
224 m_aNameLabel.Enable(bEnable);
225 m_aName.Enable(bEnable);
226 implCheckName();
227 return 0L;
229 //.........................................................................
230 } // namespace abp
231 //.........................................................................