LibreOffice Module extensions (master) 1
typeselectionpage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
27
28namespace abp
29{
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::sdbc;
32
33 // TypeSelectionPage
35 : AddressBookSourcePage(pPage, pDialog, "modules/sabpilot/ui/selecttypepage.ui", "SelectTypePage")
36 , m_xEvolution(m_xBuilder->weld_radio_button("evolution"))
37 , m_xEvolutionGroupwise(m_xBuilder->weld_radio_button("groupwise"))
38 , m_xEvolutionLdap(m_xBuilder->weld_radio_button("evoldap"))
39 , m_xThunderbird(m_xBuilder->weld_radio_button("thunderbird"))
40 , m_xKab(m_xBuilder->weld_radio_button("kde"))
41 , m_xMacab(m_xBuilder->weld_radio_button("macosx"))
42 , m_xOther(m_xBuilder->weld_radio_button("other"))
43 {
44 //TODO: For now, try to keep offering the same choices like before the
45 // Mozilla cleanup, even if the status of what driver actually
46 // provides which functionality is somewhat unclear, see the discussions
47 // of fdo#57285 "Address Book Data Source Wizard lists 'macOS address
48 // book' on Linux" and fdo#57322 "Moz-free LDAP Address Book driver."
49 // In accordance with ancient OOo 3.3, this is as follows:
50 //
51 // On Linux:
52 // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
53 // - KAB (if applicable)
54 // - OTHER
55 //
56 // On macOS:
57 // - MACAB (if applicable)
58 // - OTHER
59 //
60 // On Windows:
61 // - THUNDERBIRD
62 // - OTHER
63
64#if !defined(_WIN32)
65 bool bHaveEvolution = false;
66 bool bHaveKab = false;
67 bool bHaveMacab = false;
68
69 Reference< XDriverManager2 > xManager = DriverManager::create( pDialog->getORB() );
70
71 try
72 {
73 // check whether Evolution is available
74 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:evolution:local") );
75 if ( xDriver.is() )
76 bHaveEvolution = true;
77 }
78 catch (...)
79 {
80 }
81
82 // check whether KDE address book is available
83 try
84 {
85 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:kab") );
86 if ( xDriver.is() )
87 bHaveKab = true;
88 }
89 catch (...)
90 {
91 }
92
93 try
94 {
95 // check whether macOS address book is available
96 Reference< XDriver > xDriver( xManager->getDriverByURL("sdbc:address:macab") );
97 if ( xDriver.is() )
98 bHaveMacab = true;
99 }
100 catch(...)
101 {
102 }
103#else
104 bool const bHaveEvolution = false;
105 bool const bHaveKab = false;
106 bool const bHaveMacab = false;
107#endif
108
109 // Items are displayed in list order
110 m_aAllTypes.push_back( ButtonItem( m_xEvolution.get(), AST_EVOLUTION, bHaveEvolution ) );
111 m_aAllTypes.push_back( ButtonItem( m_xEvolutionGroupwise.get(), AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
112 m_aAllTypes.push_back( ButtonItem( m_xEvolutionLdap.get(), AST_EVOLUTION_LDAP, bHaveEvolution ) );
113 m_aAllTypes.push_back( ButtonItem( m_xThunderbird.get(), AST_THUNDERBIRD, true ) );
114 m_aAllTypes.push_back( ButtonItem( m_xKab.get(), AST_KAB, bHaveKab ) );
115 m_aAllTypes.push_back( ButtonItem( m_xMacab.get(), AST_MACAB, bHaveMacab ) );
116 m_aAllTypes.push_back( ButtonItem( m_xOther.get(), AST_OTHER, true ) );
117
118 Link<weld::Toggleable&,void> aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
119 for (auto const& elem : m_aAllTypes)
120 {
121 if (!elem.m_bVisible)
122 elem.m_pItem->hide();
123 else
124 {
125 elem.m_pItem->connect_toggled( aTypeSelectionHandler );
126 elem.m_pItem->show();
127 }
128 }
129 }
130
132 {
133 for (auto & elem : m_aAllTypes)
134 {
135 elem.m_bVisible = false;
136 }
137 }
138
140 {
142
143 for (auto const& elem : m_aAllTypes)
144 {
145 if( elem.m_pItem->get_active() && elem.m_bVisible )
146 {
147 elem.m_pItem->grab_focus();
148 break;
149 }
150 }
151
152 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, false);
153 }
154
156 {
158 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, true);
159 }
160
162 {
163 for (auto const& elem : m_aAllTypes)
164 {
165 elem.m_pItem->set_active( _eType == elem.m_eType );
166 }
167 }
168
170 {
171 for (auto const& elem : m_aAllTypes)
172 {
173 if ( elem.m_pItem->get_active() && elem.m_bVisible )
174 return elem.m_eType;
175 }
176
177 return AST_INVALID;
178 }
179
181 {
183
184 const AddressSettings& rSettings = getSettings();
185 selectType(rSettings.eType);
186 }
187
189 {
191 return false;
192
194 {
195 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xContainer.get(),
196 VclMessageType::Warning, VclButtonsType::Ok,
197 compmodule::ModuleRes(RID_STR_NEEDTYPESELECTION)));
198 xBox->run();
199 return false;
200 }
201
202 AddressSettings& rSettings = getSettings();
203 rSettings.eType = getSelectedType();
204
205 return true;
206 }
207
209 {
212 }
213
214 IMPL_LINK(TypeSelectionPage, OnTypeSelected, weld::Toggleable&, rButton, void)
215 {
216 if (!rButton.get_active())
217 return;
218 getDialog()->typeSelectionChanged( getSelectedType() );
219 updateDialogTravelUI();
220 }
221
222} // namespace abp
223
224/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::Container > m_xContainer
the base class for all tab pages in the address book source wizard
Definition: abspage.hxx:36
virtual void Activate() override
Definition: abspage.cxx:34
virtual void Deactivate() override
Definition: abspage.cxx:40
OAddressBookSourcePilot * getDialog()
Definition: abspage.cxx:46
AddressSettings & getSettings()
Definition: abspage.cxx:56
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
get the service factory which was used to create the dialog
Definition: abspilot.hxx:51
virtual void Activate() override
virtual ~TypeSelectionPage() override
std::unique_ptr< weld::RadioButton > m_xEvolution
std::unique_ptr< weld::RadioButton > m_xThunderbird
std::vector< ButtonItem > m_aAllTypes
void selectType(AddressSourceType _eType)
AddressSourceType getSelectedType() const
virtual void Deactivate() override
std::unique_ptr< weld::RadioButton > m_xOther
TypeSelectionPage(weld::Container *pPage, OAddressBookSourcePilot *pController)
std::unique_ptr< weld::RadioButton > m_xEvolutionGroupwise
virtual void initializePage() override
virtual bool canAdvance() const override
std::unique_ptr< weld::RadioButton > m_xMacab
std::unique_ptr< weld::RadioButton > m_xKab
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
std::unique_ptr< weld::RadioButton > m_xEvolutionLdap
virtual bool canAdvance() const override
virtual bool commitPage(WizardTypes::CommitPageReason _eReason) override
virtual void initializePage() override
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
@ AST_EVOLUTION_GROUPWISE
@ AST_EVOLUTION_LDAP
@ AST_THUNDERBIRD
@ AST_EVOLUTION
IMPL_LINK(TypeSelectionPage, OnTypeSelected, weld::Toggleable &, rButton, void)
OUString ModuleRes(TranslateId pId)
AddressSourceType eType