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 "typeselectionpage.hxx"
31 #include "addresssettings.hxx"
32 #include "abspilot.hxx"
33 #include <vcl/msgbox.hxx>
34 #include <com/sun/star/sdbc/XDriverAccess.hpp>
36 //.........................................................................
39 //.........................................................................
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::sdbc
;
44 //=====================================================================
46 //=====================================================================
47 //---------------------------------------------------------------------
48 TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot
* _pParent
)
49 :AddressBookSourcePage(_pParent
, ModuleRes(RID_PAGE_SELECTABTYPE
))
50 ,m_aHint (this, ModuleRes(FT_TYPE_HINTS
))
51 ,m_aTypeSep (this, ModuleRes(FL_TYPE
))
52 ,m_aEvolution (this, ModuleRes(RB_EVOLUTION
))
53 ,m_aEvolutionGroupwise (this, ModuleRes(RB_EVOLUTION_GROUPWISE
))
54 ,m_aEvolutionLdap (this, ModuleRes(RB_EVOLUTION_LDAP
))
55 ,m_aMORK (this, ModuleRes(RB_MORK
))
56 ,m_aThunderbird (this, ModuleRes(RB_THUNDERBIRD
))
57 ,m_aKab (this, ModuleRes(RB_KAB
))
58 ,m_aMacab (this, ModuleRes(RB_MACAB
))
59 ,m_aLDAP (this, ModuleRes(RB_LDAP
))
60 ,m_aOutlook (this, ModuleRes(RB_OUTLOOK
))
61 ,m_aOE (this, ModuleRes(RB_OUTLOOKEXPRESS
))
62 ,m_aOther (this, ModuleRes(RB_OTHER
))
66 Point
aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT
) );
67 Size
aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT
) );
68 aItemSize
.Width() = GetOutputSizePixel().Width() - 30;
70 bool bWithMozilla
= true, bUnx
= true;
71 bool bHaveEvolution
= true, bHaveKab
= true;
72 bool bHaveMacab
= true;
74 #if !defined WITH_MOZILLA || defined MACOSX
79 bHaveEvolution
= false;
83 Reference
< XDriverAccess
> xManager(_pParent
->getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager"))), UNO_QUERY
);
85 // check whether Evolution is available
86 Reference
< XDriver
> xDriver( xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:evolution:local"))) );
88 bHaveEvolution
= false;
90 // check whether KDE address book is available
91 xDriver
= xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab")));
95 // check whether Mac OS X address book is available
96 xDriver
= xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab")));
101 // Items are displayed in list order
102 m_aAllTypes
.push_back( ButtonItem( &m_aEvolution
, AST_EVOLUTION
, bHaveEvolution
) );
103 m_aAllTypes
.push_back( ButtonItem( &m_aEvolutionGroupwise
, AST_EVOLUTION_GROUPWISE
, bHaveEvolution
) );
104 m_aAllTypes
.push_back( ButtonItem( &m_aEvolutionLdap
, AST_EVOLUTION_LDAP
, bHaveEvolution
) );
105 m_aAllTypes
.push_back( ButtonItem( &m_aMORK
, AST_MORK
, bWithMozilla
) );
106 m_aAllTypes
.push_back( ButtonItem( &m_aThunderbird
, AST_THUNDERBIRD
, bWithMozilla
) );
107 m_aAllTypes
.push_back( ButtonItem( &m_aKab
, AST_KAB
, bHaveKab
) );
108 m_aAllTypes
.push_back( ButtonItem( &m_aMacab
, AST_MACAB
, bHaveMacab
) );
109 m_aAllTypes
.push_back( ButtonItem( &m_aLDAP
, AST_LDAP
, bWithMozilla
) );
110 m_aAllTypes
.push_back( ButtonItem( &m_aOutlook
, AST_OUTLOOK
, bWithMozilla
&& !bUnx
) );
111 m_aAllTypes
.push_back( ButtonItem( &m_aOE
, AST_OE
, bWithMozilla
&& !bUnx
) );
112 m_aAllTypes
.push_back( ButtonItem( &m_aOther
, AST_OTHER
, true ) );
114 bool bFirstVisible
= true;
115 Link aTypeSelectionHandler
= LINK(this, TypeSelectionPage
, OnTypeSelected
);
116 const Size
aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT
) );
117 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
118 loop
!= m_aAllTypes
.end(); ++loop
)
120 ButtonItem aItem
= *loop
;
121 if (!aItem
.m_bVisible
)
122 aItem
.m_pItem
->Hide();
125 aItem
.m_pItem
->SetPosPixel( aTopLeft
);
126 aTopLeft
.Y() += aItemSize
.Height() + aSpacing
.Height();
127 aItem
.m_pItem
->SetClickHdl( aTypeSelectionHandler
);
128 aItem
.m_pItem
->Show();
132 aItem
.m_pItem
->SetStyle( aItem
.m_pItem
->GetStyle() | WB_GROUP
);
133 bFirstVisible
= false;
139 //---------------------------------------------------------------------
140 TypeSelectionPage::~TypeSelectionPage()
142 for ( ::std::vector
< ButtonItem
>::iterator loop
= m_aAllTypes
.begin();
143 loop
!= m_aAllTypes
.end(); ++loop
)
145 loop
->m_bVisible
= false;
149 //---------------------------------------------------------------------
150 void TypeSelectionPage::ActivatePage()
152 AddressBookSourcePage::ActivatePage();
154 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
155 loop
!= m_aAllTypes
.end(); ++loop
)
157 const ButtonItem
& rItem
= (*loop
);
158 if( rItem
.m_pItem
->IsChecked() && rItem
.m_bVisible
)
160 rItem
.m_pItem
->GrabFocus();
165 getDialog()->enableButtons(WZB_PREVIOUS
, sal_False
);
168 //---------------------------------------------------------------------
169 void TypeSelectionPage::DeactivatePage()
171 AddressBookSourcePage::DeactivatePage();
172 getDialog()->enableButtons(WZB_PREVIOUS
, sal_True
);
175 //---------------------------------------------------------------------
176 void TypeSelectionPage::selectType( AddressSourceType _eType
)
178 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
179 loop
!= m_aAllTypes
.end(); ++loop
)
181 ButtonItem aItem
= (*loop
);
182 aItem
.m_pItem
->Check( _eType
== aItem
.m_eType
);
186 //---------------------------------------------------------------------
187 AddressSourceType
TypeSelectionPage::getSelectedType() const
189 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
190 loop
!= m_aAllTypes
.end(); ++loop
)
192 ButtonItem aItem
= (*loop
);
193 if ( aItem
.m_pItem
->IsChecked() )
194 return aItem
.m_eType
;
200 //---------------------------------------------------------------------
201 void TypeSelectionPage::initializePage()
203 AddressBookSourcePage::initializePage();
205 const AddressSettings
& rSettings
= getSettings();
206 selectType(rSettings
.eType
);
209 //---------------------------------------------------------------------
210 sal_Bool
TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
212 if (!AddressBookSourcePage::commitPage(_eReason
))
215 if (AST_INVALID
== getSelectedType( ))
217 ErrorBox
aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION
));
222 AddressSettings
& rSettings
= getSettings();
223 rSettings
.eType
= getSelectedType();
228 //---------------------------------------------------------------------
229 bool TypeSelectionPage::canAdvance() const
231 return AddressBookSourcePage::canAdvance()
232 && (AST_INVALID
!= getSelectedType());
235 //---------------------------------------------------------------------
236 IMPL_LINK( TypeSelectionPage
, OnTypeSelected
, void*, /*NOTINTERESTEDIN*/ )
238 getDialog()->typeSelectionChanged( getSelectedType() );
239 updateDialogTravelUI();
243 //.........................................................................
245 //.........................................................................