Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / abpilot / typeselectionpage.cxx
blobeb4e00b83fca158bc95390c68a14b09d7a68a5e6
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( OAddressBookSourcePilot* _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_pOther, "other");
47 //TODO: For now, try to keep offering the same choices like before the
48 // Mozilla/MORK cleanup, even if the status of what driver actually
49 // provides which functionality is somewhat unclear, see the discussions
50 // of fdo#57285 "Address Book Data Source Wizard lists 'Mac OS X address
51 // book' on Linux" and fdo#57322 "Moz-free LDAP Address Book driver."
52 // In accordance with ancient OOo 3.3, this is as follows:
54 // On Linux:
55 // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
56 // - MORK (via mork driver, which is built unconditionally)
57 // - KAB (if applicable)
58 // - OTHER
60 // On Mac OS X:
61 // - MACAB (if applicable)
62 // - MORK (via mork driver, which is built unconditionally)
63 // - OTHER
65 // On Windows:
66 // - MORK, THUNDERBIRD
67 // - OTHER
69 bool bHaveEvolution = false;
70 bool bHaveKab = false;
71 bool bHaveMacab = false;
73 #if !defined(_WIN32)
75 Reference< XDriverManager2 > xManager = DriverManager::create( _pParent->getORB() );
77 try
79 // check whether Evolution is available
80 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:evolution:local") );
81 if ( xDriver.is() )
82 bHaveEvolution = true;
84 catch (...)
88 // check whether KDE address book is available
89 try
91 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:kab") );
92 if ( xDriver.is() )
93 bHaveKab = true;
95 catch (...)
99 try
101 // check whether Mac OS X address book is available
102 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:macab") );
103 if ( xDriver.is() )
104 bHaveMacab = true;
106 catch(...)
110 #endif
112 // Items are displayed in list order
113 m_aAllTypes.push_back( ButtonItem( m_pEvolution, AST_EVOLUTION, bHaveEvolution ) );
114 m_aAllTypes.push_back( ButtonItem( m_pEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
115 m_aAllTypes.push_back( ButtonItem( m_pEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
116 m_aAllTypes.push_back( ButtonItem( m_pMORK, AST_MORK, true ) );
117 m_aAllTypes.push_back( ButtonItem( m_pThunderbird, AST_THUNDERBIRD, true ) );
118 m_aAllTypes.push_back( ButtonItem( m_pKab, AST_KAB, bHaveKab ) );
119 m_aAllTypes.push_back( ButtonItem( m_pMacab, AST_MACAB, bHaveMacab ) );
120 m_aAllTypes.push_back( ButtonItem( m_pOther, AST_OTHER, true ) );
122 Link<Button*,void> aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
123 for ( std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
124 loop != m_aAllTypes.end(); ++loop )
126 ButtonItem aItem = *loop;
127 if (!aItem.m_bVisible)
128 aItem.m_pItem->Hide();
129 else
131 aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
132 aItem.m_pItem->Show();
138 TypeSelectionPage::~TypeSelectionPage()
140 disposeOnce();
143 void TypeSelectionPage::dispose()
145 for ( std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
146 loop != m_aAllTypes.end(); ++loop )
148 loop->m_bVisible = false;
150 m_pEvolution.clear();
151 m_pEvolutionGroupwise.clear();
152 m_pEvolutionLdap.clear();
153 m_pMORK.clear();
154 m_pThunderbird.clear();
155 m_pKab.clear();
156 m_pMacab.clear();
157 m_pOther.clear();
158 AddressBookSourcePage::dispose();
162 void TypeSelectionPage::ActivatePage()
164 AddressBookSourcePage::ActivatePage();
166 for ( std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
167 loop != m_aAllTypes.end(); ++loop )
169 const ButtonItem& rItem = (*loop);
170 if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
172 rItem.m_pItem->GrabFocus();
173 break;
177 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, false);
181 void TypeSelectionPage::DeactivatePage()
183 AddressBookSourcePage::DeactivatePage();
184 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, true);
188 void TypeSelectionPage::selectType( AddressSourceType _eType )
190 for ( std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
191 loop != m_aAllTypes.end(); ++loop )
193 ButtonItem aItem = (*loop);
194 aItem.m_pItem->Check( _eType == aItem.m_eType );
199 AddressSourceType TypeSelectionPage::getSelectedType() const
201 for ( std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
202 loop != m_aAllTypes.end(); ++loop )
204 ButtonItem aItem = (*loop);
205 if ( aItem.m_pItem->IsChecked() && aItem.m_bVisible )
206 return aItem.m_eType;
209 return AST_INVALID;
213 void TypeSelectionPage::initializePage()
215 AddressBookSourcePage::initializePage();
217 const AddressSettings& rSettings = getSettings();
218 selectType(rSettings.eType);
222 bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
224 if (!AddressBookSourcePage::commitPage(_eReason))
225 return false;
227 if (AST_INVALID == getSelectedType( ))
229 ScopedVclPtrInstance< MessageDialog > aError(this, ModuleRes(RID_STR_NEEDTYPESELECTION));
230 aError->Execute();
231 return false;
234 AddressSettings& rSettings = getSettings();
235 rSettings.eType = getSelectedType();
237 return true;
241 bool TypeSelectionPage::canAdvance() const
243 return AddressBookSourcePage::canAdvance()
244 && (AST_INVALID != getSelectedType());
248 IMPL_LINK_NOARG( TypeSelectionPage, OnTypeSelected, Button*, void )
250 getDialog()->typeSelectionChanged( getSelectedType() );
251 updateDialogTravelUI();
255 } // namespace abp
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */