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 
28 #include "invite_job.hxx"
29 #include "config.hxx"
30 #include "logstorage.hxx"
31 #include <com/sun/star/oooimprovement/XCore.hpp>
32 #include <rtl/process.h>
33 
34 
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::task;
38 using namespace ::com::sun::star::uno;
39 using ::com::sun::star::oooimprovement::XCore;
40 using ::rtl::OUString;
41 
42 namespace
43 {
44     // dont show Invitation, when:
45     // -nofirststartwizard commandline switch is present
46     // [add additional conditions here]
lcl_IsInvitationAllowed()47     static bool lcl_IsInvitationAllowed()
48     {
49         static OUString sNoFirstStartWizard = OUString::createFromAscii("-nofirststartwizard");
50         sal_Int32 nCount = rtl_getAppCommandArgCount();
51         for(sal_Int32 nCurrent=0; nCurrent<nCount; nCurrent++)
52         {
53             OUString sArg;
54             rtl_getAppCommandArg(nCurrent, &sArg.pData);
55             if(sNoFirstStartWizard == sArg)
56                 return false;
57         }
58         return true;
59     }
60 }
61 
62 namespace oooimprovement
63 {
64 //    InviteJob::InviteJob(const Reference<XComponentContext>& context)
65 //        : m_ServiceFactory(Reference<XMultiServiceFactory>(
66 //            context->getServiceManager()->createInstanceWithContext(
67 //                OUString::createFromAscii("com.sun.star.lang.XMultiServiceFactory"), context),
68 //            UNO_QUERY))
69 //    { }
70 
InviteJob(const Reference<XMultiServiceFactory> & sf)71     InviteJob::InviteJob(const Reference<XMultiServiceFactory>& sf)
72         : m_ServiceFactory(sf)
73     { }
74 
~InviteJob()75     InviteJob::~InviteJob()
76     { }
77 
executeAsync(const Sequence<NamedValue> &,const Reference<XJobListener> & listener)78     void SAL_CALL InviteJob::executeAsync(const Sequence<NamedValue>&, const Reference<XJobListener>& listener) throw(RuntimeException)
79     {
80         Config config(m_ServiceFactory);
81         {
82             LogStorage log_storage(m_ServiceFactory);
83             log_storage.assureExists();
84         }
85         if(config.getOfficeStartCounterdown() > 0)
86             config.decrementOfficeStartCounterdown(1);
87         else
88         {
89             if(lcl_IsInvitationAllowed() && !config.getShowedInvitation())
90             {
91                 Reference<XCore> core(
92                     m_ServiceFactory->createInstance(OUString::createFromAscii("com.sun.star.oooimprovement.Core")),
93                     UNO_QUERY);
94                 if(core.is()) core->inviteUser();
95             }
96         }
97         Any result;
98         listener->jobFinished(Reference<XAsyncJob>(this), result);
99     }
100 
supportsService(const OUString & service_name)101     sal_Bool SAL_CALL InviteJob::supportsService(const OUString& service_name) throw(RuntimeException)
102     {
103         const Sequence<OUString> service_names(getSupportedServiceNames());
104         for (sal_Int32 idx = service_names.getLength()-1; idx>=0; --idx)
105             if(service_name == service_names[idx]) return sal_True;
106         return sal_False;
107     }
108 
getImplementationName()109     OUString SAL_CALL InviteJob::getImplementationName() throw(RuntimeException)
110     { return getImplementationName_static(); }
111 
getSupportedServiceNames()112     Sequence<OUString> SAL_CALL InviteJob::getSupportedServiceNames() throw(RuntimeException)
113     { return getSupportedServiceNames_static(); }
114 
getImplementationName_static()115     OUString SAL_CALL InviteJob::getImplementationName_static()
116     { return OUString::createFromAscii("com.sun.star.comp.extensions.oooimprovement.InviteJob"); }
117 
getSupportedServiceNames_static()118     Sequence<OUString> SAL_CALL InviteJob::getSupportedServiceNames_static()
119     {
120         Sequence<OUString> aServiceNames(1);
121         aServiceNames[0] = OUString::createFromAscii("com.sun.star.task.AsyncJob");
122         return aServiceNames;
123     }
124 
125 //    Reference<XInterface> InviteJob::Create(const Reference<XComponentContext>& context)
126 //    { return *(new InviteJob(context)); }
127 
Create(const Reference<XMultiServiceFactory> & sm)128     Reference<XInterface> InviteJob::Create(const Reference<XMultiServiceFactory>& sm)
129     { return *(new InviteJob(sm)); }
130 }
131