Update ooo320-m1
[ooovba.git] / extensions / source / abpilot / typeselectionpage.cxx
blobb6d9e0065fbf2fca282e9e7458df0b5d124c8d7a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: typeselectionpage.cxx,v $
10 * $Revision: 1.17 $
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 //.........................................................................
40 namespace abp
42 //.........................................................................
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::sdbc;
47 //=====================================================================
48 //= TypeSelectionPage
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))
67 FreeResource();
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
78 bWithMozilla = false;
79 #endif
80 #ifndef UNX
81 bUnx = false;
82 bHaveEvolution = false;
83 bHaveKab = false;
84 bHaveMacab = false;
85 #else
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"))) );
90 if ( !xDriver.is() )
91 bHaveEvolution = false;
93 // check whether KDE address book is available
94 xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab")));
95 if ( !xDriver.is() )
96 bHaveKab = false;
98 // check whether Mac OS X address book is available
99 xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab")));
100 if ( !xDriver.is() )
101 bHaveMacab = false;
102 #endif
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 const Size aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT ) );
120 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
121 loop != m_aAllTypes.end(); ++loop )
123 ButtonItem aItem = *loop;
124 if (!aItem.m_bVisible)
125 aItem.m_pItem->Hide();
126 else
128 aItem.m_pItem->SetPosPixel( aTopLeft );
129 aTopLeft.Y() += aItemSize.Height() + aSpacing.Height();
130 aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
131 aItem.m_pItem->Show();
133 if ( bFirstVisible )
135 aItem.m_pItem->SetStyle( aItem.m_pItem->GetStyle() | WB_GROUP );
136 bFirstVisible = false;
142 //---------------------------------------------------------------------
143 TypeSelectionPage::~TypeSelectionPage()
145 for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
146 loop != m_aAllTypes.end(); ++loop )
148 loop->m_bVisible = false;
152 //---------------------------------------------------------------------
153 void TypeSelectionPage::ActivatePage()
155 AddressBookSourcePage::ActivatePage();
157 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
158 loop != m_aAllTypes.end(); ++loop )
160 const ButtonItem& rItem = (*loop);
161 if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
163 rItem.m_pItem->GrabFocus();
164 break;
168 getDialog()->enableButtons(WZB_PREVIOUS, sal_False);
171 //---------------------------------------------------------------------
172 void TypeSelectionPage::DeactivatePage()
174 AddressBookSourcePage::DeactivatePage();
175 getDialog()->enableButtons(WZB_PREVIOUS, sal_True);
178 //---------------------------------------------------------------------
179 void TypeSelectionPage::selectType( AddressSourceType _eType )
181 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
182 loop != m_aAllTypes.end(); ++loop )
184 ButtonItem aItem = (*loop);
185 aItem.m_pItem->Check( _eType == aItem.m_eType );
189 //---------------------------------------------------------------------
190 AddressSourceType TypeSelectionPage::getSelectedType() const
192 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
193 loop != m_aAllTypes.end(); ++loop )
195 ButtonItem aItem = (*loop);
196 if ( aItem.m_pItem->IsChecked() )
197 return aItem.m_eType;
200 return AST_INVALID;
203 //---------------------------------------------------------------------
204 void TypeSelectionPage::initializePage()
206 AddressBookSourcePage::initializePage();
208 const AddressSettings& rSettings = getSettings();
209 selectType(rSettings.eType);
212 //---------------------------------------------------------------------
213 sal_Bool TypeSelectionPage::commitPage( CommitPageReason _eReason )
215 if (!AddressBookSourcePage::commitPage(_eReason))
216 return sal_False;
218 if (AST_INVALID == getSelectedType( ))
220 if ( _eReason != eValidateNoUI )
222 ErrorBox aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION));
223 aError.Execute();
225 return sal_False;
228 AddressSettings& rSettings = getSettings();
229 rSettings.eType = getSelectedType();
231 return sal_True;
234 //---------------------------------------------------------------------
235 bool TypeSelectionPage::canAdvance() const
237 return AddressBookSourcePage::canAdvance()
238 && (AST_INVALID != getSelectedType());
241 //---------------------------------------------------------------------
242 IMPL_LINK( TypeSelectionPage, OnTypeSelected, void*, /*NOTINTERESTEDIN*/ )
244 getDialog()->typeSelectionChanged( getSelectedType() );
245 updateDialogTravelUI();
246 return 0L;
249 //.........................................................................
250 } // namespace abp
251 //.........................................................................