1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: typeselectionpage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "typeselectionpage.hxx"
34 #include "addresssettings.hxx"
35 #include "abspilot.hxx"
36 #include <vcl/msgbox.hxx>
37 #include <com/sun/star/sdbc/XDriverAccess.hpp>
39 //.........................................................................
42 //.........................................................................
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::sdbc
;
47 //=====================================================================
49 //=====================================================================
50 //---------------------------------------------------------------------
51 TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot
* _pParent
)
52 :AddressBookSourcePage(_pParent
, ModuleRes(RID_PAGE_SELECTABTYPE
))
53 ,m_aHint (this, ModuleRes(FT_TYPE_HINTS
))
54 ,m_aTypeSep (this, ModuleRes(FL_TYPE
))
55 ,m_aEvolution (this, ModuleRes(RB_EVOLUTION
))
56 ,m_aEvolutionGroupwise (this, ModuleRes(RB_EVOLUTION_GROUPWISE
))
57 ,m_aEvolutionLdap (this, ModuleRes(RB_EVOLUTION_LDAP
))
58 ,m_aMORK (this, ModuleRes(RB_MORK
))
59 ,m_aThunderbird (this, ModuleRes(RB_THUNDERBIRD
))
60 ,m_aKab (this, ModuleRes(RB_KAB
))
61 ,m_aMacab (this, ModuleRes(RB_MACAB
))
62 ,m_aLDAP (this, ModuleRes(RB_LDAP
))
63 ,m_aOutlook (this, ModuleRes(RB_OUTLOOK
))
64 ,m_aOE (this, ModuleRes(RB_OUTLOOKEXPRESS
))
65 ,m_aOther (this, ModuleRes(RB_OTHER
))
69 Point
aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT
) );
70 Size
aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT
) );
71 aItemSize
.Width() = GetOutputSizePixel().Width() - 30;
73 bool bWithMozilla
= true, bUnx
= true;
74 bool bHaveEvolution
= true, bHaveKab
= true;
75 bool bHaveMacab
= true;
77 #if !defined WITH_MOZILLA || defined MACOSX
82 bHaveEvolution
= false;
86 Reference
< XDriverAccess
> xManager(_pParent
->getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager"))), UNO_QUERY
);
88 // check whether Evolution is available
89 Reference
< XDriver
> xDriver( xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:evolution:local"))) );
91 bHaveEvolution
= false;
93 // check whether KDE address book is available
94 xDriver
= xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab")));
98 // check whether Mac OS X address book is available
99 xDriver
= xManager
->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab")));
104 // Items are displayed in list order
105 m_aAllTypes
.push_back( ButtonItem( &m_aEvolution
, AST_EVOLUTION
, bHaveEvolution
) );
106 m_aAllTypes
.push_back( ButtonItem( &m_aEvolutionGroupwise
, AST_EVOLUTION_GROUPWISE
, bHaveEvolution
) );
107 m_aAllTypes
.push_back( ButtonItem( &m_aEvolutionLdap
, AST_EVOLUTION_LDAP
, bHaveEvolution
) );
108 m_aAllTypes
.push_back( ButtonItem( &m_aMORK
, AST_MORK
, bWithMozilla
) );
109 m_aAllTypes
.push_back( ButtonItem( &m_aThunderbird
, AST_THUNDERBIRD
, bWithMozilla
) );
110 m_aAllTypes
.push_back( ButtonItem( &m_aKab
, AST_KAB
, bHaveKab
) );
111 m_aAllTypes
.push_back( ButtonItem( &m_aMacab
, AST_MACAB
, bHaveMacab
) );
112 m_aAllTypes
.push_back( ButtonItem( &m_aLDAP
, AST_LDAP
, bWithMozilla
) );
113 m_aAllTypes
.push_back( ButtonItem( &m_aOutlook
, AST_OUTLOOK
, bWithMozilla
&& !bUnx
) );
114 m_aAllTypes
.push_back( ButtonItem( &m_aOE
, AST_OE
, bWithMozilla
&& !bUnx
) );
115 m_aAllTypes
.push_back( ButtonItem( &m_aOther
, AST_OTHER
, true ) );
117 bool bFirstVisible
= true;
118 Link aTypeSelectionHandler
= LINK(this, TypeSelectionPage
, OnTypeSelected
);
119 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
120 loop
!= m_aAllTypes
.end(); ++loop
)
122 ButtonItem aItem
= *loop
;
123 if (!aItem
.m_bVisible
)
124 aItem
.m_pItem
->Hide();
127 aItem
.m_pItem
->SetPosPixel( aTopLeft
);
128 aTopLeft
.Y() += aItemSize
.Height();
129 aItem
.m_pItem
->SetClickHdl( aTypeSelectionHandler
);
130 aItem
.m_pItem
->Show();
134 aItem
.m_pItem
->SetStyle( aItem
.m_pItem
->GetStyle() | WB_GROUP
);
135 bFirstVisible
= false;
141 //---------------------------------------------------------------------
142 TypeSelectionPage::~TypeSelectionPage()
144 for ( ::std::vector
< ButtonItem
>::iterator loop
= m_aAllTypes
.begin();
145 loop
!= m_aAllTypes
.end(); ++loop
)
147 loop
->m_bVisible
= false;
151 //---------------------------------------------------------------------
152 void TypeSelectionPage::ActivatePage()
154 AddressBookSourcePage::ActivatePage();
156 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
157 loop
!= m_aAllTypes
.end(); ++loop
)
159 const ButtonItem
& rItem
= (*loop
);
160 if( rItem
.m_pItem
->IsChecked() && rItem
.m_bVisible
)
162 rItem
.m_pItem
->GrabFocus();
167 getDialog()->enableButtons(WZB_PREVIOUS
, sal_False
);
170 //---------------------------------------------------------------------
171 void TypeSelectionPage::DeactivatePage()
173 AddressBookSourcePage::DeactivatePage();
174 getDialog()->enableButtons(WZB_PREVIOUS
, sal_True
);
177 //---------------------------------------------------------------------
178 void TypeSelectionPage::selectType( AddressSourceType _eType
)
180 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
181 loop
!= m_aAllTypes
.end(); ++loop
)
183 ButtonItem aItem
= (*loop
);
184 aItem
.m_pItem
->Check( _eType
== aItem
.m_eType
);
188 //---------------------------------------------------------------------
189 AddressSourceType
TypeSelectionPage::getSelectedType() const
191 for ( ::std::vector
< ButtonItem
>::const_iterator loop
= m_aAllTypes
.begin();
192 loop
!= m_aAllTypes
.end(); ++loop
)
194 ButtonItem aItem
= (*loop
);
195 if ( aItem
.m_pItem
->IsChecked() )
196 return aItem
.m_eType
;
202 //---------------------------------------------------------------------
203 void TypeSelectionPage::initializePage()
205 AddressBookSourcePage::initializePage();
207 const AddressSettings
& rSettings
= getSettings();
208 selectType(rSettings
.eType
);
211 //---------------------------------------------------------------------
212 sal_Bool
TypeSelectionPage::commitPage( CommitPageReason _eReason
)
214 if (!AddressBookSourcePage::commitPage(_eReason
))
217 if (AST_INVALID
== getSelectedType( ))
219 if ( _eReason
!= eValidateNoUI
)
221 ErrorBox
aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION
));
227 AddressSettings
& rSettings
= getSettings();
228 rSettings
.eType
= getSelectedType();
233 //---------------------------------------------------------------------
234 bool TypeSelectionPage::canAdvance() const
236 return AddressBookSourcePage::canAdvance()
237 && (AST_INVALID
!= getSelectedType());
240 //---------------------------------------------------------------------
241 IMPL_LINK( TypeSelectionPage
, OnTypeSelected
, void*, /*NOTINTERESTEDIN*/ )
243 getDialog()->typeSelectionChanged( getSelectedType() );
244 updateDialogTravelUI();
248 //.........................................................................
250 //.........................................................................