tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / ui / dlg / DbAdminImpl.hxx
blobdd4adcdc525bae4dcf85adcb7a621afa6669ea6a
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 #pragma once
22 #include <sal/config.h>
24 #include <map>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/sdb/XDatabaseContext.hpp>
29 #include <com/sun/star/sdbc/XConnection.hpp>
30 #include <com/sun/star/sdbc/XDriver.hpp>
31 #include <dsntypes.hxx>
32 #include <svl/itemset.hxx>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <svl/poolitem.hxx>
35 #include <vcl/weld.hxx>
37 namespace dbaui
39 namespace DataSourceInfoConverter
41 void convert(const css::uno::Reference< css::uno::XComponentContext> & xContext,
42 const ::dbaccess::ODsnTypeCollection* _pCollection,
43 std::u16string_view _sOldURLPrefix,
44 std::u16string_view _sNewURLPrefix,
45 const css::uno::Reference< css::beans::XPropertySet >& _xDatasource);
47 class IItemSetHelper;
48 // ODbDataSourceAdministrationHelper
49 class ODbDataSourceAdministrationHelper final
51 public:
52 typedef std::map<sal_Int32, OUString> MapInt2String;
54 private:
55 css::uno::Reference< css::uno::XComponentContext >
56 m_xContext; /// service factory
57 css::uno::Reference< css::sdb::XDatabaseContext >
58 m_xDatabaseContext; /// database context we're working in
59 css::uno::Reference< css::beans::XPropertySet > m_xDatasource;
60 css::uno::Reference< css::frame::XModel > m_xModel;
62 css::uno::Any m_aDataSourceOrName;
64 MapInt2String m_aDirectPropTranslator; /// translating property id's into names (direct properties of a data source)
65 MapInt2String m_aIndirectPropTranslator; /// translating property id's into names (indirect properties of a data source)
66 weld::Window* m_pParent;
67 IItemSetHelper* m_pItemSetHelper;
68 public:
70 ODbDataSourceAdministrationHelper(const css::uno::Reference< css::uno::XComponentContext >& _xORB,
71 weld::Window* pParent, weld::Window* pTopParent,
72 IItemSetHelper* _pItemSetHelper);
74 /** translate the current dialog SfxItems into driver relevant PropertyValues
75 @see successfullyConnected
77 bool getCurrentSettings(css::uno::Sequence< css::beans::PropertyValue >& _rDriverParams);
79 /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
80 @see getCurrentSettings
82 void successfullyConnected();
84 /// clear the password in the current data source's item set
85 void clearPassword();
87 const css::uno::Reference< css::uno::XComponentContext >& getORB() const { return m_xContext; }
89 /** creates a new connection. The caller is responsible to dispose it !!!!
91 std::pair< css::uno::Reference< css::sdbc::XConnection >,bool> createConnection();
93 /** return the corresponding driver for the selected URL
95 css::uno::Reference< css::sdbc::XDriver > getDriver();
96 css::uno::Reference< css::sdbc::XDriver > getDriver(const OUString& _sURL);
98 /** returns the data source the dialog is currently working with
100 css::uno::Reference< css::beans::XPropertySet > const & getCurrentDataSource();
101 // returns the Url of a database document
102 static OUString getDocumentUrl(SfxItemSet const & _rDest);
104 void setDataSourceOrName( const css::uno::Any& _rDataSourceOrName );
106 /** extracts the connection type from the given set<p/>
107 The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
109 static OUString getDatasourceType( const SfxItemSet& _rSet );
111 /** returns the connection URL
112 @return
113 The connection URL
115 OUString getConnectionURL() const;
117 /// fill the necessary information from the url line
118 static void convertUrl(SfxItemSet& _rDest);
120 const MapInt2String& getIndirectProperties() const { return m_aIndirectPropTranslator; }
122 /** translates properties of a UNO data source into SfxItems
123 @param _rxSource
124 The data source
125 @param _rDest
126 The item set to fill.
128 void translateProperties(
129 const css::uno::Reference< css::beans::XPropertySet >& _rxSource,
130 SfxItemSet& _rDest);
132 /** translate SfxItems into properties of a UNO data source
133 @param _rSource
134 The item set to read from.
135 @param _rxDest
136 The data source to fill.
138 void translateProperties(
139 const SfxItemSet& _rSource,
140 const css::uno::Reference< css::beans::XPropertySet >& _rxDest);
142 bool saveChanges(const SfxItemSet& _rSource);
143 private:
144 /** fill a data source info array with the settings from a given item set
146 void fillDatasourceInfo(const SfxItemSet& _rSource, css::uno::Sequence< css::beans::PropertyValue >& _rInfo);
148 /// translate the given value into an SfxPoolItem, put this into the given set under the given id
149 void implTranslateProperty(SfxItemSet& _rSet, sal_Int32 _nId, const css::uno::Any& _rValue);
151 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
152 static css::uno::Any implTranslateProperty(const SfxPoolItem* _pItem);
154 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>, set it (under the given name) on the given property set
155 static void implTranslateProperty(const css::uno::Reference< css::beans::XPropertySet >& _rxSet, const OUString& _rName, const SfxPoolItem* _pItem);
157 /** check if the data source described by the given set needs authentication<p/>
158 The return value depends on the data source type only.
160 static bool hasAuthentication(const SfxItemSet& _rSet);
162 OString translatePropertyId( sal_Int32 _nId );
165 } // namespace dbaui
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */