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