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