1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "typeselectionpage.hxx"
27 #include "addresssettings.hxx"
28 #include "abspilot.hxx"
29 #include <vcl/msgbox.hxx>
30 #include <com/sun/star/sdbc/XDriverAccess.hpp>
31 
32 //.........................................................................
33 namespace abp
34 {
35 //.........................................................................
36 
37 	using namespace ::com::sun::star::uno;
38 	using namespace ::com::sun::star::sdbc;
39 
40 	//=====================================================================
41 	//= TypeSelectionPage
42 	//=====================================================================
43 	//---------------------------------------------------------------------
TypeSelectionPage(OAddessBookSourcePilot * _pParent)44 	TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent )
45 		:AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_SELECTABTYPE))
46         ,m_aHint			    (this,	ModuleRes(FT_TYPE_HINTS))
47         ,m_aTypeSep			    (this,	ModuleRes(FL_TYPE))
48         ,m_aEvolution		    (this,	ModuleRes(RB_EVOLUTION))
49         ,m_aEvolutionGroupwise  (this,	ModuleRes(RB_EVOLUTION_GROUPWISE))
50         ,m_aEvolutionLdap	    (this,	ModuleRes(RB_EVOLUTION_LDAP))
51         ,m_aMORK			    (this,	ModuleRes(RB_MORK))
52         ,m_aThunderbird         (this,  ModuleRes(RB_THUNDERBIRD))
53         ,m_aKab				    (this,	ModuleRes(RB_KAB))
54         ,m_aMacab			    (this,	ModuleRes(RB_MACAB))
55         ,m_aLDAP			    (this,	ModuleRes(RB_LDAP))
56         ,m_aOutlook			    (this,	ModuleRes(RB_OUTLOOK))
57         ,m_aOE				    (this,	ModuleRes(RB_OUTLOOKEXPRESS))
58         ,m_aOther			    (this,	ModuleRes(RB_OTHER))
59     {
60 		FreeResource();
61 
62 		Point aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT ) );
63 		Size  aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) );
64         aItemSize.Width() = GetOutputSizePixel().Width() - 30;
65 
66 		bool bWithMozilla = true, bUnx = true;
67 		bool bHaveEvolution = true, bHaveKab = true;
68 		bool bHaveMacab = true;
69 
70 #if !defined WITH_MOZILLA || defined MACOSX
71 		bWithMozilla = false;
72 #endif
73 #ifndef UNX
74 		bUnx = false;
75 		bHaveEvolution = false;
76 		bHaveKab = false;
77 		bHaveMacab = false;
78 #else
79 		Reference< XDriverAccess> xManager(_pParent->getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager"))), UNO_QUERY);
80 
81 		// check whether Evolution is available
82 		Reference< XDriver > xDriver( xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:evolution:local"))) );
83 		if ( !xDriver.is() )
84 			bHaveEvolution = false;
85 
86 		// check whether KDE address book is available
87 		xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:kab")));
88 		if ( !xDriver.is() )
89 			bHaveKab = false;
90 
91 		// check whether Mac OS X address book is available
92 		xDriver = xManager->getDriverByURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:address:macab")));
93 		if ( !xDriver.is() )
94 			bHaveMacab = false;
95 #endif
96 
97 		// Items are displayed in list order
98 		m_aAllTypes.push_back( ButtonItem( &m_aEvolution, AST_EVOLUTION, bHaveEvolution ) );
99 		m_aAllTypes.push_back( ButtonItem( &m_aEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
100 		m_aAllTypes.push_back( ButtonItem( &m_aEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
101 		m_aAllTypes.push_back( ButtonItem( &m_aMORK, AST_MORK, bWithMozilla ) );
102 		m_aAllTypes.push_back( ButtonItem( &m_aThunderbird, AST_THUNDERBIRD, bWithMozilla ) );
103 		m_aAllTypes.push_back( ButtonItem( &m_aKab, AST_KAB, bHaveKab ) );
104 		m_aAllTypes.push_back( ButtonItem( &m_aMacab, AST_MACAB, bHaveMacab ) );
105 		m_aAllTypes.push_back( ButtonItem( &m_aLDAP, AST_LDAP, bWithMozilla ) );
106 		m_aAllTypes.push_back( ButtonItem( &m_aOutlook, AST_OUTLOOK, bWithMozilla && !bUnx ) );
107 		m_aAllTypes.push_back( ButtonItem( &m_aOE, AST_OE, bWithMozilla && !bUnx ) );
108 		m_aAllTypes.push_back( ButtonItem( &m_aOther, AST_OTHER, true ) );
109 
110         bool bFirstVisible = true;
111 		Link aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
112         const Size aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT ) );
113 		for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
114 			  loop != m_aAllTypes.end(); ++loop )
115 		{
116 			ButtonItem aItem = *loop;
117 			if (!aItem.m_bVisible)
118 				aItem.m_pItem->Hide();
119 			else
120 			{
121 				aItem.m_pItem->SetPosPixel( aTopLeft );
122 				aTopLeft.Y() += aItemSize.Height() + aSpacing.Height();
123 				aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
124 				aItem.m_pItem->Show();
125 
126                 if ( bFirstVisible )
127                 {
128                     aItem.m_pItem->SetStyle( aItem.m_pItem->GetStyle() | WB_GROUP );
129                     bFirstVisible = false;
130                 }
131 			}
132 		}
133 	}
134 
135 	//---------------------------------------------------------------------
~TypeSelectionPage()136     TypeSelectionPage::~TypeSelectionPage()
137     {
138 		for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
139 			  loop != m_aAllTypes.end(); ++loop )
140 		{
141 			loop->m_bVisible = false;
142         }
143     }
144 
145 	//---------------------------------------------------------------------
ActivatePage()146 	void TypeSelectionPage::ActivatePage()
147 	{
148 		AddressBookSourcePage::ActivatePage();
149 
150 		for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
151 			  loop != m_aAllTypes.end(); ++loop )
152 		{
153 			const ButtonItem& rItem = (*loop);
154 			if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
155 			{
156 				rItem.m_pItem->GrabFocus();
157                 break;
158             }
159 		}
160 
161         getDialog()->enableButtons(WZB_PREVIOUS, sal_False);
162 	}
163 
164 	//---------------------------------------------------------------------
DeactivatePage()165 	void TypeSelectionPage::DeactivatePage()
166 	{
167 		AddressBookSourcePage::DeactivatePage();
168 		getDialog()->enableButtons(WZB_PREVIOUS, sal_True);
169 	}
170 
171 	//---------------------------------------------------------------------
selectType(AddressSourceType _eType)172 	void TypeSelectionPage::selectType( AddressSourceType _eType )
173 	{
174 		for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
175 			  loop != m_aAllTypes.end(); ++loop )
176 		{
177 			ButtonItem aItem = (*loop);
178 			aItem.m_pItem->Check( _eType == aItem.m_eType );
179 		}
180 	}
181 
182 	//---------------------------------------------------------------------
getSelectedType() const183 	AddressSourceType TypeSelectionPage::getSelectedType() const
184 	{
185 		for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
186 			  loop != m_aAllTypes.end(); ++loop )
187 		{
188 			ButtonItem aItem = (*loop);
189 			if ( aItem.m_pItem->IsChecked() )
190 				return aItem.m_eType;
191 		}
192 
193 		return AST_INVALID;
194 	}
195 
196 	//---------------------------------------------------------------------
initializePage()197 	void TypeSelectionPage::initializePage()
198 	{
199 		AddressBookSourcePage::initializePage();
200 
201 		const AddressSettings& rSettings = getSettings();
202 		selectType(rSettings.eType);
203 	}
204 
205 	//---------------------------------------------------------------------
commitPage(::svt::WizardTypes::CommitPageReason _eReason)206 	sal_Bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
207 	{
208 		if (!AddressBookSourcePage::commitPage(_eReason))
209 			return sal_False;
210 
211 		if (AST_INVALID == getSelectedType( ))
212 		{
213 			ErrorBox aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION));
214 			aError.Execute();
215 			return sal_False;
216 		}
217 
218 		AddressSettings& rSettings = getSettings();
219 		rSettings.eType = getSelectedType();
220 
221 		return sal_True;
222 	}
223 
224 	//---------------------------------------------------------------------
canAdvance() const225 	bool TypeSelectionPage::canAdvance() const
226 	{
227 		return	AddressBookSourcePage::canAdvance()
228 			&&	(AST_INVALID != getSelectedType());
229 	}
230 
231 	//---------------------------------------------------------------------
232 	IMPL_LINK( TypeSelectionPage, OnTypeSelected, void*, /*NOTINTERESTEDIN*/ )
233 	{
234         getDialog()->typeSelectionChanged( getSelectedType() );
235 		updateDialogTravelUI();
236 		return 0L;
237 	}
238 
239 //.........................................................................
240 }	// namespace abp
241 //.........................................................................
242 
243