Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "inettbc.hxx"
22 : :
23 : : #include <com/sun/star/uno/Any.h>
24 : : #include <com/sun/star/frame/XFramesSupplier.hpp>
25 : : #include <com/sun/star/task/XInteractionHandler.hpp>
26 : : #include <svl/eitem.hxx>
27 : : #include <svl/stritem.hxx>
28 : : #include <unotools/historyoptions.hxx>
29 : : #include <svl/folderrestriction.hxx>
30 : : #include <vcl/toolbox.hxx>
31 : : #include <toolkit/unohlp.hxx>
32 : : #include <osl/thread.hxx>
33 : : #include <osl/mutex.hxx>
34 : : #include <rtl/ustring.hxx>
35 : :
36 : : #include <svl/itemset.hxx>
37 : : #include <svl/urihelper.hxx>
38 : : #include <unotools/pathoptions.hxx>
39 : : #include <svtools/asynclink.hxx>
40 : : #include <svtools/inettbc.hxx>
41 : :
42 : : #include <unotools/localfilehelper.hxx>
43 : : #include <comphelper/processfactory.hxx>
44 : :
45 : : #include <sfx2/sfx.hrc>
46 : : #include <sfx2/dispatch.hxx>
47 : : #include <sfx2/viewfrm.hxx>
48 : : #include <sfx2/objsh.hxx>
49 : : #include "referers.hxx"
50 : : #include "sfxtypes.hxx"
51 : : #include "helper.hxx"
52 : :
53 : : using namespace ::com::sun::star::uno;
54 : : using namespace ::com::sun::star::beans;
55 : : using namespace ::com::sun::star::util;
56 : : using namespace ::com::sun::star::frame;
57 : : using namespace ::com::sun::star::task;
58 : :
59 : : //***************************************************************************
60 : : // SfxURLToolBoxControl_Impl
61 : : //***************************************************************************
62 : :
63 [ # # ]: 233 : SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem)
64 : :
65 : 0 : SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
66 : : : SfxToolBoxControl( nSlotId, nId, rBox ),
67 : 0 : pAccExec( 0 )
68 : : {
69 [ # # ]: 0 : addStatusListener( rtl::OUString( ".uno:CurrentURL" ));
70 : 0 : }
71 : :
72 : 0 : SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl()
73 : : {
74 [ # # ][ # # ]: 0 : delete pAccExec;
75 [ # # ]: 0 : }
76 : :
77 : 0 : SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const
78 : : {
79 : 0 : return (SvtURLBox*)GetToolBox().GetItemWindow( GetId() );
80 : : }
81 : :
82 : : //***************************************************************************
83 : :
84 : 0 : void SfxURLToolBoxControl_Impl::OpenURL( const String& rName, sal_Bool /*bNew*/ ) const
85 : : {
86 [ # # ]: 0 : String aName;
87 [ # # ]: 0 : String aFilter;
88 [ # # ]: 0 : String aOptions;
89 : :
90 [ # # ][ # # ]: 0 : INetURLObject aObj( rName );
91 [ # # ]: 0 : if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
92 : : {
93 [ # # ][ # # ]: 0 : String aBaseURL = GetURLBox()->GetBaseURL();
94 [ # # ][ # # ]: 0 : aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
95 : : }
96 : : else
97 [ # # ]: 0 : aName = rName;
98 : :
99 [ # # ]: 0 : if ( !aName.Len() )
100 : 0 : return;
101 : :
102 [ # # ][ # # ]: 0 : Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
103 [ # # ][ # # ]: 0 : if ( xDispatchProvider.is() && m_xServiceManager.is() )
[ # # ]
104 : : {
105 : 0 : URL aTargetURL;
106 : 0 : ::rtl::OUString aTarget( ::rtl::OUString("_default"));
107 : :
108 [ # # ]: 0 : aTargetURL.Complete = aName;
109 : :
110 [ # # ][ # # ]: 0 : getURLTransformer()->parseStrict( aTargetURL );
[ # # ]
111 [ # # ][ # # ]: 0 : Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
112 [ # # ]: 0 : if ( xDispatch.is() )
113 : : {
114 [ # # ]: 0 : Sequence< PropertyValue > aArgs( 2 );
115 [ # # ]: 0 : aArgs[0].Name = ::rtl::OUString("Referer");
116 [ # # ][ # # ]: 0 : aArgs[0].Value = makeAny( ::rtl::OUString(SFX_REFERER_USER ));
117 [ # # ]: 0 : aArgs[1].Name = ::rtl::OUString( "FileName" );
118 [ # # ][ # # ]: 0 : aArgs[1].Value = makeAny( ::rtl::OUString( aName ));
[ # # ]
119 : :
120 [ # # ]: 0 : if ( aFilter.Len() )
121 : : {
122 [ # # ]: 0 : aArgs.realloc( 4 );
123 [ # # ]: 0 : aArgs[2].Name = ::rtl::OUString("FilterOptions");
124 [ # # ][ # # ]: 0 : aArgs[2].Value = makeAny( ::rtl::OUString( aOptions ));
[ # # ]
125 [ # # ]: 0 : aArgs[3].Name = ::rtl::OUString("FilterName");
126 [ # # ][ # # ]: 0 : aArgs[3].Value = makeAny( ::rtl::OUString( aFilter ));
[ # # ]
127 : : }
128 : :
129 [ # # ][ # # ]: 0 : SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo;
130 [ # # ]: 0 : pExecuteInfo->xDispatch = xDispatch;
131 : 0 : pExecuteInfo->aTargetURL = aTargetURL;
132 [ # # ]: 0 : pExecuteInfo->aArgs = aArgs;
133 [ # # ][ # # ]: 0 : Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
[ # # ]
134 : 0 : }
135 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
136 : : }
137 : :
138 : : //--------------------------------------------------------------------
139 : :
140 : 0 : IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
141 : : {
142 : : try
143 : : {
144 : : // Asynchronous execution as this can lead to our own destruction!
145 : : // Framework can recycle our current frame and the layout manager disposes all user interface
146 : : // elements if a component gets detached from its frame!
147 [ # # ][ # # ]: 0 : pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
148 : : }
149 : 0 : catch ( Exception& )
150 : : {
151 : : }
152 : :
153 [ # # ]: 0 : delete pExecuteInfo;
154 [ # # ]: 0 : return 0;
155 : : }
156 : :
157 : :
158 : 0 : Window* SfxURLToolBoxControl_Impl::CreateItemWindow( Window* pParent )
159 : : {
160 [ # # ]: 0 : SvtURLBox* pURLBox = new SvtURLBox( pParent );
161 : 0 : pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) );
162 : 0 : pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) );
163 : :
164 : 0 : return pURLBox;
165 : : }
166 : :
167 : 0 : IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, SelectHdl)
168 : : {
169 [ # # ]: 0 : SvtURLBox* pURLBox = GetURLBox();
170 [ # # ]: 0 : String aName( pURLBox->GetURL() );
171 : :
172 [ # # ][ # # ]: 0 : if ( !pURLBox->IsTravelSelect() && aName.Len() )
[ # # ][ # # ]
173 [ # # ]: 0 : OpenURL( aName, sal_False );
174 : :
175 [ # # ]: 0 : return 1L;
176 : : }
177 : :
178 : 0 : IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl)
179 : : {
180 : 0 : SvtURLBox* pURLBox = GetURLBox();
181 [ # # ]: 0 : OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() );
182 : :
183 [ # # ]: 0 : if ( m_xServiceManager.is() )
184 : : {
185 [ # # ]: 0 : Reference< XFramesSupplier > xDesktop( m_xServiceManager->createInstance(
186 : 0 : ::rtl::OUString("com.sun.star.frame.Desktop")),
187 [ # # ][ # # ]: 0 : UNO_QUERY );
188 [ # # ][ # # ]: 0 : Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY );
[ # # ]
189 [ # # ]: 0 : if ( xFrame.is() )
190 : : {
191 [ # # ][ # # ]: 0 : Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
[ # # ]
192 [ # # ]: 0 : if ( pWin )
193 : : {
194 [ # # ]: 0 : pWin->GrabFocus();
195 [ # # ]: 0 : pWin->ToTop( TOTOP_RESTOREWHENMIN );
196 : : }
197 : 0 : }
198 : : }
199 : :
200 : 0 : return 1L;
201 : : }
202 : :
203 : : //***************************************************************************
204 : :
205 : 0 : void SfxURLToolBoxControl_Impl::StateChanged
206 : : (
207 : : sal_uInt16 nSID,
208 : : SfxItemState eState,
209 : : const SfxPoolItem* pState
210 : : )
211 : : {
212 [ # # ]: 0 : if ( nSID == SID_OPENURL )
213 : : {
214 : : // Disable URL box if command is disabled
215 : 0 : GetURLBox()->Enable( SFX_ITEM_DISABLED != eState );
216 : : }
217 : :
218 [ # # ]: 0 : if ( GetURLBox()->IsEnabled() )
219 : : {
220 [ # # ]: 0 : if( nSID == SID_FOCUSURLBOX )
221 : : {
222 [ # # ]: 0 : if ( GetURLBox()->IsVisible() )
223 : 0 : GetURLBox()->GrabFocus();
224 : : }
225 [ # # ][ # # ]: 0 : else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE == eState )
[ # # ]
226 : : {
227 [ # # ]: 0 : SvtURLBox* pURLBox = GetURLBox();
228 [ # # ]: 0 : pURLBox->Clear();
229 : :
230 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(eHISTORY);
[ # # ]
231 [ # # ]: 0 : for (sal_Int32 i=0; i<lList.getLength(); ++i)
232 : : {
233 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lProps = lList[i];
234 [ # # ]: 0 : for (sal_Int32 p=0; p<lProps.getLength(); ++p)
235 : : {
236 [ # # ][ # # ]: 0 : if (lProps[p].Name != HISTORY_PROPERTYNAME_URL)
[ # # ]
237 : 0 : continue;
238 : :
239 : 0 : ::rtl::OUString sURL;
240 [ # # ][ # # ]: 0 : if (!(lProps[p].Value>>=sURL) || sURL.isEmpty())
[ # # ][ # # ]
241 : 0 : continue;
242 : :
243 [ # # ]: 0 : INetURLObject aURL ( sURL );
244 [ # # ][ # # ]: 0 : String sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
245 [ # # ]: 0 : String sFile;
246 : :
247 [ # # ][ # # ]: 0 : if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile))
248 [ # # ]: 0 : pURLBox->InsertEntry(sFile);
249 : : else
250 [ # # ]: 0 : pURLBox->InsertEntry(sMainURL);
251 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
252 [ # # ]: 0 : }
253 : :
254 [ # # ][ # # ]: 0 : const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState);
[ # # ][ # # ]
255 [ # # ]: 0 : String aRep( pURL->GetValue() );
256 [ # # ][ # # ]: 0 : INetURLObject aURL( aRep );
257 : 0 : INetProtocol eProt = aURL.GetProtocol();
258 [ # # ]: 0 : if ( eProt == INET_PROT_FILE )
259 : : {
260 [ # # ][ # # ]: 0 : pURLBox->SetText( aURL.PathToFileName() );
[ # # ][ # # ]
261 : : }
262 : : else
263 [ # # ][ # # ]: 0 : pURLBox->SetText( aURL.GetURLNoPass() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
264 : : }
265 : : }
266 : 0 : }
267 : :
268 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|