1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dsselect.hxx"
21 #include "dbu_dlg.hrc"
22 #include <vcl/msgbox.hxx>
23 #include "localresaccess.hxx"
24 #include <tools/rcid.h>
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>
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 ODatasourceSelectDialog::ODatasourceSelectDialog(vcl::Window
* _pParent
, const StringBag
& _rDatasources
, SfxItemSet
* _pOutputSet
)
51 : ModalDialog(_pParent
, "ChooseDataSourceDialog",
52 "dbaccess/ui/choosedatasourcedialog.ui")
53 , m_pOutputSet(_pOutputSet
)
55 get(m_pDatasource
, "treeview");
56 m_pDatasource
->set_height_request(m_pDatasource
->GetTextHeight() * 6);
58 get(m_pCancel
, "cancel");
60 fillListBox(_rDatasources
);
61 #ifdef HAVE_ODBC_ADMINISTRATION
62 get(m_pManageDatasources
, "organize");
63 m_pManageDatasources
->Show();
65 // allow ODBC datasource managenment
66 m_pManageDatasources
->Show();
67 m_pManageDatasources
->Enable();
68 m_pManageDatasources
->SetClickHdl(LINK(this,ODatasourceSelectDialog
,ManageClickHdl
));
70 m_pDatasource
->SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog
,ListDblClickHdl
));
73 ODatasourceSelectDialog::~ODatasourceSelectDialog()
78 void ODatasourceSelectDialog::dispose()
80 m_pDatasource
.clear();
83 ModalDialog::dispose();
87 IMPL_LINK( ODatasourceSelectDialog
, ListDblClickHdl
, ListBox
*, pListBox
)
89 if (pListBox
->GetSelectEntryCount())
94 bool ODatasourceSelectDialog::Close()
96 #ifdef HAVE_ODBC_ADMINISTRATION
97 if ( m_pODBCManagement
.get() && m_pODBCManagement
->isRunning() )
101 return ModalDialog::Close();
104 #ifdef HAVE_ODBC_ADMINISTRATION
105 IMPL_LINK_NOARG(ODatasourceSelectDialog
, ManageClickHdl
)
107 if ( !m_pODBCManagement
.get() )
108 m_pODBCManagement
.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog
, ManageProcessFinished
) ) );
110 if ( !m_pODBCManagement
->manageDataSources_async() )
112 // TODO: error message
113 m_pDatasource
->GrabFocus();
114 m_pManageDatasources
->Disable();
118 m_pDatasource
->Disable();
120 m_pCancel
->Disable();
121 m_pManageDatasources
->Disable();
123 SAL_WARN_IF( !m_pODBCManagement
->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
127 IMPL_LINK_NOARG( ODatasourceSelectDialog
, ManageProcessFinished
)
129 StringBag aOdbcDatasources
;
130 OOdbcEnumeration aEnumeration
;
131 aEnumeration
.getDatasourceNames( aOdbcDatasources
);
132 fillListBox( aOdbcDatasources
);
134 m_pDatasource
->Enable();
137 m_pManageDatasources
->Enable();
143 void ODatasourceSelectDialog::fillListBox(const StringBag
& _rDatasources
)
146 if (m_pDatasource
->GetEntryCount())
147 sSelected
= m_pDatasource
->GetSelectEntry();
148 m_pDatasource
->Clear();
150 for ( StringBag::const_iterator aDS
= _rDatasources
.begin();
151 aDS
!= _rDatasources
.end();
155 m_pDatasource
->InsertEntry( *aDS
);
158 if (m_pDatasource
->GetEntryCount())
160 if (!sSelected
.isEmpty())
161 m_pDatasource
->SelectEntry(sSelected
);
162 else // select the first entry
163 m_pDatasource
->SelectEntryPos(0);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */