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/layout.hxx>
24 #include <com/sun/star/sdbc/XDriver.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
26 #include <comphelper/processfactory.hxx>
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 '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:
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
69 bool bHaveEvolution
= false;
70 bool bHaveKab
= false;
71 bool bHaveMacab
= false;
75 Reference
< XDriverManager2
> xManager
= DriverManager::create( _pParent
->getORB() );
79 // check whether Evolution is available
80 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:evolution:local") );
82 bHaveEvolution
= true;
88 // check whether KDE address book is available
91 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:kab") );
101 // check whether Mac OS X address book is available
102 Reference
< XDriver
> xDriver( xManager
->getDriverByURL("sdbc:address:macab") );
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();
131 aItem
.m_pItem
->SetClickHdl( aTypeSelectionHandler
);
132 aItem
.m_pItem
->Show();
138 TypeSelectionPage::~TypeSelectionPage()
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();
154 m_pThunderbird
.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();
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
;
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
))
227 if (AST_INVALID
== getSelectedType( ))
229 ScopedVclPtrInstance
< MessageDialog
> aError(this, ModuleRes(RID_STR_NEEDTYPESELECTION
));
234 AddressSettings
& rSettings
= getSettings();
235 rSettings
.eType
= getSelectedType();
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();
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */