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