1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  ************************************************************************/
26 
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_extensions.hxx"
29 
30 #include <com/sun/star/oooimprovement/XCore.hpp>
31 
32 #include "oooimprovecore_module.hxx"
33 #include <com/sun/star/frame/XTerminateListener.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/oooimprovement/XCoreController.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <comphelper/componentmodule.hxx>
39 #include <comphelper/configurationhelper.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/uieventslogger.hxx>
42 #include <cppuhelper/implbase3.hxx>
43 #include <svx/svxdlg.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vos/mutex.hxx>
46 #include <svl/itemset.hxx>
47 #include <svl/stritem.hxx>
48 #include <sfx2/app.hxx>
49 #include <svx/dialogs.hrc>
50 #include <sfx2/sfxsids.hrc>
51 
52 using namespace ::com::sun::star::oooimprovement;
53 using ::com::sun::star::frame::XTerminateListener;
54 using ::com::sun::star::lang::EventObject;
55 using ::com::sun::star::lang::XMultiServiceFactory;
56 using ::com::sun::star::lang::XServiceInfo;
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::uno::RuntimeException;
59 using ::com::sun::star::uno::Sequence;
60 using ::com::sun::star::uno::UNO_QUERY;
61 using ::com::sun::star::uno::XComponentContext;
62 using ::com::sun::star::uno::XInterface;
63 using ::comphelper::UiEventsLogger;
64 using ::rtl::OUString;
65 
66 // declaration
67 namespace oooimprovecore
68 {
69     class Core : public ::cppu::WeakImplHelper3<XCore,XServiceInfo,XTerminateListener>
70     {
71         public:
72             // XServiceInfo - static version
73             static OUString SAL_CALL getImplementationName_static();
74             static Sequence<OUString> SAL_CALL getSupportedServiceNames_static();
75             static Reference<XInterface> Create(const Reference<XComponentContext>& context );
76 
77         protected:
78             Core(const Reference<XComponentContext>&);
79             virtual ~Core();
80 
81             // XCore
82             virtual sal_Int32 SAL_CALL getSessionLogEventCount() throw(RuntimeException);
83             virtual sal_Bool SAL_CALL getUiEventsLoggerEnabled() throw(RuntimeException);
84             virtual void SAL_CALL inviteUser() throw(RuntimeException);
85 
86             // XServiceInfo
87             virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
88             virtual sal_Bool SAL_CALL supportsService(const OUString& service_name) throw(RuntimeException);
89             virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException);
90 
91             // XTerminateListener
92             virtual void SAL_CALL queryTermination(const EventObject&) throw(RuntimeException);
93             virtual void SAL_CALL notifyTermination(const EventObject&) throw(RuntimeException);
94 
95             // XEventListener
96             virtual void SAL_CALL disposing(const EventObject&) throw(RuntimeException);
97     };
98 }
99 
100 
101 // implementation
102 namespace oooimprovecore
103 {
104 
105     Core::Core(const Reference<XComponentContext>&)
106     { }
107 
108     Core::~Core()
109     { }
110 
111     sal_Int32 SAL_CALL Core::getSessionLogEventCount() throw(RuntimeException)
112     { return UiEventsLogger::getSessionLogEventCount(); }
113 
114     sal_Bool SAL_CALL Core::getUiEventsLoggerEnabled() throw(RuntimeException)
115     { return UiEventsLogger::isEnabled(); }
116 
117     void SAL_CALL Core::inviteUser() throw(RuntimeException)
118     {
119         Reference<XMultiServiceFactory> xServiceFactory = ::comphelper::getProcessServiceFactory();
120 
121         OUString help_url;
122         Reference<XCoreController> core_c(
123             xServiceFactory->createInstance(OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")),
124             UNO_QUERY);
125         if(core_c.is())
126             ::comphelper::ConfigurationHelper::readDirectKey(
127                 xServiceFactory,
128                 OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
129                 OUString::createFromAscii("Participation"),
130                 OUString::createFromAscii("HelpUrl"),
131                 ::comphelper::ConfigurationHelper::E_READONLY) >>= help_url;
132         else
133             help_url = OUString::createFromAscii("http://www.openoffice.org");
134         {
135             ::vos::OGuard aGuard( Application::GetSolarMutex() );
136 			SfxAllItemSet aSet( SFX_APP()->GetPool() );
137 			aSet.Put( SfxStringItem( SID_CURRENT_URL, help_url ) );
138 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
139 			if ( pFact )
140 			{
141 				SfxAbstractDialog *pDlg = pFact->CreateSfxDialog( NULL, aSet, 0, RID_SVXPAGE_IMPROVEMENT );
142 				pDlg->Execute();
143 				delete pDlg;
144 			}
145         }
146     }
147 
148     sal_Bool SAL_CALL Core::supportsService(const OUString& service_name) throw(RuntimeException)
149     {
150         const Sequence<OUString> service_names(getSupportedServiceNames());
151         for (sal_Int32 idx = service_names.getLength()-1; idx>=0; --idx)
152             if(service_name == service_names[idx]) return sal_True;
153         return sal_False;
154     }
155 
156     OUString SAL_CALL Core::getImplementationName() throw(RuntimeException)
157     { return getImplementationName_static(); }
158 
159     Sequence<OUString> SAL_CALL Core::getSupportedServiceNames() throw(RuntimeException)
160     { return getSupportedServiceNames_static(); }
161 
162     OUString SAL_CALL Core::getImplementationName_static()
163     { return OUString::createFromAscii("com.sun.star.comp.extensions.oooimprovecore.Core"); }
164 
165     Sequence<OUString> SAL_CALL Core::getSupportedServiceNames_static()
166     {
167         Sequence<OUString> aServiceNames(1);
168         aServiceNames[0] = OUString::createFromAscii("com.sun.star.oooimprovement.Core");
169         return aServiceNames;
170     }
171 
172     void Core::queryTermination(const EventObject&) throw(RuntimeException)
173     { }
174 
175     void Core::notifyTermination(const EventObject&) throw(RuntimeException)
176     {
177         UiEventsLogger::disposing();
178     }
179 
180     void Core::disposing(const EventObject&) throw(RuntimeException)
181     { }
182 
183     Reference<XInterface> Core::Create(const Reference<XComponentContext>& context)
184     { return *(new Core(context)); }
185 
186     void createRegistryInfo_Core()
187     {
188         static OAutoRegistration<Core> auto_reg;
189     }
190 }
191