1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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!");
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");
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
) );
69 FinalPage::~FinalPage()
74 void FinalPage::dispose()
76 m_pLocationController
.reset();
79 m_pRegisterName
.clear();
82 m_pLocationLabel
.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
96 if ( m_aInvalidDataSourceNames
.find( sCurrentName
) != m_aInvalidDataSourceNames
.end() )
97 // there already is a data source with this name
103 void FinalPage::setFields()
105 AddressSettings
& rSettings
= getSettings();
107 INetURLObject
aURL( rSettings
.sDataSourceName
);
108 if( aURL
.GetProtocol() == INetProtocol::NotValid
)
110 OUString sPath
= SvtPathOptions().GetWorkPath();
112 sPath
+= rSettings
.sDataSourceName
;
114 std::shared_ptr
<const SfxFilter
> pFilter
= lcl_getBaseFilter();
117 OUString sExt
= pFilter
->GetDefaultExtension();
118 sPath
+= sExt
.getToken(1,'*');
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());
130 sName
= sName
.replaceAt(nPos
-1, 4, "");
132 m_pName
->SetText(sName
);
134 OnRegister(m_pRegisterName
);
138 void FinalPage::initializePage()
140 AddressBookSourcePage::initializePage();
146 bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
148 if (!AddressBookSourcePage::commitPage(_eReason
))
151 if ( ( ::svt::WizardTypes::eTravelBackward
!= _eReason
)
152 && ( !m_pLocationController
->prepareCommit() )
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();
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
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 )
220 IMPL_LINK_NOARG(FinalPage
, OnRegister
, Button
*, void)
222 bool bEnable
= m_pRegisterName
->IsChecked();
223 m_pNameLabel
->Enable(bEnable
);
224 m_pName
->Enable(bEnable
);
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
);
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */