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