bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / abpilot / typeselectionpage.cxx
blob5e3d49e1cb1d32273507fc59a0b5c4e47f39af0f
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/svapp.hxx>
24 #include <vcl/weld.hxx>
25 #include <com/sun/star/sdbc/XDriver.hpp>
26 #include <com/sun/star/sdbc/DriverManager.hpp>
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 'macOS 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 macOS:
61 // - MACAB (if applicable)
62 // - MORK (via mork driver, which is built unconditionally)
63 // - OTHER
65 // On Windows:
66 // - MORK, THUNDERBIRD
67 // - OTHER
69 #if !defined(_WIN32)
70 bool bHaveEvolution = false;
71 bool bHaveKab = false;
72 bool bHaveMacab = false;
74 Reference< XDriverManager2 > xManager = DriverManager::create( _pParent->getORB() );
76 try
78 // check whether Evolution is available
79 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:evolution:local") );
80 if ( xDriver.is() )
81 bHaveEvolution = true;
83 catch (...)
87 // check whether KDE address book is available
88 try
90 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:kab") );
91 if ( xDriver.is() )
92 bHaveKab = true;
94 catch (...)
98 try
100 // check whether macOS address book is available
101 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:macab") );
102 if ( xDriver.is() )
103 bHaveMacab = true;
105 catch(...)
108 #else
109 bool const bHaveEvolution = false;
110 bool const bHaveKab = false;
111 bool const bHaveMacab = false;
112 #endif
114 // Items are displayed in list order
115 m_aAllTypes.push_back( ButtonItem( m_pEvolution, AST_EVOLUTION, bHaveEvolution ) );
116 m_aAllTypes.push_back( ButtonItem( m_pEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
117 m_aAllTypes.push_back( ButtonItem( m_pEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
118 m_aAllTypes.push_back( ButtonItem( m_pMORK, AST_MORK, true ) );
119 m_aAllTypes.push_back( ButtonItem( m_pThunderbird, AST_THUNDERBIRD, true ) );
120 m_aAllTypes.push_back( ButtonItem( m_pKab, AST_KAB, bHaveKab ) );
121 m_aAllTypes.push_back( ButtonItem( m_pMacab, AST_MACAB, bHaveMacab ) );
122 m_aAllTypes.push_back( ButtonItem( m_pOther, AST_OTHER, true ) );
124 Link<Button*,void> aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
125 for (auto const& elem : m_aAllTypes)
127 if (!elem.m_bVisible)
128 elem.m_pItem->Hide();
129 else
131 elem.m_pItem->SetClickHdl( aTypeSelectionHandler );
132 elem.m_pItem->Show();
138 TypeSelectionPage::~TypeSelectionPage()
140 disposeOnce();
143 void TypeSelectionPage::dispose()
145 for (auto & elem : m_aAllTypes)
147 elem.m_bVisible = false;
149 m_pEvolution.clear();
150 m_pEvolutionGroupwise.clear();
151 m_pEvolutionLdap.clear();
152 m_pMORK.clear();
153 m_pThunderbird.clear();
154 m_pKab.clear();
155 m_pMacab.clear();
156 m_pOther.clear();
157 AddressBookSourcePage::dispose();
161 void TypeSelectionPage::ActivatePage()
163 AddressBookSourcePage::ActivatePage();
165 for (auto const& elem : m_aAllTypes)
167 if( elem.m_pItem->IsChecked() && elem.m_bVisible )
169 elem.m_pItem->GrabFocus();
170 break;
174 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, false);
178 void TypeSelectionPage::DeactivatePage()
180 AddressBookSourcePage::DeactivatePage();
181 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, true);
185 void TypeSelectionPage::selectType( AddressSourceType _eType )
187 for (auto const& elem : m_aAllTypes)
189 elem.m_pItem->Check( _eType == elem.m_eType );
194 AddressSourceType TypeSelectionPage::getSelectedType() const
196 for (auto const& elem : m_aAllTypes)
198 if ( elem.m_pItem->IsChecked() && elem.m_bVisible )
199 return elem.m_eType;
202 return AST_INVALID;
206 void TypeSelectionPage::initializePage()
208 AddressBookSourcePage::initializePage();
210 const AddressSettings& rSettings = getSettings();
211 selectType(rSettings.eType);
215 bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
217 if (!AddressBookSourcePage::commitPage(_eReason))
218 return false;
220 if (AST_INVALID == getSelectedType( ))
222 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
223 VclMessageType::Warning, VclButtonsType::Ok,
224 compmodule::ModuleRes(RID_STR_NEEDTYPESELECTION)));
225 xBox->run();
226 return false;
229 AddressSettings& rSettings = getSettings();
230 rSettings.eType = getSelectedType();
232 return true;
236 bool TypeSelectionPage::canAdvance() const
238 return AddressBookSourcePage::canAdvance()
239 && (AST_INVALID != getSelectedType());
243 IMPL_LINK_NOARG( TypeSelectionPage, OnTypeSelected, Button*, void )
245 getDialog()->typeSelectionChanged( getSelectedType() );
246 updateDialogTravelUI();
250 } // namespace abp
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */