xref: /aoo41x/main/cui/source/options/optimprove2.cxx (revision 9807c9de)
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/SystemShellExecute.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 {
lcl_doesLogfileExist(const::rtl::OUString & sLogPath)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 
SvxImprovementOptionsPage(Window * pParent,const SfxItemSet & rSet)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 
~SvxImprovementOptionsPage()102 SvxImprovementOptionsPage::~SvxImprovementOptionsPage()
103 {
104 }
105 
IMPL_LINK(SvxImprovementOptionsPage,HandleHyperlink,svt::FixedHyperlinkImage *,EMPTYARG)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< XSystemShellExecute > xSystemShell(
115                 com::sun::star::system::SystemShellExecute::create(
116                     ::comphelper::getProcessComponentContext() ) );
117             if ( xSystemShell.is() )
118             {
119                 xSystemShell->execute(
120                     sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
121             }
122         }
123         catch( const uno::Exception& e )
124         {
125              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
126                 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
127         }
128     }
129 
130     return 0;
131 }
132 
IMPL_LINK(SvxImprovementOptionsPage,HandleShowData,PushButton *,EMPTYARG)133 IMPL_LINK( SvxImprovementOptionsPage, HandleShowData, PushButton*, EMPTYARG )
134 {
135     uno::Reference < uno::XInterface > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
136         C2S("com.sun.star.frame.Desktop") ), uno::UNO_QUERY );
137     if ( xDesktop.is() )
138     {
139         ::rtl::OUString sLogFile( m_sLogPath );
140         sLogFile += C2S("/Current.csv");
141         uno::Sequence< beans::PropertyValue > aArgs(3);
142 		aArgs[0].Name = ::rtl::OUString::createFromAscii("FilterName");
143 		aArgs[0].Value = uno::makeAny(::rtl::OUString::createFromAscii("Text - txt - csv (StarCalc)"));
144 		aArgs[1].Name = ::rtl::OUString::createFromAscii("FilterOptions");
145 		aArgs[1].Value = uno::makeAny(::rtl::OUString::createFromAscii("44,34,12,1,"));
146 		aArgs[2].Name = ::rtl::OUString::createFromAscii("ReadOnly");
147 		aArgs[2].Value = uno::makeAny(true);
148 
149         uno::Reference< lang::XComponent > xDoc = ::comphelper::SynchronousDispatch::dispatch(
150             xDesktop, sLogFile, C2S("_default"), 0, aArgs );
151         if ( xDoc.is() )
152         {
153             dynamic_cast<Dialog*>(GetParent())->EndDialog( RET_CANCEL );
154             return 1;
155         }
156     }
157 
158     return 0;
159 }
160 
Create(Window * pParent,const SfxItemSet & rSet)161 SfxTabPage* SvxImprovementOptionsPage::Create( Window* pParent, const SfxItemSet& rSet )
162 {
163     return new SvxImprovementOptionsPage( pParent, rSet );
164 }
165 
FillItemSet(SfxItemSet &)166 sal_Bool SvxImprovementOptionsPage::FillItemSet( SfxItemSet& /*rSet*/ )
167 {
168     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
169     uno::Reference< uno::XInterface > xConfig;
170 
171     try
172     {
173         xConfig = ::comphelper::ConfigurationHelper::openConfig(
174             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
175             ::comphelper::ConfigurationHelper::E_STANDARD );
176         ::comphelper::ConfigurationHelper::writeRelativeKey(
177             xConfig, C2S("Participation"), C2S("ShowedInvitation"), uno::makeAny( true ) );
178         ::comphelper::ConfigurationHelper::writeRelativeKey(
179             xConfig, C2S("Participation"), C2S("InvitationAccepted"), uno::makeAny( m_aYesRB.IsChecked() != sal_False ) );
180         ::comphelper::ConfigurationHelper::flush( xConfig );
181         // TODO: refactor
182         ::comphelper::UiEventsLogger::reinit();
183         ::tools::InitTestToolLib();
184     }
185     catch( uno::Exception& )
186     {
187     }
188 
189     return sal_False;
190 }
191 
Reset(const SfxItemSet &)192 void SvxImprovementOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
193 {
194     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
195     uno::Reference< com::sun::star::oooimprovement::XCore > xCore(
196         xSMGR->createInstance( C2S("com.sun.star.oooimprovement.Core") ),
197         uno::UNO_QUERY );
198     uno::Reference< uno::XInterface > xConfig;
199 
200     try
201     {
202         m_aNoRB.Check();
203         xConfig = ::comphelper::ConfigurationHelper::openConfig(
204             xSMGR, C2S("/org.openoffice.Office.OOoImprovement.Settings"),
205             ::comphelper::ConfigurationHelper::E_READONLY );
206         if ( xConfig.is() )
207         {
208             bool bYesChecked = false;
209             uno::Any aAny = ::comphelper::ConfigurationHelper::
210                 readRelativeKey( xConfig, C2S("Participation"), C2S("ShowedInvitation") );
211             if ( ( aAny >>= bYesChecked ) && bYesChecked )
212             {
213                 bool bTemp = false;
214                 aAny = ::comphelper::ConfigurationHelper::
215                     readRelativeKey( xConfig, C2S("Participation"), C2S("InvitationAccepted") );
216                 if ( aAny >>= bTemp )
217                 {
218                     bYesChecked &= bTemp;
219                     if ( bYesChecked )
220                         m_aYesRB.Check();
221                 }
222             }
223 
224             ::rtl::OUString sURL;
225             aAny = ::comphelper::ConfigurationHelper::
226                 readRelativeKey( xConfig, C2S("Participation"), C2S("HelpUrl") );
227             if ( aAny >>= sURL )
228                 m_aInfoFI.SetURL( sURL );
229 
230             sal_Int32 nCount = 0;
231             aAny = ::comphelper::ConfigurationHelper::
232                 readRelativeKey( xConfig, C2S("Counters"), C2S("UploadedReports") );
233             if ( aAny >>= nCount )
234                 m_aNumberOfReportsValueFT.SetText( String::CreateFromInt32( nCount ) );
235             aAny = ::comphelper::ConfigurationHelper::
236                 readRelativeKey( xConfig, C2S("Counters"), C2S("LoggedEvents") );
237             if ( aAny >>= nCount )
238             {
239                 if ( xCore.is() )
240                     nCount += xCore->getSessionLogEventCount();
241                 m_aNumberOfActionsValueFT.SetText( String::CreateFromInt32( nCount ) );
242             }
243 
244             ::rtl::OUString sPath;
245             aAny = ::comphelper::ConfigurationHelper::readDirectKey(
246                 xSMGR, C2S("/org.openoffice.Office.Logging"), C2S("OOoImprovement"),
247                 C2S("LogPath"), ::comphelper::ConfigurationHelper::E_READONLY );
248             if ( aAny >>= sPath )
249             {
250                 uno::Reference< util::XStringSubstitution > xSubst(
251                     xSMGR->createInstance( C2S("com.sun.star.util.PathSubstitution") ),
252                     uno::UNO_QUERY );
253                 if ( xSubst.is() )
254                     sPath = xSubst->substituteVariables( sPath, sal_False );
255                 m_sLogPath = sPath;
256                 m_aShowDataPB.Enable(lcl_doesLogfileExist(m_sLogPath));
257             }
258         }
259     }
260     catch( uno::Exception& )
261     {
262         m_aShowDataPB.Enable(false);
263     }
264 }
265 
266