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 #ifndef __FRAMEWORK_DISPATCH_UIEVENTLOGHELPER_HXX_
25 #define __FRAMEWORK_DISPATCH_UIEVENTLOGHELPER_HXX_
26 
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/frame/XModuleManager.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/util/URL.hpp>
34 #include <comphelper/uieventslogger.hxx>
35 #include <rtl/ustring.hxx>
36 #include <services.h>
37 
38 namespace framework
39 {
40     class UiEventLogHelper
41     {
42         public:
UiEventLogHelper(const::rtl::OUString & aWidgetname)43             UiEventLogHelper(const ::rtl::OUString& aWidgetname)
44                 : m_aWidgetName(aWidgetname)
45                 , m_hasAppName(false)
46             { }
47 
log(const::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & rServiceManager,const::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> & rModel,const::com::sun::star::util::URL & rUrl,const::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & rArgs)48             void log(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager,
49                 const ::com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& rModel,
50                 const ::com::sun::star::util::URL& rUrl,
51                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs)
52             {
53 
54                 if(!m_hasAppName && rServiceManager.is() && rModel.is())
55                 {
56                     try
57                     {
58                         static ::rtl::OUString our_aModuleManagerName = SERVICENAME_MODULEMANAGER;
59                         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
60                             rServiceManager->createInstance(our_aModuleManagerName)
61                             , ::com::sun::star::uno::UNO_QUERY_THROW);
62                         m_aAppName = xModuleManager->identify(rModel);
63                         m_hasAppName = true;
64                     } catch(::com::sun::star::uno::Exception&) {}
65                 }
66                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> aArgsWithOrigin(rArgs);
67                 ::comphelper::UiEventsLogger::appendDispatchOrigin(aArgsWithOrigin, m_aAppName, m_aWidgetName);
68                 ::comphelper::UiEventsLogger::logDispatch(rUrl, aArgsWithOrigin);
69             }
70 
71         private:
72             const ::rtl::OUString m_aWidgetName;
73             bool m_hasAppName;
74             ::rtl::OUString m_aAppName;
75     };
76 }
77 
78 #endif // __FRAMEWORK_DISPATCH_UIEVENTLOGHELPER_HXX_
79