1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::sdbc
;
34 TypeSelectionPage::TypeSelectionPage(weld::Container
* pPage
, OAddressBookSourcePilot
* pDialog
)
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"))
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:
52 // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
53 // - KAB (if applicable)
57 // - MACAB (if applicable)
65 bool bHaveEvolution
= false;
66 bool bHaveKab
= false;
67 bool bHaveMacab
= false;
69 Reference
< XDriverManager2
> xManager
= DriverManager::create( pDialog
->getORB() );
73 // check whether Evolution is available
74 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:evolution:local") );
76 bHaveEvolution
= true;
82 // check whether KDE address book is available
85 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:kab") );
95 // check whether macOS address book is available
96 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:macab") );
104 bool const bHaveEvolution
= false;
105 bool const bHaveKab
= false;
106 bool const bHaveMacab
= false;
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 ) );
118 Link
<weld::Toggleable
&,void> aTypeSelectionHandler
= LINK(this, TypeSelectionPage
, OnTypeSelected
);
119 for (auto const& elem
: m_aAllTypes
)
121 if (!elem
.m_bVisible
)
122 elem
.m_pItem
->hide();
125 elem
.m_pItem
->connect_toggled( aTypeSelectionHandler
);
126 elem
.m_pItem
->show();
131 TypeSelectionPage::~TypeSelectionPage()
133 for (auto & elem
: m_aAllTypes
)
135 elem
.m_bVisible
= false;
139 void TypeSelectionPage::Activate()
141 AddressBookSourcePage::Activate();
143 for (auto const& elem
: m_aAllTypes
)
145 if( elem
.m_pItem
->get_active() && elem
.m_bVisible
)
147 elem
.m_pItem
->grab_focus();
152 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS
, false);
155 void TypeSelectionPage::Deactivate()
157 AddressBookSourcePage::Deactivate();
158 getDialog()->enableButtons(WizardButtonFlags::PREVIOUS
, true);
161 void TypeSelectionPage::selectType( AddressSourceType _eType
)
163 for (auto const& elem
: m_aAllTypes
)
165 elem
.m_pItem
->set_active( _eType
== elem
.m_eType
);
169 AddressSourceType
TypeSelectionPage::getSelectedType() const
171 for (auto const& elem
: m_aAllTypes
)
173 if ( elem
.m_pItem
->get_active() && elem
.m_bVisible
)
180 void TypeSelectionPage::initializePage()
182 AddressBookSourcePage::initializePage();
184 const AddressSettings
& rSettings
= getSettings();
185 selectType(rSettings
.eType
);
188 bool TypeSelectionPage::commitPage( ::vcl::WizardTypes::CommitPageReason _eReason
)
190 if (!AddressBookSourcePage::commitPage(_eReason
))
193 if (AST_INVALID
== getSelectedType( ))
195 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(m_xContainer
.get(),
196 VclMessageType::Warning
, VclButtonsType::Ok
,
197 compmodule::ModuleRes(RID_STR_NEEDTYPESELECTION
)));
202 AddressSettings
& rSettings
= getSettings();
203 rSettings
.eType
= getSelectedType();
208 bool TypeSelectionPage::canAdvance() const
210 return AddressBookSourcePage::canAdvance()
211 && (AST_INVALID
!= getSelectedType());
214 IMPL_LINK(TypeSelectionPage
, OnTypeSelected
, weld::Toggleable
&, rButton
, void)
216 if (!rButton
.get_active())
218 getDialog()->typeSelectionChanged( getSelectedType() );
219 updateDialogTravelUI();
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */