Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "abpfinalpage.hxx"
30 : : #include "addresssettings.hxx"
31 : : #include "abspilot.hxx"
32 : : #include <tools/urlobj.hxx>
33 : : #include <unotools/ucbhelper.hxx>
34 : : #include <unotools/pathoptions.hxx>
35 : : #include <svl/filenotation.hxx>
36 : : #include <sfx2/docfilt.hxx>
37 : : #include <vcl/msgbox.hxx>
38 : : #include <comphelper/componentcontext.hxx>
39 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
40 : :
41 : : //.........................................................................
42 : : namespace abp
43 : : {
44 : : //.........................................................................
45 : : using namespace ::svt;
46 : : using namespace ::utl;
47 : :
48 : 0 : const SfxFilter* lcl_getBaseFilter()
49 : : {
50 : 0 : const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
51 : : OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
52 : 0 : return pFilter;
53 : : }
54 : : //=====================================================================
55 : : //= FinalPage
56 : : //=====================================================================
57 : : //---------------------------------------------------------------------
58 : 0 : FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
59 : : :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
60 : : ,m_aExplanation ( this, ModuleRes( FT_FINISH_EXPL ) )
61 : : ,m_aLocationLabel ( this, ModuleRes( FT_LOCATION ) )
62 : : ,m_aLocation ( this, ModuleRes( CBB_LOCATION ) )
63 : : ,m_aBrowse ( this, ModuleRes( PB_BROWSE ) )
64 : : ,m_aRegisterName ( this, ModuleRes( CB_REGISTER_DS ) )
65 : : ,m_aNameLabel ( this, ModuleRes( FT_NAME_EXPL ) )
66 : : ,m_aName ( this, ModuleRes( ET_DATASOURCENAME ) )
67 : : ,m_aDuplicateNameError ( this, ModuleRes( FT_DUPLICATENAME ) )
68 : 0 : ,m_aLocationController( ::comphelper::ComponentContext( _pParent->getORB() ), m_aLocation, m_aBrowse )
69 : : {
70 : 0 : FreeResource();
71 : :
72 : 0 : m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
73 : 0 : m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
74 : 0 : m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
75 : 0 : m_aRegisterName.Check(sal_True);
76 : 0 : }
77 : :
78 : : //---------------------------------------------------------------------
79 : 0 : sal_Bool FinalPage::isValidName() const
80 : : {
81 : 0 : ::rtl::OUString sCurrentName(m_aName.GetText());
82 : :
83 : 0 : if (sCurrentName.isEmpty())
84 : : // the name must not be empty
85 : 0 : return sal_False;
86 : :
87 : 0 : if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
88 : : // there already is a data source with this name
89 : 0 : return sal_False;
90 : :
91 : 0 : return sal_True;
92 : : }
93 : :
94 : : //---------------------------------------------------------------------
95 : 0 : void FinalPage::setFields()
96 : : {
97 : 0 : AddressSettings& rSettings = getSettings();
98 : :
99 : 0 : INetURLObject aURL( rSettings.sDataSourceName );
100 : 0 : if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
101 : : {
102 : 0 : String sPath = SvtPathOptions().GetWorkPath();
103 : 0 : sPath += '/';
104 : 0 : sPath += String(rSettings.sDataSourceName);
105 : :
106 : 0 : const SfxFilter* pFilter = lcl_getBaseFilter();
107 : 0 : if ( pFilter )
108 : : {
109 : 0 : String sExt = pFilter->GetDefaultExtension();
110 : 0 : sPath += sExt.GetToken(1,'*');
111 : : }
112 : :
113 : 0 : aURL.SetURL(sPath);
114 : : }
115 : : OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
116 : 0 : rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
117 : 0 : m_aLocationController.setURL( rSettings.sDataSourceName );
118 : 0 : String sName = aURL.getName( );
119 : 0 : xub_StrLen nPos = sName.Search(String(aURL.GetExtension()));
120 : 0 : if ( nPos != STRING_NOTFOUND )
121 : : {
122 : 0 : sName.Erase(nPos-1,4);
123 : : }
124 : 0 : m_aName.SetText(sName);
125 : :
126 : 0 : OnRegister(&m_aRegisterName);
127 : 0 : }
128 : :
129 : : //---------------------------------------------------------------------
130 : 0 : void FinalPage::initializePage()
131 : : {
132 : 0 : AddressBookSourcePage::initializePage();
133 : :
134 : 0 : setFields();
135 : 0 : }
136 : :
137 : : //---------------------------------------------------------------------
138 : 0 : sal_Bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
139 : : {
140 : 0 : if (!AddressBookSourcePage::commitPage(_eReason))
141 : 0 : return sal_False;
142 : :
143 : 0 : if ( ( ::svt::WizardTypes::eTravelBackward != _eReason )
144 : 0 : && ( !m_aLocationController.prepareCommit() )
145 : : )
146 : 0 : return sal_False;
147 : :
148 : 0 : AddressSettings& rSettings = getSettings();
149 : 0 : rSettings.sDataSourceName = m_aLocationController.getURL();
150 : 0 : rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
151 : 0 : if ( rSettings.bRegisterDataSource )
152 : 0 : rSettings.sRegisteredDataSourceName = m_aName.GetText();
153 : :
154 : 0 : return sal_True;
155 : : }
156 : :
157 : : //---------------------------------------------------------------------
158 : 0 : void FinalPage::ActivatePage()
159 : : {
160 : 0 : AddressBookSourcePage::ActivatePage();
161 : :
162 : : // get the names of all data sources
163 : 0 : ODataSourceContext aContext( getORB() );
164 : 0 : aContext.getDataSourceNames( m_aInvalidDataSourceNames );
165 : :
166 : : // give the name edit the focus
167 : 0 : m_aLocation.GrabFocus();
168 : :
169 : : // default the finish button
170 : 0 : getDialog()->defaultButton( WZB_FINISH );
171 : 0 : }
172 : :
173 : : //---------------------------------------------------------------------
174 : 0 : void FinalPage::DeactivatePage()
175 : : {
176 : 0 : AddressBookSourcePage::DeactivatePage();
177 : :
178 : : // default the "next" button, again
179 : 0 : getDialog()->defaultButton( WZB_NEXT );
180 : : // disable the finish button
181 : 0 : getDialog()->enableButtons( WZB_FINISH, sal_False );
182 : 0 : }
183 : :
184 : : //---------------------------------------------------------------------
185 : 0 : bool FinalPage::canAdvance() const
186 : : {
187 : 0 : return false;
188 : : }
189 : :
190 : : //---------------------------------------------------------------------
191 : 0 : void FinalPage::implCheckName()
192 : : {
193 : 0 : sal_Bool bValidName = isValidName();
194 : 0 : sal_Bool bEmptyName = 0 == m_aName.GetText().Len();
195 : 0 : sal_Bool bEmptyLocation = 0 == m_aLocation.GetText().Len();
196 : :
197 : : // enable or disable the finish button
198 : 0 : getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
199 : :
200 : : // show the error message for an invalid name
201 : 0 : m_aDuplicateNameError.Show( !bValidName && !bEmptyName );
202 : 0 : }
203 : :
204 : : //---------------------------------------------------------------------
205 : 0 : IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
206 : : {
207 : 0 : implCheckName();
208 : 0 : return 0L;
209 : : }
210 : :
211 : : // -----------------------------------------------------------------------------
212 : 0 : IMPL_LINK_NOARG(FinalPage, OnRegister)
213 : : {
214 : 0 : sal_Bool bEnable = m_aRegisterName.IsChecked();
215 : 0 : m_aNameLabel.Enable(bEnable);
216 : 0 : m_aName.Enable(bEnable);
217 : 0 : implCheckName();
218 : 0 : return 0L;
219 : : }
220 : : //.........................................................................
221 : : } // namespace abp
222 : : //.........................................................................
223 : :
224 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|