LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - CollectionView.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 148 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 16 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "CollectionView.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include "moduledbu.hxx"
      24             : #include "dbu_dlg.hrc"
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <comphelper/interaction.hxx>
      27             : #include <cppuhelper/exc_hlp.hxx>
      28             : #include <toolkit/helper/vclunohelper.hxx>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/container/XChild.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <vcl/msgbox.hxx>
      34             : #include "dbustrings.hrc"
      35             : #include "UITools.hxx"
      36             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      37             : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      38             : #include <com/sun/star/ucb/IOErrorCode.hpp>
      39             : #include <com/sun/star/task/InteractionHandler.hpp>
      40             : #include <com/sun/star/task/InteractionClassification.hpp>
      41             : #include <com/sun/star/sdbc/SQLException.hpp>
      42             : #include <com/sun/star/awt/XWindow.hpp>
      43             : #include <unotools/viewoptions.hxx>
      44             : #include <osl/thread.h>
      45             : #include <connectivity/dbexception.hxx>
      46             : 
      47             : namespace dbaui
      48             : {
      49             : 
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star::ucb;
      52             : using namespace ::com::sun::star::lang;
      53             : using namespace ::com::sun::star::beans;
      54             : using namespace ::com::sun::star::container;
      55             : using namespace ::com::sun::star::task;
      56             : using namespace ::com::sun::star::sdbc;
      57             : using namespace comphelper;
      58           0 : OCollectionView::OCollectionView( vcl::Window * pParent
      59             :                                  ,const Reference< XContent>& _xContent
      60             :                                  ,const OUString& _sDefaultName
      61             :                                  ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      62             :     : ModalDialog( pParent, "CollectionView", "dbaccess/ui/collectionviewdialog.ui")
      63             :     , m_xContent(_xContent)
      64             :     , m_xContext(_rxContext)
      65           0 :     , m_bCreateForm(true)
      66             : {
      67           0 :     get(m_pFTCurrentPath, "currentPathLabel");
      68           0 :     get(m_pNewFolder, "newFolderButton");
      69           0 :     get(m_pUp, "upButton");
      70           0 :     get(m_pView, "viewTreeview");
      71           0 :     get(m_pName, "fileNameEntry");
      72           0 :     get(m_pPB_OK, "ok");
      73             : 
      74             :     OSL_ENSURE(m_xContent.is(),"No valid content!");
      75           0 :     m_pView->Initialize(m_xContent,OUString());
      76           0 :     m_pFTCurrentPath->SetStyle( m_pFTCurrentPath->GetStyle() | WB_PATHELLIPSIS );
      77           0 :     initCurrentPath();
      78             : 
      79           0 :     m_pName->SetText(_sDefaultName);
      80           0 :     m_pName->GrabFocus();
      81             : 
      82           0 :     m_pNewFolder->SetStyle( m_pNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
      83           0 :     m_pUp->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_BTN_UP_SC)));
      84           0 :     m_pNewFolder->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC)));
      85             : 
      86           0 :     m_pView->SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
      87           0 :     m_pView->EnableAutoResize();
      88           0 :     m_pView->EnableDelete(true);
      89           0 :     m_pUp->SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
      90           0 :     m_pNewFolder->SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
      91           0 :     m_pPB_OK->SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
      92           0 : }
      93             : 
      94           0 : OCollectionView::~OCollectionView()
      95             : {
      96           0 :     disposeOnce();
      97           0 : }
      98             : 
      99           0 : void OCollectionView::dispose()
     100             : {
     101           0 :     m_pFTCurrentPath.clear();
     102           0 :     m_pNewFolder.clear();
     103           0 :     m_pUp.clear();
     104           0 :     m_pView.clear();
     105           0 :     m_pName.clear();
     106           0 :     m_pPB_OK.clear();
     107           0 :     ModalDialog::dispose();
     108           0 : }
     109             : 
     110           0 : IMPL_LINK_NOARG(OCollectionView, Save_Click)
     111             : {
     112           0 :     OUString sName = m_pName->GetText();
     113           0 :     if ( sName.isEmpty() )
     114           0 :         return 0;
     115             :     try
     116             :     {
     117           0 :         OUString sSubFolder = m_pView->GetCurrentURL();
     118           0 :         sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
     119           0 :         if ( nIndex )
     120             :         {
     121           0 :             if ( nIndex == 1 ) // special handling for root
     122             :             {
     123           0 :                 Reference<XChild> xChild(m_xContent,UNO_QUERY);
     124           0 :                 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
     125           0 :                 while( xNameAccess.is() )
     126             :                 {
     127           0 :                     xNameAccess.set(xChild->getParent(),UNO_QUERY);
     128           0 :                     if ( xNameAccess.is() )
     129             :                     {
     130           0 :                         m_xContent.set(xNameAccess,UNO_QUERY);
     131           0 :                         xChild.set(m_xContent,UNO_QUERY);
     132             :                     }
     133             :                 }
     134           0 :                 m_pView->Initialize(m_xContent,OUString());
     135           0 :                 initCurrentPath();
     136             :             }
     137           0 :             sSubFolder = sName.copy(0,nIndex-1);
     138           0 :             sName = sName.copy(nIndex);
     139           0 :             Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
     140             :             OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
     141           0 :             if ( !sSubFolder.isEmpty() && xHier.is() )
     142             :             {
     143           0 :                 if ( xHier->hasByHierarchicalName(sSubFolder) )
     144             :                 {
     145           0 :                     m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
     146             :                 }
     147             :                 else // sub folder doesn't exist
     148             :                 {
     149           0 :                     Sequence< Any > aValues(2);
     150           0 :                     PropertyValue aValue;
     151           0 :                     aValue.Name = "ResourceName";
     152           0 :                     aValue.Value <<= sSubFolder;
     153           0 :                     aValues[0] <<= aValue;
     154             : 
     155           0 :                     aValue.Name = "ResourceType";
     156           0 :                     aValue.Value <<= OUString("folder");
     157           0 :                     aValues[1] <<= aValue;
     158             : 
     159           0 :                     InteractionClassification eClass = InteractionClassification_ERROR;
     160           0 :                     ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
     161           0 :                     OUString sTemp;
     162           0 :                     InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
     163             : 
     164             :                     Reference<XInteractionHandler2> xHandler(
     165           0 :                         InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this )));
     166           0 :                     OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
     167           0 :                     Reference< XInteractionRequest > xRequest(pRequest);
     168             : 
     169           0 :                     OInteractionApprove* pApprove = new OInteractionApprove;
     170           0 :                     pRequest->addContinuation(pApprove);
     171           0 :                     xHandler->handle(xRequest);
     172             : 
     173           0 :                     return 0;
     174             :                 }
     175           0 :             }
     176             :         }
     177           0 :         Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     178           0 :         if ( xNameContainer.is() )
     179             :         {
     180           0 :             Reference< XContent> xContent;
     181           0 :             if ( xNameContainer->hasByName(sName) )
     182             :             {
     183           0 :                 ScopedVclPtrInstance< QueryBox > aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
     184           0 :                 if ( aBox->Execute() != RET_YES )
     185           0 :                     return 0;
     186             :             }
     187           0 :             m_pName->SetText(sName);
     188           0 :             EndDialog( RET_OK );
     189           0 :         }
     190             :     }
     191           0 :     catch( const Exception& )
     192             :     {
     193             :         DBG_UNHANDLED_EXCEPTION();
     194             :     }
     195           0 :     return 0;
     196             : }
     197             : 
     198           0 : IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
     199             : {
     200             :     try
     201             :     {
     202           0 :         Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     203           0 :         if ( dbaui::insertHierachyElement(this,m_xContext,xNameContainer,OUString(),m_bCreateForm) )
     204           0 :             m_pView->Initialize(m_xContent,OUString());
     205             :     }
     206           0 :     catch( const SQLException& )
     207             :     {
     208           0 :         showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext );
     209             :     }
     210           0 :     catch( const Exception& )
     211             :     {
     212             :         DBG_UNHANDLED_EXCEPTION();
     213             :     }
     214           0 :     return 0;
     215             : }
     216             : 
     217           0 : IMPL_LINK_NOARG(OCollectionView, Up_Click)
     218             : {
     219             :     try
     220             :     {
     221           0 :         Reference<XChild> xChild(m_xContent,UNO_QUERY);
     222           0 :         if ( xChild.is() )
     223             :         {
     224           0 :             Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
     225           0 :             if ( xNameAccess.is() )
     226             :             {
     227           0 :                 m_xContent.set(xNameAccess,UNO_QUERY);
     228           0 :                 m_pView->Initialize(m_xContent,OUString());
     229           0 :                 initCurrentPath();
     230             :             }
     231             :             else
     232           0 :                 m_pUp->Disable();
     233           0 :         }
     234             :     }
     235           0 :     catch( const Exception& )
     236             :     {
     237             :         DBG_UNHANDLED_EXCEPTION();
     238             :     }
     239           0 :     return 0;
     240             : }
     241             : 
     242           0 : IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
     243             : {
     244             :     try
     245             :     {
     246           0 :         Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
     247           0 :         if ( xNameAccess.is() )
     248             :         {
     249           0 :             OUString sSubFolder = m_pView->GetCurrentURL();
     250           0 :             sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
     251           0 :             sSubFolder = sSubFolder.getToken(0,'/',nIndex);
     252           0 :             if ( !sSubFolder.isEmpty() )
     253             :             {
     254           0 :                 Reference< XContent> xContent;
     255           0 :                 if ( xNameAccess->hasByName(sSubFolder) )
     256           0 :                     xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
     257           0 :                 if ( xContent.is() )
     258             :                 {
     259           0 :                     m_xContent = xContent;
     260           0 :                     m_pView->Initialize(m_xContent,OUString());
     261           0 :                     initCurrentPath();
     262           0 :                 }
     263           0 :             }
     264           0 :         }
     265             :     }
     266           0 :     catch( const Exception& )
     267             :     {
     268             :         DBG_UNHANDLED_EXCEPTION();
     269             :     }
     270           0 :     return 0;
     271             : }
     272             : 
     273           0 : void OCollectionView::initCurrentPath()
     274             : {
     275           0 :     bool bEnable = false;
     276             :     try
     277             :     {
     278           0 :         if ( m_xContent.is() )
     279             :         {
     280           0 :             const OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
     281             :             static const char s_sFormsCID[] = "private:forms";
     282             :             static const char s_sReportsCID[] = "private:reports";
     283           0 :             m_bCreateForm = s_sFormsCID == sCID;
     284           0 :             OUString sPath("/");
     285           0 :             if ( m_bCreateForm && sCID.getLength() != (sal_Int32)strlen(s_sFormsCID))
     286           0 :                 sPath = sCID.copy(strlen(s_sFormsCID));
     287           0 :             else if ( !m_bCreateForm && sCID.getLength() != (sal_Int32)strlen(s_sReportsCID) )
     288           0 :                 sPath = sCID.copy(strlen(s_sReportsCID) - 2);
     289             : 
     290           0 :             m_pFTCurrentPath->SetText(sPath);
     291           0 :             Reference<XChild> xChild(m_xContent,UNO_QUERY);
     292           0 :             bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
     293             :         }
     294             :     }
     295           0 :     catch( const Exception& )
     296             :     {
     297             :         DBG_UNHANDLED_EXCEPTION();
     298             :     }
     299           0 :     m_pUp->Enable(bEnable);
     300           0 : }
     301             : 
     302           0 : OUString OCollectionView::getName() const
     303             : {
     304           0 :     return m_pName->GetText();
     305             : }
     306             : 
     307          36 : }   // namespace dbaui
     308             : 
     309             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11