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