Bug Summary

File:home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx
Warning:line 303, column 39
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name generalpage.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D DBACCESS_DLLIMPLEMENTATION -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/unixODBC/inc -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/dbaccess/inc -I /home/maarten/src/libreoffice/core/dbaccess/source/inc -I /home/maarten/src/libreoffice/core/dbaccess/source/ui/inc -I /home/maarten/src/libreoffice/core/workdir/YaccTarget/connectivity/source/parse -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx
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#include <core_resource.hxx>
21#include "dsnItem.hxx"
22#include "generalpage.hxx"
23#include <connectivity/dbexception.hxx>
24#include <strings.hrc>
25#include <dsitems.hxx>
26#include <sfx2/filedlghelper.hxx>
27#include <sfx2/docfilt.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/weld.hxx>
30#include <svl/stritem.hxx>
31#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
32#include <UITools.hxx>
33#include <comphelper/processfactory.hxx>
34#include <unotools/confignode.hxx>
35#include <o3tl/safeint.hxx>
36#include <osl/diagnose.h>
37#include <svtools/miscopt.hxx>
38#include <sal/log.hxx>
39#include <dbwizsetup.hxx>
40
41namespace dbaui
42{
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::container;
48
49 // OGeneralPage
50 OGeneralPage::OGeneralPage(weld::Container* pPage, weld::DialogController* pController, const OUString& _rUIXMLDescription, const SfxItemSet& _rItems)
51 : OGenericAdministrationPage(pPage, pController, _rUIXMLDescription, "PageGeneral", _rItems)
52 , m_xSpecialMessage(m_xBuilder->weld_label("specialMessage"))
53 , m_eLastMessage(smNone)
54 , m_bInitTypeList(true)
55 , m_xDatasourceType(m_xBuilder->weld_combo_box("datasourceType"))
56 , m_pCollection(nullptr)
57 {
58 // extract the datasource type collection from the item set
59 const DbuTypeCollectionItem* pCollectionItem = dynamic_cast<const DbuTypeCollectionItem*>( _rItems.GetItem(DSID_TYPECOLLECTION5) );
60 if (pCollectionItem)
61 m_pCollection = pCollectionItem->getCollection();
62 SAL_WARN_IF(!m_pCollection, "dbaccess.ui.generalpage", "OGeneralPage::OGeneralPage : really need a DSN type collection !")do { if (true && (!m_pCollection)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "dbaccess.ui.generalpage")) { case
SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "OGeneralPage::OGeneralPage : really need a DSN type collection !"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "62" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OGeneralPage::OGeneralPage : really need a DSN type collection !"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OGeneralPage::OGeneralPage : really need a DSN type collection !"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "62" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "OGeneralPage::OGeneralPage : really need a DSN type collection !"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "62" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OGeneralPage::OGeneralPage : really need a DSN type collection !"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OGeneralPage::OGeneralPage : really need a DSN type collection !"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "62" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
63
64 // do some knittings
65 m_xDatasourceType->connect_changed(LINK(this, OGeneralPage, OnDatasourceTypeSelected)::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPage
*>(this), &OGeneralPage::LinkStubOnDatasourceTypeSelected
)
);
66 }
67
68 OGeneralPage::~OGeneralPage()
69 {
70 }
71
72 namespace
73 {
74 struct DisplayedType
75 {
76 OUString eType;
77 OUString sDisplayName;
78
79 DisplayedType( const OUString& _eType, const OUString& _rDisplayName ) : eType( _eType ), sDisplayName( _rDisplayName ) { }
80 };
81 typedef std::vector< DisplayedType > DisplayedTypes;
82
83 struct DisplayedTypeLess
84 {
85 bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS )
86 {
87 return _rLHS.eType < _rRHS.eType;
88 }
89 };
90 }
91
92 void OGeneralPage::initializeTypeList()
93 {
94 if ( !m_bInitTypeList )
95 return;
96
97 m_bInitTypeList = false;
98 m_xDatasourceType->clear();
99
100 if ( !m_pCollection )
101 return;
102
103 DisplayedTypes aDisplayedTypes;
104
105 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
106 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
107 aTypeLoop != aEnd;
108 ++aTypeLoop
109 )
110 {
111 const OUString& sURLPrefix = aTypeLoop.getURLPrefix();
112 if ( !sURLPrefix.isEmpty() )
113 {
114 // skip mysql connection variations. It is handled in another window.
115 if(sURLPrefix.startsWith("sdbc:mysql:") && !sURLPrefix.startsWith("sdbc:mysql:jdbc:"))
116 continue;
117
118 OUString sDisplayName = aTypeLoop.getDisplayName();
119 if (m_xDatasourceType->find_text(sDisplayName) == -1 &&
120 approveDatasourceType(sURLPrefix, sDisplayName))
121 {
122 aDisplayedTypes.emplace_back( sURLPrefix, sDisplayName );
123 }
124 }
125 }
126 std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
127 for ( const auto& rDisplayedType : aDisplayedTypes )
128 insertDatasourceTypeEntryData( rDisplayedType.eType, rDisplayedType.sDisplayName );
129 }
130
131 void OGeneralPageWizard::initializeEmbeddedDBList()
132 {
133 if ( !m_bInitEmbeddedDBList )
134 return;
135
136 m_bInitEmbeddedDBList = false;
137 m_xEmbeddedDBType->clear();
138
139 if ( !m_pCollection )
140 return;
141
142 DisplayedTypes aDisplayedTypes;
143
144 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
145
146 SvtMiscOptions aMiscOptions;
147
148 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
149 aTypeLoop != aEnd;
150 ++aTypeLoop
151 )
152 {
153 const OUString& sURLPrefix = aTypeLoop.getURLPrefix();
154 if ( !sURLPrefix.isEmpty() )
155 {
156 OUString sDisplayName = aTypeLoop.getDisplayName();
157 if (m_xEmbeddedDBType->find_text(sDisplayName) == -1 &&
158 dbaccess::ODsnTypeCollection::isEmbeddedDatabase(sURLPrefix))
159 {
160 if( !aMiscOptions.IsExperimentalMode() && sURLPrefix.startsWith("sdbc:embedded:firebird") )
161 continue;
162 aDisplayedTypes.emplace_back( sURLPrefix, sDisplayName );
163 }
164 }
165 }
166 std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
167 for (auto const& displayedType : aDisplayedTypes)
168 insertEmbeddedDBTypeEntryData( displayedType.eType, displayedType.sDisplayName );
169 }
170
171 void OGeneralPage::setParentTitle(const OUString&)
172 {
173 }
174
175 void OGeneralPage::switchMessage(const OUString& _sURLPrefix)
176 {
177 SPECIAL_MESSAGE eMessage = smNone;
178 if ( _sURLPrefix.isEmpty()/*_eType == m_eNotSupportedKnownType*/ )
179 {
180 eMessage = smUnsupportedType;
181 }
182
183 if ( eMessage != m_eLastMessage )
184 {
185 const char* pResId = nullptr;
186 if ( smUnsupportedType == eMessage )
187 pResId = STR_UNSUPPORTED_DATASOURCE_TYPEreinterpret_cast<char const *>("STR_UNSUPPORTED_DATASOURCE_TYPE"
"\004" u8"This kind of data source is not supported on this platform.\nYou are allowed to change the settings, but you probably will not be able to connect to the database."
)
;
188 OUString sMessage;
189 if ( pResId )
190 sMessage = DBA_RES(pResId)::dbaccess::ResourceManager::loadString( pResId );
191
192 m_xSpecialMessage->set_label( sMessage );
193 m_eLastMessage = eMessage;
194 }
195 }
196
197 void OGeneralPage::onTypeSelected(const OUString& _sURLPrefix)
198 {
199 // the new URL text as indicated by the selection history
200 implSetCurrentType( _sURLPrefix );
201
202 switchMessage(_sURLPrefix);
203
204 m_aTypeSelectHandler.Call(*this);
205 }
206
207 void OGeneralPage::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
208 {
209 initializeTypeList();
210
211 m_xDatasourceType->set_active_text(getDatasourceName(_rSet));
212
213 // notify our listener that our type selection has changed (if so)
214 // FIXME: how to detect that it did not changed? (fdo#62937)
215 setParentTitle( m_eCurrentSelection );
216 onTypeSelected( m_eCurrentSelection );
217
218 // a special message for the current page state
219 switchMessage( m_eCurrentSelection );
220
221 OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
222 }
223
224 OUString OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet& _rSet )
225 {
226 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
227 bool bValid, bReadonly;
228 getFlags( _rSet, bValid, bReadonly );
229
230 // if the selection is invalid, disable everything
231
232 implSetCurrentType( OUString() );
233
234 // compare the DSN prefix with the registered ones
235 OUString sDisplayName;
236
237 if (m_pCollection && bValid)
238 {
239 implSetCurrentType( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() );
240 sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
241 onTypeSelected(m_eCurrentSelection);
242 }
243
244 // select the correct datasource type
245 if ( dbaccess::ODsnTypeCollection::isEmbeddedDatabase( m_eCurrentSelection )
246 && m_xEmbeddedDBType->find_text(sDisplayName) == -1 )
247 { // this indicates it's really a type which is known in general, but not supported on the current platform
248 // show a message saying so
249 // eSpecialMessage = smUnsupportedType;
250 insertEmbeddedDBTypeEntryData( m_eCurrentSelection, sDisplayName );
251 }
252
253 return sDisplayName;
254 }
255
256 OUString OGeneralPage::getDatasourceName( const SfxItemSet& _rSet )
257 {
258 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
259 bool bValid, bReadonly;
260 getFlags( _rSet, bValid, bReadonly );
261
262 // if the selection is invalid, disable everything
263 OUString sConnectURL;
264 if ( bValid )
4
Assuming 'bValid' is false
5
Taking false branch
265 {
266 // collect some items and some values
267 const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL3);
268 assert( pUrlItem )(static_cast <bool> (pUrlItem) ? void (0) : __assert_fail
("pUrlItem", "/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
, 268, __extension__ __PRETTY_FUNCTION__))
;
269 sConnectURL = pUrlItem->GetValue();
270 }
271
272 implSetCurrentType( OUString() );
273
274 // compare the DSN prefix with the registered ones
275 OUString sDisplayName;
276
277 if (m_pCollection && bValid)
6
Assuming field 'm_pCollection' is null
278 {
279 implSetCurrentType( m_pCollection->getPrefix( sConnectURL ) );
280 sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
281 }
282
283 // select the correct datasource type
284 if ( approveDatasourceType( m_eCurrentSelection, sDisplayName )
7
Calling 'OGeneralPage::approveDatasourceType'
285 && m_xDatasourceType->find_text(sDisplayName) == -1 )
286 { // this indicates it's really a type which is known in general, but not supported on the current platform
287 // show a message saying so
288 // eSpecialMessage = smUnsupportedType;
289 insertDatasourceTypeEntryData( m_eCurrentSelection, sDisplayName );
290 }
291
292 return sDisplayName;
293 }
294
295 // For the databaseWizard we only have one entry for the MySQL Database,
296 // because we have a separate tabpage to retrieve the respective datasource type
297 // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary
298 // representative for all MySQl databases)
299 // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
300 // databases to connect to.
301 bool OGeneralPage::approveDatasourceType( const OUString& _sURLPrefix, OUString& _inout_rDisplayName )
302 {
303 return approveDatasourceType( m_pCollection->determineType(_sURLPrefix), _inout_rDisplayName );
8
Called C++ object pointer is null
304 }
305
306 bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
307 {
308 if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
309 {
310 // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
311 // this driver is installed
312 if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) )
313 _inout_rDisplayName.clear();
314 }
315
316 if ( eType == ::dbaccess::DST_EMBEDDED_HSQLDB
317 || eType == ::dbaccess::DST_EMBEDDED_FIREBIRD )
318 _inout_rDisplayName.clear();
319
320 return _inout_rDisplayName.getLength() > 0;
321 }
322
323 void OGeneralPage::insertDatasourceTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
324 {
325 // insert a (temporary) entry
326 m_xDatasourceType->append_text(sDisplayName);
327 m_aURLPrefixes.push_back(_sType);
328 }
329
330 void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
331 {
332 // insert a (temporary) entry
333 m_xEmbeddedDBType->append_text(sDisplayName);
334 m_aEmbeddedURLPrefixes.push_back(_sType);
335 }
336
337 void OGeneralPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
338 {
339 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xSpecialMessage.get()));
340 }
341
342 void OGeneralPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
343 {
344 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ComboBox>(m_xDatasourceType.get()));
345 }
346
347 void OGeneralPage::implSetCurrentType( const OUString& _eType )
348 {
349 if ( _eType == m_eCurrentSelection )
350 return;
351
352 m_eCurrentSelection = _eType;
353 }
354
355 void OGeneralPage::Reset(const SfxItemSet* _rCoreAttrs)
356 {
357 // reset all locale data
358 implSetCurrentType( OUString() );
359 // this ensures that our type selection link will be called, even if the new one is the same as the
360 // current one
361 OGenericAdministrationPage::Reset(_rCoreAttrs);
362 }
363
364 IMPL_LINK( OGeneralPageWizard, OnEmbeddedDBTypeSelected, weld::ComboBox&, _rBox, void )void OGeneralPageWizard::LinkStubOnEmbeddedDBTypeSelected(void
* instance, weld::ComboBox& data) { return static_cast<
OGeneralPageWizard *>(instance)->OnEmbeddedDBTypeSelected
(data); } void OGeneralPageWizard::OnEmbeddedDBTypeSelected(weld
::ComboBox& _rBox)
365 {
366 // get the type from the entry data
367 const sal_Int32 nSelected = _rBox.get_active();
368 if (o3tl::make_unsigned(nSelected) >= m_aEmbeddedURLPrefixes.size() )
369 {
370 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess.ui.generalpage")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "Got out-of-range value '"
<< nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "370" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "370" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "370" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "370" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
371 return;
372 }
373 const OUString sURLPrefix = m_aEmbeddedURLPrefixes[ nSelected ];
374
375 setParentTitle( sURLPrefix );
376 // let the impl method do all the stuff
377 onTypeSelected( sURLPrefix );
378 // tell the listener we were modified
379 callModifiedHdl();
380 }
381
382 IMPL_LINK( OGeneralPage, OnDatasourceTypeSelected, weld::ComboBox&, _rBox, void )void OGeneralPage::LinkStubOnDatasourceTypeSelected(void * instance
, weld::ComboBox& data) { return static_cast<OGeneralPage
*>(instance)->OnDatasourceTypeSelected(data); } void OGeneralPage
::OnDatasourceTypeSelected(weld::ComboBox& _rBox)
383 {
384 // get the type from the entry data
385 const sal_Int32 nSelected = _rBox.get_active();
386 if (nSelected == -1)
387 return;
388 if (o3tl::make_unsigned(nSelected) >= m_aURLPrefixes.size() )
389 {
390 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess.ui.generalpage")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "Got out-of-range value '"
<< nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "390" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Got out-of-range value '" << nSelected <<
"' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess.ui.generalpage"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "390" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
391 return;
392 }
393 const OUString sURLPrefix = m_aURLPrefixes[ nSelected ];
394
395 setParentTitle( sURLPrefix );
396 // let the impl method do all the stuff
397 onTypeSelected( sURLPrefix );
398 // tell the listener we were modified
399 callModifiedHdl();
400 }
401
402 // OGeneralPageDialog
403 OGeneralPageDialog::OGeneralPageDialog(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rItems)
404 : OGeneralPage(pPage, pController, "dbaccess/ui/generalpagedialog.ui", _rItems)
405 {
406 }
407
408 void OGeneralPageDialog::setParentTitle( const OUString& _sURLPrefix )
409 {
410 const OUString sName = m_pCollection->getTypeDisplayName( _sURLPrefix );
411 if ( m_pAdminDialog )
412 {
413 OUString sMessage = DBA_RES(STR_PARENTTITLE_GENERAL)::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("STR_PARENTTITLE_GENERAL" "\004" u8"Data Source Properties: #"
) )
;
414 m_pAdminDialog->setTitle( sMessage.replaceAll( "#", sName ) );
415 }
416 }
417
418 void OGeneralPageDialog::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
419 {
420 OGeneralPage::implInitControls( _rSet, _bSaveValue );
421
422 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
423 bool bValid, bReadonly;
424 getFlags(_rSet, bValid, bReadonly );
425
426 m_xDatasourceType->set_sensitive( bValid );
427 }
428
429 bool OGeneralPageDialog::FillItemSet( SfxItemSet* _rCoreAttrs )
430 {
431 bool bChangedSomething = false;
432
433 const sal_Int32 nEntry = m_xDatasourceType->get_active();
434 OUString sURLPrefix = m_aURLPrefixes[ nEntry ];
435
436 if (m_xDatasourceType->get_value_changed_from_saved())
437 {
438 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL3, sURLPrefix ) );
439 bChangedSomething = true;
440 }
441
442 return bChangedSomething;
443 }
444
445 // OGeneralPageWizard
446 OGeneralPageWizard::OGeneralPageWizard(weld::Container* pPage, ODbTypeWizDialogSetup* pController, const SfxItemSet& _rItems)
447 : OGeneralPage( pPage, pController, "dbaccess/ui/generalpagewizard.ui", _rItems )
448 , m_xRB_CreateDatabase(m_xBuilder->weld_radio_button("createDatabase"))
449 , m_xRB_OpenExistingDatabase(m_xBuilder->weld_radio_button("openExistingDatabase"))
450 , m_xRB_ConnectDatabase(m_xBuilder->weld_radio_button("connectDatabase"))
451 , m_xFT_EmbeddedDBLabel(m_xBuilder->weld_label("embeddeddbLabel"))
452 , m_xEmbeddedDBType(m_xBuilder->weld_combo_box("embeddeddbList"))
453 , m_xFT_DocListLabel(m_xBuilder->weld_label("docListLabel"))
454 , m_xFT_HelpText(m_xBuilder->weld_label("helpText"))
455 , m_xLB_DocumentList(new OpenDocumentListBox(m_xBuilder->weld_combo_box("documentList"), "com.sun.star.sdb.OfficeDatabaseDocument"))
456 , m_xPB_OpenDatabase(new OpenDocumentButton(m_xBuilder->weld_button("openDatabase"), "com.sun.star.sdb.OfficeDatabaseDocument"))
457 , m_eOriginalCreationMode(eCreateNew)
458 , m_bInitEmbeddedDBList(true)
459 {
460 // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
461 sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() );
462 if ( nCreateNewDBIndex == -1 )
463 nCreateNewDBIndex = m_pCollection->getIndexOf( "sdbc:dbase:" );
464 bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
465
466 // also, if our application policies tell us to hide the option, do it
467 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
468 ::comphelper::getProcessComponentContext(),
469 "/org.openoffice.Office.DataAccess/Policies/Features/Base"
470 ) );
471 bool bAllowCreateLocalDatabase( true );
472 OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase )do { if (!(aConfig.getNodeValue( "CreateLocalDatabase" ) >>=
bAllowCreateLocalDatabase)) do { if (true && (!(0)))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/dlg/generalpage.cxx"
":" "472" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
473 if ( !bAllowCreateLocalDatabase )
474 bHideCreateNew = true;
475
476 if ( bHideCreateNew )
477 {
478 m_xRB_CreateDatabase->hide();
479 m_xRB_ConnectDatabase->set_active(true);
480 }
481 else
482 m_xRB_CreateDatabase->set_active(true);
483
484 // do some knittings
485 m_xEmbeddedDBType->connect_changed(LINK(this, OGeneralPageWizard, OnEmbeddedDBTypeSelected)::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnEmbeddedDBTypeSelected
)
);
486 m_xRB_CreateDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnSetupModeSelected )::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnSetupModeSelected
)
);
487 m_xRB_ConnectDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnSetupModeSelected )::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnSetupModeSelected
)
);
488 m_xRB_OpenExistingDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnSetupModeSelected )::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnSetupModeSelected
)
);
489 m_xLB_DocumentList->connect_changed( LINK( this, OGeneralPageWizard, OnDocumentSelected )::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnDocumentSelected
)
);
490 m_xPB_OpenDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnOpenDocument )::tools::detail::makeLink( ::tools::detail::castTo<OGeneralPageWizard
*>(this), &OGeneralPageWizard::LinkStubOnOpenDocument
)
);
491
492 pController->SetGeneralPage(this);
493 }
494
495 OGeneralPageWizard::~OGeneralPageWizard()
496 {
497 }
498
499 OGeneralPageWizard::CreationMode OGeneralPageWizard::GetDatabaseCreationMode() const
500 {
501 if ( m_xRB_CreateDatabase->get_active() )
502 return eCreateNew;
503 if ( m_xRB_ConnectDatabase->get_active() )
504 return eConnectExternal;
505 return eOpenExisting;
506 }
507
508 void OGeneralPageWizard::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
509 {
510 OGeneralPage::implInitControls( _rSet, _bSaveValue );
511
512 initializeEmbeddedDBList();
513 m_xEmbeddedDBType->set_active_text(getEmbeddedDBName(_rSet));
514
515 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
516 bool bValid, bReadonly;
517 getFlags( _rSet, bValid, bReadonly );
518
519 SetPageTitle(OUString());
520
521 if ( !bValid || bReadonly )
522 {
523 m_xFT_EmbeddedDBLabel->set_sensitive( false );
524 m_xDatasourceType->set_sensitive( false );
525 m_xPB_OpenDatabase->set_sensitive( false );
526 m_xFT_DocListLabel->set_sensitive( false );
527 m_xLB_DocumentList->set_sensitive( false );
528 }
529
530 if (m_xLB_DocumentList->get_count())
531 m_xLB_DocumentList->set_active(0);
532
533 m_eOriginalCreationMode = GetDatabaseCreationMode();
534
535 SetupModeSelected();
536 }
537
538 OUString OGeneralPageWizard::getDatasourceName(const SfxItemSet& _rSet)
539 {
540 // Sets the default selected database on startup.
541 if (m_xRB_CreateDatabase->get_active() )
1
Assuming the condition is false
2
Taking false branch
542 {
543 return m_pCollection->getTypeDisplayName( "sdbc:firebird:" );
544 }
545
546 return OGeneralPage::getDatasourceName( _rSet );
3
Calling 'OGeneralPage::getDatasourceName'
547 }
548
549 bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
550 {
551 switch ( eType )
552 {
553 case ::dbaccess::DST_MYSQL_JDBC:
554 case ::dbaccess::DST_MYSQL_ODBC:
555 case ::dbaccess::DST_MYSQL_NATIVE:
556 _inout_rDisplayName = "MySQL";
557 break;
558 default:
559 break;
560 }
561
562 return OGeneralPage::approveDatasourceType( eType, _inout_rDisplayName );
563 }
564
565 bool OGeneralPageWizard::FillItemSet(SfxItemSet* _rCoreAttrs)
566 {
567 bool bChangedSomething = false;
568
569 bool bCommitTypeSelection = true;
570
571 if ( m_xRB_CreateDatabase->get_active() )
572 {
573 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL3, "sdbc:dbase:" ) );
574 bChangedSomething = true;
575 bCommitTypeSelection = false;
576 }
577 else if ( m_xRB_OpenExistingDatabase->get_active() )
578 {
579 if ( m_xRB_OpenExistingDatabase->get_state_changed_from_saved() )
580 bChangedSomething = true;
581
582 // TODO
583 bCommitTypeSelection = false;
584 }
585
586 if ( bCommitTypeSelection )
587 {
588 const sal_Int32 nEntry = m_xDatasourceType->get_active();
589 OUString sURLPrefix = m_aURLPrefixes[nEntry];
590
591 if ( m_xDatasourceType->get_value_changed_from_saved()
592 || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
593 )
594 {
595 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL3,sURLPrefix ) );
596 bChangedSomething = true;
597 }
598 else
599 implSetCurrentType( sURLPrefix );
600 }
601 return bChangedSomething;
602 }
603
604 OUString OGeneralPageWizard::GetSelectedDocumentURL() const
605 {
606 if ( !m_aBrowsedDocumentURL.isEmpty() )
607 return m_aBrowsedDocumentURL;
608 else
609 return m_xLB_DocumentList->GetSelectedDocumentURL();
610 }
611
612 void OGeneralPageWizard::EnableControls()
613 {
614 bool bValid, bReadonly;
615 getFlags( GetItemSet(), bValid, bReadonly );
616 if ( bValid && !bReadonly )
617 {
618 m_xEmbeddedDBType->set_sensitive(m_xRB_CreateDatabase->get_active());
619 m_xFT_EmbeddedDBLabel->set_sensitive(m_xRB_CreateDatabase->get_active());
620 m_xDatasourceType->set_sensitive(m_xRB_ConnectDatabase->get_active());
621 m_xPB_OpenDatabase->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
622 m_xFT_DocListLabel->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
623 m_xLB_DocumentList->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
624 }
625 }
626
627 void OGeneralPageWizard::SetupModeSelected()
628 {
629 m_aCreationModeHandler.Call( *this );
630
631 if (m_xRB_CreateDatabase->get_active())
632 OnEmbeddedDBTypeSelected(*m_xEmbeddedDBType);
633 else
634 OnDatasourceTypeSelected(*m_xDatasourceType);
635
636 EnableControls();
637 }
638
639 IMPL_LINK_NOARG( OGeneralPageWizard, OnSetupModeSelected, weld::Button&, void )void OGeneralPageWizard::LinkStubOnSetupModeSelected(void * instance
, weld::Button& data) { return static_cast<OGeneralPageWizard
*>(instance)->OnSetupModeSelected(data); } void OGeneralPageWizard
::OnSetupModeSelected(__attribute__ ((unused)) weld::Button&
)
640 {
641 SetupModeSelected();
642 }
643
644 IMPL_LINK_NOARG( OGeneralPageWizard, OnDocumentSelected, weld::ComboBox&, void )void OGeneralPageWizard::LinkStubOnDocumentSelected(void * instance
, weld::ComboBox& data) { return static_cast<OGeneralPageWizard
*>(instance)->OnDocumentSelected(data); } void OGeneralPageWizard
::OnDocumentSelected(__attribute__ ((unused)) weld::ComboBox&
)
645 {
646 m_aDocumentSelectionHandler.Call( *this );
647 }
648
649 IMPL_LINK_NOARG( OGeneralPageWizard, OnOpenDocument, weld::Button&, void )void OGeneralPageWizard::LinkStubOnOpenDocument(void * instance
, weld::Button& data) { return static_cast<OGeneralPageWizard
*>(instance)->OnOpenDocument(data); } void OGeneralPageWizard
::OnOpenDocument(__attribute__ ((unused)) weld::Button&)
650 {
651 ::sfx2::FileDialogHelper aFileDlg(
652 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
653 FileDialogFlags::NONE, "sdatabase", SfxFilterFlags::NONE, SfxFilterFlags::NONE, GetFrameWeld());
654 std::shared_ptr<const SfxFilter> pFilter = getStandardDatabaseFilter();
655 if ( pFilter )
656 {
657 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
658 }
659 if ( aFileDlg.Execute() != ERRCODE_NONEErrCode(0) )
660 return;
661
662 OUString sPath = aFileDlg.GetPath();
663 // check for aFileDlg.GetCurrentFilter used to be here but current fpicker filter
664 // can be set to anything, see tdf#125267 how this breaks if other value
665 // than 'ODF Database' is selected. Let's therefore check only if wildcard matches
666 if ( !pFilter->GetWildcard().Matches(sPath) )
667 {
668 OUString sMessage(DBA_RES(STR_ERR_USE_CONNECT_TO)::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("STR_ERR_USE_CONNECT_TO" "\004" u8"Please choose 'Connect to an existing database' to connect to an existing database instead."
) )
);
669 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
670 VclMessageType::Info, VclButtonsType::Ok,
671 sMessage));
672 xInfoBox->run();
673 m_xRB_ConnectDatabase->set_active(true);
674 OnSetupModeSelected( *m_xRB_ConnectDatabase );
675 return;
676 }
677 m_aBrowsedDocumentURL = sPath;
678 m_aChooseDocumentHandler.Call( *this );
679 }
680
681} // namespace dbaui
682
683/* vim:set shiftwidth=4 softtabstop=4 expandtab: */