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