LibreOffice Module sw (master) 1
addresslistdialog.cxx
Go to the documentation of this file.
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 <swtypes.hxx>
22#include "addresslistdialog.hxx"
25#include <mailmergewizard.hxx>
26#include <mmconfigitem.hxx>
28#include <dbmgr.hxx>
29#include <dbconfig.hxx>
30#include <unotools/tempfile.hxx>
31#include <vcl/svapp.hxx>
32#include <tools/urlobj.hxx>
34#include <comphelper/types.hxx>
35#include <com/sun/star/sdbc/XCloseable.hpp>
36#include <com/sun/star/lang/XMultiServiceFactory.hpp>
37#include <com/sun/star/container/XNameAccess.hpp>
38#include <com/sun/star/sdb/DatabaseContext.hpp>
39#include <com/sun/star/sdb/XCompletedConnection.hpp>
40#include <com/sun/star/sdb/CommandType.hpp>
41#include <com/sun/star/sdb/FilterDialog.hpp>
42#include <com/sun/star/sdb/XDocumentDataSource.hpp>
43#include <com/sun/star/sdbc/XRowSet.hpp>
44#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
45#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
46#include <com/sun/star/sdb/XQueriesSupplier.hpp>
47#include <com/sun/star/task/InteractionHandler.hpp>
48#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
49#include <com/sun/star/frame/XStorable.hpp>
50#include <o3tl/safeint.hxx>
51#include <swunohelper.hxx>
53#include <tools/diagnose_ex.h>
54#include <svl/urihelper.hxx>
55#include <strings.hrc>
56#include <view.hxx>
57
58using namespace ::com::sun::star;
59using namespace ::com::sun::star::uno;
60using namespace ::com::sun::star::lang;
61using namespace ::com::sun::star::container;
62using namespace ::com::sun::star::sdb;
63using namespace ::com::sun::star::sdbc;
64using namespace ::com::sun::star::sdbcx;
65using namespace ::com::sun::star::task;
66using namespace ::com::sun::star::beans;
67using namespace ::com::sun::star::ui::dialogs;
68
70{
71 uno::Reference<XDataSource> xSource;
73 uno::Reference< XColumnsSupplier> xColumnsSupplier;
74 uno::Reference< sdbc::XResultSet> xResultSet;
75 OUString sFilter;
76 OUString sURL; // data is editable
77 sal_Int32 nCommandType;
80 nCommandType(0),
82 {}
83};
84
85static OUString lcl_getFlatURL( uno::Reference<beans::XPropertySet> const & xSourceProperties )
86{
87 if(xSourceProperties.is())
88 {
89 OUString sDBURL;
90 xSourceProperties->getPropertyValue("URL") >>= sDBURL;
91 if (sDBURL.startsWith("sdbc:flat:"))
92 {
93 uno::Sequence<OUString> aFilters;
94 xSourceProperties->getPropertyValue("TableFilter") >>= aFilters;
95 uno::Sequence<PropertyValue> aInfo;
96 xSourceProperties->getPropertyValue("Info") >>= aInfo;
97 if(aFilters.getLength() == 1 && aInfo.hasElements() )
98 {
99 OUString sExtension;
100 OUString sCharSet;
101 for(const auto& rInfo : std::as_const(aInfo))
102 {
103 if(rInfo.Name == "Extension")
104 rInfo.Value >>= sExtension;
105 else if(rInfo.Name == "CharSet")
106 rInfo.Value >>= sCharSet;
107 }
108 if (sCharSet=="UTF-8")
109 {
110 //#i97577# at this point the 'URL' can also be a file name!
111 return URIHelper::SmartRel2Abs( INetURLObject(), sDBURL.copy(10) )
112 + "/" + aFilters[0] + "." + sExtension;
113 }
114 }
115 }
116 }
117 return OUString();
118}
119
121 : SfxDialogController(pParent->GetWizard()->getDialog(), "modules/swriter/ui/selectaddressdialog.ui", "SelectAddressDialog")
122 , m_bInSelectHdl(false)
123 , m_pAddressPage(pParent)
124 , m_xDescriptionFI(m_xBuilder->weld_label("desc"))
125 , m_xConnecting(m_xBuilder->weld_label("connecting"))
126 , m_xListLB(m_xBuilder->weld_tree_view("sources"))
127 , m_xLoadListPB(m_xBuilder->weld_button("add"))
128 , m_xRemovePB(m_xBuilder->weld_button("remove"))
129 , m_xCreateListPB(m_xBuilder->weld_button("create"))
130 , m_xFilterPB(m_xBuilder->weld_button("filter"))
131 , m_xEditPB(m_xBuilder->weld_button("edit"))
132 , m_xTablePB(m_xBuilder->weld_button("changetable"))
133 , m_xOK(m_xBuilder->weld_button("ok"))
134 , m_xIter(m_xListLB->make_iterator())
135{
136 m_sConnecting = m_xConnecting->get_label();
137
138 const OUString sTemp(m_xDescriptionFI->get_label()
139 .replaceFirst("%1", m_xLoadListPB->strip_mnemonic(m_xLoadListPB->get_label()))
140 .replaceFirst("%2", m_xCreateListPB->strip_mnemonic(m_xCreateListPB->get_label())));
141 m_xDescriptionFI->set_label(sTemp);
142 m_xFilterPB->connect_clicked( LINK( this, SwAddressListDialog, FilterHdl_Impl ));
143 m_xLoadListPB->connect_clicked( LINK( this, SwAddressListDialog, LoadHdl_Impl ));
144 m_xRemovePB->connect_clicked( LINK(this, SwAddressListDialog, RemoveHdl_Impl ));
145 m_xCreateListPB->connect_clicked( LINK( this, SwAddressListDialog,CreateHdl_Impl ));
146 m_xEditPB->connect_clicked(LINK( this, SwAddressListDialog, EditHdl_Impl));
147 m_xTablePB->connect_clicked(LINK( this, SwAddressListDialog, TableSelectHdl_Impl));
148
149 m_xListLB->set_size_request(m_xListLB->get_approximate_digit_width() * 52,
150 m_xListLB->get_height_rows(9));
151
152 std::vector<int> aWidths
153 {
154 o3tl::narrowing<int>(m_xListLB->get_approximate_digit_width() * 26)
155 };
156 m_xListLB->set_column_fixed_widths(aWidths);
157
158 m_xListLB->make_sorted();
159 m_xOK->connect_clicked(LINK(this, SwAddressListDialog, OKHdl_Impl));
160
161 uno::Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
162 m_xDBContext = DatabaseContext::create(xContext);
163
165 const SwDBData& rCurrentData = rConfigItem.GetCurrentDBData();
166
167 bool bEnableEdit = false;
168 bool bEnableOK = true;
169 bool bSelected = false;
170 m_xListLB->unselect_all();
171
172 SwDBConfig aDb;
173 const OUString sBibliography = aDb.GetBibliographySource().sDataSource;
174 const uno::Sequence< OUString> aNames = m_xDBContext->getElementNames();
175 for(const OUString& rName : aNames)
176 {
177 if ( rName == sBibliography )
178 continue;
179 m_xListLB->append(m_xIter.get());
180 m_xListLB->set_text(*m_xIter, rName, 0);
181 m_aUserData.emplace_back(new AddressUserData_Impl);
182 AddressUserData_Impl* pUserData = m_aUserData.back().get();
183 m_xListLB->set_id(*m_xIter, weld::toId(pUserData));
184 if (rName == rCurrentData.sDataSource)
185 {
186 m_xListLB->select(*m_xIter);
187 bSelected = true;
188 m_xListLB->set_text(*m_xIter, rCurrentData.sCommand, 1);
189 pUserData->nCommandType = rCurrentData.nCommandType;
190 pUserData->xSource = rConfigItem.GetSource();
191 pUserData->xConnection = rConfigItem.GetConnection();
192 pUserData->xColumnsSupplier = rConfigItem.GetColumnsSupplier();
193 pUserData->xResultSet = rConfigItem.GetResultSet();
194 pUserData->sFilter = rConfigItem.GetFilter();
195 //is the data source editable (csv, Unicode, single table)
196 uno::Reference<beans::XPropertySet> xSourceProperties;
197 try
198 {
199 m_xDBContext->getByName(rName) >>= xSourceProperties;
200 pUserData->sURL = lcl_getFlatURL( xSourceProperties );
201 bEnableEdit = !pUserData->sURL.isEmpty() &&
202 SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577#
204 }
205 catch (const uno::Exception&)
206 {
207 bEnableOK = false;
208 }
209 m_aDBData = rCurrentData;
210 }
211 }
212
213 bool bHasChildren = m_xListLB->n_children() > 0;
214 if (bHasChildren && !bSelected)
215 m_xListLB->select(0); // select the first entry if nothing else selected
216 m_xOK->set_sensitive(bHasChildren && bEnableOK);
217 m_xEditPB->set_sensitive(bEnableEdit);
218 m_xRemovePB->set_sensitive(m_xListLB->n_children() > 0);
219 m_xFilterPB->set_sensitive(m_xListLB->n_children() > 0);
220 m_xTablePB->set_sensitive(m_xListLB->n_children() > 0);
221 m_xListLB->connect_changed(LINK(this, SwAddressListDialog, ListBoxSelectHdl_Impl));
222 TableSelectHdl(nullptr);
223}
224
226{
227}
228
230{
231 int nSelect = m_xListLB->get_selected_index();
232 uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
233 if (nSelect == -1)
234 return;
235
236 const OUString sCommand = m_xListLB->get_text(nSelect, 1);
237 if (sCommand.isEmpty())
238 return;
239
240 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
241 if (!pUserData->xConnection.is() )
242 return;
243
244 try
245 {
246 uno::Reference<lang::XMultiServiceFactory> xConnectFactory(pUserData->xConnection, UNO_QUERY_THROW);
247 uno::Reference<XSingleSelectQueryComposer> xComposer(
248 xConnectFactory->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"), UNO_QUERY_THROW);
249
250 uno::Reference<XRowSet> xRowSet(
251 xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY);
252 uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
253 xRowProperties->setPropertyValue("DataSourceName",
254 Any(m_xListLB->get_text(nSelect, 0)));
255 xRowProperties->setPropertyValue("Command", Any(sCommand));
256 xRowProperties->setPropertyValue("CommandType", Any(pUserData->nCommandType));
257 xRowProperties->setPropertyValue("ActiveConnection", Any(pUserData->xConnection.getTyped()));
258 xRowSet->execute();
259
260 OUString sQuery;
261 xRowProperties->getPropertyValue("ActiveCommand")>>= sQuery;
262 xComposer->setQuery(sQuery);
263 if(!pUserData->sFilter.isEmpty())
264 xComposer->setFilter(pUserData->sFilter);
265
266 uno::Reference< XExecutableDialog> xDialog = sdb::FilterDialog::createWithQuery( comphelper::getComponentContext(xMgr),
267 xComposer,xRowSet, uno::Reference<awt::XWindow>() );
268
269 if ( RET_OK == xDialog->execute() )
270 {
271 weld::WaitObject aWait(m_xDialog.get());
272 pUserData->sFilter = xComposer->getFilter();
273 }
274 ::comphelper::disposeComponent(xRowSet);
275 }
276 catch (const Exception&)
277 {
278 TOOLS_WARN_EXCEPTION( "sw", "exception caught in SwAddressListDialog::FilterHdl_Impl");
279 }
280}
281
283{
284 SwView* pView = m_pAddressPage->GetWizard()->GetSwView();
285
286 const OUString sNewSource = SwDBManager::LoadAndRegisterDataSource(m_xDialog.get(), pView ? pView->GetDocShell() : nullptr);
287 if(!sNewSource.isEmpty())
288 {
289 m_xListLB->append(m_xIter.get());
290 m_xListLB->set_text(*m_xIter, sNewSource, 0);
291 m_aUserData.emplace_back(new AddressUserData_Impl);
292 AddressUserData_Impl* pUserData = m_aUserData.back().get();
293 m_xListLB->set_id(*m_xIter, weld::toId(pUserData));
294 m_xListLB->select(*m_xIter);
295 ListBoxSelectHdl_Impl(*m_xListLB);
296 m_xRemovePB->set_sensitive(true);
297 }
298}
299
301{
302 int nEntry = m_xListLB->get_selected_index();
303 if (nEntry == -1)
304 return;
305
306 std::unique_ptr<weld::MessageDialog> xQuery(Application::CreateMessageDialog(getDialog(),
307 VclMessageType::Question, VclButtonsType::YesNo, SwResId(ST_DELETE_CONFIRM)));
308 if (xQuery->run() != RET_YES)
309 return;
310
311 // Remove data source connection
312 SwDBManager::RevokeDataSource(m_xListLB->get_selected_text());
313 // Remove item from the list
314 m_xListLB->remove(nEntry);
315 // If this was the last item, disable the Remove & Edit buttons and enable Create
316 if (m_xListLB->n_children() < 1 )
317 {
318 m_xRemovePB->set_sensitive(false);
319 m_xEditPB->set_sensitive(false);
320 m_xFilterPB->set_sensitive(false);
321 m_xCreateListPB->set_sensitive(true);
322 }
323
324
325}
326
328{
329 SwCreateAddressListDialog aDlg(m_xDialog.get(), /*sInputURL*/OUString(), m_pAddressPage->GetWizard()->GetConfigItem());
330 if (RET_OK != aDlg.run())
331 return;
332
333 //register the URL a new datasource
334 const OUString sURL = aDlg.GetURL();
335 try
336 {
337 uno::Reference<XInterface> xNewInstance = m_xDBContext->createInstance();
338 INetURLObject aURL( sURL );
339 const OUString sNewName = aURL.getBase();
340 //find a unique name if sNewName already exists
341 OUString sFind(sNewName);
342 sal_Int32 nIndex = 0;
343 while(m_xDBContext->hasByName(sFind))
344 {
345 sFind = sNewName + OUString::number(++nIndex);
346 }
347 uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY);
348
349 //only the 'path' has to be added
350 INetURLObject aTempURL(aURL);
351 aTempURL.removeSegment();
352 aTempURL.removeFinalSlash();
353 const OUString sDBURL("sdbc:flat:" + aTempURL.GetMainURL(INetURLObject::DecodeMechanism::NONE));
354 xDataProperties->setPropertyValue("URL", Any(sDBURL));
355 //set the filter to the file name without extension
356 uno::Sequence<OUString> aFilters { sNewName };
357 xDataProperties->setPropertyValue("TableFilter", Any(aFilters));
358
359 uno::Sequence<PropertyValue> aInfo
360 {
361 comphelper::makePropertyValue("FieldDelimiter", OUString('\t')),
362 comphelper::makePropertyValue("StringDelimiter", OUString('"')),
363 comphelper::makePropertyValue("Extension", aURL.getExtension()), //"csv
364 comphelper::makePropertyValue("CharSet", OUString("UTF-8"))
365 };
366 xDataProperties->setPropertyValue("Info", Any(aInfo));
367
368 uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
369 uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
370 OUString const sExt(".odb");
371 OUString sTmpName;
372 {
373 OUString sHomePath(SvtPathOptions().GetWorkPath());
374 utl::TempFile aTempFile(sFind, true, &sExt, &sHomePath);
375 aTempFile.EnableKillingFile();
376 sTmpName = aTempFile.GetURL();
377 }
378 xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
379
380 m_xDBContext->registerObject( sFind, xNewInstance );
381 //now insert the new source into the ListBox
382 m_xListLB->append(m_xIter.get());
383 m_xListLB->set_text(*m_xIter, sFind, 0);
384 m_xListLB->set_text(*m_xIter, aFilters[0], 1);
385 m_aUserData.emplace_back(new AddressUserData_Impl);
386 AddressUserData_Impl* pUserData = m_aUserData.back().get();
387 m_xListLB->set_id(*m_xIter, weld::toId(pUserData));
388 m_xListLB->select(*m_xIter);
389 ListBoxSelectHdl_Impl(*m_xListLB);
390 m_xCreateListPB->set_sensitive(false);
391 m_xRemovePB->set_sensitive(true);
392 }
393 catch (const Exception&)
394 {
395 }
396}
397
399{
400 int nEntry = m_xListLB->get_selected_index();
401 AddressUserData_Impl* pUserData = nEntry != -1 ? weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nEntry)) : nullptr;
402 if (!pUserData || pUserData->sURL.isEmpty())
403 return;
404
405 if(pUserData->xResultSet.is())
406 {
407 SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem();
408 if(rConfigItem.GetResultSet() != pUserData->xResultSet)
409 ::comphelper::disposeComponent( pUserData->xResultSet );
410 pUserData->xResultSet = nullptr;
411
412 rConfigItem.DisposeResultSet();
413 }
414 pUserData->xSource.clear();
415 pUserData->xColumnsSupplier.clear();
416 pUserData->xConnection.clear();
417 // will automatically close if it was the las reference
418 SwCreateAddressListDialog aDlg(m_xDialog.get(), pUserData->sURL,
419 m_pAddressPage->GetWizard()->GetConfigItem());
420 aDlg.run();
421};
422
424{
425 int nSelect = m_xListLB->get_selected_index();
427 StaticListBoxSelectHdl_Impl ), reinterpret_cast<void*>(nSelect) );
428}
429
430IMPL_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, void*, p, void)
431{
432 int nSelect = reinterpret_cast<sal_IntPtr>(p);
433 //prevent nested calls of the select handler
434 if (m_bInSelectHdl)
435 return;
436 weld::WaitObject aWait(m_xDialog.get());
437 m_bInSelectHdl = true;
438 AddressUserData_Impl* pUserData = nullptr;
439 if (nSelect != -1)
440 {
441 const OUString sTable(m_xListLB->get_text(nSelect, 1));
442 if (sTable.isEmpty())
443 {
444 m_xListLB->set_text(nSelect, m_sConnecting, 1);
445 }
446
447 pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
448 if(pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
449 {
450 DetectTablesAndQueries(nSelect, sTable.isEmpty());
451 }
452 else
453 {
454 //otherwise set the selected db-data
455 m_aDBData.sDataSource = m_xListLB->get_text(nSelect, 0);
456 m_aDBData.sCommand = m_xListLB->get_text(nSelect, 1);
457 m_aDBData.nCommandType = pUserData->nCommandType;
458 m_xOK->set_sensitive(true);
459 }
460 if (m_xListLB->get_text(nSelect, 1) == m_sConnecting)
461 m_xListLB->set_text(nSelect, OUString(), 1);
462 }
463 m_xEditPB->set_sensitive(pUserData && !pUserData->sURL.isEmpty() &&
464 SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577#
466 m_bInSelectHdl = false;
467}
468
469// detect the number of tables for a data source
470// if only one is available then set it at the entry
472 int nSelect,
473 bool bWidthDialog)
474{
475 try
476 {
477 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
478 uno::Reference<XCompletedConnection> xComplConnection;
479 if(!pUserData->xConnection.is())
480 {
481 m_aDBData.sDataSource = m_xListLB->get_text(nSelect, 0);
482 m_xDBContext->getByName(m_aDBData.sDataSource) >>= xComplConnection;
483 pUserData->xSource.set(xComplConnection, UNO_QUERY);
484
485 uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
486 uno::Reference< XInteractionHandler > xHandler = InteractionHandler::createWithParent(xContext, nullptr);
487 pUserData->xConnection = SharedConnection( xComplConnection->connectWithCompletion( xHandler ) );
488 }
489 if(pUserData->xConnection.is())
490 {
491 sal_Int32 nTables = 0;
492 uno::Sequence<OUString> aTables;
493 uno::Sequence<OUString> aQueries;
494 uno::Reference<XTablesSupplier> xTSupplier(pUserData->xConnection, UNO_QUERY);
495 if(xTSupplier.is())
496 {
497 uno::Reference<XNameAccess> xTables = xTSupplier->getTables();
498 aTables = xTables->getElementNames();
499 nTables += aTables.getLength();
500 }
501 uno::Reference<XQueriesSupplier> xQSupplier(pUserData->xConnection, UNO_QUERY);
502 if(xQSupplier.is())
503 {
504 uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries();
505 aQueries = xQueries->getElementNames();
506 nTables += aQueries.getLength();
507 }
508 pUserData->nTableAndQueryCount = nTables;
509 if(nTables > 1 && bWidthDialog)
510 {
511 //now call the table select dialog - if more than one table exists
512 SwSelectDBTableDialog aDlg(m_xDialog.get(), pUserData->xConnection);
513 const OUString sTable = m_xListLB->get_text(nSelect, 1);
514 if(!sTable.isEmpty())
515 aDlg.SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE);
516 if(RET_OK == aDlg.run())
517 {
518 bool bIsTable;
519 m_aDBData.sCommand = aDlg.GetSelectedTable(bIsTable);
520 m_aDBData.nCommandType = bIsTable ? CommandType::TABLE : CommandType::QUERY;
522 }
523 }
524 else if(nTables == 1)
525 {
526 if(aTables.hasElements())
527 {
528 m_aDBData.sCommand = aTables[0];
529 m_aDBData.nCommandType = CommandType::TABLE;
530 }
531 else
532 {
533 m_aDBData.sCommand = aQueries[0];
534 m_aDBData.nCommandType = CommandType::QUERY;
535 }
536 }
537 }
538 if ( !m_aDBData.sCommand.isEmpty() )
539 {
540 uno::Reference<beans::XPropertySet> xSourceProperties;
541 m_xDBContext->getByName(m_aDBData.sDataSource) >>= xSourceProperties;
542 pUserData->sURL = lcl_getFlatURL( xSourceProperties );
543
546 m_aDBData.nCommandType == CommandType::TABLE ?
548 //#i97577#
549 if( pUserData->xColumnsSupplier.is() )
550 m_xListLB->set_text(nSelect, m_aDBData.sCommand, 1);
551 else
552 m_xListLB->set_text(nSelect, OUString(), 1);
553 }
554 const OUString sCommand = m_xListLB->get_text(nSelect, 1);
555 m_xOK->set_sensitive(!sCommand.isEmpty());
556 m_xFilterPB->set_sensitive( pUserData->xConnection.is() && !sCommand.isEmpty() );
557 m_xTablePB->set_sensitive( pUserData->nTableAndQueryCount > 1 );
558 }
559 catch (const Exception&)
560 {
561 TOOLS_WARN_EXCEPTION( "sw", "exception caught in SwAddressListDialog::DetectTablesAndQueries");
562 m_xOK->set_sensitive(false);
563 }
564}
565
566IMPL_LINK(SwAddressListDialog, TableSelectHdl_Impl, weld::Button&, rButton, void)
567{
568 TableSelectHdl(&rButton);
569}
570
572{
573 weld::WaitObject aWait(m_xDialog.get());
574
575 int nSelect = m_xListLB->get_selected_index();
576 if (nSelect != -1)
577 {
578 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
579 //only call the table select dialog if tables have not been searched for or there
580 //are more than 1
581 const OUString sTable = m_xListLB->get_text(nSelect, 1);
582 if( pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
583 {
584 DetectTablesAndQueries(nSelect, (pButton != nullptr) || sTable.isEmpty());
585 }
586 }
587}
588
590{
591 m_xDialog->response(RET_OK);
592}
593
594uno::Reference< XDataSource> SwAddressListDialog::GetSource() const
595{
596 uno::Reference< XDataSource> xRet;
597 int nSelect = m_xListLB->get_selected_index();
598 if (nSelect != -1)
599 {
600 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
601 xRet = pUserData->xSource;
602 }
603 return xRet;
604
605}
606
608{
609 SharedConnection xRet;
610 int nSelect = m_xListLB->get_selected_index();
611 if (nSelect != -1)
612 {
613 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
614 xRet = pUserData->xConnection;
615 }
616 return xRet;
617}
618
619uno::Reference< XColumnsSupplier> SwAddressListDialog::GetColumnsSupplier() const
620{
621 uno::Reference< XColumnsSupplier> xRet;
622 int nSelect = m_xListLB->get_selected_index();
623 if (nSelect != -1)
624 {
625 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
626 xRet = pUserData->xColumnsSupplier;
627 }
628 return xRet;
629}
630
632{
633 int nSelect = m_xListLB->get_selected_index();
634 if (nSelect != -1)
635 {
636 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
637 return pUserData->sFilter;
638 }
639 return OUString();
640}
641
642/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString lcl_getFlatURL(uno::Reference< beans::XPropertySet > const &xSourceProperties)
IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, weld::Button &, void)
IMPL_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, void *, p, void)
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeFinalSlash()
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
std::unique_ptr< weld::Label > m_xConnecting
void TableSelectHdl(const weld::Button *pButton)
SwAddressListDialog(SwMailMergeAddressBlockPage *pParent)
std::unique_ptr< weld::Button > m_xTablePB
std::unique_ptr< weld::Button > m_xFilterPB
std::unique_ptr< weld::Button > m_xRemovePB
std::unique_ptr< weld::Label > m_xDescriptionFI
std::vector< std::unique_ptr< AddressUserData_Impl > > m_aUserData
SwMailMergeAddressBlockPage * m_pAddressPage
std::unique_ptr< weld::Button > m_xOK
SharedConnection GetConnection() const
std::unique_ptr< weld::Button > m_xEditPB
std::unique_ptr< weld::TreeIter > m_xIter
std::unique_ptr< weld::Button > m_xCreateListPB
std::unique_ptr< weld::Button > m_xLoadListPB
css::uno::Reference< css::sdbc::XDataSource > GetSource() const
css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnsSupplier() const
void DetectTablesAndQueries(int Select, bool bWidthDialog)
OUString GetFilter() const
css::uno::Reference< css::sdb::XDatabaseContext > m_xDBContext
virtual ~SwAddressListDialog() override
std::unique_ptr< weld::TreeView > m_xListLB
const OUString & GetURL() const
const SwDBData & GetBibliographySource()
Definition: dbconfig.cxx:89
static css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableOrQuery, SwDBSelect eTableOrQuery=SwDBSelect::UNKNOWN)
Definition: dbmgr.cxx:1877
static OUString LoadAndRegisterDataSource(weld::Window *pParent, SwDocShell *pDocShell=nullptr)
Loads a data source from file and registers it.
Definition: dbmgr.cxx:2779
static void RevokeDataSource(const OUString &rName)
Unregister a data source.
Definition: dbmgr.cxx:2878
SwMailMergeWizard * GetWizard()
const SwDBData & GetCurrentDBData() const
SharedConnection const & GetConnection() const
OUString & GetFilter() const
css::uno::Reference< css::sdbcx::XColumnsSupplier > const & GetColumnsSupplier()
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
css::uno::Reference< css::sdbc::XDataSource > const & GetSource() const
SwMailMergeConfigItem & GetConfigItem()
void SetSelectedTable(std::u16string_view rTable, bool bIsTable)
OUString GetSelectedTable(bool &bIsTable)
Definition: view.hxx:145
SwDocShell * GetDocShell()
Definition: view.cxx:1133
const css::uno::Reference< INTERFACE > & getTyped() const
OUString const & GetURL() const
void EnableKillingFile(bool bEnable=true)
#define TOOLS_WARN_EXCEPTION(area, stream)
URL aURL
sal_Int32 nIndex
void * p
bool UCB_IsFile(const OUString &rURL)
bool UCB_IsReadOnlyFileName(const OUString &rURL)
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
@ Exception
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
OUString toId(const void *pValue)
::utl::SharedUNOComponent< css::sdbc::XConnection > SharedConnection
uno::Reference< sdbc::XResultSet > xResultSet
uno::Reference< XDataSource > xSource
SharedConnection xConnection
uno::Reference< XColumnsSupplier > xColumnsSupplier
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
OUString sDataSource
Definition: swdbdata.hxx:30
OUString sCommand
Definition: swdbdata.hxx:31
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
RET_OK
RET_YES