xref: /aoo41x/main/cui/source/options/optimprove2.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #define _SVX_OPTIMPROVE_CXX
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <optimprove.hxx>
36*cdf0e10cSrcweir #include <dialmgr.hxx>
37*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "optimprove.hrc"
40*cdf0e10cSrcweir #include "helpid.hrc"
41*cdf0e10cSrcweir #include <cuires.hrc>
42*cdf0e10cSrcweir #include <svx/dialogs.hrc>
43*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/oooimprovement/XCore.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/oooimprovement/XCoreController.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/system/XSystemShellExecute.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
50*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
51*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52*cdf0e10cSrcweir #include <comphelper/synchronousdispatch.hxx>
53*cdf0e10cSrcweir #include <comphelper/uieventslogger.hxx>
54*cdf0e10cSrcweir #include <tools/testtoolloader.hxx>
55*cdf0e10cSrcweir #include <osl/file.hxx>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #define C2S(s)  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir namespace beans  = ::com::sun::star::beans;
60*cdf0e10cSrcweir namespace lang  = ::com::sun::star::lang;
61*cdf0e10cSrcweir namespace uno   = ::com::sun::star::uno;
62*cdf0e10cSrcweir namespace util  = ::com::sun::star::util;
63*cdf0e10cSrcweir using namespace com::sun::star::system;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir     bool lcl_doesLogfileExist(const ::rtl::OUString& sLogPath)
69*cdf0e10cSrcweir     {
70*cdf0e10cSrcweir         ::rtl::OUString sLogFile( sLogPath );
71*cdf0e10cSrcweir         sLogFile += C2S("/Current.csv");
72*cdf0e10cSrcweir         ::osl::File aLogFile(sLogFile);
73*cdf0e10cSrcweir         return aLogFile.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None;
74*cdf0e10cSrcweir     }
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir // class SvxImprovementOptionsPage ---------------------------------------
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir SvxImprovementOptionsPage::SvxImprovementOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_IMPROVEMENT ), rSet ),
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     m_aImproveFL                ( this, CUI_RES( FL_IMPROVE ) ),
84*cdf0e10cSrcweir     m_aInvitationFT             ( this, CUI_RES( FT_INVITATION ) ),
85*cdf0e10cSrcweir     m_aYesRB                    ( this, CUI_RES( RB_YES ) ),
86*cdf0e10cSrcweir     m_aNoRB                     ( this, CUI_RES( RB_NO ) ),
87*cdf0e10cSrcweir     m_aInfoFI                   ( this, CUI_RES( FI_INFO ) ),
88*cdf0e10cSrcweir     m_aDataFL                   ( this, CUI_RES( FL_DATA ) ),
89*cdf0e10cSrcweir     m_aNumberOfReportsFT        ( this, CUI_RES( FT_NR_REPORTS ) ),
90*cdf0e10cSrcweir     m_aNumberOfReportsValueFT   ( this, CUI_RES( FT_NR_REPORTS_VALUE ) ),
91*cdf0e10cSrcweir     m_aNumberOfActionsFT        ( this, CUI_RES( FT_NR_ACTIONS ) ),
92*cdf0e10cSrcweir     m_aNumberOfActionsValueFT   ( this, CUI_RES( FT_NR_ACTIONS_VALUE ) ),
93*cdf0e10cSrcweir     m_aShowDataPB               ( this, CUI_RES( PB_SHOWDATA ) ),
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     m_sInfo                     (       CUI_RES( STR_INFO ) ),
96*cdf0e10cSrcweir     m_sMoreInfo                 (       CUI_RES( STR_MOREINFO ) )
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     FreeResource();
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     m_aInfoFI.SetURL( C2S( "www.sun.com/privacy/" ) );
102*cdf0e10cSrcweir     m_aInfoFI.SetClickHdl( LINK( this, SvxImprovementOptionsPage, HandleHyperlink ) );
103*cdf0e10cSrcweir     m_aShowDataPB.SetClickHdl( LINK( this, SvxImprovementOptionsPage, HandleShowData ) );
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir SvxImprovementOptionsPage::~SvxImprovementOptionsPage()
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir IMPL_LINK( SvxImprovementOptionsPage, HandleHyperlink, svt::FixedHyperlinkImage*, EMPTYARG )
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     ::rtl::OUString sURL( m_aInfoFI.GetURL() );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     if ( sURL.getLength() > 0 )
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir         try
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xSMGR =
119*cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory();
120*cdf0e10cSrcweir             uno::Reference< XSystemShellExecute > xSystemShell(
121*cdf0e10cSrcweir                 xSMGR->createInstance( ::rtl::OUString(
122*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
123*cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
124*cdf0e10cSrcweir             if ( xSystemShell.is() )
125*cdf0e10cSrcweir             {
126*cdf0e10cSrcweir                 xSystemShell->execute(
127*cdf0e10cSrcweir                     sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
128*cdf0e10cSrcweir             }
129*cdf0e10cSrcweir         }
130*cdf0e10cSrcweir         catch( const uno::Exception& e )
131*cdf0e10cSrcweir         {
132*cdf0e10cSrcweir              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
133*cdf0e10cSrcweir                 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
134*cdf0e10cSrcweir         }
135*cdf0e10cSrcweir     }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     return 0;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir IMPL_LINK( SvxImprovementOptionsPage, HandleShowData, PushButton*, EMPTYARG )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     uno::Reference < uno::XInterface > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
143*cdf0e10cSrcweir         C2S("com.sun.star.frame.Desktop") ), uno::UNO_QUERY );
144*cdf0e10cSrcweir     if ( xDesktop.is() )
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         ::rtl::OUString sLogFile( m_sLogPath );
147*cdf0e10cSrcweir         sLogFile += C2S("/Current.csv");
148*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aArgs(3);
149*cdf0e10cSrcweir 		aArgs[0].Name = ::rtl::OUString::createFromAscii("FilterName");
150*cdf0e10cSrcweir 		aArgs[0].Value = uno::makeAny(::rtl::OUString::createFromAscii("Text - txt - csv (StarCalc)"));
151*cdf0e10cSrcweir 		aArgs[1].Name = ::rtl::OUString::createFromAscii("FilterOptions");
152*cdf0e10cSrcweir 		aArgs[1].Value = uno::makeAny(::rtl::OUString::createFromAscii("44,34,12,1,"));
153*cdf0e10cSrcweir 		aArgs[2].Name = ::rtl::OUString::createFromAscii("ReadOnly");
154*cdf0e10cSrcweir 		aArgs[2].Value = uno::makeAny(true);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         uno::Reference< lang::XComponent > xDoc = ::comphelper::SynchronousDispatch::dispatch(
157*cdf0e10cSrcweir             xDesktop, sLogFile, C2S("_default"), 0, aArgs );
158*cdf0e10cSrcweir         if ( xDoc.is() )
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             dynamic_cast<Dialog*>(GetParent())->EndDialog( RET_CANCEL );
161*cdf0e10cSrcweir             return 1;
162*cdf0e10cSrcweir         }
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     return 0;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir SfxTabPage* SvxImprovementOptionsPage::Create( Window* pParent, const SfxItemSet& rSet )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     return new SvxImprovementOptionsPage( pParent, rSet );
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir sal_Bool SvxImprovementOptionsPage::FillItemSet( SfxItemSet& /*rSet*/ )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
176*cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfig;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     try
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         xConfig = ::comphelper::ConfigurationHelper::openConfig(
181*cdf0e10cSrcweir             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
182*cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::E_STANDARD );
183*cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::writeRelativeKey(
184*cdf0e10cSrcweir             xConfig, C2S("Participation"), C2S("ShowedInvitation"), uno::makeAny( true ) );
185*cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::writeRelativeKey(
186*cdf0e10cSrcweir             xConfig, C2S("Participation"), C2S("InvitationAccepted"), uno::makeAny( m_aYesRB.IsChecked() != sal_False ) );
187*cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::flush( xConfig );
188*cdf0e10cSrcweir         // TODO: refactor
189*cdf0e10cSrcweir         ::comphelper::UiEventsLogger::reinit();
190*cdf0e10cSrcweir         ::tools::InitTestToolLib();
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir     catch( uno::Exception& )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     return sal_False;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void SvxImprovementOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
202*cdf0e10cSrcweir     uno::Reference< com::sun::star::oooimprovement::XCore > xCore(
203*cdf0e10cSrcweir         xSMGR->createInstance( C2S("com.sun.star.oooimprovement.Core") ),
204*cdf0e10cSrcweir         uno::UNO_QUERY );
205*cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfig;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     try
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         m_aNoRB.Check();
210*cdf0e10cSrcweir         xConfig = ::comphelper::ConfigurationHelper::openConfig(
211*cdf0e10cSrcweir             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
212*cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::E_READONLY );
213*cdf0e10cSrcweir         if ( xConfig.is() )
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             bool bYesChecked = false;
216*cdf0e10cSrcweir             uno::Any aAny = ::comphelper::ConfigurationHelper::
217*cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Participation"), C2S("ShowedInvitation") );
218*cdf0e10cSrcweir             if ( ( aAny >>= bYesChecked ) && bYesChecked )
219*cdf0e10cSrcweir             {
220*cdf0e10cSrcweir                 bool bTemp = false;
221*cdf0e10cSrcweir                 aAny = ::comphelper::ConfigurationHelper::
222*cdf0e10cSrcweir                     readRelativeKey( xConfig, C2S("Participation"), C2S("InvitationAccepted") );
223*cdf0e10cSrcweir                 if ( aAny >>= bTemp )
224*cdf0e10cSrcweir                 {
225*cdf0e10cSrcweir                     bYesChecked &= bTemp;
226*cdf0e10cSrcweir                     if ( bYesChecked )
227*cdf0e10cSrcweir                         m_aYesRB.Check();
228*cdf0e10cSrcweir                 }
229*cdf0e10cSrcweir             }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir             ::rtl::OUString sURL;
232*cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
233*cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Participation"), C2S("HelpUrl") );
234*cdf0e10cSrcweir             if ( aAny >>= sURL )
235*cdf0e10cSrcweir                 m_aInfoFI.SetURL( sURL );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir             sal_Int32 nCount = 0;
238*cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
239*cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Counters"), C2S("UploadedReports") );
240*cdf0e10cSrcweir             if ( aAny >>= nCount )
241*cdf0e10cSrcweir                 m_aNumberOfReportsValueFT.SetText( String::CreateFromInt32( nCount ) );
242*cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
243*cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Counters"), C2S("LoggedEvents") );
244*cdf0e10cSrcweir             if ( aAny >>= nCount )
245*cdf0e10cSrcweir             {
246*cdf0e10cSrcweir                 if ( xCore.is() )
247*cdf0e10cSrcweir                     nCount += xCore->getSessionLogEventCount();
248*cdf0e10cSrcweir                 m_aNumberOfActionsValueFT.SetText( String::CreateFromInt32( nCount ) );
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir             ::rtl::OUString sPath;
252*cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::readDirectKey(
253*cdf0e10cSrcweir                 xSMGR, C2S("/org.openoffice.Office.Logging"), C2S("OOoImprovement"),
254*cdf0e10cSrcweir                 C2S("LogPath"), ::comphelper::ConfigurationHelper::E_READONLY );
255*cdf0e10cSrcweir             if ( aAny >>= sPath )
256*cdf0e10cSrcweir             {
257*cdf0e10cSrcweir                 uno::Reference< util::XStringSubstitution > xSubst(
258*cdf0e10cSrcweir                     xSMGR->createInstance( C2S("com.sun.star.util.PathSubstitution") ),
259*cdf0e10cSrcweir                     uno::UNO_QUERY );
260*cdf0e10cSrcweir                 if ( xSubst.is() )
261*cdf0e10cSrcweir                     sPath = xSubst->substituteVariables( sPath, sal_False );
262*cdf0e10cSrcweir                 m_sLogPath = sPath;
263*cdf0e10cSrcweir                 m_aShowDataPB.Enable(lcl_doesLogfileExist(m_sLogPath));
264*cdf0e10cSrcweir             }
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir     catch( uno::Exception& )
268*cdf0e10cSrcweir     {
269*cdf0e10cSrcweir         m_aShowDataPB.Enable(false);
270*cdf0e10cSrcweir     }
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273