update dev300-m58
[ooovba.git] / ucbhelper / workben / ucbexplorer / ucbexplorer.cxx
blob4f2c03c81f276526e1f272f8830188bc34af5b9c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ucbexplorer.cxx,v $
10 * $Revision: 1.18 $
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>
43 #endif
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>
62 #endif
63 #include <vcl/msgbox.hxx>
64 #include <ucbhelper/macros.hxx>
65 #include <ucbhelper/configurationkeys.hxx>
67 #ifndef _UCBEXPLORER_HRC
68 #include "ucbexplorer.hrc"
69 #endif
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;
79 using namespace rtl;
81 //=========================================================================
83 // class TestDataSink.
85 //=========================================================================
87 class TestDataSink : public cppu::OWeakObject, public XActiveDataSink
89 uno::Reference< XInputStream > m_xStream;
91 public:
92 // TestDataSink() {}
93 // virtual ~TestDataSink();
95 // XInterface methods
96 virtual Any SAL_CALL queryInterface( const Type & rType )
97 throw( RuntimeException );
98 virtual void SAL_CALL acquire()
99 throw ();
100 virtual void SAL_CALL release()
101 throw ();
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
119 private:
120 FixedText m_aNameText;
121 Edit m_aNameEdit;
122 GroupBox m_aNameGroup;
123 OKButton m_aOKBtn;
124 CancelButton m_aCancelBtn;
125 HelpButton m_aHelpBtn;
127 DECL_LINK( OKHdl, Button * );
128 DECL_LINK( NameHdl, Edit * );
130 public:
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;
151 EntryType m_eType;
153 public:
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;
171 Bitmap m_aDocument;
172 Bitmap m_aLink;
174 private:
175 virtual SvLBoxEntry* CreateEntry() const;
176 virtual void RequestingChilds( SvLBoxEntry* pParent );
178 public:
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
198 friend class MyApp;
200 UcbExplorerTreeListBox m_aTree;
202 public:
203 UcbExplorerWindow( Window *pParent, WinBits nWinStyle );
204 virtual ~UcbExplorerWindow();
206 virtual void Resize();
209 //=========================================================================
211 // class MyApp.
213 //=========================================================================
215 class MyApp : public Application
217 public:
218 virtual void Main();
221 //=========================================================================
223 // TestDataSink implementation.
225 //=========================================================================
227 // virtual
228 Any SAL_CALL TestDataSink::queryInterface( const Type & rType )
229 throw( RuntimeException )
231 Any aRet = cppu::queryInterface(
232 rType,
233 static_cast< XActiveDataSink * >( this ) );
234 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
237 //=========================================================================
238 // virtual
239 void SAL_CALL TestDataSink::acquire()
240 throw()
242 OWeakObject::acquire();
245 //=========================================================================
246 // virtual
247 void SAL_CALL TestDataSink::release()
248 throw()
250 OWeakObject::release();
253 //=========================================================================
254 // virtual
255 void SAL_CALL TestDataSink::setInputStream(
256 const uno::Reference< XInputStream >& aStream )
257 throw( RuntimeException )
259 m_xStream = aStream;
262 //=========================================================================
263 // virtual
264 uno::Reference< XInputStream > SAL_CALL TestDataSink::getInputStream()
265 throw( RuntimeException )
267 return m_xStream;
270 //=========================================================================
272 // StringInputDialog implementation.
274 //=========================================================================
276 StringInputDialog::StringInputDialog( const String& rTitle,
277 const String& rDefaultText,
278 String* pGroupName )
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 ) )
287 FreeResource();
288 SetText( rTitle );
289 m_aNameEdit.SetText( rDefaultText );
290 m_aOKBtn.SetClickHdl( LINK( this, StringInputDialog, OKHdl ) );
291 m_aNameEdit.SetModifyHdl( LINK( this, StringInputDialog, NameHdl ) );
293 if ( pGroupName )
294 m_aNameGroup.SetText( *pGroupName );
297 //=========================================================================
298 IMPL_LINK( StringInputDialog, OKHdl, Button *, EMPTYARG )
300 // trim the strings
301 m_aNameEdit.SetText(
302 m_aNameEdit.GetText().EraseLeadingChars().EraseTrailingChars() );
303 EndDialog( RET_OK );
304 return 1;
307 //=========================================================================
308 IMPL_LINK( StringInputDialog, NameHdl, Edit *, EMPTYARG )
311 // trim the strings
312 String aName = m_aNameEdit.GetText();
313 aName.EraseLeadingChars().EraseTrailingChars();
314 if ( aName.Len() )
316 if ( !m_aOKBtn.IsEnabled() )
317 m_aOKBtn.Enable( TRUE );
319 else
321 if ( m_aOKBtn.IsEnabled() )
322 m_aOKBtn.Enable( FALSE );
325 return 0;
328 //=========================================================================
330 // UcbExplorerListBoxEntry implementation.
332 //=========================================================================
334 UcbExplorerListBoxEntry::UcbExplorerListBoxEntry()
338 //=========================================================================
339 // virtual
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 );
352 if ( nCount > 0 )
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 ) ) )
374 // string
375 pValues[ n ] <<= aValue;
377 else if ( rType == getCppuType(
378 static_cast< const sal_Int32 * >( 0 ) ) )
380 // long
381 pValues[ n ] <<= aValue.toInt32();
383 else if ( rType == getCppuType(
384 static_cast< const sal_Int16 * >( 0 ) ) )
386 // short
387 pValues[ n ] <<= sal_Int16( aValue.toInt32() ) ;
389 else if ( rType == getCppuBooleanType() )
391 // boolean
392 pValues[ n ] <<= sal_Bool( aValue.toChar() ) ;
394 else if ( rType == getCppuCharType() )
396 // char
397 pValues[ n ] <<= aValue.toChar();
399 else if ( rType == getCppuType(
400 static_cast< const sal_Int8 * >( 0 ) ) )
402 // byte
403 pValues[ n ] <<= sal_Int8( aValue.toChar() ) ;
405 else if ( rType == getCppuType(
406 static_cast< const sal_Int64 * >( 0 ) ) )
408 // hyper
409 pValues[ n ] <<= aValue.toInt64();
411 else if ( rType == getCppuType(
412 static_cast< const float * >( 0 ) ) )
414 // float
415 pValues[ n ] <<= aValue.toFloat();
417 else if ( rType == getCppuType(
418 static_cast< const double * >( 0 ) ) )
420 // double
421 pValues[ n ] <<= aValue.toDouble();
423 else
425 // See com/sun/star/ucb/ContentInfo.idl
426 DBG_ERROR( "UcbExplorerListBoxEntry::createNewContent - "
427 "Invlid type for bootstrap property!" );
431 delete pDlg;
433 if ( nRet != RET_OK )
434 return FALSE;
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" ),
450 OUString() );
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!" );
461 return FALSE;
466 uno::Reference< XCommandEnvironment > xEnv;
468 ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
469 if ( pBroker )
471 uno::Reference< XInteractionHandler > xInteractionHandler(
472 pBroker->getServiceManager()->createInstance(
473 OUString::createFromAscii(
474 "com.sun.star.task.InteractionHandler" ) ),
475 UNO_QUERY );
477 uno::Reference< XProgressHandler > xProgressHandler
478 /* = new ProgressHandler( *pBroker ) */ ;
480 xEnv = new ::ucb::CommandEnvironment( xInteractionHandler,
481 xProgressHandler );
484 ::ucb::Content aSourceContent( aSourceURL, xEnv );
486 // Get source data.
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!" );
495 return FALSE;
497 catch ( CommandAbortedException const & )
499 return FALSE;
501 catch ( RuntimeException const & )
503 throw;
505 catch ( Exception const & )
507 return FALSE;
511 delete pDlg;
513 if ( nRet != RET_OK )
514 return FALSE;
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 & )
532 throw;
534 catch ( Exception const & )
538 Application::AcquireSolarMutex( n );
539 return bRet;
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 //=========================================================================
559 // virtual
560 UcbExplorerTreeListBox::~UcbExplorerTreeListBox()
564 //=========================================================================
565 // virtual
566 SvLBoxEntry* UcbExplorerTreeListBox::CreateEntry() const
568 return new UcbExplorerListBoxEntry();
571 //=========================================================================
572 // virtual
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(
593 aPropertyNames,
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 );
604 InsertEntry(
605 xContentAccess->queryContentIdentifierString(),
606 pParent );
608 n = Application::ReleaseSolarMutex();
612 catch ( CommandAbortedException const & )
615 catch ( RuntimeException const & )
617 throw;
619 catch ( Exception const & )
623 Application::AcquireSolarMutex( n );
624 break;
627 case UcbExplorerListBoxEntry::DOCUMENT:
628 break;
630 case UcbExplorerListBoxEntry::LINK:
631 break;
633 default:
634 break;
639 //=========================================================================
640 // virtual
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 ) );
649 if ( pEntry )
651 PopupMenu* pMenu = new PopupMenu( ResId( MENU_POPUP ) );
652 PopupMenu* pNewMenu = 0;
654 // pMenu->SetSelectHdl( LINK( this,
655 // SfxCommonTemplateDialog_Impl,
656 // MenuSelectHdl ) );
658 //////////////////////////////////////////////////////////////
659 // Configure "New"
660 //////////////////////////////////////////////////////////////
662 uno::Reference< XContentCreator > xCreator(
663 pEntry->m_aContent.get(), UNO_QUERY );
664 Sequence< ContentInfo > aInfo;
665 BOOL bCanCreate = xCreator.is();
666 if ( bCanCreate )
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;
693 Property aProp =
694 pEntry->m_aContent.getProperties()->getPropertyByName(
695 OUString::createFromAscii( "Title" ) );
696 bEnable = !( aProp.Attributes & PropertyAttribute::READONLY );
698 catch( UnknownPropertyException const & )
700 // getPropertyByName
701 bEnable = sal_False;
703 catch ( CommandAbortedException const & )
706 catch ( RuntimeException const & )
708 throw;
710 catch ( Exception const & )
714 pMenu->EnableItem( MENU_RENAME, bEnable );
716 //////////////////////////////////////////////////////////////
717 // Configure "Delete"
718 //////////////////////////////////////////////////////////////
722 pMenu->EnableItem( MENU_DELETE,
723 pEntry->m_aContent
724 .getCommands()->hasCommandByName(
725 OUString::createFromAscii(
726 "delete" ) ) );
728 catch ( CommandAbortedException const & )
731 catch ( RuntimeException const & )
733 throw;
735 catch ( Exception const & )
739 //////////////////////////////////////////////////////////////
740 // Execute menu.
741 //////////////////////////////////////////////////////////////
743 USHORT nSelected = pMenu->Execute( this, rPos );
744 switch ( nSelected )
746 // case MENU_NEW:
747 // break;
749 case MENU_RENAME:
751 OUString aNewTitle;
755 pEntry->m_aContent.getPropertyValue(
756 OUString::createFromAscii( "Title" ) )
757 >>= aNewTitle;
759 catch ( CommandAbortedException const & )
762 catch ( RuntimeException const & )
764 throw;
766 catch ( Exception const & )
770 StringInputDialog* pDlg
771 = new StringInputDialog(
772 OUString::createFromAscii( "Title" ),
773 aNewTitle );
775 USHORT nRet = pDlg->Execute();
777 Any aValue;
779 if ( nRet == RET_OK )
781 aNewTitle = pDlg->GetValue();
782 aValue <<= aNewTitle;
785 delete pDlg;
787 if ( nRet != RET_OK )
788 break;
790 sal_Bool bOK = sal_False;
792 ULONG n = Application::ReleaseSolarMutex();
796 pEntry->m_aContent.setPropertyValue(
797 OUString::createFromAscii( "Title" ),
798 aValue );
799 bOK = sal_True;
801 catch ( CommandAbortedException const & )
804 catch ( RuntimeException const & )
806 throw;
808 catch ( Exception const & )
812 Application::AcquireSolarMutex( n );
814 if ( bOK )
816 OUString aText( aNewTitle );
817 OUString aTargetURL;
820 pEntry->m_aContent.getPropertyValue(
821 OUString::createFromAscii( "TargetURL" ) )
822 >>= aTargetURL;
824 catch ( CommandAbortedException const & )
827 catch ( RuntimeException const & )
829 throw;
831 catch ( Exception const & )
833 // The property is optional!
836 if ( aTargetURL.getLength() > 0 )
838 // Insert link.
839 aText += OUString::createFromAscii( " --> " );
840 aText += aTargetURL;
843 SetEntryText( pEntry, aText );
845 break;
848 case MENU_DELETE:
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 & )
861 bOK = sal_False;
863 catch ( RuntimeException const & )
865 throw;
867 catch ( Exception const & )
869 bOK = sal_False;
872 Application::AcquireSolarMutex( n );
874 if ( bOK )
875 RemoveSelection();
877 break;
880 default:
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 ],
890 aNewContent ) )
892 if ( !IsExpanded( pEntry ) )
893 Expand( pEntry );
894 else
895 InsertEntry( aNewContent, pEntry );
898 break;
902 delete pNewMenu;
903 delete pMenu;
904 return;
908 SvTreeListBox::Command( rCEvt );
911 //=========================================================================
912 UcbExplorerListBoxEntry* UcbExplorerTreeListBox::InsertEntry(
913 ::ucb::Content& rContent,
914 SvLBoxEntry* pParent )
918 OUString aTitle;
919 rContent.getPropertyValue(
920 OUString::createFromAscii( "Title" ) ) >>= aTitle;
921 if ( !aTitle.getLength() )
922 aTitle = OUString::createFromAscii( "/" );
924 UcbExplorerListBoxEntry* pEntry = 0;
926 if ( rContent.isFolder() )
928 // Insert folder.
929 pEntry = static_cast< UcbExplorerListBoxEntry * >(
930 SvTreeListBox::InsertEntry( aTitle,
931 m_aFolderOpened,
932 m_aFolderClosed,
933 pParent,
934 TRUE ) );
935 pEntry->m_eType = UcbExplorerListBoxEntry::FOLDER;
937 else
939 OUString aTargetURL;
942 rContent.getPropertyValue(
943 OUString::createFromAscii( "TargetURL" ) ) >>= aTargetURL;
945 catch ( CommandAbortedException const & )
948 catch ( RuntimeException const & )
950 throw;
952 catch ( Exception const & )
954 // The property is optional!
957 if ( aTargetURL.getLength() > 0 )
959 // Insert link.
960 aTitle += OUString::createFromAscii( " --> " );
961 aTitle += aTargetURL;
962 pEntry = static_cast< UcbExplorerListBoxEntry * >(
963 SvTreeListBox::InsertEntry( aTitle,
964 m_aLink,
965 m_aLink,
966 pParent,
967 TRUE ) );
968 pEntry->m_eType = UcbExplorerListBoxEntry::LINK;
970 else
972 // Insert Document
973 pEntry = static_cast< UcbExplorerListBoxEntry * >(
974 SvTreeListBox::InsertEntry( aTitle,
975 m_aDocument,
976 m_aDocument,
977 pParent,
978 TRUE ) );
979 pEntry->m_eType = UcbExplorerListBoxEntry::DOCUMENT;
983 pEntry->m_aContent = rContent;
984 return pEntry;
986 catch ( CommandAbortedException const & )
989 catch ( Exception const & )
993 return 0;
996 //=========================================================================
997 UcbExplorerListBoxEntry* UcbExplorerTreeListBox::InsertEntry(
998 const String& rURL,
999 SvLBoxEntry* pParent )
1003 uno::Reference< XCommandEnvironment > xEnv;
1005 ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
1006 if ( pBroker )
1008 uno::Reference< XInteractionHandler > xInteractionHandler(
1009 pBroker->getServiceManager()->createInstance(
1010 OUString::createFromAscii(
1011 "com.sun.star.task.InteractionHandler" ) ),
1012 UNO_QUERY );
1014 uno::Reference< XProgressHandler > xProgressHandler
1015 /* = new ProgressHandler( *pBroker ) */ ;
1017 xEnv = new ::ucb::CommandEnvironment( xInteractionHandler,
1018 xProgressHandler );
1021 ::ucb::Content aContent( rURL, xEnv );
1022 return InsertEntry( aContent, pParent );
1024 catch ( ContentCreationException const & )
1028 return 0;
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 ) );
1051 m_aTree.Show();
1054 //-------------------------------------------------------------------------
1055 // virtual
1056 UcbExplorerWindow::~UcbExplorerWindow()
1060 //-------------------------------------------------------------------------
1061 // virtual
1062 void UcbExplorerWindow::Resize()
1064 m_aTree.SetSizePixel( GetOutputSizePixel() );
1067 //=========================================================================
1069 // MyApp implementation.
1071 //=========================================================================
1073 // virtual
1074 void MyApp::Main()
1076 //////////////////////////////////////////////////////////////////////
1077 // Initialize local Service Manager and basic services.
1078 //////////////////////////////////////////////////////////////////////
1080 uno::Reference< XMultiServiceFactory > xFac;
1083 uno::Reference< XComponentContext > xCtx(
1084 cppu::defaultBootstrap_InitialComponentContext() );
1085 if ( !xCtx.is() )
1087 DBG_ERROR( "Error creating initial component context!" );
1088 return;
1091 xFac = uno::Reference< XMultiServiceFactory >(
1092 xCtx->getServiceManager(), UNO_QUERY );
1094 if ( !xFac.is() )
1096 DBG_ERROR( "No service manager!" );
1097 return;
1100 catch ( com::sun::star::uno::Exception const & )
1102 DBG_ERROR( "Exception during creation of initial component context!" );
1103 return;
1106 comphelper::setProcessServiceFactory( xFac );
1108 unO::Reference< XComponent > xComponent( xFac, UNO_QUERY );
1110 //////////////////////////////////////////////////////////////////////
1111 // Create UCB.
1112 //////////////////////////////////////////////////////////////////////
1114 #if 1
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 );
1120 #else
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" ),
1127 OUString() ) );
1128 sal_Bool bSuccess = ::ucb::ContentBroker::initialize( xFac, aProviders );
1129 #endif
1131 if ( !bSuccess )
1133 DBG_ERROR( "Error creating UCB!" );
1134 return;
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
1149 #if 0
1150 for ( int i = 0; i < GetCommandLineParamCount(); ++i )
1152 String aPara = GetCommandLineParam( i );
1154 #endif
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( " - " ) );
1163 aTitle += aRootURL;
1165 aAppWin.SetText( aTitle );
1167 aAppWin.SetPosSizePixel( 0, 0, 500, 750 );
1169 aAppWin.Show();
1171 aAppWin.m_aTree.InsertEntry( aRootURL );
1173 //////////////////////////////////////////////////////////////////////
1174 // Execute app.
1175 //////////////////////////////////////////////////////////////////////
1177 Execute();
1179 //////////////////////////////////////////////////////////////////////
1180 // Cleanup.
1181 //////////////////////////////////////////////////////////////////////
1183 // m_aTree holds UCB contents!
1184 aAppWin.m_aTree.Clear();
1186 ::ucb::ContentBroker::deinitialize();
1188 if ( xComponent.is() )
1189 xComponent->dispose();
1192 //=========================================================================
1194 // The Application.
1196 //=========================================================================
1198 MyApp aMyApp;