bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / abpilot / abpfinalpage.cxx
bloba27798dab01b2615ac8170c4ddf3e542f989fa21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "abpfinalpage.hxx"
21 #include "addresssettings.hxx"
22 #include "abspilot.hxx"
23 #include <tools/urlobj.hxx>
24 #include <unotools/ucbhelper.hxx>
25 #include <unotools/pathoptions.hxx>
26 #include <svl/filenotation.hxx>
27 #include <sfx2/docfilt.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <comphelper/componentcontext.hxx>
30 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
32 //.........................................................................
33 namespace abp
35 //.........................................................................
36 using namespace ::svt;
37 using namespace ::utl;
39 const SfxFilter* lcl_getBaseFilter()
41 const SfxFilter* pFilter = SfxFilter::GetFilterByName(OUString("StarOffice XML (Base)"));
42 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
43 return pFilter;
45 //=====================================================================
46 //= FinalPage
47 //=====================================================================
48 //---------------------------------------------------------------------
49 FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
50 :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
51 ,m_aExplanation ( this, ModuleRes( FT_FINISH_EXPL ) )
52 ,m_aLocationLabel ( this, ModuleRes( FT_LOCATION ) )
53 ,m_aLocation ( this, ModuleRes( CBB_LOCATION ) )
54 ,m_aBrowse ( this, ModuleRes( PB_BROWSE ) )
55 ,m_aRegisterName ( this, ModuleRes( CB_REGISTER_DS ) )
56 ,m_aNameLabel ( this, ModuleRes( FT_NAME_EXPL ) )
57 ,m_aName ( this, ModuleRes( ET_DATASOURCENAME ) )
58 ,m_aDuplicateNameError ( this, ModuleRes( FT_DUPLICATENAME ) )
59 ,m_aLocationController( ::comphelper::ComponentContext( _pParent->getORB() ), m_aLocation, m_aBrowse )
61 FreeResource();
63 m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
64 m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
65 m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
66 m_aRegisterName.Check(sal_True);
69 //---------------------------------------------------------------------
70 sal_Bool FinalPage::isValidName() const
72 OUString sCurrentName(m_aName.GetText());
74 if (sCurrentName.isEmpty())
75 // the name must not be empty
76 return sal_False;
78 if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
79 // there already is a data source with this name
80 return sal_False;
82 return sal_True;
85 //---------------------------------------------------------------------
86 void FinalPage::setFields()
88 AddressSettings& rSettings = getSettings();
90 INetURLObject aURL( rSettings.sDataSourceName );
91 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
93 String sPath = SvtPathOptions().GetWorkPath();
94 sPath += '/';
95 sPath += String(rSettings.sDataSourceName);
97 const SfxFilter* pFilter = lcl_getBaseFilter();
98 if ( pFilter )
100 String sExt = pFilter->GetDefaultExtension();
101 sPath += sExt.GetToken(1,'*');
104 aURL.SetURL(sPath);
106 OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
107 rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
108 m_aLocationController.setURL( rSettings.sDataSourceName );
109 String sName = aURL.getName( );
110 xub_StrLen nPos = sName.Search(String(aURL.GetExtension()));
111 if ( nPos != STRING_NOTFOUND )
113 sName.Erase(nPos-1,4);
115 m_aName.SetText(sName);
117 OnRegister(&m_aRegisterName);
120 //---------------------------------------------------------------------
121 void FinalPage::initializePage()
123 AddressBookSourcePage::initializePage();
125 setFields();
128 //---------------------------------------------------------------------
129 sal_Bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
131 if (!AddressBookSourcePage::commitPage(_eReason))
132 return sal_False;
134 if ( ( ::svt::WizardTypes::eTravelBackward != _eReason )
135 && ( !m_aLocationController.prepareCommit() )
137 return sal_False;
139 AddressSettings& rSettings = getSettings();
140 rSettings.sDataSourceName = m_aLocationController.getURL();
141 rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
142 if ( rSettings.bRegisterDataSource )
143 rSettings.sRegisteredDataSourceName = m_aName.GetText();
145 return sal_True;
148 //---------------------------------------------------------------------
149 void FinalPage::ActivatePage()
151 AddressBookSourcePage::ActivatePage();
153 // get the names of all data sources
154 ODataSourceContext aContext( getORB() );
155 aContext.getDataSourceNames( m_aInvalidDataSourceNames );
157 // give the name edit the focus
158 m_aLocation.GrabFocus();
160 // default the finish button
161 getDialog()->defaultButton( WZB_FINISH );
164 //---------------------------------------------------------------------
165 void FinalPage::DeactivatePage()
167 AddressBookSourcePage::DeactivatePage();
169 // default the "next" button, again
170 getDialog()->defaultButton( WZB_NEXT );
171 // disable the finish button
172 getDialog()->enableButtons( WZB_FINISH, sal_False );
175 //---------------------------------------------------------------------
176 bool FinalPage::canAdvance() const
178 return false;
181 //---------------------------------------------------------------------
182 void FinalPage::implCheckName()
184 sal_Bool bValidName = isValidName();
185 sal_Bool bEmptyName = m_aName.GetText().isEmpty();
186 sal_Bool bEmptyLocation = m_aLocation.GetText().isEmpty();
188 // enable or disable the finish button
189 getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
191 // show the error message for an invalid name
192 m_aDuplicateNameError.Show( !bValidName && !bEmptyName );
195 //---------------------------------------------------------------------
196 IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
198 implCheckName();
199 return 0L;
202 // -----------------------------------------------------------------------------
203 IMPL_LINK_NOARG(FinalPage, OnRegister)
205 sal_Bool bEnable = m_aRegisterName.IsChecked();
206 m_aNameLabel.Enable(bEnable);
207 m_aName.Enable(bEnable);
208 implCheckName();
209 return 0L;
211 //.........................................................................
212 } // namespace abp
213 //.........................................................................
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */