xref: /AOO41X/main/cui/source/options/optimprove2.cxx (revision 2ee96f1cdb99d49425d866b1ec4c5567f37285e6)
1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2ee96f1cSAndrew Rist  * distributed with this work for additional information
6*2ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2ee96f1cSAndrew Rist  * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2ee96f1cSAndrew Rist  *************************************************************/
21*2ee96f1cSAndrew Rist 
22*2ee96f1cSAndrew 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>
43cdf0e10cSrcweir #include <com/sun/star/system/XSystemShellExecute.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< lang::XMultiServiceFactory > xSMGR =
115cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory();
116cdf0e10cSrcweir             uno::Reference< XSystemShellExecute > xSystemShell(
117cdf0e10cSrcweir                 xSMGR->createInstance( ::rtl::OUString(
118cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
119cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
120cdf0e10cSrcweir             if ( xSystemShell.is() )
121cdf0e10cSrcweir             {
122cdf0e10cSrcweir                 xSystemShell->execute(
123cdf0e10cSrcweir                     sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir         catch( const uno::Exception& e )
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
129cdf0e10cSrcweir                 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     return 0;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir IMPL_LINK( SvxImprovementOptionsPage, HandleShowData, PushButton*, EMPTYARG )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     uno::Reference < uno::XInterface > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
139cdf0e10cSrcweir         C2S("com.sun.star.frame.Desktop") ), uno::UNO_QUERY );
140cdf0e10cSrcweir     if ( xDesktop.is() )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         ::rtl::OUString sLogFile( m_sLogPath );
143cdf0e10cSrcweir         sLogFile += C2S("/Current.csv");
144cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aArgs(3);
145cdf0e10cSrcweir 		aArgs[0].Name = ::rtl::OUString::createFromAscii("FilterName");
146cdf0e10cSrcweir 		aArgs[0].Value = uno::makeAny(::rtl::OUString::createFromAscii("Text - txt - csv (StarCalc)"));
147cdf0e10cSrcweir 		aArgs[1].Name = ::rtl::OUString::createFromAscii("FilterOptions");
148cdf0e10cSrcweir 		aArgs[1].Value = uno::makeAny(::rtl::OUString::createFromAscii("44,34,12,1,"));
149cdf0e10cSrcweir 		aArgs[2].Name = ::rtl::OUString::createFromAscii("ReadOnly");
150cdf0e10cSrcweir 		aArgs[2].Value = uno::makeAny(true);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         uno::Reference< lang::XComponent > xDoc = ::comphelper::SynchronousDispatch::dispatch(
153cdf0e10cSrcweir             xDesktop, sLogFile, C2S("_default"), 0, aArgs );
154cdf0e10cSrcweir         if ( xDoc.is() )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             dynamic_cast<Dialog*>(GetParent())->EndDialog( RET_CANCEL );
157cdf0e10cSrcweir             return 1;
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     return 0;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir SfxTabPage* SvxImprovementOptionsPage::Create( Window* pParent, const SfxItemSet& rSet )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     return new SvxImprovementOptionsPage( pParent, rSet );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir sal_Bool SvxImprovementOptionsPage::FillItemSet( SfxItemSet& /*rSet*/ )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
172cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfig;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     try
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         xConfig = ::comphelper::ConfigurationHelper::openConfig(
177cdf0e10cSrcweir             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
178cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::E_STANDARD );
179cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::writeRelativeKey(
180cdf0e10cSrcweir             xConfig, C2S("Participation"), C2S("ShowedInvitation"), uno::makeAny( true ) );
181cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::writeRelativeKey(
182cdf0e10cSrcweir             xConfig, C2S("Participation"), C2S("InvitationAccepted"), uno::makeAny( m_aYesRB.IsChecked() != sal_False ) );
183cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::flush( xConfig );
184cdf0e10cSrcweir         // TODO: refactor
185cdf0e10cSrcweir         ::comphelper::UiEventsLogger::reinit();
186cdf0e10cSrcweir         ::tools::InitTestToolLib();
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir     catch( uno::Exception& )
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     return sal_False;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir void SvxImprovementOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
198cdf0e10cSrcweir     uno::Reference< com::sun::star::oooimprovement::XCore > xCore(
199cdf0e10cSrcweir         xSMGR->createInstance( C2S("com.sun.star.oooimprovement.Core") ),
200cdf0e10cSrcweir         uno::UNO_QUERY );
201cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfig;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     try
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         m_aNoRB.Check();
206cdf0e10cSrcweir         xConfig = ::comphelper::ConfigurationHelper::openConfig(
207cdf0e10cSrcweir             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
208cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::E_READONLY );
209cdf0e10cSrcweir         if ( xConfig.is() )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             bool bYesChecked = false;
212cdf0e10cSrcweir             uno::Any aAny = ::comphelper::ConfigurationHelper::
213cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Participation"), C2S("ShowedInvitation") );
214cdf0e10cSrcweir             if ( ( aAny >>= bYesChecked ) && bYesChecked )
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 bool bTemp = false;
217cdf0e10cSrcweir                 aAny = ::comphelper::ConfigurationHelper::
218cdf0e10cSrcweir                     readRelativeKey( xConfig, C2S("Participation"), C2S("InvitationAccepted") );
219cdf0e10cSrcweir                 if ( aAny >>= bTemp )
220cdf0e10cSrcweir                 {
221cdf0e10cSrcweir                     bYesChecked &= bTemp;
222cdf0e10cSrcweir                     if ( bYesChecked )
223cdf0e10cSrcweir                         m_aYesRB.Check();
224cdf0e10cSrcweir                 }
225cdf0e10cSrcweir             }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir             ::rtl::OUString sURL;
228cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
229cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Participation"), C2S("HelpUrl") );
230cdf0e10cSrcweir             if ( aAny >>= sURL )
231cdf0e10cSrcweir                 m_aInfoFI.SetURL( sURL );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir             sal_Int32 nCount = 0;
234cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
235cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Counters"), C2S("UploadedReports") );
236cdf0e10cSrcweir             if ( aAny >>= nCount )
237cdf0e10cSrcweir                 m_aNumberOfReportsValueFT.SetText( String::CreateFromInt32( nCount ) );
238cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::
239cdf0e10cSrcweir                 readRelativeKey( xConfig, C2S("Counters"), C2S("LoggedEvents") );
240cdf0e10cSrcweir             if ( aAny >>= nCount )
241cdf0e10cSrcweir             {
242cdf0e10cSrcweir                 if ( xCore.is() )
243cdf0e10cSrcweir                     nCount += xCore->getSessionLogEventCount();
244cdf0e10cSrcweir                 m_aNumberOfActionsValueFT.SetText( String::CreateFromInt32( nCount ) );
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir             ::rtl::OUString sPath;
248cdf0e10cSrcweir             aAny = ::comphelper::ConfigurationHelper::readDirectKey(
249cdf0e10cSrcweir                 xSMGR, C2S("/org.openoffice.Office.Logging"), C2S("OOoImprovement"),
250cdf0e10cSrcweir                 C2S("LogPath"), ::comphelper::ConfigurationHelper::E_READONLY );
251cdf0e10cSrcweir             if ( aAny >>= sPath )
252cdf0e10cSrcweir             {
253cdf0e10cSrcweir                 uno::Reference< util::XStringSubstitution > xSubst(
254cdf0e10cSrcweir                     xSMGR->createInstance( C2S("com.sun.star.util.PathSubstitution") ),
255cdf0e10cSrcweir                     uno::UNO_QUERY );
256cdf0e10cSrcweir                 if ( xSubst.is() )
257cdf0e10cSrcweir                     sPath = xSubst->substituteVariables( sPath, sal_False );
258cdf0e10cSrcweir                 m_sLogPath = sPath;
259cdf0e10cSrcweir                 m_aShowDataPB.Enable(lcl_doesLogfileExist(m_sLogPath));
260cdf0e10cSrcweir             }
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir     catch( uno::Exception& )
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         m_aShowDataPB.Enable(false);
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269