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-05 09:09:48 +00:00
|
|
|
|
|
|
|
#include "adminpages.hxx"
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <core_resource.hxx>
|
|
|
|
#include <dbadmin.hxx>
|
|
|
|
#include <dbu_dlg.hxx>
|
|
|
|
#include <strings.hrc>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/stritem.hxx>
|
|
|
|
#include <svl/eitem.hxx>
|
|
|
|
#include <svl/intitem.hxx>
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <stringconstants.hxx>
|
|
|
|
#include <dsitems.hxx>
|
2002-11-21 14:27:11 +00:00
|
|
|
#include "dsselect.hxx"
|
2009-10-16 14:16:52 +02:00
|
|
|
#include "odbcconfig.hxx"
|
|
|
|
#include "optionalboolitem.hxx"
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <sqlmessage.hxx>
|
2009-10-16 14:16:52 +02:00
|
|
|
|
2018-04-14 22:31:33 +02:00
|
|
|
#include <comphelper/types.hxx>
|
2009-10-16 14:16:52 +02:00
|
|
|
#include <osl/file.hxx>
|
2019-04-07 18:43:32 +02:00
|
|
|
#include <vcl/svapp.hxx>
|
2018-02-19 16:33:35 +00:00
|
|
|
#include <vcl/weld.hxx>
|
2004-10-27 12:00:55 +00:00
|
|
|
|
2009-10-16 14:16:52 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <stdlib.h>
|
2004-10-27 12:00:55 +00:00
|
|
|
|
2001-01-26 05:59:12 +00:00
|
|
|
namespace dbaui
|
|
|
|
{
|
|
|
|
|
2001-01-26 15:12:12 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::dbtools;
|
2002-11-21 14:27:11 +00:00
|
|
|
using namespace ::svt;
|
|
|
|
|
2012-01-15 17:13:26 +01:00
|
|
|
ISaveValueWrapper::~ISaveValueWrapper()
|
|
|
|
{
|
|
|
|
}
|
2000-10-05 09:09:48 +00:00
|
|
|
|
2019-09-24 14:10:48 +01:00
|
|
|
OGenericAdministrationPage::OGenericAdministrationPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OString& rId, const SfxItemSet& rAttrSet)
|
|
|
|
: SfxTabPage(pPage, pController, rUIXMLDescription, rId, &rAttrSet)
|
2018-09-26 14:17:16 +01:00
|
|
|
, m_abEnableRoadmap(false)
|
|
|
|
, m_pAdminDialog(nullptr)
|
|
|
|
, m_pItemSetHelper(nullptr)
|
|
|
|
{
|
|
|
|
SetExchangeSupport();
|
2019-08-05 17:26:53 +01:00
|
|
|
|
2019-09-20 20:29:36 +01:00
|
|
|
m_xContainer->set_size_request(m_xContainer->get_approximate_digit_width() * WIZARD_PAGE_X,
|
|
|
|
m_xContainer->get_text_height() * WIZARD_PAGE_Y);
|
2018-09-26 14:17:16 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 15:15:56 +02:00
|
|
|
DeactivateRC OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
|
2000-10-05 09:09:48 +00:00
|
|
|
{
|
2001-01-26 15:12:12 +00:00
|
|
|
if (_pSet)
|
2000-10-09 11:39:52 +00:00
|
|
|
{
|
2007-05-10 09:24:13 +00:00
|
|
|
if (!prepareLeave())
|
2016-06-05 15:15:56 +02:00
|
|
|
return DeactivateRC::KeepPage;
|
2014-06-10 17:23:12 +02:00
|
|
|
FillItemSet(_pSet);
|
2000-10-09 11:39:52 +00:00
|
|
|
}
|
2000-10-05 09:09:48 +00:00
|
|
|
|
2016-06-05 15:15:56 +02:00
|
|
|
return DeactivateRC::LeavePage;
|
2000-10-05 09:09:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 10:35:24 +02:00
|
|
|
void OGenericAdministrationPage::Reset(const SfxItemSet* _rCoreAttrs)
|
2000-10-05 09:09:48 +00:00
|
|
|
{
|
2014-06-11 10:35:24 +02:00
|
|
|
implInitControls(*_rCoreAttrs, false);
|
2000-10-05 09:09:48 +00:00
|
|
|
}
|
2019-09-20 20:29:36 +01:00
|
|
|
|
|
|
|
void OGenericAdministrationPage::Activate()
|
2004-08-02 14:42:57 +00:00
|
|
|
{
|
2019-09-20 20:29:36 +01:00
|
|
|
BuilderPage::Activate();
|
2004-08-02 14:42:57 +00:00
|
|
|
OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
|
|
|
|
if ( m_pItemSetHelper )
|
|
|
|
ActivatePage(*m_pItemSetHelper->getOutputSet());
|
|
|
|
}
|
2019-09-20 20:29:36 +01:00
|
|
|
|
2001-01-26 15:12:12 +00:00
|
|
|
void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
|
2000-10-13 15:04:22 +00:00
|
|
|
{
|
2014-04-17 11:16:55 +02:00
|
|
|
implInitControls(_rSet, true);
|
2000-10-13 15:04:22 +00:00
|
|
|
}
|
2000-11-22 14:44:40 +00:00
|
|
|
|
2014-04-17 11:16:55 +02:00
|
|
|
void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, bool& _rValid, bool& _rReadonly)
|
2000-10-05 09:09:48 +00:00
|
|
|
{
|
2015-10-19 07:18:39 +02:00
|
|
|
const SfxBoolItem* pInvalid = _rSet.GetItem<SfxBoolItem>(DSID_INVALID_SELECTION);
|
2001-01-26 15:12:12 +00:00
|
|
|
_rValid = !pInvalid || !pInvalid->GetValue();
|
2015-10-19 07:18:39 +02:00
|
|
|
const SfxBoolItem* pReadonly = _rSet.GetItem<SfxBoolItem>(DSID_READONLY);
|
2001-01-26 15:12:12 +00:00
|
|
|
_rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
|
2000-10-05 09:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 10:19:16 +01:00
|
|
|
IMPL_LINK(OGenericAdministrationPage, OnControlModified, weld::Widget*, pCtrl, void)
|
2000-10-05 09:09:48 +00:00
|
|
|
{
|
2015-10-14 16:55:36 +02:00
|
|
|
callModifiedHdl(pCtrl);
|
2015-08-19 09:11:34 +02:00
|
|
|
}
|
2018-09-26 14:17:16 +01:00
|
|
|
|
|
|
|
IMPL_LINK(OGenericAdministrationPage, OnControlModifiedButtonClick, weld::ToggleButton&, rCtrl, void)
|
2015-08-19 09:11:34 +02:00
|
|
|
{
|
2018-09-26 14:17:16 +01:00
|
|
|
callModifiedHdl(&rCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK(OGenericAdministrationPage, OnControlEntryModifyHdl, weld::Entry&, rCtrl, void)
|
|
|
|
{
|
|
|
|
callModifiedHdl(&rCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK(OGenericAdministrationPage, OnControlSpinButtonModifyHdl, weld::SpinButton&, rCtrl, void)
|
|
|
|
{
|
|
|
|
callModifiedHdl(&rCtrl);
|
|
|
|
}
|
|
|
|
|
2017-07-31 12:26:12 +02:00
|
|
|
bool OGenericAdministrationPage::getSelectedDataSource(OUString& _sReturn, OUString const & _sCurr)
|
2002-11-21 14:27:11 +00:00
|
|
|
{
|
|
|
|
// collect all ODBC data source names
|
2018-06-28 23:32:05 +03:00
|
|
|
std::set<OUString> aOdbcDatasources;
|
2002-11-21 14:27:11 +00:00
|
|
|
OOdbcEnumeration aEnumeration;
|
|
|
|
if (!aEnumeration.isLoaded())
|
|
|
|
{
|
|
|
|
// show an error message
|
2017-06-11 20:56:30 +01:00
|
|
|
OUString sError(DBA_RES(STR_COULD_NOT_LOAD_ODBC_LIB));
|
2013-09-26 12:17:53 +02:00
|
|
|
sError = sError.replaceFirst("#lib#", aEnumeration.getLibraryName());
|
2019-09-25 15:14:55 +01:00
|
|
|
std::unique_ptr<weld::MessageDialog> xDialog(Application::CreateMessageDialog(GetFrameWeld(),
|
2018-02-19 16:33:35 +00:00
|
|
|
VclMessageType::Warning, VclButtonsType::Ok,
|
|
|
|
sError));
|
|
|
|
xDialog->run();
|
2014-04-17 11:16:55 +02:00
|
|
|
return false;
|
2002-11-21 14:27:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aEnumeration.getDatasourceNames(aOdbcDatasources);
|
2011-01-09 02:04:00 +09:00
|
|
|
// execute the select dialog
|
2019-09-25 15:14:55 +01:00
|
|
|
ODatasourceSelectDialog aSelector(GetFrameWeld(), aOdbcDatasources);
|
2011-12-19 18:10:37 -02:00
|
|
|
if (!_sCurr.isEmpty())
|
2019-03-03 20:23:08 +00:00
|
|
|
aSelector.Select(_sCurr);
|
|
|
|
if (RET_OK == aSelector.run())
|
|
|
|
_sReturn = aSelector.GetSelected();
|
2002-11-21 14:27:11 +00:00
|
|
|
}
|
2014-04-17 11:16:55 +02:00
|
|
|
return true;
|
2002-11-21 14:27:11 +00:00
|
|
|
}
|
2007-05-10 09:24:13 +00:00
|
|
|
|
2014-04-17 11:16:55 +02:00
|
|
|
void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
|
2004-08-02 14:42:57 +00:00
|
|
|
{
|
|
|
|
// check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
|
2014-04-17 11:16:55 +02:00
|
|
|
bool bValid, bReadonly;
|
2004-08-02 14:42:57 +00:00
|
|
|
getFlags(_rSet, bValid, bReadonly);
|
|
|
|
|
2018-09-07 14:33:33 +02:00
|
|
|
std::vector< std::unique_ptr<ISaveValueWrapper> > aControlList;
|
2004-08-02 14:42:57 +00:00
|
|
|
if ( _bSaveValue )
|
|
|
|
{
|
|
|
|
fillControls(aControlList);
|
2015-09-05 18:35:35 -04:00
|
|
|
for( const auto& pValueWrapper : aControlList )
|
|
|
|
{
|
|
|
|
pValueWrapper->SaveValue();
|
|
|
|
}
|
2004-08-02 14:42:57 +00:00
|
|
|
}
|
2002-11-21 14:27:11 +00:00
|
|
|
|
2004-08-02 14:42:57 +00:00
|
|
|
if ( bReadonly )
|
|
|
|
{
|
|
|
|
fillWindows(aControlList);
|
2015-09-05 18:35:35 -04:00
|
|
|
for( const auto& pValueWrapper : aControlList )
|
|
|
|
{
|
|
|
|
pValueWrapper->Disable();
|
|
|
|
}
|
2004-08-02 14:42:57 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-06 17:16:10 +00:00
|
|
|
|
2004-08-02 14:42:57 +00:00
|
|
|
void OGenericAdministrationPage::initializePage()
|
|
|
|
{
|
|
|
|
OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
|
|
|
|
if ( m_pItemSetHelper )
|
2014-06-11 10:35:24 +02:00
|
|
|
Reset(m_pItemSetHelper->getOutputSet());
|
2004-08-02 14:42:57 +00:00
|
|
|
}
|
2019-08-03 20:17:38 +01:00
|
|
|
bool OGenericAdministrationPage::commitPage( ::vcl::WizardTypes::CommitPageReason )
|
2004-08-02 14:42:57 +00:00
|
|
|
{
|
2014-03-25 14:20:18 +02:00
|
|
|
return true;
|
2004-08-02 14:42:57 +00:00
|
|
|
}
|
2010-05-25 10:17:24 +02:00
|
|
|
bool OGenericAdministrationPage::canAdvance() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-26 14:17:16 +01:00
|
|
|
void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, const weld::CheckButton* pCheckBox, sal_uInt16 _nID, bool bOptionalBool, bool& _bChangedSomething, bool _bRevertValue )
|
|
|
|
{
|
|
|
|
if (pCheckBox && pCheckBox->get_state_changed_from_saved())
|
|
|
|
{
|
|
|
|
bool bValue = pCheckBox->get_active();
|
|
|
|
if ( _bRevertValue )
|
|
|
|
bValue = !bValue;
|
|
|
|
|
|
|
|
if (bOptionalBool)
|
|
|
|
{
|
|
|
|
OptionalBoolItem aValue( _nID );
|
|
|
|
if ( pCheckBox->get_state() != TRISTATE_INDET )
|
|
|
|
aValue.SetValue( bValue );
|
|
|
|
_rSet.Put( aValue );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_rSet.Put( SfxBoolItem( _nID, bValue ) );
|
|
|
|
|
|
|
|
_bChangedSomething = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet, const weld::SpinButton* pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
|
|
|
|
{
|
|
|
|
if (pEdit && pEdit->get_value_changed_from_saved())
|
|
|
|
{
|
|
|
|
_rSet.Put(SfxInt32Item(_nID, pEdit->get_value()));
|
|
|
|
_bChangedSomething = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void OGenericAdministrationPage::fillString(SfxItemSet& _rSet, const weld::Entry* pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
|
|
|
|
{
|
|
|
|
if (pEdit && pEdit->get_value_changed_from_saved())
|
|
|
|
{
|
|
|
|
_rSet.Put(SfxStringItem(_nID, pEdit->get_text()));
|
|
|
|
_bChangedSomething = true;
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 16:31:05 +01:00
|
|
|
void OGenericAdministrationPage::fillString(SfxItemSet& _rSet, const dbaui::OConnectionURLEdit* pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
|
2018-10-23 10:38:03 +01:00
|
|
|
{
|
|
|
|
if (pEdit && pEdit->get_value_changed_from_saved())
|
|
|
|
{
|
|
|
|
_rSet.Put(SfxStringItem(_nID, pEdit->GetText()));
|
|
|
|
_bChangedSomething = true;
|
|
|
|
}
|
|
|
|
}
|
2000-10-05 09:09:48 +00:00
|
|
|
|
2018-10-23 10:38:03 +01:00
|
|
|
IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionButtonClickHdl, weld::Button&, void)
|
2004-10-27 12:00:55 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
|
2014-04-17 11:16:55 +02:00
|
|
|
bool bSuccess = false;
|
2004-10-27 12:00:55 +00:00
|
|
|
if ( m_pAdminDialog )
|
|
|
|
{
|
|
|
|
m_pAdminDialog->saveDatasource();
|
2014-04-17 11:16:55 +02:00
|
|
|
OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), true);
|
|
|
|
bool bShowMessage = true;
|
2004-10-27 12:00:55 +00:00
|
|
|
try
|
|
|
|
{
|
2017-12-15 08:58:54 +01:00
|
|
|
std::pair< Reference<XConnection>,bool> aConnectionPair = m_pAdminDialog->createConnection();
|
2016-04-27 09:22:13 +02:00
|
|
|
bShowMessage = aConnectionPair.second;
|
|
|
|
bSuccess = aConnectionPair.first.is();
|
|
|
|
::comphelper::disposeComponent(aConnectionPair.first);
|
2004-10-27 12:00:55 +00:00
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
}
|
2005-01-21 16:13:51 +00:00
|
|
|
if ( bShowMessage )
|
2004-10-27 12:00:55 +00:00
|
|
|
{
|
2018-03-20 17:17:10 +00:00
|
|
|
MessageType eImage = MessageType::Info;
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString aMessage,sTitle;
|
2017-06-11 20:56:30 +01:00
|
|
|
sTitle = DBA_RES(STR_CONNECTION_TEST);
|
2005-01-21 16:13:51 +00:00
|
|
|
if ( bSuccess )
|
|
|
|
{
|
2017-06-11 20:56:30 +01:00
|
|
|
aMessage = DBA_RES(STR_CONNECTION_SUCCESS);
|
2005-01-21 16:13:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 17:17:10 +00:00
|
|
|
eImage = MessageType::Error;
|
2017-06-11 20:56:30 +01:00
|
|
|
aMessage = DBA_RES(STR_CONNECTION_NO_SUCCESS);
|
2005-01-21 16:13:51 +00:00
|
|
|
}
|
2019-09-25 15:14:55 +01:00
|
|
|
OSQLMessageBox aMsg(GetFrameWeld(), sTitle, aMessage, MessBoxStyle::Ok, eImage);
|
2018-03-20 17:17:10 +00:00
|
|
|
aMsg.run();
|
2004-10-27 12:00:55 +00:00
|
|
|
}
|
2005-03-18 09:10:20 +00:00
|
|
|
if ( !bSuccess )
|
|
|
|
m_pAdminDialog->clearPassword();
|
2004-10-27 12:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-26 15:12:12 +00:00
|
|
|
} // namespace dbaui
|
2000-10-05 09:09:48 +00:00
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|