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>
85static OUString
lcl_getFlatURL( uno::Reference<beans::XPropertySet>
const & xSourceProperties )
87 if(xSourceProperties.is())
90 xSourceProperties->getPropertyValue(
"URL") >>= sDBURL;
91 if (sDBURL.startsWith(
"sdbc:flat:"))
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() )
101 for(
const auto& rInfo : std::as_const(aInfo))
103 if(rInfo.Name ==
"Extension")
104 rInfo.Value >>= sExtension;
105 else if(rInfo.Name ==
"CharSet")
106 rInfo.Value >>= sCharSet;
108 if (sCharSet==
"UTF-8")
112 +
"/" + aFilters[0] +
"." + sExtension;
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())
152 std::vector<int> aWidths
154 o3tl::narrowing<int>(
m_xListLB->get_approximate_digit_width() * 26)
156 m_xListLB->set_column_fixed_widths(aWidths);
161 uno::Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
167 bool bEnableEdit =
false;
168 bool bEnableOK =
true;
169 bool bSelected =
false;
174 const uno::Sequence< OUString> aNames =
m_xDBContext->getElementNames();
175 for(
const OUString& rName : aNames)
177 if ( rName == sBibliography )
196 uno::Reference<beans::XPropertySet> xSourceProperties;
201 bEnableEdit = !pUserData->
sURL.isEmpty() &&
205 catch (
const uno::Exception&)
213 bool bHasChildren =
m_xListLB->n_children() > 0;
214 if (bHasChildren && !bSelected)
216 m_xOK->set_sensitive(bHasChildren && bEnableOK);
231 int nSelect = m_xListLB->get_selected_index();
232 uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
236 const OUString sCommand = m_xListLB->get_text(nSelect, 1);
237 if (sCommand.isEmpty())
240 AddressUserData_Impl* pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
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);
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));
261 xRowProperties->getPropertyValue(
"ActiveCommand")>>= sQuery;
262 xComposer->setQuery(sQuery);
263 if(!pUserData->
sFilter.isEmpty())
264 xComposer->setFilter(pUserData->
sFilter);
267 xComposer,xRowSet, uno::Reference<awt::XWindow>() );
269 if (
RET_OK == xDialog->execute() )
272 pUserData->
sFilter = xComposer->getFilter();
274 ::comphelper::disposeComponent(xRowSet);
284 SwView* pView = m_pAddressPage->GetWizard()->GetSwView();
287 if(!sNewSource.isEmpty())
289 m_xListLB->append(m_xIter.get());
290 m_xListLB->set_text(*m_xIter, sNewSource, 0);
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);
302 int nEntry = m_xListLB->get_selected_index();
307 VclMessageType::Question, VclButtonsType::YesNo,
SwResId(ST_DELETE_CONFIRM)));
314 m_xListLB->remove(nEntry);
316 if (m_xListLB->n_children() < 1 )
318 m_xRemovePB->set_sensitive(
false);
319 m_xEditPB->set_sensitive(
false);
320 m_xFilterPB->set_sensitive(
false);
321 m_xCreateListPB->set_sensitive(
true);
334 const OUString sURL = aDlg.
GetURL();
337 uno::Reference<XInterface> xNewInstance = m_xDBContext->createInstance();
339 const OUString sNewName =
aURL.getBase();
341 OUString sFind(sNewName);
343 while(m_xDBContext->hasByName(sFind))
345 sFind = sNewName + OUString::number(++
nIndex);
347 uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY);
354 xDataProperties->setPropertyValue(
"URL",
Any(sDBURL));
356 uno::Sequence<OUString> aFilters { sNewName };
357 xDataProperties->setPropertyValue(
"TableFilter",
Any(aFilters));
359 uno::Sequence<PropertyValue> aInfo
366 xDataProperties->setPropertyValue(
"Info",
Any(aInfo));
368 uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
369 uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
375 sTmpName = aTempFile.
GetURL();
377 xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
379 m_xDBContext->registerObject( sFind, xNewInstance );
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);
386 m_xListLB->set_id(*m_xIter,
weld::toId(pUserData));
387 m_xListLB->select(*m_xIter);
388 ListBoxSelectHdl_Impl(*m_xListLB);
389 m_xCreateListPB->set_sensitive(
false);
390 m_xRemovePB->set_sensitive(
true);
399 int nEntry = m_xListLB->get_selected_index();
400 AddressUserData_Impl* pUserData = nEntry != -1 ? weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nEntry)) :
nullptr;
401 if (!pUserData || pUserData->
sURL.isEmpty())
408 ::comphelper::disposeComponent( pUserData->
xResultSet );
418 m_pAddressPage->GetWizard()->GetConfigItem());
424 int nSelect = m_xListLB->get_selected_index();
426 StaticListBoxSelectHdl_Impl ),
reinterpret_cast<void*
>(nSelect) );
431 int nSelect =
reinterpret_cast<sal_IntPtr
>(
p);
436 m_bInSelectHdl =
true;
440 const OUString sTable(m_xListLB->get_text(nSelect, 1));
441 if (sTable.isEmpty())
443 m_xListLB->set_text(nSelect, m_sConnecting, 1);
446 pUserData = weld::fromId<AddressUserData_Impl*>(m_xListLB->get_id(nSelect));
449 DetectTablesAndQueries(nSelect, sTable.isEmpty());
454 m_aDBData.sDataSource = m_xListLB->get_text(nSelect, 0);
455 m_aDBData.sCommand = m_xListLB->get_text(nSelect, 1);
457 m_xOK->set_sensitive(
true);
459 if (m_xListLB->get_text(nSelect, 1) == m_sConnecting)
460 m_xListLB->set_text(nSelect, OUString(), 1);
462 m_xEditPB->set_sensitive(pUserData && !pUserData->
sURL.isEmpty() &&
465 m_bInSelectHdl =
false;
477 uno::Reference<XCompletedConnection> xComplConnection;
482 pUserData->
xSource.set(xComplConnection, UNO_QUERY);
484 uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
485 uno::Reference< XInteractionHandler > xHandler = InteractionHandler::createWithParent(xContext,
nullptr);
490 sal_Int32 nTables = 0;
491 uno::Sequence<OUString> aTables;
492 uno::Sequence<OUString> aQueries;
493 uno::Reference<XTablesSupplier> xTSupplier(pUserData->
xConnection, UNO_QUERY);
496 uno::Reference<XNameAccess> xTables = xTSupplier->getTables();
497 aTables = xTables->getElementNames();
498 nTables += aTables.getLength();
500 uno::Reference<XQueriesSupplier> xQSupplier(pUserData->
xConnection, UNO_QUERY);
503 uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries();
504 aQueries = xQueries->getElementNames();
505 nTables += aQueries.getLength();
508 if(nTables > 1 && bWidthDialog)
512 const OUString sTable =
m_xListLB->get_text(nSelect, 1);
513 if(!sTable.isEmpty())
523 else if(nTables == 1)
525 if(aTables.hasElements())
539 uno::Reference<beans::XPropertySet> xSourceProperties;
551 m_xListLB->set_text(nSelect, OUString(), 1);
553 const OUString sCommand =
m_xListLB->get_text(nSelect, 1);
554 m_xOK->set_sensitive(!sCommand.isEmpty());
561 m_xOK->set_sensitive(
false);
567 TableSelectHdl(&rButton);
574 int nSelect =
m_xListLB->get_selected_index();
580 const OUString sTable =
m_xListLB->get_text(nSelect, 1);
595 uno::Reference< XDataSource> xRet;
596 int nSelect =
m_xListLB->get_selected_index();
609 int nSelect =
m_xListLB->get_selected_index();
620 uno::Reference< XColumnsSupplier> xRet;
621 int nSelect =
m_xListLB->get_selected_index();
632 int nSelect =
m_xListLB->get_selected_index();
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, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
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()
static css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableOrQuery, SwDBSelect eTableOrQuery=SwDBSelect::UNKNOWN)
static OUString LoadAndRegisterDataSource(weld::Window *pParent, SwDocShell *pDocShell=nullptr)
Loads a data source from file and registers it.
static void RevokeDataSource(const OUString &rName)
Unregister a data source.
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)
SwDocShell * GetDocShell()
const css::uno::Reference< INTERFACE > & getTyped() const
void EnableKillingFile(bool bEnable=true)
OUString const & GetURL() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define LINK(Instance, Class, Member)
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)
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
sal_Int32 nTableAndQueryCount
uno::Reference< XColumnsSupplier > xColumnsSupplier
OUString SwResId(TranslateId aId)