LCOV - code coverage report
Current view: top level - cui/source/options - dbregister.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 229 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 30 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 "dbregister.hxx"
      21             : #include "dbregistersettings.hxx"
      22             : #include "connpooloptions.hxx"
      23             : #include <svl/filenotation.hxx>
      24             : #include "helpid.hrc"
      25             : #include <svtools/editbrowsebox.hxx>
      26             : #include "svtools/treelistentry.hxx"
      27             : #include <cuires.hrc>
      28             : #include <vcl/field.hxx>
      29             : #include <vcl/layout.hxx>
      30             : #include <svl/eitem.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <com/sun/star/uno/Exception.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      35             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      36             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      37             : #include <vcl/msgbox.hxx>
      38             : #include <svtools/svtabbx.hxx>
      39             : #include <svl/itemset.hxx>
      40             : #include "doclinkdialog.hxx"
      41             : #include <unotools/localfilehelper.hxx>
      42             : #include "optHeaderTabListbox.hxx"
      43             : #include <sfx2/docfilt.hxx>
      44             : #include <dialmgr.hxx>
      45             : #include "dbregisterednamesconfig.hxx"
      46             : #include <svx/dialogs.hrc>
      47             : 
      48             : #define TAB_WIDTH1      80
      49             : #define TAB_WIDTH_MIN   10
      50             : #define TAB_WIDTH2      1000
      51             : #define ITEMID_TYPE       1
      52             : #define ITEMID_PATH       2
      53             : 
      54             : namespace svx
      55             : {
      56             : 
      57             : 
      58             : using namespace ::com::sun::star::lang;
      59             : using namespace ::com::sun::star::ui::dialogs;
      60             : using namespace ::com::sun::star::uno;
      61             : using namespace ::svt;
      62             : 
      63             : // class RegistrationItemSetHolder  -------------------------------------------------
      64             : 
      65           0 : RegistrationItemSetHolder::RegistrationItemSetHolder( const SfxItemSet& _rMasterSet )
      66           0 :     :m_aRegistrationItems( _rMasterSet )
      67             : {
      68           0 :     DbRegisteredNamesConfig::GetOptions( m_aRegistrationItems );
      69           0 : }
      70             : 
      71           0 : RegistrationItemSetHolder::~RegistrationItemSetHolder()
      72             : {
      73           0 : }
      74             : 
      75             : // class DatabaseRegistrationDialog  ------------------------------------------------
      76             : 
      77           0 : DatabaseRegistrationDialog::DatabaseRegistrationDialog( vcl::Window* pParent, const SfxItemSet& rInAttrs )
      78             :     : RegistrationItemSetHolder(rInAttrs)
      79           0 :     , SfxSingleTabDialog(pParent, getRegistrationItems())
      80             : {
      81           0 :     VclPtr<SfxTabPage> page = DbRegistrationOptionsPage::Create(get_content_area(), &getRegistrationItems());
      82           0 :     SetTabPage(page);
      83           0 :     SetText(page->get<VclFrame>("frame1")->get_label());
      84           0 : }
      85             : 
      86           0 : short DatabaseRegistrationDialog::Execute()
      87             : {
      88           0 :     short result = SfxSingleTabDialog::Execute();
      89           0 :     if ( result == RET_OK )
      90             :     {
      91             :         DBG_ASSERT( GetOutputItemSet(), "DatabaseRegistrationDialog::Execute: no output items!" );
      92           0 :         if ( GetOutputItemSet() )
      93           0 :             DbRegisteredNamesConfig::SetOptions( *GetOutputItemSet() );
      94             :     }
      95           0 :     return result;
      96             : }
      97             : 
      98             : // class DbRegistrationOptionsPage --------------------------------------------------
      99             : 
     100           0 : DbRegistrationOptionsPage::DbRegistrationOptionsPage( vcl::Window* pParent, const SfxItemSet& rSet ) :
     101             : 
     102             :     SfxTabPage( pParent, "DbRegisterPage", "cui/ui/dbregisterpage.ui", &rSet ),
     103             : 
     104           0 :     aTypeText       ( CUI_RES( RID_SVXSTR_TYPE ) ),
     105           0 :     aPathText       ( CUI_RES( RID_SVXSTR_PATH ) ),
     106             :     pPathBox        ( NULL ),
     107             :     m_pCurEntry     ( NULL ),
     108             :     m_nOldCount     ( 0 ),
     109           0 :     m_bModified     ( false )
     110             : {
     111           0 :     get(m_pPathCtrl, "pathctrl");
     112           0 :     Size aControlSize(248, 147);
     113           0 :     aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
     114           0 :     m_pPathCtrl->set_width_request(aControlSize.Width());
     115           0 :     m_pPathCtrl->set_height_request(aControlSize.Height());
     116             : 
     117           0 :     get(m_pNew, "new");
     118           0 :     get(m_pEdit, "edit");
     119           0 :     get(m_pDelete, "delete");
     120             : 
     121           0 :     m_pNew->SetClickHdl( LINK( this, DbRegistrationOptionsPage, NewHdl ) );
     122           0 :     m_pEdit->SetClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
     123           0 :     m_pDelete->SetClickHdl( LINK( this, DbRegistrationOptionsPage, DeleteHdl ) );
     124             : 
     125           0 :     Size aBoxSize = m_pPathCtrl->GetOutputSizePixel();
     126             : 
     127           0 :     WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
     128           0 :     pPathBox = VclPtr<svx::OptHeaderTabListBox>::Create( *m_pPathCtrl, nBits );
     129             : 
     130           0 :     HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     131             : 
     132           0 :     rBar.SetSelectHdl( LINK( this, DbRegistrationOptionsPage, HeaderSelect_Impl ) );
     133           0 :     rBar.SetEndDragHdl( LINK( this, DbRegistrationOptionsPage, HeaderEndDrag_Impl ) );
     134           0 :     Size aSz;
     135           0 :     aSz.Width() = TAB_WIDTH1;
     136             :     rBar.InsertItem( ITEMID_TYPE, aTypeText,
     137           0 :                             LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
     138           0 :                             HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE | HeaderBarItemBits::UPARROW );
     139           0 :     aSz.Width() = TAB_WIDTH2;
     140             :     rBar.InsertItem( ITEMID_PATH, aPathText,
     141           0 :                             LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
     142           0 :                             HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
     143             : 
     144             :     static long aTabs[] = {3, 0, TAB_WIDTH1, TAB_WIDTH1 + TAB_WIDTH2 };
     145           0 :     Size aHeadSize = rBar.GetSizePixel();
     146             : 
     147           0 :     pPathBox->SetStyle( pPathBox->GetStyle()|nBits );
     148           0 :     pPathBox->SetDoubleClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
     149           0 :     pPathBox->SetSelectHdl( LINK( this, DbRegistrationOptionsPage, PathSelect_Impl ) );
     150           0 :     pPathBox->SetSelectionMode( SINGLE_SELECTION );
     151           0 :     pPathBox->SetPosSizePixel( Point( 0, aHeadSize.Height() ),
     152           0 :                                Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
     153           0 :     pPathBox->SvSimpleTable::SetTabs( aTabs, MAP_APPFONT );
     154           0 :     pPathBox->SetHighlightRange();
     155             : 
     156           0 :     pPathBox->SetHelpId( HID_DBPATH_CTL_PATH );
     157           0 :     rBar.SetHelpId( HID_DBPATH_HEADERBAR );
     158             : 
     159           0 :     pPathBox->ShowTable();
     160           0 : }
     161             : 
     162             : 
     163             : 
     164           0 : DbRegistrationOptionsPage::~DbRegistrationOptionsPage()
     165             : {
     166           0 :     disposeOnce();
     167           0 : }
     168             : 
     169           0 : void DbRegistrationOptionsPage::dispose()
     170             : {
     171           0 :     for ( sal_uLong i = 0; i < pPathBox->GetEntryCount(); ++i )
     172           0 :         delete static_cast< DatabaseRegistration* >( pPathBox->GetEntry(i)->GetUserData() );
     173           0 :     pPathBox.disposeAndClear();
     174           0 :     m_pPathCtrl.clear();
     175           0 :     m_pNew.clear();
     176           0 :     m_pEdit.clear();
     177           0 :     m_pDelete.clear();
     178           0 :     SfxTabPage::dispose();
     179           0 : }
     180             : 
     181             : 
     182             : 
     183           0 : VclPtr<SfxTabPage> DbRegistrationOptionsPage::Create( vcl::Window* pParent,
     184             :                                     const SfxItemSet* rAttrSet )
     185             : {
     186           0 :     return VclPtr<DbRegistrationOptionsPage>::Create( pParent, *rAttrSet );
     187             : }
     188             : 
     189             : 
     190             : 
     191           0 : bool DbRegistrationOptionsPage::FillItemSet( SfxItemSet* rCoreSet )
     192             : {
     193             :     // the settings for the single drivers
     194           0 :     bool bModified = false;
     195           0 :     DatabaseRegistrations aRegistrations;
     196           0 :     sal_uLong nCount = pPathBox->GetEntryCount();
     197           0 :     for ( sal_uLong i = 0; i < nCount; ++i )
     198             :     {
     199           0 :         SvTreeListEntry* pEntry = pPathBox->GetEntry(i);
     200           0 :         DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
     201           0 :         if ( pRegistration && !pRegistration->sLocation.isEmpty() )
     202             :         {
     203           0 :             OUString sName( SvTabListBox::GetEntryText( pEntry, 0 ) );
     204           0 :             OFileNotation aTransformer( pRegistration->sLocation );
     205           0 :             aRegistrations[ sName ] = DatabaseRegistration( aTransformer.get( OFileNotation::N_URL ), pRegistration->bReadOnly );
     206             :         }
     207             :     }
     208           0 :     if ( m_nOldCount != aRegistrations.size() || m_bModified )
     209             :     {
     210           0 :         rCoreSet->Put(DatabaseMapItem( SID_SB_DB_REGISTER, aRegistrations ), SID_SB_DB_REGISTER);
     211           0 :         bModified = true;
     212             :     }
     213             : 
     214           0 :     return bModified;
     215             : }
     216             : 
     217             : 
     218             : 
     219           0 : void DbRegistrationOptionsPage::Reset( const SfxItemSet* rSet )
     220             : {
     221             :     // the settings for the single drivers
     222           0 :     SFX_ITEMSET_GET( *rSet, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, true );
     223           0 :     if ( !pRegistrations )
     224           0 :         return;
     225             : 
     226           0 :     pPathBox->Clear();
     227             : 
     228           0 :     const DatabaseRegistrations& rRegistrations = pRegistrations->getRegistrations();
     229           0 :     m_nOldCount = rRegistrations.size();
     230           0 :     DatabaseRegistrations::const_iterator aIter = rRegistrations.begin();
     231           0 :     DatabaseRegistrations::const_iterator aEnd = rRegistrations.end();
     232           0 :     for ( ; aIter != aEnd; ++aIter )
     233             :     {
     234           0 :         OFileNotation aTransformer( aIter->second.sLocation );
     235           0 :         insertNewEntry( aIter->first, aTransformer.get( OFileNotation::N_SYSTEM ), aIter->second.bReadOnly );
     236           0 :     }
     237             : 
     238           0 :     OUString aUserData = GetUserData();
     239           0 :     if ( !aUserData.isEmpty() )
     240             :     {
     241           0 :         HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     242             : 
     243             :         // restore column width
     244           0 :         rBar.SetItemSize( ITEMID_TYPE, aUserData.getToken(0, ';').toInt32() );
     245           0 :         HeaderEndDrag_Impl( &rBar );
     246             :         // restore sort direction
     247           0 :         bool bUp = aUserData.getToken(1, ';').toInt32() != 0;
     248           0 :         HeaderBarItemBits nBits = rBar.GetItemBits(ITEMID_TYPE);
     249             : 
     250           0 :         if ( bUp )
     251             :         {
     252           0 :             nBits &= ~HeaderBarItemBits::UPARROW;
     253           0 :             nBits |= HeaderBarItemBits::DOWNARROW;
     254             :         }
     255             :         else
     256             :         {
     257           0 :             nBits &= ~HeaderBarItemBits::DOWNARROW;
     258           0 :             nBits |= HeaderBarItemBits::UPARROW;
     259             :         }
     260           0 :         rBar.SetItemBits( ITEMID_TYPE, nBits );
     261           0 :         HeaderSelect_Impl( &rBar );
     262           0 :     }
     263             : }
     264             : 
     265           0 : void DbRegistrationOptionsPage::FillUserData()
     266             : {
     267           0 :     HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     268             : 
     269           0 :     OUString aUserData = OUString::number( rBar.GetItemSize( ITEMID_TYPE ) ) + ";";
     270           0 :     HeaderBarItemBits nBits = rBar.GetItemBits( ITEMID_TYPE );
     271           0 :     bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
     272           0 :     aUserData += (bUp ? OUString("1") : OUString("0"));
     273           0 :     SetUserData( aUserData );
     274           0 : }
     275             : 
     276           0 : IMPL_LINK_NOARG(DbRegistrationOptionsPage, DeleteHdl)
     277             : {
     278           0 :     SvTreeListEntry* pEntry = pPathBox->FirstSelected();
     279           0 :     if ( pEntry )
     280             :     {
     281           0 :         ScopedVclPtrInstance< MessageDialog > aQuery(this, CUI_RES(RID_SVXSTR_QUERY_DELETE_CONFIRM), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
     282           0 :         if ( aQuery->Execute() == RET_YES )
     283           0 :             pPathBox->GetModel()->Remove(pEntry);
     284             :     }
     285           0 :     return 0;
     286             : }
     287             : 
     288           0 : IMPL_LINK_NOARG(DbRegistrationOptionsPage, NewHdl)
     289             : {
     290           0 :     OUString sNewName,sNewLocation;
     291           0 :     openLinkDialog(sNewName,sNewLocation);
     292           0 :     return 0;
     293             : }
     294             : 
     295           0 : IMPL_LINK_NOARG(DbRegistrationOptionsPage, EditHdl)
     296             : {
     297           0 :     SvTreeListEntry* pEntry = pPathBox->GetCurEntry();
     298           0 :     if ( !pEntry )
     299           0 :         return 0L;
     300             : 
     301           0 :     DatabaseRegistration* pOldRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
     302           0 :     if ( !pOldRegistration || pOldRegistration->bReadOnly )
     303           0 :         return 0L;
     304             : 
     305           0 :     OUString sOldName = SvTabListBox::GetEntryText(pEntry,0);
     306           0 :     m_pCurEntry = pEntry;
     307           0 :     openLinkDialog( sOldName, pOldRegistration->sLocation, pEntry );
     308           0 :     m_pCurEntry = NULL;
     309             : 
     310           0 :     return 1L;
     311             : }
     312             : 
     313             : 
     314             : 
     315           0 : IMPL_LINK( DbRegistrationOptionsPage, HeaderSelect_Impl, HeaderBar*, pBar )
     316             : {
     317             :     assert(pBar);
     318             : 
     319           0 :     if (!pBar || pBar->GetCurItemId() != ITEMID_TYPE)
     320           0 :         return 0;
     321             : 
     322           0 :     HeaderBarItemBits nBits = pBar->GetItemBits(ITEMID_TYPE);
     323           0 :     bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
     324           0 :     SvSortMode eMode = SortAscending;
     325             : 
     326           0 :     if ( bUp )
     327             :     {
     328           0 :         nBits &= ~HeaderBarItemBits::UPARROW;
     329           0 :         nBits |= HeaderBarItemBits::DOWNARROW;
     330           0 :         eMode = SortDescending;
     331             :     }
     332             :     else
     333             :     {
     334           0 :         nBits &= ~HeaderBarItemBits::DOWNARROW;
     335           0 :         nBits |= HeaderBarItemBits::UPARROW;
     336             :     }
     337           0 :     pBar->SetItemBits( ITEMID_TYPE, nBits );
     338           0 :     SvTreeList* pModel = pPathBox->GetModel();
     339           0 :     pModel->SetSortMode( eMode );
     340           0 :     pModel->Resort();
     341           0 :     return 1;
     342             : }
     343             : 
     344             : 
     345             : 
     346           0 : IMPL_LINK( DbRegistrationOptionsPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
     347             : {
     348             :     assert(pBar);
     349             : 
     350           0 :     if (!pBar || !pBar->GetCurItemId())
     351           0 :         return 0;
     352             : 
     353           0 :     if ( !pBar->IsItemMode() )
     354             :     {
     355           0 :         Size aSz;
     356           0 :         sal_uInt16 nTabs = pBar->GetItemCount();
     357           0 :         long nTmpSz = 0;
     358           0 :         long nWidth = pBar->GetItemSize(ITEMID_TYPE);
     359           0 :         long nBarWidth = pBar->GetSizePixel().Width();
     360             : 
     361           0 :         if(nWidth < TAB_WIDTH_MIN)
     362           0 :             pBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
     363           0 :         else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
     364           0 :             pBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
     365             : 
     366           0 :         for ( sal_uInt16 i = 1; i <= nTabs; ++i )
     367             :         {
     368           0 :             long _nWidth = pBar->GetItemSize(i);
     369           0 :             aSz.Width() =  _nWidth + nTmpSz;
     370           0 :             nTmpSz += _nWidth;
     371           0 :             pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     372             :         }
     373             :     }
     374           0 :     return 1;
     375             : }
     376             : 
     377             : 
     378           0 : IMPL_LINK_NOARG(DbRegistrationOptionsPage, PathSelect_Impl)
     379             : {
     380           0 :     SvTreeListEntry* pEntry = pPathBox->FirstSelected();
     381             : 
     382           0 :     bool bReadOnly = true;
     383           0 :     if ( pEntry )
     384             :     {
     385           0 :         DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
     386           0 :         bReadOnly = pRegistration->bReadOnly;
     387             :     }
     388             : 
     389           0 :     m_pEdit->Enable( !bReadOnly );
     390           0 :     m_pDelete->Enable( !bReadOnly );
     391           0 :     return 0;
     392             : }
     393             : 
     394           0 : void DbRegistrationOptionsPage::insertNewEntry( const OUString& _sName,const OUString& _sLocation, const bool _bReadOnly )
     395             : {
     396           0 :     OUString aStr( _sName );
     397           0 :     aStr += "\t";
     398           0 :     aStr += _sLocation;
     399             : 
     400           0 :     SvTreeListEntry* pEntry = NULL;
     401           0 :     if ( _bReadOnly )
     402             :     {
     403           0 :         Image aLocked( CUI_RES( RID_SVXBMP_LOCK ) );
     404           0 :         pEntry = pPathBox->InsertEntry( aStr, aLocked, aLocked );
     405             :     }
     406             :     else
     407             :     {
     408           0 :         pEntry = pPathBox->InsertEntry( aStr );
     409             :     }
     410             : 
     411           0 :     pEntry->SetUserData( new DatabaseRegistration( _sLocation, _bReadOnly ) );
     412           0 : }
     413             : 
     414             : 
     415           0 : void DbRegistrationOptionsPage::openLinkDialog(const OUString& _sOldName,const OUString& _sOldLocation,SvTreeListEntry* _pEntry)
     416             : {
     417           0 :     ScopedVclPtrInstance< ODocumentLinkDialog > aDlg(this,_pEntry == nullptr);
     418             : 
     419           0 :     aDlg->setLink(_sOldName,_sOldLocation);
     420           0 :     aDlg->setNameValidator(LINK( this, DbRegistrationOptionsPage, NameValidator ) );
     421             : 
     422           0 :     if ( aDlg->Execute() == RET_OK )
     423             :     {
     424           0 :         OUString sNewName,sNewLocation;
     425           0 :         aDlg->getLink(sNewName,sNewLocation);
     426           0 :         if ( _pEntry == NULL || sNewName != _sOldName || sNewLocation != _sOldLocation )
     427             :         {
     428           0 :             if ( _pEntry )
     429             :             {
     430           0 :                 delete static_cast< DatabaseRegistration* >( _pEntry->GetUserData() );
     431           0 :                 pPathBox->GetModel()->Remove( _pEntry );
     432             :             }
     433           0 :             insertNewEntry( sNewName, sNewLocation, false );
     434           0 :             m_bModified = true;
     435           0 :         }
     436           0 :     }
     437           0 : }
     438             : 
     439           0 : IMPL_LINK( DbRegistrationOptionsPage, NameValidator, OUString*, _pName )
     440             : {
     441           0 :     if ( _pName )
     442             :     {
     443           0 :         sal_uLong nCount = pPathBox->GetEntryCount();
     444           0 :         for ( sal_uLong i = 0; i < nCount; ++i )
     445             :         {
     446           0 :             SvTreeListEntry* pEntry = pPathBox->GetEntry(i);
     447           0 :             if ( (!m_pCurEntry || m_pCurEntry != pEntry) && SvTabListBox::GetEntryText(pEntry,0) == *_pName )
     448           0 :                 return 0L;
     449             :         }
     450             :     }
     451           0 :     return 1L;
     452             : }
     453             : 
     454           0 : }
     455             : 
     456             : 
     457             : 
     458             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11