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