bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / abpilot / abpfinalpage.cxx
blob92a7e804f6e495359760220de769da7ea6b013b3
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 <osl/diagnose.h>
24 #include <tools/urlobj.hxx>
25 #include <unotools/ucbhelper.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <svl/filenotation.hxx>
28 #include <sfx2/docfilt.hxx>
29 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
32 namespace abp
35 using namespace ::svt;
36 using namespace ::utl;
38 static std::shared_ptr<const SfxFilter> lcl_getBaseFilter()
40 std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetFilterByName("StarOffice XML (Base)");
41 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
42 return pFilter;
45 FinalPage::FinalPage( OAddressBookSourcePilot* _pParent )
46 : AddressBookSourcePage(_pParent, "DataSourcePage",
47 "modules/sabpilot/ui/datasourcepage.ui")
49 get(m_pLocation, "location");
50 get(m_pBrowse, "browse");
51 get(m_pRegisterName, "available");
52 get(m_pEmbed, "embed");
53 get(m_pNameLabel, "nameft");
54 get(m_pLocationLabel, "locationft");
55 get(m_pName, "name");
56 get(m_pDuplicateNameError, "warning");
57 m_pLocationController.reset( new svx::DatabaseLocationInputController(_pParent->getORB(),
58 *m_pLocation, *m_pBrowse) );
60 m_pName->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
61 m_pLocation->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
62 m_pRegisterName->SetClickHdl( LINK( this, FinalPage, OnRegister ) );
63 m_pRegisterName->Check();
64 m_pEmbed->SetClickHdl( LINK( this, FinalPage, OnEmbed ) );
65 m_pEmbed->Check();
66 OnEmbed(m_pEmbed);
69 FinalPage::~FinalPage()
71 disposeOnce();
74 void FinalPage::dispose()
76 m_pLocationController.reset();
77 m_pLocation.clear();
78 m_pBrowse.clear();
79 m_pRegisterName.clear();
80 m_pEmbed.clear();
81 m_pNameLabel.clear();
82 m_pLocationLabel.clear();
83 m_pName.clear();
84 m_pDuplicateNameError.clear();
85 AddressBookSourcePage::dispose();
88 bool FinalPage::isValidName() const
90 OUString sCurrentName(m_pName->GetText());
92 if (sCurrentName.isEmpty())
93 // the name must not be empty
94 return false;
96 if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
97 // there already is a data source with this name
98 return false;
100 return true;
103 void FinalPage::setFields()
105 AddressSettings& rSettings = getSettings();
107 INetURLObject aURL( rSettings.sDataSourceName );
108 if( aURL.GetProtocol() == INetProtocol::NotValid )
110 OUString sPath = SvtPathOptions().GetWorkPath();
111 sPath += "/";
112 sPath += rSettings.sDataSourceName;
114 std::shared_ptr<const SfxFilter> pFilter = lcl_getBaseFilter();
115 if ( pFilter )
117 OUString sExt = pFilter->GetDefaultExtension();
118 sPath += sExt.getToken(1,'*');
121 aURL.SetURL(sPath);
123 OSL_ENSURE( aURL.GetProtocol() != INetProtocol::NotValid ,"No valid file name!");
124 rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
125 m_pLocationController->setURL( rSettings.sDataSourceName );
126 OUString sName = aURL.getName( );
127 sal_Int32 nPos = sName.indexOf(aURL.GetExtension());
128 if ( nPos != -1 )
130 sName = sName.replaceAt(nPos-1, 4, "");
132 m_pName->SetText(sName);
134 OnRegister(m_pRegisterName);
138 void FinalPage::initializePage()
140 AddressBookSourcePage::initializePage();
142 setFields();
146 bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
148 if (!AddressBookSourcePage::commitPage(_eReason))
149 return false;
151 if ( ( ::svt::WizardTypes::eTravelBackward != _eReason )
152 && ( !m_pLocationController->prepareCommit() )
154 return false;
156 AddressSettings& rSettings = getSettings();
157 rSettings.sDataSourceName = m_pLocationController->getURL();
158 rSettings.bRegisterDataSource = m_pRegisterName->IsChecked();
159 if ( rSettings.bRegisterDataSource )
160 rSettings.sRegisteredDataSourceName = m_pName->GetText();
161 rSettings.bEmbedDataSource = m_pEmbed->IsChecked();
163 return true;
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_pLocation->GrabFocus();
178 // default the finish button
179 getDialog()->defaultButton( WizardButtonFlags::FINISH );
183 void FinalPage::DeactivatePage()
185 AddressBookSourcePage::DeactivatePage();
187 // default the "next" button, again
188 getDialog()->defaultButton( WizardButtonFlags::NEXT );
189 // disable the finish button
190 getDialog()->enableButtons( WizardButtonFlags::FINISH, false );
194 bool FinalPage::canAdvance() const
196 return false;
200 void FinalPage::implCheckName()
202 bool bValidName = isValidName();
203 bool bEmptyName = m_pName->GetText().isEmpty();
204 bool bEmptyLocation = m_pLocation->GetText().isEmpty();
206 // enable or disable the finish button
207 getDialog()->enableButtons( WizardButtonFlags::FINISH, !bEmptyLocation && (!m_pRegisterName->IsChecked() || bValidName) );
209 // show the error message for an invalid name
210 m_pDuplicateNameError->Show( !bValidName && !bEmptyName );
214 IMPL_LINK_NOARG( FinalPage, OnNameModified, Edit&, void )
216 implCheckName();
220 IMPL_LINK_NOARG(FinalPage, OnRegister, Button*, void)
222 bool bEnable = m_pRegisterName->IsChecked();
223 m_pNameLabel->Enable(bEnable);
224 m_pName->Enable(bEnable);
225 implCheckName();
228 IMPL_LINK_NOARG(FinalPage, OnEmbed, Button*, void)
230 bool bEmbed = m_pEmbed->IsChecked();
231 m_pLocationLabel->Enable(!bEmbed);
232 m_pLocation->Enable(!bEmbed);
233 m_pBrowse->Enable(!bEmbed);
236 } // namespace abp
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */