1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "abpfinalpage.hxx"
31 #include "addresssettings.hxx"
32 #include "abspilot.hxx"
33 #include <tools/debug.hxx>
34 #include <tools/urlobj.hxx>
35 #include <unotools/ucbhelper.hxx>
36 #include <sfx2/filedlghelper.hxx>
37 #include <unotools/pathoptions.hxx>
38 #ifndef SVTOOLS_FILENOTATION_HXX_
39 #include <svl/filenotation.hxx>
41 #include <sfx2/docfilt.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <comphelper/componentcontext.hxx>
44 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46 //.........................................................................
49 //.........................................................................
50 using namespace ::svt
;
51 using namespace ::utl
;
53 const SfxFilter
* lcl_getBaseFilter()
55 static const String s_sDatabaseType
= String::CreateFromAscii("StarOffice XML (Base)");
56 const SfxFilter
* pFilter
= SfxFilter::GetFilterByName( s_sDatabaseType
);
57 OSL_ENSURE(pFilter
,"Filter: StarOffice XML (Base) could not be found!");
60 //=====================================================================
62 //=====================================================================
63 //---------------------------------------------------------------------
64 FinalPage::FinalPage( OAddessBookSourcePilot
* _pParent
)
65 :AddressBookSourcePage(_pParent
, ModuleRes(RID_PAGE_FINAL
))
66 ,m_aExplanation ( this, ModuleRes( FT_FINISH_EXPL
) )
67 ,m_aLocationLabel ( this, ModuleRes( FT_LOCATION
) )
68 ,m_aLocation ( this, ModuleRes( CBB_LOCATION
) )
69 ,m_aBrowse ( this, ModuleRes( PB_BROWSE
) )
70 ,m_aRegisterName ( this, ModuleRes( CB_REGISTER_DS
) )
71 ,m_aNameLabel ( this, ModuleRes( FT_NAME_EXPL
) )
72 ,m_aName ( this, ModuleRes( ET_DATASOURCENAME
) )
73 ,m_aDuplicateNameError ( this, ModuleRes( FT_DUPLICATENAME
) )
74 ,m_aLocationController( ::comphelper::ComponentContext( _pParent
->getORB() ), m_aLocation
, m_aBrowse
)
78 m_aName
.SetModifyHdl( LINK(this, FinalPage
, OnNameModified
) );
79 m_aLocation
.SetModifyHdl( LINK(this, FinalPage
, OnNameModified
) );
80 m_aRegisterName
.SetClickHdl( LINK( this, FinalPage
, OnRegister
) );
81 m_aRegisterName
.Check(TRUE
);
84 //---------------------------------------------------------------------
85 sal_Bool
FinalPage::isValidName() const
87 ::rtl::OUString
sCurrentName(m_aName
.GetText());
89 if (0 == sCurrentName
.getLength())
90 // the name must not be empty
93 if ( m_aInvalidDataSourceNames
.find( sCurrentName
) != m_aInvalidDataSourceNames
.end() )
94 // there already is a data source with this name
100 //---------------------------------------------------------------------
101 void FinalPage::setFields()
103 AddressSettings
& rSettings
= getSettings();
105 INetURLObject
aURL( rSettings
.sDataSourceName
);
106 if( aURL
.GetProtocol() == INET_PROT_NOT_VALID
)
108 String sPath
= SvtPathOptions().GetWorkPath();
110 sPath
+= String(rSettings
.sDataSourceName
);
112 const SfxFilter
* pFilter
= lcl_getBaseFilter();
115 String sExt
= pFilter
->GetDefaultExtension();
116 sPath
+= sExt
.GetToken(1,'*');
121 OSL_ENSURE( aURL
.GetProtocol() != INET_PROT_NOT_VALID
,"No valid file name!");
122 rSettings
.sDataSourceName
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
123 m_aLocationController
.setURL( rSettings
.sDataSourceName
);
124 String sName
= aURL
.getName( );
125 xub_StrLen nPos
= sName
.Search(String(aURL
.GetExtension()));
126 if ( nPos
!= STRING_NOTFOUND
)
128 sName
.Erase(nPos
-1,4);
130 m_aName
.SetText(sName
);
132 OnRegister(&m_aRegisterName
);
135 //---------------------------------------------------------------------
136 void FinalPage::initializePage()
138 AddressBookSourcePage::initializePage();
143 //---------------------------------------------------------------------
144 sal_Bool
FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
146 if (!AddressBookSourcePage::commitPage(_eReason
))
149 if ( ( ::svt::WizardTypes::eTravelBackward
!= _eReason
)
150 && ( !m_aLocationController
.prepareCommit() )
154 AddressSettings
& rSettings
= getSettings();
155 rSettings
.sDataSourceName
= m_aLocationController
.getURL();
156 rSettings
.bRegisterDataSource
= m_aRegisterName
.IsChecked();
157 if ( rSettings
.bRegisterDataSource
)
158 rSettings
.sRegisteredDataSourceName
= m_aName
.GetText();
163 //---------------------------------------------------------------------
164 void FinalPage::ActivatePage()
166 AddressBookSourcePage::ActivatePage();
168 // get the names of all data sources
169 ODataSourceContext
aContext( getORB() );
170 aContext
.getDataSourceNames( m_aInvalidDataSourceNames
);
172 // give the name edit the focus
173 m_aLocation
.GrabFocus();
175 // default the finish button
176 getDialog()->defaultButton( WZB_FINISH
);
179 //---------------------------------------------------------------------
180 void FinalPage::DeactivatePage()
182 AddressBookSourcePage::DeactivatePage();
184 // default the "next" button, again
185 getDialog()->defaultButton( WZB_NEXT
);
186 // disable the finish button
187 getDialog()->enableButtons( WZB_FINISH
, sal_False
);
190 //---------------------------------------------------------------------
191 bool FinalPage::canAdvance() const
196 //---------------------------------------------------------------------
197 void FinalPage::implCheckName()
199 sal_Bool bValidName
= isValidName();
200 sal_Bool bEmptyName
= 0 == m_aName
.GetText().Len();
201 sal_Bool bEmptyLocation
= 0 == m_aLocation
.GetText().Len();
203 // enable or disable the finish button
204 getDialog()->enableButtons( WZB_FINISH
, !bEmptyLocation
&& (!m_aRegisterName
.IsChecked() || bValidName
) );
206 // show the error message for an invalid name
207 m_aDuplicateNameError
.Show( !bValidName
&& !bEmptyName
);
210 //---------------------------------------------------------------------
211 IMPL_LINK( FinalPage
, OnNameModified
, Edit
*, /**/ )
217 // -----------------------------------------------------------------------------
218 IMPL_LINK( FinalPage
, OnRegister
, CheckBox
*, EMPTYARG
)
220 BOOL bEnable
= m_aRegisterName
.IsChecked();
221 m_aNameLabel
.Enable(bEnable
);
222 m_aName
.Enable(bEnable
);
226 //.........................................................................
228 //.........................................................................