[Libreoffice-commits] core.git: Branch 'feature/gsoc15-open-remote-files-dialog' - include/svtools svtools/source

Szymon Kłos eszkadev at gmail.com
Sat Jun 6 08:17:50 PDT 2015


 include/svtools/RemoteFilesDialog.hxx        |   24 +++++
 svtools/source/dialogs/RemoteFilesDialog.cxx |  109 +++++++++++++++++++++++++--
 2 files changed, 127 insertions(+), 6 deletions(-)

New commits:
commit f5db2d8805b16b2f2ef3c5adb882f6c18cddcc1e
Author: Szymon Kłos <eszkadev at gmail.com>
Date:   Sat Jun 6 17:15:59 2015 +0200

    TreeView filling
    
    Change-Id: I24963a23d1821fafecff5025dcacde255c5244f6

diff --git a/include/svtools/RemoteFilesDialog.hxx b/include/svtools/RemoteFilesDialog.hxx
index e831a32..3725be3 100644
--- a/include/svtools/RemoteFilesDialog.hxx
+++ b/include/svtools/RemoteFilesDialog.hxx
@@ -13,6 +13,8 @@
 #include <svtools/svtdllapi.h>
 #include <svtools/place.hxx>
 #include <svtools/PlaceEditDialog.hxx>
+#include <svtools/svtools.hrc>
+#include <svtools/svtresid.hxx>
 
 #include <vcl/button.hxx>
 #include <vcl/menubtn.hxx>
@@ -27,9 +29,20 @@
 
 #include <officecfg/Office/Common.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/ucb/XProgressHandler.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/InteractionHandler.hpp>
+#include <ucbhelper/commandenvironment.hxx>
 
 #include <vector>
 
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::task;
+using namespace ::comphelper;
+using namespace ::svt;
+
 #define WB_MULTISELECTION 0x20000000L
 
 #define FILTER_ALL "*.*"
@@ -69,6 +82,10 @@ private:
     SvtRemoteDlgType m_eType;
     bool m_bMultiselection;
     bool m_bIsUpdated;
+    Image m_aFolderImage;
+
+    Reference< XCommandEnvironment > m_xEnv;
+    ::osl::Mutex m_aMutex;
 
     VclPtr<PushButton> m_pOpen_btn;
     VclPtr<PushButton> m_pSave_btn;
@@ -93,7 +110,9 @@ private:
 
     OUString getCurrentFilter();
 
-    void OpenURL( OUString sURL );
+    FileViewResult OpenURL( OUString sURL );
+
+    void fillTreeEntry( SvTreeListEntry* pParent );
 
     DECL_LINK ( AddServiceHdl, void * );
     DECL_LINK ( SelectServiceHdl, void * );
@@ -105,6 +124,9 @@ private:
     DECL_LINK( SplitHdl, void * );
 
     DECL_LINK( SelectFilterHdl, void * );
+
+    DECL_LINK( TreeSelectHdl, SvTreeListBox * );
+    DECL_LINK( TreeExpandHdl, SvTreeListBox * );
 };
 
 #endif // INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX
diff --git a/svtools/source/dialogs/RemoteFilesDialog.cxx b/svtools/source/dialogs/RemoteFilesDialog.cxx
index 1c32612..00b20db 100644
--- a/svtools/source/dialogs/RemoteFilesDialog.cxx
+++ b/svtools/source/dialogs/RemoteFilesDialog.cxx
@@ -8,8 +8,7 @@
  */
 
 #include <svtools/RemoteFilesDialog.hxx>
-
-using namespace ::com::sun::star::uno;
+#include "../contnr/contentenumeration.hxx"
 
 class FileViewContainer : public vcl::Window
 {
@@ -79,6 +78,7 @@ class FileViewContainer : public vcl::Window
 RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     : ModalDialog(pParent, "RemoteFilesDialog", "svt/ui/remotefilesdialog.ui")
     , m_context(comphelper::getProcessComponentContext())
+    , m_aFolderImage(SvtResId(IMG_SVT_FOLDER))
     , m_pSplitter(NULL)
     , m_pFileView(NULL)
     , m_pContainer(NULL)
@@ -92,6 +92,11 @@ RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     get(m_pFilter_lb, "filter_lb");
     get(m_pName_ed, "name_ed");
 
+    Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
+    Reference< XInteractionHandler > xInteractionHandler(
+                    InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
+    m_xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
+
     m_eMode = (nBits & WB_SAVEAS) ? REMOTEDLG_MODE_SAVE : REMOTEDLG_MODE_OPEN;
     m_eType = (nBits & WB_PATH) ? REMOTEDLG_TYPE_PATHDLG : REMOTEDLG_TYPE_FILEDLG;
     m_bMultiselection = (nBits & WB_MULTISELECTION) ? true : false;
@@ -138,6 +143,11 @@ RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     m_pTreeView->set_width_request(aSize.Width());
     m_pTreeView->SetSizePixel(aSize);
     m_pTreeView->Show();
+    m_pTreeView->SetDefaultCollapsedEntryBmp(m_aFolderImage);
+    m_pTreeView->SetDefaultExpandedEntryBmp(m_aFolderImage);
+
+    m_pTreeView->SetSelectHdl( LINK( this, RemoteFilesDialog, TreeSelectHdl ) );
+    m_pTreeView->SetExpandedHdl( LINK( this, RemoteFilesDialog, TreeExpandHdl ) );
 
     sal_Int32 nPosX = m_pTreeView->GetSizePixel().Width();
     m_pSplitter->SetPosPixel(Point(nPosX, 0));
@@ -287,12 +297,13 @@ OUString RemoteFilesDialog::getCurrentFilter()
     return sFilter;
 }
 
-void RemoteFilesDialog::OpenURL( OUString sURL )
+FileViewResult RemoteFilesDialog::OpenURL( OUString sURL )
 {
+    FileViewResult eResult = eFailure;
+
     if(m_pFileView)
     {
         OUStringList BlackList;
-        FileViewResult eResult = eFailure;
         OUString sFilter = getCurrentFilter();
 
         m_pFileView->EndInplaceEditing( false );
@@ -306,6 +317,68 @@ void RemoteFilesDialog::OpenURL( OUString sURL )
             m_pContainer->Enable( true );
         }
     }
+
+    return eResult;
+}
+
+void RemoteFilesDialog::fillTreeEntry( SvTreeListEntry* pParent )
+{
+    if( pParent && m_pTreeView->IsExpanded( pParent ) )
+    {
+        // remove childs
+
+        if ( pParent )
+        {
+            SvTreeList* pModel = m_pTreeView->GetModel();
+
+            if( pModel->HasChildren( pParent ) )
+            {
+                SvTreeListEntries& rEntries = pModel->GetChildList( pParent );
+                rEntries.clear();
+            }
+        }
+
+        // fill with new ones
+
+        ::std::vector< SortingData_Impl* > aContent;
+
+        FileViewContentEnumerator* pContentEnumerator = new FileViewContentEnumerator(
+            m_xEnv, aContent, m_aMutex, NULL );
+
+        OUString* pURL = static_cast< OUString* >( pParent->GetUserData() );
+
+        if( pURL )
+        {
+            FolderDescriptor aFolder( *pURL );
+            Sequence< OUString > aBlackList;
+
+            EnumerationResult eResult =
+                pContentEnumerator->enumerateFolderContentSync( aFolder, aBlackList );
+
+            if ( SUCCESS == eResult )
+            {
+                unsigned int nChilds = 0;
+
+                for( unsigned int i = 0; i < aContent.size(); i++ )
+                {
+                    if( aContent[i]->mbIsFolder )
+                    {
+                        SvTreeListEntry* pEntry = m_pTreeView->InsertEntry( aContent[i]->GetTitle(), pParent, true );
+
+                        OUString* sData = new OUString( aContent[i]->maTargetURL );
+                        pEntry->SetUserData( static_cast< void* >( sData ) );
+
+                        nChilds++;
+                    }
+                }
+
+                if( nChilds == 0 )
+                {
+                    m_pTreeView->Collapse( pParent );
+                }
+            }
+        }
+    }
 }
 
 IMPL_LINK_NOARG ( RemoteFilesDialog, AddServiceHdl )
@@ -343,7 +416,16 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, SelectServiceHdl )
     {
         OUString sURL = m_aServices[nPos]->GetUrl();
 
-        OpenURL( sURL );
+        if( OpenURL( sURL ) == eSuccess )
+        {
+            m_pTreeView->Clear();
+
+            SvTreeListEntry* pRoot = m_pTreeView->InsertEntry( m_pServices_lb->GetSelectEntry(), NULL, true );
+            OUString* sData = new OUString( sURL );
+            pRoot->SetUserData( static_cast< void* >( sData ) );
+
+            m_pTreeView->Expand( pRoot );
+        }
     }
 
     return 1;
@@ -464,4 +546,21 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, SelectFilterHdl )
     return 1;
 }
 
+IMPL_LINK ( RemoteFilesDialog, TreeSelectHdl, SvTreeListBox *, pBox )
+{
+    OUString* sURL = static_cast< OUString* >( pBox->GetHdlEntry()->GetUserData() );
+
+    if( sURL )
+        OpenURL( *sURL );
+
+    return 1;
+}
+
+IMPL_LINK ( RemoteFilesDialog, TreeExpandHdl, SvTreeListBox *, pBox )
+{
+    fillTreeEntry( pBox->GetHdlEntry() );
+
+    return 1;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list