LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - dsselect.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 39 2.6 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.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 "dsselect.hxx"
      21             : #include "dbu_dlg.hrc"
      22             : #include <vcl/msgbox.hxx>
      23             : #include "localresaccess.hxx"
      24             : #include <tools/rcid.h>
      25             : 
      26             : #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      29             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      30             : #include <com/sun/star/awt/XWindow.hpp>
      31             : #include "dbustrings.hrc"
      32             : #include <toolkit/helper/vclunohelper.hxx>
      33             : #include <comphelper/extract.hxx>
      34             : #include <comphelper/types.hxx>
      35             : #include <comphelper/processfactory.hxx>
      36             : #include "dsitems.hxx"
      37             : #include <svl/stritem.hxx>
      38             : #include <svl/intitem.hxx>
      39             : #include <svl/eitem.hxx>
      40             : #include <svl/itemset.hxx>
      41             : 
      42             : namespace dbaui
      43             : {
      44             : using namespace ::com::sun::star::uno;
      45             : using namespace ::com::sun::star::beans;
      46             : using namespace ::com::sun::star::sdbc;
      47             : using namespace ::com::sun::star::sdbcx;
      48             : using namespace ::com::sun::star::ui::dialogs;
      49             : using namespace ::comphelper;
      50           0 : ODatasourceSelectDialog::ODatasourceSelectDialog(vcl::Window* _pParent, const StringBag& _rDatasources, SfxItemSet* _pOutputSet)
      51             :     : ModalDialog(_pParent, "ChooseDataSourceDialog",
      52             :         "dbaccess/ui/choosedatasourcedialog.ui")
      53           0 :     , m_pOutputSet(_pOutputSet)
      54             : {
      55           0 :     get(m_pDatasource, "treeview");
      56           0 :     m_pDatasource->set_height_request(m_pDatasource->GetTextHeight() * 6);
      57           0 :     get(m_pOk, "ok");
      58           0 :     get(m_pCancel, "cancel");
      59             : 
      60           0 :     fillListBox(_rDatasources);
      61             : #ifdef HAVE_ODBC_ADMINISTRATION
      62             :     get(m_pManageDatasources, "organize");
      63             :     m_pManageDatasources->Show();
      64             : 
      65             :     // allow ODBC datasource managenment
      66             :     m_pManageDatasources->Show();
      67             :     m_pManageDatasources->Enable();
      68             :     m_pManageDatasources->SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
      69             : #endif
      70           0 :     m_pDatasource->SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
      71           0 : }
      72             : 
      73           0 : ODatasourceSelectDialog::~ODatasourceSelectDialog()
      74             : {
      75           0 :     disposeOnce();
      76           0 : }
      77             : 
      78           0 : void ODatasourceSelectDialog::dispose()
      79             : {
      80           0 :     m_pDatasource.clear();
      81           0 :     m_pOk.clear();
      82           0 :     m_pCancel.clear();
      83           0 :     ModalDialog::dispose();
      84           0 : }
      85             : 
      86             : 
      87           0 : IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox )
      88             : {
      89           0 :     if (pListBox->GetSelectEntryCount())
      90           0 :         EndDialog(RET_OK);
      91           0 :     return 0;
      92             : }
      93             : 
      94           0 : bool ODatasourceSelectDialog::Close()
      95             : {
      96             : #ifdef HAVE_ODBC_ADMINISTRATION
      97             :     if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() )
      98             :         return sal_False;
      99             : #endif
     100             : 
     101           0 :     return ModalDialog::Close();
     102             : }
     103             : 
     104             : #ifdef HAVE_ODBC_ADMINISTRATION
     105             : IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl)
     106             : {
     107             :     if ( !m_pODBCManagement.get() )
     108             :         m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
     109             : 
     110             :     if ( !m_pODBCManagement->manageDataSources_async() )
     111             :     {
     112             :         // TODO: error message
     113             :         m_pDatasource->GrabFocus();
     114             :         m_pManageDatasources->Disable();
     115             :         return 1L;
     116             :     }
     117             : 
     118             :     m_pDatasource->Disable();
     119             :     m_pOk->Disable();
     120             :     m_pCancel->Disable();
     121             :     m_pManageDatasources->Disable();
     122             : 
     123             :     SAL_WARN_IF( !m_pODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
     124             :     return 0L;
     125             : }
     126             : 
     127             : IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished )
     128             : {
     129             :     StringBag aOdbcDatasources;
     130             :     OOdbcEnumeration aEnumeration;
     131             :     aEnumeration.getDatasourceNames( aOdbcDatasources );
     132             :     fillListBox( aOdbcDatasources );
     133             : 
     134             :     m_pDatasource->Enable();
     135             :     m_pOk->Enable();
     136             :     m_pCancel->Enable();
     137             :     m_pManageDatasources->Enable();
     138             : 
     139             :     return 0L;
     140             : }
     141             : 
     142             : #endif
     143           0 : void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources)
     144             : {
     145           0 :     OUString sSelected;
     146           0 :     if (m_pDatasource->GetEntryCount())
     147           0 :          sSelected = m_pDatasource->GetSelectEntry();
     148           0 :     m_pDatasource->Clear();
     149             :     // fill the list
     150           0 :     for (   StringBag::const_iterator aDS = _rDatasources.begin();
     151           0 :             aDS != _rDatasources.end();
     152             :             ++aDS
     153             :         )
     154             :     {
     155           0 :         m_pDatasource->InsertEntry( *aDS );
     156             :     }
     157             : 
     158           0 :     if (m_pDatasource->GetEntryCount())
     159             :     {
     160           0 :         if (!sSelected.isEmpty())
     161           0 :             m_pDatasource->SelectEntry(sSelected);
     162             :         else        // select the first entry
     163           0 :             m_pDatasource->SelectEntryPos(0);
     164           0 :     }
     165           0 : }
     166             : 
     167          36 : }   // namespace dbaui
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11