xref: /trunk/main/extensions/source/abpilot/unodialogabp.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "unodialogabp.hxx"
27cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
28cdf0e10cSrcweir #include "abspilot.hxx"
29cdf0e10cSrcweir #include <comphelper/sequence.hxx>
30cdf0e10cSrcweir #include <vcl/msgbox.hxx>
31cdf0e10cSrcweir 
createRegistryInfo_OABSPilotUno()32cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OABSPilotUno()
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     static ::abp::OMultiInstanceAutoRegistration< ::abp::OABSPilotUno > aAutoRegistration;
35cdf0e10cSrcweir }
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define PROPERTY_ID_DATASOURCENAME  3
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir namespace abp
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
46cdf0e10cSrcweir     using namespace ::com::sun::star::ui::dialogs;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     //=====================================================================
49cdf0e10cSrcweir     //= OABSPilotUno
50cdf0e10cSrcweir     //=====================================================================
51cdf0e10cSrcweir     //---------------------------------------------------------------------
OABSPilotUno(const Reference<XMultiServiceFactory> & _rxORB)52cdf0e10cSrcweir     OABSPilotUno::OABSPilotUno(const Reference< XMultiServiceFactory >& _rxORB)
53cdf0e10cSrcweir         :OGenericUnoDialog(_rxORB)
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         registerProperty( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSourceName")), PROPERTY_ID_DATASOURCENAME, PropertyAttribute::READONLY ,
56cdf0e10cSrcweir             &m_sDataSourceName, ::getCppuType( &m_sDataSourceName ) );
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     //--------------------------------------------------------------------------
queryInterface(const Type & aType)60cdf0e10cSrcweir     Any SAL_CALL OABSPilotUno::queryInterface( const Type& aType ) throw (RuntimeException)
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         Any aReturn = OABSPilotUno_DBase::queryInterface( aType );
63cdf0e10cSrcweir         return aReturn.hasValue() ? aReturn : OABSPilotUno_JBase::queryInterface( aType );
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     //--------------------------------------------------------------------------
acquire()67cdf0e10cSrcweir     void SAL_CALL OABSPilotUno::acquire(  ) throw ()
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         OABSPilotUno_DBase::acquire();
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     //--------------------------------------------------------------------------
release()73cdf0e10cSrcweir     void SAL_CALL OABSPilotUno::release(  ) throw ()
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         OABSPilotUno_DBase::release();
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     //---------------------------------------------------------------------
getTypes()79cdf0e10cSrcweir     Sequence< Type > SAL_CALL OABSPilotUno::getTypes(  ) throw (RuntimeException)
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         return ::comphelper::concatSequences(
82cdf0e10cSrcweir             OABSPilotUno_DBase::getTypes(),
83cdf0e10cSrcweir             OABSPilotUno_JBase::getTypes()
84cdf0e10cSrcweir         );
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     //---------------------------------------------------------------------
getImplementationId()88cdf0e10cSrcweir     Sequence<sal_Int8> SAL_CALL OABSPilotUno::getImplementationId(  ) throw(RuntimeException)
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         static ::cppu::OImplementationId* s_pId;
91cdf0e10cSrcweir         if ( !s_pId )
92cdf0e10cSrcweir         {
93cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
94cdf0e10cSrcweir             if ( !s_pId )
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 static ::cppu::OImplementationId s_aId;
97cdf0e10cSrcweir                 s_pId = &s_aId;
98cdf0e10cSrcweir             }
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir         return s_pId->getImplementationId();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     //---------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)104cdf0e10cSrcweir     Reference< XInterface > SAL_CALL OABSPilotUno::Create(const Reference< XMultiServiceFactory >& _rxFactory)
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         return *(new OABSPilotUno(_rxFactory));
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     //---------------------------------------------------------------------
getImplementationName()110cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OABSPilotUno::getImplementationName() throw(RuntimeException)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         return getImplementationName_Static();
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     //---------------------------------------------------------------------
getImplementationName_Static()116cdf0e10cSrcweir     ::rtl::OUString OABSPilotUno::getImplementationName_Static() throw(RuntimeException)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         return ::rtl::OUString::createFromAscii("org.openoffice.comp.abp.OAddressBookSourcePilot");
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     //---------------------------------------------------------------------
getSupportedServiceNames()122cdf0e10cSrcweir     ::comphelper::StringSequence SAL_CALL OABSPilotUno::getSupportedServiceNames() throw(RuntimeException)
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         return getSupportedServiceNames_Static();
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     //---------------------------------------------------------------------
getSupportedServiceNames_Static()128cdf0e10cSrcweir     ::comphelper::StringSequence OABSPilotUno::getSupportedServiceNames_Static() throw(RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         ::comphelper::StringSequence aSupported(1);
131cdf0e10cSrcweir         aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.AddressBookSourcePilot");
132cdf0e10cSrcweir         return aSupported;
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     //---------------------------------------------------------------------
getPropertySetInfo()136cdf0e10cSrcweir     Reference<XPropertySetInfo>  SAL_CALL OABSPilotUno::getPropertySetInfo() throw(RuntimeException)
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
139cdf0e10cSrcweir         return xInfo;
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     //---------------------------------------------------------------------
getInfoHelper()143cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper& OABSPilotUno::getInfoHelper()
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         return *const_cast<OABSPilotUno*>(this)->getArrayHelper();
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     //--------------------------------------------------------------------------
createArrayHelper() const149cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper* OABSPilotUno::createArrayHelper( ) const
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         Sequence< Property > aProps;
152cdf0e10cSrcweir         describeProperties(aProps);
153cdf0e10cSrcweir         return new ::cppu::OPropertyArrayHelper(aProps);
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     //--------------------------------------------------------------------------
createDialog(Window * _pParent)157cdf0e10cSrcweir     Dialog* OABSPilotUno::createDialog(Window* _pParent)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         return new OAddessBookSourcePilot(_pParent, m_aContext.getLegacyServiceFactory());
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     //--------------------------------------------------------------------------
execute(const Sequence<NamedValue> &)163cdf0e10cSrcweir     Any SAL_CALL OABSPilotUno::execute( const Sequence< NamedValue >& /*lArgs*/ ) throw (IllegalArgumentException, Exception, RuntimeException)
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         // not interested in the context, not interested in the args
166cdf0e10cSrcweir         // -> call the execute method of the XExecutableDialog
167cdf0e10cSrcweir         static_cast< XExecutableDialog* >( this )->execute();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         // result interest not really ...
170cdf0e10cSrcweir         // We show this dialog one times only!
171cdf0e10cSrcweir         // User has one chance to accept it or not.
172cdf0e10cSrcweir         // (or he can start it again by using wizard-menu!)
173cdf0e10cSrcweir         // So we should deregister it on our general job execution service by using right protocol parameters.
174cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > lProtocol(1);
175cdf0e10cSrcweir         lProtocol[0].Name    = ::rtl::OUString::createFromAscii("Deactivate");
176cdf0e10cSrcweir         lProtocol[0].Value <<= sal_True;
177cdf0e10cSrcweir         return makeAny( lProtocol );
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     // -----------------------------------------------------------------------------
executedDialog(sal_Int16 _nExecutionResult)180cdf0e10cSrcweir     void OABSPilotUno::executedDialog(sal_Int16 _nExecutionResult)
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         if ( _nExecutionResult == RET_OK )
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             const AddressSettings& aSettings = static_cast<OAddessBookSourcePilot*>(m_pDialog)->getSettings();
185cdf0e10cSrcweir             m_sDataSourceName = aSettings.bRegisterDataSource ? aSettings.sRegisteredDataSourceName : aSettings.sDataSourceName;
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //.........................................................................
190cdf0e10cSrcweir }   // namespace abp
191cdf0e10cSrcweir //.........................................................................
192