LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/dlg - CollectionView.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 135 0.0 %
Date: 2012-12-17 Functions: 0 14 0.0 %
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 "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/processfactory.hxx>
      27             : #include <comphelper/interaction.hxx>
      28             : #include <cppuhelper/exc_hlp.hxx>
      29             : #include <toolkit/helper/vclunohelper.hxx>
      30             : #include <svtools/QueryFolderName.hxx>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.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/InteractionHandler.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::uno::XComponentContext >& _rxContext)
      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_xContext(_rxContext)
      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             :                     Reference<XInteractionHandler2> xHandler(
     173           0 :                         InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this )));
     174           0 :                     OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
     175           0 :                     Reference< XInteractionRequest > xRequest(pRequest);
     176             : 
     177           0 :                     OInteractionApprove* pApprove = new OInteractionApprove;
     178           0 :                     pRequest->addContinuation(pApprove);
     179           0 :                     xHandler->handle(xRequest);
     180             : 
     181           0 :                     return 0;
     182             :                 }
     183           0 :             }
     184             :         }
     185           0 :         Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     186           0 :         if ( xNameContainer.is() )
     187             :         {
     188           0 :             Reference< XContent> xContent;
     189           0 :             if ( xNameContainer->hasByName(sName) )
     190             :             {
     191           0 :                 QueryBox aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
     192           0 :                 if ( aBox.Execute() != RET_YES )
     193           0 :                     return 0;
     194             :             }
     195           0 :             m_aName.SetText(sName);
     196           0 :             EndDialog( sal_True );
     197           0 :         }
     198             :     }
     199           0 :     catch( const Exception& )
     200             :     {
     201             :         DBG_UNHANDLED_EXCEPTION();
     202             :     }
     203           0 :     return 0;
     204             : }
     205             : // -----------------------------------------------------------------------------
     206           0 : IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
     207             : {
     208             :     try
     209             :     {
     210           0 :         Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
     211           0 :         if ( dbaui::insertHierachyElement(this,m_xContext,xNameContainer,String(),m_bCreateForm) )
     212           0 :             m_aView.Initialize(m_xContent,String());
     213             :     }
     214           0 :     catch( const SQLException& )
     215             :     {
     216           0 :         showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext );
     217             :     }
     218           0 :     catch( const Exception& )
     219             :     {
     220             :         DBG_UNHANDLED_EXCEPTION();
     221             :     }
     222           0 :     return 0;
     223             : }
     224             : // -----------------------------------------------------------------------------
     225           0 : IMPL_LINK_NOARG(OCollectionView, Up_Click)
     226             : {
     227             :     try
     228             :     {
     229           0 :         Reference<XChild> xChild(m_xContent,UNO_QUERY);
     230           0 :         if ( xChild.is() )
     231             :         {
     232           0 :             Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
     233           0 :             if ( xNameAccess.is() )
     234             :             {
     235           0 :                 m_xContent.set(xNameAccess,UNO_QUERY);
     236           0 :                 m_aView.Initialize(m_xContent,String());
     237           0 :                 initCurrentPath();
     238             :             }
     239             :             else
     240           0 :                 m_aUp.Disable();
     241           0 :         }
     242             :     }
     243           0 :     catch( const Exception& )
     244             :     {
     245             :         DBG_UNHANDLED_EXCEPTION();
     246             :     }
     247           0 :     return 0;
     248             : }
     249             : // -----------------------------------------------------------------------------
     250           0 : IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
     251             : {
     252             :     try
     253             :     {
     254           0 :         Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
     255           0 :         if ( xNameAccess.is() )
     256             :         {
     257           0 :             ::rtl::OUString sSubFolder = m_aView.GetCurrentURL();
     258           0 :             sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
     259           0 :             sSubFolder = sSubFolder.getToken(0,'/',nIndex);
     260           0 :             if ( !sSubFolder.isEmpty() )
     261             :             {
     262           0 :                 Reference< XContent> xContent;
     263           0 :                 if ( xNameAccess->hasByName(sSubFolder) )
     264           0 :                     xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
     265           0 :                 if ( xContent.is() )
     266             :                 {
     267           0 :                     m_xContent = xContent;
     268           0 :                     m_aView.Initialize(m_xContent,String());
     269           0 :                     initCurrentPath();
     270           0 :                 }
     271           0 :             }
     272           0 :         }
     273             :     }
     274           0 :     catch( const Exception& )
     275             :     {
     276             :         DBG_UNHANDLED_EXCEPTION();
     277             :     }
     278           0 :     return 0;
     279             : }
     280             : // -----------------------------------------------------------------------------
     281           0 : void OCollectionView::initCurrentPath()
     282             : {
     283           0 :     sal_Bool bEnable = sal_False;
     284             :     try
     285             :     {
     286           0 :         if ( m_xContent.is() )
     287             :         {
     288           0 :             const ::rtl::OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
     289           0 :             const static ::rtl::OUString s_sFormsCID(RTL_CONSTASCII_USTRINGPARAM("private:forms"));
     290           0 :             const static ::rtl::OUString s_sReportsCID(RTL_CONSTASCII_USTRINGPARAM("private:reports"));
     291           0 :             m_bCreateForm = s_sFormsCID.compareTo(sCID) == 0;
     292           0 :             ::rtl::OUString sPath(RTL_CONSTASCII_USTRINGPARAM("/"));
     293           0 :             if ( m_bCreateForm && sCID.getLength() != s_sFormsCID.getLength())
     294           0 :                 sPath = sCID.copy(s_sFormsCID.getLength());
     295           0 :             else if ( !m_bCreateForm && sCID.getLength() != s_sReportsCID.getLength() )
     296           0 :                 sPath = sCID.copy(s_sReportsCID.getLength());
     297             : 
     298           0 :             m_aFTCurrentPath.SetText(sPath);
     299           0 :             Reference<XChild> xChild(m_xContent,UNO_QUERY);
     300           0 :             bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
     301             :         }
     302             :     }
     303           0 :     catch( const Exception& )
     304             :     {
     305             :         DBG_UNHANDLED_EXCEPTION();
     306             :     }
     307           0 :     m_aUp.Enable(bEnable);
     308           0 : }
     309             : // -----------------------------------------------------------------------------
     310           0 : ::rtl::OUString OCollectionView::getName() const
     311             : {
     312           0 :     return m_aName.GetText();
     313             : }
     314             : // -----------------------------------------------------------------------------
     315             : //.........................................................................
     316             : }   // namespace dbaui
     317             : //.........................................................................
     318             : 
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10