xref: /trunk/main/extensions/source/abpilot/datasourcehandling.hxx (revision 7dbe28d420f41caf4208fa0a77115d7601de2198)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
23 #define EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
24 
25 #include <com/sun/star/uno/Reference.hxx>
26 #include "abptypes.hxx"
27 
28 //========================================================================
29 namespace com { namespace sun { namespace star {
30     namespace lang {
31         class XMultiServiceFactory;
32     }
33     namespace beans {
34         class XPropertySet;
35     }
36 } } }
37 
38 class Window;
39 
40 //.........................................................................
41 namespace abp
42 {
43 //.........................................................................
44 
45     //=====================================================================
46     //= ODataSourceContext
47     //=====================================================================
48     struct ODataSourceContextImpl;
49     class ODataSource;
50     // an non-UNO wrapper for the data source context
51     class ODataSourceContext
52     {
53     private:
54         ODataSourceContextImpl*     m_pImpl;
55 
56     public:
57         ODataSourceContext(
58             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
59         );
60 
61         // retrieves the names of all data sources
62         void    getDataSourceNames( StringBag& _rNames ) const SAL_THROW (( ));
63 
64         // disambiguate the given name by appending successive numbers
65         ::rtl::OUString& disambiguate(::rtl::OUString& _rDataSourceName);
66 
67         // creates a new Thunderbird data source
68         ODataSource createNewThunderbird( const ::rtl::OUString& _rName ) SAL_THROW (( ));
69 
70         // creates a new Evolution local data source
71         ODataSource createNewEvolution( const ::rtl::OUString& _rName ) SAL_THROW (( ));
72 
73         // creates a new Evolution LDAP data source
74         ODataSource createNewEvolutionLdap( const ::rtl::OUString& _rName ) SAL_THROW (( ));
75 
76         // creates a new Evolution GROUPWISE data source
77         ODataSource createNewEvolutionGroupwise( const ::rtl::OUString& _rName ) SAL_THROW (( ));
78 
79         // creates a new KDE address book data source
80         ODataSource createNewKab( const ::rtl::OUString& _rName ) SAL_THROW (( ));
81 
82         // creates a new macOS address book data source
83         ODataSource createNewMacab( const ::rtl::OUString& _rName ) SAL_THROW (( ));
84 
85         // creates a new LDAP data source
86         ODataSource createNewLDAP( const ::rtl::OUString& _rName ) SAL_THROW (( ));
87 
88         // creates a new Outlook data source
89         ODataSource createNewOutlook( const ::rtl::OUString& _rName ) SAL_THROW (( ));
90 
91         // creates a new Outlook express data source
92         ODataSource createNewOE( const ::rtl::OUString& _rName ) SAL_THROW (( ));
93 
94         // creates a new dBASE data source
95         ODataSource createNewDBase( const ::rtl::OUString& _rName ) SAL_THROW (( ));
96     };
97 
98     //=====================================================================
99     //= ODataSource
100     //=====================================================================
101     struct ODataSourceImpl;
102     struct PackageAccessControl;
103     /** a non-UNO wrapper for a data source
104         <p>This class allows to access data sources without the need to compile the respective file with
105         exception handling enabled (hopefully :).</p>
106         <p>In addition to wrapping an UNO data source, an instance of this class can handle at most
107         one valid connection, as obtained from the data source.</p>
108     */
109     class ODataSource
110     {
111     private:
112         ODataSourceImpl*    m_pImpl;
113 
114     public:
115         // ----------------------------------------------------------------
116         // - ctor/dtor/assignment
117         // ----------------------------------------------------------------
118         // constructs an object which is initially invalid
119         ODataSource(
120             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
121         );
122 
123         // copy ctor
124         ODataSource( const ODataSource& _rSource );
125 
126         // dtor
127         ~ODataSource( );
128 
129         // assignment
130         ODataSource& operator=( const ODataSource& _rSource );
131 
132         // ----------------------------------------------------------------
133         // checks whether or not the object represents a valid data source
134         sal_Bool    isValid() const SAL_THROW (( ));
135 
136         // ----------------------------------------------------------------
137         // removes the data source represented by the object from the data source context
138         void        remove() SAL_THROW (( ));
139             // TODO: put this into the context class
140 
141         // returns the name of the data source
142         ::rtl::OUString
143                     getName() const SAL_THROW (( ));
144 
145         // renames the data source
146         sal_Bool    rename( const ::rtl::OUString& _rName ) SAL_THROW (( ));
147             // TODO: put this into the context class
148 
149         // ----------------------------------------------------------------
150         // - connection handling
151         // ----------------------------------------------------------------
152         /** connects to the data source represented by this object
153             @param _pMessageParent
154                 the window to use as parent for any error messages. If this is <NULL/>, no messages are displayed
155                 at all.
156             @see isConnected
157         */
158         sal_Bool    connect( Window* _pMessageParent ) SAL_THROW (( ));
159 
160         // returns <TRUE/> if the object has a valid connection, obtained from its data source
161         sal_Bool    isConnected( ) const SAL_THROW (( ));
162 
163         // disconnects from the data source (i.e. disposes the UNO connection hold internally)
164         void        disconnect( ) SAL_THROW (( ));
165 
166         // stores the database file
167         void        store() SAL_THROW (( ));
168 
169         // register the data source under the given name in the configuration
170         void        registerDataSource( const ::rtl::OUString& _sRegisteredDataSourceName ) SAL_THROW (( ));
171 
172         // ----------------------------------------------------------------
173         /** retrieves the tables names from the connection
174             <p>to be called when <method>isConnection</method> returns <TRUE/> only</p>
175         */
176         const StringBag&    getTableNames() const SAL_THROW (( ));
177 
178         /** determines whether a given table exists
179         */
180         bool    hasTable( const ::rtl::OUString& _rTableName ) const;
181 
182         // return the intern data source object
183         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getDataSource() const SAL_THROW (( ));
184 
185 
186         // ----------------------------------------------------------------
187         /** set a new data source.
188             <p>Available to selected clients only</p>
189         */
190         void        setDataSource(
191             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDS
192             ,const ::rtl::OUString& _sName
193             ,PackageAccessControl
194         );
195 
196     private:
197         ODataSource( ); // never implemented
198     };
199 
200 //.........................................................................
201 }   // namespace abp
202 //.........................................................................
203 
204 #endif // EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
205 
206 /* vim: set noet sw=4 ts=4: */
207