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( 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");
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:
55 // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
56 // - MORK (via mork driver, which is built unconditionally)
57 // - KAB (if applicable)
61 // - MACAB (if applicable)
62 // - MORK (via mork driver, which is built unconditionally)
66 // - MORK, THUNDERBIRD
70 bool bHaveEvolution
= false;
71 bool bHaveKab
= false;
72 bool bHaveMacab
= false;
74 Reference
< XDriverManager2
> xManager
= DriverManager::create( _pParent
->getORB() );
78 // check whether Evolution is available
79 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:evolution:local") );
81 bHaveEvolution
= true;
87 // check whether KDE address book is available
90 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:kab") );
100 // check whether macOS address book is available
101 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:macab") );
109 bool const bHaveEvolution
= false;
110 bool const bHaveKab
= false;
111 bool const bHaveMacab
= false;
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();
131 elem
.m_pItem
->SetClickHdl( aTypeSelectionHandler
);
132 elem
.m_pItem
->Show();
138 TypeSelectionPage::~TypeSelectionPage()
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();
153 m_pThunderbird
.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();
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
)
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
))
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
)));
229 AddressSettings
& rSettings
= getSettings();
230 rSettings
.eType
= getSelectedType();
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();
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */