1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ac9096f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ac9096f4SAndrew Rist * distributed with this work for additional information
6*ac9096f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ac9096f4SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist * with the License. You may obtain a copy of the License at
10*ac9096f4SAndrew Rist *
11*ac9096f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist *
13*ac9096f4SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist * KIND, either express or implied. See the License for the
17*ac9096f4SAndrew Rist * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist * under the License.
19*ac9096f4SAndrew Rist *
20*ac9096f4SAndrew Rist *************************************************************/
21*ac9096f4SAndrew Rist
22*ac9096f4SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
27cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include "rtl/ref.hxx"
41cdf0e10cSrcweir #include <ucbhelper/content.hxx>
42cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
43cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx>
44cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
45cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
46cdf0e10cSrcweir #include <vcl/svapp.hxx>
47cdf0e10cSrcweir #include <vcl/menu.hxx>
48cdf0e10cSrcweir #include <vcl/dialog.hxx>
49cdf0e10cSrcweir #include <vcl/fixed.hxx>
50cdf0e10cSrcweir #include <vcl/group.hxx>
51cdf0e10cSrcweir #include <vcl/button.hxx>
52cdf0e10cSrcweir #include <vcl/msgbox.hxx>
53cdf0e10cSrcweir #include <ucbhelper/macros.hxx>
54cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
55cdf0e10cSrcweir
56cdf0e10cSrcweir #ifndef _UCBEXPLORER_HRC
57cdf0e10cSrcweir #include "ucbexplorer.hrc"
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir
60cdf0e10cSrcweir using namespace com::sun::star;
61cdf0e10cSrcweir using namespace com::sun::star::beans;
62cdf0e10cSrcweir using namespace com::sun::star::io;
63cdf0e10cSrcweir using namespace com::sun::star::lang;
64cdf0e10cSrcweir using namespace com::sun::star::sdbc;
65cdf0e10cSrcweir using namespace com::sun::star::task;
66cdf0e10cSrcweir using namespace com::sun::star::ucb;
67cdf0e10cSrcweir using namespace com::sun::star::uno;
68cdf0e10cSrcweir using namespace rtl;
69cdf0e10cSrcweir
70cdf0e10cSrcweir //=========================================================================
71cdf0e10cSrcweir //
72cdf0e10cSrcweir // class TestDataSink.
73cdf0e10cSrcweir //
74cdf0e10cSrcweir //=========================================================================
75cdf0e10cSrcweir
76cdf0e10cSrcweir class TestDataSink : public cppu::OWeakObject, public XActiveDataSink
77cdf0e10cSrcweir {
78cdf0e10cSrcweir uno::Reference< XInputStream > m_xStream;
79cdf0e10cSrcweir
80cdf0e10cSrcweir public:
81cdf0e10cSrcweir // TestDataSink() {}
82cdf0e10cSrcweir // virtual ~TestDataSink();
83cdf0e10cSrcweir
84cdf0e10cSrcweir // XInterface methods
85cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type & rType )
86cdf0e10cSrcweir throw( RuntimeException );
87cdf0e10cSrcweir virtual void SAL_CALL acquire()
88cdf0e10cSrcweir throw ();
89cdf0e10cSrcweir virtual void SAL_CALL release()
90cdf0e10cSrcweir throw ();
91cdf0e10cSrcweir
92cdf0e10cSrcweir // XActiveDataSink methods.
93cdf0e10cSrcweir virtual void SAL_CALL setInputStream(
94cdf0e10cSrcweir const uno::Reference< XInputStream >& aStream )
95cdf0e10cSrcweir throw( RuntimeException );
96cdf0e10cSrcweir virtual uno::Reference< XInputStream > SAL_CALL getInputStream()
97cdf0e10cSrcweir throw( RuntimeException );
98cdf0e10cSrcweir };
99cdf0e10cSrcweir
100cdf0e10cSrcweir //=========================================================================
101cdf0e10cSrcweir //
102cdf0e10cSrcweir // class StringInputDialog.
103cdf0e10cSrcweir //
104cdf0e10cSrcweir //=========================================================================
105cdf0e10cSrcweir
106cdf0e10cSrcweir class StringInputDialog : public ModalDialog
107cdf0e10cSrcweir {
108cdf0e10cSrcweir private:
109cdf0e10cSrcweir FixedText m_aNameText;
110cdf0e10cSrcweir Edit m_aNameEdit;
111cdf0e10cSrcweir GroupBox m_aNameGroup;
112cdf0e10cSrcweir OKButton m_aOKBtn;
113cdf0e10cSrcweir CancelButton m_aCancelBtn;
114cdf0e10cSrcweir HelpButton m_aHelpBtn;
115cdf0e10cSrcweir
116cdf0e10cSrcweir DECL_LINK( OKHdl, Button * );
117cdf0e10cSrcweir DECL_LINK( NameHdl, Edit * );
118cdf0e10cSrcweir
119cdf0e10cSrcweir public:
120cdf0e10cSrcweir StringInputDialog( ResMgr& rResMgr,
121cdf0e10cSrcweir const String& rTitle,
122cdf0e10cSrcweir const String& rDefaultText,
123cdf0e10cSrcweir String* pGroupName = 0 );
GetValue() const124cdf0e10cSrcweir String GetValue() const { return m_aNameEdit.GetText(); }
SetValue(const String & rNewName)125cdf0e10cSrcweir void SetValue( const String& rNewName ) { m_aNameEdit.SetText( rNewName ); }
126cdf0e10cSrcweir };
127cdf0e10cSrcweir
128cdf0e10cSrcweir //=========================================================================
129cdf0e10cSrcweir //
130cdf0e10cSrcweir // class UcbExplorerListBoxEntry.
131cdf0e10cSrcweir //
132cdf0e10cSrcweir //=========================================================================
133cdf0e10cSrcweir
134cdf0e10cSrcweir class UcbExplorerListBoxEntry : public SvLBoxEntry
135cdf0e10cSrcweir {
136cdf0e10cSrcweir friend class UcbExplorerTreeListBox;
137cdf0e10cSrcweir
138cdf0e10cSrcweir enum EntryType { FOLDER, DOCUMENT, LINK };
139cdf0e10cSrcweir
140cdf0e10cSrcweir ::ucbhelper::Content m_aContent;
141cdf0e10cSrcweir EntryType m_eType;
142cdf0e10cSrcweir
143cdf0e10cSrcweir public:
144cdf0e10cSrcweir UcbExplorerListBoxEntry();
145cdf0e10cSrcweir virtual ~UcbExplorerListBoxEntry();
146cdf0e10cSrcweir
147cdf0e10cSrcweir BOOL createNewContent( const ContentInfo& rInfo,
148cdf0e10cSrcweir ::ucbhelper::Content& rNewContent );
149cdf0e10cSrcweir };
150cdf0e10cSrcweir
151cdf0e10cSrcweir //=========================================================================
152cdf0e10cSrcweir //
153cdf0e10cSrcweir // class UcbExplorerTreeListBox.
154cdf0e10cSrcweir //
155cdf0e10cSrcweir //=========================================================================
156cdf0e10cSrcweir
157cdf0e10cSrcweir class UcbExplorerTreeListBox : public SvTreeListBox
158cdf0e10cSrcweir {
159cdf0e10cSrcweir Bitmap m_aFolderClosed;
160cdf0e10cSrcweir Bitmap m_aFolderOpened;
161cdf0e10cSrcweir Bitmap m_aDocument;
162cdf0e10cSrcweir Bitmap m_aLink;
163cdf0e10cSrcweir
164cdf0e10cSrcweir private:
165cdf0e10cSrcweir virtual SvLBoxEntry* CreateEntry() const;
166cdf0e10cSrcweir virtual void RequestingChilds( SvLBoxEntry* pParent );
167cdf0e10cSrcweir
168cdf0e10cSrcweir public:
169cdf0e10cSrcweir UcbExplorerTreeListBox( ResMgr & rResMgr, Window* pParent, WinBits nWinStyle = 0 );
170cdf0e10cSrcweir virtual ~UcbExplorerTreeListBox();
171cdf0e10cSrcweir
172cdf0e10cSrcweir virtual void Command( const CommandEvent& rCEvt );
173cdf0e10cSrcweir
174cdf0e10cSrcweir UcbExplorerListBoxEntry*
175cdf0e10cSrcweir InsertEntry( ::ucbhelper::Content& rContent, SvLBoxEntry* pParent );
176cdf0e10cSrcweir UcbExplorerListBoxEntry*
177cdf0e10cSrcweir InsertEntry( const String& rURL, SvLBoxEntry* pParent = 0 );
178cdf0e10cSrcweir };
179cdf0e10cSrcweir
180cdf0e10cSrcweir //=========================================================================
181cdf0e10cSrcweir //
182cdf0e10cSrcweir // class UcbExplorerWindow.
183cdf0e10cSrcweir //
184cdf0e10cSrcweir //=========================================================================
185cdf0e10cSrcweir
186cdf0e10cSrcweir class UcbExplorerWindow : public WorkWindow
187cdf0e10cSrcweir {
188cdf0e10cSrcweir friend class MyApp;
189cdf0e10cSrcweir
190cdf0e10cSrcweir UcbExplorerTreeListBox m_aTree;
191cdf0e10cSrcweir
192cdf0e10cSrcweir public:
193cdf0e10cSrcweir UcbExplorerWindow( ResMgr & rResMgr, Window *pParent, WinBits nWinStyle );
194cdf0e10cSrcweir virtual ~UcbExplorerWindow();
195cdf0e10cSrcweir
196cdf0e10cSrcweir virtual void Resize();
197cdf0e10cSrcweir };
198cdf0e10cSrcweir
199cdf0e10cSrcweir //=========================================================================
200cdf0e10cSrcweir //
201cdf0e10cSrcweir // class MyApp.
202cdf0e10cSrcweir //
203cdf0e10cSrcweir //=========================================================================
204cdf0e10cSrcweir
205cdf0e10cSrcweir class MyApp : public Application
206cdf0e10cSrcweir {
207cdf0e10cSrcweir public:
208cdf0e10cSrcweir virtual void Main();
209cdf0e10cSrcweir };
210cdf0e10cSrcweir
211cdf0e10cSrcweir //=========================================================================
212cdf0e10cSrcweir //
213cdf0e10cSrcweir // TestDataSink implementation.
214cdf0e10cSrcweir //
215cdf0e10cSrcweir //=========================================================================
216cdf0e10cSrcweir
217cdf0e10cSrcweir // virtual
queryInterface(const Type & rType)218cdf0e10cSrcweir Any SAL_CALL TestDataSink::queryInterface( const Type & rType )
219cdf0e10cSrcweir throw( RuntimeException )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir Any aRet = cppu::queryInterface(
222cdf0e10cSrcweir rType,
223cdf0e10cSrcweir static_cast< XActiveDataSink * >( this ) );
224cdf0e10cSrcweir return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir //=========================================================================
228cdf0e10cSrcweir // virtual
acquire()229cdf0e10cSrcweir void SAL_CALL TestDataSink::acquire()
230cdf0e10cSrcweir throw()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir OWeakObject::acquire();
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir //=========================================================================
236cdf0e10cSrcweir // virtual
release()237cdf0e10cSrcweir void SAL_CALL TestDataSink::release()
238cdf0e10cSrcweir throw()
239cdf0e10cSrcweir {
240cdf0e10cSrcweir OWeakObject::release();
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir //=========================================================================
244cdf0e10cSrcweir // virtual
setInputStream(const uno::Reference<XInputStream> & aStream)245cdf0e10cSrcweir void SAL_CALL TestDataSink::setInputStream(
246cdf0e10cSrcweir const uno::Reference< XInputStream >& aStream )
247cdf0e10cSrcweir throw( RuntimeException )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir m_xStream = aStream;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir //=========================================================================
253cdf0e10cSrcweir // virtual
getInputStream()254cdf0e10cSrcweir uno::Reference< XInputStream > SAL_CALL TestDataSink::getInputStream()
255cdf0e10cSrcweir throw( RuntimeException )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir return m_xStream;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir //=========================================================================
261cdf0e10cSrcweir //
262cdf0e10cSrcweir // StringInputDialog implementation.
263cdf0e10cSrcweir //
264cdf0e10cSrcweir //=========================================================================
265cdf0e10cSrcweir
StringInputDialog(ResMgr & rResMgr,const String & rTitle,const String & rDefaultText,String * pGroupName)266cdf0e10cSrcweir StringInputDialog::StringInputDialog( ResMgr& rResMgr,
267cdf0e10cSrcweir const String& rTitle,
268cdf0e10cSrcweir const String& rDefaultText,
269cdf0e10cSrcweir String* pGroupName )
270cdf0e10cSrcweir : ModalDialog( 0, ResId( DLG_STRINGINPUT, rResMgr ) ),
271cdf0e10cSrcweir m_aNameText ( this, ResId( FT_STRINGINPUT_DLG_NAME, rResMgr ) ),
272cdf0e10cSrcweir m_aNameEdit ( this, ResId( ED_STRINGINPUT_DLG_NAME, rResMgr ) ),
273cdf0e10cSrcweir m_aNameGroup( this, ResId( GB_STRINGINPUT_DLG_NAME, rResMgr ) ),
274cdf0e10cSrcweir m_aOKBtn ( this, ResId( BT_STRINGINPUT_DLG_OK, rResMgr ) ),
275cdf0e10cSrcweir m_aCancelBtn( this, ResId( BT_STRINGINPUT_DLG_CANCEL, rResMgr ) ),
276cdf0e10cSrcweir m_aHelpBtn ( this, ResId( BT_STRINGINPUT_DLG_HELP, rResMgr ) )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir FreeResource();
279cdf0e10cSrcweir SetText( rTitle );
280cdf0e10cSrcweir m_aNameEdit.SetText( rDefaultText );
281cdf0e10cSrcweir m_aOKBtn.SetClickHdl( LINK( this, StringInputDialog, OKHdl ) );
282cdf0e10cSrcweir m_aNameEdit.SetModifyHdl( LINK( this, StringInputDialog, NameHdl ) );
283cdf0e10cSrcweir
284cdf0e10cSrcweir if ( pGroupName )
285cdf0e10cSrcweir m_aNameGroup.SetText( *pGroupName );
286cdf0e10cSrcweir };
287cdf0e10cSrcweir
288cdf0e10cSrcweir //=========================================================================
IMPL_LINK(StringInputDialog,OKHdl,Button *,EMPTYARG)289cdf0e10cSrcweir IMPL_LINK( StringInputDialog, OKHdl, Button *, EMPTYARG )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir // trim the strings
292cdf0e10cSrcweir m_aNameEdit.SetText(
293cdf0e10cSrcweir m_aNameEdit.GetText().EraseLeadingChars().EraseTrailingChars() );
294cdf0e10cSrcweir EndDialog( RET_OK );
295cdf0e10cSrcweir return 1;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir //=========================================================================
IMPL_LINK(StringInputDialog,NameHdl,Edit *,EMPTYARG)299cdf0e10cSrcweir IMPL_LINK( StringInputDialog, NameHdl, Edit *, EMPTYARG )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir /*
302cdf0e10cSrcweir // trim the strings
303cdf0e10cSrcweir String aName = m_aNameEdit.GetText();
304cdf0e10cSrcweir aName.EraseLeadingChars().EraseTrailingChars();
305cdf0e10cSrcweir if ( aName.Len() )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir if ( !m_aOKBtn.IsEnabled() )
308cdf0e10cSrcweir m_aOKBtn.Enable( TRUE );
309cdf0e10cSrcweir }
310cdf0e10cSrcweir else
311cdf0e10cSrcweir {
312cdf0e10cSrcweir if ( m_aOKBtn.IsEnabled() )
313cdf0e10cSrcweir m_aOKBtn.Enable( FALSE );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir */
316cdf0e10cSrcweir return 0;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir //=========================================================================
320cdf0e10cSrcweir //
321cdf0e10cSrcweir // UcbExplorerListBoxEntry implementation.
322cdf0e10cSrcweir //
323cdf0e10cSrcweir //=========================================================================
324cdf0e10cSrcweir
UcbExplorerListBoxEntry()325cdf0e10cSrcweir UcbExplorerListBoxEntry::UcbExplorerListBoxEntry()
326cdf0e10cSrcweir {
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
329cdf0e10cSrcweir //=========================================================================
330cdf0e10cSrcweir // virtual
~UcbExplorerListBoxEntry()331cdf0e10cSrcweir UcbExplorerListBoxEntry::~UcbExplorerListBoxEntry()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir }
334cdf0e10cSrcweir
335cdf0e10cSrcweir //=========================================================================
createNewContent(const ContentInfo & rInfo,::ucbhelper::Content & rNewContent)336cdf0e10cSrcweir BOOL UcbExplorerListBoxEntry::createNewContent( const ContentInfo& rInfo,
337cdf0e10cSrcweir ::ucbhelper::Content& rNewContent )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir sal_Int32 nCount = rInfo.Properties.getLength();
340cdf0e10cSrcweir Sequence< Any > aPropValues( nCount );
341cdf0e10cSrcweir Sequence< OUString > aPropNames( nCount );
342cdf0e10cSrcweir
343cdf0e10cSrcweir if ( nCount > 0 )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir // Collect property values.
346cdf0e10cSrcweir
347cdf0e10cSrcweir Any* pValues = aPropValues.getArray();
348cdf0e10cSrcweir const Property* pProps = rInfo.Properties.getConstArray();
349cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir const OUString& rName = pProps[ n ].Name;
352cdf0e10cSrcweir
353cdf0e10cSrcweir std::auto_ptr< ResMgr > xManager(
354cdf0e10cSrcweir ResMgr::CreateResMgr( CREATEVERSIONRESMGR_NAME( ucbexplorer ) ) );
355cdf0e10cSrcweir StringInputDialog* pDlg = new StringInputDialog( *xManager.get(), rName, rName );
356cdf0e10cSrcweir USHORT nRet = pDlg->Execute();
357cdf0e10cSrcweir if ( nRet == RET_OK )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir OUString aValue( pDlg->GetValue() );
360cdf0e10cSrcweir
361cdf0e10cSrcweir // Convert value according to supplied type info...
362cdf0e10cSrcweir
363cdf0e10cSrcweir const Type& rType = pProps[ n ].Type;
364cdf0e10cSrcweir
365cdf0e10cSrcweir if ( rType == getCppuType(
366cdf0e10cSrcweir static_cast< const OUString * >( 0 ) ) )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir // string
369cdf0e10cSrcweir pValues[ n ] <<= aValue;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir else if ( rType == getCppuType(
372cdf0e10cSrcweir static_cast< const sal_Int32 * >( 0 ) ) )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir // long
375cdf0e10cSrcweir pValues[ n ] <<= aValue.toInt32();
376cdf0e10cSrcweir }
377cdf0e10cSrcweir else if ( rType == getCppuType(
378cdf0e10cSrcweir static_cast< const sal_Int16 * >( 0 ) ) )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir // short
381cdf0e10cSrcweir pValues[ n ] <<= sal_Int16( aValue.toInt32() ) ;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir else if ( rType == getCppuBooleanType() )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir // boolean
386cdf0e10cSrcweir pValues[ n ] <<= sal_Bool( aValue.toChar() ) ;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir else if ( rType == getCppuCharType() )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir // char
391cdf0e10cSrcweir pValues[ n ] <<= aValue.toChar();
392cdf0e10cSrcweir }
393cdf0e10cSrcweir else if ( rType == getCppuType(
394cdf0e10cSrcweir static_cast< const sal_Int8 * >( 0 ) ) )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir // byte
397cdf0e10cSrcweir pValues[ n ] <<= sal_Int8( aValue.toChar() ) ;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir else if ( rType == getCppuType(
400cdf0e10cSrcweir static_cast< const sal_Int64 * >( 0 ) ) )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir // hyper
403cdf0e10cSrcweir pValues[ n ] <<= aValue.toInt64();
404cdf0e10cSrcweir }
405cdf0e10cSrcweir else if ( rType == getCppuType(
406cdf0e10cSrcweir static_cast< const float * >( 0 ) ) )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir // float
409cdf0e10cSrcweir pValues[ n ] <<= aValue.toFloat();
410cdf0e10cSrcweir }
411cdf0e10cSrcweir else if ( rType == getCppuType(
412cdf0e10cSrcweir static_cast< const double * >( 0 ) ) )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir // double
415cdf0e10cSrcweir pValues[ n ] <<= aValue.toDouble();
416cdf0e10cSrcweir }
417cdf0e10cSrcweir else
418cdf0e10cSrcweir {
419cdf0e10cSrcweir // See com/sun/star/ucb/ContentInfo.idl
420cdf0e10cSrcweir DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
421cdf0e10cSrcweir "Invlid type for bootstrap property!" );
422cdf0e10cSrcweir }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir delete pDlg;
426cdf0e10cSrcweir
427cdf0e10cSrcweir if ( nRet != RET_OK )
428cdf0e10cSrcweir return FALSE;
429cdf0e10cSrcweir
430cdf0e10cSrcweir aPropNames[ n ] = rName;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir uno::Reference< XInputStream > xData;
435cdf0e10cSrcweir
436cdf0e10cSrcweir if ( rInfo.Attributes & ContentInfoAttribute::INSERT_WITH_INPUTSTREAM )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir // Let the user specify the URL of a content containing the
439cdf0e10cSrcweir // data to supply to the new content.
440cdf0e10cSrcweir
441cdf0e10cSrcweir std::auto_ptr< ResMgr > xManager(
442cdf0e10cSrcweir ResMgr::CreateResMgr( CREATEVERSIONRESMGR_NAME( ucbexplorer ) ) );
443cdf0e10cSrcweir StringInputDialog* pDlg = new StringInputDialog(
444cdf0e10cSrcweir *xManager.get(),
445cdf0e10cSrcweir OUString::createFromAscii(
446cdf0e10cSrcweir "Document Data Source URL" ),
447cdf0e10cSrcweir OUString() );
448cdf0e10cSrcweir USHORT nRet = pDlg->Execute();
449cdf0e10cSrcweir if ( nRet == RET_OK )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir // Create a content object for the given URL.
452cdf0e10cSrcweir
453cdf0e10cSrcweir OUString aSourceURL( pDlg->GetValue() );
454cdf0e10cSrcweir if ( aSourceURL.getLength() == 0 )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
457cdf0e10cSrcweir "No document data URL!" );
458cdf0e10cSrcweir return FALSE;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir
461cdf0e10cSrcweir try
462cdf0e10cSrcweir {
463cdf0e10cSrcweir uno::Reference< XCommandEnvironment > xEnv;
464cdf0e10cSrcweir
465cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
466cdf0e10cSrcweir if ( pBroker )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir uno::Reference< XInteractionHandler > xInteractionHandler(
469cdf0e10cSrcweir pBroker->getServiceManager()->createInstance(
470cdf0e10cSrcweir OUString::createFromAscii(
471cdf0e10cSrcweir "com.sun.star.task.InteractionHandler" ) ),
472cdf0e10cSrcweir UNO_QUERY );
473cdf0e10cSrcweir
474cdf0e10cSrcweir uno::Reference< XProgressHandler > xProgressHandler
475cdf0e10cSrcweir /* = new ProgressHandler( *pBroker ) */ ;
476cdf0e10cSrcweir
477cdf0e10cSrcweir xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler,
478cdf0e10cSrcweir xProgressHandler );
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
481cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aSourceURL, xEnv );
482cdf0e10cSrcweir
483cdf0e10cSrcweir // Get source data.
484cdf0e10cSrcweir rtl::Reference< TestDataSink > xSourceData = new TestDataSink;
485cdf0e10cSrcweir aSourceContent.openStream( xSourceData.get() );
486cdf0e10cSrcweir xData = xSourceData->getInputStream();
487cdf0e10cSrcweir }
488cdf0e10cSrcweir catch ( ContentCreationException const & )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
491cdf0e10cSrcweir "No content for document data!" );
492cdf0e10cSrcweir return FALSE;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir catch ( CommandAbortedException const & )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir return FALSE;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir catch ( RuntimeException const & )
499cdf0e10cSrcweir {
500cdf0e10cSrcweir throw;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir catch ( Exception const & )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir return FALSE;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir }
507cdf0e10cSrcweir
508cdf0e10cSrcweir delete pDlg;
509cdf0e10cSrcweir
510cdf0e10cSrcweir if ( nRet != RET_OK )
511cdf0e10cSrcweir return FALSE;
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir // Create new content.
515cdf0e10cSrcweir
516cdf0e10cSrcweir ULONG n = Application::ReleaseSolarMutex();
517cdf0e10cSrcweir BOOL bRet = sal_False;
518cdf0e10cSrcweir
519cdf0e10cSrcweir try
520cdf0e10cSrcweir {
521cdf0e10cSrcweir bRet = m_aContent.insertNewContent(
522cdf0e10cSrcweir rInfo.Type, aPropNames, aPropValues, xData, rNewContent );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir catch ( CommandAbortedException const & )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir }
527cdf0e10cSrcweir catch ( RuntimeException const & )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir throw;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir catch ( Exception const & )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir }
534cdf0e10cSrcweir
535cdf0e10cSrcweir Application::AcquireSolarMutex( n );
536cdf0e10cSrcweir return bRet;
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
539cdf0e10cSrcweir //=========================================================================
540cdf0e10cSrcweir //
541cdf0e10cSrcweir // UcbExplorerTreeListBox implementation.
542cdf0e10cSrcweir //
543cdf0e10cSrcweir //=========================================================================
544cdf0e10cSrcweir
UcbExplorerTreeListBox(ResMgr & rResMgr,Window * pParent,WinBits nWinStyle)545cdf0e10cSrcweir UcbExplorerTreeListBox::UcbExplorerTreeListBox( ResMgr & rResMgr,
546cdf0e10cSrcweir Window* pParent,
547cdf0e10cSrcweir WinBits nWinStyle )
548cdf0e10cSrcweir : SvTreeListBox( pParent, nWinStyle ),
549cdf0e10cSrcweir m_aFolderClosed( ResId( BMP_FOLDER_CLOSED, rResMgr ) ),
550cdf0e10cSrcweir m_aFolderOpened( ResId( BMP_FOLDER_OPENED, rResMgr ) ),
551cdf0e10cSrcweir m_aDocument( ResId( BMP_DOCUMENT, rResMgr ) ),
552cdf0e10cSrcweir m_aLink( ResId( BMP_LINK, rResMgr ) )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir }
555cdf0e10cSrcweir
556cdf0e10cSrcweir //=========================================================================
557cdf0e10cSrcweir // virtual
~UcbExplorerTreeListBox()558cdf0e10cSrcweir UcbExplorerTreeListBox::~UcbExplorerTreeListBox()
559cdf0e10cSrcweir {
560cdf0e10cSrcweir }
561cdf0e10cSrcweir
562cdf0e10cSrcweir //=========================================================================
563cdf0e10cSrcweir // virtual
CreateEntry() const564cdf0e10cSrcweir SvLBoxEntry* UcbExplorerTreeListBox::CreateEntry() const
565cdf0e10cSrcweir {
566cdf0e10cSrcweir return new UcbExplorerListBoxEntry();
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
569cdf0e10cSrcweir //=========================================================================
570cdf0e10cSrcweir // virtual
RequestingChilds(SvLBoxEntry * pParent)571cdf0e10cSrcweir void UcbExplorerTreeListBox::RequestingChilds( SvLBoxEntry* pParent )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir UcbExplorerListBoxEntry* pEntry
574cdf0e10cSrcweir = static_cast< UcbExplorerListBoxEntry * >( pParent );
575cdf0e10cSrcweir if ( !pEntry->HasChilds() )
576cdf0e10cSrcweir {
577cdf0e10cSrcweir switch ( pEntry->m_eType )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir case UcbExplorerListBoxEntry::FOLDER:
580cdf0e10cSrcweir {
581cdf0e10cSrcweir ULONG n = Application::ReleaseSolarMutex();
582cdf0e10cSrcweir
583cdf0e10cSrcweir try
584cdf0e10cSrcweir {
585cdf0e10cSrcweir Sequence< OUString > aPropertyNames( 0 );
586cdf0e10cSrcweir // OUString* pNames = aPropertyNames.getArray();
587cdf0e10cSrcweir // pNames[ 0 ] = OUString::createFromAscii( "Title" );
588cdf0e10cSrcweir
589cdf0e10cSrcweir uno::Reference< XResultSet > xResultSet
590cdf0e10cSrcweir = pEntry->m_aContent.createCursor(
591cdf0e10cSrcweir aPropertyNames,
592cdf0e10cSrcweir ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
593cdf0e10cSrcweir uno::Reference< XContentAccess > xContentAccess(
594cdf0e10cSrcweir xResultSet, UNO_QUERY );
595cdf0e10cSrcweir
596cdf0e10cSrcweir if ( xResultSet.is() && xContentAccess.is() )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir while ( xResultSet->next() )
599cdf0e10cSrcweir {
600cdf0e10cSrcweir Application::AcquireSolarMutex( n );
601cdf0e10cSrcweir
602cdf0e10cSrcweir InsertEntry(
603cdf0e10cSrcweir xContentAccess->queryContentIdentifierString(),
604cdf0e10cSrcweir pParent );
605cdf0e10cSrcweir
606cdf0e10cSrcweir n = Application::ReleaseSolarMutex();
607cdf0e10cSrcweir }
608cdf0e10cSrcweir }
609cdf0e10cSrcweir }
610cdf0e10cSrcweir catch ( CommandAbortedException const & )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir }
613cdf0e10cSrcweir catch ( RuntimeException const & )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir throw;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir catch ( Exception const & )
618cdf0e10cSrcweir {
619cdf0e10cSrcweir }
620cdf0e10cSrcweir
621cdf0e10cSrcweir Application::AcquireSolarMutex( n );
622cdf0e10cSrcweir break;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir
625cdf0e10cSrcweir case UcbExplorerListBoxEntry::DOCUMENT:
626cdf0e10cSrcweir break;
627cdf0e10cSrcweir
628cdf0e10cSrcweir case UcbExplorerListBoxEntry::LINK:
629cdf0e10cSrcweir break;
630cdf0e10cSrcweir
631cdf0e10cSrcweir default:
632cdf0e10cSrcweir break;
633cdf0e10cSrcweir }
634cdf0e10cSrcweir }
635cdf0e10cSrcweir }
636cdf0e10cSrcweir
637cdf0e10cSrcweir //=========================================================================
638cdf0e10cSrcweir // virtual
Command(const CommandEvent & rCEvt)639cdf0e10cSrcweir void UcbExplorerTreeListBox::Command( const CommandEvent& rCEvt )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir const Point& rPos = rCEvt.GetMousePosPixel();
644cdf0e10cSrcweir UcbExplorerListBoxEntry* pEntry
645cdf0e10cSrcweir = static_cast< UcbExplorerListBoxEntry * >(
646cdf0e10cSrcweir GetEntry( rPos, TRUE ) );
647cdf0e10cSrcweir if ( pEntry )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir std::auto_ptr< ResMgr > xManager(
650cdf0e10cSrcweir ResMgr::CreateResMgr( CREATEVERSIONRESMGR_NAME( ucbexplorer ) ) );
651cdf0e10cSrcweir PopupMenu* pMenu = new PopupMenu( ResId( MENU_POPUP, *xManager.get() ) );
652cdf0e10cSrcweir PopupMenu* pNewMenu = 0;
653cdf0e10cSrcweir
654cdf0e10cSrcweir // pMenu->SetSelectHdl( LINK( this,
655cdf0e10cSrcweir // SfxCommonTemplateDialog_Impl,
656cdf0e10cSrcweir // MenuSelectHdl ) );
657cdf0e10cSrcweir
658cdf0e10cSrcweir //////////////////////////////////////////////////////////////
659cdf0e10cSrcweir // Configure "New"
660cdf0e10cSrcweir //////////////////////////////////////////////////////////////
661cdf0e10cSrcweir
662cdf0e10cSrcweir Sequence< ContentInfo > aInfo
663cdf0e10cSrcweir = pEntry->m_aContent.queryCreatableContentsInfo();
664cdf0e10cSrcweir const ContentInfo* pInfo = aInfo.getConstArray();
665cdf0e10cSrcweir sal_Int32 nCount = aInfo.getLength();
666cdf0e10cSrcweir BOOL bCanCreate = ( nCount > 0 );
667cdf0e10cSrcweir
668cdf0e10cSrcweir pNewMenu = new PopupMenu;
669cdf0e10cSrcweir pMenu->SetPopupMenu( MENU_NEW, pNewMenu );
670cdf0e10cSrcweir
671cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
672cdf0e10cSrcweir {
673cdf0e10cSrcweir const ContentInfo& rInfo = pInfo[ n ];
674cdf0e10cSrcweir pNewMenu->InsertItem( 20000 + n + 1, rInfo.Type );
675cdf0e10cSrcweir }
676cdf0e10cSrcweir
677cdf0e10cSrcweir pMenu->EnableItem( MENU_NEW, bCanCreate );
678cdf0e10cSrcweir
679cdf0e10cSrcweir //////////////////////////////////////////////////////////////
680cdf0e10cSrcweir // Configure "Rename"
681cdf0e10cSrcweir //////////////////////////////////////////////////////////////
682cdf0e10cSrcweir
683cdf0e10cSrcweir sal_Bool bEnable = sal_False;
684cdf0e10cSrcweir
685cdf0e10cSrcweir try
686cdf0e10cSrcweir {
687cdf0e10cSrcweir Property aProp =
688cdf0e10cSrcweir pEntry->m_aContent.getProperties()->getPropertyByName(
689cdf0e10cSrcweir OUString::createFromAscii( "Title" ) );
690cdf0e10cSrcweir bEnable = !( aProp.Attributes & PropertyAttribute::READONLY );
691cdf0e10cSrcweir }
692cdf0e10cSrcweir catch( UnknownPropertyException const & )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir // getPropertyByName
695cdf0e10cSrcweir bEnable = sal_False;
696cdf0e10cSrcweir }
697cdf0e10cSrcweir catch ( CommandAbortedException const & )
698cdf0e10cSrcweir {
699cdf0e10cSrcweir }
700cdf0e10cSrcweir catch ( RuntimeException const & )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir throw;
703cdf0e10cSrcweir }
704cdf0e10cSrcweir catch ( Exception const & )
705cdf0e10cSrcweir {
706cdf0e10cSrcweir }
707cdf0e10cSrcweir
708cdf0e10cSrcweir pMenu->EnableItem( MENU_RENAME, bEnable );
709cdf0e10cSrcweir
710cdf0e10cSrcweir //////////////////////////////////////////////////////////////
711cdf0e10cSrcweir // Configure "Delete"
712cdf0e10cSrcweir //////////////////////////////////////////////////////////////
713cdf0e10cSrcweir
714cdf0e10cSrcweir try
715cdf0e10cSrcweir {
716cdf0e10cSrcweir pMenu->EnableItem( MENU_DELETE,
717cdf0e10cSrcweir pEntry->m_aContent
718cdf0e10cSrcweir .getCommands()->hasCommandByName(
719cdf0e10cSrcweir OUString::createFromAscii(
720cdf0e10cSrcweir "delete" ) ) );
721cdf0e10cSrcweir }
722cdf0e10cSrcweir catch ( CommandAbortedException const & )
723cdf0e10cSrcweir {
724cdf0e10cSrcweir }
725cdf0e10cSrcweir catch ( RuntimeException const & )
726cdf0e10cSrcweir {
727cdf0e10cSrcweir throw;
728cdf0e10cSrcweir }
729cdf0e10cSrcweir catch ( Exception const & )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir }
732cdf0e10cSrcweir
733cdf0e10cSrcweir //////////////////////////////////////////////////////////////
734cdf0e10cSrcweir // Execute menu.
735cdf0e10cSrcweir //////////////////////////////////////////////////////////////
736cdf0e10cSrcweir
737cdf0e10cSrcweir USHORT nSelected = pMenu->Execute( this, rPos );
738cdf0e10cSrcweir switch ( nSelected )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir // case MENU_NEW:
741cdf0e10cSrcweir // break;
742cdf0e10cSrcweir
743cdf0e10cSrcweir case MENU_RENAME:
744cdf0e10cSrcweir {
745cdf0e10cSrcweir OUString aNewTitle;
746cdf0e10cSrcweir
747cdf0e10cSrcweir try
748cdf0e10cSrcweir {
749cdf0e10cSrcweir pEntry->m_aContent.getPropertyValue(
750cdf0e10cSrcweir OUString::createFromAscii( "Title" ) )
751cdf0e10cSrcweir >>= aNewTitle;
752cdf0e10cSrcweir }
753cdf0e10cSrcweir catch ( CommandAbortedException const & )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir }
756cdf0e10cSrcweir catch ( RuntimeException const & )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir throw;
759cdf0e10cSrcweir }
760cdf0e10cSrcweir catch ( Exception const & )
761cdf0e10cSrcweir {
762cdf0e10cSrcweir }
763cdf0e10cSrcweir
764cdf0e10cSrcweir std::auto_ptr< ResMgr > xManager(
765cdf0e10cSrcweir ResMgr::CreateResMgr( CREATEVERSIONRESMGR_NAME( ucbexplorer ) ) );
766cdf0e10cSrcweir StringInputDialog* pDlg
767cdf0e10cSrcweir = new StringInputDialog(
768cdf0e10cSrcweir *xManager.get(),
769cdf0e10cSrcweir OUString::createFromAscii( "Title" ),
770cdf0e10cSrcweir aNewTitle );
771cdf0e10cSrcweir
772cdf0e10cSrcweir USHORT nRet = pDlg->Execute();
773cdf0e10cSrcweir
774cdf0e10cSrcweir Any aValue;
775cdf0e10cSrcweir
776cdf0e10cSrcweir if ( nRet == RET_OK )
777cdf0e10cSrcweir {
778cdf0e10cSrcweir aNewTitle = pDlg->GetValue();
779cdf0e10cSrcweir aValue <<= aNewTitle;
780cdf0e10cSrcweir }
781cdf0e10cSrcweir
782cdf0e10cSrcweir delete pDlg;
783cdf0e10cSrcweir
784cdf0e10cSrcweir if ( nRet != RET_OK )
785cdf0e10cSrcweir break;
786cdf0e10cSrcweir
787cdf0e10cSrcweir sal_Bool bOK = sal_False;
788cdf0e10cSrcweir
789cdf0e10cSrcweir ULONG n = Application::ReleaseSolarMutex();
790cdf0e10cSrcweir
791cdf0e10cSrcweir try
792cdf0e10cSrcweir {
793cdf0e10cSrcweir pEntry->m_aContent.setPropertyValue(
794cdf0e10cSrcweir OUString::createFromAscii( "Title" ),
795cdf0e10cSrcweir aValue );
796cdf0e10cSrcweir bOK = sal_True;
797cdf0e10cSrcweir }
798cdf0e10cSrcweir catch ( CommandAbortedException const & )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir }
801cdf0e10cSrcweir catch ( RuntimeException const & )
802cdf0e10cSrcweir {
803cdf0e10cSrcweir throw;
804cdf0e10cSrcweir }
805cdf0e10cSrcweir catch ( Exception const & )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir }
808cdf0e10cSrcweir
809cdf0e10cSrcweir Application::AcquireSolarMutex( n );
810cdf0e10cSrcweir
811cdf0e10cSrcweir if ( bOK )
812cdf0e10cSrcweir {
813cdf0e10cSrcweir OUString aText( aNewTitle );
814cdf0e10cSrcweir OUString aTargetURL;
815cdf0e10cSrcweir try
816cdf0e10cSrcweir {
817cdf0e10cSrcweir pEntry->m_aContent.getPropertyValue(
818cdf0e10cSrcweir OUString::createFromAscii( "TargetURL" ) )
819cdf0e10cSrcweir >>= aTargetURL;
820cdf0e10cSrcweir }
821cdf0e10cSrcweir catch ( CommandAbortedException const & )
822cdf0e10cSrcweir {
823cdf0e10cSrcweir }
824cdf0e10cSrcweir catch ( RuntimeException const & )
825cdf0e10cSrcweir {
826cdf0e10cSrcweir throw;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir catch ( Exception const & )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir // The property is optional!
831cdf0e10cSrcweir }
832cdf0e10cSrcweir
833cdf0e10cSrcweir if ( aTargetURL.getLength() > 0 )
834cdf0e10cSrcweir {
835cdf0e10cSrcweir // Insert link.
836cdf0e10cSrcweir aText += OUString::createFromAscii( " --> " );
837cdf0e10cSrcweir aText += aTargetURL;
838cdf0e10cSrcweir }
839cdf0e10cSrcweir
840cdf0e10cSrcweir SetEntryText( pEntry, aText );
841cdf0e10cSrcweir }
842cdf0e10cSrcweir break;
843cdf0e10cSrcweir }
844cdf0e10cSrcweir
845cdf0e10cSrcweir case MENU_DELETE:
846cdf0e10cSrcweir {
847cdf0e10cSrcweir ULONG n = Application::ReleaseSolarMutex();
848cdf0e10cSrcweir sal_Bool bOK = sal_True;
849cdf0e10cSrcweir
850cdf0e10cSrcweir try
851cdf0e10cSrcweir {
852cdf0e10cSrcweir pEntry->m_aContent.executeCommand(
853cdf0e10cSrcweir OUString::createFromAscii( "delete" ),
854cdf0e10cSrcweir makeAny( sal_True ) );
855cdf0e10cSrcweir }
856cdf0e10cSrcweir catch ( CommandAbortedException const & )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir bOK = sal_False;
859cdf0e10cSrcweir }
860cdf0e10cSrcweir catch ( RuntimeException const & )
861cdf0e10cSrcweir {
862cdf0e10cSrcweir throw;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir catch ( Exception const & )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir bOK = sal_False;
867cdf0e10cSrcweir }
868cdf0e10cSrcweir
869cdf0e10cSrcweir Application::AcquireSolarMutex( n );
870cdf0e10cSrcweir
871cdf0e10cSrcweir if ( bOK )
872cdf0e10cSrcweir RemoveSelection();
873cdf0e10cSrcweir
874cdf0e10cSrcweir break;
875cdf0e10cSrcweir }
876cdf0e10cSrcweir
877cdf0e10cSrcweir default:
878cdf0e10cSrcweir {
879cdf0e10cSrcweir if ( ( nSelected > 20000 ) &&
880cdf0e10cSrcweir ( ( nSelected - 20000 ) <= aInfo.getLength() ) )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir // New-menu entry selected.
883cdf0e10cSrcweir
884cdf0e10cSrcweir ::ucbhelper::Content aNewContent;
885cdf0e10cSrcweir if ( pEntry->createNewContent(
886cdf0e10cSrcweir aInfo.getConstArray()[ nSelected - 20001 ],
887cdf0e10cSrcweir aNewContent ) )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir if ( !IsExpanded( pEntry ) )
890cdf0e10cSrcweir Expand( pEntry );
891cdf0e10cSrcweir else
892cdf0e10cSrcweir InsertEntry( aNewContent, pEntry );
893cdf0e10cSrcweir }
894cdf0e10cSrcweir }
895cdf0e10cSrcweir break;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir }
898cdf0e10cSrcweir
899cdf0e10cSrcweir delete pNewMenu;
900cdf0e10cSrcweir delete pMenu;
901cdf0e10cSrcweir return;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir }
904cdf0e10cSrcweir
905cdf0e10cSrcweir SvTreeListBox::Command( rCEvt );
906cdf0e10cSrcweir }
907cdf0e10cSrcweir
908cdf0e10cSrcweir //=========================================================================
InsertEntry(::ucbhelper::Content & rContent,SvLBoxEntry * pParent)909cdf0e10cSrcweir UcbExplorerListBoxEntry* UcbExplorerTreeListBox::InsertEntry(
910cdf0e10cSrcweir ::ucbhelper::Content& rContent,
911cdf0e10cSrcweir SvLBoxEntry* pParent )
912cdf0e10cSrcweir {
913cdf0e10cSrcweir try
914cdf0e10cSrcweir {
915cdf0e10cSrcweir OUString aTitle;
916cdf0e10cSrcweir rContent.getPropertyValue(
917cdf0e10cSrcweir OUString::createFromAscii( "Title" ) ) >>= aTitle;
918cdf0e10cSrcweir if ( !aTitle.getLength() )
919cdf0e10cSrcweir aTitle = OUString::createFromAscii( "/" );
920cdf0e10cSrcweir
921cdf0e10cSrcweir UcbExplorerListBoxEntry* pEntry = 0;
922cdf0e10cSrcweir
923cdf0e10cSrcweir if ( rContent.isFolder() )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir // Insert folder.
926cdf0e10cSrcweir pEntry = static_cast< UcbExplorerListBoxEntry * >(
927cdf0e10cSrcweir SvTreeListBox::InsertEntry( aTitle,
928cdf0e10cSrcweir m_aFolderOpened,
929cdf0e10cSrcweir m_aFolderClosed,
930cdf0e10cSrcweir pParent,
931cdf0e10cSrcweir TRUE ) );
932cdf0e10cSrcweir pEntry->m_eType = UcbExplorerListBoxEntry::FOLDER;
933cdf0e10cSrcweir }
934cdf0e10cSrcweir else
935cdf0e10cSrcweir {
936cdf0e10cSrcweir OUString aTargetURL;
937cdf0e10cSrcweir try
938cdf0e10cSrcweir {
939cdf0e10cSrcweir rContent.getPropertyValue(
940cdf0e10cSrcweir OUString::createFromAscii( "TargetURL" ) ) >>= aTargetURL;
941cdf0e10cSrcweir }
942cdf0e10cSrcweir catch ( CommandAbortedException const & )
943cdf0e10cSrcweir {
944cdf0e10cSrcweir }
945cdf0e10cSrcweir catch ( RuntimeException const & )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir throw;
948cdf0e10cSrcweir }
949cdf0e10cSrcweir catch ( Exception const & )
950cdf0e10cSrcweir {
951cdf0e10cSrcweir // The property is optional!
952cdf0e10cSrcweir }
953cdf0e10cSrcweir
954cdf0e10cSrcweir if ( aTargetURL.getLength() > 0 )
955cdf0e10cSrcweir {
956cdf0e10cSrcweir // Insert link.
957cdf0e10cSrcweir aTitle += OUString::createFromAscii( " --> " );
958cdf0e10cSrcweir aTitle += aTargetURL;
959cdf0e10cSrcweir pEntry = static_cast< UcbExplorerListBoxEntry * >(
960cdf0e10cSrcweir SvTreeListBox::InsertEntry( aTitle,
961cdf0e10cSrcweir m_aLink,
962cdf0e10cSrcweir m_aLink,
963cdf0e10cSrcweir pParent,
964cdf0e10cSrcweir TRUE ) );
965cdf0e10cSrcweir pEntry->m_eType = UcbExplorerListBoxEntry::LINK;
966cdf0e10cSrcweir }
967cdf0e10cSrcweir else
968cdf0e10cSrcweir {
969cdf0e10cSrcweir // Insert Document
970cdf0e10cSrcweir pEntry = static_cast< UcbExplorerListBoxEntry * >(
971cdf0e10cSrcweir SvTreeListBox::InsertEntry( aTitle,
972cdf0e10cSrcweir m_aDocument,
973cdf0e10cSrcweir m_aDocument,
974cdf0e10cSrcweir pParent,
975cdf0e10cSrcweir TRUE ) );
976cdf0e10cSrcweir pEntry->m_eType = UcbExplorerListBoxEntry::DOCUMENT;
977cdf0e10cSrcweir }
978cdf0e10cSrcweir }
979cdf0e10cSrcweir
980cdf0e10cSrcweir pEntry->m_aContent = rContent;
981cdf0e10cSrcweir return pEntry;
982cdf0e10cSrcweir }
983cdf0e10cSrcweir catch ( CommandAbortedException const & )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir }
986cdf0e10cSrcweir catch ( Exception const & )
987cdf0e10cSrcweir {
988cdf0e10cSrcweir }
989cdf0e10cSrcweir
990cdf0e10cSrcweir return 0;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir
993cdf0e10cSrcweir //=========================================================================
InsertEntry(const String & rURL,SvLBoxEntry * pParent)994cdf0e10cSrcweir UcbExplorerListBoxEntry* UcbExplorerTreeListBox::InsertEntry(
995cdf0e10cSrcweir const String& rURL,
996cdf0e10cSrcweir SvLBoxEntry* pParent )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir try
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir uno::Reference< XCommandEnvironment > xEnv;
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
1003cdf0e10cSrcweir if ( pBroker )
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir uno::Reference< XInteractionHandler > xInteractionHandler(
1006cdf0e10cSrcweir pBroker->getServiceManager()->createInstance(
1007cdf0e10cSrcweir OUString::createFromAscii(
1008cdf0e10cSrcweir "com.sun.star.task.InteractionHandler" ) ),
1009cdf0e10cSrcweir UNO_QUERY );
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir uno::Reference< XProgressHandler > xProgressHandler
1012cdf0e10cSrcweir /* = new ProgressHandler( *pBroker ) */ ;
1013cdf0e10cSrcweir
1014cdf0e10cSrcweir xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler,
1015cdf0e10cSrcweir xProgressHandler );
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir ::ucbhelper::Content aContent( rURL, xEnv );
1019cdf0e10cSrcweir return InsertEntry( aContent, pParent );
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir catch ( ContentCreationException const & )
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir
1025cdf0e10cSrcweir return 0;
1026cdf0e10cSrcweir }
1027cdf0e10cSrcweir
1028cdf0e10cSrcweir //=========================================================================
1029cdf0e10cSrcweir //
1030cdf0e10cSrcweir // UcbExplorerWindow implementation.
1031cdf0e10cSrcweir //
1032cdf0e10cSrcweir //=========================================================================
1033cdf0e10cSrcweir
UcbExplorerWindow(ResMgr & rResMgr,Window * pParent,WinBits nWinStyle)1034cdf0e10cSrcweir UcbExplorerWindow::UcbExplorerWindow( ResMgr & rResMgr, Window *pParent, WinBits nWinStyle )
1035cdf0e10cSrcweir : WorkWindow( pParent, nWinStyle ),
1036cdf0e10cSrcweir m_aTree( rResMgr, this, WB_HSCROLL )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir Font aTreeFont( m_aTree.GetFont() );
1039cdf0e10cSrcweir aTreeFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM("Courier") ) );
1040cdf0e10cSrcweir aTreeFont.SetFamily( FAMILY_MODERN );
1041cdf0e10cSrcweir aTreeFont.SetPitch( PITCH_FIXED );
1042cdf0e10cSrcweir aTreeFont.SetSize( Size( 0, 12 ) );
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir m_aTree.SetFont( aTreeFont );
1045cdf0e10cSrcweir m_aTree.SetIndent( 20 );
1046cdf0e10cSrcweir m_aTree.SetPosPixel( Point( 0, 0 ) );
1047cdf0e10cSrcweir
1048cdf0e10cSrcweir m_aTree.Show();
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir
1051cdf0e10cSrcweir //-------------------------------------------------------------------------
1052cdf0e10cSrcweir // virtual
~UcbExplorerWindow()1053cdf0e10cSrcweir UcbExplorerWindow::~UcbExplorerWindow()
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir
1057cdf0e10cSrcweir //-------------------------------------------------------------------------
1058cdf0e10cSrcweir // virtual
Resize()1059cdf0e10cSrcweir void UcbExplorerWindow::Resize()
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir m_aTree.SetSizePixel( GetOutputSizePixel() );
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir
1064cdf0e10cSrcweir //=========================================================================
1065cdf0e10cSrcweir //
1066cdf0e10cSrcweir // MyApp implementation.
1067cdf0e10cSrcweir //
1068cdf0e10cSrcweir //=========================================================================
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir // virtual
Main()1071cdf0e10cSrcweir void MyApp::Main()
1072cdf0e10cSrcweir {
1073cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1074cdf0e10cSrcweir // Initialize local Service Manager and basic services.
1075cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1076cdf0e10cSrcweir
1077cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xFac;
1078cdf0e10cSrcweir try
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir uno::Reference< XComponentContext > xCtx(
1081cdf0e10cSrcweir cppu::defaultBootstrap_InitialComponentContext() );
1082cdf0e10cSrcweir if ( !xCtx.is() )
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir DBG_ERROR( "Error creating initial component context!" );
1085cdf0e10cSrcweir return;
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir
1088cdf0e10cSrcweir xFac = uno::Reference< XMultiServiceFactory >(
1089cdf0e10cSrcweir xCtx->getServiceManager(), UNO_QUERY );
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir if ( !xFac.is() )
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir DBG_ERROR( "No service manager!" );
1094cdf0e10cSrcweir return;
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir catch ( com::sun::star::uno::Exception const & )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir DBG_ERROR( "Exception during creation of initial component context!" );
1100cdf0e10cSrcweir return;
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir comphelper::setProcessServiceFactory( xFac );
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir uno::Reference< XComponent > xComponent( xFac, UNO_QUERY );
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1108cdf0e10cSrcweir // Create UCB.
1109cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir #if 1
1112cdf0e10cSrcweir // Init UCB (Read configuration from registry)
1113cdf0e10cSrcweir Sequence< Any > aArgs( 2 );
1114cdf0e10cSrcweir aArgs[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
1115cdf0e10cSrcweir aArgs[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
1116cdf0e10cSrcweir sal_Bool bSuccess = ::ucbhelper::ContentBroker::initialize( xFac, aArgs );
1117cdf0e10cSrcweir #else
1118cdf0e10cSrcweir // Init UCB (Use provided configuration data)
1119cdf0e10cSrcweir ::ucbhelper::ContentProviderDataList aProviders;
1120cdf0e10cSrcweir aProviders.push_back(
1121cdf0e10cSrcweir ::ucbhelper::ContentProviderData(
1122cdf0e10cSrcweir OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ),
1123cdf0e10cSrcweir OUString::createFromAscii( "file" ),
1124cdf0e10cSrcweir OUString() ) );
1125cdf0e10cSrcweir sal_Bool bSuccess = ::ucbhelper::ContentBroker::initialize( xFac, aProviders );
1126cdf0e10cSrcweir #endif
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir if ( !bSuccess )
1129cdf0e10cSrcweir {
1130cdf0e10cSrcweir DBG_ERROR( "Error creating UCB!" );
1131cdf0e10cSrcweir return;
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir
1134cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1135cdf0e10cSrcweir // Create/init/show app window.
1136cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir std::auto_ptr< ResMgr > xManager(
1139cdf0e10cSrcweir ResMgr::CreateResMgr( CREATEVERSIONRESMGR_NAME( ucbexplorer ) ) );
1140cdf0e10cSrcweir
1141cdf0e10cSrcweir UcbExplorerWindow aAppWin( *xManager.get(), 0, WB_APP | WB_STDWORK );
1142cdf0e10cSrcweir
1143cdf0e10cSrcweir MenuBar aMBMain( ResId( MENU_MAIN, *xManager.get() ) );
1144cdf0e10cSrcweir
1145cdf0e10cSrcweir // Check for command line params
1146cdf0e10cSrcweir #if 0
1147cdf0e10cSrcweir for ( int i = 0; i < GetCommandLineParamCount(); ++i )
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir String aPara = GetCommandLineParam( i );
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir #endif
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir String aRootURL = GetCommandLineParam( 0 );
1154cdf0e10cSrcweir if ( aRootURL.Len() == 0 )
1155cdf0e10cSrcweir aRootURL = UniString::CreateFromAscii(
1156cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.hier:/" ) );
1157cdf0e10cSrcweir
1158cdf0e10cSrcweir String aTitle( ResId( TEXT_TITLEBAR, *xManager.get() ) );
1159cdf0e10cSrcweir aTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) );
1160cdf0e10cSrcweir aTitle += aRootURL;
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir aAppWin.SetText( aTitle );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir aAppWin.SetPosSizePixel( 0, 0, 500, 750 );
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir aAppWin.Show();
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir aAppWin.m_aTree.InsertEntry( aRootURL );
1169cdf0e10cSrcweir
1170cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1171cdf0e10cSrcweir // Execute app.
1172cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir Execute();
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1177cdf0e10cSrcweir // Cleanup.
1178cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1179cdf0e10cSrcweir
1180cdf0e10cSrcweir // m_aTree holds UCB contents!
1181cdf0e10cSrcweir aAppWin.m_aTree.Clear();
1182cdf0e10cSrcweir
1183cdf0e10cSrcweir ::ucbhelper::ContentBroker::deinitialize();
1184cdf0e10cSrcweir
1185cdf0e10cSrcweir if ( xComponent.is() )
1186cdf0e10cSrcweir xComponent->dispose();
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir //=========================================================================
1190cdf0e10cSrcweir //
1191cdf0e10cSrcweir // The Application.
1192cdf0e10cSrcweir //
1193cdf0e10cSrcweir //=========================================================================
1194cdf0e10cSrcweir
1195cdf0e10cSrcweir MyApp aMyApp;
1196cdf0e10cSrcweir
1197