LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - dlgsave.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 144 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 20 10.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 "dlgsave.hxx"
      21             : #include <vcl/msgbox.hxx>
      22             : #include "dbu_dlg.hrc"
      23             : #include <com/sun/star/sdb/CommandType.hpp>
      24             : #include <com/sun/star/sdbc/XRow.hpp>
      25             : #include "sqlmessage.hxx"
      26             : #include <connectivity/dbtools.hxx>
      27             : #include "UITools.hxx"
      28             : #include "dbaccess_helpid.hrc"
      29             : #include "SqlNameEdit.hxx"
      30             : #include <vcl/button.hxx>
      31             : #include <vcl/fixed.hxx>
      32             : #include <vcl/edit.hxx>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      35             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      36             : #include "moduledbu.hxx"
      37             : #include "objectnamecheck.hxx"
      38             : #include <tools/diagnose_ex.h>
      39             : 
      40             : using namespace dbaui;
      41             : using namespace dbtools;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::container;
      44             : using namespace ::com::sun::star::sdb;
      45             : using namespace ::com::sun::star::sdbc;
      46             : namespace dbaui
      47             : {
      48           0 : class OSaveAsDlgImpl
      49             : {
      50             : public:
      51             :     VclPtr<FixedText>          m_pDescription;
      52             :     VclPtr<FixedText>          m_pCatalogLbl;
      53             :     VclPtr<OSQLNameComboBox>   m_pCatalog;
      54             :     VclPtr<FixedText>          m_pSchemaLbl;
      55             :     VclPtr<OSQLNameComboBox>   m_pSchema;
      56             :     VclPtr<FixedText>          m_pLabel;
      57             :     VclPtr<OSQLNameEdit>       m_pTitle;
      58             :     VclPtr<OKButton>           m_pPB_OK;
      59             :     OUString            m_aQryLabel;
      60             :     OUString            m_sTblLabel;
      61             :     OUString            m_aName;
      62             :     const IObjectNameCheck&
      63             :                         m_rObjectNameCheck;
      64             :     OUString            m_sParentURL;
      65             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>            m_xMetaData;
      66             :     sal_Int32           m_nType;
      67             :     sal_Int32           m_nFlags;
      68             : 
      69             :     OSaveAsDlgImpl( OSaveAsDlg* pParent,const sal_Int32& _rType,
      70             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
      71             :                     const OUString& rDefault,
      72             :                     const IObjectNameCheck& _rObjectNameCheck,
      73             :                     sal_Int32 _nFlags);
      74             :     OSaveAsDlgImpl( OSaveAsDlg* pParent,
      75             :                     const OUString& rDefault,
      76             :                     const IObjectNameCheck& _rObjectNameCheck,
      77             :                     sal_Int32 _nFlags);
      78             : };
      79             : 
      80             : } // dbaui
      81             : 
      82           0 : OSaveAsDlgImpl::OSaveAsDlgImpl(OSaveAsDlg* pParent,
      83             :                         const sal_Int32& _rType,
      84             :                         const Reference< XConnection>& _xConnection,
      85             :                         const OUString& rDefault,
      86             :                         const IObjectNameCheck& _rObjectNameCheck,
      87             :                         sal_Int32 _nFlags)
      88             :     : m_aQryLabel(ModuleRes(STR_QRY_LABEL))
      89             :     , m_sTblLabel(ModuleRes(STR_TBL_LABEL))
      90             :     , m_aName(rDefault)
      91             :     , m_rObjectNameCheck( _rObjectNameCheck )
      92             :     , m_nType(_rType)
      93           0 :     , m_nFlags(_nFlags)
      94             : {
      95           0 :     pParent->get(m_pDescription, "descriptionft");
      96           0 :     pParent->get(m_pCatalogLbl, "catalogft");
      97           0 :     pParent->get(m_pCatalog, "catalog");
      98           0 :     pParent->get(m_pSchemaLbl, "schemaft");
      99           0 :     pParent->get(m_pSchema, "schema");
     100           0 :     pParent->get(m_pLabel, "titleft");
     101           0 :     pParent->get(m_pTitle, "title");
     102           0 :     pParent->get(m_pPB_OK, "ok");
     103             : 
     104           0 :     if ( _xConnection.is() )
     105           0 :         m_xMetaData = _xConnection->getMetaData();
     106             : 
     107           0 :     if ( m_xMetaData.is() )
     108             :     {
     109           0 :         OUString sExtraNameChars( m_xMetaData->getExtraNameCharacters() );
     110           0 :         m_pCatalog->setAllowedChars( sExtraNameChars );
     111           0 :         m_pSchema->setAllowedChars( sExtraNameChars );
     112           0 :         m_pTitle->setAllowedChars( sExtraNameChars );
     113             :     }
     114             : 
     115           0 :     m_pCatalog->SetDropDownLineCount( 10 );
     116           0 :     m_pSchema->SetDropDownLineCount( 10 );
     117           0 : }
     118             : 
     119           0 : OSaveAsDlgImpl::OSaveAsDlgImpl(OSaveAsDlg* pParent,
     120             :                         const OUString& rDefault,
     121             :                         const IObjectNameCheck& _rObjectNameCheck,
     122             :                         sal_Int32 _nFlags)
     123             :     : m_aQryLabel(ModuleRes(STR_QRY_LABEL))
     124             :     , m_sTblLabel(ModuleRes(STR_TBL_LABEL))
     125             :     , m_aName(rDefault)
     126             :     , m_rObjectNameCheck( _rObjectNameCheck )
     127             :     , m_nType(CommandType::COMMAND)
     128           0 :     , m_nFlags(_nFlags)
     129             : {
     130           0 :     pParent->get(m_pDescription, "descriptionft");
     131           0 :     pParent->get(m_pCatalogLbl, "catalogft");
     132           0 :     pParent->get(m_pCatalog, "catalog");
     133           0 :     pParent->get(m_pSchemaLbl, "schemaft");
     134           0 :     pParent->get(m_pSchema, "schema");
     135           0 :     pParent->get(m_pLabel, "titleft");
     136           0 :     pParent->get(m_pTitle, "title");
     137           0 :     pParent->get(m_pPB_OK, "ok");
     138             : 
     139           0 :     m_pCatalog->SetDropDownLineCount( 10 );
     140           0 :     m_pSchema->SetDropDownLineCount( 10 );
     141           0 : }
     142             : 
     143             : using namespace ::com::sun::star::lang;
     144             : 
     145             : namespace
     146             : {
     147             :     typedef Reference< XResultSet > (SAL_CALL XDatabaseMetaData::*FGetMetaStrings)();
     148             : 
     149           0 :     void lcl_fillComboList( ComboBox& _rList, const Reference< XConnection >& _rxConnection,
     150             :         FGetMetaStrings _GetAll, const OUString& _rCurrent )
     151             :     {
     152             :         try
     153             :         {
     154           0 :             Reference< XDatabaseMetaData > xMetaData( _rxConnection->getMetaData(), UNO_QUERY_THROW );
     155             : 
     156           0 :             Reference< XResultSet > xRes = (xMetaData.get()->*_GetAll)();
     157           0 :             Reference< XRow > xRow( xRes, UNO_QUERY_THROW );
     158           0 :             OUString sValue;
     159           0 :             while ( xRes->next() )
     160             :             {
     161           0 :                 sValue = xRow->getString( 1 );
     162           0 :                 if ( !xRow->wasNull() )
     163           0 :                     _rList.InsertEntry( sValue );
     164             :             }
     165             : 
     166           0 :             sal_Int32 nPos = _rList.GetEntryPos( OUString( _rCurrent ) );
     167           0 :             if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
     168           0 :                 _rList.SelectEntryPos( nPos );
     169             :             else
     170           0 :                 _rList.SelectEntryPos( 0 );
     171             :         }
     172           0 :         catch( const Exception& )
     173             :         {
     174             :             DBG_UNHANDLED_EXCEPTION();
     175             :         }
     176           0 :     }
     177             : }
     178             : 
     179           0 : OSaveAsDlg::OSaveAsDlg( vcl::Window * pParent,
     180             :                         const sal_Int32& _rType,
     181             :                         const Reference< XComponentContext >& _rxContext,
     182             :                         const Reference< XConnection>& _xConnection,
     183             :                         const OUString& rDefault,
     184             :                         const IObjectNameCheck& _rObjectNameCheck,
     185             :                         sal_Int32 _nFlags)
     186             :     : ModalDialog(pParent, "SaveDialog", "dbaccess/ui/savedialog.ui")
     187           0 :     , m_xContext( _rxContext )
     188             : {
     189           0 :     m_pImpl = new OSaveAsDlgImpl(this,_rType,_xConnection,rDefault,_rObjectNameCheck,_nFlags);
     190             : 
     191           0 :     switch (_rType)
     192             :     {
     193             :         case CommandType::QUERY:
     194           0 :             implInitOnlyTitle(m_pImpl->m_aQryLabel);
     195           0 :             break;
     196             : 
     197             :         case CommandType::TABLE:
     198             :             OSL_ENSURE( m_pImpl->m_xMetaData.is(), "OSaveAsDlg::OSaveAsDlg: no meta data for entering table names: this will crash!" );
     199             :             {
     200           0 :                 m_pImpl->m_pLabel->SetText(m_pImpl->m_sTblLabel);
     201           0 :                 if(m_pImpl->m_xMetaData.is() && !m_pImpl->m_xMetaData->supportsCatalogsInTableDefinitions())
     202             :                 {
     203           0 :                     m_pImpl->m_pCatalogLbl->Hide();
     204           0 :                     m_pImpl->m_pCatalog->Hide();
     205             :                 }
     206             :                 else
     207             :                 {
     208             :                     // now fill the catalogs
     209           0 :                     lcl_fillComboList( *m_pImpl->m_pCatalog, _xConnection,
     210           0 :                         &XDatabaseMetaData::getCatalogs, _xConnection->getCatalog() );
     211             :                 }
     212             : 
     213           0 :                 if ( !m_pImpl->m_xMetaData->supportsSchemasInTableDefinitions())
     214             :                 {
     215           0 :                     m_pImpl->m_pSchemaLbl->Hide();
     216           0 :                     m_pImpl->m_pSchema->Hide();
     217             :                 }
     218             :                 else
     219             :                 {
     220           0 :                     lcl_fillComboList( *m_pImpl->m_pSchema, _xConnection,
     221           0 :                         &XDatabaseMetaData::getSchemas, m_pImpl->m_xMetaData->getUserName() );
     222             :                 }
     223             : 
     224             :                 OSL_ENSURE(m_pImpl->m_xMetaData.is(),"The metadata can not be null!");
     225           0 :                 if(m_pImpl->m_aName.indexOf('.') != -1)
     226             :                 {
     227           0 :                     OUString sCatalog,sSchema,sTable;
     228             :                     ::dbtools::qualifiedNameComponents(m_pImpl->m_xMetaData,
     229             :                                                         m_pImpl->m_aName,
     230             :                                                         sCatalog,
     231             :                                                         sSchema,
     232             :                                                         sTable,
     233           0 :                                                         ::dbtools::eInDataManipulation);
     234             : 
     235           0 :                     sal_Int32 nPos = m_pImpl->m_pCatalog->GetEntryPos(OUString(sCatalog));
     236           0 :                     if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
     237           0 :                         m_pImpl->m_pCatalog->SelectEntryPos(nPos);
     238             : 
     239           0 :                     if ( !sSchema.isEmpty() )
     240             :                     {
     241           0 :                         nPos = m_pImpl->m_pSchema->GetEntryPos(OUString(sSchema));
     242           0 :                         if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
     243           0 :                             m_pImpl->m_pSchema->SelectEntryPos(nPos);
     244             :                     }
     245           0 :                     m_pImpl->m_pTitle->SetText(sTable);
     246             :                 }
     247             :                 else
     248           0 :                     m_pImpl->m_pTitle->SetText(m_pImpl->m_aName);
     249           0 :                 m_pImpl->m_pTitle->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
     250             : 
     251           0 :                 sal_Int32 nLength =  m_pImpl->m_xMetaData.is() ? m_pImpl->m_xMetaData->getMaxTableNameLength() : 0;
     252           0 :                 nLength = nLength ? nLength : EDIT_NOLIMIT;
     253             : 
     254           0 :                 m_pImpl->m_pTitle->SetMaxTextLen(nLength);
     255           0 :                 m_pImpl->m_pSchema->SetMaxTextLen(nLength);
     256           0 :                 m_pImpl->m_pCatalog->SetMaxTextLen(nLength);
     257             : 
     258           0 :                 bool bCheck = _xConnection.is() && isSQL92CheckEnabled(_xConnection);
     259           0 :                 m_pImpl->m_pTitle->setCheck(bCheck); // enable non valid sql chars as well
     260           0 :                 m_pImpl->m_pSchema->setCheck(bCheck); // enable non valid sql chars as well
     261           0 :                 m_pImpl->m_pCatalog->setCheck(bCheck); // enable non valid sql chars as well
     262             :             }
     263           0 :             break;
     264             : 
     265             :         default:
     266             :             OSL_FAIL( "OSaveAsDlg::OSaveAsDlg: Type not supported yet!" );
     267             :     }
     268             : 
     269           0 :     implInit();
     270           0 : }
     271             : 
     272           0 : OSaveAsDlg::OSaveAsDlg( vcl::Window * pParent,
     273             :                         const Reference< XComponentContext >& _rxContext,
     274             :                         const OUString& rDefault,
     275             :                         const OUString& _sLabel,
     276             :                         const IObjectNameCheck& _rObjectNameCheck,
     277             :                         sal_Int32 _nFlags)
     278             :     : ModalDialog(pParent, "SaveDialog", "dbaccess/ui/savedialog.ui")
     279           0 :     , m_xContext( _rxContext )
     280             : {
     281           0 :     m_pImpl = new OSaveAsDlgImpl(this,rDefault,_rObjectNameCheck,_nFlags);
     282           0 :     implInitOnlyTitle(_sLabel);
     283           0 :     implInit();
     284           0 : }
     285             : 
     286           0 : OSaveAsDlg::~OSaveAsDlg()
     287             : {
     288           0 :     disposeOnce();
     289           0 : }
     290             : 
     291           0 : void OSaveAsDlg::dispose()
     292             : {
     293           0 :     DELETEZ(m_pImpl);
     294           0 :     ModalDialog::dispose();
     295           0 : }
     296             : 
     297           0 : IMPL_LINK(OSaveAsDlg, ButtonClickHdl, Button *, pButton)
     298             : {
     299           0 :     if (pButton == m_pImpl->m_pPB_OK)
     300             :     {
     301           0 :         m_pImpl->m_aName = m_pImpl->m_pTitle->GetText();
     302             : 
     303           0 :         OUString sNameToCheck( m_pImpl->m_aName );
     304             : 
     305           0 :         if ( m_pImpl->m_nType == CommandType::TABLE )
     306             :         {
     307           0 :             sNameToCheck = ::dbtools::composeTableName(
     308             :                 m_pImpl->m_xMetaData,
     309             :                 getCatalog(),
     310             :                 getSchema(),
     311             :                 sNameToCheck,
     312             :                 false,  // no quoting
     313             :                 ::dbtools::eInDataManipulation
     314           0 :             );
     315             :         }
     316             : 
     317           0 :         SQLExceptionInfo aNameError;
     318           0 :         if ( m_pImpl->m_rObjectNameCheck.isNameValid( sNameToCheck, aNameError ) )
     319           0 :             EndDialog( RET_OK );
     320             : 
     321           0 :         showError( aNameError, this, m_xContext );
     322           0 :         m_pImpl->m_pTitle->GrabFocus();
     323             :     }
     324           0 :     return 0;
     325             : }
     326             : 
     327           0 : IMPL_LINK(OSaveAsDlg, EditModifyHdl, Edit *, pEdit )
     328             : {
     329           0 :     if (pEdit == m_pImpl->m_pTitle)
     330           0 :         m_pImpl->m_pPB_OK->Enable(!m_pImpl->m_pTitle->GetText().isEmpty());
     331           0 :     return 0;
     332             : }
     333             : 
     334           0 : void OSaveAsDlg::implInitOnlyTitle(const OUString& _rLabel)
     335             : {
     336           0 :     m_pImpl->m_pLabel->SetText(_rLabel);
     337           0 :     m_pImpl->m_pCatalogLbl->Hide();
     338           0 :     m_pImpl->m_pCatalog->Hide();
     339           0 :     m_pImpl->m_pSchemaLbl->Hide();
     340           0 :     m_pImpl->m_pSchema->Hide();
     341             : 
     342           0 :     m_pImpl->m_pTitle->SetText(m_pImpl->m_aName);
     343           0 :     m_pImpl->m_pTitle->setCheck(false); // enable non valid sql chars as well
     344           0 : }
     345             : 
     346           0 : void OSaveAsDlg::implInit()
     347             : {
     348           0 :     if ( 0 == ( m_pImpl->m_nFlags & SAD_ADDITIONAL_DESCRIPTION ) )
     349             :     {
     350             :         // hide the description window
     351           0 :         m_pImpl->m_pDescription->Hide();
     352             :     }
     353             : 
     354           0 :     if ( SAD_TITLE_PASTE_AS == ( m_pImpl->m_nFlags & SAD_TITLE_PASTE_AS ) )
     355           0 :         SetText( ModuleRes( STR_TITLE_PASTE_AS ) );
     356           0 :     else if ( SAD_TITLE_RENAME == ( m_pImpl->m_nFlags & SAD_TITLE_RENAME ) )
     357           0 :         SetText( ModuleRes( STR_TITLE_RENAME ) );
     358             : 
     359           0 :     m_pImpl->m_pPB_OK->SetClickHdl(LINK(this,OSaveAsDlg,ButtonClickHdl));
     360           0 :     m_pImpl->m_pTitle->SetModifyHdl(LINK(this,OSaveAsDlg,EditModifyHdl));
     361           0 :     m_pImpl->m_pTitle->GrabFocus();
     362           0 : }
     363             : 
     364           0 : OUString OSaveAsDlg::getName() const      { return m_pImpl->m_aName; }
     365           0 : OUString OSaveAsDlg::getCatalog() const   { return m_pImpl->m_pCatalog->IsVisible() ? m_pImpl->m_pCatalog->GetText() : OUString(); }
     366          36 : OUString OSaveAsDlg::getSchema() const    { return m_pImpl->m_pSchema->IsVisible() ? m_pImpl->m_pSchema->GetText() : OUString(); }
     367             : 
     368             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11