12ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 52ee96f1cSAndrew Rist * distributed with this work for additional information 62ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 82ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 92ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 112ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 132ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 142ee96f1cSAndrew Rist * software distributed under the License is distributed on an 152ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 172ee96f1cSAndrew Rist * specific language governing permissions and limitations 182ee96f1cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 202ee96f1cSAndrew Rist *************************************************************/ 212ee96f1cSAndrew Rist 222ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include --------------------------------------------------------------- 28cdf0e10cSrcweir 29cdf0e10cSrcweir #define _SVX_OPTIMPROVE_CXX 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <optimprove.hxx> 32cdf0e10cSrcweir #include <dialmgr.hxx> 33cdf0e10cSrcweir #include <vcl/msgbox.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include "optimprove.hrc" 36cdf0e10cSrcweir #include "helpid.hrc" 37cdf0e10cSrcweir #include <cuires.hrc> 38cdf0e10cSrcweir #include <svx/dialogs.hrc> 39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 40cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 41cdf0e10cSrcweir #include <com/sun/star/oooimprovement/XCore.hpp> 42cdf0e10cSrcweir #include <com/sun/star/oooimprovement/XCoreController.hpp> 43*9807c9deSAriel Constenla-Haile #include <com/sun/star/system/SystemShellExecute.hpp> 44cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 45cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp> 46cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 47cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 48cdf0e10cSrcweir #include <comphelper/synchronousdispatch.hxx> 49cdf0e10cSrcweir #include <comphelper/uieventslogger.hxx> 50cdf0e10cSrcweir #include <tools/testtoolloader.hxx> 51cdf0e10cSrcweir #include <osl/file.hxx> 52cdf0e10cSrcweir 53cdf0e10cSrcweir #define C2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 54cdf0e10cSrcweir 55cdf0e10cSrcweir namespace beans = ::com::sun::star::beans; 56cdf0e10cSrcweir namespace lang = ::com::sun::star::lang; 57cdf0e10cSrcweir namespace uno = ::com::sun::star::uno; 58cdf0e10cSrcweir namespace util = ::com::sun::star::util; 59cdf0e10cSrcweir using namespace com::sun::star::system; 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir namespace 63cdf0e10cSrcweir { 64cdf0e10cSrcweir bool lcl_doesLogfileExist(const ::rtl::OUString& sLogPath) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir ::rtl::OUString sLogFile( sLogPath ); 67cdf0e10cSrcweir sLogFile += C2S("/Current.csv"); 68cdf0e10cSrcweir ::osl::File aLogFile(sLogFile); 69cdf0e10cSrcweir return aLogFile.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // class SvxImprovementOptionsPage --------------------------------------- 74cdf0e10cSrcweir 75cdf0e10cSrcweir SvxImprovementOptionsPage::SvxImprovementOptionsPage( Window* pParent, const SfxItemSet& rSet ) : 76cdf0e10cSrcweir 77cdf0e10cSrcweir SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_IMPROVEMENT ), rSet ), 78cdf0e10cSrcweir 79cdf0e10cSrcweir m_aImproveFL ( this, CUI_RES( FL_IMPROVE ) ), 80cdf0e10cSrcweir m_aInvitationFT ( this, CUI_RES( FT_INVITATION ) ), 81cdf0e10cSrcweir m_aYesRB ( this, CUI_RES( RB_YES ) ), 82cdf0e10cSrcweir m_aNoRB ( this, CUI_RES( RB_NO ) ), 83cdf0e10cSrcweir m_aInfoFI ( this, CUI_RES( FI_INFO ) ), 84cdf0e10cSrcweir m_aDataFL ( this, CUI_RES( FL_DATA ) ), 85cdf0e10cSrcweir m_aNumberOfReportsFT ( this, CUI_RES( FT_NR_REPORTS ) ), 86cdf0e10cSrcweir m_aNumberOfReportsValueFT ( this, CUI_RES( FT_NR_REPORTS_VALUE ) ), 87cdf0e10cSrcweir m_aNumberOfActionsFT ( this, CUI_RES( FT_NR_ACTIONS ) ), 88cdf0e10cSrcweir m_aNumberOfActionsValueFT ( this, CUI_RES( FT_NR_ACTIONS_VALUE ) ), 89cdf0e10cSrcweir m_aShowDataPB ( this, CUI_RES( PB_SHOWDATA ) ), 90cdf0e10cSrcweir 91cdf0e10cSrcweir m_sInfo ( CUI_RES( STR_INFO ) ), 92cdf0e10cSrcweir m_sMoreInfo ( CUI_RES( STR_MOREINFO ) ) 93cdf0e10cSrcweir 94cdf0e10cSrcweir { 95cdf0e10cSrcweir FreeResource(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir m_aInfoFI.SetURL( C2S( "www.sun.com/privacy/" ) ); 98cdf0e10cSrcweir m_aInfoFI.SetClickHdl( LINK( this, SvxImprovementOptionsPage, HandleHyperlink ) ); 99cdf0e10cSrcweir m_aShowDataPB.SetClickHdl( LINK( this, SvxImprovementOptionsPage, HandleShowData ) ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir SvxImprovementOptionsPage::~SvxImprovementOptionsPage() 103cdf0e10cSrcweir { 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir IMPL_LINK( SvxImprovementOptionsPage, HandleHyperlink, svt::FixedHyperlinkImage*, EMPTYARG ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir ::rtl::OUString sURL( m_aInfoFI.GetURL() ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir if ( sURL.getLength() > 0 ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir try 113cdf0e10cSrcweir { 114cdf0e10cSrcweir uno::Reference< XSystemShellExecute > xSystemShell( 115*9807c9deSAriel Constenla-Haile com::sun::star::system::SystemShellExecute::create( 116*9807c9deSAriel Constenla-Haile ::comphelper::getProcessComponentContext() ) ); 117cdf0e10cSrcweir if ( xSystemShell.is() ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir xSystemShell->execute( 120cdf0e10cSrcweir sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch( const uno::Exception& e ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir OSL_TRACE( "Caught exception: %s\n thread terminated.\n", 126cdf0e10cSrcweir rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir return 0; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir IMPL_LINK( SvxImprovementOptionsPage, HandleShowData, PushButton*, EMPTYARG ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir uno::Reference < uno::XInterface > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( 136cdf0e10cSrcweir C2S("com.sun.star.frame.Desktop") ), uno::UNO_QUERY ); 137cdf0e10cSrcweir if ( xDesktop.is() ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir ::rtl::OUString sLogFile( m_sLogPath ); 140cdf0e10cSrcweir sLogFile += C2S("/Current.csv"); 141cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs(3); 142cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii("FilterName"); 143cdf0e10cSrcweir aArgs[0].Value = uno::makeAny(::rtl::OUString::createFromAscii("Text - txt - csv (StarCalc)")); 144cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii("FilterOptions"); 145cdf0e10cSrcweir aArgs[1].Value = uno::makeAny(::rtl::OUString::createFromAscii("44,34,12,1,")); 146cdf0e10cSrcweir aArgs[2].Name = ::rtl::OUString::createFromAscii("ReadOnly"); 147cdf0e10cSrcweir aArgs[2].Value = uno::makeAny(true); 148cdf0e10cSrcweir 149cdf0e10cSrcweir uno::Reference< lang::XComponent > xDoc = ::comphelper::SynchronousDispatch::dispatch( 150cdf0e10cSrcweir xDesktop, sLogFile, C2S("_default"), 0, aArgs ); 151cdf0e10cSrcweir if ( xDoc.is() ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir dynamic_cast<Dialog*>(GetParent())->EndDialog( RET_CANCEL ); 154cdf0e10cSrcweir return 1; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir return 0; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir SfxTabPage* SvxImprovementOptionsPage::Create( Window* pParent, const SfxItemSet& rSet ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir return new SvxImprovementOptionsPage( pParent, rSet ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir sal_Bool SvxImprovementOptionsPage::FillItemSet( SfxItemSet& /*rSet*/ ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 169cdf0e10cSrcweir uno::Reference< uno::XInterface > xConfig; 170cdf0e10cSrcweir 171cdf0e10cSrcweir try 172cdf0e10cSrcweir { 173cdf0e10cSrcweir xConfig = ::comphelper::ConfigurationHelper::openConfig( 174cdf0e10cSrcweir xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"), 175cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD ); 176cdf0e10cSrcweir ::comphelper::ConfigurationHelper::writeRelativeKey( 177cdf0e10cSrcweir xConfig, C2S("Participation"), C2S("ShowedInvitation"), uno::makeAny( true ) ); 178cdf0e10cSrcweir ::comphelper::ConfigurationHelper::writeRelativeKey( 179cdf0e10cSrcweir xConfig, C2S("Participation"), C2S("InvitationAccepted"), uno::makeAny( m_aYesRB.IsChecked() != sal_False ) ); 180cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush( xConfig ); 181cdf0e10cSrcweir // TODO: refactor 182cdf0e10cSrcweir ::comphelper::UiEventsLogger::reinit(); 183cdf0e10cSrcweir ::tools::InitTestToolLib(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir catch( uno::Exception& ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir return sal_False; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir void SvxImprovementOptionsPage::Reset( const SfxItemSet& /*rSet*/ ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 195cdf0e10cSrcweir uno::Reference< com::sun::star::oooimprovement::XCore > xCore( 196cdf0e10cSrcweir xSMGR->createInstance( C2S("com.sun.star.oooimprovement.Core") ), 197cdf0e10cSrcweir uno::UNO_QUERY ); 198cdf0e10cSrcweir uno::Reference< uno::XInterface > xConfig; 199cdf0e10cSrcweir 200cdf0e10cSrcweir try 201cdf0e10cSrcweir { 202cdf0e10cSrcweir m_aNoRB.Check(); 203cdf0e10cSrcweir xConfig = ::comphelper::ConfigurationHelper::openConfig( 204cdf0e10cSrcweir xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"), 205cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY ); 206cdf0e10cSrcweir if ( xConfig.is() ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir bool bYesChecked = false; 209cdf0e10cSrcweir uno::Any aAny = ::comphelper::ConfigurationHelper:: 210cdf0e10cSrcweir readRelativeKey( xConfig, C2S("Participation"), C2S("ShowedInvitation") ); 211cdf0e10cSrcweir if ( ( aAny >>= bYesChecked ) && bYesChecked ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir bool bTemp = false; 214cdf0e10cSrcweir aAny = ::comphelper::ConfigurationHelper:: 215cdf0e10cSrcweir readRelativeKey( xConfig, C2S("Participation"), C2S("InvitationAccepted") ); 216cdf0e10cSrcweir if ( aAny >>= bTemp ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir bYesChecked &= bTemp; 219cdf0e10cSrcweir if ( bYesChecked ) 220cdf0e10cSrcweir m_aYesRB.Check(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir ::rtl::OUString sURL; 225cdf0e10cSrcweir aAny = ::comphelper::ConfigurationHelper:: 226cdf0e10cSrcweir readRelativeKey( xConfig, C2S("Participation"), C2S("HelpUrl") ); 227cdf0e10cSrcweir if ( aAny >>= sURL ) 228cdf0e10cSrcweir m_aInfoFI.SetURL( sURL ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir sal_Int32 nCount = 0; 231cdf0e10cSrcweir aAny = ::comphelper::ConfigurationHelper:: 232cdf0e10cSrcweir readRelativeKey( xConfig, C2S("Counters"), C2S("UploadedReports") ); 233cdf0e10cSrcweir if ( aAny >>= nCount ) 234cdf0e10cSrcweir m_aNumberOfReportsValueFT.SetText( String::CreateFromInt32( nCount ) ); 235cdf0e10cSrcweir aAny = ::comphelper::ConfigurationHelper:: 236cdf0e10cSrcweir readRelativeKey( xConfig, C2S("Counters"), C2S("LoggedEvents") ); 237cdf0e10cSrcweir if ( aAny >>= nCount ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if ( xCore.is() ) 240cdf0e10cSrcweir nCount += xCore->getSessionLogEventCount(); 241cdf0e10cSrcweir m_aNumberOfActionsValueFT.SetText( String::CreateFromInt32( nCount ) ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir ::rtl::OUString sPath; 245cdf0e10cSrcweir aAny = ::comphelper::ConfigurationHelper::readDirectKey( 246cdf0e10cSrcweir xSMGR, C2S("/org.openoffice.Office.Logging"), C2S("OOoImprovement"), 247cdf0e10cSrcweir C2S("LogPath"), ::comphelper::ConfigurationHelper::E_READONLY ); 248cdf0e10cSrcweir if ( aAny >>= sPath ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir uno::Reference< util::XStringSubstitution > xSubst( 251cdf0e10cSrcweir xSMGR->createInstance( C2S("com.sun.star.util.PathSubstitution") ), 252cdf0e10cSrcweir uno::UNO_QUERY ); 253cdf0e10cSrcweir if ( xSubst.is() ) 254cdf0e10cSrcweir sPath = xSubst->substituteVariables( sPath, sal_False ); 255cdf0e10cSrcweir m_sLogPath = sPath; 256cdf0e10cSrcweir m_aShowDataPB.Enable(lcl_doesLogfileExist(m_sLogPath)); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir catch( uno::Exception& ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir m_aShowDataPB.Enable(false); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266