Line data Source code
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 <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 <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 :
31 :
32 : namespace abp
33 : {
34 :
35 : using namespace ::svt;
36 : using namespace ::utl;
37 :
38 0 : const SfxFilter* lcl_getBaseFilter()
39 : {
40 0 : const SfxFilter* pFilter = SfxFilter::GetFilterByName(OUString("StarOffice XML (Base)"));
41 : OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
42 0 : return pFilter;
43 : }
44 :
45 0 : FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
46 : : AddressBookSourcePage(_pParent, "DataSourcePage",
47 0 : "modules/sabpilot/ui/datasourcepage.ui")
48 : {
49 0 : get(m_pLocation, "location");
50 0 : get(m_pBrowse, "browse");
51 0 : get(m_pRegisterName, "available");
52 0 : get(m_pEmbed, "embed");
53 0 : get(m_pNameLabel, "nameft");
54 0 : get(m_pLocationLabel, "locationft");
55 0 : get(m_pName, "name");
56 0 : get(m_pDuplicateNameError, "warning");
57 : m_pLocationController = new svx::DatabaseLocationInputController(_pParent->getORB(),
58 0 : *m_pLocation, *m_pBrowse);
59 :
60 0 : m_pName->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
61 0 : m_pLocation->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
62 0 : m_pRegisterName->SetClickHdl( LINK( this, FinalPage, OnRegister ) );
63 0 : m_pRegisterName->Check(true);
64 0 : m_pEmbed->SetClickHdl( LINK( this, FinalPage, OnEmbed ) );
65 0 : m_pEmbed->Check(true);
66 0 : OnEmbed(m_pEmbed);
67 0 : }
68 :
69 0 : FinalPage::~FinalPage()
70 : {
71 0 : disposeOnce();
72 0 : }
73 :
74 0 : void FinalPage::dispose()
75 : {
76 0 : delete m_pLocationController;
77 0 : m_pLocation.clear();
78 0 : m_pBrowse.clear();
79 0 : m_pRegisterName.clear();
80 0 : m_pEmbed.clear();
81 0 : m_pNameLabel.clear();
82 0 : m_pLocationLabel.clear();
83 0 : m_pName.clear();
84 0 : m_pDuplicateNameError.clear();
85 0 : AddressBookSourcePage::dispose();
86 0 : }
87 :
88 0 : bool FinalPage::isValidName() const
89 : {
90 0 : OUString sCurrentName(m_pName->GetText());
91 :
92 0 : if (sCurrentName.isEmpty())
93 : // the name must not be empty
94 0 : return false;
95 :
96 0 : if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
97 : // there already is a data source with this name
98 0 : return false;
99 :
100 0 : return true;
101 : }
102 :
103 0 : void FinalPage::setFields()
104 : {
105 0 : AddressSettings& rSettings = getSettings();
106 :
107 0 : INetURLObject aURL( rSettings.sDataSourceName );
108 0 : if( aURL.GetProtocol() == INetProtocol::NotValid )
109 : {
110 0 : OUString sPath = SvtPathOptions().GetWorkPath();
111 0 : sPath += "/";
112 0 : sPath += rSettings.sDataSourceName;
113 :
114 0 : const SfxFilter* pFilter = lcl_getBaseFilter();
115 0 : if ( pFilter )
116 : {
117 0 : OUString sExt = pFilter->GetDefaultExtension();
118 0 : sPath += sExt.getToken(1,'*');
119 : }
120 :
121 0 : aURL.SetURL(sPath);
122 : }
123 : OSL_ENSURE( aURL.GetProtocol() != INetProtocol::NotValid ,"No valid file name!");
124 0 : rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
125 0 : m_pLocationController->setURL( rSettings.sDataSourceName );
126 0 : OUString sName = aURL.getName( );
127 0 : sal_Int32 nPos = sName.indexOf(aURL.GetExtension());
128 0 : if ( nPos != -1 )
129 : {
130 0 : sName = sName.replaceAt(nPos-1, 4, "");
131 : }
132 0 : m_pName->SetText(sName);
133 :
134 0 : OnRegister(m_pRegisterName);
135 0 : }
136 :
137 :
138 0 : void FinalPage::initializePage()
139 : {
140 0 : AddressBookSourcePage::initializePage();
141 :
142 0 : setFields();
143 0 : }
144 :
145 :
146 0 : bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
147 : {
148 0 : if (!AddressBookSourcePage::commitPage(_eReason))
149 0 : return false;
150 :
151 0 : if ( ( ::svt::WizardTypes::eTravelBackward != _eReason )
152 0 : && ( !m_pLocationController->prepareCommit() )
153 : )
154 0 : return false;
155 :
156 0 : AddressSettings& rSettings = getSettings();
157 0 : rSettings.sDataSourceName = m_pLocationController->getURL();
158 0 : rSettings.bRegisterDataSource = m_pRegisterName->IsChecked();
159 0 : if ( rSettings.bRegisterDataSource )
160 0 : rSettings.sRegisteredDataSourceName = m_pName->GetText();
161 0 : rSettings.bEmbedDataSource = m_pEmbed->IsChecked();
162 :
163 0 : return true;
164 : }
165 :
166 :
167 0 : void FinalPage::ActivatePage()
168 : {
169 0 : AddressBookSourcePage::ActivatePage();
170 :
171 : // get the names of all data sources
172 0 : ODataSourceContext aContext( getORB() );
173 0 : aContext.getDataSourceNames( m_aInvalidDataSourceNames );
174 :
175 : // give the name edit the focus
176 0 : m_pLocation->GrabFocus();
177 :
178 : // default the finish button
179 0 : getDialog()->defaultButton( WizardButtonFlags::FINISH );
180 0 : }
181 :
182 :
183 0 : void FinalPage::DeactivatePage()
184 : {
185 0 : AddressBookSourcePage::DeactivatePage();
186 :
187 : // default the "next" button, again
188 0 : getDialog()->defaultButton( WizardButtonFlags::NEXT );
189 : // disable the finish button
190 0 : getDialog()->enableButtons( WizardButtonFlags::FINISH, false );
191 0 : }
192 :
193 :
194 0 : bool FinalPage::canAdvance() const
195 : {
196 0 : return false;
197 : }
198 :
199 :
200 0 : void FinalPage::implCheckName()
201 : {
202 0 : bool bValidName = isValidName();
203 0 : bool bEmptyName = m_pName->GetText().isEmpty();
204 0 : bool bEmptyLocation = m_pLocation->GetText().isEmpty();
205 :
206 : // enable or disable the finish button
207 0 : getDialog()->enableButtons( WizardButtonFlags::FINISH, !bEmptyLocation && (!m_pRegisterName->IsChecked() || bValidName) );
208 :
209 : // show the error message for an invalid name
210 0 : m_pDuplicateNameError->Show( !bValidName && !bEmptyName );
211 0 : }
212 :
213 :
214 0 : IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
215 : {
216 0 : implCheckName();
217 0 : return 0L;
218 : }
219 :
220 :
221 0 : IMPL_LINK_NOARG(FinalPage, OnRegister)
222 : {
223 0 : bool bEnable = m_pRegisterName->IsChecked();
224 0 : m_pNameLabel->Enable(bEnable);
225 0 : m_pName->Enable(bEnable);
226 0 : implCheckName();
227 0 : return 0L;
228 : }
229 :
230 0 : IMPL_LINK_NOARG(FinalPage, OnEmbed)
231 : {
232 0 : bool bEmbed = m_pEmbed->IsChecked();
233 0 : m_pLocationLabel->Enable(!bEmbed);
234 0 : m_pLocation->Enable(!bEmbed);
235 0 : m_pBrowse->Enable(!bEmbed);
236 0 : return 0L;
237 : }
238 :
239 0 : } // namespace abp
240 :
241 :
242 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|