fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / dlgsave.cxx
blob46bbbacf63c71b4bfc4067363052b8b648412bb8
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 #include "dlgsave.hxx"
21 #include <vcl/msgbox.hxx>
22 #include "dbu_dlg.hrc"
23 #include <com/sun/star/sdb/CommandType.hpp>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include "sqlmessage.hxx"
26 #include <connectivity/dbtools.hxx>
27 #include "UITools.hxx"
28 #include "dbaccess_helpid.hrc"
29 #include "SqlNameEdit.hxx"
30 #include <vcl/button.hxx>
31 #include <vcl/fixed.hxx>
32 #include <vcl/edit.hxx>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
35 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
36 #include "moduledbu.hxx"
37 #include "objectnamecheck.hxx"
38 #include <tools/diagnose_ex.h>
40 using namespace dbaui;
41 using namespace dbtools;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::sdb;
45 using namespace ::com::sun::star::sdbc;
46 namespace dbaui
48 class OSaveAsDlgImpl
50 public:
51 VclPtr<FixedText> m_pDescription;
52 VclPtr<FixedText> m_pCatalogLbl;
53 VclPtr<OSQLNameComboBox> m_pCatalog;
54 VclPtr<FixedText> m_pSchemaLbl;
55 VclPtr<OSQLNameComboBox> m_pSchema;
56 VclPtr<FixedText> m_pLabel;
57 VclPtr<OSQLNameEdit> m_pTitle;
58 VclPtr<OKButton> m_pPB_OK;
59 OUString m_aQryLabel;
60 OUString m_sTblLabel;
61 OUString m_aName;
62 const IObjectNameCheck&
63 m_rObjectNameCheck;
64 OUString m_sParentURL;
65 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xMetaData;
66 sal_Int32 m_nType;
67 sal_Int32 m_nFlags;
69 OSaveAsDlgImpl( OSaveAsDlg* pParent,const sal_Int32& _rType,
70 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
71 const OUString& rDefault,
72 const IObjectNameCheck& _rObjectNameCheck,
73 sal_Int32 _nFlags);
74 OSaveAsDlgImpl( OSaveAsDlg* pParent,
75 const OUString& rDefault,
76 const IObjectNameCheck& _rObjectNameCheck,
77 sal_Int32 _nFlags);
80 } // dbaui
82 OSaveAsDlgImpl::OSaveAsDlgImpl(OSaveAsDlg* pParent,
83 const sal_Int32& _rType,
84 const Reference< XConnection>& _xConnection,
85 const OUString& rDefault,
86 const IObjectNameCheck& _rObjectNameCheck,
87 sal_Int32 _nFlags)
88 : m_aQryLabel(ModuleRes(STR_QRY_LABEL))
89 , m_sTblLabel(ModuleRes(STR_TBL_LABEL))
90 , m_aName(rDefault)
91 , m_rObjectNameCheck( _rObjectNameCheck )
92 , m_nType(_rType)
93 , m_nFlags(_nFlags)
95 pParent->get(m_pDescription, "descriptionft");
96 pParent->get(m_pCatalogLbl, "catalogft");
97 pParent->get(m_pCatalog, "catalog");
98 pParent->get(m_pSchemaLbl, "schemaft");
99 pParent->get(m_pSchema, "schema");
100 pParent->get(m_pLabel, "titleft");
101 pParent->get(m_pTitle, "title");
102 pParent->get(m_pPB_OK, "ok");
104 if ( _xConnection.is() )
105 m_xMetaData = _xConnection->getMetaData();
107 if ( m_xMetaData.is() )
109 OUString sExtraNameChars( m_xMetaData->getExtraNameCharacters() );
110 m_pCatalog->setAllowedChars( sExtraNameChars );
111 m_pSchema->setAllowedChars( sExtraNameChars );
112 m_pTitle->setAllowedChars( sExtraNameChars );
115 m_pCatalog->SetDropDownLineCount( 10 );
116 m_pSchema->SetDropDownLineCount( 10 );
119 OSaveAsDlgImpl::OSaveAsDlgImpl(OSaveAsDlg* pParent,
120 const OUString& rDefault,
121 const IObjectNameCheck& _rObjectNameCheck,
122 sal_Int32 _nFlags)
123 : m_aQryLabel(ModuleRes(STR_QRY_LABEL))
124 , m_sTblLabel(ModuleRes(STR_TBL_LABEL))
125 , m_aName(rDefault)
126 , m_rObjectNameCheck( _rObjectNameCheck )
127 , m_nType(CommandType::COMMAND)
128 , m_nFlags(_nFlags)
130 pParent->get(m_pDescription, "descriptionft");
131 pParent->get(m_pCatalogLbl, "catalogft");
132 pParent->get(m_pCatalog, "catalog");
133 pParent->get(m_pSchemaLbl, "schemaft");
134 pParent->get(m_pSchema, "schema");
135 pParent->get(m_pLabel, "titleft");
136 pParent->get(m_pTitle, "title");
137 pParent->get(m_pPB_OK, "ok");
139 m_pCatalog->SetDropDownLineCount( 10 );
140 m_pSchema->SetDropDownLineCount( 10 );
143 using namespace ::com::sun::star::lang;
145 namespace
147 typedef Reference< XResultSet > (SAL_CALL XDatabaseMetaData::*FGetMetaStrings)();
149 void lcl_fillComboList( ComboBox& _rList, const Reference< XConnection >& _rxConnection,
150 FGetMetaStrings _GetAll, const OUString& _rCurrent )
154 Reference< XDatabaseMetaData > xMetaData( _rxConnection->getMetaData(), UNO_QUERY_THROW );
156 Reference< XResultSet > xRes = (xMetaData.get()->*_GetAll)();
157 Reference< XRow > xRow( xRes, UNO_QUERY_THROW );
158 OUString sValue;
159 while ( xRes->next() )
161 sValue = xRow->getString( 1 );
162 if ( !xRow->wasNull() )
163 _rList.InsertEntry( sValue );
166 sal_Int32 nPos = _rList.GetEntryPos( OUString( _rCurrent ) );
167 if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
168 _rList.SelectEntryPos( nPos );
169 else
170 _rList.SelectEntryPos( 0 );
172 catch( const Exception& )
174 DBG_UNHANDLED_EXCEPTION();
179 OSaveAsDlg::OSaveAsDlg( vcl::Window * pParent,
180 const sal_Int32& _rType,
181 const Reference< XComponentContext >& _rxContext,
182 const Reference< XConnection>& _xConnection,
183 const OUString& rDefault,
184 const IObjectNameCheck& _rObjectNameCheck,
185 sal_Int32 _nFlags)
186 : ModalDialog(pParent, "SaveDialog", "dbaccess/ui/savedialog.ui")
187 , m_xContext( _rxContext )
189 m_pImpl = new OSaveAsDlgImpl(this,_rType,_xConnection,rDefault,_rObjectNameCheck,_nFlags);
191 switch (_rType)
193 case CommandType::QUERY:
194 implInitOnlyTitle(m_pImpl->m_aQryLabel);
195 break;
197 case CommandType::TABLE:
198 OSL_ENSURE( m_pImpl->m_xMetaData.is(), "OSaveAsDlg::OSaveAsDlg: no meta data for entering table names: this will crash!" );
200 m_pImpl->m_pLabel->SetText(m_pImpl->m_sTblLabel);
201 if(m_pImpl->m_xMetaData.is() && !m_pImpl->m_xMetaData->supportsCatalogsInTableDefinitions())
203 m_pImpl->m_pCatalogLbl->Hide();
204 m_pImpl->m_pCatalog->Hide();
206 else
208 // now fill the catalogs
209 lcl_fillComboList( *m_pImpl->m_pCatalog, _xConnection,
210 &XDatabaseMetaData::getCatalogs, _xConnection->getCatalog() );
213 if ( !m_pImpl->m_xMetaData->supportsSchemasInTableDefinitions())
215 m_pImpl->m_pSchemaLbl->Hide();
216 m_pImpl->m_pSchema->Hide();
218 else
220 lcl_fillComboList( *m_pImpl->m_pSchema, _xConnection,
221 &XDatabaseMetaData::getSchemas, m_pImpl->m_xMetaData->getUserName() );
224 OSL_ENSURE(m_pImpl->m_xMetaData.is(),"The metadata can not be null!");
225 if(m_pImpl->m_aName.indexOf('.') != -1)
227 OUString sCatalog,sSchema,sTable;
228 ::dbtools::qualifiedNameComponents(m_pImpl->m_xMetaData,
229 m_pImpl->m_aName,
230 sCatalog,
231 sSchema,
232 sTable,
233 ::dbtools::eInDataManipulation);
235 sal_Int32 nPos = m_pImpl->m_pCatalog->GetEntryPos(OUString(sCatalog));
236 if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
237 m_pImpl->m_pCatalog->SelectEntryPos(nPos);
239 if ( !sSchema.isEmpty() )
241 nPos = m_pImpl->m_pSchema->GetEntryPos(OUString(sSchema));
242 if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
243 m_pImpl->m_pSchema->SelectEntryPos(nPos);
245 m_pImpl->m_pTitle->SetText(sTable);
247 else
248 m_pImpl->m_pTitle->SetText(m_pImpl->m_aName);
249 m_pImpl->m_pTitle->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
251 sal_Int32 nLength = m_pImpl->m_xMetaData.is() ? m_pImpl->m_xMetaData->getMaxTableNameLength() : 0;
252 nLength = nLength ? nLength : EDIT_NOLIMIT;
254 m_pImpl->m_pTitle->SetMaxTextLen(nLength);
255 m_pImpl->m_pSchema->SetMaxTextLen(nLength);
256 m_pImpl->m_pCatalog->SetMaxTextLen(nLength);
258 bool bCheck = _xConnection.is() && isSQL92CheckEnabled(_xConnection);
259 m_pImpl->m_pTitle->setCheck(bCheck); // enable non valid sql chars as well
260 m_pImpl->m_pSchema->setCheck(bCheck); // enable non valid sql chars as well
261 m_pImpl->m_pCatalog->setCheck(bCheck); // enable non valid sql chars as well
263 break;
265 default:
266 OSL_FAIL( "OSaveAsDlg::OSaveAsDlg: Type not supported yet!" );
269 implInit();
272 OSaveAsDlg::OSaveAsDlg( vcl::Window * pParent,
273 const Reference< XComponentContext >& _rxContext,
274 const OUString& rDefault,
275 const OUString& _sLabel,
276 const IObjectNameCheck& _rObjectNameCheck,
277 sal_Int32 _nFlags)
278 : ModalDialog(pParent, "SaveDialog", "dbaccess/ui/savedialog.ui")
279 , m_xContext( _rxContext )
281 m_pImpl = new OSaveAsDlgImpl(this,rDefault,_rObjectNameCheck,_nFlags);
282 implInitOnlyTitle(_sLabel);
283 implInit();
286 OSaveAsDlg::~OSaveAsDlg()
288 disposeOnce();
291 void OSaveAsDlg::dispose()
293 DELETEZ(m_pImpl);
294 ModalDialog::dispose();
297 IMPL_LINK(OSaveAsDlg, ButtonClickHdl, Button *, pButton)
299 if (pButton == m_pImpl->m_pPB_OK)
301 m_pImpl->m_aName = m_pImpl->m_pTitle->GetText();
303 OUString sNameToCheck( m_pImpl->m_aName );
305 if ( m_pImpl->m_nType == CommandType::TABLE )
307 sNameToCheck = ::dbtools::composeTableName(
308 m_pImpl->m_xMetaData,
309 getCatalog(),
310 getSchema(),
311 sNameToCheck,
312 false, // no quoting
313 ::dbtools::eInDataManipulation
317 SQLExceptionInfo aNameError;
318 if ( m_pImpl->m_rObjectNameCheck.isNameValid( sNameToCheck, aNameError ) )
319 EndDialog( RET_OK );
321 showError( aNameError, this, m_xContext );
322 m_pImpl->m_pTitle->GrabFocus();
324 return 0;
327 IMPL_LINK(OSaveAsDlg, EditModifyHdl, Edit *, pEdit )
329 if (pEdit == m_pImpl->m_pTitle)
330 m_pImpl->m_pPB_OK->Enable(!m_pImpl->m_pTitle->GetText().isEmpty());
331 return 0;
334 void OSaveAsDlg::implInitOnlyTitle(const OUString& _rLabel)
336 m_pImpl->m_pLabel->SetText(_rLabel);
337 m_pImpl->m_pCatalogLbl->Hide();
338 m_pImpl->m_pCatalog->Hide();
339 m_pImpl->m_pSchemaLbl->Hide();
340 m_pImpl->m_pSchema->Hide();
342 m_pImpl->m_pTitle->SetText(m_pImpl->m_aName);
343 m_pImpl->m_pTitle->setCheck(false); // enable non valid sql chars as well
346 void OSaveAsDlg::implInit()
348 if ( 0 == ( m_pImpl->m_nFlags & SAD_ADDITIONAL_DESCRIPTION ) )
350 // hide the description window
351 m_pImpl->m_pDescription->Hide();
354 if ( SAD_TITLE_PASTE_AS == ( m_pImpl->m_nFlags & SAD_TITLE_PASTE_AS ) )
355 SetText( ModuleRes( STR_TITLE_PASTE_AS ) );
356 else if ( SAD_TITLE_RENAME == ( m_pImpl->m_nFlags & SAD_TITLE_RENAME ) )
357 SetText( ModuleRes( STR_TITLE_RENAME ) );
359 m_pImpl->m_pPB_OK->SetClickHdl(LINK(this,OSaveAsDlg,ButtonClickHdl));
360 m_pImpl->m_pTitle->SetModifyHdl(LINK(this,OSaveAsDlg,EditModifyHdl));
361 m_pImpl->m_pTitle->GrabFocus();
364 OUString OSaveAsDlg::getName() const { return m_pImpl->m_aName; }
365 OUString OSaveAsDlg::getCatalog() const { return m_pImpl->m_pCatalog->IsVisible() ? m_pImpl->m_pCatalog->GetText() : OUString(); }
366 OUString OSaveAsDlg::getSchema() const { return m_pImpl->m_pSchema->IsVisible() ? m_pImpl->m_pSchema->GetText() : OUString(); }
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */