1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ucbexplorer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
33 #include <cppuhelper/weak.hxx>
34 #include <cppuhelper/bootstrap.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/beans/XPropertySetInfo.hpp>
38 #include <com/sun/star/io/XActiveDataSink.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/sdbc/XResultSet.hpp>
41 #ifndef _COM_SUN_STAR_UCB_XCOMMMANDINFO_HPP_
42 #include <com/sun/star/ucb/XCommandInfo.hpp>
44 #include <com/sun/star/ucb/XContentAccess.hpp>
45 #include <com/sun/star/ucb/XContentCreator.hpp>
46 #include <com/sun/star/ucb/CommandAbortedException.hpp>
47 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
49 #include "rtl/ref.hxx"
50 #include <ucbhelper/content.hxx>
51 #include <ucbhelper/contentbroker.hxx>
52 #include <ucbhelper/commandenvironment.hxx>
53 #include <svtools/svtreebx.hxx>
54 #include <vcl/wrkwin.hxx>
55 #include <vcl/svapp.hxx>
56 #include <vcl/menu.hxx>
57 #include <vcl/dialog.hxx>
58 #include <vcl/fixed.hxx>
59 #include <vcl/group.hxx>
60 #ifndef _SV_BUTTON_HXX
61 #include <vcl/button.hxx>
63 #include <vcl/msgbox.hxx>
64 #include <ucbhelper/macros.hxx>
65 #include <ucbhelper/configurationkeys.hxx>
67 #ifndef _UCBEXPLORER_HRC
68 #include "ucbexplorer.hrc"
71 using namespace com::sun::star
;
72 using namespace com::sun::star::beans
;
73 using namespace com::sun::star::io
;
74 using namespace com::sun::star::lang
;
75 using namespace com::sun::star::sdbc
;
76 using namespace com::sun::star::task
;
77 using namespace com::sun::star::ucb
;
78 using namespace com::sun::star::uno
;
81 //=========================================================================
83 // class TestDataSink.
85 //=========================================================================
87 class TestDataSink
: public cppu::OWeakObject
, public XActiveDataSink
89 uno::Reference
< XInputStream
> m_xStream
;
93 // virtual ~TestDataSink();
96 virtual Any SAL_CALL
queryInterface( const Type
& rType
)
97 throw( RuntimeException
);
98 virtual void SAL_CALL
acquire()
100 virtual void SAL_CALL
release()
103 // XActiveDataSink methods.
104 virtual void SAL_CALL
setInputStream(
105 const uno::Reference
< XInputStream
>& aStream
)
106 throw( RuntimeException
);
107 virtual uno::Reference
< XInputStream
> SAL_CALL
getInputStream()
108 throw( RuntimeException
);
111 //=========================================================================
113 // class StringInputDialog.
115 //=========================================================================
117 class StringInputDialog
: public ModalDialog
120 FixedText m_aNameText
;
122 GroupBox m_aNameGroup
;
124 CancelButton m_aCancelBtn
;
125 HelpButton m_aHelpBtn
;
127 DECL_LINK( OKHdl
, Button
* );
128 DECL_LINK( NameHdl
, Edit
* );
131 StringInputDialog( const String
& rTitle
,
132 const String
& rDefaultText
,
133 String
* pGroupName
= 0 );
134 String
GetValue() const { return m_aNameEdit
.GetText(); }
135 void SetValue( const String
& rNewName
) { m_aNameEdit
.SetText( rNewName
); }
138 //=========================================================================
140 // class UcbExplorerListBoxEntry.
142 //=========================================================================
144 class UcbExplorerListBoxEntry
: public SvLBoxEntry
146 friend class UcbExplorerTreeListBox
;
148 enum EntryType
{ FOLDER
, DOCUMENT
, LINK
};
150 ::ucb::Content m_aContent
;
154 UcbExplorerListBoxEntry();
155 virtual ~UcbExplorerListBoxEntry();
157 BOOL
createNewContent( const ContentInfo
& rInfo
,
158 ::ucb::Content
& rNewContent
);
161 //=========================================================================
163 // class UcbExplorerTreeListBox.
165 //=========================================================================
167 class UcbExplorerTreeListBox
: public SvTreeListBox
169 Bitmap m_aFolderClosed
;
170 Bitmap m_aFolderOpened
;
175 virtual SvLBoxEntry
* CreateEntry() const;
176 virtual void RequestingChilds( SvLBoxEntry
* pParent
);
179 UcbExplorerTreeListBox( Window
* pParent
, WinBits nWinStyle
= 0 );
180 virtual ~UcbExplorerTreeListBox();
182 virtual void Command( const CommandEvent
& rCEvt
);
184 UcbExplorerListBoxEntry
*
185 InsertEntry( ::ucb::Content
& rContent
, SvLBoxEntry
* pParent
);
186 UcbExplorerListBoxEntry
*
187 InsertEntry( const String
& rURL
, SvLBoxEntry
* pParent
= 0 );
190 //=========================================================================
192 // class UcbExplorerWindow.
194 //=========================================================================
196 class UcbExplorerWindow
: public WorkWindow
200 UcbExplorerTreeListBox m_aTree
;
203 UcbExplorerWindow( Window
*pParent
, WinBits nWinStyle
);
204 virtual ~UcbExplorerWindow();
206 virtual void Resize();
209 //=========================================================================
213 //=========================================================================
215 class MyApp
: public Application
221 //=========================================================================
223 // TestDataSink implementation.
225 //=========================================================================
228 Any SAL_CALL
TestDataSink::queryInterface( const Type
& rType
)
229 throw( RuntimeException
)
231 Any aRet
= cppu::queryInterface(
233 static_cast< XActiveDataSink
* >( this ) );
234 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
237 //=========================================================================
239 void SAL_CALL
TestDataSink::acquire()
242 OWeakObject::acquire();
245 //=========================================================================
247 void SAL_CALL
TestDataSink::release()
250 OWeakObject::release();
253 //=========================================================================
255 void SAL_CALL
TestDataSink::setInputStream(
256 const uno::Reference
< XInputStream
>& aStream
)
257 throw( RuntimeException
)
262 //=========================================================================
264 uno::Reference
< XInputStream
> SAL_CALL
TestDataSink::getInputStream()
265 throw( RuntimeException
)
270 //=========================================================================
272 // StringInputDialog implementation.
274 //=========================================================================
276 StringInputDialog::StringInputDialog( const String
& rTitle
,
277 const String
& rDefaultText
,
279 : ModalDialog( 0, ResId( DLG_STRINGINPUT
) ),
280 m_aNameText ( this, ResId( FT_STRINGINPUT_DLG_NAME
) ),
281 m_aNameEdit ( this, ResId( ED_STRINGINPUT_DLG_NAME
) ),
282 m_aNameGroup( this, ResId( GB_STRINGINPUT_DLG_NAME
) ),
283 m_aOKBtn ( this, ResId( BT_STRINGINPUT_DLG_OK
) ),
284 m_aCancelBtn( this, ResId( BT_STRINGINPUT_DLG_CANCEL
) ),
285 m_aHelpBtn ( this, ResId( BT_STRINGINPUT_DLG_HELP
) )
289 m_aNameEdit
.SetText( rDefaultText
);
290 m_aOKBtn
.SetClickHdl( LINK( this, StringInputDialog
, OKHdl
) );
291 m_aNameEdit
.SetModifyHdl( LINK( this, StringInputDialog
, NameHdl
) );
294 m_aNameGroup
.SetText( *pGroupName
);
297 //=========================================================================
298 IMPL_LINK( StringInputDialog
, OKHdl
, Button
*, EMPTYARG
)
302 m_aNameEdit
.GetText().EraseLeadingChars().EraseTrailingChars() );
307 //=========================================================================
308 IMPL_LINK( StringInputDialog
, NameHdl
, Edit
*, EMPTYARG
)
312 String aName = m_aNameEdit.GetText();
313 aName.EraseLeadingChars().EraseTrailingChars();
316 if ( !m_aOKBtn.IsEnabled() )
317 m_aOKBtn.Enable( TRUE );
321 if ( m_aOKBtn.IsEnabled() )
322 m_aOKBtn.Enable( FALSE );
328 //=========================================================================
330 // UcbExplorerListBoxEntry implementation.
332 //=========================================================================
334 UcbExplorerListBoxEntry::UcbExplorerListBoxEntry()
338 //=========================================================================
340 UcbExplorerListBoxEntry::~UcbExplorerListBoxEntry()
344 //=========================================================================
345 BOOL
UcbExplorerListBoxEntry::createNewContent( const ContentInfo
& rInfo
,
346 ::ucb::Content
& rNewContent
)
348 sal_Int32 nCount
= rInfo
.Properties
.getLength();
349 Sequence
< Any
> aPropValues( nCount
);
350 Sequence
< OUString
> aPropNames( nCount
);
354 // Collect property values.
356 Any
* pValues
= aPropValues
.getArray();
357 const Property
* pProps
= rInfo
.Properties
.getConstArray();
358 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
360 const OUString
& rName
= pProps
[ n
].Name
;
361 StringInputDialog
* pDlg
= new StringInputDialog( rName
, rName
);
362 USHORT nRet
= pDlg
->Execute();
363 if ( nRet
== RET_OK
)
365 OUString
aValue( pDlg
->GetValue() );
367 // Convert value according to supplied type info...
369 const Type
& rType
= pProps
[ n
].Type
;
371 if ( rType
== getCppuType(
372 static_cast< const OUString
* >( 0 ) ) )
375 pValues
[ n
] <<= aValue
;
377 else if ( rType
== getCppuType(
378 static_cast< const sal_Int32
* >( 0 ) ) )
381 pValues
[ n
] <<= aValue
.toInt32();
383 else if ( rType
== getCppuType(
384 static_cast< const sal_Int16
* >( 0 ) ) )
387 pValues
[ n
] <<= sal_Int16( aValue
.toInt32() ) ;
389 else if ( rType
== getCppuBooleanType() )
392 pValues
[ n
] <<= sal_Bool( aValue
.toChar() ) ;
394 else if ( rType
== getCppuCharType() )
397 pValues
[ n
] <<= aValue
.toChar();
399 else if ( rType
== getCppuType(
400 static_cast< const sal_Int8
* >( 0 ) ) )
403 pValues
[ n
] <<= sal_Int8( aValue
.toChar() ) ;
405 else if ( rType
== getCppuType(
406 static_cast< const sal_Int64
* >( 0 ) ) )
409 pValues
[ n
] <<= aValue
.toInt64();
411 else if ( rType
== getCppuType(
412 static_cast< const float * >( 0 ) ) )
415 pValues
[ n
] <<= aValue
.toFloat();
417 else if ( rType
== getCppuType(
418 static_cast< const double * >( 0 ) ) )
421 pValues
[ n
] <<= aValue
.toDouble();
425 // See com/sun/star/ucb/ContentInfo.idl
426 DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
427 "Invlid type for bootstrap property!" );
433 if ( nRet
!= RET_OK
)
436 aPropNames
[ n
] = rName
;
440 uno::Reference
< XInputStream
> xData
;
442 if ( rInfo
.Attributes
& ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
)
444 // Let the user specify the URL of a content containing the
445 // data to supply to the new content.
447 StringInputDialog
* pDlg
= new StringInputDialog(
448 OUString::createFromAscii(
449 "Document Data Source URL" ),
451 USHORT nRet
= pDlg
->Execute();
452 if ( nRet
== RET_OK
)
454 // Create a content object for the given URL.
456 OUString
aSourceURL( pDlg
->GetValue() );
457 if ( aSourceURL
.getLength() == 0 )
459 DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
460 "No document data URL!" );
466 uno::Reference
< XCommandEnvironment
> xEnv
;
468 ::ucb::ContentBroker
* pBroker
= ::ucb::ContentBroker::get();
471 uno::Reference
< XInteractionHandler
> xInteractionHandler(
472 pBroker
->getServiceManager()->createInstance(
473 OUString::createFromAscii(
474 "com.sun.star.task.InteractionHandler" ) ),
477 uno::Reference
< XProgressHandler
> xProgressHandler
478 /* = new ProgressHandler( *pBroker ) */ ;
480 xEnv
= new ::ucb::CommandEnvironment( xInteractionHandler
,
484 ::ucb::Content
aSourceContent( aSourceURL
, xEnv
);
487 rtl::Reference
< TestDataSink
> xSourceData
= new TestDataSink
;
488 aSourceContent
.openStream( xSourceData
.getBodyPtr() );
489 xData
= xSourceData
->getInputStream();
491 catch ( ContentCreationException
const & )
493 DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
494 "No content for document data!" );
497 catch ( CommandAbortedException
const & )
501 catch ( RuntimeException
const & )
505 catch ( Exception
const & )
513 if ( nRet
!= RET_OK
)
517 // Create new content.
519 ULONG n
= Application::ReleaseSolarMutex();
520 BOOL bRet
= sal_False
;
524 bRet
= m_aContent
.insertNewContent(
525 rInfo
.Type
, aPropNames
, aPropValues
, xData
, rNewContent
);
527 catch ( CommandAbortedException
const & )
530 catch ( RuntimeException
const & )
534 catch ( Exception
const & )
538 Application::AcquireSolarMutex( n
);
542 //=========================================================================
544 // UcbExplorerTreeListBox implementation.
546 //=========================================================================
548 UcbExplorerTreeListBox::UcbExplorerTreeListBox(
549 Window
* pParent
, WinBits nWinStyle
)
550 : SvTreeListBox( pParent
, nWinStyle
),
551 m_aFolderClosed( ResId( BMP_FOLDER_CLOSED
) ),
552 m_aFolderOpened( ResId( BMP_FOLDER_OPENED
) ),
553 m_aDocument( ResId( BMP_DOCUMENT
) ),
554 m_aLink( ResId( BMP_LINK
) )
558 //=========================================================================
560 UcbExplorerTreeListBox::~UcbExplorerTreeListBox()
564 //=========================================================================
566 SvLBoxEntry
* UcbExplorerTreeListBox::CreateEntry() const
568 return new UcbExplorerListBoxEntry();
571 //=========================================================================
573 void UcbExplorerTreeListBox::RequestingChilds( SvLBoxEntry
* pParent
)
575 UcbExplorerListBoxEntry
* pEntry
576 = static_cast< UcbExplorerListBoxEntry
* >( pParent
);
577 if ( !pEntry
->HasChilds() )
579 switch ( pEntry
->m_eType
)
581 case UcbExplorerListBoxEntry::FOLDER
:
583 ULONG n
= Application::ReleaseSolarMutex();
587 Sequence
< OUString
> aPropertyNames( 0 );
588 // OUString* pNames = aPropertyNames.getArray();
589 // pNames[ 0 ] = OUString::createFromAscii( "Title" );
591 uno::Reference
< XResultSet
> xResultSet
592 = pEntry
->m_aContent
.createCursor(
594 ::ucb::INCLUDE_FOLDERS_AND_DOCUMENTS
);
595 uno::Reference
< XContentAccess
> xContentAccess(
596 xResultSet
, UNO_QUERY
);
598 if ( xResultSet
.is() && xContentAccess
.is() )
600 while ( xResultSet
->next() )
602 Application::AcquireSolarMutex( n
);
605 xContentAccess
->queryContentIdentifierString(),
608 n
= Application::ReleaseSolarMutex();
612 catch ( CommandAbortedException
const & )
615 catch ( RuntimeException
const & )
619 catch ( Exception
const & )
623 Application::AcquireSolarMutex( n
);
627 case UcbExplorerListBoxEntry::DOCUMENT
:
630 case UcbExplorerListBoxEntry::LINK
:
639 //=========================================================================
641 void UcbExplorerTreeListBox::Command( const CommandEvent
& rCEvt
)
643 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
645 const Point
& rPos
= rCEvt
.GetMousePosPixel();
646 UcbExplorerListBoxEntry
* pEntry
647 = static_cast< UcbExplorerListBoxEntry
* >(
648 GetEntry( rPos
, TRUE
) );
651 PopupMenu
* pMenu
= new PopupMenu( ResId( MENU_POPUP
) );
652 PopupMenu
* pNewMenu
= 0;
654 // pMenu->SetSelectHdl( LINK( this,
655 // SfxCommonTemplateDialog_Impl,
656 // MenuSelectHdl ) );
658 //////////////////////////////////////////////////////////////
660 //////////////////////////////////////////////////////////////
662 uno::Reference
< XContentCreator
> xCreator(
663 pEntry
->m_aContent
.get(), UNO_QUERY
);
664 Sequence
< ContentInfo
> aInfo
;
665 BOOL bCanCreate
= xCreator
.is();
668 aInfo
= xCreator
->queryCreatableContentsInfo();
669 const ContentInfo
* pInfo
= aInfo
.getConstArray();
670 sal_Int32 nCount
= aInfo
.getLength();
671 bCanCreate
= ( nCount
> 0 );
673 pNewMenu
= new PopupMenu
;
674 pMenu
->SetPopupMenu( MENU_NEW
, pNewMenu
);
676 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
678 const ContentInfo
& rInfo
= pInfo
[ n
];
679 pNewMenu
->InsertItem( 20000 + n
+ 1, rInfo
.Type
);
683 pMenu
->EnableItem( MENU_NEW
, bCanCreate
);
685 //////////////////////////////////////////////////////////////
686 // Configure "Rename"
687 //////////////////////////////////////////////////////////////
689 sal_Bool bEnable
= sal_False
;
694 pEntry
->m_aContent
.getProperties()->getPropertyByName(
695 OUString::createFromAscii( "Title" ) );
696 bEnable
= !( aProp
.Attributes
& PropertyAttribute::READONLY
);
698 catch( UnknownPropertyException
const & )
703 catch ( CommandAbortedException
const & )
706 catch ( RuntimeException
const & )
710 catch ( Exception
const & )
714 pMenu
->EnableItem( MENU_RENAME
, bEnable
);
716 //////////////////////////////////////////////////////////////
717 // Configure "Delete"
718 //////////////////////////////////////////////////////////////
722 pMenu
->EnableItem( MENU_DELETE
,
724 .getCommands()->hasCommandByName(
725 OUString::createFromAscii(
728 catch ( CommandAbortedException
const & )
731 catch ( RuntimeException
const & )
735 catch ( Exception
const & )
739 //////////////////////////////////////////////////////////////
741 //////////////////////////////////////////////////////////////
743 USHORT nSelected
= pMenu
->Execute( this, rPos
);
755 pEntry
->m_aContent
.getPropertyValue(
756 OUString::createFromAscii( "Title" ) )
759 catch ( CommandAbortedException
const & )
762 catch ( RuntimeException
const & )
766 catch ( Exception
const & )
770 StringInputDialog
* pDlg
771 = new StringInputDialog(
772 OUString::createFromAscii( "Title" ),
775 USHORT nRet
= pDlg
->Execute();
779 if ( nRet
== RET_OK
)
781 aNewTitle
= pDlg
->GetValue();
782 aValue
<<= aNewTitle
;
787 if ( nRet
!= RET_OK
)
790 sal_Bool bOK
= sal_False
;
792 ULONG n
= Application::ReleaseSolarMutex();
796 pEntry
->m_aContent
.setPropertyValue(
797 OUString::createFromAscii( "Title" ),
801 catch ( CommandAbortedException
const & )
804 catch ( RuntimeException
const & )
808 catch ( Exception
const & )
812 Application::AcquireSolarMutex( n
);
816 OUString
aText( aNewTitle
);
820 pEntry
->m_aContent
.getPropertyValue(
821 OUString::createFromAscii( "TargetURL" ) )
824 catch ( CommandAbortedException
const & )
827 catch ( RuntimeException
const & )
831 catch ( Exception
const & )
833 // The property is optional!
836 if ( aTargetURL
.getLength() > 0 )
839 aText
+= OUString::createFromAscii( " --> " );
843 SetEntryText( pEntry
, aText
);
850 ULONG n
= Application::ReleaseSolarMutex();
851 sal_Bool bOK
= sal_True
;
855 pEntry
->m_aContent
.executeCommand(
856 OUString::createFromAscii( "delete" ),
857 makeAny( sal_True
) );
859 catch ( CommandAbortedException
const & )
863 catch ( RuntimeException
const & )
867 catch ( Exception
const & )
872 Application::AcquireSolarMutex( n
);
882 if ( ( nSelected
> 20000 ) &&
883 ( ( nSelected
- 20000 ) <= aInfo
.getLength() ) )
885 // New-menu entry selected.
887 ::ucb::Content aNewContent
;
888 if ( pEntry
->createNewContent(
889 aInfo
.getConstArray()[ nSelected
- 20001 ],
892 if ( !IsExpanded( pEntry
) )
895 InsertEntry( aNewContent
, pEntry
);
908 SvTreeListBox::Command( rCEvt
);
911 //=========================================================================
912 UcbExplorerListBoxEntry
* UcbExplorerTreeListBox::InsertEntry(
913 ::ucb::Content
& rContent
,
914 SvLBoxEntry
* pParent
)
919 rContent
.getPropertyValue(
920 OUString::createFromAscii( "Title" ) ) >>= aTitle
;
921 if ( !aTitle
.getLength() )
922 aTitle
= OUString::createFromAscii( "/" );
924 UcbExplorerListBoxEntry
* pEntry
= 0;
926 if ( rContent
.isFolder() )
929 pEntry
= static_cast< UcbExplorerListBoxEntry
* >(
930 SvTreeListBox::InsertEntry( aTitle
,
935 pEntry
->m_eType
= UcbExplorerListBoxEntry::FOLDER
;
942 rContent
.getPropertyValue(
943 OUString::createFromAscii( "TargetURL" ) ) >>= aTargetURL
;
945 catch ( CommandAbortedException
const & )
948 catch ( RuntimeException
const & )
952 catch ( Exception
const & )
954 // The property is optional!
957 if ( aTargetURL
.getLength() > 0 )
960 aTitle
+= OUString::createFromAscii( " --> " );
961 aTitle
+= aTargetURL
;
962 pEntry
= static_cast< UcbExplorerListBoxEntry
* >(
963 SvTreeListBox::InsertEntry( aTitle
,
968 pEntry
->m_eType
= UcbExplorerListBoxEntry::LINK
;
973 pEntry
= static_cast< UcbExplorerListBoxEntry
* >(
974 SvTreeListBox::InsertEntry( aTitle
,
979 pEntry
->m_eType
= UcbExplorerListBoxEntry::DOCUMENT
;
983 pEntry
->m_aContent
= rContent
;
986 catch ( CommandAbortedException
const & )
989 catch ( Exception
const & )
996 //=========================================================================
997 UcbExplorerListBoxEntry
* UcbExplorerTreeListBox::InsertEntry(
999 SvLBoxEntry
* pParent
)
1003 uno::Reference
< XCommandEnvironment
> xEnv
;
1005 ::ucb::ContentBroker
* pBroker
= ::ucb::ContentBroker::get();
1008 uno::Reference
< XInteractionHandler
> xInteractionHandler(
1009 pBroker
->getServiceManager()->createInstance(
1010 OUString::createFromAscii(
1011 "com.sun.star.task.InteractionHandler" ) ),
1014 uno::Reference
< XProgressHandler
> xProgressHandler
1015 /* = new ProgressHandler( *pBroker ) */ ;
1017 xEnv
= new ::ucb::CommandEnvironment( xInteractionHandler
,
1021 ::ucb::Content
aContent( rURL
, xEnv
);
1022 return InsertEntry( aContent
, pParent
);
1024 catch ( ContentCreationException
const & )
1031 //=========================================================================
1033 // UcbExplorerWindow implementation.
1035 //=========================================================================
1037 UcbExplorerWindow::UcbExplorerWindow( Window
*pParent
, WinBits nWinStyle
)
1038 : WorkWindow( pParent
, nWinStyle
),
1039 m_aTree( this, WB_HSCROLL
)
1041 Font
aTreeFont( m_aTree
.GetFont() );
1042 aTreeFont
.SetName( String( RTL_CONSTASCII_USTRINGPARAM("Courier") ) );
1043 aTreeFont
.SetFamily( FAMILY_MODERN
);
1044 aTreeFont
.SetPitch( PITCH_FIXED
);
1045 aTreeFont
.SetSize( Size( 0, 12 ) );
1047 m_aTree
.SetFont( aTreeFont
);
1048 m_aTree
.SetIndent( 20 );
1049 m_aTree
.SetPosPixel( Point( 0, 0 ) );
1054 //-------------------------------------------------------------------------
1056 UcbExplorerWindow::~UcbExplorerWindow()
1060 //-------------------------------------------------------------------------
1062 void UcbExplorerWindow::Resize()
1064 m_aTree
.SetSizePixel( GetOutputSizePixel() );
1067 //=========================================================================
1069 // MyApp implementation.
1071 //=========================================================================
1076 //////////////////////////////////////////////////////////////////////
1077 // Initialize local Service Manager and basic services.
1078 //////////////////////////////////////////////////////////////////////
1080 uno::Reference
< XMultiServiceFactory
> xFac
;
1083 uno::Reference
< XComponentContext
> xCtx(
1084 cppu::defaultBootstrap_InitialComponentContext() );
1087 DBG_ERROR( "Error creating initial component context!" );
1091 xFac
= uno::Reference
< XMultiServiceFactory
>(
1092 xCtx
->getServiceManager(), UNO_QUERY
);
1096 DBG_ERROR( "No service manager!" );
1100 catch ( com::sun::star::uno::Exception
const & )
1102 DBG_ERROR( "Exception during creation of initial component context!" );
1106 comphelper::setProcessServiceFactory( xFac
);
1108 unO::Reference
< XComponent
> xComponent( xFac
, UNO_QUERY
);
1110 //////////////////////////////////////////////////////////////////////
1112 //////////////////////////////////////////////////////////////////////
1115 // Init UCB (Read configuration from registry)
1116 Sequence
< Any
> aArgs( 2 );
1117 aArgs
[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL
);
1118 aArgs
[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE
);
1119 sal_Bool bSuccess
= ::ucb::ContentBroker::initialize( xFac
, aArgs
);
1121 // Init UCB (Use provided configuration data)
1122 ::ucb::ContentProviderDataList aProviders
;
1123 aProviders
.push_back(
1124 ::ucb::ContentProviderData(
1125 OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ),
1126 OUString::createFromAscii( "file" ),
1128 sal_Bool bSuccess
= ::ucb::ContentBroker::initialize( xFac
, aProviders
);
1133 DBG_ERROR( "Error creating UCB!" );
1137 //////////////////////////////////////////////////////////////////////
1138 // Create/init/show app window.
1139 //////////////////////////////////////////////////////////////////////
1141 ResMgr
* pMgr
= ResMgr::CreateResMgr( CREATEVERSIONRESMGR( ucbexplorer
) );
1142 Resource::SetResManager( pMgr
);
1144 UcbExplorerWindow
aAppWin( 0, WB_APP
| WB_STDWORK
);
1146 MenuBar
aMBMain( ResId( MENU_MAIN
) );
1148 // Check for command line params
1150 for ( int i
= 0; i
< GetCommandLineParamCount(); ++i
)
1152 String aPara
= GetCommandLineParam( i
);
1156 String aRootURL
= GetCommandLineParam( 0 );
1157 if ( aRootURL
.Len() == 0 )
1158 aRootURL
= UniString::CreateFromAscii(
1159 RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.hier:/" ) );
1161 String
aTitle( ResId( TEXT_TITLEBAR
) );
1162 aTitle
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) );
1165 aAppWin
.SetText( aTitle
);
1167 aAppWin
.SetPosSizePixel( 0, 0, 500, 750 );
1171 aAppWin
.m_aTree
.InsertEntry( aRootURL
);
1173 //////////////////////////////////////////////////////////////////////
1175 //////////////////////////////////////////////////////////////////////
1179 //////////////////////////////////////////////////////////////////////
1181 //////////////////////////////////////////////////////////////////////
1183 // m_aTree holds UCB contents!
1184 aAppWin
.m_aTree
.Clear();
1186 ::ucb::ContentBroker::deinitialize();
1188 if ( xComponent
.is() )
1189 xComponent
->dispose();
1192 //=========================================================================
1196 //=========================================================================