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