bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / abpilot / typeselectionpage.cxx
blob90bdf31a0ce7c7f631d4e3b3fc4fe66a70d2e4a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "typeselectionpage.hxx"
21 #include "addresssettings.hxx"
22 #include "abspilot.hxx"
23 #include <vcl/layout.hxx>
24 #include <com/sun/star/sdbc/XDriver.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
26 #include <comphelper/processfactory.hxx>
28 namespace abp
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::sdbc;
33 // TypeSelectionPage
34 TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent )
35 : AddressBookSourcePage(_pParent, "SelectTypePage",
36 "modules/sabpilot/ui/selecttypepage.ui")
38 get(m_pEvolution, "evolution");
39 get(m_pEvolutionGroupwise, "groupwise");
40 get(m_pEvolutionLdap, "evoldap");
41 get(m_pMORK, "firefox");
42 get(m_pThunderbird, "thunderbird");
43 get(m_pKab, "kde");
44 get(m_pMacab, "macosx");
45 get(m_pLDAP, "ldap");
46 get(m_pOutlook, "outlook");
47 get(m_pOE, "windows");
48 get(m_pOther, "other");
50 //TODO: For now, try to keep offering the same choices like before the
51 // Mozilla/MORK cleanup, even if the status of what driver actually
52 // provides which functionality is somewhat unclear, see the discussions
53 // of fdo#57285 "Address Book Data Source Wizard lists 'Mac OS X address
54 // book' on Linux" and fdo#57322 "Moz-free LDAP Address Book driver."
55 // In accordance with ancient OOo 3.3, this is as follows:
57 // On Linux:
58 // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
59 // - MORK (via mork driver, which is built unconditionally)
60 // - KAB (if applicable)
61 // - OTHER
63 // On Mac OS X:
64 // - MACAB (if applicable)
65 // - MORK (via mork driver, which is built unconditionally)
66 // - OTHER
68 // On Windows:
69 // - MORK, THUNDERBIRD, LDAP, OUTLOOK, OUTLOOKEXPRESS (via mozab driver,
70 // if WITH_MOZILLA)
71 // - OTHER
73 bool bWithMozilla = false;
74 bool bHaveEvolution = false;
75 bool bHaveKab = false;
76 bool bHaveMacab = false;
77 bool bWithMork = false;
79 #if defined WNT
80 #if defined WITH_MOZILLA
81 bWithMozilla = true;
82 #endif
83 #else
84 bWithMork = true;
86 Reference< XDriverManager2 > xManager = DriverManager::create( _pParent->getORB() );
88 try
90 // check whether Evolution is available
91 Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:evolution:local")) );
92 if ( xDriver.is() )
93 bHaveEvolution = true;
95 catch (...)
99 // check whether KDE address book is available
102 Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:kab")) );
103 if ( xDriver.is() )
104 bHaveKab = true;
106 catch (...)
112 // check whether Mac OS X address book is available
113 Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:macab")) );
114 if ( xDriver.is() )
115 bHaveMacab = true;
117 catch(...)
121 #endif
123 // Items are displayed in list order
124 m_aAllTypes.push_back( ButtonItem( m_pEvolution, AST_EVOLUTION, bHaveEvolution ) );
125 m_aAllTypes.push_back( ButtonItem( m_pEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
126 m_aAllTypes.push_back( ButtonItem( m_pEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
127 m_aAllTypes.push_back( ButtonItem( m_pMORK, AST_MORK, bWithMozilla || bWithMork) );
128 m_aAllTypes.push_back( ButtonItem( m_pThunderbird, AST_THUNDERBIRD, bWithMozilla || bWithMork) );
129 m_aAllTypes.push_back( ButtonItem( m_pKab, AST_KAB, bHaveKab ) );
130 m_aAllTypes.push_back( ButtonItem( m_pMacab, AST_MACAB, bHaveMacab ) );
131 m_aAllTypes.push_back( ButtonItem( m_pLDAP, AST_LDAP, bWithMozilla ) );
132 m_aAllTypes.push_back( ButtonItem( m_pOutlook, AST_OUTLOOK, bWithMozilla ) );
133 m_aAllTypes.push_back( ButtonItem( m_pOE, AST_OE, bWithMozilla ) );
134 m_aAllTypes.push_back( ButtonItem( m_pOther, AST_OTHER, true ) );
136 Link<> aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
137 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
138 loop != m_aAllTypes.end(); ++loop )
140 ButtonItem aItem = *loop;
141 if (!aItem.m_bVisible)
142 aItem.m_pItem->Hide();
143 else
145 aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
146 aItem.m_pItem->Show();
152 TypeSelectionPage::~TypeSelectionPage()
154 disposeOnce();
157 void TypeSelectionPage::dispose()
159 for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
160 loop != m_aAllTypes.end(); ++loop )
162 loop->m_bVisible = false;
164 m_pEvolution.clear();
165 m_pEvolutionGroupwise.clear();
166 m_pEvolutionLdap.clear();
167 m_pMORK.clear();
168 m_pThunderbird.clear();
169 m_pKab.clear();
170 m_pMacab.clear();
171 m_pLDAP.clear();
172 m_pOutlook.clear();
173 m_pOE.clear();
174 m_pOther.clear();
175 AddressBookSourcePage::dispose();
179 void TypeSelectionPage::ActivatePage()
181 AddressBookSourcePage::ActivatePage();
183 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
184 loop != m_aAllTypes.end(); ++loop )
186 const ButtonItem& rItem = (*loop);
187 if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
189 rItem.m_pItem->GrabFocus();
190 break;
194 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, false);
198 void TypeSelectionPage::DeactivatePage()
200 AddressBookSourcePage::DeactivatePage();
201 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, true);
205 void TypeSelectionPage::selectType( AddressSourceType _eType )
207 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
208 loop != m_aAllTypes.end(); ++loop )
210 ButtonItem aItem = (*loop);
211 aItem.m_pItem->Check( _eType == aItem.m_eType );
216 AddressSourceType TypeSelectionPage::getSelectedType() const
218 for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
219 loop != m_aAllTypes.end(); ++loop )
221 ButtonItem aItem = (*loop);
222 if ( aItem.m_pItem->IsChecked() )
223 return aItem.m_eType;
226 return AST_INVALID;
230 void TypeSelectionPage::initializePage()
232 AddressBookSourcePage::initializePage();
234 const AddressSettings& rSettings = getSettings();
235 selectType(rSettings.eType);
239 bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
241 if (!AddressBookSourcePage::commitPage(_eReason))
242 return false;
244 if (AST_INVALID == getSelectedType( ))
246 ScopedVclPtrInstance< MessageDialog > aError(this, ModuleRes(RID_STR_NEEDTYPESELECTION));
247 aError->Execute();
248 return false;
251 AddressSettings& rSettings = getSettings();
252 rSettings.eType = getSelectedType();
254 return true;
258 bool TypeSelectionPage::canAdvance() const
260 return AddressBookSourcePage::canAdvance()
261 && (AST_INVALID != getSelectedType());
265 IMPL_LINK_NOARG( TypeSelectionPage, OnTypeSelected )
267 getDialog()->typeSelectionChanged( getSelectedType() );
268 updateDialogTravelUI();
269 return 0L;
273 } // namespace abp
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */