1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optimprove2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
40 #define _SVX_OPTIMPROVE_CXX
42 #include <svx/optimprove.hxx>
43 #include <svx/dialmgr.hxx>
44 #include <vcl/msgbox.hxx>
46 #include "optimprove.hrc"
48 #include <svx/dialogs.hrc>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/lang/XComponent.hpp>
52 #include <com/sun/star/oooimprovement/XCore.hpp>
53 #include <com/sun/star/oooimprovement/XCoreController.hpp>
54 #include <com/sun/star/system/XSystemShellExecute.hpp>
55 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
56 #include <com/sun/star/util/XStringSubstitution.hpp>
57 #include <comphelper/configurationhelper.hxx>
58 #include <comphelper/processfactory.hxx>
59 #include <comphelper/synchronousdispatch.hxx>
60 #include <comphelper/uieventslogger.hxx>
61 #include <tools/testtoolloader.hxx>
63 #define C2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
65 namespace beans
= ::com::sun::star::beans
;
66 namespace lang
= ::com::sun::star::lang
;
67 namespace uno
= ::com::sun::star::uno
;
68 namespace util
= ::com::sun::star::util
;
69 using namespace com::sun::star::system
;
71 // class SvxEmptyPage ----------------------------------------------------
73 SvxEmptyPage::SvxEmptyPage( Window
* pParent
) :
75 TabPage( pParent
, SVX_RES( RID_SVXPAGE_IMPROVEMENT
) )
81 // class SvxImprovementOptionsPage ---------------------------------------
83 SvxImprovementOptionsPage::SvxImprovementOptionsPage( Window
* pParent
, const SfxItemSet
& rSet
) :
85 SfxTabPage( pParent
, SVX_RES( RID_SVXPAGE_IMPROVEMENT
), rSet
),
87 m_aImproveFL ( this, SVX_RES( FL_IMPROVE
) ),
88 m_aInvitationFT ( this, SVX_RES( FT_INVITATION
) ),
89 m_aYesRB ( this, SVX_RES( RB_YES
) ),
90 m_aNoRB ( this, SVX_RES( RB_NO
) ),
91 m_aInfoFI ( this, SVX_RES( FI_INFO
) ),
92 m_aDataFL ( this, SVX_RES( FL_DATA
) ),
93 m_aNumberOfReportsFT ( this, SVX_RES( FT_NR_REPORTS
) ),
94 m_aNumberOfReportsValueFT ( this, SVX_RES( FT_NR_REPORTS_VALUE
) ),
95 m_aNumberOfActionsFT ( this, SVX_RES( FT_NR_ACTIONS
) ),
96 m_aNumberOfActionsValueFT ( this, SVX_RES( FT_NR_ACTIONS_VALUE
) ),
97 m_aShowDataPB ( this, SVX_RES( PB_SHOWDATA
) ),
99 m_sInfo ( SVX_RES( STR_INFO
) ),
100 m_sMoreInfo ( SVX_RES( STR_MOREINFO
) )
105 m_aInfoFI
.SetURL( C2S( "www.sun.com/privacy/" ) );
106 m_aInfoFI
.SetClickHdl( LINK( this, SvxImprovementOptionsPage
, HandleHyperlink
) );
107 m_aShowDataPB
.SetClickHdl( LINK( this, SvxImprovementOptionsPage
, HandleShowData
) );
110 SvxImprovementOptionsPage::~SvxImprovementOptionsPage()
114 IMPL_LINK( SvxImprovementOptionsPage
, HandleHyperlink
, svt::FixedHyperlinkImage
*, EMPTYARG
)
116 ::rtl::OUString
sURL( m_aInfoFI
.GetURL() );
118 if ( sURL
.getLength() > 0 )
122 uno::Reference
< lang::XMultiServiceFactory
> xSMGR
=
123 ::comphelper::getProcessServiceFactory();
124 uno::Reference
< XSystemShellExecute
> xSystemShell(
125 xSMGR
->createInstance( ::rtl::OUString(
126 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
127 uno::UNO_QUERY_THROW
);
128 if ( xSystemShell
.is() )
130 xSystemShell
->execute(
131 sURL
, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS
);
134 catch( const uno::Exception
& e
)
136 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
137 rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
144 IMPL_LINK( SvxImprovementOptionsPage
, HandleShowData
, PushButton
*, EMPTYARG
)
146 uno::Reference
< uno::XInterface
> xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
147 C2S("com.sun.star.frame.Desktop") ), uno::UNO_QUERY
);
150 ::rtl::OUString
sLogFile( m_sLogPath
);
151 sLogFile
+= C2S("/Current.csv");
152 uno::Sequence
< beans::PropertyValue
> aArgs
;
154 uno::Reference
< lang::XComponent
> xDoc
= ::comphelper::SynchronousDispatch::dispatch(
155 xDesktop
, sLogFile
, C2S("_default"), 0, aArgs
);
163 SfxTabPage
* SvxImprovementOptionsPage::Create( Window
* pParent
, const SfxItemSet
& rSet
)
165 return new SvxImprovementOptionsPage( pParent
, rSet
);
168 sal_uInt16
* SvxImprovementOptionsPage::GetRanges()
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() != FALSE
) );
187 ::comphelper::ConfigurationHelper::flush( xConfig
);
189 ::comphelper::UiEventsLogger::reinit();
190 ::tools::InitTestToolLib();
192 catch( uno::Exception
& )
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") ),
205 uno::Reference
< uno::XInterface
> xConfig
;
210 xConfig
= ::comphelper::ConfigurationHelper::openConfig(
211 xSMGR
, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
212 ::comphelper::ConfigurationHelper::E_READONLY
);
215 bool bYesChecked
= false;
216 uno::Any aAny
= ::comphelper::ConfigurationHelper::
217 readRelativeKey( xConfig
, C2S("Participation"), C2S("ShowedInvitation") );
218 if ( ( aAny
>>= bYesChecked
) && bYesChecked
)
221 aAny
= ::comphelper::ConfigurationHelper::
222 readRelativeKey( xConfig
, C2S("Participation"), C2S("InvitationAccepted") );
223 if ( aAny
>>= bTemp
)
225 bYesChecked
&= bTemp
;
231 ::rtl::OUString sURL
;
232 aAny
= ::comphelper::ConfigurationHelper::
233 readRelativeKey( xConfig
, C2S("Participation"), C2S("HelpUrl") );
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
)
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") ),
261 sPath
= xSubst
->substituteVariables( sPath
, sal_False
);
266 catch( uno::Exception
& )