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 "unodialogabp.hxx"
27 #include <cppuhelper/typeprovider.hxx>
28 #include "abspilot.hxx"
29 #include <comphelper/sequence.hxx>
30 #include <vcl/msgbox.hxx>
31 
createRegistryInfo_OABSPilotUno()32 extern "C" void SAL_CALL createRegistryInfo_OABSPilotUno()
33 {
34 	static ::abp::OMultiInstanceAutoRegistration< ::abp::OABSPilotUno > aAutoRegistration;
35 }
36 
37 #define PROPERTY_ID_DATASOURCENAME  3
38 //.........................................................................
39 namespace abp
40 {
41 //.........................................................................
42 
43 	using namespace ::com::sun::star::uno;
44 	using namespace ::com::sun::star::lang;
45 	using namespace ::com::sun::star::beans;
46 	using namespace ::com::sun::star::ui::dialogs;
47 
48 	//=====================================================================
49 	//= OABSPilotUno
50 	//=====================================================================
51 	//---------------------------------------------------------------------
OABSPilotUno(const Reference<XMultiServiceFactory> & _rxORB)52 	OABSPilotUno::OABSPilotUno(const Reference< XMultiServiceFactory >& _rxORB)
53 		:OGenericUnoDialog(_rxORB)
54 	{
55         registerProperty( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSourceName")), PROPERTY_ID_DATASOURCENAME, PropertyAttribute::READONLY ,
56 		    &m_sDataSourceName, ::getCppuType( &m_sDataSourceName ) );
57 	}
58 
59 	//--------------------------------------------------------------------------
queryInterface(const Type & aType)60 	Any SAL_CALL OABSPilotUno::queryInterface( const Type& aType ) throw (RuntimeException)
61 	{
62 		Any aReturn = OABSPilotUno_DBase::queryInterface( aType );
63 		return aReturn.hasValue() ? aReturn : OABSPilotUno_JBase::queryInterface( aType );
64 	}
65 
66 	//--------------------------------------------------------------------------
acquire()67 	void SAL_CALL OABSPilotUno::acquire(  ) throw ()
68 	{
69 		OABSPilotUno_DBase::acquire();
70 	}
71 
72 	//--------------------------------------------------------------------------
release()73 	void SAL_CALL OABSPilotUno::release(  ) throw ()
74 	{
75 		OABSPilotUno_DBase::release();
76 	}
77 
78 	//---------------------------------------------------------------------
getTypes()79 	Sequence< Type > SAL_CALL OABSPilotUno::getTypes(  ) throw (RuntimeException)
80 	{
81 		return ::comphelper::concatSequences(
82 			OABSPilotUno_DBase::getTypes(),
83 			OABSPilotUno_JBase::getTypes()
84 		);
85 	}
86 
87 	//---------------------------------------------------------------------
getImplementationId()88 	Sequence<sal_Int8> SAL_CALL OABSPilotUno::getImplementationId(  ) throw(RuntimeException)
89 	{
90 		static ::cppu::OImplementationId* s_pId;
91 		if ( !s_pId )
92 		{
93 			::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
94 			if ( !s_pId )
95 			{
96 				static ::cppu::OImplementationId s_aId;
97 				s_pId = &s_aId;
98 			}
99 		}
100 		return s_pId->getImplementationId();
101 	}
102 
103 	//---------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)104 	Reference< XInterface > SAL_CALL OABSPilotUno::Create(const Reference< XMultiServiceFactory >& _rxFactory)
105 	{
106 		return *(new OABSPilotUno(_rxFactory));
107 	}
108 
109 	//---------------------------------------------------------------------
getImplementationName()110 	::rtl::OUString SAL_CALL OABSPilotUno::getImplementationName() throw(RuntimeException)
111 	{
112 		return getImplementationName_Static();
113 	}
114 
115 	//---------------------------------------------------------------------
getImplementationName_Static()116 	::rtl::OUString OABSPilotUno::getImplementationName_Static() throw(RuntimeException)
117 	{
118 		return ::rtl::OUString::createFromAscii("org.openoffice.comp.abp.OAddressBookSourcePilot");
119 	}
120 
121 	//---------------------------------------------------------------------
getSupportedServiceNames()122 	::comphelper::StringSequence SAL_CALL OABSPilotUno::getSupportedServiceNames() throw(RuntimeException)
123 	{
124 		return getSupportedServiceNames_Static();
125 	}
126 
127 	//---------------------------------------------------------------------
getSupportedServiceNames_Static()128 	::comphelper::StringSequence OABSPilotUno::getSupportedServiceNames_Static() throw(RuntimeException)
129 	{
130 		::comphelper::StringSequence aSupported(1);
131 		aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.AddressBookSourcePilot");
132 		return aSupported;
133 	}
134 
135 	//---------------------------------------------------------------------
getPropertySetInfo()136 	Reference<XPropertySetInfo>  SAL_CALL OABSPilotUno::getPropertySetInfo() throw(RuntimeException)
137 	{
138 		Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
139 		return xInfo;
140 	}
141 
142 	//---------------------------------------------------------------------
getInfoHelper()143 	::cppu::IPropertyArrayHelper& OABSPilotUno::getInfoHelper()
144 	{
145 		return *const_cast<OABSPilotUno*>(this)->getArrayHelper();
146 	}
147 
148 	//--------------------------------------------------------------------------
createArrayHelper() const149 	::cppu::IPropertyArrayHelper* OABSPilotUno::createArrayHelper( ) const
150 	{
151 		Sequence< Property > aProps;
152 		describeProperties(aProps);
153 		return new ::cppu::OPropertyArrayHelper(aProps);
154 	}
155 
156 	//--------------------------------------------------------------------------
createDialog(Window * _pParent)157 	Dialog*	OABSPilotUno::createDialog(Window* _pParent)
158 	{
159 		return new OAddessBookSourcePilot(_pParent, m_aContext.getLegacyServiceFactory());
160 	}
161 
162 	//--------------------------------------------------------------------------
execute(const Sequence<NamedValue> &)163     Any SAL_CALL OABSPilotUno::execute( const Sequence< NamedValue >& /*lArgs*/ ) throw (IllegalArgumentException, Exception, RuntimeException)
164 	{
165 		// not interested in the context, not interested in the args
166 		// -> call the execute method of the XExecutableDialog
167         static_cast< XExecutableDialog* >( this )->execute();
168 
169         // result interest not really ...
170         // We show this dialog one times only!
171         // User has one chance to accept it or not.
172         // (or he can start it again by using wizard-menu!)
173         // So we should deregister it on our general job execution service by using right protocol parameters.
174         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > lProtocol(1);
175         lProtocol[0].Name    = ::rtl::OUString::createFromAscii("Deactivate");
176         lProtocol[0].Value <<= sal_True;
177         return makeAny( lProtocol );
178 	}
179     // -----------------------------------------------------------------------------
executedDialog(sal_Int16 _nExecutionResult)180     void OABSPilotUno::executedDialog(sal_Int16 _nExecutionResult)
181     {
182         if ( _nExecutionResult == RET_OK )
183         {
184             const AddressSettings& aSettings = static_cast<OAddessBookSourcePilot*>(m_pDialog)->getSettings();
185             m_sDataSourceName = aSettings.bRegisterDataSource ? aSettings.sRegisteredDataSourceName : aSettings.sDataSourceName;
186         }
187     }
188 
189 //.........................................................................
190 }	// namespace abp
191 //.........................................................................
192 
193