Line data Source code
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/layout.hxx>
24 : #include <com/sun/star/sdbc/XDriver.hpp>
25 : #include <com/sun/star/sdbc/DriverManager.hpp>
26 : #include <comphelper/processfactory.hxx>
27 :
28 : namespace abp
29 : {
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::sdbc;
32 :
33 : // TypeSelectionPage
34 0 : TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent )
35 : : AddressBookSourcePage(_pParent, "SelectTypePage",
36 0 : "modules/sabpilot/ui/selecttypepage.ui")
37 : {
38 0 : get(m_pEvolution, "evolution");
39 0 : get(m_pEvolutionGroupwise, "groupwise");
40 0 : get(m_pEvolutionLdap, "evoldap");
41 0 : get(m_pMORK, "firefox");
42 0 : get(m_pThunderbird, "thunderbird");
43 0 : get(m_pKab, "kde");
44 0 : get(m_pMacab, "macosx");
45 0 : get(m_pLDAP, "ldap");
46 0 : get(m_pOutlook, "outlook");
47 0 : get(m_pOE, "windows");
48 0 : get(m_pOther, "other");
49 :
50 : //TODO: For now, try to keep offering the same choices like before the
51 : // Mozilla/MORK cleanup, even if the status of what driver actually
52 : // provides which functionality is somewhat unclear, see the discussions
53 : // of fdo#57285 "Address Book Data Source Wizard lists 'Mac OS X address
54 : // book' on Linux" and fdo#57322 "Moz-free LDAP Address Book driver."
55 : // In accordance with ancient OOo 3.3, this is as follows:
56 : //
57 : // On Linux:
58 : // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
59 : // - MORK (via mork driver, which is built unconditionally)
60 : // - KAB (if applicable)
61 : // - OTHER
62 : //
63 : // On Mac OS X:
64 : // - MACAB (if applicable)
65 : // - MORK (via mork driver, which is built unconditionally)
66 : // - OTHER
67 : //
68 : // On Windows:
69 : // - MORK, THUNDERBIRD, LDAP, OUTLOOK, OUTLOOKEXPRESS (via mozab driver,
70 : // if WITH_MOZILLA)
71 : // - OTHER
72 :
73 0 : bool bWithMozilla = false;
74 0 : bool bHaveEvolution = false;
75 0 : bool bHaveKab = false;
76 0 : bool bHaveMacab = false;
77 0 : bool bWithMork = false;
78 :
79 : #if defined WNT
80 : #if defined WITH_MOZILLA
81 : bWithMozilla = true;
82 : #endif
83 : #else
84 0 : bWithMork = true;
85 :
86 0 : Reference< XDriverManager2 > xManager = DriverManager::create( _pParent->getORB() );
87 :
88 : try
89 : {
90 : // check whether Evolution is available
91 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:evolution:local")) );
92 0 : if ( xDriver.is() )
93 0 : bHaveEvolution = true;
94 : }
95 0 : catch (...)
96 : {
97 : }
98 :
99 : // check whether KDE address book is available
100 : try
101 : {
102 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:kab")) );
103 0 : if ( xDriver.is() )
104 0 : bHaveKab = true;
105 : }
106 0 : catch (...)
107 : {
108 : }
109 :
110 : try
111 : {
112 : // check whether Mac OS X address book is available
113 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:macab")) );
114 0 : if ( xDriver.is() )
115 0 : bHaveMacab = true;
116 : }
117 0 : catch(...)
118 : {
119 : }
120 :
121 : #endif
122 :
123 : // Items are displayed in list order
124 0 : m_aAllTypes.push_back( ButtonItem( m_pEvolution, AST_EVOLUTION, bHaveEvolution ) );
125 0 : m_aAllTypes.push_back( ButtonItem( m_pEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
126 0 : m_aAllTypes.push_back( ButtonItem( m_pEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
127 0 : m_aAllTypes.push_back( ButtonItem( m_pMORK, AST_MORK, bWithMozilla || bWithMork) );
128 0 : m_aAllTypes.push_back( ButtonItem( m_pThunderbird, AST_THUNDERBIRD, bWithMozilla || bWithMork) );
129 0 : m_aAllTypes.push_back( ButtonItem( m_pKab, AST_KAB, bHaveKab ) );
130 0 : m_aAllTypes.push_back( ButtonItem( m_pMacab, AST_MACAB, bHaveMacab ) );
131 0 : m_aAllTypes.push_back( ButtonItem( m_pLDAP, AST_LDAP, bWithMozilla ) );
132 0 : m_aAllTypes.push_back( ButtonItem( m_pOutlook, AST_OUTLOOK, bWithMozilla ) );
133 0 : m_aAllTypes.push_back( ButtonItem( m_pOE, AST_OE, bWithMozilla ) );
134 0 : m_aAllTypes.push_back( ButtonItem( m_pOther, AST_OTHER, true ) );
135 :
136 0 : Link<> aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
137 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
138 0 : loop != m_aAllTypes.end(); ++loop )
139 : {
140 0 : ButtonItem aItem = *loop;
141 0 : if (!aItem.m_bVisible)
142 0 : aItem.m_pItem->Hide();
143 : else
144 : {
145 0 : aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
146 0 : aItem.m_pItem->Show();
147 : }
148 0 : }
149 0 : }
150 :
151 :
152 0 : TypeSelectionPage::~TypeSelectionPage()
153 : {
154 0 : disposeOnce();
155 0 : }
156 :
157 0 : void TypeSelectionPage::dispose()
158 : {
159 0 : for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
160 0 : loop != m_aAllTypes.end(); ++loop )
161 : {
162 0 : loop->m_bVisible = false;
163 : }
164 0 : m_pEvolution.clear();
165 0 : m_pEvolutionGroupwise.clear();
166 0 : m_pEvolutionLdap.clear();
167 0 : m_pMORK.clear();
168 0 : m_pThunderbird.clear();
169 0 : m_pKab.clear();
170 0 : m_pMacab.clear();
171 0 : m_pLDAP.clear();
172 0 : m_pOutlook.clear();
173 0 : m_pOE.clear();
174 0 : m_pOther.clear();
175 0 : AddressBookSourcePage::dispose();
176 0 : }
177 :
178 :
179 0 : void TypeSelectionPage::ActivatePage()
180 : {
181 0 : AddressBookSourcePage::ActivatePage();
182 :
183 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
184 0 : loop != m_aAllTypes.end(); ++loop )
185 : {
186 0 : const ButtonItem& rItem = (*loop);
187 0 : if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
188 : {
189 0 : rItem.m_pItem->GrabFocus();
190 0 : break;
191 : }
192 : }
193 :
194 0 : getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, false);
195 0 : }
196 :
197 :
198 0 : void TypeSelectionPage::DeactivatePage()
199 : {
200 0 : AddressBookSourcePage::DeactivatePage();
201 0 : getDialog()->enableButtons(WizardButtonFlags::PREVIOUS, true);
202 0 : }
203 :
204 :
205 0 : void TypeSelectionPage::selectType( AddressSourceType _eType )
206 : {
207 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
208 0 : loop != m_aAllTypes.end(); ++loop )
209 : {
210 0 : ButtonItem aItem = (*loop);
211 0 : aItem.m_pItem->Check( _eType == aItem.m_eType );
212 0 : }
213 0 : }
214 :
215 :
216 0 : AddressSourceType TypeSelectionPage::getSelectedType() const
217 : {
218 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
219 0 : loop != m_aAllTypes.end(); ++loop )
220 : {
221 0 : ButtonItem aItem = (*loop);
222 0 : if ( aItem.m_pItem->IsChecked() )
223 0 : return aItem.m_eType;
224 0 : }
225 :
226 0 : return AST_INVALID;
227 : }
228 :
229 :
230 0 : void TypeSelectionPage::initializePage()
231 : {
232 0 : AddressBookSourcePage::initializePage();
233 :
234 0 : const AddressSettings& rSettings = getSettings();
235 0 : selectType(rSettings.eType);
236 0 : }
237 :
238 :
239 0 : bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
240 : {
241 0 : if (!AddressBookSourcePage::commitPage(_eReason))
242 0 : return false;
243 :
244 0 : if (AST_INVALID == getSelectedType( ))
245 : {
246 0 : ScopedVclPtrInstance< MessageDialog > aError(this, ModuleRes(RID_STR_NEEDTYPESELECTION));
247 0 : aError->Execute();
248 0 : return false;
249 : }
250 :
251 0 : AddressSettings& rSettings = getSettings();
252 0 : rSettings.eType = getSelectedType();
253 :
254 0 : return true;
255 : }
256 :
257 :
258 0 : bool TypeSelectionPage::canAdvance() const
259 : {
260 0 : return AddressBookSourcePage::canAdvance()
261 0 : && (AST_INVALID != getSelectedType());
262 : }
263 :
264 :
265 0 : IMPL_LINK_NOARG( TypeSelectionPage, OnTypeSelected )
266 : {
267 0 : getDialog()->typeSelectionChanged( getSelectedType() );
268 0 : updateDialogTravelUI();
269 0 : return 0L;
270 : }
271 :
272 :
273 0 : } // namespace abp
274 :
275 :
276 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|