LibreOffice Module extensions (master) 1
abpfinalpage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "abpfinalpage.hxx"
21#include "addresssettings.hxx"
22#include "abspilot.hxx"
23#include <osl/diagnose.h>
24#include <tools/urlobj.hxx>
25#include <svtools/inettbc.hxx>
28#include <svl/filenotation.hxx>
29#include <sfx2/docfilt.hxx>
30#include <o3tl/string_view.hxx>
31
32namespace abp
33{
34
35 using namespace ::svt;
36 using namespace ::utl;
37
38 static std::shared_ptr<const SfxFilter> lcl_getBaseFilter()
39 {
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;
43 }
44
46 : AddressBookSourcePage(pPage, pWizard, "modules/sabpilot/ui/datasourcepage.ui",
47 "DataSourcePage")
48 , m_xLocation(new SvtURLBox(m_xBuilder->weld_combo_box("location")))
49 , m_xBrowse(m_xBuilder->weld_button("browse"))
50 , m_xRegisterName(m_xBuilder->weld_check_button("available"))
51 , m_xEmbed(m_xBuilder->weld_check_button("embed"))
52 , m_xNameLabel(m_xBuilder->weld_label("nameft"))
53 , m_xLocationLabel(m_xBuilder->weld_label("locationft"))
54 , m_xName(m_xBuilder->weld_entry("name"))
55 , m_xDuplicateNameError(m_xBuilder->weld_label("warning"))
56 {
57 m_xLocation->SetSmartProtocol(INetProtocol::File);
58 m_xLocation->DisableHistory();
59
61 *m_xLocation, *m_xBrowse, *pWizard->getDialog()) );
62
63 m_xName->connect_changed( LINK(this, FinalPage, OnEntryNameModified) );
64 m_xLocation->connect_changed( LINK(this, FinalPage, OnComboNameModified) );
65 m_xRegisterName->connect_toggled( LINK( this, FinalPage, OnRegister ) );
66 m_xRegisterName->set_active(true);
67 m_xEmbed->connect_toggled( LINK( this, FinalPage, OnEmbed ) );
68 m_xEmbed->set_active(true);
69 }
70
72 {
74 }
75
77 {
78 OUString sCurrentName(m_xName->get_text());
79
80 if (sCurrentName.isEmpty())
81 // the name must not be empty
82 return false;
83
84 if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
85 // there already is a data source with this name
86 return false;
87
88 return true;
89 }
90
92 {
93 AddressSettings& rSettings = getSettings();
94
96 if( aURL.GetProtocol() == INetProtocol::NotValid )
97 {
98 OUString sPath = SvtPathOptions().GetWorkPath() +
99 "/" + rSettings.sDataSourceName;
100
101 std::shared_ptr<const SfxFilter> pFilter = lcl_getBaseFilter();
102 if ( pFilter )
103 {
104 OUString sExt = pFilter->GetDefaultExtension();
105 sPath += o3tl::getToken(sExt,1,'*');
106 }
107
108 aURL.SetURL(sPath);
109 }
110 OSL_ENSURE( aURL.GetProtocol() != INetProtocol::NotValid ,"No valid file name!");
112 m_xLocationController->setURL( rSettings.sDataSourceName );
113 OUString sName = aURL.getName( );
114 sal_Int32 nPos = sName.indexOf(aURL.GetFileExtension());
115 if ( nPos != -1 )
116 {
117 sName = sName.replaceAt(nPos-1, 4, u"");
118 }
119 m_xName->set_text(sName);
120
121 OnRegister(*m_xRegisterName);
122 }
123
124
126 {
128
129 setFields();
130 }
131
133 {
135 return false;
136
137 if ( ( ::vcl::WizardTypes::eTravelBackward != _eReason )
138 && ( !m_xLocationController->prepareCommit() )
139 )
140 return false;
141
142 AddressSettings& rSettings = getSettings();
143 rSettings.sDataSourceName = m_xLocationController->getURL();
144 rSettings.bRegisterDataSource = m_xRegisterName->get_active();
145 if ( rSettings.bRegisterDataSource )
146 rSettings.sRegisteredDataSourceName = m_xName->get_text();
147 rSettings.bEmbedDataSource = m_xEmbed->get_active();
148
149 return true;
150 }
151
153 {
155
156 // get the names of all data sources
157 ODataSourceContext aContext( getORB() );
159
160 // give the name edit the focus
161 m_xLocation->grab_focus();
162
163 // default the finish button
164 getDialog()->defaultButton( WizardButtonFlags::FINISH );
165
166 OnEmbed(*m_xEmbed);
167 }
168
170 {
172
173 // default the "next" button, again
174 getDialog()->defaultButton( WizardButtonFlags::NEXT );
175 // disable the finish button
176 getDialog()->enableButtons( WizardButtonFlags::FINISH, false );
177 }
178
179
181 {
182 return false;
183 }
184
186 {
187 bool bValidName = isValidName();
188 bool bEmptyName = m_xName->get_text().isEmpty();
189 bool bEmptyLocation = m_xLocation->get_active_text().isEmpty();
190
191 // enable or disable the finish button
192 getDialog()->enableButtons( WizardButtonFlags::FINISH, !bEmptyLocation && (!m_xRegisterName->get_active() || bValidName) );
193
194 // show the error message for an invalid name
195 m_xDuplicateNameError->set_visible(!bValidName && !bEmptyName);
196 }
197
198 IMPL_LINK_NOARG( FinalPage, OnEntryNameModified, weld::Entry&, void )
199 {
200 implCheckName();
201 }
202
203 IMPL_LINK_NOARG( FinalPage, OnComboNameModified, weld::ComboBox&, void )
204 {
205 implCheckName();
206 }
207
209 {
210 bool bEnable = m_xRegisterName->get_active();
211 m_xNameLabel->set_sensitive(bEnable);
212 m_xName->set_sensitive(bEnable);
213 implCheckName();
214 }
215
217 {
218 bool bEmbed = m_xEmbed->get_active();
219 m_xLocationLabel->set_sensitive(!bEmbed);
220 m_xLocation->set_sensitive(!bEmbed);
221 m_xBrowse->set_sensitive(!bEmbed);
222 }
223
224} // namespace abp
225
226
227/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::shared_ptr< const SfxFilter > GetFilterByName(const OUString &rName)
const OUString & GetWorkPath() const
the base class for all tab pages in the address book source wizard
Definition: abspage.hxx:36
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
Definition: abspage.cxx:66
virtual void Activate() override
Definition: abspage.cxx:34
virtual void Deactivate() override
Definition: abspage.cxx:40
OAddressBookSourcePilot * getDialog()
Definition: abspage.cxx:46
AddressSettings & getSettings()
Definition: abspage.cxx:56
bool isValidName() const
std::unique_ptr< weld::Button > m_xBrowse
std::unique_ptr< weld::CheckButton > m_xRegisterName
std::unique_ptr< weld::CheckButton > m_xEmbed
std::unique_ptr< SvtURLBox > m_xLocation
virtual ~FinalPage() override
virtual bool canAdvance() const override
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
virtual void Deactivate() override
std::unique_ptr< weld::Label > m_xDuplicateNameError
virtual void initializePage() override
StringBag m_aInvalidDataSourceNames
std::unique_ptr< weld::Entry > m_xName
FinalPage(weld::Container *pPage, OAddressBookSourcePilot *pController)
virtual void Activate() override
std::unique_ptr< svx::DatabaseLocationInputController > m_xLocationController
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
get the service factory which was used to create the dialog
Definition: abspilot.hxx:51
a non-UNO wrapper for the data source context
void getDataSourceNames(StringBag &_rNames) const
retrieves the names of all data sources
virtual bool commitPage(WizardTypes::CommitPageReason _eReason) override
virtual void initializePage() override
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
virtual Dialog * getDialog() override
URL aURL
float u
OUString sName
sal_uInt16 nPos
static std::shared_ptr< const SfxFilter > lcl_getBaseFilter()
IMPL_LINK_NOARG(FinalPage, OnEntryNameModified, weld::Entry &, void)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString sRegisteredDataSourceName