LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - CollectionView.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 142 0.0 %
Date: 2012-08-25 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 475 0.0 %

           Branch data     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 "CollectionView.hrc"
      22                 :            : #include <tools/debug.hxx>
      23                 :            : #include <tools/diagnose_ex.h>
      24                 :            : #include "moduledbu.hxx"
      25                 :            : #include "dbu_dlg.hrc"
      26                 :            : #include <comphelper/interaction.hxx>
      27                 :            : #include <cppuhelper/exc_hlp.hxx>
      28                 :            : #include <toolkit/helper/vclunohelper.hxx>
      29                 :            : #include <svtools/QueryFolderName.hxx>
      30                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      32                 :            : #include <com/sun/star/container/XChild.hpp>
      33                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      34                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      35                 :            : #include <vcl/msgbox.hxx>
      36                 :            : #include "dbustrings.hrc"
      37                 :            : #include "UITools.hxx"
      38                 :            : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      39                 :            : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      40                 :            : #include <com/sun/star/ucb/IOErrorCode.hpp>
      41                 :            : #include <com/sun/star/task/XInteractionHandler.hpp>
      42                 :            : #include <com/sun/star/task/InteractionClassification.hpp>
      43                 :            : #include <com/sun/star/sdbc/SQLException.hpp>
      44                 :            : #include <com/sun/star/awt/XWindow.hpp>
      45                 :            : #include <unotools/viewoptions.hxx>
      46                 :            : #include <osl/thread.h>
      47                 :            : #include <connectivity/dbexception.hxx>
      48                 :            : 
      49                 :            : //.........................................................................
      50                 :            : namespace dbaui
      51                 :            : {
      52                 :            : //.........................................................................
      53                 :            : 
      54                 :            : using namespace ::com::sun::star::uno;
      55                 :            : using namespace ::com::sun::star::ucb;
      56                 :            : using namespace ::com::sun::star::lang;
      57                 :            : using namespace ::com::sun::star::beans;
      58                 :            : using namespace ::com::sun::star::container;
      59                 :            : using namespace ::com::sun::star::ucb;
      60                 :            : using namespace ::com::sun::star::task;
      61                 :            : using namespace ::com::sun::star::sdbc;
      62                 :            : using namespace comphelper;
      63                 :            : // -----------------------------------------------------------------------------
      64                 :            : DBG_NAME(OCollectionView)
      65                 :          0 : OCollectionView::OCollectionView( Window * pParent
      66                 :            :                                  ,const Reference< XContent>& _xContent
      67                 :            :                                  ,const ::rtl::OUString& _sDefaultName
      68                 :            :                                  ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
      69                 :            :     : ModalDialog( pParent, ModuleRes(DLG_COLLECTION_VIEW))
      70                 :            :     , m_aFTCurrentPath( this, ModuleRes( FT_EXPLORERFILE_CURRENTPATH ) )
      71                 :            :     , m_aNewFolder(     this, ModuleRes( BTN_EXPLORERFILE_NEWFOLDER ) )
      72                 :            :     , m_aUp(            this, ModuleRes( BTN_EXPLORERFILE_UP ) )
      73                 :            :     , m_aView(          this, ModuleRes( CTRL_VIEW ), FILEVIEW_SHOW_ONLYTITLE )
      74                 :            :     , m_aFTName(        this, ModuleRes( FT_EXPLORERFILE_FILENAME ) )
      75                 :            :     , m_aName(          this, ModuleRes( ED_EXPLORERFILE_FILENAME ) )
      76                 :            :     , m_aFL(            this, ModuleRes( FL_1 ) )
      77                 :            :     , m_aPB_OK(         this, ModuleRes( BTN_EXPLORERFILE_SAVE ) )
      78                 :            :     , m_aPB_CANCEL(     this, ModuleRes( PB_CANCEL ) )
      79                 :            :     , m_aPB_HELP(       this, ModuleRes( PB_HELP ) )
      80                 :            :     , m_sPath(          ModuleRes( STR_PATHNAME ) )
      81                 :            :     , m_xContent(_xContent)
      82                 :            :     , m_xORB(_xORB)
      83 [ #  # ][ #  # ]:          0 :     , m_bCreateForm(sal_True)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      84                 :            : {
      85                 :            :     DBG_CTOR(OCollectionView,NULL);
      86         [ #  # ]:          0 :     FreeResource();
      87                 :            : 
      88                 :            :     OSL_ENSURE(m_xContent.is(),"No valid content!");
      89 [ #  # ][ #  # ]:          0 :     m_aView.Initialize(m_xContent,String());
                 [ #  # ]
      90 [ #  # ][ #  # ]:          0 :     m_aFTCurrentPath.SetStyle( m_aFTCurrentPath.GetStyle() | WB_PATHELLIPSIS );
      91         [ #  # ]:          0 :     initCurrentPath();
      92                 :            : 
      93 [ #  # ][ #  # ]:          0 :     m_aName.SetText(_sDefaultName);
                 [ #  # ]
      94         [ #  # ]:          0 :     m_aName.GrabFocus();
      95                 :            : 
      96 [ #  # ][ #  # ]:          0 :     m_aNewFolder.SetStyle( m_aNewFolder.GetStyle() | WB_NOPOINTERFOCUS );
      97 [ #  # ][ #  # ]:          0 :     m_aUp.SetModeImage(ModuleRes(IMG_NAVIGATION_BTN_UP_SC));
         [ #  # ][ #  # ]
      98 [ #  # ][ #  # ]:          0 :     m_aNewFolder.SetModeImage(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC));
         [ #  # ][ #  # ]
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :     m_aView.SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
     101         [ #  # ]:          0 :     m_aView.EnableAutoResize();
     102         [ #  # ]:          0 :     m_aUp.SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
     103         [ #  # ]:          0 :     m_aNewFolder.SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
     104         [ #  # ]:          0 :     m_aPB_OK.SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
     105                 :          0 : }
     106                 :            : // -----------------------------------------------------------------------------
     107 [ #  # ][ #  # ]:          0 : OCollectionView::~OCollectionView( )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     108                 :            : {
     109                 :            :     DBG_DTOR(OCollectionView,NULL);
     110         [ #  # ]:          0 : }
     111                 :            : // -----------------------------------------------------------------------------
     112                 :          0 : Reference< XContent> OCollectionView::getSelectedFolder() const
     113                 :            : {
     114                 :          0 :     return m_xContent;
     115                 :            : }
     116                 :            : // -----------------------------------------------------------------------------
     117                 :          0 : IMPL_LINK_NOARG(OCollectionView, Save_Click)
     118                 :            : {
     119 [ #  # ][ #  # ]:          0 :     ::rtl::OUString sName = m_aName.GetText();
                 [ #  # ]
     120         [ #  # ]:          0 :     if ( sName.isEmpty() )
     121                 :          0 :         return 0;
     122                 :            :     try
     123                 :            :     {
     124 [ #  # ][ #  # ]:          0 :         ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
                 [ #  # ]
     125                 :          0 :         sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
     126         [ #  # ]:          0 :         if ( nIndex )
     127                 :            :         {
     128         [ #  # ]:          0 :             if ( nIndex == 1 ) // special handling for root
     129                 :            :             {
     130         [ #  # ]:          0 :                 Reference<XChild> xChild(m_xContent,UNO_QUERY);
     131         [ #  # ]:          0 :                 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
     132         [ #  # ]:          0 :                 while( xNameAccess.is() )
     133                 :            :                 {
     134 [ #  # ][ #  # ]:          0 :                     xNameAccess.set(xChild->getParent(),UNO_QUERY);
                 [ #  # ]
     135         [ #  # ]:          0 :                     if ( xNameAccess.is() )
     136                 :            :                     {
     137         [ #  # ]:          0 :                         m_xContent.set(xNameAccess,UNO_QUERY);
     138         [ #  # ]:          0 :                         xChild.set(m_xContent,UNO_QUERY);
     139                 :            :                     }
     140                 :            :                 }
     141 [ #  # ][ #  # ]:          0 :                 m_aView.Initialize(m_xContent,String());
                 [ #  # ]
     142         [ #  # ]:          0 :                 initCurrentPath();
     143                 :            :             }
     144                 :          0 :             sSubFolder = sName.copy(0,nIndex-1);
     145                 :          0 :             sName = sName.copy(nIndex);
     146         [ #  # ]:          0 :             Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
     147                 :            :             OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
     148 [ #  # ][ #  # ]:          0 :             if ( !sSubFolder.isEmpty() && xHier.is() )
                 [ #  # ]
     149                 :            :             {
     150 [ #  # ][ #  # ]:          0 :                 if ( xHier->hasByHierarchicalName(sSubFolder) )
                 [ #  # ]
     151                 :            :                 {
     152 [ #  # ][ #  # ]:          0 :                     m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
                 [ #  # ]
     153                 :            :                 }
     154                 :            :                 else // sub folder doesn't exist
     155                 :            :                 {
     156         [ #  # ]:          0 :                     Sequence< Any > aValues(2);
     157                 :          0 :                     PropertyValue aValue;
     158         [ #  # ]:          0 :                     aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceName"));
     159         [ #  # ]:          0 :                     aValue.Value <<= sSubFolder;
     160 [ #  # ][ #  # ]:          0 :                     aValues[0] <<= aValue;
     161                 :            : 
     162         [ #  # ]:          0 :                     aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceType"));
     163 [ #  # ][ #  # ]:          0 :                     aValue.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("folder"));
     164 [ #  # ][ #  # ]:          0 :                     aValues[1] <<= aValue;
     165                 :            : 
     166                 :          0 :                     InteractionClassification eClass = InteractionClassification_ERROR;
     167                 :          0 :                     ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
     168                 :          0 :                     ::rtl::OUString sTemp;
     169         [ #  # ]:          0 :                     InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
     170                 :            : 
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :                     Reference<XInitialization> xIni(m_xORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler"))),UNO_QUERY);
         [ #  # ][ #  # ]
     173         [ #  # ]:          0 :                     if ( xIni.is() )
     174                 :            :                     {
     175         [ #  # ]:          0 :                         aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
     176 [ #  # ][ #  # ]:          0 :                         aValue.Value <<= VCLUnoHelper::GetInterface( this );
     177         [ #  # ]:          0 :                         Sequence< Any > aArgs(1);
     178 [ #  # ][ #  # ]:          0 :                         aArgs[0] <<= makeAny(aValue);
                 [ #  # ]
     179 [ #  # ][ #  # ]:          0 :                         xIni->initialize(aArgs);
     180 [ #  # ][ #  # ]:          0 :                         OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
     181 [ #  # ][ #  # ]:          0 :                         Reference< XInteractionRequest > xRequest(pRequest);
     182                 :            : 
     183         [ #  # ]:          0 :                         OInteractionApprove* pApprove = new OInteractionApprove;
     184 [ #  # ][ #  # ]:          0 :                         pRequest->addContinuation(pApprove);
                 [ #  # ]
     185                 :            : 
     186         [ #  # ]:          0 :                         Reference< XInteractionHandler > xHandler(xIni,UNO_QUERY);
     187 [ #  # ][ #  # ]:          0 :                         xHandler->handle(xRequest);
                 [ #  # ]
     188                 :            :                     }
     189 [ #  # ][ #  # ]:          0 :                     return 0;
     190                 :            :                 }
     191         [ #  # ]:          0 :             }
     192                 :            :         }
     193         [ #  # ]:          0 :         Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     194         [ #  # ]:          0 :         if ( xNameContainer.is() )
     195                 :            :         {
     196                 :          0 :             Reference< XContent> xContent;
     197 [ #  # ][ #  # ]:          0 :             if ( xNameContainer->hasByName(sName) )
                 [ #  # ]
     198                 :            :             {
     199 [ #  # ][ #  # ]:          0 :                 QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
         [ #  # ][ #  # ]
     200 [ #  # ][ #  # ]:          0 :                 if ( aBox.Execute() != RET_YES )
     201 [ #  # ][ #  # ]:          0 :                     return 0;
     202                 :            :             }
     203 [ #  # ][ #  # ]:          0 :             m_aName.SetText(sName);
                 [ #  # ]
     204 [ #  # ][ #  # ]:          0 :             EndDialog( sal_True );
     205 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     206                 :            :     }
     207         [ #  # ]:          0 :     catch( const Exception& )
     208                 :            :     {
     209                 :            :         DBG_UNHANDLED_EXCEPTION();
     210                 :            :     }
     211                 :          0 :     return 0;
     212                 :            : }
     213                 :            : // -----------------------------------------------------------------------------
     214                 :          0 : IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
     215                 :            : {
     216                 :            :     try
     217                 :            :     {
     218         [ #  # ]:          0 :         Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     219 [ #  # ][ #  # ]:          0 :         if ( dbaui::insertHierachyElement(this,m_xORB,xNameContainer,String(),m_bCreateForm) )
         [ #  # ][ #  # ]
                 [ #  # ]
     220 [ #  # ][ #  # ]:          0 :             m_aView.Initialize(m_xContent,String());
                 [ #  # ]
     221                 :            :     }
     222      [ #  #  # ]:          0 :     catch( const SQLException& )
     223                 :            :     {
     224   [ #  #  #  #  :          0 :         showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xORB );
             #  #  #  # ]
     225                 :            :     }
     226                 :          0 :     catch( const Exception& )
     227                 :            :     {
     228                 :            :         DBG_UNHANDLED_EXCEPTION();
     229                 :            :     }
     230                 :          0 :     return 0;
     231                 :            : }
     232                 :            : // -----------------------------------------------------------------------------
     233                 :          0 : IMPL_LINK_NOARG(OCollectionView, Up_Click)
     234                 :            : {
     235                 :            :     try
     236                 :            :     {
     237         [ #  # ]:          0 :         Reference<XChild> xChild(m_xContent,UNO_QUERY);
     238         [ #  # ]:          0 :         if ( xChild.is() )
     239                 :            :         {
     240 [ #  # ][ #  # ]:          0 :             Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
                 [ #  # ]
     241         [ #  # ]:          0 :             if ( xNameAccess.is() )
     242                 :            :             {
     243         [ #  # ]:          0 :                 m_xContent.set(xNameAccess,UNO_QUERY);
     244 [ #  # ][ #  # ]:          0 :                 m_aView.Initialize(m_xContent,String());
                 [ #  # ]
     245         [ #  # ]:          0 :                 initCurrentPath();
     246                 :            :             }
     247                 :            :             else
     248         [ #  # ]:          0 :                 m_aUp.Disable();
     249         [ #  # ]:          0 :         }
     250                 :            :     }
     251                 :          0 :     catch( const Exception& )
     252                 :            :     {
     253                 :            :         DBG_UNHANDLED_EXCEPTION();
     254                 :            :     }
     255                 :          0 :     return 0;
     256                 :            : }
     257                 :            : // -----------------------------------------------------------------------------
     258                 :          0 : IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
     259                 :            : {
     260                 :            :     try
     261                 :            :     {
     262         [ #  # ]:          0 :         Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
     263         [ #  # ]:          0 :         if ( xNameAccess.is() )
     264                 :            :         {
     265 [ #  # ][ #  # ]:          0 :             ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
                 [ #  # ]
     266                 :          0 :             sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
     267                 :          0 :             sSubFolder = sSubFolder.getToken(0,'/',nIndex);
     268         [ #  # ]:          0 :             if ( !sSubFolder.isEmpty() )
     269                 :            :             {
     270                 :          0 :                 Reference< XContent> xContent;
     271 [ #  # ][ #  # ]:          0 :                 if ( xNameAccess->hasByName(sSubFolder) )
                 [ #  # ]
     272 [ #  # ][ #  # ]:          0 :                     xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
                 [ #  # ]
     273         [ #  # ]:          0 :                 if ( xContent.is() )
     274                 :            :                 {
     275         [ #  # ]:          0 :                     m_xContent = xContent;
     276 [ #  # ][ #  # ]:          0 :                     m_aView.Initialize(m_xContent,String());
                 [ #  # ]
     277         [ #  # ]:          0 :                     initCurrentPath();
     278                 :          0 :                 }
     279                 :          0 :             }
     280         [ #  # ]:          0 :         }
     281                 :            :     }
     282                 :          0 :     catch( const Exception& )
     283                 :            :     {
     284                 :            :         DBG_UNHANDLED_EXCEPTION();
     285                 :            :     }
     286                 :          0 :     return 0;
     287                 :            : }
     288                 :            : // -----------------------------------------------------------------------------
     289                 :          0 : void OCollectionView::initCurrentPath()
     290                 :            : {
     291                 :          0 :     sal_Bool bEnable = sal_False;
     292                 :            :     try
     293                 :            :     {
     294         [ #  # ]:          0 :         if ( m_xContent.is() )
     295                 :            :         {
     296 [ #  # ][ #  # ]:          0 :             const ::rtl::OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
         [ #  # ][ #  # ]
     297 [ #  # ][ #  # ]:          0 :             const static ::rtl::OUString s_sFormsCID(RTL_CONSTASCII_USTRINGPARAM("private:forms"));
         [ #  # ][ #  # ]
     298 [ #  # ][ #  # ]:          0 :             const static ::rtl::OUString s_sReportsCID(RTL_CONSTASCII_USTRINGPARAM("private:reports"));
         [ #  # ][ #  # ]
     299                 :          0 :             m_bCreateForm = s_sFormsCID.compareTo(sCID) == 0;
     300         [ #  # ]:          0 :             ::rtl::OUString sPath(RTL_CONSTASCII_USTRINGPARAM("/"));
     301 [ #  # ][ #  # ]:          0 :             if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
                 [ #  # ]
     302                 :          0 :                 sPath = sCID.copy(s_sFormsCID.getLength());
     303 [ #  # ][ #  # ]:          0 :             else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
                 [ #  # ]
     304                 :          0 :                 sPath = sCID.copy(s_sReportsCID.getLength());
     305                 :            : 
     306 [ #  # ][ #  # ]:          0 :             m_aFTCurrentPath.SetText(sPath);
                 [ #  # ]
     307         [ #  # ]:          0 :             Reference<XChild> xChild(m_xContent,UNO_QUERY);
     308 [ #  # ][ #  # ]:          0 :             bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     309                 :            :         }
     310                 :            :     }
     311                 :          0 :     catch( const Exception& )
     312                 :            :     {
     313                 :            :         DBG_UNHANDLED_EXCEPTION();
     314                 :            :     }
     315                 :          0 :     m_aUp.Enable(bEnable);
     316                 :          0 : }
     317                 :            : // -----------------------------------------------------------------------------
     318                 :          0 : ::rtl::OUString OCollectionView::getName() const
     319                 :            : {
     320         [ #  # ]:          0 :     return m_aName.GetText();
     321                 :            : }
     322                 :            : // -----------------------------------------------------------------------------
     323                 :            : //.........................................................................
     324                 :            : }   // namespace dbaui
     325                 :            : //.........................................................................
     326                 :            : 
     327                 :            : 
     328                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10