tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / dbaccess / source / ui / dlg / dsselect.cxx
blob3d4a17b8ffcdc8a41b8ab3f99d2ed496a1c98c9e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
23 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
25 namespace dbaui
27 ODatasourceSelectDialog::ODatasourceSelectDialog(weld::Window* _pParent, const std::set<OUString>& _rDatasources)
28 : GenericDialogController(_pParent, u"dbaccess/ui/choosedatasourcedialog.ui"_ustr, u"ChooseDataSourceDialog"_ustr)
29 , m_xDatasource(m_xBuilder->weld_tree_view(u"treeview"_ustr))
31 m_xDatasource->set_size_request(-1, m_xDatasource->get_height_rows(6));
33 fillListBox(_rDatasources);
34 #ifdef HAVE_ODBC_ADMINISTRATION
35 // allow ODBC datasource management
36 m_xManageDatasources->show();
37 m_xManageDatasources->set_sensitive(true);
38 m_xManageDatasources->connect_clicked(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
39 #endif
40 m_xDatasource->connect_row_activated(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
43 ODatasourceSelectDialog::~ODatasourceSelectDialog()
47 IMPL_LINK(ODatasourceSelectDialog, ListDblClickHdl, weld::TreeView&, rListBox, bool)
49 if (rListBox.n_children())
50 m_xDialog->response(RET_OK);
51 return true;
54 short ODatasourceSelectDialog::run()
56 short nRet = GenericDialogController::run();
57 #ifdef HAVE_ODBC_ADMINISTRATION
58 if (m_xODBCManagement.get())
59 m_xODBCManagement->disableCallback();
60 #endif
61 return nRet;
64 #ifdef HAVE_ODBC_ADMINISTRATION
65 IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, weld::Button&, void)
67 if ( !m_xODBCManagement.get() )
68 m_xODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
70 if ( !m_xODBCManagement->manageDataSources_async() )
72 // TODO: error message
73 m_xDatasource->grab_focus();
74 m_xManageDatasources->set_sensitive(false);
75 return;
78 m_xDatasource->set_sensitive(false);
79 m_xOk->set_sensitive(false);
80 m_xCancel->set_sensitive(false);
81 m_xManageDatasources->set_sensitive(false);
83 SAL_WARN_IF( !m_xODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
86 IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void )
88 m_xODBCManagement->receivedCallback();
90 std::set<OUString> aOdbcDatasources;
91 OOdbcEnumeration aEnumeration;
92 aEnumeration.getDatasourceNames( aOdbcDatasources );
93 fillListBox( aOdbcDatasources );
95 m_xDatasource->set_sensitive(true);
96 m_xOk->set_sensitive(true);
97 m_xCancel->set_sensitive(true);
98 m_xManageDatasources->set_sensitive(true);
101 #endif
102 void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources)
104 OUString sSelected;
105 if (m_xDatasource->n_children())
106 sSelected = m_xDatasource->get_selected_text();
107 m_xDatasource->clear();
108 // fill the list
109 for (auto const& datasource : _rDatasources)
111 m_xDatasource->append_text(datasource);
114 if (m_xDatasource->n_children())
116 if (!sSelected.isEmpty())
117 m_xDatasource->select_text(sSelected);
118 else // select the first entry
119 m_xDatasource->select(0);
123 } // namespace dbaui
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */