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