1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_extensions.hxx" 24 #include "typeselectionpage.hxx" 25 #include "addresssettings.hxx" 26 #include "abspilot.hxx" 27 #include <vcl/msgbox.hxx> 28 #include <com/sun/star/sdbc/XDriverAccess.hpp> 29 30 namespace abp 31 { 32 //......................................................................... 33 34 using namespace ::com::sun::star::uno; 35 using namespace ::com::sun::star::sdbc; 36 37 //===================================================================== 38 //= TypeSelectionPage 39 //===================================================================== 40 //--------------------------------------------------------------------- TypeSelectionPage(OAddessBookSourcePilot * _pParent)41 TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent ) 42 :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_SELECTABTYPE)) 43 ,m_aHint (this, ModuleRes(FT_TYPE_HINTS)) 44 ,m_aTypeSep (this, ModuleRes(FL_TYPE)) 45 ,m_aEvolution (this, ModuleRes(RB_EVOLUTION)) 46 ,m_aEvolutionGroupwise (this, ModuleRes(RB_EVOLUTION_GROUPWISE)) 47 ,m_aEvolutionLdap (this, ModuleRes(RB_EVOLUTION_LDAP)) 48 ,m_aThunderbird (this, ModuleRes(RB_THUNDERBIRD)) 49 ,m_aKab (this, ModuleRes(RB_KAB)) 50 ,m_aMacab (this, ModuleRes(RB_MACAB)) 51 ,m_aLDAP (this, ModuleRes(RB_LDAP)) 52 ,m_aOutlook (this, ModuleRes(RB_OUTLOOK)) 53 ,m_aOE (this, ModuleRes(RB_OUTLOOKEXPRESS)) 54 ,m_aOther (this, ModuleRes(RB_OTHER)) 55 { 56 FreeResource(); 57 58 Point aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT ) ); 59 Size aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) ); 60 aItemSize.Width() = GetOutputSizePixel().Width() - 30; 61 62 bool bWithMozilla = true, bUnx = true; 63 bool bHaveEvolution = true, bHaveKab = true; 64 bool bHaveMacab = true; 65 66 #if !defined WITH_MOZILLA || defined MACOSX 67 bWithMozilla = false; 68 #endif 69 #ifndef UNX 70 bUnx = false; 71 bHaveEvolution = false; 72 bHaveKab = false; 73 bHaveMacab = false; 74 #else 75 Reference< XDriverAccess> xManager(_pParent->getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager"))), UNO_QUERY); 76 77 // check whether Evolution is available 78 Reference< XDriver > xDriver( xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:evolution:local"))) ); 79 if ( !xDriver.is() ) 80 bHaveEvolution = false; 81 82 // check whether KDE address book is available 83 xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab"))); 84 if ( !xDriver.is() ) 85 bHaveKab = false; 86 87 // check whether macOS address book is available 88 xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab"))); 89 if ( !xDriver.is() ) 90 bHaveMacab = false; 91 #endif 92 93 // Items are displayed in list order 94 m_aAllTypes.push_back( ButtonItem( &m_aEvolution, AST_EVOLUTION, bHaveEvolution ) ); 95 m_aAllTypes.push_back( ButtonItem( &m_aEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) ); 96 m_aAllTypes.push_back( ButtonItem( &m_aEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) ); 97 m_aAllTypes.push_back( ButtonItem( &m_aThunderbird, AST_THUNDERBIRD, bWithMozilla ) ); 98 m_aAllTypes.push_back( ButtonItem( &m_aKab, AST_KAB, bHaveKab ) ); 99 m_aAllTypes.push_back( ButtonItem( &m_aMacab, AST_MACAB, bHaveMacab ) ); 100 m_aAllTypes.push_back( ButtonItem( &m_aLDAP, AST_LDAP, bWithMozilla ) ); 101 m_aAllTypes.push_back( ButtonItem( &m_aOutlook, AST_OUTLOOK, bWithMozilla && !bUnx ) ); 102 m_aAllTypes.push_back( ButtonItem( &m_aOE, AST_OE, bWithMozilla && !bUnx ) ); 103 m_aAllTypes.push_back( ButtonItem( &m_aOther, AST_OTHER, true ) ); 104 105 bool bFirstVisible = true; 106 Link aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected ); 107 const Size aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT ) ); 108 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin(); 109 loop != m_aAllTypes.end(); ++loop ) 110 { 111 ButtonItem aItem = *loop; 112 if (!aItem.m_bVisible) 113 aItem.m_pItem->Hide(); 114 else 115 { 116 aItem.m_pItem->SetPosPixel( aTopLeft ); 117 aTopLeft.Y() += aItemSize.Height() + aSpacing.Height(); 118 aItem.m_pItem->SetClickHdl( aTypeSelectionHandler ); 119 aItem.m_pItem->Show(); 120 121 if ( bFirstVisible ) 122 { 123 aItem.m_pItem->SetStyle( aItem.m_pItem->GetStyle() | WB_GROUP ); 124 bFirstVisible = false; 125 } 126 } 127 } 128 } 129 130 //--------------------------------------------------------------------- ~TypeSelectionPage()131 TypeSelectionPage::~TypeSelectionPage() 132 { 133 for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin(); 134 loop != m_aAllTypes.end(); ++loop ) 135 { 136 loop->m_bVisible = false; 137 } 138 } 139 140 //--------------------------------------------------------------------- ActivatePage()141 void TypeSelectionPage::ActivatePage() 142 { 143 AddressBookSourcePage::ActivatePage(); 144 145 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin(); 146 loop != m_aAllTypes.end(); ++loop ) 147 { 148 const ButtonItem& rItem = (*loop); 149 if( rItem.m_pItem->IsChecked() && rItem.m_bVisible ) 150 { 151 rItem.m_pItem->GrabFocus(); 152 break; 153 } 154 } 155 156 getDialog()->enableButtons(WZB_PREVIOUS, sal_False); 157 } 158 159 //--------------------------------------------------------------------- DeactivatePage()160 void TypeSelectionPage::DeactivatePage() 161 { 162 AddressBookSourcePage::DeactivatePage(); 163 getDialog()->enableButtons(WZB_PREVIOUS, sal_True); 164 } 165 166 //--------------------------------------------------------------------- selectType(AddressSourceType _eType)167 void TypeSelectionPage::selectType( AddressSourceType _eType ) 168 { 169 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin(); 170 loop != m_aAllTypes.end(); ++loop ) 171 { 172 ButtonItem aItem = (*loop); 173 aItem.m_pItem->Check( _eType == aItem.m_eType ); 174 } 175 } 176 177 //--------------------------------------------------------------------- getSelectedType() const178 AddressSourceType TypeSelectionPage::getSelectedType() const 179 { 180 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin(); 181 loop != m_aAllTypes.end(); ++loop ) 182 { 183 ButtonItem aItem = (*loop); 184 if ( aItem.m_pItem->IsChecked() ) 185 return aItem.m_eType; 186 } 187 188 return AST_INVALID; 189 } 190 191 //--------------------------------------------------------------------- initializePage()192 void TypeSelectionPage::initializePage() 193 { 194 AddressBookSourcePage::initializePage(); 195 196 const AddressSettings& rSettings = getSettings(); 197 selectType(rSettings.eType); 198 } 199 200 //--------------------------------------------------------------------- commitPage(::svt::WizardTypes::CommitPageReason _eReason)201 sal_Bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 202 { 203 if (!AddressBookSourcePage::commitPage(_eReason)) 204 return sal_False; 205 206 if (AST_INVALID == getSelectedType( )) 207 { 208 ErrorBox aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION)); 209 aError.Execute(); 210 return sal_False; 211 } 212 213 AddressSettings& rSettings = getSettings(); 214 rSettings.eType = getSelectedType(); 215 216 return sal_True; 217 } 218 219 //--------------------------------------------------------------------- canAdvance() const220 bool TypeSelectionPage::canAdvance() const 221 { 222 return AddressBookSourcePage::canAdvance() 223 && (AST_INVALID != getSelectedType()); 224 } 225 226 //--------------------------------------------------------------------- 227 IMPL_LINK( TypeSelectionPage, OnTypeSelected, void*, /*NOTINTERESTEDIN*/ ) 228 { 229 getDialog()->typeSelectionChanged( getSelectedType() ); 230 updateDialogTravelUI(); 231 return 0L; 232 } 233 234 //......................................................................... 235 } // namespace abp 236 237 /* vim: set noet sw=4 ts=4: */ 238