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 27 #include <com/sun/star/oooimprovement/XCore.hpp> 28 29 #include "oooimprovecore_module.hxx" 30 #include <com/sun/star/frame/XTerminateListener.hpp> 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/lang/XServiceInfo.hpp> 33 #include <com/sun/star/oooimprovement/XCoreController.hpp> 34 #include <com/sun/star/uno/XComponentContext.hpp> 35 #include <comphelper/componentmodule.hxx> 36 #include <comphelper/configurationhelper.hxx> 37 #include <comphelper/processfactory.hxx> 38 #include <comphelper/uieventslogger.hxx> 39 #include <cppuhelper/implbase3.hxx> 40 #include <svx/svxdlg.hxx> 41 #include <vcl/svapp.hxx> 42 #include <vos/mutex.hxx> 43 #include <svl/itemset.hxx> 44 #include <svl/stritem.hxx> 45 #include <sfx2/app.hxx> 46 #include <svx/dialogs.hrc> 47 #include <sfx2/sfxsids.hrc> 48 49 using namespace ::com::sun::star::oooimprovement; 50 using ::com::sun::star::frame::XTerminateListener; 51 using ::com::sun::star::lang::EventObject; 52 using ::com::sun::star::lang::XMultiServiceFactory; 53 using ::com::sun::star::lang::XServiceInfo; 54 using ::com::sun::star::uno::Reference; 55 using ::com::sun::star::uno::RuntimeException; 56 using ::com::sun::star::uno::Sequence; 57 using ::com::sun::star::uno::UNO_QUERY; 58 using ::com::sun::star::uno::XComponentContext; 59 using ::com::sun::star::uno::XInterface; 60 using ::comphelper::UiEventsLogger; 61 using ::rtl::OUString; 62 63 // declaration 64 namespace oooimprovecore 65 { 66 class Core : public ::cppu::WeakImplHelper3<XCore,XServiceInfo,XTerminateListener> 67 { 68 public: 69 // XServiceInfo - static version 70 static OUString SAL_CALL getImplementationName_static(); 71 static Sequence<OUString> SAL_CALL getSupportedServiceNames_static(); 72 static Reference<XInterface> Create(const Reference<XComponentContext>& context ); 73 74 protected: 75 Core(const Reference<XComponentContext>&); 76 virtual ~Core(); 77 78 // XCore 79 virtual sal_Int32 SAL_CALL getSessionLogEventCount() throw(RuntimeException); 80 virtual sal_Bool SAL_CALL getUiEventsLoggerEnabled() throw(RuntimeException); 81 virtual void SAL_CALL inviteUser() throw(RuntimeException); 82 83 // XServiceInfo 84 virtual OUString SAL_CALL getImplementationName() throw(RuntimeException); 85 virtual sal_Bool SAL_CALL supportsService(const OUString& service_name) throw(RuntimeException); 86 virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException); 87 88 // XTerminateListener 89 virtual void SAL_CALL queryTermination(const EventObject&) throw(RuntimeException); 90 virtual void SAL_CALL notifyTermination(const EventObject&) throw(RuntimeException); 91 92 // XEventListener 93 virtual void SAL_CALL disposing(const EventObject&) throw(RuntimeException); 94 }; 95 } 96 97 98 // implementation 99 namespace oooimprovecore 100 { 101 Core(const Reference<XComponentContext> &)102 Core::Core(const Reference<XComponentContext>&) 103 { } 104 ~Core()105 Core::~Core() 106 { } 107 getSessionLogEventCount()108 sal_Int32 SAL_CALL Core::getSessionLogEventCount() throw(RuntimeException) 109 { return UiEventsLogger::getSessionLogEventCount(); } 110 getUiEventsLoggerEnabled()111 sal_Bool SAL_CALL Core::getUiEventsLoggerEnabled() throw(RuntimeException) 112 { return UiEventsLogger::isEnabled(); } 113 inviteUser()114 void SAL_CALL Core::inviteUser() throw(RuntimeException) 115 { 116 Reference<XMultiServiceFactory> xServiceFactory = ::comphelper::getProcessServiceFactory(); 117 118 OUString help_url; 119 Reference<XCoreController> core_c( 120 xServiceFactory->createInstance(OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")), 121 UNO_QUERY); 122 if(core_c.is()) 123 ::comphelper::ConfigurationHelper::readDirectKey( 124 xServiceFactory, 125 OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"), 126 OUString::createFromAscii("Participation"), 127 OUString::createFromAscii("HelpUrl"), 128 ::comphelper::ConfigurationHelper::E_READONLY) >>= help_url; 129 else 130 help_url = OUString::createFromAscii("http://www.openoffice.org"); 131 { 132 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 133 SfxAllItemSet aSet( SFX_APP()->GetPool() ); 134 aSet.Put( SfxStringItem( SID_CURRENT_URL, help_url ) ); 135 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 136 if ( pFact ) 137 { 138 SfxAbstractDialog *pDlg = pFact->CreateSfxDialog( NULL, aSet, 0, RID_SVXPAGE_IMPROVEMENT ); 139 pDlg->Execute(); 140 delete pDlg; 141 } 142 } 143 } 144 supportsService(const OUString & service_name)145 sal_Bool SAL_CALL Core::supportsService(const OUString& service_name) throw(RuntimeException) 146 { 147 const Sequence<OUString> service_names(getSupportedServiceNames()); 148 for (sal_Int32 idx = service_names.getLength()-1; idx>=0; --idx) 149 if(service_name == service_names[idx]) return sal_True; 150 return sal_False; 151 } 152 getImplementationName()153 OUString SAL_CALL Core::getImplementationName() throw(RuntimeException) 154 { return getImplementationName_static(); } 155 getSupportedServiceNames()156 Sequence<OUString> SAL_CALL Core::getSupportedServiceNames() throw(RuntimeException) 157 { return getSupportedServiceNames_static(); } 158 getImplementationName_static()159 OUString SAL_CALL Core::getImplementationName_static() 160 { return OUString::createFromAscii("com.sun.star.comp.extensions.oooimprovecore.Core"); } 161 getSupportedServiceNames_static()162 Sequence<OUString> SAL_CALL Core::getSupportedServiceNames_static() 163 { 164 Sequence<OUString> aServiceNames(1); 165 aServiceNames[0] = OUString::createFromAscii("com.sun.star.oooimprovement.Core"); 166 return aServiceNames; 167 } 168 queryTermination(const EventObject &)169 void Core::queryTermination(const EventObject&) throw(RuntimeException) 170 { } 171 notifyTermination(const EventObject &)172 void Core::notifyTermination(const EventObject&) throw(RuntimeException) 173 { 174 UiEventsLogger::disposing(); 175 } 176 disposing(const EventObject &)177 void Core::disposing(const EventObject&) throw(RuntimeException) 178 { } 179 Create(const Reference<XComponentContext> & context)180 Reference<XInterface> Core::Create(const Reference<XComponentContext>& context) 181 { return *(new Core(context)); } 182 createRegistryInfo_Core()183 void createRegistryInfo_Core() 184 { 185 static OAutoRegistration<Core> auto_reg; 186 } 187 } 188