Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "typeselectionpage.hxx"
30 : : #include "addresssettings.hxx"
31 : : #include "abspilot.hxx"
32 : : #include <vcl/msgbox.hxx>
33 : : #include <com/sun/star/sdbc/XDriverAccess.hpp>
34 : :
35 : : //.........................................................................
36 : : namespace abp
37 : : {
38 : : //.........................................................................
39 : :
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::sdbc;
42 : :
43 : : //=====================================================================
44 : : //= TypeSelectionPage
45 : : //=====================================================================
46 : : //---------------------------------------------------------------------
47 : 0 : TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent )
48 : : :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_SELECTABTYPE))
49 : : ,m_aHint (this, ModuleRes(FT_TYPE_HINTS))
50 : : ,m_aTypeSep (this, ModuleRes(FL_TYPE))
51 : : ,m_aEvolution (this, ModuleRes(RB_EVOLUTION))
52 : : ,m_aEvolutionGroupwise (this, ModuleRes(RB_EVOLUTION_GROUPWISE))
53 : : ,m_aEvolutionLdap (this, ModuleRes(RB_EVOLUTION_LDAP))
54 : : ,m_aMORK (this, ModuleRes(RB_MORK))
55 : : ,m_aThunderbird (this, ModuleRes(RB_THUNDERBIRD))
56 : : ,m_aKab (this, ModuleRes(RB_KAB))
57 : : ,m_aMacab (this, ModuleRes(RB_MACAB))
58 : : ,m_aLDAP (this, ModuleRes(RB_LDAP))
59 : : ,m_aOutlook (this, ModuleRes(RB_OUTLOOK))
60 : : ,m_aOE (this, ModuleRes(RB_OUTLOOKEXPRESS))
61 : 0 : ,m_aOther (this, ModuleRes(RB_OTHER))
62 : : {
63 : 0 : FreeResource();
64 : :
65 : 0 : Point aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT ) );
66 : 0 : Size aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) );
67 : 0 : aItemSize.Width() = GetOutputSizePixel().Width() - 30;
68 : :
69 : 0 : bool bWithMozilla = true, bUnx = true;
70 : 0 : bool bHaveEvolution = false, bHaveKab = false;
71 : 0 : bool bHaveMacab = false;
72 : :
73 : : #if !defined WITH_MOZILLA || defined MACOSX
74 : 0 : bWithMozilla = false;
75 : : #endif
76 : : #ifndef UNX
77 : : bUnx = false;
78 : : #else
79 : 0 : Reference< XDriverAccess> xManager(_pParent->getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager"))), UNO_QUERY);
80 : :
81 : : try
82 : : {
83 : : // check whether Evolution is available
84 : 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:evolution:local"))) );
85 : 0 : if ( xDriver.is() )
86 : 0 : bHaveEvolution = true;
87 : : }
88 : 0 : catch (...)
89 : : {
90 : : }
91 : :
92 : : // check whether KDE address book is available
93 : : try
94 : : {
95 : 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab"))) );
96 : 0 : if ( xDriver.is() )
97 : 0 : bHaveKab = true;
98 : : }
99 : 0 : catch (...)
100 : : {
101 : : }
102 : :
103 : : try
104 : : {
105 : : // check whether Mac OS X address book is available
106 : 0 : Reference< XDriver > xDriver( xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab"))) );
107 : 0 : if ( xDriver.is() )
108 : 0 : bHaveMacab = true;
109 : : }
110 : 0 : catch(...)
111 : : {
112 : : }
113 : : #endif
114 : :
115 : : // Items are displayed in list order
116 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aEvolution, AST_EVOLUTION, bHaveEvolution ) );
117 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
118 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
119 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aMORK, AST_MORK, bWithMozilla ) );
120 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aThunderbird, AST_THUNDERBIRD, bWithMozilla ) );
121 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aKab, AST_KAB, bHaveKab ) );
122 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aMacab, AST_MACAB, bHaveMacab ) );
123 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aLDAP, AST_LDAP, bWithMozilla ) );
124 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aOutlook, AST_OUTLOOK, bWithMozilla && !bUnx ) );
125 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aOE, AST_OE, bWithMozilla && !bUnx ) );
126 : 0 : m_aAllTypes.push_back( ButtonItem( &m_aOther, AST_OTHER, true ) );
127 : :
128 : 0 : Link aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
129 : 0 : const Size aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT ) );
130 : 0 : if ( ! m_aAllTypes.empty() )
131 : : {
132 : 0 : ButtonItem aItem = m_aAllTypes[0];
133 : 0 : aItem.m_pItem->SetStyle( aItem.m_pItem->GetStyle() | WB_GROUP );
134 : : }
135 : 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
136 : 0 : loop != m_aAllTypes.end(); ++loop )
137 : : {
138 : 0 : ButtonItem aItem = *loop;
139 : 0 : if (!aItem.m_bVisible)
140 : 0 : aItem.m_pItem->Hide();
141 : : else
142 : : {
143 : 0 : aItem.m_pItem->SetPosPixel( aTopLeft );
144 : 0 : aTopLeft.Y() += aItemSize.Height() + aSpacing.Height();
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 : for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
155 : 0 : loop != m_aAllTypes.end(); ++loop )
156 : : {
157 : 0 : loop->m_bVisible = false;
158 : : }
159 : 0 : }
160 : :
161 : : //---------------------------------------------------------------------
162 : 0 : void TypeSelectionPage::ActivatePage()
163 : : {
164 : 0 : AddressBookSourcePage::ActivatePage();
165 : :
166 : 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
167 : 0 : loop != m_aAllTypes.end(); ++loop )
168 : : {
169 : 0 : const ButtonItem& rItem = (*loop);
170 : 0 : if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
171 : : {
172 : 0 : rItem.m_pItem->GrabFocus();
173 : 0 : break;
174 : : }
175 : : }
176 : :
177 : 0 : getDialog()->enableButtons(WZB_PREVIOUS, sal_False);
178 : 0 : }
179 : :
180 : : //---------------------------------------------------------------------
181 : 0 : void TypeSelectionPage::DeactivatePage()
182 : : {
183 : 0 : AddressBookSourcePage::DeactivatePage();
184 : 0 : getDialog()->enableButtons(WZB_PREVIOUS, sal_True);
185 : 0 : }
186 : :
187 : : //---------------------------------------------------------------------
188 : 0 : void TypeSelectionPage::selectType( AddressSourceType _eType )
189 : : {
190 : 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
191 : 0 : loop != m_aAllTypes.end(); ++loop )
192 : : {
193 : 0 : ButtonItem aItem = (*loop);
194 : 0 : aItem.m_pItem->Check( _eType == aItem.m_eType );
195 : : }
196 : 0 : }
197 : :
198 : : //---------------------------------------------------------------------
199 : 0 : AddressSourceType TypeSelectionPage::getSelectedType() const
200 : : {
201 : 0 : for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
202 : 0 : loop != m_aAllTypes.end(); ++loop )
203 : : {
204 : 0 : ButtonItem aItem = (*loop);
205 : 0 : if ( aItem.m_pItem->IsChecked() )
206 : 0 : return aItem.m_eType;
207 : : }
208 : :
209 : 0 : return AST_INVALID;
210 : : }
211 : :
212 : : //---------------------------------------------------------------------
213 : 0 : void TypeSelectionPage::initializePage()
214 : : {
215 : 0 : AddressBookSourcePage::initializePage();
216 : :
217 : 0 : const AddressSettings& rSettings = getSettings();
218 : 0 : selectType(rSettings.eType);
219 : 0 : }
220 : :
221 : : //---------------------------------------------------------------------
222 : 0 : sal_Bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
223 : : {
224 : 0 : if (!AddressBookSourcePage::commitPage(_eReason))
225 : 0 : return sal_False;
226 : :
227 : 0 : if (AST_INVALID == getSelectedType( ))
228 : : {
229 : 0 : ErrorBox aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION));
230 : 0 : aError.Execute();
231 : 0 : return sal_False;
232 : : }
233 : :
234 : 0 : AddressSettings& rSettings = getSettings();
235 : 0 : rSettings.eType = getSelectedType();
236 : :
237 : 0 : return sal_True;
238 : : }
239 : :
240 : : //---------------------------------------------------------------------
241 : 0 : bool TypeSelectionPage::canAdvance() const
242 : : {
243 : 0 : return AddressBookSourcePage::canAdvance()
244 : 0 : && (AST_INVALID != getSelectedType());
245 : : }
246 : :
247 : : //---------------------------------------------------------------------
248 : 0 : IMPL_LINK( TypeSelectionPage, OnTypeSelected, void*, /*NOTINTERESTEDIN*/ )
249 : : {
250 : 0 : getDialog()->typeSelectionChanged( getSelectedType() );
251 : 0 : updateDialogTravelUI();
252 : 0 : return 0L;
253 : : }
254 : :
255 : : //.........................................................................
256 : : } // namespace abp
257 : : //.........................................................................
258 : :
259 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|