2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-10-24 11:14:02 +00:00
|
|
|
|
|
|
|
#include "dsselect.hxx"
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <dbu_dlg.hxx>
|
2000-10-24 11:14:02 +00:00
|
|
|
|
2004-08-02 14:47:57 +00:00
|
|
|
#include <com/sun/star/sdbcx/XCreateCatalog.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
|
|
|
|
#include <com/sun/star/awt/XWindow.hpp>
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <stringconstants.hxx>
|
|
|
|
#include <dsitems.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/stritem.hxx>
|
|
|
|
#include <svl/intitem.hxx>
|
|
|
|
#include <svl/eitem.hxx>
|
|
|
|
#include <svl/itemset.hxx>
|
2018-07-27 09:42:16 +02:00
|
|
|
#include <sal/log.hxx>
|
2000-10-24 11:14:02 +00:00
|
|
|
|
|
|
|
namespace dbaui
|
|
|
|
{
|
2004-08-02 14:47:57 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::ui::dialogs;
|
|
|
|
using namespace ::comphelper;
|
2015-11-20 14:06:06 +02:00
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
ODatasourceSelectDialog::ODatasourceSelectDialog(weld::Window* _pParent, const std::set<OUString>& _rDatasources)
|
|
|
|
: GenericDialogController(_pParent, "dbaccess/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
|
|
|
|
, m_xDatasource(m_xBuilder->weld_tree_view("treeview"))
|
|
|
|
, m_xOk(m_xBuilder->weld_button("ok"))
|
|
|
|
, m_xCancel(m_xBuilder->weld_button("cancel"))
|
|
|
|
, m_xManageDatasources(m_xBuilder->weld_button("organize"))
|
2000-10-24 11:14:02 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->set_size_request(-1, m_xDatasource->get_height_rows(6));
|
2014-02-17 10:12:08 +00:00
|
|
|
|
2001-10-18 05:50:39 +00:00
|
|
|
fillListBox(_rDatasources);
|
2005-01-05 11:35:17 +00:00
|
|
|
#ifdef HAVE_ODBC_ADMINISTRATION
|
2018-05-14 16:17:19 +02:00
|
|
|
// allow ODBC datasource management
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xManageDatasources->show();
|
|
|
|
m_xManageDatasources->set_sensitive(true);
|
|
|
|
m_xManageDatasources->connect_clicked(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
|
2005-01-05 11:35:17 +00:00
|
|
|
#endif
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->connect_row_activated(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
|
2000-10-24 11:14:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 14:29:30 +02:00
|
|
|
ODatasourceSelectDialog::~ODatasourceSelectDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-05 18:36:38 +01:00
|
|
|
IMPL_LINK(ODatasourceSelectDialog, ListDblClickHdl, weld::TreeView&, rListBox, bool)
|
2000-10-24 11:14:02 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
if (rListBox.n_children())
|
|
|
|
m_xDialog->response(RET_OK);
|
2019-10-05 18:36:38 +01:00
|
|
|
return true;
|
2000-10-24 11:14:02 +00:00
|
|
|
}
|
2007-07-24 11:07:51 +00:00
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
short ODatasourceSelectDialog::run()
|
2007-07-24 11:07:51 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
short nRet = GenericDialogController::run();
|
2007-07-24 11:07:51 +00:00
|
|
|
#ifdef HAVE_ODBC_ADMINISTRATION
|
2019-03-03 20:23:08 +00:00
|
|
|
if (m_xODBCManagement.get())
|
|
|
|
m_xODBCManagement->disableCallback();
|
2007-07-24 11:07:51 +00:00
|
|
|
#endif
|
2019-03-03 20:23:08 +00:00
|
|
|
return nRet;
|
2007-07-24 11:07:51 +00:00
|
|
|
}
|
|
|
|
|
2005-01-05 11:35:17 +00:00
|
|
|
#ifdef HAVE_ODBC_ADMINISTRATION
|
2019-03-03 20:23:08 +00:00
|
|
|
IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, weld::Button&, void)
|
2000-10-24 11:14:02 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
if ( !m_xODBCManagement.get() )
|
|
|
|
m_xODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
|
2007-07-24 11:07:51 +00:00
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
if ( !m_xODBCManagement->manageDataSources_async() )
|
2000-10-24 11:14:02 +00:00
|
|
|
{
|
2007-07-24 11:07:51 +00:00
|
|
|
// TODO: error message
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->grab_focus();
|
|
|
|
m_xManageDatasources->set_sensitive(false);
|
2015-08-26 21:48:13 +02:00
|
|
|
return;
|
2000-10-24 11:14:02 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->set_sensitive(false);
|
|
|
|
m_xOk->set_sensitive(false);
|
|
|
|
m_xCancel->set_sensitive(false);
|
|
|
|
m_xManageDatasources->set_sensitive(false);
|
2007-07-24 11:07:51 +00:00
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
SAL_WARN_IF( !m_xODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
|
2007-07-24 11:07:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void )
|
2007-07-24 11:07:51 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xODBCManagement->receivedCallback();
|
|
|
|
|
2018-06-28 23:32:05 +03:00
|
|
|
std::set<OUString> aOdbcDatasources;
|
2001-10-18 05:50:39 +00:00
|
|
|
OOdbcEnumeration aEnumeration;
|
2007-07-24 11:07:51 +00:00
|
|
|
aEnumeration.getDatasourceNames( aOdbcDatasources );
|
|
|
|
fillListBox( aOdbcDatasources );
|
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->set_sensitive(true);
|
|
|
|
m_xOk->set_sensitive(true);
|
|
|
|
m_xCancel->set_sensitive(true);
|
|
|
|
m_xManageDatasources->set_sensitive(true);
|
2000-10-24 11:14:02 +00:00
|
|
|
}
|
2007-07-24 11:07:51 +00:00
|
|
|
|
2005-01-05 11:35:17 +00:00
|
|
|
#endif
|
2018-06-28 23:32:05 +03:00
|
|
|
void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources)
|
2001-10-18 05:50:39 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sSelected;
|
2019-03-03 20:23:08 +00:00
|
|
|
if (m_xDatasource->n_children())
|
|
|
|
sSelected = m_xDatasource->get_selected_text();
|
|
|
|
m_xDatasource->clear();
|
2001-10-18 05:50:39 +00:00
|
|
|
// fill the list
|
2018-03-09 23:27:25 +01:00
|
|
|
for (auto const& datasource : _rDatasources)
|
2001-10-18 05:50:39 +00:00
|
|
|
{
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->append_text(datasource);
|
2001-10-18 05:50:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 20:23:08 +00:00
|
|
|
if (m_xDatasource->n_children())
|
2005-02-21 11:44:32 +00:00
|
|
|
{
|
2011-12-19 18:10:37 -02:00
|
|
|
if (!sSelected.isEmpty())
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->select_text(sSelected);
|
2005-02-21 11:44:32 +00:00
|
|
|
else // select the first entry
|
2019-03-03 20:23:08 +00:00
|
|
|
m_xDatasource->select(0);
|
2005-02-21 11:44:32 +00:00
|
|
|
}
|
2001-10-18 05:50:39 +00:00
|
|
|
}
|
2000-10-24 11:14:02 +00:00
|
|
|
|
|
|
|
} // namespace dbaui
|
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|