xref: /trunk/main/cui/source/options/optimprove.cxx (revision 2ee96f1c)
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 #include <svx/dialogs.hrc>
35 #include "optimprove.hrc"
36 #include "helpid.hrc"
37 #include <cuires.hrc>
38 
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/system/XSystemShellExecute.hpp>
42 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
43 #include <com/sun/star/oooimprovement/XCoreController.hpp>
44 #include <comphelper/configurationhelper.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <comphelper/uieventslogger.hxx>
47 #include <tools/testtoolloader.hxx>
48 
49 namespace lang  = ::com::sun::star::lang;
50 namespace uno   = ::com::sun::star::uno;
51 using namespace com::sun::star::system;
52 
53 // class SvxImprovementPage ----------------------------------------------
54 
55 SvxImprovementPage::SvxImprovementPage( Window* pParent ) :
56 
57     TabPage( pParent, CUI_RES( RID_SVXPAGE_IMPROVEMENT ) ),
58 
59     m_aImproveFL                ( this, CUI_RES( FL_IMPROVE ) ),
60     m_aInvitationFT             ( this, CUI_RES( FT_INVITATION ) ),
61     m_aYesRB                    ( this, CUI_RES( RB_YES ) ),
62     m_aNoRB                     ( this, CUI_RES( RB_NO ) ),
63     m_aDataFL                   ( this, CUI_RES( FL_DATA ) ),
64     m_aNumberOfReportsFT        ( this, CUI_RES( FT_NR_REPORTS ) ),
65     m_aNumberOfReportsValueFT   ( this, CUI_RES( FT_NR_REPORTS_VALUE ) ),
66     m_aNumberOfActionsFT        ( this, CUI_RES( FT_NR_ACTIONS ) ),
67     m_aNumberOfActionsValueFT   ( this, CUI_RES( FT_NR_ACTIONS_VALUE ) ),
68     m_aShowDataPB               ( this, CUI_RES( PB_SHOWDATA ) ),
69 
70     m_sInfo                     (       CUI_RES( STR_INFO ) ),
71     m_sMoreInfo                 (       CUI_RES( STR_MOREINFO ) )
72 
73 {
74 	FreeResource();
75 
76     m_aInvitationFT.Show();
77     m_aDataFL.Hide();
78     m_aNumberOfReportsFT.Hide();
79     m_aNumberOfReportsValueFT.Hide();
80     m_aNumberOfActionsFT.Hide();
81     m_aNumberOfActionsValueFT.Hide();
82     m_aShowDataPB.Hide();
83 
84     Size aNewSize = m_aInvitationFT.GetSizePixel();
85     const long nMinWidth = m_aYesRB.CalcMinimumSize().Width();
86     const long nNewWidth = std::max( aNewSize.Width() * 4 / 5, nMinWidth );
87     const long nWDelta = aNewSize.Width() - nNewWidth;
88     aNewSize.Width() = nNewWidth;
89     const Size aCalcSize = m_aInvitationFT.CalcMinimumSize( nNewWidth );
90     const long nHDelta = aCalcSize.Height() - aNewSize.Height();
91     aNewSize.Height() = aCalcSize.Height();
92     m_aInvitationFT.SetSizePixel( aNewSize );
93 
94     aNewSize = m_aYesRB.GetSizePixel();
95     aNewSize.Width() = nNewWidth;
96     Point aNewPos = m_aYesRB.GetPosPixel();
97     aNewPos.Y() += nHDelta;
98     m_aYesRB.SetPosSizePixel( aNewPos, aNewSize );
99     aNewSize = m_aNoRB.GetSizePixel();
100     aNewSize.Width() = nNewWidth;
101     aNewPos = m_aNoRB.GetPosPixel();
102     aNewPos.Y() += nHDelta;
103     m_aNoRB.SetPosSizePixel( aNewPos, aNewSize );
104     aNewSize = m_aImproveFL.GetSizePixel();
105     aNewSize.Width() -= nWDelta;
106     m_aImproveFL.SetSizePixel( aNewSize );
107 
108     Size aSize = GetOutputSizePixel();
109     aSize.Width() -= nWDelta;
110     aSize.Height() = m_aDataFL.GetPosPixel().Y();
111     aSize.Height() += nHDelta;
112     SetSizePixel( aSize );
113 }
114 
115 // -----------------------------------------------------------------------
116 
117 SvxImprovementPage::~SvxImprovementPage()
118 {
119 }
120 
121 // class SvxImprovementDialog --------------------------------------------
122 
123 SvxImprovementDialog::SvxImprovementDialog( Window* pParent, const String& rInfoURL ) :
124 
125     SfxSingleTabDialog( pParent, RID_SVXPAGE_IMPROVEMENT, rInfoURL ),
126 
127     m_pPage( NULL )
128 
129 {
130     m_pPage = new SvxImprovementPage( this );
131     SetInfoLink( LINK( this, SvxImprovementDialog, HandleHyperlink ) );
132     SetPage( m_pPage );
133     if ( GetOKButton() )
134         GetOKButton()->SetClickHdl( LINK( this, SvxImprovementDialog, HandleOK ) );
135 }
136 
137 IMPL_LINK( SvxImprovementDialog, HandleHyperlink, svt::FixedHyperlinkImage*, pHyperlinkImage )
138 {
139     ::rtl::OUString sURL( pHyperlinkImage->GetURL() );
140 
141     if ( sURL.getLength() > 0 )
142     {
143         try
144         {
145             uno::Reference< lang::XMultiServiceFactory > xSMGR =
146                 ::comphelper::getProcessServiceFactory();
147             uno::Reference< XSystemShellExecute > xSystemShell(
148                 xSMGR->createInstance( ::rtl::OUString(
149                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
150                 uno::UNO_QUERY_THROW );
151             if ( xSystemShell.is() )
152             {
153                 xSystemShell->execute(
154                     sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
155             }
156         }
157         catch( const uno::Exception& e )
158         {
159              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
160                 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
161         }
162     }
163 
164     return 0;
165 }
166 
167 IMPL_LINK( SvxImprovementDialog, HandleOK, OKButton*, EMPTYARG )
168 {
169     uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
170     uno::Reference< com::sun::star::oooimprovement::XCoreController > core_c(
171             xSMGR->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")),
172             uno::UNO_QUERY);
173     if(core_c.is())
174     {
175         ::comphelper::ConfigurationHelper::writeDirectKey(
176             xSMGR,
177             ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
178             ::rtl::OUString::createFromAscii("Participation"),
179             ::rtl::OUString::createFromAscii("ShowedInvitation"),
180             uno::makeAny( true ),
181             ::comphelper::ConfigurationHelper::E_STANDARD );
182         ::comphelper::ConfigurationHelper::writeDirectKey(
183             xSMGR,
184             ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
185             ::rtl::OUString::createFromAscii("Participation"),
186             ::rtl::OUString::createFromAscii("InvitationAccepted"),
187             uno::makeAny( m_pPage->IsYesChecked() ),
188             ::comphelper::ConfigurationHelper::E_STANDARD );
189         // TODO: refactor
190         ::comphelper::UiEventsLogger::reinit();
191         ::tools::InitTestToolLib();
192     }
193     EndDialog( RET_OK );
194     return 0;
195 }
196