1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
27cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <swtypes.hxx>
30cdf0e10cSrcweir #include <addresslistdialog.hxx>
31cdf0e10cSrcweir #include <selectdbtabledialog.hxx>
32cdf0e10cSrcweir #include <createaddresslistdialog.hxx>
33cdf0e10cSrcweir #include <mailmergewizard.hxx>
34cdf0e10cSrcweir #include <mmconfigitem.hxx>
35cdf0e10cSrcweir #include <mmaddressblockpage.hxx>
36cdf0e10cSrcweir #ifndef _DBMGR_HXX
37cdf0e10cSrcweir #include <dbmgr.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <dbconfig.hxx>
40cdf0e10cSrcweir #include <unotools/tempfile.hxx>
41cdf0e10cSrcweir #include <vcl/msgbox.hxx>
42cdf0e10cSrcweir #include <vcl/svapp.hxx>
43cdf0e10cSrcweir #include <tools/urlobj.hxx>
44cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45cdf0e10cSrcweir #include <comphelper/types.hxx>
46cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp>
47cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
48cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
49cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp>
53cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
54cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSERFACTORY_HPP_
55cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
58cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
59cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
60cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
61cdf0e10cSrcweir #include <swunohelper.hxx>
62cdf0e10cSrcweir #include <vcl/waitobj.hxx>
63cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
64cdf0e10cSrcweir #include <svl/urihelper.hxx>
65cdf0e10cSrcweir #include <addresslistdialog.hrc>
66cdf0e10cSrcweir #include <dbui.hrc>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <helpid.h>
69cdf0e10cSrcweir #include <unomid.h>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir using namespace ::com::sun::star;
73cdf0e10cSrcweir using namespace ::com::sun::star::uno;
74cdf0e10cSrcweir using namespace ::com::sun::star::lang;
75cdf0e10cSrcweir using namespace ::com::sun::star::container;
76cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
77cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
78cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
79cdf0e10cSrcweir using namespace ::com::sun::star::task;
80cdf0e10cSrcweir using namespace ::com::sun::star::beans;
81cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
82cdf0e10cSrcweir using namespace ::rtl;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir #define ITEMID_NAME         1
85cdf0e10cSrcweir #define ITEMID_TABLE        2
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //typedef SharedUNOComponent< XConnection >   SharedConnection;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir static const char* cUTF8 = "UTF-8";
90cdf0e10cSrcweir /*-- 07.05.2004 14:11:34---------------------------------------------------
91cdf0e10cSrcweir 
92cdf0e10cSrcweir   -----------------------------------------------------------------------*/
93cdf0e10cSrcweir struct AddressUserData_Impl
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     uno::Reference<XDataSource>             xSource;
96cdf0e10cSrcweir     SharedConnection                        xConnection;
97cdf0e10cSrcweir     uno::Reference< XColumnsSupplier>       xColumnsSupplier;
98cdf0e10cSrcweir     uno::Reference< sdbc::XResultSet>       xResultSet;
99cdf0e10cSrcweir     ::rtl::OUString                    sFilter;
100cdf0e10cSrcweir     ::rtl::OUString                    sURL; // data is editable
101cdf0e10cSrcweir     sal_Int32                          nCommandType;
102cdf0e10cSrcweir     sal_Int32                          nTableAndQueryCount;
AddressUserData_ImplAddressUserData_Impl103cdf0e10cSrcweir     AddressUserData_Impl() :
104cdf0e10cSrcweir         nCommandType(0),
105cdf0e10cSrcweir         nTableAndQueryCount(-1)
106cdf0e10cSrcweir         {}
107cdf0e10cSrcweir };
lcl_getFlatURL(uno::Reference<beans::XPropertySet> & xSourceProperties)108cdf0e10cSrcweir ::rtl::OUString lcl_getFlatURL( uno::Reference<beans::XPropertySet>& xSourceProperties )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     ::rtl::OUString sURL;
111cdf0e10cSrcweir     if(xSourceProperties.is())
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         rtl::OUString sDBURL;
114cdf0e10cSrcweir         xSourceProperties->getPropertyValue(C2U("URL")) >>= sDBURL;
115cdf0e10cSrcweir         if(String(sDBURL).SearchAscii("sdbc:flat:") == 0)
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             uno::Sequence<OUString> aFilters;
118cdf0e10cSrcweir             xSourceProperties->getPropertyValue(C2U("TableFilter")) >>= aFilters;
119cdf0e10cSrcweir             uno::Sequence<PropertyValue> aInfo;
120cdf0e10cSrcweir             xSourceProperties->getPropertyValue(C2U("Info")) >>= aInfo;
121cdf0e10cSrcweir             if(aFilters.getLength() == 1 && aInfo.getLength() )
122cdf0e10cSrcweir             {
123cdf0e10cSrcweir                 ::rtl::OUString sFieldDelim;
124cdf0e10cSrcweir                 ::rtl::OUString sStringDelim;
125cdf0e10cSrcweir                 ::rtl::OUString sExtension;
126cdf0e10cSrcweir                 ::rtl::OUString sCharSet;
127cdf0e10cSrcweir                 for(sal_Int32 nInfo = 0; nInfo < aInfo.getLength(); ++nInfo)
128cdf0e10cSrcweir                 {
129cdf0e10cSrcweir                     if(aInfo[nInfo].Name == C2U("FieldDelimiter"))
130cdf0e10cSrcweir                         aInfo[nInfo].Value >>= sFieldDelim;
131cdf0e10cSrcweir                     else if(aInfo[nInfo].Name == C2U("StringDelimiter"))
132cdf0e10cSrcweir                         aInfo[nInfo].Value >>= sStringDelim;
133cdf0e10cSrcweir                     else if(aInfo[nInfo].Name == C2U("Extension"))
134cdf0e10cSrcweir                         aInfo[nInfo].Value >>= sExtension;
135cdf0e10cSrcweir                     else if(aInfo[nInfo].Name == C2U("CharSet"))
136cdf0e10cSrcweir                         aInfo[nInfo].Value >>= sCharSet;
137cdf0e10cSrcweir                 }
138cdf0e10cSrcweir                 if(!sCharSet.compareToAscii( cUTF8 ))
139cdf0e10cSrcweir                 {
140cdf0e10cSrcweir                     sURL = String(sDBURL).Copy( 10 );
141cdf0e10cSrcweir                     //#i97577# at this point the 'URL' can also be a file name!
142cdf0e10cSrcweir                     sURL = URIHelper::SmartRel2Abs( INetURLObject(), sURL );
143cdf0e10cSrcweir                     sURL += C2U("/");
144cdf0e10cSrcweir                     sURL += aFilters[0];
145cdf0e10cSrcweir                     sURL += C2U(".");
146cdf0e10cSrcweir                     sURL += sExtension;
147cdf0e10cSrcweir                 }
148cdf0e10cSrcweir             }
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     return sURL;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir /*-- 07.04.2004 16:35:43---------------------------------------------------
154cdf0e10cSrcweir 
155cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SwAddressListDialog(SwMailMergeAddressBlockPage * pParent)156cdf0e10cSrcweir SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent) :
157cdf0e10cSrcweir     SfxModalDialog(pParent, SW_RES(DLG_MM_ADDRESSLISTDIALOG)),
158cdf0e10cSrcweir #ifdef MSC
159cdf0e10cSrcweir #pragma warning (disable : 4355)
160cdf0e10cSrcweir #endif
161cdf0e10cSrcweir     m_aDescriptionFI( this, SW_RES(  FI_DESCRIPTION    )),
162cdf0e10cSrcweir     m_aListFT( this, SW_RES(         FT_LIST           )),
163cdf0e10cSrcweir     m_aListHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
164cdf0e10cSrcweir     m_aListLB( this, SW_RES(         LB_LIST           )),
165cdf0e10cSrcweir     m_aLoadListPB( this, SW_RES(     PB_LOADLIST       )),
166cdf0e10cSrcweir     m_aCreateListPB(this, SW_RES(    PB_CREATELIST     )),
167cdf0e10cSrcweir     m_aFilterPB( this, SW_RES(       PB_FILTER         )),
168cdf0e10cSrcweir     m_aEditPB(this, SW_RES(          PB_EDIT           )),
169cdf0e10cSrcweir     m_aTablePB(this, SW_RES(         PB_TABLE          )),
170cdf0e10cSrcweir     m_aSeparatorFL(this, SW_RES(    FL_SEPARATOR      )),
171cdf0e10cSrcweir     m_aOK( this, SW_RES(             PB_OK             )),
172cdf0e10cSrcweir     m_aCancel( this, SW_RES(         PB_CANCEL         )),
173cdf0e10cSrcweir     m_aHelp( this, SW_RES(           PB_HELP           )),
174cdf0e10cSrcweir #ifdef MSC
175cdf0e10cSrcweir #pragma warning (default : 4355)
176cdf0e10cSrcweir #endif
177cdf0e10cSrcweir     m_sName(        SW_RES( ST_NAME )),
178cdf0e10cSrcweir     m_sTable(       SW_RES( ST_TABLE )),
179cdf0e10cSrcweir     m_sConnecting(  SW_RES( ST_CONNECTING )),
180cdf0e10cSrcweir     m_pCreatedDataSource(0),
181cdf0e10cSrcweir     m_bInSelectHdl(false),
182cdf0e10cSrcweir     m_pAddressPage(pParent)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     FreeResource();
185cdf0e10cSrcweir     String sTemp(m_aDescriptionFI.GetText());
186cdf0e10cSrcweir     sTemp.SearchAndReplaceAscii("%1", m_aLoadListPB.GetText());
187cdf0e10cSrcweir     sTemp.SearchAndReplaceAscii("%2", m_aCreateListPB.GetText());
188cdf0e10cSrcweir     m_aDescriptionFI.SetText(sTemp);
189cdf0e10cSrcweir     m_aFilterPB.SetClickHdl( LINK( this, SwAddressListDialog,    FilterHdl_Impl ));
190cdf0e10cSrcweir     m_aLoadListPB.SetClickHdl( LINK( this, SwAddressListDialog,  LoadHdl_Impl ));
191cdf0e10cSrcweir     m_aCreateListPB.SetClickHdl( LINK( this, SwAddressListDialog,CreateHdl_Impl ));
192cdf0e10cSrcweir     m_aEditPB.SetClickHdl(LINK( this, SwAddressListDialog, EditHdl_Impl));
193cdf0e10cSrcweir     m_aTablePB.SetClickHdl(LINK( this, SwAddressListDialog, TableSelectHdl_Impl));
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     Size aLBSize(m_aListLB.GetSizePixel());
196cdf0e10cSrcweir     m_aListHB.SetSizePixel(aLBSize);
197cdf0e10cSrcweir     Size aHeadSize(m_aListHB.CalcWindowSizePixel());
198cdf0e10cSrcweir     aHeadSize.Width() = aLBSize.Width();
199cdf0e10cSrcweir     m_aListHB.SetSizePixel(aHeadSize);
200cdf0e10cSrcweir     Point aLBPos(m_aListLB.GetPosPixel());
201cdf0e10cSrcweir     m_aListHB.SetPosPixel(aLBPos);
202cdf0e10cSrcweir     aLBPos.Y() += aHeadSize.Height();
203cdf0e10cSrcweir     aLBSize.Height() -= aHeadSize.Height();
204cdf0e10cSrcweir     m_aListLB.SetPosSizePixel(aLBPos, aLBSize);
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     Size aSz(m_aListHB.GetOutputSizePixel());
207cdf0e10cSrcweir     m_aListHB.InsertItem( ITEMID_NAME, m_sName,
208cdf0e10cSrcweir                             aSz.Width()/2,
209cdf0e10cSrcweir                             HIB_LEFT | HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS/*| HIB_CLICKABLE | HIB_UPARROW */);
210cdf0e10cSrcweir     m_aListHB.InsertItem( ITEMID_TABLE, m_sTable,
211cdf0e10cSrcweir                             aSz.Width()/2,
212cdf0e10cSrcweir                             HIB_LEFT | HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS /*| HIB_CLICKABLE | HIB_UPARROW */);
213cdf0e10cSrcweir     m_aListHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
214cdf0e10cSrcweir     m_aListHB.Show();
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     m_aListLB.SetHelpId(HID_MM_ADDRESSLIST_TLB);
217cdf0e10cSrcweir     static long nTabs[] = {2, 0, aSz.Width()/2 };
218cdf0e10cSrcweir     m_aListLB.SetStyle( m_aListLB.GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
219cdf0e10cSrcweir     m_aListLB.SetSelectionMode( SINGLE_SELECTION );
220cdf0e10cSrcweir     m_aListLB.SetTabs(&nTabs[0], MAP_PIXEL);
221cdf0e10cSrcweir     m_aOK.SetClickHdl( LINK( this, SwAddressListDialog, OKHdl_Impl));
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
224cdf0e10cSrcweir     if( xMgr.is() )
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         uno::Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
227cdf0e10cSrcweir         m_xDBContext = uno::Reference<XNameAccess>(xInstance, UNO_QUERY) ;
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir     SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem();
230cdf0e10cSrcweir     const SwDBData& rCurrentData = rConfigItem.GetCurrentDBData();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     DBG_ASSERT(m_xDBContext.is(), "service 'com.sun.star.sdb.DatabaseContext' not found!");
233cdf0e10cSrcweir     sal_Bool bEnableEdit = sal_False;
234cdf0e10cSrcweir     sal_Bool bEnableOK = sal_True;
235cdf0e10cSrcweir     m_aListLB.SelectAll( sal_False );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     if(m_xDBContext.is())
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         SwDBConfig aDb;
240cdf0e10cSrcweir         ::rtl::OUString sBibliography = aDb.GetBibliographySource().sDataSource;
241cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString> aNames = m_xDBContext->getElementNames();
242cdf0e10cSrcweir         const ::rtl::OUString* pNames = aNames.getConstArray();
243cdf0e10cSrcweir         for(sal_Int32 nName = 0; nName < aNames.getLength(); ++nName)
244cdf0e10cSrcweir         {
245cdf0e10cSrcweir             if ( pNames[nName] == sBibliography )
246cdf0e10cSrcweir                 continue;
247cdf0e10cSrcweir             SvLBoxEntry* pEntry = m_aListLB.InsertEntry(pNames[nName]);
248cdf0e10cSrcweir             AddressUserData_Impl* pUserData = new AddressUserData_Impl();
249cdf0e10cSrcweir             pEntry->SetUserData(pUserData);
250cdf0e10cSrcweir             if(pNames[nName] == rCurrentData.sDataSource)
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 m_aListLB.Select(pEntry);
253cdf0e10cSrcweir                 m_aListLB.SetEntryText(rCurrentData.sCommand, pEntry, ITEMID_TABLE - 1);
254cdf0e10cSrcweir                 pUserData->nCommandType = rCurrentData.nCommandType;
255cdf0e10cSrcweir                 pUserData->xSource = rConfigItem.GetSource();
256cdf0e10cSrcweir                 pUserData->xConnection = rConfigItem.GetConnection();
257cdf0e10cSrcweir                 pUserData->xColumnsSupplier = rConfigItem.GetColumnsSupplier();
258cdf0e10cSrcweir                 pUserData->xResultSet = rConfigItem.GetResultSet();
259cdf0e10cSrcweir                 pUserData->sFilter = rConfigItem.GetFilter();
260cdf0e10cSrcweir                 //is the data source editable (csv, Unicode, single table)
261cdf0e10cSrcweir                 uno::Reference<beans::XPropertySet> xSourceProperties;
262cdf0e10cSrcweir                 try
263cdf0e10cSrcweir                 {
264cdf0e10cSrcweir                     m_xDBContext->getByName(pNames[nName]) >>= xSourceProperties;
265cdf0e10cSrcweir                     pUserData->sURL = lcl_getFlatURL( xSourceProperties );
266cdf0e10cSrcweir                     bEnableEdit = pUserData->sURL.getLength() > 0 &&
267cdf0e10cSrcweir                         SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577#
268cdf0e10cSrcweir                         !SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL );
269cdf0e10cSrcweir                 }
270cdf0e10cSrcweir                 catch(const uno::Exception& )
271cdf0e10cSrcweir                 {
272cdf0e10cSrcweir                     bEnableOK = sal_False;
273cdf0e10cSrcweir                 }
274cdf0e10cSrcweir                 m_aDBData = rCurrentData;
275cdf0e10cSrcweir             }
276cdf0e10cSrcweir         }
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir     m_aOK.Enable(m_aListLB.GetEntryCount()>0 && bEnableOK);
279cdf0e10cSrcweir     m_aEditPB.Enable(bEnableEdit);
280cdf0e10cSrcweir     m_aListLB.SetSelectHdl(LINK(this, SwAddressListDialog, ListBoxSelectHdl_Impl));
281cdf0e10cSrcweir 	TableSelectHdl_Impl(NULL);
282cdf0e10cSrcweir }
283cdf0e10cSrcweir /*-- 07.04.2004 16:35:43---------------------------------------------------
284cdf0e10cSrcweir 
285cdf0e10cSrcweir   -----------------------------------------------------------------------*/
~SwAddressListDialog()286cdf0e10cSrcweir SwAddressListDialog::~SwAddressListDialog()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir     SvLBoxEntry* pEntry = m_aListLB.First();
289cdf0e10cSrcweir     while(pEntry)
290cdf0e10cSrcweir     {
291cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pEntry->GetUserData());
292cdf0e10cSrcweir         delete pUserData;
293cdf0e10cSrcweir         pEntry = m_aListLB.Next( pEntry );
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir }
296cdf0e10cSrcweir /*-- 07.04.2004 16:35:44---------------------------------------------------
297cdf0e10cSrcweir 
298cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,FilterHdl_Impl,PushButton *,EMPTYARG)299cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, FilterHdl_Impl, PushButton*, EMPTYARG)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
302cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
303cdf0e10cSrcweir     if(pSelect && xMgr.is())
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         String sCommand = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
306cdf0e10cSrcweir         if ( !sCommand.Len() )
307cdf0e10cSrcweir             return 0;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
310cdf0e10cSrcweir         if(pUserData->xConnection.is() )
311cdf0e10cSrcweir         {
312cdf0e10cSrcweir             try
313cdf0e10cSrcweir             {
314cdf0e10cSrcweir                 uno::Reference<lang::XMultiServiceFactory> xConnectFactory(pUserData->xConnection, UNO_QUERY_THROW);
315cdf0e10cSrcweir                 uno::Reference<XSingleSelectQueryComposer> xComposer(
316cdf0e10cSrcweir                         xConnectFactory->createInstance(C2U("com.sun.star.sdb.SingleSelectQueryComposer")), UNO_QUERY_THROW);
317cdf0e10cSrcweir 
318cdf0e10cSrcweir                 PropertyValue aSecond;
319cdf0e10cSrcweir                 aSecond.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) );
320cdf0e10cSrcweir                 uno::Reference<XRowSet> xRowSet(
321cdf0e10cSrcweir                         xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY);
322cdf0e10cSrcweir                 uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
323cdf0e10cSrcweir                 xRowProperties->setPropertyValue(C2U("DataSourceName"),
324cdf0e10cSrcweir                         makeAny(OUString(m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1))));
325cdf0e10cSrcweir                 xRowProperties->setPropertyValue(C2U("Command"), makeAny(
326cdf0e10cSrcweir                         OUString(sCommand)));
327cdf0e10cSrcweir                 xRowProperties->setPropertyValue(C2U("CommandType"), makeAny(pUserData->nCommandType));
328cdf0e10cSrcweir                 xRowProperties->setPropertyValue(C2U("ActiveConnection"), makeAny(pUserData->xConnection.getTyped()));
329cdf0e10cSrcweir                 xRowSet->execute();
330cdf0e10cSrcweir                 aSecond.Value <<= xRowSet;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir                 PropertyValue aFirst;
333cdf0e10cSrcweir                 aFirst.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) );
334cdf0e10cSrcweir                 ::rtl::OUString sQuery;
335cdf0e10cSrcweir                 xRowProperties->getPropertyValue(C2U("ActiveCommand"))>>= sQuery;
336cdf0e10cSrcweir                 xComposer->setQuery(sQuery);
337cdf0e10cSrcweir                 if(pUserData->sFilter.getLength())
338cdf0e10cSrcweir                     xComposer->setFilter(pUserData->sFilter);
339cdf0e10cSrcweir                 aFirst.Value <<= xComposer;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir                 uno::Sequence<Any> aInit(2);
342cdf0e10cSrcweir                 aInit[0] <<= aFirst;
343cdf0e10cSrcweir                 aInit[1] <<= aSecond;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir                 ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FilterDialog" ) );
346cdf0e10cSrcweir                 uno::Reference< XExecutableDialog> xDialog(
347cdf0e10cSrcweir                         xMgr->createInstanceWithArguments( sDialogServiceName, aInit ), UNO_QUERY);
348cdf0e10cSrcweir 
349cdf0e10cSrcweir                 if ( RET_OK == xDialog->execute() )
350cdf0e10cSrcweir                 {
351cdf0e10cSrcweir                     WaitObject aWO( NULL );
352cdf0e10cSrcweir                     pUserData->sFilter = xComposer->getFilter();
353cdf0e10cSrcweir                 }
354cdf0e10cSrcweir                 ::comphelper::disposeComponent(xRowSet);
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir             catch(Exception& )
357cdf0e10cSrcweir             {
358cdf0e10cSrcweir                 DBG_ERROR("exception caught in SwAddressListDialog::FilterHdl_Impl");
359cdf0e10cSrcweir             }
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir     return 0;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir /*-- 07.04.2004 16:35:44---------------------------------------------------
365cdf0e10cSrcweir 
366cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,LoadHdl_Impl,PushButton *,EMPTYARG)367cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, LoadHdl_Impl,   PushButton*, EMPTYARG)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     String sNewSource = SwNewDBMgr::LoadAndRegisterDataSource();
370cdf0e10cSrcweir     if(sNewSource.Len())
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         SvLBoxEntry* pNewSource = m_aListLB.InsertEntry(sNewSource);
373cdf0e10cSrcweir         pNewSource->SetUserData(new AddressUserData_Impl());
374cdf0e10cSrcweir         m_aListLB.Select(pNewSource);
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir     return 0;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir /*-- 07.04.2004 16:35:44---------------------------------------------------
379cdf0e10cSrcweir 
380cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,CreateHdl_Impl,PushButton *,pButton)381cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, CreateHdl_Impl, PushButton*, pButton)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     String sInputURL;
384cdf0e10cSrcweir     SwCreateAddressListDialog* pDlg =
385cdf0e10cSrcweir             new SwCreateAddressListDialog(
386cdf0e10cSrcweir                     pButton,
387cdf0e10cSrcweir                     sInputURL,
388cdf0e10cSrcweir                     m_pAddressPage->GetWizard()->GetConfigItem());
389cdf0e10cSrcweir     if(RET_OK == pDlg->Execute())
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         //register the URL a new datasource
392cdf0e10cSrcweir         OUString sURL = pDlg->GetURL();
393cdf0e10cSrcweir         try
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             uno::Reference<XSingleServiceFactory> xFact( m_xDBContext, UNO_QUERY);
396cdf0e10cSrcweir             uno::Reference<XInterface> xNewInstance = xFact->createInstance();
397cdf0e10cSrcweir             INetURLObject aURL( sURL );
398cdf0e10cSrcweir             OUString sNewName = aURL.getBase();
399cdf0e10cSrcweir             //find a unique name if sNewName already exists
400cdf0e10cSrcweir             OUString sFind(sNewName);
401cdf0e10cSrcweir             sal_Int32 nIndex = 0;
402cdf0e10cSrcweir             while(m_xDBContext->hasByName(sFind))
403cdf0e10cSrcweir             {
404cdf0e10cSrcweir                 sFind = sNewName;
405cdf0e10cSrcweir                 sFind += OUString::valueOf(++nIndex);
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir             uno::Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY);
408cdf0e10cSrcweir 
409cdf0e10cSrcweir             OUString sDBURL(C2U("sdbc:flat:"));
410cdf0e10cSrcweir             //only the 'path' has to be added
411cdf0e10cSrcweir             INetURLObject aTempURL(aURL);
412cdf0e10cSrcweir             aTempURL.removeSegment();
413cdf0e10cSrcweir             aTempURL.removeFinalSlash();
414cdf0e10cSrcweir             sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
415cdf0e10cSrcweir             Any aAny(&sDBURL, ::getCppuType(&sDBURL));
416cdf0e10cSrcweir             xDataProperties->setPropertyValue(C2U("URL"), aAny);
417cdf0e10cSrcweir             //set the filter to the file name without extension
418cdf0e10cSrcweir             uno::Sequence<OUString> aFilters(1);
419cdf0e10cSrcweir             aFilters[0] = sNewName;
420cdf0e10cSrcweir             aAny <<= aFilters;
421cdf0e10cSrcweir             xDataProperties->setPropertyValue(C2U("TableFilter"), aAny);
422cdf0e10cSrcweir 
423cdf0e10cSrcweir             uno::Sequence<PropertyValue> aInfo(4);
424cdf0e10cSrcweir             PropertyValue* pInfo = aInfo.getArray();
425cdf0e10cSrcweir             pInfo[0].Name = C2U("FieldDelimiter");
426cdf0e10cSrcweir             pInfo[0].Value <<= OUString(String('\t'));
427cdf0e10cSrcweir             pInfo[1].Name = C2U("StringDelimiter");
428cdf0e10cSrcweir             pInfo[1].Value <<= OUString('"');
429cdf0e10cSrcweir             pInfo[2].Name = C2U("Extension");
430cdf0e10cSrcweir             pInfo[2].Value <<= ::rtl::OUString(aURL.getExtension());//C2U("csv");
431cdf0e10cSrcweir             pInfo[3].Name = C2U("CharSet");
432cdf0e10cSrcweir             pInfo[3].Value <<= C2U(cUTF8);
433cdf0e10cSrcweir             aAny <<= aInfo;
434cdf0e10cSrcweir             xDataProperties->setPropertyValue(C2U("Info"), aAny);
435cdf0e10cSrcweir 
436cdf0e10cSrcweir             uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
437cdf0e10cSrcweir             uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
438cdf0e10cSrcweir             String sExt = String::CreateFromAscii(".odb");
439cdf0e10cSrcweir             String sTmpName;
440cdf0e10cSrcweir             {
441cdf0e10cSrcweir                 String sHomePath(SvtPathOptions().GetWorkPath());
442cdf0e10cSrcweir                 utl::TempFile aTempFile(sFind , &sExt, &sHomePath);
443cdf0e10cSrcweir                 aTempFile.EnableKillingFile(sal_True);
444cdf0e10cSrcweir                 sTmpName = aTempFile.GetURL();
445cdf0e10cSrcweir             }
446cdf0e10cSrcweir             xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 
449cdf0e10cSrcweir             uno::Reference<XNamingService> xNaming(m_xDBContext, UNO_QUERY);
450cdf0e10cSrcweir             xNaming->registerObject( sFind, xNewInstance );
451cdf0e10cSrcweir             //now insert the new source into the ListBox
452cdf0e10cSrcweir             String sEntry(sFind);
453cdf0e10cSrcweir             sEntry += '\t';
454cdf0e10cSrcweir             sEntry += String(aFilters[0]);
455cdf0e10cSrcweir             m_pCreatedDataSource = m_aListLB.InsertEntry(sEntry);
456cdf0e10cSrcweir             AddressUserData_Impl* pUserData = new AddressUserData_Impl();
457cdf0e10cSrcweir             pUserData->sURL = sURL;
458cdf0e10cSrcweir             m_pCreatedDataSource->SetUserData(pUserData);
459cdf0e10cSrcweir             m_aListLB.Select(m_pCreatedDataSource);
460cdf0e10cSrcweir             m_aCreateListPB.Enable(sal_False);
461cdf0e10cSrcweir 
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir         catch(Exception& )
464cdf0e10cSrcweir         {
465cdf0e10cSrcweir         }
466cdf0e10cSrcweir     }
467cdf0e10cSrcweir     delete pDlg;
468cdf0e10cSrcweir     return 0;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir /*-- 22.04.2004 10:30:40---------------------------------------------------
471cdf0e10cSrcweir 
472cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,EditHdl_Impl,PushButton *,pButton)473cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, EditHdl_Impl, PushButton*, pButton)
474cdf0e10cSrcweir {
475cdf0e10cSrcweir     SvLBoxEntry* pEntry = m_aListLB.FirstSelected();
476cdf0e10cSrcweir     AddressUserData_Impl* pUserData = pEntry ? static_cast<AddressUserData_Impl*>(pEntry->GetUserData()) : 0;
477cdf0e10cSrcweir     if(pUserData && pUserData->sURL.getLength())
478cdf0e10cSrcweir     {
479cdf0e10cSrcweir         if(pUserData->xResultSet.is())
480cdf0e10cSrcweir         {
481cdf0e10cSrcweir             SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem();
482cdf0e10cSrcweir             if(rConfigItem.GetResultSet() != pUserData->xResultSet)
483cdf0e10cSrcweir                 ::comphelper::disposeComponent( pUserData->xResultSet );
484cdf0e10cSrcweir             pUserData->xResultSet = 0;
485cdf0e10cSrcweir 
486cdf0e10cSrcweir             rConfigItem.DisposeResultSet();
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir         pUserData->xSource.clear();
489cdf0e10cSrcweir         pUserData->xColumnsSupplier.clear();
490cdf0e10cSrcweir         pUserData->xConnection.clear();
491cdf0e10cSrcweir             // will automatically close if it was the las reference
492cdf0e10cSrcweir         SwCreateAddressListDialog* pDlg =
493cdf0e10cSrcweir                 new SwCreateAddressListDialog(
494cdf0e10cSrcweir                         pButton,
495cdf0e10cSrcweir                         pUserData->sURL,
496cdf0e10cSrcweir                         m_pAddressPage->GetWizard()->GetConfigItem());
497cdf0e10cSrcweir         if(RET_OK == pDlg->Execute())
498cdf0e10cSrcweir         {
499cdf0e10cSrcweir         }
500cdf0e10cSrcweir         delete pDlg;
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir     return 0;
503cdf0e10cSrcweir };
504cdf0e10cSrcweir /*-- 19.04.2004 09:41:05---------------------------------------------------
505cdf0e10cSrcweir 
506cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,ListBoxSelectHdl_Impl,SvTabListBox *,EMPTYARG)507cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, ListBoxSelectHdl_Impl, SvTabListBox*, EMPTYARG)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
510cdf0e10cSrcweir     Application::PostUserEvent( STATIC_LINK( this, SwAddressListDialog,
511cdf0e10cSrcweir                                                 StaticListBoxSelectHdl_Impl ), pSelect );
512cdf0e10cSrcweir     return 0;
513cdf0e10cSrcweir }
IMPL_STATIC_LINK(SwAddressListDialog,StaticListBoxSelectHdl_Impl,SvLBoxEntry *,pSelect)514cdf0e10cSrcweir IMPL_STATIC_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, SvLBoxEntry*, pSelect)
515cdf0e10cSrcweir {
516cdf0e10cSrcweir     //prevent nested calls of the select handler
517cdf0e10cSrcweir     if(pThis->m_bInSelectHdl)
518cdf0e10cSrcweir         return 0;
519cdf0e10cSrcweir     pThis->EnterWait();
520cdf0e10cSrcweir     pThis->m_bInSelectHdl = true;
521cdf0e10cSrcweir     AddressUserData_Impl* pUserData = 0;
522cdf0e10cSrcweir     if(pSelect)
523cdf0e10cSrcweir     {
524cdf0e10cSrcweir         String sTable = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
525cdf0e10cSrcweir         if(!sTable.Len())
526cdf0e10cSrcweir         {
527cdf0e10cSrcweir             pThis->m_aListLB.SetEntryText(pThis->m_sConnecting, pSelect, ITEMID_TABLE - 1);
528cdf0e10cSrcweir             // allow painting of the new entry
529cdf0e10cSrcweir             pThis->m_aListLB.Window::Invalidate(INVALIDATE_UPDATE);
530cdf0e10cSrcweir             for (sal_uInt16 i = 0; i < 10; i++)
531cdf0e10cSrcweir                 Application::Reschedule();
532cdf0e10cSrcweir         }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
535cdf0e10cSrcweir         if(pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
536cdf0e10cSrcweir         {
537cdf0e10cSrcweir             pThis->DetectTablesAndQueries(pSelect, !sTable.Len());
538cdf0e10cSrcweir         }
539cdf0e10cSrcweir         else
540cdf0e10cSrcweir         {
541cdf0e10cSrcweir             //otherwise set the selected db-data
542cdf0e10cSrcweir             pThis->m_aDBData.sDataSource = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1);
543cdf0e10cSrcweir             pThis->m_aDBData.sCommand = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
544cdf0e10cSrcweir             pThis->m_aDBData.nCommandType = pUserData->nCommandType;
545cdf0e10cSrcweir             pThis->m_aOK.Enable(sal_True);
546cdf0e10cSrcweir         }
547cdf0e10cSrcweir         sTable = pThis->m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
548cdf0e10cSrcweir         if(sTable == pThis->m_sConnecting)
549cdf0e10cSrcweir            pThis->m_aListLB.SetEntryText(String(), pSelect, ITEMID_TABLE - 1);
550cdf0e10cSrcweir     }
551cdf0e10cSrcweir     pThis->m_aEditPB.Enable(pUserData && pUserData->sURL.getLength() &&
552cdf0e10cSrcweir                     SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577#
553cdf0e10cSrcweir                     !SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL ) );
554cdf0e10cSrcweir     pThis->m_bInSelectHdl = false;
555cdf0e10cSrcweir     pThis->LeaveWait();
556cdf0e10cSrcweir     return 0;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir /*-- 13.05.2004 14:59:25---------------------------------------------------
560cdf0e10cSrcweir     detect the number of tables for a data source
561cdf0e10cSrcweir     if only one is available then set it at the entry
562cdf0e10cSrcweir   -----------------------------------------------------------------------*/
DetectTablesAndQueries(SvLBoxEntry * pSelect,bool bWidthDialog)563cdf0e10cSrcweir void SwAddressListDialog::DetectTablesAndQueries(
564cdf0e10cSrcweir         SvLBoxEntry* pSelect,
565cdf0e10cSrcweir         bool bWidthDialog)
566cdf0e10cSrcweir {
567cdf0e10cSrcweir     try
568cdf0e10cSrcweir     {
569cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
570cdf0e10cSrcweir         uno::Reference<XCompletedConnection> xComplConnection;
571cdf0e10cSrcweir         if(!pUserData->xConnection.is())
572cdf0e10cSrcweir         {
573cdf0e10cSrcweir             m_aDBData.sDataSource = m_aListLB.GetEntryText(pSelect, ITEMID_NAME - 1);
574cdf0e10cSrcweir             m_xDBContext->getByName(m_aDBData.sDataSource) >>= xComplConnection;
575cdf0e10cSrcweir             pUserData->xSource = uno::Reference<XDataSource>(xComplConnection, UNO_QUERY);
576cdf0e10cSrcweir 
577cdf0e10cSrcweir             uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
578cdf0e10cSrcweir             uno::Reference< XInteractionHandler > xHandler(
579cdf0e10cSrcweir                 xMgr->createInstance( C2U( "com.sun.star.task.InteractionHandler" )), UNO_QUERY);
580cdf0e10cSrcweir             pUserData->xConnection = SharedConnection( xComplConnection->connectWithCompletion( xHandler ) );
581cdf0e10cSrcweir         }
582cdf0e10cSrcweir         if(pUserData->xConnection.is())
583cdf0e10cSrcweir         {
584cdf0e10cSrcweir             sal_Int32 nTables = 0;
585cdf0e10cSrcweir             uno::Sequence<rtl::OUString> aTables;
586cdf0e10cSrcweir             uno::Sequence<rtl::OUString> aQueries;
587cdf0e10cSrcweir             uno::Reference<XTablesSupplier> xTSupplier(pUserData->xConnection, UNO_QUERY);
588cdf0e10cSrcweir             if(xTSupplier.is())
589cdf0e10cSrcweir             {
590cdf0e10cSrcweir                 uno::Reference<XNameAccess> xTbls = xTSupplier->getTables();
591cdf0e10cSrcweir                 aTables = xTbls->getElementNames();
592cdf0e10cSrcweir                 nTables += aTables.getLength();
593cdf0e10cSrcweir             }
594cdf0e10cSrcweir             uno::Reference<XQueriesSupplier> xQSupplier(pUserData->xConnection, UNO_QUERY);
595cdf0e10cSrcweir             if(xQSupplier.is())
596cdf0e10cSrcweir             {
597cdf0e10cSrcweir                 uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries();
598cdf0e10cSrcweir                 aQueries = xQueries->getElementNames();
599cdf0e10cSrcweir                 nTables += aQueries.getLength();
600cdf0e10cSrcweir             }
601cdf0e10cSrcweir             pUserData->nTableAndQueryCount = nTables;
602cdf0e10cSrcweir             if(nTables > 1 && bWidthDialog)
603cdf0e10cSrcweir             {
604cdf0e10cSrcweir                 //now call the table select dialog - if more than one table exists
605cdf0e10cSrcweir                 SwSelectDBTableDialog* pDlg = new SwSelectDBTableDialog(this, pUserData->xConnection);
606cdf0e10cSrcweir                 String sTable = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
607cdf0e10cSrcweir                 if(sTable.Len())
608cdf0e10cSrcweir                     pDlg->SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE);
609cdf0e10cSrcweir                 if(RET_OK == pDlg->Execute())
610cdf0e10cSrcweir                 {
611cdf0e10cSrcweir                     bool bIsTable;
612cdf0e10cSrcweir                     m_aDBData.sCommand = pDlg->GetSelectedTable(bIsTable);
613cdf0e10cSrcweir                     m_aDBData.nCommandType = bIsTable ? CommandType::TABLE : CommandType::QUERY;
614cdf0e10cSrcweir                     pUserData->nCommandType = m_aDBData.nCommandType;
615cdf0e10cSrcweir                 }
616cdf0e10cSrcweir                 delete pDlg;
617cdf0e10cSrcweir             }
618cdf0e10cSrcweir             else if(nTables == 1)
619cdf0e10cSrcweir             {
620cdf0e10cSrcweir                 if(aTables.getLength())
621cdf0e10cSrcweir                 {
622cdf0e10cSrcweir                     m_aDBData.sCommand = aTables[0];
623cdf0e10cSrcweir                     m_aDBData.nCommandType = CommandType::TABLE;
624cdf0e10cSrcweir                 }
625cdf0e10cSrcweir                 else
626cdf0e10cSrcweir                 {
627cdf0e10cSrcweir                     m_aDBData.sCommand = aQueries[0];
628cdf0e10cSrcweir                     m_aDBData.nCommandType = CommandType::QUERY;
629cdf0e10cSrcweir                 }
630cdf0e10cSrcweir             }
631cdf0e10cSrcweir         }
632cdf0e10cSrcweir         if ( m_aDBData.sCommand.getLength() )
633cdf0e10cSrcweir         {
634cdf0e10cSrcweir             uno::Reference<beans::XPropertySet> xSourceProperties;
635cdf0e10cSrcweir             m_xDBContext->getByName(m_aDBData.sDataSource) >>= xSourceProperties;
636cdf0e10cSrcweir             pUserData->sURL = lcl_getFlatURL( xSourceProperties );
637cdf0e10cSrcweir 
638cdf0e10cSrcweir             pUserData->xColumnsSupplier = SwNewDBMgr::GetColumnSupplier(pUserData->xConnection,
639cdf0e10cSrcweir                                     m_aDBData.sCommand,
640cdf0e10cSrcweir                                     m_aDBData.nCommandType == CommandType::TABLE ?
641cdf0e10cSrcweir                                             SW_DB_SELECT_TABLE : SW_DB_SELECT_QUERY );
642cdf0e10cSrcweir             //#i97577#
643cdf0e10cSrcweir             if( pUserData->xColumnsSupplier.is() )
644cdf0e10cSrcweir                 m_aListLB.SetEntryText(m_aDBData.sCommand, pSelect, ITEMID_TABLE - 1);
645cdf0e10cSrcweir             else
646cdf0e10cSrcweir                 m_aListLB.SetEntryText(String(), pSelect, ITEMID_TABLE - 1);
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir         String sCommand = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
649cdf0e10cSrcweir         m_aOK.Enable(pSelect && sCommand.Len());
650cdf0e10cSrcweir         m_aFilterPB.Enable( pUserData->xConnection.is() && sCommand.Len() );
651cdf0e10cSrcweir         m_aTablePB.Enable( pUserData->nTableAndQueryCount > 1 );
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir     catch(Exception& )
654cdf0e10cSrcweir     {
655cdf0e10cSrcweir         DBG_ERROR("exception caught in SwAddressListDialog::DetectTablesAndQueries");
656cdf0e10cSrcweir         m_aOK.Enable( sal_False );
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir /*-- 13.05.2004 12:55:40---------------------------------------------------
661cdf0e10cSrcweir 
662cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,TableSelectHdl_Impl,PushButton *,pButton)663cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, TableSelectHdl_Impl, PushButton*, pButton)
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     EnterWait();
666cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
667cdf0e10cSrcweir     if(pSelect)
668cdf0e10cSrcweir     {
669cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
670cdf0e10cSrcweir         //only call the table select dialog if tables have not been searched for or there
671cdf0e10cSrcweir         //are more than 1
672cdf0e10cSrcweir         String sTable = m_aListLB.GetEntryText(pSelect, ITEMID_TABLE - 1);
673cdf0e10cSrcweir         if( pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
674cdf0e10cSrcweir         {
675cdf0e10cSrcweir             DetectTablesAndQueries(pSelect, (pButton != 0) || (!sTable.Len()));
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir     }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     LeaveWait();
680cdf0e10cSrcweir     return 0;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir /*-- 08.04.2004 14:52:11---------------------------------------------------
684cdf0e10cSrcweir 
685cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressListDialog,OKHdl_Impl,PushButton *,EMPTYARG)686cdf0e10cSrcweir IMPL_LINK(SwAddressListDialog, OKHdl_Impl, PushButton*, EMPTYARG)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir     EndDialog(sal_True);
689cdf0e10cSrcweir     return 0;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir /*-- 07.05.2004 14:17:47---------------------------------------------------
693cdf0e10cSrcweir 
694cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetSource()695cdf0e10cSrcweir uno::Reference< XDataSource>  SwAddressListDialog::GetSource()
696cdf0e10cSrcweir {
697cdf0e10cSrcweir     uno::Reference< XDataSource>  xRet;
698cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
699cdf0e10cSrcweir     if(pSelect)
700cdf0e10cSrcweir     {
701cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
702cdf0e10cSrcweir         xRet = pUserData->xSource;
703cdf0e10cSrcweir     }
704cdf0e10cSrcweir     return xRet;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir }
707cdf0e10cSrcweir /*-- 07.05.2004 14:17:48---------------------------------------------------
708cdf0e10cSrcweir 
709cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetConnection()710cdf0e10cSrcweir SharedConnection    SwAddressListDialog::GetConnection()
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     SharedConnection xRet;
713cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
714cdf0e10cSrcweir     if(pSelect)
715cdf0e10cSrcweir     {
716cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
717cdf0e10cSrcweir         xRet = pUserData->xConnection;
718cdf0e10cSrcweir     }
719cdf0e10cSrcweir     return xRet;
720cdf0e10cSrcweir }
721cdf0e10cSrcweir /*-- 07.05.2004 14:17:48---------------------------------------------------
722cdf0e10cSrcweir 
723cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetColumnsSupplier()724cdf0e10cSrcweir uno::Reference< XColumnsSupplier> SwAddressListDialog::GetColumnsSupplier()
725cdf0e10cSrcweir {
726cdf0e10cSrcweir     uno::Reference< XColumnsSupplier> xRet;
727cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
728cdf0e10cSrcweir     if(pSelect)
729cdf0e10cSrcweir     {
730cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
731cdf0e10cSrcweir         xRet = pUserData->xColumnsSupplier;
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir     return xRet;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir /*-- 14.05.2004 15:04:09---------------------------------------------------
736cdf0e10cSrcweir 
737cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetFilter()738cdf0e10cSrcweir ::rtl::OUString     SwAddressListDialog::GetFilter()
739cdf0e10cSrcweir {
740cdf0e10cSrcweir     ::rtl::OUString sRet;
741cdf0e10cSrcweir     SvLBoxEntry* pSelect = m_aListLB.FirstSelected();
742cdf0e10cSrcweir     if(pSelect)
743cdf0e10cSrcweir     {
744cdf0e10cSrcweir         AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData());
745cdf0e10cSrcweir         sRet = pUserData->sFilter;
746cdf0e10cSrcweir     }
747cdf0e10cSrcweir     return sRet;
748cdf0e10cSrcweir }
749