Branch data Line data Source code
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 : :
21 : : #include "dsselect.hxx"
22 : : #include "dsselect.hrc"
23 : : #include "dbu_dlg.hrc"
24 : : #include <vcl/msgbox.hxx>
25 : : #include "localresaccess.hxx"
26 : : #include <tools/rcid.h>
27 : :
28 : : #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
29 : : #include <com/sun/star/beans/XPropertySet.hpp>
30 : : #include <com/sun/star/beans/XPropertySetInfo.hpp>
31 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
32 : : #include <com/sun/star/awt/XWindow.hpp>
33 : : #include "dbustrings.hrc"
34 : : #include <toolkit/helper/vclunohelper.hxx>
35 : : #include <comphelper/extract.hxx>
36 : : #include <comphelper/types.hxx>
37 : : #include <comphelper/processfactory.hxx>
38 : : #include "dsitems.hxx"
39 : : #include <svl/stritem.hxx>
40 : : #include <svl/intitem.hxx>
41 : : #include <svl/eitem.hxx>
42 : : #include <svl/itemset.hxx>
43 : :
44 : : //.........................................................................
45 : : namespace dbaui
46 : : {
47 : : //.........................................................................
48 : : using namespace ::com::sun::star::uno;
49 : : using namespace ::com::sun::star::beans;
50 : : using namespace ::com::sun::star::sdbc;
51 : : using namespace ::com::sun::star::sdbcx;
52 : : using namespace ::com::sun::star::ui::dialogs;
53 : : using namespace ::comphelper;
54 : : //==================================================================
55 : 0 : ODatasourceSelectDialog::ODatasourceSelectDialog(Window* _pParent, const StringBag& _rDatasources, SfxItemSet* _pOutputSet)
56 : : :ModalDialog(_pParent, ModuleRes(DLG_DATASOURCE_SELECTION))
57 : : ,m_aDescription (this, ModuleRes(FT_DESCRIPTION))
58 : : ,m_aDatasource (this, ModuleRes(LB_DATASOURCE))
59 : : ,m_aOk (this, ModuleRes(PB_OK))
60 : : ,m_aCancel (this, ModuleRes(PB_CANCEL))
61 : : ,m_aHelp (this, ModuleRes(PB_HELP))
62 : : #ifdef HAVE_ODBC_ADMINISTRATION
63 : : ,m_aManageDatasources (this, ModuleRes(PB_MANAGE))
64 : : #endif
65 [ # # ][ # # ]: 0 : ,m_pOutputSet(_pOutputSet)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
66 : : {
67 [ # # ]: 0 : fillListBox(_rDatasources);
68 : : #ifdef HAVE_ODBC_ADMINISTRATION
69 : : // allow ODBC datasource managenment
70 : : m_aManageDatasources.Show();
71 : : m_aManageDatasources.Enable();
72 : : m_aManageDatasources.SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
73 : : #endif
74 [ # # ]: 0 : m_aDatasource.SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
75 [ # # ]: 0 : FreeResource();
76 : 0 : }
77 : :
78 : : // -----------------------------------------------------------------------
79 [ # # ][ # # ]: 0 : ODatasourceSelectDialog::~ODatasourceSelectDialog()
[ # # ][ # # ]
[ # # ]
80 : : {
81 [ # # ]: 0 : }
82 : :
83 : : // -----------------------------------------------------------------------
84 : 0 : IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox )
85 : : {
86 [ # # ]: 0 : if (pListBox->GetSelectEntryCount())
87 : 0 : EndDialog(RET_OK);
88 : 0 : return 0;
89 : : }
90 : :
91 : : // -----------------------------------------------------------------------
92 : 0 : sal_Bool ODatasourceSelectDialog::Close()
93 : : {
94 : : #ifdef HAVE_ODBC_ADMINISTRATION
95 : : if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() )
96 : : return sal_False;
97 : : #endif
98 : :
99 : 0 : return ModalDialog::Close();
100 : : }
101 : :
102 : : // -----------------------------------------------------------------------
103 : : #ifdef HAVE_ODBC_ADMINISTRATION
104 : : IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl)
105 : : {
106 : : if ( !m_pODBCManagement.get() )
107 : : m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
108 : :
109 : : if ( !m_pODBCManagement->manageDataSources_async() )
110 : : {
111 : : // TODO: error message
112 : : m_aDatasource.GrabFocus();
113 : : m_aManageDatasources.Disable();
114 : : return 1L;
115 : : }
116 : :
117 : : m_aDatasource.Disable();
118 : : m_aOk.Disable();
119 : : m_aCancel.Disable();
120 : : m_aManageDatasources.Disable();
121 : :
122 : : OSL_POSTCOND( m_pODBCManagement->isRunning(), "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
123 : : return 0L;
124 : : }
125 : :
126 : : IMPL_LINK( ODatasourceSelectDialog, ManageProcessFinished, void*, /**/ )
127 : : {
128 : : StringBag aOdbcDatasources;
129 : : OOdbcEnumeration aEnumeration;
130 : : aEnumeration.getDatasourceNames( aOdbcDatasources );
131 : : fillListBox( aOdbcDatasources );
132 : :
133 : : m_aDatasource.Enable();
134 : : m_aOk.Enable();
135 : : m_aCancel.Enable();
136 : : m_aManageDatasources.Enable();
137 : :
138 : : return 0L;
139 : : }
140 : :
141 : : #endif
142 : : // -----------------------------------------------------------------------------
143 : 0 : void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources)
144 : : {
145 : 0 : ::rtl::OUString sSelected;
146 [ # # ][ # # ]: 0 : if (m_aDatasource.GetEntryCount())
147 [ # # ][ # # ]: 0 : sSelected = m_aDatasource.GetSelectEntry();
[ # # ]
148 [ # # ]: 0 : m_aDatasource.Clear();
149 : : // fill the list
150 [ # # ]: 0 : for ( ConstStringBagIterator aDS = _rDatasources.begin();
151 : 0 : aDS != _rDatasources.end();
152 : : ++aDS
153 : : )
154 : : {
155 [ # # ][ # # ]: 0 : m_aDatasource.InsertEntry( *aDS );
[ # # ]
156 : : }
157 : :
158 [ # # ][ # # ]: 0 : if (m_aDatasource.GetEntryCount())
159 : : {
160 [ # # ]: 0 : if (!sSelected.isEmpty())
161 [ # # ][ # # ]: 0 : m_aDatasource.SelectEntry(sSelected);
[ # # ]
162 : : else // select the first entry
163 [ # # ]: 0 : m_aDatasource.SelectEntryPos(0);
164 : 0 : }
165 : 0 : }
166 : :
167 : : //.........................................................................
168 : : } // namespace dbaui
169 : : //.........................................................................
170 : :
171 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|