Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / abpilot / datasourcehandling.hxx
blobc6058e45e30a8dc5c4617ccd159f802df8327354
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 <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <memory>
26 #include "abptypes.hxx"
29 namespace com::sun::star {
30 namespace beans {
31 class XPropertySet;
35 namespace weld { class Window; }
38 namespace abp
41 struct ODataSourceContextImpl;
42 class ODataSource;
43 /// a non-UNO wrapper for the data source context
44 class ODataSourceContext
46 private:
47 std::unique_ptr<ODataSourceContextImpl> m_pImpl;
49 public:
50 explicit ODataSourceContext(
51 const css::uno::Reference< css::uno::XComponentContext >& _rxORB
53 ~ODataSourceContext();
55 /// retrieves the names of all data sources
56 void getDataSourceNames( StringBag& _rNames ) const;
58 /// disambiguates the given name by appending successive numbers
59 void disambiguate(OUString& _rDataSourceName);
61 /// creates a new Thunderbird data source
62 ODataSource createNewThunderbird( const OUString& _rName );
64 /// creates a new Evolution local data source
65 ODataSource createNewEvolution( const OUString& _rName );
67 /// creates a new Evolution LDAP data source
68 ODataSource createNewEvolutionLdap( const OUString& _rName );
70 /// creates a new Evolution GROUPWISE data source
71 ODataSource createNewEvolutionGroupwise( const OUString& _rName );
73 /// creates a new KDE address book data source
74 ODataSource createNewKab( const OUString& _rName );
76 /// creates a new macOS address book data source
77 ODataSource createNewMacab( const OUString& _rName );
79 /// creates a new Other data source; tdf117101: Spreadsheet by default
80 ODataSource createNewOther( const OUString& _rName );
83 struct ODataSourceImpl;
84 struct AddressSettings;
85 /** a non-UNO wrapper for a data source
86 <p>This class allows to access data sources without the need to compile the respective file with
87 exception handling enabled (hopefully :).</p>
88 <p>In addition to wrapping a UNO data source, an instance of this class can handle at most
89 one valid connection, as obtained from the data source.</p>
91 class ODataSource
93 private:
94 std::unique_ptr<ODataSourceImpl> m_pImpl;
96 public:
98 // - ctor/dtor/assignment
100 /// constructs an object which is initially invalid
101 explicit ODataSource(
102 const css::uno::Reference< css::uno::XComponentContext >& _rxORB
105 /// copy ctor
106 ODataSource( const ODataSource& _rSource );
108 /// dtor
109 ~ODataSource( );
111 /// copy assignment
112 ODataSource& operator=( const ODataSource& _rSource );
114 /// move assignment
115 ODataSource& operator=(ODataSource&& _rSource) noexcept;
117 /// checks whether or not the object represents a valid data source
118 bool isValid() const;
121 /// removes the data source represented by the object from the data source context
122 void remove();
123 // TODO: put this into the context class
125 /// returns the name of the data source
126 OUString
127 getName() const;
129 /// renames the data source
130 bool rename( const OUString& _rName );
131 // TODO: put this into the context class
134 // - connection handling
136 /** connects to the data source represented by this object
137 @param _pMessageParent
138 the window to use as parent for any error messages. If this is <NULL/>, no messages are displayed
139 at all.
140 @see isConnected
142 bool connect(weld::Window* _pMessageParent);
144 /// returns <TRUE/> if the object has a valid connection, obtained from its data source
145 bool isConnected( ) const;
147 /// disconnects from the data source (i.e. disposes the UNO connection hold internally)
148 void disconnect( );
150 /// stores the database file
151 void store(const AddressSettings& rSettings);
153 /// register the data source under the given name in the configuration
154 void registerDataSource( const OUString& _sRegisteredDataSourceName );
157 /** retrieves the tables names from the connection
158 <p>to be called when <method>isConnected</method> returns <TRUE/> only</p>
160 const StringBag& getTableNames() const;
162 /** determines whether a given table exists
164 bool hasTable( const OUString& _rTableName ) const;
166 /// return the internal data source object
167 css::uno::Reference< css::beans::XPropertySet > getDataSource() const;
170 /** set a new data source.
171 <p>Available to selected clients only</p>
173 void setDataSource(
174 const css::uno::Reference< css::beans::XPropertySet >& _rxDS
175 ,const OUString& _sName
180 } // namespace abp
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */