Line data Source code
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 : #ifndef INCLUDED_DBACCESS_SOURCE_UI_DLG_DBADMINIMPL_HXX
21 : #define INCLUDED_DBACCESS_SOURCE_UI_DLG_DBADMINIMPL_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include <map>
26 : #include <set>
27 :
28 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/beans/PropertyValue.hpp>
31 : #include <com/sun/star/sdb/XDatabaseContext.hpp>
32 : #include <com/sun/star/sdbc/XConnection.hpp>
33 : #include <com/sun/star/sdbc/XDriver.hpp>
34 : #include "dsntypes.hxx"
35 : #include <svl/itemset.hxx>
36 : #include <com/sun/star/frame/XModel.hpp>
37 : #include <svl/poolitem.hxx>
38 : #include <vcl/vclptr.hxx>
39 :
40 : namespace vcl { class Window; }
41 : namespace dbaui
42 : {
43 : namespace DataSourceInfoConverter
44 : {
45 : void convert(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> & xContext,
46 : const ::dbaccess::ODsnTypeCollection* _pCollection,
47 : const OUString& _sOldURLPrefix,
48 : const OUString& _sNewURLPrefix,
49 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource);
50 : };
51 : class IItemSetHelper;
52 : // ODbDataSourceAdministrationHelper
53 0 : class ODbDataSourceAdministrationHelper
54 : {
55 : public:
56 : typedef std::map<sal_Int32, OUString> MapInt2String;
57 :
58 : private:
59 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
60 : m_xContext; /// service factory
61 : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseContext >
62 : m_xDatabaseContext; /// database context we're working in
63 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDatasource;
64 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
65 :
66 : ::com::sun::star::uno::Any m_aDataSourceOrName;
67 : typedef ::std::set< OUString > StringSet;
68 : typedef StringSet::const_iterator ConstStringSetIterator;
69 :
70 : MapInt2String m_aDirectPropTranslator; /// translating property id's into names (direct properties of a data source)
71 : MapInt2String m_aIndirectPropTranslator; /// translating property id's into names (indirect properties of a data source)
72 : VclPtr<vcl::Window> m_pParent;
73 : IItemSetHelper* m_pItemSetHelper;
74 : public:
75 :
76 : ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xORB
77 : ,vcl::Window* _pParent
78 : ,IItemSetHelper* _pItemSetHelper);
79 :
80 : /** translate the current dialog SfxItems into driver relevant PropertyValues
81 : @see successfullyConnected
82 : */
83 : bool getCurrentSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDriverParams);
84 :
85 : /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
86 : @see getCurrentSettings
87 : */
88 : void successfullyConnected();
89 :
90 : /// clear the password in the current data source's item set
91 : void clearPassword();
92 :
93 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > getORB() const { return m_xContext; }
94 :
95 : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseContext > getDatabaseContext() const { return m_xDatabaseContext; }
96 :
97 : /** creates a new connection. The caller is responsible to dispose it !!!!
98 : */
99 : ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >,sal_Bool> createConnection();
100 :
101 : /** return the corresponding driver for the selected URL
102 : */
103 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver();
104 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver(const OUString& _sURL);
105 :
106 : /** returns the data source the dialog is currently working with
107 : */
108 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getCurrentDataSource();
109 : // returns the Url of a database document
110 : static OUString getDocumentUrl(SfxItemSet& _rDest);
111 :
112 : void setDataSourceOrName( const ::com::sun::star::uno::Any& _rDataSourceOrName );
113 :
114 : /** extracts the connection type from the given set<p/>
115 : The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
116 : */
117 : static OUString getDatasourceType( const SfxItemSet& _rSet );
118 :
119 : /** returns the connection URL
120 : @return
121 : The connection URL
122 : */
123 : OUString getConnectionURL() const;
124 :
125 : /// fill the necessary information from the url line
126 : static void convertUrl(SfxItemSet& _rDest);
127 :
128 0 : const MapInt2String& getIndirectProperties() const { return m_aIndirectPropTranslator; }
129 :
130 : /** translates properties of an UNO data source into SfxItems
131 : @param _rxSource
132 : The data source
133 : @param _rDest
134 : The item set to fill.
135 : */
136 : void translateProperties(
137 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSource,
138 : SfxItemSet& _rDest);
139 :
140 : /** translate SfxItems into properties of an UNO data source
141 : @param _rSource
142 : The item set to read from.
143 : @param _rxDest
144 : The data source to fill.
145 : */
146 : void translateProperties(
147 : const SfxItemSet& _rSource,
148 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDest);
149 :
150 : bool saveChanges(const SfxItemSet& _rSource);
151 : protected:
152 : /** fill a data source info array with the settings from a given item set
153 : */
154 : void fillDatasourceInfo(const SfxItemSet& _rSource, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
155 :
156 : /// translate the given value into an SfxPoolItem, put this into the given set under the given id
157 : void implTranslateProperty(SfxItemSet& _rSet, sal_Int32 _nId, const ::com::sun::star::uno::Any& _rValue);
158 :
159 : /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
160 : static ::com::sun::star::uno::Any implTranslateProperty(const SfxPoolItem* _pItem);
161 :
162 : /// 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
163 : static void implTranslateProperty(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSet, const OUString& _rName, const SfxPoolItem* _pItem);
164 :
165 : /** check if the data source described by the given set needs authentication<p/>
166 : The return value depends on the data source type only.
167 : */
168 : static bool hasAuthentication(const SfxItemSet& _rSet);
169 :
170 : #if OSL_DEBUG_LEVEL > 0
171 : OString translatePropertyId( sal_Int32 _nId );
172 : #endif
173 : };
174 :
175 : } // namespace dbaui
176 :
177 : #endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_DBADMINIMPL_HXX
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|