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/SystemShellExecute.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
SvxImprovementPage(Window * pParent)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
~SvxImprovementPage()117 SvxImprovementPage::~SvxImprovementPage()
118 {
119 }
120
121 // class SvxImprovementDialog --------------------------------------------
122
SvxImprovementDialog(Window * pParent,const String & rInfoURL)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
IMPL_LINK(SvxImprovementDialog,HandleHyperlink,svt::FixedHyperlinkImage *,pHyperlinkImage)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< XSystemShellExecute > xSystemShell(
146 com::sun::star::system::SystemShellExecute::create(
147 ::comphelper::getProcessComponentContext() ) );
148 if ( xSystemShell.is() )
149 {
150 xSystemShell->execute(
151 sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
152 }
153 }
154 catch( const uno::Exception& e )
155 {
156 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
157 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
158 }
159 }
160
161 return 0;
162 }
163
IMPL_LINK(SvxImprovementDialog,HandleOK,OKButton *,EMPTYARG)164 IMPL_LINK( SvxImprovementDialog, HandleOK, OKButton*, EMPTYARG )
165 {
166 uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
167 uno::Reference< com::sun::star::oooimprovement::XCoreController > core_c(
168 xSMGR->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")),
169 uno::UNO_QUERY);
170 if(core_c.is())
171 {
172 ::comphelper::ConfigurationHelper::writeDirectKey(
173 xSMGR,
174 ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
175 ::rtl::OUString::createFromAscii("Participation"),
176 ::rtl::OUString::createFromAscii("ShowedInvitation"),
177 uno::makeAny( true ),
178 ::comphelper::ConfigurationHelper::E_STANDARD );
179 ::comphelper::ConfigurationHelper::writeDirectKey(
180 xSMGR,
181 ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
182 ::rtl::OUString::createFromAscii("Participation"),
183 ::rtl::OUString::createFromAscii("InvitationAccepted"),
184 uno::makeAny( m_pPage->IsYesChecked() ),
185 ::comphelper::ConfigurationHelper::E_STANDARD );
186 // TODO: refactor
187 ::comphelper::UiEventsLogger::reinit();
188 ::tools::InitTestToolLib();
189 }
190 EndDialog( RET_OK );
191 return 0;
192 }
193