LibreOffice Module dbaccess (master) 1
dsselect.cxx
Go to the documentation of this file.
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
22#include <com/sun/star/sdbcx/XCreateCatalog.hpp>
23#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
24
25namespace dbaui
26{
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::beans;
29using namespace ::com::sun::star::sdbcx;
30using namespace ::com::sun::star::ui::dialogs;
31
32ODatasourceSelectDialog::ODatasourceSelectDialog(weld::Window* _pParent, const std::set<OUString>& _rDatasources)
33 : GenericDialogController(_pParent, "dbaccess/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
34 , m_xDatasource(m_xBuilder->weld_tree_view("treeview"))
35{
36 m_xDatasource->set_size_request(-1, m_xDatasource->get_height_rows(6));
37
38 fillListBox(_rDatasources);
39#ifdef HAVE_ODBC_ADMINISTRATION
40 // allow ODBC datasource management
41 m_xManageDatasources->show();
42 m_xManageDatasources->set_sensitive(true);
43 m_xManageDatasources->connect_clicked(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
44#endif
45 m_xDatasource->connect_row_activated(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
46}
47
49{
50}
51
52IMPL_LINK(ODatasourceSelectDialog, ListDblClickHdl, weld::TreeView&, rListBox, bool)
53{
54 if (rListBox.n_children())
55 m_xDialog->response(RET_OK);
56 return true;
57}
58
60{
61 short nRet = GenericDialogController::run();
62#ifdef HAVE_ODBC_ADMINISTRATION
63 if (m_xODBCManagement.get())
64 m_xODBCManagement->disableCallback();
65#endif
66 return nRet;
67}
68
69#ifdef HAVE_ODBC_ADMINISTRATION
71{
72 if ( !m_xODBCManagement.get() )
73 m_xODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
74
75 if ( !m_xODBCManagement->manageDataSources_async() )
76 {
77 // TODO: error message
78 m_xDatasource->grab_focus();
79 m_xManageDatasources->set_sensitive(false);
80 return;
81 }
82
83 m_xDatasource->set_sensitive(false);
84 m_xOk->set_sensitive(false);
85 m_xCancel->set_sensitive(false);
86 m_xManageDatasources->set_sensitive(false);
87
88 SAL_WARN_IF( !m_xODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
89}
90
91IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void )
92{
93 m_xODBCManagement->receivedCallback();
94
95 std::set<OUString> aOdbcDatasources;
96 OOdbcEnumeration aEnumeration;
97 aEnumeration.getDatasourceNames( aOdbcDatasources );
98 fillListBox( aOdbcDatasources );
99
100 m_xDatasource->set_sensitive(true);
101 m_xOk->set_sensitive(true);
102 m_xCancel->set_sensitive(true);
103 m_xManageDatasources->set_sensitive(true);
104}
105
106#endif
107void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources)
108{
109 OUString sSelected;
110 if (m_xDatasource->n_children())
111 sSelected = m_xDatasource->get_selected_text();
112 m_xDatasource->clear();
113 // fill the list
114 for (auto const& datasource : _rDatasources)
115 {
116 m_xDatasource->append_text(datasource);
117 }
118
119 if (m_xDatasource->n_children())
120 {
121 if (!sSelected.isEmpty())
122 m_xDatasource->select_text(sSelected);
123 else // select the first entry
124 m_xDatasource->select(0);
125 }
126}
127
128} // namespace dbaui
129
130/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
virtual ~ODatasourceSelectDialog() override
Definition: dsselect.cxx:48
ODatasourceSelectDialog(weld::Window *pParent, const std::set< OUString > &rDatasources)
Definition: dsselect.cxx:32
void fillListBox(const std::set< OUString > &_rDatasources)
Definition: dsselect.cxx:107
std::unique_ptr< weld::TreeView > m_xDatasource
Definition: dsselect.hxx:34
virtual short run() override
Definition: dsselect.cxx:59
#define SAL_WARN_IF(condition, area, stream)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
RET_OK